Skip to content

Commit

Permalink
project(injector): Add back swapMenuEntries
Browse files Browse the repository at this point in the history
  • Loading branch information
Owain94 committed May 11, 2022
1 parent 7f25d14 commit 6923493
Showing 1 changed file with 30 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,21 @@
package com.openosrs.injector.injectors.raw;

//import com.openosrs.injector.InjectUtil;
import com.openosrs.injector.InjectUtil;
import com.openosrs.injector.injection.InjectData;
import com.openosrs.injector.injectors.AbstractInjector;
import java.util.List;
import java.util.ListIterator;
import net.runelite.asm.ClassFile;
import net.runelite.asm.Field;
import net.runelite.asm.Method;
import net.runelite.asm.attributes.Code;
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.BAStore;
import net.runelite.asm.attributes.code.instructions.Dup;
import net.runelite.asm.attributes.code.instructions.GetStatic;
import net.runelite.asm.attributes.code.instructions.ILoad;
import net.runelite.asm.attributes.code.instructions.InvokeSpecial;
import net.runelite.asm.attributes.code.instructions.InvokeStatic;
Expand All @@ -40,7 +43,7 @@ public void inject()
{
addInvoke("newRuneliteMenuEntry", true);
addInvoke("newBareRuneliteMenuEntry", false);
//addSwap(InjectUtil.findMethod(inject, "incrementMenuEntries"));
addSwap(InjectUtil.findMethod(inject, "menu"), InjectUtil.findField(inject, "menuShiftClick", "Client"));
}

private void addInvoke(String methodName, boolean iload)
Expand Down Expand Up @@ -75,7 +78,7 @@ private void addInvoke(String methodName, boolean iload)
ins.add(new Return(instructions, InstructionType.ARETURN));
}

private void addSwap(Method method)
private void addSwap(Method method, Field field)
{
final ClassFile clientVanilla = inject.toVanilla(
inject.getDeobfuscated()
Expand All @@ -84,22 +87,40 @@ private void addSwap(Method method)

Instructions ins = method.getCode().getInstructions();
ListIterator<Instruction> iterator = ins.getInstructions().listIterator();

int found = 0;

while (iterator.hasNext())
{
Instruction i = iterator.next();

if (!(i instanceof BAStore))
if (found < 4)
{
continue;
if (!(i instanceof GetStatic))
{
continue;
}

if (((GetStatic) i).getField().getName().equals(field.getName()))
{
found += 1;
}
}
else
{
if (!(i instanceof BAStore))
{
continue;
}

ILoad i1 = new ILoad(ins, 2);
InvokeStatic i2 = new InvokeStatic(ins, new net.runelite.asm.pool.Method(clientVanilla.getPoolClass(), "swapMenuEntries", new Signature("(I)V")));
ILoad i1 = new ILoad(ins, 3);
InvokeStatic i2 = new InvokeStatic(ins, new net.runelite.asm.pool.Method(clientVanilla.getPoolClass(), "swapMenuEntries", new Signature("(I)V")));

iterator.add(i1);
iterator.add(i2);
iterator.add(i1);
iterator.add(i2);

return;
return;
}
}
}
}

0 comments on commit 6923493

Please sign in to comment.