From bd0edc663d1283cc27f81cf5231353d72b3581d5 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Wed, 20 Jul 2022 12:33:39 +0200 Subject: [PATCH] Add 'g_pHullMasks' into SDK Static array of hull masks --- r5dev/game/server/ai_utility.cpp | 57 +++++++++++++++++++++----------- r5dev/game/server/detour_impl.h | 7 ++-- 2 files changed, 39 insertions(+), 25 deletions(-) diff --git a/r5dev/game/server/ai_utility.cpp b/r5dev/game/server/ai_utility.cpp index 29ddfd0c..3688aa9c 100644 --- a/r5dev/game/server/ai_utility.cpp +++ b/r5dev/game/server/ai_utility.cpp @@ -7,42 +7,59 @@ #include "core/stdafx.h" #include "tier1/cvar.h" #include "game/server/detour_impl.h" +#include "game/server/ai_networkmanager.h" -//----------------------------------------------------------------------------- -// Purpose: determines whether target poly is reachable from current agent poly -// input : *this - -// poly_1 - -// poly_2 - -// hull_type - -// Output : true if reachable, false otherwise -//----------------------------------------------------------------------------- -bool dtNavMesh__isPolyReachable(dtNavMesh* thisptr, dtPolyRef poly_1, dtPolyRef poly_2, int hull_type) +inline uint32_t g_pHullMasks[10] = // Hull mask table [r5apex_ds.exe + 131a2f8]. { - if (navmesh_always_reachable->GetBool()) - { - return true; - } - return v_dtNavMesh__isPolyReachable(thisptr, poly_1, poly_2, hull_type); -} + 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0xfffffffb, 0xfffffffa, 0xfffffff9, 0xfffffff8, 0x00040200 +}; //----------------------------------------------------------------------------- // Purpose: gets the navmesh by hull from global array [small, med_short, medium, large, extra_large] // input : hull - // Output : pointer to navmesh //----------------------------------------------------------------------------- -dtNavMesh* GetNavMeshForHull(int hull) +dtNavMesh* GetNavMeshForHull(int hullSize) { - Assert(hull >= 0 && hull <= 4); // Programmer error. - return g_pNavMesh[hull]; + assert(hullSize >= 0 && hullSize <= 4); // Programmer error. + return g_pNavMesh[hullSize]; +} + +//----------------------------------------------------------------------------- +// Purpose: gets hull mask by id +// input : hullId - +// Output : hull mask +//----------------------------------------------------------------------------- +uint32_t GetHullMaskById(int hullId) +{ + assert(hullId >= 0 && hullId <= 9); // Programmer error. + return (hullId + g_pHullMasks[hullId]); +} + +//----------------------------------------------------------------------------- +// Purpose: determines whether goal poly is reachable from agent poly +// input : *nav - +// fromRef - +// goalRef - +// hull_type - +// Output : value if reachable, false otherwise +//----------------------------------------------------------------------------- +uint8_t IsGoalPolyReachable(dtNavMesh* nav, dtPolyRef fromRef, dtPolyRef goalRef, int hullId) +{ + if (navmesh_always_reachable->GetBool()) + return true; + + return v_dtNavMesh__isPolyReachable(nav, fromRef, goalRef, hullId); } /////////////////////////////////////////////////////////////////////////////// void CAI_Utility_Attach() { - DetourAttach((LPVOID*)&v_dtNavMesh__isPolyReachable, &dtNavMesh__isPolyReachable); + DetourAttach((LPVOID*)&v_dtNavMesh__isPolyReachable, &IsGoalPolyReachable); } void CAI_Utility_Detach() { - DetourDetach((LPVOID*)&v_dtNavMesh__isPolyReachable, &dtNavMesh__isPolyReachable); + DetourDetach((LPVOID*)&v_dtNavMesh__isPolyReachable, &IsGoalPolyReachable); } \ No newline at end of file diff --git a/r5dev/game/server/detour_impl.h b/r5dev/game/server/detour_impl.h index 72feb904..a99c1f3d 100644 --- a/r5dev/game/server/detour_impl.h +++ b/r5dev/game/server/detour_impl.h @@ -33,11 +33,11 @@ enum EHULL_SIZE EXTRA_LARGE }; -inline dtPolyRef** g_pHullMask = nullptr; inline dtNavMesh** g_pNavMesh = nullptr; inline dtNavMeshQuery* g_pNavMeshQuery = nullptr; -dtNavMesh* GetNavMeshForHull(int hull); +dtNavMesh* GetNavMeshForHull(int hullSize); +uint32_t GetHullMaskById(int hullId); /////////////////////////////////////////////////////////////////////////////// class VRecast : public IDetour { @@ -46,7 +46,6 @@ class VRecast : public IDetour spdlog::debug("| FUN: dtNavMesh::Init : {:#18x} |\n", p_dtNavMesh__Init.GetPtr()); spdlog::debug("| FUN: dtNavMesh::addTile : {:#18x} |\n", p_dtNavMesh__addTile.GetPtr()); spdlog::debug("| FUN: dtNavMesh::isPolyReachable : {:#18x} |\n", p_dtNavMesh__isPolyReachable.GetPtr()); - spdlog::debug("| VAR: g_pHullMask[10] : {:#18x} |\n", reinterpret_cast(g_pHullMask)); spdlog::debug("| VAR: g_pNavMesh[5] : {:#18x} |\n", reinterpret_cast(g_pNavMesh)); spdlog::debug("| VAR: g_pNavMeshQuery : {:#18x} |\n", reinterpret_cast(g_pNavMeshQuery)); spdlog::debug("+----------------------------------------------------------------+\n"); @@ -67,8 +66,6 @@ class VRecast : public IDetour .FindPatternSelf("48 8D 3D").ResolveRelativeAddressSelf(0x3, 0x7).RCast(); g_pNavMeshQuery = g_mGameDll.FindPatternSIMD(reinterpret_cast("\x48\x89\x5C\x24\x00\x48\x89\x6C\x24\x00\x56\x57\x41\x56\x48\x81\xEC\x00\x00\x00\x00\x48\x63\xD9"), "xxxx?xxxx?xxxxxxx????xxx") .FindPatternSelf("48 89 0D").ResolveRelativeAddressSelf(0x3, 0x7).RCast(); - - g_pHullMask = p_dtNavMesh__isPolyReachable.FindPattern("48 8D 0D", CMemory::Direction::DOWN).ResolveRelativeAddressSelf(0x3, 0x7).RCast(); } virtual void GetCon(void) const { } virtual void Attach(void) const { }