Rebuild 'ai_script_nodes_draw'

Originally stripped from retail.
This commit is contained in:
Kawe Mazidjatari 2022-07-11 12:00:08 +02:00
parent 56dc7ffb70
commit 96abdf619c
7 changed files with 83 additions and 17 deletions

View File

@ -15,10 +15,15 @@
#include "engine/debugoverlay.h"
#include "materialsystem/cmaterialsystem.h"
#include "mathlib/mathlib.h"
#ifndef CLIENT_DLL
#include "game/server/ai_network.h"
#include "game/server/ai_networkmanager.h"
#endif // !CLIENT_DLL
//------------------------------------------------------------------------------
// Purpose: checks if overlay should be decayed
// Output : true to decay, false otherwise
//------------------------------------------------------------------------------
bool OverlayBase_t::IsDead() const
{
@ -59,6 +64,7 @@ bool OverlayBase_t::IsDead() const
//------------------------------------------------------------------------------
// Purpose: destroys the overlay
// Input : *pOverlay -
//------------------------------------------------------------------------------
void DestroyOverlay(OverlayBase_t* pOverlay)
{
@ -105,6 +111,7 @@ void DestroyOverlay(OverlayBase_t* pOverlay)
//------------------------------------------------------------------------------
// Purpose: draws a generic overlay
// Input : *pOverlay -
//------------------------------------------------------------------------------
void DrawOverlay(OverlayBase_t* pOverlay)
{
@ -128,7 +135,7 @@ void DrawOverlay(OverlayBase_t* pOverlay)
}
}
v_RenderBox(*pBox->transforms, pBox->mins, pBox->maxs, Color(pBox->r, pBox->g, pBox->b, pBox->a), false);
v_RenderBox(pBox->transforms, pBox->mins, pBox->maxs, Color(pBox->r, pBox->g, pBox->b, pBox->a), false);
break;
}
case OverlayType_t::OVERLAY_SPHERE:
@ -208,14 +215,52 @@ void DrawOverlay(OverlayBase_t* pOverlay)
}
//------------------------------------------------------------------------------
// Purpose : overlay drawing entrypoint
// Purpose : draw AIN script nodes
//------------------------------------------------------------------------------
void DrawAllOverlays(char pOverlay)
void DrawAIScriptNode()
{
#ifndef CLIENT_DLL
if (*g_pAINetwork)
{
for (int i = ai_script_nodes_draw_index->GetInt(); i < (*g_pAINetwork)->GetNumScriptNodes(); i++)
{
if (i < 0)
{
return;
}
OverlayBox_t::Transforms vTransforms{}; /*!FIXME: using '__m128' without type cast shifts the stack with 0x10 despite being the same size!*/
__m128* pTransforms = reinterpret_cast<__m128*>(&vTransforms.u0);
pTransforms[0] = _mm_set_ps((*g_pAINetwork)->m_ScriptNode[i].m_vOrigin.x - 50.f, 0.0f, 0.0f, 1.0f);
pTransforms[1] = _mm_set_ps((*g_pAINetwork)->m_ScriptNode[i].m_vOrigin.y - 50.f, 0.0f, 1.0f, 0.0f);
pTransforms[2] = _mm_set_ps((*g_pAINetwork)->m_ScriptNode[i].m_vOrigin.z - 50.f, 1.0f, 0.0f, 0.0f);
v_RenderBox(vTransforms, {0, 0, 0}, {100, 100, 100}, Color(0, 255, 0, 255), true);
if (i > 0)
{
v_RenderLine((*g_pAINetwork)->m_ScriptNode[i - 1].m_vOrigin, (*g_pAINetwork)->m_ScriptNode[i].m_vOrigin, Color(255, 0, 0, 255), true);
}
}
}
#endif // !CLIENT_DLL
}
//------------------------------------------------------------------------------
// Purpose : overlay drawing entrypoint
// Input : bDraw -
//------------------------------------------------------------------------------
void DrawAllOverlays(bool bDraw)
{
if (!enable_debug_overlays->GetBool())
{
return;
}
if (ai_script_nodes_draw->GetBool())
{
DrawAIScriptNode();
}
EnterCriticalSection(&*s_OverlayMutex);
OverlayBase_t* pCurrOverlay = *s_pOverlays; // rdi
@ -263,7 +308,7 @@ void DrawAllOverlays(char pOverlay)
}
if (bDraw)
{
if (pOverlay)
if (bDraw)
{
DrawOverlay(pCurrOverlay);
}

View File

@ -71,7 +71,17 @@ struct OverlayBox_t : public OverlayBase_t
{
OverlayBox_t(void) { m_Type = OverlayType_t::OVERLAY_BOX; }
__m128i transforms[3];
struct Transforms
{
Vector3D u0;
float x;
Vector3D u1;
float y;
Vector3D u2;
float z;
};
Transforms transforms;
Vector3D mins{};
Vector3D maxs{};
int r{};
@ -145,13 +155,13 @@ void DebugOverlays_Attach();
void DebugOverlays_Detach();
inline CMemory p_DrawAllOverlays;
inline auto v_DrawAllOverlays = p_DrawAllOverlays.RCast<void (*)(char a1)>();
inline auto v_DrawAllOverlays = p_DrawAllOverlays.RCast<void (*)(bool bDraw)>();
inline CMemory p_RenderLine;
inline auto v_RenderLine = p_RenderLine.RCast<void* (*)(const Vector3D& vOrigin, const Vector3D& vDest, Color color, bool bZBuffer)>();
inline CMemory p_RenderBox;
inline auto v_RenderBox = p_RenderBox.RCast<void* (*)(const __m128i& vTransforms, const Vector3D& vMins, const Vector3D& vMaxs, Color color, bool bZBuffer)>();
inline auto v_RenderBox = p_RenderBox.RCast<void* (*)(const OverlayBox_t::Transforms& vTransforms, const Vector3D& vMins, const Vector3D& vMaxs, Color color, bool bZBuffer)>();
inline CMemory p_RenderWireframeSphere;
inline auto v_RenderWireframeSphere = p_RenderWireframeSphere.RCast<void* (*)(const Vector3D& vCenter, float flRadius, int nTheta, int nPhi, Color color, bool bZBuffer)>();
@ -199,11 +209,11 @@ class VDebugOverlay : public IDetour
p_RenderWireframeSphere = g_mGameDll.FindPatternSIMD(reinterpret_cast<rsig_t>("\x40\x56\x41\x54\x41\x55\x48\x81\xEC\x00\x00\x00\x00"), "xxxxxxxxx????");
p_RenderLine = g_mGameDll.FindPatternSIMD(reinterpret_cast<rsig_t>("\x48\x89\x74\x24\x00\x44\x89\x44\x24\x00\x57\x41\x56"), "xxxx?xxxx?xxx");
v_DrawAllOverlays = p_DrawAllOverlays.RCast<void (*)(char)>(); /*40 55 48 83 EC 30 48 8B 05 ?? ?? ?? ?? 0F B6 E9*/
v_DestroyOverlay = p_DestroyOverlay.RCast<void (*)(OverlayBase_t*)>(); /*40 53 48 83 EC 20 48 8B D9 48 8D 0D ?? ?? ?? ?? FF 15 ?? ?? ?? ?? 48 63 03 */
v_RenderBox = p_RenderBox.RCast<void* (*)(const __m128i&, const Vector3D&, const Vector3D&, Color, bool)>(); /*48 89 5C 24 ?? 48 89 6C 24 ?? 44 89 4C 24 ??*/
v_RenderWireframeSphere = p_RenderWireframeSphere.RCast<void* (*)(const Vector3D&, float, int, int, Color, bool)>(); /*40 56 41 54 41 55 48 81 EC ?? ?? ?? ??*/
v_RenderLine = p_RenderLine.RCast<void* (*)(const Vector3D&, const Vector3D&, Color, bool)>(); /*48 89 74 24 ?? 44 89 44 24 ?? 57 41 56*/
v_DrawAllOverlays = p_DrawAllOverlays.RCast<void (*)(bool)>(); /*40 55 48 83 EC 30 48 8B 05 ?? ?? ?? ?? 0F B6 E9*/
v_DestroyOverlay = p_DestroyOverlay.RCast<void (*)(OverlayBase_t*)>(); /*40 53 48 83 EC 20 48 8B D9 48 8D 0D ?? ?? ?? ?? FF 15 ?? ?? ?? ?? 48 63 03 */
v_RenderBox = p_RenderBox.RCast<void* (*)(const OverlayBox_t::Transforms&, const Vector3D&, const Vector3D&, Color, bool)>(); /*48 89 5C 24 ?? 48 89 6C 24 ?? 44 89 4C 24 ??*/
v_RenderWireframeSphere = p_RenderWireframeSphere.RCast<void* (*)(const Vector3D&, float, int, int, Color, bool)>(); /*40 56 41 54 41 55 48 81 EC ?? ?? ?? ??*/
v_RenderLine = p_RenderLine.RCast<void* (*)(const Vector3D&, const Vector3D&, Color, bool)>(); /*48 89 74 24 ?? 44 89 44 24 ?? 57 41 56*/
}
virtual void GetVar(void) const
{

View File

@ -43,6 +43,7 @@ public:
int m_iNumNodes; // +0x1070
CAI_Node** m_pAInode; // +0x1078
};
inline CAI_Network** g_pAINetwork = nullptr;
void CAI_Network_Attach();
void CAI_Network_Detach();
@ -56,6 +57,7 @@ class VAI_Network : public IDetour
virtual void GetAdr(void) const
{
spdlog::debug("| FUN: CAI_Network::DebugConnectMsg : {:#18x} |\n", p_CAI_Network__DebugConnectMsg.GetPtr());
spdlog::debug("| VAR: g_pAINetwork : {:#18x} |\n", reinterpret_cast<uintptr_t>(g_pAINetwork));
spdlog::debug("+----------------------------------------------------------------+\n");
}
virtual void GetFun(void) const
@ -63,7 +65,11 @@ class VAI_Network : public IDetour
p_CAI_Network__DebugConnectMsg = g_mGameDll.FindPatternSIMD(reinterpret_cast<rsig_t>("\x4C\x89\x4C\x24\x00\x48\x83\xEC\x18"), "xxxx?xxxx");
v_CAI_Network__DebugConnectMsg = p_CAI_Network__DebugConnectMsg.RCast<void (*)(int, int, const char*, ...)>(); /*4C 89 4C 24 ?? 48 83 EC 18*/
}
virtual void GetVar(void) const { }
virtual void GetVar(void) const
{
g_pAINetwork = g_mGameDll.FindPatternSIMD(reinterpret_cast<rsig_t>("\x48\x89\x5C\x24\x00\x4C\x63\x91\x00\x00\x00\x00"), "xxxx?xxx????")
.FindPatternSelf("48 8B").ResolveRelativeAddressSelf(0x3, 0x7).RCast<CAI_Network**>();
}
virtual void GetCon(void) const { }
virtual void Attach(void) const { }
virtual void Detach(void) const { }

