From b75df78712f65308aa94ea1b2ae4661642da39e9 Mon Sep 17 00:00:00 2001 From: iZePlayz <69536095+iZePlayzYT@users.noreply.github.com> Date: Sat, 11 Jan 2025 21:48:20 +0100 Subject: [PATCH] added --coopnet parameter (#625) * added --coopnet parameter * bug fix * bugfix 2 * bug fix 3 * require password * removed old text * fixed indentation --- src/pc/cliopts.c | 4 ++++ src/pc/cliopts.h | 2 ++ src/pc/pc_main.c | 11 ++++++++--- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/pc/cliopts.c b/src/pc/cliopts.c index 86c61e3f2..08852deca 100644 --- a/src/pc/cliopts.c +++ b/src/pc/cliopts.c @@ -27,6 +27,7 @@ static void print_help(void) { 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("--coopnet PASSWORD Starts the game and creates a new private coopnet server with a password.\n"); printf("--playername PLAYERNAME Starts the game with a specific playername.\n"); printf("--playercount PLAYERCOUNT Starts the game with a specific player count limit.\n"); printf("--skip-update-check Skips the update check when loading the game.\n"); @@ -90,6 +91,9 @@ bool parse_cli_opts(int argc, char* argv[]) { } else { gCLIOpts.networkPort = 7777; } + } else if (!strcmp(argv[i], "--coopnet") && (i + 1) < argc && argv[i + 1][0] != '-') { + gCLIOpts.coopnet = true; + arg_string("--coopnet ", argv[++i], gCLIOpts.coopnetPassword, MAX_CONFIG_STRING); } else if (!strcmp(argv[i], "--playername") && (i + 1) < argc) { arg_string("--playername ", argv[++i], gCLIOpts.playerName, MAX_CONFIG_STRING); } else if (!strcmp(argv[i], "--playercount") && (i + 1) < argc) { diff --git a/src/pc/cliopts.h b/src/pc/cliopts.h index 94b36f451..e30f67be1 100644 --- a/src/pc/cliopts.h +++ b/src/pc/cliopts.h @@ -31,6 +31,8 @@ struct CLIOptions { bool hideLoadingScreen; bool skipUpdateCheck; bool noDiscord; + bool coopnet; + char coopnetPassword[MAX_CONFIG_STRING]; bool disableMods; int enabledModsCount; char** enableMods; diff --git a/src/pc/pc_main.c b/src/pc/pc_main.c index 7fdaecc0b..0446c866e 100644 --- a/src/pc/pc_main.c +++ b/src/pc/pc_main.c @@ -511,9 +511,14 @@ int main(int argc, char *argv[]) { snprintf(configJoinIp, MAX_CONFIG_STRING, "%s", gCLIOpts.joinIp); configJoinPort = gCLIOpts.networkPort; network_init(NT_CLIENT, false); - } else if (gCLIOpts.network == NT_SERVER) { - configNetworkSystem = NS_SOCKET; - configHostPort = gCLIOpts.networkPort; + } else if (gCLIOpts.network == NT_SERVER || gCLIOpts.coopnet == true) { + if (gCLIOpts.network == NT_SERVER) { + configNetworkSystem = NS_SOCKET; + configHostPort = gCLIOpts.networkPort; + } else { + configNetworkSystem = NS_COOPNET; + snprintf(configPassword, MAX_CONFIG_STRING, "%s", gCLIOpts.coopnetPassword); + } // horrible, hacky fix for mods that access marioObj straight away // best fix: host with the standard main menu method