Decompiled source of Peanut v1.0.0

plugins/Peanut.dll

Decompiled 3 hours 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.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using REPOLib.Modules;
using REPOLib.Objects.Sdk;
using ShyGuy;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Audio;
using UnityEngine.Events;
using UnityEngine.Networking;
using UnityEngine.Rendering;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Peanut")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Peanut")]
[assembly: AssemblyTitle("Peanut")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ShyGuy
{
	public static class B3DLoader
	{
		public class Result
		{
			public GameObject Root;

			public SkinnedMeshRenderer Renderer;

			public MeshRenderer StaticRenderer;

			public Mesh Mesh;

			public Animation Animation;

			public Dictionary<string, AnimationClip> Clips = new Dictionary<string, AnimationClip>();

			public Bounds Bounds;

			public List<string> TextureFiles = new List<string>();

			public List<(int texture, Color color)> SubmeshBrushes = new List<(int, Color)>();
		}

		private class Brush
		{
			public string Name;

			public Color Color;

			public int Texture = -1;
		}

		private class Keys
		{
			public SortedDictionary<int, Vector3> Pos = new SortedDictionary<int, Vector3>();

			public SortedDictionary<int, Vector3> Scale = new SortedDictionary<int, Vector3>();

			public SortedDictionary<int, Quaternion> Rot = new SortedDictionary<int, Quaternion>();
		}

		private class Node
		{
			public string Name;

			public Vector3 Pos;

			public Vector3 Scale;

			public Quaternion Rot;

			public Node Parent;

			public List<Node> Children = new List<Node>();

			public Keys Keys;

			public List<(int vertex, float weight)> Weights;

			public Transform Transform;

			public int BoneIndex = -1;
		}

		private class Sequence
		{
			public string Name;

			public int Start;

			public int End;
		}

		private static byte[] d;

		private static List<string> texFiles;

		private static List<Brush> brushes;

		private static List<Vector3> verts;

		private static List<Vector3> normals;

		private static List<Vector2> uvs;

		private static List<(int brush, List<int> tris)> triSets;

		private static int meshBrush;

		private static Node meshNode;

		private static int animFrames;

		private static float animFps;

		private static List<Sequence> seqs;

		public static Result Load(byte[] bytes, string name)
		{
			d = bytes;
			texFiles = new List<string>();
			brushes = new List<Brush>();
			verts = new List<Vector3>();
			normals = new List<Vector3>();
			uvs = new List<Vector2>();
			triSets = new List<(int, List<int>)>();
			meshNode = null;
			seqs = new List<Sequence>();
			animFrames = 0;
			animFps = 30f;
			meshBrush = -1;
			if (Tag(0) != "BB3D")
			{
				throw new InvalidDataException("Not a B3D file.");
			}
			Node node = null;
			int num = 8 + I(4);
			int num2 = 12;
			while (num2 < num)
			{
				string text = Tag(num2);
				int num3 = I(num2 + 4);
				int num4 = num2 + 8;
				int num5 = num4 + num3;
				switch (text)
				{
				case "TEXS":
					ReadTexs(num4, num5);
					break;
				case "BRUS":
					ReadBrus(num4, num5);
					break;
				case "NODE":
					node = ReadNode(num4, num5, null);
					break;
				}
				num2 = num5;
			}
			if (node == null || meshNode == null)
			{
				throw new InvalidDataException("B3D has no mesh.");
			}
			Result result = Build(node, name);
			d = null;
			return result;
		}

		private static string Tag(int p)
		{
			return Encoding.ASCII.GetString(d, p, 4);
		}

		private static int I(int p)
		{
			return BitConverter.ToInt32(d, p);
		}

		private static float F(int p)
		{
			return BitConverter.ToSingle(d, p);
		}

		private static string Str(ref int p)
		{
			int num = p;
			while (d[p] != 0)
			{
				p++;
			}
			StringBuilder stringBuilder = new StringBuilder(p - num);
			for (int i = num; i < p; i++)
			{
				stringBuilder.Append((char)d[i]);
			}
			p++;
			return stringBuilder.ToString();
		}

		private static void ReadTexs(int p, int end)
		{
			while (p < end)
			{
				string text = Str(ref p);
				p += 28;
				int num = Math.Max(text.LastIndexOf('\\'), text.LastIndexOf('/'));
				texFiles.Add((num >= 0) ? text.Substring(num + 1) : text);
			}
		}

		private static void ReadBrus(int p, int end)
		{
			//IL_0041: 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)
			int num = I(p);
			p += 4;
			while (p < end)
			{
				Brush brush = new Brush
				{
					Name = Str(ref p)
				};
				brush.Color = new Color(F(p), F(p + 4), F(p + 8), F(p + 12));
				p += 16;
				p += 12;
				for (int i = 0; i < num; i++)
				{
					int texture = I(p);
					p += 4;
					if (i == 0)
					{
						brush.Texture = texture;
					}
				}
				brushes.Add(brush);
			}
		}

		private static Node ReadNode(int p, int end, Node parent)
		{
			//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_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_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			Node node = new Node
			{
				Parent = parent,
				Name = Str(ref p)
			};
			node.Pos = new Vector3(F(p), F(p + 4), F(p + 8));
			node.Scale = new Vector3(F(p + 12), F(p + 16), F(p + 20));
			node.Rot = new Quaternion(0f - F(p + 28), 0f - F(p + 32), 0f - F(p + 36), F(p + 24));
			p += 40;
			while (p < end)
			{
				string text = Tag(p);
				int num = I(p + 4);
				int num2 = p + 8;
				int num3 = num2 + num;
				switch (text)
				{
				case "MESH":
					meshNode = node;
					ReadMesh(num2, num3);
					break;
				case "BONE":
				{
					node.Weights = new List<(int, float)>();
					for (int i = num2; i + 8 <= num3; i += 8)
					{
						node.Weights.Add((I(i), F(i + 4)));
					}
					break;
				}
				case "KEYS":
					ReadKeys(node, num2, num3);
					break;
				case "ANIM":
					animFrames = I(num2 + 4);
					animFps = F(num2 + 8);
					if (animFps <= 0f)
					{
						animFps = 30f;
					}
					break;
				case "SEQS":
				{
					int p2 = num2;
					Sequence sequence = new Sequence
					{
						Name = Str(ref p2)
					};
					sequence.Start = I(p2);
					sequence.End = I(p2 + 4);
					seqs.Add(sequence);
					break;
				}
				case "NODE":
					node.Children.Add(ReadNode(num2, num3, node));
					break;
				}
				p = num3;
			}
			return node;
		}

		private static void ReadMesh(int p, int end)
		{
			//IL_0082: 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_00fe: Unknown result type (might be due to invalid IL or missing references)
			meshBrush = I(p);
			p += 4;
			while (p < end)
			{
				string text = Tag(p);
				int num = I(p + 4);
				int num2 = p + 8;
				int num3 = num2 + num;
				if (text == "VRTS")
				{
					int num4 = I(num2);
					int num5 = I(num2 + 4);
					int num6 = I(num2 + 8);
					int num7 = num2 + 12;
					while (num7 < num3)
					{
						verts.Add(new Vector3(F(num7), F(num7 + 4), F(num7 + 8)));
						num7 += 12;
						if ((num4 & 1) != 0)
						{
							normals.Add(new Vector3(F(num7), F(num7 + 4), F(num7 + 8)));
							num7 += 12;
						}
						if ((num4 & 2) != 0)
						{
							num7 += 16;
						}
						for (int i = 0; i < num5; i++)
						{
							if (i == 0 && num6 >= 2)
							{
								uvs.Add(new Vector2(F(num7), 1f - F(num7 + 4)));
							}
							num7 += 4 * num6;
						}
					}
				}
				else if (text == "TRIS")
				{
					int item = I(num2);
					List<int> list = new List<int>();
					for (int j = num2 + 4; j + 12 <= num3; j += 12)
					{
						list.Add(I(j));
						list.Add(I(j + 4));
						list.Add(I(j + 8));
					}
					triSets.Add((item, list));
				}
				p = num3;
			}
		}

		private static void ReadKeys(Node n, int p, int end)
		{
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			if (n.Keys == null)
			{
				n.Keys = new Keys();
			}
			int num = I(p);
			p += 4;
			int num2 = 4 + (((num & 1) != 0) ? 12 : 0) + (((num & 2) != 0) ? 12 : 0) + (((num & 4) != 0) ? 16 : 0);
			while (p + num2 <= end)
			{
				int key = I(p);
				int num3 = p + 4;
				if ((num & 1) != 0)
				{
					n.Keys.Pos[key] = new Vector3(F(num3), F(num3 + 4), F(num3 + 8));
					num3 += 12;
				}
				if ((num & 2) != 0)
				{
					n.Keys.Scale[key] = new Vector3(F(num3), F(num3 + 4), F(num3 + 8));
					num3 += 12;
				}
				if ((num & 4) != 0)
				{
					n.Keys.Rot[key] = new Quaternion(0f - F(num3 + 4), 0f - F(num3 + 8), 0f - F(num3 + 12), F(num3));
				}
				p += num2;
			}
		}

		private static Result Build(Node root, string name)
		{
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Expected O, but got Unknown
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Expected O, but got Unknown
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0361: Unknown result type (might be due to invalid IL or missing references)
			//IL_037b: Unknown result type (might be due to invalid IL or missing references)
			//IL_037d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0528: Unknown result type (might be due to invalid IL or missing references)
			//IL_052f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0534: Unknown result type (might be due to invalid IL or missing references)
			//IL_0539: Unknown result type (might be due to invalid IL or missing references)
			//IL_057a: Unknown result type (might be due to invalid IL or missing references)
			//IL_057f: Unknown result type (might be due to invalid IL or missing references)
			//IL_058f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0594: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0694: Unknown result type (might be due to invalid IL or missing references)
			//IL_0699: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_06c1: Expected O, but got Unknown
			Result result = new Result();
			result.TextureFiles.AddRange(texFiles);
			List<Node> list = new List<Node>();
			CreateTransforms(root, null, list);
			result.Root = ((Component)root.Transform).gameObject;
			((Object)result.Root).name = name;
			List<Node> list2 = new List<Node>();
			foreach (Node item in list)
			{
				if (item.Weights != null)
				{
					item.BoneIndex = list2.Count;
					list2.Add(item);
				}
			}
			Mesh val = new Mesh
			{
				name = name + " Mesh"
			};
			if (verts.Count > 65535)
			{
				val.indexFormat = (IndexFormat)1;
			}
			val.SetVertices(verts);
			if (normals.Count == verts.Count)
			{
				val.SetNormals(normals);
			}
			if (uvs.Count == verts.Count)
			{
				val.SetUVs(0, uvs);
			}
			val.subMeshCount = triSets.Count;
			for (int i = 0; i < triSets.Count; i++)
			{
				val.SetTriangles(triSets[i].tris, i);
				int num = ((triSets[i].brush >= 0) ? triSets[i].brush : meshBrush);
				Brush brush = ((num >= 0 && num < brushes.Count) ? brushes[num] : null);
				result.SubmeshBrushes.Add((brush?.Texture ?? (-1), brush?.Color ?? Color.white));
			}
			if (list2.Count == 0)
			{
				val.RecalculateBounds();
				if (normals.Count != verts.Count)
				{
					val.RecalculateNormals();
				}
				val.RecalculateTangents();
				result.Bounds = val.bounds;
				result.Mesh = val;
				GameObject val2 = new GameObject(name + " Mesh");
				val2.transform.SetParent(meshNode.Transform, false);
				val2.AddComponent<MeshFilter>().sharedMesh = val;
				result.StaticRenderer = val2.AddComponent<MeshRenderer>();
				return result;
			}
			List<(int, float)>[] array = new List<(int, float)>[verts.Count];
			foreach (Node item2 in list2)
			{
				foreach (var (num2, num3) in item2.Weights)
				{
					if (num2 >= 0 && num2 < array.Length && num3 > 0f)
					{
						List<(int, float)>[] array2 = array;
						int num4 = num2;
						(array2[num4] ?? (array2[num4] = new List<(int, float)>())).Add((item2.BoneIndex, num3));
					}
				}
			}
			BoneWeight[] array3 = (BoneWeight[])(object)new BoneWeight[verts.Count];
			for (int j = 0; j < array.Length; j++)
			{
				List<(int, float)> list3 = array[j];
				if (list3 == null || list3.Count == 0)
				{
					int num5 = j;
					BoneWeight val3 = default(BoneWeight);
					((BoneWeight)(ref val3)).boneIndex0 = 0;
					((BoneWeight)(ref val3)).weight0 = 0f;
					array3[num5] = val3;
					continue;
				}
				list3.Sort(((int bone, float w) a, (int bone, float w) b) => b.w.CompareTo(a.w));
				float num6 = 0f;
				for (int num7 = 0; num7 < list3.Count && num7 < 4; num7++)
				{
					num6 += list3[num7].Item2;
				}
				BoneWeight val4 = default(BoneWeight);
				if (list3.Count > 0)
				{
					((BoneWeight)(ref val4)).boneIndex0 = list3[0].Item1;
					((BoneWeight)(ref val4)).weight0 = list3[0].Item2 / num6;
				}
				if (list3.Count > 1)
				{
					((BoneWeight)(ref val4)).boneIndex1 = list3[1].Item1;
					((BoneWeight)(ref val4)).weight1 = list3[1].Item2 / num6;
				}
				if (list3.Count > 2)
				{
					((BoneWeight)(ref val4)).boneIndex2 = list3[2].Item1;
					((BoneWeight)(ref val4)).weight2 = list3[2].Item2 / num6;
				}
				if (list3.Count > 3)
				{
					((BoneWeight)(ref val4)).boneIndex3 = list3[3].Item1;
					((BoneWeight)(ref val4)).weight3 = list3[3].Item2 / num6;
				}
				array3[j] = val4;
			}
			val.boneWeights = array3;
			Transform transform = meshNode.Transform;
			Transform[] array4 = (Transform[])(object)new Transform[list2.Count];
			Matrix4x4[] array5 = (Matrix4x4[])(object)new Matrix4x4[list2.Count];
			for (int num8 = 0; num8 < list2.Count; num8++)
			{
				array4[num8] = list2[num8].Transform;
				array5[num8] = array4[num8].worldToLocalMatrix * transform.localToWorldMatrix;
			}
			val.bindposes = array5;
			val.RecalculateBounds();
			if (normals.Count != verts.Count)
			{
				val.RecalculateNormals();
			}
			result.Bounds = val.bounds;
			GameObject val5 = new GameObject(name + " Skin");
			val5.transform.SetParent(transform, false);
			SkinnedMeshRenderer val6 = val5.AddComponent<SkinnedMeshRenderer>();
			val6.sharedMesh = val;
			val6.bones = array4;
			val6.rootBone = ((list2.Count > 0) ? FindTopBone(list2) : transform);
			val6.updateWhenOffscreen = true;
			result.Renderer = val6;
			result.Mesh = val;
			Animation val7 = (result.Animation = result.Root.AddComponent<Animation>());
			List<Node> list4 = list.FindAll((Node n) => n.Keys != null);
			if (seqs.Count == 0 && animFrames > 0)
			{
				seqs.Add(new Sequence
				{
					Name = "all",
					Start = 1,
					End = animFrames
				});
			}
			foreach (Sequence seq in seqs)
			{
				if (seq.End <= seq.Start)
				{
					continue;
				}
				AnimationClip val8 = new AnimationClip
				{
					name = seq.Name,
					legacy = true,
					frameRate = animFps,
					wrapMode = (WrapMode)2
				};
				foreach (Node item3 in list4)
				{
					AddCurves(val8, item3, PathTo(item3, root), seq.Start, seq.End);
				}
				val8.EnsureQuaternionContinuity();
				val7.AddClip(val8, seq.Name);
				result.Clips[seq.Name] = val8;
			}
			return result;
		}

		private static Transform FindTopBone(List<Node> bones)
		{
			Node top = bones[0];
			while (top.Parent != null && !bones.TrueForAll((Node b) => IsUnder(b, top)))
			{
				top = top.Parent;
			}
			return top.Transform;
		}

		private static bool IsUnder(Node n, Node ancestor)
		{
			while (n != null)
			{
				if (n == ancestor)
				{
					return true;
				}
				n = n.Parent;
			}
			return false;
		}

		private static void CreateTransforms(Node n, Transform parent, List<Node> all)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: 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)
			Transform transform = new GameObject(n.Name).transform;
			if (Object.op_Implicit((Object)(object)parent))
			{
				transform.SetParent(parent, false);
			}
			transform.localPosition = n.Pos;
			transform.localRotation = n.Rot;
			transform.localScale = n.Scale;
			n.Transform = transform;
			all.Add(n);
			foreach (Node child in n.Children)
			{
				CreateTransforms(child, transform, all);
			}
		}

		private static string PathTo(Node n, Node root)
		{
			List<string> list = new List<string>();
			Node node = n;
			while (node != null && node != root)
			{
				list.Insert(0, node.Name);
				node = node.Parent;
			}
			return string.Join("/", list);
		}

		private static void AddCurves(AnimationClip clip, Node n, string path, int start, int end)
		{
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			//IL_004f: 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: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: 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_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: 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_024f: 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)
			//IL_0259: 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_0273: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Unknown result type (might be due to invalid IL or missing references)
			//IL_0283: Unknown result type (might be due to invalid IL or missing references)
			//IL_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_028f: Unknown result type (might be due to invalid IL or missing references)
			//IL_029a: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a6: 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_0167: 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_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: 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_0198: 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_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: 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_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			Keys keys = n.Keys;
			int num = end - start + 1;
			if (keys.Pos.Count > 0)
			{
				Keyframe[] array = (Keyframe[])(object)new Keyframe[num];
				Keyframe[] array2 = (Keyframe[])(object)new Keyframe[num];
				Keyframe[] array3 = (Keyframe[])(object)new Keyframe[num];
				for (int i = 0; i < num; i++)
				{
					Vector3 val = SampleV(keys.Pos, start + i, n.Pos);
					float num2 = (float)i / animFps;
					array[i] = new Keyframe(num2, val.x);
					array2[i] = new Keyframe(num2, val.y);
					array3[i] = new Keyframe(num2, val.z);
				}
				Set(clip, path, "localPosition.x", array);
				Set(clip, path, "localPosition.y", array2);
				Set(clip, path, "localPosition.z", array3);
			}
			if (keys.Rot.Count > 0)
			{
				Keyframe[] array4 = (Keyframe[])(object)new Keyframe[num];
				Keyframe[] array5 = (Keyframe[])(object)new Keyframe[num];
				Keyframe[] array6 = (Keyframe[])(object)new Keyframe[num];
				Keyframe[] array7 = (Keyframe[])(object)new Keyframe[num];
				Quaternion val2 = Quaternion.identity;
				for (int j = 0; j < num; j++)
				{
					Quaternion val3 = SampleQ(keys.Rot, start + j, n.Rot);
					if (j > 0 && Quaternion.Dot(val2, val3) < 0f)
					{
						((Quaternion)(ref val3))..ctor(0f - val3.x, 0f - val3.y, 0f - val3.z, 0f - val3.w);
					}
					val2 = val3;
					float num3 = (float)j / animFps;
					array4[j] = new Keyframe(num3, val3.x);
					array5[j] = new Keyframe(num3, val3.y);
					array6[j] = new Keyframe(num3, val3.z);
					array7[j] = new Keyframe(num3, val3.w);
				}
				Set(clip, path, "localRotation.x", array4);
				Set(clip, path, "localRotation.y", array5);
				Set(clip, path, "localRotation.z", array6);
				Set(clip, path, "localRotation.w", array7);
			}
			if (keys.Scale.Count > 0)
			{
				Keyframe[] array8 = (Keyframe[])(object)new Keyframe[num];
				Keyframe[] array9 = (Keyframe[])(object)new Keyframe[num];
				Keyframe[] array10 = (Keyframe[])(object)new Keyframe[num];
				for (int k = 0; k < num; k++)
				{
					Vector3 val4 = SampleV(keys.Scale, start + k, n.Scale);
					float num4 = (float)k / animFps;
					array8[k] = new Keyframe(num4, val4.x);
					array9[k] = new Keyframe(num4, val4.y);
					array10[k] = new Keyframe(num4, val4.z);
				}
				Set(clip, path, "localScale.x", array8);
				Set(clip, path, "localScale.y", array9);
				Set(clip, path, "localScale.z", array10);
			}
		}

		private static void Set(AnimationClip clip, string path, string prop, Keyframe[] keys)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			AnimationCurve val = new AnimationCurve(keys);
			for (int i = 0; i < keys.Length; i++)
			{
				val.SmoothTangents(i, 0f);
			}
			clip.SetCurve(path, typeof(Transform), prop, val);
		}

		private static void Bracket<T>(SortedDictionary<int, T> keys, int frame, out int a, out int b)
		{
			a = int.MinValue;
			b = int.MaxValue;
			foreach (int key in keys.Keys)
			{
				if (key <= frame)
				{
					a = key;
				}
				if (key >= frame)
				{
					b = key;
					break;
				}
			}
		}

		private static Vector3 SampleV(SortedDictionary<int, Vector3> keys, int frame, Vector3 rest)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: 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_0042: 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)
			if (keys.Count == 0)
			{
				return rest;
			}
			Bracket(keys, frame, out var a, out var b);
			if (a == int.MinValue)
			{
				return keys[b];
			}
			if (b == int.MaxValue || a == b)
			{
				return keys[a];
			}
			return Vector3.Lerp(keys[a], keys[b], (float)(frame - a) / (float)(b - a));
		}

		private static Quaternion SampleQ(SortedDictionary<int, Quaternion> keys, int frame, Quaternion rest)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: 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_0042: 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)
			if (keys.Count == 0)
			{
				return rest;
			}
			Bracket(keys, frame, out var a, out var b);
			if (a == int.MinValue)
			{
				return keys[b];
			}
			if (b == int.MaxValue || a == b)
			{
				return keys[a];
			}
			return Quaternion.Slerp(keys[a], keys[b], (float)(frame - a) / (float)(b - a));
		}
	}
}
namespace Peanut
{
	internal class BlinkBarUI : SemiUI
	{
		private static BlinkBarUI bar;

