From 4ed68f73dae9e7621d7d7512b5feb686e9440bb2 Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Thu, 6 Jan 2022 23:39:21 +0000 Subject: Tidy up stubs, make vstdlib a stub, build on Linux Important note: it doesn't WORK on Linux, and there's tons of warnings and stuff, but it's easier to work on when all the compiler output and whatnot is there. --- src/sst.c | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-) (limited to 'src/sst.c') diff --git a/src/sst.c b/src/sst.c index 94e1661..9cf21c2 100644 --- a/src/sst.c +++ b/src/sst.c @@ -84,6 +84,9 @@ static const char *VCALLCONV GetStringForSymbol_hook(void *this, int s) { return ret; } +// vstdlib symbol, only currently used in l4d2 but exists everywhere so oh well +IMPORT void *KeyValuesSystem(void); + static bool do_load(ifacefactory enginef, ifacefactory serverf) { factory_engine = enginef; factory_server = serverf; #ifndef __linux__ @@ -133,31 +136,15 @@ nc: gamedata_init(); // NOTE: this is technically redundant for early versions but I CBA writing // a version check; it's easier to just do this unilaterally. if (GAMETYPE_MATCHES(L4D2)) { -#ifdef _WIN32 - // XXX: not sure if vstdlib should be done dynamically like this or just - // another stub like tier0? - void *vstdlib = GetModuleHandleW(L"vstdlib.dll"); - if (!vstdlib) { - con_warn("sst: warning: couldn't get vstdlib, won't be able to " - "prevent nag message\n"); + void *kvs = KeyValuesSystem(); + kvsvt = *(void ***)kvs; + if (!os_mprot(kvsvt + 4, sizeof(void *), PAGE_READWRITE)) { + con_warn("sst: warning: couldn't unprotect KeyValuesSystem " + "vtable; won't be able to prevent nag message\n"); goto e; } - void *(*KeyValuesSystem)(void) = (void *(*)(void))os_dlsym(vstdlib, - "KeyValuesSystem"); - if (KeyValuesSystem) { - void *kvs = KeyValuesSystem(); - kvsvt = *(void ***)kvs; - if (!os_mprot(kvsvt + 4, sizeof(void *), PAGE_READWRITE)) { - con_warn("sst: warning: couldn't unprotect KeyValuesSystem " - "vtable; won't be able to prevent nag message\n"); - goto e; - } - orig_GetStringForSymbol = (GetStringForSymbol_func)hook_vtable( - kvsvt, 4, (void *)GetStringForSymbol_hook); - } -#else -#warning TODO(linux) suitably abstract this stuff to Linux! -#endif + orig_GetStringForSymbol = (GetStringForSymbol_func)hook_vtable(kvsvt, + 4, (void *)GetStringForSymbol_hook); } e: con_colourmsg(RGBA(64, 255, 64, 255), -- cgit v1.2.3