From b190851d362e8954fc4dc15e29102fb0b715eb60 Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Fri, 15 Jul 2022 22:08:12 -0400 Subject: [PATCH] Hotfix --- docs/CHANGELOG.md | 1 + launcher/src/client/available-feature-flags | 1 + media-layer/core/src/media.c | 14 +++++++++++ media-layer/include/media-layer/core.h | 1 + media-layer/proxy/src/media-layer-core.c | 12 ++++++++++ mods/src/misc/misc.c | 26 ++++++++++++++++++--- 6 files changed, 52 insertions(+), 3 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 0e39e93..f31c8ba 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -10,6 +10,7 @@ * Add ``Add Buckets`` Feature Flag (Enabled By Default) * Add ``Classic HUD`` Feature Flag (Enabled By Default) * Add ``Translucent Toolbar`` Feature Flag (Enabled By Default) +* Add ``Force EGL`` Feature Flag (Disabled By Default) * Fix Sound Pitch/Volume/Attenuation * Fix Holding Left-Click When Attacking * Don't Force EGL (Should Fix Some NVIDIA Systems) diff --git a/launcher/src/client/available-feature-flags b/launcher/src/client/available-feature-flags index fab40c3..4bc5500 100644 --- a/launcher/src/client/available-feature-flags +++ b/launcher/src/client/available-feature-flags @@ -41,3 +41,4 @@ FALSE Remove Forced GUI Lag (Can Break Joining Servers) TRUE Add Buckets TRUE Classic HUD TRUE Translucent Toolbar +FALSE Force EGL diff --git a/media-layer/core/src/media.c b/media-layer/core/src/media.c index 9c49681..eac865d 100644 --- a/media-layer/core/src/media.c +++ b/media-layer/core/src/media.c @@ -251,6 +251,15 @@ void media_disable_vsync() { #endif } +// Force EGL +static int force_egl = 0; +void media_force_egl() { + if (force_egl == -1) { + IMPOSSIBLE(); + } + force_egl = 1; +} + // Init Media Layer #define GL_VERSION 0x1f02 typedef const unsigned char *(*glGetString_t)(unsigned int name); @@ -273,6 +282,11 @@ void SDL_WM_SetCaption(const char *title, __attribute__((unused)) const char *ic glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 1); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1); #endif + // Use EGL + if (force_egl) { + glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_EGL_CONTEXT_API); + } + force_egl = -1; // Extra Settings glfwWindowHint(GLFW_AUTO_ICONIFY, GLFW_FALSE); glfwWindowHint(GLFW_ALPHA_BITS, 0); // Fix Transparent Window On Wayland diff --git a/media-layer/include/media-layer/core.h b/media-layer/include/media-layer/core.h index 14c10e0..edc6118 100644 --- a/media-layer/include/media-layer/core.h +++ b/media-layer/include/media-layer/core.h @@ -16,6 +16,7 @@ void media_cleanup(); void media_get_framebuffer_size(int *width, int *height); void media_set_interactable(int is_interactable); void media_disable_vsync(); +void media_force_egl(); void media_set_raw_mouse_motion_enabled(int enabled); #ifdef __cplusplus diff --git a/media-layer/proxy/src/media-layer-core.c b/media-layer/proxy/src/media-layer-core.c index 17c7b93..53f7dae 100644 --- a/media-layer/proxy/src/media-layer-core.c +++ b/media-layer/proxy/src/media-layer-core.c @@ -339,3 +339,15 @@ CALL(64, media_set_raw_mouse_motion_enabled, void, (int enabled)) { media_set_raw_mouse_motion_enabled(enabled); #endif } + +CALL(66, media_force_egl, void, ()) { +#if defined(MEDIA_LAYER_PROXY_SERVER) + // Lock Proxy + start_proxy_call(); + // Release Proxy + end_proxy_call(); +#else + // Run + media_force_egl(); +#endif +} diff --git a/mods/src/misc/misc.c b/mods/src/misc/misc.c index a769996..5eb9dee 100644 --- a/mods/src/misc/misc.c +++ b/mods/src/misc/misc.c @@ -116,16 +116,31 @@ static void Inventory_selectSlot_injection(unsigned char *inventory, int32_t slo } // Translucent Toolbar +static GLfloat reset_red; +static GLfloat reset_green; +static GLfloat reset_blue; +static GLfloat reset_alpha; static void Gui_renderToolBar_injection(unsigned char *gui, float param_1, int32_t param_2, int32_t param_3) { // Call Original Method - glEnable(GL_BLEND); + int was_blend_enabled = glIsEnabled(GL_BLEND); + if (!was_blend_enabled) { + glEnable(GL_BLEND); + } glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); (*Gui_renderToolBar)(gui, param_1, param_2, param_3); - glDisable(GL_BLEND); + glColor4f(reset_red, reset_green, reset_blue, reset_alpha); + if (!was_blend_enabled) { + glDisable(GL_BLEND); + } } -static void Gui_renderToolBar_glColor4f_injection(GLfloat red, GLfloat green, GLfloat blue, __attribute__((unused)) GLfloat alpha) { +static void Gui_renderToolBar_glColor4f_injection(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) { // Fix Alpha glColor4f(red, green, blue, 1.0f); + // Stroe For Reset + reset_red = red; + reset_green = green; + reset_blue = blue; + reset_alpha = alpha; } // Sanitize Username @@ -353,6 +368,11 @@ void init_misc() { media_disable_vsync(); } + // Force EGL + if (feature_has("Force EGL", server_disabled)) { + media_force_egl(); + } + // Remove Forced GUI Lag if (feature_has("Remove Forced GUI Lag (Can Break Joining Servers)", server_enabled)) { overwrite_calls((void *) sleepMs, (void *) nop);