diff --git a/r5dev/core/init.cpp b/r5dev/core/init.cpp index 208d325b..581038be 100644 --- a/r5dev/core/init.cpp +++ b/r5dev/core/init.cpp @@ -171,6 +171,7 @@ void Systems_Init() #ifndef CLIENT_DLL CAI_Utility_Attach(); + CAI_Network_Attach(); CAI_NetworkManager_Attach(); #endif // !#ifndef CLIENT_DLL // Patch instructions @@ -271,6 +272,7 @@ void Systems_Shutdown() #ifndef CLIENT_DLL CAI_Utility_Detach(); + CAI_Network_Detach(); CAI_NetworkManager_Detach(); #endif // !CLIENT_DLL diff --git a/r5dev/game/server/ai_network.cpp b/r5dev/game/server/ai_network.cpp new file mode 100644 index 00000000..fcbd3a6a --- /dev/null +++ b/r5dev/game/server/ai_network.cpp @@ -0,0 +1,136 @@ +//=============================================================================// +// +// Purpose: +// +//=============================================================================// +#include "core/stdafx.h" +#include "tier0/cvar.h" +#include "engine/sys_utils.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 CAI_Network_Attach() +{ + DetourAttach((LPVOID*)&v_CAI_Network__DebugConnectMsg, &CAI_Network::DebugConnectMsg); +} + +void CAI_Network_Detach() +{ + DetourDetach((LPVOID*)&v_CAI_Network__DebugConnectMsg, &CAI_Network::DebugConnectMsg); +} diff --git a/r5dev/game/server/ai_network.h b/r5dev/game/server/ai_network.h index e53b1e60..32a9fa0b 100644 --- a/r5dev/game/server/ai_network.h +++ b/r5dev/game/server/ai_network.h @@ -8,6 +8,19 @@ //----------------------------------------------------------------------------- class CAI_Network { +public: + static void DebugConnectMsg(int node1, int node2, const char* pszFormat, ...); + void* GetVTable(void) const; + int GetNumLinks(void) const; + int GetNumZones(void) const; + int GetNumHints(void) const; + int GetNumScriptNodes(void) const; + int64_t GetNumPathNodes(void) const; + + short GetHint(int nIndex) const; + CAI_ScriptNode* GetScriptNodes(void) const; + CAI_Node** GetPathNodes(void) const; + public: void* m_pVTable; // <-- 'this'. @@ -30,3 +43,25 @@ public: int64_t m_iNumNodes; // +0x1070 CAI_Node** m_pAInode; // +0x1078 }; + +void CAI_Network_Attach(); +void CAI_Network_Detach(); + +namespace +{ + ADDRESS p_CAI_Network__DebugConnectMsg = g_mGameDll.FindPatternSIMD((std::uint8_t*)"\x4C\x89\x4C\x24\x00\x48\x83\xEC\x18", "xxxx?xxxx"); + void (*v_CAI_Network__DebugConnectMsg)(int node1, int node2, const char* pszFormat, ...) = (void (*)(int, int, const char*, ...))p_CAI_Network__DebugConnectMsg.GetPtr(); /*4C 89 4C 24 ? 48 83 EC 18*/ +} + +/////////////////////////////////////////////////////////////////////////////// +class HAI_Network : public IDetour +{ + virtual void debugp() + { + std::cout << "| FUN: CAI_Network::DebugConnectMsg : 0x" << std::hex << std::uppercase << p_CAI_Network__DebugConnectMsg.GetPtr() << std::setw(npad) << " |" << std::endl; + std::cout << "+----------------------------------------------------------------+" << std::endl; + } +}; +/////////////////////////////////////////////////////////////////////////////// + +REGISTER(HAI_Network); diff --git a/r5dev/game/server/ai_networkmanager.cpp b/r5dev/game/server/ai_networkmanager.cpp index 698ec244..da889104 100644 --- a/r5dev/game/server/ai_networkmanager.cpp +++ b/r5dev/game/server/ai_networkmanager.cpp @@ -133,7 +133,7 @@ void CAI_NetworkBuilder::SaveNetworkGraph(CAI_Network* pNetwork) DevMsg(eDLL_T::SERVER, " |-- Calculated linkcount: '%d'\n", nCalculatedLinkcount); nCalculatedLinkcount /= 2; - if (ai_dumpAINfileFromLoad->GetBool()) + if (ai_ainDumpOnLoad->GetBool()) { if (pNetwork->m_iNumLinks != nCalculatedLinkcount) { @@ -303,7 +303,7 @@ void HCAI_NetworkManager__LoadNetworkGraph(void* aimanager, void* buf, const cha CAI_NetworkManager__LoadNetworkGraph(aimanager, buf, filename); #endif - if (ai_dumpAINfileFromLoad->GetBool()) + if (ai_ainDumpOnLoad->GetBool()) { DevMsg(eDLL_T::SERVER, "Running BuildAINFile for loaded file '%s'\n", filename); CAI_NetworkBuilder::SaveNetworkGraph(*(CAI_Network**)(reinterpret_cast(aimanager) + AINETWORK_OFFSET)); diff --git a/r5dev/resource/cfg/autoexec_server_dev.cfg b/r5dev/resource/cfg/autoexec_server_dev.cfg index 4f221886..fa2e4ca8 100644 --- a/r5dev/resource/cfg/autoexec_server_dev.cfg +++ b/r5dev/resource/cfg/autoexec_server_dev.cfg @@ -26,4 +26,5 @@ sv_visualizetraces "1" // Show native and script related debug tr //// CAI //// ////////////////////////// ai_ainRebuildOnMapStart "0" // Whether to rebuild the AI Network graph on level load. -ai_dumpAINfileFromLoad "0" // Whether to dump the parsed AI Network graph file loaded from disk. +ai_ainDumpOnLoad "0" // Whether to dump the parsed AI Network graph file loaded from disk. +ai_ainDebugConnect "1" // Show AI Network graph connection debug. \ No newline at end of file diff --git a/r5dev/tier0/IConVar.cpp b/r5dev/tier0/IConVar.cpp index eb507e3c..f7fcf37b 100644 --- a/r5dev/tier0/IConVar.cpp +++ b/r5dev/tier0/IConVar.cpp @@ -55,7 +55,8 @@ void ConVar::Init(void) const rcon_password = new ConVar("rcon_password", "" , FCVAR_SERVER_CANNOT_QUERY | FCVAR_DONTRECORD | FCVAR_RELEASE, "Remote server access password (rcon is disabled if empty).", false, 0.f, false, 0.f, nullptr, nullptr); //------------------------------------------------------------------------- // SERVER | - ai_dumpAINfileFromLoad = new ConVar("ai_dumpAINfileFromLoad" , "0", FCVAR_DEVELOPMENTONLY, "Dumps AIN data from node graphs loaded from the disk on load.", false, 0.f, false, 0.f, nullptr, nullptr); + 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. 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); diff --git a/r5dev/tier0/cvar.cpp b/r5dev/tier0/cvar.cpp index 47c9c87f..ae3971b4 100644 --- a/r5dev/tier0/cvar.cpp +++ b/r5dev/tier0/cvar.cpp @@ -14,7 +14,8 @@ ConVar* rcon_address = nullptr; ConVar* rcon_password = nullptr; //----------------------------------------------------------------------------- // SERVER | -ConVar* ai_dumpAINfileFromLoad = nullptr; +ConVar* ai_ainDumpOnLoad = nullptr; +ConVar* ai_ainDebugConnect = nullptr; ConVar* navmesh_always_reachable = nullptr; ConVar* sv_showconnecting = nullptr; diff --git a/r5dev/tier0/cvar.h b/r5dev/tier0/cvar.h index e2eb4f81..5f99de8f 100644 --- a/r5dev/tier0/cvar.h +++ b/r5dev/tier0/cvar.h @@ -26,7 +26,8 @@ extern ConVar* rcon_address; extern ConVar* rcon_password; //------------------------------------------------------------------------- // SERVER | -extern ConVar* ai_dumpAINfileFromLoad; +extern ConVar* ai_ainDumpOnLoad; +extern ConVar* ai_ainDebugConnect; extern ConVar* navmesh_always_reachable; extern ConVar* sv_showconnecting; extern ConVar* sv_pylonvisibility; diff --git a/r5dev/tier1/bitbuf.cpp b/r5dev/tier1/bitbuf.cpp index 491b2071..97ea23ce 100644 --- a/r5dev/tier1/bitbuf.cpp +++ b/r5dev/tier1/bitbuf.cpp @@ -68,7 +68,7 @@ void bf_write::SetOverflowFlag() { if (this->m_bAssertOnOverflow) { - Assert(false); + assert(false); } this->m_bOverflow = true; diff --git a/r5dev/vproj/dedicated.vcxproj b/r5dev/vproj/dedicated.vcxproj index 0e3b2363..29b65d1c 100644 --- a/r5dev/vproj/dedicated.vcxproj +++ b/r5dev/vproj/dedicated.vcxproj @@ -379,6 +379,7 @@ + diff --git a/r5dev/vproj/dedicated.vcxproj.filters b/r5dev/vproj/dedicated.vcxproj.filters index 110a2c05..62ebde8d 100644 --- a/r5dev/vproj/dedicated.vcxproj.filters +++ b/r5dev/vproj/dedicated.vcxproj.filters @@ -1034,6 +1034,9 @@ sdk\client + + sdk\game\server + diff --git a/r5dev/vproj/gamesdk.vcxproj b/r5dev/vproj/gamesdk.vcxproj index aba48df6..ea1e9b91 100644 --- a/r5dev/vproj/gamesdk.vcxproj +++ b/r5dev/vproj/gamesdk.vcxproj @@ -44,6 +44,7 @@ + diff --git a/r5dev/vproj/gamesdk.vcxproj.filters b/r5dev/vproj/gamesdk.vcxproj.filters index 0891cef2..1be4070e 100644 --- a/r5dev/vproj/gamesdk.vcxproj.filters +++ b/r5dev/vproj/gamesdk.vcxproj.filters @@ -420,6 +420,9 @@ sdk\tier1 + + sdk\game\server +