diff options
| author | salmonik <salmonik@tuta.io> | 2026-10-27 18:21:13 +0100 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-10-27 18:21:13 +0100 |
| commit | 304441c71997ee61e618146f4d4302c6d2b952ad (patch) | |
| tree | e7a00d279b257f88e7a590da59023533cae6ae80 /src/cinput.cpp | |
| parent | GUI: allow movement while open; freeze look and block bind capture (diff) | |
| download | hl2h-304441c71997ee61e618146f4d4302c6d2b952ad.tar.gz hl2h-304441c71997ee61e618146f4d4302c6d2b952ad.zip | |
GUI: Insert-only close, freeze mouse look at the source
Feedback pass:
- Insert now toggles the GUI; the old text tree moved to F1.
- Remove the title-bar X. Insert is the only close path; Esc only cancels
bind capture.
- Discard accumulated mouse deltas in CInput::CreateMove before the game can
apply them (CInput::ClearStates), so the camera no longer moves for a frame
and snaps back. Also skip ExtraMouseSample and zero relative mouse state
while the GUI is open.
- Strip attack/use/impulse/weapon selection from the command while open;
keep jump, duck and walk. Skip combat command edits (spread seed) too.
- Widen System page buttons so "Reload config" and "Reset defaults" fit.
- Update CONTEXT/ADR for the Insert-only close behavior.
Diffstat (limited to 'src/cinput.cpp')
| -rw-r--r-- | src/cinput.cpp | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/src/cinput.cpp b/src/cinput.cpp index a75cc4f..ad7face 100644 --- a/src/cinput.cpp +++ b/src/cinput.cpp | |||
| @@ -85,12 +85,42 @@ void fix_verified_crc(int seq, uint32_t crc) { | |||
| 85 | 85 | ||
| 86 | using InputCreateMoveFn = void (*)(void *, int, float, bool); | 86 | using InputCreateMoveFn = void (*)(void *, int, float, bool); |
| 87 | static InputCreateMoveFn oInputCreateMove = nullptr; | 87 | static InputCreateMoveFn oInputCreateMove = nullptr; |
| 88 | using InputExtraMouseFn = void (*)(void *, float, bool); | ||
| 89 | static InputExtraMouseFn oInputExtraMouseSample = nullptr; | ||
| 90 | |||
| 91 | // ExtraMouseSample runs AdjustAngles at render-frame rate, between movement | ||
| 92 | // commands. While the GUI is open it must not touch the view; movement still | ||
| 93 | // comes through CreateMove. | ||
| 94 | static void hkdInputExtraMouseSample(void *self, float frametime, bool active) { | ||
| 95 | if (gui_is_open()) | ||
| 96 | return; | ||
| 97 | if (oInputExtraMouseSample) | ||
| 98 | oInputExtraMouseSample(self, frametime, active); | ||
| 99 | } | ||
| 100 | |||
| 101 | void input_clear_mouse_states() { | ||
| 102 | if (!g_input) | ||
| 103 | return; | ||
| 104 | // CInput::ClearStates (IInput slot 20): zeros both the software mouse | ||
| 105 | // accumulator and the engine raw-input accumulator. | ||
| 106 | using Fn = void (*)(void *); | ||
| 107 | vfunc<Fn>((void *)g_input, 20)((void *)g_input); | ||
| 108 | } | ||
| 88 | 109 | ||
| 89 | static void hkdInputCreateMove(void *self, int seq, float frametime, | 110 | static void hkdInputCreateMove(void *self, int seq, float frametime, |
| 90 | bool active) { | 111 | bool active) { |
| 112 | // Mouse deltas are accumulated between ticks. With the custom GUI open we | ||
| 113 | // must discard them before CInput::CreateMove applies mouse look, otherwise | ||
| 114 | // the view moves for one frame and snaps back when do_move freezes it. | ||
| 115 | if (gui_is_open()) | ||
| 116 | input_clear_mouse_states(); | ||
| 91 | if (oInputCreateMove) | 117 | if (oInputCreateMove) |
| 92 | oInputCreateMove(self, seq, frametime, active); | 118 | oInputCreateMove(self, seq, frametime, active); |
| 93 | 119 | ||
| 120 | // No combat features may modify the command while the GUI is open. | ||
| 121 | if (gui_is_open()) | ||
| 122 | return; | ||
| 123 | |||
| 94 | CUserCmd *cmd = get_usercmd(seq); | 124 | CUserCmd *cmd = get_usercmd(seq); |
| 95 | if (!cmd) | 125 | if (!cmd) |
| 96 | return; | 126 | return; |
| @@ -125,8 +155,14 @@ static bool install_input_hook() { | |||
| 125 | memcpy(nvt, vt, N * sizeof(void *)); | 155 | memcpy(nvt, vt, N * sizeof(void *)); |
| 126 | oInputCreateMove = (InputCreateMoveFn)vt[3]; | 156 | oInputCreateMove = (InputCreateMoveFn)vt[3]; |
| 127 | nvt[3] = (void *)&hkdInputCreateMove; | 157 | nvt[3] = (void *)&hkdInputCreateMove; |
| 158 | if (N > 4) { | ||
| 159 | oInputExtraMouseSample = (InputExtraMouseFn)vt[4]; | ||
| 160 | nvt[4] = (void *)&hkdInputExtraMouseSample; | ||
| 161 | } | ||
| 128 | VTABLE((void *)g_input) = nvt; | 162 | VTABLE((void *)g_input) = nvt; |
| 129 | logf("CInput CreateMove hooked: slot 3 orig=%p", (void *)oInputCreateMove); | 163 | logf("CInput CreateMove hooked: slot 3 orig=%p; ExtraMouseSample slot 4 " |
| 164 | "orig=%p", | ||
| 165 | (void *)oInputCreateMove, (void *)oInputExtraMouseSample); | ||
| 130 | return true; | 166 | return true; |
| 131 | } | 167 | } |
| 132 | 168 | ||
