diff options
Diffstat (limited to 'src/main/java')
65 files changed, 1123 insertions, 1096 deletions
diff --git a/src/main/java/com/github/bartimaeusnek/ASM/ASMUtils.java b/src/main/java/com/github/bartimaeusnek/ASM/ASMUtils.java new file mode 100644 index 0000000000..f4b61a17ba --- /dev/null +++ b/src/main/java/com/github/bartimaeusnek/ASM/ASMUtils.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2019 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.ASM; + +import org.objectweb.asm.tree.MethodNode; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; + +public class ASMUtils { + + public static String matchAny(String toCompare, String... args) { + for (int i = 0; i < args.length; i++) { + if (toCompare.equalsIgnoreCase(args[i])) + return args[i]; + } + 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 (int i = 0; i < args.length; i++) { + if (methodNode.name.equalsIgnoreCase(args[i]) || methodNode.desc.equalsIgnoreCase(args[i])) + return true; + } + return false; + } + + public static boolean writeClassToDisk(byte[] towrite, String Classname, String Path) { + try { + 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/ASM/BWCore.java b/src/main/java/com/github/bartimaeusnek/ASM/BWCore.java index bddf66ae5e..9c76b3dd82 100644 --- a/src/main/java/com/github/bartimaeusnek/ASM/BWCore.java +++ b/src/main/java/com/github/bartimaeusnek/ASM/BWCore.java @@ -31,7 +31,6 @@ 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; -import net.minecraftforge.common.config.Configuration; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -55,12 +54,6 @@ public class BWCore extends DummyModContainer { @Subscribe public void preInit(FMLPreInitializationEvent event) { - Configuration asmconfighandler = new Configuration(event.getSuggestedConfigurationFile()); - for (int i = 0; i < BWCoreTransformer.CLASSESBEEINGTRANSFORMED.length; i++) { - BWCoreTransformer.shouldTransform[i]=asmconfighandler.get("ASM fixes",BWCoreTransformer.DESCRIPTIONFORCONFIG[i]+" in class: "+BWCoreTransformer.CLASSESBEEINGTRANSFORMED[i],true).getBoolean(true); - } - if (asmconfighandler.hasChanged()) - asmconfighandler.save(); } @Override diff --git a/src/main/java/com/github/bartimaeusnek/ASM/BWCorePlugin.java b/src/main/java/com/github/bartimaeusnek/ASM/BWCorePlugin.java index becd28f524..018690d312 100644 --- a/src/main/java/com/github/bartimaeusnek/ASM/BWCorePlugin.java +++ b/src/main/java/com/github/bartimaeusnek/ASM/BWCorePlugin.java @@ -22,16 +22,36 @@ package com.github.bartimaeusnek.ASM; +import cpw.mods.fml.relauncher.FMLInjectionData; import cpw.mods.fml.relauncher.IFMLLoadingPlugin; +import net.minecraftforge.common.config.Configuration; +import java.io.File; import java.util.Map; +@IFMLLoadingPlugin.SortingIndex(999999999)//Load as late as possible (after fastcraft/OptiFine). @IFMLLoadingPlugin.MCVersion("1.7.10") @IFMLLoadingPlugin.TransformerExclusions({"com.github.bartimaeusnek.ASM"}) @IFMLLoadingPlugin.Name(BWCorePlugin.BWCORE_PLUGIN_NAME) public class BWCorePlugin implements IFMLLoadingPlugin { - public static final String BWCORE_PLUGIN_NAME="BartWorks ASM Core Plugin"; + public static final String BWCORE_PLUGIN_NAME = "BartWorks ASM Core Plugin"; + + public static File minecraftDir = null; + + public BWCorePlugin() { + //Injection Code taken from CodeChickenLib + if (minecraftDir != null) + return;//get called twice, once for IFMLCallHook + minecraftDir = (File) FMLInjectionData.data()[6]; + + Configuration asmconfighandler = new Configuration(new File(new File(minecraftDir, "config"), "bartworks.cfg")); + for (int i = 0; i < BWCoreTransformer.CLASSESBEEINGTRANSFORMED.length; i++) { + BWCoreTransformer.shouldTransform[i] = asmconfighandler.get("ASM fixes", BWCoreTransformer.DESCRIPTIONFORCONFIG[i] + " in class: " + BWCoreTransformer.CLASSESBEEINGTRANSFORMED[i], true).getBoolean(true); + } + if (asmconfighandler.hasChanged()) + asmconfighandler.save(); + } @Override public String[] getASMTransformerClass() { @@ -50,10 +70,9 @@ public class BWCorePlugin implements IFMLLoadingPlugin { @Override public void injectData(Map<String, Object> data) { - if (data.get("runtimeDeobfuscationEnabled") != null){ - BWCoreTransformer.obfs=(boolean)data.get("runtimeDeobfuscationEnabled"); + if (data.get("runtimeDeobfuscationEnabled") != null) { + BWCoreTransformer.obfs = (boolean) data.get("runtimeDeobfuscationEnabled"); } - } @Override diff --git a/src/main/java/com/github/bartimaeusnek/ASM/BWCoreStaticReplacementMethodes.java b/src/main/java/com/github/bartimaeusnek/ASM/BWCoreStaticReplacementMethodes.java index 0d98c72564..505612cd35 100644 --- a/src/main/java/com/github/bartimaeusnek/ASM/BWCoreStaticReplacementMethodes.java +++ b/src/main/java/com/github/bartimaeusnek/ASM/BWCoreStaticReplacementMethodes.java @@ -22,10 +22,8 @@ package com.github.bartimaeusnek.ASM; -import com.github.bartimaeusnek.crossmod.galacticraft.planets.ross128.world.worldprovider.WorldProviderRoss128b; -import net.minecraft.client.multiplayer.WorldClient; - public class BWCoreStaticReplacementMethodes { - private BWCoreStaticReplacementMethodes(){} + private BWCoreStaticReplacementMethodes() { + } } diff --git a/src/main/java/com/github/bartimaeusnek/ASM/BWCoreTransformer.java b/src/main/java/com/github/bartimaeusnek/ASM/BWCoreTransformer.java index 0a6f44712d..6a9850e4fe 100644 --- a/src/main/java/com/github/bartimaeusnek/ASM/BWCoreTransformer.java +++ b/src/main/java/com/github/bartimaeusnek/ASM/BWCoreTransformer.java @@ -26,7 +26,6 @@ import net.minecraft.launchwrapper.IClassTransformer; import org.apache.commons.lang3.ArrayUtils; import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassWriter; -import org.objectweb.asm.Opcodes; import org.objectweb.asm.tree.*; import java.util.Arrays; @@ -35,34 +34,25 @@ import java.util.List; import static org.objectweb.asm.Opcodes.*; public class BWCoreTransformer implements IClassTransformer { - public static boolean obfs = false; public static final String[] DESCRIPTIONFORCONFIG = { "REMOVING RAIN FROM LAST MILLENIUM (EXU)", "REMVOING CREATURES FROM LAST MILLENIUM (EXU)", "PATCHING GLOBAL RENDERER FOR USE WITH MY GALACTIC DIMS" }; - public static final String[] CLASSESBEEINGTRANSFORMED = { "com.rwtema.extrautils.worldgen.endoftime.WorldProviderEndOfTime", "com.rwtema.extrautils.worldgen.endoftime.ChunkProviderEndOfTime", //"micdoodle8.mods.galacticraft.core.client.SkyProviderOverworld", "net.minecraft.client.renderer.RenderGlobal", }; - - public static boolean[] shouldTransform = ArrayUtils.toPrimitive(new Boolean[BWCoreTransformer.CLASSESBEEINGTRANSFORMED.length],true); - - @Override - public byte[] transform(String name, String transformedName, byte[] basicClass) { - for (int i = 0; i < BWCoreTransformer.CLASSESBEEINGTRANSFORMED.length; i++) { - if (name.equalsIgnoreCase(BWCoreTransformer.CLASSESBEEINGTRANSFORMED[i])) - return BWCoreTransformer.transform(i,basicClass); - } - return basicClass; - } + public static boolean obfs = false; + public static boolean[] shouldTransform = ArrayUtils.toPrimitive(new Boolean[BWCoreTransformer.CLASSESBEEINGTRANSFORMED.length], true); public static byte[] transform(int id, byte[] basicClass) { - if (!BWCoreTransformer.shouldTransform[id]) + if (!BWCoreTransformer.shouldTransform[id]) { + BWCore.BWCORE_LOG.info("Patch: " + DESCRIPTIONFORCONFIG[id] + " is disabled, will not patch!"); return basicClass; + } if (id < BWCoreTransformer.CLASSESBEEINGTRANSFORMED.length) { BWCore.BWCORE_LOG.info(DESCRIPTIONFORCONFIG[id]); @@ -72,27 +62,27 @@ public class BWCoreTransformer implements IClassTransformer { List<MethodNode> methods = classNode.methods; switch (id) { case 0: { - BWCore.BWCORE_LOG.info("Could find: "+CLASSESBEEINGTRANSFORMED[id]); + BWCore.BWCORE_LOG.info("Could find: " + CLASSESBEEINGTRANSFORMED[id]); String name_deObfs = "canDoRainSnowIce"; String dsc_deObfs = "(Lnet/minecraft/world/chunk/Chunk;)Z"; String dsc_Obfs = "(Lapx;)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!"); + BWCore.BWCORE_LOG.info("Found " + name_deObfs + "! Removing!"); methods.remove(i); break; } } - BWCore.BWCORE_LOG.info("Creating new "+name_deObfs+"!"); - MethodNode nu = new MethodNode(Opcodes.ACC_PUBLIC, name_deObfs, + BWCore.BWCORE_LOG.info("Creating new " + name_deObfs + "!"); + MethodNode nu = new MethodNode(ACC_PUBLIC, name_deObfs, /*obfs ? dsc_Obfs :*/ dsc_deObfs, - name_deObfs+dsc_deObfs.substring(0,dsc_deObfs.length()-1), + null, new String[0] ); InsnList insnList = new InsnList(); - insnList.add(new InsnNode(Opcodes.ICONST_0)); - insnList.add(new InsnNode(Opcodes.IRETURN)); + insnList.add(new InsnNode(ICONST_0)); + insnList.add(new InsnNode(IRETURN)); nu.instructions = insnList; nu.maxLocals = 1; nu.maxStack = 1; @@ -100,18 +90,20 @@ public class BWCoreTransformer implements IClassTransformer { break; } case 1: { - BWCore.BWCORE_LOG.info("Could find: "+CLASSESBEEINGTRANSFORMED[id]); + BWCore.BWCORE_LOG.info("Could find: " + CLASSESBEEINGTRANSFORMED[id]); String name_deObfs = "getPossibleCreatures"; - String name_Obfs = "func_73155_a"; + 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 ((methods.get(i).name.equalsIgnoreCase(obfs?name_Obfs:name_deObfs) && methods.get(i).desc.equalsIgnoreCase(obfs?dsc_Obfs:dsc_deObfs))||(methods.get(i).name.equalsIgnoreCase(!obfs?name_Obfs:name_deObfs) && methods.get(i).desc.equalsIgnoreCase(!obfs?dsc_Obfs:dsc_deObfs))) { - BWCore.BWCORE_LOG.info("Found "+(name_deObfs)+"! Patching!"); + 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(Opcodes.ACONST_NULL)); - insnList.add(new InsnNode(Opcodes.ARETURN)); + insnList.add(new InsnNode(ACONST_NULL)); + insnList.add(new InsnNode(ARETURN)); toPatch.instructions = insnList; toPatch.maxStack = 1; toPatch.maxLocals = 5; @@ -121,92 +113,93 @@ public class BWCoreTransformer implements IClassTransformer { } break; } - case 2:{ + case 2: { String name_deObfs = "renderSky"; - String name_Obfs = "func_72714_a"; - String dsc_deObfs = "(F)V"; - BWCore.BWCORE_LOG.info("Could find: "+CLASSESBEEINGTRANSFORMED[id]); + String name_src = "func_72714_a"; + String name_Obfs = "a"; + String dsc_universal = "(F)V"; + String field_deObfs = "locationSunPng"; + String field_src = "field_110928_i"; + BWCore.BWCORE_LOG.info("Could find: " + CLASSESBEEINGTRANSFORMED[id]); for (int i = 0; i < methods.size(); i++) { MethodNode toPatch = methods.get(i); - if ((toPatch.name.equalsIgnoreCase(name_Obfs) || toPatch.name.equalsIgnoreCase(name_deObfs)) && methods.get(i).desc.equalsIgnoreCase(dsc_deObfs)) { - BWCore.BWCORE_LOG.info("Found "+(name_deObfs)+"! Patching!"); + if (ASMUtils.isCorrectMethod(methods.get(i), name_deObfs, name_Obfs, name_src) && ASMUtils.isCorrectMethod(methods.get(i), dsc_universal)) { + BWCore.BWCORE_LOG.info("Found " + (name_deObfs) + "! Patching!"); InsnList nu = new InsnList(); - LabelNode[] LabelNodes = { new LabelNode(),new LabelNode()}; + LabelNode[] LabelNodes = {new LabelNode(), new LabelNode()}; + + String theWorld_src = "field_72769_h"; + String renderEngine_src = "field_72770_i"; + String provider_src = "field_73011_w"; + String bindTexture_src = "func_110577_a"; + String nameFieldToPatch; + for (int j = 0; j < toPatch.instructions.size(); j++) { - if (toPatch.instructions.get(j) instanceof LineNumberNode && ((LineNumberNode) toPatch.instructions.get(j)).line == 1190) { - nu.add(toPatch.instructions.get(j)); |
