From 0b0bde5958834855e4c513aa0a2775333aca092a Mon Sep 17 00:00:00 2001 From: gir489 <100792176+gir489returns@users.noreply.github.com> Date: Sun, 19 Nov 2023 16:45:43 -0500 Subject: [PATCH] Fixed Player ESP potentially crashing on invalid models. (#2431) * Check for and handle non-normal player models when doing ESP to prevent crashes. * Added sanity checks to the non-MP model scenario. --- src/function_types.hpp | 2 +- src/gta_pointers.hpp | 2 +- src/pointers.cpp | 2 +- src/views/esp/view_esp.cpp | 18 ++++++++++++++++-- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/function_types.hpp b/src/function_types.hpp index 73c468c9..581b4f61 100644 --- a/src/function_types.hpp +++ b/src/function_types.hpp @@ -198,5 +198,5 @@ namespace big::functions using remove_player_from_sender_list = bool(*)(void* list, uint64_t* rockstar_id); - using get_ped_pone = bool(*)(CPed* ped_ptr, rage::fvector4& output, PedBones bone); + using get_ped_bone = bool(*)(CPed* ped_ptr, rage::fvector4& output, PedBones bone); } diff --git a/src/gta_pointers.hpp b/src/gta_pointers.hpp index 0d5817f3..076572cc 100644 --- a/src/gta_pointers.hpp +++ b/src/gta_pointers.hpp @@ -359,7 +359,7 @@ namespace big PVOID m_game_skeleton_update; - functions::get_ped_pone m_get_ped_pone; + functions::get_ped_bone m_get_ped_bone; }; #pragma pack(pop) static_assert(sizeof(gta_pointers) % 8 == 0, "Pointers are not properly aligned"); diff --git a/src/pointers.cpp b/src/pointers.cpp index c8ad5c94..0eb4ff5a 100644 --- a/src/pointers.cpp +++ b/src/pointers.cpp @@ -1764,7 +1764,7 @@ namespace big "48 89 5C 24 ?? 48 89 6C 24 ?? 48 89 74 24 ?? 57 48 83 EC 60 48 8B 01 41 8B E8 48 8B F2", [](memory::handle ptr) { - g_pointers->m_gta.m_get_ped_pone = ptr.as(); + g_pointers->m_gta.m_get_ped_bone = ptr.as(); } } >(); // don't leave a trailing comma at the end diff --git a/src/views/esp/view_esp.cpp b/src/views/esp/view_esp.cpp index a0c9b9a3..e753a70b 100644 --- a/src/views/esp/view_esp.cpp +++ b/src/views/esp/view_esp.cpp @@ -25,8 +25,22 @@ namespace big return; rage::fvector4 player_pos; - if (!g_pointers->m_gta.m_get_ped_pone(plyr->get_ped(), player_pos, PedBones::SKEL_Pelvis)) - return; + + if (plyr->get_ped()->m_model_info->m_hash == RAGE_JOAAT("mp_m_freemode_01") || plyr->get_ped()->m_model_info->m_hash == RAGE_JOAAT("mp_f_freemode_01")) + { + if (!g_pointers->m_gta.m_get_ped_bone(plyr->get_ped(), player_pos, PedBones::SKEL_Pelvis)) + return; + } + else + { + if (plyr->get_ped()->GetNavigation() == nullptr) + return; + + if (auto navigation_pos = plyr->get_ped()->GetNavigation()->get_position()) + player_pos = {navigation_pos->x, navigation_pos->y, navigation_pos->z, 0}; + else + return; + } float screen_x, screen_y;