From ca5843587ab2e07ea7de19bd104d8a8d331177c2 Mon Sep 17 00:00:00 2001 From: Diavolo Date: Thu, 5 Jan 2023 10:59:09 +0100 Subject: [PATCH] [General]: Clean up some dvar usage --- src/Components/Modules/Download.cpp | 9 ++++----- src/Components/Modules/FastFiles.cpp | 8 ++++---- src/Components/Modules/FileSystem.cpp | 8 ++++---- src/Components/Modules/Maps.cpp | 2 +- src/Components/Modules/ModList.cpp | 2 +- src/Components/Modules/Party.cpp | 2 +- src/Components/Modules/ZoneBuilder.cpp | 4 ++-- src/Game/Dvars.cpp | 3 +++ src/Game/Dvars.hpp | 3 +++ 9 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/Components/Modules/Download.cpp b/src/Components/Modules/Download.cpp index 0296d12e..3c1b5828 100644 --- a/src/Components/Modules/Download.cpp +++ b/src/Components/Modules/Download.cpp @@ -465,7 +465,7 @@ namespace Components std::vector fileList; - const auto path = Dvar::Var("fs_basepath").get() / 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()); + 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(); - const auto path = Dvar::Var("fs_basepath").get() + "\\" + (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()); diff --git a/src/Components/Modules/FastFiles.cpp b/src/Components/Modules/FastFiles.cpp index a3d780ea..b27ab321 100644 --- a/src/Components/Modules/FastFiles.cpp +++ b/src/Components/Modules/FastFiles.cpp @@ -236,14 +236,14 @@ namespace Components const char* FastFiles::GetZoneLocation(const char* file) { - const char* dir = Dvar::Var("fs_basepath").get(); + const auto* dir = (*Game::fs_basepath)->current.string; std::vector paths; - auto modDir = Dvar::Var("fs_game").get(); + 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_")) diff --git a/src/Components/Modules/FileSystem.cpp b/src/Components/Modules/FileSystem.cpp index 72ca85f9..9762fce4 100644 --- a/src/Components/Modules/FileSystem.cpp +++ b/src/Components/Modules/FileSystem.cpp @@ -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(), reinterpret_cast(0x63D0BB8), Utils::String::VA("%s/%s", folder.data(), file.data()), reinterpret_cast(&path)); + Game::FS_BuildPathToFile((*Game::fs_basepath)->current.string, reinterpret_cast(0x63D0BB8), Utils::String::VA("%s/%s", folder.data(), file.data()), reinterpret_cast(&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(); - const auto fs_basepath = Dvar::Var("fs_basepath").get(); - const auto fs_homepath = Dvar::Var("fs_homepath").get(); + 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); diff --git a/src/Components/Modules/Maps.cpp b/src/Components/Modules/Maps.cpp index 0a266f4b..38769218 100644 --- a/src/Components/Modules/Maps.cpp +++ b/src/Components/Modules/Maps.cpp @@ -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(), this->mapname, iwdName); + auto path = std::format("{}\\usermaps\\{}\\{}", (*Game::fs_basepath)->current.string, this->mapname, iwdName); if (Utils::IO::FileExists(path)) { diff --git a/src/Components/Modules/ModList.cpp b/src/Components/Modules/ModList.cpp index 34ec0033..13f6c3ab 100644 --- a/src/Components/Modules/ModList.cpp +++ b/src/Components/Modules/ModList.cpp @@ -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() + "\\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()); diff --git a/src/Components/Modules/Party.cpp b/src/Components/Modules/Party.cpp index d1b7d12d..e5f3bd7d 100644 --- a/src/Components/Modules/Party.cpp +++ b/src/Components/Modules/Party.cpp @@ -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().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, ""); diff --git a/src/Components/Modules/ZoneBuilder.cpp b/src/Components/Modules/ZoneBuilder.cpp index 6a1547af..430afeb2 100644 --- a/src/Components/Modules/ZoneBuilder.cpp +++ b/src/Components/Modules/ZoneBuilder.cpp @@ -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()); + 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(), 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();) diff --git a/src/Game/Dvars.cpp b/src/Game/Dvars.cpp index d6471624..029fe756 100644 --- a/src/Game/Dvars.cpp +++ b/src/Game/Dvars.cpp @@ -40,7 +40,10 @@ namespace Game const dvar_t** dvar_cheats = reinterpret_cast(0x63F3348); + const dvar_t** fs_cdpath = reinterpret_cast(0x63D0BB0); + const dvar_t** fs_basepath = reinterpret_cast(0x63D0CD4); const dvar_t** fs_gameDirVar = reinterpret_cast(0x63D0CC0); + const dvar_t** fs_homepath = reinterpret_cast(0x63D4FD8); const dvar_t** sv_hostname = reinterpret_cast(0x2098D98); const dvar_t** sv_gametype = reinterpret_cast(0x2098DD4); diff --git a/src/Game/Dvars.hpp b/src/Game/Dvars.hpp index a0d9730d..3372579a 100644 --- a/src/Game/Dvars.hpp +++ b/src/Game/Dvars.hpp @@ -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;