diff options
author | Matthew Wozniak <me@woz.blue> | 2024-11-03 00:20:45 -0400 |
---|---|---|
committer | Matthew Wozniak <me@woz.blue> | 2024-11-03 00:22:05 -0400 |
commit | 492aac484b5c65e5df21a7d1b1cf781063efef50 (patch) | |
tree | 01055654432f784c6d709690f0d6b7e175c3262d /main.c | |
parent | d00096fe2ea3dd64cff9878879c077f23a783e4a (diff) | |
download | rt-492aac484b5c65e5df21a7d1b1cf781063efef50.tar.gz rt-492aac484b5c65e5df21a7d1b1cf781063efef50.zip |
purge CR from this project
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 140 |
1 files changed, 70 insertions, 70 deletions
@@ -1,70 +1,70 @@ -// SPDX-License-Identifier: ISC
-// SPDX-FileCopyrightText: 2024 Matthew Wozniak <me@woz.blue>
-
-#include "api.h"
-#include "hook.h"
-#include "log.h"
-#include "os.h"
-
-#include <stddef.h>
-#define WIN32_LEAN_AND_MEAN
-#include <Windows.h>
-
-void (*orig_cbuf_addtext)(char *);
-void hook_cbuf_addtext(char *str) {
- orig_cbuf_addtext(str);
- // this is the last thing that happens when the game is opened
- if (!strcmp(str, "exec modsettings.cfg mod\n")) {
- }
-}
-
-char *cmdline;
-char WINAPI *hook_GetCommandLineA(void) {
- return cmdline;
-}
-
-void *(WINAPI *orig_LoadLibraryExA)(const char *, void *, int);
-void WINAPI *hook_LoadLibraryExA(const char *filename, void *hfile, int flags) {
- // if the dll is already loaded, don't run our code again
- if (os_dlhandle(filename))
- return orig_LoadLibraryExA(filename, hfile, flags);
- void *ret = orig_LoadLibraryExA(filename, hfile, flags);
- if (!ret) return ret;
- // cut down to basename for display
- const char *basename = filename;
- for (const char *p = filename; *p; p++)
- if (*p == '\\') basename = p + 1;
-
- if (!strcmp(basename, "engine.dll")) {
- if (!api_init()) die("couldn't get apis");
- orig_cbuf_addtext = (void (*)(char *))
- hook_inline((void *)cbuf_addtext, (void *)hook_cbuf_addtext);
- }
- return ret;
-}
-
-typedef int (*LauncherMain_t)(void *instance, void *prev_inst, char *cmdline,
- int cmd_show);
-
-int main(void/* int argc, char **argv */) {
- SetDllDirectoryA("bin/");
-
- // TODO: make this changeable by the user
- cmdline = "hl2.exe -console -w 1280 -h 720 -window -high -dxlevel 95";
-
- hook_init();
- orig_LoadLibraryExA = (typeof(orig_LoadLibraryExA))hook_dllapi("kernel32",
- "LoadLibraryExA", (void *)hook_LoadLibraryExA);
- hook_dllapi("kernel32", "GetCommandLineA", (void *)hook_GetCommandLineA);
-
- info("GetCommandLineA() = %s", GetCommandLineA());
-
- void *launcher_dll = os_dlopen("launcher");
- LauncherMain_t launcher_main =
- (LauncherMain_t)os_dlsym(launcher_dll, "LauncherMain");
-
- if (!launcher_main) die("couldn't open launcher");
- launcher_main(NULL, NULL, cmdline, 0);
-}
-
-// vi: sw=4 ts=4 noet tw=80 cc=80
+// SPDX-License-Identifier: ISC +// SPDX-FileCopyrightText: 2024 Matthew Wozniak <me@woz.blue> + +#include "api.h" +#include "hook.h" +#include "log.h" +#include "os.h" + +#include <stddef.h> +#define WIN32_LEAN_AND_MEAN +#include <Windows.h> + +void (*orig_cbuf_addtext)(char *); +void hook_cbuf_addtext(char *str) { + orig_cbuf_addtext(str); + // this is the last thing that happens when the game is opened + if (!strcmp(str, "exec modsettings.cfg mod\n")) { + } +} + +char *cmdline; +char WINAPI *hook_GetCommandLineA(void) { + return cmdline; +} + +void *(WINAPI *orig_LoadLibraryExA)(const char *, void *, int); +void WINAPI *hook_LoadLibraryExA(const char *filename, void *hfile, int flags) { + // if the dll is already loaded, don't run our code again + if (os_dlhandle(filename)) + return orig_LoadLibraryExA(filename, hfile, flags); + void *ret = orig_LoadLibraryExA(filename, hfile, flags); + if (!ret) return ret; + // cut down to basename for display + const char *basename = filename; + for (const char *p = filename; *p; p++) + if (*p == '\\') basename = p + 1; + + if (!strcmp(basename, "engine.dll")) { + if (!api_init()) die("couldn't get apis"); + orig_cbuf_addtext = (void (*)(char *)) + hook_inline((void *)cbuf_addtext, (void *)hook_cbuf_addtext); + } + return ret; +} + +typedef int (*LauncherMain_t)(void *instance, void *prev_inst, char *cmdline, + int cmd_show); + +int main(void/* int argc, char **argv */) { + SetDllDirectoryA("bin/"); + + // TODO: make this changeable by the user + cmdline = "hl2.exe -console -w 1280 -h 720 -window -high -dxlevel 95"; + + hook_init(); + orig_LoadLibraryExA = (typeof(orig_LoadLibraryExA))hook_dllapi("kernel32", + "LoadLibraryExA", (void *)hook_LoadLibraryExA); + hook_dllapi("kernel32", "GetCommandLineA", (void *)hook_GetCommandLineA); + + info("GetCommandLineA() = %s", GetCommandLineA()); + + void *launcher_dll = os_dlopen("launcher"); + LauncherMain_t launcher_main = + (LauncherMain_t)os_dlsym(launcher_dll, "LauncherMain"); + + if (!launcher_main) die("couldn't open launcher"); + launcher_main(NULL, NULL, cmdline, 0); +} + +// vi: sw=4 ts=4 noet tw=80 cc=80 |