Skip to content

Commit

Permalink
add fs_listfiles
Browse files Browse the repository at this point in the history
  • Loading branch information
ineed bots committed Dec 3, 2023
1 parent 4963a91 commit b79b776
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/component/fileio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
}

Expand Down
15 changes: 15 additions & 0 deletions src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
3 changes: 3 additions & 0 deletions src/game/symbols.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CRITICAL_SECTION> s_criticalSection{ 0x0, 0x2298D08 };
WEAK symbol<HunkUser*> g_DebugHunkUser{ 0x0, 0x212B2EC };
Expand Down

0 comments on commit b79b776

Please sign in to comment.