From b1c69e74b7dec42411f63157c7e7faefaf4e34a6 Mon Sep 17 00:00:00 2001 From: Federico Cecchetto Date: Mon, 21 Mar 2022 18:39:51 +0100 Subject: [PATCH] Small fix + cleanup --- src/client/component/mods.cpp | 18 ++++++++++-------- src/client/component/mods.hpp | 6 ++++++ src/client/game/game.cpp | 2 -- src/client/game/game.hpp | 2 -- src/client/game/ui_scripting/lua/context.cpp | 3 ++- 5 files changed, 18 insertions(+), 13 deletions(-) create mode 100644 src/client/component/mods.hpp diff --git a/src/client/component/mods.cpp b/src/client/component/mods.cpp index 117cd3e7..dd5404bb 100644 --- a/src/client/component/mods.cpp +++ b/src/client/component/mods.cpp @@ -9,16 +9,18 @@ #include "filesystem.hpp" #include "materials.hpp" #include "fonts.hpp" +#include "mods.hpp" #include #include namespace mods { + std::string mod_path{}; + namespace { utils::hook::detour db_release_xassets_hook; - bool release_assets = false; void db_release_xassets_stub() @@ -71,22 +73,22 @@ namespace mods } const auto path = params.get(1); - game_console::print(game_console::con_type_info, "Loading mod %s\n", path); - if (!utils::io::directory_exists(path)) { game_console::print(game_console::con_type_error, "Mod %s not found!\n", path); return; } + game_console::print(game_console::con_type_info, "Loading mod %s\n", path); + filesystem::get_search_paths().erase(mod_path); filesystem::get_search_paths().insert(path); - game::mod_folder = path; + mod_path = path; restart(); }); command::add("unloadmod", [](const command::params& params) { - if (game::mod_folder.empty()) + if (mod_path.empty()) { game_console::print(game_console::con_type_info, "No mod loaded\n"); return; @@ -99,9 +101,9 @@ namespace mods return; } - game_console::print(game_console::con_type_info, "Unloading mod %s\n", game::mod_folder.data()); - filesystem::get_search_paths().erase(game::mod_folder); - game::mod_folder.clear(); + game_console::print(game_console::con_type_info, "Unloading mod %s\n", mod_path.data()); + filesystem::get_search_paths().erase(mod_path); + mod_path.clear(); restart(); }); } diff --git a/src/client/component/mods.hpp b/src/client/component/mods.hpp new file mode 100644 index 00000000..364a2f11 --- /dev/null +++ b/src/client/component/mods.hpp @@ -0,0 +1,6 @@ +#pragma once + +namespace mods +{ + extern std::string mod_path; +} \ No newline at end of file diff --git a/src/client/game/game.cpp b/src/client/game/game.cpp index e4c8dccd..b94b6a23 100644 --- a/src/client/game/game.cpp +++ b/src/client/game/game.cpp @@ -3,8 +3,6 @@ namespace game { - std::string mod_folder{}; - namespace environment { launcher::mode mode = launcher::mode::none; diff --git a/src/client/game/game.hpp b/src/client/game/game.hpp index 4da1c52d..cad966e5 100644 --- a/src/client/game/game.hpp +++ b/src/client/game/game.hpp @@ -5,8 +5,6 @@ namespace game { - extern std::string mod_folder; - namespace environment { launcher::mode get_mode(); diff --git a/src/client/game/ui_scripting/lua/context.cpp b/src/client/game/ui_scripting/lua/context.cpp index 7d9b73cf..e568e674 100644 --- a/src/client/game/ui_scripting/lua/context.cpp +++ b/src/client/game/ui_scripting/lua/context.cpp @@ -12,6 +12,7 @@ #include "../../../component/fastfiles.hpp" #include "../../../component/updater.hpp" #include "../../../component/localized_strings.hpp" +#include "../../../component/mods.hpp" #include "component/game_console.hpp" #include "component/scheduler.hpp" @@ -434,7 +435,7 @@ namespace ui_scripting::lua game_type["getloadedmod"] = [](const game&) { - return ::game::mod_folder; + return mods::mod_path; }; game_type["addlocalizedstring"] = [](const game&, const std::string& string,