project: Mixins for recent changes

This commit is contained in:
Owain van Brakel
2021-09-05 20:12:24 +02:00
parent 7b65292c12
commit c6d5bcfa79
8 changed files with 156 additions and 89 deletions

View File

@@ -35,6 +35,7 @@ import java.util.Set;
import javax.inject.Inject; import javax.inject.Inject;
import net.runelite.api.Client; import net.runelite.api.Client;
import net.runelite.api.NPC; import net.runelite.api.NPC;
import net.runelite.api.Perspective;
import net.runelite.api.Point; import net.runelite.api.Point;
import net.runelite.api.Tile; import net.runelite.api.Tile;
import net.runelite.api.coords.LocalPoint; import net.runelite.api.coords.LocalPoint;

View File

@@ -0,0 +1,34 @@
/*
* Copyright (c) 2021, Adam <Adam@sigterm.info>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.client.util;
import javax.swing.PopupFactory;
/**
* Dummy popup factory for Java 8
*/
class MacOSPopupFactory extends PopupFactory
{
}

View File

@@ -51,6 +51,7 @@ import javax.swing.JButton;
import javax.swing.JMenuItem; import javax.swing.JMenuItem;
import javax.swing.JPopupMenu; import javax.swing.JPopupMenu;
import javax.swing.LookAndFeel; import javax.swing.LookAndFeel;
import javax.swing.PopupFactory;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import javax.swing.ToolTipManager; import javax.swing.ToolTipManager;
import javax.swing.UIManager; import javax.swing.UIManager;
@@ -112,6 +113,14 @@ public class SwingUtil
try try
{ {
UIManager.setLookAndFeel(laf); UIManager.setLookAndFeel(laf);
if (OSType.getOSType() == OSType.MacOS)
{
// On MacOS Substance doesn't install its own popup factory, and the default one uses lightweight
// components unless the Aqua LAF is used. Lightweight components do not render correctly over AWT
// canvases on MacOS - so replace the popup factory one with that forces heavy components.
PopupFactory.setSharedInstance(new MacOSPopupFactory());
}
} }
catch (UnsupportedLookAndFeelException ex) catch (UnsupportedLookAndFeelException ex)
{ {

View File

@@ -0,0 +1,42 @@
/*
* Copyright (c) 2021, Adam <Adam@sigterm.info>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.client.util;
import java.awt.Component;
import javax.swing.Popup;
import javax.swing.PopupFactory;
/**
* Popup factory for Java 11 which forces heavyweight popups. Lightweight popups do not render correctly
* over AWT canvases on OSX.
*/
class MacOSPopupFactory extends PopupFactory
{
@Override
protected Popup getPopup(Component owner, Component contents, int x, int y, boolean isHeavyWeightPopup) throws IllegalArgumentException
{
return super.getPopup(owner, contents, x, y, true);
}
}

View File

@@ -41,10 +41,7 @@ public abstract class RSModelDataMixin implements RSModelData
private static RSClient client; private static RSClient client;
@Inject @Inject
private float[][] faceTextureUCoordinates; private float[] faceTextureUVCoordinates;
@Inject
private float[][] faceTextureVCoordinates;
@Copy("toModel") @Copy("toModel")
@Replace("toModel") @Replace("toModel")
@@ -59,14 +56,13 @@ public abstract class RSModelDataMixin implements RSModelData
return null; return null;
} }
if (faceTextureUCoordinates == null) if (faceTextureUVCoordinates == null)
{ {
computeTextureUVCoordinates(); computeTextureUVCoordinates();
} }
RSModel rsModel = (RSModel) model; RSModel rsModel = (RSModel) model;
rsModel.setFaceTextureUCoordinates(faceTextureUCoordinates); rsModel.setFaceTextureUVCoordinates(faceTextureUVCoordinates);
rsModel.setFaceTextureVCoordinates(faceTextureVCoordinates);
return model; return model;
} }
@@ -94,40 +90,35 @@ public abstract class RSModelDataMixin implements RSModelData
final byte[] textureCoords = getTextureCoords(); final byte[] textureCoords = getTextureCoords();
int faceCount = getTriangleFaceCount(); int faceCount = getTriangleFaceCount();
this.faceTextureUCoordinates = new float[faceCount][]; float[] faceTextureUCoordinates = new float[faceCount * 6];
this.faceTextureVCoordinates = new float[faceCount][];
for (int i = 0; i < faceCount; i++) for (int i = 0; i < faceCount; i++)
{ {
int trianglePointX = trianglePointsX[i]; int trianglePointX = trianglePointsX[i];
int trianglePointY = trianglePointsY[i]; int trianglePointY = trianglePointsY[i];
int trianglePointZ = trianglePointsZ[i]; int trianglePointZ = trianglePointsZ[i];
int textureCoordinate = textureCoords != null && textureCoords[i] != -1 ? textureCoords[i] & 255 : -1;
short textureIdx; short textureIdx = faceTextures[i];
textureIdx = faceTextures[i];
if (textureIdx != -1) if (textureIdx != -1)
{ {
float[] u = new float[3];
float[] v = new float[3];
int triangleVertexIdx1; int triangleVertexIdx1;
int triangleVertexIdx2; int triangleVertexIdx2;
int triangleVertexIdx3; int triangleVertexIdx3;
if (textureCoordinate == -1) if (textureCoords != null && textureCoords[i] != -1)
{
int textureCoordinate = textureCoords[i] & 255;
triangleVertexIdx1 = texTriangleX[textureCoordinate];
triangleVertexIdx2 = texTriangleY[textureCoordinate];
triangleVertexIdx3 = texTriangleZ[textureCoordinate];
}
else
{ {
triangleVertexIdx1 = trianglePointX; triangleVertexIdx1 = trianglePointX;
triangleVertexIdx2 = trianglePointY; triangleVertexIdx2 = trianglePointY;
triangleVertexIdx3 = trianglePointZ; triangleVertexIdx3 = trianglePointZ;
} }
else
{
triangleVertexIdx1 = texTriangleX[textureCoordinate];
triangleVertexIdx2 = texTriangleY[textureCoordinate];
triangleVertexIdx3 = texTriangleZ[textureCoordinate];
}
float triangleX = (float) vertexPositionsX[triangleVertexIdx1]; float triangleX = (float) vertexPositionsX[triangleVertexIdx1];
float triangleY = (float) vertexPositionsY[triangleVertexIdx1]; float triangleY = (float) vertexPositionsY[triangleVertexIdx1];
@@ -157,22 +148,29 @@ public abstract class RSModelDataMixin implements RSModelData
float f_902_ = f_885_ * f_898_ - f_886_ * f_897_; float f_902_ = f_885_ * f_898_ - f_886_ * f_897_;
float f_903_ = 1.0F / (f_900_ * f_882_ + f_901_ * f_883_ + f_902_ * f_884_); float f_903_ = 1.0F / (f_900_ * f_882_ + f_901_ * f_883_ + f_902_ * f_884_);
u[0] = (f_900_ * f_888_ + f_901_ * f_889_ + f_902_ * f_890_) * f_903_; float u0 = (f_900_ * f_888_ + f_901_ * f_889_ + f_902_ * f_890_) * f_903_;
u[1] = (f_900_ * f_891_ + f_901_ * f_892_ + f_902_ * f_893_) * f_903_; float u1 = (f_900_ * f_891_ + f_901_ * f_892_ + f_902_ * f_893_) * f_903_;
u[2] = (f_900_ * f_894_ + f_901_ * f_895_ + f_902_ * f_896_) * f_903_; float u2 = (f_900_ * f_894_ + f_901_ * f_895_ + f_902_ * f_896_) * f_903_;
f_900_ = f_883_ * f_899_ - f_884_ * f_898_; f_900_ = f_883_ * f_899_ - f_884_ * f_898_;
f_901_ = f_884_ * f_897_ - f_882_ * f_899_; f_901_ = f_884_ * f_897_ - f_882_ * f_899_;
f_902_ = f_882_ * f_898_ - f_883_ * f_897_; f_902_ = f_882_ * f_898_ - f_883_ * f_897_;
f_903_ = 1.0F / (f_900_ * f_885_ + f_901_ * f_886_ + f_902_ * f_887_); f_903_ = 1.0F / (f_900_ * f_885_ + f_901_ * f_886_ + f_902_ * f_887_);
v[0] = (f_900_ * f_888_ + f_901_ * f_889_ + f_902_ * f_890_) * f_903_; float v0 = (f_900_ * f_888_ + f_901_ * f_889_ + f_902_ * f_890_) * f_903_;
v[1] = (f_900_ * f_891_ + f_901_ * f_892_ + f_902_ * f_893_) * f_903_; float v1 = (f_900_ * f_891_ + f_901_ * f_892_ + f_902_ * f_893_) * f_903_;
v[2] = (f_900_ * f_894_ + f_901_ * f_895_ + f_902_ * f_896_) * f_903_; float v2 = (f_900_ * f_894_ + f_901_ * f_895_ + f_902_ * f_896_) * f_903_;
this.faceTextureUCoordinates[i] = u; int idx = i * 6;
this.faceTextureVCoordinates[i] = v; faceTextureUCoordinates[idx] = u0;
faceTextureUCoordinates[idx + 1] = v0;
faceTextureUCoordinates[idx + 2] = u1;
faceTextureUCoordinates[idx + 3] = v1;
faceTextureUCoordinates[idx + 4] = u2;
faceTextureUCoordinates[idx + 5] = v2;
} }
} }
this.faceTextureUVCoordinates = faceTextureUCoordinates;
} }
} }