View File

@ -101,7 +101,6 @@ class VAI_NetworkManager : public IDetour
p_CAI_NetworkBuilder__Build = g_mGameDll.FindPatternSIMD(reinterpret_cast<rsig_t>("\x48\x89\x54\x24\x00\x48\x89\x4C\x24\x00\x53\x55\x56\x57\x41\x54\x41\x55\x41\x56\x41\x57\x48\x83\xEC\x38\x8B\xB2\x00\x00\x00\x00"), "xxxx?xxxx?xxxxxxxxxxxxxxxxxx????");
#endif
CAI_NetworkManager__ShouldRebuild = p_CAI_NetworkManager__ShouldRebuild.RCast<void* (*)(void*, CAI_Network*, void*, int)>(); /*40 53 48 83 EC 20 48 8B D9 48 8B 0D ?? ?? ?? ?? 8B 41 6C*/
CAI_NetworkBuilder__Build = p_CAI_NetworkBuilder__Build.RCast<void* (*)(void*, CAI_Network*, void*, int)>(); /*48 89 5C 24 ?? 48 89 6C 24 ?? 48 89 74 24 ?? 48 89 4C 24 ?? 57 41 54 41 55 41 56 41 57 48 83 EC 30 48 63 BA ?? ?? ?? ??*/
CAI_NetworkBuilder__Build = p_CAI_NetworkBuilder__Build.RCast<void* (*)(void*, CAI_Network*, void*, int)>(); /*48 89 54 24 ?? 48 89 4C 24 ?? 53 55 56 57 41 54 41 55 41 56 41 57 48 83 EC 38 8B B2 ?? ?? ?? ??*/
}
virtual void GetVar(void) const

