Skip to content

Commit

Permalink
Add dropt patch
Browse files Browse the repository at this point in the history
  • Loading branch information
kappa-maintainer committed Sep 13, 2024
1 parent 81b1bc0 commit 32c6435
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ public class FugueLoadingPlugin implements IFMLLoadingPlugin {
"cc.polyfrost.oneconfig.loader.OneConfigLoader"
);
}
if (FugueConfig.modPatchConfig.enableDropt) {
TransformerDelegate.registerExplicitTransformerByInstance(new ValidatorAdapterFactoryTransformer(), "com.codetaylor.mc.dropt.modules.dropt.rule.RuleLoader$ValidatorAdapterFactory");
}
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 @@ -114,4 +114,6 @@ public class ModPatchConfig {
public boolean enableCrossbow = true;
@Config.Name("Enable Patch to PolyForst mods")
public boolean enablePolyForst = true;
@Config.Name("Enable Dropt Patch")
public boolean enableDropt = true;
}
4 changes: 4 additions & 0 deletions src/main/java/com/cleanroommc/fugue/helper/HookHelper.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.cleanroommc.fugue.helper;

import com.cleanroommc.fugue.common.Fugue;
import com.google.gson.Gson;
import com.google.gson.TypeAdapter;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.reflect.TypeToken;
import net.minecraft.launchwrapper.IClassTransformer;
import net.minecraft.launchwrapper.Launch;
import net.minecraft.launchwrapper.LaunchClassLoader;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.cleanroommc.fugue.transformer;

import com.cleanroommc.fugue.common.Fugue;
import javassist.ClassPool;
import javassist.CtClass;
import top.outlands.foundation.IExplicitTransformer;

import java.io.ByteArrayInputStream;

public class ValidatorAdapterFactoryTransformer implements IExplicitTransformer {
@Override
public byte[] transform(byte[] bytes) {
try {
CtClass cc = ClassPool.getDefault().makeClass(new ByteArrayInputStream(bytes));
cc.getDeclaredMethod("create").setBody("{return $1.getDelegateAdapter($0, $2);}");
bytes = cc.toBytecode();
} catch (Throwable t) {
Fugue.LOGGER.error("Exception {} on {}", t, this.getClass().getSimpleName());
}
return bytes;
}
}

0 comments on commit 32c6435

Please sign in to comment.