Skip to content

Raw RPC and Packets

Алексей . edited this page Oct 22, 2026 · 5 revisions

Use context.SF.Samp.Packets and Rpc for copied raw frames. SubscribeIncoming/Outgoing accepts numeric IDs; StreamIncoming/Outgoing additionally accepts a cancellation token. Register disposable callbacks with the module context and end stream enumeration during stop.

Data fidelity

ReadOnlyMemory in a frame owns managed bytes detached from native memory. Keeping frames keeps their buffers alive. Incoming RPC data can include a header and an unaligned payload: preserve DataBitOffset and DataBitLength. Byte slicing at offset/8 is incorrect for unaligned data. Outgoing RPC generally supplies payload only. Packets include their ID.

Subscriptions route by original wire ID. Incoming(207) does not implicitly include a timestamp-wrapped 207; subscribe to 40 as well and inspect EffectivePacketId. See timestamp rules.

Filters

RegisterIncomingFilter/RegisterOutgoingFilter exist for packets and RPCs, either by ID or catch-all. A true result drops the message; false passes it. Filters run synchronously on the hook thread, not the game-thread dispatcher. Do not block, allocate, perform I/O, call native UI, await or retain the supplied span. Do not register resources there.

Transport

SendPacket takes a complete packet. SendRpc takes a separate ID, payload and payload bit length. SimulateIncoming methods enqueue synthetic input locally and do not contact the server. All transport calls require the game thread. Encoding and bit windows remain the caller's responsibility; managed bitstreams help construct valid layouts.

See full examples, ISFPackets, filter delegates and IncomingRpcFrame.

Clone this wiki locally