Decompiled source of SCP999 v2.2.0

SCP999/ProjectSCP.SCP999.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using ProjectSCP.SCP999.NetcodePatcher;
using Unity.Netcode;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("AmazingAssets.TerrainToMesh")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp-firstpass")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("ClientNetworkTransform")]
[assembly: IgnoresAccessChecksTo("DissonanceVoip")]
[assembly: IgnoresAccessChecksTo("Facepunch Transport for Netcode for GameObjects")]
[assembly: IgnoresAccessChecksTo("Facepunch.Steamworks.Win64")]
[assembly: IgnoresAccessChecksTo("Unity.AI.Navigation")]
[assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging")]
[assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging.DocCodeExamples")]
[assembly: IgnoresAccessChecksTo("Unity.Burst")]
[assembly: IgnoresAccessChecksTo("Unity.Burst.Unsafe")]
[assembly: IgnoresAccessChecksTo("Unity.Collections")]
[assembly: IgnoresAccessChecksTo("Unity.Collections.LowLevel.ILSupport")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem.ForUI")]
[assembly: IgnoresAccessChecksTo("Unity.Jobs")]
[assembly: IgnoresAccessChecksTo("Unity.Mathematics")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.Common")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.MetricTypes")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStats")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Component")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Configuration")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Implementation")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsReporting")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetworkProfiler.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetworkSolutionInterface")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Components")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.Networking.Transport")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Csg")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.KdTree")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Poly2Tri")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Stl")]
[assembly: IgnoresAccessChecksTo("Unity.Profiling.Core")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.ShaderLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Config.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.ShaderGraph.ShaderGraphLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Authentication")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Analytics")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Configuration")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Device")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Environments")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Environments.Internal")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Internal")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Networking")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Registration")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Scheduler")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Telemetry")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Threading")]
[assembly: IgnoresAccessChecksTo("Unity.Services.QoS")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Relay")]
[assembly: IgnoresAccessChecksTo("Unity.TextMeshPro")]
[assembly: IgnoresAccessChecksTo("Unity.Timeline")]
[assembly: IgnoresAccessChecksTo("Unity.VisualEffectGraph.Runtime")]
[assembly: IgnoresAccessChecksTo("UnityEngine.ARModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.NVIDIAModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UI")]
[assembly: AssemblyCompany("ProjectSCP.SCP999")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("2.2.0.0")]
[assembly: AssemblyInformationalVersion("2.2.0+e4e644679e3c4d40ea3e0043e753b05c8a42b799")]
[assembly: AssemblyProduct("SCP999")]
[assembly: AssemblyTitle("ProjectSCP.SCP999")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.2.0.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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 SCP999
{
	internal class ContainmentJarBehavior : PhysicsProp
	{
		internal enum Contents
		{
			Empty,
			SCP999,
			Blob
		}

		private static ManualLogSource logger = Plugin.LoggerInstance;

		public Sprite[] ItemIcons = null;

		public Material[] ItemMaterials = null;

		public ScanNodeProperties ScanNode = null;

		public Contents JarContents = Contents.Empty;

		public PlayerControllerB? lastPlayerHeldBy;

		public override void Start()
		{
			((GrabbableObject)this).Start();
			((GrabbableObject)this).fallTime = 0f;
		}

		public override void GrabItem()
		{
			((GrabbableObject)this).GrabItem();
			lastPlayerHeldBy = ((GrabbableObject)this).playerHeldBy;
		}

		public override void ItemActivate(bool used, bool buttonDown = true)
		{
			((GrabbableObject)this).ItemActivate(used, buttonDown);
			if (buttonDown && JarContents != 0 && !StartOfRound.Instance.inShipPhase)
			{
				OpenJarServerRpc();
			}
		}

		public override int GetItemDataToSave()
		{
			logger.LogDebug((object)("GetItemDataToSave: " + JarContents));
			return (int)JarContents;
		}

		public override void LoadItemSaveData(int saveData)
		{
			ManualLogSource obj = logger;
			Contents contents = (Contents)saveData;
			obj.LogDebug((object)("LoadItemSaveData: " + contents));
			((GrabbableObject)this).fallTime = 0f;
			ChangeJarContentsOnLocalClient((Contents)saveData);
		}

		public void ChangeJarContentsOnLocalClient(Contents contents)
		{
			logger.LogDebug((object)("ChangeJarContentsOnLocalClient: " + contents));
			((Renderer)((GrabbableObject)this).mainObjectRenderer).material = ItemMaterials[(int)contents];
			((GrabbableObject)this).itemProperties.itemIcon = ItemIcons[(int)contents];
			JarContents = contents;
			if (JarContents == Contents.Empty)
			{
				((GrabbableObject)this).scrapValue = 0;
				((GrabbableObject)this).itemProperties.isScrap = false;
				((GrabbableObject)this).itemProperties.toolTips[0] = "";
			}
			else
			{
				((GrabbableObject)this).itemProperties.isScrap = true;
				((GrabbableObject)this).itemProperties.toolTips[0] = "Release " + JarContents.ToString() + " [LMB]";
				switch (contents)
				{
				case Contents.Blob:
					((GrabbableObject)this).SetScrapValue(Plugin.configJarSlimeValue.Value);
					break;
				case Contents.SCP999:
					((GrabbableObject)this).SetScrapValue(Plugin.configJar999Value.Value);
					break;
				}
			}
			ScanNode.subText = "Contents: " + contents;
			if ((Object)(object)((GrabbableObject)this).playerHeldBy != (Object)null && (Object)(object)Plugin.LocalPlayer == (Object)(object)((GrabbableObject)this).playerHeldBy)
			{
				HUDManager.Instance.itemSlotIcons[Plugin.LocalPlayer.currentItemSlot].sprite = ((GrabbableObject)this).itemProperties.itemIcon;
			}
		}

		[ServerRpc(RequireOwnership = false)]
		private void OpenJarServerRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: 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_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: 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)((NetworkBehaviour)this).__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				ServerRpcParams val = default(ServerRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(3572622651u, val, (RpcDelivery)0);
				((NetworkBehaviour)this).__endSendServerRpc(ref val2, 3572622651u, val, (RpcDelivery)0);
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1 || (!networkManager.IsServer && !networkManager.IsHost) || (!NetworkManager.Singleton.IsServer && !NetworkManager.Singleton.IsHost))
			{
				return;
			}
			if (JarContents == Contents.SCP999)
			{
				SpawnableEnemy val3 = Enemies.spawnableEnemies.Where((SpawnableEnemy x) => ((Object)x.enemy).name == "SCP999Enemy").FirstOrDefault();
				if (val3 != null)
				{
					NetworkObject val4 = NetworkObjectReference.op_Implicit(RoundManager.Instance.SpawnEnemyGameObject(((Component)((GrabbableObject)this).playerHeldBy).transform.position + new Vector3(0f, 0f, 3.5f), ((Component)((GrabbableObject)this).playerHeldBy).transform.rotation.y + 180f, 0, val3.enemy));
					if (Plugin.configSlimeTaming.Value)
					{
						((Component)val4).GetComponent<SCP999AI>().SetTamed(((GrabbableObject)this).playerHeldBy);
					}
				}
			}
			else if (JarContents == Contents.Blob)
			{
				SpawnableEnemyWithRarity val5 = (from x in Plugin.GetEnemies()
					where ((Object)x.enemyType).name == "Blob"
					select x).FirstOrDefault();
				if (val5 != null)
				{
					RoundManager.Instance.SpawnEnemyGameObject(((Component)((GrabbableObject)this).playerHeldBy).transform.position + new Vector3(0f, 0f, 3.5f), ((Component)((GrabbableObject)this).playerHeldBy).transform.rotation.y + 180f, 0, val5.enemyType);
				}
			}
			ChangeJarContentsClientRpc(Contents.Empty);
		}

		[ClientRpc]
		public void ChangeJarContentsClientRpc(Contents contents)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: 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)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
				{
					ClientRpcParams val = default(ClientRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(3420106347u, val, (RpcDelivery)0);
					((FastBufferWriter)(ref val2)).WriteValueSafe<Contents>(ref contents, default(ForEnums));
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 3420106347u, val, (RpcDelivery)0);
				}
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
				{
					logger.LogDebug((object)("ChangeJarContentsClientRpc: " + contents));
					ChangeJarContentsOnLocalClient(contents);
				}
			}
		}

		[ClientRpc]
		public void NotifyPlayerClientRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: 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_007c: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
				{
					ClientRpcParams val = default(ClientRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(1688014456u, val, (RpcDelivery)0);
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 1688014456u, val, (RpcDelivery)0);
				}
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost) && (Object)(object)lastPlayerHeldBy != (Object)null && (Object)(object)lastPlayerHeldBy == (Object)(object)Plugin.LocalPlayer)
				{
					HUDManager.Instance.DisplayTip("You monster!", "You are a horrible person", true, false, "LC_Tip1");
				}
			}
		}

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

		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeRPCS_ContainmentJarBehavior()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			NetworkManager.__rpc_func_table.Add(3572622651u, new RpcReceiveHandler(__rpc_handler_3572622651));
			NetworkManager.__rpc_func_table.Add(3420106347u, new RpcReceiveHandler(__rpc_handler_3420106347));
			NetworkManager.__rpc_func_table.Add(1688014456u, new RpcReceiveHandler(__rpc_handler_1688014456));
		}

		private static void __rpc_handler_3572622651(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0029: 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)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((ContainmentJarBehavior)(object)target).OpenJarServerRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_3420106347(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_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				Contents contents = default(Contents);
				((FastBufferReader)(ref reader)).ReadValueSafe<Contents>(ref contents, default(ForEnums));
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((ContainmentJarBehavior)(object)target).ChangeJarContentsClientRpc(contents);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_1688014456(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0029: 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)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((ContainmentJarBehavior)(object)target).NotifyPlayerClientRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected internal override string __getTypeName()
		{
			return "ContainmentJarBehavior";
		}
	}
	[HarmonyPatch(typeof(DepositItemsDesk))]
	internal class DepositItemsDeskPatch
	{
		private static ManualLogSource logger = Plugin.LoggerInstance;

		[HarmonyPostfix]
		[HarmonyPatch("delayedAcceptanceOfItems")]
		public static void delayedAcceptanceOfItemsPostFix(GrabbableObject[] objectsOnDesk)
		{
			if (!NetworkManager.Singleton.IsHost && !NetworkManager.Singleton.IsServer)
			{
				return;
			}
			foreach (GrabbableObject val in objectsOnDesk)
			{
				if ((Object)(object)((Component)val).GetComponent<ContainmentJarBehavior>() != (Object)null)
				{
					ContainmentJarBehavior component = ((Component)val).GetComponent<ContainmentJarBehavior>();
					if (component.JarContents == ContainmentJarBehavior.Contents.SCP999)
					{
						component.NotifyPlayerClientRpc();
					}
				}
			}
		}
	}
	[BepInPlugin("ProjectSCP.SCP999", "SCP999", "2.2.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public static Plugin PluginInstance;

		public static ManualLogSource LoggerInstance;

		private readonly Harmony harmony = new Harmony("ProjectSCP.SCP999");

		public static AssetBundle? ModAssets;

		public static ConfigEntry<string> config999LevelRarities;

		public static ConfigEntry<string> config999CustomLevelRarities;

		public static ConfigEntry<int> config999SCPDungeonRarity;

		public static ConfigEntry<float> config999Size;

		public static ConfigEntry<int> configPlayerHealAmount;

		public static ConfigEntry<int> configEnemyHealAmount;

		public static ConfigEntry<float> configPlayerDetectionRange;

		public static ConfigEntry<float> configEnemyDetectionRange;

		public static ConfigEntry<float> configFollowRange;

		public static ConfigEntry<float> configHuggingRange;

		public static ConfigEntry<int> configMaxCandy;

		public static ConfigEntry<float> configInsanityDecreaseRate;

		public static ConfigEntry<bool> configEnableJar;

		public static ConfigEntry<int> configJarPrice;

		public static ConfigEntry<int> configJar999Value;

		public static ConfigEntry<int> configJarSlimeValue;

		public static ConfigEntry<bool> configSlimeTaming;

		public static List<string> Sweets = new List<string>
		{
			"Blue Candy", "Green Candy", "Pink Candy", "Purple Candy", "Rainbow Candy", "Red Candy", "Yellow Candy", "Black Candy", "Candy", "Cake",
			"SCP-559"
		};

		public static PlayerControllerB LocalPlayer => StartOfRound.Instance.localPlayerController;

		public static bool IsServerOrHost => NetworkManager.Singleton.IsServer || NetworkManager.Singleton.IsHost;

		public static PlayerControllerB PlayerFromId(ulong id)
		{
			return StartOfRound.Instance.allPlayerScripts.Where((PlayerControllerB x) => x.actualClientId == id).FirstOrDefault();
		}

		private void Awake()
		{
			if ((Object)(object)PluginInstance == (Object)null)
			{
				PluginInstance = this;
			}
			LoggerInstance = ((BaseUnityPlugin)PluginInstance).Logger;
			harmony.PatchAll();
			InitializeNetworkBehaviours();
			config999LevelRarities = ((BaseUnityPlugin)this).Config.Bind<string>("SCP-999 Rarities", "Level Rarities", "ExperimentationLevel:100, AssuranceLevel:75, VowLevel:75, OffenseLevel:50, AdamanceLevel:65, MarchLevel:50, RendLevel:45, DineLevel:45, TitanLevel:75, ArtificeLevel:70, EmbrionLevel:100, Modded:50", "Rarities for each level. See default for formatting.");
			config999CustomLevelRarities = ((BaseUnityPlugin)this).Config.Bind<string>("SCP-999 Rarities", "Custom Level Rarities", "Secret LabsLevel:150", "Rarities for modded levels. Same formatting as level rarities.");
			config999SCPDungeonRarity = ((BaseUnityPlugin)this).Config.Bind<int>("SCP-999 Rarities", "SCP Dungeon Rarity", 150, "The rarity of SCP-999 in the SCP Dungeon. Set to -1 to use level rarities.");
			config999Size = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Size", 1f, "How big SCP-999 is");
			configPlayerHealAmount = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Player Heal Amount", 10, "How much SCP-999 heals the player per second");
			configEnemyHealAmount = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Enemy Heal Amount", 1, "How much SCP-999 heals the enemy per second");
			configPlayerDetectionRange = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Player Detection Range", 50f, "How far SCP-999 can detect you");
			configEnemyDetectionRange = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Enemy Detection Range", 15f, "How far SCP-999 can detect enemies");
			configFollowRange = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Follow Range", 5f, "How far SCP-999 can follow you or other enemies");
			configHuggingRange = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Hugging Range", 2f, "How far SCP-999 will be to you when rushing over to hug/heal you");
			configMaxCandy = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Max Candy", 3, "Max amount of candy SCP-999 can eat before something bad happens");
			configInsanityDecreaseRate = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Insanity Decrease Rate", 5f, "How much insanity the player loses per second when SCP-999 is hugging them");
			configEnableJar = ((BaseUnityPlugin)this).Config.Bind<bool>("Containment Jar", "Enable", true, "Enable Containment Jar");
			configJarPrice = ((BaseUnityPlugin)this).Config.Bind<int>("Containment Jar", "Price", 25, "Price of Containment Jar");
			configJar999Value = ((BaseUnityPlugin)this).Config.Bind<int>("Containment Jar", "SCP-999 Value", 1, "Value of Containment Jar with SCP-999 inside it");
			configJarSlimeValue = ((BaseUnityPlugin)this).Config.Bind<int>("Containment Jar", "Slime Value", 50, "Value of Containment Jar");
			configSlimeTaming = ((BaseUnityPlugin)this).Config.Bind<bool>("Containment Jar", "Slime Taming", true, "When true, releasing SCP-999 from the containment jar will make it tamed to the person who released it. It will only follow that person unless it becomes hyper.");
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			ModAssets = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "scp999_assets"));
			if ((Object)(object)ModAssets == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Failed to load custom assets.");
				return;
			}
			LoggerInstance.LogDebug((object)("Got AssetBundle at: " + Path.Combine(directoryName, "scp999_assets")));
			if (configEnableJar.Value)
			{
				Item val = ModAssets.LoadAsset<Item>("Assets/ModAssets/ContainmentJar/ContainmentJarItem.asset");
				if ((Object)(object)val == (Object)null)
				{
					LoggerInstance.LogError((object)"Error: Couldnt get Containment Jar from assets");
					return;
				}
				LoggerInstance.LogDebug((object)"Got Containment Jar prefab");
				NetworkPrefabs.RegisterNetworkPrefab(val.spawnPrefab);
				Utilities.FixMixerGroups(val.spawnPrefab);
				Items.RegisterShopItem(val, configJarPrice.Value);
			}
			EnemyType val2 = ModAssets.LoadAsset<EnemyType>("Assets/ModAssets/SCP999/SCP999Enemy.asset");
			if ((Object)(object)val2 == (Object)null)
			{
				LoggerInstance.LogError((object)"Error: Couldnt get SCP-999 from assets");
				return;
			}
			LoggerInstance.LogDebug((object)"Got SCP-999 prefab");
			TerminalNode val3 = ModAssets.LoadAsset<TerminalNode>("Assets/ModAssets/SCP999/Bestiary/SCP999TN.asset");
			TerminalKeyword val4 = ModAssets.LoadAsset<TerminalKeyword>("Assets/ModAssets/SCP999/Bestiary/SCP999TK.asset");
			Dictionary<LevelTypes, int> levelRarities = GetLevelRarities(config999LevelRarities.Value);
			Dictionary<string, int> customLevelRarities = GetCustomLevelRarities(config999CustomLevelRarities.Value);
			LoggerInstance.LogDebug((object)"Registering enemy network prefab...");
			NetworkPrefabs.RegisterNetworkPrefab(val2.enemyPrefab);
			LoggerInstance.LogDebug((object)"Registering enemy...");
			Enemies.RegisterEnemy(val2, levelRarities, customLevelRarities, val3, val4);
			LoggerInstance.LogDebug((object)"Registered enemy");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"ProjectSCP.SCP999 v2.2.0 has loaded!");
		}

		public Dictionary<LevelTypes, int>? GetLevelRarities(string levelsString)
		{
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Dictionary<LevelTypes, int> dictionary = new Dictionary<LevelTypes, int>();
				if (levelsString != null && levelsString != "")
				{
					string[] array = levelsString.Split(',');
					string[] array2 = array;
					foreach (string text in array2)
					{
						string[] array3 = text.Split(':');
						if (array3.Length == 2)
						{
							string text2 = array3[0].Trim();
							string text3 = array3[1].Trim();
							if (Enum.TryParse<LevelTypes>(text2, out LevelTypes result) && int.TryParse(text3, out var result2))
							{
								dictionary.Add(result, result2);
							}
							else
							{
								LoggerInstance.LogError((object)("Error: Invalid level rarity: " + text2 + ":" + text3));
							}
						}
					}
				}
				return dictionary;
			}
			catch (Exception arg)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)$"Error: {arg}");
				return null;
			}
		}

		public Dictionary<string, int>? GetCustomLevelRarities(string levelsString)
		{
			try
			{
				Dictionary<string, int> dictionary = new Dictionary<string, int>();
				if (levelsString != null)
				{
					string[] array = levelsString.Split(',');
					string[] array2 = array;
					foreach (string text in array2)
					{
						string[] array3 = text.Split(':');
						if (array3.Length == 2)
						{
							string text2 = array3[0].Trim();
							string text3 = array3[1].Trim();
							if (int.TryParse(text3, out var result))
							{
								dictionary.Add(text2, result);
							}
							else
							{
								LoggerInstance.LogError((object)("Error: Invalid level rarity: " + text2 + ":" + text3));
							}
						}
					}
				}
				return dictionary;
			}
			catch (Exception arg)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)$"Error: {arg}");
				return null;
			}
		}

		public static List<SpawnableEnemyWithRarity> GetEnemies()
		{
			LoggerInstance.LogDebug((object)"Getting enemies");
			List<SpawnableEnemyWithRarity> list = new List<SpawnableEnemyWithRarity>();
			list = (from x in GameObject.Find("Terminal").GetComponentInChildren<Terminal>().moonsCatalogueList.SelectMany((SelectableLevel x) => x.Enemies.Concat(x.DaytimeEnemies).Concat(x.OutsideEnemies))
				where x != null && (Object)(object)x.enemyType != (Object)null && ((Object)x.enemyType).name != null
				select x).GroupBy((SpawnableEnemyWithRarity x) => ((Object)x.enemyType).name, (string k, IEnumerable<SpawnableEnemyWithRarity> v) => v.First()).ToList();
			LoggerInstance.LogDebug((object)$"Enemy types: {list.Count}");
			return list;
		}

		private static void InitializeNetworkBehaviours()
		{
			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);
					}
				}
			}
			LoggerInstance.LogDebug((object)"Finished initializing network behaviours");
		}
	}
	public class SCP999AI : EnemyAI
	{
		public enum State
		{
			Roaming,
			Following,
			Blocking,
			Healing,
			Hyper
		}

		private static ManualLogSource logger = Plugin.LoggerInstance;

		public Transform turnCompass = null;

		public List<AudioClip> hitSFXList = null;

		public List<AudioClip> hugSFXList = null;

		public List<AudioClip> hurtSFXList = null;

		public List<AudioClip> roamSFXList = null;

		public InteractTrigger jarTrigger = null;

		private EnemyAI? targetEnemy;

		private Turret? blockedTurret;

		private float timeSinceHealing;

		private float healingBuffTime;

		private float hyperTime;

		private float timeSinceBlockSFX;

		private float timeSinceHugSFX;

		private float hugTime;

		private int playerHealAmount;

		private int enemyHealAmount;

		private float playerDetectionRange;

		private float enemyDetectionRange;

		private float rangeMultiplier = 1f;

		private float followingRange;

		private float huggingRange;

		private bool walking;

		private bool hugging;

		private int maxCandy;

		private int candyEaten;

		private bool gettingInJar;

		private bool followPlayer = true;

		private bool followEnemy = true;

		private bool tamed = false;

		private PlayerControllerB tamedByPlayer = null;

		private float insanityDecreaseRate;

		public void SwitchToBehaviourStateCustom(State state)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			switch (state)
			{
			case State.Roaming:
				SetTargetNull();
				((EnemyAI)this).StartSearch(((Component)this).transform.position, (AISearchRoutine)null);
				break;
			case State.Following:
				((EnemyAI)this).StopSearch(base.currentSearch, true);
				break;
			case State.Blocking:
				((EnemyAI)this).StopSearch(base.currentSearch, true);
				break;
			case State.Healing:
				((EnemyAI)this).StopSearch(base.currentSearch, true);
				break;
			case State.Hyper:
				tamed = false;
				tamedByPlayer = null;
				SetTargetNull();
				((EnemyAI)this).StartSearch(((Component)this).transform.position, (AISearchRoutine)null);
				break;
			}
			((EnemyAI)this).SwitchToBehaviourClientRpc((int)state);
		}

		public override void Start()
		{
			//IL_00c0: 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)
			((EnemyAI)this).Start();
			logger.LogDebug((object)"SCP-999 Spawned");
			playerHealAmount = Plugin.configPlayerHealAmount.Value;
			enemyHealAmount = Plugin.configEnemyHealAmount.Value;
			playerDetectionRange = Plugin.configPlayerDetectionRange.Value;
			enemyDetectionRange = Plugin.configEnemyDetectionRange.Value;
			followingRange = Plugin.configFollowRange.Value;
			huggingRange = Plugin.configHuggingRange.Value;
			maxCandy = Plugin.configMaxCandy.Value;
			insanityDecreaseRate = Plugin.configInsanityDecreaseRate.Value;
			base.currentBehaviourStateIndex = 0;
			RoundManager.Instance.SpawnedEnemies.Add((EnemyAI)(object)this);
			if (Plugin.IsServerOrHost)
			{
				if (((Component)this).transform.localScale.y != Plugin.config999Size.Value)
				{
					ChangeSizeClientRpc(Plugin.config999Size.Value);
				}
				SetOutsideOrInside();
				((EnemyAI)this).StartSearch(((Component)this).transform.position, (AISearchRoutine)null);
			}
		}

		public override void Update()
		{
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
			((EnemyAI)this).Update();
			timeSinceHealing += Time.deltaTime;
			timeSinceBlockSFX += Time.deltaTime;
			timeSinceHugSFX += Time.deltaTime;
			if (healingBuffTime > 0f)
			{
				healingBuffTime -= Time.deltaTime;
			}
			if (hyperTime > 0f)
			{
				hyperTime -= Time.deltaTime;
			}
			if (hugTime > 0f)
			{
				hugTime -= Time.deltaTime;
				if (!hugging)
				{
					hugging = true;
					DoAnimationServerRpc("hugging", value: true);
				}
				if (hugTime <= 0f)
				{
					hugging = false;
					DoAnimationServerRpc("hugging", value: false);
				}
			}
			if ((Object)(object)base.targetPlayer != (Object)null && base.currentBehaviourStateIndex == 2)
			{
				turnCompass.LookAt(((Component)base.targetPlayer.gameplayCamera).transform.position);
				((Component)this).transform.rotation = Quaternion.Lerp(((Component)this).transform.rotation, Quaternion.Euler(new Vector3(0f, turnCompass.eulerAngles.y, 0f)), 10f * Time.deltaTime);
			}
			if ((Object)(object)Plugin.LocalPlayer.currentlyHeldObjectServer != (Object)null && ((Object)Plugin.LocalPlayer.currentlyHeldObjectServer.itemProperties).name == "ContainmentJarItem" && ((Component)Plugin.LocalPlayer.currentlyHeldObjectServer).GetComponent<ContainmentJarBehavior>().JarContents == ContainmentJarBehavior.Contents.Empty)
			{
				jarTrigger.interactable = true;
			}
			else
			{
				jarTrigger.interactable = false;
			}
			switch (base.currentBehaviourStateIndex)
			{
			case 1:
				base.creatureAnimator.SetBool("dancing", IsNearbyPlayerEmoting(followingRange));
				break;
			case 2:
				base.creatureAnimator.SetBool("stretching", true);
				break;
			case 4:
				base.creatureAnimator.SetBool("walking", false);
				base.creatureAnimator.SetBool("hyperDancing", true);
				break;
			}
			if (!Plugin.IsServerOrHost || base.currentBehaviourStateIndex == 4 || base.currentBehaviourStateIndex == 3 || base.currentBehaviourStateIndex == 2)
			{
				return;
			}
			if (base.agent.remainingDistance <= base.agent.stoppingDistance + 0.1f)
			{
				Vector3 velocity = base.agent.velocity;
				if (((Vector3)(ref velocity)).sqrMagnitude < 0.01f)
				{
					if (walking)
					{
						walking = false;
						DoAnimationClientRpc("walking", value: false);
					}
					return;
				}
			}
			if (!walking)
			{
				walking = true;
				DoAnimationClientRpc("walking", value: true);
			}
		}

		public override void DoAIInterval()
		{
			((EnemyAI)this).DoAIInterval();
			if (base.isEnemyDead || StartOfRound.Instance.allPlayersDead || gettingInJar || BabyIsCryingNearby())
			{
				return;
			}
			if (tamed && (Object)(object)tamedByPlayer != (Object)null)
			{
				base.targetPlayer = tamedByPlayer;
			}
			switch (base.currentBehaviourStateIndex)
			{
			case 0:
				base.agent.speed = 5f;
				base.agent.stoppingDistance = 0f;
				base.agent.acceleration = 8f;
				if ((((EnemyAI)this).TargetClosestPlayer(1.5f, true, 70f) && followPlayer) || (TargetClosestEnemy(1.5f, requireLineOfSight: true) && followEnemy))
				{
					logger.LogDebug((object)"Start Targeting");
					SwitchToBehaviourStateCustom(State.Following);
				}
				break;
			case 1:
				if (healingBuffTime > 0f)
				{
					base.agent.speed = 10f;
				}
				else
				{
					base.agent.speed = 5f;
				}
				base.agent.stoppingDistance = followingRange;
				base.agent.acceleration = 10f;
				if (!TargetClosestEntity() && !tamed)
				{
					logger.LogDebug((object)"Stop Targeting");
					SwitchToBehaviourStateCustom(State.Roaming);
				}
				else if (MoveToSweetsIfDroppedByPlayer())
				{
					EatSweetsIfClose();
				}
				else
				{
					FollowTarget();
				}
				break;
			case 2:
				base.agent.speed = 20f;
				base.agent.stoppingDistance = 0f;
				base.agent.acceleration = 15f;
				if (!MoveInFrontOfTurret())
				{
					logger.LogDebug((object)"Stop Blocking");
					SwitchToBehaviourStateCustom(State.Following);
					blockedTurret = null;
					DoAnimationClientRpc("stretching", value: false);
				}
				break;
			case 3:
				base.agent.speed = 10f;
				base.agent.stoppingDistance = huggingRange;
				base.agent.acceleration = 50f;
				MoveToHealTarget();
				break;
			case 4:
				base.agent.speed = 20f;
				base.agent.stoppingDistance = 0f;
				base.agent.acceleration = 25f;
				if (hyperTime <= 0f)
				{
					candyEaten = 0;
					SwitchToBehaviourStateCustom(State.Roaming);
					DoAnimationClientRpc("hyperDancing", value: false);
				}
				break;
			default:
				logger.LogWarning((object)("Invalid state: " + base.currentBehaviourStateIndex));
				break;
			}
		}

		private bool BabyIsCryingNearby()
		{
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			CaveDwellerAI val = (from x in Object.FindObjectsOfType<CaveDwellerAI>()
				where x.babyCrying && Vector3.Distance(((Component)this).transform.position, ((Component)x).transform.position) < x.babyCryingAudio.maxDistance
				select x).FirstOrDefault();
			if ((Object)(object)val != (Object)null)
			{
				base.agent.speed = 10f;
				base.agent.stoppingDistance = 0f;
				base.agent.acceleration = 50f;
				targetEnemy = (EnemyAI?)(object)val;
				return ((EnemyAI)this).SetDestinationToPosition(((Component)val).transform.position, true);
			}
			return false;
		}

		public void SetTamed(PlayerControllerB playerTamedTo)
		{
			tamed = true;
			tamedByPlayer = playerTamedTo;
			base.targetPlayer = playerTamedTo;
			SwitchToBehaviourStateCustom(State.Following);
		}

		public void SetOutsideOrInside()
		{
			//IL_0017: 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_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			GameObject closestAINode = GetClosestAINode(inside: false);
			GameObject closestAINode2 = GetClosestAINode(inside: true);
			if (Vector3.Distance(((Component)this).transform.position, closestAINode.transform.position) < Vector3.Distance(((Component)this).transform.position, closestAINode2.transform.position))
			{
				SetEnemyOutsideClientRpc(value: true);
			}
		}

		public GameObject GetClosestAINode(bool inside)
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			float num = float.PositiveInfinity;
			GameObject result = null;
			List<GameObject> list = (inside ? GameObject.FindGameObjectsWithTag("AINode").ToList() : GameObject.FindGameObjectsWithTag("OutsideAINode").ToList());
			foreach (GameObject item in list)
			{
				float num2 = Vector3.Distance(((Component)this).transform.position, item.transform.position);
				if (num2 < num)
				{
					num = num2;
					result = item;
				}
			}
			return result;
		}

		public void GetInJar()
		{
			logger.LogDebug((object)"GetInJar");
			GetInJarServerRpc(Plugin.LocalPlayer.actualClientId);
		}

		public bool TargetClosestEntity()
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: 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_00f0: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)base.targetPlayer != (Object)null && followPlayer && ((EnemyAI)this).TargetClosestPlayer(1.5f, false, 70f) && (Vector3.Distance(((Component)this).transform.position, ((Component)base.targetPlayer).transform.position) < playerDetectionRange * 2f || ((EnemyAI)this).CheckLineOfSightForPosition(((Component)base.targetPlayer).transform.position, 45f, 60, -1f, (Transform)null)))
			{
				return true;
			}
			if ((Object)(object)targetEnemy != (Object)null && followEnemy && TargetClosestEnemy(5f) && (Vector3.Distance(((Component)this).transform.position, ((Component)targetEnemy).transform.position) < enemyDetectionRange * 2f || ((EnemyAI)this).CheckLineOfSightForPosition(((Component)targetEnemy).transform.position, 45f, 60, -1f, (Transform)null)))
			{
				return true;
			}
			return false;
		}

		public bool TargetClosestEnemy(float bufferDistance = 1.5f, bool requireLineOfSight = false, float viewWidth = 70f)
		{
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			base.mostOptimalDistance = 2000f;
			EnemyAI val = targetEnemy;
			targetEnemy = null;
			foreach (EnemyAI spawnedEnemy in RoundManager.Instance.SpawnedEnemies)
			{
				if (!spawnedEnemy.isEnemyDead && !(((Object)spawnedEnemy.enemyType).name == "SCP999Enemy") && !((EnemyAI)this).PathIsIntersectedByLineOfSight(((Component)spawnedEnemy).transform.position, false, false, false) && (!requireLineOfSight || ((EnemyAI)this).CheckLineOfSightForPosition(((Component)spawnedEnemy).transform.position, viewWidth, 40, -1f, (Transform)null)))
				{
					base.tempDist = Vector3.Distance(((Component)this).transform.position, ((Component)spawnedEnemy).transform.position);
					if (base.tempDist < base.mostOptimalDistance)
					{
						base.mostOptimalDistance = base.tempDist;
						targetEnemy = spawnedEnemy;
					}
				}
			}
			if ((Object)(object)targetEnemy != (Object)null && bufferDistance > 0f && (Object)(object)val != (Object)null && Mathf.Abs(base.mostOptimalDistance - Vector3.Distance(((Component)this).transform.position, ((Component)val).transform.position)) < bufferDistance)
			{
				targetEnemy = val;
			}
			return (Object)(object)targetEnemy != (Object)null;
		}

		private void FollowTarget()
		{
			//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_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position;
			if ((Object)(object)base.targetPlayer != (Object)null)
			{
				position = ((Component)base.targetPlayer).transform.position;
			}
			else
			{
				if (!((Object)(object)targetEnemy != (Object)null))
				{
					return;
				}
				position = ((Component)targetEnemy).transform.position;
			}
			((EnemyAI)this).SetDestinationToPosition(position, false);
		}

		private void SetTarget(PlayerControllerB player)
		{
			base.targetPlayer = player;
			targetEnemy = null;
		}

		private void SetTarget(EnemyAI enemy)
		{
			base.targetPlayer = null;
			targetEnemy = enemy;
		}

		private void SetTargetNull()
		{
			base.targetPlayer = null;
			targetEnemy = null;
		}

		private void MoveToHealTarget()
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)base.targetPlayer != (Object)null)
			{
				if (base.targetPlayer.health >= 100 || base.targetPlayer.isPlayerDead)
				{
					SwitchToBehaviourStateCustom(State.Following);
				}
				else
				{
					((EnemyAI)this).SetDestinationToPosition(((Component)base.targetPlayer).transform.position, false);
				}
			}
			else if ((Object)(object)targetEnemy != (Object)null)
			{
				int enemyHP = targetEnemy.enemyType.enemyPrefab.GetComponent<EnemyAI>().enemyHP;
				if (targetEnemy.enemyHP >= enemyHP || targetEnemy.isEnemyDead)
				{
					SwitchToBehaviourStateCustom(State.Following);
				}
				else
				{
					((EnemyAI)this).SetDestinationToPosition(((Component)targetEnemy).transform.position, false);
				}
			}
		}

		private bool MoveInFrontOfTurret()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Invalid comparison between Unknown and I4
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Invalid comparison between Unknown and I4
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: 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_0076: 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 ((Object)(object)blockedTurret != (Object)null && ((int)blockedTurret.turretMode == 2 || (int)blockedTurret.turretMode == 1))
			{
				Vector3 val = Vector3.Lerp(((Component)base.targetPlayer).transform.position, ((Component)blockedTurret).transform.position, 0.5f);
				((EnemyAI)this).SetDestinationToPosition(val, false);
				if (Vector3.Distance(((Component)this).transform.position, val) < 1f && timeSinceBlockSFX > 0.5f)
				{
					logger.LogDebug((object)"Playing hitSFX");
					int index = Random.Range(0, hitSFXList.Count - 1);
					base.creatureSFX.PlayOneShot(hitSFXList[index], 1f);
					timeSinceBlockSFX = 0f;
				}
				return true;
			}
			return false;
		}

		public bool MoveToSweetsIfDroppedByPlayer()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			GrabbableObject[] array = Object.FindObjectsOfType<GrabbableObject>();
			foreach (GrabbableObject val in array)
			{
				if (Vector3.Distance(((Component)this).transform.position, ((Component)val).transform.position) <= followingRange && Plugin.Sweets.Contains(val.itemProperties.itemName) && val.hasBeenHeld && !val.heldByPlayerOnServer)
				{
					logger.LogDebug((object)("Moving to item: " + val.itemProperties.itemName));
					base.agent.stoppingDistance = 0f;
					((EnemyAI)this).SetDestinationToPosition(((Component)val).transform.position, false);
					return true;
				}
			}
			return false;
		}

		public void EatSweetsIfClose()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			GrabbableObject[] array = Object.FindObjectsOfType<GrabbableObject>();
			foreach (GrabbableObject val in array)
			{
				if (Vector3.Distance(((Component)this).transform.position, ((Component)val).transform.position) < 1f && Plugin.Sweets.Contains(val.itemProperties.itemName))
				{
					logger.LogDebug((object)("Eating item: " + val.itemProperties.itemName));
					if (val.itemProperties.itemName == "SCP-559")
					{
						ChangeSizeClientRpc(((Component)this).transform.localScale.y / 2f);
					}
					if (val.itemProperties.itemName == "Black Candy")
					{
						MakeHyper(60f);
					}
					if (val.itemProperties.itemName == "Cake")
					{
						healingBuffTime += 10f;
					}
					((Component)val).GetComponent<NetworkObject>().Despawn(true);
					candyEaten++;
					logger.LogDebug((object)("Candy eaten: " + candyEaten));
					healingBuffTime += 20f;
					if (candyEaten >= maxCandy)
					{
						MakeHyper(30f);
					}
				}
			}
		}

		public void MakeHyper(float duration)
		{
			hyperTime += duration;
			SwitchToBehaviourStateCustom(State.Hyper);
		}

		public override void DetectNoise(Vector3 noisePosition, float noiseLoudness, int timesPlayedInOneSpot = 0, int noiseID = 0)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			((EnemyAI)this).DetectNoise(noisePosition, noiseLoudness, timesPlayedInOneSpot, noiseID);
		}

		public override void ReachedNodeInSearch()
		{
			((EnemyAI)this).ReachedNodeInSearch();
			int index = Random.Range(0, roamSFXList.Count - 1);
			base.creatureVoice.PlayOneShot(roamSFXList[index], 1f);
		}

		public override void OnCollideWithPlayer(Collider other)
		{
			((EnemyAI)this).OnCollideWithPlayer(other);
			PlayerControllerB val = ((EnemyAI)this).MeetsStandardPlayerCollisionConditions(other, false, false);
			if ((Object)(object)val != (Object)null)
			{
				HealPlayer(val);
				Hug();
			}
		}

		public override void OnCollideWithEnemy(Collider other, EnemyAI? collidedEnemy = null)
		{
			((EnemyAI)this).OnCollideWithEnemy(other, collidedEnemy);
			if ((Object)(object)collidedEnemy != (Object)null && ((Object)collidedEnemy.enemyType).name != "SCP999Enemy")
			{
				HealEnemy(collidedEnemy);
				Hug();
			}
		}

		public override void HitEnemy(int force = 0, PlayerControllerB playerWhoHit = null, bool playHitSFX = true, int hitID = -1)
		{
			int index = Random.Range(0, hitSFXList.Count - 1);
			base.creatureVoice.PlayOneShot(hurtSFXList[index], 1f);
		}

		public bool IsNearbyPlayerEmoting(float distance)
		{
			//IL_001c: 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)
			PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
			foreach (PlayerControllerB val in allPlayerScripts)
			{
				if (Vector3.Distance(((Component)this).transform.position, ((Component)val).transform.position) < distance && val.performingEmote)
				{
					return true;
				}
			}
			return false;
		}

		public void Hug()
		{
			if (base.currentBehaviourStateIndex == 1 || base.currentBehaviourStateIndex == 3)
			{
				hugTime = 1f;
				if (timeSinceHugSFX > 5f)
				{
					int index = Random.Range(0, hugSFXList.Count - 1);
					base.creatureVoice.PlayOneShot(hugSFXList[index], 1f);
					timeSinceHugSFX = 0f;
				}
			}
		}

		public void HealPlayer(PlayerControllerB player)
		{
			if (!((Object)(object)player != (Object)null) || !(timeSinceHealing > 1f))
			{
				return;
			}
			timeSinceHealing = 0f;
			if (player.health < 100)
			{
				int num = ((!(healingBuffTime > 0f)) ? (player.health + playerHealAmount) : (player.health + playerHealAmount * 2));
				if (num > 100)
				{
					num = 100;
				}
				player.health = num;
				HUDManager.Instance.UpdateHealthUI(player.health, false);
			}
			player.insanityLevel -= insanityDecreaseRate;
			player.JumpToFearLevel(0f, false);
		}

		public void HealEnemy(EnemyAI enemyToHeal)
		{
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Expected O, but got Unknown
			if (timeSinceHealing > 1f)
			{
				timeSinceHealing = 0f;
				int enemyHP = enemyToHeal.enemyType.enemyPrefab.GetComponent<EnemyAI>().enemyHP;
				if (enemyToHeal.enemyHP < enemyHP)
				{
					if (healingBuffTime > 0f)
					{
						enemyToHeal.enemyHP += enemyHealAmount * 2;
					}
					else
					{
						enemyToHeal.enemyHP += enemyHealAmount;
					}
				}
			}
			if (!(enemyToHeal is CaveDwellerAI))
			{
				return;
			}
			CaveDwellerAI val = (CaveDwellerAI)enemyToHeal;
			if (val.babyCrying)
			{
				val.rockBabyTimer += Time.deltaTime * 0.4f;
				if (val.rockBabyTimer > 1f)
				{
					val.SetCryingLocalClient(false);
					val.SetBabyCryingServerRpc(false);
				}
			}
		}

		public void EnemyTookDamage(EnemyAI enemy)
		{
			if (!(hyperTime > 0f) && !tamed)
			{
				targetEnemy = enemy;
				SwitchToBehaviourStateCustom(State.Healing);
			}
		}

		[ServerRpc(RequireOwnership = false)]
		private void DoAnimationServerRpc(string animationName, bool value)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: 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_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: 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 = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				ServerRpcParams val = default(ServerRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(2710228690u, val, (RpcDelivery)0);
				bool flag = animationName != null;
				((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
				if (flag)
				{
					((FastBufferWriter)(ref val2)).WriteValueSafe(animationName, false);
				}
				((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref value, default(ForPrimitives));
				((NetworkBehaviour)this).__endSendServerRpc(ref val2, 2710228690u, val, (RpcDelivery)0);
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost) && (NetworkManager.Singleton.IsServer || NetworkManager.Singleton.IsHost))
			{
				DoAnimationClientRpc(animationName, value);
			}
		}

		[ClientRpc]
		private void DoAnimationClientRpc(string animationName, bool value)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: 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_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: 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 = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(2443945134u, val, (RpcDelivery)0);
				bool flag = animationName != null;
				((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
				if (flag)
				{
					((FastBufferWriter)(ref val2)).WriteValueSafe(animationName, false);
				}
				((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref value, default(ForPrimitives));
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 2443945134u, val, (RpcDelivery)0);
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
			{
				base.creatureAnimator.SetBool(animationName, value);
			}
		}

		[ServerRpc(RequireOwnership = false)]
		private void GetInJarServerRpc(ulong clientId)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					ServerRpcParams val = default(ServerRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(4103771736u, val, (RpcDelivery)0);
					BytePacker.WriteValueBitPacked(val2, clientId);
					((NetworkBehaviour)this).__endSendServerRpc(ref val2, 4103771736u, val, (RpcDelivery)0);
				}
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost) && (NetworkManager.Singleton.IsServer || NetworkManager.Singleton.IsHost))
				{
					PlayerControllerB val3 = Plugin.PlayerFromId(clientId);
					((Component)val3.currentlyHeldObjectServer).GetComponent<ContainmentJarBehavior>().ChangeJarContentsClientRpc(ContainmentJarBehavior.Contents.SCP999);
					RoundManager.Instance.DespawnEnemyOnServer(((NetworkBehaviour)this).NetworkObject);
				}
			}
		}

		[ClientRpc]
		private void SetEnemyOutsideClientRpc(bool value)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: 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)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
				{
					ClientRpcParams val = default(ClientRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(3990597999u, val, (RpcDelivery)0);
					((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref value, default(ForPrimitives));
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 3990597999u, val, (RpcDelivery)0);
				}
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
				{
					((EnemyAI)this).SetEnemyOutside(value);
				}
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void PlayerTookDamageServerRpc(ulong clientId)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: 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)((NetworkBehaviour)this).__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				ServerRpcParams val = default(ServerRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(771765929u, val, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val2, clientId);
				((NetworkBehaviour)this).__endSendServerRpc(ref val2, 771765929u, val, (RpcDelivery)0);
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1 || (!networkManager.IsServer && !networkManager.IsHost) || (!NetworkManager.Singleton.IsServer && !NetworkManager.Singleton.IsHost))
			{
				return;
			}
			PlayerControllerB val3 = Plugin.PlayerFromId(clientId);
			if ((Object)(object)val3 == (Object)null || (tamed && (Object)(object)val3 != (Object)(object)base.targetPlayer))
			{
				return;
			}
			float num = 2f - (float)val3.health / 100f;
			float num2 = Plugin.configPlayerDetectionRange.Value * num;
			if (Vector3.Distance(((Component)this).transform.position, ((Component)val3).transform.position) <= num2)
			{
				SetTarget(val3);
				if (!(hyperTime > 0f))
				{
					SwitchToBehaviourStateCustom(State.Healing);
				}
			}
		}

		[ClientRpc]
		private void ChangeSizeClientRpc(float size)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: 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)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
				{
					ClientRpcParams val = default(ClientRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(353376331u, val, (RpcDelivery)0);
					((FastBufferWriter)(ref val2)).WriteValueSafe<float>(ref size, default(ForPrimitives));
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 353376331u, val, (RpcDelivery)0);
				}
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
				{
					((Component)this).transform.localScale = new Vector3(size, size, size);
				}
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void BlockTurretFireServerRpc(NetworkObjectReference netObjRef)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: 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)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				ServerRpcParams val = default(ServerRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(1637096969u, val, (RpcDelivery)0);
				((FastBufferWriter)(ref val2)).WriteValueSafe<NetworkObjectReference>(ref netObjRef, default(ForNetworkSerializable));
				((NetworkBehaviour)this).__endSendServerRpc(ref val2, 1637096969u, val, (RpcDelivery)0);
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1 || (!networkManager.IsServer && !networkManager.IsHost) || (!NetworkManager.Singleton.IsServer && !NetworkManager.Singleton.IsHost))
			{
				return;
			}
			NetworkObject val3 = default(NetworkObject);
			if (((NetworkObjectReference)(ref netObjRef)).TryGet(ref val3, (NetworkManager)null))
			{
				blockedTurret = ((Component)val3).GetComponent<Turret>();
				SwitchToBehaviourStateCustom(State.Blocking);
			}
			Turret[] array = Object.FindObjectsOfType<Turret>();
			foreach (Turret val4 in array)
			{
				if ((Object)(object)val4.targetPlayerWithRotation == (Object)(object)base.targetPlayer)
				{
					blockedTurret = val4;
					SwitchToBehaviourStateCustom(State.Blocking);
					break;
				}
			}
		}

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

		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeRPCS_SCP999AI()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Expected O, but got Unknown
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Expected O, but got Unknown
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Expected O, but got Unknown
			NetworkManager.__rpc_func_table.Add(2710228690u, new RpcReceiveHandler(__rpc_handler_2710228690));
			NetworkManager.__rpc_func_table.Add(2443945134u, new RpcReceiveHandler(__rpc_handler_2443945134));
			NetworkManager.__rpc_func_table.Add(4103771736u, new RpcReceiveHandler(__rpc_handler_4103771736));
			NetworkManager.__rpc_func_table.Add(3990597999u, new RpcReceiveHandler(__rpc_handler_3990597999));
			NetworkManager.__rpc_func_table.Add(771765929u, new RpcReceiveHandler(__rpc_handler_771765929));
			NetworkManager.__rpc_func_table.Add(353376331u, new RpcReceiveHandler(__rpc_handler_353376331));
			NetworkManager.__rpc_func_table.Add(1637096969u, new RpcReceiveHandler(__rpc_handler_1637096969));
		}

		private static void __rpc_handler_2710228690(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_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				bool flag = default(bool);
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives));
				string animationName = null;
				if (flag)
				{
					((FastBufferReader)(ref reader)).ReadValueSafe(ref animationName, false);
				}
				bool value = default(bool);
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref value, default(ForPrimitives));
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((SCP999AI)(object)target).DoAnimationServerRpc(animationName, value);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_2443945134(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_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				bool flag = default(bool);
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives));
				string animationName = null;
				if (flag)
				{
					((FastBufferReader)(ref reader)).ReadValueSafe(ref animationName, false);
				}
				bool value = default(bool);
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref value, default(ForPrimitives));
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((SCP999AI)(object)target).DoAnimationClientRpc(animationName, value);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_4103771736(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: 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)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				ulong clientId = default(ulong);
				ByteUnpacker.ReadValueBitPacked(reader, ref clientId);
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((SCP999AI)(object)target).GetInJarServerRpc(clientId);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_3990597999(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_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				bool enemyOutsideClientRpc = default(bool);
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref enemyOutsideClientRpc, default(ForPrimitives));
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((SCP999AI)(object)target).SetEnemyOutsideClientRpc(enemyOutsideClientRpc);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_771765929(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: 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)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				ulong clientId = default(ulong);
				ByteUnpacker.ReadValueBitPacked(reader, ref clientId);
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((SCP999AI)(object)target).PlayerTookDamageServerRpc(clientId);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_353376331(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_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				float size = default(float);
				((FastBufferReader)(ref reader)).ReadValueSafe<float>(ref size, default(ForPrimitives));
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((SCP999AI)(object)target).ChangeSizeClientRpc(size);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_1637096969(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_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				NetworkObjectReference netObjRef = default(NetworkObjectReference);
				((FastBufferReader)(ref reader)).ReadValueSafe<NetworkObjectReference>(ref netObjRef, default(ForNetworkSerializable));
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((SCP999AI)(object)target).BlockTurretFireServerRpc(netObjRef);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected internal override string __getTypeName()
		{
			return "SCP999AI";
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "ProjectSCP.SCP999";

		public const string PLUGIN_NAME = "SCP999";

		public const string PLUGIN_VERSION = "2.2.0";
	}
}
namespace SCP999.Patches
{
	[HarmonyPatch(typeof(BlobAI))]
	internal class BlobAIPatch
	{
		private static ManualLogSource logger = Plugin.LoggerInstance;

		[HarmonyPostfix]
		[HarmonyPatch("DoAIInterval")]
		public static void DoAIIntervalPostfix(BlobAI __instance)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (!NetworkManager.Singleton.IsHost && !NetworkManager.Singleton.IsServer)
				{
					return;
				}
				ContainmentJarBehavior[] array = Object.FindObjectsOfType<ContainmentJarBehavior>();
				foreach (ContainmentJarBehavior containmentJarBehavior in array)
				{
					if (Vector3.Distance(((Component)__instance).transform.position, ((Component)containmentJarBehavior).transform.position) < 2f)
					{
						containmentJarBehavior.ChangeJarContentsClientRpc(ContainmentJarBehavior.Contents.Blob);
						RoundManager.Instance.DespawnEnemyOnServer(((NetworkBehaviour)__instance).NetworkObject);
						break;
					}
				}
			}
			catch
			{
			}
		}
	}
	[HarmonyPatch(typeof(EnemyAI))]
	internal class EnemyAIPatch
	{
		private static ManualLogSource logger = Plugin.LoggerInstance;

		[HarmonyPostfix]
		[HarmonyPatch("HitEnemy")]
		private static void HitEnemyPostfix(EnemyAI __instance)
		{
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (!Plugin.IsServerOrHost || ((Object)__instance.enemyType).name == "SCP999Enemy")
				{
					return;
				}
				int enemyHP = __instance.enemyType.enemyPrefab.GetComponent<EnemyAI>().enemyHP;
				logger.LogDebug((object)$"Max health of {((Object)__instance.enemyType).name} is {enemyHP}");
				float num = 2 - __instance.enemyHP / enemyHP;
				float num2 = Plugin.configEnemyDetectionRange.Value * num;
				foreach (SCP999AI item in RoundManager.Instance.SpawnedEnemies.OfType<SCP999AI>())
				{
					if (Vector3.Distance(((Component)item).transform.position, ((Component)__instance).transform.position) <= num2)
					{
						logger.LogDebug((object)(__instance.enemyType.enemyName + " took damage"));
						item.EnemyTookDamage(__instance);
						break;
					}
				}
			}
			catch (Exception ex)
			{
				logger.LogError((object)ex);
			}
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class PlayerControllerBPatch
	{
		private static ManualLogSource logger = Plugin.LoggerInstance;

		[HarmonyPostfix]
		[HarmonyPatch("DamagePlayer")]
		private static void DamagePlayerPostfix(PlayerControllerB __instance)
		{
			try
			{
				if (StartOfRound.Instance.inShipPhase)
				{
					return;
				}
				foreach (SCP999AI item in RoundManager.Instance.SpawnedEnemies.OfType<SCP999AI>())
				{
					if (((EnemyAI)item).currentBehaviourStateIndex == 2)
					{
						continue;
					}
					item.PlayerTookDamageServerRpc(__instance.actualClientId);
					break;
				}
			}
			catch (Exception ex)
			{
				logger.LogError((object)ex);
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch("DamagePlayer")]
		private static bool DamagePlayerPrefix(PlayerControllerB __instance, CauseOfDeath causeOfDeath)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Invalid comparison between Unknown and I4
			try
			{
				if ((int)causeOfDeath == 7)
				{
					foreach (SCP999AI item in RoundManager.Instance.SpawnedEnemies.OfType<SCP999AI>())
					{
						if ((Object)(object)((EnemyAI)item).targetPlayer != (Object)null && (Object)(object)__instance == (Object)(object)((EnemyAI)item).targetPlayer && ((EnemyAI)item).currentBehaviourStateIndex == 2)
						{
							return false;
						}
					}
				}
				return true;
			}
			catch (Exception ex)
			{
				logger.LogError((object)ex);
				return true;
			}
		}
	}
	[HarmonyPatch(typeof(RoundManager))]
	internal class RoundManagerPatch
	{
		private static ManualLogSource logger = Plugin.LoggerInstance;

		private static bool isSCPDungeon = false;

		private static int currentLevelRarity;

		[HarmonyPrefix]
		[HarmonyPatch("GeneratedFloorPostProcessing")]
		public static void GeneratedFloorPostProcessingPrefix(RoundManager __instance)
		{
			try
			{
				if (!NetworkManager.Singleton.IsServer && !NetworkManager.Singleton.IsHost)
				{
					return;
				}
				string name = ((Object)__instance.dungeonGenerator.Generator.DungeonFlow).name;
				if (name == "SCPFlow")
				{
					logger.LogDebug((object)"SCPFlow detected");
					SpawnableEnemyWithRarity val = __instance.currentLevel.Enemies.Where((SpawnableEnemyWithRarity x) => ((Object)x.enemyType).name == "SCP999Enemy").FirstOrDefault();
					if (val != null)
					{
						currentLevelRarity = val.rarity;
						val.rarity = Plugin.config999SCPDungeonRarity.Value;
						logger.LogDebug((object)$"Rarity for SCP-999 set to {val.rarity} from {currentLevelRarity}");
						isSCPDungeon = true;
					}
				}
			}
			catch (Exception ex)
			{
				logger.LogError((object)ex);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("DespawnPropsAtEndOfRound")]
		public static void DespawnPropsAtEndOfRoundPostfix(RoundManager __instance)
		{
			try
			{
				if (isSCPDungeon)
				{
					logger.LogDebug((object)"Resetting rarities");
					isSCPDungeon = false;
					SpawnableEnemyWithRarity val = __instance.currentLevel.Enemies.Where((SpawnableEnemyWithRarity x) => ((Object)x.enemyType).name == "SCP999Enemy").FirstOrDefault();
					val.rarity = currentLevelRarity;
					logger.LogDebug((object)$"Rarity for SCP-999 reset to {val.rarity} from {currentLevelRarity}");
				}
			}
			catch (Exception ex)
			{
				logger.LogError((object)ex);
			}
		}
	}
	[HarmonyPatch(typeof(Turret))]
	internal class TurretPatch
	{
		private static ManualLogSource logger = Plugin.LoggerInstance;

		[HarmonyPostfix]
		[HarmonyPatch("SwitchTurretMode")]
		private static void SwitchTurretModePostfix(Turret __instance)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Invalid comparison between Unknown and I4
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if ((!NetworkManager.Singleton.IsServer && !NetworkManager.Singleton.IsHost) || (int)__instance.turretMode != 1)
				{
					return;
				}
				PlayerControllerB targetPlayerWithRotation = __instance.targetPlayerWithRotation;
				foreach (SCP999AI item in RoundManager.Instance.SpawnedEnemies.OfType<SCP999AI>())
				{
					if ((Object)(object)((EnemyAI)item).targetPlayer != (Object)null && (Object)(object)((EnemyAI)item).targetPlayer == (Object)(object)targetPlayerWithRotation && ((EnemyAI)item).currentBehaviourStateIndex == 1)
					{
						item.BlockTurretFireServerRpc(NetworkObjectReference.op_Implicit(((NetworkBehaviour)__instance).NetworkObject));
						break;
					}
				}
			}
			catch (Exception ex)
			{
				logger.LogError((object)ex);
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}
namespace ProjectSCP.SCP999.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}