diff --git a/r5dev/engine/host_state.cpp b/r5dev/engine/host_state.cpp index 081e8b27..8807bd4b 100644 --- a/r5dev/engine/host_state.cpp +++ b/r5dev/engine/host_state.cpp @@ -244,7 +244,7 @@ FORCEINLINE void CHostState::Think(void) const string svCurrentPlaylist = KeyValues_GetCurrentPlaylist(); int32_t nPlayerCount = g_pServer->GetNumHumanPlayers(); - SetConsoleTitleA(fmt::format("{} - {}/{} Players ({} on {})", + SetConsoleTitleA(fmt::format("{:s} - {:d}/{:d} Players ({:s} on {:s})", hostname->GetString(), nPlayerCount, g_ServerGlobalVariables->m_nMaxClients, svCurrentPlaylist.c_str(), m_levelName).c_str()); statsTimer.Start(); } diff --git a/r5dev/engine/net.cpp b/r5dev/engine/net.cpp index 67e4967b..2a51e5e4 100644 --- a/r5dev/engine/net.cpp +++ b/r5dev/engine/net.cpp @@ -20,41 +20,40 @@ #endif // !NETCONSOLE #ifndef NETCONSOLE -//----------------------------------------------------------------------------- -// Purpose: shutdown netchannel -//----------------------------------------------------------------------------- -void NET_ShutDown(void* thisptr, const char* szReason, std::uint8_t a1, char a2) -{ -#if !defined (GAMEDLL_S0) || !defined (GAMEDLL_S1) // !TEMP UNTIL CHOSTSTATE IS BUILD AGNOSTIC! // - _DownloadPlaylists_f_CompletionFunc(); // Re-load playlist from disk after getting disconnected from the server. -#endif // !GAMEDLL_S0 || !GAMEDLL_S1 - v_NET_Shutdown(thisptr, szReason, a1, a2); -} - //----------------------------------------------------------------------------- // Purpose: hook and log the receive datagram +// Input : iSocket - +// *pInpacket - +// bEncrypted - +// Output : true on success, false otherwise //----------------------------------------------------------------------------- -bool NET_ReceiveDatagram(int iSocket, netpacket_s* pInpacket, bool bRaw) +bool NET_ReceiveDatagram(int iSocket, netpacket_s* pInpacket, bool bEncrypted) { - bool result = v_NET_ReceiveDatagram(iSocket, pInpacket, bRaw); + bool result = v_NET_ReceiveDatagram(iSocket, pInpacket, bEncrypted); if (result) { // Log received packet data. - HexDump("[+] NET_ReceiveDatagram", 0, &pInpacket->data[NULL], pInpacket->wiresize); + HexDump("[+] NET_ReceiveDatagram", "netchan_packet_logger", &pInpacket->data[NULL], pInpacket->wiresize); } return result; } //----------------------------------------------------------------------------- // Purpose: hook and log the send datagram +// Input : s - +// *pPayload - +// iLenght - +// *pAdr - +// bEncrypted - +// Output : outgoing sequence number for this packet //----------------------------------------------------------------------------- -void* NET_SendDatagram(SOCKET s, const char* szPayload, int iLenght, int nFlags) +int NET_SendDatagram(SOCKET s, void* pPayload, int iLenght, v_netadr_t* pAdr, bool bEncrypted) { - void* result = v_NET_SendDatagram(s, szPayload, iLenght, nFlags); + int result = v_NET_SendDatagram(s, pPayload, iLenght, pAdr, bEncrypted); if (result) { // Log transmitted packet data. - HexDump("[+] NET_SendDatagram", 0, szPayload, iLenght); + HexDump("[+] NET_SendDatagram", "netchan_packet_logger", pPayload, iLenght); } return result; } @@ -114,6 +113,8 @@ void NET_GenerateKey() //----------------------------------------------------------------------------- // Purpose: hook and log the client's signonstate to the console +// Input : *fmt - +// ... - //----------------------------------------------------------------------------- void NET_PrintFunc(const char* fmt, ...) { @@ -131,9 +132,27 @@ void NET_PrintFunc(const char* fmt, ...) } //----------------------------------------------------------------------------- -// Purpose: disconnect the client and shutdown netchannel +// Purpose: shutdown netchannel +// Input : *this - +// *szReason - +// a3 - +// bRemoveNow - //----------------------------------------------------------------------------- -void NET_DisconnectClient(CBaseClient* pClient, int nIndex, const char* szReason, uint8_t unk1, char unk2) +void NET_Shutdown(void* thisptr, const char* szReason, uint8_t a1, bool bRemoveNow) +{ + _DownloadPlaylists_f_CompletionFunc(); // Re-load playlist from disk after getting disconnected from the server. + v_NET_Shutdown(thisptr, szReason, a1, bRemoveNow); +} + +//----------------------------------------------------------------------------- +// Purpose: disconnect the client and shutdown netchannel +// Input : *pClient - +// nIndex - +// *szReason - +// unk1 - +// unk2 - +//----------------------------------------------------------------------------- +void NET_DisconnectClient(CBaseClient* pClient, int nIndex, const char* szReason, uint8_t unk1, bool bRemoveNow) { #ifndef CLIENT_DLL if (!pClient || std::strlen(szReason) == NULL || !pClient->GetNetChan()) @@ -141,10 +160,10 @@ void NET_DisconnectClient(CBaseClient* pClient, int nIndex, const char* szReason return; } - v_NET_Shutdown(pClient->GetNetChan(), szReason, unk1, unk2); // Shutdown netchan. - pClient->SetNetChan(nullptr); // Null netchan. - CBaseClient_Clear(pClient); // Reset CClient instance for client. - g_bIsPersistenceVarSet[nIndex] = false; // Reset Persistence var. + v_NET_Shutdown(pClient->GetNetChan(), szReason, unk1, bRemoveNow); // Shutdown netchan. + pClient->SetNetChan(nullptr); // Null netchan. + CBaseClient_Clear(pClient); // Reset CClient instance for client. + g_bIsPersistenceVarSet[nIndex] = false; // Reset Persistence var. #endif // !CLIENT_DLL } #endif // !NETCONSOLE @@ -211,7 +230,7 @@ void NET_Attach() { DetourAttach((LPVOID*)&v_NET_PrintFunc, &NET_PrintFunc); #ifndef DEDICATED - DetourAttach((LPVOID*)&v_NET_Shutdown, &NET_ShutDown); + DetourAttach((LPVOID*)&v_NET_Shutdown, &NET_Shutdown); #endif } @@ -219,7 +238,7 @@ void NET_Detach() { DetourDetach((LPVOID*)&v_NET_PrintFunc, &NET_PrintFunc); #ifndef DEDICATED - DetourDetach((LPVOID*)&v_NET_Shutdown, &NET_ShutDown); + DetourDetach((LPVOID*)&v_NET_Shutdown, &NET_Shutdown); #endif } diff --git a/r5dev/engine/net.h b/r5dev/engine/net.h index 78ffcc86..2a217f3a 100644 --- a/r5dev/engine/net.h +++ b/r5dev/engine/net.h @@ -11,7 +11,7 @@ inline CMemory p_NET_Init; inline auto v_NET_Init = p_NET_Init.RCast(); inline CMemory p_NET_Shutdown; -inline auto v_NET_Shutdown = p_NET_Shutdown.RCast(); +inline auto v_NET_Shutdown = p_NET_Shutdown.RCast(); inline CMemory p_NET_SetKey; inline auto v_NET_SetKey = p_NET_SetKey.RCast(); @@ -20,18 +20,19 @@ inline CMemory p_NET_ReceiveDatagram; inline auto v_NET_ReceiveDatagram = p_NET_ReceiveDatagram.RCast(); inline CMemory p_NET_SendDatagram; -inline auto v_NET_SendDatagram = p_NET_SendDatagram.RCast(); +inline auto v_NET_SendDatagram = p_NET_SendDatagram.RCast(); inline CMemory p_NET_PrintFunc; inline auto v_NET_PrintFunc = p_NET_PrintFunc.RCast(); /////////////////////////////////////////////////////////////////////////////// bool NET_ReceiveDatagram(int iSocket, netpacket_s* pInpacket, bool bRaw); -void* NET_SendDatagram(SOCKET s, const char* szPayload, int iLenght, int nFlags); +int NET_SendDatagram(SOCKET s, void* pPayload, int iLenght, v_netadr_t* pAdr, bool bEncrypted); void NET_SetKey(const string& svNetKey); void NET_GenerateKey(); void NET_PrintFunc(const char* fmt, ...); -void NET_DisconnectClient(CBaseClient* pClient, int nIndex, const char* szReason, uint8_t unk1, char unk2); +void NET_Shutdown(void* thisptr, const char* szReason, uint8_t a1, bool bRemoveNow); +void NET_DisconnectClient(CBaseClient* pClient, int nIndex, const char* szReason, uint8_t unk1, bool bRemoveNow); void NET_Attach(); void NET_Detach(); @@ -70,12 +71,12 @@ class HNetChan : public IDetour p_NET_SendDatagram = g_mGameDll.FindPatternSIMD(reinterpret_cast("\x48\x89\x5C\x24\x08\x48\x89\x6C\x24\x10\x48\x89\x74\x24\x18\x57\x41\x56\x41\x57\x48\x81\xEC\x00\x05\x00\x00"), "xxxxxxxxxxxxxxxxxxxxxxx?xxx"); p_NET_PrintFunc = g_mGameDll.FindPatternSIMD(reinterpret_cast("\x48\x89\x54\x24\x10\x4C\x89\x44\x24\x18\x4C\x89\x4C\x24\x20\xC3\x48"), "xxxxxxxxxxxxxxxxx"); - v_NET_Init = p_NET_Init.RCast(); /*48 89 5C 24 08 48 89 6C 24 10 48 89 74 24 18 48 89 7C 24 20 41 54 41 56 41 57 48 81 EC F0 01 00*/ - v_NET_Shutdown = p_NET_Shutdown.RCast(); /*48 89 6C 24 18 56 57 41 56 48 83 EC 30 83 B9 D0*/ - v_NET_SetKey = p_NET_SetKey.RCast(); /*48 89 5C 24 08 48 89 6C 24 10 48 89 74 24 18 57 48 83 EC 20 48 8B F9 41 B8*/ - v_NET_ReceiveDatagram = p_NET_ReceiveDatagram.RCast(); /*E8 ?? ?? ?? ?? 84 C0 75 35 48 8B D3*/ - v_NET_SendDatagram = p_NET_SendDatagram.RCast(); /*48 89 5C 24 08 48 89 6C 24 10 48 89 74 24 18 57 41 56 41 57 48 81 EC ?? 05 00 00*/ - v_NET_PrintFunc = p_NET_PrintFunc.RCast(); /*48 89 54 24 10 4C 89 44 24 18 4C 89 4C 24 20 C3 48*/ + v_NET_Init = p_NET_Init.RCast(); /*48 89 5C 24 08 48 89 6C 24 10 48 89 74 24 18 48 89 7C 24 20 41 54 41 56 41 57 48 81 EC F0 01 00*/ + v_NET_Shutdown = p_NET_Shutdown.RCast(); /*48 89 6C 24 18 56 57 41 56 48 83 EC 30 83 B9 D0*/ + v_NET_SetKey = p_NET_SetKey.RCast(); /*48 89 5C 24 08 48 89 6C 24 10 48 89 74 24 18 57 48 83 EC 20 48 8B F9 41 B8*/ + v_NET_ReceiveDatagram = p_NET_ReceiveDatagram.RCast(); /*E8 ?? ?? ?? ?? 84 C0 75 35 48 8B D3*/ + v_NET_SendDatagram = p_NET_SendDatagram.RCast(); /*48 89 5C 24 08 48 89 6C 24 10 48 89 74 24 18 57 41 56 41 57 48 81 EC ?? 05 00 00*/ + v_NET_PrintFunc = p_NET_PrintFunc.RCast(); /*48 89 54 24 10 4C 89 44 24 18 4C 89 4C 24 20 C3 48*/ } virtual void GetVar(void) const diff --git a/r5dev/public/include/utility.h b/r5dev/public/include/utility.h index 7c92f4ae..7e1f2264 100644 --- a/r5dev/public/include/utility.h +++ b/r5dev/public/include/utility.h @@ -12,7 +12,7 @@ DWORD64 FindPatternSIMD(const char* szModule, const unsigned char* szPattern, co // Utility void DbgPrint(LPCSTR sFormat, ...); void PrintLastError(void); -void HexDump(const char* szHeader, int nFunc, const void* pData, int nSize); +void HexDump(const char* szHeader, const char* szLogger, const void* pData, int nSize); string CreateDirectories(string svFilePath); string ConvertToWinPath(const string& svInput); diff --git a/r5dev/public/utility.cpp b/r5dev/public/utility.cpp index 9eecaf8d..9573adbd 100644 --- a/r5dev/public/utility.cpp +++ b/r5dev/public/utility.cpp @@ -159,7 +159,7 @@ void PrintLastError(void) /////////////////////////////////////////////////////////////////////////////// // For dumping data from a buffer to a file on the disk -void HexDump(const char* szHeader, int nFunc, const void* pData, int nSize) +void HexDump(const char* szHeader, const char* szLogger, const void* pData, int nSize) { static unsigned char szAscii[17] = {}; static std::atomic i = {}, j = {}, k = {}; @@ -171,8 +171,15 @@ void HexDump(const char* szHeader, int nFunc, const void* pData, int nSize) k = 1; szAscii[16] = '\0'; - // Add new loggers here to replace the placeholder. - if (nFunc == 0) { logger = spdlog::get("netchan_packet_logger"); } + if (szLogger) + { + logger = spdlog::get(szLogger); + if (!logger) + { + assert(logger == nullptr); + return; + } + } // Add timestamp. logger->set_level(spdlog::level::trace); @@ -181,7 +188,7 @@ void HexDump(const char* szHeader, int nFunc, const void* pData, int nSize) // Disable EOL and create block header. logger->set_pattern("%v"); - logger->trace("{:s} ---- LEN BYTES: {}\n:\n", szHeader, nSize); + logger->trace("{:s} ---- LEN BYTES: {:d}\n:\n", szHeader, nSize); logger->trace("-------- 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF\n"); // Output the buffer to the file.