From 7b9b662f497c59e2edd5583625da38cdaca7b7dd Mon Sep 17 00:00:00 2001 From: prabhatKrMishra Date: Mon, 13 Jan 2025 11:47:00 +0530 Subject: [PATCH] Use mutex for proper synchronization * Guard both hack and reader threads so that only one thread can interact with critical variables at a time. This fixes exception related to bone esp. --- memory-external/hacks/hack.hpp | 3 +++ memory-external/hacks/reader.cpp | 3 +++ memory-external/hacks/reader.hpp | 5 ++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/memory-external/hacks/hack.hpp b/memory-external/hacks/hack.hpp index 85be195..03c9a75 100644 --- a/memory-external/hacks/hack.hpp +++ b/memory-external/hacks/hack.hpp @@ -26,6 +26,9 @@ namespace hack { }; void loop() { + + std::lock_guard lock(dataMutex); + if (g_game.isC4Planted) { Vector3 c4Origin = g_game.c4.get_origin(); diff --git a/memory-external/hacks/reader.cpp b/memory-external/hacks/reader.cpp index 164ce54..a51589a 100644 --- a/memory-external/hacks/reader.cpp +++ b/memory-external/hacks/reader.cpp @@ -68,6 +68,9 @@ void CGame::close() { } void CGame::loop() { + + std::lock_guard lock(dataMutex); + inGame = false; isC4Planted = false; diff --git a/memory-external/hacks/reader.hpp b/memory-external/hacks/reader.hpp index 7141a97..d25b249 100644 --- a/memory-external/hacks/reader.hpp +++ b/memory-external/hacks/reader.hpp @@ -3,6 +3,7 @@ #include "../classes/vector.hpp" #include #include +#include struct view_matrix_t { float* operator[ ](int index) { @@ -74,4 +75,6 @@ private: uintptr_t localList_entry2; }; -inline CGame g_game; \ No newline at end of file +inline CGame g_game; + +inline std::mutex dataMutex; \ No newline at end of file