Ompimize modlist
This commit is contained in:
parent
883f71b7bb
commit
b912eb618b
2
deps/libtomcrypt
vendored
2
deps/libtomcrypt
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 912eff4949f46c0b426d2180429a6fa4c1144f1d
|
Subproject commit bb56ef08eb80854e78011da1f99a35f7cb2411fd
|
2
deps/protobuf
vendored
2
deps/protobuf
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 5e933847cc9e7826f1a9ee8b3dc1df4960b1ea5d
|
Subproject commit 452e2b2c5c607ab5d63cd813793f1aa960f19d1c
|
@ -67,6 +67,29 @@ namespace Components
|
|||||||
return fileList;
|
return fileList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> FileSystem::GetSysFileList(std::string path, std::string extension, bool folders)
|
||||||
|
{
|
||||||
|
std::vector<std::string> 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)
|
void FileSystem::DeleteFile(std::string folder, std::string file)
|
||||||
{
|
{
|
||||||
char path[MAX_PATH] = { 0 };
|
char path[MAX_PATH] = { 0 };
|
||||||
|
@ -41,6 +41,7 @@ namespace Components
|
|||||||
const char* GetName() { return "FileSystem"; };
|
const char* GetName() { return "FileSystem"; };
|
||||||
|
|
||||||
static std::vector<std::string> GetFileList(std::string path, std::string extension);
|
static std::vector<std::string> GetFileList(std::string path, std::string extension);
|
||||||
|
static std::vector<std::string> GetSysFileList(std::string path, std::string extension, bool folders = false);
|
||||||
static void DeleteFile(std::string folder, std::string file);
|
static void DeleteFile(std::string folder, std::string file);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -2,39 +2,34 @@
|
|||||||
|
|
||||||
namespace Components
|
namespace Components
|
||||||
{
|
{
|
||||||
static Dvar::Var cl_modVidRestart;
|
std::vector<std::string> ModList::Mods;
|
||||||
|
unsigned int ModList::CurrentMod;
|
||||||
|
|
||||||
ModList::modInfo_t ModList::modInfo;
|
bool ModList::HasMod(std::string modName)
|
||||||
|
{
|
||||||
|
auto list = FileSystem::GetSysFileList(Dvar::Var("fs_basepath").Get<std::string>() + "\\mods", "", true);
|
||||||
|
|
||||||
bool ModList::hasMod(const char* modName)
|
for (auto mod : list)
|
||||||
{
|
{
|
||||||
int count;
|
if (mod == modName)
|
||||||
auto fs_homepath = Dvar::Var("fs_basepath").Get<const char*>();
|
|
||||||
char** mods = Game::Sys_ListFiles((char*)Utils::VA("%s\\%s", fs_homepath, "mods"), NULL, NULL, &count, 1);
|
|
||||||
|
|
||||||
for (int i = 0; i < count; i++)
|
|
||||||
{
|
{
|
||||||
if (!_stricmp(modName, mods[i]))
|
|
||||||
{
|
|
||||||
Game::Sys_FreeFileList(mods);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Game::Sys_FreeFileList(mods);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int ModList::GetItemCount()
|
unsigned int ModList::GetItemCount()
|
||||||
{
|
{
|
||||||
return ModList::modInfo.max;
|
return ModList::Mods.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* ModList::GetItemText(unsigned int index, int column)
|
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 "...";
|
return "...";
|
||||||
@ -42,50 +37,43 @@ namespace Components
|
|||||||
|
|
||||||
void ModList::Select(unsigned int index)
|
void ModList::Select(unsigned int index)
|
||||||
{
|
{
|
||||||
ModList::modInfo.current = index;
|
ModList::CurrentMod = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModList::UIScript_LoadMods()
|
void ModList::UIScript_LoadMods()
|
||||||
{
|
{
|
||||||
if (ModList::modInfo.mods != NULL && *ModList::modInfo.mods != NULL)
|
auto folder = Dvar::Var("fs_basepath").Get<std::string>() + "\\mods";
|
||||||
{
|
Game::Com_Printf(0, "Searching for mods in %s...\n", folder.data());
|
||||||
Game::Sys_FreeFileList(ModList::modInfo.mods);
|
ModList::Mods = FileSystem::GetSysFileList(folder, "", true);
|
||||||
}
|
Game::Com_Printf(0, "Found %i mods!\n", ModList::Mods.size());
|
||||||
|
|
||||||
auto fs_homepath = Dvar::Var("fs_basepath").Get<const char*>();
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModList::UIScript_RunMod()
|
void ModList::UIScript_RunMod()
|
||||||
{
|
{
|
||||||
if (ModList::modInfo.mods != NULL
|
if (ModList::CurrentMod < ModList::Mods.size())
|
||||||
&& *ModList::modInfo.mods != NULL
|
|
||||||
&& ModList::modInfo.current >= 0
|
|
||||||
&& ModList::modInfo.current < ModList::modInfo.max)
|
|
||||||
{
|
{
|
||||||
Dvar::Var("fs_game").Set(Utils::VA("mods/%s", ModList::modInfo.mods[ModList::modInfo.current]));
|
auto fsGame = Dvar::Var("fs_game");
|
||||||
//Game::Cmd_ExecuteSingleCommand(0, 0, Utils::VA("fs_game \"mods/%s\"", modInfo.mods[modInfo.current]));
|
fsGame.Set(Utils::VA("mods/%s", ModList::Mods[ModList::CurrentMod].data()));
|
||||||
if (cl_modVidRestart.Get<bool>())
|
fsGame.Get<Game::dvar_t*>()->pad2[0] = 1;
|
||||||
|
|
||||||
|
if (Dvar::Var("cl_modVidRestart").Get<bool>())
|
||||||
{
|
{
|
||||||
Game::Cmd_ExecuteSingleCommand(0, 0, "vid_restart");
|
Command::Execute("vid_restart", false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Game::Cmd_ExecuteSingleCommand(0, 0, "closemenu mods_menu");
|
Command::Execute("closemenu mods_menu", false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModList::UIScript_ClearMods()
|
void ModList::UIScript_ClearMods()
|
||||||
{
|
{
|
||||||
Dvar::Var("fs_game").Set("");
|
auto fsGame = Dvar::Var("fs_game");
|
||||||
//Game::Cmd_ExecuteSingleCommand(0, 0, "fs_game \"\"");
|
fsGame.Set("");
|
||||||
if (cl_modVidRestart.Get<bool>())
|
fsGame.Get<Game::dvar_t*>()->pad2[0] = 1;
|
||||||
|
|
||||||
|
if (Dvar::Var("cl_modVidRestart").Get<bool>())
|
||||||
{
|
{
|
||||||
Game::Cmd_ExecuteSingleCommand(0, 0, "vid_restart");
|
Game::Cmd_ExecuteSingleCommand(0, 0, "vid_restart");
|
||||||
}
|
}
|
||||||
@ -97,12 +85,8 @@ namespace Components
|
|||||||
|
|
||||||
ModList::ModList()
|
ModList::ModList()
|
||||||
{
|
{
|
||||||
Dvar::OnInit([]()
|
ModList::CurrentMod = 0;
|
||||||
{
|
Dvar::Register("cl_modVidRestart", true, Game::dvar_flag::DVAR_FLAG_SAVED, "Perform a vid_restart when loading a mod.");
|
||||||
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;
|
|
||||||
|
|
||||||
UIScript::Add("LoadMods", ModList::UIScript_LoadMods);
|
UIScript::Add("LoadMods", ModList::UIScript_LoadMods);
|
||||||
UIScript::Add("RunMod", ModList::UIScript_RunMod);
|
UIScript::Add("RunMod", ModList::UIScript_RunMod);
|
||||||
@ -113,5 +97,6 @@ namespace Components
|
|||||||
|
|
||||||
ModList::~ModList()
|
ModList::~ModList()
|
||||||
{
|
{
|
||||||
|
ModList::Mods.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -5,19 +5,13 @@ namespace Components
|
|||||||
public:
|
public:
|
||||||
ModList();
|
ModList();
|
||||||
~ModList();
|
~ModList();
|
||||||
const char* GetName() { return "Mods"; };
|
const char* GetName() { return "ModList"; };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct modInfo_t
|
static std::vector<std::string> Mods;
|
||||||
{
|
static unsigned int CurrentMod;
|
||||||
char** mods;
|
|
||||||
int max;
|
|
||||||
int current;
|
|
||||||
};
|
|
||||||
|
|
||||||
static bool hasMod(const char* modName);
|
static bool HasMod(std::string modName);
|
||||||
|
|
||||||
static modInfo_t modInfo;
|
|
||||||
|
|
||||||
static unsigned int GetItemCount();
|
static unsigned int GetItemCount();
|
||||||
static const char* GetItemText(unsigned int index, int column);
|
static const char* GetItemText(unsigned int index, int column);
|
||||||
|
@ -317,7 +317,7 @@ namespace Game
|
|||||||
typedef bool(__cdecl * Sys_IsMainThread_t)();
|
typedef bool(__cdecl * Sys_IsMainThread_t)();
|
||||||
extern Sys_IsMainThread_t Sys_IsMainThread;
|
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;
|
extern Sys_ListFiles_t Sys_ListFiles;
|
||||||
|
|
||||||
typedef bool(__cdecl * Sys_SendPacket_t)(netsrc_t sock, size_t len, const char *format, netadr_t adr);
|
typedef bool(__cdecl * Sys_SendPacket_t)(netsrc_t sock, size_t len, const char *format, netadr_t adr);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user