diff options
| author | 2025-12-26 23:12:11 +0000 | |
|---|---|---|
| committer | 2026-02-16 19:11:24 +0000 | |
| commit | af370088fc178996a46ee508aaa1a2c46318bbf2 (patch) | |
| tree | cf1f6c01ad7c101d3fd4abb44835d9deb600e30d /src/kvsys.c | |
| parent | 40f9d989df2c1ff2f567656ccbdbfc0d97e34a77 (diff) | |
| download | sst-af370088fc178996a46ee508aaa1a2c46318bbf2.tar.gz sst-af370088fc178996a46ee508aaa1a2c46318bbf2.zip | |
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.
Diffstat (limited to 'src/kvsys.c')
| -rw-r--r-- | src/kvsys.c | 13 |
1 files changed, 6 insertions, 7 deletions
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); } } |
