Skip to content

Commit

Permalink
Fix crash on startup because AppleCore broke its own rules
Browse files Browse the repository at this point in the history
Player was null in GetMaxHunger hooks in injected FoodStats constructor cause I'm a dumb

Closes #125, closes #126
  • Loading branch information
squeek502 committed Jun 12, 2018
1 parent bc0022c commit 0647c9f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions java/squeek/applecore/asm/module/ModuleFoodStats.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,14 @@ public void injectFoodStatsConstructor(ClassNode classNode)
MethodNode constructor = new MethodNode(ACC_PUBLIC, "<init>", ASMHelper.toMethodDescriptor("V", ASMConstants.PLAYER), null, null);
constructor.instructions = ASMHelper.cloneInsnList(defaultConstructor.instructions);

AbstractInsnNode targetNode = ASMHelper.findLastInstructionWithOpcode(constructor, RETURN);
AbstractInsnNode targetNode = ASMHelper.findFirstInstructionWithOpcode(constructor, INVOKESPECIAL);

InsnList toInject = new InsnList();
toInject.add(new VarInsnNode(ALOAD, 0)); // this
toInject.add(new VarInsnNode(ALOAD, 1)); // player param
toInject.add(new FieldInsnNode(PUTFIELD, classNode.name, foodStatsPlayerField, ASMHelper.toDescriptor(ASMConstants.PLAYER)));

constructor.instructions.insertBefore(targetNode, toInject);
constructor.instructions.insert(targetNode, toInject);

classNode.methods.add(constructor);
}
Expand Down

0 comments on commit 0647c9f

Please sign in to comment.