		private static bool failed;

		private RawImage fillImage;

		private RawImage leftEye;

		private RawImage rightEye;

		private bool wasBlinking;

		private float warnTimer;

		private int eyeFrame = -1;

		private static Texture2D[] eyeFrames;

		internal static bool Active => Object.op_Implicit((Object)(object)bar);

		internal static void Ensure()
		{
			if (Object.op_Implicit((Object)(object)bar) || failed)
			{
				return;
			}
			TumbleWingsUI instance = TumbleWingsUI.instance;
			if (!Object.op_Implicit((Object)(object)instance) || !Object.op_Implicit((Object)(object)instance.imageBar))
			{
				return;
			}
			try
			{
				Build(instance);
			}
			catch (Exception ex)
			{
				failed = true;
				Plugin.Log.LogWarning((object)("Peanut: couldn't build the HUD blink bar, using the simple one instead. " + ex.Message));
			}
		}

		private static void Build(TumbleWingsUI src)
		{
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_010c: 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_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_02af: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b4: 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_02bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: 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_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_024a: Unknown result type (might be due to invalid IL or missing references)
			//IL_024f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: Unknown result type (might be due to invalid IL or missing references)
			//IL_0269: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_0275: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: 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_0284: Unknown result type (might be due to invalid IL or missing references)
			//IL_028b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0297: Unknown result type (might be due to invalid IL or missing references)
			//IL_029c: Unknown result type (might be due to invalid IL or missing references)
			//IL_036b: Unknown result type (might be due to invalid IL or missing references)
			//IL_038b: Unknown result type (might be due to invalid IL or missing references)
			GameObject gameObject = ((Component)src).gameObject;
			bool activeSelf = gameObject.activeSelf;
			gameObject.SetActive(false);
			GameObject val;
			try
			{
				val = Object.Instantiate<GameObject>(gameObject, gameObject.transform.parent);
			}
			finally
			{
				gameObject.SetActive(activeSelf);
			}
			((Object)val).name = "Peanut Blink Bar";
			TumbleWingsUI component = val.GetComponent<TumbleWingsUI>();
			BlinkBarUI blinkBarUI = val.AddComponent<BlinkBarUI>();
			FieldInfo[] fields = typeof(SemiUI).GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			foreach (FieldInfo fieldInfo in fields)
			{
				fieldInfo.SetValue(blinkBarUI, fieldInfo.GetValue(component));
			}
			blinkBarUI.fillImage = component.imageBar;
			blinkBarUI.leftEye = (Object.op_Implicit((Object)(object)component.rectTransformLeftWing) ? ((Component)component.rectTransformLeftWing).GetComponentInChildren<RawImage>(true) : null);
			blinkBarUI.rightEye = (Object.op_Implicit((Object)(object)component.rectTransformRightWing) ? ((Component)component.rectTransformRightWing).GetComponentInChildren<RawImage>(true) : null);
			if (Object.op_Implicit((Object)(object)component.rectTransformLeftWing))
			{
				((Transform)component.rectTransformLeftWing).localRotation = Quaternion.identity;
			}
			if (Object.op_Implicit((Object)(object)component.rectTransformRightWing))
			{
				((Transform)component.rectTransformRightWing).localRotation = Quaternion.identity;
			}
			Object.DestroyImmediate((Object)(object)component);
			Vector2 hidePosition = ((SemiUI)src).hidePosition - ((SemiUI)src).showPosition;
			Transform val2 = ((((SemiUI)blinkBarUI).animateTheEntireObject || !Object.op_Implicit((Object)(object)((SemiUI)blinkBarUI).textRectTransform)) ? val.transform : ((SemiUI)blinkBarUI).textRectTransform);
			val2.localPosition = new Vector3(((SemiUI)src).showPosition.x, ((SemiUI)src).showPosition.y, val2.localPosition.z);
			val2.localScale = Vector3.one;
			Canvas val3 = (Object.op_Implicit((Object)(object)gameObject.transform.parent) ? ((Component)gameObject.transform.parent).GetComponentInParent<Canvas>() : null);
			RectTransform val4 = (RectTransform)(Object.op_Implicit((Object)(object)val3) ? /*isinst with value type is only supported in some contexts*/: null);
			if (Object.op_Implicit((Object)(object)val4))
			{
				Transform val5 = (Transform)(Object.op_Implicit((Object)(object)((Transform)((Graphic)blinkBarUI.fillImage).rectTransform).parent) ? ((object)((Transform)((Graphic)blinkBarUI.fillImage).rectTransform).parent) : ((object)((Graphic)blinkBarUI.fillImage).rectTransform));
				Rect rect = val4.rect;
				float x = ((Rect)(ref rect)).center.x;
				rect = val4.rect;
				float y = ((Rect)(ref rect)).center.y;
				rect = val4.rect;
				Vector3 val6 = ((Transform)val4).TransformPoint(new Vector3(x, y - ((Rect)(ref rect)).height * 0.13f, 0f)) - val5.position;
				val2.position += new Vector3(val6.x, val6.y, 0f);
			}
			((SemiUI)blinkBarUI).showPosition = Vector2.op_Implicit(val2.localPosition);
			((SemiUI)blinkBarUI).hidePosition = hidePosition;
			((Graphic)blinkBarUI.fillImage).color = new Color(1f, 1f, 1f, 0.8f);
			((Transform)((Graphic)blinkBarUI.fillImage).rectTransform).localScale = Vector3.one;
			if (eyeFrames == null)
			{
				eyeFrames = MakeEyes();
			}
			RawImage[] array = (RawImage[])(object)new RawImage[2] { blinkBarUI.leftEye, blinkBarUI.rightEye };
			foreach (RawImage val7 in array)
			{
				if (Object.op_Implicit((Object)(object)val7))
				{
					val7.texture = (Texture)(object)eyeFrames[eyeFrames.Length - 1];
					val7.uvRect = new Rect(0f, 0f, 1f, 1f);
					((Graphic)val7).color = new Color(1f, 1f, 1f, 0.8f);
				}
			}
			val.SetActive(true);
			bar = blinkBarUI;
		}

