Decompiled source of FreddyKrueger v3.5.21

plugins/FreddyKrueger/FreddyKrueger.dll

Decompiled 7 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Cryptography;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using FreddyKrueger.NetcodePatcher;
using FreddyKruegerLC.Configurations;
using FreddyKruegerLC.FreddyDirectPatches;
using GameNetcodeStuff;
using HarmonyLib;
using LethalBestiary.Modules;
using LethalNetworkAPI;
using Microsoft.CodeAnalysis;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Serialization;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("FreddyKrueger")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("This is Freddy Krueger as a spawnable enemy")]
[assembly: AssemblyFileVersion("3.5.21.0")]
[assembly: AssemblyInformationalVersion("3.5.21+6cb59ea3608ed96eca0ef4409080c6ee0a0ae5f6")]
[assembly: AssemblyProduct("FreddyKrueger")]
[assembly: AssemblyTitle("FreddyKrueger")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("3.5.21.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 ExampleEnemy
{
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "FreddyKrueger";

		public const string PLUGIN_NAME = "FreddyKrueger";

		public const string PLUGIN_VERSION = "3.5.21";
	}
}
namespace FreddyKruegerLC
{
	public class FreddyAi : EnemyAI
	{
		private enum State
		{
			Spawning,
			Walking,
			Running,
			RunningClaw,
			Sneaking,
			None
		}

		public SleepMechanics sleepScript;

		public AudioClip laugh1;

		public AudioClip laugh2;

		public AudioClip laugh3;

		public AudioClip laugh4;

		public AudioClip laugh5;

		public AudioClip laugh6;

		public AudioClip laugh7;

		public AudioClip laugh8;

		public AudioClip laugh9;

		public AudioClip laugh10;

		public AudioClip enterTheDream;

		public AudioClip terminus;

		public AudioSource talkingAudioSource;

		public AudioSource feet1;

		public AudioSource feet2;

		public ParticleSystem freddyRain;

		public ParticleSystem freddyTeleport;

		public Transform attackArea;

		public Material BWShadder;

		public Material shirt;

		public Material pants;

		public Material hands;

		public Material claw;

		[FormerlySerializedAs("hat")]
		public Material face;

		public SkinnedMeshRenderer[] freddyRenderer;

		[Header("Voicelines")]
		public AudioSource speakerAudio;

		public AudioClip[] killAudio;

		public AudioClip[] rndTalkAudio;

		private List<PlayerSleep> _playerSleep;

		private ulong _clientId;

		private int _indexSleepArray;

		private bool _justSwitchedBehaviour;

		private bool _footStepRight;

		private int _enterSleep;

		private int _maxSleep;

		private bool _localPlayerAsleep;

		private int _behaviourIndexServer;

		private float _timer;

		[NonSerialized]
		public PlayerSleep _targetPlayerSleep;

		private bool _inCoroutine;

		private bool _firstCries;

		private bool _someoneIsKo;

		private bool _alreadyPlayerIntro;

		private bool _alreadyClock;

		private bool _freddySeen;

		private LethalServerMessage<List<PlayerSleep>> _serverMessageSleepArray;

		private LethalClientMessage<List<PlayerSleep>> _clientReceiveSleepArray;

		private string identifier;

		private Coroutine currentWaitAndChangebehavior;

		private bool isDeadHost;

		public void Awake()
		{
			_enterSleep = SyncedInstance<Config>.Instance.ENTER_SLEEP.Value;
			_maxSleep = SyncedInstance<Config>.Instance.SLEEP_MAX.Value;
			_ = _enterSleep;
		}

		public override void Start()
		{
			((EnemyAI)this).Start();
			sleepScript._enterSleep = _enterSleep;
			sleepScript._maxSleep = _maxSleep;
			ChangeCustomModifierClientRpc();
			isDeadHost = false;
			if (SyncedInstance<Config>.Instance.SOUND_CHILD_VOLUME.Value > 1f)
			{
				base.creatureSFX.volume = 1f;
			}
			else if (SyncedInstance<Config>.Instance.SOUND_CHILD_VOLUME.Value < 0f)
			{
				base.creatureSFX.volume = 0f;
			}
			else
			{
				base.creatureSFX.volume = SyncedInstance<Config>.Instance.SOUND_CHILD_VOLUME.Value;
			}
			if (((NetworkBehaviour)this).IsHost)
			{
				_behaviourIndexServer = 0;
				_justSwitchedBehaviour = true;
			}
			((MonoBehaviour)this).StartCoroutine(SeeIfAccessible());
			_clientId = 10101010uL;
			freddyRain.Stop();
			freddyTeleport.Stop();
			_freddySeen = true;
		}

		[ClientRpc]
		public void ChangeCustomModifierClientRpc()
		{
			//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)
			{
				return;
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(941668097u, val, (RpcDelivery)0);
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 941668097u, val, (RpcDelivery)0);
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
			{
				string text = RandomNumberGenerator.GetInt32(0, 999999999).ToString() + RandomNumberGenerator.GetInt32(0, 999999999) + RandomNumberGenerator.GetInt32(0, 999999999);
				_serverMessageSleepArray = new LethalServerMessage<List<PlayerSleep>>(text, (Action<List<PlayerSleep>, ulong>)null);
				_clientReceiveSleepArray = new LethalClientMessage<List<PlayerSleep>>(text, (Action<List<PlayerSleep>>)SetSleep, (Action<List<PlayerSleep>, ulong>)null);
				if (((NetworkBehaviour)this).IsHost)
				{
					sleepScript.SetServerMessage(_serverMessageSleepArray);
				}
			}
		}

		public override void Update()
		{
			((EnemyAI)this).Update();
			if (((NetworkBehaviour)this).IsHost)
			{
				_timer += Time.deltaTime;
				if (_timer >= 1f)
				{
					sleepScript.UpdateSleep();
					_timer = 0f;
				}
			}
		}

		public override void DoAIInterval()
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0354: Unknown result type (might be due to invalid IL or missing references)
			((EnemyAI)this).DoAIInterval();
			if (!((Object)(object)base.targetPlayer != (Object)null))
			{
				return;
			}
			((EnemyAI)this).SetDestinationToPosition(((Component)base.targetPlayer).transform.position, true);
			CheckIfPlayerIsInShip();
			switch (base.currentBehaviourStateIndex)
			{
			case 0:
				if (Object.op_Implicit((Object)(object)base.targetPlayer))
				{
					base.agent.speed = 0f;
					IdleFreddy();
					if (((NetworkBehaviour)this).IsHost)
					{
						sleepScript.SetBehavior();
					}
					_justSwitchedBehaviour = true;
					((MonoBehaviour)this).StopCoroutine(WaitAndChangeBehavior(5f));
				}
				break;
			case 1:
				if (_justSwitchedBehaviour)
				{
					base.agent.acceleration = 8f;
					TeleportRandomlyAroundPlayer(10f, 15f);
					IdleFreddy();
					DoAnimationClientRpc("Walking", setActive: true);
					base.agent.speed = 3f;
					_justSwitchedBehaviour = false;
					if (!_inCoroutine)
					{
						currentWaitAndChangebehavior = ((MonoBehaviour)this).StartCoroutine(WaitAndChangeBehavior(15f));
						_inCoroutine = true;
					}
				}
				if (((NetworkBehaviour)this).IsHost)
				{
					DoorHandler();
				}
				break;
			case 2:
				if (_justSwitchedBehaviour)
				{
					base.agent.acceleration = 8f;
					TeleportRandomlyAroundPlayer(10f, 20f);
					IdleFreddy();
					DoAnimationClientRpc("Running", setActive: true);
					base.agent.speed = 4f + SyncedInstance<Config>.Instance.SPEED_MODIFIER.Value;
					_justSwitchedBehaviour = false;
					if (!_inCoroutine)
					{
						currentWaitAndChangebehavior = ((MonoBehaviour)this).StartCoroutine(WaitAndChangeBehavior(12f));
						_inCoroutine = true;
					}
				}
				if (((NetworkBehaviour)this).IsHost)
				{
					DoorHandler();
				}
				break;
			case 3:
			{
				if (_justSwitchedBehaviour)
				{
					float num = 40 - (_targetPlayerSleep.SleepMeter - _maxSleep);
					float num2 = (40 - (_targetPlayerSleep.SleepMeter - _maxSleep)) / 2 * 3;
					TeleportRandomlyAroundPlayer((num >= 0f) ? num : 0f, (num >= 0f) ? num2 : 3f);
					IdleFreddy();
					DoAnimationClientRpc("RunWithClaw", setActive: true);
					base.agent.speed = 5f + SyncedInstance<Config>.Instance.SPEED_MODIFIER.Value;
					_justSwitchedBehaviour = false;
				}
				NavMeshAgent agent = base.agent;
				agent.speed += SyncedInstance<Config>.Instance.SPEED_MODIFIER_LAST_STAGE.Value;
				if (((NetworkBehaviour)this).IsHost)
				{
					DoorHandler();
				}
				base.agent.acceleration = 20f;
				break;
			}
			case 4:
				if (_justSwitchedBehaviour)
				{
					base.agent.acceleration = 8f;
					TeleportRandomlyAroundPlayer(10f, 13f);
					IdleFreddy();
					base.agent.speed = 1f + SyncedInstance<Config>.Instance.SPEED_MODIFIER.Value;
					DoAnimationClientRpc("Sneaking", setActive: true);
					currentWaitAndChangebehavior = ((MonoBehaviour)this).StartCoroutine(WaitAndChangeBehavior(17f));
					_justSwitchedBehaviour = false;
					base.agent.acceleration = 0f;
				}
				if (((NetworkBehaviour)this).IsHost)
				{
					DoorHandler();
				}
				if (base.targetPlayer.HasLineOfSightToPosition(((Component)this).transform.position, 45f, 60, -1f) && !_freddySeen)
				{
					_freddySeen = true;
					((MonoBehaviour)this).StopCoroutine(currentWaitAndChangebehavior);
					((MonoBehaviour)this).StartCoroutine(FreddyGotSeen());
				}
				break;
			default:
				Debug.Log((object)"Behavior State Missing");
				break;
			case 5:
				break;
			}
		}

		public void CheckIfPlayerIsInShip()
		{
			if (base.targetPlayer.isInHangarShipRoom)
			{
				StartOfRound.Instance.SetShipDoorsOverheatClientRpc();
			}
		}

		private IEnumerator FreddyGotSeen()
		{
			yield return (object)new WaitForSeconds(2f);
			IdleFreddy();
			RandomLaughClientRpc(RandomNumberGenerator.GetInt32(1, 11));
			base.agent.speed = 0f;
			if (!_inCoroutine)
			{
				RandomLaughClientRpc(RandomNumberGenerator.GetInt32(1, 11));
				DoAnimationClientRpc("Suprised");
				currentWaitAndChangebehavior = ((MonoBehaviour)this).StartCoroutine(WaitAndChangeBehavior(3f));
				_inCoroutine = true;
			}
		}

		private IEnumerator SeeIfAccessible()
		{
			int count = 0;
			while (true)
			{
				yield return (object)new WaitForSeconds(1f);
				if ((Object)(object)base.targetPlayer != (Object)null && !CanReach(((Component)this).transform.position, ((Component)base.targetPlayer).transform.position))
				{
					count++;
					if (count >= 3)
					{
						((EnemyAI)this).SwitchToBehaviourClientRpc(0);
						count = -1;
					}
				}
				else
				{
					count = 0;
				}
			}
		}

		private void LocalPlayerFreddyHandler()
		{
			if (((NetworkBehaviour)this).IsHost && isDeadHost)
			{
				SkinnedMeshEnable(enable: false);
				EnemyMeshAndPerson(enable: false);
				base.creatureVoice.Stop();
				base.creatureSFX.Stop();
			}
			else if (_playerSleep != null)
			{
				if (_indexSleepArray == -1)
				{
					SkinnedMeshEnable(enable: false);
				}
				if (_indexSleepArray != -1 && !RoundManager.Instance.playersManager.localPlayerController.isPlayerDead)
				{
					if ((Object)(object)base.targetPlayer != (Object)null && !base.targetPlayer.isPlayerControlled)
					{
						_ = _playerSleep[_indexSleepArray].SleepMeter;
						_ = _enterSleep - 50;
					}
					if (_playerSleep[_indexSleepArray].SleepMeter >= _enterSleep - 25 && !_alreadyPlayerIntro)
					{
						if (_clientId == 10101010)
						{
							_clientId = StartOfRound.Instance.localPlayerController.playerClientId;
						}
						Plugin.Logger.LogInfo((object)"Enter the dream! Sweet dream...");
						base.creatureSFX.PlayOneShot(enterTheDream);
						_alreadyPlayerIntro = true;
					}
					if (_playerSleep[_indexSleepArray].SleepMeter >= _enterSleep)
					{
						SkinnedMeshEnable(enable: true);
						EnemyMeshAndPerson(enable: true);
						if (!base.creatureSFX.isPlaying)
						{
							base.creatureSFX.Play();
							_firstCries = true;
						}
					}
					else
					{
						SkinnedMeshEnable(enable: false);
						EnemyMeshAndPerson(enable: false);
						if (_firstCries)
						{
							base.creatureSFX.Stop();
						}
					}
					if (_playerSleep[_indexSleepArray].SleepMeter >= _maxSleep - 80)
					{
						if (!_alreadyClock)
						{
							Debug.Log((object)"You better run!");
							base.creatureSFX.PlayOneShot(terminus);
							_alreadyClock = true;
						}
					}
					else
					{
						_ = _playerSleep[_indexSleepArray].SleepMeter;
						_ = _maxSleep - 80;
					}
				}
				else
				{
					if (_firstCries)
					{
						base.creatureSFX.Stop();
					}
					base.creatureVoice.Stop();
					base.creatureSFX.Stop();
				}
			}
			else
			{
				Plugin.Logger.Log((LogLevel)8, (object)"No Sleep level set yet!");
			}
		}

		public void SetSleep(List<PlayerSleep> x)
		{
			if (x.Count > 0 && SyncedInstance<Config>.Instance.SLEEP_DEBUG.Value)
			{
				Plugin.Logger.LogInfo((object)("SLEEEP " + x[0].SleepMeter));
			}
			_playerSleep = x;
			LocalPlayerFreddyHandler();
		}

		[ClientRpc]
		public void ShowTeleportParticleClientRpc()
		{
			//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(1227951244u, val, (RpcDelivery)0);
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 1227951244u, val, (RpcDelivery)0);
				}
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost) && _playerSleep != null && _indexSleepArray != -1)
				{
					((MonoBehaviour)this).StartCoroutine(TransitionMaterial(manifest: false, 1f));
				}
			}
		}

		[ClientRpc]
		public void DoAIStepIntervalClientRpc()
		{
			//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)
			{
				return;
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(395556641u, val, (RpcDelivery)0);
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 395556641u, val, (RpcDelivery)0);
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost) && _indexSleepArray != -1 && _playerSleep.Count > 0 && _playerSleep[_indexSleepArray].SleepMeter >= _enterSleep)
			{
				if (_footStepRight)
				{
					feet1.Play();
					_footStepRight = false;
				}
				else
				{
					feet2.Play();
					_footStepRight = true;
				}
			}
		}

		[ClientRpc]
		public void DoAnimationClientRpc(string animationName, bool setActive)
		{
			//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(3482447210u, 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 setActive, default(ForPrimitives));
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 3482447210u, val, (RpcDelivery)0);
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
			{
				base.creatureAnimator.SetBool(animationName, setActive);
			}
		}

		[ClientRpc]
		public void DoAnimationClientRpc(string animationName)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: 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_00ba: 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(3813649309u, val, (RpcDelivery)0);
				bool flag = animationName != null;
				((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
				if (flag)
				{
					((FastBufferWriter)(ref val2)).WriteValueSafe(animationName, false);
				}
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 3813649309u, val, (RpcDelivery)0);
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
			{
				base.creatureAnimator.SetTrigger(animationName);
			}
		}

		public override void OnCollideWithPlayer(Collider other)
		{
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			PlayerControllerB playerControllerB = ((Component)other).gameObject.GetComponent<PlayerControllerB>();
			if ((Object)(object)playerControllerB != (Object)null && _playerSleep.FirstOrDefault((PlayerSleep obj) => obj.ClientID == playerControllerB.actualClientId).SleepMeter >= _enterSleep)
			{
				PlayDeathAudioClientRpc(RandomNumberGenerator.GetInt32(0, killAudio.Length));
				playerControllerB.KillPlayer(Vector3.up, true, (CauseOfDeath)0, 1);
				((EnemyAI)this).SwitchToBehaviourClientRpc(0);
				if (((NetworkBehaviour)this).IsHost && !isDeadHost && RoundManager.Instance.playersManager.localPlayerController.playerClientId == LethalNetworkExtensions.GetClientId(playerControllerB))
				{
					((MonoBehaviour)this).StartCoroutine(HostDied());
				}
			}
		}

		[ClientRpc]
		public void RandomLaughClientRpc(int x)
		{
			//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)
			{
				return;
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(787306241u, val, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val2, x);
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 787306241u, val, (RpcDelivery)0);
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost) && _indexSleepArray != -1 && _playerSleep[_indexSleepArray].SleepMeter >= _enterSleep)
			{
				switch (x)
				{
				case 1:
					talkingAudioSource.PlayOneShot(laugh1);
					break;
				case 2:
					talkingAudioSource.PlayOneShot(laugh2);
					break;
				case 3:
					talkingAudioSource.PlayOneShot(laugh3);
					break;
				case 4:
					talkingAudioSource.PlayOneShot(laugh4);
					break;
				case 5:
					talkingAudioSource.PlayOneShot(laugh5);
					break;
				case 6:
					talkingAudioSource.PlayOneShot(laugh6);
					break;
				case 7:
					talkingAudioSource.PlayOneShot(laugh7);
					break;
				case 8:
					talkingAudioSource.PlayOneShot(laugh8);
					break;
				case 9:
					talkingAudioSource.PlayOneShot(laugh9);
					break;
				case 10:
					talkingAudioSource.PlayOneShot(laugh10);
					break;
				default:
					Debug.LogError((object)"Number Generated for laugh was a miss!");
					break;
				}
			}
		}

		[ClientRpc]
		public void TeleportExecuteClientRpc(Vector3 position)
		{
			//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_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			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(1290401464u, val, (RpcDelivery)0);
				((FastBufferWriter)(ref val2)).WriteValueSafe(ref position);
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 1290401464u, val, (RpcDelivery)0);
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 2 || (!networkManager.IsClient && !networkManager.IsHost))
			{
				return;
			}
			base.agent.Warp(position);
			((MonoBehaviour)this).StartCoroutine(TransitionMaterial(manifest: true, 3f));
			if (((NetworkBehaviour)this).IsHost)
			{
				DoAnimationClientRpc("Teleport");
				RandomLaughClientRpc(RandomNumberGenerator.GetInt32(1, 11));
				freddyTeleport.Play();
				if (base.currentBehaviourStateIndex == 4)
				{
					_freddySeen = true;
				}
				else
				{
					_freddySeen = false;
				}
			}
		}

		public static PlayerControllerB? GetPlayerController(ulong clientId)
		{
			return StartOfRound.Instance.allPlayerScripts[StartOfRound.Instance.ClientPlayerList[clientId]];
		}

		public bool CanReach(Vector3 pointA, Vector3 pointB)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: 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_0018: Invalid comparison between Unknown and I4
			NavMeshPath val = new NavMeshPath();
			if (NavMesh.CalculatePath(pointA, pointB, -1, val))
			{
				return (int)val.status == 0;
			}
			return false;
		}

		[ClientRpc]
		public void ResetIndexClientRpc()
		{
			//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(3690178122u, val, (RpcDelivery)0);
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 3690178122u, val, (RpcDelivery)0);
				}
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
				{
					SetLocalIndex();
				}
			}
		}

		private void DoorHandler()
		{
			//IL_0048: 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)
			DoorLock[] array = Object.FindObjectsOfType(typeof(DoorLock)) as DoorLock[];
			foreach (DoorLock val in array)
			{
				GameObject gameObject = ((Component)((Component)((Component)((Component)val).transform.parent).transform.parent).transform.parent).gameObject;
				if (Vector3.Distance(((Component)this).transform.position, gameObject.transform.position) <= 4f)
				{
					val.OpenDoorAsEnemyClientRpc();
				}
			}
		}

		public void TeleportRandomlyAroundPlayer(float minTeleportDistance, float maxTeleportDistance)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: 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_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: 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_0073: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)base.targetPlayer != (Object)null))
			{
				return;
			}
			int num = 10;
			for (int i = 0; i < num; i++)
			{
				Vector3 randomNavMeshPositionInRadiusSpherical = GetRandomNavMeshPositionInRadiusSpherical(((Component)base.targetPlayer).transform.position, maxTeleportDistance);
				if (Vector3.Distance(randomNavMeshPositionInRadiusSpherical, ((Component)base.targetPlayer).transform.position) >= minTeleportDistance && CanReach(randomNavMeshPositionInRadiusSpherical, ((Component)base.targetPlayer).transform.position))
				{
					ShowTeleportParticleClientRpc();
					((MonoBehaviour)this).StartCoroutine(ExecuteTeleportFreddy(randomNavMeshPositionInRadiusSpherical));
					break;
				}
				Plugin.Logger.LogInfo((object)i);
			}
		}

		public Vector3 GetRandomNavMeshPositionInRadiusSpherical(Vector3 pos, float radius = 10f, NavMeshHit navHit = default(NavMeshHit))
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: 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_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: 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)
			//IL_00bf: 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_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: 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_003a: 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_0049: 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_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			pos = Random.insideUnitSphere * radius + pos;
			if (NavMesh.SamplePosition(pos, ref navHit, radius + 2f, -1))
			{
				Debug.DrawRay(pos + Vector3.forward * 0.01f, Vector3.up * 2f, Color.blue);
				return ((NavMeshHit)(ref navHit)).position;
			}
			float num = Random.Range(0f, 360f);
			float num2 = Random.Range(5f, radius);
			Vector3 val = Quaternion.Euler(0f, num, 0f) * Vector3.forward;
			Vector3 val2 = ((Component)base.targetPlayer).transform.position + val * num2;
			RaycastHit val3 = default(RaycastHit);
			if (Physics.Raycast(val2 + Vector3.up * 100f, Vector3.down, ref val3, float.PositiveInfinity))
			{
				val2 = ((RaycastHit)(ref val3)).point;
			}
			if (CanReach(val2, ((Component)base.targetPlayer).transform.position))
			{
				ShowTeleportParticleClientRpc();
				((MonoBehaviour)this).StartCoroutine(ExecuteTeleportFreddy(val2));
				return val2;
			}
			return pos;
		}

		private IEnumerator ExecuteTeleportFreddy(Vector3 position)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			yield return (object)new WaitForSeconds(1f);
			TeleportExecuteClientRpc(position);
		}

		private IEnumerator WaitAndChangeBehavior(float x)
		{
			yield return (object)new WaitForSeconds(x);
			if (((NetworkBehaviour)this).IsHost)
			{
				((EnemyAI)this).SwitchToBehaviourClientRpc(0);
			}
			else
			{
				Debug.Log((object)"Awaiting Host Behavior");
			}
			_freddySeen = false;
			_justSwitchedBehaviour = true;
			_inCoroutine = false;
		}

		private void IdleFreddy()
		{
			DoAnimationClientRpc("Running", setActive: false);
			DoAnimationClientRpc("Walking", setActive: false);
			DoAnimationClientRpc("RunWithClaw", setActive: false);
			DoAnimationClientRpc("Sneaking", setActive: false);
		}

		public void EnemyMeshAndPerson(bool enable)
		{
			((EnemyAI)this).EnableEnemyMesh(enable, false);
			if (enable)
			{
				AudioSource creatureVoice = base.creatureVoice;
				creatureVoice.volume += 0.1f;
				if (!freddyRain.isPlaying)
				{
					freddyRain.Play();
				}
			}
			else
			{
				freddyRain.Stop();
				freddyRain.Clear();
				AudioSource creatureVoice2 = base.creatureVoice;
				creatureVoice2.volume -= 0.2f;
			}
		}

		public override void EnableEnemyMesh(bool enable, bool overrideDoNotSet = false)
		{
			if (base.skinnedMeshRenderers == null || base.meshRenderers == null)
			{
				return;
			}
			int layer = (enable ? 19 : 23);
			SkinnedMeshRenderer[] skinnedMeshRenderers = base.skinnedMeshRenderers;
			foreach (SkinnedMeshRenderer val in skinnedMeshRenderers)
			{
				if ((Object)(object)val != (Object)null && (!((Component)val).CompareTag("DoNotSet") || overrideDoNotSet))
				{
					((Component)val).gameObject.layer = layer;
					((Renderer)val).enabled = enable;
				}
			}
			MeshRenderer[] meshRenderers = base.meshRenderers;
			foreach (MeshRenderer val2 in meshRenderers)
			{
				if ((Object)(object)val2 != (Object)null && (!((Component)val2).CompareTag("DoNotSet") || overrideDoNotSet))
				{
					((Component)val2).gameObject.layer = layer;
					((Renderer)val2).enabled = enable;
				}
			}
		}

		private IEnumerator TransitionMaterial(bool manifest, float time)
		{
			float elapsedTime = 0f;
			float startValue = shirt.GetFloat("Vector1_FEFF47F1");
			float targetValue = (manifest ? 0f : 1f);
			if (manifest)
			{
				yield return (object)new WaitForSeconds(1f);
			}
			while (elapsedTime < time)
			{
				ModifyMaterial(Mathf.Lerp(startValue, targetValue, elapsedTime / time));
				elapsedTime += Time.deltaTime;
				yield return null;
			}
			ModifyMaterial(targetValue);
		}

		public void ModifyMaterial(float x)
		{
			if (x < 1.01f && x >= 0f)
			{
				shirt.SetFloat("Vector1_FEFF47F1", x);
				pants.SetFloat("Vector1_FEFF47F1", x);
				hands.SetFloat("Vector1_FEFF47F1", x);
				claw.SetFloat("Vector1_FEFF47F1", x);
				face.SetFloat("Vector1_FEFF47F1", x);
			}
		}

		public void SetLocalIndex()
		{
			bool flag = false;
			int num = 0;
			foreach (PlayerSleep item in _playerSleep)
			{
				if (item.ClientID == _clientId)
				{
					_indexSleepArray = num;
					flag = true;
				}
				num++;
			}
			if (!flag)
			{
				_indexSleepArray = -1;
			}
		}

		[ClientRpc]
		public void PlayDeathAudioClientRpc(int x)
		{
			//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 != 2 && (networkManager.IsServer || networkManager.IsHost))
				{
					ClientRpcParams val = default(ClientRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(2179566742u, val, (RpcDelivery)0);
					BytePacker.WriteValueBitPacked(val2, x);
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 2179566742u, val, (RpcDelivery)0);
				}
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
				{
					speakerAudio.PlayOneShot(killAudio[x]);
				}
			}
		}

		private IEnumerator HostDied()
		{
			yield return (object)new WaitForSeconds(10f);
			isDeadHost = true;
		}

		private void SkinnedMeshEnable(bool enable)
		{
			SkinnedMeshRenderer[] array = freddyRenderer;
			for (int i = 0; i < array.Length; i++)
			{
				((Renderer)array[i]).enabled = enable;
			}
		}

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

		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeRPCS_FreddyAi()
		{
			//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
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Expected O, but got Unknown
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Expected O, but got Unknown
			NetworkManager.__rpc_func_table.Add(941668097u, new RpcReceiveHandler(__rpc_handler_941668097));
			NetworkManager.__rpc_func_table.Add(1227951244u, new RpcReceiveHandler(__rpc_handler_1227951244));
			NetworkManager.__rpc_func_table.Add(395556641u, new RpcReceiveHandler(__rpc_handler_395556641));
			NetworkManager.__rpc_func_table.Add(3482447210u, new RpcReceiveHandler(__rpc_handler_3482447210));
			NetworkManager.__rpc_func_table.Add(3813649309u, new RpcReceiveHandler(__rpc_handler_3813649309));
			NetworkManager.__rpc_func_table.Add(787306241u, new RpcReceiveHandler(__rpc_handler_787306241));
			NetworkManager.__rpc_func_table.Add(1290401464u, new RpcReceiveHandler(__rpc_handler_1290401464));
			NetworkManager.__rpc_func_table.Add(3690178122u, new RpcReceiveHandler(__rpc_handler_3690178122));
			NetworkManager.__rpc_func_table.Add(2179566742u, new RpcReceiveHandler(__rpc_handler_2179566742));
		}

		private static void __rpc_handler_941668097(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;
				((FreddyAi)(object)target).ChangeCustomModifierClientRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_1227951244(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;
				((FreddyAi)(object)target).ShowTeleportParticleClientRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_395556641(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;
				((FreddyAi)(object)target).DoAIStepIntervalClientRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_3482447210(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 setActive = default(bool);
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref setActive, default(ForPrimitives));
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((FreddyAi)(object)target).DoAnimationClientRpc(animationName, setActive);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_3813649309(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_0061: 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)
			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);
				}
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((FreddyAi)(object)target).DoAnimationClientRpc(animationName);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_787306241(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)
			{
				int x = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref x);
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((FreddyAi)(object)target).RandomLaughClientRpc(x);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_1290401464(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//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)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				Vector3 position = default(Vector3);
				((FastBufferReader)(ref reader)).ReadValueSafe(ref position);
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((FreddyAi)(object)target).TeleportExecuteClientRpc(position);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_3690178122(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;
				((FreddyAi)(object)target).ResetIndexClientRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_2179566742(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)
			{
				int x = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref x);
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((FreddyAi)(object)target).PlayDeathAudioClientRpc(x);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		protected internal override string __getTypeName()
		{
			return "FreddyAi";
		}
	}
	public class PlayerSleep
	{
		public ulong clientID;

		public int sleepMeter;

		public int targetPoint;

		public ulong ClientID
		{
			get
			{
				return clientID;
			}
			set
			{
				clientID = value;
			}
		}

		public int SleepMeter
		{
			get
			{
				return sleepMeter;
			}
			set
			{
				sleepMeter = value;
			}
		}

		public int TargetPoint
		{
			get
			{
				return targetPoint;
			}
			set
			{
				targetPoint = value;
			}
		}

		public PlayerSleep(ulong clientID, int sleepMeter)
		{
			this.clientID = clientID;
			this.sleepMeter = sleepMeter;
			targetPoint = 0;
		}

		public PlayerSleep()
		{
			targetPoint = 0;
		}
	}
	public class SleepMechanics : MonoBehaviour
	{
		public FreddyAi mainScript;

		private List<PlayerSleep> _playerSleep;

		private LethalServerMessage<List<PlayerSleep>> _serverMessage;

		public int _enterSleep;

		public int _maxSleep;

		private int _behaviourIndexServer;

		[NonSerialized]
		public PlayerSleep targetPlayerSleep;

		private PlayerControllerB targetPlayer;

		private int currentBehaviourStateIndex;

		public void SetServerMessage(LethalServerMessage<List<PlayerSleep>> x)
		{
			_serverMessage = x;
		}

		public void UpdateLocalSleep(ulong clientID, int strenght)
		{
			int num = (int)(1.5 * (double)strenght + 20.0);
			num = _playerSleep.Find((PlayerSleep obj) => obj.ClientID == clientID).SleepMeter - num;
			if (num <= 0)
			{
				num = 0;
			}
			targetPlayerSleep = _playerSleep.Find((PlayerSleep obj) => obj.ClientID == clientID);
			targetPlayerSleep.SleepMeter = num;
		}

		public void UpdateSleep()
		{
			if (_playerSleep != null)
			{
				CheckIfMissingPlayer();
			}
			else
			{
				_playerSleep = new List<PlayerSleep>();
				foreach (PlayerControllerB item in RoundManager.Instance.playersManager.allPlayerScripts.Where((PlayerControllerB obj) => obj.isPlayerControlled))
				{
					_playerSleep.Add(new PlayerSleep(item.actualClientId, 0));
					Plugin.Logger.LogInfo((object)"[Freddy] : Added a player");
				}
			}
			for (int i = 0; i < _playerSleep.Count; i++)
			{
				PlayerControllerB playerController = LethalNetworkExtensions.GetPlayerController(_playerSleep[i].ClientID);
				if (CheckIfAlone(playerController))
				{
					if (SyncedInstance<Config>.Instance.SHIP_MOMMY_TARGET.Value || !playerController.isInHangarShipRoom)
					{
						_playerSleep[i].SleepMeter++;
						if (LethalNetworkExtensions.GetPlayerController(_playerSleep[i].clientID).insanityLevel == 50f)
						{
							_playerSleep[i].SleepMeter++;
						}
					}
					if (SyncedInstance<Config>.Instance.SOLO_GAMEPLAY.Value && _enterSleep + SyncedInstance<Config>.Instance.TIME_BEFORE_LEAVING_SLEEP.Value == _playerSleep[i].SleepMeter)
					{
						_playerSleep[i].SleepMeter = 0;
						if (SyncedInstance<Config>.Instance.RANDOM_SLEEP.Value)
						{
							_enterSleep = SyncedInstance<Config>.Instance.ENTER_SLEEP.Value + RandomNumberGenerator.GetInt32(0, 50);
							_maxSleep = _enterSleep + 200;
						}
					}
				}
				else if (_playerSleep[i].SleepMeter > 0)
				{
					if (_playerSleep[i].SleepMeter == 1)
					{
						_playerSleep[i].SleepMeter = 0;
					}
					else
					{
						_playerSleep[i].SleepMeter -= 2;
					}
				}
			}
			if (_behaviourIndexServer != 3)
			{
				ChooseTarget();
			}
			_serverMessage.SendAllClients(_playerSleep, true);
		}

		public void CheckIfMissingPlayer()
		{
			if (_playerSleep.Count <= 0)
			{
				return;
			}
			try
			{
				foreach (PlayerSleep item in _playerSleep)
				{
					if (LethalNetworkExtensions.GetPlayerController(item.ClientID).isPlayerDead)
					{
						Plugin.Logger.Log((LogLevel)3, (object)"Removing Player From array");
						_playerSleep.Remove(item);
						mainScript.ResetIndexClientRpc();
						_serverMessage.SendAllClients(_playerSleep, true);
					}
				}
			}
			catch (Exception)
			{
				Debug.Log((object)"Removing player");
			}
		}

		public bool CheckIfAlone(PlayerControllerB player)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: 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_0049: 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)
			Vector3 position = ((Component)player).transform.position;
			for (int i = 0; i < _playerSleep.Count; i++)
			{
				if (_playerSleep[i].ClientID != player.actualClientId)
				{
					Vector3 position2 = ((Component)LethalNetworkExtensions.GetPlayerController(_playerSleep[i].ClientID)).transform.position;
					if (Vector3.Distance(position, position2) <= SyncedInstance<Config>.Instance.DISTANCE_FOR_SLEEP.Value && (Object)(object)player != (Object)(object)LethalNetworkExtensions.GetPlayerController(_playerSleep[i].ClientID))
					{
						return false;
					}
				}
			}
			return true;
		}

		public void ChooseTarget()
		{
			List<PlayerSleep> list = new List<PlayerSleep>();
			foreach (PlayerSleep item in _playerSleep)
			{
				if (item.SleepMeter >= _enterSleep && LethalNetworkExtensions.GetPlayerController(item.ClientID).isPlayerControlled)
				{
					list.Add(item);
				}
			}
			list.Sort((PlayerSleep a, PlayerSleep b) => b.SleepMeter.CompareTo(a.SleepMeter));
			PlayerSleep playerSleep = new PlayerSleep();
			playerSleep.TargetPoint = -100;
			playerSleep.ClientID = 9999999999uL;
			for (int i = 0; i < list.Count; i++)
			{
				list[i].TargetPoint += 5 - i;
			}
			if (list.Count == 0 || _playerSleep == null)
			{
				return;
			}
			foreach (PlayerSleep item2 in list)
			{
				PlayerControllerB playerController = LethalNetworkExtensions.GetPlayerController(item2.ClientID);
				if (playerController.isInsideFactory)
				{
					item2.TargetPoint += 3;
				}
				if (playerController.criticallyInjured)
				{
					item2.TargetPoint += 5;
				}
				if (CheckIfAlone(playerController))
				{
					item2.TargetPoint += 7;
				}
				if (playerController.isInHangarShipRoom)
				{
					item2.TargetPoint -= 3;
				}
				if (playerController.carryWeight >= 50f)
				{
					item2.TargetPoint += 2;
				}
				if (playerController.carryWeight >= 100f)
				{
					item2.TargetPoint += 2;
				}
				if (playerController.carryWeight == 0f)
				{
					item2.TargetPoint -= 2;
				}
				if (LethalNetworkExtensions.GetPlayerController(item2.ClientID).insanityLevel == 50f)
				{
					item2.TargetPoint += 5;
				}
				if (item2.TargetPoint > playerSleep.TargetPoint)
				{
					playerSleep = item2;
				}
			}
			foreach (PlayerSleep player in _playerSleep)
			{
				if (player.ClientID == playerSleep.ClientID && playerSleep.ClientID != 9999999999L)
				{
					SetTargetPlayerClientRpc(player.ClientID);
					targetPlayer = LethalNetworkExtensions.GetPlayerController(player.ClientID);
					targetPlayerSleep = _playerSleep.Find((PlayerSleep obj) => obj.ClientID == player.ClientID);
					break;
				}
			}
		}

		[ClientRpc]
		public void SetTargetPlayerClientRpc(ulong targetPlayerId)
		{
			LethalNetworkExtensions.GetPlayerController(targetPlayerId);
			((EnemyAI)mainScript).targetPlayer = targetPlayer;
			PlayerSleep playerSleep = _playerSleep.Find((PlayerSleep obj) => obj.ClientID == targetPlayerId);
			mainScript._targetPlayerSleep = playerSleep;
		}

		public void SetBehavior()
		{
			if ((Object)(object)targetPlayer != (Object)null)
			{
				bool flag = false;
				if (targetPlayerSleep.SleepMeter >= _enterSleep && targetPlayerSleep.SleepMeter < _maxSleep)
				{
					if (targetPlayerSleep.SleepMeter >= RandomNumberGenerator.GetInt32(_maxSleep - 50, _maxSleep + 20) - SyncedInstance<Config>.Instance.STATE_INCREASE.Value)
					{
						if (currentBehaviourStateIndex != 2)
						{
							_behaviourIndexServer = 2;
							flag = true;
						}
					}
					else if (targetPlayerSleep.SleepMeter >= RandomNumberGenerator.GetInt32(_maxSleep - 50, _maxSleep + 20) - SyncedInstance<Config>.Instance.STATE_INCREASE.Value)
					{
						if (currentBehaviourStateIndex != 4)
						{
							_behaviourIndexServer = 4;
							flag = true;
						}
					}
					else if (currentBehaviourStateIndex != 4)
					{
						_behaviourIndexServer = 1;
						flag = true;
					}
				}
				else if (targetPlayerSleep.SleepMeter >= _maxSleep)
				{
					_behaviourIndexServer = 3;
					flag = true;
				}
				if (flag)
				{
					Plugin.Logger.LogInfo((object)("Set behavior state :  " + _behaviourIndexServer + "   Index"));
					((EnemyAI)mainScript).SwitchToBehaviourClientRpc(_behaviourIndexServer);
				}
			}
			else if (_behaviourIndexServer != 5)
			{
				((EnemyAI)mainScript).SwitchToBehaviourClientRpc(5);
			}
		}
	}
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("Xilef992.FreddyKrueger", "FreddyKrueger", "2.3.16")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(RoundManager))]
		internal class EndOfRoundFixes
		{
			[HarmonyPatch("BeginEnemySpawning")]
			[HarmonyPostfix]
			private static void PostfixSpawn()
			{
				//IL_0413: Unknown result type (might be due to invalid IL or missing references)
				//IL_043a: Unknown result type (might be due to invalid IL or missing references)
				//IL_032e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0355: Unknown result type (might be due to invalid IL or missing references)
				if (!((NetworkBehaviour)RoundManager.Instance).IsServer || RoundManager.Instance.allEnemyVents.Length == 0)
				{
					return;
				}
				if (Config.USE_MOON_CHANCES.Value)
				{
					bool flag = false;
					switch (RoundManager.Instance.currentLevel.PlanetName)
					{
					case "41 Experimentation":
						if (RandomNumberGenerator.GetInt32(0, 101) <= SyncedInstance<Config>.Instance.EXPERIMENTATION_SPAWNRATE.Value)
						{
							flag = true;
						}
						break;
					case "220 Assurance":
						if (RandomNumberGenerator.GetInt32(0, 101) <= SyncedInstance<Config>.Instance.ASSURANCE_SPAWNRATE.Value)
						{
							flag = true;
							Logger.LogInfo((object)"Money ain't real O_O ...");
						}
						break;
					case "56 Vow":
						if (RandomNumberGenerator.GetInt32(0, 101) <= SyncedInstance<Config>.Instance.VOW_SPAWNRATE.Value)
						{
							flag = true;
						}
						break;
					case "12 Offense":
						if (RandomNumberGenerator.GetInt32(0, 101) <= SyncedInstance<Config>.Instance.OFFENSE_SPAWNRATE.Value)
						{
							flag = true;
						}
						break;
					case "61 March":
						if (RandomNumberGenerator.GetInt32(0, 101) <= SyncedInstance<Config>.Instance.MARCH_SPAWNRATE.Value)
						{
							flag = true;
						}
						break;
					case "85 Rend":
						if (RandomNumberGenerator.GetInt32(0, 101) <= SyncedInstance<Config>.Instance.REND_SPAWNRATE.Value)
						{
							flag = true;
						}
						break;
					case "7 Dine":
						if (RandomNumberGenerator.GetInt32(0, 101) <= SyncedInstance<Config>.Instance.DINE_SPAWNRATE.Value)
						{
							flag = true;
						}
						break;
					case "8 Titan":
						if (RandomNumberGenerator.GetInt32(0, 101) <= SyncedInstance<Config>.Instance.TITAN_SPAWNRATE.Value)
						{
							flag = true;
						}
						break;
					default:
						if (RandomNumberGenerator.GetInt32(0, 101) <= SyncedInstance<Config>.Instance.BASE_SPAWN_CHANCES.Value)
						{
							flag = true;
						}
						break;
					}
					if (flag)
					{
						Logger.LogInfo((object)"Freddy is here! Wait till you sleep tho...");
						List<SpawnableEnemyWithRarity> list = new List<SpawnableEnemyWithRarity>();
						list.AddRange(RoundManager.Instance.currentLevel.Enemies);
						list.AddRange(RoundManager.Instance.currentLevel.OutsideEnemies);
						SpawnableEnemyWithRarity val = list.Find((SpawnableEnemyWithRarity x) => x.enemyType.enemyName.Equals("FreddyKrueger"));
						Logger.LogInfo((object)(val.enemyType.enemyName + "This is the name!"));
						if (val != null)
						{
							RoundManager.Instance.SpawnEnemyGameObject(((Component)RoundManager.Instance.allEnemyVents[0]).transform.position, 0f, RoundManager.Instance.currentLevel.OutsideEnemies.IndexOf(val), val.enemyType);
						}
						else
						{
							Logger.Log((LogLevel)1, (object)"There was an error finding Freddy amongst your list of enemy! \nSome mod prevented Freddy to be loaded as a monster");
						}
					}
					else
					{
						Debug.Log((object)"Freddy's Spawn was a miss");
					}
				}
				else if (RandomNumberGenerator.GetInt32(0, 101) <= SyncedInstance<Config>.Instance.BASE_SPAWN_CHANCES.Value)
				{
					Logger.Log((LogLevel)8, (object)"Freddy is here! Wait till you sleep tho...");
					List<SpawnableEnemyWithRarity> list2 = new List<SpawnableEnemyWithRarity>();
					list2.AddRange(RoundManager.Instance.currentLevel.Enemies);
					list2.AddRange(RoundManager.Instance.currentLevel.OutsideEnemies);
					SpawnableEnemyWithRarity val2 = list2.Find((SpawnableEnemyWithRarity x) => x.enemyType.enemyName.Equals("FreddyKrueger"));
					if (val2 != null)
					{
						RoundManager.Instance.SpawnEnemyGameObject(((Component)RoundManager.Instance.allEnemyVents[0]).transform.position, 0f, RoundManager.Instance.currentLevel.OutsideEnemies.IndexOf(val2), val2.enemyType);
					}
					else
					{
						Logger.Log((LogLevel)1, (object)"There was an error finding Freddy amongst your list of enemy! \nSome mod prevented Freddy to be loaded as a monster");
					}
				}
				else
				{
					Logger.LogInfo((object)"Freddy's Spawn was a miss");
				}
			}
		}

		public const string ModGUID = "Xilef992.FreddyKrueger";

		private readonly Harmony harmony = new Harmony("FreddyKrueger");

		internal static ManualLogSource Logger;

		public static AssetBundle FreddyModAssets;

		public static Config Config { get; internal set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Config = new Config(((BaseUnityPlugin)this).Config);
			InitializeNetworkBehaviours();
			string path = "freddymodassets";
			FreddyModAssets = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), path));
			if ((Object)(object)FreddyModAssets == (Object)null)
			{
				Logger.LogError((object)"Failed to load custom assets.");
				return;
			}
			EnemyType obj = FreddyModAssets.LoadAsset<EnemyType>("FreddyKrueger");
			TerminalNode val = FreddyModAssets.LoadAsset<TerminalNode>("FreddyTN");
			TerminalKeyword val2 = FreddyModAssets.LoadAsset<TerminalKeyword>("FreddyTK");
			NetworkPrefabs.RegisterNetworkPrefab(obj.enemyPrefab);
			Enemies.RegisterEnemy(obj, 9999999, (LevelTypes)(-1), (SpawnType)0, val, val2);
			harmony.PatchAll(typeof(EndOfRoundFixes));
			harmony.PatchAll(typeof(ConfigurationsPatch));
			harmony.PatchAll(typeof(FreddyDamagePatch));
			Logger.LogInfo((object)"Plugin FreddyKrueger is loaded!");
			Debug.Log((object)"                                            ░░                                                     \n                                            ░░░░░                                                  \n                                              ░░░░                                                 \n                                               ░░░░                                                \n                                                ░░░░                                               \n                                                 ░░░░                                              \n                                                  ░░░░                                             \n                                                   ░░░░                                            \n                                                   ░░░░░                                           \n                                                    ░░░░                                           \n                                                     ░░░░                                          \n                                                      ░░░░                                         \n                                                      ░░░░                                         \n                                                       ░░                                          \n                                                       ░░░                                         \n                                                        ░░░░                                       \n                                                        ░░░░                                       \n                                                        ░░░░░                                      \n                ░░▒▒░░░░                                 ░▒░░░                                     \n             ░░▒▒▒▒▒▒▒▒░░░░░░░░                          ░░░░░                                     \n                     ░░░░░░░░░░░░░░░                     ▒░░░░░                                    \n                            ░░░░░░░░░░░░░                ▒▒▒▒▒░                                    \n                                 ░░░░░░░░░░░           ░▒▒▒▒▒▒▒                                    \n                                    ░░░░▒▒▒▒▒▒░        ▒▓▓▓▓▓▒▒░                                   \n                                       ░░░▒▒▒▒▒▒░░░    ▓▓▓▓▓▓▓▓▒                                   \n                                          ░▒▒▓▓▒▒▒▒░░░▒██▓▓▓▓▓▓▒░                                  \n                                            ▒███▓▓▓▓▓▓▓▓▓▓▓▓▒▓▓▒░                                  \n                                             ▓████████▓▓▓▓▓▓▓▓▓▓▒░                                 \n                                              ░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒▓▓▒░                                 \n                                              ░▒▓▓▓▓▓▓▓▓▓▓▓▓▓▒▒▓▓▒░                                \n                                                ▒▒▒▓▓▒▒▓▓▓▓▓▓▓▒▓▓▒▒▒                               \n                                                ▒▓████▒░▒▓▓▓▓▓▒▒▓▓▓▓▒                              \n                                                 ░▒▓▓████▓▓▓▓▓▓▓▒▓▓▓▒░                             \n                                              ░░▒▒▓▓▓▓██▓▓▓▓▓███▒░▒▓▓▒░                            \n               ░░░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▓▓▓▓▓█████████▓▓▒▒███▓░░▒▓▓▒                            \n        ░░▒▒▒▒▒▒▒▒░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▓▓▓███▓▓▓▓▓████████████▓████▓░░▒▓▓▒░                           \n   ░░░▒▒▒▒▒▒▒▒░░░░░░░             ░▒▓███████▓▓▓▓█▓▓▓█████▓▓▓▓▓▓█▓▒░░▓▓▓▒░                          \n ░░▒░▒░░░░░                          ░▓████████▓▓▓▒▒█████▓▒░▓▓▓██▓░░▒▓▓▓▒                          \n                                       ░▒▓▓███████▓▓▓████▓▒▓██▓▓█▓▒▒▒▓▓▓▓░                         \n                                            ░█████▓▓▓▓████▓▓▓▓████▒▒▒▒██▓▒░                        \n                                                     ░▒▓▓▓█▓██▓██▓▒▒▒▒▓▓▓▓▒░                       \n                                                  ░░ ░▒█████▓▓▓▓██▓▓▓▓▓▓▒▓▓░                       \n                                 ░▒▓▒░        ░▓██▓███████▓▓▓▓█████▓▒▒▓▓▓▓▓░                       \n                                 ▒▓▓▓▓▓░░░▒▓██▓▓█████████▓▓▓▓▓█▓████▓▓▓▓▓▓▓▓                       \n                                 ░▓▓▓▓▓▓▓█▓▓██████▓▓█████▓▓▓▓▓█▓█▓███▓▒▒▓▓▓▓                       \n                               ░░▒▒▓▓▓▓▓▓▓▓███████▓▓██▓█▓▓▓▓▓▓█▓█▓███▓▒▒▓▓▓▒                       \n                           ░░░░░░░▒▓█▓▓▓▓▓▓▓▓█████████▓▓▓▓▓▓▓▓█▓▓▓██▓▓▓▓▓▓▓░                       \n                       ░░░░░░░░░░   ▓█▓▓▓▓▓▓▓▓▓▓██▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓█▓▓▓▓▓▒▓▓▓▒                       \n                    ░░░░░░░          ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓███▓▓▓▓▓▓▓▓▓▓▒▒▓▓▓▓▓▓▓░                      \n                ░░░░░░░              ░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒░░▓▓▓▒░                     \n             ░░░░░░░                  ▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒▓▓▓▓░                     \n           ░░░░░                      ░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓███▓▓▓▓████▓▓▓▓▓▓▓▒░                    \n        ░░░░░                           ░▓▓▓▓██▓▓▓▓▓▓▓▓▓▓███▓▓▓████████▓▓▓▓▓▓▓░                    \n      ░░░░                               ░▒▓▓▓█▓▓▓▓▓▓▓█████▓▓▓█████████▓▓▓▓▓▓▓▒░                   \n     ░░░                                  ░▓████▓▓▓▓██████▓▓████████████▓▓▓▓▓▓▓░                   \n                                           ░▓██████████████████▓█████████▓▓▓▓▓▓▒                   \n                                             ░▓██████████████▓██▓██▓█████▓▒▓▓▓▒░                   \n                                              ░▒▓███████████▓█▓▓▓▓█▓███▓██▓▓█▓▒░                   \n                                                 ▒▓████████████▓▓▓▓█▓████████▓▓▒░                  \n                                                  ░▓███████████▓▓▓▓█▓▓▓▓███▓▓▓▓▓▓░                 \n                                                   ░▓█████████▓▓▓▓██████▓▓▓▓▓██▓█▓                 \n                                                    ▒▓█████▓▓▓▓▓▓████▓▓▓▓▓▓▓▓▓▓▓▓▓▓                \n                                                    ░▓▓█▓▓▓▓▓▓▓████▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒               \n                                                    ░▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░              \n                                                     ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒              \n                                                     ▒▓▓▓▓▓▓▓▓▓▓▓▓▓█▓▓▓▓▓▓▓▓██████▓▓▓              \n                                                      ▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓███████████▓░▓░             \n                                                      ▓▓▓▓▓▓▓▓▓█▓▓██▓█████████████▓▒▓▒             \n                                                     ░▓▓▓▓▓▓▓▓▓█▓███████████████████▓░             \n                                                       ▒▓▓▓▓████████████████████████▓▓             \n                                                      ░▓▓▓▓▓█████████████████████████▓▒            \n                                                      ░▓▓▓██▓█▓█▓█▓██▓████████████████▓░           \n                                                      ▒▓▓▓▓▓▓▓██▓█▓████████████████████▓░          \n                                                    ░▒▓▓▓▓█████████████████████████████▓░          \n                                                   ░▒▓▓██████████████████████████████▓▓▒░          \n                                                   ▒▓██████████████████████████████████▓▓▒         \n                                                  ░▓█▓▓▓██████████████████████████████████▓▒░      \n                                                  ░▒▓▓▓▓▓███████████████████████████████████▓░     ");
		}

		private static void InitializeNetworkBehaviours()
		{
			Type[] types = Assembly.GetExecutingAssembly().GetTypes();
			for (int i = 0; i < types.Length; i++)
			{
				MethodInfo[] methods = types[i].GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
				foreach (MethodInfo methodInfo in methods)
				{
					if (methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false).Length != 0)
					{
						methodInfo.Invoke(null, null);
					}
				}
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "FreddyKrueger";

		public const string PLUGIN_NAME = "FreddyKrueger";

		public const string PLUGIN_VERSION = "2.3.16";
	}
}
namespace FreddyKruegerLC.FreddyDirectPatches
{
	public class EndOfRoundFixes
	{
	}
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class FreddyDamagePatch
	{
		[HarmonyPatch(typeof(PlayerControllerB), "DamagePlayer")]
		[HarmonyPrefix]
		private static bool Prefix(PlayerControllerB __instance, int damageNumber, bool hasDamageSFX = true, bool callRPC = true, CauseOfDeath causeOfDeath = 0, int deathAnimation = 0, bool fallDamage = false, Vector3 force = default(Vector3))
		{
			UpdateFreddy(__instance.actualClientId, damageNumber);
			return true;
		}

		public static void UpdateFreddy(ulong playerWithClientId, int damageNumber)
		{
			if (Object.op_Implicit((Object)(object)Object.FindObjectOfType<FreddyAi>()))
			{
				Object.FindObjectOfType<FreddyAi>().sleepScript.UpdateLocalSleep(playerWithClientId, damageNumber);
			}
		}
	}
}
namespace FreddyKruegerLC.Configurations
{
	[Serializable]
	public class Config : SyncedInstance<Config>
	{
		public ConfigEntry<int> ENTER_SLEEP { get; private set; }

