Make sure we get all fillRectangles for clearColorBuffer

This commit is contained in:
Lucas
2019-06-08 19:54:17 +02:00
parent b1da8e510a
commit 2337d3ea55
6 changed files with 92 additions and 38 deletions

View File

@@ -1,12 +1,14 @@
package net.runelite.injector.raw;
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
import net.runelite.asm.ClassFile;
import net.runelite.asm.Method;
import net.runelite.asm.attributes.Code;
import net.runelite.asm.attributes.code.Instruction;
import net.runelite.asm.attributes.code.Instructions;
import net.runelite.asm.attributes.code.instructions.ILoad;
import net.runelite.asm.attributes.code.instructions.InvokeStatic;
import net.runelite.asm.attributes.code.instructions.LDC;
import net.runelite.asm.pool.Class;
import net.runelite.asm.signature.Signature;
import net.runelite.deob.DeobAnnotations;
@@ -37,34 +39,85 @@ public class ClearColorBuffer
private void injectColorBufferHooks() throws InjectionException
{
Method obmethod = findStaticMethod("drawEntities");
net.runelite.asm.pool.Method fillRectangle = findStaticMethod("Rasterizer2D_fillRectangle").getPoolMethod();
Instructions ins = obmethod.getCode().getInstructions();
replace(ins, fillRectangle);
}
private void replace(Instructions ins, net.runelite.asm.pool.Method meth)
{
List<Instruction> insList = new ArrayList<>();
for (Instruction i : ins.getInstructions())
int count = 0;
int replaced = 0;
for (ClassFile cf : inject.getVanilla().getClasses())
{
if (i instanceof InvokeStatic)
for (Method m : cf.getMethods())
{
if (((InvokeStatic) i).getMethod().equals(meth))
if (!m.isStatic())
{
int index = ins.getInstructions().indexOf(i);
log.info("Found drawRectangle at index {}", index);
continue;
}
insList.add(i);
Code c = m.getCode();
if (c == null)
{
continue;
}
Instructions ins = c.getInstructions();
ListIterator<Instruction> it = ins.getInstructions().listIterator();
for (; it.hasNext(); )
{
Instruction i = it.next();
if (!(i instanceof InvokeStatic))
{
continue;
}
if (((InvokeStatic) i).getMethod().equals(fillRectangle))
{
int indexToReturnTo = it.nextIndex();
count++;
it.previous();
Instruction current = it.previous();
if (current instanceof LDC && ((LDC) current).getConstantAsInt() == 0)
{
int varIdx = 0;
for (; ;)
{
current = it.previous();
if (current instanceof ILoad && ((ILoad) current).getVariableIndex() == 3 - varIdx)
{
varIdx++;
log.debug(varIdx + " we can count yay");
continue;
}
break;
}
if (varIdx == 4)
{
for (; !(current instanceof InvokeStatic); )
{
current = it.next();
}
assert it.nextIndex() == indexToReturnTo;
it.set(new InvokeStatic(ins, clearBuffer));
replaced++;
log.debug("Found drawRectangle at {}. Found: {}, replaced {}", m.getName(), count, replaced);
}
else
{
log.debug("Welp, guess this wasn't it chief " + m);
}
}
while (it.nextIndex() != indexToReturnTo)
{
it.next();
}
}
}
}
}
for (Instruction i : insList)
{
Instruction invoke = new InvokeStatic(ins, clearBuffer);
ins.replace(i, invoke);
}
}
private Method findStaticMethod(String name) throws InjectionException

View File

