Repository navigation
Raw RPC and Packets
Алексей . edited this page Mar 30, 2026
·
5 revisions
Use this layer when:
- a packet or RPC is not described in the parser catalog yet
- you want to read
BitStreamReadermanually - you need transport details such as
ERpcId,EPacketId,DataBitLength, raw payload, or offsets
If a parser already exists and you only need a typed payload, SF.Events is usually the better choice.
Source:
https://github.com/AllahPower/SF-Arizona/blob/master/src/SF/Networking/SFRpc.cs
using SFSharp;
using IDisposable sub = SF.Rpc.Subscribe(ERpcId.ShowDialog, args =>
{
BitStreamReader reader = args.CreateReader();
ushort dialogId = reader.ReadUInt16();
DialogStyle style = (DialogStyle)reader.ReadUInt8();
string title = reader.ReadStringUInt8Length();
SF.Chat.Add($"dialog={dialogId} title={title}");
});using IDisposable sub = SF.Rpc.Bind(
ERpcId.ShowDialog,
SampRpc.ParseShowDialog,
(rpc, raw) =>
{
SF.Chat.Add($"dialog={rpc.DialogId} title={rpc.Title}");
},
name: "Wiki.ShowDialog");await foreach (IncomingRpcPayload payload in SF.Rpc.Stream(ERpcId.ClientMessage, cancellationToken))
{
ClientMessageRpc rpc = payload.Parse(SampRpc.ParseClientMessage);
SF.Chat.Add(rpc.Text);
}using IDisposable sub = SF.Packets.SubscribeIncoming(EPacketId.PlayerSync, args =>
{
BitStreamReader reader = args.CreateReader();
byte packetId = reader.ReadUInt8();
byte leftRight = reader.ReadUInt8();
SF.Chat.Add($"player sync packet={packetId} lr={leftRight}");
});using IDisposable sub = SF.Packets.SubscribeOutgoing(EPacketId.StatsSync, args =>
{
BitStreamReader reader = args.CreateReader();
byte packetId = reader.ReadUInt8();
SF.Chat.Add($"outgoing packet={packetId}");
});Arizona has two custom transport channels:
-
EPacketId.ArizonaCef(220) withu8 subId -
EPacketId.ArizonaCefEx(221) withu16 subId
using IDisposable sub = SF.Packets.SubscribeIncoming(EPacketId.ArizonaCef, args =>
{
BitStreamReader reader = args.CreateReader();
reader.SkipBytes(1);
int subId = ArizonaPacket.ReadSubId220(ref reader);
SF.Chat.Add($"220:{subId}");
});using IDisposable sub220 = SF.Arizona.SubscribeIncoming(EArizona.TextDrawPositionUpdate, args =>
{
BitStreamReader reader = args.CreateReader();
ushort textdrawId = reader.ReadUInt16();
float x = reader.ReadFloat();
float y = reader.ReadFloat();
SF.Chat.Add($"220:{args.SubId} td={textdrawId} pos=({x}, {y})");
});using IDisposable sub = SF.Rpc.Subscribe(ERpcId.ServerJoin, args =>
{
SF.Chat.Add($"ServerJoin bits={args.DataBitLength}");
});static (ushort Id, string Text) ParseMyDialog(IncomingRpcArgs args)
{
BitStreamReader reader = args.CreateReader();
ushort id = reader.ReadUInt16();
reader.ReadUInt8();
string title = reader.ReadStringUInt8Length();
reader.ReadStringUInt8Length();
reader.ReadStringUInt8Length();
string text = reader.ReadStringUInt16Length();
return (id, title + " | " + text);
}
using IDisposable sub = SF.Rpc.Bind(
ERpcId.ShowDialog,
ParseMyDialog,
(rpc, _) => SF.Chat.Add($"dialog={rpc.Id} {rpc.Text}"),
name: "Wiki.CustomDialog");Pros:
- full control over the bitstream
- works for unknown packets
- easy to inspect payload size and offsets
- good for reverse engineering
Cons:
- more boilerplate
- you maintain the parser yourself
- easier to make a parsing mistake
- Главная / Home
- Установка
- Архитектура и совместимость
- SA-MP R1, R3-1, R5-1
- Написание модулей
- Плагины и зависимости
- Жизненный цикл
- API модулей
- Потоки и время жизни
- Ранняя загрузка
- Конфигурация и ассеты