Decompiled source of NightmareFoxy v1.0.11

NightmareFoxy.dll

Decompiled 4 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
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 GameNetcodeStuff;
using HarmonyLib;
using LethalBestiary.Modules;
using Microsoft.CodeAnalysis;
using NightmareFoxyLC.Configurations;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("NightmareFoxy")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("This is nightmare Foxy from the FNAF 4")]
[assembly: AssemblyFileVersion("1.1.10.0")]
[assembly: AssemblyInformationalVersion("1.1.10+73481b442238454844676562981312b18e5857c8")]
[assembly: AssemblyProduct("NightmareFoxy")]
[assembly: AssemblyTitle("NightmareFoxy")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.10.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ExampleEnemy
{
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "NightmareFoxy";

		public const string PLUGIN_NAME = "NightmareFoxy";

		public const string PLUGIN_VERSION = "1.1.10";
	}
}
namespace NightmareFoxyLC
{
	public class FoxyAi : EnemyAI
	{
		private enum State
		{
			Down,
			Standing,
			ChargePose,
			Running,
			Seen,
			Jumping
		}

		public AudioSource howlingAudioSRC;

		public ParticleSystem footSpeed;

		public Light eyesLight;

		public AudioClip portalSFX;

		public AudioClip deactivate;

		public AudioClip activate;

		public BoxCollider foxyCollider;

		[Header("Engine Stuff")]
		public AudioSource engine;

		public AudioClip idle1;

		public AudioClip idle2;

		[Header("Whenseen")]
		public AudioClip fallOnKnee;

		public AudioClip fallOnBody;

		public AudioClip fallOnKneeVariant;

		public AudioClip destroyDoor;

		public AudioClip train;

		[Header("Footstep")]
		public AudioSource footStepAudio;

		public AudioClip footStep1;

		public AudioClip footStep2;

		public AudioClip footStep3;

		public AudioClip footStep4;

		[Header("Kill Animation")]
		public AudioClip[] killAnimationSound;

		public AudioClip[] howlAudioSounds;

		public Transform killZone;

		public Material foxEyes;

		private int generatedNumber;

		private bool justSwitchedBehaviour;

		private float timer;

		private bool startedHowling = false;

		private float duration = 3f;

		private float currentDuration = 0f;

		private float oldspeed;

		private PlayerControllerB localPlayer;

		public List<DoorLock> doorLocked;

		private bool stopLooking;

		public override void Start()
		{
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			((EnemyAI)this).Start();
			duration = SyncedInstance<Config>.Instance.TIME_TO_SLOW_DOWN.Value;
			foxEyes.SetFloat("_Strenght", 0f);
			base.agent.angularSpeed = 10000f;
			justSwitchedBehaviour = false;
			timer = 0f;
			foxyCollider.size = new Vector3(4.531483f, 21.24057f, 5.783448f);
			base.agent.updateRotation = true;
			localPlayer = RoundManager.Instance.playersManager.localPlayerController;
			howlingAudioSRC.volume = SyncedInstance<Config>.Instance.HOWLING_STRENGHT.Value;
		}

		public override void Update()
		{
			((EnemyAI)this).Update();
			if (justSwitchedBehaviour)
			{
				timer += Time.deltaTime;
				if (timer >= 5f)
				{
					timer = 0f;
					justSwitchedBehaviour = false;
				}
			}
		}

