Files
Ananta-ps/Ananta.Server/Ananta.Core/Protocol/Client4229938/GameSwitchCodec.cs
T

57 lines
1.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Ananta.SDK.Serialization;
namespace Ananta.Server.Protocol.Client4229938;
/// <summary>
/// 手写字节的 <c>SyncGameSwitchToClient_3</c>(53940944) 载荷。
///
/// 为什么不能用 UxSerializer:payload 是 <c>Dictionary&lt;string, UXObject&gt;</c>,
/// value 是多态静态对象(tp 单字节 + payload),UxSerializer 不支持。
///
/// 线格式由 donor 反汇编 <c>UXRPCMethodArgs53940944.Read</c> @ RVA 0x9AB5450 确认,别再改:
/// <code>
/// [Int7 计数] // Read7BitEncodedInt(),无 0xFF、无终止符
/// 计数 × { [UxString key]; [tp:1][payload] } // value 前没有存在标记
/// </code>
/// tp = 2 是 bool(跳转表 RVA 0x1DAC878,tp∈[2,8]),payload 为 1 字节。
/// 203 项 → 约 4.9 KB。
///
/// ⛔⛔ 发送时必须走 <c>Connection.NotifyRawAsync(methodId, byte[])</c>:
/// 用 <c>NotifyAsync&lt;T&gt;</c> 且 T = byte[] 会按 UX 缓冲区多写 3 字节(0xFF + varint(len+1)),
/// 客户端把 FF 8A 26 当计数 ⇒ 整体错位。
/// </summary>
internal static class GameSwitchCodec
{
private const byte TypeTagBool = 2;
internal static byte[] Build()
{
var entries = GameSwitchCatalog.Entries;
var writer = new UxWriter();
writer.Int7(entries.Length);
foreach (var (name, value) in entries)
{
writer.UxString(name);
writer.U8(TypeTagBool);
writer.Bool(value);
}
return writer.ToArray();
}
internal static byte[] Build(IEnumerable<(string Name, bool Value)> entries)
{
var list = entries as IReadOnlyCollection<(string Name, bool Value)> ?? entries.ToArray();
var writer = new UxWriter();
writer.Int7(list.Count);
foreach (var (name, value) in list)
{
writer.UxString(name);
writer.U8(TypeTagBool);
writer.Bool(value);
}
return writer.ToArray();
}
}