From ee74d050b2378d1a98496074829c5a5a31e5d8c8 Mon Sep 17 00:00:00 2001 From: TotallyNotElite <1yourexperiment@protonmail.com> Date: Fri, 14 Sep 2018 17:55:04 +0200 Subject: [PATCH] Catbots can now load configs again and autoqueue lag fix (tm) (IDEK if this works xd) --- include/hacks/AutoJoin.hpp | 2 -- src/hacks/AutoJoin.cpp | 36 ++++++++++++++------------------ src/hooks/LevelInit.cpp | 1 - src/hooks/LevelShutdown.cpp | 1 - src/settings/SettingCommands.cpp | 23 ++++++++++++++++---- src/settings/SettingsIO.cpp | 8 +++---- src/tfmm.cpp | 2 -- 7 files changed, 39 insertions(+), 34 deletions(-) diff --git a/include/hacks/AutoJoin.hpp b/include/hacks/AutoJoin.hpp index bc633718..dbe5a360 100644 --- a/include/hacks/AutoJoin.hpp +++ b/include/hacks/AutoJoin.hpp @@ -9,8 +9,6 @@ #include "common.hpp" namespace hacks::shared::autojoin { - -void resetQueueTimer(); void update(); void updateSearch(); void onShutdown(); diff --git a/src/hacks/AutoJoin.cpp b/src/hacks/AutoJoin.cpp index 55308e4c..8804d14e 100644 --- a/src/hacks/AutoJoin.cpp +++ b/src/hacks/AutoJoin.cpp @@ -38,10 +38,10 @@ bool UnassignedClass() return g_pLocalPlayer->clazz != *autojoin_class; } -static Timer autoqueue_timer{}; -static Timer queuetime{}; +static Timer autoteam_timer{}; +static Timer startqueue_timer{}; #if not ENABLE_VISUALS -static Timer req_timer{}; +static Timer queue_time{}; #endif void updateSearch() { @@ -87,14 +87,14 @@ void updateSearch() if (!auto_queue && !auto_requeue) { #if not ENABLE_VISUALS - req_timer.update(); + queue_time.update(); #endif return; } if (g_IEngine->IsInGame()) { #if not ENABLE_VISUALS - req_timer.update(); + queue_time.update(); #endif return; } @@ -116,7 +116,7 @@ void updateSearch() gc->BHaveLiveMatch()) { #if not ENABLE_VISUALS - req_timer.update(); + queue_time.update(); #endif tfmm::leaveQueue(); } @@ -127,8 +127,9 @@ void updateSearch() if (auto_requeue) { - if (gc && !gc->BConnectedToMatchServer(false) && - !gc->BHaveLiveMatch() && !invites) + if (startqueue_timer.check(5000) && gc && + !gc->BConnectedToMatchServer(false) && !gc->BHaveLiveMatch() && + !invites) if (!(pc && pc->BInQueueForMatchGroup(tfmm::getQueue()))) { logging::Info("Starting queue for standby, Invites %d", @@ -139,20 +140,20 @@ void updateSearch() if (auto_queue) { - if (gc && !gc->BConnectedToMatchServer(false) && - !gc->BHaveLiveMatch() && !invites) + if (startqueue_timer.check(5000) && gc && + !gc->BConnectedToMatchServer(false) && !gc->BHaveLiveMatch() && + !invites) if (!(pc && pc->BInQueueForMatchGroup(tfmm::getQueue()))) { logging::Info("Starting queue, Invites %d", invites); tfmm::startQueue(); } } + startqueue_timer.test_and_set(5000); #if not ENABLE_VISUALS - if (req_timer.test_and_set(600000)) + if (queue_time.test_and_set(600000)) { - logging::Info("Stuck in queue, segfaulting"); - *(int *) nullptr; - exit(1); + std::terminate(); } #endif } @@ -160,7 +161,7 @@ void updateSearch() void update() { #if !LAGBOT_MODE - if (autoqueue_timer.test_and_set(500)) + if (autoteam_timer.test_and_set(500)) { if (autojoin_team and UnassignedTeam()) { @@ -177,11 +178,6 @@ void update() #endif } -void resetQueueTimer() -{ - queuetime.update(); -} - void onShutdown() { if (auto_queue) diff --git a/src/hooks/LevelInit.cpp b/src/hooks/LevelInit.cpp index ba5b3b74..9286ceb7 100644 --- a/src/hooks/LevelInit.cpp +++ b/src/hooks/LevelInit.cpp @@ -56,7 +56,6 @@ DEFINE_HOOKED_METHOD(LevelInit, void, void *this_, const char *name) hacks::shared::backtrack::lastincomingsequencenumber = 0; hacks::shared::backtrack::sequences.clear(); #endif - hacks::shared::autojoin::resetQueueTimer(); firstcm = true; nav::init = false; #if !LAGBOT_MODE diff --git a/src/hooks/LevelShutdown.cpp b/src/hooks/LevelShutdown.cpp index b395599a..1e25770d 100644 --- a/src/hooks/LevelShutdown.cpp +++ b/src/hooks/LevelShutdown.cpp @@ -12,7 +12,6 @@ namespace hooked_methods DEFINE_HOOKED_METHOD(LevelShutdown, void, void *this_) { - hacks::shared::autojoin::resetQueueTimer(); need_name_change = true; #if !LAGBOT_MODE playerlist::Save(); diff --git a/src/settings/SettingCommands.cpp b/src/settings/SettingCommands.cpp index 0bfe4a1c..8646a62a 100755 --- a/src/settings/SettingCommands.cpp +++ b/src/settings/SettingCommands.cpp @@ -83,7 +83,7 @@ void save_thread(const CCommand &args) } static CatCommand save("save", "", [](const CCommand &args) { - if(!settings::RVarLock.load()) + if (!settings::RVarLock.load()) { settings::RVarLock.store(true); std::thread loader(save_thread, args); @@ -101,16 +101,31 @@ void load_thread(const CCommand &args) } else { +#if ENABLE_VISUALS loader.loadFrom(std::string(DATA_PATH "/configs/") + args.Arg(1) + ".conf"); +#else + for (int i = 0;; i++) + { + if (loader.loadFrom(std::string(DATA_PATH "/configs/") + + args.Arg(1) + ".conf")) + break; + if (i > 5) + std::terminate(); + std::this_thread::sleep_for(std::chrono_literals::operator""s(3)); + } +#endif } settings::RVarLock.store(false); } static CatCommand load("load", "", [](const CCommand &args) { - settings::RVarLock.store(true); - std::thread saver(load_thread, args); - saver.detach(); + if (!settings::RVarLock.load()) + { + settings::RVarLock.store(true); + std::thread saver(load_thread, args); + saver.detach(); + } }); static std::vector sortedVariables{}; diff --git a/src/settings/SettingsIO.cpp b/src/settings/SettingsIO.cpp index ad42a301..5edba2ee 100755 --- a/src/settings/SettingsIO.cpp +++ b/src/settings/SettingsIO.cpp @@ -98,7 +98,7 @@ bool settings::SettingsReader::loadFrom(std::string path) if (stream.bad() || stream.fail()) return false; - while (stream && !stream.bad()) + while (!stream.fail()) { char c; stream.read(&c, 1); @@ -106,13 +106,13 @@ bool settings::SettingsReader::loadFrom(std::string path) break; pushChar(c); } - if (stream.bad() || stream.fail()) + if (stream.fail() && !stream.eof()) { - logging::Info("FATAL: Read failed!"); + logging::Info("cat_load: FATAL: Read failed!"); return false; } - logging::Info("Read Success!"); + logging::Info("cat_load: Read Success!"); finishString(true); return true; diff --git a/src/tfmm.cpp b/src/tfmm.cpp index 6a1eea7c..225d729e 100644 --- a/src/tfmm.cpp +++ b/src/tfmm.cpp @@ -60,7 +60,6 @@ void startQueue() client->LoadSavedCasualCriteria(); client->RequestQueueForMatch((int) queue); //client->RequestQueueForStandby(); - hacks::shared::autojoin::resetQueueTimer(); queuecount++; } else @@ -72,7 +71,6 @@ void startQueueStandby() if (client) { client->RequestQueueForStandby(); - hacks::shared::autojoin::resetQueueTimer(); } } void leaveQueue()