Add 'g_pHullMasks' into SDK

Static array of hull masks
This commit is contained in:
Kawe Mazidjatari 2022-07-20 12:33:39 +02:00
parent f57da25341
commit bd0edc663d
2 changed files with 39 additions and 25 deletions

View File

@ -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);
}

View File

@ -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<uintptr_t>(g_pHullMask));
spdlog::debug("| VAR: g_pNavMesh[5] : {:#18x} |\n", reinterpret_cast<uintptr_t>(g_pNavMesh));
spdlog::debug("| VAR: g_pNavMeshQuery : {:#18x} |\n", reinterpret_cast<uintptr_t>(g_pNavMeshQuery));
spdlog::debug("+----------------------------------------------------------------+\n");
@ -67,8 +66,6 @@ class VRecast : public IDetour
.FindPatternSelf("48 8D 3D").ResolveRelativeAddressSelf(0x3, 0x7).RCast<dtNavMesh**>();
g_pNavMeshQuery = g_mGameDll.FindPatternSIMD(reinterpret_cast<rsig_t>("\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<dtNavMeshQuery*>();
g_pHullMask = p_dtNavMesh__isPolyReachable.FindPattern("48 8D 0D", CMemory::Direction::DOWN).ResolveRelativeAddressSelf(0x3, 0x7).RCast<dtPolyRef**>();
}
virtual void GetCon(void) const { }
virtual void Attach(void) const { }