mirror of
https://github.com/FalsePattern/FalsePatternLib.git
synced 2026-11-15 19:34:44 +00:00
mixinbooter compat
This commit is contained in:
12 files changed
+196
-47
No files matched your search
@@ -24,7 +24,7 @@ import com.falsepattern.lib.StableAPI;
|
||||
import com.falsepattern.lib.asm.exceptions.AsmClassNotFoundException;
|
||||
import com.falsepattern.lib.asm.exceptions.AsmFieldNotFoundException;
|
||||
import com.falsepattern.lib.asm.exceptions.AsmMethodNotFoundException;
|
||||
import com.falsepattern.lib.internal.CoreLoadingPlugin;
|
||||
import com.falsepattern.lib.internal.asm.CoreLoadingPlugin;
|
||||
import com.falsepattern.lib.mapping.MappingManager;
|
||||
import com.falsepattern.lib.mapping.types.MappingType;
|
||||
import com.falsepattern.lib.mapping.types.NameType;
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
package com.falsepattern.lib.asm;
|
||||
|
||||
import com.falsepattern.lib.StableAPI;
|
||||
import com.falsepattern.lib.internal.CoreLoadingPlugin;
|
||||
import com.falsepattern.lib.internal.asm.CoreLoadingPlugin;
|
||||
import lombok.val;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.objectweb.asm.ClassReader;
|
||||
|
||||
+5
-2
@@ -18,8 +18,10 @@
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.falsepattern.lib.internal;
|
||||
package com.falsepattern.lib.internal.asm;
|
||||
|
||||
import com.falsepattern.lib.internal.Tags;
|
||||
import com.falsepattern.lib.internal.asm.FPTransformer;
|
||||
import lombok.Getter;
|
||||
import lombok.val;
|
||||
|
||||
@@ -36,6 +38,7 @@ import java.util.Map;
|
||||
@MCVersion("1.7.10")
|
||||
@Name(Tags.MODID)
|
||||
@SortingIndex(500)
|
||||
@IFMLLoadingPlugin.TransformerExclusions({Tags.GROUPNAME + ".internal.asm", Tags.GROUPNAME + ".asm"})
|
||||
public class CoreLoadingPlugin implements IFMLLoadingPlugin {
|
||||
@Getter
|
||||
private static boolean obfuscated;
|
||||
@@ -101,7 +104,7 @@ public class CoreLoadingPlugin implements IFMLLoadingPlugin {
|
||||
|
||||
@Override
|
||||
public String[] getASMTransformerClass() {
|
||||
return null;
|
||||
return new String[]{Tags.GROUPNAME + ".internal.asm.FPTransformer"};
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.falsepattern.lib.internal.asm;
|
||||
|
||||
import com.falsepattern.lib.StableAPI;
|
||||
import com.falsepattern.lib.asm.IClassNodeTransformer;
|
||||
import com.falsepattern.lib.asm.SmartTransformer;
|
||||
import com.falsepattern.lib.internal.Tags;
|
||||
import lombok.Getter;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@Accessors(fluent = true)
|
||||
@StableAPI(since = "__INTERNAL__")
|
||||
public class FPTransformer implements SmartTransformer {
|
||||
@Getter
|
||||
private final List<IClassNodeTransformer> transformers;
|
||||
|
||||
@Getter
|
||||
private final Logger logger = LogManager.getLogger(Tags.MODNAME + " ASM");
|
||||
|
||||
public FPTransformer() {
|
||||
boolean obsolete;
|
||||
try {
|
||||
Class.forName("io.github.tox1cozz.mixinbooterlegacy.MixinBooterLegacyPlugin");
|
||||
logger.info("Detected MixinBooter Legacy.");
|
||||
obsolete = false;
|
||||
} catch (ClassNotFoundException e) {
|
||||
logger.info("Detected SpongeMixins or Grimoire. Applying legacy compat fix to IMixinPlugin.");
|
||||
obsolete = true;
|
||||
}
|
||||
transformers = Collections.singletonList(new IMixinPluginTransformer(obsolete));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.falsepattern.lib.internal.asm;
|
||||
|
||||
import com.falsepattern.lib.asm.IClassNodeTransformer;
|
||||
import com.falsepattern.lib.internal.Tags;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.val;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class IMixinPluginTransformer implements IClassNodeTransformer {
|
||||
private final boolean obsolete;
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "IMixinPluginTransformer";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldTransform(ClassNode cn, String transformedName, boolean obfuscated) {
|
||||
return transformedName.equals(Tags.GROUPNAME + ".mixin.IMixinPlugin");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transform(ClassNode cn, String transformedName, boolean obfuscated) {
|
||||
val methods = cn.methods;
|
||||
val remove = new ArrayList<MethodNode>();
|
||||
if (obsolete) {
|
||||
for (val method : methods) {
|
||||
if (method.name.equals("preApply") || method.name.equals("postApply")) {
|
||||
remove.add(method);
|
||||
}
|
||||
}
|
||||
methods.removeAll(remove);
|
||||
for (val method : methods) {
|
||||
if (method.name.equals("preApply_obsolete") || method.name.equals("postApply_obsolete")) {
|
||||
method.name = method.name.substring(0, method.name.indexOf('_'));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (val method : methods) {
|
||||
if (method.name.equals("preApply_obsolete") || method.name.equals("postApply_obsolete")) {
|
||||
remove.add(method);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@ import com.falsepattern.lib.StableAPI;
|
||||
import com.falsepattern.lib.dependencies.DependencyLoader;
|
||||
import com.falsepattern.lib.dependencies.Library;
|
||||
import com.falsepattern.lib.dependencies.SemanticVersion;
|
||||
import com.falsepattern.lib.internal.CoreLoadingPlugin;
|
||||
import com.falsepattern.lib.internal.asm.CoreLoadingPlugin;
|
||||
import com.falsepattern.lib.mapping.storage.Lookup;
|
||||
import com.falsepattern.lib.mapping.types.MappingType;
|
||||
import com.falsepattern.lib.mapping.types.NameType;
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
package com.falsepattern.lib.mapping.types;
|
||||
|
||||
import com.falsepattern.lib.StableAPI;
|
||||
import com.falsepattern.lib.internal.CoreLoadingPlugin;
|
||||
import com.falsepattern.lib.internal.asm.CoreLoadingPlugin;
|
||||
import com.falsepattern.lib.mapping.storage.Lookup;
|
||||
import com.falsepattern.lib.mapping.storage.MappedString;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@@ -73,26 +73,31 @@ public interface IMixinPlugin extends IMixinConfigPlugin {
|
||||
ITargetedMod[] getTargetedModEnumValues();
|
||||
|
||||
@Override
|
||||
@StableAPI.Expose(since = "__INTERNAL__")
|
||||
default void onLoad(String mixinPackage) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@StableAPI.Expose(since = "__INTERNAL__")
|
||||
default String getRefMapperConfig() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@StableAPI.Expose(since = "__INTERNAL__")
|
||||
default boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@StableAPI.Expose(since = "__INTERNAL__")
|
||||
default void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@StableAPI.Expose(since = "__INTERNAL__")
|
||||
default List<String> getMixins() {
|
||||
val isDevelopmentEnvironment = (boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment");
|
||||
val targetedMods = getTargetedModEnumValues();
|
||||
@@ -119,6 +124,7 @@ public interface IMixinPlugin extends IMixinConfigPlugin {
|
||||
return mixins;
|
||||
}
|
||||
|
||||
@StableAPI.Expose(since = "__INTERNAL__")
|
||||
default boolean loadJarOf(final ITargetedMod mod) {
|
||||
boolean success = false;
|
||||
try {
|
||||
@@ -140,13 +146,37 @@ public interface IMixinPlugin extends IMixinConfigPlugin {
|
||||
return success;
|
||||
}
|
||||
|
||||
@Override
|
||||
default void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
|
||||
/**
|
||||
* Fallback for spongemixins. Removed for mixinbooter
|
||||
*/
|
||||
@StableAPI.Expose(since = "__INTERNAL__")
|
||||
default void preApply_obsolete(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Fallback for spongemixins. Removed for mixinbooter
|
||||
*/
|
||||
@StableAPI.Expose(since = "__INTERNAL__")
|
||||
default void postApply_obsolete(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Regular behaviour for mixinbooter. Removed for spongemixins
|
||||
*/
|
||||
@Override
|
||||
default void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
|
||||
@StableAPI.Expose(since = "__INTERNAL__")
|
||||
default void preApply(String targetClassName, org.spongepowered.libraries.org.objectweb.asm.tree.ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Regular behaviour for mixinbooter. Removed for spongemixins
|
||||
*/
|
||||
@Override
|
||||
@StableAPI.Expose(since = "__INTERNAL__")
|
||||
default void postApply(String targetClassName, org.spongepowered.libraries.org.objectweb.asm.tree.ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user