From 9f0724dcd25a06c5674d30d045dc485a341253b1 Mon Sep 17 00:00:00 2001 From: salmonik Date: Fri, 6 Nov 2026 16:19:25 +0100 Subject: 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). --- src/cinput.cpp | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'src/cinput.cpp') 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, static bool install_input_hook() { if (!g_input) return false; - void **vt = VTABLE((void *)g_input); - if (!vt) + if (!*(void ***)g_input) return false; - constexpr size_t N = 64; - void **nvt = vtable_clone((void *)g_input, N); - if (!nvt) { - logf("CInput vtable clone failed"); + VtablePatch patches[] = { + {3, (void *)&hkdInputCreateMove, + reinterpret_cast(&oInputCreateMove)}, + {4, (void *)&hkdInputExtraMouseSample, + reinterpret_cast(&oInputExtraMouseSample)}, + }; + if (!hooks_install_vtable((void *)g_input, 64, patches, 2)) { + logf("CInput vtable patch failed"); return false; } - oInputCreateMove = (InputCreateMoveFn)vt[3]; - nvt[3] = (void *)&hkdInputCreateMove; - if (N > 4) { - oInputExtraMouseSample = (InputExtraMouseFn)vt[4]; - nvt[4] = (void *)&hkdInputExtraMouseSample; - } - VTABLE((void *)g_input) = nvt; logf("CInput CreateMove hooked: slot 3 orig=%p; ExtraMouseSample slot 4 " "orig=%p", (void *)oInputCreateMove, (void *)oInputExtraMouseSample); -- cgit v1.2.3