From 655bc994aea1da4594bdbe3bb6f3ce3e79060aca Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Sun, 19 Jan 2020 15:39:29 +0000 Subject: $ Made Keybind patch reset value to 0, if possible. $ Made it more obvious which keybinds are broken (if resetting value fails) within the controls menu. They now say "FIX!". --- .../ClassTransformer_LWJGL_Keyboard.java | 37 ++++++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) (limited to 'src/Java') diff --git a/src/Java/gtPlusPlus/preloader/asm/transformers/ClassTransformer_LWJGL_Keyboard.java b/src/Java/gtPlusPlus/preloader/asm/transformers/ClassTransformer_LWJGL_Keyboard.java index 929b443d33..3ec4426ec1 100644 --- a/src/Java/gtPlusPlus/preloader/asm/transformers/ClassTransformer_LWJGL_Keyboard.java +++ b/src/Java/gtPlusPlus/preloader/asm/transformers/ClassTransformer_LWJGL_Keyboard.java @@ -9,6 +9,7 @@ import static org.objectweb.asm.Opcodes.ILOAD; import static org.objectweb.asm.Opcodes.INVOKESTATIC; import java.lang.reflect.Field; +import java.util.HashMap; import org.apache.logging.log4j.Level; import org.objectweb.asm.ClassReader; @@ -18,8 +19,11 @@ import org.objectweb.asm.Label; import org.objectweb.asm.MethodVisitor; import cpw.mods.fml.relauncher.FMLRelaunchLog; -import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.util.Utils; import gtPlusPlus.core.util.reflect.ReflectionUtils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.settings.GameSettings; +import net.minecraft.client.settings.KeyBinding; public class ClassTransformer_LWJGL_Keyboard { @@ -27,6 +31,8 @@ public class ClassTransformer_LWJGL_Keyboard { private final ClassReader reader; private final ClassWriter writer; + private static final HashMap mBadKeyCache = new HashMap(); + /** * Gets a key's name * @@ -41,8 +47,33 @@ public class ClassTransformer_LWJGL_Keyboard { return aTemp[key]; } } - Logger.INFO("Unable to map key code "+key+" to LWJGL keymap."); - return getKeyName()[0x00]; // Return nothing + 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 (int j = 0; j < i; ++j) { + KeyBinding keybinding = akeybinding[j]; + 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") -- cgit