Skip to content

Commit

Permalink
ASM suggested by @brachy84
Browse files Browse the repository at this point in the history
  • Loading branch information
kappa-maintainer committed Aug 12, 2024
1 parent ee8f431 commit c273d54
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public class FugueLoadingPlugin implements IFMLLoadingPlugin {
if (FugueConfig.modPatchConfig.enableGroovyScript) {
//TransformerDelegate.registerExplicitTransformerByInstance(new GroovyClassLoaderTransformer(), "groovy.lang.GroovyClassLoader");

//TransformerDelegate.registerExplicitTransformerByInstance(new GroovyClassLoaderTransformer(), "groovy.lang.GroovyClassLoader");
TransformerDelegate.registerExplicitTransformerByInstance(new GroovyClassLoaderTransformer(), "groovy.lang.GroovyClassLoader");
//TransformerDelegate.registerExplicitTransformerByInstance(new ExceptionMessageTransformer(), "org.codehaus.groovy.control.messages.ExceptionMessage");
TransformerDelegate.registerExplicitTransformerByInstance(new GroovyRunnerRegistryTransformer(), "org.apache.groovy.plugin.GroovyRunnerRegistry");
TransformerDelegate.registerExplicitTransformerByInstance(new ASTTransformationCollectorCodeVisitorTransformer(), "org.codehaus.groovy.transform.ASTTransformationCollectorCodeVisitor");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import javassist.CtClass;
import javassist.expr.ExprEditor;
import javassist.expr.MethodCall;
import net.minecraft.launchwrapper.Launch;
import top.outlands.foundation.IExplicitTransformer;

import java.io.ByteArrayInputStream;
Expand All @@ -16,12 +15,12 @@ public class GroovyClassLoaderTransformer implements IExplicitTransformer {
public byte[] transform(byte[] bytes) {
try {
CtClass cc = ClassPool.getDefault().makeClass(new ByteArrayInputStream(bytes));
cc.getDeclaredMethod("access$400").instrument(new ExprEditor(){
cc.getDeclaredMethod("loadClass").instrument(new ExprEditor(){
@Override
public void edit(MethodCall m) throws CannotCompileException {
//Fugue.LOGGER.info("Transforming Groovy class method: {}", m.getMethodName());
if (m.getMethodName().equals("defineClass")) {
m.replace("$_ = com.cleanroommc.fugue.helper.HookHelper#defineClass($2, $3, $4, $5, $6);");
if (m.getMethodName().equals("loadClass")) {
m.replace("$_ = net.minecraft.launchwrapper.Launch#classLoader.loadClass($1);");
}
}
});
Expand Down

0 comments on commit c273d54

Please sign in to comment.