View File

@@ -61,51 +61,36 @@ public abstract class RSModelMixin implements RSModel
private int rl$uvBufferOffset; private int rl$uvBufferOffset;
@Inject @Inject
private float[][] rl$faceTextureUCoordinates; private float[] rl$faceTextureUVCoordinates;
@Inject
private float[][] rl$faceTextureVCoordinates;
@MethodHook(value = "<init>", end = true) @MethodHook(value = "<init>", end = true)
@Inject @Inject
public void rl$init(RSModel[] models, int length) public void rl$init(RSModel[] models, int length)
{ {
int count = 0; if (this.getFaceTextures() != null)
for (int i = 0; i < length; ++i)
{ {
RSModel model = models[i]; int count = this.getTrianglesCount();
if (model != null) float[] uv = new float[count * 6];
int idx = 0;
for (int i = 0; i < length; ++i)
{ {
count += model.getTrianglesCount(); RSModel model = models[i];
} if (model != null)
}
float[][] u = new float[count][];
float[][] v = new float[count][];
int idx = 0;
for (int i = 0; i < length; ++i)
{
RSModel model = models[i];
if (model != null)
{
float[][] modelU = model.getFaceTextureUCoordinates();
float[][] modelV = model.getFaceTextureVCoordinates();
for (int j = 0; j < model.getTrianglesCount(); ++j)
{ {
if (modelU != null && modelV != null) float[] modelUV = model.getFaceTextureUVCoordinates();
if (modelUV != null)
{ {
u[idx] = modelU[j]; System.arraycopy(modelUV, 0, uv, idx, model.getTrianglesCount() * 6);
v[idx] = modelV[j];
} }
++idx;
idx += model.getTrianglesCount() * 6;
} }
} }
}
setFaceTextureUCoordinates(u); setFaceTextureUVCoordinates(uv);
setFaceTextureVCoordinates(v); }
} }
@Override @Override
@@ -169,8 +154,7 @@ public abstract class RSModelMixin implements RSModel
if (model != null && model != this) if (model != null && model != this)
{ {
RSModel rsModel = (RSModel) model; RSModel rsModel = (RSModel) model;
rsModel.setFaceTextureUCoordinates(rl$faceTextureUCoordinates); rsModel.setFaceTextureUVCoordinates(rl$faceTextureUVCoordinates);
rsModel.setFaceTextureVCoordinates(rl$faceTextureVCoordinates);
} }
return model; return model;
} }
@@ -192,8 +176,7 @@ public abstract class RSModelMixin implements RSModel
{ {
// Animated models are usually a shared Model instance that is global // Animated models are usually a shared Model instance that is global
RSModel rsModel = (RSModel) sharedModel; RSModel rsModel = (RSModel) sharedModel;
rsModel.setFaceTextureUCoordinates(rl$faceTextureUCoordinates); rsModel.setFaceTextureUVCoordinates(rl$faceTextureUVCoordinates);
rsModel.setFaceTextureVCoordinates(rl$faceTextureVCoordinates);
} }
@Inject @Inject
@@ -385,29 +368,15 @@ public abstract class RSModelMixin implements RSModel
@Inject @Inject
@Override @Override
public float[][] getFaceTextureUCoordinates() public float[] getFaceTextureUVCoordinates()
{ {
return rl$faceTextureUCoordinates; return rl$faceTextureUVCoordinates;
} }
@Inject @Inject
@Override @Override
public void setFaceTextureUCoordinates(float[][] faceTextureUCoordinates) public void setFaceTextureUVCoordinates(float[] faceTextureUVCoordinates)
{ {
this.rl$faceTextureUCoordinates = faceTextureUCoordinates; this.rl$faceTextureUVCoordinates = faceTextureUVCoordinates;
}
@Inject
@Override
public float[][] getFaceTextureVCoordinates()
{
return rl$faceTextureVCoordinates;
}
@Inject
@Override
public void setFaceTextureVCoordinates(float[][] faceTextureVCoordinates)
{
this.rl$faceTextureVCoordinates = faceTextureVCoordinates;
} }
} }

