Merge pull request #701 from diamante0018/develop

[General]: Clean up some dvar usage
This commit is contained in:
Edo 2023-01-05 14:05:53 +00:00 committed by GitHub
commit 0fd0cc977b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 23 additions and 18 deletions

View File

@ -465,7 +465,7 @@ namespace Components
std::vector<nlohmann::json> fileList;
const auto path = Dvar::Var("fs_basepath").get<std::string>() / fs_gameDirVar;
const auto path = (*Game::fs_basepath)->current.string / fs_gameDirVar;
auto list = FileSystem::GetSysFileList(path.generic_string(), "iwd", false);
list.emplace_back("mod.ff");
@ -514,7 +514,7 @@ namespace Components
mapNamePre = mapName;
const std::filesystem::path basePath(Dvar::Var("fs_basepath").get<std::string>());
const std::filesystem::path basePath = (*Game::fs_basepath)->current.string;
const auto path = basePath / "usermaps" / mapName;
for (std::size_t i = 0; i < ARRAYSIZE(Maps::UserMapFiles); ++i)
@ -586,9 +586,8 @@ namespace Components
}
std::string file;
const auto fsGame = Dvar::Var("fs_game").get<std::string>();
const auto path = Dvar::Var("fs_basepath").get<std::string>() + "\\" + (isMap ? "" : fsGame + "\\") + url;
const std::string fsGame = (*Game::fs_gameDirVar)->current.string;
const auto path = std::format("{}\\{}{}", (*Game::fs_basepath)->current.string, isMap ? ""s : (fsGame + "\\"s), url);
if ((!isMap && fsGame.empty()) || !Utils::IO::ReadFile(path, &file))
{
mg_http_reply(c, 404, "Content-Type: text/html\r\n", "404 - Not Found %s", path.data());

View File

@ -236,14 +236,14 @@ namespace Components
const char* FastFiles::GetZoneLocation(const char* file)
{
const char* dir = Dvar::Var("fs_basepath").get<const char*>();
const auto* dir = (*Game::fs_basepath)->current.string;
std::vector<std::string> paths;
auto modDir = Dvar::Var("fs_game").get<std::string>();
const std::string fsGame = (*Game::fs_gameDirVar)->current.string;
if ((file == "mod"s || file == "mod.ff"s) && !modDir.empty())
if ((file == "mod"s || file == "mod.ff"s) && !fsGame.empty())
{
paths.push_back(std::format("{}\\", modDir));
paths.push_back(std::format("{}\\", fsGame));
}
if (Utils::String::StartsWith(file, "mp_"))

View File

@ -205,7 +205,7 @@ namespace Components
bool FileSystem::_DeleteFile(const std::string& folder, const std::string& file)
{
char path[MAX_PATH]{};
Game::FS_BuildPathToFile(Dvar::Var("fs_basepath").get<const char*>(), reinterpret_cast<char*>(0x63D0BB8), Utils::String::VA("%s/%s", folder.data(), file.data()), reinterpret_cast<char**>(&path));
Game::FS_BuildPathToFile((*Game::fs_basepath)->current.string, reinterpret_cast<char*>(0x63D0BB8), Utils::String::VA("%s/%s", folder.data(), file.data()), reinterpret_cast<char**>(&path));
return Game::FS_Remove(path);
}
@ -242,9 +242,9 @@ namespace Components
void FileSystem::RegisterFolder(const char* folder)
{
const auto fs_cdpath = Dvar::Var("fs_cdpath").get<std::string>();
const auto fs_basepath = Dvar::Var("fs_basepath").get<std::string>();
const auto fs_homepath = Dvar::Var("fs_homepath").get<std::string>();
const std::string fs_cdpath = (*Game::fs_cdpath)->current.string;
const std::string fs_basepath = (*Game::fs_basepath)->current.string;
const std::string fs_homepath = (*Game::fs_homepath)->current.string;
if (!fs_cdpath.empty()) Game::FS_AddLocalizedGameDirectory(fs_cdpath.data(), folder);
if (!fs_basepath.empty()) Game::FS_AddLocalizedGameDirectory(fs_basepath.data(), folder);

View File

@ -37,7 +37,7 @@ namespace Components
if (this->isValid() && !this->searchPath.iwd)
{
auto iwdName = std::format("{}.iwd", this->mapname);
auto path = std::format("{}\\usermaps\\{}\\{}", Dvar::Var("fs_basepath").get<std::string>(), this->mapname, iwdName);
auto path = std::format("{}\\usermaps\\{}\\{}", (*Game::fs_basepath)->current.string, this->mapname, iwdName);
if (Utils::IO::FileExists(path))
{

View File

@ -43,7 +43,7 @@ namespace Components
void ModList::UIScript_LoadMods([[maybe_unused]] const UIScript::Token& token, [[maybe_unused]] const Game::uiInfo_s* info)
{
auto folder = Dvar::Var("fs_basepath").get<std::string>() + "\\mods";
auto folder = (*Game::fs_basepath)->current.string + "\\mods"s;
Logger::Debug("Searching for mods in {}...", folder);
ModList::Mods = FileSystem::GetSysFileList(folder, "", true);
Logger::Debug("Found {} mods!", ModList::Mods.size());

View File

@ -483,7 +483,7 @@ namespace Components
Command::Execute("closemenu popup_reconnectingtoparty");
Download::InitiateClientDownload(info.get("fs_game"), info.get("isPrivate") == "1"s);
}
else if (!Dvar::Var("fs_game").get<std::string>().empty() && info.get("fs_game").empty())
else if ((*Game::fs_gameDirVar)->current.string[0] != '\0' && info.get("fs_game").empty())
{
Game::Dvar_SetString(*Game::fs_gameDirVar, "");

View File

@ -1217,7 +1217,7 @@ namespace Components
Command::Add("buildall", []([[maybe_unused]] Command::Params* params)
{
auto path = std::format("{}\\zone_source", Dvar::Var("fs_basepath").get<std::string>());
auto path = std::format("{}\\zone_source", (*Game::fs_basepath)->current.string);
auto zoneSources = FileSystem::GetSysFileList(path, "csv", false);
for (auto source : zoneSources)
@ -1583,7 +1583,7 @@ namespace Components
{
if (params->size() < 2) return;
auto path = std::format("{}\\mods\\{}\\images", Dvar::Var("fs_basepath").get<std::string>(), params->get(1));
auto path = std::format("{}\\mods\\{}\\images", (*Game::fs_basepath)->current.string, params->get(1));
auto images = FileSystem::GetSysFileList(path, "iwi", false);
for (auto i = images.begin(); i != images.end();)

View File

@ -40,7 +40,10 @@ namespace Game
const dvar_t** dvar_cheats = reinterpret_cast<const dvar_t**>(0x63F3348);
const dvar_t** fs_cdpath = reinterpret_cast<const dvar_t**>(0x63D0BB0);
const dvar_t** fs_basepath = reinterpret_cast<const dvar_t**>(0x63D0CD4);
const dvar_t** fs_gameDirVar = reinterpret_cast<const dvar_t**>(0x63D0CC0);
const dvar_t** fs_homepath = reinterpret_cast<const dvar_t**>(0x63D4FD8);
const dvar_t** sv_hostname = reinterpret_cast<const dvar_t**>(0x2098D98);
const dvar_t** sv_gametype = reinterpret_cast<const dvar_t**>(0x2098DD4);

View File

@ -90,7 +90,10 @@ namespace Game
extern const dvar_t** dvar_cheats;
extern const dvar_t** fs_cdpath;
extern const dvar_t** fs_basepath;
extern const dvar_t** fs_gameDirVar;
extern const dvar_t** fs_homepath;
extern const dvar_t** sv_hostname;
extern const dvar_t** sv_gametype;