project: Support for creating a bare MenuEntry

This commit is contained in:
Owain van Brakel
2021-12-17 11:44:13 +01:00
parent 939a3bac5e
commit 99802813b3
4 changed files with 69 additions and 0 deletions

View File

@@ -39,6 +39,7 @@ public class RuneliteMenuEntry extends AbstractInjector
public void inject()
{
addInvoke();
addInvokeBare();
addSwap(InjectUtil.findMethod(inject, "incrementMenuEntries"));
addSwap(InjectUtil.findMethod(inject, "decrementMenuEntries"));
}
@@ -69,6 +70,31 @@ public class RuneliteMenuEntry extends AbstractInjector
ins.add(new Return(instructions, InstructionType.ARETURN));
}
private void addInvokeBare()
{
ClassFile runeliteMenuEntryVanilla = inject.vanilla.findClass(RUNELITE_MENU_ENTRY);
final ClassFile clientVanilla = inject.toVanilla(
inject.getDeobfuscated()
.findClass("Client")
);
Method copy = clientVanilla.findMethod("newBareRuneliteMenuEntry");
copy.setPublic();
final Code code = new Code(copy);
code.setMaxStack(3);
copy.setCode(code);
final Instructions instructions = code.getInstructions();
final List<Instruction> ins = instructions.getInstructions();
ins.add(new New(instructions, runeliteMenuEntryVanilla.getPoolClass()));
ins.add(new Dup(instructions));
ins.add(new InvokeSpecial(instructions, new net.runelite.asm.pool.Method(runeliteMenuEntryVanilla.getPoolClass(), "<init>", new Signature("()V"))));
ins.add(new Return(instructions, InstructionType.ARETURN));
}
private void addSwap(Method method)
{
final ClassFile clientVanilla = inject.toVanilla(