From af370088fc178996a46ee508aaa1a2c46318bbf2 Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Fri, 26 Dec 2025 23:12:11 +0000 Subject: Move to static trampolines and type-safe hooks For some reason the DLL got a tiny little bit bigger again but that's fine. This will make orig_ calls more efficient in the inline case, and also make it harder to screw up and hook the wrong thing by mistake. Self-explanatory-ish, apart from the fact it's a fairly large API change of course. And it relies on some more bonkers assembler directive hackery. But it works! The only complaint one might have is that the featsetup functions no longer take an explicit string which occasionally yields slightly less perfect error messages, but I've decided this isn't really a problem and makes the API nicer to use. It's a tradeoff, innit. --- src/kvsys.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'src/kvsys.c') diff --git a/src/kvsys.c b/src/kvsys.c index 25a6672..32e9906 100644 --- a/src/kvsys.c +++ b/src/kvsys.c @@ -70,8 +70,9 @@ void kvsys_free(struct KeyValues *kv) { // We can suppress this by catching the message string that's passed from // engine.dll to gameui.dll through KeyValuesSystem in vstdlib.dll and just // replacing it with some other arbitrary string that gameui won't match. -static GetStringForSymbol_func orig_GetStringForSymbol = 0; -static const char *VCALLCONV hook_GetStringForSymbol(void *this, int s) { +DEF_VTABLE_HOOK(GetStringForSymbol_func, GetStringForSymbol) +static const char *VCALLCONV hookdest_GetStringForSymbol( + struct IKeyValuesSystem *this, int s) { const char *ret = orig_GetStringForSymbol(this, s); if (!strcmp(ret, "OnClientPluginWarning")) ret = "sstBlockedThisEvent"; return ret; @@ -108,9 +109,8 @@ INIT { errmsg_note("won't be able to prevent any nag messages"); } else { - orig_GetStringForSymbol = (GetStringForSymbol_func)hook_vtable( - vtable, vtidx_GetStringForSymbol, - (void *)hook_GetStringForSymbol); + hook_GetStringForSymbol(vtable, vtidx_GetStringForSymbol, + &hookdest_GetStringForSymbol); } } return FEAT_OK; @@ -118,8 +118,7 @@ INIT { END { if (orig_GetStringForSymbol) { - unhook_vtable(kvs->vtable, vtidx_GetStringForSymbol, - (void *)orig_GetStringForSymbol); + unhook_GetStringForSymbol(kvs->vtable, vtidx_GetStringForSymbol); } } -- cgit v1.2.3-54-g00ecf