diff --git a/public/engine/igameeventsystem.h b/public/engine/igameeventsystem.h index 339a5959..8af29401 100644 --- a/public/engine/igameeventsystem.h +++ b/public/engine/igameeventsystem.h @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -21,26 +22,26 @@ class CUtlSlot; abstract_class IGameEventSystem : public IAppSystem { public: - virtual void RegisterGameEvent( INetworkSerializable *pEvent ) = 0; + virtual void RegisterGameEvent( INetworkMessageInternal *pEvent ) = 0; - virtual void RegisterGameEventHandlerAbstract( CUtlSlot *nSlot, const CUtlAbstractDelegate &delegate, INetworkSerializable *pEvent, int nPriority ) = 0; - virtual void UnregisterGameEventHandlerAbstract( CUtlSlot *nSlot, const CUtlAbstractDelegate &delegate, INetworkSerializable *pEvent ) = 0; + virtual void RegisterGameEventHandlerAbstract( CUtlSlot *nSlot, const CUtlAbstractDelegate &delegate, INetworkMessageInternal *pEvent, int nPriority ) = 0; + virtual void UnregisterGameEventHandlerAbstract( CUtlSlot *nSlot, const CUtlAbstractDelegate &delegate, INetworkMessageInternal *pEvent ) = 0; // Providing nSize has no effect and is unused. - virtual void PostEventAbstract_Local( CSplitScreenSlot nSlot, INetworkSerializable *pEvent, const void *pData, unsigned long nSize ) = 0; + virtual void PostEventAbstract_Local( CSplitScreenSlot nSlot, INetworkMessageInternal *pEvent, const CNetMessage *pData, unsigned long nSize ) = 0; // Providing nSlot as -1 would select 0nth slot. // clients pointer is a masked uint64 value where (client index - 1) is mapped to each bit. // Providing nClientCount as -1 and clients pointer as NULL would post event to all available clients. // Providing nSize has no effect and is unused. virtual void PostEventAbstract( CSplitScreenSlot nSlot, bool bLocalOnly, int nClientCount, const uint64 *clients, - INetworkSerializable *pEvent, const void *pData, unsigned long nSize, NetChannelBufType_t bufType ) = 0; + INetworkMessageInternal *pEvent, const CNetMessage *pData, unsigned long nSize, NetChannelBufType_t bufType ) = 0; virtual void PostEventAbstract( CSplitScreenSlot nSlot, bool bLocalOnly, IRecipientFilter *pFilter, - INetworkSerializable *pEvent, const void *pData, unsigned long nSize ) = 0; + INetworkMessageInternal *pEvent, const CNetMessage *pData, unsigned long nSize ) = 0; // Posts the event to all clients, even tho the function name tells otherwise // Providing nSize has no effect and is unused. - virtual void PostEntityEventAbstract( const CBaseHandle &hndl, INetworkSerializable *pEvent, const void *pData, unsigned long nSize, NetChannelBufType_t bufType ) = 0; + virtual void PostEntityEventAbstract( const CBaseHandle &hndl, INetworkMessageInternal *pEvent, const CNetMessage *pData, unsigned long nSize, NetChannelBufType_t bufType ) = 0; virtual void ProcessQueuedEvents() = 0; virtual CEntityIndex GetEventSource() const = 0; diff --git a/public/inetchannel.h b/public/inetchannel.h index 1f321a66..a5f52cee 100644 --- a/public/inetchannel.h +++ b/public/inetchannel.h @@ -20,13 +20,13 @@ class IDemoRecorderBase; class IInstantReplayIntercept; -class INetMessage; +class CNetMessage; class INetChannelHandler; class INetChannel; class INetChannelInfo; class INetMessageBinder; class INetworkMessageProcessingPreFilter; -class INetworkSerializable; +class INetworkMessageInternal; class INetMessageDispatcher; class InstantReplayMessage_t; class CUtlSlot; @@ -59,7 +59,7 @@ abstract_class INetworkMessageProcessingPreFilter { public: // Filter incoming messages from the netchan, return true to filter out (block) the further processing of the message - virtual bool FilterMessage( INetworkSerializable *pNetMessage, const void *pData, INetChannel *pChannel ) = 0; + virtual bool FilterMessage( INetworkMessageInternal *pNetMessage, const CNetMessage *pData, INetChannel *pChannel ) = 0; }; abstract_class INetChannel : public INetChannelInfo @@ -73,7 +73,7 @@ public: virtual HSteamNetConnection GetSteamNetConnection( void ) const = 0; - virtual bool SendNetMessage( INetworkSerializable *pNetMessage, const void *pData, NetChannelBufType_t bufType ) = 0; + virtual bool SendNetMessage( INetworkMessageInternal *pNetMessage, const CNetMessage *pData, NetChannelBufType_t bufType ) = 0; virtual bool SendData( bf_write &msg, NetChannelBufType_t bufferType ) = 0; virtual int Transmit( const char *pDebugName, bf_write *data ) = 0; virtual void SetBitsToSend( void ) = 0; @@ -112,8 +112,8 @@ public: virtual void StartRegisteringMessageHandlers( void ) = 0; virtual void FinishRegisteringMessageHandlers( void ) = 0; - virtual void RegisterNetMessageHandlerAbstract( CUtlSlot *nSlot, const CUtlAbstractDelegate &delegate, int nParamCount, INetworkSerializable *pNetMessage, int nPriority ) = 0; - virtual void UnregisterNetMessageHandlerAbstract( CUtlSlot *nSlot, const CUtlAbstractDelegate &delegate, INetworkSerializable *pNetMessage ) = 0; + virtual void RegisterNetMessageHandlerAbstract( CUtlSlot *nSlot, const CUtlAbstractDelegate &delegate, int nParamCount, INetworkMessageInternal *pNetMessage, int nPriority ) = 0; + virtual void UnregisterNetMessageHandlerAbstract( CUtlSlot *nSlot, const CUtlAbstractDelegate &delegate, INetworkMessageInternal *pNetMessage ) = 0; virtual void SetChallengeNr( unsigned int challenge ) = 0; virtual int GetNumBitsWritten( NetChannelBufType_t bufferType ) const = 0; @@ -126,7 +126,7 @@ public: virtual void InstallMessageFilter( INetworkMessageProcessingPreFilter *pFilter ) = 0; virtual void UninstallMessageFilter( INetworkMessageProcessingPreFilter *pFilter ) = 0; - virtual void PostReceivedNetMessage( INetworkSerializable *pNetMessage, const void *pData, const NetChannelBufType_t *pBufType, int nBits, int nInSequenceNr ) = 0; + virtual void PostReceivedNetMessage( INetworkMessageInternal *pNetMessage, const CNetMessage *pData, const NetChannelBufType_t *pBufType, int nBits, int nInSequenceNr ) = 0; virtual void InsertReplayMessage( InstantReplayMessage_t &msg ) = 0; virtual bool HasQueuedNetMessages( int nMessageId ) const = 0; diff --git a/public/inetmessage.h b/public/inetmessage.h deleted file mode 100644 index eceb8734..00000000 --- a/public/inetmessage.h +++ /dev/null @@ -1,48 +0,0 @@ -//========= Copyright © 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 (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; // calls 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 GetType( void ) const = 0; // returns module specific header tag eg svc_serverinfo - virtual int GetGroup( void ) const = 0; // returns net message group of this message - 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() const = 0; -}; - - -#endif - diff --git a/public/networksystem/inetworkmessages.h b/public/networksystem/inetworkmessages.h index 3ff8a817..f6e94d38 100644 --- a/public/networksystem/inetworkmessages.h +++ b/public/networksystem/inetworkmessages.h @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -60,31 +61,36 @@ abstract_class INetworkMessages public: virtual void RegisterNetworkCategory(NetworkCategoryId nCategoryId, char const *szDebugName) = 0; - virtual void AssociateNetMessageWithChannelCategoryAbstract(INetworkSerializable *pNetMessage, NetworkCategoryId nCategoryId, bool) = 0; + virtual void AssociateNetMessageWithChannelCategoryAbstract(INetworkMessageInternal *pNetMessage, NetworkCategoryId nCategoryId, bool) = 0; // Passing nMessasgeId as -1 would auto-assign the id even if bAutoAssignId is false based on the message name hash. - virtual INetworkSerializable *FindOrCreateNetMessage(int nMessageId, IProtobufBinding const *pProtoBinding, uint nMessageSize, INetworkSerializerBindingBuildFilter *pUnused, bool bCreateIfNotFound = true, bool bAutoAssignId = false) = 0; + virtual INetworkMessageInternal *FindOrCreateNetMessage(int nMessageId, IProtobufBinding const *pProtoBinding, uint nMessageSize, INetworkSerializerBindingBuildFilter *pUnused, bool bCreateIfNotFound = true, bool bAutoAssignId = false) = 0; - virtual bool SerializeAbstract(bf_write &pBuf, INetworkSerializable *pNetMessage, void const *pData) = 0; + virtual bool Serialize(bf_write &pBuf, const CNetMessage *pData) = 0; + + virtual bool UnserializeMessageInternal( bf_read &pBuf, CNetMessage *pData ) = 0; + virtual bool SerializeMessageInternal( bf_write &pBuf, const CNetMessage *pData ) = 0; + + virtual bool SerializeAbstract(bf_write &pBuf, INetworkMessageInternal *pNetMessage, const CNetMessage *pData) = 0; // Returns true if the buffer is fully read, false if there's still data left - virtual bool UnserializeAbstract(bf_read &pBuf, INetworkSerializable *pNetMessage, void *pData) = 0; - virtual bool UnserializeAbstract(bf_read &pBuf, INetworkSerializable **pNetMessage, void **pData) = 0; + virtual bool UnserializeAbstract(bf_read &pBuf, INetworkMessageInternal *pNetMessage, CNetMessage *pData) = 0; + virtual bool UnserializeAbstract(bf_read &pBuf, INetworkMessageInternal **pNetMessage, CNetMessage **pData) = 0; - virtual void *AllocateNetMessageAbstract(INetworkSerializable *pNetMessage) = 0; - virtual void *AllocateAndCopyConstructNetMessageAbstract(INetworkSerializable *pNetMessage, void const *pFrom) = 0; + virtual CNetMessage *AllocateNetMessageAbstract(INetworkMessageInternal *pNetMessage) = 0; + virtual CNetMessage *AllocateAndCopyConstructNetMessageAbstract(INetworkMessageInternal *pNetMessage, const CNetMessage *pFrom) = 0; - virtual void DeallocateNetMessageAbstract(INetworkSerializable *pNetMessage, void *pData) = 0; + virtual void DeallocateNetMessageAbstract(INetworkMessageInternal *pNetMessage, CNetMessage *pData) = 0; virtual void *RegisterNetworkFieldSerializer(char const *, NetworkSerializationMode_t, NetworkableDataType_t, int, NetworkFieldSerializeCB, NetworkFieldUnserializeCB, NetworkFieldInfoCB, NetworkFieldMetaInfoCB, NetworkableDataCB, NetworkUnkCB001, NetworkFieldSerializeCB, NetworkFieldUnserializeCB) = 0; virtual void *RegisterNetworkArrayFieldSerializer(char const *, NetworkSerializationMode_t, NetworkFieldSerializeBufferCB, NetworkFieldUnserializeBufferCB, NetworkFieldInfoCB, NetworkFieldMetaInfoCB, NetworkFieldSerializeBufferCB, NetworkFieldUnserializeBufferCB) = 0; - virtual NetMessageInfo_t *GetNetMessageInfo(INetworkSerializable *pNetMessage) = 0; + virtual NetMessageInfo_t *GetNetMessageInfo(INetworkMessageInternal *pNetMessage) = 0; - virtual INetworkSerializable* FindNetworkMessage(char const *szName) = 0; - virtual INetworkSerializable* FindNetworkMessagePartial(char const *szPartialName) = 0; + virtual INetworkMessageInternal* FindNetworkMessage(char const *szName) = 0; + virtual INetworkMessageInternal* FindNetworkMessagePartial(char const *szPartialName) = 0; virtual NetworkGroupId FindNetworkGroup(char const *szGroup, bool bCreateIfNotFound = false) = 0; virtual int GetNetworkGroupCount() = 0; @@ -98,7 +104,8 @@ public: virtual void SetNetworkSerializationContextData(char const *szContext, NetworkSerializationMode_t, void *) = 0; virtual void *GetNetworkSerializationContextData(char const *szContext) = 0; - virtual void unk001() = 0; + virtual void unk101() = 0; + virtual void unk102() = 0; // Doesn't support duplicated callbacks per field virtual void RegisterNetworkFieldChangeCallbackInternal(char const *szFieldName, uint64, NetworkFieldChangedDelegateType_t fieldType, CUtlAbstractDelegate pCallback, NetworkFieldChangeCallbackPerformType_t cbPerformType, int unkflag ) = 0; @@ -111,7 +118,7 @@ public: virtual void RegisterFieldChangeCallbackPriority(int nPriority) = 0; - virtual INetworkSerializable *FindNetworkMessageById(int nMessageId) = 0; + virtual INetworkMessageInternal *FindNetworkMessageById(int nMessageId) = 0; virtual void SetIsForServer(bool bIsForServer) = 0; virtual bool GetIsForServer() = 0; diff --git a/public/networksystem/inetworkserializer.h b/public/networksystem/inetworkserializer.h index 037a7b2f..c8ee8675 100644 --- a/public/networksystem/inetworkserializer.h +++ b/public/networksystem/inetworkserializer.h @@ -12,6 +12,8 @@ #include #include "Color.h" +class CNetMessage; + enum NetworkValidationMode_t { @@ -49,26 +51,28 @@ struct NetMessageInfo_t bool m_bOkayToRedispatch; }; -abstract_class INetworkSerializable +abstract_class INetworkMessageInternal { public: - virtual ~INetworkSerializable() = 0; + virtual ~INetworkMessageInternal() = 0; virtual const char *GetUnscopedName() = 0; virtual NetMessageInfo_t *GetNetMessageInfo() = 0; - virtual void SetMessageId(unsigned short nMessageId) = 0; + virtual void SetMessageId( unsigned short nMessageId ) = 0; - virtual void AddCategoryMask(int nMask, bool) = 0; + virtual void AddCategoryMask( int nMask, bool ) = 0; - virtual void SwitchMode(NetworkValidationMode_t nMode) = 0; + virtual void SwitchMode( NetworkValidationMode_t nMode ) = 0; - virtual void *AllocateMessage() = 0; - virtual void DeallocateMessage(void *pMsg) = 0; - virtual void *AllocateAndCopyConstructNetMessage(void const *pOther) = 0; + virtual CNetMessage *AllocateMessage() = 0; + virtual void DeallocateMessage( CNetMessage *pMsg ) = 0; + virtual CNetMessage *AllocateAndCopyConstructNetMessage( const CNetMessage *pOther ) = 0; - virtual bool Serialize(bf_write &pBuf, void const *pData, NetworkSerializationMode_t unused) = 0; - virtual bool Unserialize(bf_read &pBuf, void *pData, NetworkSerializationMode_t unused) = 0; + // Calls to INetworkMessages::SerializeMessageInternal + virtual bool Serialize( bf_write &pBuf, const CNetMessage *pData ) = 0; + // Calls to INetworkMessages::UnserializeMessageInternal + virtual bool Unserialize( bf_read &pBuf, CNetMessage *pData ) = 0; }; #endif /* NETWORKSERIALIZER_H */ \ No newline at end of file diff --git a/public/networksystem/netmessage.h b/public/networksystem/netmessage.h new file mode 100644 index 00000000..69f31aeb --- /dev/null +++ b/public/networksystem/netmessage.h @@ -0,0 +1,65 @@ +#ifndef NETMESSAGE_H +#define NETMESSAGE_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "networksystem/inetworkserializer.h" + +template +class CNetMessagePB; + +class CNetMessage +{ +public: + virtual ~CNetMessage() {} + + // Returns the underlying proto object + virtual void *AsProto() const = 0; + virtual void *AsProto2() const = 0; + + virtual INetworkMessageInternal *GetNetMessage() const + { + // This shouldn't ever be called and the game provided vtable should be called instead! + Assert(0); + return nullptr; + } + + // Helper function to cast up the abstract message to a concrete CNetMessagePB type. + // Doesn't do any validity checks itself! + template + const CNetMessagePB *ToPB() const + { + return static_cast *>(this); + } + + template + CNetMessagePB *ToPB() + { + return static_cast *>(this); + } +}; + +// AMNOTE: This is a stub class over real CNetMessagePB! +// This is mainly to access the game constructed objects, and not for direct initialization of them +// since this misses the CNetMessage implementation which requires supplying other proto related info like +// proto binding object, proto msg id/group, etc. +// So to allocate the message yourself use INetworkMessageInternal::AllocateMessage() or INetworkMessages::AllocateNetMessageAbstract() +// functions instead of direct initialization (they both are equivalent)! +// Example usage: +// CNetMessagePB *msg = INetworkMessageInternal::AllocateMessage()->ToPB(); +// msg->field1( 2 ); +// msg->field2( 3 ); +// IGameEventSystem::PostEventAbstract( ..., msg, ... ); +template +class CNetMessagePB : public CNetMessage, public PROTO_TYPE +{ +private: + // Prevent manual construction of this object as per the comment above + CNetMessagePB() { }; + CNetMessagePB( const CNetMessagePB & ) { }; +}; + +#endif // NETMESSAGE_H +