From 2dd69e08daab99241b874ff378bf53b5edf9c614 Mon Sep 17 00:00:00 2001 From: ZekerZhayard Date: Wed, 2 Sep 2020 12:30:25 +0800 Subject: [PATCH] Fix InvalidMixinException before 1.15-snapshot. (#115) --- Fabric/resource/fabric.mod.json | 5 +- Fabric/resource/mixins.customskinloader.json | 1 + .../fabric/MixinConfigPlugin.java | 81 +++++++++++++++++++ 3 files changed, 83 insertions(+), 4 deletions(-) create mode 100644 Fabric/source/customskinloader/fabric/MixinConfigPlugin.java diff --git a/Fabric/resource/fabric.mod.json b/Fabric/resource/fabric.mod.json index b7f2ec7..fb43bb6 100644 --- a/Fabric/resource/fabric.mod.json +++ b/Fabric/resource/fabric.mod.json @@ -15,9 +15,6 @@ "environment": "client", "mixins": [ - { - "config": "mixins.customskinloader.json", - "environment": "client" - } + "mixins.customskinloader.json" ] } diff --git a/Fabric/resource/mixins.customskinloader.json b/Fabric/resource/mixins.customskinloader.json index d1a4822..5219b7e 100644 --- a/Fabric/resource/mixins.customskinloader.json +++ b/Fabric/resource/mixins.customskinloader.json @@ -10,6 +10,7 @@ "MixinTileEntitySkull" ], "refmap": "mixins.customskinloader.refmap.json", + "plugin": "customskinloader.fabric.MixinConfigPlugin", "injectors": { "defaultRequire": 1 } diff --git a/Fabric/source/customskinloader/fabric/MixinConfigPlugin.java b/Fabric/source/customskinloader/fabric/MixinConfigPlugin.java new file mode 100644 index 0000000..d140868 --- /dev/null +++ b/Fabric/source/customskinloader/fabric/MixinConfigPlugin.java @@ -0,0 +1,81 @@ +package customskinloader.fabric; + +import java.io.IOException; +import java.io.InputStream; +import java.util.List; +import java.util.Set; + +import org.apache.commons.io.IOUtils; +import org.objectweb.asm.ClassReader; +import org.objectweb.asm.Type; +import org.objectweb.asm.tree.ClassNode; +import org.objectweb.asm.tree.FieldNode; +import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; +import org.spongepowered.asm.mixin.extensibility.IMixinInfo; + +public class MixinConfigPlugin implements IMixinConfigPlugin { + @Override + public void onLoad(String mixinPackage) { + + } + + @Override + public String getRefMapperConfig() { + return null; + } + + @Override + public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { + if (!mixinClassName.equals("customskinloader.mixin.MixinThreadDownloadImageData")) { + return true; + } + + // ProcessTask didn't exist in ThreadDownloadImageData before 1.15-snapshot, Mixin shouldn't apply this. + try (InputStream is = this.getClass().getResourceAsStream("/" + targetClassName.replace(".", "/") + ".class")) { + if (is == null) { + return true; + } + ClassNode cn = new ClassNode(); + new ClassReader(IOUtils.toByteArray(is)).accept(cn, 0); + for (FieldNode fn : cn.fields) { + if (fn.desc.equals(Type.getDescriptor(Runnable.class))) { + return true; + } + } + return false; + } catch (IOException e) { + e.printStackTrace(); + } + return true; + } + + @Override + public void acceptTargets(Set myTargets, Set otherTargets) { + + } + + @Override + public List getMixins() { + return null; + } + + @Override + public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { + + } + + @Override + public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { + + } + + // To be compatible with 0.7.11 + public void preApply(String targetClassName, org.spongepowered.asm.lib.tree.ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { + + } + + // To be compatible with 0.7.11 + public void postApply(String targetClassName, org.spongepowered.asm.lib.tree.ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { + + } +}