Add enable/disable mod launch parameters

This commit is contained in:
Agent X 2025-01-11 13:12:34 -05:00
parent fefb222198
commit dc416cecf8
3 changed files with 37 additions and 1 deletions

View file

@ -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;

View file

@ -28,6 +28,9 @@ struct CLIOptions {
bool hideLoadingScreen;
bool skipUpdateCheck;
bool noDiscord;
bool disableMods;
int enabledModsCount;
char** enableMods;
};
extern struct CLIOptions gCLIOpts;

View file

@ -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