Skip to main content

NetMessages

Entry point for sending and hooking Source 2 network messages. Messages are identified by their protobuf type; IDs are resolved via NetMessageRegistry.

public static class NetMessages

Namespace: DeadworksManaged.Api
Source: NetMessages/NetMessages.cs#L9

Methods​

NetMessages.Send()​

Sends a protobuf net message to the specified recipients.

Signature

public static void Send<T>(T message, RecipientFilter recipients, bool reliable = true) where T : IMessage<T>

Parameters

  • message: The message to send.
  • recipients: Which players should receive this message.
  • reliable: Which net-channel buffer to use. Reliable guarantees ordered delivery but disconnects the client if the server outruns its acks (NETWORK_DISCONNECT_RELIABLEOVERFLOW) — it degrades off a cliff, not gracefully. Unreliable simply drops the packet under pressure, which is the right trade for latest-wins traffic such as telemetry or HUD state. Anything that must not be lost — layout, ordering, handshakes, or one fragment of a multi-part message — has to stay reliable.

Throws

  • InvalidOperationException: Thrown if T has no registered message ID.

Source: NetMessages/NetMessages.cs#L31

NetMessages.HookOutgoing()​

Registers a hook that fires before a server→client message of type T is sent.

Signature

public static IHandle HookOutgoing<T>(Func<OutgoingMessageContext<T>, HookResult> handler) where T : IMessage<T>, new()

Parameters

  • handler: Called with the message context; return HookResult.Handled to suppress the message.

Returns A handle that keeps the hook alive. Dispose or call UnhookOutgoing&lt;T&gt; to remove it.

Throws

  • InvalidOperationException: Thrown if T has no registered message ID.

Source: NetMessages/NetMessages.cs#L48

NetMessages.HookIncoming()​

Registers a hook that fires when the server receives a client→server message of type T.

Signature

public static IHandle HookIncoming<T>(Func<IncomingMessageContext<T>, HookResult> handler) where T : IMessage<T>, new()

Parameters

  • handler: Called with the message context; return HookResult.Handled to suppress processing.

Returns A handle that keeps the hook alive. Dispose or call UnhookIncoming&lt;T&gt; to remove it.

Throws

  • InvalidOperationException: Thrown if T has no registered message ID.

Source: NetMessages/NetMessages.cs#L65

NetMessages.UnhookOutgoing()​

Removes a previously registered outgoing hook for message type T.

Signature

public static void UnhookOutgoing<T>(Func<OutgoingMessageContext<T>, HookResult> handler) where T : IMessage<T>, new()

Parameters

  • handler: The exact delegate instance that was passed to HookOutgoing&lt;T&gt;.

Source: NetMessages/NetMessages.cs#L78

NetMessages.UnhookIncoming()​

Removes a previously registered incoming hook for message type T.

Signature

public static void UnhookIncoming<T>(Func<IncomingMessageContext<T>, HookResult> handler) where T : IMessage<T>, new()

Parameters

  • handler: The exact delegate instance that was passed to HookIncoming&lt;T&gt;.

Source: NetMessages/NetMessages.cs#L89