View File

@ -60,9 +60,10 @@ void ConVar::Init(void) const
r_drawWorldMeshesDepthAtTheEnd = new ConVar("r_drawWorldMeshesDepthAtTheEnd", "1", FCVAR_DEVELOPMENTONLY | FCVAR_CHEAT, "Render world meshes (depth at the end).", false, 0.f, false, 0.f, nullptr, nullptr);
//-------------------------------------------------------------------------
// SERVER |
ai_ainDumpOnLoad = new ConVar("ai_ainDumpOnLoad" , "0", FCVAR_DEVELOPMENTONLY, "Dumps AIN data from node graphs loaded from the disk on load.", false, 0.f, false, 0.f, nullptr, nullptr);
ai_ainDebugConnect = new ConVar("ai_ainDebugConnect" , "0", FCVAR_DEVELOPMENTONLY, "Debug AIN node connections.", false, 0.f, false, 0.f, nullptr, nullptr);
navmesh_always_reachable = new ConVar("navmesh_always_reachable" , "1", FCVAR_DEVELOPMENTONLY, "Marks poly from agent to target on navmesh as reachable regardless of table data ( !slower! ).", false, 0.f, false, 0.f, nullptr, nullptr); // !TODO: Default to '0' once the reachability table gets properly parsed.
ai_ainDumpOnLoad = new ConVar("ai_ainDumpOnLoad" , "0", FCVAR_DEVELOPMENTONLY, "Dumps AIN data from node graphs loaded from the disk on load.", false, 0.f, false, 0.f, nullptr, nullptr);
ai_ainDebugConnect = new ConVar("ai_ainDebugConnect" , "0", FCVAR_DEVELOPMENTONLY, "Debug AIN node connections.", false, 0.f, false, 0.f, nullptr, nullptr);
ai_script_nodes_draw_index = new ConVar("ai_script_nodes_draw_index", "0", FCVAR_DEVELOPMENTONLY, "Start index for drawing script nodes.", false, 0.f, false, 0.f, nullptr, nullptr);
navmesh_always_reachable = new ConVar("navmesh_always_reachable" , "1", FCVAR_DEVELOPMENTONLY, "Marks poly from agent to target on navmesh as reachable regardless of table data ( !slower! ).", false, 0.f, false, 0.f, nullptr, nullptr); // !TODO: Default to '0' once the reachability table gets properly parsed.
sv_showconnecting = new ConVar("sv_showconnecting" , "1", FCVAR_RELEASE, "Logs information about the connecting client to the console.", false, 0.f, false, 0.f, nullptr, nullptr);
sv_pylonVisibility = new ConVar("sv_pylonVisibility", "0", FCVAR_RELEASE, "Determines the visiblity to the Pylon master server, 0 = Offline, 1 = Hidden, 2 = Public.", false, 0.f, false, 0.f, nullptr, nullptr);
@ -172,6 +173,7 @@ void ConVar::Init(void) const
//-----------------------------------------------------------------------------
void ConVar::InitShipped(void) const
{
ai_script_nodes_draw = g_pCVar->FindVar("ai_script_nodes_draw");
single_frame_shutdown_for_reload = g_pCVar->FindVar("single_frame_shutdown_for_reload");
enable_debug_overlays = g_pCVar->FindVar("enable_debug_overlays");
model_defaultFadeDistScale = g_pCVar->FindVar("model_defaultFadeDistScale");

View File

@ -41,6 +41,8 @@ ConVar* r_drawWorldMeshesDepthAtTheEnd = nullptr;
// SERVER |
ConVar* ai_ainDumpOnLoad = nullptr;
ConVar* ai_ainDebugConnect = nullptr;
ConVar* ai_script_nodes_draw = nullptr;
ConVar* ai_script_nodes_draw_index = nullptr;
ConVar* navmesh_always_reachable = nullptr;
ConVar* sv_showconnecting = nullptr;

View File

@ -40,6 +40,8 @@ extern ConVar* r_drawWorldMeshesDepthAtTheEnd;
// SERVER |
extern ConVar* ai_ainDumpOnLoad;
extern ConVar* ai_ainDebugConnect;
extern ConVar* ai_script_nodes_draw;
extern ConVar* ai_script_nodes_draw_index;
extern ConVar* navmesh_always_reachable;
extern ConVar* sv_showconnecting;
extern ConVar* sv_pylonVisibility;