Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of LCSyncTool v1.1.1
LCSyncTool.dll
Decompiled 2 years agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Logging; using GameNetcodeStuff; using HarmonyLib; using Microsoft.CodeAnalysis; using Unity.Netcode; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("LCSyncTool")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("LCSyncTool")] [assembly: AssemblyTitle("LCSyncTool")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace LCSyncTool { public static class ParseUtils { public const string MESSAGE_PREFIX = "__LCST"; public const char RESOURCE_SEPARATOR = '/'; public const char LIST_SEPARATOR = ';'; public const char INNER_LIST_SEPARATOR = ','; public static readonly char[] INVALID_CHARS = new char[3] { '/', ';', ',' }; public static string[] SplitArgs(string raw, char delimiter = ';') { return raw.Split(delimiter); } public static bool ParseULong(string str, out ulong value) { return ulong.TryParse(str, out value); } public static bool ParseLong(string str, out long value) { return long.TryParse(str, out value); } public static bool ParseUInt(string str, out uint value) { return uint.TryParse(str, out value); } public static bool ParseInt(string str, out int value) { return int.TryParse(str, out value); } public static bool ParseFloat(string str, out float value) { return float.TryParse(str, out value); } public static bool ParseBool(string str, out bool value) { return bool.TryParse(str, out value); } public static bool ParseVec2(string str, out Vector2 vec2) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) string[] array = SplitArgs(str, ','); vec2 = default(Vector2); if (array.Length != 2) { return false; } if (!ParseFloat(array[0], out var value)) { return false; } if (!ParseFloat(array[1], out var value2)) { return false; } vec2 = new Vector2(value, value2); return true; } public static bool ParseVec3(string str, out Vector3 vec3) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) string[] array = SplitArgs(str, ','); vec3 = default(Vector3); if (array.Length != 3) { return false; } if (!ParseFloat(array[0], out var value)) { return false; } if (!ParseFloat(array[1], out var value2)) { return false; } if (!ParseFloat(array[2], out var value3)) { return false; } vec3 = new Vector3(value, value2, value3); return true; } public static bool ParseIntList(string str, out List<int> xs) { string[] array = SplitArgs(str); xs = new List<int>(); string[] array2 = array; for (int i = 0; i < array2.Length; i++) { if (!int.TryParse(array2[i], out var result)) { xs = null; return false; } xs.Add(result); } return true; } public static bool ParseULongList(string str, out List<ulong> xs) { string[] array = SplitArgs(str); xs = new List<ulong>(); string[] array2 = array; for (int i = 0; i < array2.Length; i++) { if (!ulong.TryParse(array2[i], out var result)) { xs = null; return false; } xs.Add(result); } return true; } public static bool ParseFloatList(string str, out List<float> xs) { string[] array = SplitArgs(str); xs = new List<float>(); string[] array2 = array; for (int i = 0; i < array2.Length; i++) { if (!float.TryParse(array2[i], out var result)) { xs = null; return false; } xs.Add(result); } return true; } public static string RemoveInvalidChars(string raw_str) { return INVALID_CHARS.Aggregate(raw_str, (string str, char c) => str.Replace(c.ToString(), "")); } public static bool ContainsInvalidChars(string raw_str) { return INVALID_CHARS.Any(raw_str.Contains); } } public interface IMessageHandler : IEquatable<IMessageHandler> { bool OnMessage(ParseableMessage msg); } public class LambdaMessageHandler : IMessageHandler, IEquatable<IMessageHandler> { private readonly Func<ParseableMessage, bool> m_Impl; private readonly string m_Name; public LambdaMessageHandler(string name, Func<ParseableMessage, bool> impl) { if (name == null || impl == null) { Plugin.LOGGER.LogError((object)"LambdaMessageHandler one or more constructor params are null."); throw new ArgumentException(); } m_Name = name; m_Impl = impl; } public bool Equals(IMessageHandler other) { if (!(other is LambdaMessageHandler lambdaMessageHandler)) { return false; } return lambdaMessageHandler.m_Name == m_Name; } public bool OnMessage(ParseableMessage msg) { return m_Impl(msg); } public override string ToString() { return "Lambda::" + m_Name; } } public class CommandMessageHandler : IMessageHandler, IEquatable<IMessageHandler> { public string CommandPrefix { get; set; } public Func<ParseableMessage, bool> m_Impl { get; set; } public CommandMessageHandler(string cmd, Func<ParseableMessage, bool> impl) { if (cmd == null || impl == null) { Plugin.LOGGER.LogError((object)"CommandMessageHandler one or more constructor params are null."); throw new ArgumentException(); } CommandPrefix = cmd; m_Impl = impl; } public bool Equals(IMessageHandler other) { return this == other; } public bool OnMessage(ParseableMessage msg) { string str = msg.GetStr(0); if (m_Impl != null && str != null && str.Equals(CommandPrefix)) { return m_Impl(msg); } return false; } public override string ToString() { return "CMD::" + CommandPrefix; } } public abstract class AbstractCommand : IMessageHandler, IEquatable<IMessageHandler> { private readonly string m_CommandPrefix; protected AbstractCommand(string cmd) { if (cmd == null) { Plugin.LOGGER.LogError((object)"Abstract Command cannot have a null command."); throw new ArgumentException(); } m_CommandPrefix = cmd; } public bool Equals(IMessageHandler other) { if (this == other) { return true; } if (other is AbstractCommand abstractCommand) { return abstractCommand.m_CommandPrefix == m_CommandPrefix; } return false; } protected virtual bool IsCommand(ParseableMessage msg) { return m_CommandPrefix.Equals(msg.Identifier()); } public bool OnMessage(ParseableMessage msg) { if (IsCommand(msg)) { return OnCommand(msg); } return false; } protected abstract bool OnCommand(ParseableMessage msg); public override string ToString() { return GetType().Name + "::" + m_CommandPrefix; } } public class ParseableMessage { public string Raw { get; } public string[] SplitParams { get; } public ulong SourceClient { get; private set; } public List<ulong> TargetClients { get; private set; } public string[] Params { get; private set; } public ParseableMessage(string raw) { if (raw != null && raw.StartsWith("__LCST")) { Raw = raw; SplitParams = ParseUtils.SplitArgs(raw, '/'); ParseInternal(); } } public bool IsValid() { if (Raw != null) { string[] splitParams = SplitParams; if (splitParams != null) { return splitParams.Length == 4; } return false; } return false; } public string GetSourceClientRaw() { return SplitParams[1]; } public string GetTargetClientRaw() { return SplitParams[2]; } public string GetParamsRaw() { return SplitParams[3]; } public bool IsFrom(ulong id) { return id == SourceClient; } public bool IsFromServer() { PlayerControllerB val = ((IEnumerable<PlayerControllerB>)StartOfRound.Instance.allPlayerScripts).FirstOrDefault((Func<PlayerControllerB, bool>)((PlayerControllerB x) => x.isHostPlayerObject)); if ((Object)(object)val != (Object)null && SourceClient == 0L) { return SourceClient == val.actualClientId; } return false; } public bool IsTargetServer() { PlayerControllerB val = ((IEnumerable<PlayerControllerB>)StartOfRound.Instance.allPlayerScripts).FirstOrDefault((Func<PlayerControllerB, bool>)((PlayerControllerB x) => x.isHostPlayerObject)); if ((Object)(object)val != (Object)null) { return TargetClients.Contains(val.actualClientId); } return false; } public bool IsTargetLocal() { PlayerControllerB localPlayerController = StartOfRound.Instance.localPlayerController; return TargetClients.Contains(localPlayerController.actualClientId); } private void ParseInternal() { if (IsValid() && ParseUtils.ParseULong(GetSourceClientRaw(), out var value) && ParseUtils.ParseULongList(GetTargetClientRaw(), out var xs)) { SourceClient = value; TargetClients = xs; Params = ParseUtils.SplitArgs(SplitParams[3]); } } public string GetStr(int i) { if (Params == null || i < 0 || i >= Params.Length) { return null; } return Params[i]; } public string Identifier() { return GetStr(0); } public bool GetUInt(int i, out uint v) { return ParseUtils.ParseUInt(GetStr(i), out v); } public bool GetInt(int i, out int v) { return ParseUtils.ParseInt(GetStr(i), out v); } public bool GetULong(int i, out ulong v) { return ParseUtils.ParseULong(GetStr(i), out v); } public bool GetLong(int i, out long v) { return ParseUtils.ParseLong(GetStr(i), out v); } public bool GetBool(int i, out bool v) { return ParseUtils.ParseBool(GetStr(i), out v); } public bool GetFloat(int i, out float v) { return ParseUtils.ParseFloat(GetStr(i), out v); } public bool GetVec2(int i, out Vector2 v) { return ParseUtils.ParseVec2(GetStr(i), out v); } public bool GetVec3(int i, out Vector3 v) { return ParseUtils.ParseVec3(GetStr(i), out v); } public bool GetIntList(int i, out List<int> xs) { return ParseUtils.ParseIntList(GetStr(i), out xs); } public bool GetFloatList(int i, out List<float> xs) { return ParseUtils.ParseFloatList(GetStr(i), out xs); } public bool GetStr(int i, out string v) { v = GetStr(i); return v != null; } } public class MessageBuilder { public string Identifier { get; private set; } = "__LCST"; public ulong SourceClient { get; private set; } public List<ulong> TargetClients { get; private set; } = new List<ulong>(); public List<string> Params { get; private set; } = new List<string>(); public float DelaySeconds { get; set; } = -1f; public static MessageBuilder Create() { return new MessageBuilder(); } public MessageBuilder SetIdentifier(string id) { Identifier = id; return this; } public MessageBuilder SetSourceClientToLocal() { SourceClient = StartOfRound.Instance.localPlayerController.actualClientId; return this; } public MessageBuilder SetSourceClient(ulong client_id) { SourceClient = client_id; return this; } public MessageBuilder SetTargetClientAll(bool include_local = false) { TargetClients.Clear(); if (include_local) { TargetClients.Add(StartOfRound.Instance.localPlayerController.actualClientId); } PlayerControllerB localPlayerController = StartOfRound.Instance.localPlayerController; PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts; foreach (PlayerControllerB val in allPlayerScripts) { if (!((Object)(object)val == (Object)null) && !val.isTestingPlayer && ((NetworkBehaviour)val).IsSpawned && (val.actualClientId != 0L || val.isHostPlayerObject) && val.actualClientId != localPlayerController.actualClientId) { TargetClients.Add(val.actualClientId); } } return this; } public MessageBuilder SetTargetToServer() { TargetClients.Clear(); PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts; foreach (PlayerControllerB val in allPlayerScripts) { if (val.isHostPlayerObject) { TargetClients.Add(val.actualClientId); return this; } } Plugin.LOGGER.LogError((object)"Could not find server player!"); return this; } public MessageBuilder AddTargetClient(ulong client_id) { if (TargetClients.Contains(client_id)) { return this; } TargetClients.Add(client_id); return this; } public MessageBuilder AddDelaySeconds(float delay) { DelaySeconds = delay; return this; } public MessageBuilder AddParam(string param, bool silent_replace = true) { if (silent_replace) { param = ParseUtils.RemoveInvalidChars(param); } else if (ParseUtils.ContainsInvalidChars(param)) { Plugin.LOGGER.LogError((object)("Param '" + param + "' contains one or more invalid character.")); throw new Exception("Invalid Char/s in string '" + param + "'"); } Params.Add(param); return this; } public MessageBuilder AddParam(uint param) { Params.Add(param.ToString()); return this; } public MessageBuilder AddParam(int param) { Params.Add(param.ToString()); return this; } public MessageBuilder AddParam(float param) { Params.Add(param.ToString(CultureInfo.InvariantCulture)); return this; } public MessageBuilder AddParam(bool param) { Params.Add(param.ToString()); return this; } public MessageBuilder AddParams(params object[] elements) { //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Unknown result type (might be due to invalid IL or missing references) foreach (object obj in elements) { if (obj is int) { AddParam((int)obj); continue; } if (obj is uint) { AddParam((uint)obj); continue; } if (obj is float) { AddParam((float)obj); continue; } if (obj is ulong) { AddParam((float)(ulong)obj); continue; } if (obj is long) { AddParam((float)(long)obj); continue; } if (obj is string) { AddParam((string)obj); continue; } if (obj is bool) { AddParam((bool)obj); continue; } if (obj is Vector2) { this.AddParam((Vector2)obj); continue; } if (obj is Vector3) { this.AddParam((Vector3)obj); continue; } throw new ArgumentException("Unsupported Type: " + obj.GetType().Name); } return this; } public MessageBuilder AddParam(Vector2 param) { Params.Add(param.x.ToString(CultureInfo.InvariantCulture) + "," + param.y.ToString(CultureInfo.InvariantCulture)); return this; } public MessageBuilder AddParam(Vector3 param) { Params.Add(param.x.ToString(CultureInfo.InvariantCulture) + "," + param.y.ToString(CultureInfo.InvariantCulture) + "," + param.z.ToString(CultureInfo.InvariantCulture)); return this; } public string Build() { return Identifier + "/" + SourceClient + "/" + GeneralExtensions.Join<ulong>((IEnumerable<ulong>)TargetClients, (Func<ulong, string>)null, ';'.ToString()) + "/" + GeneralExtensions.Join<string>((IEnumerable<string>)Params, (Func<string, string>)null, ';'.ToString()); } public ParseableMessage BuildAsParseableMessage() { return new ParseableMessage(Build()); } public MessageBuilder SetTargetClients(params ulong[] targets) { if (targets == null) { return this; } TargetClients.AddRange(targets); return this; } public void Broadcast() { MessageSystem.Broadcast(Build()); } } public static class MessageSystem { private static readonly List<IMessageHandler> s_Handlers = new List<IMessageHandler>(); public static void AddHandler(IMessageHandler handler) { Plugin.LOGGER.LogInfo((object)("MessageSystem :: Adding Message Handler '" + handler?.ToString() + "'")); s_Handlers.Add(handler); } public static void AddHandler(string name, Func<ParseableMessage, bool> handler) { AddHandler(new LambdaMessageHandler(name, handler)); } public static void AddCommand(CommandMessageHandler cmd) { AddHandler(cmd); } public static void AddCommand(string cmd, Func<ParseableMessage, bool> action) { AddCommand(new CommandMessageHandler(cmd, action)); } public static void AddAllFromAssembly(Assembly assembly = null) { if (assembly == null) { assembly = Assembly.GetCallingAssembly(); } Type type = typeof(IMessageHandler); CollectionExtensions.Do<IMessageHandler>(from x in assembly.GetTypes() where !x.IsAbstract && type.IsAssignableFrom(x) select x.GetConstructor(Type.EmptyTypes) into x where x != null select (IMessageHandler)x.Invoke(null), (Action<IMessageHandler>)AddHandler); } public static void Clear() { Plugin.LOGGER.LogInfo((object)"MessageSystem :: Clearing Message Handlers!"); s_Handlers.Clear(); } private static void BroadcastImpl(string msg, float delay = -1f) { HUDManager hud = HUDManager.Instance; if ((Object)(object)hud == (Object)null) { Plugin.LOGGER.LogWarning((object)("MessageSystem :: Could not broadcast '" + msg + "' HUDManager.Instance is null")); } else if (delay < 0f) { hud.AddTextToChatOnServer(msg, -1); } else { ((MonoBehaviour)hud).StartCoroutine(AddChatMessageDelayed()); } IEnumerator AddChatMessageDelayed() { Plugin.LOGGER.LogInfo((object)$"Sending Message '{msg}' in {delay:F2} seconds"); yield return (object)new WaitForSeconds(delay); Plugin.LOGGER.LogInfo((object)("Sending Message '" + msg + "' now")); hud.AddTextToChatOnServer(msg, -1); } } public static void Broadcast(string raw) { BroadcastImpl(raw); } public static void Broadcast(MessageBuilder builder) { BroadcastImpl(builder.Build(), builder.DelaySeconds); } public static void BroadcastCommand(string cmd, params ulong[] targets) { BroadcastImpl(MessageBuilder.Create().SetIdentifier("__LCST").SetSourceClient(StartOfRound.Instance.localPlayerController.actualClientId) .SetTargetClients(targets) .AddParam(cmd) .Build()); } private static bool DispatchIncomingMessage(string str_msg) { if (!str_msg.StartsWith("__LCST")) { return true; } ParseableMessage parseableMessage = new ParseableMessage(str_msg); foreach (IMessageHandler s_Handler in s_Handlers) { if (s_Handler.OnMessage(parseableMessage)) { Plugin.LOGGER.LogInfo((object)($"MessageSystem :: '{s_Handler}' handled message '{str_msg}';" + " '" + GeneralExtensions.Join<string>((IEnumerable<string>)parseableMessage.SplitParams, (Func<string, string>)null, ", ") + "'")); return false; } } return false; } [HarmonyPatch(typeof(HUDManager), "AddChatMessage")] [HarmonyPrefix] private static bool OnAddServerMessage(string chatMessage) { return DispatchIncomingMessage(chatMessage); } } public static class Util { public static byte[] LoadEmbeddedResource(string path, Assembly assem = null) { if (path == null) { return null; } if (assem == null) { assem = Assembly.GetCallingAssembly(); } using Stream stream = assem.GetManifestResourceStream(path); if (stream == null) { Plugin.LOGGER.LogError((object)("Resource stream for '" + path + "' is null...")); return null; } byte[] array = new byte[stream.Length]; Plugin.LOGGER.LogInfo((object)("Reading Bytes: " + stream.Read(array, 0, array.Length))); return array; } public static float[] ByteAudioToFloat(byte[] bytes) { float[] array = new float[bytes.Length / 2]; for (int i = 0; i < array.Length; i++) { array[i] = (float)BitConverter.ToInt16(bytes, i * 2) / 32767f; } return array; } [HarmonyPatch(typeof(Terminal), "BeginUsingTerminal")] [HarmonyPostfix] private static void ResetPlayerScaleWhenUsingTerminal(Terminal __instance) { //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) PlayerControllerB local = StartOfRound.Instance.localPlayerController; Transform trans = ((Component)local).transform; Vector3 original_scale = trans.localScale; trans.localScale = new Vector3(1f, 1f, 1f); ((MonoBehaviour)__instance).StartCoroutine(ResetScaleBackWhenNotUsingTerminal()); IEnumerator ResetScaleBackWhenNotUsingTerminal() { yield return (object)new WaitUntil((Func<bool>)(() => !local.inTerminalMenu)); trans.localScale = original_scale; } } } [BepInPlugin("LCSyncTool", "LCSyncTool", "1.0.0")] public class Plugin : BaseUnityPlugin { public static Harmony HARMONY = new Harmony("LCSyncTool"); public static ManualLogSource LOGGER; private static float s_Theta = 5f; private void Awake() { LOGGER = ((BaseUnityPlugin)this).Logger; ((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin LCSyncTool is loaded!"); MessageSystem.AddAllFromAssembly(); HARMONY.PatchAll(typeof(MessageSystem)); HARMONY.PatchAll(typeof(Plugin)); HARMONY.PatchAll(typeof(MovingLandmines)); HARMONY.PatchAll(typeof(SetPlayerScale)); HARMONY.PatchAll(typeof(Util)); } [HarmonyPatch(typeof(StartOfRound), "Update")] [HarmonyPrefix] private static void Ping(ref StartOfRound __instance) { if (((NetworkBehaviour)__instance).IsServer) { s_Theta -= Time.deltaTime; if (!((double)s_Theta > 0.0)) { s_Theta = 8f; MessageBuilder.Create().SetSourceClientToLocal().SetTargetClientAll() .AddParam("Ping") .AddParam(Random.RandomRangeInt(1, 101)) .Broadcast(); } } } } internal class PingCommand : AbstractCommand { public PingCommand() : base("Ping") { } protected override bool OnCommand(ParseableMessage msg) { if (!msg.IsTargetLocal() || (Object)(object)StartOfRound.Instance == (Object)null) { return true; } if (!msg.GetInt(1, out var v)) { return true; } Plugin.LOGGER.LogInfo((object)("Ping Received from " + (msg.IsFromServer() ? "Server" : "Client") + "; Value: " + v)); if (msg.IsFromServer() && !((NetworkBehaviour)StartOfRound.Instance).IsServer) { MessageBuilder.Create().SetSourceClientToLocal().SetTargetToServer() .AddParam("Ping") .AddParam(Random.RandomRangeInt(1, 101)) .Broadcast(); } return true; } } internal class SpawnExplosionOnPlayer : AbstractCommand { public SpawnExplosionOnPlayer() : base("SpawnExplosionOnPlayer") { } protected override bool OnCommand(ParseableMessage msg) { //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) if (!msg.IsTargetLocal()) { return true; } if (!msg.GetULong(1, out var v)) { v = StartOfRound.Instance.localPlayerController.actualClientId; } if (!msg.GetBool(2, out var v2)) { v2 = true; } if (!msg.GetFloat(3, out var v3)) { v3 = 1f; } if (!msg.GetFloat(4, out var v4)) { v4 = 2f; } Vector3 val = default(Vector3); PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts; foreach (PlayerControllerB val2 in allPlayerScripts) { if (val2.actualClientId == v && (v != 0L || val2.isHostPlayerObject)) { val = ((Component)val2).transform.position; } } Landmine.SpawnExplosion(val, v2, v3, v4); return true; } } internal class SpawnExplosionAt : AbstractCommand { public SpawnExplosionAt() : base("SpawnExplosionAt") { } protected override bool OnCommand(ParseableMessage msg) { //IL_0046: Unknown result type (might be due to invalid IL or missing references) if (!msg.IsTargetLocal()) { return true; } if (!msg.GetVec3(1, out var v)) { return true; } if (!msg.GetBool(2, out var v2)) { v2 = false; } if (!msg.GetFloat(3, out var v3)) { v3 = 1f; } if (!msg.GetFloat(4, out var v4)) { v4 = 1f; } Landmine.SpawnExplosion(v, v2, v3, v4); return true; } } internal class MovingLandmines : AbstractCommand { private static bool s_IsEnabled; private static StartOfRound s_StartOfRound; private static float s_Speed; public MovingLandmines() : base("MovingLandmines") { } protected override bool OnCommand(ParseableMessage msg) { s_StartOfRound = StartOfRound.Instance; if ((Object)(object)s_StartOfRound == (Object)null) { return true; } if (!msg.IsFromServer() || ((NetworkBehaviour)s_StartOfRound).IsServer) { return true; } if (!msg.IsTargetLocal()) { return true; } if (!msg.GetBool(1, out var v)) { return true; } if (!msg.GetFloat(2, out var v2)) { return true; } Plugin.LOGGER.LogInfo((object)$"MovingLandmine :: Speed: '{v2:2F}', Enabled? '{v}'"); s_Speed = v2; s_IsEnabled = v; return true; } [HarmonyPatch(typeof(Landmine), "Update")] [HarmonyPrefix] private static void LandmineUpdate(ref Landmine __instance) { //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_00de: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) if (!s_IsEnabled || (Object)(object)s_StartOfRound == (Object)null || s_StartOfRound.inShipPhase || __instance.hasExploded) { return; } Transform transform = ((Component)__instance).transform; Vector3 position = transform.position; Vector3 val = default(Vector3); float num = float.MaxValue; PlayerControllerB val2 = null; PlayerControllerB[] allPlayerScripts = s_StartOfRound.allPlayerScripts; foreach (PlayerControllerB val3 in allPlayerScripts) { if (val3.isPlayerDead) { continue; } Vector3 position2 = ((Component)val3).transform.position; if (!(Mathf.Abs(position2.y - position.y) > 0.15f)) { float num2 = Vector3.Distance(position, position2); if (!(num2 > 4f) && !(num2 < 1.75f) && num2 < num) { val2 = val3; num = num2; val = position2; } } } if (!((Object)(object)val2 == (Object)null)) { Vector3 val4 = val - position; ((Vector3)(ref val4)).Normalize(); transform.position += val4 * s_Speed * Time.deltaTime; } } [HarmonyPatch(typeof(Landmine), "OnTriggerEnter")] [HarmonyPrefix] private static bool LandmineTriggerEnter(ref Landmine __instance, Collider other) { if (!s_IsEnabled) { return true; } if (!((Component)other).CompareTag("PlayerRagdoll")) { return ((Component)other).CompareTag("Player"); } return true; } [HarmonyPatch(typeof(Landmine), "OnTriggerExit")] [HarmonyPrefix] private static bool LandmineTriggerExit(ref Landmine __instance, Collider other) { if (!s_IsEnabled) { return true; } if (!((Component)other).CompareTag("PlayerRagdoll")) { return ((Component)other).CompareTag("Player"); } return true; } } internal class ResetAllPlayerScales : AbstractCommand { public ResetAllPlayerScales() : base("ResetAllPlayerScales") { } protected override bool OnCommand(ParseableMessage msg) { //IL_004a: Unknown result type (might be due to invalid IL or missing references) if (!msg.IsTargetLocal()) { return true; } PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts; foreach (PlayerControllerB val in allPlayerScripts) { if (val.isPlayerControlled && (val.isHostPlayerObject || val.actualClientId != 0L)) { ((Component)val).transform.localScale = new Vector3(1f, 1f, 1f); } } return true; } } internal class SetPlayerScale : AbstractCommand { private class DeactivateComponent : MonoBehaviour { private void Update() { ((Component)this).gameObject.SetActive(false); } } internal class DeadBodySFX : MonoBehaviour { private static AudioClip s_AudioClip; private AudioSource m_Source; private DeadBodyInfo m_Body; private float m_Theta; private bool m_HasAudioPlayed; private void Start() { Plugin.LOGGER.LogInfo((object)"DeadBodySFX Starting!"); if ((Object)(object)s_AudioClip == (Object)null) { float[] array = Util.ByteAudioToFloat(Util.LoadEmbeddedResource("LCSyncTool.Resources.AmongUsDeadBodySFX.wav")); s_AudioClip = AudioClip.Create("AmongUsSFX", array.Length, 2, 48000, false); s_AudioClip.SetData(array, 0); } m_Source = ((Component)this).gameObject.AddComponent<AudioSource>(); m_Body = ((Component)this).GetComponentInParent<DeadBodyInfo>(); } private void Update() { //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)m_Body == (Object)null) && !((Object)(object)StartOfRound.Instance == (Object)null) && m_Body.seenByLocalPlayer && !(m_Theta > 2.75f)) { if (!m_HasAudioPlayed) { m_Source.PlayOneShot(s_AudioClip); m_HasAudioPlayed = true; } Transform transform = ((Component)m_Body).transform; Transform transform2 = ((Component)StartOfRound.Instance.localPlayerController).transform; Quaternion val = Quaternion.LookRotation(transform.position - transform2.position); transform2.rotation = Quaternion.Lerp(transform2.rotation, val, 10f * Time.deltaTime); m_Theta += Time.deltaTime; if (m_Theta > 2.75f) { m_Source.Stop(); } } } private void OnDestroy() { Plugin.LOGGER.LogInfo((object)"DeadBodySFX Destroyed!"); } } private static Dictionary<string, Vector3> s_OriginalScales = new Dictionary<string, Vector3>(); private static Dictionary<string, Vector3> s_OriginalOffsets = new Dictionary<string, Vector3>(); public SetPlayerScale() : base("SetPlayerScale") { } protected override bool OnCommand(ParseableMessage msg) { //IL_0049: Unknown result type (might be due to invalid IL or missing references) if (!msg.IsTargetLocal()) { return true; } if (!msg.GetULong(1, out var v)) { return true; } if (!msg.GetVec3(2, out var v2)) { return true; } PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts; foreach (PlayerControllerB val in allPlayerScripts) { if (val.actualClientId == v) { ((Component)val).transform.localScale = v2; } } return true; } [HarmonyPatch(typeof(PlayerControllerB), "Start")] [HarmonyPrefix] private static void RemoveVisor() { GameObject val = GameObject.Find("PlayerHUDHelmetModel"); if ((Object)(object)val != (Object)null) { val.AddComponent<DeactivateComponent>(); } } [HarmonyPatch(typeof(PlayerControllerB), "SwitchToItemSlot")] [HarmonyPrefix] private static void SetHeldObjectScalePrefix(ref PlayerControllerB __instance, ref int slot, ref GrabbableObject fillSlotWithItem) { //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Unknown result type (might be due to invalid IL or missing references) //IL_010e: Unknown result type (might be due to invalid IL or missing references) string text = (((Object)(object)fillSlotWithItem == (Object)null) ? "Null" : fillSlotWithItem.itemProperties.itemName); Plugin.LOGGER.LogInfo((object)("[Switch Held Object Prefix] :: '" + text + "'")); if ((Object)(object)fillSlotWithItem != (Object)null) { s_OriginalScales.TryAdd(fillSlotWithItem.itemProperties.itemName, ((Component)fillSlotWithItem).transform.localScale); s_OriginalOffsets.TryAdd(fillSlotWithItem.itemProperties.itemName, fillSlotWithItem.itemProperties.positionOffset); } GrabbableObject currentlyHeldObjectServer = __instance.currentlyHeldObjectServer; if (!((Object)(object)currentlyHeldObjectServer == (Object)null)) { Item itemProperties = currentlyHeldObjectServer.itemProperties; if (!s_OriginalScales.TryAdd(itemProperties.itemName, ((Component)currentlyHeldObjectServer).transform.localScale) && !s_OriginalOffsets.TryAdd(itemProperties.itemName, currentlyHeldObjectServer.itemProperties.positionOffset)) { ((Component)currentlyHeldObjectServer).transform.localScale = s_OriginalScales[itemProperties.itemName]; currentlyHeldObjectServer.itemProperties.positionOffset = s_OriginalOffsets[itemProperties.itemName]; } } } [HarmonyPatch(typeof(PlayerControllerB), "SwitchToItemSlot")] [HarmonyPostfix] private static void SetHeldObjectScalePostfix(ref PlayerControllerB __instance) { //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_015d: Unknown result type (might be due to invalid IL or missing references) //IL_0163: Unknown result type (might be due to invalid IL or missing references) //IL_016e: Unknown result type (might be due to invalid IL or missing references) //IL_0174: Unknown result type (might be due to invalid IL or missing references) //IL_017f: Unknown result type (might be due to invalid IL or missing references) //IL_0185: Unknown result type (might be due to invalid IL or missing references) //IL_0190: Unknown result type (might be due to invalid IL or missing references) //IL_01a0: Unknown result type (might be due to invalid IL or missing references) //IL_01a6: Unknown result type (might be due to invalid IL or missing references) //IL_01b1: Unknown result type (might be due to invalid IL or missing references) //IL_01b7: Unknown result type (might be due to invalid IL or missing references) //IL_01c2: Unknown result type (might be due to invalid IL or missing references) //IL_01c8: Unknown result type (might be due to invalid IL or missing references) //IL_01d3: Unknown result type (might be due to invalid IL or missing references) //IL_01d8: Unknown result type (might be due to invalid IL or missing references) //IL_012e: Unknown result type (might be due to invalid IL or missing references) GrabbableObject currentlyHeldObjectServer = __instance.currentlyHeldObjectServer; if ((Object)(object)currentlyHeldObjectServer == (Object)null) { return; } Item itemProperties = currentlyHeldObjectServer.itemProperties; s_OriginalScales.TryAdd(itemProperties.itemName, ((Component)currentlyHeldObjectServer).transform.localScale); if (!s_OriginalScales.TryGetValue(itemProperties.itemName, out var value)) { Plugin.LOGGER.LogInfo((object)("Item '" + itemProperties.itemName + "' does not contain an original scale...")); return; } if (!s_OriginalOffsets.TryGetValue(itemProperties.itemName, out var value2)) { Plugin.LOGGER.LogInfo((object)("Item '" + itemProperties.itemName + "' does not contain an original scale...")); return; } Vector3 localScale = ((Component)__instance).transform.localScale; if (!(localScale.x > 0.99f)) { if (!new Dictionary<string, float> { ["Jar of pickles"] = 0.33f, ["Large axle"] = 0.33f, ["Cash register"] = 0.33f, ["V-type engine"] = 0.33f, ["Chemical jug"] = 0.33f, ["Bottles"] = 0.66f }.TryGetValue(itemProperties.itemName, out var value3)) { value3 = ((!(Mathf.Abs(localScale.x - 1f) <= float.Epsilon)) ? 0.95f : 1f); } ((Component)currentlyHeldObjectServer).transform.localScale = new Vector3(value.x * localScale.x * value3, value.y * localScale.y * value3, value.z * localScale.z * value3); currentlyHeldObjectServer.itemProperties.positionOffset = new Vector3(value2.x * localScale.x * value3, value2.y * localScale.y * value3, value2.z * localScale.z * value3); } } [HarmonyPatch(typeof(DeadBodyInfo), "Update")] [HarmonyPrefix] private static void SetDeadBodyScale(ref DeadBodyInfo __instance) { //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) if (__instance.deactivated || (Object)(object)__instance.playerScript == (Object)null) { return; } Vector3 localScale = ((Component)__instance.playerScript).transform.localScale; Rigidbody[] bodyParts = __instance.bodyParts; foreach (Rigidbody val in bodyParts) { if (!((Object)(object)val == (Object)null)) { ((Component)val).transform.localScale = new Vector3(Mathf.Clamp(localScale.x, 0.75f, 1.5f), Mathf.Clamp(localScale.y, 0.75f, 1.5f), Mathf.Clamp(localScale.z, 0.75f, 1.5f)); } } } [HarmonyPatch(typeof(DeadBodyInfo), "Start")] [HarmonyPrefix] private static void PlaySFXOnDeath(ref DeadBodyInfo __instance) { if ((Object)(object)((Component)__instance).GetComponent<DeadBodySFX>() == (Object)null) { ((Component)__instance).gameObject.AddComponent<DeadBodySFX>(); } } } internal class SetEnemyScale : AbstractCommand { public SetEnemyScale() : base("SetEnemyScale") { } protected override bool OnCommand(ParseableMessage msg) { //IL_0052: Unknown result type (might be due to invalid IL or missing references) if (!msg.IsTargetLocal()) { return true; } if (!msg.GetULong(1, out var v)) { return true; } if (!msg.GetVec3(2, out var v2)) { return true; } foreach (EnemyAI spawnedEnemy in RoundManager.Instance.SpawnedEnemies) { if (spawnedEnemy.thisNetworkObject.NetworkObjectId == v) { ((Component)spawnedEnemy).transform.localScale = v2; break; } } return true; } } internal class SetForceToAllBodyParts : AbstractCommand { private static Dictionary<ulong, Coroutine> m_CoroutineMap = new Dictionary<ulong, Coroutine>(); public SetForceToAllBodyParts() : base("SetForceToAllBodyParts") { } protected override bool OnCommand(ParseableMessage msg) { //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Unknown result type (might be due to invalid IL or missing references) if (!msg.IsTargetLocal()) { return true; } if (!msg.GetULong(1, out var v)) { return true; } if (!msg.GetVec3(2, out var v2)) { return true; } if (!msg.GetVec3(3, out var v3)) { return true; } if (!msg.GetVec3(4, out var v4)) { return true; } PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts; foreach (PlayerControllerB val in allPlayerScripts) { if (val.isPlayerDead && (val.actualClientId != 0L || val.isHostPlayerObject) && val.actualClientId == v) { ((Component)val.deadBody).transform.position = v3; Rigidbody[] bodyParts = val.deadBody.bodyParts; for (int j = 0; j < bodyParts.Length; j++) { bodyParts[j].AddForce(v2, (ForceMode)1); } ulong actualClientId = val.actualClientId; PlayerControllerB localPlayerController = StartOfRound.Instance.localPlayerController; if (m_CoroutineMap.TryGetValue(actualClientId, out var value)) { ((MonoBehaviour)localPlayerController).StopCoroutine(value); } m_CoroutineMap[actualClientId] = ((MonoBehaviour)localPlayerController).StartCoroutine(SyncFinalPosition(val.deadBody, v4)); return true; } } return true; static IEnumerator SyncFinalPosition(DeadBodyInfo body, Vector3 final_pos) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) yield return (object)new WaitForSeconds(1f); if (!((Object)(object)body.playerScript == (Object)null)) { ((Component)body).transform.position = final_pos; } } } } internal class DisplayTipMessage : AbstractCommand { public DisplayTipMessage() : base("DisplayTipOnHUD") { } protected override bool OnCommand(ParseableMessage msg) { if (!msg.IsTargetLocal()) { return true; } if (!msg.GetStr(1, out var v)) { return true; } if (!msg.GetStr(2, out var v2)) { return true; } HUDManager instance = HUDManager.Instance; if ((Object)(object)instance == (Object)null) { return true; } instance.DisplayTip(v, v2, false, false, "LC_Tip1"); return true; } } internal class SetQuotaParams : AbstractCommand { public SetQuotaParams() : base("SetQuotaParams") { } protected override bool OnCommand(ParseableMessage msg) { if (!msg.IsTargetLocal()) { return true; } TimeOfDay instance = TimeOfDay.Instance; StartOfRound instance2 = StartOfRound.Instance; if ((Object)(object)instance == (Object)null || (Object)(object)instance2 == (Object)null) { Plugin.LOGGER.LogError((object)"TimeOfDay and or StartOfRound is null..."); return true; } if (!msg.GetInt(1, out var v)) { return true; } if (!msg.GetFloat(2, out var v2)) { return true; } instance.daysUntilDeadline = v; instance2.companyBuyingRate = v2; return true; } } public static class PluginInfo { public const string PLUGIN_GUID = "LCSyncTool"; public const string PLUGIN_NAME = "LCSyncTool"; public const string PLUGIN_VERSION = "1.0.0"; } }