From 08b977f645d1edef94a78dbb81fb2bfa4574d447 Mon Sep 17 00:00:00 2001
From: EmeraldLockdown <86802223+EmeraldLoc@users.noreply.github.com>
Date: Sat, 24 Jan 2026 17:10:54 -0600
Subject: [PATCH] Add `get_mod_files`
---
autogen/lua_definitions/functions.lua | 8 ++++++
docs/lua/functions-7.md | 24 +++++++++++++++++
docs/lua/functions.md | 1 +
src/pc/lua/smlua_functions_autogen.c | 20 ++++++++++++++
src/pc/lua/utils/smlua_misc_utils.c | 39 +++++++++++++++++++++++++++
src/pc/lua/utils/smlua_misc_utils.h | 4 ++-
6 files changed, 95 insertions(+), 1 deletion(-)
diff --git a/autogen/lua_definitions/functions.lua b/autogen/lua_definitions/functions.lua
index 816cc8018..8ddceffed 100644
--- a/autogen/lua_definitions/functions.lua
+++ b/autogen/lua_definitions/functions.lua
@@ -11604,6 +11604,14 @@ function get_active_mod()
-- ...
end
+--- @param mod Mod
+--- @param subDirectory string
+--- @return table
+--- Gets all files a mod contains
+function get_mod_files(mod, subDirectory)
+ -- ...
+end
+
--- @param title string
--- Sets the window title to a custom title
function set_window_title(title)
diff --git a/docs/lua/functions-7.md b/docs/lua/functions-7.md
index 3373d70ee..b3b10e893 100644
--- a/docs/lua/functions-7.md
+++ b/docs/lua/functions-7.md
@@ -2086,6 +2086,30 @@ Gets the mod currently being processed
+## [get_mod_files](#get_mod_files)
+
+### Description
+Gets all files a mod contains
+
+### Lua Example
+`local tableValue = get_mod_files(mod, subDirectory)`
+
+### Parameters
+| Field | Type |
+| ----- | ---- |
+| mod | [Mod](structs.md#Mod) |
+| subDirectory | `string` |
+
+### Returns
+- `table`
+
+### C Prototype
+`LuaTable get_mod_files(struct Mod* mod, const char* subDirectory);`
+
+[:arrow_up_small:](#)
+
+
+
## [set_window_title](#set_window_title)
### Description
diff --git a/docs/lua/functions.md b/docs/lua/functions.md
index e2cff77bf..134adbb49 100644
--- a/docs/lua/functions.md
+++ b/docs/lua/functions.md
@@ -2061,6 +2061,7 @@
- [set_environment_region](functions-7.md#set_environment_region)
- [mod_file_exists](functions-7.md#mod_file_exists)
- [get_active_mod](functions-7.md#get_active_mod)
+ - [get_mod_files](functions-7.md#get_mod_files)
- [set_window_title](functions-7.md#set_window_title)
- [reset_window_title](functions-7.md#reset_window_title)
- [get_os_name](functions-7.md#get_os_name)
diff --git a/src/pc/lua/smlua_functions_autogen.c b/src/pc/lua/smlua_functions_autogen.c
index 60ced0477..319ee4efc 100644
--- a/src/pc/lua/smlua_functions_autogen.c
+++ b/src/pc/lua/smlua_functions_autogen.c
@@ -34629,6 +34629,25 @@ int smlua_func_get_active_mod(UNUSED lua_State* L) {
return 1;
}
+int smlua_func_get_mod_files(lua_State* L) {
+ if (L == NULL) { return 0; }
+
+ int top = lua_gettop(L);
+ if (top != 2) {
+ LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "get_mod_files", 2, top);
+ return 0;
+ }
+
+ struct Mod* mod = (struct Mod*)smlua_to_cobject(L, 1, LOT_MOD);
+ if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "get_mod_files"); return 0; }
+ const char* subDirectory = smlua_to_string(L, 2);
+ if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "get_mod_files"); return 0; }
+
+ smlua_push_lua_table(L, get_mod_files(mod, subDirectory));
+
+ return 1;
+}
+
int smlua_func_set_window_title(lua_State* L) {
if (L == NULL) { return 0; }
@@ -38971,6 +38990,7 @@ void smlua_bind_functions_autogen(void) {
smlua_bind_function(L, "set_environment_region", smlua_func_set_environment_region);
smlua_bind_function(L, "mod_file_exists", smlua_func_mod_file_exists);
smlua_bind_function(L, "get_active_mod", smlua_func_get_active_mod);
+ smlua_bind_function(L, "get_mod_files", smlua_func_get_mod_files);
smlua_bind_function(L, "set_window_title", smlua_func_set_window_title);
smlua_bind_function(L, "reset_window_title", smlua_func_reset_window_title);
smlua_bind_function(L, "get_os_name", smlua_func_get_os_name);
diff --git a/src/pc/lua/utils/smlua_misc_utils.c b/src/pc/lua/utils/smlua_misc_utils.c
index bff36cbbf..ed7b0e586 100644
--- a/src/pc/lua/utils/smlua_misc_utils.c
+++ b/src/pc/lua/utils/smlua_misc_utils.c
@@ -601,6 +601,45 @@ struct Mod* get_active_mod(void) {
return gLuaActiveMod;
}
+LuaTable get_mod_files(struct Mod* mod, const char* subDirectory) {
+ char* normalizedSubDir = malloc(strlen(subDirectory) + 2);
+ strcpy(normalizedSubDir, subDirectory);
+ normalize_path(normalizedSubDir);
+
+ size_t subDirLen = strlen(normalizedSubDir);
+ if (subDirLen > 0 && normalizedSubDir[subDirLen - 1] != '/') {
+ strcat(normalizedSubDir, "/");
+ subDirLen = strlen(normalizedSubDir);
+ }
+
+ struct lua_State *L = gLuaState;
+ if (!L) { return 0; }
+
+ LUA_STACK_CHECK_BEGIN_NUM(L, 1);
+
+ lua_newtable(L);
+
+ int luaTableIndex = 1;
+ for (int i = 0; i < mod->fileCount; i++) {
+ struct ModFile* file = &mod->files[i];
+ char* normalizedPath = strdup(file->relativePath);
+ normalize_path(normalizedPath);
+
+ if (strncmp(normalizedPath, normalizedSubDir, subDirLen) == 0) {
+ lua_pushstring(L, file->relativePath);
+ lua_rawseti(L, -2, luaTableIndex++);
+ }
+
+ free(normalizedPath);
+ }
+
+ LUA_STACK_CHECK_END(L);
+
+ free(normalizedSubDir);
+
+ return smlua_to_lua_table(L, -1);
+}
+
///
void set_window_title(const char* title) {
diff --git a/src/pc/lua/utils/smlua_misc_utils.h b/src/pc/lua/utils/smlua_misc_utils.h
index 5171af3ee..a768dd96a 100644
--- a/src/pc/lua/utils/smlua_misc_utils.h
+++ b/src/pc/lua/utils/smlua_misc_utils.h
@@ -37,7 +37,7 @@ enum ActSelectHudPart {
ACT_SELECT_HUD_ACT_NAME = 1 << 3,
ACT_SELECT_HUD_STAR_NUM = 1 << 4,
ACT_SELECT_HUD_PLAYERS_IN_LEVEL = 1 << 5,
-
+
ACT_SELECT_HUD_NONE = 0,
ACT_SELECT_HUD_ALL = ACT_SELECT_HUD_SCORE | ACT_SELECT_HUD_LEVEL_NAME | ACT_SELECT_HUD_COURSE_NUM | ACT_SELECT_HUD_ACT_NAME |ACT_SELECT_HUD_STAR_NUM | ACT_SELECT_HUD_PLAYERS_IN_LEVEL
};
@@ -243,6 +243,8 @@ void set_environment_region(u8 index, s16 value);
bool mod_file_exists(const char* filename);
/* |description|Gets the mod currently being processed|descriptionEnd| */
struct Mod* get_active_mod(void);
+/* |description|Gets all files a mod contains|descriptionEnd| */
+LuaTable get_mod_files(struct Mod* mod, const char* subDirectory);
/* |description|Sets the window title to a custom title|descriptionEnd| */
void set_window_title(const char* title);