diff options
Diffstat (limited to 'src/main/java')
18 files changed, 474 insertions, 581 deletions
diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/ASM/ASMUtils.java b/src/main/java/com/github/bartimaeusnek/bartworks/ASM/ASMUtils.java deleted file mode 100644 index 725a0135a4..0000000000 --- a/src/main/java/com/github/bartimaeusnek/bartworks/ASM/ASMUtils.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2018-2020 bartimaeusnek 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.github.bartimaeusnek.bartworks.ASM; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; - -import org.objectweb.asm.tree.MethodNode; - -public class ASMUtils { - - public static String matchAny(String toCompare, String... args) { - for (String arg : args) { - if (toCompare.equalsIgnoreCase(arg)) return arg; - } - return ""; - } - - /** - * Call this Method twice, one time for the Descriptor and one time for the Name. - */ - public static boolean isCorrectMethod(MethodNode methodNode, String... args) { - for (String arg : args) { - if (methodNode.name.equalsIgnoreCase(arg) || methodNode.desc.equalsIgnoreCase(arg)) return true; - } - return false; - } - - public static boolean writeClassToDisk(byte[] towrite, String Classname, String Path) { - try { - if (Path.charAt(Path.length() - 1) == '/' || Path.charAt(Path.length() - 1) == '\\') - Path = Path.substring(0, Path.length() - 1); - OutputStream os = new FileOutputStream(new File(Path + '/' + Classname + ".class")); - os.write(towrite); - } catch (IOException e) { - e.printStackTrace(); - return false; - } - return true; - } -} diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/ASM/BWCore.java b/src/main/java/com/github/bartimaeusnek/bartworks/ASM/BWCore.java deleted file mode 100644 index 9841ef78da..0000000000 --- a/src/main/java/com/github/bartimaeusnek/bartworks/ASM/BWCore.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2018-2020 bartimaeusnek 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.github.bartimaeusnek.bartworks.ASM; - -import static com.github.bartimaeusnek.bartworks.ASM.BWCoreTransformer.shouldTransform; -import static gregtech.api.enums.Mods.ExtraUtilities; -import static gregtech.api.enums.Mods.RWG; -import static gregtech.api.enums.Mods.Thaumcraft; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import com.github.bartimaeusnek.bartworks.MainMod; -import com.github.bartimaeusnek.bartworks.common.configs.ConfigHandler; -import com.github.bartimaeusnek.crossmod.BartWorksCrossmod; -import com.google.common.eventbus.EventBus; -import com.google.common.eventbus.Subscribe; - -import cpw.mods.fml.common.DummyModContainer; -import cpw.mods.fml.common.LoadController; -import cpw.mods.fml.common.ModMetadata; -import cpw.mods.fml.common.event.FMLPreInitializationEvent; -import cpw.mods.fml.common.versioning.ArtifactVersion; -import cpw.mods.fml.common.versioning.DefaultArtifactVersion; - -public class BWCore extends DummyModContainer { - - public static final String BWCORE_NAME = "BartWorks ASM Core"; - public static final Logger BWCORE_LOG = LogManager.getLogger(BWCore.BWCORE_NAME); - - public BWCore() { - super(new ModMetadata()); - ModMetadata metadata = this.getMetadata(); - metadata.modId = "BWCore"; - metadata.name = BWCore.BWCORE_NAME; - metadata.version = "0.0.1"; - metadata.authorList.add("bartimaeusnek"); - metadata.dependants = this.getDependants(); - metadata.parent = MainMod.MOD_ID; - } - - @Subscribe - public void preInit(FMLPreInitializationEvent event) { - shouldTransform[0] = ConfigHandler.enabledPatches[0]; - shouldTransform[1] = ConfigHandler.enabledPatches[1]; - shouldTransform[2] = ConfigHandler.enabledPatches[2]; - shouldTransform[3] = ConfigHandler.enabledPatches[3]; - BWCore.BWCORE_LOG.info("Extra Utilities found and ASM Patch enabled? " + shouldTransform[0]); - BWCore.BWCORE_LOG.info("Thaumcraft found and ASM Patch enabled? " + shouldTransform[2]); - } - - @Override - public List<ArtifactVersion> getDependants() { - List<ArtifactVersion> ret = new ArrayList<>(); - ret.add(new DefaultArtifactVersion(ExtraUtilities.ID, true)); - ret.add(new DefaultArtifactVersion(Thaumcraft.ID, true)); - ret.add(new DefaultArtifactVersion(RWG.ID, true)); - ret.add(new DefaultArtifactVersion(MainMod.MOD_ID, true)); - ret.add(new DefaultArtifactVersion(BartWorksCrossmod.MOD_ID, true)); - return ret; - } - - @Override - public boolean registerBus(EventBus bus, LoadController controller) { - bus.register(this); - return true; - } -} diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/ASM/BWCoreTransformer.java b/src/main/java/com/github/bartimaeusnek/bartworks/ASM/BWCoreTransformer.java deleted file mode 100644 index 2659f07af1..0000000000 --- a/src/main/java/com/github/bartimaeusnek/bartworks/ASM/BWCoreTransformer.java +++ /dev/null @@ -1,227 +0,0 @@ -/* - * Copyright (c) 2018-2020 bartimaeusnek 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.github.bartimaeusnek.bartworks.ASM; - -import static org.objectweb.asm.Opcodes.ACC_PUBLIC; -import static org.objectweb.asm.Opcodes.ACONST_NULL; -import static org.objectweb.asm.Opcodes.ALOAD; -import static org.objectweb.asm.Opcodes.ARETURN; -import static org.objectweb.asm.Opcodes.GETFIELD; -import static org.objectweb.asm.Opcodes.ICONST_0; -import static org.objectweb.asm.Opcodes.IFNE; -import static org.objectweb.asm.Opcodes.INVOKESTATIC; -import static org.objectweb.asm.Opcodes.INVOKEVIRTUAL; -import static org.objectweb.asm.Opcodes.IRETURN; -import static org.objectweb.asm.Opcodes.POP; - -import java.util.Arrays; -import java.util.List; - -import net.minecraft.launchwrapper.IClassTransformer; - -import org.objectweb.asm.ClassReader; -import org.objectweb.asm.ClassWriter; -import org.objectweb.asm.tree.AbstractInsnNode; -import org.objectweb.asm.tree.ClassNode; -import org.objectweb.asm.tree.FieldInsnNode; -import org.objectweb.asm.tree.InsnList; -import org.objectweb.asm.tree.InsnNode; -import org.objectweb.asm.tree.JumpInsnNode; -import org.objectweb.asm.tree.LabelNode; -import org.objectweb.asm.tree.MethodInsnNode; -import org.objectweb.asm.tree.MethodNode; -import org.objectweb.asm.tree.VarInsnNode; - -public class BWCoreTransformer implements IClassTransformer { - - public static final String[] DESCRIPTIONFORCONFIG = { "REMOVING RAIN FROM LAST MILLENNIUM (EXU)", - "REMOVING CREATURES FROM LAST MILLENNIUM (EXU)", "PATCHING THAUMCRAFT WAND PEDESTAL TO PREVENT VIS DUPLICATION", - "PATCHING CRAFTING MANAGER FOR CACHING RECIPES" }; - public static final String[] CLASSESBEINGTRANSFORMED = { - "com.rwtema.extrautils.worldgen.endoftime.WorldProviderEndOfTime", - "com.rwtema.extrautils.worldgen.endoftime.ChunkProviderEndOfTime", "thaumcraft.common.tiles.TileWandPedestal", - "net.minecraft.item.crafting.CraftingManager" }; - public static boolean obfs; - - public static boolean[] shouldTransform = new boolean[BWCoreTransformer.CLASSESBEINGTRANSFORMED.length]; - - /** - * Made by DarkShaddow44 - */ - private static MethodNode transformThaumcraftWandPedestal(MethodNode method) { - InsnList nu = new InsnList(); - for (int j = 0; j < method.instructions.size(); j++) { - AbstractInsnNode instruction = method.instructions.get(j); - nu.add(instruction); - if (instruction.getOpcode() == INVOKEVIRTUAL) { - MethodInsnNode invokevirtual = (MethodInsnNode) instruction; - if ("addVis".equals(invokevirtual.name)) { - AbstractInsnNode beginning = method.instructions.get(j - 7); - LabelNode label = new LabelNode(); - nu.insertBefore(beginning, new VarInsnNode(ALOAD, 0)); - nu.insertBefore( - beginning, - new FieldInsnNode( - GETFIELD, - "thaumcraft/common/tiles/TileWandPedestal", - obfs ? "field_145850_b" : "worldObj", - "Lnet/minecraft/world/World;")); - nu.insertBefore( - beginning, - new FieldInsnNode( - GETFIELD, - "net/minecraft/world/World", - obfs ? "field_72995_K" : "isRemote", - "Z")); - nu.insertBefore(beginning, new JumpInsnNode(IFNE, label)); - nu.add(new InsnNode(POP)); - nu.add(label); - j++; // Skip actual Pop - } - } - } - method.instructions = nu; - return method; - } - - public static byte[] transform(int id, byte[] basicClass) { - if (!BWCoreTransformer.shouldTransform[id]) { - BWCore.BWCORE_LOG - .info("Patch: " + BWCoreTransformer.DESCRIPTIONFORCONFIG[id] + " is disabled, will not patch!"); - return basicClass; - } - - if (id < BWCoreTransformer.CLASSESBEINGTRANSFORMED.length) { - BWCore.BWCORE_LOG.info(BWCoreTransformer.DESCRIPTIONFORCONFIG[id]); - ClassReader classReader = new ClassReader(basicClass); - ClassNode classNode = new ClassNode(); - classReader.accept(classNode, ClassReader.SKIP_FRAMES); - List<MethodNode> methods = classNode.methods; - scase: switch (id) { - case 0: { - BWCore.BWCORE_LOG.info("Could find: " + BWCoreTransformer.CLASSESBEINGTRANSFORMED[id]); - String name_deObfs = "canDoRainSnowIce"; - - String dsc_deObfs = "(Lnet/minecraft/world/chunk/Chunk;)Z"; - for (int i = 0; i < methods.size(); i++) { - if (methods.get(i).name.equalsIgnoreCase(name_deObfs)) { - BWCore.BWCORE_LOG.info("Found " + name_deObfs + "! Removing!"); - methods.remove(i); - break; - } - } - BWCore.BWCORE_LOG.info("Creating new " + name_deObfs + "!"); - MethodNode nu = new MethodNode(ACC_PUBLIC, name_deObfs, dsc_deObfs, null, new String[0]); - InsnList insnList = new InsnList(); - insnList.add(new InsnNode(ICONST_0)); - insnList.add(new InsnNode(IRETURN)); - nu.instructions = insnList; - nu.maxLocals = 1; - nu.maxStack = 1; - methods.add(nu); - break; - } - case 1: { - BWCore.BWCORE_LOG.info("Could find: " + BWCoreTransformer.CLASSESBEINGTRANSFORMED[id]); - String name_deObfs = "getPossibleCreatures"; - String name_src = "func_73155_a"; - String name_Obfs = "a"; - String dsc_deObfs = "(Lnet/minecraft/entity/EnumCreatureType;III)Ljava/util/List;"; - String dsc_Obfs = "(Lsx;III)Ljava/util/List;"; - - for (int i = 0; i < methods.size(); i++) { - if (ASMUtils.isCorrectMethod(methods.get(i), name_deObfs, name_Obfs, name_src) - && ASMUtils.isCorrectMethod(methods.get(i), dsc_deObfs, dsc_Obfs)) { - BWCore.BWCORE_LOG.info("Found " + name_deObfs + "! Patching!"); - MethodNode toPatch = methods.get(i); - InsnList insnList = new InsnList(); - insnList.add(new InsnNode(ACONST_NULL)); - insnList.add(new InsnNode(ARETURN)); - toPatch.instructions = insnList; - toPatch.maxStack = 1; - toPatch.maxLocals = 5; - methods.set(i, toPatch); - break scase; - } - } - } - case 2: { - BWCore.BWCORE_LOG.info("Could find: " + BWCoreTransformer.CLASSESBEINGTRANSFORMED[id]); - String name_deObfs = "updateEntity"; - String name_src = "func_145845_h"; - String name_Obfs = "h"; - String dsc_universal = "()V"; - - for (int i = 0; i < methods.size(); i++) { - if (ASMUtils.isCorrectMethod(methods.get(i), name_deObfs, name_Obfs, name_src) - && ASMUtils.isCorrectMethod(methods.get(i), dsc_universal, dsc_universal)) { - BWCore.BWCORE_LOG.info("Found " + name_deObfs + "! Patching!"); - methods.set(i, BWCoreTransformer.transformThaumcraftWandPedestal(methods.get(i))); - break scase; - } - } - } - case 3: { - BWCore.BWCORE_LOG.info("Could find: " + BWCoreTransformer.CLASSESBEINGTRANSFORMED[id]); - String name_deObfs = "findMatchingRecipe"; - String name_Obfs = "a"; - String name_src = "func_82787_a"; - for (MethodNode toPatch : methods) { - if (ASMUtils.isCorrectMethod(toPatch, name_deObfs, name_Obfs, name_src)) { - toPatch.instructions = new InsnList(); - toPatch.instructions.add(new VarInsnNode(ALOAD, 1)); - toPatch.instructions.add(new VarInsnNode(ALOAD, 2)); - toPatch.instructions.add( - new MethodInsnNode( - INVOKESTATIC, - "com/github/bartimaeusnek/bartworks/ASM/BWCoreStaticReplacementMethodes", - "findCachedMatchingRecipe", - "(Lnet/minecraft/inventory/InventoryCrafting;Lnet/minecraft/world/World;)Lnet/minecraft/item/ItemStack;", - false)); - toPatch.instructions.add(new InsnNode(ARETURN)); - toPatch.localVariables.clear(); - toPatch.maxStack = 2; - toPatch.maxLocals = 3; - break scase; - } - } - } - - default: { - BWCore.BWCORE_LOG.info("Could not find: " + BWCoreTransformer.CLASSESBEINGTRANSFORMED[id]); - return basicClass; - } - } - - classNode.methods = methods; - ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES); - classNode.accept(classWriter); - byte[] ret = classWriter.toByteArray(); - if (Arrays.hashCode(basicClass) == Arrays.hashCode(ret)) - BWCore.BWCORE_LOG.warn("Could not patch: " + BWCoreTransformer.CLASSESBEINGTRANSFORMED[id]); - return ret; - } - return basicClass; - } - - @Override - public byte[] transform(String name, String transformedName, byte[] basicClass) { - for (int i = 0; i < BWCoreTransformer.CLASSESBEINGTRANSFORMED.length; i++) { - if (name.equalsIgnoreCase(BWCoreTransformer.CLASSESBEINGTRANSFORMED[i]) - || transformedName.equalsIgnoreCase(BWCoreTransformer.CLASSESBEINGTRANSFORMED[i])) - return BWCoreTransformer.transform(i, basicClass); - } - return basicClass; - } -} diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/common/configs/ConfigHandler.java b/src/main/java/com/github/bartimaeusnek/bartworks/common/configs/ConfigHandler.java index 7c5a515b86..ee53c6ec64 100644 --- a/src/main/java/com/github/bartimaeusnek/bartworks/common/configs/ConfigHandler.java +++ b/src/main/java/com/github/bartimaeusnek/bartworks/common/configs/ConfigHandler.java @@ -21,7 +21,6 @@ import java.util.Set; import net.minecraftforge.common.config.Configuration; import com.github.bartimaeusnek.bartworks.API.API_ConfigValues; -import com.github.bartimaeusnek.bartworks.ASM.BWCoreTransformer; public class ConfigHandler { @@ -104,6 +103,14 @@ public class ConfigHandler { "Ultimate Extended Mega Voltage", "Overpowered Voltage", "Maximum Voltage" }; private static final String[] names = { "Generators", "Buffers", "Cables", "Machines" }; + public static final String[] ASM_TRANSFORMER_DESCRIPTIONS = { "REMOVING RAIN FROM LAST MILLENNIUM (EXU)", + "REMOVING CREATURES FROM LAST MILLENNIUM (EXU)", "PATCHING THAUMCRAFT WAND PEDESTAL TO PREVENT VIS DUPLICATION", + "PATCHING CRAFTING MANAGER FOR CACHING RECIPES" }; + public static final String[] ASM_TRANSFORMER_CLASSES = { + "com.rwtema.extrautils.worldgen.endoftime.WorldProviderEndOfTime", + "com.rwtema.extrautils.worldgen.endoftime.ChunkProviderEndOfTime", "thaumcraft.common.tiles.TileWandPedestal", + "net.minecraft.item.crafting.CraftingManager" }; + public ConfigHandler(Configuration C) { ConfigHandler.c = C; ConfigHandler.classicMode = ConfigHandler.c @@ -255,18 +262,11 @@ public class ConfigHandler { .get("System", "Enable Debug Log", false, "Enables or Disables the debug log.") .getBoolean(false); - for (int i = 0; i < BWCoreTransformer.CLASSESBEINGTRANSFORMED.length; i++) - BWCoreTransformer.shouldTransform[i] = ConfigHandler.c - .get( - "ASM fixes", - BWCoreTransformer.DESCRIPTIONFORCONFIG[i] + " in class: " - + BWCoreTransformer.CLASSESBEINGTRANSFORMED[i], - true) - .getBoolean(true); - - ConfigHandler.enabledPatches = new boolean[BWCoreTransformer.shouldTransform.length]; - ConfigHandler.enabledPatches = Arrays - .copyOf(BWCoreTransformer.shouldTransform, BWCoreTransformer.shouldTransform.length); + ConfigHandler.enabledPatches = new boolean[ASM_TRANSFORMER_CLASSES.length]; + for (int i = 0; i < ASM_TRANSFORMER_CLASSES.length; i++) ConfigHandler.enabledPatches[i] = ConfigHandler.c + .get("ASM fixes", ASM_TRANSFORMER_DESCRIPTIONS[i] + " in class: " + ASM_TRANSFORMER_CLASSES[i], true) + .getBoolean(true); + ConfigHandler.ross128BID = ConfigHandler.c .get("CrossMod Interactions", "DimID - Ross128b", -64, "The Dim ID for Ross128b") .getInt(-64); diff --git a/src/main/java/gregtech/asm/GTCorePlugin.java b/src/main/java/gregtech/asm/GTCorePlugin.java index a31d106bbe..0f50b78f1d 100644 --- a/src/main/java/gregtech/asm/GTCorePlugin.java +++ b/src/main/java/gregtech/asm/GTCorePlugin.java @@ -1,17 +1,18 @@ package gregtech.asm; import java.io.File; -import java.util.ArrayList; +import java.util.List; import java.util.Map; +import java.util.Set; import net.minecraftforge.common.config.Configuration; -import com.github.bartimaeusnek.bartworks.ASM.BWCore; -import com.github.bartimaeusnek.bartworks.ASM.BWCoreTransformer; import com.github.bartimaeusnek.bartworks.common.configs.ConfigHandler; +import com.gtnewhorizon.gtnhmixins.IEarlyMixinLoader; import cpw.mods.fml.relauncher.FMLInjectionData; import cpw.mods.fml.relauncher.IFMLLoadingPlugin; +import gregtech.mixin.Mixin; import gtPlusPlus.preloader.CORE_Preloader; import gtPlusPlus.preloader.asm.AsmConfig; import gtPlusPlus.preloader.asm.Preloader_DummyContainer; @@ -23,7 +24,7 @@ import gtPlusPlus.preloader.asm.transformers.Preloader_Transformer_Handler; "gregtech.asm" }) @IFMLLoadingPlugin.Name("GregTech 5 Unofficial core plugin") @SuppressWarnings("unused") // loaded by FML -public class GTCorePlugin implements IFMLLoadingPlugin { +public class GTCorePlugin implements IFMLLoadingPlugin, IEarlyMixinLoader { public static final String BWCORE_PLUGIN_NAME = "BartWorks ASM Core Plugin"; public static File minecraftDir; @@ -34,17 +35,15 @@ public class GTCorePlugin implements IFMLLoadingPlugin { minecraftDir = (File) FMLInjectionData.data()[6]; // do all the configuration already now... new ConfigHandler(new Configuration(new File(new File(minecraftDir, "config"), "bartworks.cfg"))); - BWCoreTransformer.shouldTransform[2] = false; } @Override public String[] getASMTransformerClass() { - return new String[] { BWCoreTransformer.class.getName(), Preloader_Transformer_Handler.class.getName() }; + return new String[] { Preloader_Transformer_Handler.class.getName() }; } @Override public String getModContainerClass() { - FMLInjectionData.containers.add(BWCore.class.getName()); return Preloader_DummyContainer.class.getName(); } @@ -62,24 +61,20 @@ public class GTCorePlugin implements IFMLLoadingPlugin { CORE_Preloader.setMinecraftDirectory(mcDir); } CORE_Preloader.DEBUG_MODE = AsmConfig.debugMode; - - // Bartworks - if (data.get("runtimeDeobfuscationEnabled") != null) { - BWCoreTransformer.obfs = (boolean) data.get("runtimeDeobfuscationEnabled"); - } - if (data.get("coremodList") != null) { - for (Object o : (ArrayList) data.get("coremodList")) { - if (o.toString() - .contains("MicdoodlePlugin")) { - BWCoreTransformer.shouldTransform[2] = ConfigHandler.enabledPatches[2]; - break; - } - } - } } @Override public String getAccessTransformerClass() { return null; } + + @Override + public String getMixinConfig() { + return "mixins.gregtech.early.json"; + } + + @Override + public List<String> getMixins(Set<String> loadedCoreMods) { + return Mixin.getEarlyMixins(loadedCoreMods); + } } diff --git a/src/main/java/gregtech/mixin/LateMixinPlugin.java b/src/main/java/gregtech/mixin/LateMixinPlugin.java new file mode 100644 index 0000000000..dab8cc5f03 --- /dev/null +++ b/src/main/java/gregtech/mixin/LateMixinPlugin.java @@ -0,0 +1,21 @@ +package gregtech.mixin; + +import java.util.List; +import java.util.Set; + +import com.gtnewhorizon.gtnhmixins.ILateMixinLoader; +import com.gtnewhorizon.gtnhmixins.LateMixin; + +@LateMixin +public class LateMixinPlugin implements ILateMixinLoader { + + @Override + public String getMixinConfig() { + return "mixins.gregtech.late.json"; + } + + @Override + public List<String> getMixins(Set<String> loadedMods) { + return Mixin.getLateMixins(loadedMods); + } +} diff --git a/src/main/java/gregtech/mixin/Mixin.java b/src/main/java/gregtech/mixin/Mixin.java index 347dec2c5e..6e2b927afe 100644 --- a/src/main/java/gregtech/mixin/Mixin.java +++ b/src/main/java/gregtech/mixin/Mixin.java @@ -1,50 +1,237 @@ package gregtech.mixin; +import static gregtech.mixin.TargetedMod.EXTRA_UTILITIES; +import static gregtech.mixin.TargetedMod.THAUMCRAFT; import static gregtech.mixin.TargetedMod.VANILLA; +import java.util.ArrayList; import java.util.Arrays; -import java.util.HashSet; +import java.util.Collections; import java.util.List; +import java.util.Set; +import java.util.function.Supplier; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import com.github.bartimaeusnek.bartworks.common.configs.ConfigHandler; import cpw.mods.fml.relauncher.FMLLaunchHandler; public enum Mixin { // Minecraft - WorldMixin("minecraft.WorldMixin", VANILLA), - StringTranslateMixin("minecraft.StringTranslateMixin", VANILLA), - LanguageRegistryMixin("minecraft.LanguageRegistryMixin", VANILLA), - LocaleMixin("minecraft.LocaleMixin", Side.CLIENT, VANILLA), + WorldMixin(new Builder("Block update detection").addMixinClasses("minecraft.WorldMixin") + .addTargetedMod(VANILLA) + .setApplyIf(() -> true) + .setPhase(Phase.EARLY) + .setSide(Side.BOTH)), + StringTranslateMixin(new Builder("Keep track of currently translating mods") + .addMixinClasses("minecraft.StringTranslateMixin", "minecraft.LanguageRegistryMixin") + .addTargetedMod(VANILLA) + .setApplyIf(() -> true) + .setPhase(Phase.EARLY) + .setSide(Side.BOTH)), + LocaleMixin(new Builder("Keep track of currently translating client mods").addMixinClasses("minecraft.LocaleMixin") + .addTargetedMod(VANILLA) + .setApplyIf(() -> true) + .setPhase(Phase.EARLY) + .setSide(Side.CLIENT)), + CacheCraftingManagerRecipes( + new Builder("Cache CraftingManager recipes").addMixinClasses("minecraft.CraftingManagerMixin") + .addTargetedMod(VANILLA) + .setApplyIf(() -> ConfigHandler.enabledPatches[3]) + .setPhase(Phase.EARLY) + .setSide(Side.BOTH)), + // Extra utilities + RemoveLastMilleniumRain(new Builder("Remove rain from the Last Millenium (Extra Utilities)") + .addMixinClasses("xu.WorldProviderEndOfTimeMixin") + .addTargetedMod(EXTRA_UTILITIES) + .setApplyIf(() -> ConfigHandler.enabledPatches[0]) + .setPhase(Phase.LATE) + .setSide(Side.BOTH)), + RemoveLastMilleniumCreatures(new Builder("Remove creatures from the Last Millenium (Extra Utilities)") + .addMixinClasses("xu.ChunkProviderEndOfTimeMixin") + .addTargetedMod(EXTRA_UTILITIES) + .setApplyIf(() -> ConfigHandler.enabledPatches[1]) + .setPhase(Phase.LATE) + .setSide(Side.BOTH)), + // Thaumcraft + PatchWandPedestalVisDuplication(new Builder("Fix wand pedestal vis duplication (Thaumcraft)") + .addMixinClasses("thaumcraft.TileWandPedestalMixin") + .addTargetedMod(THAUMCRAFT) + .setApplyIf(() -> ConfigHandler.enabledPatches[2]) + .setPhase(Phase.LATE) + .setSide(Side.BOTH)),; - ; + public static final Logger LOGGER = LogManager.getLogger("GregTech-Mixin"); - public final String mixinClass; - public final List<TargetedMod> targetedMods; + private final List<String> mixinClasses; + private final List<TargetedMod> targetedMods; + private final List<TargetedMod> excludedMods; + private final Supplier<Boolean> applyIf; + private final Phase phase; private final Side side; - Mixin(String mixinClass, Side side, TargetedMod... targetedMods) { - this.mixinClass = mixinClass; - this.targetedMods = Arrays.asList(targetedMods); - this.side = side; + Mixin(Builder builder) { + this.mixinClasses = builder.mixinClasses; + this.targetedMods = builder.targetedMods; + this.excludedMods = builder.excludedMods; + this.applyIf = builder.applyIf; + this.phase = builder.phase; + this.side = builder.side; + if (this.mixinClasses.isEmpty()) { + throw new RuntimeException("No mixin class specified for Mixin : " + this.name()); + } + if (this.targetedMods.isEmpty()) { + throw new RuntimeException("No targeted mods specified for Mixin : " + this.name()); + } + if (this.applyIf == null) { + throw new RuntimeException("No ApplyIf function specified for Mixin : " + this.name()); + } + if (this.phase == null) { + throw new RuntimeException("No Phase specified for Mixin : " + this.name()); + } + if (this.side == null) { + throw new RuntimeException("No Side function specified for Mixin : " + this.name()); + } + } + + public static List<String> getEarlyMixins(Set<String> loadedCoreMods) { + final List<String> mixins = new ArrayList<>(); + final List<String> notLoading = new ArrayList<>(); + for (Mixin mixin : Mixin.values()) { + if (mixin.phase == Phase.EARLY) { + if (mixin.shouldLoad(loadedCoreMods, Collections.emptySet())) { + mixins.addAll(mixin.mixinClasses); + } else { + notLoading.addAll(mixin.mixinClasses); + } + } + } + LOGGER.info("Not loading the following EARLY mixins: {}", notLoading.toString()); + return mixins; + } + + public static List<String> getLateMixins(Set<String> loadedMods) { + // NOTE: Any targetmod here needs a modid, not a coremod id + final List<String> mixins = new ArrayList<>(); + final List<String> notLoading = new ArrayList<>(); + for (Mixin mixin : Mixin.values()) { + if (mixin.phase == Phase.LATE) { + if (mixin.shouldLoad(Collections.emptySet(), loadedMods)) { + mixins.addAll(mixin.mixinClasses); + } else { + notLoading.addAll(mixin.mixinClasses); + } + } + } + LOGGER.info("Not loading the following LATE mixins: {}", notLoading.toString()); + return mixins; + } + + private boolean shouldLoadSide() { + return side == Side.BOTH || (side == Side.SERVER && FMLLaunchHandler.side() + .isServer()) + || (side == Side.CLIENT && FMLLaunchHandler.side() + .isClient()); + } + + private boolean allModsLoaded(List<TargetedMod> targetedMods, Set<String> loadedCoreMods, Set<String> loadedMods) { + if (targetedMods.isEmpty()) return false; + + for (TargetedMod target : targetedMods) { + if (target == TargetedMod.VANILLA) continue; + + // Check coremod first + if (!loadedCoreMods.isEmpty() && target.coreModClass != null + && !loadedCoreMods.contains(target.coreModClass)) return false; + else if (!loadedMods.isEmpty() && target.modId != null && !loadedMods.contains(target.modId)) return false; + } + + return true; + } + + private boolean noModsLoaded(List<TargetedMod> targetedMods, Set<String> loadedCoreMods, Set<String> loadedMods) { + if (targetedMods.isEmpty()) return true; + + for (TargetedMod target : targetedMods) { + if (target == TargetedMod.VANILLA) continue; |
