mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Fix bug in 'Detour_LevelShutdown'
Pointer in array never got nulled after getting freed, causing undefined behavior. Also made a dedicated function for clearing a NavMesh slot by hull.
This commit is contained in:
parent
3e246a9d27
commit
68ae16d93a
@ -69,9 +69,9 @@ class VAI_NetworkManager : public IDetour
|
||||
LogFunAdr("CAI_NetworkManager::ShouldRebuild", p_CAI_NetworkManager__ShouldRebuild.GetPtr());
|
||||
LogFunAdr("CAI_NetworkBuilder::Build", p_CAI_NetworkBuilder__Build.GetPtr());
|
||||
LogVarAdr("g_nAiNodeClusters", reinterpret_cast<uintptr_t>(g_nAiNodeClusters));
|
||||
LogVarAdr("g_pppAiNodeClusters", reinterpret_cast<uintptr_t>(g_pppAiNodeClusters));
|
||||
LogVarAdr("g_pAiNodeClusters", reinterpret_cast<uintptr_t>(g_pppAiNodeClusters));
|
||||
LogVarAdr("g_nAiNodeClusterLinks", reinterpret_cast<uintptr_t>(g_nAiNodeClusterLinks));
|
||||
LogVarAdr("g_pppAiNodeClusterLinks", reinterpret_cast<uintptr_t>(g_pppAiNodeClusterLinks));
|
||||
LogVarAdr("g_pAiNodeClusterLinks", reinterpret_cast<uintptr_t>(g_pppAiNodeClusterLinks));
|
||||
}
|
||||
virtual void GetFun(void) const
|
||||
{
|
||||
|
@ -10,7 +10,7 @@
|
||||
#include "game/server/detour_impl.h"
|
||||
#include "game/server/ai_networkmanager.h"
|
||||
|
||||
inline uint32_t g_pHullMasks[10] = // Hull mask table [r5apex_ds.exe + 131a2f8].
|
||||
inline uint32_t g_HullMasks[10] = // Hull mask table [r5apex_ds.exe + 131a2f8].
|
||||
{
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0xfffffffb, 0xfffffffa, 0xfffffff9, 0xfffffff8, 0x00040200
|
||||
@ -27,6 +27,25 @@ dtNavMesh* GetNavMeshForHull(int hullSize)
|
||||
return g_pNavMesh[hullSize];
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: gets the navmesh by hull from global array [small, med_short, medium, large, extra_large]
|
||||
// input : hull -
|
||||
// Output : pointer to navmesh
|
||||
//-----------------------------------------------------------------------------
|
||||
void ClearNavMeshForHull(int hullSize)
|
||||
{
|
||||
Assert(hullSize >= NULL && hullSize < MAX_HULLS); // Programmer error.
|
||||
dtNavMesh* nav = g_pNavMesh[hullSize];
|
||||
|
||||
if (nav) // Only free if NavMesh for hull is loaded.
|
||||
{
|
||||
v_Detour_FreeNavMesh(nav); // Frees tiles, polys, tris, etc.
|
||||
MemAllocSingleton()->Free(nav); // Frees the main navmesh memory.
|
||||
|
||||
g_pNavMesh[hullSize] = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: gets hull mask by id
|
||||
// input : hullId -
|
||||
@ -35,7 +54,7 @@ dtNavMesh* GetNavMeshForHull(int hullSize)
|
||||
uint32_t GetHullMaskById(int hullId)
|
||||
{
|
||||
Assert(hullId >= NULL && hullId < SDK_ARRAYSIZE(g_pHullMasks)); // Programmer error.
|
||||
return (hullId + g_pHullMasks[hullId]);
|
||||
return (hullId + g_HullMasks[hullId]);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -48,8 +67,8 @@ uint32_t GetHullMaskById(int hullId)
|
||||
//-----------------------------------------------------------------------------
|
||||
uint8_t IsGoalPolyReachable(dtNavMesh* nav, dtPolyRef fromRef, dtPolyRef goalRef, int hullId)
|
||||
{
|
||||
if (navmesh_always_reachable->GetBool())
|
||||
return true;
|
||||
if (navmesh_always_reachable->GetBool())
|
||||
return true;
|
||||
|
||||
return v_dtNavMesh__isPolyReachable(nav, fromRef, goalRef, hullId);
|
||||
}
|
||||
@ -70,12 +89,7 @@ void Detour_LevelShutdown()
|
||||
{
|
||||
for (int i = 0; i < MAX_HULLS; i++)
|
||||
{
|
||||
dtNavMesh* nav = GetNavMeshForHull(i);
|
||||
if (nav) // Only free if NavMesh for hull is loaded.
|
||||
{
|
||||
v_Detour_FreeNavMesh(nav);
|
||||
MemAllocSingleton()->Free(nav);
|
||||
}
|
||||
ClearNavMeshForHull(i);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user