From d5ed8e251810d43884f332fc13597cad66064398 Mon Sep 17 00:00:00 2001 From: alemidev Date: Tue, 7 Feb 2023 01:52:48 +0100 Subject: build: removed asm patching and moved asm patches --- build.gradle | 5 + src/main/java/bscv/asm/BoSCoVicinoLoader.java | 111 --------------------- src/main/java/bscv/asm/api/IInjector.java | 56 ----------- src/main/java/bscv/asm/patches/TestPatch.java | 51 ---------- src/main/java/bscv/patches/TestPatch.java | 51 ++++++++++ .../META-INF/services/bscv.asm.api.IInjector | 2 - ...ods.modlauncher.serviceapi.ILaunchPluginService | 1 - .../META-INF/services/ftbsc.lll.IInjector | 2 + 8 files changed, 58 insertions(+), 221 deletions(-) delete mode 100644 src/main/java/bscv/asm/BoSCoVicinoLoader.java delete mode 100644 src/main/java/bscv/asm/api/IInjector.java delete mode 100644 src/main/java/bscv/asm/patches/TestPatch.java create mode 100644 src/main/java/bscv/patches/TestPatch.java delete mode 100644 src/main/resources/META-INF/services/bscv.asm.api.IInjector delete mode 100644 src/main/resources/META-INF/services/cpw.mods.modlauncher.serviceapi.ILaunchPluginService create mode 100644 src/main/resources/META-INF/services/ftbsc.lll.IInjector diff --git a/build.gradle b/build.gradle index a29d2f8..822c884 100644 --- a/build.gradle +++ b/build.gradle @@ -9,6 +9,10 @@ buildscript { } } +repositories { + maven { url = 'https://maven.fantabos.co' } +} + apply plugin: 'net.minecraftforge.gradle' apply plugin: 'eclipse' apply plugin: 'maven-publish' @@ -82,6 +86,7 @@ sourceSets.main.resources { srcDir 'src/generated/resources' } dependencies { minecraft "net.minecraftforge:forge:${minecraftVersion}-${forgeVersion}" + implementation 'ftbsc:lll:0.0.3' } jar { 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 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> resources) { - LOGGER.info("Resources being added:"); - for (Map.Entry 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 handlesClass(Type classType, final boolean isEmpty) { - throw new IllegalStateException("Outdated ModLauncher"); //mixin does it - } - - private static final EnumSet YAY = EnumSet.of(Phase.BEFORE); - private static final EnumSet NAY = EnumSet.noneOf(Phase.class); - - @Override - public EnumSet 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 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/asm/patches/TestPatch.java deleted file mode 100644 index 3d1a9a2..0000000 --- a/src/main/java/bscv/asm/patches/TestPatch.java +++ /dev/null @@ -1,51 +0,0 @@ -package bscv.asm.patches; - -import org.objectweb.asm.Opcodes; -import org.objectweb.asm.tree.ClassNode; -import org.objectweb.asm.tree.InsnList; -import org.objectweb.asm.tree.InsnNode; -import org.objectweb.asm.tree.MethodNode; - -import bscv.asm.api.IInjector; - -/** - * When working as intended, this patch will crash the game - * as soon it finished loading with a NegativeArraySizeException. - */ -public class TestPatch { - - public static class FramerateFix implements IInjector, Opcodes { - public String name() { return "FramerateFix"; } - public String targetClass() { return "net.minecraft.client.Minecraft"; } - public String methodName() { return "func_213243_aC"; } // getFramerateLimit() - public String methodDesc() { return "()I"; } - - public void inject(ClassNode clazz, MethodNode main) { - InsnList insnList = new InsnList(); - insnList.add(new InsnNode(POP)); - main.instructions.insert(insnList); - } - } - - - public static class TickPatch implements IInjector, Opcodes { - public String name() { return "TickPatch"; } - public String targetClass() { return "net.minecraft.client.Minecraft"; } - public String methodName() { return "func_71407_l"; } // tick() - public String methodDesc() { return "()V"; } - - public void inject(ClassNode clazz, MethodNode main) { - InsnList insnList = new InsnList(); - insnList.add(new InsnNode(POP)); - insnList.add(new InsnNode(POP)); - insnList.add(new InsnNode(POP)); - insnList.add(new InsnNode(POP)); - insnList.add(new InsnNode(POP)); - insnList.add(new InsnNode(POP)); - insnList.add(new InsnNode(POP)); - insnList.add(new InsnNode(POP)); - main.instructions.insert(insnList); - } - } - -} diff --git a/src/main/java/bscv/patches/TestPatch.java b/src/main/java/bscv/patches/TestPatch.java new file mode 100644 index 0000000..381ee48 --- /dev/null +++ b/src/main/java/bscv/patches/TestPatch.java @@ -0,0 +1,51 @@ +package bscv.asm.patches; + +import org.objectweb.asm.Opcodes; +import org.objectweb.asm.tree.ClassNode; +import org.objectweb.asm.tree.InsnList; +import org.objectweb.asm.tree.InsnNode; +import org.objectweb.asm.tree.MethodNode; + +import ftbsc.lll.IInjector; + +/** + * When working as intended, this patch will crash the game + * as soon it finished loading with a NegativeArraySizeException. + */ +public class TestPatch { + + public static class FramerateFix implements IInjector, Opcodes { + public String name() { return "FramerateFix"; } + public String targetClass() { return "net.minecraft.client.Minecraft"; } + public String methodName() { return "func_213243_aC"; } // getFramerateLimit() + public String methodDesc() { return "()I"; } + + public void inject(ClassNode clazz, MethodNode main) { + InsnList insnList = new InsnList(); + insnList.add(new InsnNode(POP)); + main.instructions.insert(insnList); + } + } + + + public static class TickPatch implements IInjector, Opcodes { + public String name() { return "TickPatch"; } + public String targetClass() { return "net.minecraft.client.Minecraft"; } + public String methodName() { return "func_71407_l"; } // tick() + public String methodDesc() { return "()V"; } + + public void inject(ClassNode clazz, MethodNode main) { + InsnList insnList = new InsnList(); + insnList.add(new InsnNode(POP)); + insnList.add(new InsnNode(POP)); + insnList.add(new InsnNode(POP)); + insnList.add(new InsnNode(POP)); + insnList.add(new InsnNode(POP)); + insnList.add(new InsnNode(POP)); + insnList.add(new InsnNode(POP)); + insnList.add(new InsnNode(POP)); + main.instructions.insert(insnList); + } + } + +} diff --git a/src/main/resources/META-INF/services/bscv.asm.api.IInjector b/src/main/resources/META-INF/services/bscv.asm.api.IInjector deleted file mode 100644 index 076ba1a..0000000 --- a/src/main/resources/META-INF/services/bscv.asm.api.IInjector +++ /dev/null @@ -1,2 +0,0 @@ -bscv.asm.patches.TestPatch$FramerateFix -bscv.asm.patches.TestPatch$TickPatch 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/ftbsc.lll.IInjector b/src/main/resources/META-INF/services/ftbsc.lll.IInjector new file mode 100644 index 0000000..076ba1a --- /dev/null +++ b/src/main/resources/META-INF/services/ftbsc.lll.IInjector @@ -0,0 +1,2 @@ +bscv.asm.patches.TestPatch$FramerateFix +bscv.asm.patches.TestPatch$TickPatch -- cgit v1.2.3-56-ga3b1