diff --git a/src/pc/djui/djui_panel_mod_menu.c b/src/pc/djui/djui_panel_mod_menu.c index 814ac63e..b10257fe 100644 --- a/src/pc/djui/djui_panel_mod_menu.c +++ b/src/pc/djui/djui_panel_mod_menu.c @@ -2,8 +2,7 @@ #include "djui_panel.h" #include "djui_panel_menu.h" #include "pc/lua/smlua_hooks.h" - -static char* sDjuiPanelModMenuModName = NULL; +#include "pc/mods/mods.h" static char* to_uppercase(char* str) { char* buffer = strdup(str); @@ -82,13 +81,23 @@ static void djui_panel_mod_menu_mod_create_element(struct DjuiBase* parent, int } void djui_panel_mod_menu_mod_create(struct DjuiBase* caller) { - struct DjuiThreePanel* panel = djui_panel_menu_create(to_uppercase(sDjuiPanelModMenuModName)); + struct Mod* mod = NULL; + for (int i = 0; i < gActiveMods.entryCount; i++) { + if (gActiveMods.entries[i]->index == caller->tag) { + mod = gActiveMods.entries[i]; + } + } + if (mod == NULL) { return; } + + struct DjuiThreePanel* panel = djui_panel_menu_create(to_uppercase(mod->name)); struct DjuiBase* body = djui_three_panel_get_body(panel); { struct DjuiPaginated* paginated = djui_paginated_create(body, 8); struct DjuiBase* layoutBase = &paginated->layout->base; for (int i = 0; i < gHookedModMenuElementsCount; i++) { - djui_panel_mod_menu_mod_create_element(layoutBase, i); + if (gHookedModMenuElements[i].mod == mod) { + djui_panel_mod_menu_mod_create_element(layoutBase, i); + } } djui_paginated_calculate_height(paginated); @@ -104,13 +113,24 @@ void djui_panel_mod_menu_create(struct DjuiBase* caller) { { struct DjuiPaginated* paginated = djui_paginated_create(body, 8); struct DjuiBase* layoutBase = &paginated->layout->base; - struct Mod* lastMod = NULL; + struct Mod* addedMods[MAX_HOOKED_MOD_MENU_ELEMENTS] = { 0 }; + int modCount = 0; for (int i = 0; i < gHookedModMenuElementsCount; i++) { struct LuaHookedModMenuElement* hooked = &gHookedModMenuElements[i]; - if (lastMod == hooked->mod) { continue; } - lastMod = hooked->mod; - sDjuiPanelModMenuModName = lastMod->name; - djui_button_create(layoutBase, hooked->mod->name, DJUI_BUTTON_STYLE_NORMAL, djui_panel_mod_menu_mod_create); + bool shouldContinue = false; + for (int i = 0; i < MAX_HOOKED_MOD_MENU_ELEMENTS; i++) { + if (addedMods[i] == NULL) { break; } + if (addedMods[i] == hooked->mod) { + shouldContinue = true; + break; + } + } + if (shouldContinue) { continue; } + + struct DjuiButton* button = djui_button_create(layoutBase, hooked->mod->name, DJUI_BUTTON_STYLE_NORMAL, djui_panel_mod_menu_mod_create); + button->base.tag = hooked->mod->index; + addedMods[modCount] = hooked->mod; + modCount++; } djui_paginated_calculate_height(paginated); diff --git a/src/pc/djui/djui_panel_pause.c b/src/pc/djui/djui_panel_pause.c index d7e27bff..54ace416 100644 --- a/src/pc/djui/djui_panel_pause.c +++ b/src/pc/djui/djui_panel_pause.c @@ -74,11 +74,7 @@ void djui_panel_pause_create(struct DjuiBase* caller) { if (gHookedModMenuElementsCount == 1 && gHookedModMenuElements[0].element == MOD_MENU_ELEMENT_BUTTON) { struct LuaHookedModMenuElement* hooked = &gHookedModMenuElements[0]; char buffer[256] = { 0 }; - if (strlen(hooked->name) > 0) { - snprintf(buffer, 256, "%s - %s", hooked->mod->name, hooked->name); - } else { - snprintf(buffer, 256, "%s", hooked->mod->name); - } + snprintf(buffer, 256, "%s - %s", hooked->mod->name, hooked->name); struct DjuiButton* button = djui_button_create(body, buffer, DJUI_BUTTON_STYLE_NORMAL, djui_panel_mod_menu_mod_button); button->base.tag = 0; } else if (gHookedModMenuElementsCount > 0) { diff --git a/src/pc/lua/smlua_hooks.c b/src/pc/lua/smlua_hooks.c index 219392e5..03f59d30 100644 --- a/src/pc/lua/smlua_hooks.c +++ b/src/pc/lua/smlua_hooks.c @@ -1989,8 +1989,6 @@ int smlua_hook_on_sync_table_change(lua_State* L) { // hooked mod menu button // //////////////////////////// -#define MAX_HOOKED_MOD_MENU_ELEMENTS 256 - struct LuaHookedModMenuElement gHookedModMenuElements[MAX_HOOKED_MOD_MENU_ELEMENTS] = { 0 }; int gHookedModMenuElementsCount = 0; @@ -2009,7 +2007,7 @@ int smlua_hook_mod_menu_button(lua_State* L) { } const char* name = smlua_to_string(L, 1); - if (name == NULL || !gSmLuaConvertSuccess) { + if (name == NULL || strlen(name) == 0 || !gSmLuaConvertSuccess) { LOG_LUA_LINE("Hook mod menu element: tried to hook invalid element"); return 0; } @@ -2210,12 +2208,7 @@ int smlua_update_mod_menu_element_name(lua_State* L) { } const char* name = smlua_to_string(L, 2); - if (name == NULL || !gSmLuaConvertSuccess) { - LOG_LUA_LINE("Update mod menu element: tried to update invalid name"); - return 0; - } - - if (gHookedModMenuElements[index].element != MOD_MENU_ELEMENT_BUTTON && strlen(name) == 0) { + if (name == NULL || strlen(name) == 0 || !gSmLuaConvertSuccess) { LOG_LUA_LINE("Update mod menu element: tried to update invalid name"); return 0; } diff --git a/src/pc/lua/smlua_hooks.h b/src/pc/lua/smlua_hooks.h index 25aa4edb..cbc48c3a 100644 --- a/src/pc/lua/smlua_hooks.h +++ b/src/pc/lua/smlua_hooks.h @@ -120,6 +120,8 @@ static const char* LuaActionHookTypeArgName[] = { "max (dummy)", }; +#define MAX_HOOKED_MOD_MENU_ELEMENTS 256 + enum LuaModMenuElementType { MOD_MENU_ELEMENT_BUTTON, MOD_MENU_ELEMENT_CHECKBOX,