@@ -1736,7 +1736,7 @@ public final class Client extends GameShell implements Usernamed {
class214.__hf_u = null;
}
class13.method163();
class13.playPcmPlayers();
class171.method3498();
MouseHandler var47 = MouseHandler.MouseHandler_instance;
synchronized(MouseHandler.MouseHandler_instance) {
@@ -1820,7 +1820,7 @@ public final class Client extends GameShell implements Usernamed {
class68.drawLoadingMessage("Loading - please wait." + "<br>" + " (" + 100 + "%" + ")", true);
}
class13.method163();
class13.playPcmPlayers();
class65.scene.clear();
for(var48 = 0; var48 < 4; ++var48) {
@@ -1836,7 +1836,7 @@ public final class Client extends GameShell implements Usernamed {
}
}
class13.method163();
class13.playPcmPlayers();
Tiles.Tiles_minPlane = 99;
Tiles.__bq_w = new byte[4][104][104];
Fonts.__kz_o = new byte[4][104][104];
@@ -1874,7 +1874,7 @@ public final class Client extends GameShell implements Usernamed {
var5 = (class308.regions[var49] & 255) * 64 - GraphicsObject.baseY;
var6 = class40.regionLandArchives[var49];
if(var6 != null) {
class13.method163();
class13.playPcmPlayers();
Varcs.method2166(var6, var4, var5, GameObject.__eh_fy * 8 - 48, WorldMapLabelSize.__s_fi * 8 - 48, collisionMaps);
}
}
@@ -1884,7 +1884,7 @@ public final class Client extends GameShell implements Usernamed {
var5 = (class308.regions[var49] & 255) * 64 - GraphicsObject.baseY;
var6 = class40.regionLandArchives[var49];
if(var6 == null && WorldMapLabelSize.__s_fi < 800) {
class13.method163();
class13.playPcmPlayers();
UserComparator6.method3390(var4, var5, 64, 64);
}
}
@@ -1896,7 +1896,7 @@ public final class Client extends GameShell implements Usernamed {
if(var50 != null) {
var5 = (class308.regions[var49] >> 8) * 64 - class50.baseX;
var51 = (class308.regions[var49] & 255) * 64 - GraphicsObject.baseY;
class13.method163();
class13.playPcmPlayers();
Scene var7 = class65.scene;
CollisionMap[] var8 = collisionMaps;
Buffer var9 = new Buffer(var50);
@@ -1971,7 +1971,7 @@ public final class Client extends GameShell implements Usernamed {
break label1186;
}
class13.method163();
class13.playPcmPlayers();
for(var4 = 0; var4 < 13; ++var4) {
for(var5 = 0; var5 < 13; ++var5) {
@@ -1997,7 +1997,7 @@ public final class Client extends GameShell implements Usernamed {
}
}
class13.method163();
class13.playPcmPlayers();
for(var4 = 0; var4 < 13; ++var4) {
for(var5 = 0; var5 < 13; ++var5) {
@@ -2058,7 +2058,7 @@ public final class Client extends GameShell implements Usernamed {
}
UserComparator10.method3352(true);
class13.method163();
class13.playPcmPlayers();
Scene var65 = class65.scene;
CollisionMap[] var71 = collisionMaps;
@@ -2548,7 +2548,7 @@ public final class Client extends GameShell implements Usernamed {
}
}
class13.method163();
class13.playPcmPlayers();
ScriptEvent.method1179();
ObjectDefinition.__jr_o.clear();
PacketBufferNode var67;
@@ -2575,7 +2575,7 @@ public final class Client extends GameShell implements Usernamed {
}
GameShell.updateGameState(30);
class13.method163();
class13.playPcmPlayers();
BufferedSink.method3603();
var67 = Interpreter.method1915(ClientPacket.__gs_bv, packetWriter.isaacCipher);
packetWriter.__q_167(var67);

View File

@@ -265,7 +265,7 @@ public class MouseRecorder implements Runnable {
garbageValue = "-335916694"
)
static final void method1189(Widget var0, int var1, int var2, int var3) {
class13.method163();
class13.playPcmPlayers();
SpriteMask var4 = var0.getSpriteMask(false);
if(var4 != null) {
Rasterizer2D.Rasterizer2D_setClip(var1, var2, var4.width + var1, var2 + var4.height);

View File

@@ -37,7 +37,7 @@ public class UserComparator10 extends AbstractUserComparator {
garbageValue = "653874364"
)
static final void method3352(boolean var0) {
class13.method163();
class13.playPcmPlayers();
++Client.packetWriter.__d;
if(Client.packetWriter.__d >= 50 || var0) {
Client.packetWriter.__d = 0;

View File

@@ -35,7 +35,8 @@ public class class13 {
signature = "(B)V",
garbageValue = "63"
)
static final void method163() {
@Export("playPcmPlayers")
static final void playPcmPlayers() {
if(AbstractIndexCache.pcmPlayer1 != null) {
AbstractIndexCache.pcmPlayer1.run();
}

View File

@@ -835,14 +835,14 @@ public class class40 {
ViewportMouse.ViewportMouse_entityCount = 0;
}
class13.method163();
class13.playPcmPlayers();
Rasterizer2D.Rasterizer2D_fillRectangle(var0, var1, var2, var3, 0);
class13.method163();
class13.playPcmPlayers();
var12 = Rasterizer3D.Rasterizer3D_zoom;
Rasterizer3D.Rasterizer3D_zoom = Client.viewportZoom;
class65.scene.draw(WorldMapSection1.cameraX, GrandExchangeEvents.cameraY, class11.cameraZ, WorldMapIcon1.cameraPitch, MusicPatchNode.cameraYaw, var4);
Rasterizer3D.Rasterizer3D_zoom = var12;
class13.method163();
class13.playPcmPlayers();
class65.scene.clearTempGameObjects();
UrlRequester.method3258(var0, var1, var2, var3);
UnitPriceComparator.method136(var0, var1);