From 5ce5dbcc0072473d2aad7fbd31f14cf4254a6a40 Mon Sep 17 00:00:00 2001 From: Duy Tran Khanh Date: Mon, 23 Aug 2021 11:19:54 +0700 Subject: [PATCH] Changes - Avoid printing "Session ID". Several Minecraft versions do that. - Fixes Minecraft 1.13 snapshot due to the usage of LWJGL functions from an older version. - Minecraft's built in Fullscreen Resolution scaler is available now, but not working properly. - Regal internal changes (still fail at ) --- .../net/kdt/pojavlaunch/uikit/AccountJNI.java | 2 +- .../src/main/java/org/lwjgl/glfw/GLFW.java | 40 +++++++++-------- .../org/lwjgl/glfw/GLFWWindowProperties.java | 1 + .../src/main/java/org/lwjgl/opengl/GL.java | 4 +- .../java/org/lwjgl/system/MemoryUtil.java | 12 +++++ Natives/JavaLauncher.m | 45 ++++++++++++++++--- Natives/LoginViewController.m | 9 ++-- Natives/SurfaceViewController.m | 5 +-- Natives/egl_bridge.m | 13 ++++++ 9 files changed, 99 insertions(+), 32 deletions(-) diff --git a/JavaApp/src/main/java/net/kdt/pojavlaunch/uikit/AccountJNI.java b/JavaApp/src/main/java/net/kdt/pojavlaunch/uikit/AccountJNI.java index f61d30cc..7d27bf0d 100644 --- a/JavaApp/src/main/java/net/kdt/pojavlaunch/uikit/AccountJNI.java +++ b/JavaApp/src/main/java/net/kdt/pojavlaunch/uikit/AccountJNI.java @@ -18,7 +18,7 @@ public class AccountJNI { // Call back about account credentials for login public static boolean loginAccount(int type, String data // One of: - // Offline username + // Local username // Mojang json response // Microsoft token ) { diff --git a/JavaApp/src/main/java/org/lwjgl/glfw/GLFW.java b/JavaApp/src/main/java/org/lwjgl/glfw/GLFW.java index f4adf8d2..1398ada7 100644 --- a/JavaApp/src/main/java/org/lwjgl/glfw/GLFW.java +++ b/JavaApp/src/main/java/org/lwjgl/glfw/GLFW.java @@ -687,9 +687,11 @@ public class GLFW mGLFWFramebufferSizeCallback = GLFWFramebufferSizeCallback.createSafe(nglfwSetFramebufferSizeCallback(window, memAddressSafe(cbfun))); + /* try { mGLFWFramebufferSizeCallback.invoke(window, mGLFWWindowWidth, mGLFWWindowHeight); } catch (Throwable th) {} + */ return lastCallback; } @@ -823,7 +825,6 @@ public class GLFW @NativeType("GLFWwindow *") public static long glfwGetCurrentContext() { - // Stub prevent NULL check return nativeEglGetCurrentContext(); } @@ -913,14 +914,17 @@ public class GLFW @NativeType("GLFWmonitor *") public static long glfwGetWindowMonitor(@NativeType("GLFWwindow *") long window) { - return mGLFWWindowMonitor; + return internalGetWindow(window).monitor; } public static void glfwSetWindowMonitor(@NativeType("GLFWwindow *") long window, @NativeType("GLFWmonitor *") long monitor, int xpos, int ypos, int width, int height, int refreshRate) { - // weird calculation to fake pointer - mGLFWWindowMonitor = window * monitor; + GLFWWindowProperties properties = internalGetWindow(window); + properties.monitor = monitor; + properties.x = xpos; + properties.y = ypos; + internalChangeMonitorSize(width, height); } - + public static int glfwGetWindowAttrib(@NativeType("GLFWwindow *") long window, int attrib) { return internalGetWindow(window).windowAttribs.get(attrib); } @@ -1012,22 +1016,22 @@ public class GLFW // GLFW Window functions public static long glfwCreateWindow(int width, int height, CharSequence title, long monitor, long share) { EventLoop.OffScreen.check(); - // Create an ACTUAL EGL context - long ptr = nativeEglCreateContext(share); - //nativeEglMakeCurrent(ptr); - GLFWWindowProperties win = new GLFWWindowProperties(); + // Create an ACTUAL EGL context + long ptr = nativeEglCreateContext(share); + //nativeEglMakeCurrent(ptr); + GLFWWindowProperties win = new GLFWWindowProperties(); - // win.width = width; - // win.height = height; - - win.width = mGLFWWindowWidth; - win.height = mGLFWWindowHeight; + win.width = width; + win.height = height; - win.title = title; + // win.width = mGLFWWindowWidth; + // win.height = mGLFWWindowHeight; + + win.title = title; - mGLFWWindowMap.put(ptr, win); - mainContext = ptr; - return ptr; + mGLFWWindowMap.put(ptr, win); + mainContext = ptr; + return ptr; //Return our context } diff --git a/JavaApp/src/main/java/org/lwjgl/glfw/GLFWWindowProperties.java b/JavaApp/src/main/java/org/lwjgl/glfw/GLFWWindowProperties.java index 06caecfb..30ec8cd4 100644 --- a/JavaApp/src/main/java/org/lwjgl/glfw/GLFWWindowProperties.java +++ b/JavaApp/src/main/java/org/lwjgl/glfw/GLFWWindowProperties.java @@ -8,6 +8,7 @@ public class GLFWWindowProperties { public int x, y; public CharSequence title; public boolean shouldClose, isInitialSizeCalled, isCursorEntered; + public long monitor; public Map inputModes = new HashMap<>(); public Map windowAttribs = new HashMap<>(); diff --git a/JavaApp/src/main/java/org/lwjgl/opengl/GL.java b/JavaApp/src/main/java/org/lwjgl/opengl/GL.java index bfb0b558..a289de6e 100644 --- a/JavaApp/src/main/java/org/lwjgl/opengl/GL.java +++ b/JavaApp/src/main/java/org/lwjgl/opengl/GL.java @@ -91,6 +91,8 @@ public final class GL { } } + private static native void nativeRegalMakeCurrent(); + private GL() {} /** Ensures that the lwjgl_opengl shared library has been loaded. */ @@ -370,7 +372,7 @@ public final class GL { // This fixed framebuffer issue on 1.13+ 64-bit by another making current GLFW.nativeEglMakeCurrent(GLFW.mainContext); if (isUsingRegal) { - callPV(callJ(functionProvider.getFunctionAddress("eglGetCurrentContext"), functionProvider.getFunctionAddress("RegalMakeCurrent")); + nativeRegalMakeCurrent(); } } else if (System.getenv("RENDERER").contains("zink")) { int[] dims = getNativeWidthHeight(); diff --git a/JavaApp/src/main/java/org/lwjgl/system/MemoryUtil.java b/JavaApp/src/main/java/org/lwjgl/system/MemoryUtil.java index ea607016..0bec229e 100644 --- a/JavaApp/src/main/java/org/lwjgl/system/MemoryUtil.java +++ b/JavaApp/src/main/java/org/lwjgl/system/MemoryUtil.java @@ -1838,6 +1838,18 @@ public final class MemoryUtil { return a ^ ((a ^ b) & mask); } + /** + * Sets all bytes in a specified block of memory to a copy of another block. + * + * @param src the source memory address + * @param dst the destination memory address + * @param bytes the number of bytes to copy + */ + // from LWJGL 3.1.2 + public static void memCopy(long src, long dst, int bytes) { + memCopy(src, dst, (long)bytes); + } + /** * Sets all bytes in a specified block of memory to a copy of another block. * diff --git a/Natives/JavaLauncher.m b/Natives/JavaLauncher.m index dc8db84c..3ef448bd 100644 --- a/Natives/JavaLauncher.m +++ b/Natives/JavaLauncher.m @@ -67,7 +67,9 @@ typedef jint JLI_Launch_func(int argc, char ** argv, /* main argc, argc */ static int margc = 0; static char* margv[1000]; static int pfd[2]; +static int log_fd; static pthread_t logger; +static BOOL filteredSessionID; const char *javaHome; const char *renderer; @@ -76,6 +78,27 @@ NSString *javaHome_pre; NSString *renderer_pre; NSString *allocmem_pre; +static void *logger_thread() { + ssize_t rsize; + char buf[2048]; + while((rsize = read(pfd[0], buf, sizeof(buf)-1)) > 0) { + // Filter out Session ID here + int index; + if (!filteredSessionID) { + char *sessionStr = strstr(buf, "(Session ID is "); + if (sessionStr) { + char *censorStr = "(Session ID is )\n\0"; + strcpy(sessionStr, censorStr); + rsize = strlen(buf); + filteredSessionID = true; + } + } + write(log_fd, buf, rsize); + } + close(log_fd); + return NULL; +} + void init_loadCustomEnv() { FILE *envFile = fopen(env_path, "r"); @@ -217,17 +240,29 @@ int launchJVM(int argc, char *argv[]) { debug("[Pre-init] Error: failed to open %s: %s", log_path, strerror(errno)); assert(0 && "Failed to open latestlog.txt. Check oslog for more details."); } - int log_fd = fileno(logFile); - dup2(log_fd, 1); - dup2(log_fd, 2); - close(log_fd); + log_fd = fileno(logFile); + setvbuf(stdout, 0, _IOLBF, 0); // make stdout line-buffered + setvbuf(stderr, 0, _IONBF, 0); // make stderr unbuffered + + /* create the pipe and redirect stdout and stderr */ + pipe(pfd); + dup2(pfd[1], 1); + dup2(pfd[1], 2); + + /* spawn the logging thread */ + if(pthread_create(&logger, 0, logger_thread, 0) == -1) { + char *fail_str = "Failed to start logging!"; + write(log_fd, fail_str, strlen(fail_str)); + close(log_fd); + } + pthread_detach(logger); } init_logDeviceAndVer(argv[0]); debug("[Pre-init] Beginning JVM launch\n"); char javaAwtPath[4096]; - // accidentally patched a bit wrong, the value should be a path containing libawt_xawt.dylib, but here is libawt.dylib path (no need to exist) + // I accidentally patched a bit wrong, the value should be a path containing libawt_xawt.dylib, but here is libawt.dylib path (no need to exist) sprintf(javaAwtPath, "%s/Frameworks/libawt.dylib", getenv("BUNDLE_PATH")); setenv("JAVA_AWT_PATH", javaAwtPath, 1); diff --git a/Natives/LoginViewController.m b/Natives/LoginViewController.m index 62234054..4f58e403 100644 --- a/Natives/LoginViewController.m +++ b/Natives/LoginViewController.m @@ -27,14 +27,14 @@ void loginAccountInput(UINavigationController *controller, int type, const char* jclass clazz = (*env)->FindClass(env, "net/kdt/pojavlaunch/uikit/AccountJNI"); assert(clazz); - + jmethodID method = (*env)->GetStaticMethodID(env, clazz, "loginAccount", "(ILjava/lang/String;)Z"); assert(method); - + jboolean result = (*env)->CallStaticBooleanMethod(env, clazz, method, type, data); - + (*runtimeJavaVMPtr)->DetachCurrentThread(runtimeJavaVMPtr); - + if (result == JNI_TRUE) { if ([NSThread isMainThread]) { LauncherViewController *vc = [[LauncherViewController alloc] init]; @@ -354,6 +354,7 @@ void loginAccountInput(UINavigationController *controller, int type, const char* long statusCode = (long)[httpResponse statusCode]; NSString *dataStr = [NSString stringWithUTF8String:[data bytes]]; + // NSLog(@"status=%ld, data=%@, response=%@, error=%@", statusCode, dataStr, httpResponse, error); NSError *jsonError = nil; diff --git a/Natives/SurfaceViewController.m b/Natives/SurfaceViewController.m index 8a641d16..f61abb31 100644 --- a/Natives/SurfaceViewController.m +++ b/Natives/SurfaceViewController.m @@ -161,7 +161,7 @@ float resolutionScale; NSError *cc_error; NSString *cc_data = [NSString stringWithContentsOfFile:controlFilePath encoding:NSUTF8StringEncoding error:&cc_error]; - if (cc_error != nil) { + if (cc_error) { NSLog(@"Error: could not read %@: %@", controlFilePath, cc_error.localizedDescription); showDialog(self, @"Error", [NSString stringWithFormat:@"Could not read %@: %@", controlFilePath, cc_error.localizedDescription]); } else { @@ -175,8 +175,7 @@ float resolutionScale; CGFloat currentScale = ((NSNumber *)self.cc_dictionary[@"scaledAt"]).floatValue; CGFloat savedScale = ((NSNumber *)getPreference(@"button_scale")).floatValue; int cc_version = ((NSNumber *)self.cc_dictionary[@"version"]).intValue; - for (int i = 0; i < (int) cc_controlDataList.count; i++) { - NSMutableDictionary *cc_buttonDict = cc_controlDataList[i]; + for (NSMutableDictionary *cc_buttonDict in cc_controlDataList) { APPLY_SCALE(cc_buttonDict[@"width"]); APPLY_SCALE(cc_buttonDict[@"height"]); APPLY_SCALE(cc_buttonDict[@"strokeWidth"]); diff --git a/Natives/egl_bridge.m b/Natives/egl_bridge.m index bab9db9d..bb5f7725 100644 --- a/Natives/egl_bridge.m +++ b/Natives/egl_bridge.m @@ -109,6 +109,11 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_GLFW_nativeEglMakeCurrent(JNIEnv* debug("Error: eglMakeCurrent() failed: %x", eglGetError()); } + RegalMakeCurrent_func *RegalMakeCurrent = (RegalMakeCurrent_func *) dlsym(RTLD_DEFAULT, "RegalMakeCurrent"); + if (RegalMakeCurrent) { + RegalMakeCurrent(potatoBridge.eglContext); + } + debug("EGLBridge: Trigger an initial swapBuffers"); [viewController.view.subviews[0] display]; @@ -161,6 +166,14 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_GLFW_nativeEglTerminate(JNIEnv* e return JNI_TRUE; } +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GL_nativeRegalMakeCurrent(JNIEnv *env, jclass clazz) { + debug("Regal: making current"); + + RegalMakeCurrent_func *RegalMakeCurrent = (RegalMakeCurrent_func *) dlsym(RTLD_DEFAULT, "RegalMakeCurrent"); + assert(RegalMakeCurrent); + RegalMakeCurrent(potatoBridge.eglContext); +} + bool stopMakeCurrent; JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_GLFW_nativeEglSwapBuffers(JNIEnv *env, jclass clazz) { jboolean result = (jboolean) eglSwapBuffers(potatoBridge.eglDisplay, eglGetCurrentSurface(EGL_DRAW));