aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorGravatar Matthew Wozniak <me@woz.blue> 2024-11-01 13:47:31 -0400
committerGravatar Matthew Wozniak <me@woz.blue> 2024-11-01 13:48:09 -0400
commita2f7e37d8adf2047e1f3b0ea1227ac9d51514783 (patch)
tree2942ee2a12abe02e27f119552221c6a06ac87273 /main.c
parentfb95177298bb92098b61f09b9f66c1fce32f2f02 (diff)
downloadrt-a2f7e37d8adf2047e1f3b0ea1227ac9d51514783.tar.gz
rt-a2f7e37d8adf2047e1f3b0ea1227ac9d51514783.zip
play demo using the demoplayer object
Diffstat (limited to 'main.c')
-rw-r--r--main.c44
1 files changed, 34 insertions, 10 deletions
diff --git a/main.c b/main.c
index e16786e..376c615 100644
--- a/main.c
+++ b/main.c
@@ -10,20 +10,38 @@
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
+void (*orig_cbuf_addtext)(char *);
+void hook_cbuf_addtext(char *str) {
+ orig_cbuf_addtext(str);
+ info("%s", str);
+ // this is the last thing that happens when the game is opened
+ if (!strcmp(str, "exec modsettings.cfg mod\n")) {
+ demoplayer->vt->start_playback(demoplayer, "demo.dem", false);
+ }
+}
+
+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
+ // cut down to basename for display
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
+ 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;
}
@@ -31,19 +49,25 @@ void WINAPI *hook_LoadLibraryExA(const char *filename, void *hfile, int flags) {
typedef int (*LauncherMain_t)(void *instance, void *prev_inst, char *cmdline,
int cmd_show);
-int main(int argc, char **argv) {
+int main(/* int argc, char **argv */) {
SetDllDirectoryA("bin/");
- void *launcher_dll = os_dlopen("launcher");
- LauncherMain_t launcher_main =
- (LauncherMain_t)os_dlsym(launcher_dll, "LauncherMain");
+ // 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, NULL, 0);
+ launcher_main(NULL, NULL, cmdline, 0);
}
// vi: sw=4 ts=4 noet tw=80 cc=80