Skip to content

Commit

Permalink
Fix crash on minecraft close from main menu
Browse files Browse the repository at this point in the history
  • Loading branch information
FreezeEngine committed Aug 1, 2024
1 parent 0d522db commit d05bf5c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 51 deletions.
20 changes: 9 additions & 11 deletions src/Client/Module/Modules/ArrowCounter/ArrowListener.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,30 +31,31 @@ 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++) {
auto item = inventory->getItem(i);

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;
Expand Down
18 changes: 8 additions & 10 deletions src/Client/Module/Modules/PotCounter/PotListener.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down
35 changes: 5 additions & 30 deletions src/Client/Module/Modules/SpeedDisplay/SpeedDisplayListener.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,44 +18,19 @@ class SpeedDisplayListener : public Listener {

Vec3<float> 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:
Expand Down

0 comments on commit d05bf5c

Please sign in to comment.