		public override void Update()
		{
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			((SemiUI)this).Update();
			PlayerAvatar instance = PlayerAvatar.instance;
			bool flag = Time.frameCount - PeanutAI.meterFrame <= 2;
			bool flag2 = Object.op_Implicit((Object)(object)instance) && !instance.isDisabled && !instance.deadSet;
			bool blinking = PeanutAI.Blinking;
			bool flag3 = Plugin.Blinking.Value && Plugin.ShowBlinkMeter.Value && flag2 && flag && (PeanutAI.lookedLastFrame || blinking || PeanutAI.eyes < 0.999f);
			if (flag3)
			{
				((SemiUI)this).Show();
			}
			else
			{
				((SemiUI)this).Hide();
			}
			float num = (blinking ? 0f : PeanutAI.eyes);
			if (Object.op_Implicit((Object)(object)fillImage))
			{
				((Transform)((Graphic)fillImage).rectTransform).localScale = new Vector3(num, 1f, 1f);
			}
			float num2 = ((PeanutAI.lookedLastFrame || blinking) ? 0.85f : 0.45f);
			Color color = default(Color);
			((Color)(ref color))..ctor(1f, 1f, 1f, num2);
			if (Object.op_Implicit((Object)(object)fillImage))
			{
				((Graphic)fillImage).color = color;
			}
			int num3 = ((!blinking) ? Mathf.Clamp(Mathf.CeilToInt(num * (float)(eyeFrames.Length - 1)), 1, eyeFrames.Length - 1) : 0);
			RawImage[] array = (RawImage[])(object)new RawImage[2] { leftEye, rightEye };
			foreach (RawImage val in array)
			{
				if (Object.op_Implicit((Object)(object)val))
				{
					((Graphic)val).color = color;
					if (num3 != eyeFrame)
					{
						val.texture = (Texture)(object)eyeFrames[num3];
					}
				}
			}
			eyeFrame = num3;
			if (blinking && !wasBlinking)
			{
				((SemiUI)this).SemiUISpringScale(0.5f, 0.2f, 0.1f);
				((SemiUI)this).SemiUISpringShakeY(4f, 3f, 0.25f);
			}
			wasBlinking = blinking;
			if (flag3 && PeanutAI.lookedLastFrame && !blinking && num < 0.3f)
			{
				warnTimer += Time.deltaTime * ((num < 0.15f) ? 2f : 1f);
				if (warnTimer > 0.5f)
				{
					warnTimer = 0f;
					((SemiUI)this).SemiUISpringShakeX(3f, 3f, 0.2f);
				}
			}
			else
			{
				warnTimer = 0f;
			}
		}

