Decompiled source of ColourfulFlashlights v2.2.1

ColourfulFlashlights.dll

Decompiled 11 months ago
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using TerminalApi;
using TerminalApi.Events;
using Unity.Netcode;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("ColourfulFlashlights")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ColourfulFlashlights")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("35a79675-215d-4715-be09-288b1d07a711")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
internal class <Module>
{
	static <Module>()
	{
	}
}
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 ColourfulFlashlights
{
	public static class Assets
	{
		public static AssetBundle MainAssetBundle;

		public static void PopulateAssets(string streamName)
		{
			if ((Object)(object)MainAssetBundle == (Object)null)
			{
				MainAssetBundle = AssetBundle.LoadFromMemory(Resources.asset);
			}
		}
	}
	public static class ColourData
	{
		private static readonly Dictionary<string, Color> Colours = new Dictionary<string, Color>
		{
			{
				"blue",
				Color.blue
			},
			{
				"red",
				Color.red
			},
			{
				"green",
				Color.green
			},
			{
				"yellow",
				Color.yellow
			},
			{
				"white",
				Color.white
			},
			{
				"pink",
				Helpers.StringToColor("#FF73FF")
			},
			{
				"orange",
				Helpers.StringToColor("#FF6400")
			},
			{
				"purple",
				Helpers.StringToColor("#7800DC")
			}
		};

		public static Color? GetColour(string colourName)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			if (Colours.TryGetValue(colourName.ToLower(), out var value))
			{
				return value;
			}
			return null;
		}
	}
	public static class Helpers
	{
		private static string persistentDataPath = Application.persistentDataPath + "\\ColourfulFlashlights.txt";

		public static string SerializeDict(Dictionary<int, string> dict)
		{
			return JsonConvert.SerializeObject((object)dict);
		}

		public static Dictionary<int, string> DeserializeDict(string serialized)
		{
			return JsonConvert.DeserializeObject<Dictionary<int, string>>(serialized);
		}

		public static Color StringToColor(string value)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//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)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			Color result = default(Color);
			if (ColorUtility.TryParseHtmlString(value, ref result))
			{
				return result;
			}
			return Color.white;
		}

		public static string ColorToHexString(Color colour)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			string text = ColorUtility.ToHtmlStringRGB(colour);
			return "#" + text;
		}

		public static void WriteCFValue(Color color)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				File.WriteAllText(persistentDataPath, ColorToHexString(color));
			}
			catch (IOException ex)
			{
				Plugin.mls.LogError((object)"ColourfulFlashlights - Failed to write ColourfulFlashlights.txt");
				Plugin.mls.LogError((object)ex.ToString());
			}
		}

		public static Color ReadCFValue()
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (File.Exists(persistentDataPath))
				{
					return StringToColor(File.ReadAllText(persistentDataPath));
				}
				return Color.white;
			}
			catch (IOException ex)
			{
				Plugin.mls.LogError((object)"ColourfulFlashlights - Failed to read ColourfulFlashlights.txt");
				Plugin.mls.LogError((object)ex.ToString());
				return Color.white;
			}
		}
	}
	public class NetworkHandler : NetworkBehaviour
	{
		public static NetworkHandler Instance;

		public override void OnNetworkSpawn()
		{
			((NetworkBehaviour)this).OnNetworkSpawn();
		}

		private void Awake()
		{
			Instance = this;
		}

		public void UpdateColourData(int playerId, string colour, bool justSpawned = false)
		{
			if (((NetworkBehaviour)this).IsOwner)
			{
				UpdateColourDataClientRpc(playerId, colour);
			}
			else
			{
				UpdateColourDataServerRpc(playerId, colour, justSpawned);
			}
		}

		[ClientRpc]
		public void UpdateColourDataClientRpc(int playerId, string colour)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: 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)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(3043746830u, val, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val2, playerId);
				bool flag = colour != null;
				((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
				if (flag)
				{
					((FastBufferWriter)(ref val2)).WriteValueSafe(colour, false);
				}
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 3043746830u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
			{
				Plugin.playerData[playerId] = colour;
				Plugin.mls.LogInfo((object)$"CLIENTRPC - UPDATING {playerId} COLOUR TO {colour}");
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void UpdateColourDataServerRpc(int playerId, string colour, bool justSpawned = true)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: 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)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				ServerRpcParams val = default(ServerRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(4000546698u, val, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val2, playerId);
				bool flag = colour != null;
				((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
				if (flag)
				{
					((FastBufferWriter)(ref val2)).WriteValueSafe(colour, false);
				}
				((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref justSpawned, default(ForPrimitives));
				((NetworkBehaviour)this).__endSendServerRpc(ref val2, 4000546698u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				UpdateColourDataClientRpc(playerId, colour);
				Plugin.mls.LogInfo((object)$"SERVERRPC - UPDATING {playerId} COLOUR TO {colour}");
				if (justSpawned)
				{
					ClientRpcParams val3 = default(ClientRpcParams);
					val3.Send = new ClientRpcSendParams
					{
						TargetClientIds = new ulong[1] { (ulong)playerId }
					};
					ClientRpcParams clientRpcParams = val3;
					string serializedData = Helpers.SerializeDict(Plugin.playerData);
					GetColourDataClientRpc(playerId, serializedData, clientRpcParams);
					Plugin.mls.LogInfo((object)$"SERVERRPC - GETTING PLAYERDATA FOR {playerId}");
				}
			}
		}

		[ClientRpc]
		public void GetColourDataClientRpc(int playerId, string serializedData, ClientRpcParams clientRpcParams = default(ClientRpcParams))
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: 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)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				FastBufferWriter val = ((NetworkBehaviour)this).__beginSendClientRpc(1967303990u, clientRpcParams, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val, playerId);
				bool flag = serializedData != null;
				((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
				if (flag)
				{
					((FastBufferWriter)(ref val)).WriteValueSafe(serializedData, false);
				}
				((NetworkBehaviour)this).__endSendClientRpc(ref val, 1967303990u, clientRpcParams, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
			{
				Plugin.playerData = Helpers.DeserializeDict(serializedData);
				if (!Plugin.playerData.ContainsKey(Plugin.currentPlayerId))
				{
					Plugin.playerData[Plugin.currentPlayerId] = Helpers.ColorToHexString(Plugin.activeColour);
				}
				Plugin.mls.LogInfo((object)$"CLIENTRPC - SENT PLAYERDATA TO {playerId}");
			}
		}

		protected override void __initializeVariables()
		{
			((NetworkBehaviour)this).__initializeVariables();
		}

		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeRPCS_NetworkHandler()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			NetworkManager.__rpc_func_table.Add(3043746830u, new RpcReceiveHandler(__rpc_handler_3043746830));
			NetworkManager.__rpc_func_table.Add(4000546698u, new RpcReceiveHandler(__rpc_handler_4000546698));
			NetworkManager.__rpc_func_table.Add(1967303990u, new RpcReceiveHandler(__rpc_handler_1967303990));
		}

		private static void __rpc_handler_3043746830(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: 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)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				int playerId = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref playerId);
				bool flag = default(bool);
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives));
				string colour = null;
				if (flag)
				{
					((FastBufferReader)(ref reader)).ReadValueSafe(ref colour, false);
				}
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((NetworkHandler)(object)target).UpdateColourDataClientRpc(playerId, colour);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_4000546698(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: 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)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: 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)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				int playerId = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref playerId);
				bool flag = default(bool);
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives));
				string colour = null;
				if (flag)
				{
					((FastBufferReader)(ref reader)).ReadValueSafe(ref colour, false);
				}
				bool justSpawned = default(bool);
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref justSpawned, default(ForPrimitives));
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((NetworkHandler)(object)target).UpdateColourDataServerRpc(playerId, colour, justSpawned);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_1967303990(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: 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)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: 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_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				int playerId = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref playerId);
				bool flag = default(bool);
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives));
				string serializedData = null;
				if (flag)
				{
					((FastBufferReader)(ref reader)).ReadValueSafe(ref serializedData, false);
				}
				ClientRpcParams client = rpcParams.Client;
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((NetworkHandler)(object)target).GetColourDataClientRpc(playerId, serializedData, client);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		protected internal override string __getTypeName()
		{
			return "NetworkHandler";
		}
	}
	[HarmonyPatch]
	public class NetworkObjectManager
	{
		public static GameObject networkHandlerHost;

		private static GameObject networkPrefab;

		[HarmonyPostfix]
		[HarmonyPatch(typeof(GameNetworkManager), "Start")]
		public static void Init()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			if (!((Object)(object)networkPrefab != (Object)null))
			{
				networkPrefab = (GameObject)Assets.MainAssetBundle.LoadAsset("CFNetwork");
				networkPrefab.AddComponent<NetworkHandler>();
				NetworkManager.Singleton.AddNetworkPrefab(networkPrefab);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(StartOfRound), "Awake")]
		private static void SpawnNetworkHandler()
		{
			if (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer)
			{
				networkHandlerHost = Object.Instantiate<GameObject>(networkPrefab);
				networkHandlerHost.GetComponent<NetworkObject>().Spawn(true);
			}
		}
	}
	public static class Patches
	{
		[HarmonyPatch(typeof(FlashlightItem))]
		public class CFFlashlightItemPatch
		{
			[HarmonyPatch("SwitchFlashlight")]
			[HarmonyPostfix]
			public static void SwitchFlashlightPatch(FlashlightItem __instance)
			{
				//IL_0040: Unknown result type (might be due to invalid IL or missing references)
				//IL_0045: Unknown result type (might be due to invalid IL or missing references)
				//IL_0063: Unknown result type (might be due to invalid IL or missing references)
				//IL_0068: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ca: 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_00e9: Unknown result type (might be due to invalid IL or missing references)
				//IL_0100: 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_007e: Unknown result type (might be due to invalid IL or missing references)
				//IL_008b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0090: Unknown result type (might be due to invalid IL or missing references)
				if (!((Object)(object)__instance != (Object)null))
				{
					return;
				}
				int num = (int)((GrabbableObject)__instance).playerHeldBy.playerClientId;
				if (!Plugin.ConfigSyncOthers.Value && num != Plugin.currentPlayerId)
				{
					return;
				}
				Color val = Color.white;
				if (Plugin.playerData.ContainsKey(num))
				{
					val = Helpers.StringToColor(Plugin.playerData[num]);
				}
				if (num == Plugin.currentPlayerId)
				{
					val = Plugin.activeColour;
					if (Plugin.firstFlashlight)
					{
						if (Plugin.activeColour == Color.white)
						{
							HUDManager.Instance.DisplayTip("Change flashlight colour!", "Type 'cf' into the ship terminal for guidance!", false, false, "LC_Tip1");
						}
						Plugin.firstFlashlight = false;
					}
				}
				__instance.flashlightBulb.color = val;
				__instance.flashlightBulbGlow.color = val;
				((GrabbableObject)__instance).playerHeldBy.helmetLight.color = val;
				Plugin.mls.LogInfo((object)$"SwitchFlash - owner id: {num} - activecolour: {Helpers.ColorToHexString(val)}");
			}
		}

		[HarmonyPatch(typeof(PlayerControllerB))]
		public class CFPlayerControllerBPatch
		{
			[HarmonyPatch("SpawnPlayerAnimation")]
			[HarmonyPostfix]
			public static void SpawnPlayerPatch(PlayerControllerB __instance)
			{
				//IL_0009: Unknown result type (might be due to invalid IL or missing references)
				//IL_0020: Unknown result type (might be due to invalid IL or missing references)
				int num = (int)__instance.playerClientId;
				string text = Helpers.ColorToHexString(Plugin.activeColour);
				Plugin.currentPlayerId = num;
				Plugin.playerData[num] = Helpers.ColorToHexString(Plugin.activeColour);
				Plugin.mls.LogInfo((object)$"Player spawned with client id: {num}, colour: {text}");
				NetworkHandler.Instance.UpdateColourData(num, text, justSpawned: true);
			}
		}
	}
	[BepInPlugin("Cubly.ColourfulFlashlights", "ColourfulFlashlights", "2.2.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		private const string MOD_NAME = "ColourfulFlashlights";

		private const string MOD_GUID = "Cubly.ColourfulFlashlights";

		public const string MOD_VERSION = "2.2.0";

		private readonly Harmony harmony = new Harmony("Cubly.ColourfulFlashlights");

		public static Plugin Instance;

		public static ManualLogSource mls;

		public static ConfigEntry<string> ConfigHex1;

		public static ConfigEntry<string> ConfigHex2;

		public static ConfigEntry<string> ConfigHex3;

		public static ConfigEntry<bool> ConfigSyncOthers;

		public static ConfigEntry<bool> ConfigPersist;

		public static Dictionary<int, string> playerData = new Dictionary<int, string>();

		public static int currentPlayerId;

		public static bool firstFlashlight = true;

		public static Color activeColour = Color.white;

		private void Awake()
		{
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("Cubly.ColourfulFlashlights");
			ConfigHex1 = ((BaseUnityPlugin)this).Config.Bind<string>("Flashlight Colour", "cfcustom1", "#7BF286", "A hex colour value (e.g #FF00BB)");
			ConfigHex2 = ((BaseUnityPlugin)this).Config.Bind<string>("Flashlight Colour", "cfcustom2", "#EFB8EC", "A hex colour value (e.g #FF00BB)");
			ConfigHex3 = ((BaseUnityPlugin)this).Config.Bind<string>("Flashlight Colour", "cfcustom3", "#6456D0", "A hex colour value (e.g #FF00BB)");
			ConfigSyncOthers = ((BaseUnityPlugin)this).Config.Bind<bool>("Flashlight Colour", "Sync others", true, "If true, you will sync flashlight colours with other players.");
			ConfigPersist = ((BaseUnityPlugin)this).Config.Bind<bool>("Flashlight Colour", "Persist colour", true, "If true, the last used flashlight colour will be loaded on game startup.");
			if (ConfigPersist.Value)
			{
				activeColour = Helpers.ReadCFValue();
			}
			harmony.PatchAll();
			Assets.PopulateAssets("ColourfulFlashlights.Properties.Resources.asset");
			Terminal.Init();
			NetcodeWeaver();
			mls.LogInfo((object)"ColourfulFlashlights loaded");
		}

		private static void NetcodeWeaver()
		{
			Type[] types = Assembly.GetExecutingAssembly().GetTypes();
			Type[] array = types;
			foreach (Type type in array)
			{
				MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
				MethodInfo[] array2 = methods;
				foreach (MethodInfo methodInfo in array2)
				{
					object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false);
					if (customAttributes.Length != 0)
					{
						methodInfo.Invoke(null, null);
					}
				}
			}
		}
	}
	[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
	[DebuggerNonUserCode]
	[CompilerGenerated]
	internal class Resources
	{
		private static ResourceManager resourceMan;

		private static CultureInfo resourceCulture;

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static ResourceManager ResourceManager
		{
			get
			{
				if (resourceMan == null)
				{
					ResourceManager resourceManager = new ResourceManager("ColourfulFlashlights.Resources", typeof(Resources).Assembly);
					resourceMan = resourceManager;
				}
				return resourceMan;
			}
		}

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static CultureInfo Culture
		{
			get
			{
				return resourceCulture;
			}
			set
			{
				resourceCulture = value;
			}
		}

		internal static byte[] asset
		{
			get
			{
				object @object = ResourceManager.GetObject("asset", resourceCulture);
				return (byte[])@object;
			}
		}

		internal Resources()
		{
		}
	}
	public static class Terminal
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static TerminalParseSentenceEventHandler <0>__TextSubmitted;

			public static TerminalTextChangedEventHandler <1>__OnTerminalTextChanged;
		}

		private static string cmdList = "Commands - Basic usage: cf <option> <arg>\n\ncf blue\ncf red\ncf green\ncf white\ncf yellow\ncf orange\ncf pink\ncf purple\ncf custom <1,2,3>   [e.g cf custom 2]\ncf hex <code>   [e.g cf hex #FF00CC]\ncf list";

		public static void Init()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_0032: 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_003d: Expected O, but got Unknown
			object obj = <>O.<0>__TextSubmitted;
			if (obj == null)
			{
				TerminalParseSentenceEventHandler val = TextSubmitted;
				<>O.<0>__TextSubmitted = val;
				obj = (object)val;
			}
			Events.TerminalParsedSentence += (TerminalParseSentenceEventHandler)obj;
			object obj2 = <>O.<1>__OnTerminalTextChanged;
			if (obj2 == null)
			{
				TerminalTextChangedEventHandler val2 = OnTerminalTextChanged;
				<>O.<1>__OnTerminalTextChanged = val2;
				obj2 = (object)val2;
			}
			Events.TerminalTextChanged += (TerminalTextChangedEventHandler)obj2;
			TerminalApi.AddCommand("cf", "Colourful flashlights", (string)null, true);
		}

		public static void TextSubmitted(object sender, TerminalParseSentenceEventArgs e)
		{
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			if (e.SubmittedText == "cf")
			{
				e.ReturnedNode.displayText = "Colourful Flashlights | Version 2.2.0\nBy cubly\n\nChange your flashlight to shine whatever colour you like!\n\nType 'cf list' for a list of commands!\n\n";
			}
			else
			{
				if (!e.SubmittedText.StartsWith("cf "))
				{
					return;
				}
				string[] array = e.SubmittedText.Split(new char[1] { ' ' });
				if (array[1] == "hex")
				{
					if (array[2] == null)
					{
						e.ReturnedNode.displayText = "[Colourful Flashlights]\nERROR! Please provide a valid hexadecimal colour code!\nCommand usage: cf hex <code>\nExample: cf hex #ffcc00\n";
						return;
					}
					string text = array[2];
					if (Regex.IsMatch(text, "^#(?:[0-9a-fA-F]{3}){1,2}$"))
					{
						UpdateActiveColour(Helpers.StringToColor(text), e.ReturnedNode);
					}
					else
					{
						e.ReturnedNode.displayText = "[Colourful Flashlights]\nERROR! Please provide a valid hexadecimal colour code!\nCommand usage: cf hex <code>\nExample: cf hex #ffcc00\n";
					}
					return;
				}
				if (array[1] == "custom")
				{
					if (array[2] != null)
					{
						switch (array[2])
						{
						case "1":
							UpdateActiveColour(Helpers.StringToColor(Plugin.ConfigHex1.Value), e.ReturnedNode);
							break;
						case "2":
							UpdateActiveColour(Helpers.StringToColor(Plugin.ConfigHex2.Value), e.ReturnedNode);
							break;
						case "3":
							UpdateActiveColour(Helpers.StringToColor(Plugin.ConfigHex3.Value), e.ReturnedNode);
							break;
						default:
							e.ReturnedNode.displayText = "[Colourful Flashlights]\nERROR! Please enter only values: 1, 2 or 3!\n\nCommand usage: cf custom <value>\n\nExample: cf custom 1\n\n";
							break;
						}
					}
					else
					{
						e.ReturnedNode.displayText = "Colourful Flashlights | Version 2.2.0\nBy cubly\n\nChange your flashlight to shine whatever colour you like!\n\nType 'cf list' for a list of commands!\n\n";
					}
					return;
				}
				if (array[1] == "list")
				{
					e.ReturnedNode.displayText = "[Colourful Flashlights]\n" + cmdList + "\n\n";
					return;
				}
				Color? colour = ColourData.GetColour(array[1]);
				if (array[1] != null)
				{
					if (colour.HasValue)
					{
						UpdateActiveColour(colour.Value, e.ReturnedNode);
					}
					else
					{
						e.ReturnedNode.displayText = "[Colourful Flashlights]\nERROR! Please provide a valid colour or option from the list below!\n" + cmdList + "\n\n";
					}
				}
				else
				{
					e.ReturnedNode.displayText = "Colourful Flashlights | Version 2.2.0\nBy cubly\n\nPlease use 'cf list' for commands!\n\n";
				}
			}
		}

		private static void OnTerminalTextChanged(object sender, TerminalTextChangedEventArgs e)
		{
			string terminalInput = TerminalApi.GetTerminalInput();
			if (terminalInput.StartsWith("cf"))
			{
				if (terminalInput == "cfred")
				{
					TerminalApi.SetTerminalInput("cf red");
				}
				if (terminalInput == "cfblue")
				{
					TerminalApi.SetTerminalInput("cf blue");
				}
				if (terminalInput == "cfyellow")
				{
					TerminalApi.SetTerminalInput("cf yellow");
				}
				if (terminalInput == "cforange")
				{
					TerminalApi.SetTerminalInput("cf orange");
				}
				if (terminalInput == "cfwhite")
				{
					TerminalApi.SetTerminalInput("cf white");
				}
				if (terminalInput == "cfpurple")
				{
					TerminalApi.SetTerminalInput("cf purple");
				}
				if (terminalInput == "cfpink")
				{
					TerminalApi.SetTerminalInput("cf pink");
				}
				if (terminalInput == "cfgreen")
				{
					TerminalApi.SetTerminalInput("cf green");
				}
				if (terminalInput == "cfcustom")
				{
					TerminalApi.SetTerminalInput("cf custom");
				}
				if (terminalInput == "cf custom1")
				{
					TerminalApi.SetTerminalInput("cf custom 1");
				}
				if (terminalInput == "cf custom2")
				{
					TerminalApi.SetTerminalInput("cf custom 2");
				}
				if (terminalInput == "cf custom3")
				{
					TerminalApi.SetTerminalInput("cf custom 3");
				}
				if (terminalInput == "cfcustom1")
				{
					TerminalApi.SetTerminalInput("cf custom 1");
				}
				if (terminalInput == "cfcustom2")
				{
					TerminalApi.SetTerminalInput("cf custom 2");
				}
				if (terminalInput == "cfcustom3")
				{
					TerminalApi.SetTerminalInput("cf custom 3");
				}
				if (terminalInput == "cfhex")
				{
					TerminalApi.SetTerminalInput("cf hex");
				}
				if (terminalInput == "cflist")
				{
					TerminalApi.SetTerminalInput("cf list");
				}
			}
		}

		private static void UpdateActiveColour(Color color, TerminalNode e)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			e.displayText = "[Colourful Flashlights]\nSUCCESS! Flashlight colour updated!\n\nToggle your flashlight for your new colour!\n\n";
			Plugin.activeColour = color;
			Helpers.WriteCFValue(color);
			if (Plugin.ConfigSyncOthers.Value)
			{
				NetworkHandler.Instance.UpdateColourData(Plugin.currentPlayerId, Helpers.ColorToHexString(color));
			}
		}
	}
}