aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c81
1 files changed, 75 insertions, 6 deletions
diff --git a/main.c b/main.c
index 8f487a1..a8b5725 100644
--- a/main.c
+++ b/main.c
@@ -17,21 +17,42 @@
#include "api.h"
#include "hook.h"
#include "log.h"
+#include "render.h"
#include "os.h"
+#include "ms/getopt.h"
+
#include <stddef.h>
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
+struct {
+ int width;
+ int height;
+ char *game;
+ int fps;
+ int quality;
+ int bitrate;
+ char *out;
+ char **demo;
+ bool combine;
+} args = {0};
+
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")) {
+ bool use_bitrate = !!args.bitrate;
+ if (!render_init(args.width, args.height, args.fps, use_bitrate,
+ use_bitrate ? args.bitrate : args.quality, args.out))
+ die("couldn't init render");
+ // play the demo
+ demoplayer->vt->start_playback(demoplayer, args.demo[0], false);
}
}
-char *cmdline;
+char cmdline[128];
char WINAPI *hook_GetCommandLineA(void) {
return cmdline;
}
@@ -59,19 +80,67 @@ 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(void/* int argc, char **argv */) {
+int main(int argc, char **argv) {
SetDllDirectoryA("bin/");
+ int c;
+ char *strend;
+ while ((c = getopt(argc, argv, "w:h:g:r:q:b:")) != -1) {
+ switch (c) {
+ case 'w':
+ args.width = strtol(optarg, &strend, 10);
+ if (strend == optarg) die("width must be a number!");
+ break;
+ case 'h':
+ args.height = strtol(optarg, &strend, 10);
+ if (strend == optarg) die("height must be a number");
+ break;
+ case 'r':
+ args.fps = strtol(optarg, &strend, 10);
+ if (strend == optarg) die("must pass a number to -w!");
+ break;
+ case 'q':
+ args.quality = strtol(optarg, &strend, 10);
+ if (strend == optarg) die("must pass a number to -w!");
+ break;
+ case 'b':
+ args.bitrate = strtol(optarg, &strend, 10);
+ if (strend == optarg) die("must pass a number to -w!");
+ break;
+ case 'g':
+ args.game = optarg;
+ case '1':
+ args.combine = true;
+ case '?':
+ break;
+ }
+ }
+
+ if (!args.width) args.width = 1280;
+ if (!args.height) args.height = 720;
+ if (!args.game) args.game = "hl2";
+ if (!args.fps) args.fps = 30;
+ if (!args.quality) args.quality = 75;
- // TODO: make this changeable by the user
- cmdline = "hl2.exe -console -w 1280 -h 720 -window -high -dxlevel 95";
+ if (argc - optind < 2) {
+ printf(
+ "usage:\n"
+ " rt -w <width> -h <height> -g <game> -r <fps> [-q <quality>] [-b <bitrate>]\n"
+ " path/to/video.mp4 path/to/demo1.dem...\n");
+ exit(1);
+ }
+ args.out = argv[optind++];
+ args.demo = argv + optind;
+
+ sprintf(cmdline, "hl2.exe -game %s -w %d -h %d -window -console",
+ args.game, args.width, args.height);
+
+ info("cmdline = %s", cmdline);
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");