diff --git a/deps/libtomcrypt b/deps/libtomcrypt index 912eff49..bb56ef08 160000 --- a/deps/libtomcrypt +++ b/deps/libtomcrypt @@ -1 +1 @@ -Subproject commit 912eff4949f46c0b426d2180429a6fa4c1144f1d +Subproject commit bb56ef08eb80854e78011da1f99a35f7cb2411fd diff --git a/deps/protobuf b/deps/protobuf index 5e933847..452e2b2c 160000 --- a/deps/protobuf +++ b/deps/protobuf @@ -1 +1 @@ -Subproject commit 5e933847cc9e7826f1a9ee8b3dc1df4960b1ea5d +Subproject commit 452e2b2c5c607ab5d63cd813793f1aa960f19d1c diff --git a/src/Components/Modules/FileSystem.cpp b/src/Components/Modules/FileSystem.cpp index 9314e754..1718a07f 100644 --- a/src/Components/Modules/FileSystem.cpp +++ b/src/Components/Modules/FileSystem.cpp @@ -67,6 +67,29 @@ namespace Components return fileList; } + std::vector FileSystem::GetSysFileList(std::string path, std::string extension, bool folders) + { + std::vector fileList; + + int numFiles = 0; + char** files = Game::Sys_ListFiles(path.data(), extension.data(), NULL, &numFiles, folders); + + if (files) + { + for (int i = 0; i < numFiles; ++i) + { + if (files[i]) + { + fileList.push_back(files[i]); + } + } + + Game::Sys_FreeFileList(files); + } + + return fileList; + } + void FileSystem::DeleteFile(std::string folder, std::string file) { char path[MAX_PATH] = { 0 }; diff --git a/src/Components/Modules/FileSystem.hpp b/src/Components/Modules/FileSystem.hpp index 4e0313ab..2925a05d 100644 --- a/src/Components/Modules/FileSystem.hpp +++ b/src/Components/Modules/FileSystem.hpp @@ -41,6 +41,7 @@ namespace Components const char* GetName() { return "FileSystem"; }; static std::vector GetFileList(std::string path, std::string extension); + static std::vector GetSysFileList(std::string path, std::string extension, bool folders = false); static void DeleteFile(std::string folder, std::string file); private: diff --git a/src/Components/Modules/ModList.cpp b/src/Components/Modules/ModList.cpp index 109ccc25..2856dbef 100644 --- a/src/Components/Modules/ModList.cpp +++ b/src/Components/Modules/ModList.cpp @@ -2,39 +2,34 @@ namespace Components { - static Dvar::Var cl_modVidRestart; + std::vector ModList::Mods; + unsigned int ModList::CurrentMod; - ModList::modInfo_t ModList::modInfo; - - bool ModList::hasMod(const char* modName) + bool ModList::HasMod(std::string modName) { - int count; - auto fs_homepath = Dvar::Var("fs_basepath").Get(); - char** mods = Game::Sys_ListFiles((char*)Utils::VA("%s\\%s", fs_homepath, "mods"), NULL, NULL, &count, 1); + auto list = FileSystem::GetSysFileList(Dvar::Var("fs_basepath").Get() + "\\mods", "", true); - for (int i = 0; i < count; i++) + for (auto mod : list) { - if (!_stricmp(modName, mods[i])) + if (mod == modName) { - Game::Sys_FreeFileList(mods); return true; } } - Game::Sys_FreeFileList(mods); return false; } unsigned int ModList::GetItemCount() { - return ModList::modInfo.max; + return ModList::Mods.size(); } const char* ModList::GetItemText(unsigned int index, int column) { - if (ModList::modInfo.current >= 0 && ModList::modInfo.current < ModList::modInfo.max) + if (index < ModList::Mods.size()) { - return ModList::modInfo.mods[index]; + return ModList::Mods[index].data(); } return "..."; @@ -42,50 +37,43 @@ namespace Components void ModList::Select(unsigned int index) { - ModList::modInfo.current = index; + ModList::CurrentMod = index; } void ModList::UIScript_LoadMods() { - if (ModList::modInfo.mods != NULL && *ModList::modInfo.mods != NULL) - { - Game::Sys_FreeFileList(ModList::modInfo.mods); - } - - auto fs_homepath = Dvar::Var("fs_basepath").Get(); - auto searchFolder = (char*)Utils::VA("%s\\%s", fs_homepath, "mods"); - Game::Com_Printf(0, "Searching for mods in %s...\n", searchFolder); - - ModList::modInfo.mods = Game::Sys_ListFiles(searchFolder, NULL, NULL, &ModList::modInfo.max, 1); - - Game::Com_Printf(0, "Found %i mods!\n", ModList::modInfo.max); + auto folder = Dvar::Var("fs_basepath").Get() + "\\mods"; + Game::Com_Printf(0, "Searching for mods in %s...\n", folder.data()); + ModList::Mods = FileSystem::GetSysFileList(folder, "", true); + Game::Com_Printf(0, "Found %i mods!\n", ModList::Mods.size()); } void ModList::UIScript_RunMod() { - if (ModList::modInfo.mods != NULL - && *ModList::modInfo.mods != NULL - && ModList::modInfo.current >= 0 - && ModList::modInfo.current < ModList::modInfo.max) + if (ModList::CurrentMod < ModList::Mods.size()) { - Dvar::Var("fs_game").Set(Utils::VA("mods/%s", ModList::modInfo.mods[ModList::modInfo.current])); - //Game::Cmd_ExecuteSingleCommand(0, 0, Utils::VA("fs_game \"mods/%s\"", modInfo.mods[modInfo.current])); - if (cl_modVidRestart.Get()) + auto fsGame = Dvar::Var("fs_game"); + fsGame.Set(Utils::VA("mods/%s", ModList::Mods[ModList::CurrentMod].data())); + fsGame.Get()->pad2[0] = 1; + + if (Dvar::Var("cl_modVidRestart").Get()) { - Game::Cmd_ExecuteSingleCommand(0, 0, "vid_restart"); + Command::Execute("vid_restart", false); } else { - Game::Cmd_ExecuteSingleCommand(0, 0, "closemenu mods_menu"); + Command::Execute("closemenu mods_menu", false); } } } void ModList::UIScript_ClearMods() { - Dvar::Var("fs_game").Set(""); - //Game::Cmd_ExecuteSingleCommand(0, 0, "fs_game \"\""); - if (cl_modVidRestart.Get()) + auto fsGame = Dvar::Var("fs_game"); + fsGame.Set(""); + fsGame.Get()->pad2[0] = 1; + + if (Dvar::Var("cl_modVidRestart").Get()) { Game::Cmd_ExecuteSingleCommand(0, 0, "vid_restart"); } @@ -97,12 +85,8 @@ namespace Components ModList::ModList() { - Dvar::OnInit([]() - { - cl_modVidRestart = Dvar::Register("cl_modVidRestart", true, Game::dvar_flag::DVAR_FLAG_SAVED, "Perform a vid_restart when loading a mod."); - }); - - ModList::modInfo.max = ModList::modInfo.current = 0; + ModList::CurrentMod = 0; + Dvar::Register("cl_modVidRestart", true, Game::dvar_flag::DVAR_FLAG_SAVED, "Perform a vid_restart when loading a mod."); UIScript::Add("LoadMods", ModList::UIScript_LoadMods); UIScript::Add("RunMod", ModList::UIScript_RunMod); @@ -113,5 +97,6 @@ namespace Components ModList::~ModList() { + ModList::Mods.clear(); } } \ No newline at end of file diff --git a/src/Components/Modules/ModList.hpp b/src/Components/Modules/ModList.hpp index 16b8dec1..710ef748 100644 --- a/src/Components/Modules/ModList.hpp +++ b/src/Components/Modules/ModList.hpp @@ -5,19 +5,13 @@ namespace Components public: ModList(); ~ModList(); - const char* GetName() { return "Mods"; }; + const char* GetName() { return "ModList"; }; private: - struct modInfo_t - { - char** mods; - int max; - int current; - }; + static std::vector Mods; + static unsigned int CurrentMod; - static bool hasMod(const char* modName); - - static modInfo_t modInfo; + static bool HasMod(std::string modName); static unsigned int GetItemCount(); static const char* GetItemText(unsigned int index, int column); diff --git a/src/Game/Functions.hpp b/src/Game/Functions.hpp index a06ea30c..5992d9ec 100644 --- a/src/Game/Functions.hpp +++ b/src/Game/Functions.hpp @@ -317,7 +317,7 @@ namespace Game typedef bool(__cdecl * Sys_IsMainThread_t)(); extern Sys_IsMainThread_t Sys_IsMainThread; - typedef char** (__cdecl * Sys_ListFiles_t)(char* path, char* extension, int noclue, int* amount, bool listFolders); + typedef char** (__cdecl * Sys_ListFiles_t)(const char *directory, const char *extension, const char *filter, int *numfiles, int wantsubs); extern Sys_ListFiles_t Sys_ListFiles; typedef bool(__cdecl * Sys_SendPacket_t)(netsrc_t sock, size_t len, const char *format, netadr_t adr);