diff options
| author | salmonik <salmonik@tuta.io> | 2026-11-06 16:19:25 +0100 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-11-06 16:19:25 +0100 |
| commit | 9f0724dcd25a06c5674d30d045dc485a341253b1 (patch) | |
| tree | e7587dd03c0b164113d3b879b18d81fccf332c05 /src/cinput.cpp | |
| parent | Chams: leave engine-forced material passes alone (diff) | |
| download | hl2h-9f0724dcd25a06c5674d30d045dc485a341253b1.tar.gz hl2h-9f0724dcd25a06c5674d30d045dc485a341253b1.zip | |
Hooks: central vtable install with restore support
Move vtable patching into hooks.cpp: one call clones the table, validates every
slot, records the originals and installs the clone. Installs happen from the
setup, game and paint threads, so the bookkeeping is mutex-protected.
Client, CInput, IVModelRender, IStudioRender and ISurface all use it, and
hooks_restore_all() can now put every interface back (previously impossible).
Diffstat (limited to '')
| -rw-r--r-- | src/cinput.cpp | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/src/cinput.cpp b/src/cinput.cpp index 45e2b04..9cad30d 100644 --- a/src/cinput.cpp +++ b/src/cinput.cpp | |||
| @@ -159,22 +159,18 @@ static void hkdInputCreateMove(void *self, int seq, float frametime, | |||
| 159 | static bool install_input_hook() { | 159 | static bool install_input_hook() { |
| 160 | if (!g_input) | 160 | if (!g_input) |
| 161 | return false; | 161 | return false; |
| 162 | void **vt = VTABLE((void *)g_input); | 162 | if (!*(void ***)g_input) |
| 163 | if (!vt) | ||
| 164 | return false; | 163 | return false; |
| 165 | constexpr size_t N = 64; | 164 | VtablePatch patches[] = { |
| 166 | void **nvt = vtable_clone((void *)g_input, N); | 165 | {3, (void *)&hkdInputCreateMove, |
| 167 | if (!nvt) { | 166 | reinterpret_cast<void **>(&oInputCreateMove)}, |
| 168 | logf("CInput vtable clone failed"); | 167 | {4, (void *)&hkdInputExtraMouseSample, |
| 168 | reinterpret_cast<void **>(&oInputExtraMouseSample)}, | ||
| 169 | }; | ||
| 170 | if (!hooks_install_vtable((void *)g_input, 64, patches, 2)) { | ||
| 171 | logf("CInput vtable patch failed"); | ||
| 169 | return false; | 172 | return false; |
| 170 | } | 173 | } |
| 171 | oInputCreateMove = (InputCreateMoveFn)vt[3]; | ||
| 172 | nvt[3] = (void *)&hkdInputCreateMove; | ||
| 173 | if (N > 4) { | ||
| 174 | oInputExtraMouseSample = (InputExtraMouseFn)vt[4]; | ||
| 175 | nvt[4] = (void *)&hkdInputExtraMouseSample; | ||
| 176 | } | ||
| 177 | VTABLE((void *)g_input) = nvt; | ||
| 178 | logf("CInput CreateMove hooked: slot 3 orig=%p; ExtraMouseSample slot 4 " | 174 | logf("CInput CreateMove hooked: slot 3 orig=%p; ExtraMouseSample slot 4 " |
| 179 | "orig=%p", | 175 | "orig=%p", |
| 180 | (void *)oInputCreateMove, (void *)oInputExtraMouseSample); | 176 | (void *)oInputCreateMove, (void *)oInputExtraMouseSample); |
