Decompiled source of The Incident v1.0.1

plugins\KeysMonster\KeysMonster.dll

Decompiled 6 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Events;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.Networking;
using UnityEngine.Rendering;

[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("KeysMonster")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("KeysMonster")]
[assembly: AssemblyTitle("KeysMonster")]
[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 KeysMonster
{
	internal static class Assets
	{
		public static bool MaterialsReady;

		public static Material Brass;

		public static Material BrassDark;

		public static Material FacePlate;

		public static Material EyeWhite;

		public static Material Pupil;

		public static Material Tooth;

		public static Material Mouth;

		public static Material SuitWhite;

		public static Material SuitGrey;

		public static Material SuitOrange;

		public static Material Visor;

		public static Material GunMetal;

		public static Material GunGlow;

		public static Material Beam;

		private static readonly List<Object> keepAlive = new List<Object>();

		public const float ModelScale = 2.1f;

		public static readonly Vector3 ModelOffset = new Vector3(0f, 0.51f, 0f);

		public static Mesh KeyModelMesh;

		public static Texture2D KeyModelTexture;

		public static Material KeyModel;

		public static AudioClip[] Chant = (AudioClip[])(object)new AudioClip[0];

		public static AudioClip[] Call = (AudioClip[])(object)new AudioClip[0];

		public static AudioClip[] Whisper = (AudioClip[])(object)new AudioClip[0];

		public static AudioClip[] Bite = (AudioClip[])(object)new AudioClip[0];

		public static AudioClip[] Hurt = (AudioClip[])(object)new AudioClip[0];

		public static AudioClip[] Death = (AudioClip[])(object)new AudioClip[0];

		public static AudioClip[] Spawn = (AudioClip[])(object)new AudioClip[0];

		public static AudioClip[] Jingle = (AudioClip[])(object)new AudioClip[0];

		public static AudioClip[] Step = (AudioClip[])(object)new AudioClip[0];

		public static AudioClip[] AllyVoiceDefault = (AudioClip[])(object)new AudioClip[0];

		public static AudioClip[] AllyVoiceCustom = (AudioClip[])(object)new AudioClip[0];

		public static AudioClip[] AllyArrive = (AudioClip[])(object)new AudioClip[0];

		public static AudioClip[] AllyLeave = (AudioClip[])(object)new AudioClip[0];

		public static AudioClip[] AllyZap = (AudioClip[])(object)new AudioClip[0];

		public static AudioClip[] AllyHum = (AudioClip[])(object)new AudioClip[0];

		public static string SoundDir;

		private static readonly Dictionary<string, Vector2[]> fireWindows = new Dictionary<string, Vector2[]>(StringComparer.OrdinalIgnoreCase);

		public static AudioClip[] AllyVoice
		{
			get
			{
				if (AllyVoiceCustom.Length == 0)
				{
					return AllyVoiceDefault;
				}
				return AllyVoiceCustom;
			}
		}

		public static void LoadModel(string pluginDir)
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Expected O, but got Unknown
			try
			{
				string path = Path.Combine(pluginDir, "model");
				if (!File.Exists(Path.Combine(path, "keys_model.obj")))
				{
					path = pluginDir;
				}
				string path2 = Path.Combine(path, "keys_model.obj");
				string path3 = Path.Combine(path, "keys_model.png");
				if (!File.Exists(path2))
				{
					Plugin.Log.LogInfo((object)"No keys_model.obj found - using the built-in procedural key model.");
					return;
				}
				Mesh val = ObjLoader.Load(path2, 2.1f, ModelOffset);
				if ((Object)(object)val == (Object)null)
				{
					return;
				}
				if (File.Exists(path3))
				{
					Texture2D val2 = new Texture2D(2, 2, (TextureFormat)4, true);
					if (ImageConversion.LoadImage(val2, File.ReadAllBytes(path3), true))
					{
						((Object)val2).name = "Keys Model Albedo";
						((Texture)val2).wrapMode = (TextureWrapMode)0;
						((Object)val2).hideFlags = (HideFlags)61;
						KeyModelTexture = val2;
						keepAlive.Add((Object)(object)val2);
					}
				}
				KeyModelMesh = val;
				keepAlive.Add((Object)(object)val);
				Plugin.Log.LogInfo((object)string.Format("Loaded key model: {0} vertices, texture={1}", val.vertexCount, Object.op_Implicit((Object)(object)KeyModelTexture) ? (((Texture)KeyModelTexture).width + "px") : "none"));
			}
			catch (Exception ex)
			{
				KeyModelMesh = null;
				Plugin.Log.LogWarning((object)("Could not load the key model (falling back to the procedural key): " + ex.Message));
			}
		}

		public static void InitMaterials(Material source)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: 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_008c: 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_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_0275: Unknown result type (might be due to invalid IL or missing references)
			//IL_0284: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c6: 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_02f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_031d: Unknown result type (might be due to invalid IL or missing references)
			//IL_033b: Unknown result type (might be due to invalid IL or missing references)
			//IL_035f: Unknown result type (might be due to invalid IL or missing references)
			//IL_037d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			if (MaterialsReady || (Object)(object)source == (Object)null)
			{
				return;
			}
			Brass = Make(source, "Keys Brass", new Color(0.8f, 0.6f, 0.2f), 0.85f, 0.62f, Color.black);
			BrassDark = Make(source, "Keys Brass Dark", new Color(0.42f, 0.29f, 0.09f), 0.8f, 0.5f, Color.black);
			FacePlate = Make(source, "Keys Face Plate", new Color(0.3f, 0.2f, 0.07f), 0.6f, 0.4f, Color.black);
			EyeWhite = Make(source, "Keys Eye", new Color(0.95f, 0.93f, 0.85f), 0f, 0.7f, new Color(0.1f, 0.1f, 0.09f));
			Pupil = Make(source, "Keys Pupil", new Color(0.05f, 0.02f, 0.02f), 0f, 0.8f, Color.black);
			Tooth = Make(source, "Keys Tooth", new Color(0.93f, 0.9f, 0.78f), 0f, 0.5f, Color.black);
			Mouth = Make(source, "Keys Mouth", new Color(0.1f, 0.01f, 0.01f), 0f, 0.2f, Color.black);
			if ((Object)(object)KeyModelMesh != (Object)null)
			{
				KeyModel = Make(source, "Keys Model", new Color(0.85f, 0.66f, 0.22f), 0.35f, 0.5f, Color.black);
				if ((Object)(object)KeyModelTexture != (Object)null)
				{
					SetTex(KeyModel, "_AlbedoTexture", (Texture)(object)KeyModelTexture);
					SetTex(KeyModel, "_MainTex", (Texture)(object)KeyModelTexture);
				}
			}
			SuitWhite = Make(source, "CaseOh Suit", new Color(0.9f, 0.9f, 0.88f), 0f, 0.35f, Color.black);
			SuitGrey = Make(source, "CaseOh Suit Grey", new Color(0.36f, 0.38f, 0.42f), 0.2f, 0.4f, Color.black);
			SuitOrange = Make(source, "CaseOh Suit Trim", new Color(0.92f, 0.42f, 0.08f), 0f, 0.4f, Color.black);
			Visor = Make(source, "CaseOh Visor", new Color(0.85f, 0.62f, 0.12f), 0.9f, 0.95f, new Color(0.25f, 0.16f, 0.02f));
			GunMetal = Make(source, "CaseOh Gun", new Color(0.16f, 0.17f, 0.2f), 0.8f, 0.6f, Color.black);
			GunGlow = Make(source, "CaseOh Gun Glow", new Color(0.25f, 1f, 0.35f), 0f, 0.6f, new Color(0.4f, 2.4f, 0.6f));
			Beam = Make(source, "CaseOh Beam", new Color(0.45f, 1f, 0.55f), 0f, 0.2f, new Color(0.8f, 4f, 1.1f));
			MaterialsReady = true;
		}

		private static Material Make(Material source, string name, Color color, float metallic, float smoothness, Color emission)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			Material val = new Material(source);
			((Object)val).name = name;
			((Object)val).hideFlags = (HideFlags)61;
			Texture2D val2 = new Texture2D(4, 4, (TextureFormat)4, false);
			Color[] array = (Color[])(object)new Color[16];
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = color;
			}
			val2.SetPixels(array);
			val2.Apply(false, true);
			((Object)val2).name = name + " Albedo";
			((Object)val2).hideFlags = (HideFlags)61;
			keepAlive.Add((Object)(object)val2);
			SetTex(val, "_AlbedoTexture", (Texture)(object)val2);
			SetTex(val, "_MainTex", (Texture)(object)val2);
			SetCol(val, "_AlbedoColor", Color.white);
			SetCol(val, "_Color", Color.white);
			SetTex(val, "_NormalTexture", null);
			SetFloat(val, "_NormalStrength", 0f);
			SetTex(val, "_MetallicTexture", (Texture)(object)Texture2D.whiteTexture);
			SetTex(val, "_SmoothnessTexture", (Texture)(object)Texture2D.whiteTexture);
			SetFloat(val, "_Metallic", metallic);
			SetFloat(val, "_Smoothness", smoothness);
			SetTex(val, "_EmissionTexture", (Texture)(object)Texture2D.whiteTexture);
			SetCol(val, "_EmissionColor", emission);
			SetFloat(val, "_TilingX", 1f);
			SetFloat(val, "_TilingY", 1f);
			SetFloat(val, "_OffsetX", 0f);
			SetFloat(val, "_OffsetY", 0f);
			SetFloat(val, "_ColorOverlayAmount", 0f);
			keepAlive.Add((Object)(object)val);
			return val;
		}

		private static void SetTex(Material m, string prop, Texture t)
		{
			if (m.HasProperty(prop))
			{
				m.SetTexture(prop, t);
			}
		}

		private static void SetCol(Material m, string prop, Color c)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			if (m.HasProperty(prop))
			{
				m.SetColor(prop, c);
			}
		}

		private static void SetFloat(Material m, string prop, float f)
		{
			if (m.HasProperty(prop))
			{
				m.SetFloat(prop, f);
			}
		}

		public static Vector2[] FireWindows(AudioClip clip)
		{
			if (!Object.op_Implicit((Object)(object)clip) || !fireWindows.TryGetValue(((Object)clip).name, out var value))
			{
				return null;
			}
			return value;
		}

		private static void LoadFireWindows(string audioFile, AudioClip clip)
		{
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				string path = Path.ChangeExtension(audioFile, ".txt");
				if (!File.Exists(path))
				{
					return;
				}
				List<Vector2> list = new List<Vector2>();
				foreach (Match item in Regex.Matches(File.ReadAllText(path), "(\\d+(?:\\.\\d+)?)\\s*-\\s*(\\d+(?:\\.\\d+)?)"))
				{
					float num = float.Parse(item.Groups[1].Value, CultureInfo.InvariantCulture);
					float num2 = float.Parse(item.Groups[2].Value, CultureInfo.InvariantCulture);
					if (num2 > num)
					{
						list.Add(new Vector2(num, num2));
					}
				}
				if (list.Count > 0)
				{
					fireWindows[((Object)clip).name] = list.ToArray();
					Plugin.Log.LogInfo((object)$"{Path.GetFileName(audioFile)}: CaseOh fires in time with this clip ({list.Count} bursts).");
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Could not read the firing times for '" + audioFile + "': " + ex.Message));
			}
		}

		public static void LoadSounds(string pluginDir)
		{
			SoundDir = Path.Combine(pluginDir, "sounds");
			if (!Directory.Exists(SoundDir))
			{
				SoundDir = pluginDir;
			}
			Chant = LoadGroup("keys_chant");
			Call = LoadGroup("keys_call");
			Whisper = LoadGroup("keys_whisper");
			Bite = LoadGroup("keys_bite");
			Hurt = LoadGroup("keys_hurt");
			Death = LoadGroup("keys_death");
			Spawn = LoadGroup("keys_spawn");
			Jingle = LoadGroup("keys_jingle");
			Step = LoadGroup("keys_step");
			AllyVoiceDefault = LoadGroup("ally_voice");
			AllyArrive = LoadGroup("ally_arrive");
			AllyLeave = LoadGroup("ally_leave");
			AllyZap = LoadGroup("ally_zap");
			AllyHum = LoadGroup("ally_hum");
			Plugin.Log.LogInfo((object)$"Loaded sounds from {SoundDir}: chant={Chant.Length} whisper={Whisper.Length} bite={Bite.Length} hurt={Hurt.Length} death={Death.Length} jingle={Jingle.Length} allyVoice={AllyVoiceDefault.Length}");
		}

		private static AudioClip[] LoadGroup(string prefix)
		{
			List<AudioClip> list = new List<AudioClip>();
			try
			{
				foreach (string item in Directory.GetFiles(SoundDir, prefix + "*.wav").OrderBy<string, string>((string f) => f, StringComparer.OrdinalIgnoreCase))
				{
					AudioClip val = WavLoader.Load(item);
					if ((Object)(object)val != (Object)null)
					{
						((Object)val).name = Path.GetFileNameWithoutExtension(item);
						keepAlive.Add((Object)(object)val);
						list.Add(val);
						LoadFireWindows(item, val);
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Could not load sound group '" + prefix + "': " + ex.Message));
			}
			return list.ToArray();
		}

		public static IEnumerator LoadCustomVoice(string pluginDir, string configDir)
		{
			List<string> obj = new List<string>
			{
				Path.Combine(pluginDir, "sounds"),
				pluginDir,
				Path.Combine(configDir, "KeysMonster")
			};
			List<string> list = new List<string>();
			foreach (string item in obj)
			{
				try
				{
					if (!Directory.Exists(item))
					{
						continue;
					}
					string[] files = Directory.GetFiles(item, "caseoh*.*");
					foreach (string file in files)
					{
						switch (Path.GetExtension(file).ToLowerInvariant())
						{
						case ".wav":
						case ".ogg":
						case ".mp3":
							if (!list.Any((string f) => string.Equals(f, file, StringComparison.OrdinalIgnoreCase)))
							{
								list.Add(file);
							}
							break;
						}
					}
				}
				catch (Exception ex)
				{
					Plugin.Log.LogWarning((object)("Could not scan '" + item + "' for a CaseOh clip: " + ex.Message));
				}
			}
			List<AudioClip> clips = new List<AudioClip>();
			foreach (string file2 in list.OrderBy<string, string>((string f) => f, StringComparer.OrdinalIgnoreCase))
			{
				string text = Path.GetExtension(file2).ToLowerInvariant();
				AudioClip clip = null;
				if (text == ".wav")
				{
					clip = WavLoader.Load(file2);
				}
				if ((Object)(object)clip == (Object)null)
				{
					AudioType val = (AudioType)((text == ".ogg") ? 14 : ((text == ".mp3") ? 13 : 20));
					UnityWebRequest request = UnityWebRequestMultimedia.GetAudioClip(new Uri(file2).AbsoluteUri, val);
					try
					{
						yield return request.SendWebRequest();
						if ((int)request.result == 1)
						{
							try
							{
								clip = DownloadHandlerAudioClip.GetContent(request);
							}
							catch (Exception ex2)
							{
								Plugin.Log.LogWarning((object)("Could not decode '" + file2 + "': " + ex2.Message));
							}
						}
						else
						{
							Plugin.Log.LogWarning((object)("Could not load '" + file2 + "': " + request.error));
						}
					}
					finally
					{
						((IDisposable)request)?.Dispose();
					}
				}
				if ((Object)(object)clip != (Object)null)
				{
					((Object)clip).name = Path.GetFileNameWithoutExtension(file2);
					keepAlive.Add((Object)(object)clip);
					clips.Add(clip);
					LoadFireWindows(file2, clip);
					Plugin.Log.LogInfo((object)$"Using your CaseOh clip: {Path.GetFileName(file2)} ({clip.length:0.0}s)");
				}
			}
			AllyVoiceCustom = clips.ToArray();
			if (AllyVoiceCustom.Length == 0)
			{
				Plugin.Log.LogInfo((object)"No extra caseoh.wav/.ogg/.mp3 found - CaseOh uses the bundled clip.");
			}
		}

		public static Sound MakeSound(AudioClip[] clips, float volume, float pitch = 1f, float pitchRandom = 0.06f, float falloff = 1f, AudioType type = (AudioType)0, float spatialBlend = 1f)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			//IL_0018: 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_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Expected O, but got Unknown
			Sound val = new Sound();
			val.Sounds = (AudioClip[])(((object)clips) ?? ((object)new AudioClip[0]));
			val.Type = type;
			val.Volume = volume;
			val.VolumeRandom = 0.03f;
			val.Pitch = pitch;
			val.PitchRandom = pitchRandom;
			val.SpatialBlend = spatialBlend;
			val.FalloffMultiplier = falloff;
			val.OffscreenVolume = 1f;
			val.OffscreenFalloff = 1f;
			val.onLoopComplete = new UnityEvent();
			if (val.LowPassIgnoreColliders == null)
			{
				val.LowPassIgnoreColliders = new List<Collider>();
			}
			return val;
		}

		public static AudioSource Play(Sound sound, Vector3 position, float volumeMultiplier = 1f)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (sound == null || sound.Sounds == null || sound.Sounds.Length == 0)
				{
					return null;
				}
				return sound.Play(position, volumeMultiplier, 1f, 1f, 1f);
			}
			catch (Exception arg)
			{
				Plugin.LogOnce("sound-play", $"Sound playback failed: {arg}");
				return null;
			}
		}
	}
	internal static class WavLoader
	{
		public static AudioClip Load(string path)
		{
			try
			{
				byte[] array = File.ReadAllBytes(path);
				if (array.Length < 44 || array[0] != 82 || array[1] != 73 || array[2] != 70 || array[3] != 70 || array[8] != 87 || array[9] != 65 || array[10] != 86 || array[11] != 69)
				{
					Plugin.Log.LogWarning((object)("'" + Path.GetFileName(path) + "' is not a RIFF/WAVE file."));
					return null;
				}
				int num = 1;
				int num2 = 1;
				int num3 = 44100;
				int num4 = 16;
				int num5 = -1;
				int num6 = 0;
				int num7 = 12;
				while (num7 + 8 <= array.Length)
				{
					string text = Encoding.ASCII.GetString(array, num7, 4);
					int num8 = BitConverter.ToInt32(array, num7 + 4);
					int num9 = num7 + 8;
					if (text == "fmt ")
					{
						num = BitConverter.ToUInt16(array, num9);
						num2 = BitConverter.ToUInt16(array, num9 + 2);
						num3 = BitConverter.ToInt32(array, num9 + 4);
						num4 = BitConverter.ToUInt16(array, num9 + 14);
						if (num == 65534 && num8 >= 26)
						{
							num = BitConverter.ToUInt16(array, num9 + 24);
						}
					}
					else if (text == "data")
					{
						num5 = num9;
						num6 = Mathf.Min((num8 < 0) ? int.MaxValue : num8, array.Length - num9);
						break;
					}
					num7 = num9 + num8 + (num8 & 1);
				}
				if (num5 < 0 || num2 < 1 || (num != 1 && num != 3))
				{
					Plugin.Log.LogWarning((object)$"'{Path.GetFileName(path)}' uses an unsupported WAV encoding (format {num}).");
					return null;
				}
				int num10 = num4 / 8;
				if (num10 < 1)
				{
					return null;
				}
				int num11 = num6 / num10;
				num11 -= num11 % num2;
				if (num11 <= 0)
				{
					return null;
				}
				float[] array2 = new float[num11];
				for (int i = 0; i < num11; i++)
				{
					int num12 = num5 + i * num10;
					switch (num4)
					{
					case 8:
						array2[i] = (float)(array[num12] - 128) / 128f;
						break;
					case 16:
						array2[i] = (float)BitConverter.ToInt16(array, num12) / 32768f;
						break;
					case 24:
						array2[i] = (float)(array[num12] | (array[num12 + 1] << 8) | ((sbyte)array[num12 + 2] << 16)) / 8388608f;
						break;
					case 32:
						array2[i] = ((num == 3) ? BitConverter.ToSingle(array, num12) : ((float)BitConverter.ToInt32(array, num12) / 2.1474836E+09f));
						break;
					default:
						return null;
					}
				}
				AudioClip obj = AudioClip.Create(Path.GetFileNameWithoutExtension(path), num11 / num2, num2, num3, false);
				obj.SetData(array2, 0);
				((Object)obj).hideFlags = (HideFlags)61;
				return obj;
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Could not read '" + Path.GetFileName(path) + "': " + ex.Message));
				return null;
			}
		}
	}
	internal static class CaseOhDirector
	{
		private static float nextAllowed;

		private static bool IsHost => SemiFunc.IsMasterClientOrSingleplayer();

		public static void OnKeysNotice(PlayerAvatar player)
		{
			try
			{
				if (IsHost && Plugin.AllyEnabled.Value && !Object.op_Implicit((Object)(object)CaseOhAlly.Current) && !(Time.time < nextAllowed))
				{
					if (Random.value * 100f >= Plugin.AllyChance.Value)
					{
						nextAllowed = Time.time + 15f;
					}
					else
					{
						Summon(player, force: false);
					}
				}
			}
			catch (Exception arg)
			{
				Plugin.LogOnce("ally-notice", $"CaseOh roll failed: {arg}");
			}
		}

		public static bool Summon(PlayerAvatar player, bool force)
		{
			//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_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown 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_0080: 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_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: 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_0093: Unknown result type (might be due to invalid IL or missing references)
			if (!IsHost || Object.op_Implicit((Object)(object)CaseOhAlly.Current) || !Object.op_Implicit((Object)(object)Templates.AllyPrefab) || !Object.op_Implicit((Object)(object)player))
			{
				return false;
			}
			if (!force && !Plugin.AllyEnabled.Value)
			{
				return false;
			}
			Templates.SeedPools();
			Vector3 val = FindSpot(player);
			Vector3 val2 = ((Component)player).transform.position - val;
			val2.y = 0f;
			Quaternion val3 = ((((Vector3)(ref val2)).sqrMagnitude > 0.01f) ? Quaternion.LookRotation(((Vector3)(ref val2)).normalized) : Quaternion.identity);
			GameObject val4 = (GameManager.Multiplayer() ? PhotonNetwork.InstantiateRoomObject("KeysMonster/CaseOh Ally", val, val3, (byte)0, (object[])null) : Object.Instantiate<GameObject>(Templates.AllyPrefab, val, val3));
			if (!Object.op_Implicit((Object)(object)val4))
			{
				return false;
			}
			CaseOhAlly component = val4.GetComponent<CaseOhAlly>();
			if (Object.op_Implicit((Object)(object)component))
			{
				component.followPlayer = player;
			}
			nextAllowed = Time.time + Plugin.AllyDuration.Value + Plugin.AllyCooldown.Value;
			Plugin.Log.LogInfo((object)"Commander CaseOh has arrived.");
			return true;
		}

		internal static int WorldMask()
		{
			return LayerMask.GetMask(new string[2] { "Default", "StaticGrabObject" });
		}

		internal static NavMeshQueryFilter Filter()
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			NavMeshQueryFilter result = default(NavMeshQueryFilter);
			((NavMeshQueryFilter)(ref result)).agentTypeID = (Templates.HasAgentType ? Templates.AgentTypeId : 0);
			((NavMeshQueryFilter)(ref result)).areaMask = -1;
			return result;
		}

		internal static Vector3 FindSpot(PlayerAvatar player)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: 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_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: 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_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)
			//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_00b4: 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_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: 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_0102: 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)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: 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_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position = ((Component)player).transform.position;
			Vector3 forward = ((Component)player).transform.forward;
			forward.y = 0f;
			if (((Vector3)(ref forward)).sqrMagnitude < 0.01f)
			{
				forward = Vector3.forward;
			}
			((Vector3)(ref forward)).Normalize();
			NavMeshQueryFilter val = Filter();
			int num = WorldMask();
			Vector3 result = position;
			bool flag = false;
			NavMeshHit val3 = default(NavMeshHit);
			for (int i = 0; i < 16; i++)
			{
				float num2 = ((i < 6) ? 70f : 180f);
				float num3 = Random.Range(0f - num2, num2);
				Vector3 val2 = Quaternion.Euler(0f, num3, 0f) * forward;
				if (NavMesh.SamplePosition(position + val2 * Random.Range(2.2f, 3.6f), ref val3, 1.5f, val) && !(Mathf.Abs(((NavMeshHit)(ref val3)).position.y - position.y) > 1.5f))
				{
					if (!flag)
					{
						result = ((NavMeshHit)(ref val3)).position;
						flag = true;
					}
					if (!Physics.Linecast(position + Vector3.up * 1.2f, ((NavMeshHit)(ref val3)).position + Vector3.up * 1.2f, num, (QueryTriggerInteraction)1))
					{
						return ((NavMeshHit)(ref val3)).position;
					}
				}
			}
			return result;
		}
	}
	public class CaseOhAlly : MonoBehaviourPun, IPunObservable
	{
		internal static CaseOhAlly Current;

		internal PlayerAvatar followPlayer;

		private Transform visual;

		private Transform gunArm;

		private Transform muzzle;

		private Transform beam;

		private Light muzzleLight;

		private Sound sfxArrive;

		private Sound sfxLeave;

		private Sound sfxZap;

		private Sound sfxVoice;

		private AudioSource voiceSource;

		private Vector2[] voiceWindows;

		private float voiceGap;

		internal bool firing;

		private bool leaving;

		private Vector3 aimPoint;

		private float yaw;

		private Vector3 netPosition;

		private float netYaw;

		private float lifeTimer;

		private float leaveTimer;

		private float retargetTimer;

		private float burstTimer = 0.6f;

		private bool burstOn;

		private float tickTimer;

		private Enemy target;

		private float pathTimer;

		private float stuckTimer;

		private NavMeshPath path;

		private Vector3[] corners;

		private int cornerIndex;

		private bool moving;

		private float appear;

		private float zapTimer;

		private bool leaveSoundPlayed;

		private float seed;

		internal float VoiceTime
		{
			get
			{
				if (!Object.op_Implicit((Object)(object)voiceSource) || !voiceSource.isPlaying)
				{
					return -1f;
				}
				return voiceSource.time;
			}
		}

		private static bool IsHost => SemiFunc.IsMasterClientOrSingleplayer();

		private void Awake()
		{
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: 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_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: 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)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: 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_00ca: 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)
			//IL_0162: Expected O, but got Unknown
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Expected O, but got Unknown
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			Current = this;
			seed = Random.value * 10f;
			visual = ((Component)this).transform.Find("Visual");
			gunArm = (Object.op_Implicit((Object)(object)visual) ? visual.Find("Gun Arm") : null);
			muzzle = (Object.op_Implicit((Object)(object)gunArm) ? gunArm.Find("Muzzle") : null);
			beam = ((Component)this).transform.Find("Beam");
			if (Object.op_Implicit((Object)(object)beam))
			{
				((Component)beam).gameObject.SetActive(false);
			}
			if (Object.op_Implicit((Object)(object)visual))
			{
				visual.localScale = Vector3.one * 0.001f;
			}
			netPosition = ((Component)this).transform.position;
			yaw = (netYaw = ((Component)this).transform.eulerAngles.y);
			aimPoint = ((Component)this).transform.position + ((Component)this).transform.forward * 3f + Vector3.up;
			lifeTimer = ((Plugin.AllyDuration != null) ? Plugin.AllyDuration.Value : 25f);
			path = new NavMeshPath();
			if (Object.op_Implicit((Object)(object)muzzle))
			{
				GameObject val = new GameObject("Ray Light");
				val.transform.SetParent(muzzle, false);
				muzzleLight = val.AddComponent<Light>();
				muzzleLight.type = (LightType)2;
				muzzleLight.color = new Color(0.35f, 1f, 0.45f);
				muzzleLight.range = 5f;
				muzzleLight.intensity = 0f;
				muzzleLight.shadows = (LightShadows)0;
			}
			float num = ((Plugin.AllyVoiceVolume != null) ? Plugin.AllyVoiceVolume.Value : 1f);
			sfxArrive = Assets.MakeSound(Assets.AllyArrive, 0.6f, 1f, 0.03f, 2f, (AudioType)0);
			sfxLeave = Assets.MakeSound(Assets.AllyLeave, 0.55f, 1f, 0.03f, 2f, (AudioType)0);
			sfxZap = Assets.MakeSound(Assets.AllyZap, 0.4f, 1f, 0.1f, 1.6f, (AudioType)0);
			sfxVoice = Assets.MakeSound(Assets.AllyVoice, 0.95f * num, 1f, 0f, 3f, (AudioType)0);
			sfxVoice.VolumeRandom = 0f;
		}

		private void Start()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			Assets.Play(sfxArrive, ((Component)this).transform.position + Vector3.up);
			StartVoice();
		}

		private void StartVoice()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			voiceGap = 0f;
			voiceSource = Assets.Play(sfxVoice, HeadPosition());
			voiceWindows = (Object.op_Implicit((Object)(object)voiceSource) ? Assets.FireWindows(voiceSource.clip) : null);
		}

		private bool VoiceInFireWindow()
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			if (voiceWindows == null || !Object.op_Implicit((Object)(object)voiceSource) || !voiceSource.isPlaying)
			{
				return false;
			}
			float time = voiceSource.time;
			Vector2[] array = voiceWindows;
			foreach (Vector2 val in array)
			{
				if (time >= val.x && time <= val.y)
				{
					return true;
				}
			}
			return false;
		}

		private void OnDestroy()
		{
			if ((Object)(object)Current == (Object)(object)this)
			{
				Current = null;
			}
			if (Object.op_Implicit((Object)(object)voiceSource))
			{
				voiceSource.Stop();
			}
		}

		private Vector3 HeadPosition()
		{
			//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_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			return ((Component)this).transform.position + Vector3.up * 1.8f;
		}

		private void Update()
		{
			try
			{
				if (IsHost)
				{
					HostUpdate();
				}
				else
				{
					RemoteUpdate();
				}
				Present();
			}
			catch (Exception arg)
			{
				Plugin.LogOnce("ally-update", $"CaseOh update failed: {arg}");
			}
		}

		private void HostUpdate()
		{
			//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)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			float deltaTime = Time.deltaTime;
			if (leaving)
			{
				firing = false;
				leaveTimer -= deltaTime;
				if (leaveTimer <= 0f)
				{
					leaveTimer = 999f;
					Despawn();
				}
				return;
			}
			lifeTimer -= deltaTime;
			if (!PlayerValid(followPlayer))
			{
				followPlayer = NearestPlayer();
			}
			bool flag = Object.op_Implicit((Object)(object)LevelGenerator.Instance) && LevelGenerator.Instance.Generated;
			if (lifeTimer <= 0f || !Object.op_Implicit((Object)(object)followPlayer) || !flag)
			{
				leaving = true;
				firing = false;
				leaveTimer = 1.3f;
				return;
			}
			retargetTimer -= deltaTime;
			if (!TargetValid(target))
			{
				target = null;
				burstOn = false;
			}
			if (retargetTimer <= 0f)
			{
				retargetTimer = (firing ? 1.1f : 0.3f);
				Enemy val = PickTarget();
				if (Object.op_Implicit((Object)(object)val))
				{
					target = val;
				}
			}
			if (voiceWindows != null)
			{
				firing = VoiceInFireWindow();
			}
			else
			{
				if (Object.op_Implicit((Object)(object)target))
				{
					burstTimer -= deltaTime;
					if (burstTimer <= 0f)
					{
						burstOn = !burstOn;
						burstTimer = (burstOn ? 2.4f : 0.9f);
						tickTimer = 0.12f;
					}
				}
				else
				{
					burstOn = false;
					burstTimer = Mathf.Min(burstTimer, 0.35f);
				}
				firing = burstOn && Object.op_Implicit((Object)(object)target);
			}
			if (firing)
			{
				if (Object.op_Implicit((Object)(object)target))
				{
					aimPoint = TargetPoint(target);
					tickTimer -= deltaTime;
					if (tickTimer <= 0f)
					{
						tickTimer = 0.33f;
						Zap(target);
					}
				}
				else
				{
					aimPoint = FreeAim();
				}
			}
			Move(deltaTime);
		}

		private Vector3 FreeAim()
		{
			//IL_0001: 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_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//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_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: 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_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = GunOrigin();
			Vector3 val2 = (Object.op_Implicit((Object)(object)followPlayer) ? ((Component)followPlayer).transform.forward : ((Component)this).transform.forward);
			val2.y = 0f;
			if (((Vector3)(ref val2)).sqrMagnitude < 0.01f)
			{
				val2 = ((Component)this).transform.forward;
			}
			Vector3 val3 = Quaternion.Euler(0f, Mathf.Sin(Time.time * 2.3f + seed) * 28f, 0f) * ((Vector3)(ref val2)).normalized;
			val3.y = Mathf.Sin(Time.time * 3.1f + seed) * 0.06f;
			((Vector3)(ref val3)).Normalize();
			float num = 9f;
			RaycastHit val4 = default(RaycastHit);
			if (Physics.Raycast(val, val3, ref val4, num, CaseOhDirector.WorldMask(), (QueryTriggerInteraction)1))
			{
				num = ((RaycastHit)(ref val4)).distance;
			}
			return val + val3 * num;
		}

		private static bool PlayerValid(PlayerAvatar player)
		{
			if (Object.op_Implicit((Object)(object)player))
			{
				return !player.isDisabled;
			}
			return false;
		}

		private PlayerAvatar NearestPlayer()
		{
			//IL_004a: 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_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)
			PlayerAvatar result = null;
			float num = float.MaxValue;
			if (!Object.op_Implicit((Object)(object)GameDirector.instance) || GameDirector.instance.PlayerList == null)
			{
				return null;
			}
			foreach (PlayerAvatar player in GameDirector.instance.PlayerList)
			{
				if (PlayerValid(player))
				{
					Vector3 val = ((Component)player).transform.position - ((Component)this).transform.position;
					float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude;
					if (sqrMagnitude < num)
					{
						num = sqrMagnitude;
						result = player;
					}
				}
			}
			return result;
		}

		private Vector3 GunOrigin()
		{
			//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_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			return ((Component)this).transform.position + Vector3.up * 1.4f;
		}

		private static Vector3 TargetPoint(Enemy enemy)
		{
			//IL_0013: 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_0039: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)enemy.CenterTransform))
			{
				return enemy.CenterTransform.position;
			}
			if (enemy.HasRigidbody && Object.op_Implicit((Object)(object)enemy.Rigidbody))
			{
				return ((Component)enemy.Rigidbody).transform.position;
			}
			return ((Component)enemy).transform.position;
		}

		private bool TargetValid(Enemy enemy)
		{
			//IL_0058: 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_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_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)enemy) || !((Component)enemy).gameObject.activeInHierarchy)
			{
				return false;
			}
			if (Object.op_Implicit((Object)(object)enemy.EnemyParent) && !enemy.EnemyParent.Spawned)
			{
				return false;
			}
			if (enemy.HasHealth && Object.op_Implicit((Object)(object)enemy.Health) && enemy.Health.dead)
			{
				return false;
			}
			Vector3 val = TargetPoint(enemy);
			Vector3 val2 = GunOrigin();
			Vector3 val3 = val - val2;
			if (((Vector3)(ref val3)).sqrMagnitude > 256f)
			{
				return false;
			}
			return !Physics.Linecast(val2, val, CaseOhDirector.WorldMask(), (QueryTriggerInteraction)1);
		}

		private Enemy PickTarget()
		{
			//IL_002d: 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_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: 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)
			Enemy best = null;
			float bestScore = float.MaxValue;
			Vector3 protect = (Object.op_Implicit((Object)(object)followPlayer) ? ((Component)followPlayer).transform.position : ((Component)this).transform.position);
			if (Plugin.AllyTargetsAllEnemies.Value && Object.op_Implicit((Object)(object)EnemyDirector.instance) && EnemyDirector.instance.enemiesSpawned != null)
			{
				foreach (EnemyParent item in EnemyDirector.instance.enemiesSpawned)
				{
					if (Object.op_Implicit((Object)(object)item) && Object.op_Implicit((Object)(object)item.Enemy))
					{
						Consider(item.Enemy, protect, ref best, ref bestScore);
					}
				}
			}
			else
			{
				foreach (EnemyKeys item2 in EnemyKeys.All)
				{
					if (Object.op_Implicit((Object)(object)item2) && Object.op_Implicit((Object)(object)item2.enemy))
					{
						Consider(item2.enemy, protect, ref best, ref bestScore);
					}
				}
			}
			return best;
		}

		private void Consider(Enemy enemy, Vector3 protect, ref Enemy best, ref float bestScore)
		{
			//IL_000b: 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)
			if (TargetValid(enemy))
			{
				float num = Vector3.Distance(TargetPoint(enemy), protect);
				if (enemy.IsStunned())
				{
					num += 6f;
				}
				if (num < bestScore)
				{
					bestScore = num;
					best = enemy;
				}
			}
		}

		private void Zap(Enemy enemy)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: 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: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = TargetPoint(enemy) - GunOrigin();
			val = ((((Vector3)(ref val)).sqrMagnitude > 0.001f) ? ((Vector3)(ref val)).normalized : ((Component)this).transform.forward);
			if (enemy.HasStateStunned && Object.op_Implicit((Object)(object)enemy.StateStunned))
			{
				enemy.StateStunned.Set(1.4f);
			}
			if (enemy.HasRigidbody && Object.op_Implicit((Object)(object)enemy.Rigidbody) && Object.op_Implicit((Object)(object)enemy.Rigidbody.rb))
			{
				enemy.Rigidbody.rb.AddForce(val * 5f + Vector3.up * 1.5f, (ForceMode)1);
			}
			int value = Plugin.AllyDamage.Value;
			if (value > 0 && enemy.HasHealth && Object.op_Implicit((Object)(object)enemy.Health) && (Plugin.AllyCanKill.Value || enemy.Health.healthCurrent > value))
			{
				enemy.Health.Hurt(value, val);
			}
		}

		private void Move(float dt)
		{
			//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_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: 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)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: 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_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0288: Unknown result type (might be due to invalid IL or missing references)
			//IL_028d: Unknown result type (might be due to invalid IL or missing references)
			//IL_028e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_0283: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: Unknown result type (might be due to invalid IL or missing references)
			//IL_027b: Unknown result type (might be due to invalid IL or missing references)
			//IL_027c: 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_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fb: 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_02b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: 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_01f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: 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_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: 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)
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Invalid comparison between Unknown and I4
			Vector3 val = ((Component)this).transform.position;
			Vector3 position = ((Component)followPlayer).transform.position;
			Vector3 val2 = position - val;
			float num = Mathf.Abs(val2.y);
			val2.y = 0f;
			float magnitude = ((Vector3)(ref val2)).magnitude;
			if (magnitude > 22f || num > 6f || stuckTimer > 2.5f)
			{
				stuckTimer = 0f;
				corners = null;
				val = CaseOhDirector.FindSpot(followPlayer);
				((Component)this).transform.position = val;
				return;
			}
			pathTimer -= dt;
			if (pathTimer <= 0f)
			{
				pathTimer = 0.35f;
				moving = magnitude > (moving ? 2.6f : 3.4f);
				corners = null;
				if (moving)
				{
					Vector3 val3 = -val2;
					Vector3 val4 = position + ((((Vector3)(ref val3)).sqrMagnitude > 0.01f) ? ((Vector3)(ref val3)).normalized : Vector3.back) * 2.3f;
					NavMeshQueryFilter val5 = CaseOhDirector.Filter();
					NavMeshHit val6 = default(NavMeshHit);
					NavMeshHit val7 = default(NavMeshHit);
					if (NavMesh.SamplePosition(val, ref val6, 2f, val5) && NavMesh.SamplePosition(val4, ref val7, 2.5f, val5) && NavMesh.CalculatePath(((NavMeshHit)(ref val6)).position, ((NavMeshHit)(ref val7)).position, val5, path) && (int)path.status != 2)
					{
						corners = path.corners;
						cornerIndex = ((corners.Length > 1) ? 1 : 0);
					}
				}
			}
			Vector3 val8 = Vector3.zero;
			if (moving)
			{
				if (corners != null && cornerIndex < corners.Length)
				{
					stuckTimer = 0f;
					float num2 = ((magnitude > 8f) ? 7.5f : 4.6f) * dt;
					Vector3 val9 = corners[cornerIndex] - val;
					if (((Vector3)(ref val9)).magnitude <= num2)
					{
						val = corners[cornerIndex];
						cornerIndex++;
					}
					else
					{
						val += ((Vector3)(ref val9)).normalized * num2;
					}
					val8 = val9;
				}
				else
				{
					stuckTimer += dt;
				}
			}
			((Component)this).transform.position = val;
			Vector3 val10 = (firing ? (aimPoint - val) : ((((Vector3)(ref val8)).sqrMagnitude > 0.01f) ? val8 : (position - val)));
			val10.y = 0f;
			if (((Vector3)(ref val10)).sqrMagnitude > 0.01f)
			{
				Quaternion val11 = Quaternion.LookRotation(((Vector3)(ref val10)).normalized);
				float y = ((Quaternion)(ref val11)).eulerAngles.y;
				yaw = Mathf.MoveTowardsAngle(yaw, y, 420f * dt);
			}
			((Component)this).transform.rotation = Quaternion.Euler(0f, yaw, 0f);
		}

		private void Despawn()
		{
			if (GameManager.Multiplayer())
			{
				PhotonNetwork.Destroy(((Component)this).gameObject);
			}
			else
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}
		}

		private void RemoteUpdate()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_004a: 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_0067: 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_00b0: Unknown result type (might be due to invalid IL or missing references)
			float deltaTime = Time.deltaTime;
			Vector3 val = netPosition - ((Component)this).transform.position;
			if (((Vector3)(ref val)).sqrMagnitude > 36f)
			{
				((Component)this).transform.position = netPosition;
			}
			else
			{
				((Component)this).transform.position = Vector3.Lerp(((Component)this).transform.position, netPosition, 1f - Mathf.Exp(-12f * deltaTime));
			}
			yaw = Mathf.LerpAngle(yaw, netYaw, 1f - Mathf.Exp(-12f * deltaTime));
			((Component)this).transform.rotation = Quaternion.Euler(0f, yaw, 0f);
		}

		public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
		{
			//IL_006a: 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_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			if (stream.IsWriting)
			{
				stream.SendNext((object)((Component)this).transform.position);
				stream.SendNext((object)yaw);
				stream.SendNext((object)firing);
				stream.SendNext((object)aimPoint);
				stream.SendNext((object)leaving);
			}
			else
			{
				netPosition = (Vector3)stream.ReceiveNext();
				netYaw = (float)stream.ReceiveNext();
				firing = (bool)stream.ReceiveNext();
				aimPoint = (Vector3)stream.ReceiveNext();
				leaving = (bool)stream.ReceiveNext();
			}
		}

		private void Present()
		{
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: 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_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: 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)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_028f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0294: Unknown result type (might be due to invalid IL or missing references)
			//IL_0297: Unknown result type (might be due to invalid IL or missing references)
			//IL_029c: 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_02a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_041b: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ed: 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_02f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_030d: Unknown result type (might be due to invalid IL or missing references)
			float deltaTime = Time.deltaTime;
			float num = Time.time + seed;
			appear = Mathf.MoveTowards(appear, leaving ? 0f : 1f, deltaTime * (leaving ? 1.1f : 1.8f));
			float num2 = appear * appear * (3f - 2f * appear);
			if (Object.op_Implicit((Object)(object)visual))
			{
				float num3 = 0.16f + Mathf.Sin(num * 2.6f) * 0.05f;
				float num4 = (leaving ? ((1f - num2) * 2.5f) : 0f);
				visual.localScale = Vector3.one * Mathf.Max(0.001f, num2);
				visual.localPosition = new Vector3(0f, num3 + num4, 0f);
				visual.localRotation = Quaternion.Euler(0f, (1f - num2) * 540f, Mathf.Sin(num * 1.7f) * 2f);
			}
			if (leaving && !leaveSoundPlayed)
			{
				leaveSoundPlayed = true;
				Assets.Play(sfxLeave, ((Component)this).transform.position + Vector3.up);
			}
			bool flag = firing && !leaving && appear > 0.9f;
			if (Object.op_Implicit((Object)(object)gunArm) && Object.op_Implicit((Object)(object)visual))
			{
				Quaternion val = visual.rotation * Quaternion.Euler(38f, -8f, 0f);
				if (flag)
				{
					Vector3 val2 = aimPoint - gunArm.position;
					if (((Vector3)(ref val2)).sqrMagnitude > 0.01f)
					{
						val = Quaternion.LookRotation(((Vector3)(ref val2)).normalized, Vector3.up);
					}
				}
				gunArm.rotation = Quaternion.Slerp(gunArm.rotation, val, 1f - Mathf.Exp(-14f * deltaTime));
			}
			if (Object.op_Implicit((Object)(object)beam))
			{
				bool flag2 = flag && Object.op_Implicit((Object)(object)muzzle);
				if (((Component)beam).gameObject.activeSelf != flag2)
				{
					((Component)beam).gameObject.SetActive(flag2);
				}
				if (flag2)
				{
					Vector3 position = muzzle.position;
					Vector3 val3 = aimPoint - position;
					float magnitude = ((Vector3)(ref val3)).magnitude;
					if (magnitude > 0.05f)
					{
						float num5 = 0.03f + Mathf.Abs(Mathf.Sin(num * 47f)) * 0.025f;
						beam.position = position;
						beam.rotation = Quaternion.LookRotation(val3 / magnitude, Vector3.up);
						beam.localScale = new Vector3(num5, num5, magnitude);
					}
				}
			}
			if (Object.op_Implicit((Object)(object)muzzleLight))
			{
				float num6 = (flag ? (2.2f + Mathf.Sin(num * 47f) * 0.6f) : 0f);
				muzzleLight.intensity = Mathf.Lerp(muzzleLight.intensity, num6, 1f - Mathf.Exp(-20f * deltaTime));
			}
			if (flag && voiceWindows == null)
			{
				zapTimer -= deltaTime;
				if (zapTimer <= 0f)
				{
					zapTimer = 0.33f;
					Assets.Play(sfxZap, Object.op_Implicit((Object)(object)muzzle) ? muzzle.position : (((Component)this).transform.position + Vector3.up));
				}
			}
			else
			{
				zapTimer = 0f;
			}
			if (Object.op_Implicit((Object)(object)voiceSource) && voiceSource.isPlaying)
			{
				((Component)voiceSource).transform.position = HeadPosition();
				if (leaving)
				{
					voiceSource.volume = Mathf.MoveTowards(voiceSource.volume, 0f, deltaTime * 1.2f);
				}
			}
			else if (!leaving && voiceWindows != null && appear > 0.9f)
			{
				voiceGap += deltaTime;
				if (voiceGap > 0.7f)
				{
					StartVoice();
				}
			}
		}
	}
	internal static class CaseOhBuilder
	{
		public static GameObject Build(Transform holder)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: 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_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: 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_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0256: Unknown result type (might be due to invalid IL or missing references)
			//IL_026a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_0299: 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_02d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0311: Unknown result type (might be due to invalid IL or missing references)
			//IL_0339: Unknown result type (might be due to invalid IL or missing references)
			//IL_034d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0375: Unknown result type (might be due to invalid IL or missing references)
			//IL_0395: Unknown result type (might be due to invalid IL or missing references)
			//IL_039b: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0405: Unknown result type (might be due to invalid IL or missing references)
			//IL_0420: Unknown result type (might be due to invalid IL or missing references)
			//IL_0434: Unknown result type (might be due to invalid IL or missing references)
			//IL_045c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0470: Unknown result type (might be due to invalid IL or missing references)
			//IL_0495: Unknown result type (might be due to invalid IL or missing references)
			//IL_049b: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_051f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0533: Unknown result type (might be due to invalid IL or missing references)
			//IL_0551: Unknown result type (might be due to invalid IL or missing references)
			//IL_0565: Unknown result type (might be due to invalid IL or missing references)
			//IL_0580: Unknown result type (might be due to invalid IL or missing references)
			//IL_0586: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_05de: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0602: Unknown result type (might be due to invalid IL or missing references)
			//IL_0627: Unknown result type (might be due to invalid IL or missing references)
			//IL_062d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0654: Unknown result type (might be due to invalid IL or missing references)
			//IL_0674: Unknown result type (might be due to invalid IL or missing references)
			//IL_067a: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_06e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0713: Unknown result type (might be due to invalid IL or missing references)
			//IL_073b: Unknown result type (might be due to invalid IL or missing references)
			//IL_074f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0774: Unknown result type (might be due to invalid IL or missing references)
			//IL_077a: Unknown result type (might be due to invalid IL or missing references)
			//IL_07a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_07b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_07d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_07e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0805: Unknown result type (might be due to invalid IL or missing references)
			//IL_0825: Unknown result type (might be due to invalid IL or missing references)
			//IL_082b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0846: Unknown result type (might be due to invalid IL or missing references)
			//IL_084b: Unknown result type (might be due to invalid IL or missing references)
			//IL_086c: Unknown result type (might be due to invalid IL or missing references)
			//IL_087c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0890: Unknown result type (might be due to invalid IL or missing references)
			//IL_08ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_08c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_08ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_08f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_08fa: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("CaseOh Ally");
			val.transform.SetParent(holder, false);
			Transform transform = new GameObject("Visual").transform;
			transform.SetParent(val.transform, false);
			MeshBuilder meshBuilder = new MeshBuilder();
			meshBuilder.Sphere(new Vector3(0f, 0.98f, 0f), new Vector3(0.56f, 0.52f, 0.5f), 20, 14);
			meshBuilder.Sphere(new Vector3(0f, 1.3f, 0f), new Vector3(0.47f, 0.3f, 0.4f), 16, 10);
			meshBuilder.Sphere(new Vector3(0f, 1.7f, 0.02f), 0.3f, 18, 12);
			meshBuilder.Cylinder(new Vector3(-0.21f, 0.62f, 0f), new Vector3(-0.21f, 0.12f, 0f), 0.18f, 0.155f, 12);
			meshBuilder.Cylinder(new Vector3(0.21f, 0.62f, 0f), new Vector3(0.21f, 0.12f, 0f), 0.18f, 0.155f, 12);
			meshBuilder.Sphere(new Vector3(-0.5f, 1.3f, 0f), 0.145f, 10);
			meshBuilder.Sphere(new Vector3(0.5f, 1.3f, 0f), 0.145f, 10);
			meshBuilder.Cylinder(new Vector3(-0.5f, 1.3f, 0f), new Vector3(-0.68f, 0.86f, 0.1f), 0.125f, 0.105f);
			meshBuilder.BuildObject("Suit", transform, Assets.SuitWhite);
			MeshBuilder meshBuilder2 = new MeshBuilder();
			meshBuilder2.Box(new Vector3(-0.21f, 0.07f, 0.05f), new Vector3(0.32f, 0.14f, 0.44f));
			meshBuilder2.Box(new Vector3(0.21f, 0.07f, 0.05f), new Vector3(0.32f, 0.14f, 0.44f));
			meshBuilder2.Box(new Vector3(0f, 1.15f, -0.48f), new Vector3(0.58f, 0.68f, 0.26f));
			meshBuilder2.Cylinder(new Vector3(-0.16f, 0.86f, -0.48f), new Vector3(-0.16f, 0.74f, -0.48f), 0.07f, 0.1f);
			meshBuilder2.Cylinder(new Vector3(0.16f, 0.86f, -0.48f), new Vector3(0.16f, 0.74f, -0.48f), 0.07f, 0.1f);
			meshBuilder2.Cylinder(new Vector3(0f, 0.74f, 0f), new Vector3(0f, 0.81f, 0f), 0.525f, 0.535f, 20);
			meshBuilder2.Cylinder(new Vector3(0f, 1.44f, 0.01f), new Vector3(0f, 1.51f, 0.01f), 0.27f, 0.27f, 16);
			meshBuilder2.Sphere(new Vector3(-0.69f, 0.81f, 0.11f), 0.125f, 10);
			meshBuilder2.BuildObject("Suit Grey", transform, Assets.SuitGrey);
			MeshBuilder meshBuilder3 = new MeshBuilder();
			meshBuilder3.Box(new Vector3(0.2f, 1.24f, 0.36f), new Vector3(0.17f, 0.12f, 0.08f));
			meshBuilder3.Box(new Vector3(0f, 1.2f, -0.615f), new Vector3(0.42f, 0.08f, 0.02f));
			meshBuilder3.Cylinder(new Vector3(-0.21f, 0.38f, 0f), new Vector3(-0.21f, 0.44f, 0f), 0.185f, 0.185f, 12);
			meshBuilder3.Cylinder(new Vector3(0.21f, 0.38f, 0f), new Vector3(0.21f, 0.44f, 0f), 0.185f, 0.185f, 12);
			meshBuilder3.BuildObject("Suit Trim", transform, Assets.SuitOrange);
			MeshBuilder meshBuilder4 = new MeshBuilder();
			meshBuilder4.Sphere(new Vector3(0f, 1.71f, 0.16f), new Vector3(0.235f, 0.19f, 0.17f), 16, 10);
			meshBuilder4.BuildObject("Visor", transform, Assets.Visor);
			MeshBuilder meshBuilder5 = new MeshBuilder();
			meshBuilder5.Sphere(new Vector3(-0.16f, 0.72f, -0.48f), new Vector3(0.075f, 0.05f, 0.075f), 10, 6);
			meshBuilder5.Sphere(new Vector3(0.16f, 0.72f, -0.48f), new Vector3(0.075f, 0.05f, 0.075f), 10, 6);
			NoShadows(meshBuilder5.BuildObject("Thrusters", transform, Assets.GunGlow));
			Transform transform2 = new GameObject("Gun Arm").transform;
			transform2.SetParent(transform, false);
			transform2.localPosition = new Vector3(0.5f, 1.3f, 0f);
			transform2.localRotation = Quaternion.Euler(38f, -8f, 0f);
			MeshBuilder meshBuilder6 = new MeshBuilder();
			meshBuilder6.Cylinder(Vector3.zero, new Vector3(0f, 0f, 0.5f), 0.125f, 0.105f);
			meshBuilder6.BuildObject("Sleeve", transform2, Assets.SuitWhite);
			MeshBuilder meshBuilder7 = new MeshBuilder();
			meshBuilder7.Sphere(new Vector3(0f, 0f, 0.54f), 0.125f, 10);
			meshBuilder7.BuildObject("Glove", transform2, Assets.SuitGrey);
			MeshBuilder meshBuilder8 = new MeshBuilder();
			meshBuilder8.Box(new Vector3(0f, 0.06f, 0.72f), new Vector3(0.1f, 0.17f, 0.3f));
			meshBuilder8.Box(new Vector3(0f, 0.17f, 0.68f), new Vector3(0.025f, 0.09f, 0.2f));
			meshBuilder8.Cylinder(new Vector3(0f, 0.08f, 0.85f), new Vector3(0f, 0.08f, 1.12f), 0.045f, 0.035f);
			meshBuilder8.Cylinder(new Vector3(0f, 0.08f, 1.12f), new Vector3(0f, 0.08f, 1.17f), 0.03f, 0.1f, 12);
			meshBuilder8.BuildObject("Ray Gun", transform2, Assets.GunMetal);
			MeshBuilder meshBuilder9 = new MeshBuilder();
			meshBuilder9.Sphere(new Vector3(0f, 0.08f, 0.93f), new Vector3(0.075f, 0.075f, 0.03f), 12, 6);
			meshBuilder9.Sphere(new Vector3(0f, 0.08f, 1.02f), new Vector3(0.065f, 0.065f, 0.025f), 12, 6);
			meshBuilder9.Sphere(new Vector3(0f, 0.08f, 1.18f), 0.04f, 10);
			NoShadows(meshBuilder9.BuildObject("Ray Gun Glow", transform2, Assets.GunGlow));
			GameObject val2 = new GameObject("Muzzle");
			val2.transform.SetParent(transform2, false);
			val2.transform.localPosition = new Vector3(0f, 0.08f, 1.2f);
			MeshBuilder meshBuilder10 = new MeshBuilder();
			meshBuilder10.Cylinder(Vector3.zero, new Vector3(0f, 0f, 1f), 1f, 1f);
			GameObject obj = meshBuilder10.BuildObject("Beam", val.transform, Assets.Beam);
			NoShadows(obj);
			obj.SetActive(false);
			PhotonView obj2 = val.AddComponent<PhotonView>();
			CaseOhAlly item = val.AddComponent<CaseOhAlly>();
			obj2.Synchronization = (ViewSynchronization)3;
			obj2.OwnershipTransfer = (OwnershipOption)0;
			obj2.observableSearch = (ObservableSearch)0;
			obj2.ObservedComponents = new List<Component> { (Component)(object)item };
			return val;
		}

		private static void NoShadows(GameObject go)
		{
			Renderer val = (Object.op_Implicit((Object)(object)go) ? go.GetComponent<Renderer>() : null);
			if (Object.op_Implicit((Object)(object)val))
			{
				val.shadowCastingMode = (ShadowCastingMode)0;
				val.receiveShadows = false;
			}
		}
	}
	public class EnemyKeys : MonoBehaviour
	{
		public enum State
		{
			Spawn,
			Idle,
			Roam,
			Investigate,
			Notice,
			Chase,
			Attack,
			Stun,
			Leave,
			Despawn
		}

		internal static readonly List<EnemyKeys> All = new List<EnemyKeys>();

		public State currentState;

		internal Enemy enemy;

		private PhotonView photonView;

		private EnemyParent enemyParent;

		private Transform body;

		private Rigidbody bodyRigidbody;

		private GameObject hurtCollider;

		private KeysVisual visual;

		private ParticleSystem particleBits;

		private ParticleSystem particleDirectionalBits;

		private ParticleSystem particleImpact;

		private Sound sfxChant;

		private Sound sfxCall;

		private Sound sfxWhisper;

		private Sound sfxBite;

		private Sound sfxHurt;

		private Sound sfxDeath;

		private Sound sfxSpawn;

		private Sound sfxJingle;

		private static float lastFullChant = -999f;

		private bool stateImpulse = true;

		private float stateTimer;

		private Vector3 agentDestination;

		private PlayerAvatar playerTarget;

		private float grabAggroTimer;

		private float alertDelay = -1f;

		private PlayerAvatar alertPlayer;

		private State presentedState = (State)(-1);

		private float whisperTimer;

		private float biteTimer;

		private Vector3 lastBodyPosition;

		private float bodySpeed;

		internal PlayerAvatar VisualTarget => playerTarget;

		internal bool IsStunnedVisual
		{
			get
			{
				//IL_001c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0023: Invalid comparison between Unknown and I4
				if (currentState != State.Stun)
				{
					if (Object.op_Implicit((Object)(object)enemy))
					{
						return (int)enemy.CurrentState == 9;
					}
					return false;
				}
				return true;
			}
		}

		internal Vector3 Position
		{
			get
			{
				//IL_001f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0013: Unknown result type (might be due to invalid IL or missing references)
				if (!Object.op_Implicit((Object)(object)body))
				{
					return ((Component)this).transform.position;
				}
				return body.position;
			}
		}

		internal float Tilt
		{
			get
			{
				//IL_0019: 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)
				if (!Object.op_Implicit((Object)(object)body))
				{
					return 0f;
				}
				return Vector3.Angle(body.up, Vector3.up);
			}
		}

		private static bool IsHost => SemiFunc.IsMasterClientOrSingleplayer();

		private bool Calm
		{
			get
			{
				if (currentState != State.Idle && currentState != State.Roam && currentState != State.Investigate)
				{
					return currentState == State.Leave;
				}
				return true;
			}
		}

		private void Awake()
		{
			//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_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Expected O, but got Unknown
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Expected O, but got Unknown
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Expected O, but got Unknown
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Expected O, but got Unknown
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Expected O, but got Unknown
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Expected O, but got Unknown
			enemy = ((Component)this).GetComponent<Enemy>();
			photonView = ((Component)this).GetComponent<PhotonView>();
			Transform parent = ((Component)this).transform.parent;
			enemyParent = ((Component)this).GetComponentInParent<EnemyParent>();
			body = (Object.op_Implicit((Object)(object)parent) ? parent.Find("Rigidbody") : null);
			if (Object.op_Implicit((Object)(object)body))
			{
				Transform val = body.Find("Mesh/Main Animation/Hurt Collider");
				hurtCollider = (Object.op_Implicit((Object)(object)val) ? ((Component)val).gameObject : null);
				visual = ((Component)body).GetComponentInChildren<KeysVisual>(true);
				if (Object.op_Implicit((Object)(object)visual))
				{
					visual.controller = this;
					visual.follow = body;
				}
				lastBodyPosition = body.position;
			}
			if (Object.op_Implicit((Object)(object)hurtCollider))
			{
				hurtCollider.SetActive(false);
			}
			Transform val2 = (Object.op_Implicit((Object)(object)enemyParent) ? ((Component)enemyParent).transform : (Object.op_Implicit((Object)(object)parent) ? parent.parent : null));
			if (Object.op_Implicit((Object)(object)val2))
			{
				particleBits = FindParticles(val2, "Particles/Bits");
				particleDirectionalBits = FindParticles(val2, "Particles/Directional Bits");
				particleImpact = FindParticles(val2, "Particles/Impact");
			}
			EnemyHealth component = ((Component)this).GetComponent<EnemyHealth>();
			if (Object.op_Implicit((Object)(object)component))
			{
				component.onHurt.AddListener(new UnityAction(OnHurt));
				component.onDeath.AddListener(new UnityAction(OnDeath));
			}
			EnemyStateSpawn component2 = ((Component)this).GetComponent<EnemyStateSpawn>();
			if (Object.op_Implicit((Object)(object)component2))
			{
				component2.OnSpawn.AddListener(new UnityAction(OnSpawn));
			}
			EnemyVision component3 = ((Component)this).GetComponent<EnemyVision>();
			if (Object.op_Implicit((Object)(object)component3))
			{
				component3.onVisionTriggered.AddListener(new UnityAction(OnVision));
			}
			EnemyStateInvestigate component4 = ((Component)this).GetComponent<EnemyStateInvestigate>();
			if (Object.op_Implicit((Object)(object)component4))
			{
				component4.onInvestigateTriggered.AddListener(new UnityAction(OnInvestigate));
			}
			EnemyRigidbody val3 = (Object.op_Implicit((Object)(object)body) ? ((Component)body).GetComponent<EnemyRigidbody>() : null);
			if (Object.op_Implicit((Object)(object)val3))
			{
				val3.onGrabbed.AddListener(new UnityAction(OnGrabbed));
			}
			float num = ((Plugin.KeysVolume != null) ? Plugin.KeysVolume.Value : 1f);
			sfxChant = Assets.MakeSound(Assets.Chant, 0.8f * num, 1f, 0.04f, 1.8f, (AudioType)0);
			sfxCall = Assets.MakeSound((Assets.Call.Length != 0) ? Assets.Call : Assets.Chant, 0.7f * num, 1f, 0.08f, 1.6f, (AudioType)0);
			sfxWhisper = Assets.MakeSound((Assets.Whisper.Length != 0) ? Assets.Whisper : Assets.Call, 0.4f * num, 0.97f, 0.12f, 1.1f, (AudioType)0);
			sfxBite = Assets.MakeSound(Assets.Bite, 0.55f * num, 1f, 0.12f, 1f, (AudioType)0);
			sfxHurt = Assets.MakeSound(Assets.Hurt, 0.6f * num, 1f, 0.1f, 1.2f, (AudioType)0);
			sfxDeath = Assets.MakeSound(Assets.Death, 0.75f * num, 1f, 0.06f, 1.5f, (AudioType)0);
			sfxSpawn = Assets.MakeSound(Assets.Spawn, 0.5f * num, 1f, 0.08f, 1.2f, (AudioType)0);
			sfxJingle = Assets.MakeSound(Assets.Jingle, 0.32f * num, 1f, 0.05f, 1f, (AudioType)0);
			Transform val4 = (Object.op_Implicit((Object)(object)body) ? body.Find("Audio Source") : null);
			sfxJingle.Source = (Object.op_Implicit((Object)(object)val4) ? ((Component)val4).GetComponent<AudioSource>() : null);
		}

		private static ParticleSystem FindParticles(Transform root, string path)
		{
			Transform val = root.Find(path);
			if (!Object.op_Implicit((Object)(object)val))
			{
				return null;
			}
			return ((Component)val).GetComponent<ParticleSystem>();
		}

		private void OnEnable()
		{
			//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)
			if (!All.Contains(this))
			{
				All.Add(this);
			}
			presentedState = (State)(-1);
			if (Object.op_Implicit((Object)(object)body))
			{
				lastBodyPosition = body.position;
			}
			bodySpeed = 0f;
		}

		private void OnDisable()
		{
			All.Remove(this);
			if (Object.op_Implicit((Object)(object)hurtCollider))
			{
				hurtCollider.SetActive(false);
			}
		}

		private void OnDestroy()
		{
			All.Remove(this);
		}

		private void Update()
		{
			if (!Object.op_Implicit((Object)(object)enemy))
			{
				return;
			}
			try
			{
				Present();
				if (IsHost)
				{
					HostUpdate();
				}
			}
			catch (Exception arg)
			{
				Plugin.LogOnce("keys-update", $"EnemyKeys update failed: {arg}");
			}
		}

		private void FixedUpdate()
		{
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: 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_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: 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_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Invalid comparison between Unknown and I4
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: 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_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: 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)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: 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_01b1: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)enemy) || !IsHost)
			{
				return;
			}
			if (!Object.op_Implicit((Object)(object)bodyRigidbody))
			{
				bodyRigidbody = (Object.op_Implicit((Object)(object)body) ? ((Component)body).GetComponent<Rigidbody>() : null);
				if (!Object.op_Implicit((Object)(object)bodyRigidbody))
				{
					return;
				}
			}
			if (bodyRigidbody.isKinematic)
			{
				return;
			}
			if (currentState == State.Stun || enemy.IsStunned() || (enemy.HasRigidbody && enemy.Rigidbody.grabbed))
			{
				if ((int)bodyRigidbody.constraints != 0)
				{
					bodyRigidbody.constraints = (RigidbodyConstraints)0;
				}
				return;
			}
			Quaternion rotation = bodyRigidbody.rotation;
			if (Vector3.Angle(rotation * Vector3.up, Vector3.up) < 0.5f)
			{
				if ((int)bodyRigidbody.constraints != 80)
				{
					bodyRigidbody.constraints = (RigidbodyConstraints)80;
				}
				return;
			}
			Vector3 val = Vector3.ProjectOnPlane(rotation * Vector3.forward, Vector3.up);
			if (((Vector3)(ref val)).sqrMagnitude < 0.01f)
			{
				val = Vector3.ProjectOnPlane(((Component)this).transform.forward, Vector3.up);
			}
			if (((Vector3)(ref val)).sqrMagnitude < 0.01f)
			{
				val = Vector3.forward;
			}
			Quaternion val2 = Quaternion.LookRotation(((Vector3)(ref val)).normalized, Vector3.up);
			if ((int)bodyRigidbody.constraints != 0)
			{
				bodyRigidbody.constraints = (RigidbodyConstraints)0;
			}
			Vector3 angularVelocity = bodyRigidbody.angularVelocity;
			bodyRigidbody.angularVelocity = new Vector3(0f, angularVelocity.y, 0f);
			bodyRigidbody.MoveRotation(Quaternion.RotateTowards(rotation, val2, 260f * Time.fixedDeltaTime));
		}

		private void HostUpdate()
		{
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Invalid comparison between Unknown and I4
			if (grabAggroTimer > 0f)
			{
				grabAggroTimer -= Time.deltaTime;
			}
			if (alertDelay >= 0f)
			{
				alertDelay -= Time.deltaTime;
				if (alertDelay < 0f)
				{
					if (Calm && TargetValid(alertPlayer) && !enemy.IsStunned())
					{
						playerTarget = alertPlayer;
						UpdateState(State.Notice);
					}
					alertPlayer = null;
				}
			}
			if ((int)enemy.CurrentState == 11 && !enemy.IsStunned())
			{
				UpdateState(State.Despawn);
			}
			if (enemy.IsStunned())
			{
				UpdateState(State.Stun);
			}
			switch (currentState)
			{
			case State.Spawn:
				StateSpawn();
				break;
			case State.Idle:
				StateIdle();
				break;
			case State.Roam:
				StateRoam();
				break;
			case State.Investigate:
				StateInvestigate();
				break;
			case State.Notice:
				StateNotice();
				break;
			case State.Chase:
				StateChase();
				break;
			case State.Attack:
				StateAttack();
				break;
			case State.Stun:
				StateStun();
				break;
			case State.Leave:
				StateLeave();
				break;
			case State.Despawn:
				StateDespawn();
				break;
			}
		}

		private void StateSpawn()
		{
			if (stateImpulse)
			{
				stateImpulse = false;
				stateTimer = 1.2f;
			}
			stateTimer -= Time.deltaTime;
			if (stateTimer <= 0f)
			{
				UpdateState(State.Idle);
			}
		}

		private void StateIdle()
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			if (stateImpulse)
			{
				enemy.NavMeshAgent.ResetPath();
				enemy.NavMeshAgent.Warp(((Component)enemy.Rigidbody).transform.position, false);
				stateTimer = Random.Range(1.5f, 4.5f);
				stateImpulse = false;
			}
			if (!SemiFunc.EnemySpawnIdlePause())
			{
				stateTimer -= Time.deltaTime;
				if (stateTimer <= 0f)
				{
					UpdateState(State.Roam);
				}
				if (SemiFunc.EnemyForceLeave(enemy))
				{
					UpdateState(State.Leave);
				}
			}
		}

		private void StateRoam()
		{
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: 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_0162: 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_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: 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_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			if (stateImpulse)
			{
				enemy.NavMeshAgent.ResetPath();
				enemy.NavMeshAgent.Warp(((Component)enemy.Rigidbody).transform.position, false);
				agentDestination = ((Component)this).transform.position;
				LevelPoint val = SemiFunc.LevelPointGet(((Component)this).transform.position, 5f, 15f);
				if (!Object.op_Implicit((Object)(object)val))
				{
					val = SemiFunc.LevelPointGet(((Component)this).transform.position, 0f, 999f);
				}
				NavMeshHit val2 = default(NavMeshHit);
				if (Object.op_Implicit((Object)(object)val) && NavMesh.SamplePosition(((Component)val).transform.position + Random.insideUnitSphere * 3f, ref val2, 5f, -1) && Physics.Raycast(((NavMeshHit)(ref val2)).position, Vector3.down, 5f, LayerMask.GetMask(new string[1] { "Default" })))
				{
					agentDestination = ((NavMeshHit)(ref val2)).position;
				}
				stateTimer = 5f;
				stateImpulse = false;
			}
			enemy.NavMeshAgent.SetDestination(agentDestination);
			if (enemy.Rigidbody.notMovingTimer > 2f)
			{
				stateTimer -= Time.deltaTime;
			}
			if (stateTimer <= 0f || Vector3.Distance(((Component)this).transform.position, agentDestination) < 1f)
			{
				UpdateState(State.Idle);
			}
			if (SemiFunc.EnemyForceLeave(enemy))
			{
				UpdateState(State.Leave);
			}
		}

		private void StateInvestigate()
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			if (stateImpulse)
			{
				stateTimer = 5f;
				enemy.Rigidbody.notMovingTimer = 0f;
				stateImpulse = false;
			}
			else
			{
				enemy.NavMeshAgent.SetDestination(agentDestination);
				enemy.NavMeshAgent.OverrideAgent(3.5f, 12f, 0.25f);
				if (enemy.Rigidbody.notMovingTimer > 2f)
				{
					stateTimer -= Time.deltaTime;
				}
				if (stateTimer <= 0f || Vector3.Distance(((Component)this).transform.position, agentDestination) < 2f)
				{
					UpdateState(State.Idle);
				}
			}
			if (SemiFunc.EnemyForceLeave(enemy))
			{
				UpdateState(State.Leave);
			}
		}

		private void StateNotice()
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			if (stateImpulse)
			{
				stateTimer = 1.25f;
				stateImpulse = false;
				foreach (EnemyKeys item in All)
				{
					if (Object.op_Implicit((Object)(object)item) && (Object)(object)item != (Object)(object)this && item.Calm && Vector3.Distance(item.Position, Position) < 16f)
					{
						item.Alert(playerTarget, Random.Range(0.25f, 0.9f));
					}
				}
				CaseOhDirector.OnKeysNotice(playerTarget);
			}
			enemy.NavMeshAgent.ResetPath();
			enemy.NavMeshAgent.Stop(0.1f);
			LookAtTarget();
			stateTimer -= Time.deltaTime;
			if (stateTimer <= 0f)
			{
				enemy.NavMeshAgent.Stop(0f);
				UpdateState((!TargetValid(playerTarget)) ? State.Idle : State.Chase);
			}
		}

		private void StateChase()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: 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_0067: 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_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: 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_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: 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_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			if (!TargetValid(playerTarget))
			{
				UpdateState(State.Leave);
				return;
			}
			Vector3 position = ((Component)playerTarget).transform.position;
			enemy.NavMeshAgent.SetDestination(position);
			if (stateImpulse)
			{
				stateTimer = 12f;
				stateImpulse = false;
				return;
			}
			Vector3 position2 = ((Component)enemy.Rigidbody).transform.position;
			if (HorizontalDistance(position2, position) < 1.6f && Mathf.Abs(position2.y - position.y) < 1.8f)
			{
				UpdateState(State.Attack);
				return;
			}
			if (Vector3.Distance(position2, enemy.NavMeshAgent.GetDestination()) < 1f && Vector3.Distance(position2, position) > 1.5f)
			{
				enemy.Jump.StuckTrigger(position - position2);
				enemy.Rigidbody.DisableFollowPosition(1f, 10f);
			}
			float value = Plugin.KeysChaseSpeed.Value;
			enemy.NavMeshAgent.OverrideAgent(value, 14f, 0.25f);
			stateTimer -= Time.deltaTime;
			if (stateTimer <= 0f)
			{
				UpdateState(State.Leave);
			}
		}

		private void StateAttack()
		{
			//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_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			if (stateImpulse)
			{
				stateTimer = 1.4f;
				stateImpulse = false;
			}
			if (!TargetValid(playerTarget))
			{
				UpdateState(State.Idle);
				return;
			}
			Vector3 position = ((Component)playerTarget).transform.position;
			enemy.NavMeshAgent.SetDestination(position);
			enemy.NavMeshAgent.OverrideAgent(Plugin.KeysChaseSpeed.Value * 0.85f, 14f, 0.25f);
			LookAtTarget();
			stateTimer -= Time.deltaTime;
			if (stateTimer <= 0f)
			{
				if (HorizontalDistance(((Component)enemy.Rigidbody).transform.position, position) < 2.2f)
				{
					stateTimer = 1.4f;
				}
				else
				{
					UpdateState(State.Chase);
				}
			}
		}

		private void StateStun()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			enemy.NavMeshAgent.Disable(0.1f);
			((Component)this).transform