From 00bcb6f698985dd287018703658bd0e6f07708ff Mon Sep 17 00:00:00 2001 From: jrbudda Date: Wed, 8 Mar 2017 21:49:22 -0500 Subject: [PATCH] 38 pre --- minecriftversion.py | 2 +- .../net/minecraft/client/Minecraft.java.patch | 12 +- .../minecraft/client/gui/GuiChat.java.patch | 21 ++- .../net/minecraft/client/main/Main.java.patch | 13 ++ .../network/NetHandlerPlayServer.java.patch | 9 + .../mtbs3d/minecrift/provider/MCOpenVR.java | 28 +-- .../provider/OpenVRStereoRenderer.java | 6 +- .../minecrift/utils/KeyboardSimulator.java | 130 +++++++++++++- .../mtbs3d/minecrift/utils/MCReflection.java | 164 ++++++++++++++++++ 9 files changed, 349 insertions(+), 36 deletions(-) create mode 100644 patches/net/minecraft/client/main/Main.java.patch create mode 100644 src/com/mtbs3d/minecrift/utils/MCReflection.java diff --git a/minecriftversion.py b/minecriftversion.py index 11a98145..9b4944d6 100644 --- a/minecriftversion.py +++ b/minecriftversion.py @@ -4,7 +4,7 @@ of_json_name = "1.7.10_HD_U_D1" of_file_md5 = "57c724fe8335c82aef8d54c101043e60" minecrift_version_num = "1.7.10" -minecrift_build = "jrbudda-37r1" +minecrift_build = "jrbudda-38pre" of_file_extension = ".jar" mcp_version = "mcp908" mcp_uses_generics = False diff --git a/patches/net/minecraft/client/Minecraft.java.patch b/patches/net/minecraft/client/Minecraft.java.patch index 370632f7..c658d523 100644 --- a/patches/net/minecraft/client/Minecraft.java.patch +++ b/patches/net/minecraft/client/Minecraft.java.patch @@ -1246,7 +1246,7 @@ + * The minecriftVerString will be automatically updated by the build scripts, do not modify here. + * Modify minecriftversion.py in root minecrift dir. + */ -+ public final String minecriftVerString = "Vivecraft 1.7.10 jrbudda-37r1"; ++ public final String minecriftVerString = "Vivecraft 1.7.10 jrbudda-38pre"; + private boolean trigger; + /* end version */ + /** END MINECRIFT */ @@ -5157,11 +5157,11 @@ + this.reinitFramebuffers = true; + } + -+ if (!Display.isActive() && this.fullscreen) -+ { -+ this.toggleFullscreen(); -+ this.reinitFramebuffers = true; -+ } ++// if (!Display.isActive() && this.fullscreen) ++// { ++// this.toggleFullscreen(); ++// this.reinitFramebuffers = true; ++// } + + if (wasDisplayResized()) + { diff --git a/patches/net/minecraft/client/gui/GuiChat.java.patch b/patches/net/minecraft/client/gui/GuiChat.java.patch index 42d162dd..784b46c3 100644 --- a/patches/net/minecraft/client/gui/GuiChat.java.patch +++ b/patches/net/minecraft/client/gui/GuiChat.java.patch @@ -1,6 +1,15 @@ --- a/net/minecraft/client/gui/GuiChat.java +++ b/net/minecraft/client/gui/GuiChat.java -@@ -118,9 +118,9 @@ +@@ -3,6 +3,8 @@ + import com.google.common.base.Splitter; + import com.google.common.collect.Lists; + import com.google.common.collect.Sets; ++import com.mtbs3d.minecrift.provider.MCOpenVR; ++ + import java.io.File; + import java.net.URI; + import java.net.URISyntaxException; +@@ -118,9 +120,9 @@ this.playerNamesFound = false; } @@ -12,7 +21,7 @@ } else if (keyCode != 28 && keyCode != 156) { -@@ -153,8 +153,11 @@ +@@ -153,8 +155,15 @@ { this.submitChatMessage(var3); } @@ -21,12 +30,16 @@ + + //VIVE DONT CLOSE ON RETURN + // this.mc.displayGuiScreen((GuiScreen)null); -+ this.inputField.setText(""); ++ if (MCOpenVR.keyboardShowing) { ++ this.inputField.setText(""); ++ } else { ++ this.mc.displayGuiScreen((GuiScreen)null); ++ } + } } -@@ -184,7 +187,7 @@ +@@ -184,7 +193,7 @@ var1 = -1; } diff --git a/patches/net/minecraft/client/main/Main.java.patch b/patches/net/minecraft/client/main/Main.java.patch new file mode 100644 index 00000000..0826d7fb --- /dev/null +++ b/patches/net/minecraft/client/main/Main.java.patch @@ -0,0 +1,13 @@ +--- a/net/minecraft/client/main/Main.java ++++ b/net/minecraft/client/main/Main.java +@@ -77,8 +77,8 @@ + ArgumentAcceptingOptionSpec var12 = var1.accepts("uuid").withRequiredArg(); + ArgumentAcceptingOptionSpec var13 = var1.accepts("accessToken").withRequiredArg().required(); + ArgumentAcceptingOptionSpec var14 = var1.accepts("version").withRequiredArg().required(); +- ArgumentAcceptingOptionSpec var15 = var1.accepts("width").withRequiredArg().ofType(Integer.class).defaultsTo(Integer.valueOf(854), new Integer[0]); +- ArgumentAcceptingOptionSpec var16 = var1.accepts("height").withRequiredArg().ofType(Integer.class).defaultsTo(Integer.valueOf(480), new Integer[0]); ++ ArgumentAcceptingOptionSpec var15 = var1.accepts("width").withRequiredArg().ofType(Integer.class).defaultsTo(Integer.valueOf(1280), new Integer[0]); ++ ArgumentAcceptingOptionSpec var16 = var1.accepts("height").withRequiredArg().ofType(Integer.class).defaultsTo(Integer.valueOf(720), new Integer[0]); + ArgumentAcceptingOptionSpec var17 = var1.accepts("userProperties").withRequiredArg().required(); + ArgumentAcceptingOptionSpec var18 = var1.accepts("assetIndex").withRequiredArg(); + ArgumentAcceptingOptionSpec var19 = var1.accepts("userType").withRequiredArg().defaultsTo("legacy", new String[0]); diff --git a/patches/net/minecraft/network/NetHandlerPlayServer.java.patch b/patches/net/minecraft/network/NetHandlerPlayServer.java.patch index e7250cae..3742c34a 100644 --- a/patches/net/minecraft/network/NetHandlerPlayServer.java.patch +++ b/patches/net/minecraft/network/NetHandlerPlayServer.java.patch @@ -102,6 +102,15 @@ { this.setPlayerLocation(this.lastPosX, this.lastPosY, this.lastPosZ, var11, var12); return; +@@ -468,7 +472,7 @@ + double var11 = this.playerEntity.posZ - ((double)var6 + 0.5D); + double var13 = var7 * var7 + var9 * var9 + var11 * var11; + +- if (var13 > 36.0D) ++ if (var13 > 262144.0D) + { + return; + } @@ -1129,20 +1133,20 @@ { var3 = var2.readItemStackFromBuffer(); diff --git a/src/com/mtbs3d/minecrift/provider/MCOpenVR.java b/src/com/mtbs3d/minecrift/provider/MCOpenVR.java index ee31d4fe..14b6c832 100644 --- a/src/com/mtbs3d/minecrift/provider/MCOpenVR.java +++ b/src/com/mtbs3d/minecrift/provider/MCOpenVR.java @@ -7,6 +7,7 @@ import com.mtbs3d.minecrift.settings.VRHotkeys; import com.mtbs3d.minecrift.settings.VRSettings; import com.mtbs3d.minecrift.utils.KeyboardSimulator; +import com.mtbs3d.minecrift.utils.MCReflection; import com.sun.jna.Memory; import com.sun.jna.NativeLibrary; import com.sun.jna.Pointer; @@ -999,7 +1000,7 @@ else if (controllerMouseX == -1.0f) if (pressedLMB || pressedRMB) { - {mc.thePlayer.closeScreen();} + // {mc.thePlayer.closeScreen();} } } } @@ -1846,6 +1847,16 @@ private static void pollInputEvents() case EVREventType.EVREventType_VREvent_KeyboardClosed: //'huzzah' keyboardShowing = false; + if (mc.currentScreen instanceof GuiChat) { + GuiTextField field = (GuiTextField)MCReflection.getField(MCReflection.chatInputField, mc.currentScreen); + if (field != null) { + String s = field.getText().trim(); + if (!s.isEmpty()) { + ((GuiChat)mc.currentScreen).submitChatMessage(s); + } + } + mc.displayGuiScreen((GuiScreen)null); + } break; case EVREventType.EVREventType_VREvent_KeyboardCharInput: byte[] inbytes = event.data.getPointer().getByteArray(0, 8); @@ -1857,18 +1868,9 @@ private static void pollInputEvents() if (mc.currentScreen != null) { // experimental, needs testing try { for (char ch : str.toCharArray()) { - switch (ch) { - case '\r': - case '\n': - case '\t': - case '\b': - KeyboardSimulator.type(ch); - break; - default: - int[] codes = KeyboardSimulator.getCodes(ch); - mc.currentScreen.keyTypedPublic(ch, codes.length > 0 ? codes[codes.length - 1] : 0); - break; - } + int[] codes = KeyboardSimulator.getLWJGLCodes(ch); + mc.currentScreen.keyTypedPublic(ch, codes.length > 0 ? codes[codes.length - 1] : 0); + break; } } catch (Exception e) { e.printStackTrace(); diff --git a/src/com/mtbs3d/minecrift/provider/OpenVRStereoRenderer.java b/src/com/mtbs3d/minecrift/provider/OpenVRStereoRenderer.java index 5cfc8b6d..86295867 100644 --- a/src/com/mtbs3d/minecrift/provider/OpenVRStereoRenderer.java +++ b/src/com/mtbs3d/minecrift/provider/OpenVRStereoRenderer.java @@ -42,11 +42,11 @@ public RenderTextureInfo getRenderTextureSizes(float renderScaleFactor) RenderTextureInfo info = new RenderTextureInfo(); info.HmdNativeResolution.w = rtx.getValue(); - info.HmdNativeResolution.h = rtx.getValue(); + info.HmdNativeResolution.h = rty.getValue(); info.LeftFovTextureResolution.w = (int) (rtx.getValue()); - info.LeftFovTextureResolution.h = (int) (rtx.getValue()); + info.LeftFovTextureResolution.h = (int) (rty.getValue()); info.RightFovTextureResolution.w = (int) (rtx.getValue()); - info.RightFovTextureResolution.h = (int) (rtx.getValue()); + info.RightFovTextureResolution.h = (int) (rty.getValue()); if ( info.LeftFovTextureResolution.w % 2 != 0) info.LeftFovTextureResolution.w++; if ( info.LeftFovTextureResolution.h % 2 != 0) info.LeftFovTextureResolution.w++; if ( info.RightFovTextureResolution.w % 2 != 0) info.LeftFovTextureResolution.w++; diff --git a/src/com/mtbs3d/minecrift/utils/KeyboardSimulator.java b/src/com/mtbs3d/minecrift/utils/KeyboardSimulator.java index 5a55dc75..3468c688 100644 --- a/src/com/mtbs3d/minecrift/utils/KeyboardSimulator.java +++ b/src/com/mtbs3d/minecrift/utils/KeyboardSimulator.java @@ -1,10 +1,16 @@ package com.mtbs3d.minecrift.utils; +import net.minecraft.client.Minecraft; + +import org.lwjgl.input.Keyboard; +import org.lwjgl.opengl.Display; + import static java.awt.event.KeyEvent.*; import java.awt.AWTException; import java.awt.Robot; + public class KeyboardSimulator { public static Robot robot; @@ -12,6 +18,7 @@ public class KeyboardSimulator { try { robot = new Robot(); } catch (AWTException e) { + e.printStackTrace(); } } @@ -143,8 +150,114 @@ public static int[] getCodes(char character) { case ' ': return codes(VK_SPACE); case '\b': return codes(VK_BACK_SPACE); case '\r': return codes(VK_ENTER); - default: - throw new IllegalArgumentException("Cannot type character " + character); + default: return codes(); + //default: throw new IllegalArgumentException("Cannot type character " + character); + } + } + + public static int[] getLWJGLCodes(char character) { + switch (character) { + case 'a': return codes(Keyboard.KEY_A); + case 'b': return codes(Keyboard.KEY_B); + case 'c': return codes(Keyboard.KEY_C); + case 'd': return codes(Keyboard.KEY_D); + case 'e': return codes(Keyboard.KEY_E); + case 'f': return codes(Keyboard.KEY_F); + case 'g': return codes(Keyboard.KEY_G); + case 'h': return codes(Keyboard.KEY_H); + case 'i': return codes(Keyboard.KEY_I); + case 'j': return codes(Keyboard.KEY_J); + case 'k': return codes(Keyboard.KEY_K); + case 'l': return codes(Keyboard.KEY_L); + case 'm': return codes(Keyboard.KEY_M); + case 'n': return codes(Keyboard.KEY_N); + case 'o': return codes(Keyboard.KEY_O); + case 'p': return codes(Keyboard.KEY_P); + case 'q': return codes(Keyboard.KEY_Q); + case 'r': return codes(Keyboard.KEY_R); + case 's': return codes(Keyboard.KEY_S); + case 't': return codes(Keyboard.KEY_T); + case 'u': return codes(Keyboard.KEY_U); + case 'v': return codes(Keyboard.KEY_V); + case 'w': return codes(Keyboard.KEY_W); + case 'x': return codes(Keyboard.KEY_X); + case 'y': return codes(Keyboard.KEY_Y); + case 'z': return codes(Keyboard.KEY_Z); + case 'A': return codes(Keyboard.KEY_LSHIFT, Keyboard.KEY_A); + case 'B': return codes(Keyboard.KEY_LSHIFT, Keyboard.KEY_B); + case 'C': return codes(Keyboard.KEY_LSHIFT, Keyboard.KEY_C); + case 'D': return codes(Keyboard.KEY_LSHIFT, Keyboard.KEY_D); + case 'E': return codes(Keyboard.KEY_LSHIFT, Keyboard.KEY_E); + case 'F': return codes(Keyboard.KEY_LSHIFT, Keyboard.KEY_F); + case 'G': return codes(Keyboard.KEY_LSHIFT, Keyboard.KEY_G); + case 'H': return codes(Keyboard.KEY_LSHIFT, Keyboard.KEY_H); + case 'I': return codes(Keyboard.KEY_LSHIFT, Keyboard.KEY_I); + case 'J': return codes(Keyboard.KEY_LSHIFT, Keyboard.KEY_J); + case 'K': return codes(Keyboard.KEY_LSHIFT, Keyboard.KEY_K); + case 'L': return codes(Keyboard.KEY_LSHIFT, Keyboard.KEY_L); + case 'M': return codes(Keyboard.KEY_LSHIFT, Keyboard.KEY_M); + case 'N': return codes(Keyboard.KEY_LSHIFT, Keyboard.KEY_N); + case 'O': return codes(Keyboard.KEY_LSHIFT, Keyboard.KEY_O); + case 'P': return codes(Keyboard.KEY_LSHIFT, Keyboard.KEY_P); + case 'Q': return codes(Keyboard.KEY_LSHIFT, Keyboard.KEY_Q); + case 'R': return codes(Keyboard.KEY_LSHIFT, Keyboard.KEY_R); + case 'S': return codes(Keyboard.KEY_LSHIFT, Keyboard.KEY_S); + case 'T': return codes(Keyboard.KEY_LSHIFT, Keyboard.KEY_T); + case 'U': return codes(Keyboard.KEY_LSHIFT, Keyboard.KEY_U); + case 'V': return codes(Keyboard.KEY_LSHIFT, Keyboard.KEY_V); + case 'W': return codes(Keyboard.KEY_LSHIFT, Keyboard.KEY_W); + case 'X': return codes(Keyboard.KEY_LSHIFT, Keyboard.KEY_X); + case 'Y': return codes(Keyboard.KEY_LSHIFT, Keyboard.KEY_Y); + case 'Z': return codes(Keyboard.KEY_LSHIFT, Keyboard.KEY_Z); + case '`': return codes(Keyboard.KEY_GRAVE); + case '0': return codes(Keyboard.KEY_0); + case '1': return codes(Keyboard.KEY_1); + case '2': return codes(Keyboard.KEY_2); + case '3': return codes(Keyboard.KEY_3); + case '4': return codes(Keyboard.KEY_4); + case '5': return codes(Keyboard.KEY_5); + case '6': return codes(Keyboard.KEY_6); + case '7': return codes(Keyboard.KEY_7); + case '8': return codes(Keyboard.KEY_8); + case '9': return codes(Keyboard.KEY_9); + case '-': return codes(Keyboard.KEY_MINUS); + case '=': return codes(Keyboard.KEY_EQUALS); + case '~': return codes(Keyboard.KEY_LSHIFT, Keyboard.KEY_B); + case '!': return codes(Keyboard.KEY_LSHIFT, Keyboard.KEY_1); + case '@': return codes(Keyboard.KEY_LSHIFT, Keyboard.KEY_2); + case '#': return codes(Keyboard.KEY_LSHIFT, Keyboard.KEY_3); + case '$': return codes(Keyboard.KEY_LSHIFT, Keyboard.KEY_4); + case '%': return codes(Keyboard.KEY_LSHIFT, Keyboard.KEY_5); + case '^': return codes(Keyboard.KEY_LSHIFT, Keyboard.KEY_6); + case '&': return codes(Keyboard.KEY_LSHIFT, Keyboard.KEY_7); + case '*': return codes(Keyboard.KEY_LSHIFT, Keyboard.KEY_8); + case '(': return codes(Keyboard.KEY_LSHIFT, Keyboard.KEY_9); + case ')': return codes(Keyboard.KEY_LSHIFT, Keyboard.KEY_0); + case '_': return codes(Keyboard.KEY_LSHIFT, Keyboard.KEY_MINUS); + case '+': return codes(Keyboard.KEY_LSHIFT, Keyboard.KEY_EQUALS); + case '\t': return codes(Keyboard.KEY_TAB); + case '\n': return codes(Keyboard.KEY_RETURN); + case '[': return codes(Keyboard.KEY_LBRACKET); + case ']': return codes(Keyboard.KEY_RBRACKET); + case '\\': return codes(Keyboard.KEY_BACKSLASH); + case '{': return codes(Keyboard.KEY_LSHIFT, Keyboard.KEY_LBRACKET); + case '}': return codes(Keyboard.KEY_LSHIFT, Keyboard.KEY_RBRACKET); + case '|': return codes(Keyboard.KEY_LSHIFT, Keyboard.KEY_BACKSLASH); + case ';': return codes(Keyboard.KEY_SEMICOLON); + case ':': return codes(Keyboard.KEY_LSHIFT, Keyboard.KEY_SEMICOLON); + case '\'': return codes(Keyboard.KEY_APOSTROPHE); + case '"': return codes(Keyboard.KEY_LSHIFT, Keyboard.KEY_APOSTROPHE); + case ',': return codes(Keyboard.KEY_COMMA); + case '<': return codes(Keyboard.KEY_LSHIFT, Keyboard.KEY_COMMA); + case '.': return codes(Keyboard.KEY_PERIOD); + case '>': return codes(Keyboard.KEY_LSHIFT, Keyboard.KEY_PERIOD); + case '/': return codes(Keyboard.KEY_SLASH); + case '?': return codes(Keyboard.KEY_LSHIFT, Keyboard.KEY_SLASH); + case ' ': return codes(Keyboard.KEY_SPACE); + case '\b': return codes(Keyboard.KEY_BACK); + case '\r': return codes(Keyboard.KEY_RETURN); + default: return codes(); + //default: throw new IllegalArgumentException("Cannot type character " + character); } } @@ -154,13 +267,12 @@ private static int[] codes(int... keyCodes) { private static void doType(int[] keyCodes, int offset, int length) { try { - - if (length == 0) { - return; - } - robot.keyPress(keyCodes[offset]); - doType(keyCodes, offset + 1, length - 1); - robot.keyRelease(keyCodes[offset]); + if (length == 0) { + return; + } + robot.keyPress(keyCodes[offset]); + doType(keyCodes, offset + 1, length - 1); + robot.keyRelease(keyCodes[offset]); } catch (Exception e) { System.out.println("Cannot type keycode: " + keyCodes[offset]); } diff --git a/src/com/mtbs3d/minecrift/utils/MCReflection.java b/src/com/mtbs3d/minecrift/utils/MCReflection.java new file mode 100644 index 00000000..752dd87a --- /dev/null +++ b/src/com/mtbs3d/minecrift/utils/MCReflection.java @@ -0,0 +1,164 @@ +package com.mtbs3d.minecrift.utils; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; + +import com.google.common.base.Throwables; + +import net.minecraft.client.audio.SoundManager; +import net.minecraft.client.gui.GuiChat; +import net.minecraft.client.multiplayer.PlayerControllerMP; +import net.minecraft.world.WorldProvider; + +public class MCReflection { + public static Field chatInputField = getDeclaredField(GuiChat.class, "inputField", "a", "field_146415_a"); + + public static Object getField(Field field, Object obj) { + try { + return field.get(obj); + } catch (ReflectiveOperationException e) { + Throwables.propagate(e); + } + return null; // shut up compiler + } + + public static void setField(Field field, Object obj, Object value) { + try { + field.set(obj, value); + } catch (ReflectiveOperationException e) { + Throwables.propagate(e); + } + } + + public static Object invokeMethod(Method method, Object obj, Object... args) { + try { + return method.invoke(obj, args); + } catch (ReflectiveOperationException e) { + Throwables.propagate(e); + } + return null; // shut up compiler + } + + public static Object invokeConstructor(Constructor constructor, Object... args) { + try { + return constructor.newInstance(args); + } catch (ReflectiveOperationException e) { + Throwables.propagate(e); + } + return null; // shut up compiler + } + + public static Class getClassForName(String name) { + Class clazz = null; + + try + { + clazz = Class.forName(name); + } + catch (ClassNotFoundException e) + { + System.out.println("[Vivecraft] WARNING: could not reflect class " + name); + } + + return clazz; + } + + public static Field getDeclaredField(Class clazz, String unObfuscatedName, String obfuscatedName, String srgName) + { + Field field = null; + + try + { + field = clazz.getDeclaredField(unObfuscatedName); + } + catch (NoSuchFieldException e) + { + try + { + field = clazz.getDeclaredField(obfuscatedName); + } + catch (NoSuchFieldException e1) + { + try + { + field = clazz.getDeclaredField(srgName); + } + catch (NoSuchFieldException e2) + { + System.out.println("[Vivecraft] WARNING: could not reflect field " + unObfuscatedName + "," + srgName + "," + obfuscatedName + " in " + clazz.toString()); + Throwables.propagate(e); + }; + }; + } + + field.setAccessible(true); //lets be honest this is why we have this method. + + return field; + } + + public static Method getDeclaredMethod(Class clazz, String unObfuscatedName, String obfuscatedName, String srgName, Class... params) + { + Method method = null; + + try + { + method = clazz.getDeclaredMethod(unObfuscatedName, params); + } + catch (NoSuchMethodException e) + { + try + { + method = clazz.getDeclaredMethod(obfuscatedName, params); + } + catch (NoSuchMethodException e1) + { + try + { + method = clazz.getDeclaredMethod(srgName, params); + } + catch (NoSuchMethodException e2) + { + System.out.println("[Vivecraft] WARNING: could not reflect method " + unObfuscatedName + "," + srgName + "," + obfuscatedName + " in " + clazz.toString()); + Throwables.propagate(e); + }; + }; + } + + method.setAccessible(true); + + return method; + } + + public static Constructor getDeclaredConstructor(Class clazz, Class... params) + { + Constructor constructor = null; + + try + { + constructor = clazz.getDeclaredConstructor(params); + } + catch (NoSuchMethodException e) + { + try + { + constructor = clazz.getDeclaredConstructor(params); + } + catch (NoSuchMethodException e1) + { + try + { + constructor = clazz.getDeclaredConstructor(params); + } + catch (NoSuchMethodException e2) + { + System.out.println("[Vivecraft] WARNING: could not reflect constructor in " + clazz.toString()); + }; + }; + } + + constructor.setAccessible(true); + + return constructor; + } +}