2022-04-02 02:48:54 +02:00
|
|
|
//=============================================================================//
|
|
|
|
//
|
|
|
|
// Purpose:
|
|
|
|
//
|
|
|
|
//=============================================================================//
|
|
|
|
|
|
|
|
#ifndef NET_CHAN_H
|
|
|
|
#define NET_CHAN_H
|
|
|
|
|
|
|
|
#include "tier1/bitbuf.h"
|
2023-01-29 15:12:27 +01:00
|
|
|
#include "tier1/NetAdr.h"
|
2023-02-12 02:15:58 +01:00
|
|
|
#include "tier1/NetKey.h"
|
2022-04-02 02:48:54 +02:00
|
|
|
#include "tier1/utlmemory.h"
|
2022-06-23 19:52:58 +02:00
|
|
|
#include "tier1/utlvector.h"
|
2022-04-02 02:48:54 +02:00
|
|
|
#include "common/netmessages.h"
|
|
|
|
#include "common/protocol.h"
|
2022-08-09 17:18:07 +02:00
|
|
|
#include "public/inetchannel.h"
|
2021-12-25 22:36:38 +01:00
|
|
|
|
2022-04-02 02:48:54 +02:00
|
|
|
#define NET_FRAMES_BACKUP 128
|
2022-04-05 01:13:27 +02:00
|
|
|
#define NET_CHANNELNAME_MAXLEN 32
|
2022-04-02 02:48:54 +02:00
|
|
|
#define NET_FRAMES_MASK (NET_FRAMES_BACKUP-1)
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Purpose: forward declarations
|
|
|
|
//-----------------------------------------------------------------------------
|
2022-05-20 11:52:19 +02:00
|
|
|
class CClient;
|
2022-03-27 23:50:35 +02:00
|
|
|
|
2022-04-02 02:48:54 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
struct netframe_t
|
2021-12-25 22:36:38 +01:00
|
|
|
{
|
2022-04-02 02:48:54 +02:00
|
|
|
float one;
|
|
|
|
float two;
|
|
|
|
float three;
|
|
|
|
float four;
|
|
|
|
float five;
|
|
|
|
float six;
|
|
|
|
};
|
2021-12-25 22:36:38 +01:00
|
|
|
|
2022-04-02 02:48:54 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
2022-04-02 12:27:35 +02:00
|
|
|
struct netflow_t
|
2022-04-02 02:48:54 +02:00
|
|
|
{
|
|
|
|
float nextcompute;
|
|
|
|
float avgbytespersec;
|
|
|
|
float avgpacketspersec;
|
|
|
|
float avgloss;
|
|
|
|
float avgchoke;
|
|
|
|
float avglatency;
|
|
|
|
float latency;
|
|
|
|
int64_t totalpackets;
|
|
|
|
int64_t totalbytes;
|
|
|
|
netframe_t frames[NET_FRAMES_BACKUP];
|
|
|
|
netframe_t current_frame;
|
|
|
|
};
|
2021-12-25 22:36:38 +01:00
|
|
|
|
2022-04-02 02:48:54 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
2022-04-02 12:27:35 +02:00
|
|
|
struct dataFragments_t
|
2022-04-02 02:48:54 +02:00
|
|
|
{
|
|
|
|
char* data;
|
|
|
|
int64_t block_size;
|
|
|
|
bool m_bIsCompressed;
|
|
|
|
uint8_t gap11[7];
|
|
|
|
int64_t m_nRawSize;
|
|
|
|
bool m_bFirstFragment;
|
|
|
|
bool m_bLastFragment;
|
|
|
|
bool m_bIsOutbound;
|
|
|
|
int transferID;
|
|
|
|
int m_nTransferSize;
|
|
|
|
int m_nCurrentOffset;
|
|
|
|
};
|
2021-12-25 22:36:38 +01:00
|
|
|
|
2022-04-02 02:48:54 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
enum EBufType
|
|
|
|
{
|
|
|
|
BUF_RELIABLE = 0,
|
|
|
|
BUF_UNRELIABLE,
|
|
|
|
BUF_VOICE
|
|
|
|
};
|
2021-12-25 22:36:38 +01:00
|
|
|
|
2022-04-02 02:48:54 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
2022-04-02 12:27:35 +02:00
|
|
|
class CNetChan
|
2022-04-02 02:48:54 +02:00
|
|
|
{
|
|
|
|
public:
|
2022-08-11 11:07:45 +02:00
|
|
|
const char* GetName(void) const;
|
2023-04-30 01:24:45 +02:00
|
|
|
const char* GetAddress(bool onlyBase = false) const;
|
|
|
|
int GetPort(void) const;
|
2022-04-02 02:48:54 +02:00
|
|
|
int GetDataRate(void) const;
|
|
|
|
int GetBufferSize(void) const;
|
2021-12-25 22:36:38 +01:00
|
|
|
|
2022-04-02 02:48:54 +02:00
|
|
|
float GetLatency(int flow) const;
|
|
|
|
float GetAvgChoke(int flow) const;
|
|
|
|
float GetAvgLatency(int flow) const;
|
|
|
|
float GetAvgLoss(int flow) const;
|
|
|
|
float GetAvgPackets(int flow) const;
|
|
|
|
float GetAvgData(int flow) const;
|
2021-12-25 22:36:38 +01:00
|
|
|
|
2022-08-14 18:35:01 +02:00
|
|
|
int64_t GetTotalData(int flow) const;
|
|
|
|
int64_t GetTotalPackets(int flow) const;
|
2022-04-02 02:48:54 +02:00
|
|
|
int GetSequenceNr(int flow) const;
|
2021-12-25 22:36:38 +01:00
|
|
|
|
2022-04-02 02:48:54 +02:00
|
|
|
float GetTimeoutSeconds(void) const;
|
2023-02-15 20:49:14 +01:00
|
|
|
double GetTimeConnected(void) const;
|
2022-04-02 02:48:54 +02:00
|
|
|
int GetSocket(void) const;
|
2021-12-25 22:36:38 +01:00
|
|
|
|
2023-04-29 11:11:10 +01:00
|
|
|
const bf_write& GetStreamVoice(void) const;
|
2023-04-30 11:11:33 +02:00
|
|
|
const netadr_t& GetRemoteAddress(void) const;
|
2023-04-29 11:11:10 +01:00
|
|
|
|
2022-04-02 02:48:54 +02:00
|
|
|
bool IsOverflowed(void) const;
|
2022-05-21 18:56:56 +02:00
|
|
|
void Clear(bool bStopProcessing);
|
2022-09-17 23:34:36 +02:00
|
|
|
|
|
|
|
static bool ProcessMessages(CNetChan* pChan, bf_read* pMsg);
|
2023-02-18 00:05:55 +01:00
|
|
|
|
|
|
|
void SetRemoteFramerate(float flFrameTime, float flFrameTimeStdDeviation);
|
|
|
|
void SetRemoteCPUStatistics(uint8_t nStats);
|
2022-04-02 02:48:54 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
private:
|
|
|
|
bool m_bProcessingMessages;
|
|
|
|
bool m_bShouldDelete;
|
|
|
|
bool m_bStopProcessing;
|
|
|
|
bool shutting_down;
|
|
|
|
int m_nOutSequenceNr;
|
|
|
|
int m_nInSequenceNr;
|
|
|
|
int m_nOutSequenceNrAck;
|
|
|
|
int m_nChokedPackets;
|
|
|
|
int unknown_challenge_var;
|
2022-04-02 04:11:44 +02:00
|
|
|
#if defined (GAMEDLL_S0) || defined (GAMEDLL_S1) || defined (GAMEDLL_S2)
|
|
|
|
char pad[8];
|
|
|
|
#endif
|
2022-04-02 02:48:54 +02:00
|
|
|
int m_nLastRecvFlags;
|
|
|
|
RTL_SRWLOCK LOCK;
|
|
|
|
bf_write m_StreamReliable;
|
2022-05-20 20:14:39 +02:00
|
|
|
CUtlMemory<byte> m_ReliableDataBuffer;
|
2022-04-02 02:48:54 +02:00
|
|
|
bf_write m_StreamUnreliable;
|
2022-05-20 20:14:39 +02:00
|
|
|
CUtlMemory<byte> m_UnreliableDataBuffer;
|
2022-04-02 02:48:54 +02:00
|
|
|
bf_write m_StreamVoice;
|
2022-05-20 20:14:39 +02:00
|
|
|
CUtlMemory<byte> m_VoiceDataBuffer;
|
2022-04-02 02:48:54 +02:00
|
|
|
int m_Socket;
|
|
|
|
int m_MaxReliablePayloadSize;
|
|
|
|
double last_received;
|
|
|
|
double connect_time;
|
|
|
|
uint32_t m_Rate;
|
|
|
|
int padding_maybe;
|
|
|
|
double m_fClearTime;
|
2022-06-23 19:52:58 +02:00
|
|
|
CUtlVector<dataFragments_t*> m_WaitingList;
|
2022-04-02 02:48:54 +02:00
|
|
|
dataFragments_t m_ReceiveList;
|
|
|
|
int m_nSubOutFragmentsAck;
|
|
|
|
int m_nSubInFragments;
|
|
|
|
int m_nNonceHost;
|
|
|
|
uint32_t m_nNonceRemote;
|
|
|
|
bool m_bReceivedRemoteNonce;
|
|
|
|
bool m_bInReliableState;
|
|
|
|
bool m_bPendingRemoteNonceAck;
|
|
|
|
uint32_t m_nSubOutSequenceNr;
|
|
|
|
int m_nLastRecvNonce;
|
|
|
|
bool m_bUseCompression;
|
|
|
|
uint32_t dword168;
|
|
|
|
float m_Timeout;
|
|
|
|
INetChannelHandler* m_MessageHandler;
|
2022-06-23 19:52:58 +02:00
|
|
|
CUtlVector<INetMessage*> m_NetMessages;
|
2022-04-02 02:48:54 +02:00
|
|
|
uint64_t qword198;
|
|
|
|
int m_nQueuedPackets;
|
|
|
|
float m_flRemoteFrameTime;
|
|
|
|
float m_flRemoteFrameTimeStdDeviation;
|
2023-02-15 17:35:47 +01:00
|
|
|
uint8_t m_nServerCPU;
|
2022-04-02 02:48:54 +02:00
|
|
|
int m_nMaxRoutablePayloadSize;
|
|
|
|
int m_nSplitPacketSequence;
|
|
|
|
int64_t m_StreamSendBuffer;
|
|
|
|
bf_write m_StreamSend;
|
|
|
|
uint8_t m_bInMatch_maybe;
|
|
|
|
netflow_t m_DataFlow[2];
|
|
|
|
int m_nLifetimePacketsDropped;
|
|
|
|
int m_nSessionPacketsDropped;
|
|
|
|
int m_nSequencesSkipped_MAYBE;
|
|
|
|
int m_nSessionRecvs;
|
|
|
|
uint32_t m_nLiftimeRecvs;
|
2022-08-11 11:07:45 +02:00
|
|
|
bool m_bPad;
|
2022-04-05 01:13:27 +02:00
|
|
|
char m_Name[NET_CHANNELNAME_MAXLEN];
|
2023-01-29 15:12:27 +01:00
|
|
|
netadr_t remote_address;
|
2021-12-25 22:36:38 +01:00
|
|
|
};
|
2022-04-02 04:11:44 +02:00
|
|
|
#if defined (GAMEDLL_S0) || defined (GAMEDLL_S1) || defined (GAMEDLL_S2)
|
|
|
|
static_assert(sizeof(CNetChan) == 0x1AD0);
|
|
|
|
#else
|
2022-04-02 02:48:54 +02:00
|
|
|
static_assert(sizeof(CNetChan) == 0x1AC8);
|
2022-04-02 04:11:44 +02:00
|
|
|
#endif
|
2022-04-02 02:48:54 +02:00
|
|
|
|
2022-05-21 18:56:56 +02:00
|
|
|
inline CMemory p_NetChan_Clear;
|
|
|
|
inline auto v_NetChan_Clear = p_NetChan_Clear.RCast<void (*)(CNetChan* pChannel, bool bStopProcessing)>();
|
2022-09-17 23:34:36 +02:00
|
|
|
|
|
|
|
inline CMemory p_NetChan_ProcessMessages;
|
|
|
|
inline auto v_NetChan_ProcessMessages = p_NetChan_ProcessMessages.RCast<bool (*)(CNetChan* pChan, bf_read* pMsg)>();
|
2022-05-21 18:56:56 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2023-02-18 00:05:55 +01:00
|
|
|
class VNetChan : public IDetour
|
2022-05-21 18:56:56 +02:00
|
|
|
{
|
|
|
|
virtual void GetAdr(void) const
|
|
|
|
{
|
2023-01-25 02:26:52 +01:00
|
|
|
LogFunAdr("CNetChan::Clear", p_NetChan_Clear.GetPtr());
|
|
|
|
LogFunAdr("CNetChan::ProcessMessages", p_NetChan_ProcessMessages.GetPtr());
|
2022-05-21 18:56:56 +02:00
|
|
|
}
|
|
|
|
virtual void GetFun(void) const
|
|
|
|
{
|
2022-12-01 22:44:55 +01:00
|
|
|
p_NetChan_Clear = g_GameDll.FindPatternSIMD("88 54 24 10 53 55 57");
|
2022-05-21 18:56:56 +02:00
|
|
|
v_NetChan_Clear = p_NetChan_Clear.RCast<void (*)(CNetChan*, bool)>(); /*88 54 24 10 53 55 57*/
|
2022-09-17 23:34:36 +02:00
|
|
|
|
2022-12-01 22:44:55 +01:00
|
|
|
p_NetChan_ProcessMessages = g_GameDll.FindPatternSIMD("48 89 5C 24 ?? 48 89 6C 24 ?? 57 48 81 EC ?? ?? ?? ?? 48 8B FA");
|
2022-09-17 23:34:36 +02:00
|
|
|
v_NetChan_ProcessMessages = p_NetChan_ProcessMessages.RCast<bool (*)(CNetChan* pChan, bf_read* pMsg)>();/*48 89 5C 24 ?? 48 89 6C 24 ?? 57 48 81 EC ?? ?? ?? ?? 48 8B FA*/
|
2022-05-21 18:56:56 +02:00
|
|
|
}
|
|
|
|
virtual void GetVar(void) const { }
|
|
|
|
virtual void GetCon(void) const { }
|
2023-01-25 02:26:52 +01:00
|
|
|
virtual void Attach(void) const;
|
|
|
|
virtual void Detach(void) const;
|
2022-05-21 18:56:56 +02:00
|
|
|
};
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2022-09-17 23:34:36 +02:00
|
|
|
|
2022-04-02 02:48:54 +02:00
|
|
|
#endif // NET_CHAN_H
|