From 93c831084bd735d20e4e147a71a91be88f46b48d Mon Sep 17 00:00:00 2001 From: IMXNOOBX <69653071+IMXNOOBX@users.noreply.github.com> Date: Tue, 14 Jan 2025 18:12:42 +0100 Subject: [PATCH] Checking rendering items out of bounds when looking at the ground & removed handle hijack because of not working properly --- memory-external/classes/utils.cpp | 5 + memory-external/classes/utils.h | 2 + memory-external/hacks/hack.hpp | 249 +++++++++++++++--------------- memory-external/hacks/reader.cpp | 5 +- memory-external/hacks/reader.hpp | 2 +- 5 files changed, 136 insertions(+), 127 deletions(-) diff --git a/memory-external/classes/utils.cpp b/memory-external/classes/utils.cpp index 74b395b..7f03010 100644 --- a/memory-external/classes/utils.cpp +++ b/memory-external/classes/utils.cpp @@ -11,4 +11,9 @@ void Utils::update_console_title() { config::show_extra_flags ? title += " | Flags: [O]" : title += " | Flags: [X]"; SetConsoleTitle(title.c_str()); +} + + +bool Utils::is_in_bounds(const Vector3& pos, int width, int heigh) { + return pos.x >= 0 && pos.x <= width && pos.y >= 0 && pos.y <= heigh; } \ No newline at end of file diff --git a/memory-external/classes/utils.h b/memory-external/classes/utils.h index 91b7270..3c35ed4 100644 --- a/memory-external/classes/utils.h +++ b/memory-external/classes/utils.h @@ -3,11 +3,13 @@ #include #include "config.hpp" +#include "vector.hpp" class Utils { private: public: void update_console_title(); + bool is_in_bounds(const Vector3& pos, int width, int heigh); }; inline Utils utils; \ No newline at end of file diff --git a/memory-external/hacks/hack.hpp b/memory-external/hacks/hack.hpp index 03c9a75..8938d20 100644 --- a/memory-external/hacks/hack.hpp +++ b/memory-external/hacks/hack.hpp @@ -6,7 +6,6 @@ #include "../classes/globals.hpp" namespace hack { - std::vector> boneConnections = { {"neck_0", "spine_1"}, {"spine_1", "spine_2"}, @@ -27,7 +26,7 @@ namespace hack { void loop() { - std::lock_guard lock(dataMutex); + std::lock_guard lock(reader_mutex); if (g_game.isC4Planted) { @@ -73,165 +72,169 @@ namespace hack { const Vector3 screenPos = g_game.world_to_screen(&player->origin); const Vector3 screenHead = g_game.world_to_screen(&player->head); - if (screenPos.z >= 0.01f) { - const float height = screenPos.y - screenHead.y; - const float width = height / 2.4f; + if ( + screenPos.z < 0.01f || + !utils.is_in_bounds(screenPos, g_game.game_bounds.right, g_game.game_bounds.bottom) + ) + continue; - float distance = g_game.localOrigin.calculate_distance(player->origin); - int roundedDistance = std::round(distance / 10.f); + const float height = screenPos.y - screenHead.y; + const float width = height / 2.4f; - if (config::show_head_tracker) { - render::DrawCircle( + float distance = g_game.localOrigin.calculate_distance(player->origin); + int roundedDistance = std::round(distance / 10.f); + + if (config::show_head_tracker) { + render::DrawCircle( + g::hdcBuffer, + player->bones.bonePositions["head"].x, + player->bones.bonePositions["head"].y - width / 12, + width / 5, + (g_game.localTeam == player->team ? config::esp_skeleton_color_team : config::esp_skeleton_color_enemy) + ); + } + + if (config::show_skeleton_esp) { + for (const auto& connection : boneConnections) { + const std::string& boneFrom = connection.first; + const std::string& boneTo = connection.second; + + render::DrawLine( g::hdcBuffer, - player->bones.bonePositions["head"].x, - player->bones.bonePositions["head"].y - width / 12, - width / 5, - (g_game.localTeam == player->team ? config::esp_skeleton_color_team : config::esp_skeleton_color_enemy) - ); - } - - if (config::show_skeleton_esp) { - for (const auto& connection : boneConnections) { - const std::string& boneFrom = connection.first; - const std::string& boneTo = connection.second; - - render::DrawLine( - g::hdcBuffer, - player->bones.bonePositions[boneFrom].x, player->bones.bonePositions[boneFrom].y, - player->bones.bonePositions[boneTo].x, player->bones.bonePositions[boneTo].y, - g_game.localTeam == player->team ? config::esp_skeleton_color_team : config::esp_skeleton_color_enemy - ); - } - } - - if (config::show_box_esp) - { - render::DrawBorderBox( - g::hdcBuffer, - screenHead.x - width / 2, - screenHead.y, - width, - height, - (g_game.localTeam == player->team ? config::esp_box_color_team : config::esp_box_color_enemy) + player->bones.bonePositions[boneFrom].x, player->bones.bonePositions[boneFrom].y, + player->bones.bonePositions[boneTo].x, player->bones.bonePositions[boneTo].y, + g_game.localTeam == player->team ? config::esp_skeleton_color_team : config::esp_skeleton_color_enemy ); } + } + if (config::show_box_esp) + { render::DrawBorderBox( g::hdcBuffer, - screenHead.x - (width / 2 + 10), - screenHead.y + (height * (100 - player->armor) / 100), - 2, - height - (height * (100 - player->armor) / 100), - RGB(0, 185, 255) - ); - - render::DrawBorderBox( - g::hdcBuffer, - screenHead.x - (width / 2 + 5), - screenHead.y + (height * (100 - player->health) / 100), - 2, - height - (height * (100 - player->health) / 100), - RGB( - (255 - player->health), - (55 + player->health * 2), - 75 - ) - ); - - render::RenderText( - g::hdcBuffer, - screenHead.x + (width / 2 + 5), + screenHead.x - width / 2, screenHead.y, - player->name.c_str(), - config::esp_name_color, - 10 + width, + height, + (g_game.localTeam == player->team ? config::esp_box_color_team : config::esp_box_color_enemy) ); + } - /** - * I know is not the best way but a simple way to not saturate the screen with a ton of information - */ - if (roundedDistance > config::flag_render_distance) - continue; + render::DrawBorderBox( + g::hdcBuffer, + screenHead.x - (width / 2 + 10), + screenHead.y + (height * (100 - player->armor) / 100), + 2, + height - (height * (100 - player->armor) / 100), + RGB(0, 185, 255) + ); + render::DrawBorderBox( + g::hdcBuffer, + screenHead.x - (width / 2 + 5), + screenHead.y + (height * (100 - player->health) / 100), + 2, + height - (height * (100 - player->health) / 100), + RGB( + (255 - player->health), + (55 + player->health * 2), + 75 + ) + ); + + render::RenderText( + g::hdcBuffer, + screenHead.x + (width / 2 + 5), + screenHead.y, + player->name.c_str(), + config::esp_name_color, + 10 + ); + + /** + * I know is not the best way but a simple way to not saturate the screen with a ton of information + */ + if (roundedDistance > config::flag_render_distance) + continue; + + render::RenderText( + g::hdcBuffer, + screenHead.x + (width / 2 + 5), + screenHead.y + 10, + (std::to_string(player->health) + "hp").c_str(), + RGB( + (255 - player->health), + (55 + player->health * 2), + 75 + ), + 10 + ); + + render::RenderText( + g::hdcBuffer, + screenHead.x + (width / 2 + 5), + screenHead.y + 20, + (std::to_string(player->armor) + "armor").c_str(), + RGB( + (255 - player->armor), + (55 + player->armor * 2), + 75 + ), + 10 + ); + + if (config::show_extra_flags) + { render::RenderText( g::hdcBuffer, screenHead.x + (width / 2 + 5), - screenHead.y + 10, - (std::to_string(player->health) + "hp").c_str(), - RGB( - (255 - player->health), - (55 + player->health * 2), - 75 - ), + screenHead.y + 30, + player->weapon.c_str(), + config::esp_distance_color, 10 ); render::RenderText( g::hdcBuffer, screenHead.x + (width / 2 + 5), - screenHead.y + 20, - (std::to_string(player->armor) + "armor").c_str(), - RGB( - (255 - player->armor), - (55 + player->armor * 2), - 75 - ), + screenHead.y + 40, + (std::to_string(roundedDistance) + "m away").c_str(), + config::esp_distance_color, 10 ); - if (config::show_extra_flags) + render::RenderText( + g::hdcBuffer, + screenHead.x + (width / 2 + 5), + screenHead.y + 50, + ("$" + std::to_string(player->money)).c_str(), + RGB(0, 125, 0), + 10 + ); + + if (player->flashAlpha > 100) { render::RenderText( g::hdcBuffer, screenHead.x + (width / 2 + 5), - screenHead.y + 30, - player->weapon.c_str(), + screenHead.y + 60, + "Player is flashed", config::esp_distance_color, 10 ); + } + if (player->is_defusing) + { + const std::string defuText = "Player is defusing"; render::RenderText( g::hdcBuffer, screenHead.x + (width / 2 + 5), - screenHead.y + 40, - (std::to_string(roundedDistance) + "m away").c_str(), + screenHead.y + 60, + defuText.c_str(), config::esp_distance_color, 10 ); - - render::RenderText( - g::hdcBuffer, - screenHead.x + (width / 2 + 5), - screenHead.y + 50, - ("$" + std::to_string(player->money)).c_str(), - RGB(0, 125, 0), - 10 - ); - - if (player->flashAlpha > 100) - { - render::RenderText( - g::hdcBuffer, - screenHead.x + (width / 2 + 5), - screenHead.y + 60, - "Player is flashed", - config::esp_distance_color, - 10 - ); - } - - if (player->is_defusing) - { - const std::string defuText = "Player is defusing"; - render::RenderText( - g::hdcBuffer, - screenHead.x + (width / 2 + 5), - screenHead.y + 60, - defuText.c_str(), - config::esp_distance_color, - 10 - ); - } } } } diff --git a/memory-external/hacks/reader.cpp b/memory-external/hacks/reader.cpp index dc8834e..941371b 100644 --- a/memory-external/hacks/reader.cpp +++ b/memory-external/hacks/reader.cpp @@ -43,7 +43,7 @@ void CGame::init() { std::cout << "[cs2] Waiting for cs2.exe..." << std::endl; process = std::make_shared(); - while (!process->AttachProcessHj("cs2.exe")) + while (!process->AttachProcess("cs2.exe")) std::this_thread::sleep_for(std::chrono::seconds(1)); std::cout << "[cs2] Attached to cs2.exe\n" << std::endl; @@ -68,8 +68,7 @@ void CGame::close() { } void CGame::loop() { - - std::lock_guard lock(dataMutex); + std::lock_guard lock(reader_mutex); if (updater::offsets::dwLocalPlayerController == 0x0) throw std::runtime_error("Offsets have not been corretly set, cannot proceed."); diff --git a/memory-external/hacks/reader.hpp b/memory-external/hacks/reader.hpp index d25b249..9b851cf 100644 --- a/memory-external/hacks/reader.hpp +++ b/memory-external/hacks/reader.hpp @@ -77,4 +77,4 @@ private: inline CGame g_game; -inline std::mutex dataMutex; \ No newline at end of file +inline std::mutex reader_mutex; \ No newline at end of file