Skip to content

Commit

Permalink
Fix item patching when switching world types (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
conker-rsc authored May 9, 2024
1 parent af1058f commit 8880399
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Client/JClassPatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ private void patchGeneric(ClassNode node) {
"[Ljava/lang/String;");
hookStaticVariable(methodNode, "kb", "b", "[I", "Game/Item", "item_price", "[I");
hookStaticVariable(methodNode, "fa", "e", "[I", "Game/Item", "item_stackable", "[I");
hookStaticVariable(methodNode, "ka", "c", "[I", "Game/Item", "item_members", "[I");

hookConditionalClassVariable(
methodNode,
Expand Down
4 changes: 4 additions & 0 deletions src/Game/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -2356,6 +2356,10 @@ else if (soundBuf == null) {
// force re-render of game world terrain
lastHeightOffset = (planeIndex + 1) % 2;
}

// Re-patch item names
ItemNamePatch.reinit();
Item.repatchItemNames();
} catch (Exception e) {
}
}
Expand Down
17 changes: 16 additions & 1 deletion src/Game/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ public class Item {
public static String[] item_commands;
public static int[] item_price;
public static int[] item_stackable;
public static int[] item_members;
public static List<Item> cool_items = new ArrayList<>();

private static int name_patch_last = 0;
private static int name_patch_last = -1;

public static int[] groundItemX;
public static int[] groundItemY;
Expand Down Expand Up @@ -87,9 +88,23 @@ public static void patchItemNames() {
item_name = ItemNamePatch.item_name_patch3.clone();
break;
}

if (!Client.members) {
for (int i = 0; i < item_members.length; i++) {
if (item_members[i] == 1) {
item_name[i] = "Members object";
}
}
}

name_patch_last = namePatchType;
}

public static void repatchItemNames() {
name_patch_last = -1;
patchItemNames();
}

/**
* Patches discontinued edible item commands. Removes completely the option to eat or drink them
*/
Expand Down
5 changes: 5 additions & 0 deletions src/Game/ItemNamePatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -1000,4 +1000,9 @@ public static void init() {

initialized = true;
}

public static void reinit() {
initialized = false;
init();
}
}

0 comments on commit 8880399

Please sign in to comment.