mirror of
https://github.com/Gurge44/EndlessHostRoles.git
synced 2026-10-20 01:46:25 +00:00
83 lines
2.7 KiB
C#
83 lines
2.7 KiB
C#
using System;
|
|
using System.Collections;
|
|
using AmongUs.GameOptions;
|
|
using Hazel;
|
|
using Il2CppInterop.Runtime.InteropTypes.Arrays;
|
|
|
|
namespace EHR.Modules;
|
|
|
|
public sealed class NormalGameOptionsSender : GameOptionsSender
|
|
{
|
|
private LogicOptions _logicOptions;
|
|
private static IGameOptions BasedGameOptions => GameOptionsManager.Instance.CurrentGameOptions;
|
|
|
|
protected override bool IsDirty
|
|
{
|
|
get
|
|
{
|
|
try
|
|
{
|
|
if (GameManager.Instance != null && GameManager.Instance.LogicComponents != null && (_logicOptions == null || !GameManager.Instance.LogicComponents.Contains(_logicOptions)))
|
|
{
|
|
foreach (GameLogicComponent glc in GameManager.Instance.LogicComponents)
|
|
{
|
|
if (glc.TryCast(out LogicOptions lo))
|
|
_logicOptions = lo;
|
|
}
|
|
}
|
|
|
|
return _logicOptions is { IsDirty: true };
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Logger.Error(ex.ToString(), "NormalGameOptionsSender.IsDirty.Get");
|
|
return _logicOptions is { IsDirty: true };
|
|
}
|
|
}
|
|
set => _logicOptions?.ClearDirtyFlag();
|
|
}
|
|
|
|
public override IGameOptions BuildGameOptions()
|
|
{
|
|
return BasedGameOptions;
|
|
}
|
|
|
|
protected override IEnumerator SendOptionsArrayAsync(Il2CppStructArray<byte> optionArray, byte logicOptionsIndex)
|
|
{
|
|
yield return DataFlagRateLimiter.Enqueue(SendOptionsAction(optionArray, logicOptionsIndex)).Wait();
|
|
}
|
|
|
|
protected override void SendOptionsArray(Il2CppStructArray<byte> optionArray, byte logicOptionsIndex)
|
|
{
|
|
DataFlagRateLimiter.Enqueue(SendOptionsAction(optionArray, logicOptionsIndex));
|
|
}
|
|
|
|
private static Action SendOptionsAction(Il2CppStructArray<byte> optionArray, byte logicOptionsIndex)
|
|
{
|
|
return () =>
|
|
{
|
|
MessageWriter writer = MessageWriter.Get(SendOption.Reliable);
|
|
|
|
writer.StartMessage(5);
|
|
{
|
|
writer.Write(AmongUsClient.Instance.GameId);
|
|
|
|
writer.StartMessage(1);
|
|
{
|
|
writer.WritePacked(GameManager.Instance.NetId);
|
|
writer.StartMessage(logicOptionsIndex);
|
|
{
|
|
writer.WriteBytesAndSize(optionArray);
|
|
}
|
|
writer.EndMessage();
|
|
}
|
|
writer.EndMessage();
|
|
}
|
|
|
|
writer.EndMessage();
|
|
|
|
AmongUsClient.Instance.SendOrDisconnect(writer);
|
|
writer.Recycle();
|
|
};
|
|
}
|
|
} |