diff --git a/src/component/fileio.cpp b/src/component/fileio.cpp index b8937d7..8fee060 100644 --- a/src/component/fileio.cpp +++ b/src/component/fileio.cpp @@ -401,6 +401,23 @@ namespace fileio game::Scr_AddInt(game::SCRIPTINSTANCE_SERVER, 1); }); + + gsc::function::add("fs_listfiles", []() + { + auto fpath = build_base_path(game::Scr_GetString(0, game::SCRIPTINSTANCE_SERVER)); + + int numfiles; + auto* files = game::FS_ListFiles(fpath.c_str(), "", game::FS_LIST_ALL, &numfiles); + + game::Scr_MakeArray(game::SCRIPTINSTANCE_SERVER); + for (int i = 0; i < numfiles; i++) + { + game::Scr_AddString(game::SCRIPTINSTANCE_SERVER, files[i]); + game::Scr_AddArray(game::SCRIPTINSTANCE_SERVER); + } + + game::FS_FreeFileList(files); + }); } } diff --git a/src/game/game.cpp b/src/game/game.cpp index 5d429cc..7a19514 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -231,6 +231,21 @@ namespace game *cmd_functions = newCmd; } + // restored + const char** FS_ListFiles(const char* path, const char* extension, FsListBehavior_e behavior, int* numfiles) + { + return FS_ListFilteredFiles(*fs_searchpaths, path, extension, nullptr, behavior, numfiles); + } + + // restored + void FS_FreeFileList(const char** list) + { + if ( list ) + { + Hunk_UserDestroy((HunkUser*)*(list - 1)); + } + } + // restored void Sys_EnterCriticalSection(CriticalSection critSect) { diff --git a/src/game/symbols.hpp b/src/game/symbols.hpp index 1489c56..c25d338 100644 --- a/src/game/symbols.hpp +++ b/src/game/symbols.hpp @@ -78,6 +78,9 @@ namespace game void Sys_EnterCriticalSection(CriticalSection critSect); void Sys_LeaveCriticalSection(CriticalSection critSect); + const char** FS_ListFiles(const char* path, const char* extension, FsListBehavior_e behavior, int* numfiles); + void FS_FreeFileList(const char** list); + // Variables WEAK symbol s_criticalSection{ 0x0, 0x2298D08 }; WEAK symbol g_DebugHunkUser{ 0x0, 0x212B2EC };