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(

View File

@@ -643,6 +643,12 @@ public interface Client extends GameEngine
*/
MenuEntry createMenuEntry(int idx);
/**
* Create a new menu entry
* @return the newly created menu entry
*/
MenuEntry createMenuEntry(String option, String target, int identifier, int opcode, int param1, int param2);
/**
* Gets an array of currently open right-click menu entries that can be
* clicked and activated.

View File

@@ -796,12 +796,35 @@ public abstract class RSClientMixin implements RSClient
setChatCycle(getCycleCntr());
}
@Inject
public static RSRuneLiteMenuEntry newBareRuneliteMenuEntry()
{
return null;
}
@Inject
public static RSRuneLiteMenuEntry newRuneliteMenuEntry(int idx)
{
return null;
}
@Inject
@Override
public MenuEntry createMenuEntry(String option, String target, int identifier, int opcode, int param1, int param2)
{
RSRuneLiteMenuEntry menuEntry = newBareRuneliteMenuEntry();
menuEntry.setOption(option);
menuEntry.setTarget(target);
menuEntry.setIdentifier(identifier);
menuEntry.setType(MenuAction.of(opcode));
menuEntry.setParam0(param1);
menuEntry.setParam1(param2);
menuEntry.setConsumer(null);
return menuEntry;
}
@Inject
@Override
public MenuEntry createMenuEntry(int idx)

View File

@@ -7,11 +7,25 @@ public class RuneLiteMenuEntry implements MenuEntry
public Consumer consumer;
public int idx;
public RuneLiteMenuEntry()
{
}
public RuneLiteMenuEntry(int idx)
{
this.idx = idx;
}
public void test(int idx)
{
new RuneLiteMenuEntry(idx);
}
public void test2()
{
new RuneLiteMenuEntry();
}
public Consumer getConsumer()
{
return consumer;