Decompiled source of PeekingFreak v1.0.0

BepInEx/plugins/PeekingFreak/PeekingFreak.dll

Decompiled 2 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using PeekingFreak.NetcodePatcher;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Audio;

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

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

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

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace PeekingFreak
{
	internal static class FreakAssets
	{
		public static List<FreakPart> Parts = new List<FreakPart>();

		public static readonly Dictionary<string, Mesh> Meshes = new Dictionary<string, Mesh>();

		public static Material? Material;

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

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

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

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

		public static AudioClip? Alert;

		public static AudioClip? Lash;

		public static AudioClip? Die;

		private static readonly Dictionary<string, WavData> Waves = new Dictionary<string, WavData>();

		private static byte[] _texturePng = new byte[0];

		private static bool _unityObjectsReady;

		private static readonly string[] SoundNames = new string[13]
		{
			"squeak1", "squeak2", "squeak3", "yap1", "yap2", "yap3", "wet1", "wet2", "alert", "slap1",
			"slap2", "lash", "die"
		};

		public static void LoadRawData()
		{
			Parts = FreakModelFile.Read(ReadResource("freak.bin"));
			_texturePng = ReadResource("freak.png");
			string[] soundNames = SoundNames;
			foreach (string text in soundNames)
			{
				Waves[text] = WavFile.Read(ReadResource(text + ".wav"));
			}
		}

		private static byte[] ReadResource(string fileName)
		{
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			string text = executingAssembly.GetManifestResourceNames().FirstOrDefault((string n) => n.EndsWith("." + fileName, StringComparison.OrdinalIgnoreCase) || n.EndsWith("/" + fileName, StringComparison.OrdinalIgnoreCase) || n.Equals(fileName, StringComparison.OrdinalIgnoreCase));
			if (text == null)
			{
				throw new FileNotFoundException("Embedded resource not found: " + fileName);
			}
			using Stream stream = executingAssembly.GetManifestResourceStream(text);
			using MemoryStream memoryStream = new MemoryStream();
			stream.CopyTo(memoryStream);
			return memoryStream.ToArray();
		}

		public static void EnsureUnityObjects()
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: 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_0197: Expected O, but got Unknown
			//IL_00a8: 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_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Expected O, but got Unknown
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			if (_unityObjectsReady)
			{
				return;
			}
			_unityObjectsReady = true;
			foreach (FreakPart part in Parts)
			{
				Mesh val = new Mesh
				{
					name = "PeekingFreak_" + part.Name,
					hideFlags = (HideFlags)61
				};
				int vertexCount = part.VertexCount;
				Vector3[] array = (Vector3[])(object)new Vector3[vertexCount];
				Vector3[] array2 = (Vector3[])(object)new Vector3[vertexCount];
				Vector2[] array3 = (Vector2[])(object)new Vector2[vertexCount];
				int[] array4 = new int[vertexCount];
				for (int i = 0; i < vertexCount; i++)
				{
					array[i] = new Vector3(part.Positions[i * 3], part.Positions[i * 3 + 1], part.Positions[i * 3 + 2]);
					array2[i] = new Vector3(part.Normals[i * 3], part.Normals[i * 3 + 1], part.Normals[i * 3 + 2]);
					array3[i] = new Vector2(part.Uvs[i * 2], part.Uvs[i * 2 + 1]);
					array4[i] = i;
				}
				val.vertices = array;
				val.normals = array2;
				val.uv = array3;
				val.triangles = array4;
				val.RecalculateBounds();
				Meshes[part.Name] = val;
			}
			Texture2D val2 = new Texture2D(2, 2, (TextureFormat)4, false)
			{
				name = "PeekingFreak_Texture",
				hideFlags = (HideFlags)61
			};
			ImageConversion.LoadImage(val2, _texturePng);
			((Texture)val2).filterMode = (FilterMode)0;
			((Texture)val2).wrapMode = (TextureWrapMode)1;
			Shader val3 = Shader.Find("HDRP/Lit");
			if ((Object)(object)val3 == (Object)null)
			{
				Plugin.Log.LogError((object)"Shader HDRP/Lit not found; PeekingFreak will render with a fallback shader.");
				val3 = Shader.Find("Standard");
			}
			if ((Object)(object)val3 != (Object)null)
			{
				Material = new Material(val3)
				{
					name = "PeekingFreak_Material",
					hideFlags = (HideFlags)61
				};
				if (Material.HasProperty("_BaseColorMap"))
				{
					Material.SetTexture("_BaseColorMap", (Texture)(object)val2);
				}
				if (Material.HasProperty("_MainTex"))
				{
					Material.SetTexture("_MainTex", (Texture)(object)val2);
				}
				if (Material.HasProperty("_BaseColor"))
				{
					Material.SetColor("_BaseColor", Color.white);
				}
				if (Material.HasProperty("_Smoothness"))
				{
					Material.SetFloat("_Smoothness", 0.25f);
				}
				if (Material.HasProperty("_Metallic"))
				{
					Material.SetFloat("_Metallic", 0f);
				}
			}
			Squeaks = (AudioClip[])(object)new AudioClip[3]
			{
				Clip("squeak1"),
				Clip("squeak2"),
				Clip("squeak3")
			};
			Yaps = (AudioClip[])(object)new AudioClip[3]
			{
				Clip("yap1"),
				Clip("yap2"),
				Clip("yap3")
			};
			Wets = (AudioClip[])(object)new AudioClip[2]
			{
				Clip("wet1"),
				Clip("wet2")
			};
			Slaps = (AudioClip[])(object)new AudioClip[2]
			{
				Clip("slap1"),
				Clip("slap2")
			};
			Alert = Clip("alert");
			Lash = Clip("lash");
			Die = Clip("die");
		}

		private static AudioClip Clip(string name)
		{
			WavData wavData = Waves[name];
			AudioClip obj = AudioClip.Create("PeekingFreak_" + name, wavData.Samples.Length / wavData.Channels, wavData.Channels, wavData.SampleRate, false);
			obj.SetData(wavData.Samples, 0);
			((Object)obj).hideFlags = (HideFlags)61;
			return obj;
		}
	}
	public enum FreakState
	{
		Wandering,
		Peeking,
		Attacking
	}
	public struct FreakSenses
	{
		public bool SeesPlayer;

		public bool TargetValid;

		public bool TargetVisible;

		public float TargetDistance;

		public bool FacingTarget;
	}
	public struct FreakDecision
	{
		public bool StateChanged;

		public bool StartLash;

		public bool ResolveHit;

		public bool Paused;
	}
	public sealed class FreakBrain
	{
		public const float PeekSeconds = 2.4f;

		public const float LoseSeconds = 5f;

		public const float LashStartDistance = 2.2f;

		public const float LashHitDelay = 0.18f;

		public const float LashSeconds = 0.5f;

		public const float CalmSeconds = 3f;

		private readonly Random _random;

		private float _cooldown;

		private float _lost;

		private float _calm;

		private bool _hitResolved;

		private float _pauseLeft;

		private float _untilPause;

		public FreakState State { get; private set; }

		public float StateTime { get; private set; }

		public float LashTime { get; private set; } = -1f;

		public bool IsLashing => LashTime >= 0f;

		public FreakBrain(Random random)
		{
			_random = random ?? new Random();
			_untilPause = Range(5f, 12f);
		}

		public FreakDecision Tick(float dt, FreakSenses senses, float attackCooldown)
		{
			FreakDecision decision = default(FreakDecision);
			StateTime += dt;
			if (_cooldown > 0f)
			{
				_cooldown -= dt;
			}
			if (_calm > 0f)
			{
				_calm -= dt;
			}
			if (IsLashing)
			{
				LashTime += dt;
				if (!_hitResolved && LashTime >= 0.18f)
				{
					_hitResolved = true;
					decision.ResolveHit = State == FreakState.Attacking;
				}
				if (LashTime >= 0.5f)
				{
					LashTime = -1f;
				}
			}
			switch (State)
			{
			case FreakState.Wandering:
				if (senses.SeesPlayer && _calm <= 0f)
				{
					Enter(FreakState.Peeking, ref decision);
					break;
				}
				if (_pauseLeft > 0f)
				{
					_pauseLeft -= dt;
					decision.Paused = _pauseLeft > 0f;
					break;
				}
				_untilPause -= dt;
				if (_untilPause <= 0f)
				{
					_pauseLeft = Range(2f, 4.5f);
					_untilPause = Range(6f, 14f);
					decision.Paused = true;
				}
				break;
			case FreakState.Peeking:
				if (!senses.TargetValid)
				{
					Enter(FreakState.Wandering, ref decision);
				}
				else if (StateTime >= 2.4f)
				{
					_lost = 0f;
					_cooldown = 0f;
					Enter(FreakState.Attacking, ref decision);
				}
				break;
			case FreakState.Attacking:
				if (!senses.TargetValid)
				{
					GiveUp(ref decision);
					break;
				}
				_lost = (senses.TargetVisible ? 0f : (_lost + dt));
				if (_lost >= 5f)
				{
					GiveUp(ref decision);
				}
				else if (!IsLashing && _cooldown <= 0f && senses.TargetVisible && senses.FacingTarget && senses.TargetDistance <= 2.2f)
				{
					LashTime = 0f;
					_hitResolved = false;
					_cooldown = Math.Max(attackCooldown, 0.5f);
					decision.StartLash = true;
				}
				break;
			}
			return decision;
		}

		private void GiveUp(ref FreakDecision decision)
		{
			_calm = 3f;
			Enter(FreakState.Wandering, ref decision);
		}

		private void Enter(FreakState state, ref FreakDecision decision)
		{
			State = state;
			StateTime = 0f;
			_pauseLeft = 0f;
			decision.StateChanged = true;
			decision.Paused = false;
		}

		private float Range(float min, float max)
		{
			return min + (float)_random.NextDouble() * (max - min);
		}
	}
	public sealed class FreakPart
	{
		public string Name = "";

		public string Parent = "";

		public float PivotX;

		public float PivotY;

		public float PivotZ;

		public int VertexCount;

		public float[] Positions = new float[0];

		public float[] Normals = new float[0];

		public float[] Uvs = new float[0];
	}
	public static class FreakModelFile
	{
		public static List<FreakPart> Read(byte[] data)
		{
			using BinaryReader binaryReader = new BinaryReader(new MemoryStream(data));
			if (Encoding.ASCII.GetString(binaryReader.ReadBytes(4)) != "PFRK")
			{
				throw new InvalidDataException("Not a PeekingFreak model file.");
			}
			int num = binaryReader.ReadInt32();
			if (num != 1)
			{
				throw new InvalidDataException("Unsupported model version " + num + ".");
			}
			int num2 = binaryReader.ReadInt32();
			List<FreakPart> list = new List<FreakPart>(num2);
			for (int i = 0; i < num2; i++)
			{
				FreakPart freakPart = new FreakPart();
				freakPart.Name = ReadName(binaryReader);
				freakPart.Parent = ReadName(binaryReader);
				freakPart.PivotX = binaryReader.ReadSingle();
				freakPart.PivotY = binaryReader.ReadSingle();
				freakPart.PivotZ = binaryReader.ReadSingle();
				int num3 = binaryReader.ReadInt32();
				if (num3 < 0 || num3 % 3 != 0)
				{
					throw new InvalidDataException("Bad vertex count in part " + freakPart.Name + ".");
				}
				freakPart.VertexCount = num3;
				freakPart.Positions = new float[num3 * 3];
				freakPart.Normals = new float[num3 * 3];
				freakPart.Uvs = new float[num3 * 2];
				for (int j = 0; j < num3; j++)
				{
					for (int k = 0; k < 3; k++)
					{
						freakPart.Positions[j * 3 + k] = binaryReader.ReadSingle();
					}
					for (int l = 0; l < 3; l++)
					{
						freakPart.Normals[j * 3 + l] = binaryReader.ReadSingle();
					}
					for (int m = 0; m < 2; m++)
					{
						freakPart.Uvs[j * 2 + m] = binaryReader.ReadSingle();
					}
				}
				list.Add(freakPart);
			}
			if (binaryReader.BaseStream.Position != binaryReader.BaseStream.Length)
			{
				throw new InvalidDataException("Trailing data in model file.");
			}
			return list;
		}

		private static string ReadName(BinaryReader reader)
		{
			int count = reader.ReadByte();
			return Encoding.ASCII.GetString(reader.ReadBytes(count));
		}
	}
	public sealed class WavData
	{
		public int SampleRate;

		public int Channels;

		public float[] Samples = new float[0];
	}
	public static class WavFile
	{
		public static WavData Read(byte[] data)
		{
			using BinaryReader binaryReader = new BinaryReader(new MemoryStream(data));
			if (Tag(binaryReader) != "RIFF")
			{
				throw new InvalidDataException("Not a RIFF file.");
			}
			binaryReader.ReadInt32();
			if (Tag(binaryReader) != "WAVE")
			{
				throw new InvalidDataException("Not a WAVE file.");
			}
			WavData wavData = new WavData();
			bool flag = false;
			while (binaryReader.BaseStream.Position + 8 <= binaryReader.BaseStream.Length)
			{
				string text = Tag(binaryReader);
				int num = binaryReader.ReadInt32();
				long val = binaryReader.BaseStream.Position + num + (num & 1);
				if (text == "fmt ")
				{
					short num2 = binaryReader.ReadInt16();
					wavData.Channels = binaryReader.ReadInt16();
					wavData.SampleRate = binaryReader.ReadInt32();
					binaryReader.ReadInt32();
					binaryReader.ReadInt16();
					int num3 = binaryReader.ReadInt16();
					if (num2 != 1 || num3 != 16 || wavData.Channels < 1)
					{
						throw new InvalidDataException("Only 16-bit PCM WAV is supported.");
					}
					flag = true;
				}
				else if (text == "data")
				{
					if (!flag)
					{
						throw new InvalidDataException("WAV data before format.");
					}
					int num4 = Math.Min(num, (int)(binaryReader.BaseStream.Length - binaryReader.BaseStream.Position)) / 2;
					wavData.Samples = new float[num4];
					for (int i = 0; i < num4; i++)
					{
						wavData.Samples[i] = (float)binaryReader.ReadInt16() / 32768f;
					}
					return wavData;
				}
				binaryReader.BaseStream.Position = Math.Min(val, binaryReader.BaseStream.Length);
			}
			throw new InvalidDataException("WAV file has no data chunk.");
		}

		private static string Tag(BinaryReader reader)
		{
			return Encoding.ASCII.GetString(reader.ReadBytes(4));
		}
	}
	public static class FreakMath
	{
		public const float TongueReach = 1.6f;

		public const float TongueHitRadius = 0.55f;

		public const float PlayerHeight = 2.2f;

		public const float RestTongueTilt = 14f;

		public const float AlertYapsPerSecond = 4.5f;

		public static float LashExtension(float lashTime)
		{
			if (lashTime < 0f || lashTime >= 0.5f)
			{
				return 0f;
			}
			if (lashTime < 0.18f)
			{
				float num = lashTime / 0.18f;
				return 1f - (1f - num) * (1f - num);
			}
			if (lashTime < 0.24000001f)
			{
				return 1f;
			}
			float num2 = (lashTime - 0.18f - 0.06f) / 0.26f;
			return (1f - num2) * (1f - num2);
		}

		public static bool TongueHits(float mouthX, float mouthY, float mouthZ, float forwardX, float forwardY, float forwardZ, float feetX, float feetY, float feetZ)
		{
			return SegmentDistance(mouthX, mouthY, mouthZ, mouthX + forwardX * 1.6f, mouthY + forwardY * 1.6f, mouthZ + forwardZ * 1.6f, feetX, feetY, feetZ, feetX, feetY + 2.2f, feetZ) <= 0.55f;
		}

		public static float SegmentDistance(float p1x, float p1y, float p1z, float q1x, float q1y, float q1z, float p2x, float p2y, float p2z, float q2x, float q2y, float q2z)
		{
			double num = q1x - p1x;
			double num2 = q1y - p1y;
			double num3 = q1z - p1z;
			double num4 = q2x - p2x;
			double num5 = q2y - p2y;
			double num6 = q2z - p2z;
			double num7 = p1x - p2x;
			double num8 = p1y - p2y;
			double num9 = p1z - p2z;
			double num10 = num * num + num2 * num2 + num3 * num3;
			double num11 = num4 * num4 + num5 * num5 + num6 * num6;
			double num12 = num4 * num7 + num5 * num8 + num6 * num9;
			double num13;
			double num14;
			if (num10 <= 1E-09 && num11 <= 1E-09)
			{
				num13 = (num14 = 0.0);
			}
			else if (num10 <= 1E-09)
			{
				num13 = 0.0;
				num14 = Clamp01(num12 / num11);
			}
			else
			{
				double num15 = num * num7 + num2 * num8 + num3 * num9;
				if (num11 <= 1E-09)
				{
					num14 = 0.0;
					num13 = Clamp01((0.0 - num15) / num10);
				}
				else
				{
					double num16 = num * num4 + num2 * num5 + num3 * num6;
					double num17 = num10 * num11 - num16 * num16;
					num13 = ((num17 > 1E-09) ? Clamp01((num16 * num12 - num15 * num11) / num17) : 0.0);
					num14 = (num16 * num13 + num12) / num11;
					if (num14 < 0.0)
					{
						num14 = 0.0;
						num13 = Clamp01((0.0 - num15) / num10);
					}
					else if (num14 > 1.0)
					{
						num14 = 1.0;
						num13 = Clamp01((num16 - num15) / num10);
					}
				}
			}
			double num18 = num7 + num * num13 - num4 * num14;
			double num19 = num8 + num2 * num13 - num5 * num14;
			double num20 = num9 + num3 * num13 - num6 * num14;
			return (float)Math.Sqrt(num18 * num18 + num19 * num19 + num20 * num20);
		}

		private static double Clamp01(double v)
		{
			if (!(v < 0.0))
			{
				if (!(v > 1.0))
				{
					return v;
				}
				return 1.0;
			}
			return 0.0;
		}
	}
	internal sealed class FreakVisual
	{
		private const float TongueRestLength = 0.59f;

		private readonly Transform _root;

		private readonly Dictionary<string, Transform> _parts = new Dictionary<string, Transform>();

		private readonly Dictionary<string, Vector3> _rest = new Dictionary<string, Vector3>();

		private readonly Transform[] _tongue = (Transform[])(object)new Transform[4];

		private readonly Transform[] _drops = (Transform[])(object)new Transform[4];

		private readonly Vector3[] _dropRest = (Vector3[])(object)new Vector3[4];

		private float _time;

		private float _gait;

		private float _tonguePhase;

		private float _peek;

		private float _chase;

		private float _mouth;

		private float _deadBlend;

		public FreakVisual(Transform enemy)
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Expected O, but got Unknown
			//IL_0162: 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_0232: Unknown result type (might be due to invalid IL or missing references)
			//IL_0237: Unknown result type (might be due to invalid IL or missing references)
			_root = new GameObject("Model").transform;
			_root.SetParent(enemy, false);
			foreach (FreakPart part in FreakAssets.Parts)
			{
				GameObject val = new GameObject(part.Name);
				val.layer = ((Component)enemy).gameObject.layer;
				_parts[part.Name] = val.transform;
				val.AddComponent<MeshFilter>().sharedMesh = FreakAssets.Meshes[part.Name];
				((Renderer)val.AddComponent<MeshRenderer>()).sharedMaterial = FreakAssets.Material;
			}
			foreach (FreakPart part2 in FreakAssets.Parts)
			{
				Transform val2 = _parts[part2.Name];
				if (part2.Parent.Length == 0 || !_parts.TryGetValue(part2.Parent, out Transform value))
				{
					value = _root;
				}
				val2.SetParent(value, false);
				val2.localPosition = new Vector3(part2.PivotX, part2.PivotY, part2.PivotZ);
				_rest[part2.Name] = val2.localPosition;
			}
			for (int i = 0; i < 4; i++)
			{
				_tongue[i] = Find("Tongue" + i);
			}
			_drops[0] = Find("DropT0");
			_drops[1] = Find("DropT1");
			_drops[2] = Find("DropM0");
			_drops[3] = Find("DropM1");
			for (int j = 0; j < 4; j++)
			{
				_dropRest[j] = _drops[j].localPosition;
			}
		}

		private Transform Find(string name)
		{
			if (!_parts.TryGetValue(name, out Transform value))
			{
				return _root;
			}
			return value;
		}

		private static float Approach(float value, float target, float rate, float dt)
		{
			return Mathf.Lerp(value, target, 1f - Mathf.Exp((0f - rate) * dt));
		}

		public void Tick(float dt, float speed, FreakState state, float lashTime, bool dead, bool voicing)
		{
			//IL_01c9: 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_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_024d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: 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_02b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_034e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0467: Unknown result type (might be due to invalid IL or missing references)
			//IL_047c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0481: Unknown result type (might be due to invalid IL or missing references)
			//IL_0492: Unknown result type (might be due to invalid IL or missing references)
			//IL_0497: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_03da: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0415: Unknown result type (might be due to invalid IL or missing references)
			//IL_041a: Unknown result type (might be due to invalid IL or missing references)
			//IL_073b: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0504: Unknown result type (might be due to invalid IL or missing references)
			//IL_0529: Unknown result type (might be due to invalid IL or missing references)
			//IL_052e: Unknown result type (might be due to invalid IL or missing references)
			//IL_06cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_07a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_07ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_07bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_07c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_07d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_06f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_06fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0700: Unknown result type (might be due to invalid IL or missing references)
			//IL_0704: Unknown result type (might be due to invalid IL or missing references)
			//IL_07f1: Unknown result type (might be due to invalid IL or missing references)
			_time += dt;
			float num = (dead ? 0f : Mathf.Clamp01(speed / 1.5f));
			float num2 = Mathf.Lerp(0.45f, 0.95f, Mathf.InverseLerp(2f, 7f, speed));
			_gait += speed / num2 * dt * MathF.PI * 2f;
			_peek = Approach(_peek, (!dead && state == FreakState.Peeking) ? 1f : 0f, 8f, dt);
			_chase = Approach(_chase, (!dead && state == FreakState.Attacking) ? 1f : 0f, 8f, dt);
			_deadBlend = Approach(_deadBlend, dead ? 1f : 0f, 6f, dt);
			float num3 = (dead ? 0f : FreakMath.LashExtension(lashTime));
			float num4 = ((state == FreakState.Peeking) ? 4.5f : 7f);
			float num5 = ((voicing && !dead) ? Mathf.Abs(Mathf.Sin(_time * MathF.PI * num4)) : 0f);
			float num6 = Mathf.Max(Mathf.Max(_peek * 0.55f, _chase * 0.5f), num3) + num5 * 0.45f;
			_mouth = Approach(_mouth, Mathf.Clamp01(num6), 30f, dt);
			float num7 = Mathf.Sin(_time * 2.4f) * 0.012f * (1f - _deadBlend);
			float num8 = Mathf.Sin(_gait);
			_root.localRotation = Quaternion.Euler(0f, 0f, 90f * _deadBlend);
			_root.localPosition = new Vector3(0f, 0.36f * _deadBlend, 0f);
			Transform obj = Find("Body");
			float num9 = Mathf.Sin(_gait * 2f + 0.6f) * 0.035f * num + num7;
			obj.localPosition = _rest["Body"] + Vector3.up * (Mathf.Abs(num8) * 0.03f * num);
			obj.localRotation = Quaternion.Euler(_chase * 8f, 0f, num8 * 7f * num + _peek * 12f);
			obj.localScale = new Vector3(1f - num9 * 0.5f, 1f + num9, 1f - num9 * 0.5f);
			float num10 = (1f - num) * (1f - _peek) * (1f - _chase) * (1f - _deadBlend);
			Find("Head").localRotation = Quaternion.Euler((0f - _chase) * 6f + Mathf.Sin(_time * 1.3f) * 2f, Mathf.Sin(_time * 0.9f) * 28f * num10, _peek * 16f - num8 * 3f * num);
			for (int i = 0; i < 2; i++)
			{
				string text = ((i == 0) ? "CheekL" : "CheekR");
				float num11 = Mathf.Sin(_gait * 2f + 1.4f + (float)i * 0.5f) * 0.07f * num + Mathf.Sin(_time * 2.4f + 0.5f) * 0.02f + num5 * 0.05f;
				Transform obj2 = Find(text);
				obj2.localScale = Vector3.one * (1f + num11);
				obj2.localPosition = _rest[text] + Vector3.down * (Mathf.Sin(_gait * 2f + 2f) * 0.015f * num);
			}
			Transform obj3 = Find("Jaw");
			obj3.localScale = new Vector3(1f + 0.15f * _mouth, 1f + 1.1f * _mouth, 1f);
			obj3.localPosition = _rest["Jaw"] + Vector3.down * (0.035f * _mouth);
			for (int j = 0; j < 2; j++)
			{
				float num12 = ((j == 0) ? (-1f) : 1f);
				string text2 = ((j == 0) ? "LegL" : "LegR");
				Transform obj4 = Find(text2);
				obj4.localRotation = Quaternion.Euler(num12 * num8 * 38f * num, 0f, 0f);
				obj4.localPosition = _rest[text2] + Vector3.up * (Mathf.Max(0f, num12 * Mathf.Cos(_gait)) * 0.035f * num);
				float num13 = _peek * 30f + _chase * (25f + Mathf.Sin(_time * 22f + (float)j * 2f) * 25f) + num12 * num8 * 8f * num;
				Find((j == 0) ? "ArmL" : "ArmR").localRotation = Quaternion.Euler(0f, 0f, num12 * num13);
			}
			float num14 = Mathf.Lerp(6f, 14f, num) + _peek * 22f + _chase * 18f;
			_tonguePhase += (3f + num * 6f + _peek * 9f + _chase * 8f) * dt;
			float num15 = Mathf.Clamp01(num3 * 1.5f);
			for (int k = 0; k < 4; k++)
			{
				float num16 = num14 * Mathf.Sin(_tonguePhase - (float)k * 0.75f) * (0.6f + 0.2f * (float)k);
				float num17 = (_chase * 14f + _peek * 8f) * Mathf.Sin(_tonguePhase * 1.3f - (float)k * 0.9f);
				Quaternion val = Quaternion.Euler(((k == 0) ? (-14f * (1f - _deadBlend)) : 0f) + num17, 0f, num16 * (1f - _deadBlend));
				Quaternion val2 = ((k == 0) ? Quaternion.Euler(-98f, 0f, 0f) : Quaternion.identity);
				_tongue[k].localRotation = Quaternion.Slerp(val, val2, num15);
			}
			_tongue[0].localScale = new Vector3(1f, 1f + num3 * 1.7118645f, 1f);
			for (int l = 0; l < _drops.Length; l++)
			{
				float num18 = 1.3f + 0.27f * (float)l - 0.5f * Mathf.Max(_peek, _chase);
				float num19 = Mathf.Repeat(_time / num18 + (float)l * 0.37f, 1f);
				_drops[l].localPosition = _dropRest[l] + Vector3.down * (0.22f * num19 * num19);
				_drops[l].localScale = Vector3.one * (dead ? 0f : (1f - 0.6f * num19));
			}
		}
	}
	public class PeekingFreakAI : EnemyAI
	{
		private const int SoundSqueak = 0;

		private const int SoundYap = 1;

		private const int SoundWet = 2;

		private FreakBrain _brain;

		private FreakVisual? _visual;

		private Random _random;

		private FreakSenses _senses;

		private PlayerControllerB? _seenPlayer;

		private float _localLashTime = -1f;

		private float _observedSpeed;

		private Vector3 _lastPosition;

		private float _nextSound;

		private bool _stoppedForDeath;

		private const float AssumedPlayerWalkSpeed = 4.6f;

		private FreakState State => (FreakState)base.currentBehaviourStateIndex;

		public override void Start()
		{
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)0;
			try
			{
				FreakAssets.EnsureUnityObjects();
				_visual = new FreakVisual(((Component)this).transform);
				base.dieSFX = FreakAssets.Die;
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("PeekingFreak model could not be built: " + ex));
			}
			SetUpAudio();
			((EnemyAI)this).Start();
			base.enemyHP = 3;
			_random = new Random(StartOfRound.Instance.randomMapSeed + base.thisEnemyIndex);
			_brain = new FreakBrain(_random);
			_lastPosition = ((Component)this).transform.position;
			_nextSound = 2f + (float)_random.NextDouble() * 4f;
			base.currentBehaviourStateIndex = 0;
			if (((NetworkBehaviour)this).IsServer)
			{
				base.agent.speed = WanderSpeed();
				((EnemyAI)this).StartSearch(((Component)this).transform.position, (AISearchRoutine)null);
			}
		}

		private float ChaseSpeed()
		{
			PlayerControllerB val = base.targetPlayer;
			if ((Object)(object)val == (Object)null && (Object)(object)GameNetworkManager.Instance != (Object)null)
			{
				val = GameNetworkManager.Instance.localPlayerController;
			}
			return (((Object)(object)val != (Object)null && val.movementSpeed > 0.1f) ? val.movementSpeed : 4.6f) * Mathf.Clamp(Plugin.Settings.ChasePercent.Value, 10f, 300f) / 100f;
		}

		private float WanderSpeed()
		{
			return Mathf.Min(Plugin.Settings.WalkSpeed.Value, ChaseSpeed());
		}

		private void SetUpAudio()
		{
			float volume = Mathf.Clamp01(Plugin.Settings.SoundVolume.Value);
			AudioMixerGroup val = null;
			try
			{
				PlayerControllerB val2 = (((Object)(object)GameNetworkManager.Instance != (Object)null) ? GameNetworkManager.Instance.localPlayerController : null);
				if ((Object)(object)val2 != (Object)null && (Object)(object)val2.movementAudio != (Object)null)
				{
					val = val2.movementAudio.outputAudioMixerGroup;
				}
			}
			catch (Exception)
			{
			}
			AudioSource[] array = (AudioSource[])(object)new AudioSource[2] { base.creatureVoice, base.creatureSFX };
			foreach (AudioSource val3 in array)
			{
				if (!((Object)(object)val3 == (Object)null))
				{
					val3.volume = volume;
					if ((Object)(object)val != (Object)null)
					{
						val3.outputAudioMixerGroup = val;
					}
				}
			}
		}

		public override void Update()
		{
			//IL_0012: 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_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: 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_0156: 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)
			((EnemyAI)this).Update();
			float deltaTime = Time.deltaTime;
			Vector3 val = ((Component)this).transform.position - _lastPosition;
			val.y = 0f;
			_lastPosition = ((Component)this).transform.position;
			if (deltaTime > 0f)
			{
				_observedSpeed = Mathf.Lerp(_observedSpeed, ((Vector3)(ref val)).magnitude / deltaTime, 1f - Mathf.Exp(-10f * deltaTime));
			}
			if (_localLashTime >= 0f)
			{
				_localLashTime += deltaTime;
				if (_localLashTime >= 0.5f)
				{
					_localLashTime = -1f;
				}
			}
			if (base.isEnemyDead)
			{
				if (((NetworkBehaviour)this).IsServer && !_stoppedForDeath)
				{
					_stoppedForDeath = true;
					StopMoving();
				}
			}
			else if (((NetworkBehaviour)this).IsServer && !((Object)(object)StartOfRound.Instance == (Object)null) && !StartOfRound.Instance.allPlayersDead)
			{
				if ((Object)(object)base.targetPlayer != (Object)null)
				{
					Vector3 val2 = ((Component)base.targetPlayer).transform.position - ((Component)this).transform.position;
					_senses.TargetDistance = ((Vector3)(ref val2)).magnitude;
					val2.y = 0f;
					_senses.FacingTarget = ((Vector3)(ref val2)).sqrMagnitude < 0.01f || Vector3.Angle(((Component)this).transform.forward, val2) < 30f;
				}
				FreakDecision freakDecision = _brain.Tick(deltaTime, _senses, Plugin.Settings.AttackCooldown.Value);
				if (freakDecision.StateChanged)
				{
					OnStateChanged();
				}
				if (freakDecision.StartLash)
				{
					LashClientRpc();
				}
				if (freakDecision.ResolveHit)
				{
					ResolveTongueHit();
				}
				Steer(deltaTime, freakDecision.Paused);
				MakeNoises(deltaTime);
			}
		}

		public override void DoAIInterval()
		{
			((EnemyAI)this).DoAIInterval();
			if (base.isEnemyDead || !((NetworkBehaviour)this).IsServer || StartOfRound.Instance.allPlayersDead)
			{
				return;
			}
			switch (_brain.State)
			{
			case FreakState.Wandering:
			{
				PlayerControllerB val2 = ((EnemyAI)this).CheckLineOfSightForPlayer(70f, 16, 2);
				if ((Object)(object)val2 != (Object)null && ((EnemyAI)this).PlayerIsTargetable(val2, false, false, true))
				{
					_seenPlayer = val2;
					_senses.SeesPlayer = true;
				}
				else
				{
					_senses.SeesPlayer = false;
				}
				break;
			}
			case FreakState.Peeking:
			case FreakState.Attacking:
			{
				bool flag = (Object)(object)base.targetPlayer != (Object)null && ((EnemyAI)this).PlayerIsTargetable(base.targetPlayer, false, false, true);
				bool flag2 = flag && CanSee(base.targetPlayer);
				if (_brain.State == FreakState.Attacking && !flag2)
				{
					PlayerControllerB val = ((EnemyAI)this).CheckLineOfSightForPlayer(90f, 16, 2);
					if ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)base.targetPlayer && ((EnemyAI)this).PlayerIsTargetable(val, false, false, true))
					{
						base.targetPlayer = val;
						((EnemyAI)this).SetMovingTowardsTargetPlayer(val);
						SetStateClientRpc(2, (int)val.playerClientId);
						flag = (flag2 = true);
					}
				}
				_senses.TargetValid = flag;
				_senses.TargetVisible = flag2;
				break;
			}
			}
		}

		private bool CanSee(PlayerControllerB player)
		{
			//IL_002b: 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_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: 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_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_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = (((Object)(object)base.eye != (Object)null) ? base.eye.position : (((Component)this).transform.position + Vector3.up));
			Vector3 val2 = (((Object)(object)player.gameplayCamera != (Object)null) ? ((Component)player.gameplayCamera).transform.position : (((Component)player).transform.position + Vector3.up * 1.5f));
			if (Vector3.Distance(val, val2) > 25f)
			{
				return false;
			}
			return !Physics.Linecast(val, val2, StartOfRound.Instance.collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1);
		}

		private void OnStateChanged()
		{
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			switch (_brain.State)
			{
			case FreakState.Peeking:
				base.targetPlayer = _seenPlayer;
				_senses.SeesPlayer = false;
				_senses.TargetValid = (Object)(object)base.targetPlayer != (Object)null;
				_senses.TargetVisible = (Object)(object)base.targetPlayer != (Object)null;
				StopMoving();
				break;
			case FreakState.Attacking:
				if ((Object)(object)base.targetPlayer != (Object)null)
				{
					((EnemyAI)this).SetMovingTowardsTargetPlayer(base.targetPlayer);
				}
				_nextSound = 0.4f;
				break;
			default:
				base.targetPlayer = null;
				_seenPlayer = null;
				_senses = default(FreakSenses);
				base.movingTowardsTargetPlayer = false;
				base.agent.speed = WanderSpeed();
				((EnemyAI)this).StartSearch(((Component)this).transform.position, (AISearchRoutine)null);
				_nextSound = 2f + (float)_random.NextDouble() * 3f;
				break;
			}
			int targetPlayerId = (((Object)(object)base.targetPlayer != (Object)null) ? ((int)base.targetPlayer.playerClientId) : (-1));
			SetStateClientRpc((int)_brain.State, targetPlayerId);
		}

		private void StopMoving()
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			if (base.currentSearch != null && base.currentSearch.inProgress)
			{
				((EnemyAI)this).StopSearch(base.currentSearch, true);
			}
			base.movingTowardsTargetPlayer = false;
			if ((Object)(object)base.agent != (Object)null && ((Behaviour)base.agent).enabled)
			{
				base.agent.speed = 0f;
				base.agent.velocity = Vector3.zero;
			}
		}

		private void Steer(float dt, bool paused)
		{
			if ((Object)(object)base.agent == (Object)null || !((Behaviour)base.agent).enabled)
			{
				return;
			}
			switch (_brain.State)
			{
			case FreakState.Wandering:
				base.agent.speed = (paused ? 0f : WanderSpeed());
				break;
			case FreakState.Peeking:
				base.agent.speed = 0f;
				FaceTarget(dt, 6f);
				break;
			case FreakState.Attacking:
			{
				float num = ChaseSpeed();
				base.agent.speed = (_brain.IsLashing ? (num * 0.25f) : num);
				if (_senses.TargetDistance < 3.5f)
				{
					FaceTarget(dt, 10f);
				}
				break;
			}
			}
		}

		private void FaceTarget(float dt, float rate)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: 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_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)base.targetPlayer == (Object)null))
			{
				Vector3 val = ((Component)base.targetPlayer).transform.position - ((Component)this).transform.position;
				val.y = 0f;
				if (!(((Vector3)(ref val)).sqrMagnitude < 0.01f))
				{
					((Component)this).transform.rotation = Quaternion.Slerp(((Component)this).transform.rotation, Quaternion.LookRotation(val), 1f - Mathf.Exp((0f - rate) * dt));
				}
			}
		}

		private void MakeNoises(float dt)
		{
			_nextSound -= dt;
			if (!(_nextSound > 0f))
			{
				float num = 0.9f + (float)_random.NextDouble() * 0.25f;
				switch (_brain.State)
				{
				case FreakState.Wandering:
				{
					double num2 = _random.NextDouble();
					int kind = ((!(num2 < 0.45)) ? ((num2 < 0.75) ? 1 : 2) : 0);
					VoiceClientRpc(kind, _random.Next(0, 3), num);
					_nextSound = 3.5f + (float)_random.NextDouble() * 5f;
					break;
				}
				case FreakState.Attacking:
					VoiceClientRpc(1, _random.Next(0, 3), num + 0.15f);
					_nextSound = 0.55f + (float)_random.NextDouble() * 0.6f;
					break;
				default:
					_nextSound = 0.5f;
					break;
				}
			}
		}

		private void ResolveTongueHit()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: 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_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: 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_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = ((Component)this).transform.position + Vector3.up * 0.8f + ((Component)this).transform.forward * 0.35f;
			Vector3 forward = ((Component)this).transform.forward;
			int damage = Mathf.Max(0, Plugin.Settings.TongueDamage.Value);
			PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
			foreach (PlayerControllerB val2 in allPlayerScripts)
			{
				if (!((Object)(object)val2 == (Object)null) && val2.isPlayerControlled && !val2.isPlayerDead)
				{
					Vector3 position = ((Component)val2).transform.position;
					if (FreakMath.TongueHits(val.x, val.y, val.z, forward.x, forward.y, forward.z, position.x, position.y, position.z) && !Physics.Linecast(val, position + Vector3.up * 1.2f, StartOfRound.Instance.collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1))
					{
						TongueHitClientRpc((int)val2.playerClientId, damage);
					}
				}
			}
		}

		public override void HitEnemy(int force = 1, PlayerControllerB playerWhoHit = null, bool playHitSFX = false, int hitID = -1)
		{
			((EnemyAI)this).HitEnemy(force, playerWhoHit, playHitSFX, hitID);
			if (base.isEnemyDead)
			{
				return;
			}
			base.enemyHP -= force;
			if ((Object)(object)base.creatureSFX != (Object)null && FreakAssets.Squeaks.Length != 0)
			{
				base.creatureSFX.PlayOneShot(FreakAssets.Squeaks[2]);
			}
			if (((NetworkBehaviour)this).IsOwner)
			{
				if (base.enemyHP <= 0)
				{
					StopMoving();
					((EnemyAI)this).KillEnemyOnOwnerClient(false);
				}
				else if (((NetworkBehaviour)this).IsServer && _brain.State == FreakState.Wandering && (Object)(object)playerWhoHit != (Object)null && ((EnemyAI)this).PlayerIsTargetable(playerWhoHit, false, false, true))
				{
					_seenPlayer = playerWhoHit;
					_senses.SeesPlayer = true;
				}
			}
		}

		private void LateUpdate()
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			if (!((NetworkBehaviour)this).IsServer && !base.isEnemyDead)
			{
				float deltaTime = Time.deltaTime;
				bool flag = (Object)(object)base.targetPlayer != (Object)null && Vector3.Distance(((Component)this).transform.position, ((Component)base.targetPlayer).transform.position) < 3.5f;
				if (State == FreakState.Peeking || (State == FreakState.Attacking && flag))
				{
					FaceTarget(deltaTime, 8f);
				}
			}
			if (_visual != null)
			{
				bool voicing = (Object)(object)base.creatureVoice != (Object)null && base.creatureVoice.isPlaying;
				_visual.Tick(Time.deltaTime, _observedSpeed, State, _localLashTime, base.isEnemyDead, voicing);
			}
		}

		[ClientRpc]
		public void SetStateClientRpc(int state, int targetPlayerId)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Invalid comparison between Unknown and I4
			//IL_005f: 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_0071: 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_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val2 = default(ClientRpcParams);
				FastBufferWriter val = ((NetworkBehaviour)this).__beginSendClientRpc(765560378u, val2, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val, state);
				BytePacker.WriteValueBitPacked(val, targetPlayerId);
				((NetworkBehaviour)this).__endSendClientRpc(ref val, 765560378u, val2, (RpcDelivery)0);
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				((NetworkBehaviour)this).__rpc_exec_stage = (__RpcExecStage)0;
				bool num = base.currentBehaviourStateIndex != state;
				base.previousBehaviourStateIndex = base.currentBehaviourStateIndex;
				base.currentBehaviourStateIndex = state;
				if (!((NetworkBehaviour)this).IsServer)
				{
					base.targetPlayer = PlayerById(targetPlayerId);
				}
				if (num && state == 1 && (Object)(object)base.creatureVoice != (Object)null && (Object)(object)FreakAssets.Alert != (Object)null)
				{
					base.creatureVoice.Stop();
					base.creatureVoice.pitch = 1f;
					base.creatureVoice.PlayOneShot(FreakAssets.Alert);
				}
			}
		}

		[ClientRpc]
		public void VoiceClientRpc(int kind, int index, float pitch)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Invalid comparison between Unknown and I4
			//IL_005f: 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_0071: 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_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val2 = default(ClientRpcParams);
				FastBufferWriter val = ((NetworkBehaviour)this).__beginSendClientRpc(2203308899u, val2, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val, kind);
				BytePacker.WriteValueBitPacked(val, index);
				((FastBufferWriter)(ref val)).WriteValueSafe<float>(ref pitch, default(ForPrimitives));
				((NetworkBehaviour)this).__endSendClientRpc(ref val, 2203308899u, val2, (RpcDelivery)0);
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1 || (!networkManager.IsClient && !networkManager.IsHost))
			{
				return;
			}
			((NetworkBehaviour)this).__rpc_exec_stage = (__RpcExecStage)0;
			if (!base.isEnemyDead && !((Object)(object)base.creatureVoice == (Object)null))
			{
				AudioClip[] array = kind switch
				{
					1 => FreakAssets.Yaps, 
					0 => FreakAssets.Squeaks, 
					_ => FreakAssets.Wets, 
				};
				if (array.Length != 0)
				{
					base.creatureVoice.pitch = Mathf.Clamp(pitch, 0.5f, 2f);
					base.creatureVoice.PlayOneShot(array[Mathf.Abs(index) % array.Length]);
				}
			}
		}

		[ClientRpc]
		public void LashClientRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//IL_005f: 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_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val2 = default(ClientRpcParams);
				FastBufferWriter val = ((NetworkBehaviour)this).__beginSendClientRpc(1234722301u, val2, (RpcDelivery)0);
				((NetworkBehaviour)this).__endSendClientRpc(ref val, 1234722301u, val2, (RpcDelivery)0);
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				((NetworkBehaviour)this).__rpc_exec_stage = (__RpcExecStage)0;
				_localLashTime = 0f;
				if ((Object)(object)base.creatureSFX != (Object)null && (Object)(object)FreakAssets.Lash != (Object)null)
				{
					base.creatureSFX.PlayOneShot(FreakAssets.Lash);
				}
			}
		}

		[ClientRpc]
		public void TongueHitClientRpc(int playerId, int damage)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Invalid comparison between Unknown and I4
			//IL_005f: 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_0071: 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_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val2 = default(ClientRpcParams);
				FastBufferWriter val = ((NetworkBehaviour)this).__beginSendClientRpc(2462172718u, val2, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val, playerId);
				BytePacker.WriteValueBitPacked(val, damage);
				((NetworkBehaviour)this).__endSendClientRpc(ref val, 2462172718u, val2, (RpcDelivery)0);
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				((NetworkBehaviour)this).__rpc_exec_stage = (__RpcExecStage)0;
				if ((Object)(object)base.creatureSFX != (Object)null && FreakAssets.Slaps.Length != 0)
				{
					base.creatureSFX.PlayOneShot(FreakAssets.Slaps[Mathf.Abs(playerId) % FreakAssets.Slaps.Length]);
				}
				PlayerControllerB val3 = PlayerById(playerId);
				if (!((Object)(object)val3 == (Object)null) && !((Object)(object)GameNetworkManager.Instance == (Object)null) && !((Object)(object)val3 != (Object)(object)GameNetworkManager.Instance.localPlayerController) && !val3.isPlayerDead && val3.isPlayerControlled && damage > 0)
				{
					val3.DamagePlayer(damage, true, true, (CauseOfDeath)6, 0, false, ((Component)this).transform.forward * 3f);
				}
			}
		}

		private static PlayerControllerB? PlayerById(int id)
		{
			if ((Object)(object)StartOfRound.Instance == (Object)null)
			{
				return null;
			}
			PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
			if (id < 0 || id >= allPlayerScripts.Length)
			{
				return null;
			}
			return allPlayerScripts[id];
		}

		protected override void __initializeVariables()
		{
			((EnemyAI)this).__initializeVariables();
		}

		protected override void __initializeRpcs()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Expected O, but got Unknown
			((NetworkBehaviour)this).__registerRpc(765560378u, new RpcReceiveHandler(__rpc_handler_765560378), "SetStateClientRpc");
			((NetworkBehaviour)this).__registerRpc(2203308899u, new RpcReceiveHandler(__rpc_handler_2203308899), "VoiceClientRpc");
			((NetworkBehaviour)this).__registerRpc(1234722301u, new RpcReceiveHandler(__rpc_handler_1234722301), "LashClientRpc");
			((NetworkBehaviour)this).__registerRpc(2462172718u, new RpcReceiveHandler(__rpc_handler_2462172718), "TongueHitClientRpc");
			((EnemyAI)this).__initializeRpcs();
		}

		private static void __rpc_handler_765560378(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: 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_0043: 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)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				int state = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref state);
				int targetPlayerId = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref targetPlayerId);
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((PeekingFreakAI)(object)target).SetStateClientRpc(state, targetPlayerId);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_2203308899(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: 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_0049: 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_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				int kind = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref kind);
				int index = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref index);
				float pitch = default(float);
				((FastBufferReader)(ref reader)).ReadValueSafe<float>(ref pitch, default(ForPrimitives));
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((PeekingFreakAI)(object)target).VoiceClientRpc(kind, index, pitch);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_1234722301(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0029: 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)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((PeekingFreakAI)(object)target).LashClientRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_2462172718(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: 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_0043: 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)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				int playerId = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref playerId);
				int damage = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref damage);
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((PeekingFreakAI)(object)target).TongueHitClientRpc(playerId, damage);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected internal override string __getTypeName()
		{
			return "PeekingFreakAI";
		}
	}
	public sealed class FreakConfig
	{
		public readonly ConfigEntry<int> SpawnRarity;

		public readonly ConfigEntry<int> MaxCount;

		public readonly ConfigEntry<float> WalkSpeed;

		public readonly ConfigEntry<float> ChasePercent;

		public readonly ConfigEntry<int> TongueDamage;

		public readonly ConfigEntry<float> AttackCooldown;

		public readonly ConfigEntry<float> SoundVolume;

		public FreakConfig(ConfigFile file)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Expected O, but got Unknown
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Expected O, but got Unknown
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Expected O, but got Unknown
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Expected O, but got Unknown
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Expected O, but got Unknown
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Expected O, but got Unknown
			SpawnRarity = file.Bind<int>("Spawning", "Indoor spawn rarity", 30, new ConfigDescription("Spawn weight inside facilities on every moon. Higher is more common; 0 disables spawning. Host's value is used. Needs a game restart.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 500), Array.Empty<object>()));
			MaxCount = file.Bind<int>("Spawning", "Maximum number of PeekingFreaks", 2, new ConfigDescription("How many can be alive in one round. Host's value is used. Needs a game restart.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 20), Array.Empty<object>()));
			WalkSpeed = file.Bind<float>("Movement", "Walking speed", 2.6f, new ConfigDescription("Speed while wandering, metres per second. Never exceeds the chase speed. Host's value is used.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 10f), Array.Empty<object>()));
			ChasePercent = file.Bind<float>("Movement", "Chase speed percent of player walking speed", 80f, new ConfigDescription("Speed while chasing, as a percentage of the targeted player's unencumbered walking speed. 80 means 20% slower than a walking player. Host's value is used.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(10f, 300f), Array.Empty<object>()));
			TongueDamage = file.Bind<int>("Attack", "Tongue attack damage", 25, new ConfigDescription("Health removed by one tongue hit (a player has 100). Host's value is used.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
			AttackCooldown = file.Bind<float>("Attack", "Attack cooldown", 1.2f, new ConfigDescription("Seconds between tongue lashes. Host's value is used.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 10f), Array.Empty<object>()));
			SoundVolume = file.Bind<float>("Audio", "Sound volume", 0.8f, new ConfigDescription("Volume of all PeekingFreak sounds on this computer, 0 to 1.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
		}
	}
	[BepInPlugin("PeekingFreak", "PeekingFreak", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "PeekingFreak";

		public const string Name = "PeekingFreak";

		public const string Version = "1.0.0";

		internal static ManualLogSource Log;

		internal static FreakConfig Settings;

		public static EnemyType? FreakType;

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			Settings = new FreakConfig(((BaseUnityPlugin)this).Config);
			InitializeNetworkBehaviours();
			try
			{
				FreakAssets.LoadRawData();
			}
			catch (Exception ex)
			{
				Log.LogError((object)("PeekingFreak assets could not be read, the enemy is not registered: " + ex));
				return;
			}
			FreakType = BuildEnemyType();
			TerminalNode val = ScriptableObject.CreateInstance<TerminalNode>();
			((Object)val).name = "PeekingFreakFile";
			val.creatureName = "PeekingFreak";
			val.clearPreviousText = true;
			val.maxCharactersToType = 2000;
			val.displayText = "PEEKINGFREAK\n\nSigurd's danger level: 40%\n\nScientific name: Cricetus linguosus\nA hamster about half as tall as an employee, mostly cheek. It wanders the facility squeaking to itself and is harmless until it notices you.\n\nWhen it sees someone it stops, cocks sideways to peek at them and yaps at the top of its lungs for a couple of seconds. That is the warning. After that it runs at you and slaps with its tongue, which has more reach than you would guess.\n\nBreak line of sight for a few seconds and it forgets about you. Three shovel hits put it down.\n\nCute face. Freaky tongue. Deadly surprise.\n\n";
			int num = Mathf.Max(0, Settings.SpawnRarity.Value);
			Enemies.RegisterEnemy(FreakType, num, (LevelTypes)(-1), (SpawnType)0, val, (TerminalKeyword)null);
			Log.LogInfo((object)("PeekingFreak 1.0.0 loaded (rarity " + num + ", max " + FreakType.MaxCount + ")."));
		}

		private static EnemyType BuildEnemyType()
		{
			//IL_00d2: 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_026e: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: Expected O, but got Unknown
			//IL_027c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0281: Unknown result type (might be due to invalid IL or missing references)
			//IL_028d: Expected O, but got Unknown
			//IL_028f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0294: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a0: Expected O, but got Unknown
			//IL_02c1: 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_0323: Unknown result type (might be due to invalid IL or missing references)
			//IL_0347: Unknown result type (might be due to invalid IL or missing references)
			int num = LayerMask.NameToLayer("Enemies");
			if (num < 0)
			{
				num = 19;
			}
			int num2 = LayerMask.NameToLayer("ScanNode");
			if (num2 < 0)
			{
				num2 = 22;
			}
			GameObject val = NetworkPrefabs.CreateNetworkPrefab("PeekingFreak");
			val.layer = num;
			try
			{
				val.tag = "Enemy";
			}
			catch (UnityException)
			{
			}
			Rigidbody obj = val.AddComponent<Rigidbody>();
			obj.isKinematic = true;
			obj.useGravity = false;
			NavMeshAgent obj2 = val.AddComponent<NavMeshAgent>();
			obj2.radius = 0.4f;
			obj2.height = 1.2f;
			obj2.baseOffset = 0f;
			obj2.speed = Settings.WalkSpeed.Value;
			obj2.angularSpeed = 500f;
			obj2.acceleration = 30f;
			obj2.stoppingDistance = 0f;
			Transform val2 = Child(val, "Eye", num);
			val2.localPosition = new Vector3(0f, 0.95f, 0.3f);
			AudioSource creatureVoice = Audio(((Component)Child(val, "Voice", num)).gameObject, 26f);
			AudioSource creatureSFX = Audio(((Component)Child(val, "SFX", num)).gameObject, 20f);
			Animator creatureAnimator = ((Component)Child(val, "AnimatorStub", num)).gameObject.AddComponent<Animator>();
			EnemyType val3 = ScriptableObject.CreateInstance<EnemyType>();
			((Object)val3).name = "PeekingFreak";
			val3.enemyName = "PeekingFreak";
			val3.enemyPrefab = val;
			val3.MaxCount = Mathf.Max(0, Settings.MaxCount.Value);
			val3.PowerLevel = 1f;
			val3.probabilityCurve = AnimationCurve.Constant(0f, 1f, 1f);
			val3.numberSpawnedFalloff = AnimationCurve.Constant(0f, 1f, 1f);
			val3.useNumberSpawnedFalloff = false;
			val3.isOutsideEnemy = false;
			val3.isDaytimeEnemy = false;
			val3.canDie = true;
			val3.canBeStunned = false;
			val3.doorSpeedMultiplier = 0.6f;
			val3.loudnessMultiplier = 1f;
			PeekingFreakAI peekingFreakAI = val.AddComponent<PeekingFreakAI>();
			((EnemyAI)peekingFreakAI).enemyType = val3;
			((EnemyAI)peekingFreakAI).creatureVoice = creatureVoice;
			((EnemyAI)peekingFreakAI).creatureSFX = creatureSFX;
			((EnemyAI)peekingFreakAI).creatureAnimator = creatureAnimator;
			((EnemyAI)peekingFreakAI).eye = val2;
			((EnemyAI)peekingFreakAI).enemyHP = 3;
			((EnemyAI)peekingFreakAI).AIIntervalTime = 0.2f;
			((EnemyAI)peekingFreakAI).updatePositionThreshold = 0.3f;
			((EnemyAI)peekingFreakAI).syncMovementSpeed = 0.15f;
			((EnemyAI)peekingFreakAI).exitVentAnimationTime = 1f;
			((EnemyAI)peekingFreakAI).enemyBehaviourStates = (EnemyBehaviourState[])(object)new EnemyBehaviourState[3]
			{
				new EnemyBehaviourState
				{
					name = "Wandering"
				},
				new EnemyBehaviourState
				{
					name = "Peeking"
				},
				new EnemyBehaviourState
				{
					name = "Attacking"
				}
			};
			Transform obj3 = Child(val, "Collision", num);
			obj3.localPosition = new Vector3(0f, 0.6f, 0f);
			BoxCollider obj4 = ((Component)obj3).gameObject.AddComponent<BoxCollider>();
			((Collider)obj4).isTrigger = true;
			obj4.size = new Vector3(0.95f, 1.2f, 0.85f);
			((Component)obj3).gameObject.AddComponent<EnemyAICollisionDetect>().mainScript = (EnemyAI)(object)peekingFreakAI;
			Transform obj5 = Child(val, "ScanNode", num2);
			obj5.localPosition = new Vector3(0f, 0.7f, 0f);
			((Component)obj5).gameObject.AddComponent<BoxCollider>().size = new Vector3(0.6f, 0.6f, 0.6f);
			ScanNodeProperties obj6 = ((Component)obj5).gameObject.AddComponent<ScanNodeProperties>();
			obj6.headerText = "PeekingFreak";
			obj6.subText = "";
			obj6.nodeType = 1;
			obj6.minRange = 1;
			obj6.maxRange = 13;
			obj6.requiresLineOfSight = true;
			obj6.creatureScanID = -1;
			return val3;
		}

		private static Transform Child(GameObject parent, string name, int layer)
		{
			//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_000d: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name)
			{
				layer = layer
			};
			val.transform.SetParent(parent.transform, false);
			return val.transform;
		}

		private static AudioSource Audio(GameObject go, float maxDistance)
		{
			AudioSource obj = go.AddComponent<AudioSource>();
			obj.playOnAwake = false;
			obj.loop = false;
			obj.spatialBlend = 1f;
			obj.rolloffMode = (AudioRolloffMode)1;
			obj.minDistance = 2f;
			obj.maxDistance = maxDistance;
			obj.dopplerLevel = 0f;
			return obj;
		}

		private static void InitializeNetworkBehaviours()
		{
			Type[] types = Assembly.GetExecutingAssembly().GetTypes();
			for (int i = 0; i < types.Length; i++)
			{
				MethodInfo[] methods = types[i].GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
				foreach (MethodInfo methodInfo in methods)
				{
					if (methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false).Length != 0)
					{
						methodInfo.Invoke(null, null);
					}
				}
			}
		}
	}
}
namespace __GEN
{
	internal class NetworkVariableSerializationHelper
	{
		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeSerialization()
		{
		}
	}
}
namespace PeekingFreak.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}