From 3fae02c7d342981c9910db7715305bc57b261a8b Mon Sep 17 00:00:00 2001 From: salmonik Date: Tue, 27 Oct 2026 18:09:19 +0100 Subject: GUI: allow movement while open; freeze look and block bind capture Feedback pass on the preview shell: - Freeze the rendered view explicitly in CreateMove and again at FRAME_RENDER_START; CInput was still letting mouse look move the camera. - Allow normal WASD/jump/duck movement while the GUI is open; strip attack/use/impulse/weapon selection so GUI clicks do not fire. - While bind capture is active, block all game input. - Esc no longer closes the GUI; it only cancels bind capture. F2 or the title-bar X close the preview. - Interpose SDL_ShowCursor / SDL_SetRelativeMouseMode / warp / window grab so the game cannot re-capture or hide the native cursor while the GUI is open. --- src/gui.cpp | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- src/hl2h.cpp | 38 ++++++++++++++++++------ src/hl2h.h | 1 + 3 files changed, 120 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/gui.cpp b/src/gui.cpp index 74dd537..923cd4d 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -879,12 +879,8 @@ void gui_handle_input() { return; } - if (esc_edge) { - if (g_capture_card >= 0) - g_capture_card = -1; - else - close_gui(); - } + if (esc_edge && g_capture_card >= 0) + g_capture_card = -1; // Keep the native cursor free even if the game re-grabs it. if (sd_set_relative) @@ -1196,4 +1192,92 @@ void gui_draw() { } bool gui_is_open() { return g_open; } +bool gui_bind_capture_active() { return g_open && g_capture_card >= 0; } QAngle gui_frozen_view() { return g_frozen; } + +// --------------------------------------------------------------------------- +// SDL cursor interposition +// --------------------------------------------------------------------------- +// The game re-asserts relative mouse mode / hides the cursor every frame. While +// the GUI is open, force the opposite so the native cursor stays usable. + +static int (*real_show_cursor)(int) = nullptr; +static int (*real_set_relative)(int) = nullptr; +static void (*real_warp_mouse)(void *, int, int) = nullptr; +static void (*real_set_grab)(void *, int) = nullptr; + +extern "C" __attribute__((visibility("default"))) int SDL_ShowCursor(int toggle) { + if (!real_show_cursor) + real_show_cursor = (int (*)(int))dlsym(RTLD_NEXT, "SDL_ShowCursor"); + if (g_open && toggle != -1) { + if (real_show_cursor) + real_show_cursor(1); + return 1; + } + return real_show_cursor ? real_show_cursor(toggle) : 0; +} + +extern "C" __attribute__((visibility("default"))) int +SDL_SetRelativeMouseMode(int enabled) { + if (!real_set_relative) + real_set_relative = + (int (*)(int))dlsym(RTLD_NEXT, "SDL_SetRelativeMouseMode"); + if (g_open) { + if (real_set_relative) + real_set_relative(0); + return 0; + } + return real_set_relative ? real_set_relative(enabled) : 0; +} + +extern "C" __attribute__((visibility("default"))) void +SDL_WarpMouseInWindow(void *window, int x, int y) { + if (!real_warp_mouse) + real_warp_mouse = + (void (*)(void *, int, int))dlsym(RTLD_NEXT, "SDL_WarpMouseInWindow"); + if (g_open) + return; + if (real_warp_mouse) + real_warp_mouse(window, x, y); +} + +extern "C" __attribute__((visibility("default"))) void +SDL_SetWindowGrab(void *window, int grabbed) { + if (!real_set_grab) + real_set_grab = + (void (*)(void *, int))dlsym(RTLD_NEXT, "SDL_SetWindowGrab"); + if (g_open) { + if (real_set_grab) + real_set_grab(window, 0); + return; + } + if (real_set_grab) + real_set_grab(window, grabbed); +} + +static void (*real_set_mouse_grab)(void *, int) = nullptr; +static void (*real_warp_global)(int, int) = nullptr; + +extern "C" __attribute__((visibility("default"))) void +SDL_SetWindowMouseGrab(void *window, int grabbed) { + if (!real_set_mouse_grab) + real_set_mouse_grab = + (void (*)(void *, int))dlsym(RTLD_NEXT, "SDL_SetWindowMouseGrab"); + if (g_open) { + if (real_set_mouse_grab) + real_set_mouse_grab(window, 0); + return; + } + if (real_set_mouse_grab) + real_set_mouse_grab(window, grabbed); +} + +extern "C" __attribute__((visibility("default"))) void +SDL_WarpMouseGlobal(int x, int y) { + if (!real_warp_global) + real_warp_global = (void (*)(int, int))dlsym(RTLD_NEXT, "SDL_WarpMouseGlobal"); + if (g_open) + return; + if (real_warp_global) + real_warp_global(x, y); +} diff --git a/src/hl2h.cpp b/src/hl2h.cpp index c0c27af..a0e6b53 100644 --- a/src/hl2h.cpp +++ b/src/hl2h.cpp @@ -546,10 +546,23 @@ static void do_move(int seq, float frametime) { cmd->viewangles[0] = f.x; cmd->viewangles[1] = f.y; cmd->viewangles[2] = f.z; - cmd->forwardmove = 0.0f; - cmd->sidemove = 0.0f; - cmd->upmove = 0.0f; - cmd->buttons = 0; + // Freeze the rendered view explicitly: CInput may not push the modified + // command view back to the engine if the client mode returns false. + if (g_iface.engine) { + QAngle set = f; + using SetViewFn = void (*)(void *, QAngle *); + vfunc(g_iface.engine, 20)(g_iface.engine, &set); + } + if (gui_bind_capture_active()) { + // Bind capture must not move/act in the game while keys are sampled. + cmd->forwardmove = 0.0f; + cmd->sidemove = 0.0f; + cmd->upmove = 0.0f; + cmd->buttons = 0; + } else { + // Movement is allowed while the GUI is open, but not look/attack/use. + cmd->buttons &= (IN_JUMP | IN_DUCK); + } cmd->impulse = 0; cmd->weaponselect = 0; cmd->weaponsubtype = 0; @@ -670,12 +683,19 @@ void set_silent_restore(const QAngle &angles) { static void hkdFrameStageNotify(void *self, int stage) { if (oFrameStageNotify) oFrameStageNotify(self, stage); - if (stage == 5 && g_silent_restore_pending) { - g_silent_restore_pending = false; - if (g_iface.engine) { - QAngle a = g_silent_restore_angles; + if (stage == 5) { + if (g_silent_restore_pending) { + g_silent_restore_pending = false; + if (g_iface.engine) { + QAngle a = g_silent_restore_angles; + using SetViewFn = void (*)(void *, QAngle *); + vfunc(g_iface.engine, 20)(g_iface.engine, &a); + } + } + if (gui_is_open() && g_iface.engine) { + QAngle f = gui_frozen_view(); using SetViewFn = void (*)(void *, QAngle *); - vfunc(g_iface.engine, 20)(g_iface.engine, &a); + vfunc(g_iface.engine, 20)(g_iface.engine, &f); } } } diff --git a/src/hl2h.h b/src/hl2h.h index 11b9014..8a81439 100644 --- a/src/hl2h.h +++ b/src/hl2h.h @@ -234,6 +234,7 @@ void menu_force_close(); void gui_handle_input(); void gui_draw(); bool gui_is_open(); +bool gui_bind_capture_active(); QAngle gui_frozen_view(); // ISurface pointer (defined in menu.cpp, used for drawing tests) struct ISurface; -- cgit v1.2.3