2022-02-06 16:48:52 +01:00
|
|
|
#pragma once
|
|
|
|
|
2022-04-02 02:48:54 +02:00
|
|
|
#ifndef NETCONSOLE
|
|
|
|
#include "engine/net_chan.h"
|
|
|
|
#define MAX_STREAMS 2
|
|
|
|
#define FRAGMENT_BITS 8
|
|
|
|
#define FRAGMENT_SIZE (1<<FRAGMENT_BITS)
|
|
|
|
|
2022-08-15 02:59:41 +02:00
|
|
|
// user message
|
|
|
|
#define MAX_USER_MSG_DATA 511 // <-- 255 in Valve Source.
|
|
|
|
|
|
|
|
#define NETMSG_TYPE_BITS 8 // must be 2^NETMSG_TYPE_BITS > SVC_LASTMSG (6 in Valve Source).
|
|
|
|
#define NETMSG_LENGTH_BITS 12 // 512 bytes (11 in Valve Source, 256 bytes).
|
|
|
|
#define NET_MIN_MESSAGE 5 // Even connectionless packets require int32 value (-1) + 1 byte content
|
|
|
|
|
2022-08-30 12:10:07 +02:00
|
|
|
constexpr unsigned int AES_128_KEY_SIZE = 16;
|
2022-08-30 20:04:59 +02:00
|
|
|
constexpr unsigned int AES_128_B64_ENCODED_SIZE = 24;
|
2022-08-30 12:10:07 +02:00
|
|
|
constexpr const char* DEFAULT_NET_ENCRYPTION_KEY = "WDNWLmJYQ2ZlM0VoTid3Yg==";
|
2022-08-30 01:22:53 +02:00
|
|
|
|
2022-04-09 02:18:57 +02:00
|
|
|
/* ==== CNETCHAN ======================================================================================================================================================== */
|
2022-04-18 03:35:08 +02:00
|
|
|
inline CMemory p_NET_Init;
|
2022-05-12 01:20:19 +02:00
|
|
|
inline auto v_NET_Init = p_NET_Init.RCast<void* (*)(bool bDeveloper)>();
|
2022-04-02 02:48:54 +02:00
|
|
|
|
2022-04-18 03:35:08 +02:00
|
|
|
inline CMemory p_NET_Shutdown;
|
2022-05-12 01:20:19 +02:00
|
|
|
inline auto v_NET_Shutdown = p_NET_Shutdown.RCast<void (*)(void* thisptr, const char* szReason, uint8_t bBadRep, bool bRemoveNow)>();
|
2022-04-02 02:48:54 +02:00
|
|
|
|
2022-04-18 03:35:08 +02:00
|
|
|
inline CMemory p_NET_SetKey;
|
|
|
|
inline auto v_NET_SetKey = p_NET_SetKey.RCast<void (*)(uintptr_t pKey, const char* szHash)>();
|
2022-04-02 02:48:54 +02:00
|
|
|
|
2022-04-18 03:35:08 +02:00
|
|
|
inline CMemory p_NET_ReceiveDatagram;
|
|
|
|
inline auto v_NET_ReceiveDatagram = p_NET_ReceiveDatagram.RCast<bool (*)(int iSocket, netpacket_s* pInpacket, bool bRaw)>();
|
2022-04-02 02:48:54 +02:00
|
|
|
|
2022-04-18 03:35:08 +02:00
|
|
|
inline CMemory p_NET_SendDatagram;
|
2022-04-24 19:32:47 +02:00
|
|
|
inline auto v_NET_SendDatagram = p_NET_SendDatagram.RCast<int (*)(SOCKET s, void* pPayload, int iLenght, v_netadr_t* pAdr, bool bEncrypted)>();
|
2022-04-02 02:48:54 +02:00
|
|
|
|
2022-04-18 03:35:08 +02:00
|
|
|
inline CMemory p_NET_PrintFunc;
|
|
|
|
inline auto v_NET_PrintFunc = p_NET_PrintFunc.RCast<void(*)(const char* fmt)>();
|
2022-04-02 02:48:54 +02:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
bool NET_ReceiveDatagram(int iSocket, netpacket_s* pInpacket, bool bRaw);
|
2022-04-24 19:32:47 +02:00
|
|
|
int NET_SendDatagram(SOCKET s, void* pPayload, int iLenght, v_netadr_t* pAdr, bool bEncrypted);
|
2022-08-30 20:04:59 +02:00
|
|
|
void NET_SetKey(string svNetKey);
|
2022-04-02 02:48:54 +02:00
|
|
|
void NET_GenerateKey();
|
|
|
|
void NET_PrintFunc(const char* fmt, ...);
|
2022-05-12 01:20:19 +02:00
|
|
|
void NET_Shutdown(void* thisptr, const char* szReason, uint8_t bBadRep, bool bRemoveNow);
|
2022-09-18 23:19:50 +02:00
|
|
|
void NET_RemoveChannel(CClient* pClient, int nIndex, const char* szReason, uint8_t bBadRep, bool bRemoveNow);
|
2022-04-02 02:48:54 +02:00
|
|
|
|
|
|
|
void NET_Attach();
|
|
|
|
void NET_Detach();
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2022-05-27 02:24:34 +02:00
|
|
|
extern string g_svNetKey;
|
2022-04-10 19:59:34 +02:00
|
|
|
extern uintptr_t g_pNetKey;
|
2022-08-30 01:22:53 +02:00
|
|
|
inline std::mutex g_NetKeyMutex;
|
2022-04-02 02:48:54 +02:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2022-05-21 18:56:56 +02:00
|
|
|
class VNet : public IDetour
|
2022-04-02 02:48:54 +02:00
|
|
|
{
|
2022-04-11 01:44:30 +02:00
|
|
|
virtual void GetAdr(void) const
|
2022-04-02 02:48:54 +02:00
|
|
|
{
|
2022-05-13 14:53:25 +02:00
|
|
|
spdlog::debug("| FUN: NET_Init : {:#18x} |\n", p_NET_Init.GetPtr());
|
|
|
|
spdlog::debug("| FUN: NET_Shutdown : {:#18x} |\n", p_NET_Shutdown.GetPtr());
|
|
|
|
spdlog::debug("| FUN: NET_SetKey : {:#18x} |\n", p_NET_SetKey.GetPtr());
|
|
|
|
spdlog::debug("| FUN: NET_ReceiveDatagram : {:#18x} |\n", p_NET_ReceiveDatagram.GetPtr());
|
|
|
|
spdlog::debug("| FUN: NET_SendDatagram : {:#18x} |\n", p_NET_SendDatagram.GetPtr());
|
|
|
|
spdlog::debug("| FUN: NET_PrintFunc : {:#18x} |\n", p_NET_PrintFunc.GetPtr());
|
|
|
|
spdlog::debug("| VAR: g_pNetKey : {:#18x} |\n", g_pNetKey);
|
|
|
|
spdlog::debug("+----------------------------------------------------------------+\n");
|
2022-04-02 02:48:54 +02:00
|
|
|
}
|
2022-04-18 03:35:08 +02:00
|
|
|
virtual void GetFun(void) const
|
|
|
|
{
|
|
|
|
#if defined (GAMEDLL_S0) || defined (GAMEDLL_S1) || defined (GAMEDLL_S2)
|
2022-12-01 22:44:55 +01:00
|
|
|
p_NET_Init = g_GameDll.FindPatternSIMD("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 C0 01 ??");
|
|
|
|
p_NET_Shutdown = g_GameDll.FindPatternSIMD("48 89 6C 24 18 56 57 41 56 48 83 EC 30 83 B9 D8");
|
2022-04-18 03:35:08 +02:00
|
|
|
#elif defined (GAMEDLL_S3)
|
2022-12-01 22:44:55 +01:00
|
|
|
p_NET_Init = g_GameDll.FindPatternSIMD("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 ??");
|
|
|
|
p_NET_Shutdown = g_GameDll.FindPatternSIMD("48 89 6C 24 18 56 57 41 56 48 83 EC 30 83 B9 D0");
|
2022-04-18 03:35:08 +02:00
|
|
|
#endif
|
2022-12-01 22:44:55 +01:00
|
|
|
p_NET_SetKey = g_GameDll.FindPatternSIMD("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");
|
|
|
|
p_NET_ReceiveDatagram = g_GameDll.FindPatternSIMD("48 89 74 24 18 48 89 7C 24 20 55 41 54 41 55 41 56 41 57 48 8D AC 24 50 EB");
|
|
|
|
p_NET_SendDatagram = g_GameDll.FindPatternSIMD("48 89 5C 24 08 48 89 6C 24 10 48 89 74 24 18 57 41 56 41 57 48 81 EC ?? 05 ?? ??");
|
|
|
|
p_NET_PrintFunc = g_GameDll.FindPatternSIMD("48 89 54 24 10 4C 89 44 24 18 4C 89 4C 24 20 C3 48");
|
2022-04-18 03:35:08 +02:00
|
|
|
|
2022-05-12 01:20:19 +02:00
|
|
|
v_NET_Init = p_NET_Init.RCast<void* (*)(bool)>(); /*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*/
|
2022-04-24 19:32:47 +02:00
|
|
|
v_NET_Shutdown = p_NET_Shutdown.RCast<void (*)(void*, const char*, uint8_t, bool)>(); /*48 89 6C 24 18 56 57 41 56 48 83 EC 30 83 B9 D0*/
|
|
|
|
v_NET_SetKey = p_NET_SetKey.RCast<void (*)(uintptr_t, const char*)>(); /*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<bool (*)(int, netpacket_s*, bool)>(); /*E8 ?? ?? ?? ?? 84 C0 75 35 48 8B D3*/
|
|
|
|
v_NET_SendDatagram = p_NET_SendDatagram.RCast<int (*)(SOCKET, void*, int, v_netadr_t*, bool)>(); /*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<void(*)(const char*)>(); /*48 89 54 24 10 4C 89 44 24 18 4C 89 4C 24 20 C3 48*/
|
2022-04-18 03:35:08 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
virtual void GetVar(void) const
|
|
|
|
{
|
2022-08-09 03:02:00 +02:00
|
|
|
g_pNetKey = g_GameDll.FindString("client:NetEncryption_NewKey").FindPatternSelf("48 8D ? ? ? ? ? 48 3B", CMemory::Direction::UP, 300).ResolveRelativeAddressSelf(0x3, 0x7).GetPtr();
|
2022-04-18 03:35:08 +02:00
|
|
|
}
|
2022-04-11 01:44:30 +02:00
|
|
|
virtual void GetCon(void) const { }
|
|
|
|
virtual void Attach(void) const { }
|
|
|
|
virtual void Detach(void) const { }
|
2022-04-02 02:48:54 +02:00
|
|
|
};
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2022-05-21 18:56:56 +02:00
|
|
|
REGISTER(VNet);
|
2022-04-02 02:48:54 +02:00
|
|
|
#endif // !NETCONSOLE
|
|
|
|
|
2022-02-06 16:48:52 +01:00
|
|
|
const char* NET_ErrorString(int iCode);
|