From dc416cecf883ac0e7df364d21bcdee6cf9d0cea4 Mon Sep 17 00:00:00 2001 From: Agent X <44549182+AgentXLP@users.noreply.github.com> Date: Sat, 11 Jan 2025 13:12:34 -0500 Subject: [PATCH] Add enable/disable mod launch parameters --- src/pc/cliopts.c | 15 ++++++++++++++- src/pc/cliopts.h | 3 +++ src/pc/configfile.c | 20 ++++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/pc/cliopts.c b/src/pc/cliopts.c index 2f444d126..af232cda1 100644 --- a/src/pc/cliopts.c +++ b/src/pc/cliopts.c @@ -27,7 +27,9 @@ static void print_help(void) { printf("--client IP PORT Starts the game and joins an existing server.\n"); printf("--playername PLAYERNAME Starts the game with a specific playername.\n"); printf("--skip-update-check Skips the update check when loading the game.\n"); - printf("--no-discord Disables discord integration."); + printf("--no-discord Disables discord integration.\n"); + printf("--disable-mods Disables all mods that are already enabled.\n"); + printf("--enable-mod MODNAME Enables a mod."); } static inline int arg_string(const char *name, const char *value, char *target, int maxLength) { @@ -49,6 +51,7 @@ static inline int arg_uint(UNUSED const char *name, const char *value, unsigned bool parse_cli_opts(int argc, char* argv[]) { // initialize options with false values memset(&gCLIOpts, 0, sizeof(gCLIOpts)); + gCLIOpts.enableMods = NULL; for (int i = 1; i < argc; i++) { #if defined(_WIN32) || defined(_WIN64) @@ -86,6 +89,16 @@ bool parse_cli_opts(int argc, char* argv[]) { gCLIOpts.skipUpdateCheck = true; } else if (!strcmp(argv[i], "--no-discord")) { gCLIOpts.noDiscord = true; + } else if (!strcmp(argv[i], "--disable-mods")) { + gCLIOpts.disableMods = true; + } else if (!strcmp(argv[i], "--enable-mod") && (i + 1) < argc) { + gCLIOpts.enabledModsCount++; + if (gCLIOpts.enableMods == NULL) { + gCLIOpts.enableMods = malloc(sizeof(char*)); + } else { + gCLIOpts.enableMods = realloc(gCLIOpts.enableMods, sizeof(char*) * gCLIOpts.enabledModsCount); + } + gCLIOpts.enableMods[gCLIOpts.enabledModsCount - 1] = strdup(argv[++i]); } else if (!strcmp(argv[i], "--help")) { print_help(); return false; diff --git a/src/pc/cliopts.h b/src/pc/cliopts.h index 7552519c1..62d30cdee 100644 --- a/src/pc/cliopts.h +++ b/src/pc/cliopts.h @@ -28,6 +28,9 @@ struct CLIOptions { bool hideLoadingScreen; bool skipUpdateCheck; bool noDiscord; + bool disableMods; + int enabledModsCount; + char** enableMods; }; extern struct CLIOptions gCLIOpts; diff --git a/src/pc/configfile.c b/src/pc/configfile.c index a46c2c7c9..2b9ac7b11 100644 --- a/src/pc/configfile.c +++ b/src/pc/configfile.c @@ -360,6 +360,8 @@ void enable_queued_mods(void) { } static void enable_mod_read(char** tokens, UNUSED int numTokens) { + if (gCLIOpts.disableMods) { return; } + char combined[256] = { 0 }; for (int i = 1; i < numTokens; i++) { if (i != 1) { strncat(combined, " ", 255); } @@ -378,6 +380,19 @@ static void enable_mod_read(char** tokens, UNUSED int numTokens) { } } +static void enable_mod(char* mod) { + struct QueuedFile* queued = malloc(sizeof(struct QueuedFile)); + queued->path = strdup(mod); + queued->next = NULL; + if (!sQueuedEnableModsHead) { + sQueuedEnableModsHead = queued; + } else { + struct QueuedFile* tail = sQueuedEnableModsHead; + while (tail->next) { tail = tail->next; } + tail->next = queued; + } +} + static void enable_mod_write(FILE* file) { for (unsigned int i = 0; i < gLocalMods.entryCount; i++) { struct Mod* mod = gLocalMods.entries[i]; @@ -724,6 +739,11 @@ NEXT_OPTION: if (configDjuiTheme >= DJUI_THEME_MAX) { configDjuiTheme = 0; } if (configDjuiScale >= 5) { configDjuiScale = 0; } + for (int i = 0; i < gCLIOpts.enabledModsCount; i++) { + enable_mod(gCLIOpts.enableMods[i]); + } + free(gCLIOpts.enableMods); + #ifndef COOPNET configNetworkSystem = NS_SOCKET; #endif