aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/preloader/asm
diff options
context:
space:
mode:
authorAlkalus <3060479+draknyte1@users.noreply.github.com>2020-01-19 15:39:29 +0000
committerAlkalus <3060479+draknyte1@users.noreply.github.com>2020-01-19 15:39:29 +0000
commit655bc994aea1da4594bdbe3bb6f3ce3e79060aca (patch)
tree63433f27397c0cff3c824edcb266bf9d9ae36516 /src/Java/gtPlusPlus/preloader/asm
parent34646419362b3b2a5a26d77310dada90bce8fa77 (diff)
downloadGT5-Unofficial-655bc994aea1da4594bdbe3bb6f3ce3e79060aca.tar.gz
GT5-Unofficial-655bc994aea1da4594bdbe3bb6f3ce3e79060aca.tar.bz2
GT5-Unofficial-655bc994aea1da4594bdbe3bb6f3ce3e79060aca.zip
$ 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!".
Diffstat (limited to 'src/Java/gtPlusPlus/preloader/asm')
-rw-r--r--src/Java/gtPlusPlus/preloader/asm/transformers/ClassTransformer_LWJGL_Keyboard.java37
1 files changed, 34 insertions, 3 deletions
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<String, String> mBadKeyCache = new HashMap<String, String>();
+
/**
* 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")