mirror of
https://github.com/FalsePattern/FalsePatternLib.git
synced 2026-11-11 19:37:34 +00:00
fix mixin plugin transformer again
This commit is contained in:
1 file changed
+41
-10
@@ -26,8 +26,16 @@ import com.falsepattern.lib.internal.Tags;
|
||||
import com.falsepattern.lib.mixin.MixinInfo;
|
||||
import lombok.val;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class IMixinPluginTransformer implements IClassNodeTransformer {
|
||||
private static final String CLASSNODE_MIXINBOOTER = "org/spongepowered/libraries/org/objectweb/asm/tree/ClassNode";
|
||||
private static final String CLASSNODE_SPONGEMIXINS = "org/spongepowered/asm/lib/tree/ClassNode";
|
||||
private static final String IMIXINPLUGIN = Tags.GROUPNAME + ".mixin.IMixinPlugin";
|
||||
private static final String IMIXINPLUGIN_INTERNAL = IMIXINPLUGIN.replace('.', '/');
|
||||
private static final String IMIXINCONFIGPLUGIN_INTERNAL = "org/spongepowered/asm/mixin/extensibility/IMixinConfigPlugin";
|
||||
@Override
|
||||
public String getName() {
|
||||
return "IMixinPluginTransformer";
|
||||
@@ -35,22 +43,45 @@ public class IMixinPluginTransformer implements IClassNodeTransformer {
|
||||
|
||||
@Override
|
||||
public boolean shouldTransform(ClassNode cn, String transformedName, boolean obfuscated) {
|
||||
return transformedName.equals(Tags.GROUPNAME + ".mixin.IMixinPlugin");
|
||||
return transformedName.equals(IMIXINPLUGIN) ||
|
||||
cn.interfaces.stream().anyMatch((i) -> i.equals(IMIXINPLUGIN_INTERNAL) || i.equals(IMIXINCONFIGPLUGIN_INTERNAL));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transform(ClassNode cn, String transformedName, boolean obfuscated) {
|
||||
val methods = cn.methods;
|
||||
if (transformedName.equals(IMIXINPLUGIN)) {
|
||||
transformIMixinPlugin(cn);
|
||||
} else {
|
||||
transformPlugin(cn, transformedName);
|
||||
}
|
||||
}
|
||||
|
||||
private static void transformIMixinPlugin(ClassNode cn) {
|
||||
if (!MixinInfo.isMixinBooterLegacy()) {
|
||||
FPTransformer.LOG.info("Could not detect MixinBooterLegacy. Converting IMixinPlugin to legacy compat mode.");
|
||||
for (val method : methods) {
|
||||
if (method.name.equals("preApply") || method.name.equals("postApply")) {
|
||||
method.desc = method.desc.replace("org/spongepowered/libraries/org/objectweb/asm/tree/ClassNode",
|
||||
"org/spongepowered/asm/lib/tree/ClassNode");
|
||||
for (val local: method.localVariables) {
|
||||
local.desc = local.desc.replace("org/spongepowered/libraries/org/objectweb/asm/tree/ClassNode",
|
||||
"org/spongepowered/asm/lib/tree/ClassNode");
|
||||
}
|
||||
doRename(cn.methods, CLASSNODE_MIXINBOOTER, CLASSNODE_SPONGEMIXINS);
|
||||
}
|
||||
}
|
||||
|
||||
private static void transformPlugin(ClassNode cn, String transformedName) {
|
||||
FPTransformer.LOG.info("Transforming " + transformedName + " to fit current mixin environment.");
|
||||
if (!MixinInfo.isMixinBooterLegacy()) {
|
||||
doRename(cn.methods, CLASSNODE_MIXINBOOTER, CLASSNODE_SPONGEMIXINS);
|
||||
} else {
|
||||
doRename(cn.methods, CLASSNODE_SPONGEMIXINS, CLASSNODE_MIXINBOOTER);
|
||||
}
|
||||
}
|
||||
|
||||
private static void doRename(List<MethodNode> methods, String from, String to) {
|
||||
for (val method : methods) {
|
||||
if (method.name.equals("preApply") || method.name.equals("postApply")) {
|
||||
val newDesc = method.desc.replace(from, to);
|
||||
if (!method.desc.equals(newDesc)) {
|
||||
FPTransformer.LOG.debug(method.name + method.desc + " -> " + method.name + newDesc);
|
||||
}
|
||||
method.desc = newDesc;
|
||||
for (val local: method.localVariables) {
|
||||
local.desc = local.desc.replace(from, to);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user