Interface for manipulating and sending Source2 network (protobuf) messages.
Provides functionality for:
Allocating and deallocating network messages by ID or partial name
Reading and writing protobuf fields via reflection (scalar, repeated, nested)
Sending messages to individual players or a set of players
Hooking outgoing server/client network messages
Interface for working with Source2 network messages.
All field access is done via protobuf reflection using field names. The @p msg pointer is an opaque handle to an allocated protobuf message; always deallocate with DeallocateNetMessage() when done.
Interface id ISource2ModNetworkMessages002 (SOURCE2MOD_NETWORKMESSAGES_INTERFACE) · Global g_pSource2ModNetworkMessages · Header source2mod/ISource2ModNetworkMessages.h
using Source2ModNetMessageHookId = Source2ModHookId ;
A net message hook (HookServerMessage / HookClientMessage / HookServerInternalMessage).
using NetMessageServerHook = Source2ModCallback < Action ( uint64_t* clients , int messageid , void* msg )>;
Hook called when the server sends a message to a set of clients.
using NetMessageClientHook = Source2ModCallback < Action ( CPlayerSlot slot , int messageid , void* msg )>;
Hook called when a client sends a message to the server, or for internal server sends.
virtual void* AllocateNetMessageByID ( int msgid ) = 0 ;
Allocates a network message by its numeric ID.
Parameter Type Description msgidintMessage ID.
Returns void* — Opaque message pointer, or nullptr on failure.
virtual void* AllocateNetMessageByPartialName ( const char* name ) = 0 ;
Allocates a network message by a partial name match.
Parameter Type Description nameconst char*Partial name string (e.g. "CSVCMsg_UserMessage").
Returns void* — Opaque message pointer, or nullptr on failure.
virtual void DeallocateNetMessage ( void* msg ) = 0 ;
Deallocates a previously allocated network message.
Parameter Type Description msgvoid*Message pointer returned by Allocate*.
virtual bool HasField ( void* msg , const char* fieldName ) = 0 ;
Returns true if a singular field is set on the message.
Parameter Type msgvoid*fieldNameconst char*
virtual int GetInt32 ( void* msg , const char* fieldName ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*
virtual int GetRepeatedInt32 ( void* msg , const char* fieldName , int index ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*indexint
virtual void SetInt32 ( void* msg , const char* fieldName , int value ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*valueint
virtual void SetRepeatedInt32 ( void* msg , const char* fieldName , int index , int value ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*indexintvalueint
virtual void AddInt32 ( void* msg , const char* fieldName , int value ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*valueint
virtual int64_t GetInt64 ( void* msg , const char* fieldName ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*
virtual int64_t GetRepeatedInt64 ( void* msg , const char* fieldName , int index ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*indexint
virtual void SetInt64 ( void* msg , const char* fieldName , int64_t value ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*valueint64_t
virtual void SetRepeatedInt64 ( void* msg , const char* fieldName , int index , int64_t value ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*indexintvalueint64_t
virtual void AddInt64 ( void* msg , const char* fieldName , int64_t value ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*valueint64_t
virtual uint32_t GetUInt32 ( void* msg , const char* fieldName ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*
virtual uint32_t GetRepeatedUInt32 ( void* msg , const char* fieldName , int index ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*indexint
virtual void SetUInt32 ( void* msg , const char* fieldName , uint32_t value ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*valueuint32_t
virtual void SetRepeatedUInt32 ( void* msg , const char* fieldName , int index , uint32_t value ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*indexintvalueuint32_t
virtual void AddUInt32 ( void* msg , const char* fieldName , uint32_t value ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*valueuint32_t
virtual uint64_t GetUInt64 ( void* msg , const char* fieldName ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*
virtual uint64_t GetRepeatedUInt64 ( void* msg , const char* fieldName , int index ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*indexint
virtual void SetUInt64 ( void* msg , const char* fieldName , uint64_t value ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*valueuint64_t
virtual void SetRepeatedUInt64 ( void* msg , const char* fieldName , int index , uint64_t value ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*indexintvalueuint64_t
virtual void AddUInt64 ( void* msg , const char* fieldName , uint64_t value ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*valueuint64_t
virtual bool GetBool ( void* msg , const char* fieldName ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*
virtual bool GetRepeatedBool ( void* msg , const char* fieldName , int index ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*indexint
virtual void SetBool ( void* msg , const char* fieldName , bool value ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*valuebool
virtual void SetRepeatedBool ( void* msg , const char* fieldName , int index , bool value ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*indexintvaluebool
virtual void AddBool ( void* msg , const char* fieldName , bool value ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*valuebool
virtual float GetFloat ( void* msg , const char* fieldName ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*
virtual float GetRepeatedFloat ( void* msg , const char* fieldName , int index ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*indexint
virtual void SetFloat ( void* msg , const char* fieldName , float value ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*valuefloat
virtual void SetRepeatedFloat ( void* msg , const char* fieldName , int index , float value ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*indexintvaluefloat
virtual void AddFloat ( void* msg , const char* fieldName , float value ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*valuefloat
virtual double GetDouble ( void* msg , const char* fieldName ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*
virtual double GetRepeatedDouble ( void* msg , const char* fieldName , int index ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*indexint
virtual void SetDouble ( void* msg , const char* fieldName , double value ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*valuedouble
virtual void SetRepeatedDouble ( void* msg , const char* fieldName , int index , double value ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*indexintvaluedouble
virtual void AddDouble ( void* msg , const char* fieldName , double value ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*valuedouble
virtual std :: string GetString ( void* msg , const char* fieldName ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*
virtual std :: string GetRepeatedString ( void* msg , const char* fieldName , int index ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*indexint
virtual void SetString ( void* msg , const char* fieldName , const char* value ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*valueconst char*
virtual void SetRepeatedString ( void* msg , const char* fieldName , int index , const char* value ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*indexintvalueconst char*
virtual void AddString ( void* msg , const char* fieldName , const char* value ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*valueconst char*
virtual Vector2D GetVector2D ( void* msg , const char* fieldName ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*
virtual Vector2D GetRepeatedVector2D ( void* msg , const char* fieldName , int index ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*indexint
virtual void SetVector2D ( void* msg , const char* fieldName , Vector2D value ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*valueVector2D
virtual void SetRepeatedVector2D ( void* msg , const char* fieldName , int index , Vector2D value ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*indexintvalueVector2D
virtual void AddVector2D ( void* msg , const char* fieldName , Vector2D value ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*valueVector2D
virtual Vector GetVector ( void* msg , const char* fieldName ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*
virtual Vector GetRepeatedVector ( void* msg , const char* fieldName , int index ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*indexint
virtual void SetVector ( void* msg , const char* fieldName , Vector value ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*valueVector
virtual void SetRepeatedVector ( void* msg , const char* fieldName , int index , Vector value ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*indexintvalueVector
virtual void AddVector ( void* msg , const char* fieldName , Vector value ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*valueVector
virtual Color GetColor ( void* msg , const char* fieldName ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*
virtual Color GetRepeatedColor ( void* msg , const char* fieldName , int index ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*indexint
virtual void SetColor ( void* msg , const char* fieldName , Color value ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*valueColor
virtual void SetRepeatedColor ( void* msg , const char* fieldName , int index , Color value ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*indexintvalueColor
virtual void AddColor ( void* msg , const char* fieldName , Color value ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*valueColor
virtual QAngle GetQAngle ( void* msg , const char* fieldName ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*
virtual QAngle GetRepeatedQAngle ( void* msg , const char* fieldName , int index ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*indexint
virtual void SetQAngle ( void* msg , const char* fieldName , QAngle value ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*valueQAngle
virtual void SetRepeatedQAngle ( void* msg , const char* fieldName , int index , QAngle value ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*indexintvalueQAngle
virtual void AddQAngle ( void* msg , const char* fieldName , QAngle value ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*valueQAngle
virtual int GetBytes ( uint8_t* out , void* msg , const char* fieldName ) = 0 ;
Copies a bytes field into @p out.
Pass @p out as nullptr to query the size without copying.
Parameter Type outuint8_t*msgvoid*fieldNameconst char*
Returns int — Number of bytes in the field.
virtual int GetRepeatedBytes ( uint8_t* out , void* msg , const char* fieldName , int index ) = 0 ;
Parameter Type outuint8_t*msgvoid*fieldNameconst char*indexint
virtual void SetBytes ( void* msg , const char* fieldName , const char* value , int valueLength ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*valueconst char*valueLengthint
virtual void SetRepeatedBytes ( void* msg , const char* fieldName , int index , const char* value , int valueLength ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*indexintvalueconst char*valueLengthint
virtual void AddBytes ( void* msg , const char* fieldName , const char* value , int valueLength ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*valueconst char*valueLengthint
virtual void* GetNestedMessage ( void* msg , const char* fieldName ) = 0 ;
Returns a mutable pointer to a singular nested message field.
Parameter Type msgvoid*fieldNameconst char*
virtual void* GetRepeatedNestedMessage ( void* msg , const char* fieldName , int index ) = 0 ;
Returns a mutable pointer to a repeated nested message element.
Parameter Type msgvoid*fieldNameconst char*indexint
virtual void* AddNestedMessage ( void* msg , const char* fieldName ) = 0 ;
Appends a new element to a repeated nested message field and returns it.
Parameter Type msgvoid*fieldNameconst char*
virtual int GetRepeatedFieldSize ( void* msg , const char* fieldName ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*
virtual void ClearRepeatedField ( void* msg , const char* fieldName ) = 0 ;
Parameter Type msgvoid*fieldNameconst char*
virtual void Clear ( void* msg ) = 0 ;
Clears all fields on the message.
virtual void SendMessage ( void* msg , int msgid , CPlayerSlot slot ) = 0 ;
Sends a network message to a single player.
Parameter Type Description msgvoid*Allocated message to send (not freed by this call). msgidintMessage ID matching the allocation. slotCPlayerSlot
virtual void SendMessageToPlayers ( void* msg , int msgid , uint64_t playermask ) = 0 ;
Sends a network message to a set of players.
Parameter Type Description msgvoid*Allocated message to send (not freed by this call). msgidintMessage ID matching the allocation. playermaskuint64_t64-bit bitmask; bit N = slot N.
virtual Source2ModNetMessageHookId HookServerMessage ( NetMessageServerHook handler ) = 0 ;
Hooks outgoing server-to-client messages.
A plugin may hook as often as it likes; each handler runs. The source2mod drops what a plugin still holds when it unloads, so a plugin that forgets to unhook does not leave the engine calling into a closed library. Whose a hook is, the core reads off the handler (see Source2ModCallback).
Returns Source2ModNetMessageHookId — The id UnhookServerMessage(id) takes
virtual bool UnhookServerMessage ( const NetMessageServerHook & handler ) = 0 ;
virtual bool UnhookServerMessage ( Source2ModNetMessageHookId id ) = 0 ;
Drops the hook with this handler -- a function or an object and a method; a lambda goes by its id.
Drops the hook HookServerMessage() returned the id for.
Returns bool — true when one was found
virtual Source2ModNetMessageHookId HookClientMessage ( NetMessageClientHook handler ) = 0 ;
Hooks incoming client-to-server messages (as HookServerMessage()).
Returns Source2ModNetMessageHookId — The id UnhookClientMessage(id) takes
virtual bool UnhookClientMessage ( const NetMessageClientHook & handler ) = 0 ;
virtual bool UnhookClientMessage ( Source2ModNetMessageHookId id ) = 0 ;
Drops the hook with this handler -- a function or an object and a method; a lambda goes by its id.
Drops the hook HookClientMessage() returned the id for.
Returns bool — true when one was found
virtual Source2ModNetMessageHookId HookServerInternalMessage ( NetMessageClientHook handler ) = 0 ;
Hooks internal server-side message sends, per client (as HookServerMessage()).
Returns Source2ModNetMessageHookId — The id UnhookServerInternalMessage(id) takes
virtual bool UnhookServerInternalMessage ( const NetMessageClientHook & handler ) = 0 ;
virtual bool UnhookServerInternalMessage ( Source2ModNetMessageHookId id ) = 0 ;
Drops the hook with this handler -- a function or an object and a method; a lambda goes by its id.
Drops the hook HookServerInternalMessage() returned the id for.
Returns bool — true when one was found
#define NET_MSG_ALLOC_BY_ID ( id ) g_pSource2ModNetworkMessages-> AllocateNetMessageByID (id)
Shorthand accessors via g_Source2ModAPI.
#define HOOK_SERVER_MESSAGE ( handler ) g_pSource2ModNetworkMessages-> HookServerMessage (handler)
Hook macros, matching HOOK_GAME_EVENT and HOOK_CONVAR_CHANGE.
Macro Expands to NET_MSG_ALLOC_BY_NAME(name)g_pSource2ModNetworkMessages->AllocateNetMessageByPartialName(name)NET_MSG_FREE(msg)g_pSource2ModNetworkMessages->DeallocateNetMessage(msg)NET_MSG_SEND(msg, id, slot)g_pSource2ModNetworkMessages->SendMessage(msg, id, slot)NET_MSG_SEND_PLAYERS(msg, id, mask)g_pSource2ModNetworkMessages->SendMessageToPlayers(msg, id, mask)UNHOOK_SERVER_MESSAGE(handler)g_pSource2ModNetworkMessages->UnhookServerMessage(handler)HOOK_CLIENT_MESSAGE(handler)g_pSource2ModNetworkMessages->HookClientMessage(handler)UNHOOK_CLIENT_MESSAGE(handler)g_pSource2ModNetworkMessages->UnhookClientMessage(handler)HOOK_SERVER_INTERNAL_MESSAGE(handler)g_pSource2ModNetworkMessages->HookServerInternalMessage(handler)UNHOOK_SERVER_INTERNAL_MESSAGE(handler)g_pSource2ModNetworkMessages->UnhookServerInternalMessage(handler)