Merge pull request #5 from open-osrs/weird-entityhider-bug

This commit is contained in:
Owain van Brakel
2020-05-02 15:39:20 +02:00
committed by GitHub
3 changed files with 60 additions and 12 deletions

View File

@@ -18,7 +18,7 @@ plugins {
val oprsver = "3.3.1" val oprsver = "3.3.1"
group = "com.openosrs" group = "com.openosrs"
version = "1.1.0" version = "1.1.1"
repositories { repositories {
mavenCentral() mavenCentral()

View File

@@ -17,7 +17,7 @@ import com.openosrs.injector.injectors.RSApiInjector;
import com.openosrs.injector.injectors.raw.ClearColorBuffer; import com.openosrs.injector.injectors.raw.ClearColorBuffer;
import com.openosrs.injector.injectors.raw.DrawAfterWidgets; import com.openosrs.injector.injectors.raw.DrawAfterWidgets;
import com.openosrs.injector.injectors.raw.DrawMenu; import com.openosrs.injector.injectors.raw.DrawMenu;
import com.openosrs.injector.injectors.raw.HidePlayerAttacks; import com.openosrs.injector.injectors.raw.AddPlayerToMenu;
import com.openosrs.injector.injectors.raw.Occluder; import com.openosrs.injector.injectors.raw.Occluder;
import com.openosrs.injector.injectors.raw.RasterizerAlpha; import com.openosrs.injector.injectors.raw.RasterizerAlpha;
import com.openosrs.injector.injectors.raw.RenderDraw; import com.openosrs.injector.injectors.raw.RenderDraw;
@@ -77,7 +77,7 @@ public class Injection extends InjectData implements InjectTaskHandler
inject(new DrawMenu(this)); inject(new DrawMenu(this));
inject(new HidePlayerAttacks(this)); inject(new AddPlayerToMenu(this));
validate(new InjectorValidator(this)); validate(new InjectorValidator(this));

View File

@@ -1,5 +1,6 @@
/* /*
* Copyright (c) 2019, Lucas <https://github.com/Lucwousin> * Copyright (c) 2019, Lucas <https://github.com/Lucwousin>
* Copyright (c) 2020, ThatGamerBlue <https://github.com/ThatGamerBlue>
* All rights reserved. * All rights reserved.
* *
* This code is licensed under GPL3, see the complete license in * This code is licensed under GPL3, see the complete license in
@@ -11,10 +12,13 @@ import com.openosrs.injector.InjectUtil;
import com.openosrs.injector.Injexception; import com.openosrs.injector.Injexception;
import com.openosrs.injector.injection.InjectData; import com.openosrs.injector.injection.InjectData;
import com.openosrs.injector.injectors.AbstractInjector; import com.openosrs.injector.injectors.AbstractInjector;
import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
import java.util.ListIterator; import java.util.ListIterator;
import net.runelite.asm.Method; import net.runelite.asm.Method;
import net.runelite.asm.attributes.code.Instruction; import net.runelite.asm.attributes.code.Instruction;
import net.runelite.asm.attributes.code.InstructionType;
import net.runelite.asm.attributes.code.Instructions; import net.runelite.asm.attributes.code.Instructions;
import net.runelite.asm.attributes.code.Label; import net.runelite.asm.attributes.code.Label;
import net.runelite.asm.attributes.code.instruction.types.ComparisonInstruction; import net.runelite.asm.attributes.code.instruction.types.ComparisonInstruction;
@@ -28,11 +32,13 @@ import net.runelite.asm.attributes.code.instructions.IfACmpNe;
import net.runelite.asm.attributes.code.instructions.IfICmpNe; import net.runelite.asm.attributes.code.instructions.IfICmpNe;
import net.runelite.asm.attributes.code.instructions.IfNe; import net.runelite.asm.attributes.code.instructions.IfNe;
import net.runelite.asm.attributes.code.instructions.InvokeStatic; import net.runelite.asm.attributes.code.instructions.InvokeStatic;
import net.runelite.asm.attributes.code.instructions.LDC;
import net.runelite.asm.attributes.code.instructions.Return;
import net.runelite.asm.pool.Field; import net.runelite.asm.pool.Field;
public class HidePlayerAttacks extends AbstractInjector public class AddPlayerToMenu extends AbstractInjector
{ {
public HidePlayerAttacks(InjectData inject) public AddPlayerToMenu(InjectData inject)
{ {
super(inject); super(inject);
} }
@@ -40,22 +46,57 @@ public class HidePlayerAttacks extends AbstractInjector
public void inject() throws Injexception public void inject() throws Injexception
{ {
final Method addPlayerOptions = InjectUtil.findMethod(inject, "addPlayerToMenu"); final Method addPlayerOptions = InjectUtil.findMethod(inject, "addPlayerToMenu");
final net.runelite.asm.pool.Method shouldHideAttackOptionFor = inject.getVanilla().findClass("client").findMethod("shouldHideAttackOptionFor").getPoolMethod(); final net.runelite.asm.pool.Method shouldHideAttackOptionFor =
inject.getVanilla().findClass("client").findMethod("shouldHideAttackOptionFor").getPoolMethod();
final net.runelite.asm.pool.Method shouldDrawMethod =
inject.getVanilla().findStaticMethod("shouldDraw").getPoolMethod();
try try
{ {
injectSameTileFix(addPlayerOptions, shouldDrawMethod);
injectHideAttack(addPlayerOptions, shouldHideAttackOptionFor); injectHideAttack(addPlayerOptions, shouldHideAttackOptionFor);
injectHideCast(addPlayerOptions, shouldHideAttackOptionFor); injectHideCast(addPlayerOptions, shouldHideAttackOptionFor);
} }
catch (Injexception | AssertionError e) catch (Injexception | AssertionError e)
{ {
log.warn("HidePlayerAttacks failed, but as this doesn't mess up anything other than that functionality, we're carrying on", e); log.warn(
"HidePlayerAttacks failed, but as this doesn't mess up anything other than that functionality, we're carrying on",
e);
} }
} }
private void injectHideAttack(Method addPlayerOptions, net.runelite.asm.pool.Method shouldHideAttackOptionFor) throws Injexception private void injectSameTileFix(Method addPlayerOptions, net.runelite.asm.pool.Method shouldDrawMethod)
{ {
final Field AttackOption_hidden = InjectUtil.findField(inject, "AttackOption_hidden", "AttackOption").getPoolField(); // ALOAD 0
// ICONST_0
// INVOKESTATIC Scene.shouldDraw
// IFNE CONTINUE_LABEL if returned true then jump to continue
// RETURN
// CONTINUE_LABEL
// REST OF METHOD GOES HERE
Instructions insns = addPlayerOptions.getCode().getInstructions();
Label CONTINUE_LABEL = new Label(insns);
List<Instruction> prependList = new ArrayList<>()
{{
add(new ALoad(insns, 0));
add(new LDC(insns, 0));
add(new InvokeStatic(insns, shouldDrawMethod));
add(new IfNe(insns, CONTINUE_LABEL));
add(new Return(insns, InstructionType.RETURN));
add(CONTINUE_LABEL);
}};
int i = 0;
for (Instruction instruction : prependList)
{
insns.addInstruction(i++, instruction);
}
}
private void injectHideAttack(Method addPlayerOptions, net.runelite.asm.pool.Method shouldHideAttackOptionFor)
throws Injexception
{
final Field AttackOption_hidden =
InjectUtil.findField(inject, "AttackOption_hidden", "AttackOption").getPoolField();
final Field attackOption = InjectUtil.findField(inject, "playerAttackOption", "Client").getPoolField(); final Field attackOption = InjectUtil.findField(inject, "playerAttackOption", "Client").getPoolField();
// GETSTATIC GETSTATIC // GETSTATIC GETSTATIC
@@ -143,7 +184,8 @@ public class HidePlayerAttacks extends AbstractInjector
ins.addInstruction(injectIdx, i3); ins.addInstruction(injectIdx, i3);
} }
private void injectHideCast(Method addPlayerOptions, net.runelite.asm.pool.Method shouldHideAttackOptionFor) throws Injexception private void injectHideCast(Method addPlayerOptions, net.runelite.asm.pool.Method shouldHideAttackOptionFor)
throws Injexception
{ {
// LABEL before // LABEL before
// BIPUSH 8 // BIPUSH 8
@@ -176,10 +218,17 @@ public class HidePlayerAttacks extends AbstractInjector
if ((i instanceof BiPush) && (byte) ((BiPush) i).getConstant() == 8) if ((i instanceof BiPush) && (byte) ((BiPush) i).getConstant() == 8)
{ {
if (!b1) if (!b1)
{
b1 = true; b1 = true;
}
else if (!b2) else if (!b2)
{
b2 = true; b2 = true;
else throw new Injexception("3 bipushes? fucking mental, Hide spells failed btw"); }
else
{
throw new Injexception("3 bipushes? fucking mental, Hide spells failed btw");
}
continue; continue;
} }
@@ -196,7 +245,6 @@ public class HidePlayerAttacks extends AbstractInjector
continue; continue;
} }
if (!(i instanceof JumpingInstruction)) if (!(i instanceof JumpingInstruction))
{ {
if (b1 && b2 && iAnd && getstatic) if (b1 && b2 && iAnd && getstatic)