		public override void DoAIInterval()
		{
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: 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_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_0307: Unknown result type (might be due to invalid IL or missing references)
			//IL_0317: Unknown result type (might be due to invalid IL or missing references)
			//IL_0326: Unknown result type (might be due to invalid IL or missing references)
			//IL_033d: Unknown result type (might be due to invalid IL or missing references)
			//IL_034d: Unknown result type (might be due to invalid IL or missing references)
			//IL_035c: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_05de: Unknown result type (might be due to invalid IL or missing references)
			//IL_07b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_07bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_07bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_07c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_068b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0408: Unknown result type (might be due to invalid IL or missing references)
			//IL_06bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_047d: Unknown result type (might be due to invalid IL or missing references)
			((EnemyAI)this).DoAIInterval();
			if (((NetworkBehaviour)this).IsHost)
			{
				if (!justSwitchedBehaviour)
				{
					generatedNumber = RandomNumberGenerator.GetInt32(1, SyncedInstance<Config>.Instance.CHANCE_NEXT_PHASE.Value);
				}
				else
				{
					generatedNumber = 100;
				}
			}
			switch (base.currentBehaviourStateIndex)
			{
			case 0:
				footSpeed.Stop();
				engine.Stop();
				base.movingTowardsTargetPlayer = false;
				base.agent.isStopped = true;
				base.agent.ResetPath();
				base.targetPlayer = null;
				base.creatureAnimator.speed = 1f;
				footSpeed.Stop();
				if (((NetworkBehaviour)this).IsHost && generatedNumber <= 1)
				{
					((EnemyAI)this).SwitchToBehaviourClientRpc(1);
					engine.PlayOneShot(portalSFX);
				}
				break;
			case 1:
				footSpeed.Stop();
				foxyCollider.size = new Vector3(foxyCollider.size.x, foxyCollider.size.y, 6.619311f);
				foxyCollider.center = new Vector3(foxyCollider.center.x, foxyCollider.center.y, 0.8878318f);
				base.creatureAnimator.speed = 1f;
				base.agent.isStopped = true;
				base.agent.ResetPath();
				if (generatedNumber <= 1)
				{
					((EnemyAI)this).SwitchToBehaviourClientRpc(2);
					((MonoBehaviour)this).StartCoroutine(EyesManager(opening: true));
				}
				break;
			case 2:
				if (!engine.isPlaying)
				{
					engine.clip = idle1;
					engine.Play(3uL);
					engine.loop = true;
				}
				base.creatureAnimator.speed = 1f;
				base.agent.isStopped = true;
				base.agent.ResetPath();
				if (generatedNumber <= 2 && !startedHowling)
				{
					engine.clip = idle2;
					base.creatureAnimator.speed = 0f;
					base.agent.speed = 0f;
					engine.Play();
					startedHowling = true;
					if (((NetworkBehaviour)this).IsHost)
					{
						((MonoBehaviour)this).StartCoroutine(CloseHunt(RandomNumberGenerator.GetInt32(SyncedInstance<Config>.Instance.MIN_AMOUNT_HOWL.Value, SyncedInstance<Config>.Instance.MAX_AMOUNT_HOWL.Value)));
					}
				}
				break;
			case 3:
				foxyCollider.size = new Vector3(foxyCollider.size.x, foxyCollider.size.y, 30f);
				foxyCollider.center = new Vector3(foxyCollider.center.x, foxyCollider.center.y, 12.56404f);
				if ((Object)(object)base.targetPlayer == (Object)null || base.targetPlayer.isPlayerDead || !base.targetPlayer.isInsideFactory)
				{
					if (((NetworkBehaviour)this).IsHost)
					{
						FetchTarget();
					}
					if ((Object)(object)base.targetPlayer == (Object)null)
					{
						((EnemyAI)this).SwitchToBehaviourClientRpc(4);
						((MonoBehaviour)this).StartCoroutine(EyesManager(opening: false));
						break;
					}
				}
				if (!base.targetPlayer.isInsideFactory)
				{
					((EnemyAI)this).SwitchToBehaviourClientRpc(0);
				}
				if (base.targetPlayer.HasLineOfSightToPosition(((Component)this).transform.position, 45f, 60, -1f) || !base.targetPlayer.isInsideFactory || !base.targetPlayer.isPlayerControlled || base.targetPlayer.isPlayerDead)
				{
					((EnemyAI)this).SwitchToBehaviourClientRpc(4);
					((MonoBehaviour)this).StartCoroutine(EyesManager(opening: false));
					break;
				}
				base.movingTowardsTargetPlayer = true;
				((EnemyAI)this).SetDestinationToPosition(((Component)base.targetPlayer).transform.position, false);
				if (base.agent.speed <= SyncedInstance<Config>.Instance.MAX_SPEED.Value)
				{
					NavMeshAgent agent = base.agent;
					agent.speed += 0.1f * SyncedInstance<Config>.Instance.SPEED_MULTIPLIER.Value;
					Animator creatureAnimator = base.creatureAnimator;
					creatureAnimator.speed += 0.02f * SyncedInstance<Config>.Instance.SPEED_MULTIPLIER.Value;
				}
				else
				{
					base.creatureVoice.PlayOneShot(train);
				}
				BreakDoorServerRpc();
				if (!footSpeed.isPlaying)
				{
					footSpeed.Play();
				}
				currentDuration = 0f;
				break;
			case 4:
			{
				Vector3 velocity;
				if (currentDuration < duration)
				{
					float num = currentDuration / duration;
					float speed = Mathf.Lerp(base.agent.speed, 0f, num);
					float speed2 = Mathf.Lerp(base.creatureAnimator.speed, 0f, num);
					base.agent.speed = speed;
					base.creatureAnimator.speed = speed2;
					Transform transform = ((Component)this).transform;
					velocity = base.agent.velocity;
					transform.rotation = Quaternion.LookRotation(((Vector3)(ref velocity)).normalized);
					if (CheckIfFlashedAt())
					{
						currentDuration += Time.deltaTime * SyncedInstance<Config>.Instance.FLASHLIGHT_SLOW_DOWN_MODIFIER.Value;
						if ((double)base.agent.speed >= 0.3)
						{
							NavMeshAgent agent2 = base.agent;
							agent2.speed -= 0.1f * SyncedInstance<Config>.Instance.FLASHLIGHT_SLOW_DOWN_MODIFIER.Value;
						}
					}
					else if ((Object)(object)base.targetPlayer != (Object)null)
					{
						((EnemyAI)this).SetDestinationToPosition(((Component)base.targetPlayer).transform.position, false);
						if (SyncedInstance<Config>.Instance.ACTIVATE_CONSTANT_LOOK.Value)
						{
							if (!base.targetPlayer.HasLineOfSightToPosition(((Component)this).transform.position, 45f, 60, -1f) && base.targetPlayer.isInsideFactory && base.targetPlayer.isPlayerControlled && !base.targetPlayer.isPlayerDead)
							{
								SwitchToBehaviourWithoutEnterStateClientRpc(3);
								((MonoBehaviour)this).StartCoroutine(EyesManager(opening: true));
								break;
							}
							currentDuration += Time.deltaTime;
						}
						else
						{
							currentDuration += Time.deltaTime;
						}
					}
					else
					{
						currentDuration += Time.deltaTime;
					}
				}
				else
				{
					base.agent.speed = 0f;
					base.creatureAnimator.speed = 0f;
				}
				if (base.agent.speed <= 0.1f)
				{
					Transform transform2 = ((Component)this).transform;
					velocity = base.agent.velocity;
					transform2.rotation = Quaternion.LookRotation(((Vector3)(ref velocity)).normalized);
					base.agent.ResetPath();
					base.agent.speed = 0f;
					base.creatureAnimator.speed = 0.8f;
					DoAnimationClientRpc("GotSeen");
					((MonoBehaviour)this).StartCoroutine(EyesManager(opening: false));
					((EnemyAI)this).SwitchToBehaviourClientRpc(5);
					footSpeed.Stop();
					if (((NetworkBehaviour)this).IsHost)
					{
						((MonoBehaviour)this).StartCoroutine(WaitAndGoBackUp(RandomNumberGenerator.GetInt32(10, 30)));
					}
				}
				break;
			}
			case 5:
				break;
			default:
				if (((NetworkBehaviour)this).IsHost)
				{
					((EnemyAI)this).SwitchToBehaviourClientRpc(1);
				}
				break;
			}
		}

