Skip to content

Commit

Permalink
Add Colytra patch
Browse files Browse the repository at this point in the history
  • Loading branch information
kappa-maintainer committed Aug 17, 2024
1 parent 99c7b0a commit 5003f51
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ public class FugueLoadingPlugin implements IFMLLoadingPlugin {
"com.unascribed.ears.common.agent.mini.PatchContext$SearchResult"
);
}
if (FugueConfig.modPatchConfig.enableColytra && Launch.classLoader.isClassExist("c4.colytra.asm.ASMHooks")) {
TransformerDelegate.registerExplicitTransformerByInstance(new EntityLivingBaseTransformer(), "net.minecraft.entity.EntityLivingBase");
}
if (FugueConfig.getCodeSourcePatchTargets.length > 0) {
TransformerDelegate.registerExplicitTransformerByInstance(new ITweakerTransformer(), FugueConfig.getCodeSourcePatchTargets);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,6 @@ public class ModPatchConfig {
@Config.Name("Enable Ears Patch")
@Config.Comment("This mod is packing a copy of ASM itself")
public boolean enableEars = true;
@Config.Name("Enable Colytra Patch")
public boolean enableColytra = true;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.cleanroommc.fugue.transformer;

import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.*;
import top.outlands.foundation.IExplicitTransformer;

public class EntityLivingBaseTransformer implements IExplicitTransformer {
@Override
public byte[] transform(byte[] bytes) {
ClassNode classNode = new ClassNode();
ClassReader classReader = new ClassReader(bytes);
classReader.accept(classNode, 0);
if (classNode.methods != null)
{
out:
for (MethodNode methodNode : classNode.methods)
{
if (methodNode.name.equals("func_70636_d")) {
InsnList instructions = methodNode.instructions;
if (instructions != null)
{
for (AbstractInsnNode insnNode : instructions)
{
if (insnNode.getOpcode() == Opcodes.INVOKEVIRTUAL && insnNode instanceof MethodInsnNode methodInsnNode)
{
if (methodInsnNode.name.equals("func_184616_r"))
{
InsnList toInject = new InsnList();
toInject.add(new VarInsnNode(Opcodes.ALOAD, 0));
toInject.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "c4/colytra/asm/ASMHooks", "updateColytra", "(Lnet/minecraft/entity/EntityLivingBase;)V"));
methodNode.instructions.insert(methodInsnNode, toInject);
break out;
}
}
}
}
}
}
}
ClassWriter classWriter = new ClassWriter(0);

classNode.accept(classWriter);
return classWriter.toByteArray();
}
}

0 comments on commit 5003f51

Please sign in to comment.