From c039ab5978a31382e19463e47b4bf4a478eed606 Mon Sep 17 00:00:00 2001 From: TotallyNotElite <1yourexperiment@protonmail.com> Date: Sat, 25 May 2019 15:38:44 +0200 Subject: [PATCH] Cat_save changes and playerlist color changes * Removed cat_save and cat_load thread * Made the cat_save system not save variables set to default settings and made cat_load reset all variables to default before loading --- include/settings/Settings.hpp | 2 +- include/settings/SettingsIO.hpp | 4 +- src/globals.cpp | 2 +- src/hack.cpp | 2 +- src/settings/SettingCommands.cpp | 68 ++----------------- src/settings/Settings.cpp | 2 +- src/settings/SettingsIO.cpp | 9 ++- src/visual/menu/GuiInterface.cpp | 1 - .../menu/special/PlayerListController.cpp | 4 +- 9 files changed, 22 insertions(+), 72 deletions(-) diff --git a/include/settings/Settings.hpp b/include/settings/Settings.hpp index 0f5c0a63..99152246 100644 --- a/include/settings/Settings.hpp +++ b/include/settings/Settings.hpp @@ -38,7 +38,7 @@ namespace settings { -extern std::atomic RVarLock; +extern std::atomic cathook_disabled; enum class VariableType { BOOL, diff --git a/include/settings/SettingsIO.hpp b/include/settings/SettingsIO.hpp index 453a9e6e..af67a990 100644 --- a/include/settings/SettingsIO.hpp +++ b/include/settings/SettingsIO.hpp @@ -42,7 +42,7 @@ class SettingsWriter public: explicit SettingsWriter(Manager &manager); - bool saveTo(std::string path, bool only_changed); + bool saveTo(std::string path); protected: void write(std::string name, IVariable *variable); @@ -52,4 +52,4 @@ protected: std::ofstream stream{}; Manager &manager; }; -} // namespace settings \ No newline at end of file +} // namespace settings diff --git a/src/globals.cpp b/src/globals.cpp index b131b82f..eb7e9ffc 100644 --- a/src/globals.cpp +++ b/src/globals.cpp @@ -45,7 +45,7 @@ CUserCmd *current_user_cmd{ nullptr }; bool isHackActive() { - return !settings::RVarLock.load() && *global_enable; + return !settings::cathook_disabled.load() && *global_enable; } GlobalSettings g_Settings{}; diff --git a/src/hack.cpp b/src/hack.cpp index 33598911..5c7477dd 100644 --- a/src/hack.cpp +++ b/src/hack.cpp @@ -409,7 +409,7 @@ void hack::Shutdown() return; hack::shutdown = true; // Stop cathook stuff - settings::RVarLock.store(true); + settings::cathook_disabled.store(true); playerlist::Save(); #if ENABLE_VISUALS sdl_hooks::cleanSdlHooks(); diff --git a/src/settings/SettingCommands.cpp b/src/settings/SettingCommands.cpp index 7bc9b0aa..9e4808bb 100644 --- a/src/settings/SettingCommands.cpp +++ b/src/settings/SettingCommands.cpp @@ -51,8 +51,7 @@ static CatCommand cat("cat", "", [](const CCommand &args) { } }); -void save_thread(const int ArgC, const std::string ArgS) -{ +static CatCommand save("save", "", [](const CCommand &args) { settings::SettingsWriter writer{ settings::Manager::instance() }; DIR *config_directory = opendir(DATA_PATH "/configs"); @@ -62,86 +61,33 @@ void save_thread(const int ArgC, const std::string ArgS) mkdir(DATA_PATH "/configs", S_IRWXU | S_IRWXG); } - if (ArgC == 1) + if (args.ArgC() == 1) { - writer.saveTo(DATA_PATH "/configs/default.conf", false); + writer.saveTo(DATA_PATH "/configs/default.conf"); } else { - writer.saveTo(std::string(DATA_PATH "/configs/") + ArgS + ".conf", false); + writer.saveTo(std::string(DATA_PATH "/configs/") + args.ArgS() + ".conf"); } logging::Info("cat_save: Sorting configs..."); getAndSortAllConfigs(); logging::Info("cat_save: Closing dir..."); closedir(config_directory); - logging::Info("cat_save: Enabeling cathook..."); - settings::RVarLock.store(false); -} - -static CatCommand save("save", "", [](const CCommand &args) { - if (!settings::RVarLock.load()) - { - settings::RVarLock.store(true); - std::thread loader; - if (args.ArgC() == 1) - { - std::string string; - loader = std::thread(save_thread, 1, string); - } - else - { - loader = std::thread(save_thread, args.ArgC(), args.Arg(1)); - } - loader.detach(); - } }); -void load_thread(const int ArgC, const std::string ArgS) -{ +static CatCommand load("load", "", [](const CCommand &args) { settings::SettingsReader loader{ settings::Manager::instance() }; - if (ArgC == 1) + if (args.ArgC() == 1) { loader.loadFrom(DATA_PATH "/configs/default.conf"); } else { - std::string backup = ArgS; + std::string backup = args.ArgS(); std::string ArgS = backup; ArgS.erase(std::remove(ArgS.begin(), ArgS.end(), '\n'), ArgS.end()); ArgS.erase(std::remove(ArgS.begin(), ArgS.end(), '\r'), ArgS.end()); -#if ENABLE_VISUALS loader.loadFrom(std::string(DATA_PATH "/configs/") + ArgS + ".conf"); -#else - for (int i = 0;; i++) - { - if (loader.loadFrom(std::string(DATA_PATH "/configs/") + ArgS + ".conf")) - break; - if (i > 5) - { - logging::Info("cat_load: Force crash. Couldn't load config!"); - std::terminate(); - } - } -#endif - } - settings::RVarLock.store(false); -} - -static CatCommand load("load", "", [](const CCommand &args) { - if (!settings::RVarLock.load()) - { - settings::RVarLock.store(true); - std::thread saver; - if (args.ArgC() == 1) - { - std::string string; - saver = std::thread(load_thread, 1, string); - } - else - { - saver = std::thread(load_thread, args.ArgC(), args.Arg(1)); - } - saver.detach(); } }); diff --git a/src/settings/Settings.cpp b/src/settings/Settings.cpp index 7c74610e..b27e9e12 100644 --- a/src/settings/Settings.cpp +++ b/src/settings/Settings.cpp @@ -6,5 +6,5 @@ namespace settings { -std::atomic RVarLock{ false }; +std::atomic cathook_disabled{ false }; } diff --git a/src/settings/SettingsIO.cpp b/src/settings/SettingsIO.cpp index f27b2907..13f66688 100644 --- a/src/settings/SettingsIO.cpp +++ b/src/settings/SettingsIO.cpp @@ -14,10 +14,10 @@ settings::SettingsWriter::SettingsWriter(settings::Manager &manager) : manager(m { } -bool settings::SettingsWriter::saveTo(std::string path, bool only_changed) +bool settings::SettingsWriter::saveTo(std::string path) { logging::Info("cat_save: started"); - this->only_changed = only_changed; + this->only_changed = true; stream.open(path, std::ios::out); @@ -105,6 +105,11 @@ bool settings::SettingsReader::loadFrom(std::string path) return false; } + for (auto &v : settings::Manager::instance().registered) + { + v.second.variable.fromString(v.second.defaults); + } + while (!stream.fail()) { char c; diff --git a/src/visual/menu/GuiInterface.cpp b/src/visual/menu/GuiInterface.cpp index aa9a814c..78842581 100644 --- a/src/visual/menu/GuiInterface.cpp +++ b/src/visual/menu/GuiInterface.cpp @@ -101,7 +101,6 @@ static void initPlayerlist() pl.state = playerlist::k_EState((int) pl.state + 1); if ((int) pl.state > (int) playerlist::k_EState::STATE_LAST) pl.state = playerlist::k_EState(0); - logging::Info("%s", std::to_string(steam).c_str()); controller->updatePlayerState(userid, playerlist::k_Names[(int) pl.state]); }); } diff --git a/src/visual/menu/menu/special/PlayerListController.cpp b/src/visual/menu/menu/special/PlayerListController.cpp index 7c66e85c..289c3d5e 100644 --- a/src/visual/menu/menu/special/PlayerListController.cpp +++ b/src/visual/menu/menu/special/PlayerListController.cpp @@ -12,10 +12,10 @@ Created on 26.07.18. */ -static settings::RVariable color_team_red{ "zk.style.player-list.team.red", "ce1015" }; +static settings::RVariable color_team_red{ "zk.style.player-list.team.red", "d10e25" }; static settings::RVariable color_team_red_dead{ "zk.style.player-list.team.red-dead", "660000" }; static settings::RVariable color_team_blue{ "zk.style.player-list.team.blue", "0000ff" }; -static settings::RVariable color_team_blue_dead{ "zk.style.player-list.team.blue-dead", "000066" }; +static settings::RVariable color_team_blue_dead{ "zk.style.player-list.team.blue-dead", "6f6fce" }; static settings::RVariable color_team_other{ "zk.style.player-list.team.other", "E6E6E6" }; static settings::RVariable color_team_other_dead{ "zk.style.player-list.team.other-dead", "E6E6E6" };