Decompiled source of CreepoFear v1.1.1

CreepoFear.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using System.Threading;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Audio;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("CreepoFear")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("CreepoFear")]
[assembly: AssemblyTitle("CreepoFear")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 CreepoFear
{
	internal static class Dread
	{
		private class Body
		{
			internal bool hasShape;

			internal float checkedAt = -10f;
		}

		internal static bool Active;

		internal static float Threat;

		internal static float Tension;

		internal static float Depth;

		internal static Camera Cam;

		internal static Vector3 Eye;

		internal static readonly List<Vector3> Seen = new List<Vector3>();

		internal static bool BeatNow;

		internal static float BeatStrength;

		internal static bool AfterNow;

		internal static bool Outdoors;

		internal static bool Alone;

		internal static bool InTruck;

		internal static float Nearest;

		internal static float NearAny = float.MaxValue;

		internal static bool SteppedOut;

		internal static bool Strayed;

		internal static bool NewRoom;

		internal static bool GrabbedLoot;

		internal static bool StoodStill;

		internal static bool TeammateDied;

		internal static bool Crouched;

		internal static bool LastAlive;

		internal static bool BadHit;

		internal static float HealthLeft = 1f;

		internal static bool Spun;

		internal static Vector3 SpunFrom;

		internal static bool MadeNoise;

		internal static Vector3 NoiseAt;

		internal static string NoiseWhat = "";

		internal static bool Payoff;

		private const float NearMetres = 4f;

		private const float FarMetres = 18f;

		private static readonly Dictionary<int, Body> bodies = new Dictionary<int, Body>();

		private static int levelId;

		private static readonly HashSet<int> visited = new HashSet<int>();

		private static readonly HashSet<int> dead = new HashSet<int>();

		private static float nextLook;

		private static float payoffAt;

		private static float stillSince;

		private static float nextBody;

		private static Vector3 stillAt;

		private static bool holdingLoot;

		private static bool stillNoted;

		private static float beatTimer;

		private static float lookedUpAt;

		private static float skyNoteAt;

		private static float lastSeenAt = -100f;

		private static float seenFor;

		private static float afterDue;

		private static float afterReady;

		private static float sprintedAt = -100f;

		private static float escapeStart;

		private static float escapeEnd;

		private static float escapeReady;

		private static int skyRun;

		private static int skyMask;

		private static int lastHealth = -1;

		private static bool noisePending;

		private static bool yawSet;

		private static string noiseWhat = "";

		private static Vector3 noiseAt;

		private static float yawBefore;

		private static float turned;

		private static float spunAt;

		private static readonly Queue<KeyValuePair<float, float>> turns = new Queue<KeyValuePair<float, float>>();

		internal static float SinceSeen => Time.time - lastSeenAt;

		internal static bool Escaping => escapeEnd > 0f;

		internal static float Strength => Mathf.Clamp(Plugin.Intensity.Value, 0f, 2f);

		internal static float Wait(float minSeconds, float maxSeconds)
		{
			float num = Mathf.Lerp(1.35f, 0.6f, Depth) / Mathf.Max(0.25f, Strength);
			return Random.Range(minSeconds, maxSeconds) * num;
		}

		internal static void Tick()
		{
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0232: Unknown result type (might be due to invalid IL or missing references)
			BeatNow = false;
			AfterNow = false;
			SteppedOut = (Strayed = (NewRoom = (GrabbedLoot = (StoodStill = (TeammateDied = false)))));
			BadHit = (Spun = (MadeNoise = false));
			Active = InLevel();
			if (!Active)
			{
				Threat = 0f;
				Nearest = 0f;
				Tension = Mathf.MoveTowards(Tension, 0f, Time.deltaTime);
				Seen.Clear();
				levelId = 0;
				Crouched = (LastAlive = false);
				lastHealth = -1;
				yawSet = (noisePending = false);
				return;
			}
			Eye = ((Component)Cam).transform.position;
			Depth = Mathf.Clamp01((float)RunManager.instance.levelsCompleted / 8f);
			int instanceID = ((Object)LevelGenerator.Instance).GetInstanceID();
			if (instanceID != levelId)
			{
				levelId = instanceID;
				bodies.Clear();
				payoffAt = 0f;
				Outdoors = (Alone = (InTruck = (holdingLoot = false)));
				visited.Clear();
				dead.Clear();
				stillSince = Time.time;
				stillNoted = true;
				skyRun = 0;
				seenFor = 0f;
				afterDue = 0f;
				escapeEnd = 0f;
				lastHealth = -1;
				yawSet = (noisePending = false);
				LastAlive = false;
			}
			if (Time.time >= nextLook)
			{
				nextLook = Time.time + 0.2f;
				Threat = Look();
			}
			float num = Mathf.Clamp01(Threat * Mathf.Lerp(0.8f, 1.1f, Depth) * Mathf.Min(Strength, 1.25f));
			Tension = Mathf.MoveTowards(Tension, num, ((num > Tension) ? 0.5f : 0.12f) * Time.deltaTime);
			Sky();
			Doing();
			Self();
			Turning();
			if (noisePending)
			{
				noisePending = false;
				MadeNoise = true;
				NoiseAt = noiseAt;
				NoiseWhat = noiseWhat;
			}
			Aftermath();
			if (payoffAt > 0f && Time.time >= payoffAt)
			{
				payoffAt = 0f;
				Payoff = true;
			}
			Heartbeat();
		}

		private static bool InLevel()
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Invalid comparison between Unknown and I4
			if (Strength <= 0f)
			{
				return false;
			}
			if ((Object)(object)RunManager.instance == (Object)null || (Object)(object)GameDirector.instance == (Object)null || (Object)(object)LevelGenerator.Instance == (Object)null)
			{
				return false;
			}
			if ((int)GameDirector.instance.currentState != 2)
			{
				return false;
			}
			if (!LevelGenerator.Instance.Generated || !SemiFunc.RunIsLevel())
			{
				return false;
			}
			PlayerAvatar instance = PlayerAvatar.instance;
			if ((Object)(object)instance == (Object)null || instance.isDisabled || instance.deadSet)
			{
				return false;
			}
			Cam = GameDirector.instance.MainCamera;
			return (Object)(object)Cam != (Object)null;
		}

		private static float Look()
		{
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			Seen.Clear();
			Nearest = 0f;
			NearAny = float.MaxValue;
			float num = 0f;
			EnemyDirector instance = EnemyDirector.instance;
			if ((Object)(object)instance == (Object)null || instance.enemiesSpawned == null)
			{
				return 0f;
			}
			foreach (EnemyParent item in instance.enemiesSpawned)
			{
				if ((Object)(object)item == (Object)null || !item.Spawned || (Object)(object)item.Enemy == (Object)null || (Object)(object)item.Enemy.CenterTransform == (Object)null)
				{
					continue;
				}
				Vector3 position = item.Enemy.CenterTransform.position;
				float num2 = Vector3.Distance(Eye, position);
				if (Quiet(item))
				{
					continue;
				}
				NearAny = Mathf.Min(NearAny, num2);
				if (!(num2 > 18f) && HasShape(item) && Phantoms.OnScreen(position, -0.03f) && Phantoms.ClearLine(position, ((Component)item).transform))
				{
					Seen.Add(position);
					if (Nearest <= 0f || num2 < Nearest)
					{
						Nearest = num2;
					}
					num = Mathf.Max(num, Mathf.Lerp(0.3f, 1f, 1f - Mathf.InverseLerp(4f, 18f, num2)));
				}
			}
			return num;
		}

		private static bool Quiet(EnemyParent parent)
		{
			string text = parent.enemyName + "|" + ((Object)((Component)parent).gameObject).name;
			string[] array = Plugin.SilentFor.Value.Split(',');
			for (int i = 0; i < array.Length; i++)
			{
				string text2 = array[i].Trim();
				if (text2.Length > 0 && text.IndexOf(text2, StringComparison.OrdinalIgnoreCase) >= 0)
				{
					return true;
				}
			}
			if (Plugin.PassiveDroid.Value)
			{
				return text.IndexOf("droid", StringComparison.OrdinalIgnoreCase) >= 0;
			}
			return false;
		}

		private static bool HasShape(EnemyParent parent)
		{
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Invalid comparison between Unknown and I4
			int instanceID = ((Object)parent).GetInstanceID();
			if (!bodies.TryGetValue(instanceID, out var value))
			{
				value = (bodies[instanceID] = new Body());
			}
			if (Time.time - value.checkedAt < 2f)
			{
				return value.hasShape;
			}
			value.checkedAt = Time.time;
			value.hasShape = false;
			Renderer[] componentsInChildren = ((Component)parent).GetComponentsInChildren<Renderer>(false);
			foreach (Renderer val in componentsInChildren)
			{
				if (!((Object)(object)val == (Object)null) && val.enabled && (val is MeshRenderer || val is SkinnedMeshRenderer) && (int)val.shadowCastingMode != 3)
				{
					value.hasShape = true;
					break;
				}
			}
			return value.hasShape;
		}

		internal static void PayoffLater()
		{
			if (Random.value < 0.3f)
			{
				payoffAt = Time.time + Random.Range(4f, 9f);
			}
		}

		private static void Doing()
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			PlayerAvatar instance = PlayerAvatar.instance;
			PhysGrabber physGrabber = instance.physGrabber;
			int num;
			if ((Object)(object)physGrabber != (Object)null && physGrabber.grabbed && (Object)(object)physGrabber.grabbedPhysGrabObject != (Object)null)
			{
				num = (physGrabber.grabbedPhysGrabObject.isValuable ? 1 : 0);
				if (num != 0 && !holdingLoot)
				{
					GrabbedLoot = true;
				}
			}
			else
			{
				num = 0;
			}
			holdingLoot = (byte)num != 0;
			Vector3 val = ((Component)instance).transform.position - stillAt;
			if (((Vector3)(ref val)).sqrMagnitude > 0.64000005f)
			{
				stillAt = ((Component)instance).transform.position;
				stillSince = Time.time;
				stillNoted = false;
			}
			else if (!stillNoted && Time.time - stillSince > 8f)
			{
				stillNoted = true;
				StoodStill = true;
			}
			if (Time.time < nextBody)
			{
				return;
			}
			nextBody = Time.time + 0.25f;
			RoomVolumeCheck roomVolumeCheck = instance.RoomVolumeCheck;
			InTruck = (Object)(object)roomVolumeCheck != (Object)null && roomVolumeCheck.inTruck;
			if ((Object)(object)roomVolumeCheck != (Object)null && roomVolumeCheck.CurrentRooms != null)
			{
				foreach (RoomVolume currentRoom in roomVolumeCheck.CurrentRooms)
				{
					if (!((Object)(object)currentRoom == (Object)null) && !currentRoom.Truck && !currentRoom.Extraction && (!((Object)(object)currentRoom.Module != (Object)null) || !currentRoom.Module.StartRoom) && visited.Add(((Object)currentRoom).GetInstanceID()) && visited.Count > 1)
					{
						NewRoom = true;
					}
				}
			}
			if (GameDirector.instance.PlayerList == null)
			{
				return;
			}
			foreach (PlayerAvatar player in GameDirector.instance.PlayerList)
			{
				if (!((Object)(object)player == (Object)null) && !((Object)(object)player == (Object)(object)instance))
				{
					int instanceID = ((Object)player).GetInstanceID();
					if (player.deadSet && dead.Add(instanceID))
					{
						TeammateDied = true;
					}
					else if (!player.deadSet)
					{
						dead.Remove(instanceID);
					}
				}
			}
		}

		private static void Sky()
		{
			//IL_003c: 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_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			if (Time.time < lookedUpAt)
			{
				return;
			}
			lookedUpAt = Time.time + 1f;
			if (skyMask == 0)
			{
				skyMask = LayerMask.GetMask(new string[1] { "Default" });
			}
			Vector3 val = Eye + Vector3.up * 0.4f;
			int num = 0;
			for (int i = 0; i < 5; i++)
			{
				Vector3 val2 = ((i == 0) ? Vector3.up : (Quaternion.Euler(0f, (float)i * 90f, 0f) * new Vector3(0.42f, 0.91f, 0f)));
				if (!Physics.Raycast(val, val2, 80f, skyMask, (QueryTriggerInteraction)1))
				{
					num++;
				}
			}
			bool flag = num >= 4;
			if (flag == Outdoors)
			{
				skyRun = 0;
			}
			else if (++skyRun >= 2)
			{
				skyRun = 0;
				Outdoors = flag;
				SteppedOut = flag;
				if (Time.time - skyNoteAt > 20f)
				{
					skyNoteAt = Time.time;
					Plugin.Note(flag ? "place: under the open sky" : "place: indoors again");
				}
			}
			bool alone = Alone;
			Alone = false;
			LastAlive = false;
			if (!SemiFunc.IsMultiplayer() || GameDirector.instance.PlayerList == null)
			{
				return;
			}
			float num2 = float.MaxValue;
			int num3 = 0;
			int num4 = 0;
			foreach (PlayerAvatar player in GameDirector.instance.PlayerList)
			{
				if (!((Object)(object)player == (Object)null) && !((Object)(object)player == (Object)(object)PlayerAvatar.instance))
				{
					num3++;
					if (player.isDisabled || player.deadSet)
					{
						num4++;
					}
					else
					{
						num2 = Mathf.Min(num2, Vector3.Distance(((Component)player).transform.position, Eye));
					}
				}
			}
			Alone = num2 < float.MaxValue && num2 > 20f;
			if (Alone && !alone)
			{
				Strayed = true;
			}
			LastAlive = num3 > 0 && num4 == num3;
		}

		internal static void Heard(string what, Vector3 at)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			noisePending = true;
			noiseWhat = what;
			noiseAt = at;
		}

		private static void Self()
		{
			PlayerAvatar instance = PlayerAvatar.instance;
			PlayerController instance2 = PlayerController.instance;
			Crouched = ((Object)(object)instance2 != (Object)null && (instance2.Crouching || instance2.Crawling)) || instance.isCrouching || instance.isCrawling;
			PlayerHealth playerHealth = instance.playerHealth;
			if (!((Object)(object)playerHealth == (Object)null))
			{
				int health = playerHealth.health;
				int num = Mathf.Max(1, playerHealth.maxHealth);
				if (lastHealth >= 0 && health > 0 && health < lastHealth && (float)(lastHealth - health) >= (float)num * 0.2f && (float)health <= (float)num * 0.5f)
				{
					BadHit = true;
					HealthLeft = (float)health / (float)num;
				}
				lastHealth = health;
			}
		}

		private static void Turning()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			float y = ((Component)Cam).transform.eulerAngles.y;
			if (!yawSet)
			{
				yawSet = true;
				yawBefore = y;
				turns.Clear();
				turned = 0f;
				return;
			}
			float num = Mathf.DeltaAngle(yawBefore, y);
			yawBefore = y;
			if (PlayerAvatar.instance.isTumbling || Mathf.Abs(num) > 100f)
			{
				turns.Clear();
				turned = 0f;
				return;
			}
			turns.Enqueue(new KeyValuePair<float, float>(Time.time, num));
			turned += num;
			while (turns.Count > 0 && Time.time - turns.Peek().Key > 0.7f)
			{
				turned -= turns.Dequeue().Value;
			}
			if (!(Mathf.Abs(turned) < 135f) && !(Time.time - spunAt < 1.5f))
			{
				spunAt = Time.time;
				Spun = true;
				SpunFrom = Quaternion.Euler(0f, y - turned, 0f) * Vector3.forward;
				turns.Clear();
				turned = 0f;
			}
		}

		private static void Aftermath()
		{
			if (Threat > 0f)
			{
				seenFor += Time.deltaTime;
				lastSeenAt = Time.time;
				afterDue = 0f;
			}
			else if (!(seenFor < 2f) && !(Time.time < afterReady))
			{
				if (afterDue == 0f)
				{
					afterDue = Time.time + Random.Range(4f, 9f);
				}
				else if (!(Time.time < afterDue))
				{
					AfterNow = true;
					seenFor = 0f;
					afterDue = 0f;
					afterReady = Time.time + 40f;
				}
			}
		}

		private static void Heartbeat()
		{
			PlayerController instance = PlayerController.instance;
			if ((Object)(object)instance == (Object)null)
			{
				return;
			}
			if (instance.sprinting)
			{
				sprintedAt = Time.time;
			}
			float num = ((instance.EnergyStart > 0f) ? (instance.EnergyCurrent / instance.EnergyStart) : 1f);
			if (escapeEnd <= 0f)
			{
				if (Time.time < escapeReady || Time.time - lastSeenAt > 20f || num > 0.3f || Time.time - sprintedAt > 2f)
				{
					return;
				}
				escapeStart = Time.time;
				escapeEnd = Time.time + Random.Range(18f, 28f);
				beatTimer = 0f;
				Plugin.Note($"heartbeat: ran from a monster, stamina {num:0%}");
			}
			float num2 = (Time.time - escapeStart) / (escapeEnd - escapeStart);
			if (num2 >= 1f || (num > 0.85f && num2 > 0.3f))
			{
				escapeEnd = 0f;
				escapeReady = Time.time + 30f;
				return;
			}
			beatTimer -= Time.deltaTime;
			if (!(beatTimer > 0f))
			{
				beatTimer = 60f / Mathf.Lerp(130f, 72f, num2);
				BeatNow = true;
				BeatStrength = 1f - num2;
			}
		}
	}
	internal static class Droid
	{
		private static MethodInfo updateState;

		private static FieldInfo terminator;

		private static FieldInfo count;

		private static FieldInfo countMax;

		private static object transformState;

		private static object wanderState;

		internal static void Apply(Harmony harmony)
		{
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Expected O, but got Unknown
			try
			{
				if (Plugin.PassiveDroid.Value && Chainloader.PluginInfos.TryGetValue("WesleysEnemies", out var value))
				{
					Type? type = ((object)value.Instance).GetType().Assembly.GetTypes().FirstOrDefault((Type t) => t.Name == "LostDroid");
					Type type2 = type?.GetNestedType("State", BindingFlags.Public | BindingFlags.NonPublic);
					updateState = type?.GetMethod("UpdateState", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					terminator = type?.GetField("Terminator", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					count = type?.GetField("_transformCount", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					countMax = type?.GetField("_transformCountMax", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					if (type2 == null || updateState == null || terminator == null || count == null || countMax == null)
					{
						Plugin.Log.LogWarning((object)"Lost Droid not found as expected; it is NOT passive.");
						return;
					}
					transformState = Enum.Parse(type2, "Transform");
					wanderState = Enum.Parse(type2, "Wander");
					harmony.Patch((MethodBase)updateState, new HarmonyMethod(typeof(Droid), "RefuseTransform", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
					Plugin.Log.LogInfo((object)"Lost Droid passive ready.");
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Lost Droid could not be made passive: " + ex.Message));
			}
		}

		private static bool RefuseTransform(object __instance, object __0)
		{
			try
			{
				if (!object.Equals(__0, transformState) || (bool)terminator.GetValue(__instance))
				{
					return true;
				}
				count.SetValue(__instance, (float)countMax.GetValue(__instance) * 0.5f);
				updateState.Invoke(__instance, new object[1] { wanderState });
				Plugin.Note("lost droid: calmed down instead of transforming");
				return false;
			}
			catch
			{
				return true;
			}
		}
	}
	internal static class Hush
	{
		internal static float Level = 1f;

		private const float Low = 0.12f;

		private static readonly Dictionary<AudioSource, float> own = new Dictionary<AudioSource, float>();

		private static float want = 1f;

		private static float perSecond = 1f;

		private static float backAt;

		private static float backSeconds;

		internal static void Apply(Harmony harmony)
		{
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Expected O, but got Unknown
			//IL_00a8: Expected O, but got Unknown
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Expected O, but got Unknown
			//IL_00dd: Expected O, but got Unknown
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Expected O, but got Unknown
			try
			{
				MethodInfo methodInfo = AccessTools.Method(typeof(AmbienceLoop), "Update", (Type[])null, (Type[])null);
				MethodInfo methodInfo2 = AccessTools.Method(typeof(AmbienceLoopOverride), "Update", (Type[])null, (Type[])null);
				MethodInfo methodInfo3 = AccessTools.Method(typeof(AmbienceBreakers), "PlaySoundRPC", (Type[])null, (Type[])null);
				if (methodInfo == null || methodInfo2 == null || methodInfo3 == null)
				{
					Plugin.Log.LogWarning((object)"Level ambience not found; hiding will not quiet it.");
					return;
				}
				harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(Hush), "LoopBefore", (Type[])null), new HarmonyMethod(typeof(Hush), "LoopAfter", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				harmony.Patch((MethodBase)methodInfo2, new HarmonyMethod(typeof(Hush), "OverBefore", (Type[])null), new HarmonyMethod(typeof(Hush), "OverAfter", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				harmony.Patch((MethodBase)methodInfo3, new HarmonyMethod(typeof(Hush), "HoldBreaker", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Level ambience could not be hooked: " + ex.Message));
			}
		}

		internal static void Down(float seconds)
		{
			want = 0.12f;
			perSecond = 1f / Mathf.Max(0.05f, seconds);
			backAt = 0f;
			if ((Object)(object)LevelMusic.instance != (Object)null)
			{
				LevelMusic.instance.Interrupt(Mathf.Max(0.5f, 1f / Mathf.Max(0.05f, seconds)));
			}
		}

		internal static void Back(float seconds)
		{
			want = 1f;
			perSecond = 1f / Mathf.Max(0.05f, seconds);
			backAt = 0f;
		}

		internal static void Cut(float hold, float back)
		{
			Down(0.05f);
			backAt = Time.time + hold;
			backSeconds = back;
		}

		internal static void Tick()
		{
			if (!Dread.Active)
			{
				want = 1f;
				perSecond = 0.5f;
				backAt = 0f;
			}
			if (backAt > 0f && Time.time >= backAt)
			{
				Back(backSeconds);
			}
			Level = Mathf.MoveTowards(Level, want, Time.deltaTime * perSecond);
		}

		private static void LoopBefore(AmbienceLoop __instance)
		{
			try
			{
				Restore(__instance.source);
			}
			catch
			{
			}
		}

		private static void LoopAfter(AmbienceLoop __instance)
		{
			try
			{
				Lower(__instance.source);
			}
			catch
			{
			}
		}

		private static void OverBefore(AmbienceLoopOverride __instance)
		{
			try
			{
				Restore(__instance.source);
			}
			catch
			{
			}
		}

		private static void OverAfter(AmbienceLoopOverride __instance)
		{
			try
			{
				Lower(__instance.source);
			}
			catch
			{
			}
		}

		private static bool HoldBreaker()
		{
			return Level > 0.6f;
		}

		private static void Restore(AudioSource source)
		{
			if ((Object)(object)source != (Object)null && own.TryGetValue(source, out var value))
			{
				source.volume = value;
			}
		}

		private static void Lower(AudioSource source)
		{
			if ((Object)(object)source == (Object)null)
			{
				return;
			}
			if (Level >= 0.999f)
			{
				own.Remove(source);
				return;
			}
			if (own.Count > 64)
			{
				own.Clear();
			}
			own[source] = source.volume;
			source.volume *= Level;
		}
	}
	internal static class Lights
	{
		private class Lamp
		{
			internal PropLight light;

			internal float strength;

			internal float target = 1f;

			internal float timer;

			internal bool keep;

			internal bool chase;
		}

		private struct Pulse
		{
			internal Vector3 at;

			internal float range;

			internal float from;

			internal float until;

			internal float strength;
		}

		private const float PlayerRange = 24f;

		private const float MonsterRange = 6f;

		private const float ChaseRange = 14f;

		internal const float MostFlashes = 1.2f;

		private static readonly Dictionary<int, Lamp> lamps = new Dictionary<int, Lamp>();

		private static readonly List<int> gone = new List<int>();

		private static readonly List<Pulse> pulses = new List<Pulse>();

		private static float nextScan;

		private static float chaseUntil;

		private static float chaseRate;

		private static float chasePhase;

		private static float flashUntil;

		internal static void Chase(float perSecond)
		{
			if (Plugin.LightFlicker.Value)
			{
				if (Time.time >= chaseUntil)
				{
					chasePhase = 0.9f;
					nextScan = 0f;
				}
				chaseRate = Mathf.Clamp(perSecond, 0.1f, 1.2f);
				chaseUntil = Time.time + 0.5f;
			}
		}

		internal static void Burst(Vector3 at, float range, float seconds)
		{
			//IL_000d: 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)
			if (Plugin.LightFlicker.Value)
			{
				Add(at, range, 0f, seconds, 1f);
				Buzz(at, 1f);
			}
		}

		internal static bool Single(float seconds)
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_006e: 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)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.LightFlicker.Value || (Object)(object)LightManager.instance == (Object)null)
			{
				return false;
			}
			List<Vector3> list = new List<Vector3>();
			foreach (PropLight propLight in LightManager.instance.propLights)
			{
				if (Usable(propLight))
				{
					Vector3 position = ((Component)propLight).transform.position;
					float num = Vector3.Distance(position, Dread.Eye);
					if (!(num < 7f) && !(num > 20f) && Phantoms.OnScreen(position, 0.1f) && Phantoms.ClearLine(position, 0.6f))
					{
						list.Add(position);
					}
				}
			}
			if (list.Count == 0)
			{
				return false;
			}
			Vector3 at = list[Random.Range(0, list.Count)];
			Add(at, 1.5f, 0f, seconds, 0.85f);
			Buzz(at, 0.6f);
			return true;
		}

		internal static void Walk(Vector3 from, Vector3 to, float secondsPerStep)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: 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_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			if (Plugin.LightFlicker.Value)
			{
				int num = Mathf.Clamp(Mathf.RoundToInt(Vector3.Distance(from, to) / 3f), 2, 7);
				for (int i = 0; i < num; i++)
				{
					Add(Vector3.Lerp(from, to, (float)i / (float)(num - 1)), 3.5f, (float)i * secondsPerStep, secondsPerStep + 0.5f, 0.9f);
				}
				Buzz(from, 0.6f);
			}
		}

		private static void Add(Vector3 at, float range, float delay, float seconds, float strength)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			pulses.Add(new Pulse
			{
				at = at,
				range = range,
				from = Time.time + delay,
				until = Time.time + delay + seconds,
				strength = strength
			});
			nextScan = 0f;
		}

		internal static void Tick()
		{
			if (!Dread.Active || !Plugin.LightFlicker.Value || (Object)(object)LightManager.instance == (Object)null)
			{
				if (lamps.Count > 0)
				{
					RestoreAll();
				}
				pulses.Clear();
				return;
			}
			if (Time.time >= nextScan)
			{
				nextScan = Time.time + ((pulses.Count > 0) ? 0.1f : 0.25f);
				Scan();
			}
			float num = 1f;
			if (Time.time < chaseUntil)
			{
				chasePhase += Time.deltaTime * chaseRate;
				if (chasePhase >= 1f)
				{
					chasePhase -= 1f;
					flashUntil = Time.time + Mathf.Min(0.25f, 0.3f / chaseRate);
				}
				if (Time.time < flashUntil)
				{
					num = 0.15f;
				}
			}
			foreach (Lamp value in lamps.Values)
			{
				if (!((Object)(object)value.light == (Object)null) && !((Object)(object)value.light.lightComponent == (Object)null) && !(Time.time < value.light.fadeEndTime))
				{
					value.timer -= Time.deltaTime;
					if (value.timer <= 0f)
					{
						value.timer = Random.Range(0.04f, 0.16f);
						value.target = ((Random.value < 0.35f) ? 1f : Random.Range(Mathf.Lerp(1f, 0.1f, value.strength), 1f));
					}
					Light lightComponent = value.light.lightComponent;
					float num2 = value.light.originalIntensity * value.target * (value.chase ? num : 1f);
					lightComponent.intensity = Mathf.Lerp(lightComponent.intensity, num2, Time.deltaTime * ((num2 < lightComponent.intensity) ? 30f : 10f));
				}
			}
		}

		private static bool Usable(PropLight light)
		{
			if ((Object)(object)light == (Object)null || light.turnedOff || (Object)(object)light.lightComponent == (Object)null)
			{
				return false;
			}
			if (!((Behaviour)light.lightComponent).enabled || !((Component)light).gameObject.activeInHierarchy)
			{
				return false;
			}
			return Time.time >= light.fadeEndTime;
		}

		private static void Scan()
		{
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			foreach (Lamp value2 in lamps.Values)
			{
				value2.keep = (value2.chase = false);
			}
			bool flag = Time.time < chaseUntil;
			for (int num = pulses.Count - 1; num >= 0; num--)
			{
				if (Time.time >= pulses[num].until)
				{
					pulses.RemoveAt(num);
				}
			}
			foreach (PropLight propLight in LightManager.instance.propLights)
			{
				if (!Usable(propLight))
				{
					continue;
				}
				Vector3 position = ((Component)propLight).transform.position;
				Vector3 val = position - Dread.Eye;
				if (((Vector3)(ref val)).sqrMagnitude > 576f)
				{
					continue;
				}
				float num2 = 0f;
				foreach (Pulse pulse in pulses)
				{
					if (Time.time >= pulse.from)
					{
						val = position - pulse.at;
						if (((Vector3)(ref val)).sqrMagnitude < pulse.range * pulse.range)
						{
							num2 = Mathf.Max(num2, pulse.strength);
						}
					}
				}
				foreach (Vector3 item in Dread.Seen)
				{
					float num3 = Vector3.Distance(position, item);
					if (num3 < 6f)
					{
						num2 = Mathf.Max(num2, 0.5f * (1f - num3 / 6f) + 0.1f);
					}
				}
				int num4;
				if (flag)
				{
					val = position - Dread.Eye;
					num4 = ((((Vector3)(ref val)).sqrMagnitude < 196f) ? 1 : 0);
				}
				else
				{
					num4 = 0;
				}
				bool flag2 = (byte)num4 != 0;
				if (!(num2 <= 0f) || flag2)
				{
					int instanceID = ((Object)propLight).GetInstanceID();
					if (!lamps.TryGetValue(instanceID, out var value))
					{
						Dictionary<int, Lamp> dictionary = lamps;
						Lamp obj = new Lamp
						{
							light = propLight
						};
						value = obj;
						dictionary[instanceID] = obj;
					}
					value.strength = Mathf.Clamp01(num2 * Mathf.Min(Dread.Strength, 1.5f));
					value.keep = true;
					value.chase = flag2;
				}
			}
			gone.Clear();
			foreach (KeyValuePair<int, Lamp> lamp in lamps)
			{
				if (!lamp.Value.keep)
				{
					Restore(lamp.Value);
					gone.Add(lamp.Key);
				}
			}
			foreach (int item2 in gone)
			{
				lamps.Remove(item2);
			}
		}

		private static void Restore(Lamp lamp)
		{
			PropLight light = lamp.light;
			if (!((Object)(object)light == (Object)null) && !((Object)(object)light.lightComponent == (Object)null) && !light.turnedOff && ((Component)light).gameObject.activeInHierarchy && !(Time.time < light.fadeEndTime))
			{
				light.lightComponent.intensity = light.originalIntensity;
			}
		}

		private static void RestoreAll()
		{
			foreach (Lamp value in lamps.Values)
			{
				Restore(value);
			}
			lamps.Clear();
		}

		private static void Buzz(Vector3 at, float volume)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			Phantoms.PlayCopy(((Object)(object)LightManager.instance != (Object)null) ? LightManager.instance.lampFlickerSound : null, at, volume);
		}
	}
	internal static class ScreenFx
	{
		private static readonly string[] Names = new string[4] { "colour drains", "picture breathes", "grain", "colour drains, pulse on the heartbeat" };

		private static GameObject owner;

		private static int kind;

		private static bool fresh = true;

		private static float Shake()
		{
			if (!((Object)(object)GameplayManager.instance != (Object)null))
			{
				return 1f;
			}
			return GameplayManager.instance.cameraNoise;
		}

		internal static void Tick()
		{
			//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_0045: Expected O, but got Unknown
			if (!Dread.Active || !Plugin.ScreenPulse.Value || (Object)(object)PostProcessing.Instance == (Object)null)
			{
				return;
			}
			if ((Object)(object)owner == (Object)null)
			{
				owner = new GameObject("CreepoFear Screen")
				{
					hideFlags = (HideFlags)61
				};
				Object.DontDestroyOnLoad((Object)(object)owner);
			}
			float num = Mathf.InverseLerp(0.5f, 1f, Dread.Tension) * Mathf.Min(Dread.Strength, 1.5f);
			if (num <= 0f)
			{
				fresh = true;
				return;
			}
			if (fresh)
			{
				fresh = false;
				kind = (kind + Random.Range(1, Names.Length)) % Names.Length;
				Plugin.Note("screen: " + Names[kind]);
			}
			PostProcessing instance = PostProcessing.Instance;
			switch (kind)
			{
			case 0:
				instance.SaturationOverride(-22f * num, 1.5f, 0.7f, 0.2f, owner, 1000);
				break;
			case 1:
			{
				float num2 = Mathf.Sin(Time.time * 2f * MathF.PI * 0.3f);
				instance.LensDistortionOverride(instance.lensDistortionIntensity + 9f * num * num2, 4f, 2f, 0.2f, owner);
				break;
			}
			case 2:
				instance.GrainIntensityOverride(instance.grainIntensityDefault * (1f + 1.2f * num), 2f, 1f, 0.2f, owner);
				if ((Object)(object)CameraNoise.Instance != (Object)null)
				{
					CameraNoise.Instance.Override(CameraNoise.Instance.StrengthDefault * Shake() * (1f + 1.2f * num), 0.2f);
				}
				break;
			default:
				instance.SaturationOverride(-16f * num, 1.5f, 0.7f, 0.2f, owner, 1000);
				if (Dread.BeatNow)
				{
					instance.LensDistortionOverride(instance.lensDistortionIntensity + 10f * num, 14f, 5f, 0.07f, owner);
				}
				break;
			}
		}
	}
	internal static class Loom
	{
		internal static float Level;

		internal static bool Hunting;

		private const float Gain = 0.7f;

		private const float Far = 24f;

		private const float HuntFar = 30f;

		private static readonly Dictionary<int, EnemyShadow> found = new Dictionary<int, EnemyShadow>();

		private static readonly Dictionary<int, State> lastState = new Dictionary<int, State>();

		private static AudioSource drone;

		private static AudioSource fall;

		private static AudioClip droneClip;

		private static AudioClip fallClip;

		private static int placeId;

		private static bool asked;

		private static float nextLook;

		private static float want;

		private static float pitchWant = 1f;

		private static float noteAt = -100f;

		private static float flashes;

		private static float fallingUntil;

		internal static void Tick()
		{
			if ((Object)(object)drone == (Object)null)
			{
				Build();
			}
			Route();
			float volume = (Plugin.TensionOn.Value ? Plugin.TensionVolume.Value : 0f);
			if (!Dread.Active)
			{
				want = 0f;
				Hunting = false;
				Apply(volume);
				return;
			}
			if (Score.Here.id != placeId)
			{
				placeId = Score.Here.id;
				Forget();
			}
			if (Time.time >= nextLook)
			{
				nextLook = Time.time + 0.2f;
				Look();
			}
			if (Hunting && flashes > 0f)
			{
				Lights.Chase(flashes);
			}
			Apply(volume);
		}

		private static void Look()
		{
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ae: Invalid comparison between Unknown and I4
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Invalid comparison between Unknown and I4
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Invalid comparison between Unknown and I4
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Invalid comparison between Unknown and I4
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Invalid comparison between Unknown and I4
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: Invalid comparison between Unknown and I4
			EnemyDirector instance = EnemyDirector.instance;
			if ((Object)(object)instance == (Object)null || instance.enemiesSpawned == null)
			{
				return;
			}
			EnemyShadow val = null;
			float num = 0f;
			float num2 = 0f;
			float num3 = 0f;
			bool flag = false;
			bool flag2 = false;
			bool flag3 = false;
			bool flag4 = false;
			foreach (EnemyParent item in instance.enemiesSpawned)
			{
				if ((Object)(object)item == (Object)null)
				{
					continue;
				}
				EnemyShadow val2 = Find(item);
				if ((Object)(object)val2 == (Object)null)
				{
					continue;
				}
				flag = true;
				int instanceID = ((Object)item).GetInstanceID();
				State currentState = val2.currentState;
				State value;
				bool flag5 = lastState.TryGetValue(instanceID, out value) && value != currentState;
				lastState[instanceID] = currentState;
				if (item.Spawned && !((Object)(object)item.Enemy == (Object)null) && !((Object)(object)item.Enemy.CenterTransform == (Object)null))
				{
					Vector3 position = item.Enemy.CenterTransform.position;
					float num4 = Vector3.Distance(Dread.Eye, position);
					bool flag6 = num4 < 24f && Phantoms.OnScreen(position, -0.03f) && Phantoms.ClearLine(position, ((Component)item).transform);
					bool flag7 = (Object)(object)val2.playerTarget == (Object)(object)PlayerAvatar.instance && Hunts(currentState);
					if (flag5 && (int)currentState == 8 && (flag6 || flag7))
					{
						Leaves();
					}
					if (flag5 && (int)currentState == 4 && (flag6 || flag7))
					{
						Plugin.Note("loom: stunned, its drone sags");
					}
					float num5 = 1f - Mathf.InverseLerp(3f, flag7 ? 30f : 24f, num4);
					float num6 = (flag7 ? Mathf.Lerp(0.3f, 1f, num5) : (flag6 ? (Mathf.Lerp(0.3f, 1f, num5) * 0.5f) : 0f));
					if ((Object)(object)val2.playerTarget == (Object)(object)PlayerAvatar.instance && (int)currentState == 4)
					{
						num6 = 0.3f;
					}
					if ((int)currentState == 8 || (int)currentState == 2)
					{
						num6 = 0f;
					}
					if (flag7)
					{
						flag2 = true;
						flag3 = flag3 || flag6;
						num3 = Mathf.Max(num3, Flashes(num4, flag6));
					}
					if (!(num6 <= num))
					{
						num = num6;
						num2 = num4;
						val = val2;
						flag4 = flag6;
					}
				}
			}
			if (flag && !asked)
			{
				asked = true;
				Synth.Want("loom");
				Synth.Want("bend");
			}
			if (asked && (Object)(object)droneClip == (Object)null)
			{
				Gesture gesture = Synth.Take("loom");
				if (gesture != null)
				{
					droneClip = Synth.Clip("creepo loom", gesture.data);
					drone.clip = droneClip;
				}
			}
			flashes = num3;
			if (flag2 && !Hunting)
			{
				Plugin.Note(string.Format("loom: hunting you from {0:0} m{1}, the drone begins{2}", num2, flag3 ? ", in sight" : "", Plugin.LightFlicker.Value ? $", lamps dip every {1f / flashes:0.0} s" : ""));
			}
			Hunting = flag2;
			if ((Object)(object)val == (Object)null || (Object)(object)droneClip == (Object)null)
			{
				want = 0f;
				pitchWant = ((Time.time < fallingUntil) ? 0.8f : 1f);
				return;
			}
			want = num;
			pitchWant = 1f + 0.05f * (1f - Mathf.InverseLerp(3f, 30f, num2));
			if ((int)val.currentState == 4)
			{
				pitchWant = 0.86f;
			}
			if (!flag2 && flag4 && Time.time - noteAt > 10f)
			{
				Plugin.Note($"loom: in sight at {num2:0} m, after someone else");
			}
			noteAt = Time.time;
		}

		private static bool Hunts(State state)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Invalid comparison between Unknown and I4
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Invalid comparison between Unknown and I4
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Invalid comparison between Unknown and I4
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Invalid comparison between Unknown and I4
			if ((int)state != 3 && (int)state != 5 && (int)state != 6)
			{
				return (int)state == 7;
			}
			return true;
		}

		private static float Flashes(float metres, bool seen)
		{
			float num = 1f - Mathf.InverseLerp(4f, 30f, metres);
			if (!seen)
			{
				return Mathf.Lerp(0.25f, 0.5f, num * num);
			}
			return Mathf.Lerp(0.7f, 1.2f, num);
		}

		private static void Leaves()
		{
			fallingUntil = Time.time + 3f;
			Plugin.Note("loom: leaves, its drone falls away");
			if (!Plugin.TensionOn.Value || fall.isPlaying)
			{
				return;
			}
			Gesture gesture = Synth.Take("bend");
			if (gesture != null)
			{
				fall.clip = null;
				if ((Object)(object)fallClip != (Object)null)
				{
					Object.Destroy((Object)(object)fallClip);
				}
				fallClip = Synth.Clip("creepo " + gesture.kind, gesture.data);
				fall.clip = fallClip;
				fall.volume = 0.55f * Plugin.TensionVolume.Value * 0.7f;
				fall.panStereo = Random.Range(-0.2f, 0.2f);
				fall.Play();
				Synth.Want("bend");
			}
		}

		private static void Apply(float volume)
		{
			Level = Mathf.MoveTowards(Level, want, Time.deltaTime / ((want > Level) ? 1.5f : 2.5f));
			drone.pitch = Mathf.MoveTowards(drone.pitch, pitchWant, Time.deltaTime * ((pitchWant < 0.9f) ? 0.08f : 0.05f));
			drone.volume = Level * volume * 0.7f * 0.8f;
			if (Level > 0.001f && !drone.isPlaying && (Object)(object)drone.clip != (Object)null)
			{
				drone.time = Random.Range(0f, drone.clip.length * 0.9f);
				drone.Play();
			}
			else if (Level <= 0.001f && drone.isPlaying)
			{
				drone.Stop();
				drone.pitch = 1f;
			}
		}

		private static EnemyShadow Find(EnemyParent parent)
		{
			int instanceID = ((Object)parent).GetInstanceID();
			if (!found.TryGetValue(instanceID, out var value))
			{
				value = (found[instanceID] = ((Component)parent).GetComponentInChildren<EnemyShadow>(true));
			}
			return value;
		}

		private static void Forget()
		{
			drone.Stop();
			fall.Stop();
			drone.clip = null;
			fall.clip = null;
			if ((Object)(object)droneClip != (Object)null)
			{
				Object.Destroy((Object)(object)droneClip);
			}
			if ((Object)(object)fallClip != (Object)null)
			{
				Object.Destroy((Object)(object)fallClip);
			}
			droneClip = (fallClip = null);
			found.Clear();
			lastState.Clear();
			asked = false;
			Hunting = false;
			Level = (want = (flashes = (fallingUntil = 0f)));
			float num = (drone.pitch = 1f);
			pitchWant = num;
		}

		private static void Build()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: 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: Expected O, but got Unknown
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_0033: Expected O, but got Unknown
			GameObject val = new GameObject("CreepoFear Loom")
			{
				hideFlags = (HideFlags)61
			};
			Object.DontDestroyOnLoad((Object)val);
			drone = Score.Source(val);
			drone.loop = true;
			fall = Score.Source(val);
		}

		private static void Route()
		{
			if (!((Object)(object)AudioManager.instance == (Object)null))
			{
				AudioMixerGroup musicMasterGroup = AudioManager.instance.MusicMasterGroup;
				if (!((Object)(object)musicMasterGroup == (Object)null) && !((Object)(object)drone.outputAudioMixerGroup == (Object)(object)musicMasterGroup))
				{
					drone.outputAudioMixerGroup = musicMasterGroup;
					fall.outputAudioMixerGroup = musicMasterGroup;
				}
			}
		}
	}
	internal static class Noise
	{
		internal static void Apply(Harmony harmony)
		{
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Expected O, but got Unknown
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Expected O, but got Unknown
			try
			{
				MethodInfo methodInfo = AccessTools.Method(typeof(PhysGrabObjectImpactDetector), "ImpactHeavyRPC", (Type[])null, (Type[])null);
				MethodInfo methodInfo2 = AccessTools.Method(typeof(PhysGrabObjectImpactDetector), "BreakRPC", (Type[])null, (Type[])null);
				if (methodInfo == null || methodInfo2 == null)
				{
					Plugin.Log.LogWarning((object)"Impact sounds not found; loud noises will not be answered.");
					return;
				}
				harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(Noise), "HitHard", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				harmony.Patch((MethodBase)methodInfo2, (HarmonyMethod)null, new HarmonyMethod(typeof(Noise), "Broke", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Impact sounds could not be hooked: " + ex.Message));
			}
		}

		private static void HitHard(PhysGrabObjectImpactDetector __instance)
		{
			try
			{
				Mine(__instance, "a hard knock");
			}
			catch
			{
			}
		}

		private static void Broke(PhysGrabObjectImpactDetector __instance, int breakLevel)
		{
			try
			{
				if (breakLevel != __instance.breakLevelLight)
				{
					Mine(__instance, "something broke");
				}
			}
			catch
			{
			}
		}

		private static void Mine(PhysGrabObjectImpactDetector hit, string what)
		{
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			PlayerAvatar instance = PlayerAvatar.instance;
			if ((Object)(object)instance == (Object)null || !Dread.Active || (Object)(object)hit == (Object)null || hit.isCart || hit.inCart)
			{
				return;
			}
			PhysGrabObject physGrabObject = hit.physGrabObject;
			if ((Object)(object)physGrabObject == (Object)null)
			{
				return;
			}
			bool flag = (Object)(object)physGrabObject.lastPlayerGrabbing == (Object)(object)instance;
			foreach (PhysGrabber item in physGrabObject.playerGrabbing)
			{
				if ((Object)(object)item != (Object)null && (Object)(object)item.playerAvatar == (Object)(object)instance)
				{
					flag = true;
				}
			}
			if (flag)
			{
				Dread.Heard(what, ((Component)physGrabObject).transform.position);
			}
		}
	}
	internal static class Phantoms
	{
		private class Voice
		{
			internal Sound sound;

			internal string label;

			internal bool steps;
		}

		private struct Queued
		{
			internal float at;

			internal Sound sound;

			internal Vector3 where;
		}

		private static readonly Regex Wanted = new Regex("step|moveshort|movelong|movesmall|movebig|idlebreak|breath|rustle|crack|squeak|rattle|humm|notice|laugh|chatter|groan|sing", RegexOptions.IgnoreCase);

		private static readonly Regex Calls = new Regex("notice|idlebreak|groan|laugh|chatter|sing|humm|breath", RegexOptions.IgnoreCase);

		private static readonly Regex Unwanted = new Regex("loop|attack|hurt|death|die|stun|explo|global|local|jump|land|kick|punch|hit|shoot|laser|spawn|music|vo$", RegexOptions.IgnoreCase);

		private static readonly Dictionary<Type, FieldInfo[]> soundFields = new Dictionary<Type, FieldInfo[]>();

		private static readonly List<Voice> voices = new List<Voice>();

		private static readonly List<Queued> queue = new List<Queued>();

		private static readonly List<string> recent = new List<string>();

		private static PhysGrabHinge[] doors;

		private static int levelId;

		private static int voicesFor = -1;

		private static int lastKind = -1;

		private static Figure figure;

		private static readonly RaycastHit[] hits = (RaycastHit[])(object)new RaycastHit[16];

		internal static void Tick()
		{
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			if (!Dread.Active)
			{
				Clear();
				levelId = 0;
				return;
			}
			int instanceID = ((Object)LevelGenerator.Instance).GetInstanceID();
			if (instanceID != levelId)
			{
				Clear();
				levelId = instanceID;
				voices.Clear();
				voicesFor = -1;
				recent.Clear();
				doors = null;
			}
			for (int num = queue.Count - 1; num >= 0; num--)
			{
				if (Time.time >= queue[num].at)
				{
					PlayCopy(queue[num].sound, queue[num].where, 1f);
					queue.RemoveAt(num);
				}
			}
			if (figure != null && !figure.Tick())
			{
				figure = null;
			}
			bool payoff = Dread.Payoff;
			Dread.Payoff = false;
			if (payoff && Dread.Threat <= 0f && !Loom.Hunting && Score.Silent(2f) && !Score.Held)
			{
				Plugin.Note("follow-up to the last moment:");
				Fire("follow-up");
			}
		}

		internal static bool Now(string why)
		{
			return Fire(why);
		}

		internal static bool Answer()
		{
			//IL_0089: 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_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.PhantomSounds.Value)
			{
				return false;
			}
			FindVoices();
			List<Voice> list = voices.FindAll((Voice v) => Calls.IsMatch(v.label));
			List<Voice> list2 = ((list.Count > 0) ? list : voices);
			if (list2.Count == 0)
			{
				return TryDoor(12f, 22f, "phantom answer: a door");
			}
			Voice voice = list2[Random.Range(0, list2.Count)];
			Vector3 val = HiddenPoint(15f, 26f);
			float num = Vector3.Distance(val, Dread.Eye);
			if (voice.steps)
			{
				int num2 = Random.Range(3, 6);
				float num3 = Random.Range(0.4f, 0.6f);
				for (int num4 = 0; num4 < num2; num4++)
				{
					queue.Add(new Queued
					{
						at = Time.time + (float)num4 * num3,
						sound = voice.sound,
						where = val
					});
				}
			}
			else if (!PlayCopy(voice.sound, val, 1f))
			{
				return false;
			}
			Plugin.Note($"phantom answer: {voice.label} at {num:0} m");
			return true;
		}

		private static void Clear()
		{
			queue.Clear();
			Dread.Payoff = false;
			if (figure != null)
			{
				figure.Remove();
			}
			figure = null;
		}

		private static bool Fire(string why)
		{
			int[] array = new int[5] { 20, 25, 15, 15, 25 };
			List<int> list = new List<int>();
			List<int> list2 = new List<int> { 0, 1, 2, 3, 4 };
			list2.Remove(lastKind);
			while (list2.Count > 0)
			{
				int num = 0;
				foreach (int item in list2)
				{
					num += array[item];
				}
				int num2 = Random.Range(0, num);
				foreach (int item2 in list2)
				{
					num2 -= array[item2];
					if (num2 < 0)
					{
						list.Add(item2);
						list2.Remove(item2);
						break;
					}
				}
			}
			if (lastKind >= 0)
			{
				list.Add(lastKind);
			}
			foreach (int item3 in list)
			{
				if (item3 switch
				{
					3 => TryKnock(), 
					2 => TryDoor(), 
					1 => TrySound(), 
					0 => TryFigure(), 
					_ => TryLights(), 
				})
				{
					lastKind = item3;
					return true;
				}
			}
			Plugin.Note("phantom: nothing could be done this time (" + why + ")");
			return false;
		}

		private static bool TrySound()
		{
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.PhantomSounds.Value)
			{
				return false;
			}
			FindVoices();
			if (voices.Count == 0)
			{
				return false;
			}
			List<Voice> list = voices.FindAll((Voice v) => !recent.Contains(v.label));
			Voice voice = ((list.Count > 0) ? list[Random.Range(0, list.Count)] : voices[Random.Range(0, voices.Count)]);
			recent.Add(voice.label);
			if (recent.Count > Mathf.Min(5, voices.Count - 1))
			{
				recent.RemoveAt(0);
			}
			Vector3 val = HiddenPoint(5f, 13f);
			float num = Vector3.Distance(val, Dread.Eye);
			if (voice.steps)
			{
				Vector3 val2 = Dread.Eye - val;
				val2.y = 0f;
				val2 = ((((Vector3)(ref val2)).sqrMagnitude > 0.01f) ? ((Vector3)(ref val2)).normalized : Vector3.forward);
				int num2 = Random.Range(3, 7);
				float num3 = Random.Range(0.38f, 0.6f);
				for (int num4 = 0; num4 < num2; num4++)
				{
					queue.Add(new Queued
					{
						at = Time.time + (float)num4 * num3,
						sound = voice.sound,
						where = val + val2 * (0.7f * (float)num4)
					});
				}
			}
			else if (!PlayCopy(voice.sound, val, 1f))
			{
				return false;
			}
			Plugin.Note($"phantom sound: {voice.label} at {num:0} m");
			return true;
		}

		private static void FindVoices()
		{
			EnemyDirector instance = EnemyDirector.instance;
			if ((Object)(object)instance == (Object)null || instance.enemiesSpawned == null || instance.enemiesSpawned.Count == voicesFor)
			{
				return;
			}
			voicesFor = instance.enemiesSpawned.Count;
			voices.Clear();
			foreach (EnemyParent item in instance.enemiesSpawned)
			{
				if ((Object)(object)item == (Object)null)
				{
					continue;
				}
				MonoBehaviour[] componentsInChildren = ((Component)item).GetComponentsInChildren<MonoBehaviour>(true);
				foreach (MonoBehaviour val in componentsInChildren)
				{
					if ((Object)(object)val == (Object)null)
					{
						continue;
					}
					Type type = ((object)val).GetType();
					FieldInfo[] fields;
					if (!soundFields.TryGetValue(type, out var value))
					{
						List<FieldInfo> list = new List<FieldInfo>();
						fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
						foreach (FieldInfo fieldInfo in fields)
						{
							if (fieldInfo.FieldType == typeof(Sound) && Wanted.IsMatch(fieldInfo.Name) && !Unwanted.IsMatch(fieldInfo.Name))
							{
								list.Add(fieldInfo);
							}
						}
						value = (soundFields[type] = list.ToArray());
					}
					fields = value;
					foreach (FieldInfo fieldInfo2 in fields)
					{
						object? value2 = fieldInfo2.GetValue(val);
						Sound val2 = (Sound)((value2 is Sound) ? value2 : null);
						if (val2 != null && Usable(val2))
						{
							voices.Add(new Voice
							{
								sound = val2,
								label = item.enemyName + " " + fieldInfo2.Name,
								steps = (fieldInfo2.Name.IndexOf("step", StringComparison.OrdinalIgnoreCase) >= 0)
							});
						}
					}
				}
			}
			Plugin.Note($"phantom sounds: {voices.Count} to choose from in this level");
		}

		private static bool Usable(Sound sound)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Invalid comparison between Unknown and I4
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Invalid comparison between Unknown and I4
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Invalid comparison between Unknown and I4
			if (sound == null || sound.Sounds == null || sound.Sounds.Length == 0)
			{
				return false;
			}
			AudioClip[] sounds = sound.Sounds;
			for (int i = 0; i < sounds.Length; i++)
			{
				if ((Object)(object)sounds[i] == (Object)null)
				{
					return false;
				}
			}
			if ((int)sound.Type != 7 && (int)sound.Type != 4)
			{
				return (int)sound.Type != 10;
			}
			return false;
		}

		internal static bool PlayCopy(Sound own, Vector3 where, float volume)
		{
			//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_0028: 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)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//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_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: 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_00a8: Unknown result type (might be due to invalid IL or missing references)
			if (!Usable(own) || (Object)(object)AudioManager.instance == (Object)null)
			{
				return false;
			}
			return (Object)(object)new Sound
			{
				Sounds = own.Sounds,
				Type = own.Type,
				Volume = own.Volume,
				VolumeRandom = own.VolumeRandom,
				Pitch = own.Pitch,
				PitchRandom = own.PitchRandom,
				SpatialBlend = 1f,
				Doppler = 0f,
				ReverbMix = own.ReverbMix,
				FalloffMultiplier = own.FalloffMultiplier,
				OffscreenVolume = 1f,
				OffscreenFalloff = 1f
			}.Play(where, volume, 1.5f, 1f, 1f) != (Object)null;
		}

		private static bool TryDoor(float min = 5f, float max = 14f, string label = "phantom door")
		{
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.PhantomSounds.Value)
			{
				return false;
			}
			if (doors == null)
			{
				doors = Object.FindObjectsByType<PhysGrabHinge>((FindObjectsSortMode)0);
			}
			List<PhysGrabHinge> list = new List<PhysGrabHinge>();
			PhysGrabHinge[] array = doors;
			foreach (PhysGrabHinge val in array)
			{
				if (!((Object)(object)val == (Object)null) && !val.dead && !val.broken && !((Object)(object)val.hingeAudio == (Object)null))
				{
					Vector3 position = ((Component)val).transform.position;
					float num = Vector3.Distance(position, Dread.Eye);
					if (!(num < min) && !(num > max) && !OnScreen(position, 0.1f))
					{
						list.Add(val);
					}
				}
			}
			if (list.Count == 0)
			{
				return false;
			}
			PhysGrabHinge val2 = list[Random.Range(0, list.Count)];
			HingeAudio hingeAudio = val2.hingeAudio;
			Sound[] array2 = (Sound[])(object)new Sound[3] { hingeAudio.Open, hingeAudio.Close, hingeAudio.moveLoopEnd };
			int num2 = Random.Range(0, array2.Length);
			for (int j = 0; j < array2.Length; j++)
			{
				if (PlayCopy(array2[(num2 + j) % array2.Length], ((Component)val2).transform.position, 1f))
				{
					Plugin.Note($"{label}: at {Vector3.Distance(((Component)val2).transform.position, Dread.Eye):0} m");
					return true;
				}
			}
			return false;
		}

		private static bool TryKnock()
		{
			//IL_005c: 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_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.PhantomSounds.Value || (Object)(object)ValuableDirector.instance == (Object)null)
			{
				return false;
			}
			List<ValuableObject> list = new List<ValuableObject>();
			foreach (ValuableObject valuable in ValuableDirector.instance.valuableList)
			{
				if (!((Object)(object)valuable == (Object)null) && !((Object)(object)valuable.audioPreset == (Object)null))
				{
					Vector3 position = ((Component)valuable).transform.position;
					float num = Vector3.Distance(position, Dread.Eye);
					if (!(num < 5f) && !(num > 13f) && !OnScreen(position, 0.1f))
					{
						list.Add(valuable);
					}
				}
			}
			if (list.Count == 0)
			{
				return false;
			}
			ValuableObject val = list[Random.Range(0, list.Count)];
			Vector3 position2 = ((Component)val).transform.position;
			if (!PlayCopy((Random.value < 0.7f) ? val.audioPreset.impactLight : val.audioPreset.impactMedium, position2, 1f))
			{
				return false;
			}
			if (Random.value < 0.4f)
			{
				queue.Add(new Queued
				{
					at = Time.time + Random.Range(0.25f, 0.6f),
					sound = val.audioPreset.impactLight,
					where = position2
				});
			}
			Plugin.Note($"phantom knock: at {Vector3.Distance(position2, Dread.Eye):0} m");
			return true;
		}

		private static bool TryLights()
		{
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//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_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: 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)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.LightFlicker.Value)
			{
				return false;
			}
			float value = Random.value;
			if (value < 0.4f)
			{
				float num = Random.Range(1.2f, 3f);
				if (Lights.Single(num))
				{
					Plugin.Note($"phantom flicker: one lamp, {num:0.0} s");
					return true;
				}
			}
			if (value < 0.7f)
			{
				Vector3 val = HiddenPoint(10f, 18f);
				Vector3 to = Vector3.MoveTowards(Dread.Eye, val, 3f);
				Lights.Walk(val, to, Random.Range(0.35f, 0.6f));
				Plugin.Note($"phantom flicker: a run of lamps from {Vector3.Distance(val, Dread.Eye):0} m");
				return true;
			}
			float num2 = Random.Range(0.8f, 2.2f);
			Lights.Burst(Dread.Eye, 12f, num2);
			Plugin.Note($"phantom flicker: all around, {num2:0.0} s");
			return true;
		}

		private static bool TryFigure()
		{
			//IL_006f: 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_008f: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.PhantomFigures.Value || figure != null)
			{
				return false;
			}
			EnemyDirector instance = EnemyDirector.instance;
			if ((Object)(object)instance == (Object)null || instance.enemiesSpawned == null || instance.enemiesSpawned.Count == 0)
			{
				return false;
			}
			if (!FigurePoint(out var where))
			{
				return false;
			}
			EnemyParent val = instance.enemiesSpawned[Random.Range(0, instance.enemiesSpawned.Count)];
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			figure = Figure.Make(val, where);
			if (figure == null)
			{
				return false;
			}
			Plugin.Note($"phantom figure: {val.enemyName} at {Vector3.Distance(where, Dread.Eye):0} m");
			return true;
		}

		internal static bool OnScreen(Vector3 point, float margin)
		{
			//IL_0005: 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_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = Dread.Cam.WorldToViewportPoint(point);
			if (val.z > 0f && val.x > 0f - margin && val.x < 1f + margin && val.y > 0f - margin)
			{
				return val.y < 1f + margin;
			}
			return false;
		}

		internal static bool ClearLine(Vector3 to)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: 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)
			return !Physics.Linecast(Dread.Eye, to, LayerMask.op_Implicit(SemiFunc.LayerMaskGetVisionObstruct()), (QueryTriggerInteraction)1);
		}

		internal static bool ClearLine(Vector3 to, Transform body)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: 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_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: 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_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = to - Dread.Eye;
			float magnitude = ((Vector3)(ref val)).magnitude;
			if (magnitude < 0.05f)
			{
				return true;
			}
			int num = LayerMask.op_Implicit(SemiFunc.LayerMaskGetVisionObstruct()) & ~LayerMask.GetMask(new string[1] { "Player" });
			int num2 = Physics.RaycastNonAlloc(Dread.Eye, val / magnitude, hits, magnitude, num, (QueryTriggerInteraction)1);
			for (int i = 0; i < num2; i++)
			{
				RaycastHit val2 = hits[i];
				if (!((Object)(object)((RaycastHit)(ref val2)).collider == (Object)null) && !((Component)((RaycastHit)(ref val2)).collider).transform.IsChildOf(body) && !((Component)((RaycastHit)(ref val2)).transform).CompareTag("Player") && !((Object)(object)((Component)((RaycastHit)(ref val2)).transform).GetComponent<PlayerTumble>() != (Object)null))
				{
					return false;
				}
			}
			return true;
		}

		internal static bool ClearLine(Vector3 to, float slack)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: 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_001a: 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_003f: 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_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = to - Dread.Eye;
			float magnitude = ((Vector3)(ref val)).magnitude;
			if (magnitude <= slack)
			{
				return true;
			}
			int num = LayerMask.op_Implicit(SemiFunc.LayerMaskGetVisionObstruct()) & ~LayerMask.GetMask(new string[1] { "Player" });
			int num2 = Physics.RaycastNonAlloc(Dread.Eye, val / magnitude, hits, magnitude, num, (QueryTriggerInteraction)1);
			for (int i = 0; i < num2; i++)
			{
				RaycastHit val2 = hits[i];
				if (!((Object)(object)((RaycastHit)(ref val2)).collider == (Object)null) && !(((RaycastHit)(ref val2)).distance >= magnitude - slack) && !((Component)((RaycastHit)(ref val2)).transform).CompareTag("Player") && !((Object)(object)((Component)((RaycastHit)(ref val2)).transform).GetComponent<PlayerTumble>() != (Object)null))
				{
					return false;
				}
			}
			return true;
		}

		private static Vector3 HiddenPoint(float min, float max)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: 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_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			List<Vector3> list = new List<Vector3>();
			List<Vector3> list2 = new List<Vector3>();
			Vector3 forward = ((Component)Dread.Cam).transform.forward;
			foreach (LevelPoint levelPathPoint in LevelGenerator.Instance.LevelPathPoints)
			{
				if (!((Object)(object)levelPathPoint == (Object)null))
				{
					Vector3 val = ((Component)levelPathPoint).transform.position + Vector3.up;
					float num = Vector3.Distance(val, Dread.Eye);
					if (!(num < min) && !(num > max) && !OnScreen(val, 0.05f))
					{
						((Vector3.Dot(forward, val - Dread.Eye) < 0f) ? list : list2).Add(val);
					}
				}
			}
			List<Vector3> list3 = ((list.Count > 0) ? list : list2);
			if (list3.Count > 0)
			{
				return list3[Random.Range(0, list3.Count)];
			}
			Vector3 val2 = -forward;
			val2.y = 0f;
			return Dread.Eye + ((((Vector3)(ref val2)).sqrMagnitude > 0.01f) ? ((Vector3)(ref val2)).normalized : Vector3.back) * ((min + max) * 0.5f);
		}

		private static bool FigurePoint(out Vector3 where)
		{
			//IL_0001: 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_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: 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)
			//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_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			where = Vector3.zero;
			List<Vector3> list = new List<Vector3>();
			foreach (LevelPoint levelPathPoint in LevelGenerator.Instance.LevelPathPoints)
			{
				if (!((Object)(object)levelPathPoint == (Object)null))
				{
					Vector3 position = ((Component)levelPathPoint).transform.position;
					float num = Vector3.Distance(position, Dread.Eye);
					if (!(num < 9f) && !(num > 22f) && !(Mathf.Abs(position.y - Dread.Eye.y) > 3f) && !OnScreen(position + Vector3.up, 0.1f) && ClearLine(position + Vector3.up * 1.2f) && !NearSomeone(position))
					{
						list.Add(position);
					}
				}
			}
			if (list.Count == 0)
			{
				return false;
			}
			where = list[Random.Range(0, list.Count)];
			return true;
		}

		private static bool NearSomeone(Vector3 at)
		{
			//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_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val;
			if (GameDirector.instance.PlayerList != null)
			{
				foreach (PlayerAvatar player in GameDirector.instance.PlayerList)
				{
					if ((Object)(object)player != (Object)null)
					{
						val = ((Component)player).transform.position - at;
						if (((Vector3)(ref val)).sqrMagnitude < 36f)
						{
							return true;
						}
					}
				}
			}
			foreach (EnemyParent item in EnemyDirector.instance.enemiesSpawned)
			{
				if (!((Object)(object)item == (Object)null) && item.Spawned && !((Object)(object)item.Enemy == (Object)null) && !((Object)(object)item.Enemy.CenterTransform == (Object)null))
				{
					val = item.Enemy.CenterTransform.position - at;
					if (((Vector3)(ref val)).sqrMagnitude < 64f)
					{
						return true;
					}
				}
			}
			return false;
		}
	}
	internal class Figure
	{
		private GameObject root;

		private List<Mesh> baked;

		private Vector3 centre;

		private float born;

		private float seen;

		private float hold;

		private bool slips;

		private bool noticed;

		internal static Figure Make(EnemyParent model, Vector3 where)
		{
			//IL_0244: 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_0257: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_025d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0262: Unknown result type (might be due to invalid IL or missing references)
			//IL_0276: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_029e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: 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_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Expected O, but got Unknown
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ea: 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_032a: 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_0350: Unknown result type (might be due to invalid IL or missing references)
			//IL_0363: Unknown result type (might be due to invalid IL or missing references)
			//IL_0368: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Invalid comparison between Unknown and I4
			//IL_03a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: 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_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Expected O, but got Unknown
			if ((Object)(object)model.Enemy == (Object)null || (Object)(object)model.Enemy.CenterTransform == (Object)null)
			{
				return null;
			}
			Transform val = (((Object)(object)model.EnableObject != (Object)null) ? model.EnableObject.transform : ((Component)model).transform);
			Vector3 position = model.Enemy.CenterTransform.position;
			Vector3 position2 = position + Vector3.down;
			RaycastHit val2 = default(RaycastHit);
			if (Physics.Raycast(position, Vector3.down, ref val2, 5f, LayerMask.op_Implicit(SemiFunc.LayerMaskGetVisionObstruct()), (QueryTriggerInteraction)1))
			{
				position2 = ((RaycastHit)(ref val2)).point;
			}
			GameObject val3 = new GameObject("CreepoFear Figure");
			val3.transform.position = position2;
			List<Mesh> list = new List<Mesh>();
			int num = 0;
			try
			{
				Renderer[] componentsInChildren = ((Component)val).GetComponentsInChildren<Renderer>(true);
				foreach (Renderer val4 in componentsInChildren)
				{
					if ((Object)(object)val4 == (Object)null || !val4.enabled || !SwitchedOn(((Component)val4).transform, val) || (int)val4.shadowCastingMode == 3)
					{
						continue;
					}
					Mesh val5 = null;
					if (val4 is MeshRenderer)
					{
						MeshFilter component = ((Component)val4).GetComponent<MeshFilter>();
						if ((Object)(object)component != (Object)null)
						{
							val5 = component.sharedMesh;
						}
					}
					else
					{
						SkinnedMeshRenderer val6 = (SkinnedMeshRenderer)(object)((val4 is SkinnedMeshRenderer) ? val4 : null);
						if (val6 != null && (Object)(object)val6.sharedMesh != (Object)null)
						{
							val5 = new Mesh();
							list.Add(val5);
							val6.BakeMesh(val5, true);
						}
					}
					if (!((Object)(object)val5 == (Object)null))
					{
						GameObject val7 = new GameObject("part");
						val7.transform.SetParent(val3.transform, false);
						val7.transform.position = ((Component)val4).transform.position;
						val7.transform.rotation = ((Component)val4).transform.rotation;
						val7.transform.localScale = ((Component)val4).transform.lossyScale;
						val7.AddComponent<MeshFilter>().sharedMesh = val5;
						MeshRenderer obj = val7.AddComponent<MeshRenderer>();
						((Renderer)obj).sharedMaterials = val4.sharedMaterials;
						((Renderer)obj).shadowCastingMode = val4.shadowCastingMode;
						((Renderer)obj).receiveShadows = val4.receiveShadows;
						num++;
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Figure could not be copied: " + ex.Message));
				num = 0;
			}
			Vector3 forward = model.Enemy.CenterTransform.forward;
			forward.y = 0f;
			Vector3 val8 = Dread.Eye - where;
			val8.y = 0f;
			val3.transform.position = where;
			if (((Vector3)(ref forward)).sqrMagnitude > 0.01f && ((Vector3)(ref val8)).sqrMagnitude > 0.01f)
			{
				val3.transform.rotation = Quaternion.AngleAxis(Vector3.SignedAngle(forward, val8, Vector3.up), Vector3.up);
			}
			bool flag = false;
			Bounds bounds = default(Bounds);
			((Bounds)(ref bounds))..ctor(where, Vector3.zero);
			MeshRenderer[] componentsInChildren2 = val3.GetComponentsInChildren<MeshRenderer>();
			foreach (MeshRenderer val9 in componentsInChildren2)
			{
				if (!flag)
				{
					bounds = ((Renderer)val9).bounds;
				}
				else
				{
					((Bounds)(ref bounds)).Encapsulate(((Renderer)val9).bounds);
				}
				flag = true;
			}
			if (num == 0 || !flag || ((Bounds)(ref bounds)).size.y < 0.3f || ((Bounds)(ref bounds)).size.y > 7f || ((Bounds)(ref bounds)).size.x > 8f || ((Bounds)(ref bounds)).size.z > 8f || Vector3.Distance(((Bounds)(ref bounds)).center, where) > 5f)
			{
				Figure figure = new Figure();
				figure.root = val3;
				figure.baked = list;
				figure.Remove();
				return null;
			}
			return new Figure
			{
				root = val3,
				baked = list,
				centre = ((Bounds)(ref bounds)).center,
				born = Time.time,
				hold = Random.Range(0.5f, 1.3f),
				slips = (Random.value < 0.5f)
			};
		}

		private static bool SwitchedOn(Transform part, Transform within)
		{
			Transform val = part;
			while ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)within)
			{
				if (!((Component)val).gameObject.activeSelf)
				{
					return false;
				}
				val = val.parent;
			}
			return true;
		}

		internal bool Tick()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)root == (Object)null)
			{
				return false;
			}
			float num = Vector3.Distance(centre, Dread.Eye);
			bool flag = Phantoms.OnScreen(centre, -0.02f) && Phantoms.ClearLine(centre);
			if (flag)
			{
				seen += Time.deltaTime;
			}
			if (flag && num >= 6f && slips && seen >= hold)
			{
				noticed = true;
				if (seen < hold + 6f)
				{
					return true;
				}
			}
			else if (noticed && !flag)
			{
				Plugin.Note($"phantom figure: seen for {seen:0.0} s, gone on looking away");
				Remove();
				return false;
			}
			if (flag && (seen >= hold || num < 6f))
			{
				Lights.Burst(centre, 9f, 0.7f);
				if (Random.value < 0.5f && (Object)(object)AudioScare.instance != (Object)null)
				{
					AudioScare.instance.PlaySoft();
				}
				Plugin.Note($"phantom figure: seen for {seen:0.0} s, gone");
				Remove();
				return false;
			}
			if (!flag && (Time.time - born > 30f || num < 5f))
			{
				Plugin.Note("phantom figure: left unseen");
				Remove();
				return false;
			}
			return true;
		}

		internal void Remove()
		{
			if ((Object)(object)root != (Object)null)
			{
				Object.Destroy((Object)(object)root);
			}
			root = null;
			if (baked != null)
			{
				foreach (Mesh item in baked)
				{
					if ((Object)(object)item != (Object)null)
					{
						Object.Destroy((Object)(object)item);
					}
				}
			}
			baked = null;
		}
	}
	[BepInPlugin("cam.creepofear", "Creepo Fear", "1.1.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "cam.creepofear";

		public const string Version = "1.1.1";

		internal static ManualLogSource Log;

		internal static ConfigEntry<float> Intensity;

		internal static ConfigEntry<bool> TensionOn;

		internal static ConfigEntry<float> TensionVolume;

		internal static ConfigEntry<string> SilentFor;

		internal static ConfigEntry<bool> PlaceOn;

		internal static ConfigEntry<float> PlaceVolume;

		internal static ConfigEntry<bool> PhantomSounds;

		internal static ConfigEntry<bool> PhantomFigures;

		internal static ConfigEntry<bool> LightFlicker;

		internal static ConfigEntry<bool> ScreenPulse;

		internal static ConfigEntry<bool> PassiveDroid;

		internal static ConfigEntry<bool> LogEvents;

		private void Awake()
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Expected O, but got Unknown
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Expected O, but got Unknown
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Expected O, but got Unknown
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Expected O, but got Unknown
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Expected O, but got Unknown
			//IL_0206: Expected O, but got Unknown
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			Intensity = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Intensity", 1f, new ConfigDescription("How often and how strongly everything in this mod happens. 0 turns it all off.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 2f), Array.Empty<object>()));
			TensionOn = ((BaseUnityPlugin)this).Config.Bind<bool>("Tension", "Enabled", true, "Quiet string sounds, each one the answer to something that just happened: spotting a monster, it closing in, losing sight of it, a teammate dying, or a long silence broken when you stray, enter a new room, pick up loot or stand still (sometimes a sound that builds and then stops dead). The Loom's drone while it hunts you, a heartbeat after running from a monster until out of breath, a low note when you are the last one alive, and now and then a faint tick behind you when you spin round. Crouching while a monster walks past in sight makes everything go quiet until it has gone. Never for a monster behind a wall or behind you, and never two at once.");
			TensionVolume = ((BaseUnityPlugin)this).Config.Bind<float>("Tension", "Volume", 0.6f, new ConfigDescription("Loudness of the tension layer. It also follows the game's music volume.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			SilentFor = ((BaseUnityPlugin)this).Config.Bind<string>("Tension", "SilentFor", "Mimic,Whispral", "Monsters that never set off the tension sounds or screen effects, by name, separated by commas. Meant for the ones that pass for a teammate.");
			PlaceOn = ((BaseUnityPlugin)this).Config.Bind<bool>("Place", "Enabled", true, "Quiet sounds of the map itself, picked by what it is built from, only into silence: a wind gust when you step outside, a creak, knock or drip when you enter a new room, a deep settling when you stand still. Nothing to do with monsters.");
			PlaceVolume = ((BaseUnityPlugin)this).Config.Bind<float>("Place", "Volume", 0.5f, new ConfigDescription("Loudness of the place sounds. They also follow the game's sound effects volume.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			PhantomSounds = ((BaseUnityPlugin)this).Config.Bind<bool>("Phantoms", "Sounds", true, "After a long silence, when you stray, enter a new room, pick up loot or stand still: sometimes a sound with nothing behind it (one of the level's monsters, a door, something bumped in the next room). Also, sometimes, something far off answers when you drop or break something loud.");
			PhantomFigures = ((BaseUnityPlugin)this).Config.Bind<bool>("Phantoms", "Figures", true, "At those same moments: sometimes the shape of one of the level's monsters stands in the distance, and is gone when watched.");
			LightFlicker = ((BaseUnityPlugin)this).Config.Bind<bool>("Lights", "Flicker", true, "Lamps flicker near a monster you can see, dip and come back while the Loom hunts you (slowly, never fast), and sometimes when a long silence is broken.");
			ScreenPulse = ((BaseUnityPlugin)this).Config.Bind<bool>("Screen", "Pulse", true, "With a monster in sight and close, the picture changes a little: less colour, a slow breathing, or more grain. A different one each time.");
			PassiveDroid = ((BaseUnityPlugin)this).Config.Bind<bool>("Lost Droid", "Passive", true, "Host only. With Wesley's Enemies installed, the Lost Droid follows and talks but never turns into its armed form.");
			LogEvents = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "LogEvents", true, "Write one line to the BepInEx log for each thing this mod does.");
			Synth.Begin();
			Harmony val = new Harmony("cam.creepofear");
			Droid.Apply(val);
			Hush.Apply(val);
			Noise.Apply(val);
			GameObject val2 = new GameObject("CreepoFear")
			{
				hideFlags = (HideFlags)61
			};
			Object.DontDestroyOnLoad((Object)val2);
			val2.AddComponent<Director>();
			Log.LogInfo((object)"Creepo Fear 1.1.1 loaded.");
		}

		internal static void Note(string what)
		{
			if (LogEvents.Value)
			{
				Log.LogInfo((object)what);
			}
		}
	}
	internal class Director : MonoBehaviour
	{
		private float quietUntil;

		private void Update()
		{
			Run(Dread.Tick, "dread");
			Run(Score.Tick, "tension sound");
			Run(Hush.Tick, "hush");
			Run(Loom.Tick, "loom");
			Run(Phantoms.Tick, "phantoms");
			Run(Lights.Tick, "lights");
			Run(ScreenFx.Tick, "screen");
		}

		private void Run(Action part, string name)
		{
			try
			{
				part();
			}
			catch (Exception arg)
			{
				if (!(Time.unscaledTime < quietUntil))
				{
					quietUntil = Time.unscaledTime + 10f;
					Plugin.Log.LogWarning((object)$"{name} failed: {arg}");
				}
			}
		}
	}
	internal static class Score
	{
		private enum Tie
		{
			None,
			Sight,
			Outdoors
		}

		private class Voice
		{
			internal AudioSource source;

			internal AudioClip clip;

			internal float level;

			internal float fade;

			internal bool leaving;

			internal Tie tie;
		}

		private sealed class Moment
		{
			internal readonly string name;

			internal string[] kinds;

			internal string next;

			internal string last;

			internal Moment(string name, params string[] kinds)
			{
				this.name = name;
				this.kinds = kinds;
			}
		}

		private static readonly Moment SpotFar = new Moment("spotted far off", "contrabass", "harmonic",