		public override void OnDestroy()
		{
			((SemiUI)this).OnDestroy();
			if ((Object)(object)bar == (Object)(object)this)
			{
				bar = null;
			}
		}

		private static Texture2D[] MakeEyes()
		{
			//IL_0038: 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_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Expected O, but got Unknown
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			Texture2D[] array = (Texture2D[])(object)new Texture2D[5];
			Color val = default(Color);
			((Color)(ref val))..ctor(1f, 1f, 1f, 0f);
			for (int i = 0; i < 5; i++)
			{
				float num = (float)i / 4f;
				Texture2D val2 = new Texture2D(16, 16, (TextureFormat)4, false)
				{
					filterMode = (FilterMode)0,
					wrapMode = (TextureWrapMode)1
				};
				Color[] array2 = (Color[])(object)new Color[256];
				for (int j = 0; j < array2.Length; j++)
				{
					array2[j] = val;
				}
				float num2 = 7.5f;
				for (int k = 0; k < 16; k++)
				{
					float num3 = ((float)k + 0.5f) / 16f;
					float num4 = num * 5.5f * Mathf.Sin(num3 * MathF.PI);
					int num5 = Mathf.RoundToInt(num2 + num4);
					int num6 = Mathf.RoundToInt(num2 - num4);
					for (int l = num6; l <= num5; l++)
					{
						bool num7 = l == num5 || l == num6 || k == 0 || k == 15;
						float num8 = (float)k - 7.5f;
						float num9 = (float)l - num2;
						bool flag = num > 0f && num8 * num8 + num9 * num9 <= 6.7599993f;
						if (num7 || flag)
						{
							array2[l * 16 + k] = Color.white;
						}
					}
				}
				val2.SetPixels(array2);
				val2.Apply();
				array[i] = val2;
			}
			return array;
		}
	}
	[HarmonyPatch]
	internal static class Patches
	{
		[HarmonyPatch(typeof(EnemyDirector), "Awake")]
		[HarmonyPrefix]
		[HarmonyPriority(800)]
		private static void BuildBeforeDirector(EnemyDirector __instance)
		{
			try
			{
				PeanutBuilder.BuildAndRegister(__instance);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("Failed to build the Peanut: " + ex));
			}
		}