View File

@@ -24,6 +24,7 @@
*/ */
package net.runelite.mixins; package net.runelite.mixins;
import java.awt.Polygon;
import java.awt.Shape; import java.awt.Shape;
import net.runelite.api.AnimationID; import net.runelite.api.AnimationID;
import net.runelite.api.NPCComposition; import net.runelite.api.NPCComposition;
@@ -169,6 +170,22 @@ public abstract class RSNPCMixin implements RSNPC
return composition; return composition;
} }
@Inject
@Override
public Polygon getCanvasTilePoly()
{
NPCComposition transformedComposition = this.getTransformedComposition();
if (transformedComposition == null)
{
return null;
}
else
{
int size = transformedComposition.getSize();
return Perspective.getCanvasTileAreaPoly(client, this.getLocalLocation(), size);
}
}
@Inject @Inject
@Override @Override
public Shape getConvexHull() public Shape getConvexHull()

View File

@@ -169,9 +169,6 @@ public interface RSModel extends RSRenderable, Model
*/ */
Shape getConvexHull(int localX, int localY, int orientation, int tileHeight); Shape getConvexHull(int localX, int localY, int orientation, int tileHeight);
float[][] getFaceTextureUCoordinates(); float[] getFaceTextureUVCoordinates();
void setFaceTextureUCoordinates(float[][] rl$faceTextureUCoordinates); void setFaceTextureUVCoordinates(float[] rl$faceTextureUVCoordinates);
float[][] getFaceTextureVCoordinates();
void setFaceTextureVCoordinates(float[][] rl$faceTextureVCoordinates);
} }