From ae22eaac989e94d7e2bc6e0a98d9a31faf98c248 Mon Sep 17 00:00:00 2001 From: Agent X <44549182+Agent-11@users.noreply.github.com> Date: Sat, 11 Nov 2023 14:16:27 -0500 Subject: [PATCH] Add "-- deluxe:" field to mods --- autogen/lua_definitions/structs.lua | 1 + docs/lua/structs.md | 1 + src/pc/lua/smlua_cobject_autogen.c | 3 ++- src/pc/mods/mod.c | 2 ++ src/pc/mods/mod.h | 1 + src/pc/mods/mods_utils.c | 12 ++++++++++++ src/pc/network/packets/packet_mod_list.c | 7 +++++++ 7 files changed, 26 insertions(+), 1 deletion(-) diff --git a/autogen/lua_definitions/structs.lua b/autogen/lua_definitions/structs.lua index e422de56..00f4ec1c 100644 --- a/autogen/lua_definitions/structs.lua +++ b/autogen/lua_definitions/structs.lua @@ -1042,6 +1042,7 @@ --- @class Mod --- @field public basePath string --- @field public customBehaviorIndex integer +--- @field public deluxe boolean --- @field public description string --- @field public enabled boolean --- @field public fileCount integer diff --git a/docs/lua/structs.md b/docs/lua/structs.md index c001c250..9772ee44 100644 --- a/docs/lua/structs.md +++ b/docs/lua/structs.md @@ -1420,6 +1420,7 @@ | ----- | ---- | ------ | | basePath | `string` | read-only | | customBehaviorIndex | `integer` | read-only | +| deluxe | `boolean` | read-only | | description | `string` | read-only | | enabled | `boolean` | read-only | | fileCount | `integer` | read-only | diff --git a/src/pc/lua/smlua_cobject_autogen.c b/src/pc/lua/smlua_cobject_autogen.c index ec494953..161bf672 100644 --- a/src/pc/lua/smlua_cobject_autogen.c +++ b/src/pc/lua/smlua_cobject_autogen.c @@ -1160,10 +1160,11 @@ static struct LuaObjectField sMarioStateFields[LUA_MARIO_STATE_FIELD_COUNT] = { { "waterLevel", LVT_S16, offsetof(struct MarioState, waterLevel), false, LOT_NONE }, }; -#define LUA_MOD_FIELD_COUNT 12 +#define LUA_MOD_FIELD_COUNT 13 static struct LuaObjectField sModFields[LUA_MOD_FIELD_COUNT] = { { "basePath", LVT_STRING, offsetof(struct Mod, basePath), true, LOT_NONE }, { "customBehaviorIndex", LVT_U8, offsetof(struct Mod, customBehaviorIndex), true, LOT_NONE }, + { "deluxe", LVT_BOOL, offsetof(struct Mod, deluxe), true, LOT_NONE }, { "description", LVT_STRING_P, offsetof(struct Mod, description), true, LOT_NONE }, { "enabled", LVT_BOOL, offsetof(struct Mod, enabled), true, LOT_NONE }, { "fileCount", LVT_U16, offsetof(struct Mod, fileCount), true, LOT_NONE }, diff --git a/src/pc/mods/mod.c b/src/pc/mods/mod.c index 2fe1f63e..652ada81 100644 --- a/src/pc/mods/mod.c +++ b/src/pc/mods/mod.c @@ -432,6 +432,8 @@ static void mod_extract_fields(struct Mod* mod) { if (snprintf(mod->description, MOD_DESCRIPTION_MAX_LENGTH, "%s", extracted) < 0) { LOG_INFO("Truncated mod description field '%s'", mod->description); } + } else if (!mod->deluxe && (extracted = extract_lua_field("-- deluxe:", buffer))) { + mod->deluxe = !strcmp(extracted, "true"); } } diff --git a/src/pc/mods/mod.h b/src/pc/mods/mod.h index 2a1a187e..bec06b48 100644 --- a/src/pc/mods/mod.h +++ b/src/pc/mods/mod.h @@ -34,6 +34,7 @@ struct Mod { bool enabled; bool selectable; bool renderBehindHud; + bool deluxe; size_t size; u8 customBehaviorIndex; }; diff --git a/src/pc/mods/mods_utils.c b/src/pc/mods/mods_utils.c index 40ddd9f9..e04cfa1b 100644 --- a/src/pc/mods/mods_utils.c +++ b/src/pc/mods/mods_utils.c @@ -3,6 +3,7 @@ #include "mods.h" #include "mods_utils.h" #include "pc/debuglog.h" +#include "pc/pc_main.h" #if defined(_WIN32) || defined(_WIN64) #include @@ -25,6 +26,16 @@ void mods_size_enforce(struct Mods* mods) { } } +void mods_deluxe_enforce(struct Mods* mods) { + for (int i = 0; i < mods->entryCount; i++) { + struct Mod* mod = mods->entries[i]; + if (mod->deluxe && gCoopCompatibility) { + mod->enabled = false; + mod->selectable = false; + } + } +} + static bool mods_incompatible_match(struct Mod* a, struct Mod* b) { if (a->incompatible == NULL || b->incompatible == NULL) { return false; @@ -76,6 +87,7 @@ void mods_update_selectable(void) { } mods_size_enforce(&gLocalMods); + mods_deluxe_enforce(&gLocalMods); } void mods_delete_folder(char* path) { diff --git a/src/pc/network/packets/packet_mod_list.c b/src/pc/network/packets/packet_mod_list.c index 9f71aecb..62ca70d5 100644 --- a/src/pc/network/packets/packet_mod_list.c +++ b/src/pc/network/packets/packet_mod_list.c @@ -5,6 +5,7 @@ #include "pc/djui/djui.h" #include "pc/djui/djui_panel_join_message.h" #include "pc/debuglog.h" +#include "pc/pc_main.h" #include "pc/mods/mod_cache.h" void network_send_mod_list_request(void) { @@ -84,6 +85,9 @@ void network_send_mod_list(void) { packet_write(&p, mod->relativePath, sizeof(u8) * relativePathLength); packet_write(&p, &modSize, sizeof(u64)); packet_write(&p, &mod->isDirectory, sizeof(u8)); + if (!gCoopCompatibility) { + packet_write(&p, &mod->deluxe, sizeof(u8)); + } packet_write(&p, &mod->fileCount, sizeof(u16)); network_send_to(0, &p); LOG_INFO(" '%s': %llu", mod->name, (u64)mod->size); @@ -222,6 +226,9 @@ void network_receive_mod_list_entry(struct Packet* p) { packet_read(p, mod->relativePath, relativePathLength * sizeof(u8)); packet_read(p, &mod->size, sizeof(u64)); packet_read(p, &mod->isDirectory, sizeof(u8)); + if (!gCoopCompatibility) { + packet_read(p, &mod->deluxe, sizeof(u8)); + } normalize_path(mod->relativePath); LOG_INFO(" '%s': %llu", mod->name, (u64)mod->size);