		public ConfigEntry<int> SLEEP_MAX { get; private set; }

		public ConfigEntry<float> DISTANCE_FOR_SLEEP { get; private set; }

		public ConfigEntry<bool> SHIP_MOMMY_TARGET { get; private set; }

		public ConfigEntry<bool> SOLO_GAMEPLAY { get; private set; }

		public ConfigEntry<bool> RANDOM_SLEEP { get; private set; }

		public ConfigEntry<int> TIME_BEFORE_LEAVING_SLEEP { get; private set; }

		public ConfigEntry<int> BASE_SPAWN_CHANCES { get; private set; }

		public ConfigEntry<bool> USE_MOON_CHANCES { get; private set; }

		public ConfigEntry<int> EXPERIMENTATION_SPAWNRATE { get; private set; }

		public ConfigEntry<int> ASSURANCE_SPAWNRATE { get; private set; }

		public ConfigEntry<int> VOW_SPAWNRATE { get; private set; }

		public ConfigEntry<int> OFFENSE_SPAWNRATE { get; private set; }

		public ConfigEntry<int> MARCH_SPAWNRATE { get; private set; }

		public ConfigEntry<int> REND_SPAWNRATE { get; private set; }

		public ConfigEntry<int> DINE_SPAWNRATE { get; private set; }

