Skip to content

Commit

Permalink
Fix ASM to place methods more appropriately
Browse files Browse the repository at this point in the history
  • Loading branch information
voidsong-dragonfly committed Mar 29, 2021
1 parent 6568951 commit bc1b6d1
Showing 1 changed file with 8 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -740,30 +740,23 @@ public byte[] transform(String name, String transformedName,
if(onUpdate != null) {
final InsnList nodeAdd = new InsnList();
AbstractInsnNode pos = null;
int numALoadsInARow = 0;
int firstALoadIndex = 0;
int lastReturnIndex = 0;
AbstractInsnNode ain;

for(int i = 0; i < onUpdate.instructions.size(); i++) {
for(int i = 0; i < onUpdate.instructions.size() ; i++) {
ain = onUpdate.instructions.get(i);
if(ain.getOpcode() == Opcodes.GETFIELD) {
if(numALoadsInARow == 0)
firstALoadIndex = i;
numALoadsInARow++;
if(numALoadsInARow == 4) {
break;
}
if(ain.getOpcode() == Opcodes.ALOAD) {
lastReturnIndex = i;

break;
}
else
numALoadsInARow = 0;
}
int i = firstALoadIndex;

pos = onUpdate.instructions.get(i);
pos = onUpdate.instructions.get(lastReturnIndex);

nodeAdd.add(new VarInsnNode(Opcodes.ALOAD, 0));
nodeAdd.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "zmaster587/advancedRocketry/util/GravityHandler", "applyGravity", "(L" + getName(CLASS_KEY_ENTITY) + ";)V", false));
onUpdate.instructions.insert(pos, nodeAdd);
onUpdate.instructions.insertBefore(pos, nodeAdd);
}

return finishInjection(cn);
Expand Down

0 comments on commit bc1b6d1

Please sign in to comment.