Make sure we get all fillRectangles for clearColorBuffer
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user