From fb95177298bb92098b61f09b9f66c1fce32f2f02 Mon Sep 17 00:00:00 2001 From: Matthew Wozniak Date: Sun, 27 Oct 2024 23:28:51 -0400 Subject: add hooking and IVEngineServer interface --- main.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index ae79d3b..e16786e 100644 --- a/main.c +++ b/main.c @@ -1,11 +1,32 @@ // SPDX-License-Identifier: ISC // SPDX-FileCopyrightText: 2024 Matthew Wozniak -#include "os.h" +#include "api.h" +#include "hook.h" #include "log.h" +#include "os.h" -#include #include +#define WIN32_LEAN_AND_MEAN +#include + +void *(WINAPI *orig_LoadLibraryExA)(const char *, void *, int); +void WINAPI *hook_LoadLibraryExA(const char *filename, void *hfile, int flags) { + void *ret = orig_LoadLibraryExA(filename, hfile, flags); + if (!ret) return ret; + // cut down to basename + const char *basename = filename; + for (const char *p = filename; *p; p++) + if (*p == '\\') basename = p + 1; + info("loaded %s", basename); + + // last dll to load + if (!strcmp(basename, "serverbrowser.dll")) { + api_init(); + // TODO: figure out hooks that run AFTER valve.rc is called + } + return ret; +} typedef int (*LauncherMain_t)(void *instance, void *prev_inst, char *cmdline, int cmd_show); @@ -17,6 +38,10 @@ int main(int argc, char **argv) { LauncherMain_t launcher_main = (LauncherMain_t)os_dlsym(launcher_dll, "LauncherMain"); + hook_init(); + orig_LoadLibraryExA = (typeof(orig_LoadLibraryExA))hook_dllapi("kernel32", + "LoadLibraryExA", (void *)hook_LoadLibraryExA); + if (!launcher_main) die("couldn't open launcher"); launcher_main(NULL, NULL, NULL, 0); } -- cgit v1.2.3-54-g00ecf