		private IEnumerator CloseHunt(int howling)
		{
			int howlingStore = howling;
			yield return (object)new WaitForSeconds(4f);
			while (howlingStore > 0)
			{
				HowlClientRpc();
				yield return (object)new WaitForSeconds(3f);
				howlingStore--;
			}
			startedHowling = false;
			base.creatureAnimator.speed = 0f;
			base.agent.speed = 0f;
			((EnemyAI)this).SwitchToBehaviourClientRpc(3);
			UnlockAllDoorClientRpc();
		}

		private IEnumerator WaitAndGoBackUp(int x)
		{
			base.movingTowardsTargetPlayer = false;
			base.agent.isStopped = true;
			base.agent.ResetPath();
			base.agent.speed = 0f;
			yield return (object)new WaitForSeconds((float)x);
			DoAnimationClientRpc("FallDown");
			((EnemyAI)this).SwitchToBehaviourClientRpc(0);
		}

		private IEnumerator EyesManager(bool opening)
		{
			float objective = (opening ? 2f : 0f);
			float currentState = (opening ? 0f : 2f);
			if (opening)
			{
				engine.PlayOneShot(activate);
			}
			else
			{
				engine.PlayOneShot(deactivate);
			}
			bool fixing = true;
			float elapsedTime = 0f;
			while (fixing)
			{
				foxEyes.SetFloat("_Strenght", Mathf.Lerp(currentState, objective, elapsedTime / 10f));
				elapsedTime += Time.deltaTime;
				if (foxEyes.GetFloat("_Strenght") == objective)
				{
					break;
				}
			}
			yield break;
		}

