2022-02-27 07:53:44 -05:00
|
|
|
#include <STDInclude.hpp>
|
2022-12-26 07:07:24 -05:00
|
|
|
#include "UIFeeder.hpp"
|
2017-01-19 16:23:59 -05:00
|
|
|
|
|
|
|
namespace Components
|
|
|
|
{
|
|
|
|
std::vector<std::string> ModList::Mods;
|
|
|
|
unsigned int ModList::CurrentMod;
|
|
|
|
|
2018-12-17 08:29:18 -05:00
|
|
|
bool ModList::HasMod(const std::string& modName)
|
2017-01-19 16:23:59 -05:00
|
|
|
{
|
|
|
|
auto list = FileSystem::GetSysFileList(Dvar::Var("fs_basepath").get<std::string>() + "\\mods", "", true);
|
|
|
|
|
|
|
|
for (auto mod : list)
|
|
|
|
{
|
|
|
|
if (mod == modName)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int ModList::GetItemCount()
|
|
|
|
{
|
|
|
|
return ModList::Mods.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* ModList::GetItemText(unsigned int index, int /*column*/)
|
|
|
|
{
|
|
|
|
if (index < ModList::Mods.size())
|
|
|
|
{
|
|
|
|
return ModList::Mods[index].data();
|
|
|
|
}
|
|
|
|
|
|
|
|
return "...";
|
|
|
|
}
|
|
|
|
|
|
|
|
void ModList::Select(unsigned int index)
|
|
|
|
{
|
|
|
|
ModList::CurrentMod = index;
|
|
|
|
}
|
|
|
|
|
2022-08-24 10:38:14 -04:00
|
|
|
void ModList::UIScript_LoadMods([[maybe_unused]] const UIScript::Token& token, [[maybe_unused]] const Game::uiInfo_s* info)
|
2017-01-19 16:23:59 -05:00
|
|
|
{
|
|
|
|
auto folder = Dvar::Var("fs_basepath").get<std::string>() + "\\mods";
|
2022-06-22 04:58:51 -04:00
|
|
|
Logger::Debug("Searching for mods in {}...", folder);
|
2017-01-19 16:23:59 -05:00
|
|
|
ModList::Mods = FileSystem::GetSysFileList(folder, "", true);
|
2022-06-22 04:58:51 -04:00
|
|
|
Logger::Debug("Found {} mods!", ModList::Mods.size());
|
2017-01-19 16:23:59 -05:00
|
|
|
}
|
|
|
|
|
2022-08-24 10:38:14 -04:00
|
|
|
void ModList::UIScript_RunMod([[maybe_unused]] const UIScript::Token& token, [[maybe_unused]] const Game::uiInfo_s* info)
|
2017-01-19 16:23:59 -05:00
|
|
|
{
|
|
|
|
if (ModList::CurrentMod < ModList::Mods.size())
|
|
|
|
{
|
|
|
|
ModList::RunMod(ModList::Mods[ModList::CurrentMod]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-24 10:38:14 -04:00
|
|
|
void ModList::UIScript_ClearMods([[maybe_unused]] const UIScript::Token& token, [[maybe_unused]] const Game::uiInfo_s* info)
|
2017-01-19 16:23:59 -05:00
|
|
|
{
|
2023-01-04 12:55:17 -05:00
|
|
|
Game::Dvar_SetString(*Game::fs_gameDirVar, "");
|
|
|
|
const_cast<Game::dvar_t*>((*Game::fs_gameDirVar))->modified = true;
|
2017-01-19 16:23:59 -05:00
|
|
|
|
|
|
|
if (Dvar::Var("cl_modVidRestart").get<bool>())
|
|
|
|
{
|
|
|
|
Game::Cmd_ExecuteSingleCommand(0, 0, "vid_restart");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Game::Cmd_ExecuteSingleCommand(0, 0, "closemenu mods_menu");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-17 08:29:18 -05:00
|
|
|
void ModList::RunMod(const std::string& mod)
|
2017-01-19 16:23:59 -05:00
|
|
|
{
|
2023-01-04 12:55:17 -05:00
|
|
|
Game::Dvar_SetString(*Game::fs_gameDirVar, Utils::String::Format("mods/{}", mod));
|
|
|
|
const_cast<Game::dvar_t*>((*Game::fs_gameDirVar))->modified = true;
|
2017-01-19 16:23:59 -05:00
|
|
|
|
|
|
|
if (Dvar::Var("cl_modVidRestart").get<bool>())
|
|
|
|
{
|
|
|
|
Command::Execute("vid_restart", false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Command::Execute("closemenu mods_menu", false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ModList::ModList()
|
|
|
|
{
|
2017-02-21 15:49:42 -05:00
|
|
|
if (Dedicated::IsEnabled()) return;
|
2017-02-21 15:39:58 -05:00
|
|
|
|
2017-01-19 16:23:59 -05:00
|
|
|
ModList::CurrentMod = 0;
|
2022-07-02 13:52:57 -04:00
|
|
|
Dvar::Register("cl_modVidRestart", true, Game::DVAR_ARCHIVE, "Perform a vid_restart when loading a mod.");
|
2017-01-19 16:23:59 -05:00
|
|
|
|
|
|
|
UIScript::Add("LoadMods", ModList::UIScript_LoadMods);
|
|
|
|
UIScript::Add("RunMod", ModList::UIScript_RunMod);
|
|
|
|
UIScript::Add("ClearMods", ModList::UIScript_ClearMods);
|
|
|
|
|
|
|
|
UIFeeder::Add(9.0f, ModList::GetItemCount, ModList::GetItemText, ModList::Select);
|
|
|
|
}
|
|
|
|
}
|