		[HarmonyPatch(typeof(EnemyDirector), "AmountSetup")]
		[HarmonyPostfix]
		private static void ForcePeanut(EnemyDirector __instance)
		{
			if (Plugin.AlwaysSpawn.Value && !((Object)(object)PeanutBuilder.Setup == (Object)null))
			{
				List<EnemySetup> enemyList = __instance.enemyList;
				int enemyListIndex = __instance.enemyListIndex;
				if (enemyListIndex < enemyList.Count)
				{
					enemyList[enemyListIndex] = PeanutBuilder.Setup;
					return;
				}
				enemyList.Add(PeanutBuilder.Setup);
				__instance.totalAmount++;
			}
		}
	}
	public class PeanutAI : MonoBehaviour
	{
		public Transform model;

		public AudioSource drag;

		public AudioSource sfx;

		public float faceHeight;

		private Enemy enemy;

		private PhotonView photonView;

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

		private PlayerAvatar target;

		private bool watched;

		private bool wasWatched;

		private bool despawning;

		private float killCooldown;

		private float aloneTimer;

		private float graceUntil;

		private float heldFor;

		private const float MaxHoldSeconds = 3f;

		private const float BurstDistance = 2.5f;

		private float lastBurst = -10f;

		private readonly NavMeshPath burstPath = new NavMeshPath();

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

		private const float GraceSeconds = 5f;

		private const float WarnRange = 15f;

		private const float WarnSeconds = 2.5f;

		private Quaternion facing = Quaternion.identity;

		private bool moving;

		private bool localSees;

		private float nextReport;

		private float nextRattle;

		private bool reportedSees;

		private Vector3 lastModelPos;

		private float speedSmoothed;

		internal static float eyes = 1f;

		internal static float blinkUntil = -10f;

		internal static int meterFrame = -1;

		internal static bool lookingThisFrame;

		internal static bool lookedLastFrame;

		private const float DrainSeconds = 7f;

		private const float RecoverSeconds = 10f;

		private const float BlinkSeconds = 0.2f;

		private const float CloseSeconds = 0.08f;

		private const float OpenSeconds = 0.12f;

		private const float BlinkDarkness = 0.92f;

		internal const float BarBelowCentre = 0.13f;

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

		private static Light[] lamps = (Light[])(object)new Light[0];

		private static float lampsAt = -100f;

		private float litUntil;

		private float unlitUntil;

		private static Texture2D solid;

		private static Texture2D white;

		private static Texture2D fadeDown;

		private static Texture2D fadeUp;

		private static int drawnFrame = -1;

		private static float barAlpha;

		internal static bool Blinking
		{
			get
			{
				if (Plugin.Blinking.Value)
				{
					return Time.time < blinkUntil;
				}
				return false;
			}
		}

		private static float TimeToBlink
		{
			get
			{
				if (!lookedLastFrame || Blinking)
				{
					return float.PositiveInfinity;
				}
				return eyes * 7f;
			}
		}

		private void Awake()
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Expected O, but got Unknown
			enemy = ((Component)this).GetComponent<Enemy>();
			photonView = ((Component)this).GetComponent<PhotonView>();
			EnemyStateSpawn component = ((Component)this).GetComponent<EnemyStateSpawn>();
			if (Object.op_Implicit((Object)(object)component))
			{
				component.OnSpawn.AddListener(new UnityAction(OnSpawn));
			}
			EnemyHealth component2 = ((Component)this).GetComponent<EnemyHealth>();
			if (Object.op_Implicit((Object)(object)component2))
			{
				component2.onDeath.AddListener(new UnityAction(OnDeath));
			}
		}

		private void OnEnable()
		{
			if (Object.op_Implicit((Object)(object)photonView))
			{
				photonView.RefreshRpcMonoBehaviourCache();
			}
			watchedUntil.Clear();
			despawning = false;
			killCooldown = 1f;
		}

		private void Update()
		{
			if (!Object.op_Implicit((Object)(object)PeanutAssets.StoneDrag) && !PeanutAssets.Loading)
			{
				PeanutAssets.LoadSounds((MonoBehaviour)(object)this);
			}
			LocalWatch();
			if (SemiFunc.IsMasterClientOrSingleplayer())
			{
				HostLogic();
			}
			Sounds();
		}

		private void HostLogic()
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Invalid comparison between Unknown and I4
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_030c: Unknown result type (might be due to invalid IL or missing references)
			//IL_032c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0332: Unknown result type (might be due to invalid IL or missing references)
			//IL_0337: Unknown result type (might be due to invalid IL or missing references)
			//IL_033c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0287: Unknown result type (might be due to invalid IL or missing references)
			//IL_028c: Unknown result type (might be due to invalid IL or missing references)
			//IL_028e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0298: Unknown result type (might be due to invalid IL or missing references)
			//IL_029a: 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_02a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_036c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0378: Unknown result type (might be due to invalid IL or missing references)
			//IL_0394: Unknown result type (might be due to invalid IL or missing references)
			//IL_039a: Unknown result type (might be due to invalid IL or missing references)
			//IL_039f: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0359: Unknown result type (might be due to invalid IL or missing references)
			//IL_035b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0360: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_02be: Unknown result type (might be due to invalid IL or missing references)
			//IL_051d: Unknown result type (might be due to invalid IL or missing references)
			//IL_042e: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_049c: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_0474: Unknown result type (might be due to invalid IL or missing references)
			//IL_05cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_05dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0603: Unknown result type (might be due to invalid IL or missing references)
			//IL_055d: Unknown result type (might be due to invalid IL or missing references)
			EnemyRigidbody rigidbody = enemy.Rigidbody;
			Rigidbody val = (Object.op_Implicit((Object)(object)rigidbody) ? rigidbody.rb : null);
			if (!Object.op_Implicit((Object)(object)val))
			{
				return;
			}
			if ((int)enemy.CurrentState == 11)
			{
				if (!despawning)
				{
					despawning = true;
					enemy.EnemyParent.Despawn();
				}
				return;
			}
			watched = false;
			foreach (KeyValuePair<int, float> item in watchedUntil)
			{
				if (item.Value > Time.time)
				{
					watched = true;
					break;
				}
			}
			target = Nearest(val.position, 45f);
			killCooldown -= Time.deltaTime;
			UpdateNearness(val.position);
			PhysGrabObject physGrabObject = rigidbody.physGrabObject;
			bool flag = Object.op_Implicit((Object)(object)physGrabObject) && physGrabObject.playerGrabbing.Count > 0;
			heldFor = (flag ? (heldFor + Time.deltaTime) : 0f);
			if (flag && ((!watched && Time.time >= graceUntil) || heldFor > 3f))
			{
				rigidbody.GrabReleaseShake();
				physGrabObject.grabDisableTimer = 1.5f;
				heldFor = 0f;
			}
			bool flag2 = Time.time < graceUntil || watched || !Object.op_Implicit((Object)(object)target) || enemy.IsStunned();
			if (flag2)
			{
				if (!wasWatched)
				{
					val.linearVelocity = Vector3.zero;
					val.angularVelocity = Vector3.zero;
					SnapToFloor(val);
				}
				enemy.NavMeshAgent.ResetPath();
				enemy.NavMeshAgent.Warp(val.position, false);
				rigidbody.disableFollowPositionTimer = 0.2f;
				rigidbody.disableFollowRotationTimer = 0.2f;
				SetMoving(m: false);
			}
			else
			{
				if (wasWatched && Time.time - lastBurst > 0.4f)
				{
					lastBurst = Time.time;
					Burst(val, target);
				}
				float value = Plugin.MoveSpeed.Value;
				enemy.NavMeshAgent.OverrideAgent(value, 200f, 0.2f);
				rigidbody.OverrideFollowPosition(0.2f, value * 2f, -1f);
				if (Object.op_Implicit((Object)(object)rigidbody.followTarget))
				{
					Vector3 position = ((Component)enemy).transform.position;
					float y = position.y;
					if (FloorBelow(position + Vector3.up * 0.5f, 1.1f, out var floor))
					{
						y = ((RaycastHit)(ref floor)).point.y;
					}
					rigidbody.followTarget.position = new Vector3(position.x, y + 1.1f + 0.01f, position.z);
				}
				enemy.NavMeshAgent.SetDestination(((Component)target).transform.position);
				enemy.SetChaseTimer();
				Vector3 val2 = ((Component)target).transform.position - val.position;
				val2.y = 0f;
				if (((Vector3)(ref val2)).sqrMagnitude > 0.01f)
				{
					facing = Quaternion.LookRotation(val2);
				}
				((Component)this).transform.rotation = facing;
				val.rotation = facing;
				SetMoving(m: true);
				Vector3 val3 = ((Component)target).transform.position - val.position;
				float y2 = val3.y;
				val3.y = 0f;
				if (((Vector3)(ref val3)).magnitude < 1.15f && Mathf.Abs(y2) < 1.6f && killCooldown <= 0f && Object.op_Implicit((Object)(object)target.playerHealth) && Warned(target))
				{
					killCooldown = 1.5f;
					target.playerHealth.HurtOther(9999, Vector3.zero, false, SemiFunc.EnemyGetIndex(enemy), false);
					int num = Random.Range(0, 3);
					if (SemiFunc.IsMultiplayer())
					{
						photonView.RPC("Peanut_SnapRPC", (RpcTarget)0, new object[2]
						{
							((Component)target).transform.position,
							num
						});
					}
					else
					{
						Peanut_SnapRPC(((Component)target).transform.position, num);
					}
				}
			}
			rigidbody.gravity = flag2;
			wasWatched = flag2;
			aloneTimer = (Object.op_Implicit((Object)(object)Nearest(val.position, 40f)) ? 0f : (aloneTimer + Time.deltaTime));
			if (!(aloneTimer > 20f) || watched)
			{
				return;
			}
			aloneTimer = 0f;
			LevelPoint val4 = null;
			List<LevelPoint> list = SemiFunc.LevelPointsGetPlayerDistance(val.position, 15f, 30f, false);
			if (list != null)
			{
				foreach (LevelPoint item2 in list)
				{
					if (Object.op_Implicit((Object)(object)item2) && FarFromEveryone(((Component)item2).transform.position, 15f) && ((Object)(object)val4 == (Object)null || Random.value < 0.35f))
					{
						val4 = item2;
					}
				}
			}
			NavMeshHit val5 = default(NavMeshHit);
			if (Object.op_Implicit((Object)(object)val4) && NavMesh.SamplePosition(((Component)val4).transform.position, ref val5, 3f, -1))
			{
				rigidbody.physGrabObject.Teleport(((NavMeshHit)(ref val5)).position + Vector3.up * 1.15f, ((Component)this).transform.rotation);
				enemy.NavMeshAgent.Warp(((NavMeshHit)(ref val5)).position, false);
				Arrived();
			}
		}

		private void FixedUpdate()
		{
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: 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_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_026d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_027b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0282: 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_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0260: Unknown result type (might be due to invalid IL or missing references)
			//IL_0265: Unknown result type (might be due to invalid IL or missing references)
			//IL_026a: Unknown result type (might be due to invalid IL or missing references)
			if (!SemiFunc.IsMasterClientOrSingleplayer())
			{
				return;
			}
			bool flag = Object.op_Implicit((Object)(object)enemy) && Object.op_Implicit((Object)(object)enemy.Rigidbody) && Object.op_Implicit((Object)(object)enemy.Rigidbody.physGrabObject) && enemy.Rigidbody.physGrabObject.playerGrabbing.Count > 0;
			if (!wasWatched && !flag)
			{
				return;
			}
			EnemyRigidbody val = (Object.op_Implicit((Object)(object)enemy) ? enemy.Rigidbody : null);
			Rigidbody val2 = (Object.op_Implicit((Object)(object)val) ? val.rb : null);
			if (!Object.op_Implicit((Object)(object)val2))
			{
				return;
			}
			if (wasWatched && !flag && FloorBelow(val2, 0.25f, out var floor))
			{
				Vector3 normal = ((RaycastHit)(ref floor)).normal;
				if (normal.y > 0.5f && normal.y < 0.999f)
				{
					Vector3 val3 = Physics.gravity + Vector3.down * (val.customGravity / Mathf.Max(0.01f, val2.mass));
					val2.AddForce(-(val3 - normal * Vector3.Dot(val3, normal)), (ForceMode)5);
					Vector3 linearVelocity = val2.linearVelocity;
					if (((Vector3)(ref linearVelocity)).sqrMagnitude < 0.09f)
					{
						val2.linearVelocity = normal * Vector3.Dot(linearVelocity, normal);
					}
				}
			}
			Vector3 linearVelocity2 = val2.linearVelocity;
			Vector3 val4 = default(Vector3);
			((Vector3)(ref val4))..ctor(linearVelocity2.x, 0f, linearVelocity2.z);
			NavMeshHit val5 = default(NavMeshHit);
			if (((Vector3)(ref val4)).sqrMagnitude < 0.0025f || !NavMesh.SamplePosition(val2.position + Vector3.down * 1.1f, ref val5, 1.2f, -1))
			{
				return;
			}
			Vector3 normalized = ((Vector3)(ref val4)).normalized;
			Vector3 val6 = ((NavMeshHit)(ref val5)).position + normalized * (0.45f + ((Vector3)(ref val4)).magnitude * Time.fixedDeltaTime);
			NavMeshHit val7 = default(NavMeshHit);
			if (NavMesh.Raycast(((NavMeshHit)(ref val5)).position, val6, ref val7, -1))
			{
				Vector3 val8 = ((NavMeshHit)(ref val7)).normal;
				val8.y = 0f;
				if (((Vector3)(ref val8)).sqrMagnitude < 0.0001f)
				{
					val8 = -normalized;
				}
				else
				{
					((Vector3)(ref val8)).Normalize();
				}
				float num = Vector3.Dot(val4, -val8);
				if (num > 0f)
				{
					val4 += val8 * num;
				}
				val2.linearVelocity = new Vector3(val4.x, linearVelocity2.y, val4.z);
			}
		}

		private void Burst(Rigidbody rb, PlayerAvatar to)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: 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_002c: 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_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: 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_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: 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_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0250: Unknown result type (might be due to invalid IL or missing references)
			//IL_0255: 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_025e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0265: Unknown result type (might be due to invalid IL or missing references)
			//IL_0268: Unknown result type (might be due to invalid IL or missing references)
			//IL_026d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_0280: Unknown result type (might be due to invalid IL or missing references)
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_028c: Unknown result type (might be due to invalid IL or missing references)
			//IL_028d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0297: Unknown result type (might be due to invalid IL or missing references)
			//IL_029c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02db: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0306: 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)
			NavMeshHit val = default(NavMeshHit);
			if (!NavMesh.SamplePosition(rb.position + Vector3.down * 1.1f, ref val, 1.5f, -1) || !NavMesh.CalculatePath(((NavMeshHit)(ref val)).position, ((Component)to).transform.position, -1, burstPath) || burstPath.corners.Length < 2)
			{
				return;
			}
			float num = Vector3.Distance(new Vector3(((NavMeshHit)(ref val)).position.x, 0f, ((NavMeshHit)(ref val)).position.z), new Vector3(((Component)to).transform.position.x, 0f, ((Component)to).transform.position.z));
			float num2 = Mathf.Min(2.5f, Mathf.Max(0f, num - 0.92f));
			Vector3 val2 = ((NavMeshHit)(ref val)).position;
			Vector3[] corners = burstPath.corners;
			for (int i = 1; i < corners.Length; i++)
			{
				if (!(num2 > 0.01f))
				{
					break;
				}
				float num3 = Vector3.Distance(val2, corners[i]);
				if (num3 <= num2)
				{
					num2 -= num3;
					val2 = corners[i];
				}
				else
				{
					val2 = Vector3.MoveTowards(val2, corners[i], num2);
					num2 = 0f;
				}
			}
			Vector3 val3 = ((NavMeshHit)(ref val)).position + Vector3.up * 1.2f;
			Vector3 val4 = val2 + Vector3.up * 1.2f - val3;
			if (((Vector3)(ref val4)).magnitude < 0.05f)
			{
				return;
			}
			int num4 = Physics.RaycastNonAlloc(val3, ((Vector3)(ref val4)).normalized, hits, ((Vector3)(ref val4)).magnitude + 0.4f, LayerMask.op_Implicit(SemiFunc.LayerMaskGetVisionObstruct()), (QueryTriggerInteraction)1);
			float num5 = ((Vector3)(ref val4)).magnitude;
			for (int j = 0; j < num4; j++)
			{
				Transform transform = ((RaycastHit)(ref hits[j])).transform;
				if (Object.op_Implicit((Object)(object)transform) && !transform.IsChildOf(((Component)enemy.EnemyParent).transform) && !Object.op_Implicit((Object)(object)((Component)transform).GetComponentInParent<PlayerAvatar>()) && !((Component)transform).CompareTag("Player"))
				{
					num5 = Mathf.Min(num5, ((RaycastHit)(ref hits[j])).distance - 0.45f);
				}
			}
			if (!(num5 <= 0.05f))
			{
				Vector3 position = ((NavMeshHit)(ref val)).position;
				Vector3 val5 = val2 - ((NavMeshHit)(ref val)).position;
				Vector3 normalized = ((Vector3)(ref val5)).normalized;
				float num6 = num5;
				val5 = val2 - ((NavMeshHit)(ref val)).position;
				val2 = position + normalized * Mathf.Min(num6, ((Vector3)(ref val5)).magnitude);
				rb.position = val2 + Vector3.up * 1.12f;
				rb.linearVelocity = Vector3.zero;
				SnapToFloor(rb);
				enemy.NavMeshAgent.Warp(val2, false);
				Vector3 val6 = ((Component)to).transform.position - val2;
				val6.y = 0f;
				if (((Vector3)(ref val6)).sqrMagnitude > 0.01f)
				{
					facing = Quaternion.LookRotation(val6);
					rb.rotation = facing;
					((Component)this).transform.rotation = facing;
				}
			}
		}

		private bool FloorBelow(Rigidbody rb, float slack, out RaycastHit floor)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			return FloorBelow(rb.position + Vector3.up * 0.2f, 1.3000001f + slack, out floor);
		}

		private bool FloorBelow(Vector3 from, float range, out RaycastHit floor)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			floor = default(RaycastHit);
			int num = Physics.RaycastNonAlloc(from, Vector3.down, hits, range, LayerMask.op_Implicit(SemiFunc.LayerMaskGetVisionObstruct()), (QueryTriggerInteraction)1);
			bool flag = false;
			for (int i = 0; i < num; i++)
			{
				Transform transform = ((RaycastHit)(ref hits[i])).transform;
				if (Object.op_Implicit((Object)(object)transform) && !transform.IsChildOf(((Component)enemy.EnemyParent).transform) && !Object.op_Implicit((Object)(object)((Component)transform).GetComponentInParent<PlayerAvatar>()) && !((Component)transform).CompareTag("Player") && (!flag || ((RaycastHit)(ref hits[i])).distance < ((RaycastHit)(ref floor)).distance))
				{
					floor = hits[i];
					flag = true;
				}
			}
			return flag;
		}

		private void SnapToFloor(Rigidbody rb)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: 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_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			if (FloorBelow(rb, 0.8f, out var floor))
			{
				Vector3 position = rb.position;
				position.y = ((RaycastHit)(ref floor)).point.y + 1.1f + 0.01f;
				rb.position = position;
				((Component)rb).transform.position = position;
				Vector3 linearVelocity = rb.linearVelocity;
				rb.linearVelocity = new Vector3(linearVelocity.x, 0f, linearVelocity.z);
			}
		}

		private void Arrived()
		{
			//IL_0032: 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)
			graceUntil = Time.time + 5f;
			if (SemiFunc.IsMultiplayer())
			{
				photonView.RPC("Peanut_ArriveRPC", (RpcTarget)0, Array.Empty<object>());
			}
			else
			{
				Peanut_ArriveRPC();
			}
		}

		private void UpdateNearness(Vector3 at)
		{
			//IL_0041: 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)
			foreach (PlayerAvatar player in GameDirector.instance.PlayerList)
			{
				if (!Object.op_Implicit((Object)(object)player) || !Object.op_Implicit((Object)(object)player.photonView))
				{
					continue;
				}
				int viewID = player.photonView.ViewID;
				float num = Vector3.Distance(((Component)player).transform.position, at);
				if (num < 15f)
				{
					if (!nearSince.ContainsKey(viewID))
					{
						nearSince[viewID] = Time.time;
					}
				}
				else if (num > 18f)
				{
					nearSince.Remove(viewID);
				}
			}
		}

		private bool Warned(PlayerAvatar p)
		{
			if (nearSince.TryGetValue(p.photonView.ViewID, out var value))
			{
				return Time.time - value >= 2.5f;
			}
			return false;
		}

		private bool FarFromEveryone(Vector3 at, float min)
		{
			//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)
			foreach (PlayerAvatar player in GameDirector.instance.PlayerList)
			{
				if (Object.op_Implicit((Object)(object)player) && !player.isDisabled && Vector3.Distance(((Component)player).transform.position, at) < min)
				{
					return false;
				}
			}
			return true;
		}

		private void SetWatching(int viewId, bool watching)
		{
			if (watching)
			{
				watchedUntil[viewId] = Time.time + 0.6f;
			}
			else
			{
				watchedUntil.Remove(viewId);
			}
		}

		private PlayerAvatar Nearest(Vector3 from, float range)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			PlayerAvatar result = null;
			float num = range;
			foreach (PlayerAvatar player in GameDirector.instance.PlayerList)
			{
				if (Object.op_Implicit((Object)(object)player) && !player.isDisabled && !player.deadSet)
				{
					float num2 = Vector3.Distance(((Component)player).transform.position, from);
					if (num2 < num)
					{
						num = num2;
						result = player;
					}
				}
			}
			return result;
		}

		private void SetMoving(bool m)
		{
			if (m != moving)
			{
				moving = m;
				if (SemiFunc.IsMultiplayer())
				{
					photonView.RPC("Peanut_MovingRPC", (RpcTarget)1, new object[1] { m });
				}
			}
		}

		public void OnSpawn()
		{
			if (SemiFunc.IsMasterClientOrSingleplayer())
			{
				SemiFunc.EnemySpawn(enemy);
				despawning = false;
				nearSince.Clear();
				Arrived();
			}
		}

		public void OnDeath()
		{
			//IL_0042: 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)
			if (Object.op_Implicit((Object)(object)sfx) && Object.op_Implicit((Object)(object)PeanutAssets.Rattle[0]))
			{
				AudioSource.PlayClipAtPoint(PeanutAssets.Rattle[0], Object.op_Implicit((Object)(object)model) ? model.position : ((Component)this).transform.position, 1f);
			}
			if (SemiFunc.IsMasterClientOrSingleplayer())
			{
				enemy.EnemyParent.Despawn();
			}
		}

		private static void TickMeter()
		{
			if (meterFrame == Time.frameCount)
			{
				return;
			}
			meterFrame = Time.frameCount;
			lookedLastFrame = lookingThisFrame;
			lookingThisFrame = false;
			if (!Plugin.Blinking.Value)
			{
				eyes = 1f;
			}
			else
			{
				if (Time.time < blinkUntil)
				{
					return;
				}
				if (lookedLastFrame)
				{
					eyes -= Time.deltaTime / 7f;
					if (eyes <= 0f)
					{
						eyes = 1f;
						blinkUntil = Time.time + 0.2f;
					}
				}
				else
				{
					eyes = Mathf.Min(1f, eyes + Time.deltaTime / 10f);
				}
			}
		}

		private void LocalWatch()
		{
			//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_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: 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_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			TickMeter();
			PlayerAvatar instance = PlayerAvatar.instance;
			localSees = false;
			if (!Object.op_Implicit((Object)(object)instance) || instance.isDisabled || instance.deadSet || !Object.op_Implicit((Object)(object)instance.localCamera) || !Object.op_Implicit((Object)(object)model))
			{
				return;
			}
			Transform transform = ((Component)instance.localCamera).transform;
			Vector3 position = model.position;
			float num = Vector3.Distance(transform.position, position);
			bool flag = false;
			if (num < 35f)
			{
				float[] array = new float[3] { 0.3f, 1.1f, faceHeight };
				foreach (float num2 in array)
				{
					Vector3 val = position + Vector3.up * num2;
					if (OnScreen(val) && !SightBlocked(transform.position, val, instance) && (!(num > 9f) || Lit(instance, val)))
					{
						flag = true;
						break;
					}
				}
			}
			if (flag)
			{
				lookingThisFrame = true;
			}
			localSees = flag && !Blinking;
			if (localSees != reportedSees || (localSees && Time.time >= nextReport))
			{
				reportedSees = localSees;
				nextReport = Time.time + 0.15f;
				int viewID = instance.photonView.ViewID;
				if (SemiFunc.IsMasterClientOrSingleplayer())
				{
					SetWatching(viewID, localSees);
					return;
				}
				photonView.RPC("Peanut_WatchingRPC", (RpcTarget)2, new object[2] { viewID, localSees });
			}
		}

		private static bool OnScreen(Vector3 p)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: 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_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			Camera main = Camera.main;
			if (!Object.op_Implicit((Object)(object)main))
			{
				return false;
			}
			Vector3 val = main.WorldToViewportPoint(p);
			if (val.z > 0f && val.x > 0f && val.x < 1f && val.y > 0f)
			{
				return val.y < 1f;
			}
			return false;
		}

		private bool SightBlocked(Vector3 from, Vector3 to, PlayerAvatar viewer)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = to - from;
			int num = Physics.RaycastNonAlloc(from, ((Vector3)(ref val)).normalized, hits, ((Vector3)(ref val)).magnitude, LayerMask.op_Implicit(SemiFunc.LayerMaskGetVisionObstruct()), (QueryTriggerInteraction)1);
			for (int i = 0; i < num; i++)
			{
				Transform transform = ((RaycastHit)(ref hits[i])).transform;
				if (Object.op_Implicit((Object)(object)transform) && !transform.IsChildOf(((Component)enemy.EnemyParent).transform) && (!Object.op_Implicit((Object)(object)viewer) || !transform.IsChildOf(((Component)viewer).transform)) && !((Component)transform).CompareTag("Player") && !Object.op_Implicit((Object)(object)((Component)transform).GetComponentInParent<PlayerTumble>()) && !Object.op_Implicit((Object)(object)((Component)transform).GetComponentInParent<PlayerAvatar>()))
				{
					return true;
				}
			}
			return false;
		}

		private bool Lit(PlayerAvatar viewer, Vector3 p)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Invalid comparison between Unknown and I4
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: 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_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: 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_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			FlashlightController flashlightController = viewer.flashlightController;
			if (Object.op_Implicit((Object)(object)flashlightController) && flashlightController.LightActive && Object.op_Implicit((Object)(object)flashlightController.spotlight) && ((Behaviour)flashlightController.spotlight).enabled)
			{
				Transform transform = ((Component)flashlightController.spotlight).transform;
				Vector3 val = p - transform.position;
				if (((Vector3)(ref val)).magnitude < flashlightController.spotlight.range && Vector3.Angle(transform.forward, val) < flashlightController.spotlight.spotAngle * 0.5f)
				{
					return true;
				}
			}
			if (Time.time < litUntil)
			{
				return true;
			}
			if (Time.time < unlitUntil)
			{
				return false;
			}
			if (Time.time - lampsAt > 3f)
			{
				lamps = Object.FindObjectsByType<Light>((FindObjectsSortMode)0);
				lampsAt = Time.time;
			}
			Light[] array = lamps;
			foreach (Light val2 in array)
			{
				if (!Object.op_Implicit((Object)(object)val2) || !((Behaviour)val2).isActiveAndEnabled || val2.intensity < 0.05f || ((int)val2.type != 2 && (int)val2.type != 0) || (Object.op_Implicit((Object)(object)flashlightController) && (Object)(object)val2 == (Object)(object)flashlightController.spotlight))
				{
					continue;
				}
				Vector3 val3 = p - ((Component)val2).transform.position;
				float magnitude = ((Vector3)(ref val3)).magnitude;
				if (!(magnitude > val2.range) && ((int)val2.type != 0 || !(Vector3.Angle(((Component)val2).transform.forward, val3) > val2.spotAngle * 0.5f)))
				{
					float num = 1f - magnitude / val2.range;
					if (!(val2.intensity * num * num < 0.12f) && !SightBlocked(((Component)val2).transform.position, p, null))
					{
						litUntil = Time.time + 0.5f;
						return true;
					}
				}
			}
			unlitUntil = Time.time + 0.3f;
			return false;
		}

		private void Sounds()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: 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_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)model))
			{
				return;
			}
			Vector3 position = model.position;
			Vector3 val = position - lastModelPos;
			float num = ((Vector3)(ref val)).magnitude / Mathf.Max(Time.deltaTime, 0.0001f);
			lastModelPos = position;
			speedSmoothed = Mathf.Lerp(speedSmoothed, Mathf.Min(num, 30f), Time.deltaTime * 10f);
			if (Object.op_Implicit((Object)(object)drag) && Object.op_Implicit((Object)(object)PeanutAssets.StoneDrag))
			{
				if ((Object)(object)drag.clip != (Object)(object)PeanutAssets.StoneDrag)
				{
					drag.clip = PeanutAssets.StoneDrag;
				}
				float num2 = (moving ? Mathf.Clamp01(speedSmoothed / 4f) : (Mathf.Clamp01(speedSmoothed / 4f) * 0.6f));
				drag.volume = Mathf.MoveTowards(drag.volume, num2, Time.deltaTime * 6f);
				if (drag.volume > 0.02f && !drag.isPlaying)
				{
					drag.Play();
				}
				else if (drag.volume <= 0.02f && drag.isPlaying)
				{
					drag.Pause();
				}
			}
			PlayerAvatar instance = PlayerAvatar.instance;
			if (localSees && Object.op_Implicit((Object)(object)instance) && Object.op_Implicit((Object)(object)sfx) && Vector3.Distance(((Component)instance).transform.position, position) < 3f && Time.time > nextRattle)
			{
				nextRattle = Time.time + Random.Range(6f, 14f);
				AudioClip val2 = PeanutAssets.Rattle[Random.Range(0, 3)];
				if (Object.op_Implicit((Object)(object)val2))
				{
					sfx.PlayOneShot(val2, 0.8f);
				}
			}
		}

		private void OnGUI()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Invalid comparison between Unknown and I4
			//IL_015e: 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_0075: Expected O, but got Unknown
			//IL_007c: 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_009c: Expected O, but got Unknown
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Expected O, but got Unknown
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Expected O, but got Unknown
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_038a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0261: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0410: Unknown result type (might be due to invalid IL or missing references)
			//IL_042b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0449: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
			if ((int)Event.current.type != 7 || drawnFrame == Time.frameCount)
			{
				return;
			}
			drawnFrame = Time.frameCount;
			if (!Plugin.Blinking.Value)
			{
				return;
			}
			PlayerAvatar instance = PlayerAvatar.instance;
			if (!Object.op_Implicit((Object)(object)instance) || instance.deadSet || instance.isDisabled)
			{
				barAlpha = 0f;
				return;
			}
			if (!Object.op_Implicit((Object)(object)solid))
			{
				solid = new Texture2D(1, 1);
				solid.SetPixel(0, 0, Color.black);
				solid.Apply();
				white = new Texture2D(1, 1);
				white.SetPixel(0, 0, Color.white);
				white.Apply();
				fadeDown = new Texture2D(1, 64)
				{
					wrapMode = (TextureWrapMode)1
				};
				fadeUp = new Texture2D(1, 64)
				{
					wrapMode = (TextureWrapMode)1
				};
				for (int i = 0; i < 64; i++)
				{
					fadeDown.SetPixel(0, i, new Color(0f, 0f, 0f, (float)i / 63f));
					fadeUp.SetPixel(0, i, new Color(0f, 0f, 0f, 1f - (float)i / 63f));
				}
				fadeDown.Apply();
				fadeUp.Apply();
			}
			Color color = GUI.color;
			float num = Screen.width;
			float num2 = Screen.height;
			bool flag = lookedLastFrame || Blinking || eyes < 0.999f;
			barAlpha = Mathf.MoveTowards(barAlpha, flag ? 1f : 0f, Time.unscaledDeltaTime * (flag ? 6f : 1.5f));
			BlinkBarUI.Ensure();
			if (barAlpha > 0.001f && !BlinkBarUI.Active && Plugin.ShowBlinkMeter.Value)
			{
				float num3 = Mathf.Round(num2 * 0.16f);
				float num4 = Mathf.Max(3f, Mathf.Round(num2 * 0.006f));
				float num5 = Mathf.Round((num - num3) * 0.5f);
				float num6 = Mathf.Round(num2 * 0.63f);
				float num7 = (Blinking ? 0f : eyes);
				GUI.color = new Color(1f, 1f, 1f, 0.15f * barAlpha);
				GUI.DrawTexture(new Rect(num5, num6, num3, num4), (Texture)(object)white);
				float num8 = Mathf.Round(num3 * num7);
				GUI.color = new Color(1f, 1f, 1f, (lookedLastFrame ? 0.55f : 0.3f) * barAlpha);
				GUI.DrawTexture(new Rect(num5 + (num3 - num8) * 0.5f, num6, num8, num4), (Texture)(object)white);
			}
			float time = Time.time;
			float num9 = 0f;
			if (time < blinkUntil)
			{
				num9 = 1f;
			}
			else if (time - blinkUntil < 0.12f)
			{
				num9 = 1f - Mathf.SmoothStep(0f, 1f, (time - blinkUntil) / 0.12f);
			}
			float timeToBlink = TimeToBlink;
			if (timeToBlink < 0.08f)
			{
				num9 = Mathf.Max(num9, Mathf.SmoothStep(0f, 1f, 1f - timeToBlink / 0.08f));
			}
			if (num9 > 0.001f)
			{
				GUI.color = new Color(1f, 1f, 1f, 0.92f);
				float num10 = num2 * 0.5f;
				if (num9 >= 0.999f)
				{
					GUI.DrawTexture(new Rect(0f, 0f, num, num2), (Texture)(object)solid);
				}
				else
				{
					float num11 = num2 * 0.12f;
					float num12 = num9 * (num10 + num11);
					float num13 = Mathf.Max(0f, num12 - num11);
					GUI.DrawTexture(new Rect(0f, 0f, num, num13), (Texture)(object)solid);
					GUI.DrawTexture(new Rect(0f, num13, num, num11), (Texture)(object)fadeDown);
					GUI.DrawTexture(new Rect(0f, num2 - num13, num, num13), (Texture)(object)solid);
					GUI.DrawTexture(new Rect(0f, num2 - num13 - num11, num, num11), (Texture)(object)fadeUp);
				}
			}
			GUI.color = color;
		}

		[PunRPC]
		public void Peanut_WatchingRPC(int viewId, bool watching, PhotonMessageInfo info = default(PhotonMessageInfo))
		{
			if (SemiFunc.IsMasterClientOrSingleplayer())
			{
				SetWatching(viewId, watching);
			}
		}

		[PunRPC]
		public void Peanut_ArriveRPC(PhotonMessageInfo info = default(PhotonMessageInfo))
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			if ((!SemiFunc.IsMultiplayer() || SemiFunc.MasterOnlyRPC(info)) && Object.op_Implicit((Object)(object)sfx))
			{
				AudioClip val = PeanutAssets.Rattle[Random.Range(0, 3)];
				if (Object.op_Implicit((Object)(object)val))
				{
					sfx.PlayOneShot(val, 1f);
				}
				if (Object.op_Implicit((Object)(object)PeanutAssets.StoneDrag))
				{
					sfx.PlayOneShot(PeanutAssets.StoneDrag, 0.7f);
				}
			}
		}

		[PunRPC]
		public void Peanut_MovingRPC(bool m, PhotonMessageInfo info = default(PhotonMessageInfo))
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			if (SemiFunc.MasterOnlyRPC(info))
			{
				moving = m;
			}
		}

		[PunRPC]
		public void Peanut_SnapRPC(Vector3 at, int clip, PhotonMessageInfo info = default(PhotonMessageInfo))
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			if (!SemiFunc.IsMultiplayer() || SemiFunc.MasterOnlyRPC(info))
			{
				AudioClip val = PeanutAssets.NeckSnap[Mathf.Clamp(clip, 0, 2)];
				if (Object.op_Implicit((Object)(object)val))
				{
					AudioSource.PlayClipAtPoint(val, at + Vector3.up * 1.5f, 1f);
				}
			}
		}
	}
	internal static class PeanutAssets
	{
		public static AudioClip StoneDrag;

		public static readonly AudioClip[] NeckSnap = (AudioClip[])(object)new AudioClip[3];

		public static readonly AudioClip[] Rattle = (AudioClip[])(object)new AudioClip[3];

		private static float loadStarted = -100f;

		private static bool loadDone;

		public static bool Loading
		{
			get
			{
				if (Time.realtimeSinceStartup - loadStarted < 15f)
				{
					return !loadDone;
				}
				return false;
			}
		}

		public static byte[] Embedded(string name)
		{
			using Stream stream = typeof(PeanutAssets).Assembly.GetManifestResourceStream("Peanut." + name);
			if (stream == null)
			{
				throw new FileNotFoundException("Embedded resource missing: " + name);
			}
			using MemoryStream memoryStream = new MemoryStream();
			stream.CopyTo(memoryStream);
			return memoryStream.ToArray();
		}

		public static Texture2D Texture(string name, bool linear)
		{
			//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_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			//IL_0028: 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_0030: 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_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, true, linear)
			{
				name = "Peanut " + name
			};
			ImageConversion.LoadImage(val, Embedded(name));
			((Texture)val).wrapMode = (TextureWrapMode)0;
			((Object)val).hideFlags = (HideFlags)(((Object)val).hideFlags | 0x20);
			return val;
		}

		public static void LoadSounds(MonoBehaviour host)
		{
			loadStarted = Time.realtimeSinceStartup;
			loadDone = false;
			host.StartCoroutine(LoadAll());
		}

		private static IEnumerator LoadAll()
		{
			string dir = Path.Combine(Plugin.Folder, "sounds");
			yield return Load(dir, "StoneDrag.ogg", delegate(AudioClip c)
			{
				StoneDrag = c;
			});
			for (int i = 0; i < 3; i++)
			{
				int k = i;
				yield return Load(dir, $"NeckSnap{k + 1}.ogg", delegate(AudioClip c)
				{
					NeckSnap[k] = c;
				});
				yield return Load(dir, $"Rattle{k + 1}.ogg", delegate(AudioClip c)
				{
					Rattle[k] = c;
				});
			}
			loadDone = true;
		}

		private static IEnumerator Load(string dir, string file, Action<AudioClip> set)
		{
			string text = Path.Combine(dir, file);
			if (!File.Exists(text))
			{
				Plugin.Log.LogWarning((object)("Sound missing: " + text));
				yield break;
			}
			UnityWebRequest req = UnityWebRequestMultimedia.GetAudioClip("file:///" + text.Replace('\\', '/'), (AudioType)14);
			try
			{
				yield return req.SendWebRequest();
				if ((int)req.result != 1)
				{
					Plugin.Log.LogWarning((object)("Could not load " + file + ": " + req.error));
					yield break;
				}
				AudioClip content = DownloadHandlerAudioClip.GetContent(req);
				((Object)content).name = "Peanut " + file;
				((Object)content).hideFlags = (HideFlags)(((Object)content).hideFlags | 0x20);
				set(content);
			}
			finally
			{
				((IDisposable)req)?.Dispose();
			}
		}
	}
	internal static class PeanutBuilder
	{
		public const string PrefabName = "Enemy - Peanut";

		public static EnemySetup Setup;

		private static bool tried;

		public static void BuildAndRegister(EnemyDirector director)
		{
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Expected O, but got Unknown
			//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fd: Expected O, but got Unknown
			//IL_0311: Unknown result type (might be due to invalid IL or missing references)
			//IL_031b: Expected O, but got Unknown
			//IL_032f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0339: Expected O, but got Unknown
			//IL_034d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0357: Expected O, but got Unknown
			//IL_0359: Unknown result type (might be due to invalid IL or missing references)
			//IL_0363: Expected O, but got Unknown
			//IL_0365: Unknown result type (might be due to invalid IL or missing references)
			//IL_036f: Expected O, but got Unknown
			//IL_0371: Unknown result type (might be due to invalid IL or missing references)
			//IL_037b: Expected O, but got Unknown
			//IL_03e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f2: Expected O, but got Unknown
			//IL_04bc: Unknown result type (might be due to invalid IL or missing references)
			if (tried)
			{
				return;
			}
			tried = true;
			EnemySetup val = director.enemiesDifficulty1.Concat(director.enemiesDifficulty2).Concat(director.enemiesDifficulty3).FirstOrDefault((Func<EnemySetup, bool>)((EnemySetup s) => Object.op_Implicit((Object)(object)s) && ((Object)s).name.Contains("Robe")));
			if ((Object)(object)val == (Object)null)
			{
				throw new Exception("Could not find REPO's Robe enemy to build on. The game may have been updated.");
			}
			GameObject? obj = val.spawnObjects.Select((PrefabRef r) => ((PrefabRef<GameObject>)(object)r)?.Prefab).FirstOrDefault((Func<GameObject, bool>)((GameObject p) => Object.op_Implicit((Object)(object)p) && Object.op_Implicit((Object)(object)p.GetComponent<EnemyParent>())));
			if ((Object)(object)obj == (Object)null)
			{
				throw new Exception("The Robe enemy has no prefab.");
			}
			GameObject val2 = new GameObject("Peanut Prefabs");
			val2.SetActive(false);
			((Object)val2).hideFlags = (HideFlags)61;
			Object.DontDestroyOnLoad((Object)(object)val2);
			GameObject val3 = Object.Instantiate<GameObject>(obj, val2.transform);
			((Object)val3).name = "Enemy - Peanut";
			EnemyParent component = val3.GetComponent<EnemyParent>();
			Enemy componentInChildren = val3.GetComponentInChildren<Enemy>(true);
			EnemyRigidbody componentInChildren2 = val3.GetComponentInChildren<EnemyRigidbody>(true);
			if (!Object.op_Implicit((Object)(object)componentInChildren) || !Object.op_Implicit((Object)(object)componentInChildren2))
			{
				throw new Exception("The Robe prefab is missing its Enemy or EnemyRigidbody.");
			}
			AudioMixerGroup mixer = (from a in val3.GetComponentsInChildren<AudioSource>(true)
				select a.outputAudioMixerGroup).FirstOrDefault((Func<AudioMixerGroup, bool>)((AudioMixerGroup g) => Object.op_Implicit((Object)(object)g)));
			Material baseMat = (from r in val3.GetComponentsInChildren<Renderer>(true)
				where !(r is ParticleSystemRenderer)
				select r.sharedMaterial).FirstOrDefault((Func<Material, bool>)((Material m) => Object.op_Implicit((Object)(object)m)));
			MonoBehaviour[] componentsInChildren = val3.GetComponentsInChildren<MonoBehaviour>(true);
			foreach (MonoBehaviour val4 in componentsInChildren)
			{
				if (Object.op_Implicit((Object)(object)val4) && ((object)val4).GetType().Name.StartsWith("EnemyRobe"))
				{
					Object.DestroyImmediate((Object)(object)val4);
				}
			}
			Animator[] componentsInChildren2 = val3.GetComponentsInChildren<Animator>(true);
			for (int num = 0; num < componentsInChildren2.Length; num++)
			{
				((Behaviour)componentsInChildren2[num]).enabled = false;
			}
			Renderer[] componentsInChildren3 = val3.GetComponentsInChildren<Renderer>(true);
			for (int num = 0; num < componentsInChildren3.Length; num++)
			{
				componentsInChildren3[num].enabled = false;
			}
			Light[] componentsInChildren4 = val3.GetComponentsInChildren<Light>(true);
			for (int num = 0; num < componentsInChildren4.Length; num++)
			{
				((Behavio