From 0b16e8f9121f68e6a4ecac50346d84ce35cade46 Mon Sep 17 00:00:00 2001 From: Agent X <44549182+Agent-11@users.noreply.github.com> Date: Sat, 9 Mar 2024 23:47:39 -0500 Subject: [PATCH] Overhaul launch paremeter code --- src/pc/cliopts.c | 95 ++++++++++++++++++---------------------- src/pc/cliopts.h | 25 +++++------ src/pc/configfile.c | 2 +- src/pc/djui/djui.c | 21 +++++---- src/pc/loading.c | 3 +- src/pc/network/network.c | 2 +- src/pc/pc_main.c | 29 ++++++------ 7 files changed, 82 insertions(+), 95 deletions(-) diff --git a/src/pc/cliopts.c b/src/pc/cliopts.c index 0b79af88d..f8b2394d5 100644 --- a/src/pc/cliopts.c +++ b/src/pc/cliopts.c @@ -10,20 +10,22 @@ #include #include -struct PCCLIOptions gCLIOpts; +struct CLIOptions gCLIOpts; static void print_help(void) { - printf("\nsm64coopdx\n"); - printf("%-20s\tSaves the configuration file as CONFIGNAME.\n", "--configfile CONFIGNAME"); - printf("%-20s\tSets additional data directory name (only 'res' is used by default).\n", "--gamedir DIRNAME"); - printf("%-20s\tOverrides the default save/config path ('!' expands to executable path).\n", "--savepath SAVEPATH"); - printf("%-20s\tStarts the game in full screen mode.\n", "--fullscreen"); - printf("%-20s\tSkips the Peach and Castle intro when starting a new game.\n", "--skip-intro"); - printf("%-20s\tStarts the game in windowed mode.\n", "--windowed"); - printf("%-20s\tStarts the game and creates a new server.\n", "--server PORT"); - printf("%-20s\tStarts the game and joins an existing server.\n", "--client IP PORT"); - printf("%-20s\tStarts the game using a poolsize of your choice.\n", "--poolsize POOLSIZE"); - printf("%-20s\tStarts the game with a specific playername.\n", "--playername PLAYERNAME"); + printf("sm64coopdx\n"); +#if defined(_WIN32) || defined(_WIN64) + printf("--console Enables the Windows console.\n"); +#endif + printf("--savepath SAVEPATH Overrides the default save/config path ('!' expands to executable path).\n"); + printf("--configfile CONFIGNAME Saves the configuration file as CONFIGNAME.\n"); + printf("--hide-loading-screen Hides the loading screen before the menu boots up.\n"); + printf("--fullscreen Starts the game in full screen mode.\n"); + printf("--windowed Starts the game in windowed mode.\n"); + printf("--skip-intro Skips the Peach and Lakitu intros when on a zero star save.\n"); + printf("--server PORT Starts the game and creates a new server on PORT.\n"); + printf("--client IP PORT Starts the game and joins an existing server.\n"); + printf("--playername PLAYERNAME Starts the game with a specific playername.\n"); } static inline int arg_string(const char *name, const char *value, char *target, int maxLength) { @@ -43,55 +45,42 @@ 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. + // initialize options with false values memset(&gCLIOpts, 0, sizeof(gCLIOpts)); for (int i = 1; i < argc; i++) { - if (strcmp(argv[i], "--skip-intro") == 0) // Skip Peach Intro - gCLIOpts.SkipIntro = 1; - - else if (strcmp(argv[i], "--fullscreen") == 0) // Open game in fullscreen - gCLIOpts.FullScreen = 1; - - else if (strcmp(argv[i], "--windowed") == 0) // Open game in windowed mode - gCLIOpts.FullScreen = 2; - #if defined(_WIN32) || defined(_WIN64) - else if (strcmp(argv[i], "--console") == 0) // Open game with console - gCLIOpts.Console = 1; + if (!strcmp(argv[i], "--console")) { + gCLIOpts.console = true; + } else if (!strcmp(argv[i], "--savepath") && (i + 1) < argc) { +#else + if (!strcmp(argv[i], "--savepath") && (i + 1) < argc) { #endif - - else if (strcmp(argv[i], "--server") == 0 && (i + 1) < argc) { // Host server - gCLIOpts.Network = NT_SERVER; - arg_uint("--server ", argv[++i], &gCLIOpts.NetworkPort); - - } else if (strcmp(argv[i], "--client") == 0 && (((i + 1) < argc) || (i + 2) < argc)) { // Join server - gCLIOpts.Network = NT_CLIENT; - arg_string("--client ", argv[++i], gCLIOpts.JoinIp, IP_MAX_LEN); + arg_string("--savepath", argv[++i], gCLIOpts.savePath, SYS_MAX_PATH); + } else if (!strcmp(argv[i], "--configfile") && (i + 1) < argc) { + arg_string("--configfile", argv[++i], gCLIOpts.configFile, SYS_MAX_PATH); + } else if (!strcmp(argv[i], "--hide-loading-screen")) { + gCLIOpts.hideLoadingScreen = true; + } else if (!strcmp(argv[i], "--fullscreen")) { + gCLIOpts.fullscreen = 1; + } else if (!strcmp(argv[i], "--windowed")) { + gCLIOpts.fullscreen = 2; + } else if (!strcmp(argv[i], "--skip-intro")) { + gCLIOpts.skipIntro = true; + } else if (!strcmp(argv[i], "--server") && (i + 1) < argc) { + gCLIOpts.network = NT_SERVER; + arg_uint("--server ", argv[++i], &gCLIOpts.networkPort); + } else if (!strcmp(argv[i], "--client") && (((i + 1) < argc) || (i + 2) < argc)) { + gCLIOpts.network = NT_CLIENT; + arg_string("--client ", argv[++i], gCLIOpts.joinIp, IP_MAX_LEN); if ((i + 2) < argc) { - arg_uint("--client ", argv[++i], &gCLIOpts.NetworkPort); + arg_uint("--client ", argv[++i], &gCLIOpts.networkPort); } else { - gCLIOpts.NetworkPort = 7777; + gCLIOpts.networkPort = 7777; } - - } else if (strcmp(argv[i], "--poolsize") == 0) // Main pool size - arg_uint("--poolsize", argv[++i], &gCLIOpts.PoolSize); - - else if (strcmp(argv[i], "--configfile") == 0 && (i + 1) < argc) - arg_string("--configfile", argv[++i], gCLIOpts.ConfigFile, SYS_MAX_PATH); - - else if (strcmp(argv[i], "--gamedir") == 0 && (i + 1) < argc) - arg_string("--gamedir", argv[++i], gCLIOpts.GameDir, SYS_MAX_PATH); - - else if (strcmp(argv[i], "--savepath") == 0 && (i + 1) < argc) - arg_string("--savepath", argv[++i], gCLIOpts.SavePath, SYS_MAX_PATH); - - else if (strcmp(argv[i], "--playername") == 0 && (i + 1) < argc) - arg_string("--playername", argv[++i], gCLIOpts.PlayerName, MAX_PLAYER_STRING); - - // Print help - else if (strcmp(argv[i], "--help") == 0) { + } else if (!strcmp(argv[i], "--playername") && (i + 1) < argc) { + arg_string("--playername", argv[++i], gCLIOpts.playerName, MAX_PLAYER_STRING); + } else if (!strcmp(argv[i], "--help")) { print_help(); return false; } diff --git a/src/pc/cliopts.h b/src/pc/cliopts.h index eb8948ee9..dd0fb0091 100644 --- a/src/pc/cliopts.h +++ b/src/pc/cliopts.h @@ -13,23 +13,22 @@ enum NetworkType { #define IP_MAX_LEN 32 #define PORT_MAX_LEN 16 -struct PCCLIOptions { - unsigned int SkipIntro; - unsigned int FullScreen; +struct CLIOptions { #if defined(_WIN32) || defined(_WIN64) - unsigned int Console; + bool console; #endif - enum NetworkType Network; - char JoinIp[IP_MAX_LEN]; - unsigned int NetworkPort; - unsigned int PoolSize; - char ConfigFile[SYS_MAX_PATH]; - char SavePath[SYS_MAX_PATH]; - char GameDir[SYS_MAX_PATH]; - char PlayerName[MAX_PLAYER_STRING]; + char savePath[SYS_MAX_PATH]; + char configFile[SYS_MAX_PATH]; + unsigned int fullscreen; + bool skipIntro; + enum NetworkType network; + unsigned int networkPort; + char joinIp[IP_MAX_LEN]; + char playerName[MAX_PLAYER_STRING]; + bool hideLoadingScreen; }; -extern struct PCCLIOptions gCLIOpts; +extern struct CLIOptions gCLIOpts; bool parse_cli_opts(int argc, char* argv[]); diff --git a/src/pc/configfile.c b/src/pc/configfile.c index b35d1eb1c..d988393ef 100644 --- a/src/pc/configfile.c +++ b/src/pc/configfile.c @@ -482,7 +482,7 @@ static unsigned int tokenize_string(char *str, int maxTokens, char **tokens) { // Gets the config file path and caches it const char *configfile_name(void) { - return (gCLIOpts.ConfigFile[0]) ? gCLIOpts.ConfigFile : CONFIGFILE_DEFAULT; + return (gCLIOpts.configFile[0]) ? gCLIOpts.configFile : CONFIGFILE_DEFAULT; } const char *configfile_backup_name(void) { diff --git a/src/pc/djui/djui.c b/src/pc/djui/djui.c index 572bb1911..4a8a18848 100644 --- a/src/pc/djui/djui.c +++ b/src/pc/djui/djui.c @@ -89,18 +89,17 @@ void djui_init(void) { } void djui_init_late(void) { - if (gCLIOpts.Network != NT_SERVER) { - djui_panel_main_create(NULL); - if (configLanguage[0] == '\0') { - gPanelLanguageOnStartup = true; - djui_panel_language_create(NULL); - } - if (strcmp(configLastVersion, SM64COOPDX_VERSION)) { - strncpy(configLastVersion, SM64COOPDX_VERSION, MAX_CONFIG_STRING); - djui_panel_changelog_create(NULL); - } - //djui_panel_debug_create(); + djui_panel_main_create(NULL); + if (configLanguage[0] == '\0') { + gPanelLanguageOnStartup = true; + djui_panel_language_create(NULL); } + if (strcmp(configLastVersion, SM64COOPDX_VERSION)) { + strncpy(configLastVersion, SM64COOPDX_VERSION, MAX_CONFIG_STRING); + djui_panel_changelog_create(NULL); + } + + // djui_panel_debug_create(); djui_cursor_create(); } diff --git a/src/pc/loading.c b/src/pc/loading.c index 4dc8d7e25..065070c86 100644 --- a/src/pc/loading.c +++ b/src/pc/loading.c @@ -7,6 +7,7 @@ #include "pc_main.h" #include "loading.h" #include "pc/utils/misc.h" +#include "pc/cliopts.h" extern ALIGNED8 u8 texture_coopdx_logo[]; @@ -47,7 +48,7 @@ static void loading_screen_produce_one_frame(void) { gSPPopMatrix(gDisplayListHead++, G_MTX_MODELVIEW); // render loading screen elements - if (sLoading) { djui_base_render(&sLoading->base); } + if (sLoading && !gCLIOpts.hideLoadingScreen) { djui_base_render(&sLoading->base); } // render frame djui_gfx_displaylist_end(); diff --git a/src/pc/network/network.c b/src/pc/network/network.c index 12541120e..f4722b12a 100644 --- a/src/pc/network/network.c +++ b/src/pc/network/network.c @@ -119,7 +119,7 @@ bool network_init(enum NetworkType inNetworkType, bool reconnecting) { gServerSettings.bouncyLevelBounds = configCoopCompatibility ? 0 : configBouncyLevelBounds; gServerSettings.playerKnockbackStrength = configPlayerKnockbackStrength; gServerSettings.stayInLevelAfterStar = configStayInLevelAfterStar; - gServerSettings.skipIntro = configSkipIntro; + gServerSettings.skipIntro = gCLIOpts.skipIntro ? TRUE : configSkipIntro; gServerSettings.enableCheats = 0; gServerSettings.bubbleDeath = configBubbleDeath; gServerSettings.enablePlayersInLevelDisplay = TRUE; diff --git a/src/pc/pc_main.c b/src/pc/pc_main.c index 007612261..75052ddd9 100644 --- a/src/pc/pc_main.c +++ b/src/pc/pc_main.c @@ -268,9 +268,8 @@ void game_exit(void) { } void* main_game_init(UNUSED void* arg) { - const char *gamedir = gCLIOpts.GameDir[0] ? gCLIOpts.GameDir : FS_BASEDIR; - const char *userpath = gCLIOpts.SavePath[0] ? gCLIOpts.SavePath : sys_user_path(); - fs_init(sys_ropaths, gamedir, userpath); + const char *userpath = gCLIOpts.savePath[0] ? gCLIOpts.savePath : sys_user_path(); + fs_init(sys_ropaths, FS_BASEDIR, userpath); if (gIsThreaded) { REFRESH_MUTEX(snprintf(gCurrLoadingSegment.str, 256, "Loading")); } dynos_gfx_init(); @@ -280,7 +279,7 @@ void* main_game_init(UNUSED void* arg) { configWindow.settings_changed = true; if (!djui_language_init(configLanguage)) { snprintf(configLanguage, MAX_CONFIG_STRING, "%s", ""); } - if (gCLIOpts.Network != NT_SERVER) { + if (gCLIOpts.network != NT_SERVER) { check_for_updates(); } @@ -306,11 +305,11 @@ void* main_game_init(UNUSED void* arg) { } else if (memcmp(&configPlayerPalette, &gPalettePresets[i], sizeof(struct PlayerPalette)) == 0) { break; } } - if (gCLIOpts.FullScreen == 1) { configWindow.fullscreen = true; } - else if (gCLIOpts.FullScreen == 2) { configWindow.fullscreen = false; } + if (gCLIOpts.fullscreen == 1) { configWindow.fullscreen = true; } + else if (gCLIOpts.fullscreen == 2) { configWindow.fullscreen = false; } - if (gCLIOpts.PlayerName[0] != '\0') { - snprintf(configPlayerName, MAX_PLAYER_STRING, "%s", gCLIOpts.PlayerName); + if (gCLIOpts.playerName[0] != '\0') { + snprintf(configPlayerName, MAX_PLAYER_STRING, "%s", gCLIOpts.playerName); } if (!gGfxInited) { @@ -339,7 +338,7 @@ int main(int argc, char *argv[]) { #if defined(_WIN32) || defined(_WIN64) // Handle Windows console - if (!gCLIOpts.Console) { + if (!gCLIOpts.console) { FreeConsole(); } @@ -377,15 +376,15 @@ int main(int argc, char *argv[]) { show_update_popup(); // Init network - if (gCLIOpts.Network == NT_CLIENT) { + if (gCLIOpts.network == NT_CLIENT) { network_set_system(NS_SOCKET); - snprintf(gGetHostName, MAX_CONFIG_STRING, "%s", gCLIOpts.JoinIp); - snprintf(configJoinIp, MAX_CONFIG_STRING, "%s", gCLIOpts.JoinIp); - configJoinPort = gCLIOpts.NetworkPort; + snprintf(gGetHostName, MAX_CONFIG_STRING, "%s", gCLIOpts.joinIp); + snprintf(configJoinIp, MAX_CONFIG_STRING, "%s", gCLIOpts.joinIp); + configJoinPort = gCLIOpts.networkPort; network_init(NT_CLIENT, false); - } else if (gCLIOpts.Network == NT_SERVER) { + } else if (gCLIOpts.network == NT_SERVER) { network_set_system(NS_SOCKET); - configHostPort = gCLIOpts.NetworkPort; + configHostPort = gCLIOpts.networkPort; djui_panel_do_host(NULL); } else { network_init(NT_NONE, false);