From 6e32a584804158daec2f57cfe3fa058f1ce3d0a7 Mon Sep 17 00:00:00 2001 From: Jack <66967891+ASpoonPlaysGames@users.noreply.github.com> Date: Mon, 30 Oct 2023 19:29:15 +0000 Subject: Refactor `debugoverlay.cpp` (fix smart pistol lines) (#538) Refactors `debugoverlay.cpp` based on primedev and fixes smart pistol lines in the process. Co-authored-by: F1F7Y <64418963+F1F7Y@users.noreply.github.com> --- NorthstarDLL/client/debugoverlay.cpp | 228 +++++++++++++++++++++++++++++++++-- 1 file changed, 218 insertions(+), 10 deletions(-) diff --git a/NorthstarDLL/client/debugoverlay.cpp b/NorthstarDLL/client/debugoverlay.cpp index cdb14693..e231054d 100644 --- a/NorthstarDLL/client/debugoverlay.cpp +++ b/NorthstarDLL/client/debugoverlay.cpp @@ -9,8 +9,10 @@ enum OverlayType_t OVERLAY_BOX = 0, OVERLAY_SPHERE, OVERLAY_LINE, + OVERLAY_SMARTAMMO, OVERLAY_TRIANGLE, OVERLAY_SWEPT_BOX, + // [Fifty]: the 2 bellow i did not confirm, rest are good OVERLAY_BOX2, OVERLAY_CAPSULE }; @@ -31,7 +33,7 @@ struct OverlayBase_t int m_nServerCount; // Latch server count, too float m_flEndTime; // When does this box go away OverlayBase_t* m_pNextOverlay; - void* m_pUnk; + __int64 m_pUnk; }; struct OverlayLine_t : public OverlayBase_t @@ -67,25 +69,116 @@ struct OverlayBox_t : public OverlayBase_t int a; }; -static HMODULE sEngineModule; +struct OverlayTriangle_t : public OverlayBase_t +{ + OverlayTriangle_t() + { + m_Type = OVERLAY_TRIANGLE; + } -typedef void (*RenderLineType)(Vector3 v1, Vector3 v2, Color c, bool bZBuffer); + Vector3 p1; + Vector3 p2; + Vector3 p3; + int r; + int g; + int b; + int a; + bool noDepthTest; +}; + +struct OverlaySweptBox_t : public OverlayBase_t +{ + OverlaySweptBox_t() + { + m_Type = OVERLAY_SWEPT_BOX; + } + + Vector3 start; + Vector3 end; + Vector3 mins; + Vector3 maxs; + QAngle angles; + int r; + int g; + int b; + int a; +}; + +struct OverlaySphere_t : public OverlayBase_t +{ + OverlaySphere_t() + { + m_Type = OVERLAY_SPHERE; + } + + Vector3 vOrigin; + float flRadius; + int nTheta; + int nPhi; + int r; + int g; + int b; + int a; + 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 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; -typedef void (*RenderBoxType)(Vector3 vOrigin, QAngle angles, Vector3 vMins, Vector3 vMaxs, Color c, bool bZBuffer, bool bInsideOut); + +// 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; +int* g_nOverlayTickCount; + // clang-format off AUTOHOOK(DrawOverlay, engine.dll + 0xABCB0, void, __fastcall, (OverlayBase_t * pOverlay)) // clang-format on { - EnterCriticalSection((LPCRITICAL_SECTION)((char*)sEngineModule + 0x10DB0A38)); // s_OverlayMutex - - void* pMaterialSystem = *(void**)((char*)sEngineModule + 0x14C675B0); + EnterCriticalSection(s_OverlayMutex); switch (pOverlay->m_Type) { + case OVERLAY_SMARTAMMO: case OVERLAY_LINE: { OverlayLine_t* pLine = static_cast(pOverlay); @@ -119,21 +212,136 @@ void, __fastcall, (OverlayBase_t * pOverlay)) } } break; + case OVERLAY_TRIANGLE: + { + OverlayTriangle_t* pTriangle = static_cast(pOverlay); + RenderTriangle( + pTriangle->p1, + pTriangle->p2, + pTriangle->p3, + Color(pTriangle->r, pTriangle->g, pTriangle->b, pTriangle->a), + pTriangle->noDepthTest); } - LeaveCriticalSection((LPCRITICAL_SECTION)((char*)sEngineModule + 0x10DB0A38)); + break; + case OVERLAY_SWEPT_BOX: + { + OverlaySweptBox_t* pBox = static_cast(pOverlay); + RenderWireframeSweptBox( + pBox->start, pBox->end, pBox->angles, pBox->mins, pBox->maxs, Color(pBox->r, pBox->g, pBox->b, pBox->a), false); + } + break; + case OVERLAY_SPHERE: + { + OverlaySphere_t* pSphere = static_cast(pOverlay); + RenderSphere( + pSphere->vOrigin, + pSphere->flRadius, + pSphere->nTheta, + pSphere->nPhi, + Color(pSphere->r, pSphere->g, pSphere->b, pSphere->a), + false); + } + break; + default: + { + spdlog::warn("Unimplemented overlay type {}", pOverlay->m_Type); + } + break; + } + + LeaveCriticalSection(s_OverlayMutex); +} + +// clang-format off +AUTOHOOK(DrawAllOverlays, engine.dll + 0xAB780, +void, __fastcall, (bool bRender)) +// clang-format on +{ + EnterCriticalSection(s_OverlayMutex); + + OverlayBase_t* pCurrOverlay = *s_pOverlays; // rbx + OverlayBase_t* pPrevOverlay = nullptr; // rsi + OverlayBase_t* pNextOverlay = nullptr; // rdi + + int m_nCreationTick; // eax + bool bShouldDraw; // zf + int m_pUnk; // eax + + while (pCurrOverlay) + { + if (OverlayBase_t__IsDead(pCurrOverlay)) + { + if (pPrevOverlay) + { + pPrevOverlay->m_pNextOverlay = pCurrOverlay->m_pNextOverlay; + } + else + { + *s_pOverlays = pCurrOverlay->m_pNextOverlay; + } + + pNextOverlay = pCurrOverlay->m_pNextOverlay; + OverlayBase_t__DestroyOverlay(pCurrOverlay); + pCurrOverlay = pNextOverlay; + } + else + { + if (pCurrOverlay->m_nCreationTick == -1) + { + m_pUnk = pCurrOverlay->m_pUnk; + + if (m_pUnk == -1) + { + bShouldDraw = true; + } + else + { + bShouldDraw = m_pUnk == *g_nOverlayTickCount; + } + } + else + { + bShouldDraw = pCurrOverlay->m_nCreationTick == *g_nRenderTickCount; + } + + if (bShouldDraw && bRender && (Cvar_enable_debug_overlays->GetBool() || pCurrOverlay->m_Type == OVERLAY_SMARTAMMO)) + { + DrawOverlay(pCurrOverlay); + } + + pPrevOverlay = pCurrOverlay; + pCurrOverlay = pCurrOverlay->m_pNextOverlay; + } + } + + LeaveCriticalSection(s_OverlayMutex); } 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(); - sEngineModule = reinterpret_cast(module.m_nAddress); + 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(); + + s_pOverlays = module.Offset(0x10DB0968).RCast(); + + g_nRenderTickCount = module.Offset(0x10DB0984).RCast(); + g_nOverlayTickCount = module.Offset(0x10DB0980).RCast(); // not in g_pCVar->FindVar by this point for whatever reason, so have to get from memory - ConVar* Cvar_enable_debug_overlays = module.Offset(0x10DB0990).RCast(); + Cvar_enable_debug_overlays = module.Offset(0x10DB0990).RCast(); Cvar_enable_debug_overlays->SetValue(false); Cvar_enable_debug_overlays->m_pszDefaultValue = (char*)"0"; Cvar_enable_debug_overlays->AddFlags(FCVAR_CHEAT); -- cgit v1.2.3