		public override void OnCollideWithPlayer(Collider other)
		{
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_0249: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			PlayerControllerB val = ((EnemyAI)this).MeetsStandardPlayerCollisionConditions(other, false, false);
			if ((Object)(object)val == (Object)null || !val.isPlayerControlled)
			{
				return;
			}
			if ((Object)(object)val == (Object)(object)base.targetPlayer)
			{
				if (3 == base.currentBehaviourStateIndex)
				{
					Debug.Log((object)"Agent has reached the destination!");
					((EnemyAI)this).SwitchToBehaviourClientRpc(5);
					base.agent.speed = 0f;
					((MonoBehaviour)this).StartCoroutine(FoxyKills(base.targetPlayer));
				}
				if (4 == base.currentBehaviourStateIndex)
				{
					if (base.agent.speed >= SyncedInstance<Config>.Instance.MAX_SPEED.Value / (100f / SyncedInstance<Config>.Instance.SPEED_FOXY_KILLS.Value))
					{
						Debug.Log((object)("Agent has reached the destination. Current Speed = " + base.agent.speed));
						((EnemyAI)this).SwitchToBehaviourClientRpc(5);
						base.agent.speed = 0f;
						((MonoBehaviour)this).StartCoroutine(FoxyKills(base.targetPlayer));
					}
					else if (base.agent.speed >= SyncedInstance<Config>.Instance.MAX_SPEED.Value / (100f / SyncedInstance<Config>.Instance.SPEED_FOXY_DAMAGES.Value))
					{
						Debug.Log((object)("Agent has reached the destination. Current speed to low = " + base.agent.speed));
						base.targetPlayer.DamagePlayer(SyncedInstance<Config>.Instance.FOXY_DAMAGES.Value, true, true, (CauseOfDeath)0, 0, false, default(Vector3));
						base.agent.speed = 0f;
					}
				}
			}
			else if (3 == base.currentBehaviourStateIndex)
			{
				if (base.agent.speed > 5f)
				{
					val.DamagePlayer(2, true, true, (CauseOfDeath)0, 0, false, default(Vector3));
				}
			}
			else if (4 == base.currentBehaviourStateIndex && base.agent.speed > 2f)
			{
				val.DamagePlayer(1, true, true, (CauseOfDeath)0, 0, false, default(Vector3));
			}
		}

