Decompiled source of TheLocust v1.7.1

TheLocust.dll

Decompiled 41 minutes ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using ExitGames.Client.Photon;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json.Linq;
using Photon.Pun;
using Photon.Realtime;
using REPOLib.Modules;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Audio;
using UnityEngine.Networking;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("TheLocust")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.7.1.0")]
[assembly: AssemblyInformationalVersion("1.7.1")]
[assembly: AssemblyProduct("TheLocust")]
[assembly: AssemblyTitle("TheLocust")]
[assembly: AssemblyVersion("1.7.1.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

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

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

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[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 TheLocust
{
	internal sealed class LocustClip
	{
		internal sealed class Track
		{
			public string Bone;

			public bool Rotation;

			public float[] Times;

			public Quaternion[] Rot;

			public Vector3[] Pos;
		}

		public string Name;

		public float Length;

		public bool Loop;

		public readonly List<Track> Tracks = new List<Track>();
	}
	internal static class LocustAssets
	{
		public static GameObject Template;

		public static readonly Dictionary<string, LocustClip> Clips = new Dictionary<string, LocustClip>();

		public static readonly Dictionary<string, List<AudioClip>> Sounds = new Dictionary<string, List<AudioClip>>();

		public static readonly string[] SoundKeys = new string[7] { "lurk", "tilt", "creak", "lure", "jumpscare", "banish", "holy" };

		public static GameObject Crucifix;

		public static readonly Dictionary<string, Texture2D> CircleTex = new Dictionary<string, Texture2D>();

		private static JObject _j;

		private static byte[] _bin;

		public static IEnumerator Load()
		{
			try
			{
				LoadModel(Find("TheLocust.glb").FirstOrDefault() ?? throw new FileNotFoundException("TheLocust.glb not found under " + Plugin.Dir));
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("Model load failed, using fallback silhouette: " + ex));
				Template = FallbackModel();
			}
			try
			{
				LoadCrucifix();
			}
			catch (Exception ex2)
			{
				Plugin.Log.LogWarning((object)("Crucifix model: " + ex2.Message));
			}
			string[] array = new string[5] { "ring", "runes", "inner", "flare", "beam" };
			foreach (string text in array)
			{
				string text2 = Find("circle_" + text + ".png").FirstOrDefault();
				if (text2 != null)
				{
					Texture2D val = new Texture2D(2, 2, (TextureFormat)4, true)
					{
						wrapMode = (TextureWrapMode)1
					};
					ImageConversion.LoadImage(val, File.ReadAllBytes(text2));
					CircleTex[text] = val;
				}
			}
			yield return LoadSounds();
		}

		private static void LoadCrucifix()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: 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_01ce: 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)
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_024d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_025f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0267: Unknown result type (might be due to invalid IL or missing references)
			//IL_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0277: Unknown result type (might be due to invalid IL or missing references)
			//IL_0281: Expected O, but got Unknown
			//IL_028d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0292: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a4: 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_02c8: Expected O, but got Unknown
			GameObject val = new GameObject("Crucifix");
			val.SetActive(false);
			Object.DontDestroyOnLoad((Object)(object)val);
			Crucifix = val;
			string text = Find("Crucifix.glb").FirstOrDefault();
			if (text == null)
			{
				FallbackCross(val);
				return;
			}
			Parse(text);
			foreach (JToken item in (JArray)_j["nodes"])
			{
				if (item[(object)"mesh"] == null)
				{
					continue;
				}
				foreach (JToken item2 in (JArray)_j["meshes"][(object)(int)item[(object)"mesh"]][(object)"primitives"])
				{
					JToken val2 = item2[(object)"attributes"];
					int comps;
					float[] array = Floats((int)val2[(object)"POSITION"], out comps);
					float[] array2 = Floats((int)val2[(object)"NORMAL"], out comps);
					float[] array3 = ((val2[(object)"TEXCOORD_0"] != null) ? Floats((int)val2[(object)"TEXCOORD_0"], out comps) : null);
					int num = array.Length / 3;
					Vector3[] array4 = (Vector3[])(object)new Vector3[num];
					Vector3[] array5 = (Vector3[])(object)new Vector3[num];
					Vector2[] array6 = (Vector2[])(object)new Vector2[num];
					for (int i = 0; i < num; i++)
					{
						array4[i] = new Vector3(0f - array[i * 3], array[i * 3 + 1], array[i * 3 + 2]);
						array5[i] = new Vector3(0f - array2[i * 3], array2[i * 3 + 1], array2[i * 3 + 2]);
						array6[i] = (Vector2)((array3 != null) ? new Vector2(array3[i * 2], 1f - array3[i * 2 + 1]) : Vector2.zero);
					}
					float[] array7 = Floats((int)item2[(object)"indices"], out comps);
					int[] array8 = new int[array7.Length];
					for (int j = 0; j < array7.Length; j += 3)
					{
						array8[j] = (int)array7[j];
						array8[j + 1] = (int)array7[j + 2];
						array8[j + 2] = (int)array7[j + 1];
					}
					Mesh val3 = new Mesh
					{
						name = "CrucifixMesh",
						indexFormat = (IndexFormat)1,
						vertices = array4,
						normals = array5,
						uv = array6,
						triangles = array8
					};
					val3.RecalculateBounds();
					GameObject val4 = new GameObject("Mesh");
					val4.transform.SetParent(val.transform, false);
					val4.AddComponent<MeshFilter>().sharedMesh = val3;
					Material val5 = new Material(FindShader())
					{
						name = "CrucifixMat"
					};
					JToken val6 = ((item2[(object)"material"] != null) ? _j["materials"][(object)(int)item2[(object)"material"]][(object)"pbrMetallicRoughness"] : null);
					if (((val6 != null) ? val6[(object)"baseColorTexture"] : null) != null)
					{
						val5.mainTexture = (Texture)(object)LoadTexture((int)val6[(object)"baseColorTexture"][(object)"index"]);
					}
					val5.SetFloat("_Metallic", 0.3f);
					val5.SetFloat("_Glossiness", 0.5f);
					((Renderer)val4.AddComponent<MeshRenderer>()).sharedMaterial = val5;
				}
			}
			_j = null;
			_bin = null;
		}

		private static void FallbackCross(GameObject root)
		{
			//IL_000d: 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_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			//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_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Expected O, but got Unknown
			//IL_0062: 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_0092: 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_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			Material m = new Material(FindShader())
			{
				color = new Color(0.16f, 0.08f, 0.04f)
			};
			Material val = new Material(FindShader())
			{
				color = new Color(1f, 0.75f, 0.25f)
			};
			val.SetFloat("_Metallic", 0.9f);
			Bar(Vector3.zero, new Vector3(0.05f, 0.45f, 0.04f), m);
			Bar(new Vector3(0f, 0.08f, 0f), new Vector3(0.27f, 0.05f, 0.04f), m);
			Bar(new Vector3(0f, 0.08f, -0.022f), new Vector3(0.06f, 0.06f, 0.01f), val);
			void Bar(Vector3 pos, Vector3 size, Material sharedMaterial)
			{
				//IL_002e: Unknown result type (might be due to invalid IL or missing references)
				//IL_003a: Unknown result type (might be due to invalid IL or missing references)
				GameObject obj = GameObject.CreatePrimitive((PrimitiveType)3);
				Object.DestroyImmediate((Object)(object)obj.GetComponent<Collider>());
				obj.transform.SetParent(root.transform, false);
				obj.transform.localPosition = pos;
				obj.transform.localScale = size;
				obj.GetComponent<Renderer>().sharedMaterial = sharedMaterial;
			}
		}

		private static void Parse(string path)
		{
			byte[] array = File.ReadAllBytes(path);
			if (BitConverter.ToUInt32(array, 0) != 1179937895)
			{
				throw new Exception("not a GLB");
			}
			int num = BitConverter.ToInt32(array, 12);
			_j = JObject.Parse(Encoding.UTF8.GetString(array, 20, num));
			int num2 = 20 + num;
			_bin = new byte[BitConverter.ToInt32(array, num2)];
			Buffer.BlockCopy(array, num2 + 8, _bin, 0, _bin.Length);
		}

		private static void LoadModel(string path)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			//IL_0074: 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_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_025f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0263: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			Parse(path);
			JArray val = (JArray)_j["nodes"];
			GameObject val2 = new GameObject("TheLocust");
			val2.SetActive(false);
			Object.DontDestroyOnLoad((Object)(object)val2);
			Transform[] array = (Transform[])(object)new Transform[((JContainer)val).Count];
			for (int i = 0; i < ((JContainer)val).Count; i++)
			{
				JToken val3 = val[i];
				array[i] = new GameObject(((string)val3[(object)"name"]) ?? ("node" + i)).transform;
				array[i].SetParent(val2.transform, false);
			}
			for (int j = 0; j < ((JContainer)val).Count; j++)
			{
				JToken val4 = val[j];
				if (val4[(object)"children"] != null)
				{
					foreach (JToken item in (IEnumerable<JToken>)val4[(object)"children"])
					{
						array[(int)item].SetParent(array[j], false);
					}
				}
				JToken obj = val4[(object)"translation"];
				JArray val5 = (JArray)(object)((obj is JArray) ? obj : null);
				if (val5 != null)
				{
					array[j].localPosition = new Vector3(0f - (float)val5[0], (float)val5[1], (float)val5[2]);
				}
				JToken obj2 = val4[(object)"rotation"];
				JArray val6 = (JArray)(object)((obj2 is JArray) ? obj2 : null);
				if (val6 != null)
				{
					array[j].localRotation = new Quaternion((float)val6[0], 0f - (float)val6[1], 0f - (float)val6[2], (float)val6[3]);
				}
				JToken obj3 = val4[(object)"scale"];
				JArray val7 = (JArray)(object)((obj3 is JArray) ? obj3 : null);
				if (val7 != null)
				{
					array[j].localScale = new Vector3((float)val7[0], (float)val7[1], (float)val7[2]);
				}
			}
			for (int k = 0; k < ((JContainer)val).Count; k++)
			{
				if (val[k][(object)"mesh"] != null)
				{
					BuildSkinnedMesh(val[k], array);
				}
			}
			? val8 = (JArray)_j["animations"];
			if ((int)val8 == 0)
			{
				val8 = new JArray();
			}
			foreach (JToken item2 in (JArray)val8)
			{
				LocustClip locustClip = ReadClip(item2, val);
				Clips[locustClip.Name] = locustClip;
			}
			Template = val2;
			_j = null;
			_bin = null;
			Plugin.Log.LogInfo((object)$"Model loaded: {Clips.Count} animation clips");
		}

		private static void BuildSkinnedMesh(JToken node, Transform[] t)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fe: Expected O, but got Unknown
			//IL_045f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0464: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ba: Expected O, but got Unknown
			//IL_050d: Unknown result type (might be due to invalid IL or missing references)
			//IL_056b: Unknown result type (might be due to invalid IL or missing references)
			//IL_056d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0296: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_026c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_0254: Unknown result type (might be due to invalid IL or missing references)
			JArray val = (JArray)_j["meshes"][(object)(int)node[(object)"mesh"]][(object)"primitives"];
			List<Vector3> list = new List<Vector3>();
			List<Vector3> list2 = new List<Vector3>();
			List<Vector2> list3 = new List<Vector2>();
			List<BoneWeight> list4 = new List<BoneWeight>();
			List<int[]> list5 = new List<int[]>();
			List<Material> list6 = new List<Material>();
			int comps;
			foreach (JToken item2 in val)
			{
				JToken val2 = item2[(object)"attributes"];
				int count = list.Count;
				float[] array = Floats((int)val2[(object)"POSITION"], out comps);
				float[] array2 = Floats((int)val2[(object)"NORMAL"], out comps);
				float[] array3 = ((val2[(object)"TEXCOORD_0"] != null) ? Floats((int)val2[(object)"TEXCOORD_0"], out comps) : null);
				float[] array4 = ((val2[(object)"JOINTS_0"] != null) ? Floats((int)val2[(object)"JOINTS_0"], out comps) : null);
				float[] array5 = ((val2[(object)"WEIGHTS_0"] != null) ? Floats((int)val2[(object)"WEIGHTS_0"], out comps) : null);
				int num = array.Length / 3;
				for (int i = 0; i < num; i++)
				{
					list.Add(new Vector3(0f - array[i * 3], array[i * 3 + 1], array[i * 3 + 2]));
					list2.Add(new Vector3(0f - array2[i * 3], array2[i * 3 + 1], array2[i * 3 + 2]));
					list3.Add((Vector2)((array3 != null) ? new Vector2(array3[i * 2], 1f - array3[i * 2 + 1]) : Vector2.zero));
					BoneWeight val3;
					BoneWeight item;
					if (array4 != null)
					{
						val3 = default(BoneWeight);
						((BoneWeight)(ref val3)).boneIndex0 = (int)array4[i * 4];
						((BoneWeight)(ref val3)).weight0 = array5[i * 4];
						((BoneWeight)(ref val3)).boneIndex1 = (int)array4[i * 4 + 1];
						((BoneWeight)(ref val3)).weight1 = array5[i * 4 + 1];
						((BoneWeight)(ref val3)).boneIndex2 = (int)array4[i * 4 + 2];
						((BoneWeight)(ref val3)).weight2 = array5[i * 4 + 2];
						((BoneWeight)(ref val3)).boneIndex3 = (int)array4[i * 4 + 3];
						((BoneWeight)(ref val3)).weight3 = array5[i * 4 + 3];
						item = val3;
					}
					else
					{
						val3 = default(BoneWeight);
						((BoneWeight)(ref val3)).weight0 = 1f;
						item = val3;
					}
					list4.Add(item);
				}
				int count2 = list.Count;
				for (int j = 0; j < num; j++)
				{
					list.Add(list[count + j]);
					list2.Add(-list2[count + j]);
					list3.Add(list3[count + j]);
					list4.Add(list4[count + j]);
				}
				float[] array6 = Floats((int)item2[(object)"indices"], out comps);
				int[] array7 = new int[array6.Length * 2];
				for (int k = 0; k < array6.Length; k += 3)
				{
					array7[k] = count + (int)array6[k];
					array7[k + 1] = count + (int)array6[k + 2];
					array7[k + 2] = count + (int)array6[k + 1];
					array7[array6.Length + k] = count2 + (int)array6[k];
					array7[array6.Length + k + 1] = count2 + (int)array6[k + 1];
					array7[array6.Length + k + 2] = count2 + (int)array6[k + 2];
				}
				list5.Add(array7);
				list6.Add(MakeMaterial((item2[(object)"material"] != null) ? ((int)item2[(object)"material"]) : (-1)));
			}
			Mesh val4 = new Mesh
			{
				name = "TheLocustMesh",
				indexFormat = (IndexFormat)1
			};
			val4.SetVertices(list);
			val4.SetNormals(list2);
			val4.SetUVs(0, list3);
			val4.subMeshCount = list5.Count;
			for (int l = 0; l < list5.Count; l++)
			{
				val4.SetTriangles(list5[l], l);
			}
			val4.boneWeights = list4.ToArray();
			GameObject val5 = new GameObject("Body");
			val5.transform.SetParent(t[0].root, false);
			SkinnedMeshRenderer val6 = val5.AddComponent<SkinnedMeshRenderer>();
			JToken obj = _j["skins"][(object)(int)node[(object)"skin"]];
			JArray val7 = (JArray)obj[(object)"joints"];
			float[] array8 = Floats((int)obj[(object)"inverseBindMatrices"], out comps);
			Transform[] array9 = (Transform[])(object)new Transform[((JContainer)val7).Count];
			Matrix4x4[] array10 = (Matrix4x4[])(object)new Matrix4x4[((JContainer)val7).Count];
			for (int m = 0; m < ((JContainer)val7).Count; m++)
			{
				array9[m] = t[(int)val7[m]];
				Matrix4x4 val8 = default(Matrix4x4);
				for (int n = 0; n < 4; n++)
				{
					for (int num2 = 0; num2 < 4; num2++)
					{
						((Matrix4x4)(ref val8))[num2, n] = array8[m * 16 + n * 4 + num2] * ((num2 == 0 != (n == 0)) ? (-1f) : 1f);
					}
				}
				array10[m] = val8;
			}
			val4.bindposes = array10;
			val4.RecalculateBounds();
			val6.sharedMesh = val4;
			val6.bones = array9;
			val6.rootBone = array9[0];
			((Renderer)val6).sharedMaterials = list6.ToArray();
			val6.updateWhenOffscreen = true;
			((Renderer)val6).shadowCastingMode = (ShadowCastingMode)1;
		}

		private static Material MakeMaterial(int index)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			//IL_00eb: 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_00bf: Unknown result type (might be due to invalid IL or missing references)
			Material val = new Material(FindShader())
			{
				name = "LocustSkin"
			};
			JToken val2 = ((index >= 0) ? _j["materials"][(object)index][(object)"pbrMetallicRoughness"] : null);
			Texture2D val3 = ((((val2 != null) ? val2[(object)"baseColorTexture"] : null) != null) ? LoadTexture((int)val2[(object)"baseColorTexture"][(object)"index"]) : null);
			if ((Object)(object)val3 != (Object)null)
			{
				val.mainTexture = (Texture)(object)val3;
				val.color = Color.white;
				val.EnableKeyword("_EMISSION");
				val.SetTexture("_EmissionMap", (Texture)(object)val3);
				val.SetColor("_EmissionColor", new Color(0.16f, 0.15f, 0.15f));
				val.SetFloat("_Glossiness", 0.15f);
			}
			else
			{
				val.color = new Color(0.012f, 0.012f, 0.014f);
				val.SetFloat("_Glossiness", 0.42f);
				val.SetFloat("_Metallic", 0f);
			}
			return val;
		}

		private static Shader FindShader()
		{
			Shader val = Shader.Find("Standard");
			if ((Object)(object)val != (Object)null)
			{
				return val;
			}
			Renderer[] array = Object.FindObjectsByType<Renderer>((FindObjectsSortMode)0);
			foreach (Renderer val2 in array)
			{
				if ((Object)(object)val2.sharedMaterial != (Object)null && (Object)(object)val2.sharedMaterial.shader != (Object)null)
				{
					return val2.sharedMaterial.shader;
				}
			}
			return Shader.Find("Sprites/Default");
		}

		private static Texture2D LoadTexture(int texIndex)
		{
			//IL_00af: 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_00bb: Expected O, but got Unknown
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Expected O, but got Unknown
			int num = (int)_j["textures"][(object)texIndex][(object)"source"];
			JToken obj = _j["bufferViews"][(object)(int)_j["images"][(object)num][(object)"bufferView"]];
			int valueOrDefault = ((int?)obj[(object)"byteOffset"]).GetValueOrDefault();
			int num2 = (int)obj[(object)"byteLength"];
			byte[] array = new byte[num2];
			Buffer.BlockCopy(_bin, valueOrDefault, array, 0, num2);
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, true);
			ImageConversion.LoadImage(val, array);
			((Texture)val).wrapMode = (TextureWrapMode)1;
			return val;
		}

		private static float[] Floats(int accessor, out int comps)
		{
			JToken val = _j["accessors"][(object)accessor];
			int num = (int)val[(object)"count"];
			comps = TypeSize((string)val[(object)"type"]);
			int num2 = (int)val[(object)"componentType"];
			int num3;
			switch (num2)
			{
			default:
				num3 = 1;
				break;
			case 5122:
			case 5123:
				num3 = 2;
				break;
			case 5125:
			case 5126:
				num3 = 4;
				break;
			}
			int num4 = num3;
			JToken obj = _j["bufferViews"][(object)(int)val[(object)"bufferView"]];
			int num5 = ((int?)obj[(object)"byteOffset"]).GetValueOrDefault() + ((int?)val[(object)"byteOffset"]).GetValueOrDefault();
			int num6 = ((int?)obj[(object)"byteStride"]) ?? (comps * num4);
			bool valueOrDefault = (bool?)val[(object)"normalized"] == true;
			float[] array = new float[num * comps];
			for (int i = 0; i < num; i++)
			{
				for (int j = 0; j < comps; j++)
				{
					int num7 = num5 + i * num6 + j * num4;
					float num8;
					switch (num2)
					{
					case 5126:
						num8 = BitConverter.ToSingle(_bin, num7);
						break;
					case 5125:
						num8 = BitConverter.ToUInt32(_bin, num7);
						break;
					case 5123:
						num8 = (int)BitConverter.ToUInt16(_bin, num7);
						if (valueOrDefault)
						{
							num8 /= 65535f;
						}
						break;
					case 5122:
						num8 = BitConverter.ToInt16(_bin, num7);
						if (valueOrDefault)
						{
							num8 = Mathf.Max(num8 / 32767f, -1f);
						}
						break;
					case 5121:
						num8 = (int)_bin[num7];
						if (valueOrDefault)
						{
							num8 /= 255f;
						}
						break;
					default:
						num8 = (sbyte)_bin[num7];
						if (valueOrDefault)
						{
							num8 = Mathf.Max(num8 / 127f, -1f);
						}
						break;
					}
					array[i * comps + j] = num8;
				}
			}
			return array;
		}

		private static int TypeSize(string t)
		{
			return t switch
			{
				"VEC4" => 4, 
				"VEC3" => 3, 
				"VEC2" => 2, 
				"SCALAR" => 1, 
				_ => 16, 
			};
		}

		private static LocustClip ReadClip(JToken a, JArray nodes)
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected O, but got Unknown
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: 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_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			LocustClip locustClip = new LocustClip
			{
				Name = (string)a[(object)"name"]
			};
			locustClip.Loop = !locustClip.Name.Contains("Jumpscare");
			JArray val = (JArray)a[(object)"samplers"];
			foreach (JToken item in (IEnumerable<JToken>)a[(object)"channels"])
			{
				string text = (string)item[(object)"target"][(object)"path"];
				if (text != "rotation" && text != "translation")
				{
					continue;
				}
				JToken obj = val[(int)item[(object)"sampler"]];
				int comps;
				float[] array = Floats((int)obj[(object)"input"], out comps);
				int comps2;
				float[] array2 = Floats((int)obj[(object)"output"], out comps2);
				LocustClip.Track track = new LocustClip.Track
				{
					Bone = (string)nodes[(int)item[(object)"target"][(object)"node"]][(object)"name"],
					Rotation = (text == "rotation"),
					Times = array
				};
				int num = array.Length;
				bool flag = true;
				if (track.Rotation)
				{
					track.Rot = (Quaternion[])(object)new Quaternion[num];
					for (int i = 0; i < num; i++)
					{
						track.Rot[i] = new Quaternion(array2[i * 4], 0f - array2[i * 4 + 1], 0f - array2[i * 4 + 2], array2[i * 4 + 3]);
						if (i > 0 && Quaternion.Angle(track.Rot[i], track.Rot[0]) > 0.05f)
						{
							flag = false;
						}
					}
				}
				else
				{
					track.Pos = (Vector3[])(object)new Vector3[num];
					for (int j = 0; j < num; j++)
					{
						track.Pos[j] = new Vector3(0f - array2[j * 3], array2[j * 3 + 1], array2[j * 3 + 2]);
						if (j > 0)
						{
							Vector3 val2 = track.Pos[j] - track.Pos[0];
							if (((Vector3)(ref val2)).sqrMagnitude > 1E-06f)
							{
								flag = false;
							}
						}
					}
					if (flag)
					{
						continue;
					}
				}
				locustClip.Tracks.Add(track);
				locustClip.Length = Mathf.Max(locustClip.Length, array[num - 1]);
			}
			return locustClip;
		}

		private static GameObject FallbackModel()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//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_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Expected O, but got Unknown
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: 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_00d5: 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_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: 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_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: 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_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Unknown result type (might be due to invalid IL or missing references)
			//IL_027f: 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_02c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02da: Unknown result type (might be due to invalid IL or missing references)
			//IL_030b: Unknown result type (might be due to invalid IL or missing references)
			//IL_031f: Unknown result type (might be due to invalid IL or missing references)
			//IL_034f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0363: Unknown result type (might be due to invalid IL or missing references)
			//IL_0392: Unknown result type (might be due to invalid IL or missing references)
			//IL_0397: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("TheLocust");
			val.SetActive(false);
			Object.DontDestroyOnLoad((Object)(object)val);
			Material mat = new Material(FindShader())
			{
				color = new Color(0.01f, 0.01f, 0.01f)
			};
			Transform parent = Bone("Root", val.transform, new Vector3(0f, 1.68f, 0f), new Vector3(0.22f, 0.12f, 0.12f), (PrimitiveType)3);
			Transform parent2 = Bone("Spine", parent, new Vector3(0f, 0.23f, 0f), new Vector3(0.08f, 0.15f, 0.08f), (PrimitiveType)1);
			Transform parent3 = Bone("Chest", parent2, new Vector3(0f, 0.29f, 0f), new Vector3(0.3f, 0.1f, 0.15f), (PrimitiveType)3);
			Transform parent4 = Bone("Neck", parent3, new Vector3(0f, 0.17f, 0f), new Vector3(0.06f, 0.1f, 0.06f), (PrimitiveType)1);
			Transform parent5 = Bone("Head", parent4, new Vector3(0f, 0.19f, 0f), new Vector3(0.26f, 0.3f, 0.24f), (PrimitiveType)0);
			Bone("Jaw", parent5, new Vector3(0f, 0.09f, 0.03f), Vector3.zero, null);
			Bone("Tendrils", parent5, new Vector3(0f, 0.04f, -0.05f), Vector3.zero, null);
			float[] array = new float[2] { 1f, -1f };
			foreach (float num in array)
			{
				string obj = ((num > 0f) ? "Left" : "Right");
				Transform parent6 = Bone(obj + "Arm", parent3, new Vector3(0.15f * num, -0.03f, 0f), new Vector3(0.05f, 0.36f, 0.05f), (PrimitiveType)1);
				Transform parent7 = Bone(obj + "ForeArm", parent6, new Vector3(0.04f * num, -0.72f, 0f), new Vector3(0.045f, 0.36f, 0.045f), (PrimitiveType)1);
				Bone(obj + "Hand", parent7, new Vector3(0.03f * num, -0.72f, 0f), new Vector3(0.08f, 0.13f, 0.03f), (PrimitiveType)3);
				Transform parent8 = Bone(obj + "Leg", parent, new Vector3(0.07f * num, 0f, 0f), new Vector3(0.06f, 0.4f, 0.06f), (PrimitiveType)1);
				Transform parent9 = Bone(obj + "Shin", parent8, new Vector3(0f, -0.81f, 0f), new Vector3(0.05f, 0.38f, 0.05f), (PrimitiveType)1);
				Bone(obj + "Foot", parent9, new Vector3(0f, -0.75f, 0f), Vector3.zero, null);
			}
			return val;
			Transform Bone(string name, Transform val2, Vector3 local, Vector3 scale, PrimitiveType? shape)
			{
				//IL_0001: 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_0026: Unknown result type (might be due to invalid IL or missing references)
				//IL_0060: Unknown result type (might be due to invalid IL or missing references)
				//IL_0070: 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_0093: Unknown result type (might be due to invalid IL or missing references)
				Transform transform = new GameObject(name).transform;
				transform.SetParent(val2, false);
				transform.localPosition = local;
				if (shape.HasValue)
				{
					GameObject obj2 = GameObject.CreatePrimitive(shape.Value);
					Object.Destroy((Object)(object)obj2.GetComponent<Collider>());
					obj2.GetComponent<Renderer>().sharedMaterial = mat;
					obj2.transform.SetParent(transform, false);
					obj2.transform.localScale = scale;
					obj2.transform.localPosition = new Vector3(0f, 0f - scale.y, 0f) * (float)((local.y < 0f) ? 1 : (-1));
				}
				return transform;
			}
		}

		private static IEnumerator LoadSounds()
		{
			string[] soundKeys = SoundKeys;
			foreach (string key in soundKeys)
			{
				List<AudioClip> list = (Sounds[key] = new List<AudioClip>());
				List<AudioClip> list3 = list;
				string[] array = new string[2] { "*.wav", "*.ogg" };
				foreach (string ext in array)
				{
					string[] array2 = Find(key + "_" + ext);
					foreach (string f in array2)
					{
						UnityWebRequest req = UnityWebRequestMultimedia.GetAudioClip("file:///" + f.Replace('\\', '/'), (AudioType)((ext == "*.wav") ? 20 : 14));
						try
						{
							yield return req.SendWebRequest();
							if ((int)req.result == 1)
							{
								AudioClip content = DownloadHandlerAudioClip.GetContent(req);
								((Object)content).name = Path.GetFileNameWithoutExtension(f);
								list3.Add(content);
							}
							else
							{
								Plugin.Log.LogWarning((object)("Sound " + f + ": " + req.error));
							}
						}
						finally
						{
							((IDisposable)req)?.Dispose();
						}
					}
				}
				if (list3.Count == 0)
				{
					list3.Add(Synth(key));
				}
			}
			Plugin.Log.LogInfo((object)("Sounds: " + string.Join(", ", SoundKeys.Select((string text) => text + "=" + Sounds[text].Count))));
		}

		private static string[] Find(string pattern)
		{
			return Directory.GetFiles(Plugin.Dir, pattern, SearchOption.AllDirectories);
		}

		public static AudioClip Synth(string key)
		{
			float num = key switch
			{
				"creak" => 1.6f, 
				"lure" => 0.25f, 
				"tilt" => 0.4f, 
				"jumpscare" => 1.8f, 
				"holy" => 3f, 
				"banish" => 3f, 
				_ => 6f, 
			};
			float[] array = new float[(int)(44100f * num)];
			Random random = new Random(key.GetHashCode());
			float num2 = 0f;
			for (int i = 0; i < array.Length; i++)
			{
				float num3 = (float)i / 44100f;
				float num4 = (float)(random.NextDouble() * 2.0 - 1.0);
				num2 += (num4 - num2) * 0.08f;
				array[i] = Mathf.Clamp(key switch
				{
					"tilt" => ((num3 < 0.01f) ? num4 : 0f) + Mathf.Exp((0f - num3) * 60f) * num2 * 3f + ((num3 > 0.12f && num3 < 0.13f) ? (num4 * 0.8f) : 0f), 
					"lure" => Mathf.Sin(MathF.PI * 5800f * num3) * Mathf.Exp((0f - num3) * 45f) * 0.6f + num4 * Mathf.Exp((0f - num3) * 300f) * 0.4f, 
					"creak" => Mathf.Sign(Mathf.Sin(MathF.PI * 2f * (60f + 35f * Mathf.Sin(num3 * 2.3f)) * num3)) * num2 * 2f * Mathf.Sin(MathF.PI * num3 / num), 
					"holy" => (Mathf.Sin(MathF.PI * 1046f * num3) + Mathf.Sin(MathF.PI * 1318f * num3) + Mathf.Sin(MathF.PI * 1568f * num3)) * 0.15f * Mathf.Sin(MathF.PI * num3 / num), 
					"jumpscare" => Mathf.Clamp((Mathf.Sin(MathF.PI * 2360f * num3 + Mathf.Sin(num3 * 230f) * 6f) + num4) * 2.5f, -1f, 1f) * Mathf.Min(1f, (num - num3) * 4f), 
					_ => Mathf.Sin(MathF.PI * 82f * num3) * 0.3f + num2 * 0.5f * (0.5f + 0.5f * Mathf.Sin(num3 * 1.3f)), 
				}, -1f, 1f);
			}
			AudioClip obj = AudioClip.Create("locust_" + key, array.Length, 1, 44100, false);
			obj.SetData(array, 0);
			return obj;
		}

		public static AudioClip Random(string key)
		{
			if (!Sounds.TryGetValue(key, out var value) || value.Count <= 0)
			{
				return null;
			}
			return value[Random.Range(0, value.Count)];
		}
	}
	internal static class LocustBanish
	{
		public const float Duration = 5.2f;

		private static readonly Color Gold = new Color(1f, 0.72f, 0.22f);

		private static readonly Color Pale = new Color(1f, 0.92f, 0.6f);

		private static Shader _add;

		private static Texture2D _chain;

		public static void Play(LocustEntity e, Vector3 floor)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)LocustFX.Instance != (Object)null)
			{
				((MonoBehaviour)LocustFX.Instance).StartCoroutine(Run(e, floor));
			}
		}

		private static IEnumerator Run(LocustEntity e, Vector3 floor)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			GameObject root = new GameObject("LocustBanishCircle");
			root.transform.position = floor + Vector3.up * 0.03f;
			Transform ring = Disc(root.transform, "ring", 5f, 0f, Gold);
			Transform inner = Disc(root.transform, "inner", 3.2f, 0.25f, Pale);
			Transform runes = Disc(root.transform, "runes", 2f, 0.02f, Gold);
			Transform flare = Disc(root.transform, "flare", 4f, 1.4f, Pale, vertical: true);
			Light light = new GameObject("Light").AddComponent<Light>();
			((Component)light).transform.SetParent(root.transform, false);
			((Component)light).transform.localPosition = Vector3.up * 1.2f;
			light.type = (LightType)2;
			light.color = Gold;
			light.range = 9f;
			light.intensity = 0f;
			List<Transform> beams = new List<Transform>();
			for (int i = 0; i < 10; i++)
			{
				Transform val = Disc(root.transform, "beam", 1f, 0f, Pale, vertical: true);
				float num = (float)i * 36f * (MathF.PI / 180f);
				val.localPosition = new Vector3(Mathf.Cos(num), 0f, Mathf.Sin(num)) * 2.2f;
				beams.Add(val);
			}
			List<LineRenderer> chains = new List<LineRenderer>();
			for (int j = 0; j < 6; j++)
			{
				LineRenderer val2 = new GameObject("Chain").AddComponent<LineRenderer>();
				((Component)val2).transform.SetParent(root.transform, false);
				((Renderer)val2).material = Mat((Texture)(object)ChainTex(), Gold);
				val2.textureMode = (LineTextureMode)1;
				val2.widthMultiplier = 0.09f;
				val2.positionCount = 2;
				chains.Add(val2);
			}
			LocustFX.Instance.Holy(1f);
			Play3D("holy", "sweep", floor + Vector3.up, 30f, 0.8f);
			Play3D("banish", "chain", floor + Vector3.up, 22f, 0.55f);
			bool screamed = false;
			bool rumbled = false;
			bool choir = false;
			Camera cam = SemiFunc.MainCamera();
			for (float t = 0f; t < 5.2f; t += Time.deltaTime)
			{
				float num2 = Mathf.SmoothStep(0f, 1f, t / 0.5f);
				float num3 = 1f - Mathf.Clamp01((t - 4.3999996f) / 0.8f);
				float num4 = num2 * num3;
				ring.localScale = Vector3.one * 5f * num2;
				inner.localScale = Vector3.one * 3.2f * num2;
				runes.localScale = Vector3.one * 2f * num2;
				ring.Rotate(0f, 20f * Time.deltaTime, 0f, (Space)0);
				inner.Rotate(0f, -35f * Time.deltaTime, 0f, (Space)0);
				runes.Rotate(0f, 60f * Time.deltaTime, 0f, (Space)0);
				inner.localPosition = Vector3.up * (0.25f + 0.08f * Mathf.Sin(t * 3f));
				if ((Object)(object)cam != (Object)null)
				{
					flare.rotation = Quaternion.LookRotation(flare.position - ((Component)cam).transform.position);
				}
				flare.localScale = Vector3.one * (3f + 0.6f * Mathf.Sin(t * 17f)) * num4;
				light.intensity = (3f + Mathf.Sin(t * 23f)) * num4;
				Renderer[] componentsInChildren = root.GetComponentsInChildren<Renderer>();
				for (int k = 0; k < componentsInChildren.Length; k++)
				{
					SetAlpha(componentsInChildren[k], num4);
				}
				for (int l = 0; l < beams.Count; l++)
				{
					float num5 = Mathf.Sin(MathF.PI * Mathf.Repeat(t * 0.8f + (float)l * 0.17f, 1f)) * 4.5f * num4 + 0.01f;
					Transform val3 = beams[l];
					val3.localScale = new Vector3(0.45f, num5, 1f);
					if ((Object)(object)cam != (Object)null)
					{
						val3.rotation = Quaternion.LookRotation(Vector3.ProjectOnPlane(val3.position - ((Component)cam).transform.position, Vector3.up) + Vector3.forward * 0.001f);
					}
					val3.localPosition = new Vector3(val3.localPosition.x, num5 * 0.5f, val3.localPosition.z);
				}
				if (!screamed && t > 0.6f)
				{
					screamed = true;
					Play3D("banish", "screech", floor + Vector3.up * 2f, 35f, 0.85f);
				}
				if (!rumbled && t > 1.4f)
				{
					rumbled = true;
					Play3D("banish", "rumble", floor, 28f, 0.45f);
				}
				if (!choir && t > 3.8999999f)
				{
					choir = true;
					Play3D("holy", "heaven", floor + Vector3.up, 30f, 0.7f);
				}
				if ((Object)(object)e != (Object)null)
				{
					float sink = Mathf.Pow(Mathf.Clamp01((t - 0.8f) / 3.6f), 2.2f) * 3.4f;
					e.Sink = sink;
					Vector3 position = ((Component)e).transform.position;
					for (int m = 0; m < chains.Count; m++)
					{
						float num6 = ((float)m * 60f + t * 25f) * (MathF.PI / 180f);
						chains[m].SetPosition(0, floor + new Vector3(Mathf.Cos(num6), 0.05f, Mathf.Sin(num6)) * 2.4f * num2);
						chains[m].SetPosition(1, position + Vector3.up * (0.6f + 0.35f * (float)m) + Random.insideUnitSphere * 0.05f);
						chains[m].widthMultiplier = 0.09f * num4;
					}
					if (Random.value < 0.25f)
					{
						LocustFX.Burst(position + Vector3.up * Random.Range(0.3f, 2.4f), Pale, 6, 0.08f, 2.5f, 0.9f);
					}
					if (Random.value < 0.2f)
					{
						LocustFX.Burst(floor + Random.insideUnitSphere * 1.5f, new Color(0.01f, 0.01f, 0.01f, 0.8f), 5, 0.6f, 0.6f, 1.6f);
					}
				}
				if (t > 4.2f && (Object)(object)e != (Object)null && e.Sink < 99f)
				{
					LocustFX.Instance.Holy(1f);
					LocustFX.Smoke(floor + Vector3.up, 1.6f);
					LocustFX.Burst(floor + Vector3.up, Gold, 80, 0.12f, 6f, 1.4f);
					e.Sink = 99f;
				}
				yield return null;
			}
			Object.Destroy((Object)(object)root);
		}

		private static Transform Disc(Transform parent, string tex, float size, float y, Color c, bool vertical = false)
		{
			//IL_002b: 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_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: 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)
			GameObject obj = GameObject.CreatePrimitive((PrimitiveType)5);
			Object.Destroy((Object)(object)obj.GetComponent<Collider>());
			((Object)obj).name = tex;
			obj.transform.SetParent(parent, false);
			obj.transform.localPosition = Vector3.up * y;
			obj.transform.localRotation = (vertical ? Quaternion.identity : Quaternion.Euler(90f, 0f, 0f));
			obj.transform.localScale = Vector3.one * size;
			LocustAssets.CircleTex.TryGetValue(tex, out var value);
			Renderer component = obj.GetComponent<Renderer>();
			component.material = Mat((Texture)(object)value, c);
			component.shadowCastingMode = (ShadowCastingMode)0;
			return obj.transform;
		}

		private static Material Mat(Texture tex, Color c)
		{
			//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_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Expected O, but got Unknown
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_add == (Object)null)
			{
				_add = Shader.Find("Legacy Shaders/Particles/Additive") ?? Shader.Find("Particles/Additive") ?? Shader.Find("Sprites/Default");
			}
			Material val = new Material(_add)
			{
				mainTexture = tex,
				renderQueue = 3100
			};
			if (val.HasProperty("_TintColor"))
			{
				val.SetColor("_TintColor", c * 0.6f);
			}
			val.color = c;
			return val;
		}

		private static void SetAlpha(Renderer r, float a)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			Material material = r.material;
			Color color = material.color;
			color.a = a;
			material.color = color;
			if (material.HasProperty("_TintColor"))
			{
				Color color2 = material.GetColor("_TintColor");
				color2.a = 0.5f * a;
				material.SetColor("_TintColor", color2);
			}
		}

		private static Texture2D ChainTex()
		{
			//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)
			//IL_002a: Expected O, but got Unknown
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_chain != (Object)null)
			{
				return _chain;
			}
			_chain = new Texture2D(64, 32, (TextureFormat)4, true)
			{
				wrapMode = (TextureWrapMode)0
			};
			for (int i = 0; i < 32; i++)
			{
				for (int j = 0; j < 64; j++)
				{
					float num = ((float)j - 16f) / 14f;
					float num2 = ((float)i - 16f) / 9f;
					float num3 = Mathf.Sqrt(num * num + num2 * num2);
					float num4 = Mathf.Clamp01(1f - Mathf.Abs(num3 - 0.8f) * 6f);
					float num5 = ((j > 34 && j < 62 && Mathf.Abs(i - 16) < 3) ? 1f : 0f);
					float num6 = Mathf.Max(num4, num5);
					_chain.SetPixel(j, i, new Color(1f, 1f, 1f, num6));
				}
			}
			_chain.Apply();
			return _chain;
		}

		private static void Play3D(string key, string part, Vector3 pos, float range, float vol)
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Expected O, but got Unknown
			//IL_0097: Expected O, but got Unknown
			AudioClip val = null;
			if (LocustAssets.Sounds.TryGetValue(key, out var value))
			{
				val = value.Find((AudioClip x) => ((Object)x).name.Contains(part));
			}
			if ((Object)(object)val == (Object)null)
			{
				val = LocustAssets.Random(key);
			}
			if (!((Object)(object)val == (Object)null))
			{
				GameObject val2 = new GameObject("LocustBanishSound");
				val2.transform.position = pos;
				AudioSource obj = LocustEntity.NewSource(val2, range);
				obj.minDistance = 4f;
				obj.PlayOneShot(val, vol * Plugin.Volume.Value);
				Object.Destroy((Object)val2, val.length + 0.5f);
			}
		}
	}
	internal static class LocustCrucifix
	{
		public const string Name = "Sacred Crucifix";

		public const string PrefabName = "Item Sacred Crucifix";

		public static bool Registered;

		public static Item ItemAsset;

		private static readonly string[] Templates = new string[4] { "Tracker", "Duck", "Health Pack", "Grenade" };

		private static readonly HashSet<string> Keep = new HashSet<string> { "ItemAttributes", "ItemEquippable", "ItemToggle" };

		public static void TryRegister()
		{
			if (Registered || (Object)(object)LocustAssets.Crucifix == (Object)null || (Object)(object)StatsManager.instance == (Object)null || StatsManager.instance.itemDictionary == null || StatsManager.instance.itemDictionary.Count == 0)
			{
				return;
			}
			Registered = true;
			try
			{
				Register();
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("Sacred Crucifix registration failed: " + ex));
			}
		}

		private static void Register()
		{
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Expected O, but got Unknown
			//IL_0249: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0317: Unknown result type (might be due to invalid IL or missing references)
			//IL_031c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0321: Unknown result type (might be due to invalid IL or missing references)
			//IL_0326: Unknown result type (might be due to invalid IL or missing references)
			//IL_032a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0336: Unknown result type (might be due to invalid IL or missing references)
			//IL_0342: Unknown result type (might be due to invalid IL or missing references)
			//IL_034e: Unknown result type (might be due to invalid IL or missing references)
			Item val = null;
			GameObject val2 = null;
			string[] templates = Templates;
			foreach (string value in templates)
			{
				foreach (Item value3 in StatsManager.instance.itemDictionary.Values)
				{
					if (!((Object)(object)value3 == (Object)null) && value3.itemName != null && value3.itemName.Contains(value))
					{
						object value2 = Traverse.Create((object)value3.prefab).Property("Prefab", (object[])null).GetValue();
						GameObject val3 = (GameObject)((value2 is GameObject) ? value2 : null);
						if ((Object)(object)val3 != (Object)null && (Object)(object)val3.GetComponent<ItemAttributes>() != (Object)null && (Object)(object)val3.GetComponent<PhysGrabObject>() != (Object)null)
						{
							val = value3;
							val2 = val3;
							break;
						}
					}
				}
				if ((Object)(object)val != (Object)null)
				{
					break;
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Log.LogWarning((object)"Sacred Crucifix: no template item found");
				return;
			}
			GameObject val4 = new GameObject("LocustItemHolder");
			val4.SetActive(false);
			Object.DontDestroyOnLoad((Object)(object)val4);
			GameObject val5 = Object.Instantiate<GameObject>(val2, val4.transform);
			((Object)val5).name = "Item Sacred Crucifix";
			MonoBehaviour[] componentsInChildren = val5.GetComponentsInChildren<MonoBehaviour>(true);
			foreach (MonoBehaviour val6 in componentsInChildren)
			{
				string name = ((object)val6).GetType().Name;
				if ((name.StartsWith("Item") && !Keep.Contains(name)) || name.Contains("Battery"))
				{
					Object.DestroyImmediate((Object)(object)val6);
				}
			}
			Renderer[] componentsInChildren2 = val5.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer obj in componentsInChildren2)
			{
				obj.enabled = false;
				obj.forceRenderingOff = true;
			}
			Light[] componentsInChildren3 = val5.GetComponentsInChildren<Light>(true);
			for (int i = 0; i < componentsInChildren3.Length; i++)
			{
				((Behaviour)componentsInChildren3[i]).enabled = false;
			}
			Canvas[] componentsInChildren4 = val5.GetComponentsInChildren<Canvas>(true);
			for (int i = 0; i < componentsInChildren4.Length; i++)
			{
				((Component)componentsInChildren4[i]).gameObject.SetActive(false);
			}
			if ((Object)(object)val5.GetComponent<ItemToggle>() == (Object)null)
			{
				val5.AddComponent<ItemToggle>();
			}
			GameObject obj2 = Object.Instantiate<GameObject>(LocustAssets.Crucifix, val5.transform);
			((Object)obj2).name = "CrossModel";
			obj2.transform.localPosition = Vector3.zero;
			obj2.transform.localRotation = Quaternion.identity;
			obj2.SetActive(true);
			bool flag = true;
			Collider[] componentsInChildren5 = val5.GetComponentsInChildren<Collider>(true);
			foreach (Collider val7 in componentsInChildren5)
			{
				if (val7.isTrigger)
				{
					continue;
				}
				if (!flag)
				{
					val7.enabled = false;
					continue;
				}
				flag = false;
				Transform transform = ((Component)val7).transform;
				BoxCollider val8 = (BoxCollider)(object)((val7 is BoxCollider) ? val7 : null);
				if ((Object)(object)val8 == (Object)null)
				{
					PhysicsMaterial sharedMaterial = val7.sharedMaterial;
					Object.DestroyImmediate((Object)(object)val7);
					val8 = ((Component)transform).gameObject.AddComponent<BoxCollider>();
					((Collider)val8).sharedMaterial = sharedMaterial;
				}
				val8.center = transform.InverseTransformPoint(val5.transform.position);
				Vector3 val9 = transform.InverseTransformVector(val5.transform.TransformVector(new Vector3(0.27f, 0.45f, 0.06f)));
				val8.size = new Vector3(Mathf.Abs(val9.x), Mathf.Abs(val9.y), Mathf.Abs(val9.z));
			}
			val5.AddComponent<CrucifixItem>();
			Item val10 = Object.Instantiate<Item>(val);
			((Object)val10).name = "Item Sacred Crucifix";
			val10.itemName = "Sacred Crucifix";
			val10.description = "Carved wood and gold. The only thing it fears.";
			Value val11 = ScriptableObject.CreateInstance<Value>();
			val11.valueMin = (((Object)(object)val.value != (Object)null) ? (val.value.valueMin * 2.5f) : 6000f);
			val11.valueMax = (((Object)(object)val.value != (Object)null) ? (val.value.valueMax * 2.5f) : 8000f);
			val10.value = val11;
			val10.maxAmount = 2;
			val10.maxAmountInShop = 1;
			val10.disabled = false;
			val5.GetComponent<ItemAttributes>().item = val10;
			ItemAsset = val10;
			Items.RegisterItem(val5.GetComponent<ItemAttributes>());
			Plugin.Log.LogInfo((object)("Sacred Crucifix registered (template: " + val.itemName + ")"));
		}

		public static void PatchNames(Harmony h)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Expected O, but got Unknown
			MethodInfo methodInfo = AccessTools.Method(typeof(ItemAttributes), "RefreshLocalizations", (Type[])null, (Type[])null);
			if (methodInfo != null)
			{
				h.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(LocustCrucifix), "AttrName", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			MethodInfo methodInfo2 = AccessTools.Method("MapShopScreen:ItemNameGet", (Type[])null, (Type[])null);
			if (methodInfo2 != null)
			{
				h.Patch((MethodBase)methodInfo2, (HarmonyMethod)null, new HarmonyMethod(typeof(LocustCrucifix), "ShopName", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
		}

		private static void AttrName(ItemAttributes __instance)
		{
			if ((Object)(object)__instance.item != (Object)null && __instance.item.itemName == "Sacred Crucifix")
			{
				Traverse.Create((object)__instance).Field("cachedItemName").SetValue((object)"Sacred Crucifix");
			}
		}

		private static void ShopName(object[] __args, ref string __result)
		{
			foreach (object obj in __args)
			{
				switch (obj as string)
				{
				default:
				{
					Item val = (Item)((obj is Item) ? obj : null);
					if (val == null || !(val.itemName == "Sacred Crucifix"))
					{
						continue;
					}
					break;
				}
				case "Item Sacred Crucifix":
				case "Sacred Crucifix":
					break;
				}
				__result = "Sacred Crucifix";
			}
		}

		public static void Spawn(Vector3 pos)
		{
			//IL_0012: 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)(object)ItemAsset != (Object)null)
			{
				Items.SpawnItem(ItemAsset, pos, Quaternion.identity);
			}
		}
	}
	internal sealed class CrucifixItem : MonoBehaviour
	{
		private ItemToggle _toggle;

		private PhysGrabObject _grab;

		private Light _glow;

		private bool _last;

		private float _cool;

		private float _flash;

		private void Start()
		{
			//IL_001e: 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)
			_toggle = ((Component)this).GetComponent<ItemToggle>();
			_grab = ((Component)this).GetComponent<PhysGrabObject>();
			_glow = new GameObject("CrossGlow").AddComponent<Light>();
			((Component)_glow).transform.SetParent(((Component)this).transform, false);
			_glow.type = (LightType)2;
			_glow.color = new Color(1f, 0.75f, 0.3f);
			_glow.range = 3f;
			_glow.intensity = 0f;
			if ((Object)(object)_toggle != (Object)null)
			{
				_last = _toggle.toggleState;
			}
		}

		private void Update()
		{
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: 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)
			_cool -= Time.deltaTime;
			_flash = Mathf.MoveTowards(_flash, 0f, Time.deltaTime * 2f);
			bool flag = (Object)(object)_grab != (Object)null && _grab.grabbed;
			_glow.intensity = (flag ? (0.5f + 0.15f * Mathf.Sin(Time.time * 3f)) : 0f) + _flash * 7f;
			_glow.range = 3f + _flash * 6f;
			bool flag2 = flag && _grab.playerGrabbing != null && _grab.playerGrabbing.Exists((PhysGrabber g) => (Object)(object)g != (Object)null && g.isLocal);
			if (flag2 && (Object)(object)ItemInfoExtraUI.instance != (Object)null)
			{
				ItemInfoExtraUI.instance.ItemInfoText("[E] RAISE THE CROSS", new Color(1f, 0.8f, 0.35f));
			}
			if ((Object)(object)_toggle == (Object)null || _toggle.toggleState == _last)
			{
				return;
			}
			_last = _toggle.toggleState;
			if (!(_cool > 0f) && flag)
			{
				_cool = 3f;
				_flash = 1f;
				List<AudioClip> value;
				AudioClip val = (LocustAssets.Sounds.TryGetValue("holy", out value) ? (value.Find((AudioClip x) => ((Object)x).name.Contains("tones")) ?? LocustAssets.Random("holy")) : null);
				if ((Object)(object)val != (Object)null)
				{
					AudioSource.PlayClipAtPoint(val, ((Component)this).transform.position, 0.8f * Plugin.Volume.Value);
				}
				if (flag2)
				{
					LocustFX.Instance?.Holy(0.35f);
				}
				if (LocustNet.IsHost)
				{
					LocustDirector.Instance?.TryBanish(((Component)this).transform.position);
				}
			}
		}
	}
	internal sealed class LocustDirector : MonoBehaviour
	{
		public static LocustDirector Instance;

		private static readonly FieldRef<PlayerAvatar, bool> IsDisabled = AccessTools.FieldRefAccess<PlayerAvatar, bool>("isDisabled");

		private static readonly FieldRef<PlayerAvatar, bool> DeadSet = AccessTools.FieldRefAccess<PlayerAvatar, bool>("deadSet");

		private static readonly FieldRef<PlayerAvatar, bool> IsSprinting = AccessTools.FieldRefAccess<PlayerAvatar, bool>("isSprinting");

		private static readonly FieldRef<PlayerAvatar, bool> IsCrouching = AccessTools.FieldRefAccess<PlayerAvatar, bool>("isCrouching");

		private static readonly FieldRef<PlayerAvatar, PlayerVoiceChat> Voice = AccessTools.FieldRefAccess<PlayerAvatar, PlayerVoiceChat>("voiceChat");

		private static readonly FieldRef<PlayerVoiceChat, float> Loudness = AccessTools.FieldRefAccess<PlayerVoiceChat, float>("clipLoudness");

		private static readonly FieldRef<PhysGrabHinge, HingeJoint> Joint = AccessTools.FieldRefAccess<PhysGrabHinge, HingeJoint>("joint");

		private static readonly FieldRef<PhysGrabHinge, bool> HingeBroken = AccessTools.FieldRefAccess<PhysGrabHinge, bool>("broken");

		private static readonly FieldRef<Enemy, PlayerAvatar> EnemyTarget = AccessTools.FieldRefAccess<Enemy, PlayerAvatar>("TargetPlayerAvatar");

		private static readonly FieldRef<LevelPoint, bool> InStartRoom = AccessTools.FieldRefAccess<LevelPoint, bool>("inStartRoom");

		private LocustEntity _e;

		private NavMeshAgent _agent;

		private LevelGenerator _level;

		private readonly List<Vector3> _points = new List<Vector3>();

		private bool _rolled;

		private bool _active;

		private float _levelTime;

		private float _cooldown;

		private float _stateTime;

		private float _sendTimer;

		private float _stare;

		private float _lit;

		private float _retarget;

		private float _doorTimer;

		private float _moveTimer;

		private PlayerAvatar _target;

		private Vector3 _goal;

		private float _watchFor = 10f;

		private float _stareMin = 1.5f;

		private float _prevNear = -1f;

		private float _closing;

		private float _noSight;

		private float _aggr;

		private float _vultureTimer;

		private float _paranoiaTimer = 30f;

		private float _lureTimer = 45f;

		private float _groupTime;

		private bool _hasGoal;

		private bool _retreat;

		private bool _slip;

		private bool _creaked;

		private bool _opening;

		private bool _vulture;

		private bool _escape;

		private readonly Dictionary<int, bool> _seenBy = new Dictionary<int, bool>();

		private readonly Dictionary<int, bool> _litBy = new Dictionary<int, bool>();

		private int _crawlPhase;

		private float _crawlT;

		private Vector3 _crawlFrom;

		private Vector3 _crawlTo;

		private Quaternion _crawlRotFrom;

		private int _underPhase;

		private float _underT;

		private float _underFor;

		private float _sayTimer = 20f;

		private Vector3 _underNav;

		private Vector3 _underBody;

		private Vector3 _underFrom;

		private Quaternion _underRot;

		private Quaternion _underRotFrom;

		private LurkNode _node;

		private bool _hasNode;

		private bool _atNode;

		private bool _preferHigh;

		private bool _cling;

		private bool _attackDrop;

		private Quaternion _clingRot;

		private Coroutine _scan;

		private bool _seenNow;

		private bool _lurePending;

		private int _lureCount;

		private float _glide = 10f;

		private const float FrenzySpeed = 13.5f;

		private const float ScuttleSpeed = 8.5f;

		private int _netTarget = -1;

		private float _grace;

		private bool _sentSeen;

		private bool _sentLit;

		private static readonly FieldRef<PhysGrabObject, PlayerAvatar> LastGrabber = AccessTools.FieldRefAccess<PhysGrabObject, PlayerAvatar>("lastPlayerGrabbing");

		private bool _banished;

		private static readonly float[] SeeHeights = new float[3] { 2.5f, 1.7f, 0.9f };

		private readonly Dictionary<int, Vector3> _pPos = new Dictionary<int, Vector3>();

		private readonly Dictionary<int, Vector3> _pVel = new Dictionary<int, Vector3>();

		private readonly Dictionary<int, float> _pAng = new Dictionary<int, float>();

		private readonly Dictionary<int, float> _pTurn = new Dictionary<int, float>();

		private static readonly float[] TorsoHeights = new float[3] { 1f, 1.45f, 1.9f };

		public LocustEntity Entity => _e;

		private static bool InLevel
		{
			get
			{
				if (SemiFunc.RunIsLevel() && !SemiFunc.RunIsShop() && !SemiFunc.RunIsArena() && !SemiFunc.RunIsTutorial() && !SemiFunc.RunIsLobby() && !SemiFunc.RunIsLobbyMenu())
				{
					return SemiFunc.LevelGenDone();
				}
				return false;
			}
		}

		private static int VisionMask => LayerMask.op_Implicit(SemiFunc.LayerMaskGetVisionObstruct()) | LayerMask.GetMask(new string[1] { "HideTriggers" });

		private float Glide(float watched)
		{
			if (!_seenNow)
			{
				return _glide;
			}
			return watched;
		}

		private static bool High(LurkNodeType t)
		{
			if (t != LurkNodeType.CeilingAnchor && t != LurkNodeType.WallPerch)
			{
				return t == LurkNodeType.PitWall;
			}
			return true;
		}

		private void Awake()
		{
			Instance = this;
			LocustEntity.OnHit = delegate(LocustEntity e, Rigidbody rb)
			{
				if (LocustNet.IsHost && (Object)(object)e == (Object)(object)_e)
				{
					Provoke(rb);
				}
			};
		}

		private void Provoke(Rigidbody rb)
		{
			_aggr = Mathf.Min(100f, _aggr + 30f);
			PhysGrabObject component = ((Component)rb).GetComponent<PhysGrabObject>();
			PlayerAvatar val = (((Object)(object)component != (Object)null) ? LastGrabber.Invoke(component) : null);
			if ((Object)(object)val != (Object)null && Alive().Contains(val))
			{
				_target = val;
			}
		}

		public void TryBanish(Vector3 from)
		{
			//IL_0042: 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_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0068: 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_0080: 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_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: 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_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: 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_014a: Unknown result type (might be due to invalid IL or missing references)
			if (!LocustNet.IsHost || (Object)(object)_e == (Object)null || _banished)
			{
				return;
			}
			LocustState state = _e.State;
			if (state == LocustState.Hidden || state == LocustState.Kill || state == LocustState.Banished)
			{
				return;
			}
			Vector3 val = ((Component)_e).transform.position + ((Component)_e).transform.up * 1.4f;
			float num = Vector3.Distance(from, val);
			if (!(num > 9f) && (!(num > 4f) || !Physics.Linecast(from, val, VisionMask, (QueryTriggerInteraction)1)))
			{
				_banished = true;
				_active = false;
				Stop();
				if ((Object)(object)_agent != (Object)null)
				{
					((Behaviour)_agent).enabled = false;
				}
				NavMeshHit val3 = default(NavMeshHit);
				Vector3 val2 = (NavMesh.SamplePosition(((Component)_e).transform.position, ref val3, 6f, -1) ? ((NavMeshHit)(ref val3)).position : ((Component)_e).transform.position);
				((Component)_e).transform.position = val2;
				((Component)_e).transform.rotation = Quaternion.LookRotation(Flat(from - val2) + Vector3.forward * 0.001f);
				Enter(LocustState.Banished);
				LocustNet.SendBanish(_e, val2);
				Plugin.Log.LogInfo((object)"The Locust was banished by the crucifix");
			}
		}

		public void SpawnCrucifix()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: 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_003b: 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_004a: Unknown result type (might be due to invalid IL or missing references)
			PlayerAvatar val = SemiFunc.PlayerAvatarLocal();
			if (LocustNet.IsHost && (Object)(object)val != (Object)null)
			{
				LocustCrucifix.Spawn(((Component)val).transform.position + ((Component)val).transform.forward * 1.2f + Vector3.up * 1f);
			}
		}

		private void Update()
		{
			if ((Object)(object)LocustAssets.Template == (Object)null)
			{
				return;
			}
			LocustCrucifix.TryRegister();
			LevelGenerator instance = LevelGenerator.Instance;
			if ((Object)(object)instance == (Object)null || !InLevel)
			{
				if ((Object)(object)_e != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)_e).gameObject);
				}
				_level = null;
				return;
			}
			if ((Object)(object)instance != (Object)(object)_level)
			{
				ResetLevel(instance);
			}
			SenseLocal();
			if ((Object)(object)_e != (Object)null)
			{
				_e.LookAt = LookPoint();
			}
			if (LocustNet.IsHost)
			{
				HostTick(Time.deltaTime);
			}
		}

		private void ResetLevel(LevelGenerator lg)
		{
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			_level = lg;
			if ((Object)(object)_e != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)_e).gameObject);
			}
			_e = null;
			_agent = null;
			_target = null;
			_rolled = (_active = (_banished = false));
			_levelTime = (_cooldown = 0f);
			_seenBy.Clear();
			_litBy.Clear();
			_pPos.Clear();
			_pVel.Clear();
			_pAng.Clear();
			_pTurn.Clear();
			_aggr = 0f;
			_points.Clear();
			foreach (LevelPoint item in SemiFunc.LevelPointsGetAll())
			{
				if ((Object)(object)item != (Object)null && !item.Truck && !InStartRoom.Invoke(item))
				{
					_points.Add(((Component)item).transform.position);
				}
			}
			_sayTimer = Random.Range(12f, 20f);
			_lureCount = 0;
			if (_scan != null)
			{
				((MonoBehaviour)this).StopCoroutine(_scan);
			}
			LocustMapAnalyzer.Ready = false;
			if (LocustNet.IsHost)
			{
				_scan = ((MonoBehaviour)this).StartCoroutine(LocustMapAnalyzer.Scan(_points));
			}
		}

		public static List<PlayerAvatar> Alive()
		{
			List<PlayerAvatar> list = new List<PlayerAvatar>();
			foreach (PlayerAvatar item in SemiFunc.PlayerGetList())
			{
				if ((Object)(object)item != (Object)null && !IsDisabled.Invoke(item) && !DeadSet.Invoke(item))
				{
					list.Add(item);
				}
			}
			return list;
		}

		public static Vector3 Head(PlayerAvatar p)
		{
			//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_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)p == (Object)(object)SemiFunc.PlayerAvatarLocal()) || !((Object)(object)SemiFunc.MainCamera() != (Object)null))
			{
				return ((Component)p).transform.position + Vector3.up * 1.5f;
			}
			return ((Component)SemiFunc.MainCamera()).transform.position;
		}

		private static int ViewId(PlayerAvatar p)
		{
			if (!((Object)(object)p != (Object)null) || !((Object)(object)p.photonView != (Object)null))
			{
				return -1;
			}
			return p.photonView.ViewID;
		}

		private Vector3? LookPoint()
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			PlayerAvatar val = (LocustNet.IsHost ? _target : ((_netTarget >= 0) ? SemiFunc.PlayerAvatarGetFromPhotonID(_netTarget) : null));
			if (!((Object)(object)val != (Object)null))
			{
				return null;
			}
			return Head(val);
		}

		private void SenseLocal()
		{
			//IL_0071: 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_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: 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_00bf: 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_00c3: 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_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: 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_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			PlayerAvatar val = SemiFunc.PlayerAvatarLocal();
			Camera val2 = SemiFunc.MainCamera();
			bool flag = false;
			bool flag2 = false;
			if ((Object)(object)_e != (Object)null && (Object)(object)val != (Object)null && (Object)(object)val2 != (Object)null && _e.State != LocustState.Hidden && !DeadSet.Invoke(val) && !IsDisabled.Invoke(val))
			{
				Vector3 position = ((Component)val2).transform.position;
				bool flag3 = false;
				float[] seeHeights = SeeHeights;
				RaycastHit val5 = default(RaycastHit);
				foreach (float num in seeHeights)
				{
					Vector3 val3 = ((Component)_e).transform.position + ((Component)_e).transform.up * num;
					Vector3 val4 = position - val3;
					float magnitude = ((Vector3)(ref val4)).magnitude;
					if (!(magnitude > 30f) && SemiFunc.OnScreen(val3, -0.12f, -0.12f) && (!Physics.Raycast(val3, val4 / magnitude, ref val5, magnitude, VisionMask) || ((Component)((RaycastHit)(ref val5)).transform).CompareTag("Player") || !((Object)(object)((Component)((RaycastHit)(ref val5)).transform).GetComponentInParent<PlayerTumble>() == (Object)null)))
					{
						flag3 = true;
						break;
					}
				}
				Vector3 val6 = ((Component)_e).transform.position + ((Component)_e).transform.up * 1.7f;
				float num2 = Vector3.Distance(val6, position);
				FlashlightController flashlightController = val.flashlightController;
				if (flag3 && (Object)(object)flashlightController != (Object)null && flashlightController.LightActive && (Object)(object)flashlightController.spotlight != (Object)null && ((Behaviour)flashlightController.spotlight).enabled)
				{
					Transform transform = ((Component)flashlightController.spotlight).transform;
					flag2 = num2 < flashlightController.spotlight.range * 1.2f && Vector3.Angle(transform.forward, val6 - transform.position) < flashlightController.spotlight.spotAngle * 0.5f;
				}
				_grace = ((flag3 || flag2) ? (_grace + Time.deltaTime) : 0f);
				flag = _grace >= 0.25f;
				flag2 = flag2 && flag;
				LocustFX.Gaze = flag;
			}
			else
			{
				_grace = 0f;
				LocustFX.Gaze = false;
			}
			if ((flag != _sentSeen || flag2 != _sentLit) && (Object)(object)val != (Object)null)
			{
				_sentSeen = flag;
				_sentLit = flag2;
				LocustNet.SendSeen(ViewId(val), flag, flag2);
			}
		}

		public void ReportSeen(int viewId, bool seen, bool lit)
		{
			_seenBy[viewId] = seen;
			_litBy[viewId] = lit;
		}

		public void ClientState(LocustState s, Vector3 pos, Quaternion rot, int target)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: 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)
			_netTarget = target;
			if ((Object)(object)_e == (Object)null)
			{
				if (s == LocustState.Hidden)
				{
					return;
				}
				_e = LocustEntity.Create(pos, rot);
			}
			_e.Remote = true;
			_e.NetPos = pos;
			_e.NetRot = rot;
			_e.SetState(s);
		}

		public void ForceSpawn()
		{
			if (LocustNet.IsHost && !((Object)(object)_level == (Object)null))
			{
				_rolled = (_active = true);
				Spawn(near: true);
			}
		}

		private void HostTick(float dt)
		{
			_levelTime += dt;
			if (!_rolled && _levelTime > Plugin.SpawnDelay.Value)
			{
				_rolled = true;
				_active = Random.value < Plugin.SpawnChance.Value;
				if (_active)
				{
					Spawn(near: false);
				}
			}
			if ((Object)(object)_e == (Object)null || _e.State == LocustState.Hidden)
			{
				_cooldown -= dt;
				if (_active && !_banished && _cooldown <= 0f)
				{
					Spawn((Object)(object)_e != (Object)null);
				}
				if ((Object)(object)_e == (Object)null)
				{
					return;
				}
			}
			else
			{
				Think(dt);
			}
			_sendTimer -= dt;
			if (_sendTimer <= 0f)
			{
				Broadcast();
			}
		}

		private void Broadcast()
		{
			//IL_0021: 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)
			_sendTimer = 0.1f;
			LocustNet.SendState(_e.State, ((Component)_e).transform.position, ((Component)_e).transform.rotation, ViewId(_target));
		}

		private void Enter(LocustState s)
		{
			Plugin.Log.LogDebug((object)$"Locust {_e.State} -> {s} (t={_levelTime:0})");
			_stateTime = 0f;
			_hasGoal = false;
			_atNode = false;
			_lurePending = false;
			_stare = 0f;
			_noSight = 0f;
			_retreat = (_slip = (_creaked = false));
			_stareMin = Random.Range(1.2f, 2f);
			_glide = Random.Range(9.5f, 12f);
			_watchFor = Random.Range(8f, 18f);
			_e.SetState(s);
			Broadcast();
		}

		private void Spawn(bool near)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: 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)
			List<PlayerAvatar> list = Alive();
			if (list.Count == 0)
			{
				return;
			}
			if (!SpawnPoint(list, near, out var pos))
			{
				_cooldown = 5f;
				return;
			}
			Quaternion val = Quaternion.LookRotation(Flat(((Component)list[0]).transform.position - pos));
			if ((Object)(object)_e == (Object)null)
			{
				NavMeshAgent val2 = Object.FindAnyObjectByType<NavMeshAgent>();
				_e = LocustEntity.Create(pos, val);
				((Component)_e).gameObject.SetActive(false);
				_agent = ((Component)_e).gameObject.AddComponent<NavMeshAgent>();
				if ((Object)(object)val2 != (Object)null)
				{
					_agent.agentTypeID = val2.agentTypeID;
				}
				_agent.radius = 0.3f;
				_agent.height = 2.6f;
				_agent.stoppingDistance = 0.4f;
				_agent.obstacleAvoidanceType = (ObstacleAvoidanceType)0;
				_agent.updateRotation = false;
				_agent.acceleration = 45f;
				_agent.angularSpeed = 120f;
				((Component)_e).gameObject.SetActive(true);
			}
			((Behaviour)_agent).enabled = true;
			_agent.Warp(pos);
			((Component)_e).transform.rotation = val;
			_target = PickTarget(list);
			_stare = (_lit = 0f);
			_seenBy.Clear();
			_litBy.Clear();
			_pPos.Clear();
			_pAng.Clear();
			_pTurn.Clear();
			Enter(LocustState.Lurk);
			Plugin.Log.LogInfo((object)$"The Locust appeared at {pos}");
		}

		private bool SpawnPoint(List<PlayerAvatar> players, bool near, out Vector3 pos)
		{
			//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_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: 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_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: 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_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: 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_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			float num = (near ? 10f : 16f);
			float num2 = (near ? 24f : 45f);
			PlayerAvatar val = ((near && (Object)(object)_target != (Object)null && players.Contains(_target)) ? _target : null);
			List<Vector3> list = new List<Vector3>();
			List<Vector3> list2 = new List<Vector3>();
			foreach (Vector3 point in _points)
			{
				float num3 = (((Object)(object)val != (Object)null) ? Vector3.Distance(((Component)val).transform.position, point) : float.MaxValue);
				bool flag = false;
				foreach (PlayerAvatar player in players)
				{
					float num4 = Vector3.Distance(((Component)player).transform.position, point);
					if (num4 < 8f)
					{
						num3 = 0f;
					}
					if ((Object)(object)val == (Object)null)
					{
						num3 = Mathf.Min(num3, num4);
					}
					flag |= !Physics.Linecast(Head(player), point + Vector3.up * 1.5f, LayerMask.op_Implicit(SemiFunc.LayerMaskGetVisionObstruct()), (QueryTriggerInteraction)1);
				}
				if (!(num3 < num) && !(num3 > num2))
				{
					(flag ? list2 : list).Add(point);
				}
			}
			List<Vector3> list3 = ((list.Count > 0) ? list : list2);
			if (list3.Count == 0 && near)
			{
				return SpawnPoint(players, near: false, out pos);
			}
			pos = Vector3.zero;
			NavMeshHit val2 = default(NavMeshHit);
			if (list3.Count == 0 || !NavMesh.SamplePosition(list3[Random.Range(0, list3.Count)], ref val2, 3f, -1))
			{
				return false;
			}
			pos = ((NavMeshHit)(ref val2)).position;
			return true;
		}

		private PlayerAvatar PickTarget(List<PlayerAvatar> players)
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			PlayerAvatar result = null;
			float num = float.MinValue;
			foreach (PlayerAvatar player in players)
			{
				float num2 = 30f;
				foreach (PlayerAvatar player2 in players)
				{
					if ((Object)(object)player2 != (Object)(object)player)
					{
						num2 = Mathf.Min(num2, Vector3.Distance(((Component)player2).transform.position, ((Component)player).transform.position));
					}
				}
				float num3 = num2 - 0.35f * Vector3.Distance(((Component)player).transform.position, ((Object)(object)_e != (Object)null) ? ((Component)_e).transform.position : ((Component)player).transform.position);
				if (num3 > num)
				{
					num = num3;
					result = player;
				}
			}
			return result;
		}

		private void Think(float dt)
		{
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: 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_03e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03db: Unknown result type (might be due to invalid IL or missing references)
			//IL_06cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_07c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_07c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_07cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_07d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_07db: Unknown result type (might be due to invalid IL or missing references)
			//IL_067f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0726: Unknown result type (might be due to invalid IL or missing references)
			//IL_0428: Unknown result type (might be due to invalid IL or missing references)
			//IL_088d: Unknown result type (might be due to invalid IL or missing references)
			//IL_086f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0484: Unknown result type (might be due to invalid IL or missing references)
			//IL_0576: Unknown result type (might be due to invalid IL or missing references)
			//IL_053b: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_0563: Unknown result type (might be due to invalid IL or missing references)
			//IL_0556: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0568: Unknown result type (might be due to invalid IL or missing references)
			//IL_0610: Unknown result type (might be due to invalid IL or missing references)
			//IL_0617: Unknown result type (might be due to invalid IL or missing references)
			//IL_061c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0340: Unknown result type (might be due to invalid IL or missing references)
			//IL_0323: Unknown result type (might be due to invalid IL or missing references)
			_stateTime += dt;
			List<PlayerAvatar> list = Alive();
			if (list.Count == 0)
			{
				Vanish(10f);
				return;
			}
			if ((Object)(object)_target == (Object)null || !list.Contains(_target))
			{
				_target = PickTarget(list);
			}
			Vector3 position = ((Component)_e).transform.position;
			TrackPlayers(list, position, dt);
			float num = Vector3.Distance(Flat3(position), Flat3(((Component)_target).transform.position));
			int num2 = Count(_seenBy);
			int num3 = Count(_litBy);
			bool flag = (_seenNow = num2 > 0);
			LocustState state = _e.State;
			_e.SteerByVelocity = state != LocustState.Watch && state != LocustState.Peek && state != LocustState.Kill && state != LocustState.Stare && state != LocustState.Under && state != LocustState.Banished;
			if (state == LocustState.Banished)
			{
				if (_stateTime > 5.2f)
				{
					Vanish(99999f);
				}
				return;
			}
			_stare = (flag ? (_stare + dt) : 0f);
			_lit = ((num3 > 0) ? (_lit + dt) : Mathf.Max(0f, _lit - dt * 0.5f));
			if (state == LocustState.Frenzy && _lit > 1.6f)
			{
				Vanish(Plugin.Cooldown.Value);
				return;
			}
			if (state == LocustState.Lurk || state == LocustState.Watch || state == LocustState.Peek || state == LocustState.Stalk || state == LocustState.Stare)
			{
				float num4 = float.MaxValue;
				PlayerAvatar val = null;
				foreach (PlayerAvatar item in list)
				{
					float num5 = Vector3.Distance(((Component)item).transform.position, position);
					if (num5 < num4)
					{
						num4 = num5;
						val = item;
					}
				}
				if (_prevNear >= 0f)
				{
					_closing = Mathf.Lerp(_closing, (_prevNear - num4) / Mathf.Max(dt, 0.001f), dt * 3f);
				}
				_prevNear = num4;
				if (num3 >= 2 && !_retreat)
				{
					if (!TryCrawl(escape: true))
					{
						Retreat(val);
					}
					return;
				}
				if (!_retreat && state != LocustState.Stalk && (num4 < 3.5f || (num4 < 6f && flag)))
				{
					Retreat(val);
					return;
				}
				if (!_retreat && !_slip && !flag && state != LocustState.Stalk && state != LocustState.Stare && num4 < 9f && _closing > 1.2f)
				{
					Slip(val);
					return;
				}
				if (flag && _atNode && !_retreat)
				{
					if (_stare > 0.4f)
					{
						_preferHigh = true;
						Slip(val);
					}
				}
				else if (flag && state != LocustState.Stare && !_retreat)
				{
					Enter(LocustState.Stare);
					return;
				}
				if (!flag && !_retreat && !_slip && state != LocustState.Stalk && state != LocustState.Stare)
				{
					PlayerAvatar val2 = Turning(list, position);
					if ((Object)(object)val2 != (Object)null)
					{
						Slip(val2);
						return;
					}
				}
				Aggression(list, position, flag, dt);
				if (_aggr >= 100f && _opening && !flag && !_retreat && state != LocustState.Stalk && state != LocustState.Stare)
				{
					Strike();
					return;
				}
				_retarget -= dt;
				if (_retarget <= 0f && !_vulture)
				{
					_retarget = 8f;
					_target = PickTarget(list);
				}
				if (!_retreat && state != LocustState.Stalk && state != LocustState.Stare && Paranoia(list, dt))
				{
					return;
				}
			}
			if (state == LocustState.Under)
			{
				Aggression(list, position, flag, dt);
			}
			Mimic(list, position, flag, num, dt);
			switch (state)
			{
			case LocustState.Lurk:
			{
				if (_retreat)
				{
					MoveTo(_goal, Glide(2.8f));
					if (Arrived() || _stateTime > 6f)
					{
						if (flag)
						{
							Vanish(Random.Range(5f, 9f));
						}
						else
						{
							Enter(LocustState.Lurk);
						}
					}
					break;
				}
				if (_slip)
				{
					MoveTo(_goal, Glide(2.6f));
					if (Arrived() || _stateTime > 5f)
					{
						if (_preferHigh && PickNode(position, 8f, highOnly: true))
						{
							_preferHigh = false;
							_slip = false;
							_hasNode = (_hasGoal = true);
							_goal = _node.Floor;
							_stateTime = 0f;
						}
						else
						{
							Enter(LocustState.Watch);
						}
					}
					break;
				}
				if (!_hasGoal)
				{
					if (Random.value < 0.35f && UnderSpot())
					{
						Enter(LocustState.Under);
						_underPhase = 0;
						break;
					}
					_hasNode = PickNode(position, 0f, highOnly: false);
					_goal = (_hasNode ? _node.Floor : CoverPoint());
					_hasGoal = true;
				}
				MoveTo(_goal, Glide(1.9f));
				if (_lurePending && (Arrived() || _stateTime > 15f))
				{
					_lurePending = false;
					PlayLure();
				}
				if (!Arrived() && !(_stateTime > 25f))
				{
					break;
				}
				if (_hasNode && High(_node.Type))
				{
					Cling(_node);
					break;
				}
				bool atNode = _hasNode && Arrived();
				if (_hasNode)
				{
					Face(position - _node.Normal, 1f);
				}
				Enter(((!_hasNode || _node.Type == LurkNodeType.DoorframePeek) && CanPeek() && Random.value < 0.6f) ? LocustState.Peek : LocustState.Watch);
				_atNode = atNode;
				break;
			}
			case LocustState.Watch:
				Stop();
				Face(((Component)_target).transform.position, dt * 2f);
				if (_stateTime > _watchFor || CheckLostSight(dt) || num > 30f)
				{
					Enter(LocustState.Lurk);
				}
				break;
			case LocustState.Peek:
				Stop();
				Face(((Component)_target).transform.position, dt * 2f);
				if (!_creaked)
				{
					_creaked = true;
					CreakNearbyDoor();
				}
				if (_stateTime > _watchFor || CheckLostSight(dt))
				{
					Enter(LocustState.Lurk);
				}
				break;
			case LocustState.Stare:
				Stop();
				Face(((Component)_target).transform.position, dt * 3f);
				if (_stare > 8f)
				{
					if (Random.value < 0.35f)
					{
						Vanish(Random.Range(6f, 10f));
					}
					else
					{
						Slip(_target);
					}
				}
				else if (!flag && _stateTime > _stareMin && (!(Random.value < 0.4f) || !TryCrawl(escape: true)))
				{
					Slip(_target);
				}
				break;
			case LocustState.Stalk:
			{
				Transform transform = ((Component)_target).transform;
				MoveTo(transform.position - Flat(transform.forward) * 1.5f, Glide(6f));
				if (num < 4.5f)
				{
					Enter(LocustState.Frenzy);
				}
				else if (_stateTime > 25f || (_stateTime > 3f && !_opening))
				{
					_aggr = 40f;
					Enter(LocustState.Lurk);
				}
				break;
			}
			case LocustState.Crawl:
				CrawlStep(dt, flag);
				break;
			case LocustState.Under:
				UnderStep(dt, list, flag);
				break;
			case LocustState.Frenzy:
				if (_stateTime < 0.35f)
				{
					Stop();
					Face(((Component)_target).transform.position, dt * 8f);
					break;
				}
				MoveTo(((Component)_target).transform.position, 13.5f);
				PushDoors(4f, dt);
				if (num < 1.7f)
				{
					Kill(_target);
				}
				else if (_stateTime > 13f)
				{
					Vanish(Random.Range(15f, 25f));
				}
				break;
			case LocustState.Kill:
				Stop();
				if (_stateTime > 2.1f)
				{
					Vanish(Plugin.Cooldown.Value);
				}
				break;
			}
		}

		private static int Count(Dictionary<int, bool> d)
		{
			int num = 0;
			foreach (bool value in d.Values)
			{
				if (value)
				{
					num++;
				}
			}
			return num;
		}

		private void TrackPlayers(List<PlayerAvatar> players, Vector3 pos, float dt)
		{
			//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_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_0047: 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_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: 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_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: 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_00a7: Unknown result type (might be due to invalid IL or missing references)
			float num = 1f / Mathf.Max(dt, 0.001f);
			foreach (PlayerAvatar player in players)
			{
				int key = ViewId(player);
				Vector3 position = ((Component)player).transform.position;
				float num2 = Vector3.Angle(Flat(((Component)player).transform.forward), Flat(pos - position));
				if (_pPos.TryGetValue(key, out var value))
				{
					_pVel[key] = Vector3.Lerp(_pVel.TryGetValue(key, out var value2) ? value2 : Vector3.zero, Flat(position - value) * num, dt * 4f);
					_pTurn[key] = Mathf.Lerp(_pTurn.TryGetValue(key, out var value3) ? value3 : 0f, (_pAng[key] - num2) * num, dt * 8f);
				}
				_pPos[key] = position;
				_pAng[key] = num2;
			}
		}

		private Vector3 Vel(PlayerAvatar p)
		{
			//IL_001b: 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)
			if (!_pVel.TryGetValue(ViewId(p), out var value))
			{
				return Vector3.zero;
			}
			return value;
		}

		private Vector3 Predict(PlayerAvatar p)
		{
			//IL_0002: 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_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: 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)
			Vector3 val = Vector3.ClampMagnitude(Vel(p) * 4f, 12f);
			NavMeshHit val2 = default(NavMeshHit);
			if (!(((Vector3)(ref val)).sqrMagnitude > 1f) || !NavMesh.SamplePosition(((Component)p).transform.position + val, ref val2, 3f, -1))
			{
				return ((Component)p).transform.position;
			}
			return ((NavMeshHit)(ref val2)).position;
		}

		private PlayerAvatar Turning(List<PlayerAvatar> players, Vector3 pos)
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			foreach (PlayerAvatar player in players)
			{
				int key = ViewId(player);
				if (_pAng.TryGetValue(key, out var value) && !(value < 45f) && !(value > 95f) && _pTurn.TryGetValue(key, out var value2) && !(value2 < 50f) && Vector3.Distance(((Component)player).transform.position, pos) < 30f && Sees(pos, Head(player)))
				{
					return player;
				}
			}
			return null;
		}

		private void Aggression(List<PlayerAvatar> players, Vector3 pos, bool seen, float dt)
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			_vultureTimer -= dt;
			if (_vultureTimer <= 0f)
			{
				_vultureTimer = 1f;
				_vulture = Vulture(players);
			}
			bool flag = players.Count > 1 && Straggler(_target, players);
			bool flag2 = Unwatched(players,