		public ConfigEntry<int> TITAN_SPAWNRATE { get; private set; }

		public ConfigEntry<float> SOUND_CHILD_VOLUME { get; private set; }

		public ConfigEntry<int> STATE_INCREASE { get; private set; }

		public ConfigEntry<float> SPEED_MODIFIER { get; private set; }

		public ConfigEntry<float> SPEED_MODIFIER_LAST_STAGE { get; private set; }

		public ConfigEntry<float> TIME_SPAWN { get; private set; }

		public ConfigEntry<float> TIME_DESPAWN { get; private set; }

		public ConfigEntry<bool> SLEEP_DEBUG { get; private set; }

		public ConfigEntry<bool> PARTICLE_SHOW { get; private set; }

		public Config(ConfigFile cfg)
		{
			InitInstance(this);
			ENTER_SLEEP = cfg.Bind<int>("Sleep Parameter", "Enter Sleep Value", 260, "You get 1 of value every seconds you are alone and when you reach the decided number, freddy can officially target you (Minimum 50)");
			SLEEP_MAX = cfg.Bind<int>("Sleep Parameter", "Sleep Meter Before Rampage", 380, "This is the amount of sleep before Freddy wants you dead and starts running (Minimum 80 higher than 'Enter Sleep Value', suggested at very least 100 higher)");
			DISTANCE_FOR_SLEEP = cfg.Bind<float>("Sleep Parameter", "Distance between player before they are considered to be alone", 15f, "If the distance is greater than the designated number, your sleep meter will increase, if it is lower, your sleep meter will decrease");
			SHIP_MOMMY_TARGET = cfg.Bind<bool>("Target Choosing", "Does sleep meter goes up for people in the ship", true, "If true, it will go up for people in the ship, if false, sleep meter will stay the same if inside the ship");
			SOLO_GAMEPLAY = cfg.Bind<bool>("Solo Run Settings", "Activate Solo Run", false, "Activating solo run makes the settings of 'Solo Run Settings' activated. Leaving it to false WILL block all the settings of this section");
			RANDOM_SLEEP = cfg.Bind<bool>("Solo Run Settings", "Make Freddy sleep unpredictable", true, "ACTIVATE SOLO RUN MUST BE ON : This settings make Enter Sleep Value and Sleep Meter before Rampage useless and instead chooses and random moment for you to enter the dream world");
			TIME_BEFORE_LEAVING_SLEEP = cfg.Bind<int>("Solo Run Settings", "Time Before Leaving Sleep", 60, "ACTIVATE SOLO RUN MUST BE ON : This setting decides how much time will it take for you to automatically leave the dream world after entering it");
			BASE_SPAWN_CHANCES = cfg.Bind<int>("Spawn Behaviour", "Default Spawn Chance in Percentage", 35, "Option must be between 0 and 100 : This config changes the default spawn chances that Freddy manifest when you lend on a moon. This value is override on basic moons. This will be the value used on modded moons");
			USE_MOON_CHANCES = cfg.Bind<bool>("Spawn Behaviour", "Activate the per moon spawn rate", true, "If set to true, the spawn rate will be different based on the moon difficulty. This will not work for non basic moons and will instead use the Default Spawn Chances in percentage");
			EXPERIMENTATION_SPAWNRATE = cfg.Bind<int>("Moon Spawn rate", "Spawn rate for Experimentation", 14, "This option is only activated if it Activate the per moon spawn rate is true. This value is in percentage %");
			ASSURANCE_SPAWNRATE = cfg.Bind<int>("Moon Spawn rate", "Spawn rate for Assurance", 15, "This option is only activated if it Activate the per moon spawn rate is true. This value is in percentage %");
			VOW_SPAWNRATE = cfg.Bind<int>("Moon Spawn rate", "Spawn rate for Assurance", 20, "This option is only activated if it Activate the per moon spawn rate is true. This value is in percentage %");
			OFFENSE_SPAWNRATE = cfg.Bind<int>("Moon Spawn rate", "Spawn rate for Offense", 10, "This option is only activated if it Activate the per moon spawn rate is true. This value is in percentage %");
			MARCH_SPAWNRATE = cfg.Bind<int>("Moon Spawn rate", "Spawn rate for March", 20, "This option is only activated if it Activate the per moon spawn rate is true. This value is in percentage %");
			REND_SPAWNRATE = cfg.Bind<int>("Moon Spawn rate", "Spawn rate for Rend", 30, "This option is only activated if it Activate the per moon spawn rate is true. This value is in percentage %");
			DINE_SPAWNRATE = cfg.Bind<int>("Moon Spawn rate", "Spawn rate for Dine", 40, "This option is only activated if it Activate the per moon spawn rate is true. This value is in percentage %");
			TITAN_SPAWNRATE = cfg.Bind<int>("Moon Spawn rate", "Spawn rate for Titan", 25, "This option is only activated if it Activate the per moon spawn rate is true. This value is in percentage %");
			SOUND_CHILD_VOLUME = cfg.Bind<float>("Sound Parameter", "Enter the Volume of the Child Singing", 0.5f, "This value must be from 0.0f to 1.0f . Anything above or under will be treated as 0.0f or 1.0f. THIS DISABLES ALL MUSICS. A person told me they were afraid of copyrights");
			STATE_INCREASE = cfg.Bind<int>("Difficulty modifier", "Behaviour other than walking chances", 30, "This value must be above 0 up to infinite (Tho it will make Freddy always run). This upgrades the chances of freddy spawning with a special behaviour that is not walking");
			SPEED_MODIFIER = cfg.Bind<float>("Difficulty modifier", "This number directly affects the speed of the Freddy", 4f, "This value must not be lower than 0 and can be a decimal number. It is suggested to not put it lower than it already is");
			SPEED_MODIFIER_LAST_STAGE = cfg.Bind<float>("Difficulty modifier", "Added speed last stage", 0.1f, "Every 0.2 seconds, this number will be added to Freddy's speed when he is running with his claw. a number like 1.0 is already a lot... Believe me... It can be a decimal number");
			SLEEP_DEBUG = cfg.Bind<bool>("Developer", "Show Sleep of player 0 in array", false, "This is for me and my development process, I can't suggest putting this on");
		}

