r5sdk/r5dev/game/server/ai_network.cpp
Kawe Mazidjatari a618990937 Detour code refactor
This change was planned for a long time. This moves all REGISTER calls to a single translation unit, this is required as we currently added a very dirty workaround for not registering duplicates by checking if VFTable pointer was already present in the vector... Registering from single translation unit prevents duplicate instances that gets created if header is included by more cpp files.
Reworking this reduced 100kb+ of compiled code. This commit also reworked the way functions/variables/constant gets logged with their addresses; the new code formats them on the fly, and allows for resize at any time. Formatting is no longer required by programmer.

TODO: currently there are some compile errors for dedicated and client dll's. These will be resolved very soon as they need to be properly worked out still (server & client only stuff needs to be properly split). Use the 'main' (stable) branch for the time being if you need to compile these dll's.
2023-01-25 02:26:52 +01:00

136 lines
4.1 KiB
C++

//=============================================================================//
//
// Purpose:
//
//=============================================================================//
#include "core/stdafx.h"
#include "tier1/cvar.h"
#include "game/server/ai_network.h"
int g_DebugConnectNode1 = -1;
int g_DebugConnectNode2 = -1;
#define DebuggingConnect( node1, node2 ) ( ( node1 == g_DebugConnectNode1 && node2 == g_DebugConnectNode2 ) || ( node1 == g_DebugConnectNode2 && node2 == g_DebugConnectNode1 ) )
//-----------------------------------------------------------------------------
// Purpose: debug logs node connections
// Input : node1 -
// node2 -
// *pszFormat -
// ... -
//-----------------------------------------------------------------------------
void CAI_Network::DebugConnectMsg(int node1, int node2, const char* pszFormat, ...)
{
if (ai_ainDebugConnect->GetBool())
{
if (DebuggingConnect(node1, node2))
{
static char buf[1024] = {};
{/////////////////////////////
va_list args{};
va_start(args, pszFormat);
vsnprintf(buf, sizeof(buf), pszFormat, args);
buf[sizeof(buf) - 1] = '\0';
va_end(args);
}/////////////////////////////
DevMsg(eDLL_T::SERVER, "%s", buf);
}
}
}
//-----------------------------------------------------------------------------
// Purpose: gets the AI Network VTable
// Output : void*
//-----------------------------------------------------------------------------
void* CAI_Network::GetVTable(void) const
{
return m_pVTable;
}
//-----------------------------------------------------------------------------
// Purpose: gets the number of node links
// Output : int
//-----------------------------------------------------------------------------
int CAI_Network::GetNumLinks(void) const
{
return m_iNumLinks;
}
//-----------------------------------------------------------------------------
// Purpose: gets the number of zones
// Output : int
//-----------------------------------------------------------------------------
int CAI_Network::GetNumZones(void) const
{
return m_iNumZones;
}
//-----------------------------------------------------------------------------
// Purpose: gets the number of hints
// Output : int
//-----------------------------------------------------------------------------
int CAI_Network::GetNumHints(void) const
{
return m_iNumHints;
}
//-----------------------------------------------------------------------------
// Purpose: gets the number of script nodes
// Output : int
//-----------------------------------------------------------------------------
int CAI_Network::GetNumScriptNodes(void) const
{
return m_iNumScriptNodes;
}
//-----------------------------------------------------------------------------
// Purpose: gets the path nodes
// Output : int64_t
//-----------------------------------------------------------------------------
int64_t CAI_Network::GetNumPathNodes(void) const
{
return m_iNumNodes;
}
//-----------------------------------------------------------------------------
// Purpose: gets the specified hint from static array
// Input : nIndex -
// Output : int
//-----------------------------------------------------------------------------
short CAI_Network::GetHint(int nIndex) const
{
return m_Hints[nIndex];
}
//-----------------------------------------------------------------------------
// Purpose: gets the pointer to script node array
// Output : CAI_ScriptNode*
//-----------------------------------------------------------------------------
CAI_ScriptNode* CAI_Network::GetScriptNodes(void) const
{
return m_ScriptNode;
}
//-----------------------------------------------------------------------------
// Purpose: gets the pointer to path nodes
// Output : CAI_Node**
//-----------------------------------------------------------------------------
CAI_Node** CAI_Network::GetPathNodes(void) const
{
return m_pAInode;
}
//-----------------------------------------------------------------------------
void VAI_Network::Attach() const
{
DetourAttach(&v_CAI_Network__DebugConnectMsg, &CAI_Network::DebugConnectMsg);
}
void VAI_Network::Detach() const
{
DetourDetach(&v_CAI_Network__DebugConnectMsg, &CAI_Network::DebugConnectMsg);
}