aboutsummaryrefslogtreecommitdiff
path: root/gtpp/src/main/java/gtPlusPlus/preloader/asm
diff options
context:
space:
mode:
authorRaven Szewczyk <git@eigenraven.me>2024-05-24 19:50:35 +0100
committerRaven Szewczyk <git@eigenraven.me>2024-05-24 19:50:35 +0100
commit6d1b2216464d4dad449ac6fcfec476832224a55e (patch)
tree526a0c15f7056313c80e6c0386e025e9b3f61781 /gtpp/src/main/java/gtPlusPlus/preloader/asm
parentb5d35f40afa606ed1b07061dad82e0521a59c186 (diff)
downloadGT5-Unofficial-6d1b2216464d4dad449ac6fcfec476832224a55e.tar.gz
GT5-Unofficial-6d1b2216464d4dad449ac6fcfec476832224a55e.tar.bz2
GT5-Unofficial-6d1b2216464d4dad449ac6fcfec476832224a55e.zip
Merge addon sources
Diffstat (limited to 'gtpp/src/main/java/gtPlusPlus/preloader/asm')
-rw-r--r--gtpp/src/main/java/gtPlusPlus/preloader/asm/AsmConfig.java144
-rw-r--r--gtpp/src/main/java/gtPlusPlus/preloader/asm/Preloader_DummyContainer.java70
-rw-r--r--gtpp/src/main/java/gtPlusPlus/preloader/asm/Preloader_FMLLoadingPlugin.java47
-rw-r--r--gtpp/src/main/java/gtPlusPlus/preloader/asm/transformers/ClassTransformer_COFH_OreDictionaryArbiter.java187
-rw-r--r--gtpp/src/main/java/gtPlusPlus/preloader/asm/transformers/ClassTransformer_IC2_GetHarvestTool.java233
-rw-r--r--gtpp/src/main/java/gtPlusPlus/preloader/asm/transformers/ClassTransformer_LWJGL_Keyboard.java297
-rw-r--r--gtpp/src/main/java/gtPlusPlus/preloader/asm/transformers/ClassTransformer_TC_ItemWispEssence.java317
-rw-r--r--gtpp/src/main/java/gtPlusPlus/preloader/asm/transformers/Preloader_ClassTransformer.java79
-rw-r--r--gtpp/src/main/java/gtPlusPlus/preloader/asm/transformers/Preloader_Transformer_Handler.java92
9 files changed, 0 insertions, 1466 deletions
diff --git a/gtpp/src/main/java/gtPlusPlus/preloader/asm/AsmConfig.java b/gtpp/src/main/java/gtPlusPlus/preloader/asm/AsmConfig.java
deleted file mode 100644
index b4a49c275c..0000000000
--- a/gtpp/src/main/java/gtPlusPlus/preloader/asm/AsmConfig.java
+++ /dev/null
@@ -1,144 +0,0 @@
-package gtPlusPlus.preloader.asm;
-
-import java.io.File;
-import java.util.ArrayList;
-
-import net.minecraftforge.common.config.Configuration;
-import net.minecraftforge.common.config.Property;
-
-import org.apache.logging.log4j.Level;
-
-import cpw.mods.fml.common.FMLLog;
-import gtPlusPlus.preloader.Preloader_Logger;
-
-public class AsmConfig {
-
- public static Configuration config;
-
- public static boolean enableOreDictPatch;
- public static boolean enableGtTooltipFix;
- public static boolean enableGtNbtFix;
- public static boolean enableGtCharcoalPitFix;
- public static boolean enableCofhPatch;
- public static boolean enableTcAspectSafety;
- public static boolean enabledLwjglKeybindingFix;
- public static boolean enabledFixEntitySetHealth;
- public static boolean enableThaumicTinkererRepairFix;
-
- public static boolean disableAllLogging;
- public static boolean debugMode;
-
- static {
- config = new Configuration(new File("config/GTplusplus/asm.cfg"));
- syncConfig(true);
- }
-
- public static void syncConfig(boolean load) {
- ArrayList<String> propOrder = new ArrayList<>();
- ArrayList<String> propOrderDebug = new ArrayList<>();
-
- try {
- if (!config.isChild && load) {
- config.load();
- }
-
- Property prop;
-
- // Debug
- prop = config.get("debug", "disableAllLogging", true);
- prop.comment = "Disables ALL logging from GT++.";
- prop.setLanguageKey("gtpp.disableAllLogging")
- .setRequiresMcRestart(false);
- disableAllLogging = prop.getBoolean(true);
- propOrderDebug.add(prop.getName());
-
- prop = config.get("debug", "debugMode", false);
- prop.comment = "Enables all sorts of debug logging. (Don't use unless told to, breaks other things.)";
- prop.setLanguageKey("gtpp.debugMode")
- .setRequiresMcRestart(false);
- debugMode = prop.getBoolean(false);
- propOrderDebug.add(prop.getName());
-
- prop = config.get("debug", "enabledFixEntitySetHealth", false);
- prop.comment = "Enable/Disable entity setHealth() fix.";
- prop.setLanguageKey("gtpp.enabledFixEntitySetHealth")
- .setRequiresMcRestart(true);
- enabledFixEntitySetHealth = prop.getBoolean(false);
- propOrderDebug.add(prop.getName());
-
- prop = config.get("debug", "enableGtNbtFix", true);
- prop.comment = "Enable/Disable GT NBT Persistency Fix";
- prop.setLanguageKey("gtpp.enableGtNbtFix")
- .setRequiresMcRestart(true);
- enableGtNbtFix = prop.getBoolean(true);
- propOrderDebug.add(prop.getName());
-
- prop = config.get("debug", "enableCofhPatch", false);
- prop.comment = "Enable/Disable COFH OreDictionaryArbiter Patch (Useful for Development)";
- prop.setLanguageKey("gtpp.enableCofhPatch")
- .setRequiresMcRestart(true);
- enableCofhPatch = prop.getBoolean(false);
- propOrderDebug.add(prop.getName());
-
- prop = config.get("debug", "enableOreDictPatch", false);
- prop.comment = "Enable/Disable Forge OreDictionary Patch (Useful for Development)";
- prop.setLanguageKey("gtpp.enableOreDictPatch")
- .setRequiresMcRestart(true);
- enableOreDictPatch = prop.getBoolean(false);
- propOrderDebug.add(prop.getName());
-
- prop = config.get("debug", "enableThaumicTinkererRepairFix", false);
- prop.comment = "Enable/Disable Patch for Thaumic Repairer";
- prop.setLanguageKey("gtpp.enableThaumicTinkererRepairFix")
- .setRequiresMcRestart(true);
- enableThaumicTinkererRepairFix = prop.getBoolean(false);
- propOrderDebug.add(prop.getName());
-
- // General Features
- prop = config.get("general", "enabledLwjglKeybindingFix", true);
- prop.comment = "Prevents the game crashing from having invalid keybinds. https://github.com/alkcorp/GTplusplus/issues/544";
- prop.setLanguageKey("gtpp.enabledLwjglKeybindingFix")
- .setRequiresMcRestart(true);
- enabledLwjglKeybindingFix = prop.getBoolean(true);
- propOrder.add(prop.getName());
-
- prop = config.get("general", "enableGtTooltipFix", true);
- prop.comment = "Enable/Disable Custom GT Tooltips";
- prop.setLanguageKey("gtpp.enableGtTooltipFix")
- .setRequiresMcRestart(true);
- enableGtTooltipFix = prop.getBoolean(true);
- propOrder.add(prop.getName());
-
- prop = config.get("general", "enableGtCharcoalPitFix", true);
- prop.comment = "Makes the Charcoal Pile Igniter work better.";
- prop.setLanguageKey("gtpp.enableGtCharcoalPitFix")
- .setRequiresMcRestart(true);
- enableGtCharcoalPitFix = prop.getBoolean(true);
- propOrder.add(prop.getName());
-
- // TC Aspect Safety
- prop = config.get("general", "enableTcAspectSafety", true);
- prop.comment = "Fixes small oversights in Thaumcraft 4.";
- prop.setLanguageKey("gtpp.enableTcAspectSafety")
- .setRequiresMcRestart(true);
- enableTcAspectSafety = prop.getBoolean(true);
- propOrder.add(prop.getName());
-
- config.setCategoryPropertyOrder("general", propOrder);
- config.setCategoryPropertyOrder("debug", propOrderDebug);
- if (config.hasChanged()) {
- config.save();
- }
-
- Preloader_Logger.INFO("Gt Nbt Fix - Enabled: " + enableGtNbtFix);
- Preloader_Logger.INFO("Gt Tooltip Fix - Enabled: " + enableGtTooltipFix);
- Preloader_Logger.INFO("COFH Patch - Enabled: " + enableCofhPatch);
- Preloader_Logger.INFO("Thaumcraft Aspect Safety Patch - Enabled: " + enableTcAspectSafety);
- Preloader_Logger
- .INFO("Fix bad usage of EntityLivingBase.setHealth Patch - Enabled: " + enabledFixEntitySetHealth);
-
- } catch (Exception var3) {
- FMLLog.log(Level.ERROR, var3, "GT++ ASM had a problem loading it's config", new Object[0]);
- }
- }
-}
diff --git a/gtpp/src/main/java/gtPlusPlus/preloader/asm/Preloader_DummyContainer.java b/gtpp/src/main/java/gtPlusPlus/preloader/asm/Preloader_DummyContainer.java
deleted file mode 100644
index c77f570a8d..0000000000
--- a/gtpp/src/main/java/gtPlusPlus/preloader/asm/Preloader_DummyContainer.java
+++ /dev/null
@@ -1,70 +0,0 @@
-package gtPlusPlus.preloader.asm;
-
-import static gregtech.api.enums.Mods.GTPlusPlus;
-import static gregtech.api.enums.Mods.GregTech;
-
-import java.io.File;
-import java.util.Collections;
-
-import net.minecraftforge.common.config.Configuration;
-
-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 gtPlusPlus.preloader.CORE_Preloader;
-import gtPlusPlus.preloader.Preloader_Logger;
-
-public class Preloader_DummyContainer extends DummyModContainer {
-
- public Preloader_DummyContainer() {
- super(new ModMetadata());
- ModMetadata meta = getMetadata();
- meta.modId = CORE_Preloader.MODID;
- meta.name = CORE_Preloader.NAME;
- meta.version = CORE_Preloader.VERSION;
- meta.credits = "Roll Credits ...";
- meta.authorList = Collections.singletonList("Alkalus");
- meta.screenshots = new String[0];
- meta.parent = GTPlusPlus.ID;
- }
-
- @Override
- public boolean registerBus(EventBus bus, LoadController controller) {
- bus.register(this);
- return true;
- }
-
- @Subscribe
- public void preInit(FMLPreInitializationEvent event) {
- Preloader_Logger.INFO("Loading " + CORE_Preloader.MODID + " V" + CORE_Preloader.VERSION);
- // Handle GT++ Config
- handleConfigFile(event);
- }
-
- public static void handleConfigFile(final FMLPreInitializationEvent event) {
- final Configuration config = new Configuration(
- new File(event.getModConfigurationDirectory(), "GTplusplus/GTplusplus.cfg"));
- config.load();
-
- // BGM Watchdog
- CORE_Preloader.enableWatchdogBGM = config.getInt(
- "enableWatchdogBGM",
- "features",
- 0,
- 0,
- Short.MAX_VALUE,
- "Set to a value greater than 0 to reduce the ticks taken to delay between BGM tracks. Acceptable Values are 1-32767, where 0 is disabled. Vanilla Uses 12,000 & 24,000. 200 is 10s.");
-
- // Circuits
- CORE_Preloader.enableOldGTcircuits = config.getBoolean(
- "enableOldGTcircuits",
- GregTech.ID,
- false,
- "Restores circuits and their recipes from Pre-5.09.28 times.");
- }
-
-}
diff --git a/gtpp/src/main/java/gtPlusPlus/preloader/asm/Preloader_FMLLoadingPlugin.java b/gtpp/src/main/java/gtPlusPlus/preloader/asm/Preloader_FMLLoadingPlugin.java
deleted file mode 100644
index cdd25bb268..0000000000
--- a/gtpp/src/main/java/gtPlusPlus/preloader/asm/Preloader_FMLLoadingPlugin.java
+++ /dev/null
@@ -1,47 +0,0 @@
-package gtPlusPlus.preloader.asm;
-
-import java.io.File;
-import java.util.Map;
-
-import cpw.mods.fml.relauncher.IFMLLoadingPlugin;
-import cpw.mods.fml.relauncher.IFMLLoadingPlugin.MCVersion;
-import cpw.mods.fml.relauncher.IFMLLoadingPlugin.SortingIndex;
-import gtPlusPlus.preloader.CORE_Preloader;
-import gtPlusPlus.preloader.asm.transformers.Preloader_Transformer_Handler;
-
-@SortingIndex(10097)
-@MCVersion(value = "1.7.10")
-@IFMLLoadingPlugin.TransformerExclusions("gtPlusPlus.preloader")
-@IFMLLoadingPlugin.Name(CORE_Preloader.NAME)
-public class Preloader_FMLLoadingPlugin implements IFMLLoadingPlugin {
-
- @Override
- public String getAccessTransformerClass() {
- return null;
- }
-
- @Override
- public String[] getASMTransformerClass() {
- return new String[] { Preloader_Transformer_Handler.class.getName() };
- }
-
- @Override
- public String getModContainerClass() {
- return Preloader_DummyContainer.class.getName();
- }
-
- @Override
- public String getSetupClass() {
- return null;
- }
-
- @Override
- public void injectData(Map<String, Object> data) {
- CORE_Preloader.DEV_ENVIRONMENT = !(boolean) data.get("runtimeDeobfuscationEnabled");
- File mcDir = (File) data.get("mcLocation");
- if (mcDir != null && mcDir.exists()) {
- CORE_Preloader.setMinecraftDirectory(mcDir);
- }
- CORE_Preloader.DEBUG_MODE = AsmConfig.debugMode;
- }
-}
diff --git a/gtpp/src/main/java/gtPlusPlus/preloader/asm/transformers/ClassTransformer_COFH_OreDictionaryArbiter.java b/gtpp/src/main/java/gtPlusPlus/preloader/asm/transformers/ClassTransformer_COFH_OreDictionaryArbiter.java
deleted file mode 100644
index 0b41846928..0000000000
--- a/gtpp/src/main/java/gtPlusPlus/preloader/asm/transformers/ClassTransformer_COFH_OreDictionaryArbiter.java
+++ /dev/null
@@ -1,187 +0,0 @@
-package gtPlusPlus.preloader.asm.transformers;
-
-import static org.objectweb.asm.Opcodes.ACC_PUBLIC;
-import static org.objectweb.asm.Opcodes.ACC_STATIC;
-import static org.objectweb.asm.Opcodes.ALOAD;
-import static org.objectweb.asm.Opcodes.ASM5;
-import static org.objectweb.asm.Opcodes.INVOKESTATIC;
-import static org.objectweb.asm.Opcodes.RETURN;
-
-import java.util.ArrayList;
-
-import net.minecraft.item.ItemStack;
-import net.minecraftforge.oredict.OreDictionary;
-
-import org.apache.logging.log4j.Level;
-import org.objectweb.asm.ClassReader;
-import org.objectweb.asm.ClassVisitor;
-import org.objectweb.asm.ClassWriter;
-import org.objectweb.asm.Label;
-import org.objectweb.asm.MethodVisitor;
-
-import com.google.common.base.Strings;
-import com.google.common.collect.BiMap;
-import com.google.common.collect.HashBiMap;
-
-import cofh.core.util.oredict.OreDictionaryArbiter;
-import cofh.lib.util.ItemWrapper;
-import cpw.mods.fml.relauncher.FMLRelaunchLog;
-import gnu.trove.map.TMap;
-import gnu.trove.map.hash.THashMap;
-import gtPlusPlus.core.util.reflect.ReflectionUtils;
-
-public class ClassTransformer_COFH_OreDictionaryArbiter {
-
- // The qualified name of the class we plan to transform.
- private static final String className = "cofh.core.util.oredict.OreDictionaryArbiter";
- // cofh/core/util/oredict/OreDictionaryArbiter
-
- private final boolean isValid;
- private final ClassReader reader;
- private final ClassWriter writer;
-
- public ClassTransformer_COFH_OreDictionaryArbiter(byte[] basicClass) {
- ClassReader aTempReader = null;
- ClassWriter aTempWriter = null;
- aTempReader = new ClassReader(basicClass);
- aTempWriter = new ClassWriter(aTempReader, ClassWriter.COMPUTE_FRAMES);
- aTempReader.accept(new localClassVisitor(aTempWriter), 0);
-
- if (aTempReader != null && aTempWriter != null) {
- isValid = true;
- } else {
- isValid = false;
- }
- reader = aTempReader;
- writer = aTempWriter;
-
- if (reader != null && writer != null) {
- injectMethod("registerOreDictionaryEntry");
- }
- }
-
- public boolean isValidTransformer() {
- return isValid;
- }
-
- public ClassReader getReader() {
- return reader;
- }
-
- public ClassWriter getWriter() {
- return writer;
- }
-
- public void injectMethod(String aMethodName) {
-
- String aItemStack = "net/minecraft/item/ItemStack";
- MethodVisitor mv;
- if (aMethodName.equals("registerOreDictionaryEntry")) {
- FMLRelaunchLog.log(
- "[GT++ ASM] COFH OreDictionaryArbiter Patch",
- Level.INFO,
- "Injecting " + aMethodName + " into " + className + ". ItemStack: " + aItemStack);
- mv = getWriter().visitMethod(
- ACC_PUBLIC + ACC_STATIC,
- "registerOreDictionaryEntry",
- "(L" + aItemStack + ";Ljava/lang/String;)V",
- null,
- null);
- mv.visitCode();
- Label l0 = new Label();
- mv.visitLabel(l0);
- mv.visitLineNumber(61, l0);
- mv.visitVarInsn(ALOAD, 0);
- mv.visitVarInsn(ALOAD, 1);
- mv.visitMethodInsn(
- INVOKESTATIC,
- "gtPlusPlus/preloader/asm/transformers/ClassTransformer_COFH_OreDictionaryArbiter$FixCOFH",
- "registerOreDictionaryEntry",
- "(L" + aItemStack + ";Ljava/lang/String;)V",
- false);
- Label l1 = new Label();
- mv.visitLabel(l1);
- mv.visitLineNumber(62, l1);
- mv.visitInsn(RETURN);
- Label l2 = new Label();
- mv.visitLabel(l2);
- mv.visitLocalVariable("arg", "L" + aItemStack + ";", null, l0, l2, 0);
- mv.visitLocalVariable("arg0", "Ljava/lang/String;", null, l0, l2, 1);
- mv.visitMaxs(2, 2);
- mv.visitEnd();
- }
- FMLRelaunchLog.log("[GT++ ASM] COFH OreDictionaryArbiter Patch", Level.INFO, "Method injection complete.");
- }
-
- public static final class localClassVisitor extends ClassVisitor {
-
- public localClassVisitor(ClassVisitor cv) {
- super(ASM5, cv);
- }
-
- @Override
- public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
- if (name.equals("registerOreDictionaryEntry")) {
- FMLRelaunchLog.log("[GT++ ASM] COFH OreDictionaryArbiter Patch", Level.INFO, "Removing method " + name);
- return null;
- }
- MethodVisitor methodVisitor = super.visitMethod(access, name, desc, signature, exceptions);
- return methodVisitor;
- }
- }
-
- @SuppressWarnings("unchecked")
- public static class FixCOFH {
-
- private static BiMap<String, Integer> oreIDs;
- private static TMap<Integer, ArrayList<ItemStack>> oreStacks;
- private static TMap<ItemWrapper, ArrayList<Integer>> stackIDs;
- private static TMap<ItemWrapper, ArrayList<String>> stackNames;
-
- static {
- try {
- oreIDs = (BiMap<String, Integer>) ReflectionUtils.getField(OreDictionaryArbiter.class, "oreIDs")
- .get(null);
- oreStacks = (TMap<Integer, ArrayList<ItemStack>>) ReflectionUtils
- .getField(OreDictionaryArbiter.class, "oreStacks")
- .get(null);
- stackIDs = (TMap<ItemWrapper, ArrayList<Integer>>) ReflectionUtils
- .getField(OreDictionaryArbiter.class, "stackIDs")
- .get(null);
- stackNames = (TMap<ItemWrapper, ArrayList<String>>) ReflectionUtils
- .getField(OreDictionaryArbiter.class, "stackNames")
- .get(null);
- } catch (Throwable t) {
- oreIDs = HashBiMap.create();
- oreStacks = new THashMap<>();
- stackIDs = new THashMap<>();
- stackNames = new THashMap<>();
- }
- }
-
- public static void registerOreDictionaryEntry(ItemStack arg, String arg0) {
- try {
- if (arg == null) {
- return;
- }
- if (arg.getItem() != null && !Strings.isNullOrEmpty(arg0)) {
- int arg1 = OreDictionary.getOreID(arg0);
- oreIDs.put(arg0, Integer.valueOf(arg1));
- if (!oreStacks.containsKey(Integer.valueOf(arg1))) {
- oreStacks.put(Integer.valueOf(arg1), new ArrayList<>());
- }
- ((ArrayList<ItemStack>) oreStacks.get(Integer.valueOf(arg1))).add(arg);
- ItemWrapper arg2 = ItemWrapper.fromItemStack(arg);
- if (!stackIDs.containsKey(arg2)) {
- stackIDs.put(arg2, new ArrayList<>());
- stackNames.put(arg2, new ArrayList<>());
- }
- ((ArrayList<Integer>) stackIDs.get(arg2)).add(Integer.valueOf(arg1));
- ((ArrayList<String>) stackNames.get(arg2)).add(arg0);
- }
- } catch (Throwable t) {
- return;
- }
- }
- }
-}
diff --git a/gtpp/src/main/java/gtPlusPlus/preloader/asm/transformers/ClassTransformer_IC2_GetHarvestTool.java b/gtpp/src/main/java/gtPlusPlus/preloader/asm/transformers/ClassTransformer_IC2_GetHarvestTool.java
deleted file mode 100644
index 7aa5ff4f90..0000000000
--- a/gtpp/src/main/java/gtPlusPlus/preloader/asm/transformers/ClassTransformer_IC2_GetHarvestTool.java
+++ /dev/null
@@ -1,233 +0,0 @@
-package gtPlusPlus.preloader.asm.transformers;
-
-import static org.objectweb.asm.Opcodes.ACC_PUBLIC;
-import static org.objectweb.asm.Opcodes.ALOAD;
-import static org.objectweb.asm.Opcodes.ARETURN;
-import static org.objectweb.asm.Opcodes.ASM5;
-import static org.objectweb.asm.Opcodes.ILOAD;
-import static org.objectweb.asm.Opcodes.INVOKESTATIC;
-import static org.objectweb.asm.Opcodes.IRETURN;
-
-import java.util.Random;
-
-import net.minecraft.block.Block;
-import net.minecraft.item.Item;
-
-import org.apache.logging.log4j.Level;
-import org.objectweb.asm.ClassReader;
-import org.objectweb.asm.ClassVisitor;
-import org.objectweb.asm.ClassWriter;
-import org.objectweb.asm.Label;
-import org.objectweb.asm.MethodVisitor;
-
-import cpw.mods.fml.relauncher.FMLRelaunchLog;
-
-public class ClassTransformer_IC2_GetHarvestTool {
-
- private final boolean isValid;
- private final ClassReader reader;
- private final ClassWriter writer;
- private final String className;
-
- private final String aName_getItemDropped;
- private final String aName_damageDropped;
-
- public static String getHarvestTool(int aMeta) {
- return "wrench";
- }
-
- public static Item getItemDropped(Block aBlock, int meta, Random random, int fortune) {
- return Item.getItemFromBlock(aBlock);
- }
-
- public static int damageDropped(int aMeta) {
- return aMeta;
- }
-
- public ClassTransformer_IC2_GetHarvestTool(byte[] basicClass, boolean obfuscated, String aClassName) {
- className = aClassName;
- ClassReader aTempReader = null;
- ClassWriter aTempWriter = null;
-
- aName_getItemDropped = obfuscated ? "func_149650_a" : "getItemDropped";
- aName_damageDropped = obfuscated ? "func_149692_a" : "damageDropped";
-
- FMLRelaunchLog.log(
- "[GT++ ASM] IC2 getHarvestTool Patch",
- Level.INFO,
- "Attempting to patch in mode " + className + ". Obfuscated? " + obfuscated);
-
- aTempReader = new ClassReader(basicClass);
- aTempWriter = new ClassWriter(aTempReader, ClassWriter.COMPUTE_FRAMES);
- aTempReader.accept(new localClassVisitor(aTempWriter, className), 0);
-
- if (aTempReader != null && aTempWriter != null) {
- isValid = true;
- } else {
- isValid = false;
- }
-
- FMLRelaunchLog.log("[GT++ ASM] IC2 getHarvestTool Patch", Level.INFO, "Valid patch? " + isValid + ".");
- reader = aTempReader;
- writer = aTempWriter;
-
- if (reader != null && writer != null) {
- FMLRelaunchLog.log("[GT++ ASM] IC2 getHarvestTool Patch", Level.INFO, "Attempting Method Injection.");
- injectMethod("getHarvestTool");
- if (aClassName.equals("ic2.core.block.machine.BlockMachine2")
- || aClassName.equals("ic2.core.block.machine.BlockMachine3")
- || aClassName.equals("ic2.core.block.wiring.BlockElectric")) {
- injectMethod(aName_getItemDropped);
- injectMethod(aName_damageDropped);
- } else if (aClassName.equals("ic2.core.block.generator.block.BlockGenerator")
- || aClassName.equals("ic2.core.block.machine.BlockMachine")) {
- injectMethod(aName_damageDropped);
- }
- }
- }
-
- public boolean isValidTransformer() {
- return isValid;
- }
-
- public ClassReader getReader() {
- return reader;
- }
-
- public ClassWriter getWriter() {
- return writer;
- }
-
- public boolean injectMethod(String aMethodName) {
- MethodVisitor mv;
- boolean didInject = false;
- String aFormattedClassName = className.replace('.', '/');
- ClassWriter cw = getWriter();
-
- FMLRelaunchLog.log("[GT++ ASM] IC2 getHarvestTool Patch", Level.INFO, "Injecting " + aMethodName + ".");
- if (aMethodName.equals("getHarvestTool")) {
- mv = getWriter().visitMethod(ACC_PUBLIC, "getHarvestTool", "(I)Ljava/lang/String;", null, null);
- mv.visitCode();
- Label l0 = new Label();
- mv.visitLabel(l0);
- mv.visitLineNumber(63, l0);
- mv.visitVarInsn(ILOAD, 1);
- mv.visitMethodInsn(
- INVOKESTATIC,
- "gtPlusPlus/preloader/asm/transformers/ClassTransformer_IC2_GetHarvestTool",
- "getHarvestTool",
- "(I)Ljava/lang/String;",
- false);
- mv.visitInsn(ARETURN);
- Label l1 = new Label();
- mv.visitLabel(l1);
- mv.visitLocalVariable("this", "L" + aFormattedClassName + ";", null, l0, l1, 0);
- mv.visitLocalVariable("aMeta", "I", null, l0, l1, 1);
- mv.visitMaxs(1, 2);
- mv.visitEnd();
- didInject = true;
- } else if (aMethodName.equals(aName_getItemDropped)) {
- mv = cw.visitMethod(
- ACC_PUBLIC,
- aName_getItemDropped,
- "(ILjava/util/Random;I)Lnet/minecraft/item/Item;",
- null,
- null);
- mv.visitCode();
- Label l0 = new Label();
- mv.visitLabel(l0);
- mv.visitLineNumber(44, l0);
- mv.visitVarInsn(ALOAD, 0);
- mv.visitVarInsn(ILOAD, 1);
- mv.visitVarInsn(ALOAD, 2);
- mv.visitVarInsn(ILOAD, 3);
- mv.visitMethodInsn(
- INVOKESTATIC,
- "gtPlusPlus/preloader/asm/transformers/ClassTransformer_IC2_GetHarvestTool",
- "getItemDropped",
- "(Lnet/minecraft/block/Block;ILjava/util/Random;I)Lnet/minecraft/item/Item;",
- false);
- mv.visitInsn(ARETURN);
- Label l1 = new Label();
- mv.visitLabel(l1);
- mv.visitLocalVariable("this", "L" + aFormattedClassName + ";", null, l0, l1, 0);
- mv.visitLocalVariable("meta", "I", null, l0, l1, 1);
- mv.visitLocalVariable("random", "Ljava/util/Random;", null, l0, l1, 2);
- mv.visitLocalVariable("fortune", "I", null, l0, l1, 3);
- mv.visitMaxs(4, 4);
- mv.visitEnd();
- didInject = true;
- } else if (aMethodName.equals(aName_damageDropped)) {
- mv = cw.visitMethod(ACC_PUBLIC, aName_damageDropped, "(I)I", null, null);
- mv.visitCode();
- Label l0 = new Label();
- mv.visitLabel(l0);
- mv.visitLineNumber(48, l0);
- mv.visitVarInsn(ILOAD, 1);
- mv.visitMethodInsn(
- INVOKESTATIC,
- "gtPlusPlus/preloader/asm/transformers/ClassTransformer_IC2_GetHarvestTool",
- "damageDropped",
- "(I)I",
- false);
- mv.visitInsn(IRETURN);
- Label l1 = new Label();
- mv.visitLabel(l1);
- mv.visitLocalVariable("this", "L" + aFormattedClassName + ";", null, l0, l1, 0);
- mv.visitLocalVariable("meta", "I", null, l0, l1, 1);
- mv.visitMaxs(1, 2);
- mv.visitEnd();
- didInject = true;
- }
- FMLRelaunchLog.log("[GT++ ASM] IC2 getHarvestTool Patch", Level.INFO, "Method injection complete.");
- return didInject;
- }
-
- public final class localClassVisitor extends ClassVisitor {
-
- String aClassName;
-
- public localClassVisitor(ClassVisitor cv, String aName) {
- super(ASM5, cv);
- aClassName = aName;
- }
-
- @Override
- public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
- MethodVisitor methodVisitor;
- if (aClassName.equals("ic2.core.block.machine.BlockMachine2")
- || aClassName.equals("ic2.core.block.machine.BlockMachine3")
- || aClassName.equals("ic2.core.block.wiring.BlockElectric")) {
- if (name.equals(aName_getItemDropped)) {
- methodVisitor = null;
- } else if (name.equals(aName_damageDropped)) {
- methodVisitor = null;
- } else if (name.equals("getHarvestTool")) {
- methodVisitor = null;
- } else {
- methodVisitor = super.visitMethod(access, name, desc, signature, exceptions);
- }
- } else if (aClassName.equals("ic2.core.block.generator.block.BlockGenerator")
- || aClassName.equals("ic2.core.block.machine.BlockMachine")) {
- if (name.equals(aName_damageDropped)) {
- methodVisitor = null;
- } else if (name.equals("getHarvestTool")) {
- methodVisitor = null;
- } else {
- methodVisitor = super.visitMethod(access, name, desc, signature, exceptions);
- }
- } else {
- if (name.equals("getHarvestTool")) {
- methodVisitor = null;
- } else {
- methodVisitor = super.visitMethod(access, name, desc, signature, exceptions);
- }
- }
- if (methodVisitor == null) {
- FMLRelaunchLog
- .log("[GT++ ASM] IC2 getHarvestTool Patch", Level.INFO, "Found method " + name + ", removing.");
- }
- return methodVisitor;
- }
- }
-}
diff --git a/gtpp/src/main/java/gtPlusPlus/preloader/asm/transformers/ClassTransformer_LWJGL_Keyboard.java b/gtpp/src/main/java/gtPlusPlus/preloader/asm/transformers/ClassTransformer_LWJGL_Keyboard.java
deleted file mode 100644
index 4d3c78e6bd..0000000000
--- a/gtpp/src/main/java/gtPlusPlus/preloader/asm/transformers/ClassTransformer_LWJGL_Keyboard.java
+++ /dev/null
@@ -1,297 +0,0 @@
-package gtPlusPlus.preloader.asm.transformers;
-
-import static org.objectweb.asm.Opcodes.ACC_PUBLIC;
-import static org.objectweb.asm.Opcodes.ACC_STATIC;
-import static org.objectweb.asm.Opcodes.ACC_SYNCHRONIZED;
-import static org.objectweb.asm.Opcodes.ARETURN;
-import static org.objectweb.asm.Opcodes.ASM5;
-import static org.objectweb.asm.Opcodes.ILOAD;
-import static org.objectweb.asm.Opcodes.INVOKESTATIC;
-
-import java.lang.reflect.Field;
-import java.util.HashMap;
-
-import net.minecraft.client.Minecraft;
-import net.minecraft.client.settings.GameSettings;
-import net.minecraft.client.settings.KeyBinding;
-
-import org.apache.logging.log4j.Level;
-import org.objectweb.asm.ClassReader;
-import org.objectweb.asm.ClassVisitor;
-import org.objectweb.asm.ClassWriter;
-import org.objectweb.asm.Label;
-import org.objectweb.asm.MethodVisitor;
-
-import cpw.mods.fml.relauncher.FMLRelaunchLog;
-import gtPlusPlus.core.util.Utils;
-import gtPlusPlus.core.util.reflect.ReflectionUtils;
-
-public class ClassTransformer_LWJGL_Keyboard {
-
- private final boolean isValid;
- private final ClassReader reader;
- private final ClassWriter writer;
-
- private static final HashMap<String, String> mBadKeyCache = new HashMap<>();
-
- /**
- * Gets a key's name
- *
- * @param key The key
- * @return a String with the key's human readable name in it or null if the key is unnamed
- */
- public static synchronized String getKeyName(int key) {
- if (init()) {
- String[] aTemp = getKeyName();
- if (key < aTemp.length && key >= 0) {
- return aTemp[key];
- }
- }
- String aCachedValue = mBadKeyCache.get("key-" + key);
- if (aCachedValue == null) {
- FMLRelaunchLog.log(
- "[GT++ ASM] LWJGL Keybinding index out of bounds fix",
- Level.INFO,
- "Unable to map key code " + key + " to LWJGL keymap.");
- FMLRelaunchLog.log(
- "[GT++ ASM] LWJGL Keybinding index out of bounds fix",
- Level.INFO,
- "Caching key value to be empty.");
- // mBadKeyCache.put("key-"+key, getKeyName()[0x00]);
- aCachedValue = "FIX!";
- mBadKeyCache.put("key-" + key, aCachedValue);
- trySetClientKey(key);
- }
- return aCachedValue; // Return nothing
- }
-
- public static void trySetClientKey(int aKey) {
- if (Utils.isClient() && ReflectionUtils.doesClassExist("net.minecraft.client.Minecraft")) {
- FMLRelaunchLog.log(
- "[GT++ ASM] LWJGL Keybinding index out of bounds fix",
- Level.INFO,
- "Trying to set key value to be empty.");
- GameSettings options = Minecraft.getMinecraft().gameSettings;
- KeyBinding[] akeybinding = Minecraft.getMinecraft().gameSettings.keyBindings;
- int i = akeybinding.length;
- for (KeyBinding keybinding : akeybinding) {
- if (keybinding != null && keybinding.getKeyCode() == aKey) {
- options.setOptionKeyBinding(keybinding, 0);
- FMLRelaunchLog.log(
- "[GT++ ASM] LWJGL Keybinding index out of bounds fix",
- Level.INFO,
- "Set keybind " + aKey + " to 0.");
- break;
- }
- }
- }
- }
-
- @SuppressWarnings("rawtypes")
- private static Class mKeyboard;
-
- private static Field mKeyName;
-
- @SuppressWarnings("rawtypes")
- private static boolean init() {
- if (mKeyName != null) {
- return true;
- }
- Class aKeyboard = ReflectionUtils.getClass("org.lwjgl.input.Keyboard");
- if (aKeyboard != null) {
- mKeyboard = aKeyboard;
- Field aKeyName = ReflectionUtils.getField(mKeyboard, "keyName");
- if (aKeyName != null) {
- mKeyName = aKeyName;
- }
- }
- return mKeyName != null;
- }
-
- private static String[] getKeyName() {
- if (init()) {