		public void FetchTarget()
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			//IL_0040: 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)
			List<string> list = new List<string>();
			PlayerControllerB[] allPlayerScripts = RoundManager.Instance.playersManager.allPlayerScripts;
			foreach (PlayerControllerB val in allPlayerScripts)
			{
				if (val.isInsideFactory)
				{
					NavMeshPath val2 = new NavMeshPath();
					if (NavMesh.CalculatePath(((Component)base.agent).transform.position, ((Component)val).transform.position, -1, val2))
					{
						list.Add(((Object)val).name);
					}
				}
			}
			if (list.Count > 0)
			{
				SetTargetPlayerClientRpc(list[RandomNumberGenerator.GetInt32(0, list.Count)]);
				base.agent.speed = 0f;
				base.creatureAnimator.speed = 0f;
			}
			else
			{
				base.targetPlayer = null;
				SetTargetPlayerClientRpc("NoneCode1234567890");
			}
		}

		public void FootStepHandler()
		{
			if (localPlayer.isInsideFactory)
			{
				switch (RandomNumberGenerator.GetInt32(0, 4))
				{
				case 0:
					footStepAudio.PlayOneShot(footStep1);
					break;
				case 1:
					footStepAudio.PlayOneShot(footStep2);
					break;
				case 2:
					footStepAudio.PlayOneShot(footStep3);
					break;
				case 3:
					footStepAudio.PlayOneShot(footStep4);
					break;
				}
			}
		}

		public void FallOnKnee()
		{
			if (RandomNumberGenerator.GetInt32(0, 101) != 0)
			{
				base.creatureVoice.PlayOneShot(fallOnKnee);
			}
			else
			{
				base.creatureVoice.PlayOneShot(fallOnKneeVariant);
			}
		}

		public void FallOnBody()
		{
			base.creatureVoice.PlayOneShot(fallOnBody);
		}

		private IEnumerator FoxyKills(PlayerControllerB player)
		{
			((EnemyAI)this).SwitchToBehaviourClientRpc(5);
			base.agent.speed = 0f;
			base.creatureAnimator.speed = 1f;
			base.movingTowardsTargetPlayer = false;
			base.agent.isStopped = true;
			base.agent.ResetPath();
			oldspeed = player.movementSpeed;
			player.movementSpeed = 0f;
			((MonoBehaviour)this).StartCoroutine(RotatePlayerToMe(player));
			((Component)this).transform.LookAt(((Component)player).transform.position, Vector3.up);
			DoAnimationClientRpc("Kill");
			yield return (object)new WaitForSeconds(5f);
			player.movementSpeed = oldspeed;
			engine.Stop();
			footSpeed.Stop();
		}

		private IEnumerator RotatePlayerToMe(PlayerControllerB PCB)
		{
			stopLooking = false;
			((MonoBehaviour)this).StartCoroutine(StopAfterThreeSeconds(PCB));
			if (Object.op_Implicit((Object)(object)PCB))
			{
				Vector3 Position = ((Component)this).transform.position - ((Component)PCB).gameObject.transform.position;
				while (PCB.health != 0 && !PCB.isPlayerDead && !stopLooking)
				{
					PlayerSmoothLookAt(Position, PCB);
					yield return null;
				}
			}
		}

		private IEnumerator StopAfterThreeSeconds(PlayerControllerB PCB)
		{
			yield return (object)new WaitForSeconds(3f);
			stopLooking = true;
			yield return (object)new WaitForSeconds(1f);
			stopLooking = false;
		}

