diff options
author | alemidev <me@alemi.dev> | 2023-02-07 01:52:48 +0100 |
---|---|---|
committer | alemidev <me@alemi.dev> | 2023-02-07 01:52:48 +0100 |
commit | d5ed8e251810d43884f332fc13597cad66064398 (patch) | |
tree | 17d380b8d423b70ef22f5360b1af369adee57a3f /src/main | |
parent | 9821169333f0fcfe7a23179906270668700a382d (diff) |
build: removed asm patching and moved asm patches
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/bscv/asm/BoSCoVicinoLoader.java | 111 | ||||
-rw-r--r-- | src/main/java/bscv/asm/api/IInjector.java | 56 | ||||
-rw-r--r-- | src/main/java/bscv/patches/TestPatch.java (renamed from src/main/java/bscv/asm/patches/TestPatch.java) | 2 | ||||
-rw-r--r-- | src/main/resources/META-INF/services/cpw.mods.modlauncher.serviceapi.ILaunchPluginService | 1 | ||||
-rw-r--r-- | src/main/resources/META-INF/services/ftbsc.lll.IInjector (renamed from src/main/resources/META-INF/services/bscv.asm.api.IInjector) | 0 |
5 files changed, 1 insertions, 169 deletions
diff --git a/src/main/java/bscv/asm/BoSCoVicinoLoader.java b/src/main/java/bscv/asm/BoSCoVicinoLoader.java deleted file mode 100644 index 4adc22b..0000000 --- a/src/main/java/bscv/asm/BoSCoVicinoLoader.java +++ /dev/null @@ -1,111 +0,0 @@ -package bscv.asm; - -import bscv.asm.api.IInjector; -import cpw.mods.modlauncher.serviceapi.ILaunchPluginService; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.objectweb.asm.Type; -import org.objectweb.asm.tree.ClassNode; -import org.objectweb.asm.tree.MethodNode; - -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.EnumSet; -import java.util.List; -import java.util.Map; -import java.util.ServiceLoader; -import java.util.stream.Collectors; - -public class BoSCoVicinoLoader implements ILaunchPluginService { - public static final Logger LOGGER = LogManager.getLogger("BoSCoVicino-ASM"); - public static final String NAME = "boscovicino_asm"; //TODO: temp name - - private List<IInjector> injectors = new ArrayList<>(); - - public BoSCoVicinoLoader() { - LOGGER.info("BoSCoVicino ASM Patcher instantiated"); - } - - @Override - public String name() { - return NAME; - } - - - // Load mods requesting patches from resources - - @Override - public void offerResource(Path resource, String name) { - LOGGER.warn(String.format("Resource offered to us: %s @ '%s'", name, resource.toString())); - } - - @Override - public void addResources(List<Map.Entry<String, Path>> resources) { - LOGGER.info("Resources being added:"); - for (Map.Entry<String, Path> row : resources) { - LOGGER.info(String.format("> %s @ '%s'", row.getKey(), row.getValue().toString())); - try { - URL jarUrl = new URL("file:" + row.getValue().toString()); - URLClassLoader loader = new URLClassLoader(new URL[] { jarUrl }); - for (IInjector inj : ServiceLoader.load(IInjector.class, loader)) { - LOGGER.info(String.format("Registering injector %s", inj.name())); - this.injectors.add(inj); - } - } catch (MalformedURLException e) { - LOGGER.error(String.format("Malformed URL for resource %s - 'file:%s'", row.getKey(), row.getValue().toString())); - } - } - } - - - // Filter only classes we need to patch - - @Override - public EnumSet<Phase> handlesClass(Type classType, final boolean isEmpty) { - throw new IllegalStateException("Outdated ModLauncher"); //mixin does it - } - - private static final EnumSet<Phase> YAY = EnumSet.of(Phase.BEFORE); - private static final EnumSet<Phase> NAY = EnumSet.noneOf(Phase.class); - - @Override - public EnumSet<Phase> handlesClass(Type classType, final boolean isEmpty, final String reason) { - if (isEmpty) return NAY; - // TODO can I make a set of target classes to make this faster - for (IInjector inj : this.injectors) { - if (inj.targetClass().equals(classType.getClassName())) - return YAY; - } - return NAY; - } - - - // Process classes and inject methods - - @Override - public int processClassWithFlags(Phase phase, ClassNode classNode, Type classType, String reason) { - LOGGER.debug("Processing class {} in phase {} of {}", classType.getClassName(), phase.name(), reason); - List<IInjector> relevantInjectors = this.injectors.stream() - .filter(i -> i.targetClass().equals(classType.getClassName())) - .collect(Collectors.toList()); - boolean modified = false; - for (MethodNode method : classNode.methods) { - for (IInjector inj : relevantInjectors) { - if ( - inj.methodName().equals(method.name) && - inj.methodDesc().equals(method.desc) - ) { - LOGGER.info(String.format("Patching %s.%s with %s", classType.getClassName(), method.name, inj.name())); - inj.inject(classNode, method); // TODO catch patching exceptions - modified = true; - } - } - } - - return modified ? ComputeFlags.COMPUTE_FRAMES : ComputeFlags.NO_REWRITE; - } -} - diff --git a/src/main/java/bscv/asm/api/IInjector.java b/src/main/java/bscv/asm/api/IInjector.java deleted file mode 100644 index d02ddaa..0000000 --- a/src/main/java/bscv/asm/api/IInjector.java +++ /dev/null @@ -1,56 +0,0 @@ -package bscv.asm.api; - -import org.objectweb.asm.tree.ClassNode; -import org.objectweb.asm.tree.MethodNode; - -public interface IInjector { - - /** - * @return name of injector, for logging - */ - String name(); - - /** - * @return reason for patching for this injector, for loggin - */ - default String reason() { return ""; } - - /** - * This is used by the Launch Plugin to identify which classes should be - * altered, and on which classes this injector should operate. - * - * Class name should be dot-separated, for example "net.minecraft.client.Minecraft" - * - * @return target class to operate onto - */ - String targetClass(); - - /** - * This is used by the Launch Plugin to identify which methods to provide - * to this injector for patching. It should return the Searge name of wanted function. - * example: "func_71407_l", which is "tick()" on "Minecraft" class in 1.16.5 - * - * @return target method name to operate onto - */ - String methodName(); - - /** - * This is used by the Launch Plugin to identify which methods to provide - * to this injector for patching. It should return the method descriptor, with - * parameters and return types. example: "()V" for void parameters and return. - * - * TODO better example... - * - * @return target method name to operate onto - */ - String methodDesc(); - - /** - * Once the Launch Plugin has identified classes and methods for injectors, - * this method will be called providing the correct class and method nodes for patching. - * - * @param clazz class node which is being patched - * @param method main method node of requested function for patching - */ - void inject(ClassNode clazz, MethodNode method); -} diff --git a/src/main/java/bscv/asm/patches/TestPatch.java b/src/main/java/bscv/patches/TestPatch.java index 3d1a9a2..381ee48 100644 --- a/src/main/java/bscv/asm/patches/TestPatch.java +++ b/src/main/java/bscv/patches/TestPatch.java @@ -6,7 +6,7 @@ import org.objectweb.asm.tree.InsnList; import org.objectweb.asm.tree.InsnNode; import org.objectweb.asm.tree.MethodNode; -import bscv.asm.api.IInjector; +import ftbsc.lll.IInjector; /** * When working as intended, this patch will crash the game diff --git a/src/main/resources/META-INF/services/cpw.mods.modlauncher.serviceapi.ILaunchPluginService b/src/main/resources/META-INF/services/cpw.mods.modlauncher.serviceapi.ILaunchPluginService deleted file mode 100644 index da2569c..0000000 --- a/src/main/resources/META-INF/services/cpw.mods.modlauncher.serviceapi.ILaunchPluginService +++ /dev/null @@ -1 +0,0 @@ -bscv.asm.BoSCoVicinoLoader diff --git a/src/main/resources/META-INF/services/bscv.asm.api.IInjector b/src/main/resources/META-INF/services/ftbsc.lll.IInjector index 076ba1a..076ba1a 100644 --- a/src/main/resources/META-INF/services/bscv.asm.api.IInjector +++ b/src/main/resources/META-INF/services/ftbsc.lll.IInjector |