From 6a577d691ffc7a9d19c5b735fdb26c8193915379 Mon Sep 17 00:00:00 2001 From: MysterD Date: Fri, 14 Apr 2023 11:59:35 -0700 Subject: [PATCH] Make lobby hosting detect the largest mod by lua size --- src/pc/mods/mod.c | 13 +++++++++++++ src/pc/mods/mod.h | 1 + src/pc/mods/mods.c | 17 +++++++++++++++++ src/pc/mods/mods.h | 1 + src/pc/network/coopnet/coopnet.c | 5 ++++- 5 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/pc/mods/mod.c b/src/pc/mods/mod.c index e7ba2f364..df2b6b699 100644 --- a/src/pc/mods/mod.c +++ b/src/pc/mods/mod.c @@ -7,6 +7,19 @@ #include "pc/utils/md5.h" #include "pc/debuglog.h" +size_t mod_get_lua_size(struct Mod* mod) { + if (!mod) { return 0; } + size_t size = 0; + + for (int i = 0; i < mod->fileCount; i++) { + struct ModFile* file = &mod->files[i]; + if (!str_ends_with(file->relativePath, ".lua")) { continue; } + size += file->size; + } + + return size; +} + static void mod_activate_bin(struct ModFile* file) { // copy geo name char geoName[64] = { 0 }; diff --git a/src/pc/mods/mod.h b/src/pc/mods/mod.h index 62774dd4e..2f57f22fb 100644 --- a/src/pc/mods/mod.h +++ b/src/pc/mods/mod.h @@ -32,6 +32,7 @@ struct Mod { size_t size; }; +size_t mod_get_lua_size(struct Mod* mod); void mod_activate(struct Mod* mod); void mod_clear(struct Mod* mod); bool mod_load(struct Mods* mods, char* basePath, char* modName); diff --git a/src/pc/mods/mods.c b/src/pc/mods/mods.c index 5345a5c82..c3611c43b 100644 --- a/src/pc/mods/mods.c +++ b/src/pc/mods/mods.c @@ -20,6 +20,23 @@ struct LocalEnabledPath { struct LocalEnabledPath* sLocalEnabledPaths = NULL; +void mods_get_main_mod_name(char* destination, u32 maxSize) { + struct Mod* picked = NULL; + size_t pickedSize = 0; + + for (unsigned int i = 0; i < gLocalMods.entryCount; i++) { + struct Mod* mod = gLocalMods.entries[i]; + if (!mod->enabled) { continue; } + size_t size = mod_get_lua_size(mod); + if (size > pickedSize) { + picked = mod; + pickedSize = size; + } + } + + snprintf(destination, maxSize, "%s", picked ? picked->name : "Super Mario 64"); +} + static void mods_local_store_enabled(void) { assert(sLocalEnabledPaths == NULL); struct LocalEnabledPath* prev = NULL; diff --git a/src/pc/mods/mods.h b/src/pc/mods/mods.h index 59a5f1f51..3560e1253 100644 --- a/src/pc/mods/mods.h +++ b/src/pc/mods/mods.h @@ -22,6 +22,7 @@ extern struct Mods gActiveMods; extern char gRemoteModsBasePath[]; +void mods_get_main_mod_name(char* destination, u32 maxSize); bool mods_generate_remote_base_path(void); void mods_activate(struct Mods* mods); void mods_clear(struct Mods* mods); diff --git a/src/pc/network/coopnet/coopnet.c b/src/pc/network/coopnet/coopnet.c index cd0ce6598..757031765 100644 --- a/src/pc/network/coopnet/coopnet.c +++ b/src/pc/network/coopnet/coopnet.c @@ -5,6 +5,7 @@ #include "pc/network/version.h" #include "pc/djui/djui_language.h" #include "pc/djui/djui_popup.h" +#include "pc/mods/mods.h" #include "pc/debuglog.h" #ifdef COOPNET @@ -100,7 +101,9 @@ void ns_coopnet_update(void) { if (gNetworkType != NT_NONE && sNetworkType != NT_NONE) { if (sNetworkType == NT_SERVER) { LOG_INFO("Create lobby"); - coopnet_lobby_create(CN_GAME_STR, get_version(), configPlayerName, "Super Mario 64", (uint16_t)configAmountofPlayers, ""); + char mode[64] = ""; + mods_get_main_mod_name(mode, 64); + coopnet_lobby_create(CN_GAME_STR, get_version(), configPlayerName, mode, (uint16_t)configAmountofPlayers, ""); } else if (sNetworkType == NT_CLIENT) { LOG_INFO("Join lobby"); coopnet_lobby_join(gCoopNetDesiredLobby, "");