project: Support for creating a bare MenuEntry
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user