diff --git a/include/settings/Settings.hpp b/include/settings/Settings.hpp index 56687a51..be818783 100644 --- a/include/settings/Settings.hpp +++ b/include/settings/Settings.hpp @@ -7,6 +7,7 @@ #include #include #include +#include #if ENABLE_VISUALS #include @@ -37,7 +38,7 @@ namespace settings { - +extern std::atomic RVarLock; enum class VariableType { BOOL, diff --git a/src/globals.cpp b/src/globals.cpp index 7793110d..caa62117 100755 --- a/src/globals.cpp +++ b/src/globals.cpp @@ -40,7 +40,7 @@ CUserCmd *current_user_cmd{ nullptr }; bool isHackActive() { - return *global_enable; + return !settings::RVarLock.load() && *global_enable; } GlobalSettings g_Settings{}; diff --git a/src/hooks/CreateMove.cpp b/src/hooks/CreateMove.cpp index 3a2654e7..40823aa8 100644 --- a/src/hooks/CreateMove.cpp +++ b/src/hooks/CreateMove.cpp @@ -126,13 +126,6 @@ DEFINE_HOOKED_METHOD(CreateMove, bool, void *this_, float input_sample_time, float curtime_old, servertime, speed, yaw; Vector vsilent, ang; - if (firstcm) - { - DelayTimer.update(); - hacks::tf2::NavBot::Init(); - hacks::tf2::NavBot::initonce(); - firstcm = false; - } tickcount++; current_user_cmd = cmd; #if !LAGBOT_MODE @@ -161,6 +154,14 @@ DEFINE_HOOKED_METHOD(CreateMove, bool, void *this_, float input_sample_time, return ret; } + if (firstcm) + { + DelayTimer.update(); + hacks::tf2::NavBot::Init(); + hacks::tf2::NavBot::initonce(); + firstcm = false; + } + if (!g_IEngine->IsInGame()) { g_Settings.bInvalid = true; diff --git a/src/hooks/DispatchUserMessage.cpp b/src/hooks/DispatchUserMessage.cpp index 3a880d1c..d967809e 100644 --- a/src/hooks/DispatchUserMessage.cpp +++ b/src/hooks/DispatchUserMessage.cpp @@ -36,6 +36,8 @@ namespace hooked_methods DEFINE_HOOKED_METHOD(DispatchUserMessage, bool, void *this_, int type, bf_read &buf) { + if (!isHackActive()) + return original::DispatchUserMessage(this_, type, buf); if (retrun && gitgud.test_and_set(100)) { PrintChat("\x07%06X%s\x01: %s", 0xe05938, lastname.c_str(), diff --git a/src/hooks/SendNetMsg.cpp b/src/hooks/SendNetMsg.cpp index 9e1b2b2a..c3acd714 100644 --- a/src/hooks/SendNetMsg.cpp +++ b/src/hooks/SendNetMsg.cpp @@ -17,6 +17,8 @@ namespace hooked_methods DEFINE_HOOKED_METHOD(SendNetMsg, bool, INetChannel *this_, INetMessage &msg, bool force_reliable, bool voice) { + if (!isHackActive()) + original::SendNetMsg(this_, msg, force_reliable, voice); size_t say_idx, say_team_idx; int offset; std::string newlines; diff --git a/src/hooks/visual/DrawModelExecute.cpp b/src/hooks/visual/DrawModelExecute.cpp index 5cae7320..87a4f738 100644 --- a/src/hooks/visual/DrawModelExecute.cpp +++ b/src/hooks/visual/DrawModelExecute.cpp @@ -18,7 +18,7 @@ DEFINE_HOOKED_METHOD(DrawModelExecute, void, IVModelRender *this_, const ModelRenderInfo_t &info, matrix3x4_t *bone) { if (!isHackActive()) - return; + return original::DrawModelExecute(this_, state, info, bone); if (!(spectator_target || no_arms || no_hats || (clean_screenshots && g_IEngine->IsTakingScreenshot()) || diff --git a/src/settings/SettingCommands.cpp b/src/settings/SettingCommands.cpp index cc28ca01..0fe34acb 100755 --- a/src/settings/SettingCommands.cpp +++ b/src/settings/SettingCommands.cpp @@ -6,6 +6,7 @@ #include #include #include +#include /* Created on 29.07.18. @@ -52,7 +53,9 @@ static CatCommand cat("cat", "", [](const CCommand &args) { } }); -static CatCommand save("save", "", [](const CCommand &args) { +void save_thread(const CCommand &args) +{ + std::this_thread::sleep_for(std::chrono_literals::operator""s(1)); settings::SettingsWriter writer{ settings::Manager::instance() }; DIR *config_directory = opendir(DATA_PATH "/configs"); @@ -73,9 +76,21 @@ static CatCommand save("save", "", [](const CCommand &args) { } getAndSortAllConfigs(); closedir(config_directory); + settings::RVarLock.store(false); +} + +static CatCommand save("save", "", [](const CCommand &args) { + if(!settings::RVarLock.load()) + { + settings::RVarLock.store(true); + std::thread loader(save_thread, args); + loader.detach(); + } }); -static CatCommand load("load", "", [](const CCommand &args) { +void load_thread(const CCommand &args) +{ + std::this_thread::sleep_for(std::chrono_literals::operator""s(1)); settings::SettingsReader loader{ settings::Manager::instance() }; if (args.ArgC() == 1) { @@ -86,6 +101,13 @@ static CatCommand load("load", "", [](const CCommand &args) { loader.loadFrom(std::string(DATA_PATH "/configs/") + args.Arg(1) + ".conf"); } + settings::RVarLock.store(false); +} + +static CatCommand load("load", "", [](const CCommand &args) { + settings::RVarLock.store(true); + std::thread saver(load_thread, args); + saver.detach(); }); static std::vector sortedVariables{}; diff --git a/src/settings/Settings.cpp b/src/settings/Settings.cpp index 7e4195f2..6659adbc 100755 --- a/src/settings/Settings.cpp +++ b/src/settings/Settings.cpp @@ -6,4 +6,5 @@ namespace settings { -} \ No newline at end of file +std::atomic RVarLock{false}; +} diff --git a/src/settings/SettingsIO.cpp b/src/settings/SettingsIO.cpp index eac465f1..3d1322cf 100755 --- a/src/settings/SettingsIO.cpp +++ b/src/settings/SettingsIO.cpp @@ -5,6 +5,7 @@ #include #include #include +#include "core/logging.hpp" settings::SettingsWriter::SettingsWriter(settings::Manager &manager) : manager(manager) @@ -13,29 +14,40 @@ settings::SettingsWriter::SettingsWriter(settings::Manager &manager) bool settings::SettingsWriter::saveTo(std::string path, bool only_changed) { + logging::Info("cat_save: started"); this->only_changed = only_changed; stream.open(path, std::ios::out); - if (stream.bad() || !stream.is_open()) + if (stream.bad() || !stream.is_open() || stream.fail() || !stream) + { + logging::Info("FATAL: cat_save FAILED!"); return false; + } using pair_type = std::pair; std::vector all_registered{}; + logging::Info("cat_save: Getting variable references..."); for (auto &v : settings::Manager::instance().registered) { if (!only_changed || v.second.isChanged()) all_registered.emplace_back( std::make_pair(v.first, &v.second.variable)); } - + logging::Info("cat_save: Sorting..."); std::sort(all_registered.begin(), all_registered.end(), [](const pair_type &a, const pair_type &b) -> bool { return a.first.compare(b.first) < 0; }); + logging::Info("cat_save: Writing..."); for (auto &v : all_registered) if (!v.first.empty()) + { write(v.first, v.second); + stream.flush(); + } + if (stream.bad() || stream.fail() || !stream) + logging::Info("cat_save: FATAL! Stream bad!"); stream.close(); return true; } @@ -75,10 +87,10 @@ bool settings::SettingsReader::loadFrom(std::string path) { stream.open(path, std::ios::in | std::ios::binary); - if (stream.bad()) + if (stream.bad() || stream.fail()) return false; - while (stream) + while (stream && !stream.bad()) { char c; stream.read(&c, 1); @@ -86,6 +98,13 @@ bool settings::SettingsReader::loadFrom(std::string path) break; pushChar(c); } + if (stream.bad() || stream.fail()) + { + logging::Info("FATAL: Read failed!"); + return false; + } + + logging::Info("Read Success!"); finishString(true); return true;