From 45e36f71d9765de2b73dd2d9bf9451c308ecf953 Mon Sep 17 00:00:00 2001 From: kappa_maintainer Date: Tue, 9 Jan 2024 11:53:16 +0800 Subject: [PATCH] Add patch to Advanced Rocketry --- README.md | 1 + gradle.properties | 2 +- .../com/cleanroommc/FugueLoadingPlugin.java | 4 +- .../mixin/charset/ColorspacesMixin.java | 4 -- .../ClassTransformerTransformer.java | 62 +++++++++++++++++++ 5 files changed, 67 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/cleanroommc/transformer/ClassTransformerTransformer.java diff --git a/README.md b/README.md index 926f047..005b700 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ Also check [The Fugue Plane](https://forgottenrealms.fandom.com/wiki/Fugue_Plane * Snow! Real Magic * Botania Tweaks * Aqua Acrobatics +* Advanced Rocketry ## Note Add ! to start of the file name to fix Lag Goggles. \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 10fb7e3..215b460 100644 --- a/gradle.properties +++ b/gradle.properties @@ -16,7 +16,7 @@ mappings_version=39-1.12 mod_id=fugue mod_name=Fugue mod_main_class=Fugue -mod_version=0.3.0 +mod_version=0.3.1 mod_base_package=com.cleanroommc.fugue mod_authors=kappa_maintainer mod_description=A mod that patch dead mods for Cleanroom diff --git a/src/main/java/com/cleanroommc/FugueLoadingPlugin.java b/src/main/java/com/cleanroommc/FugueLoadingPlugin.java index 9d216d8..cb14f89 100644 --- a/src/main/java/com/cleanroommc/FugueLoadingPlugin.java +++ b/src/main/java/com/cleanroommc/FugueLoadingPlugin.java @@ -14,6 +14,7 @@ public class FugueLoadingPlugin implements IFMLLoadingPlugin, IEarlyMixinLoader static { Launch.classLoader.addTransformerExclusionFilter("com.github.terminatornl.laggoggles."); Launch.classLoader.addTransformerExclusionFilter("quaternary.botaniatweaks."); + Launch.classLoader.addTransformerExclusionFilter("zmaster587.advancedRocketry.asm."); Launch.classLoader.registerTransformer("com.cleanroommc.transformer.InitializerTransformer"); } @@ -22,7 +23,8 @@ public String[] getASMTransformerClass() { return new String[]{ "com.cleanroommc.transformer.EnderCoreTransformerTransformer", - "com.cleanroommc.transformer.InitializerTransformer" + "com.cleanroommc.transformer.InitializerTransformer", + "com.cleanroommc.transformer.ClassTransformerTransformer" }; } diff --git a/src/main/java/com/cleanroommc/mixin/charset/ColorspacesMixin.java b/src/main/java/com/cleanroommc/mixin/charset/ColorspacesMixin.java index d9c5785..85e8936 100644 --- a/src/main/java/com/cleanroommc/mixin/charset/ColorspacesMixin.java +++ b/src/main/java/com/cleanroommc/mixin/charset/ColorspacesMixin.java @@ -3,15 +3,12 @@ import com.google.common.collect.Table; import com.google.common.graph.ValueGraph; import com.llamalad7.mixinextras.sugar.Local; -import org.checkerframework.checker.units.qual.A; import org.objectweb.asm.Opcodes; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import pl.asie.charset.lib.loader.ModuleLoader; import pl.asie.charset.lib.utils.colorspace.Colorspace; import pl.asie.charset.lib.utils.colorspace.Colorspaces; @@ -23,7 +20,6 @@ public class ColorspacesMixin { @Shadow private static Table> conversionTable; @Inject(method = "buildConversionTable", at = @At(value = "JUMP", opcode = Opcodes.IF_ICMPGE, ordinal = 3), cancellable = true) - @SuppressWarnings("uncheck") private static void buildConversionTable(ValueGraph> conversionGraph, CallbackInfo ci, @Local(ordinal = 3) Colorspace[] path, diff --git a/src/main/java/com/cleanroommc/transformer/ClassTransformerTransformer.java b/src/main/java/com/cleanroommc/transformer/ClassTransformerTransformer.java new file mode 100644 index 0000000..27ccc23 --- /dev/null +++ b/src/main/java/com/cleanroommc/transformer/ClassTransformerTransformer.java @@ -0,0 +1,62 @@ +package com.cleanroommc.transformer; + +import net.minecraft.launchwrapper.IClassTransformer; +import org.objectweb.asm.ClassReader; +import org.objectweb.asm.ClassWriter; +import org.objectweb.asm.Opcodes; +import org.objectweb.asm.tree.*; + +public class ClassTransformerTransformer implements IClassTransformer { + private static boolean hit = false; + @Override + public byte[] transform(String s, String s1, byte[] bytes) { + if (bytes == null) + { + return null; + } + + if (hit || !s1.equals("zmaster587.advancedRocketry.asm.ClassTransformer")) + { + return bytes; + } + + + ClassNode classNode = new ClassNode(); + ClassReader classReader = new ClassReader(bytes); + classReader.accept(classNode, 0); + boolean modified = false; + AbstractInsnNode prevLine = null; + if (classNode.methods != null) + { + for (MethodNode methodNode : classNode.methods) + { + if (methodNode.name.equals("transform")) { + InsnList instructions = methodNode.instructions; + if (instructions != null) + { + for (AbstractInsnNode insnNode : instructions) + { + if (insnNode instanceof LineNumberNode lineNumberNode) + { + if (lineNumberNode.line == 693) { + instructions.remove(instructions.get(instructions.indexOf(lineNumberNode) + 1)); + instructions.insert(lineNumberNode, new InsnNode(Opcodes.ICONST_0)); + modified = true; + } + } + } + } + } + } + } + if (modified) + { + hit = true; + ClassWriter classWriter = new ClassWriter(0); + + classNode.accept(classWriter); + return classWriter.toByteArray(); + } + return bytes; + } +}