More mapped out network interface classes

More interface classes directly usable with the engine.
This commit is contained in:
Kawe Mazidjatari 2022-08-15 14:44:54 +02:00
parent e6f45aaa9b
commit bb6a05cb81
15 changed files with 262 additions and 41 deletions

View File

@ -12,7 +12,7 @@
#include "engine/net.h"
#include "common/netmessages.h"
bool SVC_Print::Process()
bool SVC_Print::ProcessImpl()
{
if (this->m_szText)
{
@ -22,7 +22,7 @@ bool SVC_Print::Process()
return true; // Original just return true also.
}
bool SVC_UserMessage::Process()
bool SVC_UserMessage::ProcessImpl()
{
bf_read buf = m_DataIn;
int type = buf.ReadByte();
@ -43,8 +43,8 @@ bool SVC_UserMessage::Process()
void CNetMessages_Attach()
{
auto SVCPrint = &SVC_Print::Process;
auto SVCUserMessage = &SVC_UserMessage::Process;
auto SVCPrint = &SVC_Print::ProcessImpl;
auto SVCUserMessage = &SVC_UserMessage::ProcessImpl;
CMemory::HookVirtualMethod((uintptr_t)g_pSVC_Print_VTable, (LPVOID&)SVCPrint, 3, (LPVOID*)&SVC_Print_Process);
CMemory::HookVirtualMethod((uintptr_t)g_pSVC_UserMessage_VTable, (LPVOID&)SVCUserMessage, 3, (LPVOID*)&SVC_UserMessage_Process);
}

View File

@ -1,5 +1,13 @@
//====== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. =======//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#pragma once
#include "tier1/bitbuf.h"
#include "public/inetmessage.h"
#include "public/inetmsghandler.h"
#define HUD_PRINTNOTIFY 1
@ -7,23 +15,43 @@
#define HUD_PRINTTALK 3
#define HUD_PRINTCENTER 4
class INetMessage
{
void* __vftable /*VFT*/;
};
//-------------------------------------------------------------------------------------
// Forward declarations
//-------------------------------------------------------------------------------------
class CNetChan;
class CNetMessage : public INetMessage
{
public:
int m_nGroup;
bool m_bReliable;
void* m_NetChannel;
CNetChan* m_NetChannel;
};
///////////////////////////////////////////////////////////////////////////////////////
// server messages:
///////////////////////////////////////////////////////////////////////////////////////
class SVC_Print : public CNetMessage, IServerMessageHandler
{
public:
bool Process();
virtual ~SVC_Print() {};
virtual void SetNetChannel(INetChannel* netchan) = 0;
virtual void SetReliable(bool state) = 0;
virtual bool Process(void) = 0; bool ProcessImpl(void);
virtual bool ReadFromBuffer(bf_read& buffer) = 0;
virtual bool WriteToBuffer(bf_write& buffer) = 0;
virtual bool IsReliable(void) const = 0;
virtual int GetGroup(void) const = 0;
virtual int GetType(void) const = 0;
virtual const char* GetName(void) const = 0;
virtual INetChannel* GetNetChannel(void) const = 0;
virtual const char* ToString(void) const = 0;
virtual size_t GetSize(void) const = 0;
const void* m_pData;
const char* m_szText;
@ -34,7 +62,24 @@ private:
class SVC_UserMessage : public CNetMessage, IServerMessageHandler
{
public:
bool Process();
virtual ~SVC_UserMessage() {};
virtual void SetNetChannel(INetChannel* netchan) = 0;
virtual void SetReliable(bool state) = 0;
virtual bool Process(void) = 0; bool ProcessImpl(void);
virtual bool ReadFromBuffer(bf_read& buffer) = 0;
virtual bool WriteToBuffer(bf_write& buffer) = 0;
virtual bool IsReliable(void) const = 0;
virtual int GetGroup(void) const = 0;
virtual int GetType(void) const = 0;
virtual const char* GetName(void) const = 0;
virtual INetChannel* GetNetChannel(void) const = 0;
virtual const char* ToString(void) const = 0;
virtual size_t GetSize(void) const = 0;
int m_nMsgType;
int m_nLength; // data length in bits
@ -68,8 +113,8 @@ class HMM_Heartbeat : public IDetour
virtual void GetAdr(void) const
{
spdlog::debug("| FUN: MM_Heartbeat::ToString : {:#18x} |\n", MM_Heartbeat__ToString.GetPtr());
spdlog::debug("| VAR: SVC_Print_VTable : {:#18x} |\n", reinterpret_cast<uintptr_t>(g_pSVC_Print_VTable));
spdlog::debug("| VAR: SVC_UserMessage_VTable : {:#18x} |\n", reinterpret_cast<uintptr_t>(g_pSVC_UserMessage_VTable));
spdlog::debug("| CON: SVC_Print (VFTable) : {:#18x} |\n", reinterpret_cast<uintptr_t>(g_pSVC_Print_VTable));
spdlog::debug("| CON: SVC_UserMessage (VFTable) : {:#18x} |\n", reinterpret_cast<uintptr_t>(g_pSVC_UserMessage_VTable));
spdlog::debug("+----------------------------------------------------------------+\n");
}
virtual void GetFun(void) const
@ -77,13 +122,13 @@ class HMM_Heartbeat : public IDetour
MM_Heartbeat__ToString = g_GameDll.FindPatternSIMD(reinterpret_cast<rsig_t>("\x48\x83\xEC\x38\xE8\x00\x00\x00\x00\x3B\x05\x00\x00\x00\x00"), "xxxxx????xx????");
// 48 83 EC 38 E8 ? ? ? ? 3B 05 ? ? ? ?
}
virtual void GetVar(void) const
{
virtual void GetVar(void) const { }
virtual void GetCon(void) const
{
// We get the actual address of the vtable here, not the class instance.
g_pSVC_Print_VTable = g_GameDll.GetVirtualMethodTable(".?AVSVC_Print@@");
g_pSVC_UserMessage_VTable = g_GameDll.GetVirtualMethodTable(".?AVSVC_UserMessage@@");
}
virtual void GetCon(void) const { }
virtual void Attach(void) const { }
virtual void Detach(void) const { }
};

View File

@ -3,7 +3,9 @@
class IClientNetworkable
{
void* __vftable /*VFT*/;
public:
virtual ~IClientNetworkable(void) = 0;
// !TODO!
};
#endif // ICLIENTNETWORKABLE_H

View File

@ -30,21 +30,21 @@ public:
class CStdioFile : public CStdFilesystemFile
{
public:
/* // [ !!! IMPLEMENTED IN ENGINE !!! ]
// [ !!! IMPLEMENTED IN ENGINE !!! ]
static CStdioFile* FS_fopen(const char* filename, const char* options, int64* size);
virtual void FS_setbufsize(unsigned nBytes);
virtual void FS_fclose();
virtual void FS_fseek(int64 pos, int seekType);
virtual long FS_ftell();
virtual int FS_feof();
virtual size_t FS_fread(void* dest, size_t destSize, size_t size);
virtual size_t FS_fwrite(const void* src, size_t size);
virtual bool FS_setmode(FileMode_t mode);
virtual size_t FS_vfprintf(const char* fmt, va_list list);
virtual int FS_ferror();
virtual int FS_fflush();
virtual char* FS_fgets(char* dest, int destSize);*/
virtual void FS_setbufsize(unsigned nBytes) = 0;
virtual void FS_fclose() = 0;
virtual void FS_fseek(int64 pos, int seekType) = 0;
virtual long FS_ftell() = 0;
virtual int FS_feof() = 0;
virtual size_t FS_fread(void* dest, size_t destSize, size_t size) = 0;
virtual size_t FS_fwrite(const void* src, size_t size) = 0;
virtual bool FS_setmode(FileMode_t mode) = 0;
virtual size_t FS_vfprintf(const char* fmt, va_list list) = 0;
virtual int FS_ferror() = 0;
virtual int FS_fflush() = 0;
virtual char* FS_fgets(char* dest, int destSize) = 0;
#ifdef POSIX
static CUtlMap< ino_t, CThreadMutex* > m_LockedFDMap;

View File

@ -6,14 +6,48 @@
#define FLOW_INCOMING 1
#define MAX_FLOWS 2 // in & out
struct IClientMessageHandler
class IClientMessageHandler
{
void* __vftable /*VFT*/;
public:
virtual void* Destructor(void) = 0;
virtual void* ProcessStringCmd(void) = 0;
virtual void* ProcessScriptMessage(void) = 0;
virtual void* ProcessSetConVar(void) = 0;
virtual char ProcessSignonState(void* msg) = 0; // NET_SignonState
virtual bool nullsub_0(void) = 0;
virtual bool nullsub_1(void) = 0;
virtual void* ProcessClientInfo(void) = 0;;
virtual void* ProcessMove(void) = 0;;
virtual void* ProcessVoiceData(void) = 0;;
virtual void* ProcessDurangoVoiceData(void) = 0;;
virtual bool nullsub_2(void) = 0;
virtual void* ProcessLoadingProgress(void) = 0;
virtual void* ProcessPersistenceRequestSave(void) = 0;
virtual bool nullsub_3(void) = 0;
virtual bool nullsub_4(void) = 0;
virtual void* ProcessSetPlaylistVarOverride(void) = 0;
virtual void* ProcessClaimClientSidePickup(void) = 0;
virtual void* ProcessCmdKeyValues(void) = 0;
virtual void* ProcessClientTick(void) = 0;
virtual void* ProcessClientSayText(void) = 0;
virtual bool nullsub_5(void) = 0;
virtual bool nullsub_6(void) = 0;
virtual bool nullsub_7(void) = 0;
virtual bool nullsub_8(void) = 0;
virtual void* ProcessScriptMessageChecksum(void) = 0;
};
struct INetChannelHandler
class INetChannelHandler
{
void* __vftable /*VFT*/;
public:
virtual ~INetChannelHandler(void) = 0;
virtual void*ConnectionStart(INetChannel* chan) = 0;
virtual void ConnectionClosing(const char* reason, int unk) = 0;
virtual void ConnectionCrashed(const char* reason) = 0;
virtual void PacketStart(int incoming_sequence, int outgoing_acknowledged) = 0;
virtual void PacketEnd(void) = 0;
virtual void FileRequested(const char* fileName, unsigned int transferID) = 0;
virtual void ChannelDisconnect(const char* fileName) = 0;
};
struct CS_INetChannelHandler : INetChannelHandler

View File

@ -0,0 +1,48 @@
//====== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. =======//
//
// Purpose: INetMessage interface
//
// $NoKeywords: $
//=============================================================================//
#ifndef INETMESSAGE_H
#define INETMESSAGE_H
#include "tier1/bitbuf.h"
class INetMsgHandler;
class INetMessage;
class INetChannel;
// typedef bool (INetMsgHandler::*PROCESSFUNCPTR)(INetMessage*);
// #define CASTPROCPTR( fn ) static_cast <bool (INetMsgHandler::*)(INetMessage*)> (fn)
class INetMessage
{
public:
virtual ~INetMessage() {};
// Use these to setup who can hear whose voice.
// Pass in client indices (which are their ent indices - 1).
virtual void SetNetChannel(INetChannel * netchan) = 0; // netchannel this message is from/for
virtual void SetReliable( bool state ) = 0; // set to true if it's a reliable message
virtual bool Process( void ) = 0; // calles the recently set handler to process this message
virtual bool ReadFromBuffer( bf_read &buffer ) = 0; // returns true if parsing was OK
virtual bool WriteToBuffer( bf_write &buffer ) = 0; // returns true if writing was OK
virtual bool IsReliable( void ) const = 0; // true, if message needs reliable handling
virtual int GetGroup( void ) const = 0; // returns net message group of this message
virtual int GetType( void ) const = 0; // returns module specific header tag eg svc_serverinfo
virtual const char *GetName( void ) const = 0; // returns network message name, eg "svc_serverinfo"
virtual INetChannel *GetNetChannel( void ) const = 0;
virtual const char *ToString( void ) const = 0; // returns a human readable string about message content
virtual size_t GetSize( void ) const = 0; // returns net message size of this message
};
#endif // INETMESSAGE_H

View File

@ -13,17 +13,72 @@
#if !defined( INETMSGHANDLER_H )
#define INETMSGHANDLER_H
struct IConnectionlessPacketHandler
abstract_class IConnectionlessPacketHandler
{
void* __vftable /*VFT*/;
public:
virtual ~IConnectionlessPacketHandler(void) = 0;
virtual bool ProcessConnectionlessPacket(void* packet) = 0;
};
struct INetMessageHandler
abstract_class INetMessageHandler
{
void* __vftable /*VFT*/;
public:
virtual ~INetMessageHandler(void) = 0;
virtual void ProcessStringCmd(void* msg) = 0;
//virtual void ProcessScriptMessage(void* msg) = 0; // NET_ScriptMessage
virtual void ProcessSetConVar(void* msg) = 0;
virtual void ProcessSignonState(void* msg) = 0;
virtual void ProcessMTXUserMsg(void* msg) = 0;
//virtual void ProcessAutoPlayerMsg(void* msg) = 0;
};
struct IServerMessageHandler : INetMessageHandler
{};
abstract_class IServerMessageHandler : public INetMessageHandler // !TODO: PROCESS_SVC_MESSAGE macro.
{
public:
virtual ~IServerMessageHandler(void) = 0;
virtual void ProcessStringCmd(void* msg) = 0;
//virtual void ProcessScriptMessage(void* msg) = 0;
virtual void ProcessSetConVar(void* msg) = 0;
virtual void ProcessSignonState(void* msg) = 0;
virtual void ProcessMTXUserMsg(void* msg) = 0;
//virtual void ProcessAutoPlayerMsg(void* msg) = 0;
virtual bool ProcessPrint(void* msg) = 0;
virtual bool ProcessServerInfo(void* msg) = 0;
virtual bool ProcessSendTable(void* msg) = 0;
virtual bool ProcessClassInfo(void* msg) = 0;
virtual bool ProcessSetPause(void* msg) = 0;
virtual bool ProcessPlaylists(void* msg) = 0;
virtual bool ProcessCreateStringTable(void* msg) = 0;
virtual bool ProcessUpdateStringTable(void* msg) = 0;
virtual bool ProcessVoiceData(void* msg) = 0;
virtual bool ProcessDurangoVoiceData(void* msg) = 0;
virtual bool ProcessSounds(void* msg) = 0;
virtual bool ProcessFixAngle(void* msg) = 0;
virtual bool ProcessCrosshairAngle(void* msg) = 0;
virtual bool ProcessGrantClientSidePickup(void* msg) = 0;
virtual bool ProcessUserMessage(void* msg) = 0;
virtual bool ProcessSnapshot(void* msg) = 0;
virtual bool ProcessTempEntities(void* msg) = 0;
virtual bool ProcessMenu(void* msg) = 0;
virtual bool ProcessCmdKeyValues(void* msg) = 0;
virtual bool ProcessServerTick(void* msg) = 0;
virtual bool ProcessUseCachedPersistenceDefFile(void* msg) = 0;
virtual bool ProcessPersistenceDefFile(void* msg) = 0;
virtual bool ProcessPersistenceBaseline(void* msg) = 0;
virtual bool ProcessPersistenceUpdateVar(void* msg) = 0;
virtual bool ProcessPersistenceNotifySaved(void* msg) = 0;
virtual bool ProcessDLCNotifyOwnership(void* msg) = 0;
virtual bool ProcessMatchmakingETAs(void* msg) = 0;
virtual bool ProcessMatchmakingStatus(void* msg) = 0;
virtual bool ProcessMTX_ReadUserInfo(void* msg) = 0;
virtual bool ProcessPlaylistChange(void* msg) = 0;
virtual bool ProcessSetTeam(void* msg) = 0;
virtual bool ProcessPlaylistOverrides(void* msg) = 0;
virtual bool ProcessAntiCheat(void* msg) = 0;
virtual bool ProcessAntiCheatChallenge(void* msg) = 0;
virtual bool ProcessDatatableChecksum(void* msg) = 0;
//virtual bool ProcessDeathRecap(void* msg) = 0;
};
#endif // INETMSGHANDLER_H

View File

@ -1,9 +1,12 @@
#ifndef ISERVER_H
#define ISERVER_H
#include "inetchannel.h"
class IServer
{
IServer* m_pVTable;
public:
virtual ~IServer(void) = 0;
virtual bool ConnectionlessPacketHandler(netpacket_t* pInPacket) = 0;
};
#endif // ISERVER_H

View File

@ -0,0 +1,10 @@
#ifndef ISNAPSHOTMGR_H
#define ISNAPSHOTMGR_H
abstract_class IClientSnapshotManager
{
public:
virtual ~IClientSnapshotManager(void) = 0;
};
#endif // ISNAPSHOTMGR_H

View File

@ -258,7 +258,9 @@
<ClInclude Include="..\public\ifilesystem.h" />
<ClInclude Include="..\public\ihandleentity.h" />
<ClInclude Include="..\public\inetchannel.h" />
<ClInclude Include="..\public\inetmessage.h" />
<ClInclude Include="..\public\inetmsghandler.h" />
<ClInclude Include="..\public\isnapshotmgr.h" />
<ClInclude Include="..\public\isurfacesystem.h" />
<ClInclude Include="..\public\ivrenderview.h" />
<ClInclude Include="..\public\ivscript.h" />

View File

@ -1721,6 +1721,12 @@
<ClInclude Include="..\public\isurfacesystem.h">
<Filter>sdk\public</Filter>
</ClInclude>
<ClInclude Include="..\public\inetmessage.h">
<Filter>sdk\public</Filter>
</ClInclude>
<ClInclude Include="..\public\isnapshotmgr.h">
<Filter>sdk\public</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Image Include="..\shared\resource\lockedserver.png">

View File

@ -224,8 +224,10 @@
<ClInclude Include="..\public\ifile.h" />
<ClInclude Include="..\public\ifilesystem.h" />
<ClInclude Include="..\public\inetchannel.h" />
<ClInclude Include="..\public\inetmessage.h" />
<ClInclude Include="..\public\inetmsghandler.h" />
<ClInclude Include="..\public\iserver.h" />
<ClInclude Include="..\public\isnapshotmgr.h" />
<ClInclude Include="..\public\ivscript.h" />
<ClInclude Include="..\public\model_types.h" />
<ClInclude Include="..\public\studio.h" />

View File

@ -1230,6 +1230,12 @@
<ClInclude Include="..\vstdlib\concommandhash.h">
<Filter>sdk\vstdlib</Filter>
</ClInclude>
<ClInclude Include="..\public\inetmessage.h">
<Filter>sdk\public</Filter>
</ClInclude>
<ClInclude Include="..\public\isnapshotmgr.h">
<Filter>sdk\public</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\common\opcodes.cpp">

View File

@ -283,8 +283,10 @@
<ClInclude Include="..\public\ifilesystem.h" />
<ClInclude Include="..\public\ihandleentity.h" />
<ClInclude Include="..\public\inetchannel.h" />
<ClInclude Include="..\public\inetmessage.h" />
<ClInclude Include="..\public\inetmsghandler.h" />
<ClInclude Include="..\public\iserver.h" />
<ClInclude Include="..\public\isnapshotmgr.h" />
<ClInclude Include="..\public\isurfacesystem.h" />
<ClInclude Include="..\public\ivrenderview.h" />
<ClInclude Include="..\public\ivscript.h" />

View File

@ -1808,6 +1808,12 @@
<ClInclude Include="..\networksystem\listmanager.h">
<Filter>sdk\networksystem</Filter>
</ClInclude>
<ClInclude Include="..\public\inetmessage.h">
<Filter>sdk\public</Filter>
</ClInclude>
<ClInclude Include="..\public\isnapshotmgr.h">
<Filter>sdk\public</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Image Include="..\shared\resource\lockedserver.png">