		private void PlayerSmoothLookAt(Vector3 newDirection, PlayerControllerB PCB)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			((Component)PCB).gameObject.transform.rotation = Quaternion.Lerp(((Component)PCB).gameObject.transform.rotation, Quaternion.LookRotation(newDirection), Time.deltaTime * 5f);
		}

		[ClientRpc]
		public void SwingAttackHitClientRpc()
		{
			//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_002a: Unknown result type (might be due to invalid IL or missing references)
			if (base.currentBehaviourStateIndex != 3)
			{
				return;
			}
			int num = 8;
			Collider[] array = Physics.OverlapBox(killZone.position, killZone.localScale, Quaternion.identity, num);
			if (array.Length == 0)
			{
				return;
			}
			Collider[] array2 = array;
			foreach (Collider val in array2)
			{
				Debug.Log((object)"Player In punishable zone!");
				PlayerControllerB val2 = ((EnemyAI)this).MeetsStandardPlayerCollisionConditions(val, false, false);
				if ((Object)(object)val2 != (Object)null && (Object)(object)val2 == (Object)(object)base.targetPlayer)
				{
					base.agent.speed = 0f;
					base.agent.ResetPath();
					base.creatureAnimator.speed = 1.5f;
					((EnemyAI)this).SwitchToBehaviourClientRpc(5);
					((MonoBehaviour)this).StartCoroutine(FoxyKills(base.targetPlayer));
				}
			}
		}

		[ClientRpc]
		public void KillTargetPlayerClientRpc()
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			((EnemyAI)this).SwitchToBehaviourClientRpc(1);
			base.targetPlayer.KillPlayer(Vector3.back, true, (CauseOfDeath)1, 2, default(Vector3));
			base.targetPlayer = null;
		}

		[ClientRpc]
		public void DoAnimationClientRpc(string x)
		{
			base.creatureAnimator.SetTrigger(x);
		}

		public void PlayKillSound(int x)
		{
			base.creatureVoice.PlayOneShot(killAnimationSound[x]);
		}

		[ClientRpc]
		public void SetTargetPlayerClientRpc(string name)
		{
			if (name == "NoneCode1234567890")
			{
				base.targetPlayer = null;
			}
			PlayerControllerB[] allPlayerScripts = RoundManager.Instance.playersManager.allPlayerScripts;
			foreach (PlayerControllerB val in allPlayerScripts)
			{
				if (((Object)val).name == name)
				{
					base.targetPlayer = val;
				}
			}
		}

		[ClientRpc]
		public void HowlClientRpc()
		{
			int num = 200;
			howlingAudioSRC.Play();
		}

		[ClientRpc]
		public void UnlockAllDoorClientRpc()
		{
			DoorLock[] array = Object.FindObjectsOfType(typeof(DoorLock)) as DoorLock[];
			foreach (DoorLock val in array)
			{
				if (val.isLocked)
				{
					doorLocked.Add(val);
					val.UnlockDoorClientRpc();
					val.isLocked = false;
				}
			}
		}

		[ServerRpc]
		public void BreakDoorServerRpc()
		{
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: 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_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: 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_00b5: 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)
			DoorLock[] array = Object.FindObjectsOfType(typeof(DoorLock)) as DoorLock[];
			foreach (DoorLock val in array)
			{
				try
				{
					GameObject gameObject = ((Component)((Component)((Component)((Component)val).transform.parent).transform.parent).transform.parent).gameObject;
					if (!Object.op_Implicit((Object)(object)gameObject.GetComponent<Rigidbody>()) && Vector3.Distance(((Component)this).transform.position, gameObject.transform.position) <= 4f)
					{
						NetworkObjectReference netObjRef = NetworkObjectReference.op_Implicit(gameObject);
						Vector3 val2 = ((Component)base.targetPlayer).transform.position - ((Component)this).transform.position;
						BashDoorClientRpc(netObjRef, ((Vector3)(ref val2)).normalized * 20f);
					}
				}
				catch (NullReferenceException)
				{
					try
					{
						val.OpenDoorAsEnemyClientRpc();
					}
					catch (Exception ex)
					{
						Debug.Log((object)("The doors are not formatted the right way and as such foxy may seems really stupid hitting doors " + ex));
					}
				}
			}
		}

		[ClientRpc]
		public void BashDoorClientRpc(NetworkObjectReference netObjRef, Vector3 Position)
		{
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			NetworkObject val = default(NetworkObject);
			if (((NetworkObjectReference)(ref netObjRef)).TryGet(ref val, (NetworkManager)null))
			{
				GameObject gameObject = ((Component)val).gameObject;
				Rigidbody val2 = gameObject.AddComponent<Rigidbody>();
				AudioSource val3 = gameObject.AddComponent<AudioSource>();
				val3.spatialBlend = 1f;
				val3.maxDistance = 60f;
				val3.rolloffMode = (AudioRolloffMode)1;
				val3.volume = 1f;
				((MonoBehaviour)this).StartCoroutine(TurnOffC(val2, 0.12f));
				val2.AddForce(Position, (ForceMode)1);
				val3.PlayOneShot(destroyDoor);
			}
		}

		private bool CheckIfFlashedAt()
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: 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)
			PlayerControllerB[] allPlayerScripts = RoundManager.Instance.playersManager.allPlayerScripts;
			foreach (PlayerControllerB val in allPlayerScripts)
			{
				if (!val.HasLineOfSightToPosition(((Component)this).transform.position, 45f, 60, -1f))
				{
					continue;
				}
				GrabbableObject[] itemSlots = val.ItemSlots;
				foreach (GrabbableObject val2 in itemSlots)
				{
					if ((Object)(object)val2 != (Object)null && (Object)(object)((Component)val2).gameObject.GetComponent<FlashlightItem>() != (Object)null && ((GrabbableObject)((Component)val2).gameObject.GetComponent<FlashlightItem>()).isBeingUsed && Vector3.Distance(((Component)val).transform.position, ((Component)this).transform.position) < 6f)
					{
						Debug.Log((object)"FlashedAt");
						return true;
					}
				}
			}
			return false;
		}

		private IEnumerator TurnOffC(Rigidbody rigidbody, float time)
		{
			rigidbody.detectCollisions = false;
			yield return (object)new WaitForSeconds(time);
			rigidbody.detectCollisions = true;
			Object.Destroy((Object)(object)((Component)rigidbody).gameObject, 5f);
		}

		[ClientRpc]
		public void SwitchToBehaviourWithoutEnterStateClientRpc(int x)
		{
			base.previousBehaviourStateIndex = base.currentBehaviourStateIndex;
			base.currentBehaviourStateIndex = x;
			base.currentBehaviourState = base.enemyBehaviourStates[x];
		}
	}
	[BepInPlugin("Xilef992.NightmareFoxy", "NightmareFoxy", "1.1.5")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string ModGUID = "Xilef992.NightmareFoxy";

		internal static ManualLogSource Logger;

		public static AssetBundle ModAssets;

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

		public static Config FoxyConfig { get; internal set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Debug.Log((object)"LOADING NIGHTMARE FOXY : Xilef992.NightmareFoxy NightmareFoxy");
			FoxyConfig = new Config(((BaseUnityPlugin)this).Config);
			NetcodePatcher();
			InitializeNetworkBehaviours();
			string path = "foxymodasset";
			ModAssets = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), path));
			if ((Object)(object)ModAssets == (Object)null)
			{
				Logger.LogError((object)"Failed to load custom assets.");
				return;
			}
			EnemyType val = ModAssets.LoadAsset<EnemyType>("Foxy");
			TerminalNode val2 = ModAssets.LoadAsset<TerminalNode>("FoxyTN");
			TerminalKeyword val3 = ModAssets.LoadAsset<TerminalKeyword>("FoxyTK");
			NetworkPrefabs.RegisterNetworkPrefab(val.enemyPrefab);
			Enemies.RegisterEnemy(val, FoxyConfig.RARITY.Value, (LevelTypes)(-1), (SpawnType)0, val2, val3);
			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              ░░▒▒▒▒▓▓▓▓▓▓▓▒▒▒▒░░░░                 ");
			Logger.LogInfo((object)"Plugin NightmareFoxy is loaded!");
			harmony.PatchAll(typeof(ConfigurationsPatch));
		}

		private static void NetcodePatcher()
		{
			Type[] types = Assembly.GetExecutingAssembly().GetTypes();
			foreach (Type type in types)
			{
				MethodInfo[] methods = type.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);
					}
				}
			}
		}

		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);
					}
				}
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "NightmareFoxy";

		public const string PLUGIN_NAME = "NightmareFoxy";

		public const string PLUGIN_VERSION = "1.1.5";
	}
}
namespace NightmareFoxyLC.Configurations
{
	[Serializable]
	public class Config : SyncedInstance<Config>
	{
		public ConfigEntry<float> MAX_SPEED { get; private set; }

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

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

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

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

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

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

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

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

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

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

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

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

