From d05bf5cea5d8e21c22d8ccba28e3de220ef4c1d0 Mon Sep 17 00:00:00 2001 From: FreezeEngine Date: Thu, 1 Aug 2024 19:37:24 +0300 Subject: [PATCH] Fix crash on minecraft close from main menu --- .../Modules/ArrowCounter/ArrowListener.hpp | 20 +++++------ .../Module/Modules/PotCounter/PotListener.hpp | 18 +++++----- .../SpeedDisplay/SpeedDisplayListener.hpp | 35 +++---------------- 3 files changed, 22 insertions(+), 51 deletions(-) diff --git a/src/Client/Module/Modules/ArrowCounter/ArrowListener.hpp b/src/Client/Module/Modules/ArrowCounter/ArrowListener.hpp index 35c0760f..0b197ae1 100644 --- a/src/Client/Module/Modules/ArrowCounter/ArrowListener.hpp +++ b/src/Client/Module/Modules/ArrowCounter/ArrowListener.hpp @@ -19,13 +19,10 @@ class ArrowListener : public Listener { void onTick(TickEvent &event) override { - - } - - void onRender(RenderEvent &event) override { if (SDK::hasInstanced && SDK::clientInstance != nullptr) { if (SDK::clientInstance->getLocalPlayer() != nullptr) { if (SDK::clientInstance->getLocalPlayer()->playerInventory != nullptr) { + auto arrowsCount = 0; auto inventory = SDK::clientInstance->getLocalPlayer()->playerInventory->inventory; if(inventory == nullptr) return; @@ -34,7 +31,7 @@ class ArrowListener : public Listener { if(offhandItem != nullptr) if (offhandItem->getItem() != nullptr) if (offhandItem->getItem()->name == "arrow") - arrows = offhandItem->count; + arrowsCount = offhandItem->count; for (int i = 0; i < 36; i++) { @@ -42,22 +39,23 @@ class ArrowListener : public Listener { if (item->getItem() != nullptr) { if (item->getItem()->name == "arrow") { - arrows += item->count; + arrowsCount += item->count; } } } - auto arrowsStr = std::to_string(arrows); - - this->module->normalRender(13, arrowsStr); - - arrows = 0; + arrows = arrowsCount; } } } } + void onRender(RenderEvent &event) override { + auto arrowsStr = std::to_string(arrows); + this->module->normalRender(13, arrowsStr); + } + public: explicit ArrowListener(const char string[5], Module *module) { this->name = string; diff --git a/src/Client/Module/Modules/PotCounter/PotListener.hpp b/src/Client/Module/Modules/PotCounter/PotListener.hpp index 9d639b54..3698fda1 100644 --- a/src/Client/Module/Modules/PotCounter/PotListener.hpp +++ b/src/Client/Module/Modules/PotCounter/PotListener.hpp @@ -20,12 +20,9 @@ class PotListener : public Listener { void onTick(TickEvent& event) override { - - } - - void onRender(RenderEvent& event) override { if (SDK::hasInstanced && SDK::clientInstance != nullptr) { if (SDK::clientInstance->getLocalPlayer() != nullptr) { + auto potsCount = 0; if (SDK::clientInstance->getLocalPlayer()->playerInventory != nullptr) { auto inventory = SDK::clientInstance->getLocalPlayer()->playerInventory->inventory; @@ -35,22 +32,23 @@ class PotListener : public Listener { if (item->getItem() != nullptr) { if (item->getItem()->name == "splash_potion") { - pots++; + potsCount++; } } } } - auto potsStr = std::to_string(pots); - - this->module->normalRender(14, potsStr); - - pots = 0; + pots = potsCount; } } } } + void onRender(RenderEvent& event) override { + auto potsStr = std::to_string(pots); + this->module->normalRender(14, potsStr); + } + public: explicit PotListener(const char string[5], Module* module) { this->name = string; diff --git a/src/Client/Module/Modules/SpeedDisplay/SpeedDisplayListener.hpp b/src/Client/Module/Modules/SpeedDisplay/SpeedDisplayListener.hpp index f5af3084..0e72bc80 100644 --- a/src/Client/Module/Modules/SpeedDisplay/SpeedDisplayListener.hpp +++ b/src/Client/Module/Modules/SpeedDisplay/SpeedDisplayListener.hpp @@ -18,44 +18,19 @@ class SpeedDisplayListener : public Listener { Vec3 PrevPos; std::string speed; - bool toes = false; - int interval = 50; //ms void onRender(RenderEvent &event) override { - if ( - module->isEnabled() && - SDK::hasInstanced && SDK::clientInstance != nullptr && - SDK::clientInstance->getLocalPlayer() != nullptr - ) - this->module->normalRender(15, speed); + this->module->normalRender(15, speed); } - void update() { - if ( - module->isEnabled() && - SDK::hasInstanced && SDK::clientInstance != nullptr && - SDK::clientInstance->getLocalPlayer() != nullptr - ) { - if(SDK::clientInstance->getLocalPlayer()->getStateVectorComponent() != nullptr) - speed = std::format("{:.2f}", SDK::clientInstance->getLocalPlayer()->getStateVectorComponent()->Pos.dist(PrevPos) * 20); - } - }; - void onTick(TickEvent &event) override { if (!SDK::clientInstance->getLocalPlayer()) return; - - if (!toes) { - toes = true; - std::thread lol([&]() { - while (!Client::disable) { - update(); - Sleep(interval); - } - }); - lol.detach(); + auto stateVectorComponent = SDK::clientInstance->getLocalPlayer()->getStateVectorComponent(); + if(stateVectorComponent != nullptr) { + speed = std::format("{:.2f}", stateVectorComponent->Pos.dist(PrevPos) * 20); + PrevPos = stateVectorComponent->Pos; } - PrevPos = SDK::clientInstance->getLocalPlayer()->getStateVectorComponent()->Pos; } public: