Skip to content

Commit

Permalink
Harden bank UI drawing hook (#200)
Browse files Browse the repository at this point in the history
  • Loading branch information
conker-rsc authored May 9, 2024
1 parent c62bb53 commit af1058f
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 1 deletion.
67 changes: 67 additions & 0 deletions src/Client/JClassPatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -1738,6 +1738,25 @@ private void patchClient(ClassNode node) {
}
}
}

// reset bank drawn flag
insnNodeList = methodNode.instructions.iterator();
while (insnNodeList.hasNext()) {
AbstractInsnNode insnNode = insnNodeList.next();

if (insnNode.getOpcode() == Opcodes.PUTFIELD
&& ((FieldInsnNode) insnNode).owner.equals("client")
&& ((FieldInsnNode) insnNode).name.equals("Fe")
&& ((FieldInsnNode) insnNode).desc.equals("Z")) {
insnNode = insnNode.getNext();
methodNode.instructions.insertBefore(insnNode, new InsnNode(Opcodes.ICONST_0));
methodNode.instructions.insertBefore(
insnNode,
new FieldInsnNode(Opcodes.PUTSTATIC, "Game/Client", "bank_interface_drawn", "Z"));

break;
}
}
}

if (methodNode.name.equals("a")
Expand Down Expand Up @@ -4758,6 +4777,54 @@ else if (pos == 1) {
}
}

// draw bank interface
if (methodNode.name.equals("r") && methodNode.desc.equals("(I)V")) {
Iterator<AbstractInsnNode> insnNodeList = methodNode.instructions.iterator();
while (insnNodeList.hasNext()) {
AbstractInsnNode insnNode = insnNodeList.next();

// reset bank drawn flag
if (insnNode.getOpcode() == Opcodes.PUTFIELD
&& ((FieldInsnNode) insnNode).owner.equals("client")
&& ((FieldInsnNode) insnNode).name.equals("Fe")
&& ((FieldInsnNode) insnNode).desc.equals("Z")) {
insnNode = insnNode.getNext();
methodNode.instructions.insertBefore(insnNode, new InsnNode(Opcodes.ICONST_0));
methodNode.instructions.insertBefore(
insnNode,
new FieldInsnNode(Opcodes.PUTSTATIC, "Game/Client", "bank_interface_drawn", "Z"));

break;
}
}

// set bank drawn flag
insnNodeList = methodNode.instructions.iterator();
while (insnNodeList.hasNext()) {
AbstractInsnNode insnNode = insnNodeList.next();
if (insnNode.getOpcode() == Opcodes.INVOKEVIRTUAL
&& ((MethodInsnNode) insnNode).owner.equals("ba")
&& ((MethodInsnNode) insnNode).name.equals("b")
&& ((MethodInsnNode) insnNode).desc.equals("(IIIIB)V")) {
insnNode = insnNodeList.next();

LabelNode skipLabel = new LabelNode();
methodNode.instructions.insertBefore(
insnNode,
new FieldInsnNode(Opcodes.GETSTATIC, "Game/Client", "bank_interface_drawn", "Z"));
methodNode.instructions.insertBefore(
insnNode, new JumpInsnNode(Opcodes.IFGT, skipLabel));
methodNode.instructions.insertBefore(insnNode, new InsnNode(Opcodes.ICONST_1));
methodNode.instructions.insertBefore(
insnNode,
new FieldInsnNode(Opcodes.PUTSTATIC, "Game/Client", "bank_interface_drawn", "Z"));
methodNode.instructions.insertBefore(insnNode, skipLabel);

break;
}
}
}

// hookTracer(node, methodNode);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Game/Bank.java
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ public static String importBankCsv(File file) {

// Draws extra buttons on the side of the bank to control filtering
public static void drawBankAugmentations(Graphics2D g2, BufferedMouseClick bufferedMouseClick) {
if (Client.show_bank) {
if (Client.bank_interface_drawn) {
if (Settings.SORT_FILTER_BANK.get(Settings.currentProfile)) {
// existing bank interface dimensions
int bankWidth = 408;
Expand Down
4 changes: 4 additions & 0 deletions src/Game/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ public class Client {
public static int combat_timer;
public static boolean isGameLoaded;
public static boolean show_bank;
public static boolean bank_interface_drawn;
public static boolean show_duel;
public static boolean show_duelconfirm;
public static int show_friends;
Expand Down Expand Up @@ -1509,6 +1510,9 @@ public static boolean gameOpcodeReceivedHook(int opcode, int psize) {
// sleep exit packet, restore whatever was in pm
pm_enteredText = pm_enteredTextCopy;
pm_enteredTextCopy = "";
} else if (opcode == 203) {
// bank close packet
bank_interface_drawn = false;
}

if (Bank.processPacket(opcode, psize)) {
Expand Down

0 comments on commit af1058f

Please sign in to comment.