mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-24 06:46:46 +00:00
57 lines
1.8 KiB
C#
57 lines
1.8 KiB
C#
using Hazel;
|
|
using MiraAPI.GameOptions;
|
|
using Reactor.Networking.Attributes;
|
|
using Reactor.Networking.Rpc;
|
|
|
|
namespace MiraAPI.Networking;
|
|
|
|
// METHOD RPC DOESN'T WORK WITH THE ARRAYS AND STUFF SO THIS IS HOW WE WILL DO IT FOR NOW
|
|
[RegisterCustomRpc((uint)MiraRpc.SyncGameOptions)]
|
|
#pragma warning disable SA1515 // Single-line comment should be preceded by blank line (Justification: ReSharper suppression.)
|
|
// ReSharper disable once ClassNeverInstantiated.Global (Justification: Instantiated by Reactor.)
|
|
internal sealed class SyncOptionsRpc(MiraApiPlugin plugin, uint id) : PlayerCustomRpc<MiraApiPlugin, NetData[]>(plugin, id)
|
|
#pragma warning restore SA1515 // Single-line comment should be preceded by blank line
|
|
{
|
|
public override RpcLocalHandling LocalHandling => RpcLocalHandling.None;
|
|
|
|
public override void Write(MessageWriter writer, NetData[]? data)
|
|
{
|
|
if (data == null)
|
|
{
|
|
writer.WritePacked(0U);
|
|
return;
|
|
}
|
|
|
|
writer.WritePacked((uint)data.Length);
|
|
foreach (var netData in data)
|
|
{
|
|
writer.WritePacked(netData.Id);
|
|
writer.WriteBytesAndSize(netData.Data);
|
|
}
|
|
}
|
|
|
|
public override NetData[] Read(MessageReader reader)
|
|
{
|
|
var length = reader.ReadPackedUInt32();
|
|
var data = new NetData[length];
|
|
for (var i = 0; i < length; i++)
|
|
{
|
|
var dataId = reader.ReadPackedUInt32();
|
|
var bytes = reader.ReadBytesAndSize();
|
|
data[i] = new NetData(dataId, bytes);
|
|
}
|
|
|
|
return data;
|
|
}
|
|
|
|
public override void Handle(PlayerControl playerControl, NetData[]? data)
|
|
{
|
|
if (AmongUsClient.Instance.HostId != playerControl.OwnerId)
|
|
{
|
|
return;
|
|
}
|
|
|
|
ModdedOptionsManager.HandleSyncOptions(data ?? []);
|
|
}
|
|
}
|