		public Config(ConfigFile cfg)
		{
			InitInstance(this);
			MAX_SPEED = cfg.Bind<float>("Difficulty", "Maximum speed", 10f, "This is the maximum speed foxy can go at! Please note that to high might actually slow him down in the end for the game won't handle his speed properly, 20 is REALLY fast");
			RARITY = cfg.Bind<int>("Spawn", "His chance rarity", 20, "Refer to other guids for better idea on how that works, I am sadly not qualified enough to explain it well");
			CHANCE_NEXT_PHASE = cfg.Bind<int>("Difficulty", "His chance of going to the next phase", 125, "Every 0.2 seconds, foxy will generate a random number from 0-this number. If this number is 1, he will go to the next phase. There are four inactive state and 1 state where he chases you");
			SPEED_MULTIPLIER = cfg.Bind<float>("Difficulty", "Speed multiplier", 1.5f, "Every 0.2 seconds, FOxy will add 0.01 to his speed which leads to him being faster and faster. This number multiplies this 0.01 directly to whatever number you want!");
			TIME_TO_SLOW_DOWN = cfg.Bind<float>("Difficulty", "Slow down speed", 3f, "Time it takes in seconds for foxy to loose all his speed in seconds");
			MIN_AMOUNT_HOWL = cfg.Bind<int>("Audio", "Minimum amount of Howl", 4, "This is for the howls before he starts chasing you");
			MAX_AMOUNT_HOWL = cfg.Bind<int>("Audio", "Maximum amount of Howl", 7, "This is for the howls before he starts chasing you");
			SPEED_FOXY_KILLS = cfg.Bind<float>("Kill Behaviour", "Seen Amount of speed needed to kill", 50f, "This is for the howls before he starts chasing you. DON'T ENTER 0, ENTER 1 INSTEAD. This is a percentage relative to Foxy's Max speed");
			SPEED_FOXY_DAMAGES = cfg.Bind<float>("Kill Behaviour", "Seen Amount of speed needed to deal damage", 25f, "This is for the howls before he starts chasing you. DON'T ENTER 0, ENTER 1 instead. This is a percentage relative to Foxy's Max speed");
			FOXY_DAMAGES = cfg.Bind<int>("Kill Behaviour", "Foxy Damage", 40, "Amount of damage Foxy does to you when he doesn't have the speed to kill you");
			HOWLING_STRENGHT = cfg.Bind<float>("Audio", "How loud are the screaming before he runs!", 7f, "A value usually betweeen 0 and 1 where 0 is no volume and 1 is max volume. It is possible to go over 1, but it will be really loud");
			FLASHLIGHT_SLOW_DOWN_MODIFIER = cfg.Bind<float>("Difficulty", "Sleep deceleration when Foxy is flshed At", 3f, "Affects how fast Foxy slows down when a flashlight is pointed at him. The chosen value is direcly multiplied with his deceleration");
			ACTIVATE_CONSTANT_LOOK = cfg.Bind<bool>("Difficulty", "Do you have to constantly look at foxy for him to slow down?", false, "If this value is true, foxy will re-accelerate when not looked at even if you took a glimpse of him earlier. Putting it to false, the second foxy is looked at, he will start decelerating even if you stop looking at him");
		}

		public static void RequestSync()
		{
			//IL_0029: 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("Xilef992NightmareFoxy_OnRequestConfigSync", 0uL, val, (NetworkDelivery)3);
			}
			finally
			{
				((IDisposable)(FastBufferWriter)(ref val)).Dispose();
			}
		}

		public static void OnRequestSync(ulong clientId, FastBufferReader _)
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: 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("Xilef992NightmareFoxys_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_002d: 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)
			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_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Expected O, but got Unknown
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: 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("FoxyNightmare_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("FoxyNightmare_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);
			}
		}
	}
}