From f5c0b428cba8c26aa190508ca37a8b58e3f4b348 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Wed, 4 Sep 2024 00:57:26 +0200 Subject: [PATCH] Recast: add hook bodies for NavMesh functions Used for debugging the Detour implementation of the engine. --- src/game/server/ai_utility.cpp | 33 +++++++++++++++++++++++++++++++++ src/game/server/detour_impl.h | 7 ++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/game/server/ai_utility.cpp b/src/game/server/ai_utility.cpp index e31c3411..a2abf8f8 100644 --- a/src/game/server/ai_utility.cpp +++ b/src/game/server/ai_utility.cpp @@ -74,6 +74,37 @@ bool Detour_IsGoalPolyReachable(dtNavMesh* const nav, const dtPolyRef fromRef, return nav->isGoalPolyReachable(fromRef, goalRef, !hasAnimType, traverseTableIndex); } +//----------------------------------------------------------------------------- +// Purpose: finds the nearest polygon to specified center point. +// Input : *query - +// *center - +// *halfExtents - +// *filter - +// *nearestRef - +// *nearestPt - +// Output: The status flags for the query. +//----------------------------------------------------------------------------- +dtStatus Detour_FindNearestPoly(dtNavMeshQuery* query, const float* center, const float* halfExtents, + const dtQueryFilter* filter, dtPolyRef* nearestRef, float* nearestPt) +{ + return query->findNearestPoly(center, halfExtents, filter, nearestRef, nearestPt); +} + +//----------------------------------------------------------------------------- +// Purpose: adds a tile to the NavMesh. +// Input : *nav - +// *unused - +// *data - +// *dataSize - +// *flags - +// *lastRef - +// Output: The status flags for the operation. +//----------------------------------------------------------------------------- +dtStatus Detour_AddTile(dtNavMesh* nav, void* unused, unsigned char* data, int dataSize, int flags, dtTileRef lastRef) +{ + return nav->addTile(data, dataSize, flags, lastRef, nullptr); +} + //----------------------------------------------------------------------------- // Purpose: initialize NavMesh and Detour query singleton for level //----------------------------------------------------------------------------- @@ -213,4 +244,6 @@ void VRecast::Detour(const bool bAttach) const { DetourSetup(&v_Detour_IsGoalPolyReachable, &Detour_IsGoalPolyReachable, bAttach); DetourSetup(&v_Detour_LevelInit, &Detour_LevelInit, bAttach); + //DetourSetup(&dtNavMesh__addTile, &Detour_AddTile, bAttach); + //DetourSetup(&dtNavMeshQuery__findNearestPoly, &Detour_FindNearestPoly, bAttach); } diff --git a/src/game/server/detour_impl.h b/src/game/server/detour_impl.h index c5188c8e..0913d002 100644 --- a/src/game/server/detour_impl.h +++ b/src/game/server/detour_impl.h @@ -11,7 +11,10 @@ inline void(*v_Detour_LevelInit)(void); inline void(*v_Detour_FreeNavMesh)(dtNavMesh* mesh); inline bool(*v_Detour_IsGoalPolyReachable)(dtNavMesh* const nav, const dtPolyRef fromPoly, const dtPolyRef goalPoly, const TraverseAnimType_e animType); inline dtStatus(*dtNavMesh__Init)(dtNavMesh* thisptr, unsigned char* data, int flags); -inline dtStatus(*dtNavMesh__addTile)(dtNavMesh* thisptr, unsigned char* data, dtMeshHeader* header, int dataSize, int flags, dtTileRef lastRef); +inline dtStatus(*dtNavMesh__addTile)(dtNavMesh* thisptr, void* unused, unsigned char* data, int dataSize, int flags, dtTileRef lastRef); +inline dtStatus(*dtNavMeshQuery__findNearestPoly)(dtNavMeshQuery* query, const float* center, const float* halfExtents, + const dtQueryFilter* filter, + dtPolyRef* nearestRef, float* nearestPt); constexpr const char* NAVMESH_PATH = "maps/navmesh/"; @@ -36,6 +39,7 @@ class VRecast : public IDetour LogFunAdr("Detour_IsGoalPolyReachable", v_Detour_IsGoalPolyReachable); LogFunAdr("dtNavMesh::Init", dtNavMesh__Init); LogFunAdr("dtNavMesh::addTile", dtNavMesh__addTile); + LogFunAdr("dtNavMeshQuery::findNearestPoly", dtNavMeshQuery__findNearestPoly); LogVarAdr("g_pNavMesh[ NavMeshType_e::NAVMESH_COUNT ]", g_pNavMesh); LogVarAdr("g_pNavMeshQuery", g_pNavMeshQuery); } @@ -46,6 +50,7 @@ class VRecast : public IDetour g_GameDll.FindPatternSIMD("48 89 6C 24 ?? 48 89 74 24 ?? 48 89 7C 24 ?? 41 56 49 63 F1").GetPtr(v_Detour_IsGoalPolyReachable); g_GameDll.FindPatternSIMD("4C 89 44 24 ?? 53 41 56 48 81 EC ?? ?? ?? ?? 0F 10 11").GetPtr(dtNavMesh__Init); g_GameDll.FindPatternSIMD("44 89 4C 24 ?? 41 55").GetPtr(dtNavMesh__addTile); + g_GameDll.FindPatternSIMD("4C 8B DC 49 89 4B ?? 41 54 41 57").GetPtr(dtNavMeshQuery__findNearestPoly); } virtual void GetVar(void) const {