From 73262ca616f0623a9715ceac90c17b0da4b320d7 Mon Sep 17 00:00:00 2001 From: Jack <66967891+ASpoonPlaysGames@users.noreply.github.com> Date: Mon, 5 Feb 2024 17:01:22 +0000 Subject: Port navmesh debug renderer from primedev (#626) Adds support for rendering navmeshes in-game using debug overlay Cherry-picked from primedev, originally written by F1F7Y Co-authored-by: F1F7Y Co-authored-by: Maya <11448698+RoyalBlue1@users.noreply.github.com> --- primedev/client/cdll_client_int.h | 5 +++ primedev/client/debugoverlay.cpp | 69 ++++++++++----------------------- primedev/client/debugoverlay.h | 28 +++++++++++++ primedev/client/entity_client_tools.cpp | 13 +++++++ 4 files changed, 67 insertions(+), 48 deletions(-) create mode 100644 primedev/client/cdll_client_int.h create mode 100644 primedev/client/debugoverlay.h create mode 100644 primedev/client/entity_client_tools.cpp (limited to 'primedev/client') diff --git a/primedev/client/cdll_client_int.h b/primedev/client/cdll_client_int.h new file mode 100644 index 00000000..a32ccbeb --- /dev/null +++ b/primedev/client/cdll_client_int.h @@ -0,0 +1,5 @@ +#pragma once + +#include "toolframework/itoolentity.h" + +inline IClientTools* g_pClientTools = nullptr; diff --git a/primedev/client/debugoverlay.cpp b/primedev/client/debugoverlay.cpp index 8e860218..a67b8355 100644 --- a/primedev/client/debugoverlay.cpp +++ b/primedev/client/debugoverlay.cpp @@ -1,6 +1,9 @@ +#include "debugoverlay.h" + #include "dedicated/dedicated.h" #include "core/convar/cvar.h" #include "core/math/vector.h" +#include "server/ai_helper.h" AUTOHOOK_INIT() @@ -122,48 +125,13 @@ struct OverlaySphere_t : public OverlayBase_t bool m_bWireframe; }; -typedef bool (*OverlayBase_t__IsDeadType)(OverlayBase_t* a1); -static OverlayBase_t__IsDeadType OverlayBase_t__IsDead; -typedef void (*OverlayBase_t__DestroyOverlayType)(OverlayBase_t* a1); -static OverlayBase_t__DestroyOverlayType OverlayBase_t__DestroyOverlay; +static bool (*OverlayBase_t__IsDead)(OverlayBase_t* a1); +static void (*OverlayBase_t__DestroyOverlay)(OverlayBase_t* a1); static ConVar* Cvar_enable_debug_overlays; LPCRITICAL_SECTION s_OverlayMutex; -// Render Line -typedef void (*RenderLineType)(const Vector3& v1, const Vector3& v2, Color c, bool bZBuffer); -static RenderLineType RenderLine; - -// Render box -typedef void (*RenderBoxType)( - const Vector3& vOrigin, const QAngle& angles, const Vector3& vMins, const Vector3& vMaxs, Color c, bool bZBuffer, bool bInsideOut); -static RenderBoxType RenderBox; - -// Render wireframe box -static RenderBoxType RenderWireframeBox; - -// Render swept box -typedef void (*RenderWireframeSweptBoxType)( - const Vector3& vStart, const Vector3& vEnd, const QAngle& angles, const Vector3& vMins, const Vector3& vMaxs, Color c, bool bZBuffer); -RenderWireframeSweptBoxType RenderWireframeSweptBox; - -// Render Triangle -typedef void (*RenderTriangleType)(const Vector3& p1, const Vector3& p2, const Vector3& p3, Color c, bool bZBuffer); -static RenderTriangleType RenderTriangle; - -// Render Axis -typedef void (*RenderAxisType)(const Vector3& vOrigin, float flScale, bool bZBuffer); -static RenderAxisType RenderAxis; - -// I dont know -typedef void (*RenderUnknownType)(const Vector3& vUnk, float flUnk, bool bUnk); -static RenderUnknownType RenderUnknown; - -// Render Sphere -typedef void (*RenderSphereType)(const Vector3& vCenter, float flRadius, int nTheta, int nPhi, Color c, bool bZBuffer); -static RenderSphereType RenderSphere; - OverlayBase_t** s_pOverlays; int* g_nRenderTickCount; @@ -317,6 +285,11 @@ void, __fastcall, (bool bRender)) } } + if (bRender && Cvar_enable_debug_overlays->GetBool()) + { + g_pAIHelper->DrawNavmeshPolys(); + } + LeaveCriticalSection(s_OverlayMutex); } @@ -324,17 +297,17 @@ ON_DLL_LOAD_CLIENT_RELIESON("engine.dll", DebugOverlay, ConVar, (CModule module) { AUTOHOOK_DISPATCH() - OverlayBase_t__IsDead = module.Offset(0xACAC0).RCast(); - OverlayBase_t__DestroyOverlay = module.Offset(0xAB680).RCast(); - - RenderLine = module.Offset(0x192A70).RCast(); - RenderBox = module.Offset(0x192520).RCast(); - RenderWireframeBox = module.Offset(0x193DA0).RCast(); - RenderWireframeSweptBox = module.Offset(0x1945A0).RCast(); - RenderTriangle = module.Offset(0x193940).RCast(); - RenderAxis = module.Offset(0x1924D0).RCast(); - RenderSphere = module.Offset(0x194170).RCast(); - RenderUnknown = module.Offset(0x1924E0).RCast(); + OverlayBase_t__IsDead = module.Offset(0xACAC0).RCast(); + OverlayBase_t__DestroyOverlay = module.Offset(0xAB680).RCast(); + + RenderLine = module.Offset(0x192A70).RCast(); + RenderBox = module.Offset(0x192520).RCast(); + RenderWireframeBox = module.Offset(0x193DA0).RCast(); + RenderWireframeSweptBox = module.Offset(0x1945A0).RCast(); + RenderTriangle = module.Offset(0x193940).RCast(); + RenderAxis = module.Offset(0x1924D0).RCast(); + RenderSphere = module.Offset(0x194170).RCast(); + RenderUnknown = module.Offset(0x1924E0).RCast(); s_OverlayMutex = module.Offset(0x10DB0A38).RCast(); diff --git a/primedev/client/debugoverlay.h b/primedev/client/debugoverlay.h new file mode 100644 index 00000000..498bfafd --- /dev/null +++ b/primedev/client/debugoverlay.h @@ -0,0 +1,28 @@ +#pragma once + +// Render Line +inline void (*RenderLine)(const Vector3& v1, const Vector3& v2, Color c, bool bZBuffer); + +// Render box +inline void (*RenderBox)( + const Vector3& vOrigin, const QAngle& angles, const Vector3& vMins, const Vector3& vMaxs, Color c, bool bZBuffer, bool bInsideOut); + +// Render wireframe box +inline void (*RenderWireframeBox)( + const Vector3& vOrigin, const QAngle& angles, const Vector3& vMins, const Vector3& vMaxs, Color c, bool bZBuffer, bool bInsideOut); + +// Render swept box +inline void (*RenderWireframeSweptBox)( + const Vector3& vStart, const Vector3& vEnd, const QAngle& angles, const Vector3& vMins, const Vector3& vMaxs, Color c, bool bZBuffer); + +// Render Triangle +inline void (*RenderTriangle)(const Vector3& p1, const Vector3& p2, const Vector3& p3, Color c, bool bZBuffer); + +// Render Axis +inline void (*RenderAxis)(const Vector3& vOrigin, float flScale, bool bZBuffer); + +// I dont know +inline void (*RenderUnknown)(const Vector3& vUnk, float flUnk, bool bUnk); + +// Render Sphere +inline void (*RenderSphere)(const Vector3& vCenter, float flRadius, int nTheta, int nPhi, Color c, bool bZBuffer); diff --git a/primedev/client/entity_client_tools.cpp b/primedev/client/entity_client_tools.cpp new file mode 100644 index 00000000..d6f0be11 --- /dev/null +++ b/primedev/client/entity_client_tools.cpp @@ -0,0 +1,13 @@ +#include "toolframework/itoolentity.h" +#include "client/cdll_client_int.h" +#include "core/tier1.h" + +class CClientTools : public IClientTools +{ +public: +}; + +ON_DLL_LOAD("client.dll", ClientClientTools, (CModule module)) +{ + g_pClientTools = Sys_GetFactoryPtr("client.dll", "VCLIENTTOOLS001").RCast(); +} -- cgit v1.2.3