		public static void RequestSync()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			if (!SyncedInstance<Config>.IsClient)
			{
				return;
			}
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(SyncedInstance<Config>.IntSize, (Allocator)2, -1);
			try
			{
				SyncedInstance<Config>.MessageManager.SendNamedMessage("Xilef992FreddyKrueger_OnRequestConfigSync", 0uL, val, (NetworkDelivery)3);
			}
			finally
			{
				((IDisposable)(FastBufferWriter)(ref val)).Dispose();
			}
		}

		public static void OnRequestSync(ulong clientId, FastBufferReader _)
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			if (!SyncedInstance<Config>.IsHost)
			{
				return;
			}
			Plugin.Logger.LogInfo((object)$"Config sync request received from client: {clientId}");
			byte[] array = SyncedInstance<Config>.SerializeToBytes(SyncedInstance<Config>.Instance);
			int num = array.Length;
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(num + SyncedInstance<Config>.IntSize, (Allocator)2, -1);
			try
			{
				((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref num, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteBytesSafe(array, -1, 0);
				SyncedInstance<Config>.MessageManager.SendNamedMessage("Xilef992FreddyKrueger_OnReceiveConfigSync", clientId, val, (NetworkDelivery)3);
			}
			catch (Exception arg)
			{
				Plugin.Logger.LogInfo((object)$"Error occurred syncing config with client: {clientId}\n{arg}");
			}
			finally
			{
				((IDisposable)(FastBufferWriter)(ref val)).Dispose();
			}
		}

		public static void OnReceiveSync(ulong _, FastBufferReader reader)
		{
			//IL_0024: 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)
			if (!((FastBufferReader)(ref reader)).TryBeginRead(SyncedInstance<Config>.IntSize))
			{
				Plugin.Logger.LogError((object)"Config sync error: Could not begin reading buffer.");
				return;
			}
			int num = default(int);
			((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref num, default(ForPrimitives));
			if (!((FastBufferReader)(ref reader)).TryBeginRead(num))
			{
				Plugin.Logger.LogError((object)"Config sync error: Host could not sync.");
				return;
			}
			byte[] data = new byte[num];
			((FastBufferReader)(ref reader)).ReadBytesSafe(ref data, num, 0);
			SyncedInstance<Config>.SyncInstance(data);
			Plugin.Logger.LogInfo((object)"Successfully synced config with host.");
		}
	}
	public static class ConfigurationsPatch
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static HandleNamedMessageDelegate <0>__OnRequestSync;

			public static HandleNamedMessageDelegate <1>__OnReceiveSync;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(PlayerControllerB), "ConnectClientToPlayerObject")]
		public static void InitializeLocalPlayer()
		{
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Expected O, but got Unknown
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			if (((NetworkBehaviour)RoundManager.Instance).IsHost)
			{
				CustomMessagingManager messageManager = SyncedInstance<Config>.MessageManager;
				object obj = <>O.<0>__OnRequestSync;
				if (obj == null)
				{
					HandleNamedMessageDelegate val = Config.OnRequestSync;
					<>O.<0>__OnRequestSync = val;
					obj = (object)val;
				}
				messageManager.RegisterNamedMessageHandler("FreddyKrueger_OnRequestConfigSync", (HandleNamedMessageDelegate)obj);
				SyncedInstance<Config>.Synced = true;
				return;
			}
			SyncedInstance<Config>.Synced = false;
			CustomMessagingManager messageManager2 = SyncedInstance<Config>.MessageManager;
			object obj2 = <>O.<1>__OnReceiveSync;
			if (obj2 == null)
			{
				HandleNamedMessageDelegate val2 = Config.OnReceiveSync;
				<>O.<1>__OnReceiveSync = val2;
				obj2 = (object)val2;
			}
			messageManager2.RegisterNamedMessageHandler("FreddyKrueger_OnReceiveConfigSync", (HandleNamedMessageDelegate)obj2);
			Config.RequestSync();
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(GameNetworkManager), "StartDisconnect")]
		public static void PlayerLeave()
		{
			SyncedInstance<Config>.RevertSync();
		}
	}
	public class SyncedInstance<T>
	{
		[NonSerialized]
		protected static int IntSize = 4;

		internal static CustomMessagingManager MessageManager => NetworkManager.Singleton.CustomMessagingManager;

		internal static bool IsClient => NetworkManager.Singleton.IsClient;

		internal static bool IsHost => NetworkManager.Singleton.IsHost;

		public static T Default { get; private set; }

		public static T Instance { get; private set; }

		public static bool Synced { get; internal set; }

		protected void InitInstance(T instance)
		{
			Default = instance;
			Instance = instance;
			IntSize = 4;
		}

		internal static void SyncInstance(byte[] data)
		{
			Instance = DeserializeFromBytes(data);
			Synced = true;
		}

		internal static void RevertSync()
		{
			Instance = Default;
			Synced = false;
		}

		public static byte[] SerializeToBytes(T val)
		{
			BinaryFormatter binaryFormatter = new BinaryFormatter();
			using MemoryStream memoryStream = new MemoryStream();
			try
			{
				binaryFormatter.Serialize(memoryStream, val);
				return memoryStream.ToArray();
			}
			catch (Exception arg)
			{
				Debug.Log((object)$"Error serializing instance: {arg}");
				return null;
			}
		}

		public static T DeserializeFromBytes(byte[] data)
		{
			BinaryFormatter binaryFormatter = new BinaryFormatter();
			using MemoryStream serializationStream = new MemoryStream(data);
			try
			{
				return (T)binaryFormatter.Deserialize(serializationStream);
			}
			catch (Exception arg)
			{
				Debug.Log((object)$"Error deserializing instance: {arg}");
				return default(T);
			}
		}
	}
}
namespace FreddyKrueger.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}