Decompiled source of MonsterHotkeys v1.3.6

com.github.zehsteam.MonsterHotkeys.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net.Sockets;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using DunGen;
using DunGen.Graph;
using GameNetcodeStuff;
using HarmonyLib;
using LethalCompanyInputUtils.Api;
using LethalConfig;
using LethalConfig.ConfigItems;
using LethalConfig.ConfigItems.Options;
using Microsoft.CodeAnalysis;
using TMPro;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.InputSystem;
using UnityEngine.UI;
using com.github.zehsteam.MonsterHotkeys.Data;
using com.github.zehsteam.MonsterHotkeys.Dependencies;
using com.github.zehsteam.MonsterHotkeys.MonoBehaviours;
using com.github.zehsteam.MonsterHotkeys.NetcodePatcher;
using com.github.zehsteam.MonsterHotkeys.Patches;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.github.zehsteam.MonsterHotkeys")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Spawn Monsters and Monster Plushies using hotkeys. Highly Configurable.")]
[assembly: AssemblyFileVersion("1.3.6.0")]
[assembly: AssemblyInformationalVersion("1.3.6+74aed77aeddbef7a5ae3ac19928322d8e7df129e")]
[assembly: AssemblyProduct("MonsterHotkeys")]
[assembly: AssemblyTitle("com.github.zehsteam.MonsterHotkeys")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.3.6.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
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 com.github.zehsteam.MonsterHotkeys
{
	internal static class ConfigHelper
	{
		public static ConfigEntry<T> Bind<T>(string section, string key, T defaultValue, bool requiresRestart, string description, AcceptableValueBase acceptableValues = null, Action<T> settingChanged = null, ConfigFile configFile = null)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Expected O, but got Unknown
			if (configFile == null)
			{
				configFile = ((BaseUnityPlugin)Plugin.Instance).Config;
			}
			ConfigEntry<T> configEntry = ((acceptableValues == null) ? configFile.Bind<T>(section, key, defaultValue, description) : configFile.Bind<T>(section, key, defaultValue, new ConfigDescription(description, acceptableValues, Array.Empty<object>())));
			if (settingChanged != null)
			{
				configEntry.SettingChanged += delegate
				{
					settingChanged?.Invoke(configEntry.Value);
				};
			}
			if (LethalConfigProxy.Enabled)
			{
				if (acceptableValues == null)
				{
					LethalConfigProxy.AddConfig<T>(configEntry, requiresRestart);
				}
				else
				{
					LethalConfigProxy.AddConfigSlider<T>(configEntry, requiresRestart);
				}
			}
			return configEntry;
		}
	}
	internal static class Content
	{
		public static GameObject NetworkHandlerPrefab;

		public static GameObject MessageCanvasPrefab;

		public static EnemyDataList EnemyDataList;

		public static Sprite ModIcon;

		public static void Load()
		{
			LoadAssetsFromAssetBundle();
		}

		private static void LoadAssetsFromAssetBundle()
		{
			try
			{
				string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)Plugin.Instance).Info.Location);
				string text = Path.Combine(directoryName, "monsterhotkeys_assets");
				AssetBundle val = AssetBundle.LoadFromFile(text);
				NetworkHandlerPrefab = val.LoadAsset<GameObject>("NetworkHandler");
				MessageCanvasPrefab = val.LoadAsset<GameObject>("MonsterHotkeysCanvas");
				EnemyDataList = val.LoadAsset<EnemyDataList>("EnemyDataList");
				ModIcon = val.LoadAsset<Sprite>("ModIcon");
				Plugin.logger.LogInfo((object)"Successfully loaded assets from AssetBundle!");
			}
			catch (Exception arg)
			{
				Plugin.logger.LogError((object)$"Failed to load assets from AssetBundle.\n\n{arg}");
			}
		}
	}
	public static class EnemyHelper
	{
		private static List<TwitchSubEvent> _twitchSubEventQueue = new List<TwitchSubEvent>();

		private static List<TwitchBitsEvents> _twitchBitsEventQueue = new List<TwitchBitsEvents>();

		public static void Initialize()
		{
			TwitchEvents.OnSub = (Action<TwitchSubEvent>)Delegate.Combine(TwitchEvents.OnSub, new Action<TwitchSubEvent>(SpawnEnemyFromSub));
			TwitchEvents.OnBits = (Action<TwitchBitsEvents>)Delegate.Combine(TwitchEvents.OnBits, new Action<TwitchBitsEvents>(SpawnEnemyFromBits));
		}

		public static void SpawnEnemy(EnemyData enemyData, string phrase = "")
		{
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			if (CanSpawnEnemy())
			{
				if (enemyData == null)
				{
					Plugin.logger.LogError((object)"Failed to spawn enemy. EnemyData is null.");
				}
				else if (NetworkUtils.IsServer)
				{
					SpawnEnemyOnServer(enemyData, PlayerUtils.GetLocalPlayerScript(), phrase);
				}
				else
				{
					PluginNetworkBehaviour.Instance.SpawnEnemyServerRpc(enemyData.EnemyName, phrase);
				}
			}
		}

		public static void SpawnRandomEnemy(string phrase = "")
		{
			SpawnEnemy(Content.EnemyDataList.GetRandom(PlayerUtils.GetLocalPlayerScript()), phrase);
		}

		public static void SpawnEnemyOnServer(EnemyData enemyData, PlayerControllerB playerScript, string phrase = "")
		{
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: 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_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: 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_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			if (!NetworkUtils.IsServer)
			{
				Plugin.logger.LogError((object)"Failed to spawn enemy. Only the host can spawn enemies.");
				return;
			}
			if (enemyData == null)
			{
				Plugin.logger.LogError((object)"Failed to spawn enemy. EnemyData is null.");
				return;
			}
			EnemyType enemyType = enemyData.EnemyType;
			if ((Object)(object)enemyType == (Object)null)
			{
				Plugin.logger.LogError((object)("Failed to spawn \"" + enemyData.EnemyName + "\" enemy. EnemyType is null."));
				return;
			}
			if ((Object)(object)enemyType.enemyPrefab == (Object)null)
			{
				Plugin.logger.LogError((object)("Failed to spawn \"" + enemyData.EnemyName + "\" enemy. EnemyType.enemyPrefab is null."));
				return;
			}
			if ((Object)(object)playerScript == (Object)null)
			{
				Plugin.logger.LogError((object)("Failed to spawn \"" + enemyData.EnemyName + "\" enemy. PlayerControllerB is null."));
				return;
			}
			int value = enemyData.ConfigData.SpawnCount.Value;
			bool value2 = enemyData.ConfigData.SpawnNearPlayer.Value;
			bool value3 = enemyData.ConfigData.SpawnInFrontOfPlayer.Value;
			Plugin.Instance.LogInfoExtended($"Trying to spawn \"{enemyData.EnemyName}\" enemy. (SpawnCount: {value})");
			List<NetworkObjectReference> list = new List<NetworkObjectReference>();
			List<Vector3> list2 = new List<Vector3>();
			for (int i = 0; i < value; i++)
			{
				Vector3 val = ((value2 && !value3) ? GetSpawnPositionNearPlayer(playerScript, enemyData) : ((!value3) ? GetRandomSpawnPosition(playerScript) : GetSpawnPositionInFrontOfPlayer(playerScript, enemyData)));
				list2.Add(val);
				NetworkObjectReference item = SpawnEnemyAtPositionOnServer(val, enemyType);
				list.Add(item);
				Plugin.Instance.LogInfoExtended($"Spawned \"{enemyData.EnemyName}\" enemy at position: (x: {val.x}, y: {val.y}, z: {val.z})");
			}
			AudioPlayerManager.Instance.SpawnOnServer(enemyData.EnemyName, list2.ToArray(), playerScript.isInsideFactory);
			MessageCanvas.Instance.ShowSpawnEnemyMessageOnServer(enemyData, playerScript, phrase);
			EnemyNametagManager.Instance.SpawnNametagsOnServer(playerScript.playerUsername, playerScript, list.ToArray());
		}

		public static void SpawnEnemyFromSub(TwitchSubEvent twitchSubEvent)
		{
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			if (!CanSpawnEnemy())
			{
				MessageCanvas.Instance?.ShowMessageOnLocalClient("Could not spawn enemies from Twitch sub event from " + twitchSubEvent.Sender);
				MessageCanvas.Instance?.ShowMessageOnLocalClient("Adding Twitch sub event to the queue for the next round");
				_twitchSubEventQueue.Add(twitchSubEvent);
			}
			else if (NetworkUtils.IsServer)
			{
				SpawnEnemyFromSubOnServer(twitchSubEvent, PlayerUtils.GetLocalPlayerScript());
			}
			else
			{
				PluginNetworkBehaviour.Instance.SpawnEnemyFromSubServerRpc(twitchSubEvent);
			}
		}

		public static void SpawnEnemyFromSubOnServer(TwitchSubEvent twitchSubEvent, PlayerControllerB playerScript)
		{
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			if (!NetworkUtils.IsServer)
			{
				Plugin.logger.LogError((object)"Failed to spawn enemy from Twitch sub. Only the host can spawn enemies.");
				return;
			}
			if ((Object)(object)playerScript == (Object)null)
			{
				Plugin.logger.LogError((object)"Failed to spawn enemy from Twitch sub. PlayerControllerB is null.");
				return;
			}
			int num = twitchSubEvent.Amount;
			if (twitchSubEvent.Tier == 2)
			{
				num = twitchSubEvent.Amount * 2;
			}
			if (twitchSubEvent.Tier == 3)
			{
				num = twitchSubEvent.Amount * 6;
			}
			Plugin.Instance.LogInfoExtended($"Trying to spawn {num} enemies from Twitch sub.");
			if (TrySpawnEnemiesForTwitchEventOnServer(twitchSubEvent.Sender, num, playerScript, out var enemyDisplayName))
			{
				MessageCanvas.Instance.ShowSpawnEnemyMessageFromSubOnServer(enemyDisplayName, num, twitchSubEvent, playerScript);
				return;
			}
			MessageCanvas.Instance.ShowMessage("[" + playerScript.playerUsername + "] Failed to spawn enemies from " + twitchSubEvent.Sender + " Twitch sub", Color.yellow);
		}

		public static void SpawnEnemyFromBits(TwitchBitsEvents twitchBitsEvents)
		{
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			if (twitchBitsEvents.Amount >= Plugin.ConfigManager.TwitchBitsEvent_MinAmountToSpawnMonster)
			{
				if (!CanSpawnEnemy())
				{
					MessageCanvas.Instance?.ShowMessageOnLocalClient("Could not spawn enemies from Twitch bits event from " + twitchBitsEvents.Sender);
					MessageCanvas.Instance?.ShowMessageOnLocalClient("Adding Twitch bits event to the queue for the next round");
					_twitchBitsEventQueue.Add(twitchBitsEvents);
				}
				else if (NetworkUtils.IsServer)
				{
					SpawnEnemyFromBitsOnServer(twitchBitsEvents, PlayerUtils.GetLocalPlayerScript());
				}
				else
				{
					PluginNetworkBehaviour.Instance.SpawnEnemyFromBitsServerRpc(twitchBitsEvents);
				}
			}
		}

		public static void SpawnEnemyFromBitsOnServer(TwitchBitsEvents twitchBitsEvents, PlayerControllerB playerScript)
		{
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			if (!NetworkUtils.IsServer)
			{
				Plugin.logger.LogError((object)"Failed to spawn enemy from Twitch bits. Only the host can spawn enemies.");
				return;
			}
			if ((Object)(object)playerScript == (Object)null)
			{
				Plugin.logger.LogError((object)"Failed to spawn enemy from Twitch bits. PlayerControllerB is null.");
				return;
			}
			int twitchBitsEvent_MinAmountToSpawnMonster = Plugin.ConfigManager.TwitchBitsEvent_MinAmountToSpawnMonster;
			int num = (int)Mathf.Floor((float)(twitchBitsEvents.Amount / twitchBitsEvent_MinAmountToSpawnMonster));
			Plugin.Instance.LogInfoExtended($"Trying to spawn {num} enemies from Twitch bits.");
			if (TrySpawnEnemiesForTwitchEventOnServer(twitchBitsEvents.Sender, num, playerScript, out var enemyDisplayName))
			{
				MessageCanvas.Instance.ShowSpawnEnemyMessageFromBitsOnServer(enemyDisplayName, num, twitchBitsEvents, playerScript);
				return;
			}
			MessageCanvas.Instance.ShowMessage("[" + playerScript.playerUsername + "] Failed to spawn enemies from " + twitchBitsEvents.Sender + " Twitch bits.", Color.yellow);
		}

		private static bool TrySpawnEnemiesForTwitchEventOnServer(string sender, int amount, PlayerControllerB playerScript, out string enemyDisplayName)
		{
			//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0316: Unknown result type (might be due to invalid IL or missing references)
			//IL_031b: Unknown result type (might be due to invalid IL or missing references)
			//IL_030a: Unknown result type (might be due to invalid IL or missing references)
			//IL_030f: Unknown result type (might be due to invalid IL or missing references)
			//IL_031f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0327: Unknown result type (might be due to invalid IL or missing references)
			//IL_032b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0330: Unknown result type (might be due to invalid IL or missing references)
			//IL_0333: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: 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_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: 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_01b4: Unknown result type (might be due to invalid IL or missing references)
			enemyDisplayName = string.Empty;
			if (!NetworkUtils.IsServer)
			{
				Plugin.logger.LogError((object)"Failed to spawn enemies for Twitch event. Only the host can spawn enemies.");
				return false;
			}
			if ((Object)(object)playerScript == (Object)null)
			{
				Plugin.logger.LogError((object)"Failed to spawn enemies for Twitch event. PlayerControllerB is null.");
				return false;
			}
			if (amount < 1)
			{
				Plugin.logger.LogError((object)"Failed to spawn enemies for Twitch event. The spawn amount is less than 1.");
				return false;
			}
			Plugin.Instance.LogInfoExtended("Trying to spawn enemies for Twitch event.");
			List<NetworkObjectReference> list = new List<NetworkObjectReference>();
			List<Vector3> list2 = new List<Vector3>();
			if (Plugin.ConfigManager.TwitchSubEvent_SpawnAllOfTheSameEnemy)
			{
				EnemyData random = Content.EnemyDataList.GetRandom(playerScript, forTwitchEvent: true);
				if (random == null)
				{
					random = Content.EnemyDataList.GetRandom(playerScript);
				}
				if (random == null)
				{
					Plugin.logger.LogError((object)"Failed to spawn enemies for Twitch event. EnemyData is null.");
					return false;
				}
				EnemyType enemyType = random.EnemyType;
				if (!IsValidEnemyType(enemyType))
				{
					Plugin.logger.LogError((object)"Failed to spawn enemies for Twitch event. EnemyType is invalid.");
					return false;
				}
				bool value = random.ConfigData.SpawnNearPlayer.Value;
				bool value2 = random.ConfigData.SpawnInFrontOfPlayer.Value;
				for (int i = 0; i < amount; i++)
				{
					Vector3 val = ((value && !value2) ? GetSpawnPositionNearPlayer(playerScript, random) : ((!value2) ? GetRandomSpawnPosition(playerScript) : GetSpawnPositionInFrontOfPlayer(playerScript, random)));
					list2.Add(val);
					NetworkObjectReference item = SpawnEnemyAtPositionOnServer(val, enemyType);
					list.Add(item);
				}
				enemyDisplayName = random.EnemyDisplayName;
				AudioPlayerManager.Instance.SpawnOnServer(random.EnemyName, list2.ToArray(), playerScript.isInsideFactory);
				EnemyNametagManager.Instance.SpawnNametagsOnServer(sender, playerScript, list.ToArray());
				return true;
			}
			List<EnemyData> spawnedEnemiesData = new List<EnemyData>();
			for (int j = 0; j < amount; j++)
			{
				EnemyData random2 = Content.EnemyDataList.GetRandom(playerScript, forTwitchEvent: true);
				if (random2 == null)
				{
					random2 = Content.EnemyDataList.GetRandom(playerScript);
				}
				if (random2 == null)
				{
					Plugin.logger.LogError((object)"Failed to spawn enemies for Twitch event. EnemyData is null.");
					continue;
				}
				EnemyType enemyType2 = random2.EnemyType;
				if (!IsValidEnemyType(enemyType2))
				{
					Plugin.logger.LogError((object)"Failed to spawn enemies for Twitch event. EnemyType is invalid.");
					continue;
				}
				spawnedEnemiesData.Add(random2);
				bool value3 = random2.ConfigData.SpawnNearPlayer.Value;
				bool value4 = random2.ConfigData.SpawnInFrontOfPlayer.Value;
				Vector3 zero = Vector3.zero;
				zero = ((value3 && !value4) ? GetSpawnPositionNearPlayer(playerScript, random2) : ((!value4) ? GetRandomSpawnPosition(playerScript) : GetSpawnPositionInFrontOfPlayer(playerScript, random2)));
				list2.Add(zero);
				NetworkObjectReference item2 = SpawnEnemyAtPositionOnServer(zero, enemyType2);
				list.Add(item2);
			}
			if (spawnedEnemiesData.Count == 0)
			{
				return false;
			}
			enemyDisplayName = "random enemies";
			string enemyName = string.Empty;
			if (spawnedEnemiesData.All((EnemyData _) => _ == spawnedEnemiesData[0]))
			{
				enemyDisplayName = spawnedEnemiesData[0].EnemyDisplayName;
				enemyName = spawnedEnemiesData[0].EnemyName;
			}
			AudioPlayerManager.Instance.SpawnOnServer(enemyName, list2.ToArray(), playerScript.isInsideFactory);
			EnemyNametagManager.Instance.SpawnNametagsOnServer(sender, playerScript, list.ToArray());
			return true;
		}

		public static void PlayTwitchEventsFromQueue()
		{
			Utils.StartCoroutine(PlayTwitchEventsFromQueueCoroutine());
		}

		private static IEnumerator PlayTwitchEventsFromQueueCoroutine()
		{
			float timer = 0f;
			while (!CanSpawnEnemy() && timer < 120f)
			{
				yield return null;
				timer += Time.deltaTime;
			}
			if (_twitchSubEventQueue.Count == 0 && _twitchBitsEventQueue.Count == 0)
			{
				yield break;
			}
			yield return (object)new WaitForSeconds(10f);
			if (!CanSpawnEnemy())
			{
				MessageCanvas.Instance.ShowMessageOnLocalClient("Failed to play monster Twitch events from queue", Color.red);
				yield break;
			}
			MessageCanvas.Instance.ShowMessageOnLocalClient("Playing monster Twitch events from queue");
			int subEventLength = _twitchSubEventQueue.Count;
			foreach (TwitchSubEvent twitchSubEvent in _twitchSubEventQueue)
			{
				SpawnEnemyFromSub(twitchSubEvent);
				yield return (object)new WaitForSeconds(1f);
			}
			_twitchSubEventQueue.RemoveRange(0, subEventLength);
			int bitsEventLength = _twitchBitsEventQueue.Count;
			foreach (TwitchBitsEvents twitchBitsEvent in _twitchBitsEventQueue)
			{
				SpawnEnemyFromBits(twitchBitsEvent);
				yield return (object)new WaitForSeconds(1f);
			}
			_twitchBitsEventQueue.RemoveRange(0, bitsEventLength);
		}

		public static NetworkObjectReference SpawnEnemyAtPositionOnServer(Vector3 spawnPosition, EnemyType enemyType)
		{
			//IL_0001: 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_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			return SpawnEnemyAtPositionOnServer(spawnPosition, Random.Range(0f, 360f), enemyType);
		}

		public static NetworkObjectReference SpawnEnemyAtPositionOnServer(Vector3 spawnPosition, float yRot, EnemyType enemyType)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: 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_0077: 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_0010: 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_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			if (!IsValidEnemyType(enemyType))
			{
				return default(NetworkObjectReference);
			}
			NetworkObjectReference result = RoundManager.Instance.SpawnEnemyGameObject(spawnPosition, yRot, -1, enemyType);
			Plugin.Instance.LogInfoExtended($"Spawned \"{enemyType.enemyName}\" enemy at position: (x: {spawnPosition.x}, y: {spawnPosition.y}, z: {spawnPosition.z})");
			return result;
		}

		public static bool CanSpawnEnemy()
		{
			if ((Object)(object)StartOfRound.Instance == (Object)null)
			{
				return false;
			}
			if (StartOfRound.Instance.inShipPhase)
			{
				return false;
			}
			if (StartOfRound.Instance.shipIsLeaving)
			{
				return false;
			}
			if (!StartOfRound.Instance.currentLevel.spawnEnemiesAndScrap)
			{
				return false;
			}
			PlayerControllerB localPlayerScript = PlayerUtils.GetLocalPlayerScript();
			if ((Object)(object)localPlayerScript == (Object)null)
			{
				return false;
			}
			if (localPlayerScript.isPlayerDead)
			{
				return false;
			}
			return true;
		}

		private static Vector3 GetRandomSpawnPosition(PlayerControllerB playerScript)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: 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_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: 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_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)RoundManager.Instance == (Object)null || (Object)(object)playerScript == (Object)null)
			{
				return Vector3.zero;
			}
			GameObject[] array;
			if (playerScript.isInsideFactory)
			{
				if (RoundManager.Instance.insideAINodes == null || RoundManager.Instance.insideAINodes.Length == 0)
				{
					return Vector3.zero;
				}
				array = RoundManager.Instance.insideAINodes.Where((GameObject _) => (Object)(object)_ != (Object)null).ToArray();
				if (array.Length == 0)
				{
					return Vector3.zero;
				}
				return array[Random.Range(0, array.Length)].transform.position;
			}
			if (RoundManager.Instance.outsideAINodes == null || RoundManager.Instance.outsideAINodes.Length == 0)
			{
				return Vector3.zero;
			}
			array = RoundManager.Instance.outsideAINodes.Where((GameObject _) => (Object)(object)_ != (Object)null).ToArray();
			if (array.Length == 0)
			{
				return Vector3.zero;
			}
			return array[Random.Range(0, array.Length)].transform.position;
		}

		private static Vector3 GetSpawnPositionNearPlayer(PlayerControllerB playerScript, EnemyData enemyData)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			return GetSpawnPositionNearPlayer(playerScript, enemyData.ConfigData.MinDistance.Value, enemyData.ConfigData.MaxDistance.Value);
		}

		private static Vector3 GetSpawnPositionNearPlayer(PlayerControllerB playerScript, float minRadius, float maxRadius)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: 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_0059: Unknown result type (might be due to invalid IL or missing references)
			bool flag = false;
			Vector3 position = Vector3.zero;
			for (int i = 0; i < 50; i++)
			{
				if (flag)
				{
					break;
				}
				if (TryGetRandomPositionInNavMesh(playerScript, ((Component)playerScript).transform.position, minRadius, maxRadius, out position))
				{
					flag = true;
				}
			}
			if (flag)
			{
				return position;
			}
			return GetRandomSpawnPosition(playerScript);
		}

		private static Vector3 GetSpawnPositionInFrontOfPlayer(PlayerControllerB playerScript, EnemyData enemyData)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			return GetSpawnPositionInFrontOfPlayer(playerScript, enemyData.ConfigData.MinDistance.Value, enemyData.ConfigData.MaxDistance.Value);
		}

		private static Vector3 GetSpawnPositionInFrontOfPlayer(PlayerControllerB playerScript, float minDistance, float maxDistance)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: 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)
			//IL_0050: 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_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: 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_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = ((Component)playerScript).transform;
			float num = maxDistance - minDistance;
			float num2 = 1.5f;
			List<Vector3> list = new List<Vector3>();
			int num3 = (int)num / (int)num2;
			if (num3 < 1)
			{
				num3 = 1;
			}
			for (int i = 0; i < num3; i++)
			{
				Vector3 item = transform.position + transform.forward * (minDistance + (float)i * num2);
				item.y += 0.5f;
				list.Add(item);
			}
			RaycastHit val2 = default(RaycastHit);
			for (int num4 = list.Count - 1; num4 >= 0; num4--)
			{
				int index = Random.Range(0, num4);
				Vector3 val = list[index];
				if (Physics.Raycast(val, Vector3.down, ref val2, 25f))
				{
					val = ((RaycastHit)(ref val2)).point;
				}
				if (TryGetRandomPositionInNavMesh(playerScript, val, 0f, num2, out var position))
				{
					return position;
				}
				list.RemoveAt(index);
			}
			return GetSpawnPositionNearPlayer(playerScript, minDistance, maxDistance);
		}

		private static bool TryGetRandomPositionInNavMesh(PlayerControllerB playerScript, Vector3 sourcePosition, float minRadius, float maxRadius, out Vector3 position)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: 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_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_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: 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)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			position = Vector3.zero;
			Vector3 val = Random.insideUnitSphere * maxRadius;
			val += sourcePosition;
			NavMeshHit val2 = default(NavMeshHit);
			if (NavMesh.SamplePosition(val, ref val2, maxRadius, 1))
			{
				position = ((NavMeshHit)(ref val2)).position;
				if (IsYPositionTooHigh(playerScript, position.y))
				{
					return false;
				}
				if (Vector3.Distance(sourcePosition, position) <= minRadius)
				{
					return false;
				}
				return true;
			}
			return false;
		}

		private static bool IsYPositionTooHigh(PlayerControllerB playerScript, float yPosition)
		{
			if (!playerScript.isInsideFactory)
			{
				return false;
			}
			if (!InteriorHelper.IsFacilityInterior())
			{
				return false;
			}
			return yPosition > -210f;
		}

		public static EnemyType GetEnemyType(string enemyName)
		{
			foreach (EnemyType enemyType in GetEnemyTypes())
			{
				if (enemyType.enemyName == enemyName)
				{
					return enemyType;
				}
			}
			try
			{
				EnemyType val = Resources.FindObjectsOfTypeAll<EnemyType>().Single((EnemyType x) => x.enemyName == enemyName);
				if (IsValidEnemyType(val) && NetworkUtils.IsNetworkPrefab(val.enemyPrefab))
				{
					Plugin.Instance.LogInfoExtended("Found EnemyType \"" + val.enemyName + "\" from Resources.");
					return val;
				}
			}
			catch
			{
			}
			return null;
		}

		public static List<EnemyType> GetEnemyTypes()
		{
			HashSet<EnemyType> hashSet = new HashSet<EnemyType>(new EnemyTypeComparer());
			SelectableLevel[] levels = StartOfRound.Instance.levels;
			foreach (SelectableLevel val in levels)
			{
				IEnumerable<EnemyType> enumerable = (from e in val.Enemies.Concat(val.DaytimeEnemies).Concat(val.OutsideEnemies)
					select e.enemyType).Where(IsValidEnemyType);
				foreach (EnemyType item in enumerable)
				{
					hashSet.Add(item);
				}
			}
			return hashSet.ToList();
		}

		public static bool IsValidEnemyType(EnemyType enemyType)
		{
			if ((Object)(object)enemyType == (Object)null)
			{
				return false;
			}
			if (string.IsNullOrWhiteSpace(enemyType.enemyName))
			{
				return false;
			}
			if ((Object)(object)enemyType.enemyPrefab == (Object)null)
			{
				return false;
			}
			return true;
		}
	}
	public class EnemyTypeComparer : IEqualityComparer<EnemyType>
	{
		public bool Equals(EnemyType x, EnemyType y)
		{
			if ((Object)(object)x == (Object)null || (Object)(object)y == (Object)null)
			{
				return false;
			}
			return x.enemyName == y.enemyName;
		}

		public int GetHashCode(EnemyType obj)
		{
			return obj.enemyName?.GetHashCode() ?? 0;
		}
	}
	internal class HotkeyInputClass : LcInputActions
	{
		[InputAction(/*Could not decode attribute arguments.*/)]
		public InputAction MonsterPrefixKey { get; set; }

		[InputAction(/*Could not decode attribute arguments.*/)]
		public InputAction PlushiePrefixKey { get; set; }

		[InputAction(/*Could not decode attribute arguments.*/)]
		public InputAction SpawnRandomKey { get; set; }

		[InputAction(/*Could not decode attribute arguments.*/)]
		public InputAction SpawnBaboonHawkKey { get; set; }

		[InputAction(/*Could not decode attribute arguments.*/)]
		public InputAction SpawnBarberKey { get; set; }

		[InputAction(/*Could not decode attribute arguments.*/)]
		public InputAction SpawnBlobKey { get; set; }

		[InputAction(/*Could not decode attribute arguments.*/)]
		public InputAction SpawnBrackenKey { get; set; }

		[InputAction(/*Could not decode attribute arguments.*/)]
		public InputAction SpawnBunkerSpiderKey { get; set; }

		[InputAction(/*Could not decode attribute arguments.*/)]
		public InputAction SpawnButlerKey { get; set; }

		[InputAction(/*Could not decode attribute arguments.*/)]
		public InputAction SpawnCoilHeadKey { get; set; }

		[InputAction(/*Could not decode attribute arguments.*/)]
		public InputAction SpawnEarthLeviathanKey { get; set; }

		[InputAction(/*Could not decode attribute arguments.*/)]
		public InputAction SpawnEyelessDogKey { get; set; }

		[InputAction(/*Could not decode attribute arguments.*/)]
		public InputAction SpawnForestGiantKey { get; set; }

		[InputAction(/*Could not decode attribute arguments.*/)]
		public InputAction SpawnGhostGirlKey { get; set; }

		[InputAction(/*Could not decode attribute arguments.*/)]
		public InputAction SpawnHoardingBugKey { get; set; }

		[InputAction(/*Could not decode attribute arguments.*/)]
		public InputAction SpawnJesterKey { get; set; }

		[InputAction(/*Could not decode attribute arguments.*/)]
		public InputAction SpawnKidnapperFoxKey { get; set; }

		[InputAction(/*Could not decode attribute arguments.*/)]
		public InputAction SpawnManeaterKey { get; set; }

		[InputAction(/*Could not decode attribute arguments.*/)]
		public InputAction SpawnManticoilKey { get; set; }

		[InputAction(/*Could not decode attribute arguments.*/)]
		public InputAction SpawnMaskedKey { get; set; }

		[InputAction(/*Could not decode attribute arguments.*/)]
		public InputAction SpawnNutcrackerKey { get; set; }

		[InputAction(/*Could not decode attribute arguments.*/)]
		public InputAction SpawnOldBirdKey { get; set; }

		[InputAction(/*Could not decode attribute arguments.*/)]
		public InputAction SpawnSnareFleaKey { get; set; }

		[InputAction(/*Could not decode attribute arguments.*/)]
		public InputAction SpawnSporeLizardKey { get; set; }

		[InputAction(/*Could not decode attribute arguments.*/)]
		public InputAction SpawnThumperKey { get; set; }

		[InputAction(/*Could not decode attribute arguments.*/)]
		public InputAction SpawnTulipSnakeKey { get; set; }
	}
	public static class HotkeyListener
	{
		public static bool DisableHotkeys;

		public static bool IsMonsterPrefixKeyPressed => Plugin.InputActionsInstance.MonsterPrefixKey.IsPressed();

		public static bool IsPlushiePrefixKeyPressed => Plugin.InputActionsInstance.PlushiePrefixKey.IsPressed();

		internal static void SetupKeybindCallbacks()
		{
			Plugin.InputActionsInstance.SpawnRandomKey.performed += OnSpawnRandomKeyPressed;
			Plugin.InputActionsInstance.SpawnBaboonHawkKey.performed += OnSpawnKeyPressed;
			Plugin.InputActionsInstance.SpawnBarberKey.performed += OnSpawnKeyPressed;
			Plugin.InputActionsInstance.SpawnBlobKey.performed += OnSpawnKeyPressed;
			Plugin.InputActionsInstance.SpawnBrackenKey.performed += OnSpawnKeyPressed;
			Plugin.InputActionsInstance.SpawnBunkerSpiderKey.performed += OnSpawnKeyPressed;
			Plugin.InputActionsInstance.SpawnButlerKey.performed += OnSpawnKeyPressed;
			Plugin.InputActionsInstance.SpawnCoilHeadKey.performed += OnSpawnKeyPressed;
			Plugin.InputActionsInstance.SpawnEarthLeviathanKey.performed += OnSpawnKeyPressed;
			Plugin.InputActionsInstance.SpawnEyelessDogKey.performed += OnSpawnKeyPressed;
			Plugin.InputActionsInstance.SpawnForestGiantKey.performed += OnSpawnKeyPressed;
			Plugin.InputActionsInstance.SpawnGhostGirlKey.performed += OnSpawnKeyPressed;
			Plugin.InputActionsInstance.SpawnHoardingBugKey.performed += OnSpawnKeyPressed;
			Plugin.InputActionsInstance.SpawnJesterKey.performed += OnSpawnKeyPressed;
			Plugin.InputActionsInstance.SpawnKidnapperFoxKey.performed += OnSpawnKeyPressed;
			Plugin.InputActionsInstance.SpawnManeaterKey.performed += OnSpawnKeyPressed;
			Plugin.InputActionsInstance.SpawnManticoilKey.performed += OnSpawnKeyPressed;
			Plugin.InputActionsInstance.SpawnMaskedKey.performed += OnSpawnKeyPressed;
			Plugin.InputActionsInstance.SpawnNutcrackerKey.performed += OnSpawnKeyPressed;
			Plugin.InputActionsInstance.SpawnOldBirdKey.performed += OnSpawnKeyPressed;
			Plugin.InputActionsInstance.SpawnSnareFleaKey.performed += OnSpawnKeyPressed;
			Plugin.InputActionsInstance.SpawnSporeLizardKey.performed += OnSpawnKeyPressed;
			Plugin.InputActionsInstance.SpawnThumperKey.performed += OnSpawnKeyPressed;
			Plugin.InputActionsInstance.SpawnTulipSnakeKey.performed += OnSpawnKeyPressed;
			Plugin.logger.LogInfo((object)"Setup keybind callbacks.");
		}

		private static void OnSpawnKeyPressed(CallbackContext context)
		{
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			if (!((CallbackContext)(ref context)).performed)
			{
				return;
			}
			string name = ((CallbackContext)(ref context)).action.name;
			Plugin.Instance.LogInfoExtended(name + " key pressed.");
			if (!Utils.CanPerformHotkeys())
			{
				return;
			}
			if (DisableHotkeys && (IsMonsterPrefixKeyPressed || IsPlushiePrefixKeyPressed))
			{
				MessageCanvas.Instance.ShowMessageOnLocalClient("Hotkeys have been disabled by another mod", Color.red);
				Plugin.logger.LogInfo((object)"Hotkeys have been disabled by another mod.");
				return;
			}
			string text = name.Replace("Spawn", "").Replace("Key", "");
			switch (text)
			{
			case "BaboonHawk":
				text = "Baboon hawk";
				break;
			case "BunkerSpider":
				text = "Bunker Spider";
				break;
			case "Bracken":
				text = "Flowerman";
				break;
			case "CoilHead":
				text = "Spring";
				break;
			case "EarthLeviathan":
				text = "Earth Leviathan";
				break;
			case "EyelessDog":
				text = "MouthDog";
				break;
			case "GhostGirl":
				text = "Girl";
				break;
			case "HoardingBug":
				text = "Hoarding bug";
				break;
			case "OldBird":
				text = "RadMech";
				break;
			case "SnareFlea":
				text = "Centipede";
				break;
			case "SporeLizard":
				text = "Puffer";
				break;
			case "Thumper":
				text = "Crawler";
				break;
			case "TulipSnake":
				text = "Tulip Snake";
				break;
			case "KidnapperFox":
				text = "Bush Wolf";
				break;
			case "Barber":
				text = "Clay Surgeon";
				break;
			}
			EnemyData byEnemyName = Content.EnemyDataList.GetByEnemyName(text);
			if (byEnemyName == null)
			{
				Plugin.logger.LogError((object)("Failed to find EnemyData from key name \"" + name + "\"."));
				return;
			}
			if (Plugin.InputActionsInstance.MonsterPrefixKey.IsPressed())
			{
				EnemyHelper.SpawnEnemy(byEnemyName);
			}
			if (Plugin.InputActionsInstance.PlushiePrefixKey.IsPressed())
			{
				PlushieManager.Instance.SpawnPlushies(byEnemyName.EnemyName);
			}
		}

		private static void OnSpawnRandomKeyPressed(CallbackContext context)
		{
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			if (!((CallbackContext)(ref context)).performed)
			{
				return;
			}
			Plugin.Instance.LogInfoExtended(((CallbackContext)(ref context)).action.name + " key pressed.");
			if (!Utils.CanPerformHotkeys())
			{
				return;
			}
			if (DisableHotkeys && (IsMonsterPrefixKeyPressed || IsPlushiePrefixKeyPressed))
			{
				MessageCanvas.Instance.ShowMessageOnLocalClient("Hotkeys have been disabled by another mod", Color.red);
				Plugin.logger.LogInfo((object)"Hotkeys have been disabled by another mod.");
				return;
			}
			if (IsMonsterPrefixKeyPressed)
			{
				EnemyHelper.SpawnRandomEnemy();
			}
			if (IsPlushiePrefixKeyPressed)
			{
				PlushieManager.Instance.SpawnRandomPlushies();
			}
		}
	}
	public enum InteriorType
	{
		None,
		Facility,
		Mansion,
		Mineshaft,
		Other
	}
	internal static class InteriorHelper
	{
		private static InteriorType interiorType;

		public static void SetInteriorType()
		{
			try
			{
				RuntimeDungeon val = Object.FindFirstObjectByType<RuntimeDungeon>((FindObjectsInactive)0);
				if (!((Object)(object)val == (Object)null))
				{
					DungeonFlow dungeonFlow = val.Generator.DungeonFlow;
					switch (((Object)dungeonFlow).name)
					{
					case "Level1Flow":
						interiorType = InteriorType.Facility;
						break;
					case "Level2Flow":
						interiorType = InteriorType.Mansion;
						break;
					case "Level3Flow":
						interiorType = InteriorType.Mineshaft;
						break;
					default:
						interiorType = InteriorType.Other;
						break;
					}
					Plugin.Instance.LogInfoExtended("Found interior: " + Utils.GetEnumName(interiorType) + " \"" + ((Object)dungeonFlow).name + "\".");
				}
			}
			catch
			{
				interiorType = InteriorType.None;
			}
		}

		public static bool IsFacilityInterior()
		{
			return interiorType == InteriorType.Facility;
		}
	}
	internal static class NetworkUtils
	{
		public static bool IsServer
		{
			get
			{
				if ((Object)(object)NetworkManager.Singleton == (Object)null)
				{
					return false;
				}
				return NetworkManager.Singleton.IsServer;
			}
		}

		public static bool IsHost
		{
			get
			{
				if ((Object)(object)NetworkManager.Singleton == (Object)null)
				{
					return false;
				}
				return NetworkManager.Singleton.IsHost;
			}
		}

		public static ulong GetLocalClientId()
		{
			return NetworkManager.Singleton.LocalClientId;
		}

		public static bool IsLocalClientId(ulong clientId)
		{
			return clientId == GetLocalClientId();
		}

		public static bool IsNetworkPrefab(GameObject prefab)
		{
			foreach (NetworkPrefab prefab2 in NetworkManager.Singleton.NetworkConfig.Prefabs.Prefabs)
			{
				if ((Object)(object)prefab2.Prefab == (Object)(object)prefab)
				{
					return true;
				}
			}
			return false;
		}
	}
	internal static class PlayerUtils
	{
		public static PlayerControllerB GetLocalPlayerScript()
		{
			if ((Object)(object)GameNetworkManager.Instance == (Object)null)
			{
				return null;
			}
			return GameNetworkManager.Instance.localPlayerController;
		}

		public static bool IsLocalPlayer(PlayerControllerB playerScript)
		{
			return (Object)(object)playerScript == (Object)(object)GetLocalPlayerScript();
		}

		public static PlayerControllerB GetPlayerScriptByClientId(ulong clientId)
		{
			PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
			foreach (PlayerControllerB val in allPlayerScripts)
			{
				if (val.actualClientId == clientId)
				{
					return val;
				}
			}
			return null;
		}
	}
	[BepInPlugin("com.github.zehsteam.MonsterHotkeys", "MonsterHotkeys", "1.3.6")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	internal class Plugin : BaseUnityPlugin
	{
		private readonly Harmony harmony = new Harmony("com.github.zehsteam.MonsterHotkeys");

		internal static Plugin Instance;

		internal static ManualLogSource logger;

		internal static SyncedConfigManager ConfigManager;

		internal static HotkeyInputClass InputActionsInstance;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			logger = Logger.CreateLogSource("com.github.zehsteam.MonsterHotkeys");
			logger.LogInfo((object)"MonsterHotkeys has awoken!");
			harmony.PatchAll(typeof(GameNetworkManagerPatch));
			harmony.PatchAll(typeof(MenuManagerPatch));
			harmony.PatchAll(typeof(StartOfRoundPatch));
			harmony.PatchAll(typeof(RoundManagerPatch));
			harmony.PatchAll(typeof(HUDManagerPatch));
			harmony.PatchAll(typeof(PlayerControllerBPatch));
			harmony.PatchAll(typeof(EnemyAIPatch));
			ConfigManager = new SyncedConfigManager();
			InputActionsInstance = new HotkeyInputClass();
			Content.Load();
			HotkeyListener.SetupKeybindCallbacks();
			Content.EnemyDataList.Initialize();
			TwitchEvents.Initialize();
			EnemyHelper.Initialize();
			PlushieManager.Initialize();
			if (LethalConfigProxy.Enabled)
			{
				LethalConfigProxy.SetModIcon(Content.ModIcon);
				LethalConfigProxy.SetModDescription("Spawn Monsters and Monster Plushies using Hotkeys or from Twitch subs, resubs, gift subs, and bits. Supports Modded Monsters. Highly Configurable. (Twitch Integration)");
			}
			NetcodePatcherAwake();
		}

		private void NetcodePatcherAwake()
		{
			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);
					}
				}
			}
		}

		public void OnNewLevelLoaded()
		{
			InteriorHelper.SetInteriorType();
			EnemyNametagManager.Instance?.Reset();
		}

		public void OnLocalDisconnect()
		{
			logger.LogInfo((object)"Local player disconnected. Removing hostConfigData.");
			ConfigManager.SetHostConfigData(null);
		}

		public void SpawnMessageCanvas()
		{
			if (!((Object)(object)MessageCanvas.Instance != (Object)null))
			{
				Object.Instantiate<GameObject>(Content.MessageCanvasPrefab);
			}
		}

		public void LogInfoExtended(object data)
		{
			if (ConfigManager.ExtendedLogging)
			{
				logger.LogInfo(data);
			}
		}

		public void LogWarningExtended(object data)
		{
			if (ConfigManager.ExtendedLogging)
			{
				logger.LogWarning(data);
			}
		}

		public void LogMessageExtended(object data)
		{
			if (ConfigManager.ExtendedLogging)
			{
				logger.LogMessage(data);
			}
		}
	}
	[Serializable]
	public class SyncedConfigData : INetworkSerializable
	{
		public int PlushieSpawnCount;

		public float PlushieDespawnDuration;

		public bool PlushiePlaySFXOnCollision;

		public bool PlushieAttractDogs;

		public float PlushieScale;

		public SyncedConfigData()
		{
		}

		public SyncedConfigData(SyncedConfigManager configManager)
		{
			PlushieSpawnCount = configManager.PlushieSpawnCount;
			PlushieDespawnDuration = configManager.PlushieDespawnDuration;
			PlushiePlaySFXOnCollision = configManager.PlushiePlaySFXOnCollision;
			PlushieAttractDogs = configManager.PlushieAttractDogs;
			PlushieScale = configManager.PlushieScale;
		}

		public unsafe void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: 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)
			((BufferSerializer<int>*)(&serializer))->SerializeValue<int>(ref PlushieSpawnCount, default(ForPrimitives));
			((BufferSerializer<float>*)(&serializer))->SerializeValue<float>(ref PlushieDespawnDuration, default(ForPrimitives));
			((BufferSerializer<bool>*)(&serializer))->SerializeValue<bool>(ref PlushiePlaySFXOnCollision, default(ForPrimitives));
			((BufferSerializer<bool>*)(&serializer))->SerializeValue<bool>(ref PlushieAttractDogs, default(ForPrimitives));
			((BufferSerializer<float>*)(&serializer))->SerializeValue<float>(ref PlushieScale, default(ForPrimitives));
		}
	}
	public class SyncedConfigManager
	{
		private SyncedConfigData _hostConfigData;

		private ConfigEntry<bool> ExtendedLoggingCfg;

		private ConfigEntry<bool> OnlyHostSpawnMonstersCfg;

		private ConfigEntry<bool> MuteSpawnSFXCfg;

		private ConfigEntry<int> PlushieSpawnCountCfg;

		private ConfigEntry<float> PlushieDespawnDurationCfg;

		private ConfigEntry<float> PlushieSFXVolumeCfg;

		private ConfigEntry<bool> PlushiePlaySFXOnCollisionCfg;

		private ConfigEntry<bool> PlushieAttractDogsCfg;

		private ConfigEntry<float> PlushieScaleCfg;

		private ConfigEntry<bool> ShowMessagesCfg;

		private ConfigEntry<bool> ShowSpawnEnemyMessagesCfg;

		private ConfigEntry<bool> ShowLocalSpawnEnemyMessagesCfg;

		private ConfigEntry<bool> ShowDetailedTwitchEventSpawnEnemyMessagesCfg;

		private ConfigEntry<float> MessageDurationCfg;

		private ConfigEntry<int> MessageFontSizeCfg;

		private ConfigEntry<int> MessageBackgroundTransparencyCfg;

		private ConfigEntry<bool> TwitchIntegration_EnabledCfg;

		private ConfigEntry<string> TwitchIntegration_UsernameCfg;

		private ConfigEntry<string> TwitchEvent_CheckMessageFromUserCfg;

		private ConfigEntry<bool> TwitchSubEvent_EnabledCfg;

		private ConfigEntry<bool> TwitchSubEvent_SpawnAllOfTheSameEnemyCfg;

		private ConfigEntry<bool> TwitchBitsEvent_EnabledCfg;

		private ConfigEntry<int> TwitchBitsEvent_MinAmountToSpawnMonsterCfg;

		private ConfigEntry<int> TwitchBitsEvent_MinAmountToSpawnPlushiesCfg;

		private ConfigEntry<bool> EnemyNametag_EnabledCfg;

		private ConfigEntry<float> EnemyNametag_ScaleMultiplierCfg;

		private ConfigEntry<int> EnemyNametag_BackgroundTransparencyCfg;

		internal bool ExtendedLogging
		{
			get
			{
				return ExtendedLoggingCfg.Value;
			}
			set
			{
				ExtendedLoggingCfg.Value = value;
			}
		}

		internal bool OnlyHostSpawnMonsters
		{
			get
			{
				return OnlyHostSpawnMonstersCfg.Value;
			}
			set
			{
				OnlyHostSpawnMonstersCfg.Value = value;
			}
		}

		internal bool MuteSpawnSFX
		{
			get
			{
				return MuteSpawnSFXCfg.Value;
			}
			set
			{
				MuteSpawnSFXCfg.Value = value;
			}
		}

		internal int PlushieSpawnCount
		{
			get
			{
				return (_hostConfigData == null) ? PlushieSpawnCountCfg.Value : _hostConfigData.PlushieSpawnCount;
			}
			set
			{
				PlushieSpawnCountCfg.Value = value;
				SyncedConfigsChanged();
			}
		}

		internal float PlushieDespawnDuration
		{
			get
			{
				float num = ((_hostConfigData == null) ? PlushieDespawnDurationCfg.Value : _hostConfigData.PlushieDespawnDuration);
				return Mathf.Max(num, 0.1f);
			}
			set
			{
				PlushieDespawnDurationCfg.Value = value;
				SyncedConfigsChanged();
			}
		}

		internal bool PlushiePlaySFXOnCollision
		{
			get
			{
				return (_hostConfigData == null) ? PlushiePlaySFXOnCollisionCfg.Value : _hostConfigData.PlushiePlaySFXOnCollision;
			}
			set
			{
				PlushiePlaySFXOnCollisionCfg.Value = value;
				SyncedConfigsChanged();
			}
		}

		internal float PlushieSFXVolume
		{
			get
			{
				return PlushieSFXVolumeCfg.Value;
			}
			set
			{
				PlushieSFXVolumeCfg.Value = value;
			}
		}

		internal bool PlushieAttractDogs
		{
			get
			{
				return (_hostConfigData == null) ? PlushieAttractDogsCfg.Value : _hostConfigData.PlushieAttractDogs;
			}
			set
			{
				PlushieAttractDogsCfg.Value = value;
				SyncedConfigsChanged();
			}
		}

		internal float PlushieScale
		{
			get
			{
				float num = ((_hostConfigData == null) ? PlushieScaleCfg.Value : _hostConfigData.PlushieScale);
				return Mathf.Max(num, 0.1f);
			}
			set
			{
				PlushieScaleCfg.Value = value;
				SyncedConfigsChanged();
			}
		}

		internal bool ShowMessages
		{
			get
			{
				return ShowMessagesCfg.Value;
			}
			set
			{
				ShowMessagesCfg.Value = value;
			}
		}

		internal bool ShowSpawnEnemyMessages
		{
			get
			{
				return ShowSpawnEnemyMessagesCfg.Value;
			}
			set
			{
				ShowSpawnEnemyMessagesCfg.Value = value;
			}
		}

		internal bool ShowLocalSpawnEnemyMessages
		{
			get
			{
				return ShowLocalSpawnEnemyMessagesCfg.Value;
			}
			set
			{
				ShowLocalSpawnEnemyMessagesCfg.Value = value;
			}
		}

		internal bool ShowDetailedTwitchEventSpawnEnemyMessages
		{
			get
			{
				return ShowDetailedTwitchEventSpawnEnemyMessagesCfg.Value;
			}
			set
			{
				ShowDetailedTwitchEventSpawnEnemyMessagesCfg.Value = value;
			}
		}

		internal float MessageDuration
		{
			get
			{
				return Mathf.Max(MessageDurationCfg.Value, 0.1f);
			}
			set
			{
				MessageDurationCfg.Value = value;
			}
		}

		internal int MessageFontSize
		{
			get
			{
				return Mathf.Max(MessageFontSizeCfg.Value, 1);
			}
			set
			{
				MessageFontSizeCfg.Value = value;
			}
		}

		internal int MessageBackgroundTransparency
		{
			get
			{
				return MessageBackgroundTransparencyCfg.Value;
			}
			set
			{
				MessageBackgroundTransparencyCfg.Value = value;
			}
		}

		internal bool TwitchIntegration_Enabled
		{
			get
			{
				return TwitchIntegration_EnabledCfg.Value;
			}
			set
			{
				TwitchIntegration_EnabledCfg.Value = value;
			}
		}

		internal string TwitchIntegration_Username
		{
			get
			{
				return TwitchIntegration_UsernameCfg.Value;
			}
			set
			{
				TwitchIntegration_UsernameCfg.Value = value;
			}
		}

		internal string TwitchEvent_CheckMessageFromUser
		{
			get
			{
				return TwitchEvent_CheckMessageFromUserCfg.Value;
			}
			set
			{
				TwitchEvent_CheckMessageFromUserCfg.Value = value;
			}
		}

		internal bool TwitchSubEvent_Enabled
		{
			get
			{
				return TwitchSubEvent_EnabledCfg.Value;
			}
			set
			{
				TwitchSubEvent_EnabledCfg.Value = value;
			}
		}

		internal bool TwitchSubEvent_SpawnAllOfTheSameEnemy
		{
			get
			{
				return TwitchSubEvent_SpawnAllOfTheSameEnemyCfg.Value;
			}
			set
			{
				TwitchSubEvent_SpawnAllOfTheSameEnemyCfg.Value = value;
			}
		}

		internal bool TwitchBitsEvent_Enabled
		{
			get
			{
				return TwitchBitsEvent_EnabledCfg.Value;
			}
			set
			{
				TwitchBitsEvent_EnabledCfg.Value = value;
			}
		}

		internal int TwitchBitsEvent_MinAmountToSpawnMonster
		{
			get
			{
				return TwitchBitsEvent_MinAmountToSpawnMonsterCfg.Value;
			}
			set
			{
				TwitchBitsEvent_MinAmountToSpawnMonsterCfg.Value = value;
			}
		}

		internal int TwitchBitsEvent_MinAmountToSpawnPlushies
		{
			get
			{
				return TwitchBitsEvent_MinAmountToSpawnPlushiesCfg.Value;
			}
			set
			{
				TwitchBitsEvent_MinAmountToSpawnPlushiesCfg.Value = value;
			}
		}

		internal bool EnemyNametag_Enabled
		{
			get
			{
				return EnemyNametag_EnabledCfg.Value;
			}
			set
			{
				EnemyNametag_EnabledCfg.Value = value;
			}
		}

		internal float EnemyNametag_ScaleMultiplier
		{
			get
			{
				return EnemyNametag_ScaleMultiplierCfg.Value;
			}
			set
			{
				EnemyNametag_ScaleMultiplierCfg.Value = value;
			}
		}

		internal int EnemyNametag_BackgroundTransparency
		{
			get
			{
				return EnemyNametag_BackgroundTransparencyCfg.Value;
			}
			set
			{
				EnemyNametag_BackgroundTransparencyCfg.Value = value;
			}
		}

		public SyncedConfigManager()
		{
			BindConfigs();
			SetupChangedEvents();
		}

		private void BindConfigs()
		{
			if (LethalConfigProxy.Enabled)
			{
				LethalConfigProxy.SkipAutoGen();
			}
			ExtendedLoggingCfg = ConfigHelper.Bind("General Settings", "ExtendedLogging", defaultValue: false, requiresRestart: false, "Enable extended logging.");
			OnlyHostSpawnMonstersCfg = ConfigHelper.Bind("Monster Settings", "OnlyHostSpawnMonsters", defaultValue: false, requiresRestart: false, "If enabled, only the host can spawn monsters.");
			MuteSpawnSFXCfg = ConfigHelper.Bind("Monster Settings", "MuteSpawnSFX", defaultValue: false, requiresRestart: false, "If enabled, the monster spawn sfx will not play.");
			PlushieSpawnCountCfg = ConfigHelper.Bind("Plushie Settings", "SpawnCount", 30, requiresRestart: false, "The amount of plushies to spawn.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100));
			PlushieDespawnDurationCfg = ConfigHelper.Bind("Plushie Settings", "DespawnDuration", 15f, requiresRestart: false, "The duration in seconds until a plushie gets despawned.");
			PlushieSFXVolumeCfg = ConfigHelper.Bind("Plushie Settings", "SFXVolume", 25f, requiresRestart: false, "The volume of the plushie's squeak sound effect.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f));
			PlushiePlaySFXOnCollisionCfg = ConfigHelper.Bind("Plushie Settings", "PlaySFXOnCollision", defaultValue: true, requiresRestart: false, "If enabled, the plushies will play a sound effect when colliding with the environment.");
			PlushieAttractDogsCfg = ConfigHelper.Bind("Plushie Settings", "AttractDogs", defaultValue: true, requiresRestart: false, "If enabled, the plushies will attract dogs when making noise.");
			PlushieScaleCfg = ConfigHelper.Bind("Plushie Settings", "Scale", 4f, requiresRestart: false, "The size of the plushies.");
			ShowMessagesCfg = ConfigHelper.Bind("Message Settings", "ShowMessages", defaultValue: true, requiresRestart: false, "If enabled, will show messages in the bottom right.");
			ShowSpawnEnemyMessagesCfg = ConfigHelper.Bind("Message Settings", "ShowSpawnEnemyMessages", defaultValue: true, requiresRestart: false, "If enabled, will show a message when someone else spawns an enemy.");
			ShowLocalSpawnEnemyMessagesCfg = ConfigHelper.Bind("Message Settings", "ShowLocalSpawnEnemyMessages", defaultValue: true, requiresRestart: false, "If enabled, will show a message when you spawn an enemy.");
			ShowDetailedTwitchEventSpawnEnemyMessagesCfg = ConfigHelper.Bind("Message Settings", "ShowDetailedTwitchEventSpawnEnemyMessages", defaultValue: true, requiresRestart: false, "If enabled, will show a detailed Twitch event spawn enemy messages.");
			MessageDurationCfg = ConfigHelper.Bind("Message Settings", "MessageDuration", 8f, requiresRestart: false, "The duration of a message in seconds.");
			MessageFontSizeCfg = ConfigHelper.Bind("Message Settings", "MessageFontSize", 25, requiresRestart: false, "The font size of the messages.");
			MessageBackgroundTransparencyCfg = ConfigHelper.Bind("Message Settings", "MessageBackgroundTransparency", 192, requiresRestart: false, "The transparency of the message background.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 255));
			TwitchIntegration_EnabledCfg = ConfigHelper.Bind("Twitch Integration Settings", "Enabled", defaultValue: false, requiresRestart: false, "Enable events from Twitch chat.");
			TwitchIntegration_UsernameCfg = ConfigHelper.Bind("Twitch Integration Settings", "Username", "", requiresRestart: false, "Your Twitch username.");
			if (LethalConfigProxy.Enabled)
			{
				LethalConfigProxy.AddButton("Twitch Integration Settings", "Refresh", "Click to refresh the connection to Twitch.", "Refresh", TwitchIntegration_Refresh_OnButtonClicked);
			}
			TwitchEvent_CheckMessageFromUserCfg = ConfigHelper.Bind("Twitch Event Settings", "CheckMessageFromUser", "", requiresRestart: false, "The username of the Twitch bot which will be sending the messages for the Twitch events. The Twitch bot must send specific messages for these events. (See README on the Thunderstore page for full details)");
			TwitchSubEvent_EnabledCfg = ConfigHelper.Bind("Twitch Subs Event Settings", "Enabled", defaultValue: false, requiresRestart: false, "If enabled, subs will spawn random monsters. (Requires Twitch Integration to be enabled)");
			TwitchSubEvent_SpawnAllOfTheSameEnemyCfg = ConfigHelper.Bind("Twitch Subs Event Settings", "SpawnAllOfTheSameEnemy", defaultValue: true, requiresRestart: false, "If enabled, will only spawn monsters of one type.");
			TwitchBitsEvent_EnabledCfg = ConfigHelper.Bind("Twitch Bits Event Settings", "Enabled", defaultValue: false, requiresRestart: false, "If enabled, bits will spawn a random monsters or random plushies. (Requires Twitch Integration to be enabled)");
			TwitchBitsEvent_MinAmountToSpawnMonsterCfg = ConfigHelper.Bind("Twitch Bits Event Settings", "MinAmountToSpawnMonster", 495, requiresRestart: false, "The min amount of bits to spawn a random monster.");
			TwitchBitsEvent_MinAmountToSpawnPlushiesCfg = ConfigHelper.Bind("Twitch Bits Event Settings", "MinAmountToSpawnPlushies", 90, requiresRestart: false, "The min amount of bits to spawn random plushies.");
			EnemyNametag_EnabledCfg = ConfigHelper.Bind("Enemy Nametag Settings", "Enabled", defaultValue: true, requiresRestart: false, "If enabled, nametags will spawn on enemies spawned by Twitch sub events.");
			EnemyNametag_ScaleMultiplierCfg = ConfigHelper.Bind("Enemy Nametag Settings", "ScaleMultiplier", 1f, requiresRestart: false, "The scale multiplier for enemy nametags.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.25f, 5f));
			EnemyNametag_BackgroundTransparencyCfg = ConfigHelper.Bind("Enemy Nametag Settings", "BackgroundTransparency", 192, requiresRestart: false, "The transparency of the nametag background.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 255));
		}

		private void SetupChangedEvents()
		{
			MuteSpawnSFXCfg.SettingChanged += AudioPlayerManager.OnSettingsChanged;
			PlushieSpawnCountCfg.SettingChanged += PlushieManager.OnSettingsChanged;
			PlushieSFXVolumeCfg.SettingChanged += Plushie.OnSettingsChanged;
			MessageFontSizeCfg.SettingChanged += MessageItem.OnSettingsChanged;
			MessageBackgroundTransparencyCfg.SettingChanged += MessageItem.OnSettingsChanged;
			TwitchIntegration_EnabledCfg.SettingChanged += TwitchIntegrationEnabled_SettingChanged;
			TwitchIntegration_UsernameCfg.SettingChanged += TwitchIntegrationUsername_SettingChanged;
			EnemyNametag_ScaleMultiplierCfg.SettingChanged += EnemyNametag.OnSettingsChanged;
			EnemyNametag_BackgroundTransparencyCfg.SettingChanged += EnemyNametag.OnSettingsChanged;
		}

		private void TwitchIntegrationEnabled_SettingChanged(object sender, EventArgs e)
		{
			if (TwitchIntegration_Enabled)
			{
				TwitchChat.StartReading();
			}
			else
			{
				TwitchChat.StopReading();
			}
		}

		private void TwitchIntegrationUsername_SettingChanged(object sender, EventArgs e)
		{
			if (NetworkUtils.IsServer && TwitchIntegration_Enabled)
			{
				TwitchChat.StartReading();
			}
		}

		private void TwitchIntegration_Refresh_OnButtonClicked()
		{
			if (TwitchIntegration_Enabled)
			{
				TwitchChat.StartReading();
			}
			else
			{
				TwitchChat.StopReading();
			}
		}

		private void ClearUnusedEntries()
		{
			ConfigFile config = ((BaseUnityPlugin)Plugin.Instance).Config;
			PropertyInfo property = ((object)config).GetType().GetProperty("OrphanedEntries", BindingFlags.Instance | BindingFlags.NonPublic);
			Dictionary<ConfigDefinition, string> dictionary = (Dictionary<ConfigDefinition, string>)property.GetValue(config, null);
			dictionary.Clear();
			config.Save();
		}

		internal void SetHostConfigData(SyncedConfigData syncedConfigData)
		{
			if (!NetworkUtils.IsServer)
			{
				_hostConfigData = syncedConfigData;
			}
		}

		private void SyncedConfigsChanged()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			if (NetworkUtils.IsServer)
			{
				PluginNetworkBehaviour.Instance.SendConfigToPlayerClientRpc(new SyncedConfigData(this));
			}
		}
	}
	internal static class TwitchChat
	{
		public const string TwitchServer = "irc.chat.twitch.tv";

		public const int TwitchPort = 6667;

		private static TcpClient _tcpClient;

		private static NetworkStream _stream;

		private static StreamReader _reader;

		private static StreamWriter _writer;

		private static CancellationTokenSource _cts;

		private static Task _readTask;

		public static string TwitchChannel => ("#" + Plugin.ConfigManager.TwitchIntegration_Username).Trim();

		public static bool IsReading { get; private set; }

		public static bool IsBusy { get; private set; }

		public static DateTime? TimeStartedReading { get; private set; }

		public static Action<TwitchMessage> OnMessage { get; set; }

		public static async Task StartReading()
		{
			Plugin.Instance.LogMessageExtended("[TwitchChat] Trying to start reading.");
			if (TwitchChannel == "#")
			{
				Plugin.Instance.LogMessageExtended("[TwitchChat] Twitch username is empty!");
				return;
			}
			if (IsBusy)
			{
				Plugin.Instance.LogMessageExtended("[TwitchChat] Process is busy.");
				return;
			}
			if (IsReading)
			{
				Plugin.Instance.LogMessageExtended("[TwitchChat] You are already reading.");
				await StopReading();
			}
			IsBusy = true;
			_cts = new CancellationTokenSource();
			CancellationToken token = _cts.Token;
			try
			{
				_tcpClient = new TcpClient("irc.chat.twitch.tv", 6667);
				_stream = _tcpClient.GetStream();
				_reader = new StreamReader(_stream);
				_writer = new StreamWriter(_stream)
				{
					AutoFlush = true
				};
				await _writer.WriteLineAsync("PASS 1337");
				await _writer.WriteLineAsync("NICK justinfan123");
				await _writer.WriteLineAsync("JOIN " + TwitchChannel);
				Plugin.Instance.LogMessageExtended("[TwitchChat] Started reading.");
				IsReading = true;
				TimeStartedReading = DateTime.Now;
			}
			catch (Exception ex)
			{
				Exception e = ex;
				Plugin.logger.LogError((object)$"[TwitchChat] Failed to start reading Twitch chat. {e}");
			}
			finally
			{
				IsBusy = false;
			}
			_readTask = Task.Run(async delegate
			{
				try
				{
					while (!token.IsCancellationRequested)
					{
						string message = await _reader.ReadLineAsync();
						if (message != null)
						{
							if (message.StartsWith("PING"))
							{
								Plugin.Instance.LogMessageExtended(message);
								await _writer.WriteLineAsync("PONG " + message.Split(' ')[1]);
								Plugin.Instance.LogMessageExtended("[TwitchChat] Responded with PONG to keep connection alive.");
							}
							else
							{
								ParseMessage(message);
							}
						}
					}
				}
				catch (TaskCanceledException)
				{
					Plugin.logger.LogError((object)"[TwitchChat] StartReading task canceled.");
				}
				catch (Exception ex3)
				{
					Exception e2 = ex3;
					if (Plugin.ConfigManager.TwitchIntegration_Enabled)
					{
						Plugin.logger.LogError((object)$"[TwitchChat] StartReading task failed. {e2}");
					}
				}
				finally
				{
					IsReading = false;
				}
			}, token);
		}

		public static async Task StopReading()
		{
			Plugin.Instance.LogMessageExtended("[TwitchChat] Trying to stop reading.");
			if (!IsReading || IsBusy)
			{
				Plugin.Instance.LogMessageExtended("[TwitchChat] Not reading or busy. No need to stop or wait for the current process.");
				return;
			}
			IsBusy = true;
			if (_cts != null)
			{
				_cts.Cancel();
				try
				{
				}
				catch (TaskCanceledException)
				{
				}
				finally
				{
					IsReading = false;
					TimeStartedReading = null;
					_reader?.Close();
					_writer?.Close();
					_stream?.Close();
					_tcpClient?.Close();
					Plugin.Instance.LogMessageExtended("[TwitchChat] Stopped reading.");
				}
			}
			IsBusy = false;
		}

		private static void ParseMessage(string message)
		{
			if (message.StartsWith(":tmi.twitch.tv") || message.StartsWith(":justinfan123"))
			{
				Plugin.Instance.LogMessageExtended(message);
			}
			else if (message.StartsWith(":"))
			{
				string[] array = message.Split(' ');
				string text = array[0].Substring(1).Split('!')[0];
				string text2 = array[2];
				string text3 = message.Substring(message.IndexOf(text2) + text2.Length + 2);
				Plugin.Instance.LogMessageExtended($"[TwitchChat] [{DateTime.Now:HH:mm}] info: [{text2}] <{text}>: {text3}");
				if (Plugin.ConfigManager.TwitchIntegration_Enabled)
				{
					OnMessage?.Invoke(new TwitchMessage(text, text3));
				}
			}
		}
	}
	public struct TwitchMessage
	{
		public string Sender;

		public string Message;

		public TwitchMessage(string sender, string message)
		{
			Sender = sender;
			Message = message;
		}
	}
	internal static class TwitchEvents
	{
		public static Action<TwitchSubEvent> OnSub { get; set; }

		public static Action<TwitchBitsEvents> OnBits { get; set; }

		public static void Initialize()
		{
			TwitchChat.OnMessage = (Action<TwitchMessage>)Delegate.Combine(TwitchChat.OnMessage, new Action<TwitchMessage>(ParseMessageForSub));
			TwitchChat.OnMessage = (Action<TwitchMessage>)Delegate.Combine(TwitchChat.OnMessage, new Action<TwitchMessage>(ParseMessageForBits));
		}

		private static void ParseMessageForSub(TwitchMessage twitchMessage)
		{
			if (!Plugin.ConfigManager.TwitchSubEvent_Enabled || !IsCorrectUserForEvents(twitchMessage.Sender))
			{
				return;
			}
			string text = twitchMessage.Message.Replace("@", "");
			text = text.Replace("(test)", "").Trim();
			if (!IsSubMessage(text, out var subType))
			{
				return;
			}
			try
			{
				Match match = Regex.Match(text, "^(\\w+)\\s");
				string sender = (match.Success ? match.Groups[1].Value : string.Empty);
				Match match2 = Regex.Match(text, "gifted\\s(\\d+)\\s");
				int amount = ((!match2.Success) ? 1 : int.Parse(match2.Groups[1].Value));
				Match match3 = Regex.Match(text, "for\\s(\\d+)\\s+months");
				int months = ((!match3.Success) ? 1 : int.Parse(match3.Groups[1].Value));
				Match match4 = Regex.Match(text, "gifted a sub to (\\w+)\\s");
				string target = (match4.Success ? match4.Groups[1].Value : string.Empty);
				InvokeActionNextFrame(OnSub, new TwitchSubEvent(sender, subType, 1, amount, months, target));
			}
			catch (Exception arg)
			{
				Plugin.logger.LogError((object)$"[TwitchEvents] Failed to parse message for Twitch sub event. {arg}");
			}
		}

		private static bool IsSubMessage(string message, out TwitchSubType subType)
		{
			subType = TwitchSubType.Sub;
			if (!message.EndsWith("<3"))
			{
				return false;
			}
			if (message.Contains("just subbed", StringComparison.OrdinalIgnoreCase))
			{
				return true;
			}
			if (message.Contains("just resubbed", StringComparison.OrdinalIgnoreCase))
			{
				subType = TwitchSubType.Resub;
				return true;
			}
			if (message.Contains("gifted a sub to", StringComparison.OrdinalIgnoreCase))
			{
				subType = TwitchSubType.Gift;
				return true;
			}
			if (message.Contains("gifted", StringComparison.OrdinalIgnoreCase))
			{
				subType = TwitchSubType.MysteryGift;
				return true;
			}
			return false;
		}

		private static void ParseMessageForBits(TwitchMessage twitchMessage)
		{
			if (!Plugin.ConfigManager.TwitchBitsEvent_Enabled || !IsCorrectUserForEvents(twitchMessage.Sender))
			{
				return;
			}
			string text = twitchMessage.Message.Replace("@", "");
			text = text.Replace("(test)", "").Trim();
			if (!IsBitsMessage(text))
			{
				return;
			}
			try
			{
				Match match = Regex.Match(text, "^(\\w+)\\s");
				string sender = (match.Success ? match.Groups[1].Value : string.Empty);
				Match match2 = Regex.Match(text, "just dropped\\s(\\d+)\\s+bits");
				int amount = (match2.Success ? int.Parse(match2.Groups[1].Value) : 0);
				InvokeActionNextFrame(OnBits, new TwitchBitsEvents(sender, amount));
			}
			catch (Exception arg)
			{
				Plugin.logger.LogError((object)$"[TwitchEvents] Failed to parse message for Twitch bits event. {arg}");
			}
		}

		private static bool IsBitsMessage(string message)
		{
			if (!message.EndsWith("<3"))
			{
				return false;
			}
			if (!message.Contains("just dropped", StringComparison.OrdinalIgnoreCase))
			{
				return false;
			}
			if (!message.Contains("bits", StringComparison.OrdinalIgnoreCase))
			{
				return false;
			}
			return true;
		}

		private static bool IsCorrectUserForEvents(string sender)
		{
			string value = Plugin.ConfigManager.TwitchEvent_CheckMessageFromUser.Trim();
			if (string.IsNullOrWhiteSpace(value) || !sender.Equals(value, StringComparison.OrdinalIgnoreCase))
			{
				return false;
			}
			return true;
		}

		public static void InvokeActionNextFrame<T>(Action<T> action, T data)
		{
			Utils.StartCoroutine(InvokeActionNextFrameCoroutine(action, data));
		}

		private static IEnumerator InvokeActionNextFrameCoroutine<T>(Action<T> action, T data)
		{
			yield return null;
			action?.Invoke(data);
		}
	}
	[Serializable]
	public class TwitchEvent
	{
		public string Sender;

		public TwitchEvent()
		{
		}

		public TwitchEvent(string sender)
		{
			Sender = sender;
		}
	}
	[Serializable]
	public class TwitchSubEvent : TwitchEvent, INetworkSerializable
	{
		public TwitchSubType SubType;

		public int Tier;

		public int Amount;

		public int Months;

		public string Target;

		public TwitchSubEvent()
		{
		}

		public TwitchSubEvent(string sender, TwitchSubType subType, int tier = 1, int amount = 1, int months = 1, string target = "")
			: base(sender)
		{
			SubType = subType;
			Tier = tier;
			Amount = amount;
			Months = months;
			Target = target;
		}

		public unsafe void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter
		{
			//IL_001a: 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)
			//IL_0031: 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_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			serializer.SerializeValue(ref Sender, false);
			((BufferSerializer<TwitchSubType>*)(&serializer))->SerializeValue<TwitchSubType>(ref SubType, default(ForEnums));
			((BufferSerializer<int>*)(&serializer))->SerializeValue<int>(ref Tier, default(ForPrimitives));
			((BufferSerializer<int>*)(&serializer))->SerializeValue<int>(ref Amount, default(ForPrimitives));
			((BufferSerializer<int>*)(&serializer))->SerializeValue<int>(ref Months, default(ForPrimitives));
			serializer.SerializeValue(ref Target, false);
		}
	}
	public enum TwitchSubType
	{
		Sub,
		Resub,
		Gift,
		MysteryGift
	}
	[Serializable]
	public class TwitchBitsEvents : TwitchEvent, INetworkSerializable
	{
		public int Amount;

		public TwitchBitsEvents()
		{
		}

		public TwitchBitsEvents(string sender, int amount)
			: base(sender)
		{
			Amount = amount;
		}

		public unsafe void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter
		{
			//IL_001a: 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)
			serializer.SerializeValue(ref Sender, false);
			((BufferSerializer<int>*)(&serializer))->SerializeValue<int>(ref Amount, default(ForPrimitives));
		}
	}
	internal static class Utils
	{
		public static bool RandomPercent(float percent)
		{
			if (percent <= 0f)
			{
				return false;
			}
			if (percent >= 100f)
			{
				return true;
			}
			return Random.value * 100f <= percent;
		}

		public static string GetEnumName(object e)
		{
			try
			{
				return Enum.GetName(e.GetType(), e);
			}
			catch
			{
				return string.Empty;
			}
		}

		public static string GetFormattedString(string text)
		{
			if (string.IsNullOrWhiteSpace(text))
			{
				return string.Empty;
			}
			return string.Join(" ", from word in text.Split(' ', StringSplitOptions.RemoveEmptyEntries)
				select $"{char.ToUpper(word[0])}{word.Substring(1).ToLower()}");
		}

		public static bool CanPerformHotkeys()
		{
			PlayerControllerB localPlayerScript = PlayerUtils.GetLocalPlayerScript();
			if ((Object)(object)localPlayerScript == (Object)null)
			{
				return false;
			}
			if (localPlayerScript.isPlayerDead)
			{
				return false;
			}
			if (localPlayerScript.isTypingChat)
			{
				return false;
			}
			if (localPlayerScript.quickMenuManager.isMenuOpen)
			{
				return false;
			}
			return true;
		}

		public static Coroutine StartCoroutine(IEnumerator routine)
		{
			if ((Object)(object)Plugin.Instance != (Object)null)
			{
				return ((MonoBehaviour)Plugin.Instance).StartCoroutine(routine);
			}
			if ((Object)(object)GameNetworkManager.Instance != (Object)null)
			{
				return ((MonoBehaviour)GameNetworkManager.Instance).StartCoroutine(routine);
			}
			Plugin.logger.LogError((object)("Failed to start coroutine. " + routine));
			return null;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "com.github.zehsteam.MonsterHotkeys";

		public const string PLUGIN_NAME = "MonsterHotkeys";

		public const string PLUGIN_VERSION = "1.3.6";
	}
}
namespace com.github.zehsteam.MonsterHotkeys.Patches
{
	[HarmonyPatch(typeof(EnemyAI))]
	internal static class EnemyAIPatch
	{
		public static EnemyAI EnemyAttackingLocalPlayer { get; private set; }

		[HarmonyPatch("KillEnemy")]
		[HarmonyPrefix]
		private static void KillEnemyPatch(ref EnemyAI __instance)
		{
			if (__instance.enemyType.canDie)
			{
				EnemyNametagManager.Instance?.DespawnNametagOnLocalClient(__instance);
			}
		}

		[HarmonyPatch("MeetsStandardPlayerCollisionConditions")]
		[HarmonyPostfix]
		private static void MeetsStandardPlayerCollisionConditionsPatch(ref EnemyAI __instance, ref PlayerControllerB __result)
		{
			if (PlayerUtils.IsLocalPlayer(__result))
			{
				EnemyAttackingLocalPlayer = __instance;
			}
		}
	}
	[HarmonyPatch(typeof(GameNetworkManager))]
	internal static class GameNetworkManagerPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void StartPatch()
		{
			AddNetworkPrefabs();
		}

		private static void AddNetworkPrefabs()
		{
			AddNetworkPrefab(Content.NetworkHandlerPrefab);
		}

		private static void AddNetworkPrefab(GameObject prefab)
		{
			if ((Object)(object)prefab == (Object)null)
			{
				Plugin.logger.LogError((object)"Failed to add network prefab. GameObject is null.");
				return;
			}
			NetworkManager.Singleton.AddNetworkPrefab(prefab);
			Plugin.logger.LogInfo((object)("Registered \"" + ((Object)prefab).name + "\" network prefab."));
		}
	}
	[HarmonyPatch(typeof(HUDManager))]
	internal static class HUDManagerPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void StartPatch()
		{
			Plugin.Instance.SpawnMessageCanvas();
		}
	}
	[HarmonyPatch(typeof(MenuManager))]
	internal static class MenuManagerPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void StartPatch()
		{
			if (Plugin.ConfigManager.TwitchIntegration_Enabled && !TwitchChat.IsReading)
			{
				TwitchChat.StartReading();
			}
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal static class PlayerControllerBPatch
	{
		[HarmonyPatch("KillPlayer")]
		[HarmonyPostfix]
		private static void KillPlayerPatch(ref PlayerControllerB __instance)
		{
			if (!PlayerUtils.IsLocalPlayer(__instance) || (Object)(object)EnemyAIPatch.EnemyAttackingLocalPlayer == (Object)null)
			{
				return;
			}
			StackTrace stackTrace = new StackTrace();
			for (int i = 1; i < stackTrace.FrameCount; i++)
			{
				StackFrame frame = stackTrace.GetFrame(i);
				MethodBase method = frame.GetMethod();
				Type declaringType = method.DeclaringType;
				if (!(declaringType != null))
				{
					continue;
				}
				Type type = declaringType;
				if (declaringType.Name.Contains("<") || declaringType.Name.Contains("+"))
				{
					type = declaringType.DeclaringType;
				}
				if (type != null && type.IsSubclassOf(typeof(EnemyAI)))
				{
					if (!(type != ((object)EnemyAIPatch.EnemyAttackingLocalPlayer).GetType()) && __instance.isPlayerDead)
					{
						LocalPlayerDiedToEnemy();
					}
					break;
				}
			}
		}

		private static void LocalPlayerDiedToEnemy()
		{
			EnemyAI enemyAttackingLocalPlayer = EnemyAIPatch.EnemyAttackingLocalPlayer;
			if (!((Object)(object)enemyAttackingLocalPlayer == (Object)null) && EnemyNametagManager.Instance.EnemyNametagPairs.TryGetValue(enemyAttackingLocalPlayer, out var value))
			{
				EnemyData byEnemyName = Content.EnemyDataList.GetByEnemyName(enemyAttackingLocalPlayer.enemyType.enemyName);
				string text = "You died to a " + byEnemyName.EnemyDisplayName + " from " + value.Username;
				if (!PlayerUtils.IsLocalPlayer(value.PlayerScript) && value.Username != value.PlayerScript.playerUsername)
				{
					text = text + " <color=#9c9c9c>(Spawned from " + value.PlayerScript.playerUsername + ")</color>";
				}
				DeathMessage.Instance?.Show(text);
			}
		}
	}
	[HarmonyPatch(typeof(RoundManager))]
	internal static class RoundManagerPatch
	{
		private static bool ShipArrived;

		[HarmonyPatch("LoadNewLevel")]
		[HarmonyPostfix]
		private static void LoadNewLevelPatch()
		{
			Plugin.Instance.OnNewLevelLoaded();
		}

		[HarmonyPatch("GenerateNewLevelClientRpc")]
		[HarmonyPrefix]
		private static void GenerateNewLevelClientRpcPatch()
		{
			if (!NetworkUtils.IsServer)
			{
				Plugin.Instance.OnNewLevelLoaded();
			}
		}

		[HarmonyPatch("FinishGeneratingNewLevelClientRpc")]
		[HarmonyPostfix]
		private static void FinishGeneratingNewLevelClientRpcPatch()
		{
			if (!ShipArrived)
			{
				ShipArrived = true;
				if (StartOfRound.Instance.currentLevel.spawnEnemiesAndScrap)
				{
					EnemyHelper.PlayTwitchEventsFromQueue();
					PlushieManager.Instance?.PlayTwitchEventsFromQueue();
					Utils.StartCoroutine(ResetShipArrivedAfterTime(10f));
				}
			}
		}

		private static IEnumerator ResetShipArrivedAfterTime(float time)
		{
			yield return (object)new WaitForSeconds(time);
			ShipArrived = false;
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	internal static class StartOfRoundPatch
	{
		[HarmonyPatch("Awake")]
		[HarmonyPostfix]
		private static void AwakePatch()
		{
			SpawnNetworkHandler();
		}

		private static void SpawnNetworkHandler()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			if (NetworkUtils.IsServer)
			{
				GameObject val = Object.Instantiate<GameObject>(Content.NetworkHandlerPrefab, Vector3.zero, Quaternion.identity);
				val.GetComponent<NetworkObject>().Spawn(false);
			}
		}

		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		[HarmonyPriority(0)]
		private static void StartPatch()
		{
			Content.EnemyDataList.AddNewEnemyTypes();
		}

		[HarmonyPatch("OnClientConnect")]
		[HarmonyPrefix]
		private static void OnClientConnectPatch(ref ulong clientId)
		{
			SendConfigToNewConnectedPlayer(clientId);
		}

		private static void SendConfigToNewConnectedPlayer(ulong clientId)
		{
			//IL_0011: 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_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: 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)
			if (NetworkUtils.IsServer)
			{
				ClientRpcParams val = default(ClientRpcParams);
				val.Send = new ClientRpcSendParams
				{
					TargetClientIds = new <>z__ReadOnlySingleElementList<ulong>(clientId)
				};
				ClientRpcParams clientRpcParams = val;
				Plugin.logger.LogInfo((object)$"Sending config to client: {clientId}");
				PluginNetworkBehaviour.Instance.SendConfigToPlayerClientRpc(new SyncedConfigData(Plugin.ConfigManager), clientRpcParams);
			}
		}

		[HarmonyPatch("OnLocalDisconnect")]
		[HarmonyPrefix]
		private static void OnLocalDisconnectPatch()
		{
			Plugin.Instance.OnLocalDisconnect();
		}
	}
}
namespace com.github.zehsteam.MonsterHotkeys.MonoBehaviours
{
	public class AudioPlayer : MonoBehaviour
	{
		public AudioSource AudioSource;

		public AudioClip BeforeSpawnSFX;

		public AudioClip GenericSpawnSFX;

		private Coroutine _playSoundCoroutine;

		public void PlaySound(AudioClip spawnSFX, float volumeScale)
		{
			if (_playSoundCoroutine != null)
			{
				((MonoBehaviour)this).StopCoroutine(_playSoundCoroutine);
			}
			_playSoundCoroutine = ((MonoBehaviour)this).StartCoroutine(PlaySoundCoroutine(spawnSFX, volumeScale));
		}

		private IEnumerator PlaySoundCoroutine(AudioClip spawnSFX, float volumeScale)
		{
			if ((Object)(object)spawnSFX == (Object)null)
			{
				spawnSFX = GenericSpawnSFX;
			}
			AudioSource.PlayOneShot(BeforeSpawnSFX, volumeScale);
			yield return (object)new WaitForSeconds(BeforeSpawnSFX.length + 0.25f);
			AudioSource.PlayOneShot(spawnSFX, volumeScale);
			yield return (object)new WaitForSeconds(spawnSFX.length);
		}
	}
	public class AudioPlayerManager : NetworkBehaviour
	{
		public static AudioPlayerManager Instance;

		public GameObject AudioPlayerPrefab;

		private Queue<AudioPlayer> _pool = new Queue<AudioPlayer>();

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
		}

		private void Start()
		{
			UpdateSettings();
		}

		private void CreatePool()
		{
			ClearPool();
			int num = 100;
			for (int i = 0; i < num; i++)
			{
				GameObject val = Object.Instantiate<GameObject>(AudioPlayerPrefab);
				val.transform.SetParent(((Component)this).transform);
				AudioPlayer component = val.GetComponent<AudioPlayer>();
				val.SetActive(false);
				_pool.Enqueue(component);
			}
			Plugin.Instance.LogInfoExtended($"Created AudioPlayer pool. (amount: {num})");
		}

		private void ClearPool()
		{
			if (_pool.Count == 0)
			{
				return;
			}
			foreach (AudioPlayer item in _pool)
			{
				Object.Destroy((Object)(object)((Component)item).gameObject);
			}
			_pool.Clear();
			Plugin.Instance.LogInfoExtended("Cleared AudioPlayer pool.");
		}

		private AudioPlayer SpawnFromPool(Vector3 position, AudioClip spawnSFX, float volumeScale)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			AudioPlayer audioPlayer = _pool.Dequeue();
			((Component)audioPlayer).gameObject.SetActive(false);
			((Component)audioPlayer).gameObject.SetActive(true);
			((Component)audioPlayer).transform.position = position;
			audioPlayer.PlaySound(spawnSFX, volumeScale);
			_pool.Enqueue(audioPlayer);
			return audioPlayer;
		}

		public void SpawnOnServer(string enemyName, Vector3[] positions, bool inFactory)
		{
			if (NetworkUtils.IsServer)
			{
				SpawnClientRpc(enemyName, positions, inFactory);
				SpawnOnLocalClient(enemyName, positions, inFactory);
			}
		}

		[ClientRpc]
		public void SpawnClientRpc(string enemyName, Vector3[] positions, bool inFactory)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: 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_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: 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(1947173315u, val, (RpcDelivery)0);
				bool flag = enemyName != null;
				((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
				if (flag)
				{
					((FastBufferWriter)(ref val2)).WriteValueSafe(enemyName, false);
				}
				bool flag2 = positions != null;
				((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flag2, default(ForPrimitives));
				if (flag2)
				{
					((FastBufferWriter)(ref val2)).WriteValueSafe(positions);
				}
				((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref inFactory, default(ForPrimitives));
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 1947173315u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost) && !NetworkUtils.IsServer)
			{
				SpawnOnLocalClient(enemyName, positions, inFactory);
			}
		}

		private void SpawnOnLocalClient(string enemyName, Vector3[] positions, bool inFactory)
		{
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			if (_pool.Count == 0)
			{
				return;
			}
			PlayerControllerB localPlayerScript = PlayerUtils.GetLocalPlayerScript();
			if ((Object)(object)localPlayerScript == (Object)null)
			{
				return;
			}
			bool flag = true;
			if (localPlayerScript.isPlayerDead)
			{
				if ((Object)(object)localPlayerScript.spectatedPlayerScript != (Object)null && localPlayerScript.spectatedPlayerScript.isInsideFactory && !inFactory)
				{
					flag = false;
				}
			}
			else if (localPlayerScript.isInsideFactory && !inFactory)
			{
				flag = false;
			}
			if (flag)
			{
				AudioClip spawnSFX = null;
				float num = 0.8f;
				EnemyData byEnemyName = Content.EnemyDataList.GetByEnemyName(enemyName);
				if (byEnemyName != null)
				{
					spawnSFX = byEnemyName.SpawnSFX;
					num = byEnemyName.ConfigData.SpawnSFXVolume.Value * 0.01f;
				}
				else
				{
					num = 0.8f;
				}
				foreach (Vector3 position in positions)
				{
					SpawnFromPool(position, spawnSFX, num);
				}
			}
		}

		public void UpdateSettings()
		{
			if (Plugin.ConfigManager.MuteSpawnSFX)
			{
				ClearPool();
			}
			else
			{
				CreatePool();
			}
		}

		public static void OnSettingsChanged(object sender, EventArgs e)
		{
			if (!((Object)(object)Instance == (Object)null))
			{
				Instance.UpdateSettings();
			}
		}

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

		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeRPCS_AudioPlayerManager()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			NetworkManager.__rpc_func_table.Add(1947173315u, new RpcReceiveHandler(__rpc_handler_1947173315));
		}

		private static void __rpc_handler_1947173315(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: 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_009e: 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_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				bool flag = default(bool);
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives));
				string enemyName = null;
				if (flag)
				{
					((FastBufferReader)(ref reader)).ReadValueSafe(ref enemyName, false);
				}
				bool flag2 = default(bool);
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag2, default(ForPrimitives));
				Vector3[] positions = null;
				if (flag2)
				{
					((FastBufferReader)(ref reader)).ReadValueSafe(ref positions);
				}
				bool inFactory = default(bool);
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref inFactory, default(ForPrimitives));
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((AudioPlayerManager)(object)target).SpawnClientRpc(enemyName, positions, inFactory);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected internal override string __getTypeName()
		{
			return "AudioPlayerManager";
		}
	}
	public class DeathMessage : MonoBehaviour
	{
		public static DeathMessage Instance;

		public TextMeshProUGUI TextUGUI;

		public CanvasGroup CanvasGroup;

		private Coroutine _playAnimation;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
		}

		private void Start()
		{
			CanvasGroup.alpha = 0f;
		}

		public void Show(string message)
		{
			if (_playAnimation != null)
			{
				((MonoBehaviour)this).StopCoroutine(_playAnimation);
			}
			((TMP_Text)TextUGUI).text = message;
			_playAnimation = ((MonoBehaviour)this).StartCoroutine(PlayAnimation(15f));
		}

		private IEnumerator PlayAnimation(float durtaion)
		{
			CanvasGroup.alpha = 1f;
			yield return (object)new WaitForSeconds(durtaion);
			float fadeOutDuration = 1f;
			for (float timer = 0f; timer < fadeOutDuration; timer += Time.deltaTime)
			{
				float percent = 1f / fadeOutDuration * timer;
				float alpha = 1f + -1f * percent;
				CanvasGroup.alpha = alpha;
				yield return null;
			}
			CanvasGroup.alpha = 0f;
		}
	}
	public class EnemyNametag : MonoBehaviour
	{
		public static float BaseScale = 2f;

		public TextMeshProUGUI UsernameText;

		public Image BackgroundImage;

		public CanvasGroup CanvasGroup;

		public string Username { get; private set; }

		public PlayerControllerB PlayerScript { get; private set; }

		public EnemyAI EnemyAI { get; private set; }

		public EnemyNametagData NametagData { get; private set; }

		private void Start()
		{
			if ((Object)(object)((Component)this).transform.parent == (Object)null)
			{
				return;
			}
			EnemyAI = ((Component)((Component)this).transform.parent).GetComponent<EnemyAI>();
			if (!((Object)(object)EnemyAI == (Object)null))
			{
				EnemyData byEnemyName = Content.EnemyDataList.GetByEnemyName(EnemyAI.enemyType.enemyName);
				if (byEnemyName != null)
				{
					NametagData = byEnemyName.NametagData;
				}
				SetPosition();
				((MonoBehaviour)this).StartCoroutine(LateStartCoroutine());
			}
		}

		private IEnumerator LateStartCoroutine()
		{
			yield return null;
			LateStart();
		}

		private void LateStart()
		{
			string enemyName = EnemyAI.enemyType.enemyName;
			string text = enemyName;
			if (!(text == "Manticoil"))
			{
				if (text == "RadMech")
				{
					EnemyAI enemyAI = EnemyAI;
					OldBird_LateStart((RadMechAI)(object)((enemyAI is RadMechAI) ? enemyAI : null));
				}
			}
			else
			{
				EnemyAI enemyAI2 = EnemyAI;
				Manticoil_LateStart((DoublewingAI)(object)((enemyAI2 is DoublewingAI) ? enemyAI2 : null));
			}
			SetScale();
		}

		private void Manticoil_LateStart(DoublewingAI doublewingAI)
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)doublewingAI == (Object)null))
			{
				((Component)this).transform.SetParent(doublewingAI.Body);
				((Component)this).transform.localPosition = new Vector3(0f, 3f, 0f);
			}
		}

		private void OldBird_LateStart(RadMechAI radMechAI)
		{
			if ((Object)(object)radMechAI == (Object)null)
			{
				return;
			}
			try
			{
				Transform parent = ((Component)radMechAI).transform.Find("MeshContainer").Find("AnimContainer").Find("metarig");
				((Component)this).transform.SetParent(parent);
			}
			catch
			{
			}
		}

		private void Update()
		{
			if ((Object)(object)EnemyAI == (Object)null || EnemyAI.isEnemyDead)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}
			switch (EnemyAI.enemyType.enemyName)
			{
			case "Clay Surgeon":
			{
				EnemyAI enemyAI3 = EnemyAI;
				Barber_Update((ClaySurgeonAI)(object)((enemyAI3 is ClaySurgeonAI) ? enemyAI3 : null));
				break;
			}
			case "Earth Leviathan":
			{
				EnemyAI enemyAI2 = EnemyAI;
				EarthLeviathan_Update((SandWormAI)(object)((enemyAI2 is SandWormAI) ? enemyAI2 : null));
				break;
			}
			case "Girl":
			{
				EnemyAI enemyAI = EnemyAI;
				GhostGirl_Update((DressGirlAI)(object)((enemyAI is DressGirlAI) ? enemyAI : null));
				break;
			}
			}
		}

		private void Barber_Update(ClaySurgeonAI claySurgeonAI)
		{
			//IL_0031: 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)
			if (!((Object)(object)claySurgeonAI == (Object)null))
			{
				PlayerControllerB localPlayerScript = PlayerUtils.GetLocalPlayerScript();
				if ((Object)(object)localPlayerScript == (Object)null)
				{
					SetVisible(value: false);
				}
				else
				{
					SetVisible(Vector3.Distance(((Component)claySurgeonAI).transform.position, ((Component)localPlayerScript).transform.position) <= claySurgeonAI.maxDistance);
				}
			}
		}

		private void EarthLeviathan_Update(SandWormAI sandWormAI)
		{
			if (!((Object)(object)sandWormAI == (Object)null))
			{
				SetVisible(sandWormAI.emerged);
			}
		}

		private void GhostGirl_Update(DressGirlAI dressGirlAI)
		{
			if (!((Object)(object)dressGirlAI == (Object)null))
			{
				if (!PlayerUtils.IsLocalPlayer(dressGirlAI.hauntingPlayer))
				{
					SetVisible(value: false);
				}
				else
				{
					SetVisible(dressGirlAI.enemyMeshEnabled);
				}
			}
		}

		private void SetVisible(bool value)
		{
			CanvasGroup.alpha = (value ? 1f : 0f);
		}

		private void LateUpdate()
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown res