From 42543dc388c81d9f6cd133e2052820cd53c6b7b8 Mon Sep 17 00:00:00 2001 From: FalsePattern <30945458+FalsePattern@users.noreply.github.com> Date: Tue, 23 Aug 2022 21:18:43 +0200 Subject: [PATCH] mixin fix attempt --- .../internal/asm/IMixinPluginTransformer.java | 26 +++++------- .../falsepattern/lib/mixin/IMixinPlugin.java | 12 +----- .../spongepowered/asm/lib/tree/ClassNode.java | 25 ----------- .../extensibility/IMixinConfigPlugin.java | 41 +++++++++++++++++++ 4 files changed, 52 insertions(+), 52 deletions(-) delete mode 100644 src/main/java/com/falsepattern/lib/mixin/stubpackage/org/spongepowered/asm/lib/tree/ClassNode.java create mode 100644 src/main/java/com/falsepattern/lib/mixin/stubpackage/org/spongepowered/asm/mixin/extensibility/IMixinConfigPlugin.java diff --git a/src/main/java/com/falsepattern/lib/internal/asm/IMixinPluginTransformer.java b/src/main/java/com/falsepattern/lib/internal/asm/IMixinPluginTransformer.java index 8501480..d31a10c 100644 --- a/src/main/java/com/falsepattern/lib/internal/asm/IMixinPluginTransformer.java +++ b/src/main/java/com/falsepattern/lib/internal/asm/IMixinPluginTransformer.java @@ -26,9 +26,6 @@ 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.ArrayList; public class IMixinPluginTransformer implements IClassNodeTransformer { @Override @@ -44,21 +41,18 @@ public class IMixinPluginTransformer implements IClassNodeTransformer { @Override public void transform(ClassNode cn, String transformedName, boolean obfuscated) { val methods = cn.methods; - val remove = new ArrayList(); - String name; if (!MixinInfo.isMixinBooterLegacy()) { - FPTransformer.LOG.info("Could not detect MixinBooterLegacy. Removing MBL compat code."); - name = "org/spongepowered/libraries/org/objectweb/asm/tree/ClassNode"; - } else { - FPTransformer.LOG.info("Detected MixinBooterLegacy. Removing SpongeMixins compat code."); - name = "org/spongepowered/asm/lib/tree/ClassNode"; - } - for (val method: methods) { - if ((method.name.equals("preApply") || method.name.equals("postApply")) && - method.desc.contains(name)) { - remove.add(method); + 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"); + } + } } } - methods.removeAll(remove); } } diff --git a/src/main/java/com/falsepattern/lib/mixin/IMixinPlugin.java b/src/main/java/com/falsepattern/lib/mixin/IMixinPlugin.java index f1e8f51..441abda 100644 --- a/src/main/java/com/falsepattern/lib/mixin/IMixinPlugin.java +++ b/src/main/java/com/falsepattern/lib/mixin/IMixinPlugin.java @@ -21,11 +21,11 @@ package com.falsepattern.lib.mixin; import com.falsepattern.lib.StableAPI; +import com.falsepattern.lib.mixin.stubpackage.org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; import com.falsepattern.lib.util.FileUtil; import lombok.val; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; import org.spongepowered.asm.mixin.extensibility.IMixinInfo; import org.spongepowered.libraries.org.objectweb.asm.tree.ClassNode; @@ -157,14 +157,4 @@ public interface IMixinPlugin extends IMixinConfigPlugin { default void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { } - - @StableAPI.Expose(since = "__INTERNAL__") - default void preApply(String targetClassName, com.falsepattern.lib.mixin.stubpackage.org.spongepowered.asm.lib.tree.ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { - - } - - @StableAPI.Expose(since = "__INTERNAL__") - default void postApply(String targetClassName, com.falsepattern.lib.mixin.stubpackage.org.spongepowered.asm.lib.tree.ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { - - } } diff --git a/src/main/java/com/falsepattern/lib/mixin/stubpackage/org/spongepowered/asm/lib/tree/ClassNode.java b/src/main/java/com/falsepattern/lib/mixin/stubpackage/org/spongepowered/asm/lib/tree/ClassNode.java deleted file mode 100644 index be22876..0000000 --- a/src/main/java/com/falsepattern/lib/mixin/stubpackage/org/spongepowered/asm/lib/tree/ClassNode.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (C) 2022 FalsePattern - * All Rights Reserved - * - * The above copyright notice, this permission notice and the word "SNEED" - * shall be included in all copies or substantial portions of the Software. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package com.falsepattern.lib.mixin.stubpackage.org.spongepowered.asm.lib.tree; - -public class ClassNode { -} diff --git a/src/main/java/com/falsepattern/lib/mixin/stubpackage/org/spongepowered/asm/mixin/extensibility/IMixinConfigPlugin.java b/src/main/java/com/falsepattern/lib/mixin/stubpackage/org/spongepowered/asm/mixin/extensibility/IMixinConfigPlugin.java new file mode 100644 index 0000000..450441f --- /dev/null +++ b/src/main/java/com/falsepattern/lib/mixin/stubpackage/org/spongepowered/asm/mixin/extensibility/IMixinConfigPlugin.java @@ -0,0 +1,41 @@ +/* + * This file is part of Mixin, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package com.falsepattern.lib.mixin.stubpackage.org.spongepowered.asm.mixin.extensibility; + +import java.util.List; +import java.util.Set; + +import org.spongepowered.asm.mixin.extensibility.IMixinInfo; +import org.spongepowered.libraries.org.objectweb.asm.tree.ClassNode; + +public interface IMixinConfigPlugin { + void onLoad(String mixinPackage); + String getRefMapperConfig(); + boolean shouldApplyMixin(String targetClassName, String mixinClassName); + void acceptTargets(Set myTargets, Set otherTargets); + List getMixins(); + void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo); + void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo); +}