Decompiled source of Jenny Headman Replacement v0.8.0

BepInEx/plugins/JennyHeadmanReplacement/EllieHeadman.dll

Decompiled 3 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using ExitGames.Client.Photon;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Networking;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;

[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("EllieHeadman")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.8.0.0")]
[assembly: AssemblyInformationalVersion("0.8.0")]
[assembly: AssemblyProduct("EllieHeadman")]
[assembly: AssemblyTitle("EllieHeadman")]
[assembly: AssemblyVersion("0.8.0.0")]
[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 EllieHeadman
{
	internal sealed class AttackContactRelay : MonoBehaviour
	{
		internal Action<Collider> Stay;

		internal Func<bool> CanRelay;

		private void OnTriggerStay(Collider other)
		{
			if (Stay != null && CanRelay != null && CanRelay() && Object.op_Implicit((Object)(object)((Component)other).GetComponent<PlayerTrigger>()))
			{
				Stay(other);
			}
		}
	}
	internal sealed class AttackPlayback
	{
		private float eventTime = -1f;

		public float Time { get; private set; }

		public void Signal()
		{
			if (eventTime < 0f)
			{
				eventTime = 0f;
			}
		}

		public void Reset()
		{
			eventTime = -1f;
			Time = 0f;
		}

		public bool Step(float dt, bool animatorAttack, float normalizedTime, float duration, bool frozen)
		{
			if (animatorAttack)
			{
				eventTime = -1f;
				Time = Math.Max(0f, Math.Min(1f, normalizedTime)) * duration;
				return true;
			}
			if (eventTime < 0f)
			{
				return false;
			}
			if (!frozen)
			{
				eventTime += Math.Max(0f, dt);
			}
			if (eventTime >= duration)
			{
				eventTime = -1f;
				return false;
			}
			Time = eventTime;
			return true;
		}
	}
	internal sealed class CaptureTimer
	{
		private float cooldown;

		private bool damageConsumed;

		private bool completionPending;

		public float Elapsed { get; private set; }

		public float Duration { get; private set; }

		public bool Active { get; private set; }

		public bool Available
		{
			get
			{
				if (!Active)
				{
					return cooldown <= 0f;
				}
				return false;
			}
		}

		public bool Begin(float duration)
		{
			if (!Available)
			{
				return false;
			}
			Duration = Math.Max(0.5f, Math.Min(8f, duration));
			Elapsed = 0f;
			Active = true;
			damageConsumed = false;
			completionPending = false;
			cooldown = Duration + 4f;
			return true;
		}

		public bool TryConsumeDamage()
		{
			if (!Active || damageConsumed)
			{
				return false;
			}
			damageConsumed = true;
			return true;
		}

		public void Step(float dt)
		{
			dt = Math.Max(0f, dt);
			cooldown = Math.Max(0f, cooldown - dt);
			if (Active)
			{
				Elapsed = Math.Min(Duration, Elapsed + dt);
				if (Elapsed >= Duration)
				{
					Active = false;
					completionPending = true;
				}
			}
		}

		public bool TryConsumeCompletion()
		{
			if (!completionPending)
			{
				return false;
			}
			completionPending = false;
			return true;
		}

		public void Cancel()
		{
			Active = false;
			Elapsed = 0f;
			damageConsumed = true;
			completionPending = false;
		}
	}
	internal sealed class CharacterAsset
	{
		internal sealed class Part
		{
			public string Name;

			public int Parent;

			public Vector3 Bind;

			public Mesh Mesh;

			public Vector3[] Vertices;
		}

		internal sealed class Clip
		{
			public string Name;

			public float Duration;

			public bool Loop;

			public Quaternion[][] Rotations;

			public Vector3[][] Offsets;

			public void Sample(float time, Transform[] joints, Part[] parts, float blend)
			{
				//IL_0070: 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_0087: Unknown result type (might be due to invalid IL or missing references)
				//IL_008c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0091: 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_00ad: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bb: 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_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_00d1: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
				float num = (Loop ? Mathf.Repeat(time, Duration) : Mathf.Clamp(time, 0f, Duration)) / Duration * (float)(Rotations.Length - 1);
				int num2 = Mathf.Min((int)num, Rotations.Length - 1);
				int num3 = Mathf.Min(num2 + 1, Rotations.Length - 1);
				for (int i = 0; i < joints.Length; i++)
				{
					Quaternion val = Quaternion.Slerp(Rotations[num2][i], Rotations[num3][i], num - (float)num2);
					Vector3 val2 = parts[i].Bind + Vector3.Lerp(Offsets[num2][i], Offsets[num3][i], num - (float)num2);
					joints[i].localRotation = Quaternion.Slerp(joints[i].localRotation, val, blend);
					joints[i].localPosition = Vector3.Lerp(joints[i].localPosition, val2, blend);
				}
			}
		}

		public Part[] Parts;

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

		public Texture2D Texture;

		public BoneWeight[] SkinWeights;

		public Matrix4x4[] SkinBindposes;

		public int[] SoleVertices;

		private void LoadSkin(string path)
		{
			//IL_0291: 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_02a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e6: 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_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			using (BinaryReader binaryReader = new BinaryReader(File.OpenRead(path)))
			{
				if (Encoding.ASCII.GetString(binaryReader.ReadBytes(4)) != "SKN1")
				{
					throw new InvalidDataException("Unknown skin version");
				}
				int num = Count(binaryReader, 200000);
				if (num != Parts[0].Vertices.Length)
				{
					throw new InvalidDataException("Skin vertex count mismatch");
				}
				SkinWeights = (BoneWeight[])(object)new BoneWeight[num];
				for (int i = 0; i < num; i++)
				{
					int num2 = binaryReader.ReadInt32();
					int num3 = binaryReader.ReadInt32();
					int num4 = binaryReader.ReadInt32();
					int num5 = binaryReader.ReadInt32();
					float num6 = binaryReader.ReadSingle();
					float num7 = binaryReader.ReadSingle();
					float num8 = binaryReader.ReadSingle();
					float num9 = binaryReader.ReadSingle();
					if (num2 < 0 || num3 < 0 || num4 < 0 || num5 < 0 || num2 >= Parts.Length || num3 >= Parts.Length || num4 >= Parts.Length || num5 >= Parts.Length || num6 < 0f || num7 < 0f || num8 < 0f || num9 < 0f || float.IsNaN(num6 + num7 + num8 + num9) || Mathf.Abs(num6 + num7 + num8 + num9 - 1f) > 0.001f)
					{
						throw new InvalidDataException("Invalid skin weights");
					}
					BoneWeight[] skinWeights = SkinWeights;
					int num10 = i;
					BoneWeight val = default(BoneWeight);
					((BoneWeight)(ref val)).boneIndex0 = num2;
					((BoneWeight)(ref val)).boneIndex1 = num3;
					((BoneWeight)(ref val)).boneIndex2 = num4;
					((BoneWeight)(ref val)).boneIndex3 = num5;
					((BoneWeight)(ref val)).weight0 = num6;
					((BoneWeight)(ref val)).weight1 = num7;
					((BoneWeight)(ref val)).weight2 = num8;
					((BoneWeight)(ref val)).weight3 = num9;
					skinWeights[num10] = val;
				}
				int num11 = Count(binaryReader, num);
				if (num11 == 0)
				{
					throw new InvalidDataException("No sole vertices");
				}
				SoleVertices = new int[num11];
				for (int j = 0; j < num11; j++)
				{
					SoleVertices[j] = binaryReader.ReadInt32();
					if (SoleVertices[j] < 0 || SoleVertices[j] >= num)
					{
						throw new InvalidDataException("Invalid sole vertex");
					}
				}
				if (binaryReader.BaseStream.Position != binaryReader.BaseStream.Length)
				{
					throw new InvalidDataException("Trailing skin bytes");
				}
			}
			SkinBindposes = (Matrix4x4[])(object)new Matrix4x4[Parts.Length];
			Vector3[] array = (Vector3[])(object)new Vector3[Parts.Length];
			for (int k = 0; k < Parts.Length; k++)
			{
				array[k] = Parts[k].Bind + ((Parts[k].Parent >= 0) ? array[Parts[k].Parent] : Vector3.zero);
				SkinBindposes[k] = Matrix4x4.Translate(-array[k]);
			}
			Parts[0].Mesh.boneWeights = SkinWeights;
			Parts[0].Mesh.bindposes = SkinBindposes;
		}

		public float SoleHeight(Transform[] bones, Matrix4x4[] matrices)
		{
			//IL_0009: 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_001f: 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_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: 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_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < bones.Length; i++)
			{
				matrices[i] = bones[i].localToWorldMatrix * SkinBindposes[i];
			}
			float num = float.PositiveInfinity;
			int[] soleVertices = SoleVertices;
			foreach (int num2 in soleVertices)
			{
				BoneWeight val = SkinWeights[num2];
				Vector3 val2 = Parts[0].Vertices[num2];
				Vector3 val3 = ((Matrix4x4)(ref matrices[((BoneWeight)(ref val)).boneIndex0])).MultiplyPoint3x4(val2) * ((BoneWeight)(ref val)).weight0 + ((Matrix4x4)(ref matrices[((BoneWeight)(ref val)).boneIndex1])).MultiplyPoint3x4(val2) * ((BoneWeight)(ref val)).weight1 + ((Matrix4x4)(ref matrices[((BoneWeight)(ref val)).boneIndex2])).MultiplyPoint3x4(val2) * ((BoneWeight)(ref val)).weight2 + ((Matrix4x4)(ref matrices[((BoneWeight)(ref val)).boneIndex3])).MultiplyPoint3x4(val2) * ((BoneWeight)(ref val)).weight3;
				num = Mathf.Min(num, val3.y);
			}
			return num;
		}

		private static int Count(BinaryReader r, int max)
		{
			int num = r.ReadInt32();
			if (num < 0 || num > max)
			{
				throw new InvalidDataException("Invalid asset count: " + num);
			}
			return num;
		}

		private static string String(BinaryReader r)
		{
			int num = Count(r, 128);
			byte[] array = r.ReadBytes(num);
			if (array.Length != num)
			{
				throw new EndOfStreamException();
			}
			return Encoding.UTF8.GetString(array);
		}

		private static Vector3 Vector(BinaryReader r)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
		}

		public static CharacterAsset Load(string folder)
		{
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//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_0124: 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_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_0458: Unknown result type (might be due to invalid IL or missing references)
			//IL_045d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0468: Unknown result type (might be due to invalid IL or missing references)
			//IL_046f: Unknown result type (might be due to invalid IL or missing references)
			//IL_047b: Expected O, but got Unknown
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Expected O, but got Unknown
			//IL_0348: Unknown result type (might be due to invalid IL or missing references)
			//IL_034d: Unknown result type (might be due to invalid IL or missing references)
			//IL_035f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0364: Unknown result type (might be due to invalid IL or missing references)
			CharacterAsset characterAsset = new CharacterAsset();
			try
			{
				using (BinaryReader binaryReader = new BinaryReader(File.OpenRead(Path.Combine(folder, "ellie.hmr"))))
				{
					if (Encoding.ASCII.GetString(binaryReader.ReadBytes(4)) != "HMR1")
					{
						throw new InvalidDataException("Unknown asset version");
					}
					int num = Count(binaryReader, 64);
					if (num == 0)
					{
						throw new InvalidDataException("No joints");
					}
					characterAsset.Parts = new Part[num];
					for (int i = 0; i < num; i++)
					{
						Part part = new Part
						{
							Name = String(binaryReader),
							Parent = binaryReader.ReadInt32(),
							Bind = Vector(binaryReader)
						};
						characterAsset.Parts[i] = part;
						if (part.Parent < -1 || part.Parent >= i)
						{
							throw new InvalidDataException("Invalid joint parent");
						}
						int num2 = Count(binaryReader, 200000);
						int num3 = Count(binaryReader, 600000);
						if (num3 % 3 != 0)
						{
							throw new InvalidDataException("Invalid triangles");
						}
						Vector3[] array = (Vector3[])(object)new Vector3[num2];
						Vector3[] array2 = (Vector3[])(object)new Vector3[num2];
						Vector2[] array3 = (Vector2[])(object)new Vector2[num2];
						for (int j = 0; j < num2; j++)
						{
							array[j] = Vector(binaryReader);
							array2[j] = Vector(binaryReader);
							array3[j] = new Vector2(binaryReader.ReadSingle(), binaryReader.ReadSingle());
						}
						int[] array4 = new int[num3 * 2];
						for (int k = 0; k < num3; k++)
						{
							int num4 = binaryReader.ReadInt32();
							if (num4 < 0 || num4 >= num2)
							{
								throw new InvalidDataException("Invalid vertex index");
							}
							array4[k] = num4;
						}
						for (int l = 0; l < num3; l += 3)
						{
							array4[num3 + l] = array4[l + 2];
							array4[num3 + l + 1] = array4[l + 1];
							array4[num3 + l + 2] = array4[l];
						}
						part.Mesh = new Mesh
						{
							name = "Ellie_" + part.Name,
							indexFormat = (IndexFormat)1
						};
						part.Mesh.vertices = array;
						part.Mesh.normals = array2;
						part.Mesh.uv = array3;
						part.Vertices = array;
						part.Mesh.triangles = array4;
						part.Mesh.RecalculateBounds();
					}
					int num5 = Count(binaryReader, 16);
					for (int m = 0; m < num5; m++)
					{
						Clip clip = new Clip
						{
							Name = String(binaryReader),
							Duration = binaryReader.ReadSingle(),
							Loop = (binaryReader.ReadInt32() != 0)
						};
						if (!(clip.Duration > 0f) || float.IsInfinity(clip.Duration))
						{
							throw new InvalidDataException("Invalid duration");
						}
						int num6 = Count(binaryReader, 10000);
						if (num6 < 2)
						{
							throw new InvalidDataException("Clip needs two samples");
						}
						clip.Rotations = new Quaternion[num6][];
						clip.Offsets = new Vector3[num6][];
						for (int n = 0; n < num6; n++)
						{
							clip.Rotations[n] = (Quaternion[])(object)new Quaternion[num];
							clip.Offsets[n] = (Vector3[])(object)new Vector3[num];
							for (int num7 = 0; num7 < num; num7++)
							{
								clip.Rotations[n][num7] = new Quaternion(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
								clip.Offsets[n][num7] = Vector(binaryReader);
							}
						}
						characterAsset.Clips.Add(clip.Name, clip);
					}
					if (binaryReader.BaseStream.Position != binaryReader.BaseStream.Length)
					{
						throw new InvalidDataException("Trailing asset bytes");
					}
				}
				string[] array5 = new string[4] { "Idle", "Walk", "Chase", "Attack" };
				foreach (string text in array5)
				{
					if (!characterAsset.Clips.ContainsKey(text))
					{
						throw new InvalidDataException("Missing clip " + text);
					}
				}
				string path = Path.Combine(folder, "ellie.skin");
				if (File.Exists(path))
				{
					characterAsset.LoadSkin(path);
				}
				characterAsset.Texture = new Texture2D(2, 2, (TextureFormat)4, false)
				{
					name = "EllieArmor",
					filterMode = (FilterMode)0,
					wrapMode = (TextureWrapMode)1
				};
				if (!ImageConversion.LoadImage(characterAsset.Texture, File.ReadAllBytes(Path.Combine(folder, "ellie.png"))))
				{
					throw new InvalidDataException("Texture could not be loaded");
				}
				return characterAsset;
			}
			catch
			{
				characterAsset.Dispose();
				throw;
			}
		}

		public void Dispose()
		{
			if (Parts != null)
			{
				Part[] parts = Parts;
				foreach (Part part in parts)
				{
					if (Object.op_Implicit((Object)(object)part?.Mesh))
					{
						Object.Destroy((Object)(object)part.Mesh);
					}
				}
			}
			if (Object.op_Implicit((Object)(object)Texture))
			{
				Object.Destroy((Object)(object)Texture);
			}
		}
	}
	internal sealed class ChestDeformation
	{
		private readonly SpringAxis bounce = new SpringAxis();

		private readonly SpringAxis depth = new SpringAxis();

		private readonly SpringAxis compression = new SpringAxis();

		public float OffsetY => bounce.Angle;

		public float OffsetZ => depth.Angle;

		public float ScaleY { get; private set; } = 1f;

		public float ScaleXZ { get; private set; } = 1f;

		public void Reset()
		{
			bounce.Reset();
			depth.Reset();
			compression.Reset();
			float scaleY = (ScaleXZ = 1f);
			ScaleY = scaleY;
		}

		public void Step(float accelerationY, float accelerationZ, float gaitPhase, float gaitWeight, float dt, float strength, float damping, bool squish)
		{
			float num = (float)Math.Pow(Math.Max(0.0, Math.Cos(gaitPhase)), 8.0) * Math.Max(0f, Math.Min(1f, gaitWeight));
			bounce.Step(((0f - accelerationY) * 0.9f + (0.14f * gaitWeight - num) * 5f) * strength, dt, 220f, damping, 0.025f);
			depth.Step((0f - accelerationZ) * 0.6f * strength, dt, 220f, damping, 0.015f);
			if (squish)
			{
				float num2 = Math.Max(-0.025f, Math.Min(0.025f, accelerationY * 0.0015f));
				compression.Step(240f * (0.065f * num - 0.009f * gaitWeight + num2) * strength, dt, 240f, damping, 0.09f);
				float num3 = Math.Max(-0.04f, Math.Min(0.09f, compression.Angle));
				ScaleY = 1f - num3;
				ScaleXZ = 1f / (float)Math.Sqrt(ScaleY);
			}
			else
			{
				compression.Reset();
				float scaleY = (ScaleXZ = 1f);
				ScaleY = scaleY;
			}
		}
	}
	internal sealed class GrabIndentation
	{
		private sealed class Dent
		{
			public Vector3 Center;

			public Vector3 Normal;

			public float Amount;

			public bool Held;
		}

		private readonly CharacterAsset asset;

		private readonly Transform[] bones;

		private readonly Matrix4x4[] matrices;

		private readonly PhysGrabObject[] objects;

		private readonly SkinnedMeshRenderer renderer;

		private readonly Mesh mesh;

		private readonly Vector3[] original;

		private readonly Vector3[] normals;

		private readonly Vector3[] vertices;

		private readonly Vector3[] workingNormals;

		private readonly float[] mask;

		private readonly List<int> chest = new List<int>();

		private readonly List<int> front = new List<int>();

		private readonly Dictionary<PhysGrabber, Dent> dents = new Dictionary<PhysGrabber, Dent>();

		private readonly List<PhysGrabber> expired = new List<PhysGrabber>();

		private bool dirty;

		public int ChestVertices => chest.Count;

		public int GrabObjects => objects.Length;

		public bool Held
		{
			get
			{
				PhysGrabObject[] array = objects;
				foreach (PhysGrabObject val in array)
				{
					if (Object.op_Implicit((Object)(object)val) && val.grabbed)
					{
						return true;
					}
				}
				return false;
			}
		}

		public GrabIndentation(CharacterAsset asset, Transform[] bones, SkinnedMeshRenderer renderer, PhysGrabObject[] objects)
		{
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			this.asset = asset;
			this.bones = bones;
			this.renderer = renderer;
			this.objects = objects;
			mesh = Object.Instantiate<Mesh>(renderer.sharedMesh);
			((Object)mesh).name = "JennyGrabDeformMesh";
			mesh.MarkDynamic();
			renderer.sharedMesh = mesh;
			original = asset.Parts[0].Vertices;
			normals = mesh.normals;
			vertices = (Vector3[])(object)new Vector3[original.Length];
			workingNormals = (Vector3[])(object)new Vector3[original.Length];
			mask = new float[original.Length];
			matrices = (Matrix4x4[])(object)new Matrix4x4[bones.Length];
			for (int i = 0; i < mask.Length; i++)
			{
				BoneWeight val = asset.SkinWeights[i];
				mask[i] = ChestWeight(((BoneWeight)(ref val)).boneIndex0, ((BoneWeight)(ref val)).weight0) + ChestWeight(((BoneWeight)(ref val)).boneIndex1, ((BoneWeight)(ref val)).weight1) + ChestWeight(((BoneWeight)(ref val)).boneIndex2, ((BoneWeight)(ref val)).weight2) + ChestWeight(((BoneWeight)(ref val)).boneIndex3, ((BoneWeight)(ref val)).weight3);
				if (mask[i] > 0.02f)
				{
					chest.Add(i);
					if (normals[i].z > 0.05f)
					{
						front.Add(i);
					}
				}
			}
		}

		private float ChestWeight(int index, float weight)
		{
			if (!(asset.Parts[index].Name == "LeftBreast") && !(asset.Parts[index].Name == "RightBreast"))
			{
				return 0f;
			}
			return weight;
		}

		private Vector3 Position(int index)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0031: 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_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			BoneWeight val = asset.SkinWeights[index];
			Vector3 val2 = original[index];
			return ((Matrix4x4)(ref matrices[((BoneWeight)(ref val)).boneIndex0])).MultiplyPoint3x4(val2) * ((BoneWeight)(ref val)).weight0 + ((Matrix4x4)(ref matrices[((BoneWeight)(ref val)).boneIndex1])).MultiplyPoint3x4(val2) * ((BoneWeight)(ref val)).weight1 + ((Matrix4x4)(ref matrices[((BoneWeight)(ref val)).boneIndex2])).MultiplyPoint3x4(val2) * ((BoneWeight)(ref val)).weight2 + ((Matrix4x4)(ref matrices[((BoneWeight)(ref val)).boneIndex3])).MultiplyPoint3x4(val2) * ((BoneWeight)(ref val)).weight3;
		}

		public void Reset()
		{
			dents.Clear();
			if (dirty && Object.op_Implicit((Object)(object)mesh))
			{
				mesh.vertices = original;
				mesh.normals = normals;
				dirty = false;
			}
		}

		public void Step(float dt, bool enabled, float radius, float depth)
		{
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: 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_03f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f8: 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_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0421: Unknown result type (might be due to invalid IL or missing references)
			//IL_0428: Unknown result type (might be due to invalid IL or missing references)
			//IL_042d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0432: Unknown result type (might be due to invalid IL or missing references)
			//IL_0434: Unknown result type (might be due to invalid IL or missing references)
			//IL_0438: Unknown result type (might be due to invalid IL or missing references)
			//IL_0457: Unknown result type (might be due to invalid IL or missing references)
			//IL_045b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0462: 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_046c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0520: Unknown result type (might be due to invalid IL or missing references)
			//IL_0525: 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_0533: Unknown result type (might be due to invalid IL or missing references)
			//IL_0548: Unknown result type (might be due to invalid IL or missing references)
			//IL_054d: Unknown result type (might be due to invalid IL or missing references)
			//IL_054f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0554: Unknown result type (might be due to invalid IL or missing references)
			//IL_0558: 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)
			//IL_049e: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c3: 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_04e8: 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_04f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: 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_020e: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			//IL_0249: 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_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_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			if (!enabled || front.Count == 0)
			{
				Reset();
			}
			else
			{
				if (dt <= 0f)
				{
					return;
				}
				foreach (Dent value2 in dents.Values)
				{
					value2.Held = false;
				}
				Vector3 val3;
				if (Held)
				{
					for (int i = 0; i < bones.Length; i++)
					{
						matrices[i] = bones[i].localToWorldMatrix * asset.SkinBindposes[i];
					}
					PhysGrabObject[] array = objects;
					foreach (PhysGrabObject val in array)
					{
						if (!Object.op_Implicit((Object)(object)val) || !val.grabbed || val.playerGrabbing == null)
						{
							continue;
						}
						foreach (PhysGrabber item in val.playerGrabbing)
						{
							if (!Object.op_Implicit((Object)(object)item) || !item.grabbed)
							{
								continue;
							}
							Vector3 val2 = (Object.op_Implicit((Object)(object)item.grabbedObjectTransform) ? item.grabbedObjectTransform.TransformPoint(item.localGrabPosition) : item.physGrabPointPosition);
							int num = -1;
							float num2 = float.PositiveInfinity;
							foreach (int item2 in front)
							{
								val3 = Position(item2) - val2;
								float sqrMagnitude = ((Vector3)(ref val3)).sqrMagnitude;
								if (sqrMagnitude < num2)
								{
									num2 = sqrMagnitude;
									num = item2;
								}
							}
							if (num >= 0)
							{
								if (!dents.TryGetValue(item, out var value))
								{
									value = new Dent
									{
										Center = original[num],
										Normal = normals[num]
									};
									dents.Add(item, value);
								}
								float num3 = 1f - Mathf.Exp((0f - dt) * 20f);
								value.Center = Vector3.Lerp(value.Center, original[num], num3);
								Dent dent = value;
								val3 = Vector3.Slerp(value.Normal, normals[num], num3);
								dent.Normal = ((Vector3)(ref val3)).normalized;
								value.Held = true;
							}
						}
					}
				}
				expired.Clear();
				foreach (KeyValuePair<PhysGrabber, Dent> dent2 in dents)
				{
					dent2.Value.Amount = IndentKernel.Envelope(dent2.Value.Amount, dent2.Value.Held, dt);
					if (!dent2.Value.Held && dent2.Value.Amount < 0.001f)
					{
						expired.Add(dent2.Key);
					}
				}
				foreach (PhysGrabber item3 in expired)
				{
					dents.Remove(item3);
				}
				if (dents.Count == 0)
				{
					if (dirty)
					{
						mesh.vertices = original;
						mesh.normals = normals;
						dirty = false;
					}
					return;
				}
				Array.Copy(original, vertices, original.Length);
				Array.Copy(normals, workingNormals, normals.Length);
				foreach (int item4 in chest)
				{
					Vector3 val4 = Vector3.zero;
					Vector3 val5 = Vector3.zero;
					foreach (Dent value3 in dents.Values)
					{
						Vector3 val6 = original[item4] - value3.Center;
						float num4 = Vector3.Dot(val6, value3.Normal);
						if (!(Mathf.Abs(num4) > radius * 0.5f))
						{
							Vector3 val7 = val6 - value3.Normal * num4;
							float sqrMagnitude2 = ((Vector3)(ref val7)).sqrMagnitude;
							float num5 = IndentKernel.Depth(sqrMagnitude2, radius, depth) * value3.Amount * mask[item4];
							if (!(num5 <= 0f))
							{
								val4 -= value3.Normal * num5;
								float num6 = 1f - sqrMagnitude2 / (radius * radius);
								val5 -= val7 * (4f * depth * num6 / (radius * radius) * value3.Amount * mask[item4]);
							}
						}
					}
					vertices[item4] = original[item4] + Vector3.ClampMagnitude(val4, depth);
					Vector3[] array2 = workingNormals;
					val3 = normals[item4] + val5;
					array2[item4] = ((Vector3)(ref val3)).normalized;
				}
				mesh.vertices = vertices;
				mesh.normals = workingNormals;
				dirty = true;
			}
		}

		public void Dispose()
		{
			Reset();
			if (Object.op_Implicit((Object)(object)renderer))
			{
				renderer.sharedMesh = asset.Parts[0].Mesh;
			}
			if (Object.op_Implicit((Object)(object)mesh))
			{
				Object.Destroy((Object)(object)mesh);
			}
		}
	}
	internal sealed class HeadmanVoice : MonoBehaviour
	{
		private static readonly Dictionary<Sound, HeadmanVoice> owners = new Dictionary<Sound, HeadmanVoice>();

		private readonly List<Sound> sounds = new List<Sound>();

		private AudioSource source;

		private Transform anchor;

		private VoiceGainFilter gainFilter;

		private bool autoStarted;

		private float nextDiagnostic;

		private float lastStart = -1f;

		internal static void Attach(EnemyHeadController controller, Transform head)
		{
			HeadmanVoice headmanVoice = ((Component)controller).GetComponent<HeadmanVoice>() ?? ((Component)controller).gameObject.AddComponent<HeadmanVoice>();
			if (!Object.op_Implicit((Object)(object)headmanVoice.source))
			{
				headmanVoice.CreateSource(head);
				headmanVoice.Register(controller, new string[1] { "DeathSound" });
				headmanVoice.Register(controller.AnimationSystem, new string[14]
				{
					"ChaseBegin", "ChaseBeginGlobal", "ChaseBeginToChase", "ChaseToIdle", "ChaseLoop", "ChaseLoop2", "TeethChatter", "MoveLong", "MoveShort", "BiteStart",
					"BiteEnd", "Spawn", "Despawn", "Hurt"
				});
				Plugin.Instance?.ReportReady("Custom MP3 registered for " + headmanVoice.sounds.Count + " Headman voice cues.");
			}
		}

		internal static void EnsureCutscene(EnemyHeadCatchCutscene cutscene)
		{
			HeadmanVoice headmanVoice = ((Component)cutscene).GetComponent<HeadmanVoice>() ?? ((Component)cutscene).gameObject.AddComponent<HeadmanVoice>();
			if (!Object.op_Implicit((Object)(object)headmanVoice.source))
			{
				headmanVoice.CreateSource(((Component)cutscene).transform);
				headmanVoice.Register(cutscene, new string[3] { "BiteBegin", "BiteFirst", "BiteLast" });
			}
		}

		private void CreateSource(Transform anchor)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			this.anchor = anchor;
			GameObject val = new GameObject("JennyCustomVoice");
			val.transform.position = anchor.position;
			source = val.AddComponent<AudioSource>();
			source.playOnAwake = false;
			source.loop = false;
			source.spatialBlend = 1f;
			source.minDistance = 6f;
			source.maxDistance = 35f;
			source.priority = 32;
			source.rolloffMode = (AudioRolloffMode)1;
			source.dopplerLevel = 0f;
			gainFilter = val.AddComponent<VoiceGainFilter>();
			AudioManager instance = AudioManager.instance;
			GameObject val2 = (GameObject)(Object.op_Implicit((Object)(object)instance) ? /*isinst with value type is only supported in some contexts*/: null);
			AudioSource val3 = (Object.op_Implicit((Object)(object)val2) ? val2.GetComponentInChildren<AudioSource>(true) : null);
			if (Object.op_Implicit((Object)(object)val3))
			{
				source.outputAudioMixerGroup = val3.outputAudioMixerGroup;
			}
		}

		private void Register(object component, string[] fields)
		{
			if (component == null)
			{
				return;
			}
			foreach (string text in fields)
			{
				object? obj = AccessTools.Field(component.GetType(), text)?.GetValue(component);
				Sound val = (Sound)((obj is Sound) ? obj : null);
				if (val != null && !sounds.Contains(val))
				{
					sounds.Add(val);
					owners[val] = this;
				}
			}
		}

		internal static bool TryGet(Sound sound, out HeadmanVoice voice)
		{
			voice = null;
			if (Object.op_Implicit((Object)(object)Plugin.Instance) && Plugin.Instance.CustomVoiceEnabled.Value && Object.op_Implicit((Object)(object)Plugin.Instance.VoiceClip) && owners.TryGetValue(sound, out voice) && Object.op_Implicit((Object)(object)voice) && ((Behaviour)voice).isActiveAndEnabled)
			{
				return Object.op_Implicit((Object)(object)voice.source);
			}
			return false;
		}

		internal AudioSource Play()
		{
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: 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)
			foreach (Sound sound in sounds)
			{
				if (Object.op_Implicit((Object)(object)sound.Source) && (Object)(object)sound.Source != (Object)(object)source)
				{
					sound.Source.Stop();
				}
			}
			source.volume = Plugin.Instance.VoiceVolume.Value;
			source.pitch = 1f;
			if (Object.op_Implicit((Object)(object)gainFilter))
			{
				gainFilter.Gain = Plugin.Instance.CustomVoiceGain.Value;
			}
			if (Object.op_Implicit((Object)(object)anchor))
			{
				((Component)source).transform.position = anchor.position;
			}
			if (!source.isPlaying && Time.unscaledTime - lastStart > 0.35f)
			{
				source.clip = Plugin.Instance.VoiceClip;
				source.time = Mathf.Clamp(Plugin.Instance.VoiceStartSeconds.Value, 0f, Mathf.Max(0f, source.clip.length - 0.1f));
				source.Play();
				lastStart = Time.unscaledTime;
				autoStarted = source.isPlaying;
				nextDiagnostic = Time.unscaledTime + 3f;
				Plugin.Instance.ReportReady("Custom voice started: playing=" + source.isPlaying + ", active=" + ((Component)source).gameObject.activeInHierarchy + ", gain=" + gainFilter.Gain + ", volume=" + source.volume + ", clipState=" + ((object)source.clip.loadState/*cast due to .constrained prefix*/).ToString() + ", source=" + ((object)((Component)source).transform.position/*cast due to .constrained prefix*/).ToString());
			}
			return source;
		}

		internal void Stop()
		{
			if (Object.op_Implicit((Object)(object)source))
			{
				source.Stop();
			}
		}

		private void Update()
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)Plugin.Instance) || !Plugin.Instance.CustomVoiceEnabled.Value)
			{
				Stop();
			}
			else if (Object.op_Implicit((Object)(object)source))
			{
				if (Object.op_Implicit((Object)(object)anchor))
				{
					((Component)source).transform.position = anchor.position;
				}
				source.volume = Plugin.Instance.VoiceVolume.Value;
				if (Object.op_Implicit((Object)(object)gainFilter))
				{
					gainFilter.Gain = Plugin.Instance.CustomVoiceGain.Value;
				}
				if (!autoStarted && Object.op_Implicit((Object)(object)Plugin.Instance.VoiceClip) && Object.op_Implicit((Object)(object)anchor) && ((Component)anchor).gameObject.activeInHierarchy)
				{
					Play();
				}
				if (source.isPlaying && Time.unscaledTime >= nextDiagnostic)
				{
					Plugin.Instance.ReportReady("Custom voice output: time=" + source.time.ToString("F1") + ", peak=" + gainFilter.Peak.ToString("F4") + ", rms=" + gainFilter.Rms.ToString("F4") + ", distanceToListener=" + (Object.op_Implicit((Object)(object)Camera.main) ? Vector3.Distance(((Component)source).transform.position, ((Component)Camera.main).transform.position).ToString("F1") : "unknown"));
					nextDiagnostic = Time.unscaledTime + 15f;
				}
			}
		}

		private void OnEnable()
		{
			autoStarted = false;
		}

		private void OnDisable()
		{
			Stop();
			autoStarted = false;
		}

		private void OnDestroy()
		{
			Stop();
			foreach (Sound sound in sounds)
			{
				if (owners.TryGetValue(sound, out var value) && (Object)(object)value == (Object)(object)this)
				{
					owners.Remove(sound);
				}
			}
			if (Object.op_Implicit((Object)(object)source))
			{
				Object.Destroy((Object)(object)((Component)source).gameObject);
			}
		}
	}
	[HarmonyPatch]
	internal static class VoicePlayPatch
	{
		private static IEnumerable<MethodBase> TargetMethods()
		{
			MethodInfo[] methods = typeof(Sound).GetMethods(BindingFlags.Instance | BindingFlags.Public);
			foreach (MethodInfo methodInfo in methods)
			{
				if (methodInfo.Name == "Play" && methodInfo.ReturnType == typeof(AudioSource))
				{
					yield return methodInfo;
				}
			}
		}

		private static bool Prefix(Sound __instance, ref AudioSource __result)
		{
			if (!HeadmanVoice.TryGet(__instance, out var voice))
			{
				return true;
			}
			__result = voice.Play();
			return false;
		}
	}
	[HarmonyPatch(typeof(Sound), "PlayLoop")]
	internal static class VoiceLoopPatch
	{
		private static bool Prefix(Sound __instance, bool playing)
		{
			if (!HeadmanVoice.TryGet(__instance, out var voice))
			{
				return true;
			}
			if (playing)
			{
				voice.Play();
			}
			else if (Object.op_Implicit((Object)(object)__instance.Source))
			{
				__instance.Source.Stop();
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(Sound), "Stop")]
	internal static class VoiceStopPatch
	{
		private static bool Prefix(Sound __instance)
		{
			if (!HeadmanVoice.TryGet(__instance, out var voice))
			{
				return true;
			}
			voice.Stop();
			return false;
		}
	}
	[HarmonyPatch]
	internal static class CutsceneVoicePatch
	{
		private static IEnumerable<MethodBase> TargetMethods()
		{
			string[] array = new string[3] { "PlayBiteBegin", "PlayBiteFirst", "PlayBiteLast" };
			foreach (string text in array)
			{
				yield return AccessTools.Method(typeof(EnemyHeadCatchCutscene), text, (Type[])null, (Type[])null);
			}
		}

		private static void Prefix(EnemyHeadCatchCutscene __instance)
		{
			HeadmanVoice.EnsureCutscene(__instance);
		}
	}
	internal static class IndentKernel
	{
		public static float Depth(float squaredDistance, float radius, float depth)
		{
			if (radius <= 0f || depth <= 0f || squaredDistance < 0f || float.IsNaN(squaredDistance) || float.IsInfinity(squaredDistance) || float.IsNaN(radius) || float.IsInfinity(radius) || float.IsNaN(depth) || float.IsInfinity(depth))
			{
				return 0f;
			}
			float num = 1f - squaredDistance / (radius * radius);
			if (!(num > 0f))
			{
				return 0f;
			}
			return Math.Min(depth, 0.08f) * num * num;
		}

		public static float Envelope(float value, bool held, float dt)
		{
			if (dt <= 0f)
			{
				return value;
			}
			return value + ((float)(held ? 1 : 0) - value) * (1f - (float)Math.Exp((float)(-(held ? 24 : 7)) * Math.Min(dt, 0.1f)));
		}
	}
	internal sealed class MotionTracker
	{
		public float X;

		public float Z;

		public float Speed;

		public float Yaw;

		public bool Walking;

		public bool Snapped;

		private float rawX;

		private float rawZ;

		private float vx;

		private float vz;

		private float stoppedTime;

		private bool initialized;

		private float faceX;

		private float faceZ;

		private float pendingYaw;

		private float pendingTime;

		private float acceptedYaw;

		private bool hasPending;

		public void Reset(float x, float z, float yaw)
		{
			X = (rawX = x);
			Z = (rawZ = z);
			Yaw = yaw;
			vx = (vz = (Speed = (stoppedTime = 0f)));
			Walking = false;
			initialized = true;
			faceX = x;
			faceZ = z;
			pendingYaw = (acceptedYaw = yaw);
			pendingTime = 0f;
			hasPending = false;
		}

		public void Step(float x, float z, float dt, float steeringX = 0f, float steeringZ = 0f, bool useSteering = false, bool holdFacing = false)
		{
			Snapped = false;
			if (!initialized)
			{
				Reset(x, z, 0f);
				Snapped = true;
			}
			else
			{
				if (dt <= 0f)
				{
					return;
				}
				float num = x - rawX;
				float num2 = z - rawZ;
				rawX = x;
				rawZ = z;
				if (num * num + num2 * num2 > 9f)
				{
					Reset(x, z, Yaw);
					Snapped = true;
					return;
				}
				float num3 = 1f - (float)Math.Exp((0f - dt) / 0.065f);
				X += (x - X) * num3;
				Z += (z - Z) * num3;
				float num4 = 1f - (float)Math.Exp((0f - dt) * 9f);
				vx += (num / dt - vx) * num4;
				vz += (num2 / dt - vz) * num4;
				Speed = (float)Math.Sqrt(vx * vx + vz * vz);
				if (Speed > 0.18f)
				{
					Walking = true;
					stoppedTime = 0f;
				}
				else if (Speed < 0.08f)
				{
					stoppedTime += dt;
					if (stoppedTime > 0.2f)
					{
						Walking = false;
					}
				}
				else
				{
					stoppedTime = 0f;
				}
				if (holdFacing)
				{
					return;
				}
				float num5 = (useSteering ? steeringX : vx);
				float num6 = (useSteering ? steeringZ : vz);
				float num7 = x - faceX;
				float num8 = z - faceZ;
				if (num5 * num5 + num6 * num6 > 0.0324f && (useSteering || num7 * num7 + num8 * num8 >= 0.01f))
				{
					float num9 = (float)(Math.Atan2(num5, num6) * 180.0 / Math.PI);
					float value = (num9 - pendingYaw + 540f) % 360f - 180f;
					if (!hasPending || Math.Abs(value) > 25f)
					{
						pendingTime = 0f;
						hasPending = true;
					}
					else
					{
						pendingTime += dt;
					}
					pendingYaw = num9;
					if (pendingTime >= 0.14f)
					{
						acceptedYaw = num9;
						faceX = x;
						faceZ = z;
					}
				}
				else
				{
					hasPending = false;
					pendingTime = 0f;
				}
				float val = ((acceptedYaw - Yaw + 540f) % 360f - 180f) * (1f - (float)Math.Exp((0f - dt) * 10f));
				float num10 = 240f * dt;
				Yaw = (Yaw + Math.Max(0f - num10, Math.Min(num10, val))) % 360f;
				if (Yaw < 0f)
				{
					Yaw += 360f;
				}
			}
		}
	}
	internal sealed class PlayerFreeze : MonoBehaviour
	{
		private PlayerController controller;

		private Rigidbody body;

		private RigidbodyConstraints saved;

		private Vector3 anchor;

		private float until;

		private bool holding;

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

		private readonly List<int> expired = new List<int>();

		internal void Begin(PlayerController player, float duration, int owner)
		{
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			controller = player;
			if (!holding)
			{
				body = player.rb;
				if (!Object.op_Implicit((Object)(object)body))
				{
					return;
				}
				saved = body.constraints;
				anchor = body.position;
				holding = true;
			}
			leases[owner] = Time.time + duration;
			until = Mathf.Max(until, leases[owner]);
			body.linearVelocity = Vector3.zero;
			Rigidbody obj = body;
			obj.constraints = (RigidbodyConstraints)(obj.constraints | 0xE);
		}

		private void Update()
		{
			if (!holding)
			{
				return;
			}
			expired.Clear();
			foreach (KeyValuePair<int, float> lease in leases)
			{
				if (lease.Value <= Time.time)
				{
					expired.Add(lease.Key);
				}
			}
			foreach (int item in expired)
			{
				leases.Remove(item);
			}
			if (!Object.op_Implicit((Object)(object)controller) || !Object.op_Implicit((Object)(object)body) || !((Behaviour)controller).isActiveAndEnabled)
			{
				Release();
			}
			else if (Time.time >= until)
			{
				Release();
			}
			else
			{
				controller.OverrideSpeed(0f, 0.1f, 0f);
			}
		}

		internal void ReleaseOwner(int owner)
		{
			leases.Remove(owner);
			if (leases.Count == 0)
			{
				Release();
				return;
			}
			until = 0f;
			foreach (KeyValuePair<int, float> lease in leases)
			{
				until = Mathf.Max(until, lease.Value);
			}
		}

		private void FixedUpdate()
		{
			//IL_0031: 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)
			if (holding && Object.op_Implicit((Object)(object)body))
			{
				if (Time.time >= until)
				{
					Release();
					return;
				}
				body.position = anchor;
				body.linearVelocity = Vector3.zero;
			}
		}

		internal void Release()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: 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)
			if (holding && Object.op_Implicit((Object)(object)body))
			{
				body.constraints = (RigidbodyConstraints)((body.constraints & -15) | (saved & 0xE));
			}
			holding = false;
			until = 0f;
			leases.Clear();
		}

		private void OnDisable()
		{
			Release();
		}

		private void OnDestroy()
		{
			Release();
		}
	}
	[BepInPlugin("local.ellie.headman", "Jenny Headman Replacement", "0.8.0")]
	public sealed class Plugin : BaseUnityPlugin
	{
		internal static Plugin Instance;

		internal CharacterAsset Asset;

		internal ConfigEntry<float> Height;

		internal ConfigEntry<float> VerticalOffset;

		internal ConfigEntry<float> Yaw;

		internal ConfigEntry<bool> Enabled;

		internal ConfigEntry<bool> FreezeAttack;

		internal ConfigEntry<float> FreezeSeconds;

		internal ConfigEntry<float> ThrowSpeed;

		internal ConfigEntry<float> ThrowLift;

		internal ConfigEntry<float> RetargetRadius;

		internal ConfigEntry<float> TumbleSeconds;

		internal ConfigEntry<bool> JigglePhysics;

		internal ConfigEntry<float> JiggleStrength;

		internal ConfigEntry<float> JiggleDamping;

		internal ConfigEntry<float> ChestStrength;

		internal ConfigEntry<float> ChestDamping;

		internal ConfigEntry<bool> ChestSquish;

		internal ConfigEntry<bool> CustomVoiceEnabled;

		internal ConfigEntry<float> VoiceVolume;

		internal ConfigEntry<float> CustomVoiceGain;

		internal ConfigEntry<float> VoiceStartSeconds;

		internal AudioClip VoiceClip;

		internal ConfigEntry<bool> GrabImprint;

		internal ConfigEntry<float> ImprintDepth;

		internal ConfigEntry<float> ImprintRadius;

		private const byte CaptureEventCode = 181;

		private const string CaptureMessage = "local.ellie.headman.capture.v2";

		private const string FinishMessage = "local.ellie.headman.finish.v2";

		private static int nextCaptureToken;

		private Harmony harmony;

		private void Awake()
		{
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Expected O, but got Unknown
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Expected O, but got Unknown
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Expected O, but got Unknown
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Expected O, but got Unknown
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Expected O, but got Unknown
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Expected O, but got Unknown
			//IL_0256: Unknown result type (might be due to invalid IL or missing references)
			//IL_0260: Expected O, but got Unknown
			//IL_0294: Unknown result type (might be due to invalid IL or missing references)
			//IL_029e: Expected O, but got Unknown
			//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dc: Expected O, but got Unknown
			//IL_0310: Unknown result type (might be due to invalid IL or missing references)
			//IL_031a: Expected O, but got Unknown
			//IL_0390: Unknown result type (might be due to invalid IL or missing references)
			//IL_039a: Expected O, but got Unknown
			//IL_03ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d8: Expected O, but got Unknown
			//IL_040c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0416: Expected O, but got Unknown
			//IL_046b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0475: Expected O, but got Unknown
			//IL_04a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b3: Expected O, but got Unknown
			//IL_0511: Unknown result type (might be due to invalid IL or missing references)
			//IL_051b: Expected O, but got Unknown
			//IL_0556: Unknown result type (might be due to invalid IL or missing references)
			//IL_055b: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Appearance", "Enabled", true, "Replace Headman's visible model.");
			Height = ((BaseUnityPlugin)this).Config.Bind<float>("Appearance", "Height", 2.2f, new ConfigDescription("Character height in meters.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 5f), Array.Empty<object>()));
			VerticalOffset = ((BaseUnityPlugin)this).Config.Bind<float>("Appearance", "VerticalOffset", 0f, "Additional vertical offset in meters.");
			Yaw = ((BaseUnityPlugin)this).Config.Bind<float>("Appearance", "Yaw", 0f, "Additional yaw relative to travel direction, in degrees.");
			FreezeAttack = ((BaseUnityPlugin)this).Config.Bind<bool>("Combat", "FreezeAndCrouch", true, "Replace the player bite with a brief immobilization and crouch sequence.");
			FreezeSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("Combat", "FreezeSeconds", 2f, new ConfigDescription("Immobilization and crouch duration.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 8f), Array.Empty<object>()));
			ThrowSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Combat", "ThrowSpeed", 24f, new ConfigDescription("Horizontal launch speed of the tumble body at release.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 40f), Array.Empty<object>()));
			ThrowLift = ((BaseUnityPlugin)this).Config.Bind<float>("Combat", "ThrowLift", 8f, new ConfigDescription("Upward launch speed of the tumble body at release.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 15f), Array.Empty<object>()));
			TumbleSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("Combat", "TumbleSeconds", 3f, new ConfigDescription("Minimum time in ball/tumble form after launch.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 8f), Array.Empty<object>()));
			RetargetRadius = ((BaseUnityPlugin)this).Config.Bind<float>("Combat", "RetargetRadius", 12f, new ConfigDescription("Search radius for another player after throwing the victim.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(2f, 30f), Array.Empty<object>()));
			JigglePhysics = ((BaseUnityPlugin)this).Config.Bind<bool>("Physics", "Enabled", true, "Enable damped motion on weighted hair, accessory, and soft body bones.");
			JiggleStrength = ((BaseUnityPlugin)this).Config.Bind<float>("Physics", "Strength", 1f, new ConfigDescription("Secondary-motion response to movement and impacts.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 2f), Array.Empty<object>()));
			JiggleDamping = ((BaseUnityPlugin)this).Config.Bind<float>("Physics", "Damping", 0.75f, new ConfigDescription("Higher values reduce oscillation more quickly.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.3f, 2f), Array.Empty<object>()));
			ChestStrength = ((BaseUnityPlugin)this).Config.Bind<float>("Physics", "ChestStrength", 1f, new ConfigDescription("Chest motion multiplier, including response to footfalls.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 2f), Array.Empty<object>()));
			ChestDamping = ((BaseUnityPlugin)this).Config.Bind<float>("Physics", "ChestDamping", 0.65f, new ConfigDescription("Chest-specific damping, independent of the general damping setting.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.3f, 2f), Array.Empty<object>()));
			ChestSquish = ((BaseUnityPlugin)this).Config.Bind<bool>("Physics", "ChestSquish", true, "Enable limited, volume-preserving chest compression and rebound.");
			CustomVoiceEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Voice", "Enabled", true, "Replace Headman voice cues with bundled custom_voice.mp3.");
			VoiceVolume = ((BaseUnityPlugin)this).Config.Bind<float>("Voice", "Volume", 1f, new ConfigDescription("Custom voice playback volume.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			CustomVoiceGain = ((BaseUnityPlugin)this).Config.Bind<float>("Voice", "Gain", 8f, new ConfigDescription("Amplification for the quiet recording; a soft limiter prevents clipping.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 16f), Array.Empty<object>()));
			VoiceStartSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("Voice", "StartSeconds", 2f, new ConfigDescription("Skip the nearly silent opening when starting the custom recording.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 300f), Array.Empty<object>()));
			GrabImprint = ((BaseUnityPlugin)this).Config.Bind<bool>("Physics", "GrabImprint", true, "Show a temporary pressure indentation on the chest while grabbed.");
			ImprintDepth = ((BaseUnityPlugin)this).Config.Bind<float>("Physics", "ImprintDepth", 0.025f, new ConfigDescription("Maximum local grab indentation depth.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.005f, 0.08f), Array.Empty<object>()));
			ImprintRadius = ((BaseUnityPlugin)this).Config.Bind<float>("Physics", "ImprintRadius", 0.14f, new ConfigDescription("Radius of the pressure indentation.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.05f, 0.3f), Array.Empty<object>()));
			try
			{
				Asset = CharacterAsset.Load(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location));
				if (!Asset.Clips.ContainsKey("Crouch"))
				{
					throw new InvalidDataException("Crouch clip missing; install the matching model asset.");
				}
				PhotonNetwork.NetworkingClient.EventReceived += OnNetworkEvent;
				harmony = new Harmony("local.ellie.headman");
				harmony.PatchAll(typeof(Plugin).Assembly);
				((MonoBehaviour)this).StartCoroutine(LoadVoice());
				EnemyHeadController[] array = Resources.FindObjectsOfTypeAll<EnemyHeadController>();
				foreach (EnemyHeadController val in array)
				{
					Scene scene = ((Component)val).gameObject.scene;
					if (((Scene)(ref scene)).IsValid())
					{
						Attach(val);
					}
				}
				((BaseUnityPlugin)this).Logger.LogInfo((object)("Loaded Jenny: " + Asset.Parts.Length + " joints and five clips. Freeze-and-crouch player attack enabled=" + FreezeAttack.Value));
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Replacement could not load; original Headman retained. " + ex));
			}
		}

		internal static void Attach(EnemyHeadController controller)
		{
			if (!Object.op_Implicit((Object)(object)((Component)controller).GetComponent<Replacement>()))
			{
				((Component)controller).gameObject.AddComponent<Replacement>();
			}
		}

		internal void Report(Exception error)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)error);
		}

		internal void ReportReady(string message)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)message);
		}

		private IEnumerator LoadVoice()
		{
			string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "custom_voice.mp3");
			if (!File.Exists(text))
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)"Bundled MP3 missing; native voices retained.");
				yield break;
			}
			UnityWebRequest request = UnityWebRequestMultimedia.GetAudioClip(new Uri(text).AbsoluteUri, (AudioType)13);
			try
			{
				((DownloadHandlerAudioClip)request.downloadHandler).streamAudio = true;
				yield return request.SendWebRequest();
				if ((int)request.result != 1)
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)("Custom MP3 could not load; native voices retained: " + request.error));
					yield break;
				}
				VoiceClip = DownloadHandlerAudioClip.GetContent(request);
				if (Object.op_Implicit((Object)(object)VoiceClip))
				{
					((Object)VoiceClip).name = "JennyCustomVoice";
					((BaseUnityPlugin)this).Logger.LogInfo((object)("Bundled custom MP3 loaded (" + VoiceClip.length.ToString("F1") + " seconds)."));
				}
			}
			finally
			{
				((IDisposable)request)?.Dispose();
			}
		}

		internal static void BroadcastCapture(Replacement replacement, PlayerAvatar target, float seconds)
		{
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Expected O, but got Unknown
			if (++nextCaptureToken <= 0)
			{
				nextCaptureToken = 1;
			}
			if (!SemiFunc.IsMasterClientOrSingleplayer() || !replacement.BeginCapture(target, seconds, nextCaptureToken))
			{
				return;
			}
			replacement.DealCaptureDamage(target);
			if (PhotonNetwork.InRoom)
			{
				PhotonView animationView = replacement.GetAnimationView();
				if (Object.op_Implicit((Object)(object)animationView) && Object.op_Implicit((Object)(object)target.photonView))
				{
					PhotonNetwork.RaiseEvent((byte)181, (object)new object[5]
					{
						"local.ellie.headman.capture.v2",
						animationView.ViewID,
						target.photonView.ViewID,
						seconds,
						nextCaptureToken
					}, new RaiseEventOptions
					{
						Receivers = (ReceiverGroup)0
					}, SendOptions.SendReliable);
				}
			}
		}

		internal static void BroadcastFinish(Replacement replacement, PlayerAvatar target, int token, Vector3 velocity)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: 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_00a3: 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_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Expected O, but got Unknown
			if (SemiFunc.IsMasterClientOrSingleplayer() && replacement.FinishCapture(target, token, velocity))
			{
				replacement.ThrowAsBall(target, velocity);
				PhotonView animationView = replacement.GetAnimationView();
				if (PhotonNetwork.InRoom && Object.op_Implicit((Object)(object)animationView) && Object.op_Implicit((Object)(object)target) && Object.op_Implicit((Object)(object)target.photonView))
				{
					PhotonNetwork.RaiseEvent((byte)181, (object)new object[7]
					{
						"local.ellie.headman.finish.v2",
						animationView.ViewID,
						target.photonView.ViewID,
						token,
						velocity.x,
						velocity.y,
						velocity.z
					}, new RaiseEventOptions
					{
						Receivers = (ReceiverGroup)0
					}, SendOptions.SendReliable);
				}
			}
		}

		private static bool Finite(float value)
		{
			if (!float.IsNaN(value))
			{
				return !float.IsInfinity(value);
			}
			return false;
		}

		private void OnNetworkEvent(EventData message)
		{
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			if (message.Code == 181 && PhotonNetwork.InRoom && PhotonNetwork.MasterClient != null && message.Sender == PhotonNetwork.MasterClient.ActorNumber && message.CustomData is object[] array && array.Length >= 4 && array[0] is string text && array[1] is int enemyId && array[2] is int playerId)
			{
				if (text == "local.ellie.headman.capture.v2" && array.Length == 5 && array[3] is float num && Finite(num) && array[4] is int num2 && num2 > 0)
				{
					Replacement.ReceiveCapture(enemyId, playerId, Mathf.Clamp(num, 0.5f, 8f), num2);
				}
				else if (text == "local.ellie.headman.finish.v2" && array.Length == 7 && array[3] is int num3 && num3 > 0 && array[4] is float num4 && array[5] is float num5 && array[6] is float num6 && Finite(num4) && Finite(num5) && Finite(num6) && num4 * num4 + num6 * num6 <= 1601f && num5 >= 0f && num5 <= 15f)
				{
					Replacement.ReceiveFinish(enemyId, playerId, num3, new Vector3(num4, num5, num6));
				}
			}
		}

		private void OnDestroy()
		{
			Harmony obj = harmony;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
			PhotonNetwork.NetworkingClient.EventReceived -= OnNetworkEvent;
			PlayerFreeze[] array = Resources.FindObjectsOfTypeAll<PlayerFreeze>();
			for (int i = 0; i < array.Length; i++)
			{
				array[i].Release();
			}
			Replacement[] array2 = Resources.FindObjectsOfTypeAll<Replacement>();
			for (int i = 0; i < array2.Length; i++)
			{
				array2[i].Cleanup();
			}
			HeadmanVoice[] array3 = Resources.FindObjectsOfTypeAll<HeadmanVoice>();
			for (int i = 0; i < array3.Length; i++)
			{
				array3[i].Stop();
			}
			if (Object.op_Implicit((Object)(object)VoiceClip))
			{
				Object.Destroy((Object)(object)VoiceClip);
			}
			Asset?.Dispose();
			Instance = null;
		}
	}
	[HarmonyPatch(typeof(EnemyHeadController), "Awake")]
	internal static class AttachPatch
	{
		private static void Postfix(EnemyHeadController __instance)
		{
			Plugin.Attach(__instance);
		}
	}
	[HarmonyPatch]
	internal static class AttackEventPatch
	{
		private static IEnumerable<MethodBase> TargetMethods()
		{
			string[] array = new string[4] { "PlayChaseBiteStart", "PlayBiteStart", "PlayChaseBiteImpact", "IdleBiteImpact" };
			foreach (string text in array)
			{
				yield return AccessTools.Method(typeof(EnemyHeadAnimationSystem), text, (Type[])null, (Type[])null);
			}
		}

		private static void Postfix(EnemyHeadAnimationSystem __instance, MethodBase __originalMethod)
		{
			Replacement.AttackEvent(__instance, __originalMethod.Name);
		}
	}
	[HarmonyPatch(typeof(EnemyHeadAnimationSystem), "ChaseBiteTrigger")]
	internal static class FreezeAttackPatch
	{
		private static bool Prefix(EnemyHeadAnimationSystem __instance)
		{
			return Replacement.AllowNativeBite(__instance);
		}
	}
	[HarmonyPatch(typeof(EnemyHeadController), "VisionTriggered")]
	internal static class RetargetVisionPatch
	{
		private static bool Prefix(EnemyHeadController __instance)
		{
			Replacement component = ((Component)__instance).GetComponent<Replacement>();
			if (Object.op_Implicit((Object)(object)component))
			{
				return component.AllowVisionTarget();
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Enemy), "SetChaseTarget")]
	internal static class RetargetChasePatch
	{
		private static bool Prefix(Enemy __instance, PlayerAvatar playerAvatar)
		{
			return Replacement.AllowChaseTarget(__instance, playerAvatar);
		}
	}
	[DefaultExecutionOrder(10000)]
	public sealed class Replacement : MonoBehaviour
	{
		private EnemyHeadController controller;

		private Enemy enemy;

		private Transform model;

		private Transform[] joints;

		private Matrix4x4[] skinMatrices;

		private SecondaryMotion secondaryMotion;

		private GrabIndentation grabIndentation;

		private bool headingInitialized;

		private Renderer[] originals;

		private readonly Dictionary<Renderer, bool> originalForceOff = new Dictionary<Renderer, bool>();

		private readonly Dictionary<Animator, AnimatorCullingMode> originalCulling = new Dictionary<Animator, AnimatorCullingMode>();

		private readonly Dictionary<SkinnedMeshRenderer, bool> originalOffscreen = new Dictionary<SkinnedMeshRenderer, bool>();

		private static readonly Dictionary<EnemyHeadAnimationSystem, Replacement> instances = new Dictionary<EnemyHeadAnimationSystem, Replacement>();

		private readonly AttackPlayback attackPlayback = new AttackPlayback();

		private Material material;

		private CharacterAsset asset;

		private readonly MotionTracker motion = new MotionTracker();

		private readonly RaycastHit[] floorHits = (RaycastHit[])(object)new RaycastHit[32];

		private readonly List<Renderer> feet = new List<Renderer>();

		private Transform movementSource;

		private Transform owningRoot;

		private NavMeshAgent navigation;

		private float floorY;

		private int floorMask;

		private bool floorKnown;

		private bool tracking;

		private string current = "";

		private float clipTime;

		private bool ready;

		private float nextDiagnostic;

		private EnemyTriggerAttack nativeAttackTrigger;

		private EnemyVision nativeVision;

		private float nextContactDiagnostic;

		private readonly CaptureTimer capture = new CaptureTimer();

		private PlayerAvatar capturedPlayer;

		private Vector3 capturePosition;

		private float captureYaw;

		private PlayerAvatar lastContactPlayer;

		private float lastContactAt;

		private int captureToken;

		private int capturedViewId;

		private bool throwApplied;

		private PlayerAvatar previousVictim;

		private float ignoreVictimUntil;

		private float tossPoseUntil;

		private static readonly FieldInfo DisabledField = AccessTools.Field(typeof(PlayerAvatar), "isDisabled");

		private static readonly FieldInfo DeadField = AccessTools.Field(typeof(PlayerAvatar), "deadSet");

		private static readonly FieldInfo SteamField = AccessTools.Field(typeof(PlayerAvatar), "steamID");

		private static readonly FieldInfo PlayersField = AccessTools.Field(typeof(GameDirector), "PlayerList");

		private static readonly FieldInfo NoVisionField = AccessTools.Field(typeof(EnemyDirector), "debugNoVision");

		private static readonly FieldInfo VisionPlayerField = AccessTools.Field(typeof(EnemyVision), "onVisionTriggeredPlayer");

		private static bool Alive(PlayerAvatar player)
		{
			if (Object.op_Implicit((Object)(object)player) && ((Component)player).gameObject.activeInHierarchy && !(bool)(DisabledField?.GetValue(player) ?? ((object)false)))
			{
				return !(bool)(DeadField?.GetValue(player) ?? ((object)false));
			}
			return false;
		}

		private bool Ignored(PlayerAvatar player)
		{
			if (Object.op_Implicit((Object)(object)player) && (Object)(object)player == (Object)(object)previousVictim && Time.time < ignoreVictimUntil && Object.op_Implicit((Object)(object)Plugin.Instance) && Plugin.Instance.Enabled.Value)
			{
				return Plugin.Instance.FreezeAttack.Value;
			}
			return false;
		}

		internal bool AllowVisionTarget()
		{
			if (Object.op_Implicit((Object)(object)nativeVision))
			{
				object? obj = VisionPlayerField?.GetValue(nativeVision);
				return !Ignored((PlayerAvatar)((obj is PlayerAvatar) ? obj : null));
			}
			return true;
		}

		internal static bool AllowChaseTarget(Enemy source, PlayerAvatar player)
		{
			foreach (Replacement value in instances.Values)
			{
				if (Object.op_Implicit((Object)(object)value) && (Object)(object)value.enemy == (Object)(object)source)
				{
					return !value.Ignored(player);
				}
			}
			return true;
		}

		internal PhotonView GetAnimationView()
		{
			return ((Component)controller.AnimationSystem).GetComponent<PhotonView>();
		}

		internal static void ReceiveCapture(int enemyId, int playerId, float duration, int token)
		{
			PhotonView val = PhotonView.Find(playerId);
			PlayerAvatar val2 = (Object.op_Implicit((Object)(object)val) ? ((Component)val).GetComponent<PlayerAvatar>() : null);
			if (!Object.op_Implicit((Object)(object)val2))
			{
				return;
			}
			foreach (Replacement value in instances.Values)
			{
				if (Object.op_Implicit((Object)(object)value) && value.ready && Object.op_Implicit((Object)(object)value.GetAnimationView()) && value.GetAnimationView().ViewID == enemyId)
				{
					value.BeginCapture(val2, duration, token);
					break;
				}
			}
		}

		internal static void ReceiveFinish(int enemyId, int playerId, int token, Vector3 velocity)
		{
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			PhotonView val = PhotonView.Find(playerId);
			PlayerAvatar val2 = (Object.op_Implicit((Object)(object)val) ? ((Component)val).GetComponent<PlayerAvatar>() : null);
			if (!Object.op_Implicit((Object)(object)val2))
			{
				return;
			}
			foreach (Replacement value in instances.Values)
			{
				if (Object.op_Implicit((Object)(object)value) && value.ready && ((Behaviour)value).isActiveAndEnabled && Object.op_Implicit((Object)(object)value.GetAnimationView()) && value.GetAnimationView().ViewID == enemyId)
				{
					value.FinishCapture(val2, token, velocity);
					break;
				}
			}
		}

		internal static bool AllowNativeBite(EnemyHeadAnimationSystem system)
		{
			//IL_0138: 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_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_014e: 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_015a: 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)
			if (!instances.TryGetValue(system, out var value) || !Object.op_Implicit((Object)(object)value) || !value.ready || !Object.op_Implicit((Object)(object)Plugin.Instance) || !Plugin.Instance.Enabled.Value || !Plugin.Instance.FreezeAttack.Value)
			{
				return true;
			}
			if (Object.op_Implicit((Object)(object)value.nativeAttackTrigger))
			{
				AccessTools.Field(typeof(EnemyTriggerAttack), "Attack")?.SetValue(value.nativeAttackTrigger, false);
			}
			if (!SemiFunc.IsMasterClientOrSingleplayer())
			{
				return false;
			}
			if (value.capture.Active)
			{
				return false;
			}
			PlayerAvatar val = (PlayerAvatar)((Object.op_Implicit((Object)(object)value.lastContactPlayer) && Time.time - value.lastContactAt < 0.5f) ? ((object)value.lastContactPlayer) : ((object)/*isinst with value type is only supported in some contexts*/));
			if (!Alive(val) || value.Ignored(val) || !value.capture.Available || value.enemy.IsStunned() || value.enemy.FreezeTimer > 0f)
			{
				return false;
			}
			Vector3 val2 = ((Component)val).transform.position - value.model.position;
			Vector2 val3 = new Vector2(val2.x, val2.z);
			if (((Vector2)(ref val3)).sqrMagnitude > 9f)
			{
				return false;
			}
			Plugin.BroadcastCapture(value, val, Plugin.Instance.FreezeSeconds.Value);
			return false;
		}

		internal void DealCaptureDamage(PlayerAvatar target)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			if (SemiFunc.IsMasterClientOrSingleplayer() && Object.op_Implicit((Object)(object)target) && Object.op_Implicit((Object)(object)target.playerHealth) && capture.TryConsumeDamage())
			{
				target.playerHealth.HurtOther(90, ((Component)target).transform.position, false, SemiFunc.EnemyGetIndex(enemy), false);
				Plugin.Instance?.ReportReady("Jenny capture attack: one 90-damage hit submitted through native player health.");
			}
		}

		internal bool BeginCapture(PlayerAvatar target, float duration, int token)
		{
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: 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_00c5: 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_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: 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_0111: 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_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: 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_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_014f: 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_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)
			if (!ready || !Object.op_Implicit((Object)(object)target) || !capture.Begin(duration))
			{
				return false;
			}
			capturedPlayer = target;
			captureToken = token;
			capturedViewId = (Object.op_Implicit((Object)(object)target.photonView) ? target.photonView.ViewID : 0);
			throwApplied = false;
			Vector3 val = (Object.op_Implicit((Object)(object)target.localCamera) ? ((Component)target.localCamera).transform.forward : ((Component)target).transform.forward);
			val.y = 0f;
			if (((Vector3)(ref val)).sqrMagnitude < 0.01f)
			{
				val = ((Component)target).transform.forward;
			}
			val.y = 0f;
			((Vector3)(ref val)).Normalize();
			Vector3 val2 = ((Component)target).transform.position + val * 1.15f;
			if (Physics.Linecast(((Component)target).transform.position + Vector3.up, val2 + Vector3.up, floorMask, (QueryTriggerInteraction)1))
			{
				val2 = model.position;
			}
			capturePosition = new Vector3(val2.x, model.position.y, val2.z);
			Vector3 val3 = ((Component)target).transform.position - capturePosition;
			captureYaw = Mathf.Atan2(val3.x, val3.z) * 57.29578f;
			PlayerController instance = PlayerController.instance;
			if (Object.op_Implicit((Object)(object)instance) && (Object)(object)instance.playerAvatarScript == (Object)(object)target)
			{
				(((Component)instance).GetComponent<PlayerFreeze>() ?? ((Component)instance).gameObject.AddComponent<PlayerFreeze>()).Begin(instance, duration, ((Object)this).GetInstanceID());
			}
			if (SemiFunc.IsMasterClientOrSingleplayer())
			{
				enemy.Freeze(duration);
			}
			Plugin.Instance?.ReportReady("Jenny freeze-and-crouch started for " + duration + " seconds.");
			return true;
		}

		internal unsafe bool FinishCapture(PlayerAvatar target, int token, Vector3 velocity)
		{
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			if (token != captureToken || throwApplied || !Object.op_Implicit((Object)(object)target) || (Object.op_Implicit((Object)(object)target.photonView) && target.photonView.ViewID != capturedViewId))
			{
				return false;
			}
			throwApplied = true;
			capture.Cancel();
			if (Alive(target))
			{
				tossPoseUntil = Time.time + 0.4f;
			}
			if (Object.op_Implicit((Object)(object)model))
			{
				motion.Reset(model.position.x, model.position.z, model.eulerAngles.y - Plugin.Instance.Yaw.Value);
			}
			ReleaseCapturedPlayer();
			Plugin.Instance?.ReportReady("Jenny released capture " + token + " with throw impulse " + ((object)(*(Vector3*)(&velocity))/*cast due to .constrained prefix*/).ToString());
			return true;
		}

		internal unsafe void ThrowAsBall(PlayerAvatar target, Vector3 velocity)
		{
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			if (SemiFunc.IsMasterClientOrSingleplayer() && Alive(target))
			{
				object? obj = AccessTools.Field(typeof(PlayerAvatar), "tumble")?.GetValue(target);
				PlayerTumble val = (PlayerTumble)((obj is PlayerTumble) ? obj : null);
				if (!Object.op_Implicit((Object)(object)val))
				{
					val = ((Component)target).GetComponentInChildren<PlayerTumble>(true);
				}
				if (!Object.op_Implicit((Object)(object)val))
				{
					Plugin.Instance?.ReportReady("Jenny ball launch skipped: native PlayerTumble was not found.");
					return;
				}
				val.TumbleOverrideTime(Plugin.Instance.TumbleSeconds.Value);
				val.TumbleStunTime(Plugin.Instance.TumbleSeconds.Value);
				val.TumbleSet(true, false, false);
				object? obj2 = AccessTools.Field(typeof(PlayerTumble), "rb")?.GetValue(val);
				Rigidbody val2 = (Rigidbody)((obj2 is Rigidbody) ? obj2 : null);
				val.TumbleForce(velocity * (Object.op_Implicit((Object)(object)val2) ? val2.mass : 1f));
				Plugin.Instance?.ReportReady("Jenny launched the player in ball form with target velocity " + ((object)(*(Vector3*)(&velocity))/*cast due to .constrained prefix*/).ToString());
			}
		}

		private void CompleteCapture()
		{
			//IL_0018: 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_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: 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_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			PlayerAvatar val = capturedPlayer;
			if (Object.op_Implicit((Object)(object)val))
			{
				Vector3 val2 = ((Component)val).transform.position - model.position;
				val2.y = 0f;
				if (((Vector3)(ref val2)).sqrMagnitude < 0.01f)
				{
					val2 = model.forward;
					val2.y = 0f;
				}
				((Vector3)(ref val2)).Normalize();
				Vector3 velocity = val2 * Plugin.Instance.ThrowSpeed.Value + Vector3.up * Plugin.Instance.ThrowLift.Value;
				Plugin.BroadcastFinish(this, val, captureToken, velocity);
			}
			RetargetAfter(val);
		}

		private void RetargetAfter(PlayerAvatar victim)
		{
			//IL_0252: 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_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_00e5: 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_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Expected O, but got Unknown
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			previousVictim = victim;
			ignoreVictimUntil = Time.time + 8f;
			lastContactPlayer = null;
			IEnumerable<PlayerAvatar> enumerable = (Object.op_Implicit((Object)(object)GameDirector.instance) ? (PlayersField?.GetValue(GameDirector.instance) as IEnumerable<PlayerAvatar>) : null);
			ICollection<string> collection = (Object.op_Implicit((Object)(object)EnemyDirector.instance) ? (NoVisionField?.GetValue(EnemyDirector.instance) as ICollection<string>) : null);
			PlayerAvatar val = null;
			float bestSquaredDistance = float.PositiveInfinity;
			if (enumerable != null)
			{
				foreach (PlayerAvatar item in enumerable)
				{
					if (!Alive(item))
					{
						continue;
					}
					bool num = collection?.Contains(SteamField?.GetValue(item) as string) ?? false;
					Vector3 val3 = ((Component)item).transform.position - model.position;
					float sqrMagnitude = ((Vector3)(ref val3)).sqrMagnitude;
					if (!TargetChoice.Better(!num, (Object)(object)item == (Object)(object)victim, sqrMagnitude, Plugin.Instance.RetargetRadius.Value, bestSquaredDistance))
					{
						continue;
					}
					Vector3 val4 = ((Component)enemy).transform.position + Vector3.up;
					Vector3 val5 = ((Component)item).transform.position + Vector3.up;
					if (Physics.Linecast(val4, val5, floorMask, (QueryTriggerInteraction)1))
					{
						continue;
					}
					if (Object.op_Implicit((Object)(object)navigation) && ((Behaviour)navigation).isActiveAndEnabled && navigation.isOnNavMesh)
					{
						NavMeshPath val6 = new NavMeshPath();
						if (!navigation.CalculatePath(((Component)item).transform.position, val6) || (int)val6.status != 0)
						{
							continue;
						}
					}
					val = item;
					bestSquaredDistance = sqrMagnitude;
				}
			}
			if (Object.op_Implicit((Object)(object)val))
			{
				enemy.SetChaseTarget(val);
				enemy.SetChaseTimer();
				Plugin.Instance.ReportReady("Jenny switched pursuit to another nearby player after throwing the previous victim.");
			}
			else
			{
				AccessTools.Field(typeof(Enemy), "TargetPlayerAvatar")?.SetValue(enemy, null);
				AccessTools.Field(typeof(Enemy), "TargetPlayerViewID")?.SetValue(enemy, -1);
				enemy.CurrentState = (EnemyState)2;
				Plugin.Instance.ReportReady("Jenny found no other eligible nearby player; returning to roaming.");
			}
		}

		private void ReleaseCapturedPlayer()
		{
			PlayerController instance = PlayerController.instance;
			if (Object.op_Implicit((Object)(object)instance) && Object.op_Implicit((Object)(object)capturedPlayer) && (Object)(object)instance.playerAvatarScript == (Object)(object)capturedPlayer)
			{
				((Component)instance).GetComponent<PlayerFreeze>()?.ReleaseOwner(((Object)this).GetInstanceID());
			}
			capturedPlayer = null;
		}

		internal static void AttackEvent(EnemyHeadAnimationSystem system, string name)
		{
			if (instances.TryGetValue(system, out var value) && Object.op_Implicit((Object)(object)value) && value.ready)
			{
				if (name.EndsWith("Start") && value.current != "Attack")
				{
					value.attackPlayback.Signal();
				}
				Plugin.Instance?.ReportReady("Headman combat event: " + name);
			}
		}

		private void PreserveAnimatorUpdates(bool replacing)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			foreach (KeyValuePair<Animator, AnimatorCullingMode> item in originalCulling)
			{
				if (Object.op_Implicit((Object)(object)item.Key))
				{
					item.Key.cullingMode = (AnimatorCullingMode)((!replacing) ? ((int)item.Value) : 0);
				}
			}
			foreach (KeyValuePair<SkinnedMeshRenderer, bool> item2 in originalOffscreen)
			{
				if (Object.op_Implicit((Object)(object)item2.Key))
				{
					item2.Key.updateWhenOffscreen = replacing || item2.Value;
				}
			}
		}

		private void Start()
		{
			//IL_0341: 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_0462: Unknown result type (might be due to invalid IL or missing references)
			//IL_046c: Expected O, but got Unknown
			//IL_0490: Unknown result type (might be due to invalid IL or missing references)
			//IL_049a: Expected O, but got Unknown
			//IL_053d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0564: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0661: Unknown result type (might be due to invalid IL or missing references)
			//IL_0668: Expected O, but got Unknown
			//IL_074f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0754: Unknown result type (might be due to invalid IL or missing references)
			//IL_07d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_07e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_07e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_099b: Unknown result type (might be due to invalid IL or missing references)
			//IL_09a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_09b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_09c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_09d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_09f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a0f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0aae: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ab3: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Plugin instance = Plugin.Instance;
				if (!Object.op_Implicit((Object)(object)instance) || instance.Asset == null)
				{
					((Behaviour)this).enabled = false;
					return;
				}
				asset = instance.Asset;
				controller = ((Component)this).GetComponent<EnemyHeadController>();
				enemy = ((Component)controller).GetComponentInParent<Enemy>();
				nativeVision = (EnemyVision)(Object.op_Implicit((Object)(object)enemy) ? /*isinst with value type is only supported in some contexts*/: null);
				if (!Object.op_Implicit((Object)(object)controller.Visual) || !Object.op_Implicit((Object)(object)controller.AnimationSystem))
				{
					throw new InvalidOperationException("Headman visual references are missing.");
				}
				EnemyParent componentInParent = ((Component)controller).GetComponentInParent<EnemyParent>();
				Transform val = (owningRoot = (Object.op_Implicit((Object)(object)componentInParent) ? ((Component)componentInParent).transform : (Object.op_Implicit((Object)(object)enemy) ? ((Component)enemy).transform : ((Component)controller).transform)));
				EnemyNavMeshAgent val2 = (EnemyNavMeshAgent)(Object.op_Implicit((Object)(object)enemy) ? /*isinst with value type is only supported in some contexts*/: null);
				if (Object.op_Implicit((Object)(object)val2))
				{
					ref NavMeshAgent reference = ref navigation;
					object? obj = AccessTools.Field(typeof(EnemyNavMeshAgent), "Agent")?.GetValue(val2);
					reference = (NavMeshAgent)((obj is NavMeshAgent) ? obj : null);
				}
				movementSource = (Object.op_Implicit((Object)(object)controller.Visual.FollowPosition) ? controller.Visual.FollowPosition : ((Component)enemy).transform);
				floorMask = LayerMask.GetMask(new string[1] { "Default" });
				Transform[] obj2 = new Transform[6]
				{
					val,
					((Component)controller).transform,
					((Component)controller.Visual).transform,
					controller.AnimationTransform,
					controller.HairParent,
					Object.op_Implicit((Object)(object)controller.AnimationSystem.Animator) ? ((Component)controller.AnimationSystem.Animator).transform : null
				};
				HashSet<Renderer> hashSet = new HashSet<Renderer>();
				Transform[] array = (Transform[])(object)obj2;
				Renderer[] componentsInChildren;
				foreach (Transform val3 in array)
				{
					if (!Object.op_Implicit((Object)(object)val3))
					{
						continue;
					}
					componentsInChildren = ((Component)val3).GetComponentsInChildren<Renderer>(true);
					foreach (Renderer item in componentsInChildren)
					{
						hashSet.Add(item);
					}
					Animator[] componentsInChildren2 = ((Component)val3).GetComponentsInChildren<Animator>(true);
					foreach (Animator val4 in componentsInChildren2)
					{
						if (!originalCulling.ContainsKey(val4))
						{
							originalCulling.Add(val4, val4.cullingMode);
						}
					}
				}
				if (Object.op_Implicit((Object)(object)controller.AnimationSystem.Animator) && !originalCulling.ContainsKey(controller.AnimationSystem.Animator))
				{
					originalCulling.Add(controller.AnimationSystem.Animator, controller.AnimationSystem.Animator.cullingMode);
				}
				originals = (Renderer[])(object)new Renderer[hashSet.Count];
				hashSet.CopyTo(originals);
				List<Renderer> list = new List<Renderer>();
				componentsInChildren = originals;
				foreach (Renderer val5 in componentsInChildren)
				{
					if (!(val5 is MeshRenderer) && !(val5 is SkinnedMeshRenderer))
					{
						continue;
					}
					EnemyParent componentInParent2 = ((Component)val5).GetComponentInParent<EnemyParent>();
					if ((!Object.op_Implicit((Object)(object)componentInParent) || !Object.op_Implicit((Object)(object)componentInParent2) || !((Object)(object)componentInParent2 != (Object)(object)componentInParent)) && !Object.op_Implicit((Object)(object)((Component)val5).GetComponentInParent<ReplacementGeometry>()))
					{
						list.Add(val5);
						originalForceOff.Add(val5, val5.forceRenderingOff);
						SkinnedMeshRenderer val6 = (SkinnedMeshRenderer)(object)((val5 is SkinnedMeshRenderer) ? val5 : null);
						if (val6 != null)
						{
							originalOffscreen.Add(val6, val6.updateWhenOffscreen);
						}
					}
				}
				originals = list.ToArray();
				if (originals.Length == 0)
				{
					throw new InvalidOperationException("No original Headman meshes found.");
				}
				Shader val7 = Shader.Find("Standard") ?? Shader.Find("Universal Render Pipeline/Lit");
				if (Object.op_Implicit((Object)(object)val7))
				{
					material = new Material(val7);
				}
				else
				{
					if (!Object.op_Implicit((Object)(object)originals[0].sharedMaterial))
					{
						throw new InvalidOperationException("No usable character shader found.");
					}
					material = new Material(originals[0].sharedMaterial);
				}
				((Object)material).name = "EllieArmoredMaterial";
				string[] array2 = new string[4] { "_MainTex", "_BaseMap", "_BaseColorMap", "_AlbedoTex" };
				foreach (string text in array2)
				{
					if (material.HasProperty(text))
					{
						material.SetTexture(text, (Texture)(object)asset.Texture);
					}
				}
				if (material.HasProperty("_Color"))
				{
					material.SetColor("_Color", Color.white);
				}
				if (material.HasProperty("_BaseColor"))
				{
					material.SetColor("_BaseColor", Color.white);
				}
				if (material.HasProperty("_Metallic"))
				{
					material.SetFloat("_Metallic", 0f);
				}
				if (material.HasProperty("_Glossiness"))
				{
					material.SetFloat("_Glossiness", 0.12f);
				}
				if (material.HasProperty("_Cutoff"))
				{
					material.SetFloat("_Cutoff", 0.05f);
				}
				material.EnableKeyword("_ALPHATEST_ON");
				model = new GameObject("JennyHeadmanVisual").transform;
				((Component)model).gameObject.AddComponent<ReplacementGeometry>();
				((Component)model).gameObject.SetActive(false);
				joints = (Transform[])(object)new Transform[asset.Parts.Length];
				for (int k = 0; k < joints.Length; k++)
				{
					CharacterAsset.Part part = asset.Parts[k];
					GameObject val8 = new GameObject(part.Name);
					joints[k] = val8.transform;
					joints[k].SetParent((part.Parent < 0) ? model : joints[part.Parent], false);
					joints[k].localPosition = part.Bind;
					if (asset.SkinWeights == null)
					{
						val8.AddComponent<MeshFilter>().sharedMesh = part.Mesh;
						MeshRenderer val9 = val8.AddComponent<MeshRenderer>();
						((Renderer)val9).sharedMaterial = material;
						if (part.Name == "ShinL" || part.Name == "ShinR")
						{
							feet.Add((Renderer)(object)val9);
						}
					}
				}
				if (asset.SkinWeights != null)
				{
					GameObject val10 = new GameObject("JennySkinnedGeometry");
					val10.transform.SetParent(model, false);
					SkinnedMeshRenderer val11 = val