Skip to content

Commit

Permalink
Merge pull request #58 from jchung01/ar-reworked-compat
Browse files Browse the repository at this point in the history
Make AR transformer compatible with fork version
  • Loading branch information
kappa-maintainer authored Sep 27, 2024
2 parents 01b34d6 + ca832ae commit e8263ac
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
public class ModPatchConfig {
@Config.Name("Enable Ender Core Patch")
public boolean enableEnderCore = true;
@Config.Comment({
"This patch is only for Advanced Rocketry by zmaster587.",
"Advanced Rocketry - Reworked by MarvinEckhardt doesn't need this!"
})
@Config.Name("Enable Advanced Rocketry Patch")
public boolean enableAR = true;
@Config.Name("Enable Shoulder Surfing Reloaded Patch")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.cleanroommc.fugue.transformer;

import com.cleanroommc.fugue.common.Fugue;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Opcodes;
Expand All @@ -22,16 +23,46 @@ public byte[] transform(byte[] bytes) {
InsnList instructions = methodNode.instructions;
if (instructions != null)
{
for (AbstractInsnNode insnNode : instructions)
int fromIndex = 0;
int toIndex = 0;
for (int i = 0; i < instructions.size(); i++)
{
if (insnNode instanceof LineNumberNode lineNumberNode)
AbstractInsnNode insnNode = instructions.get(i);
// Find beginning of EntityPlayer patch block
if (insnNode.getOpcode() == Opcodes.LDC && ((LdcInsnNode) insnNode).cst.equals("net.minecraft.entity.player.EntityPlayer"))
{
if (lineNumberNode.line == 693) {
instructions.remove(instructions.get(instructions.indexOf(lineNumberNode) + 1));
instructions.insert(lineNumberNode, new InsnNode(Opcodes.ICONST_0));
fromIndex = i;
}
// Then find start of loop
else if (fromIndex > 0 && insnNode instanceof FrameNode)
{
toIndex = i;
break;
}
}
int constCounts = 0;
AbstractInsnNode targetNode = null;
// Now count number of ICONST opcodes
for (; fromIndex < toIndex; fromIndex++)
{
AbstractInsnNode insnNode = instructions.get(fromIndex);
if (insnNode.getOpcode() == Opcodes.ICONST_0 || insnNode.getOpcode() == Opcodes.ICONST_1)
{
if (targetNode == null)
{
targetNode = insnNode;
}
constCounts++;
}
}
Fugue.LOGGER.debug("Advanced Rocketry: Found {} ICONST invocations", constCounts);
// This is regular AR, patch
if (constCounts == 2)
{
instructions.insertBefore(targetNode, new InsnNode(Opcodes.ICONST_0));
instructions.remove(targetNode);
}
break;
}
}
}
Expand Down

0 comments on commit e8263ac

Please sign in to comment.