Fix hiding player attacks in client, add option to hide cast as well (#896)

Tiny bit of refactoring as well
This commit is contained in:
Lucwousin
2019-07-05 23:10:02 +02:00
committed by Kyleeld
parent a8cf657e4c
commit 2367f7ee18
19 changed files with 187 additions and 69 deletions

View File

@@ -2,6 +2,7 @@ package net.runelite.injector.raw;
import com.google.common.base.Stopwatch;
import java.util.Iterator;
import java.util.ListIterator;
import net.runelite.asm.Method;
import net.runelite.asm.attributes.code.Instruction;
import net.runelite.asm.attributes.code.Instructions;
@@ -9,9 +10,12 @@ import net.runelite.asm.attributes.code.Label;
import net.runelite.asm.attributes.code.instruction.types.ComparisonInstruction;
import net.runelite.asm.attributes.code.instruction.types.JumpingInstruction;
import net.runelite.asm.attributes.code.instructions.ALoad;
import net.runelite.asm.attributes.code.instructions.BiPush;
import net.runelite.asm.attributes.code.instructions.GetStatic;
import net.runelite.asm.attributes.code.instructions.IAnd;
import net.runelite.asm.attributes.code.instructions.IfACmpEq;
import net.runelite.asm.attributes.code.instructions.IfACmpNe;
import net.runelite.asm.attributes.code.instructions.IfICmpNe;
import net.runelite.asm.attributes.code.instructions.IfNe;
import net.runelite.asm.attributes.code.instructions.InvokeStatic;
import net.runelite.asm.pool.Field;
@@ -31,14 +35,28 @@ public class HidePlayerAttacks
this.inject = inject;
}
private Method addPlayerOptions;
private net.runelite.asm.pool.Method shouldHideAttackOptionFor;
public void inject() throws InjectionException
{
Stopwatch stopwatch = Stopwatch.createStarted();
final Method addPlayerOptions = InjectUtil.findStaticMethod(inject, "addPlayerToMenu");
addPlayerOptions = InjectUtil.findStaticMethod(inject, "addPlayerToMenu");
shouldHideAttackOptionFor = inject.getVanilla().findClass("client").findMethod("shouldHideAttackOptionFor").getPoolMethod();
injectHideAttack();
injectHideCast();
stopwatch.stop();
log.info("HidePlayerAttacks took {}", stopwatch.toString());
}
private void injectHideAttack() throws InjectionException
{
final Field AttackOption_hidden = InjectUtil.findDeobField(inject, "AttackOption_hidden", "AttackOption").getPoolField();
final Field attackOption = InjectUtil.findDeobField(inject, "playerAttackOption", "Client").getPoolField();
final net.runelite.asm.pool.Method shouldHideAttackOptionFor = inject.getVanilla().findClass("client").findMethod("shouldHideAttackOptionFor").getPoolMethod();
// GETSTATIC GETSTATIC
// GETSTATIC GETSTATIC
@@ -123,9 +141,65 @@ public class HidePlayerAttacks
IfNe i3 = new IfNe(ins, label);
ins.addInstruction(injectIdx, i3);
}
stopwatch.stop();
private void injectHideCast() throws InjectionException
{
// LABEL before
// BIPUSH 8
// LDC (garbage)
// GETSTATIC selectedSpellFlags
// IMUL
// BIPUSH 8
// IAND
// IF_ICMPNE -> skip adding option
//
// <--- Inject call here
// <--- Inject comparison here (duh)
//
// add option n such
log.info("HidePlayerAttacks took {}", stopwatch.toString());
Instructions ins = addPlayerOptions.getCode().getInstructions();
ListIterator<Instruction> iterator = ins.getInstructions().listIterator();
while (iterator.hasNext())
{
Instruction i = iterator.next();
if (!(i instanceof BiPush) || (byte) ((BiPush) i).getConstant() != 8)
{
continue;
}
i = iterator.next();
while (!(i instanceof BiPush) || (byte) ((BiPush) i).getConstant() != 8)
{
i = iterator.next();
}
i = iterator.next();
if (!(i instanceof IAnd))
{
throw new InjectionException("Yikes I didn't expect this");
}
i = iterator.next();
if (!(i instanceof IfICmpNe))
{
throw new InjectionException("Yikes I didn't expect this");
}
Label target = ((IfICmpNe) i).getJumps().get(0);
// Load the player
ALoad i1 = new ALoad(ins, 0);
// Get the boolean
InvokeStatic i2 = new InvokeStatic(ins, shouldHideAttackOptionFor);
// Compare n such
IfNe i3 = new IfNe(ins, target);
iterator.add(i1);
iterator.add(i2);
iterator.add(i3);
return;
}
}
}