Decompiled source of ProcedualAnimation v30.4.5

Procudeal aimation.dll

Decompiled a week ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using HarmonyLib;
using MelonLoader;
using ModThatIsNotMod.BoneMenu;
using ModThatIsNotMod.MonoBehaviours;
using Procudeal_aimation;
using PuppetMasta;
using StressLevelZero.AI;
using StressLevelZero.Props.Weapons;
using UnhollowerBaseLib;
using UnhollowerRuntimeLib;
using UnityEngine;
using UnityEngine.Audio;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(Main), "Procudeal aimation", "5.6.3", "Jeb", null)]
[assembly: MelonGame("Stress Level Zero", "BONEWORKS")]
[assembly: AssemblyTitle("Procudeal aimation")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Procudeal aimation")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e02c3ff9-db33-4862-8ec0-1d1790eb4fef")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[HarmonyPatch(typeof(PuppetMaster), "Resurrect", new Type[] { })]
public class PuppetMasterResurrectPatch
{
	[HarmonyPrefix]
	public static bool Prefix(PuppetMaster __instance)
	{
		if (!Main.modEnabled)
		{
			return true;
		}
		AIBrain componentInParent = ((Component)__instance).GetComponentInParent<AIBrain>();
		if ((Object)(object)componentInParent == (Object)null)
		{
			return true;
		}
		AgonyLogic component = ((Component)componentInParent).GetComponent<AgonyLogic>();
		if ((Object)(object)component != (Object)null && component.isSuffering)
		{
			return false;
		}
		return true;
	}
}
namespace ModThatIsNotMod.MonoBehaviours
{
	public class OriginalPuppetProperties : MonoBehaviour
	{
		public float damper;

		public float weight;

		public float animSpeed;

		public StateSettings stateSettings;

		public OriginalPuppetProperties(IntPtr ptr)
			: base(ptr)
		{
		}
	}
	public class AgonyLogic : MonoBehaviour
	{
		private AIBrain _brain;

		private BehaviourPowerLegs _legsBehaviour;

		private List<Rigidbody> _limbs = new List<Rigidbody>();

		private List<Rigidbody> _legs = new List<Rigidbody>();

		private Rigidbody _pelvis;

		private Rigidbody _chest;

		private Rigidbody _head;

		private bool _frontCalibrated = false;

		private Vector3 _chestFrontLocal = Vector3.up;

		private Transform _pelvisTransform;

		private Transform _chestTransform;

		private List<Rigidbody> _knees = new List<Rigidbody>();

		private List<Rigidbody> _feet = new List<Rigidbody>();

		private List<Rigidbody> _spineChain = new List<Rigidbody>();

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

		private Dictionary<string, Quaternion> initialPoseRots = new Dictionary<string, Quaternion>();

		public Rigidbody lastHitBone;

		public bool isSuffering = false;

		public float sufferingStartTime = 0f;

		public int mercyShotsLeft = 1;

		private bool _isSmallEnemy = false;

		private bool _isInitialized = false;

		private AudioSource _agonySource;

		private string[] legKeywords = new string[6] { "foot", "calf", "thigh", "knee", "toe", "leg" };

		private string[] armKeywords = new string[5] { "hand", "arm", "shoulder", "wrist", "elbow" };

		private string[] coreKeywords = new string[3] { "chest", "spine", "neck" };

		private string[] pelvisKeywords = new string[3] { "pelvis", "hip", "root" };

		private Vector3[] _footPrevPos = (Vector3[])(object)new Vector3[0];

		private Vector3[] _footPrevTarget = (Vector3[])(object)new Vector3[0];

		private float[] _footStuckTime = new float[0];

		private bool[] _footUnsticking = new bool[0];

		private PhysicMaterial _slipperyMaterial;

		private Dictionary<Collider, PhysicMaterial> _originalMaterials = new Dictionary<Collider, PhysicMaterial>();

		private bool _isVocal = false;

		private float _audioCooldown = 0f;

		private int _lastAudioIndex = -1;

		public AgonyLogic(IntPtr ptr)
			: base(ptr)
		{
		}//IL_001e: 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)


		private void Awake()
		{
			_brain = ((Component)this).GetComponent<AIBrain>();
		}

		public void OnEnable()
		{
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			isSuffering = false;
			_isInitialized = false;
			lastHitBone = null;
			RestoreOriginalFriction();
			PuppetMaster val = (((Object)(object)_brain != (Object)null) ? _brain.puppetMaster : null);
			if ((Object)(object)val != (Object)null)
			{
				if ((Object)(object)val.targetAnimator != (Object)null)
				{
					((Behaviour)val.targetAnimator).enabled = true;
					val.targetAnimator.speed = 1f;
				}
				OriginalPuppetProperties component = ((Component)this).GetComponent<OriginalPuppetProperties>();
				if ((Object)(object)component != (Object)null)
				{
					val.muscleDamper = component.damper;
					val.muscleWeight = component.weight;
					val.stateSettings = component.stateSettings;
				}
			}
			Il2CppArrayBase<AudioSource> componentsInChildren = ((Component)((Component)this).transform).GetComponentsInChildren<AudioSource>(true);
			foreach (AudioSource item in componentsInChildren)
			{
				if (!((Object)(object)item == (Object)null))
				{
					string text = ((Object)((Component)item).gameObject).name.ToLower();
					if (!text.Contains("ambient") && !text.Contains("music") && !text.Contains("system") && !text.Contains("master"))
					{
						item.mute = false;
						item.volume = 1f;
						((Behaviour)item).enabled = true;
					}
				}
			}
			Il2CppArrayBase<MonoBehaviour> componentsInChildren2 = ((Component)((Component)this).transform).GetComponentsInChildren<MonoBehaviour>(true);
			foreach (MonoBehaviour item2 in componentsInChildren2)
			{
				if (!((Object)(object)item2 == (Object)null))
				{
					string name = ((object)item2).GetType().Name;
					string text2 = ((object)item2).GetType().Namespace ?? "";
					if ((text2 == "ModThatIsNotMod.MonoBehaviours" || text2.Contains("SLZ")) && (name.IndexOf("sfx", StringComparison.OrdinalIgnoreCase) >= 0 || name.IndexOf("vocal", StringComparison.OrdinalIgnoreCase) >= 0 || name.IndexOf("voice", StringComparison.OrdinalIgnoreCase) >= 0))
					{
						((Behaviour)item2).enabled = true;
					}
				}
			}
		}

		private void Update()
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Invalid comparison between Unknown and I4
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: 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_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: 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)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			if (_frontCalibrated || (Object)(object)_brain == (Object)null)
			{
				return;
			}
			PuppetMaster puppetMaster = _brain.puppetMaster;
			if ((Object)(object)puppetMaster == (Object)null || (int)puppetMaster.state == 1)
			{
				return;
			}
			if ((Object)(object)_chestTransform == (Object)null)
			{
				foreach (Muscle item in (Il2CppArrayBase<Muscle>)(object)puppetMaster.muscles)
				{
					if ((Object)(object)item.rigidbody == (Object)null || !((Object)item.rigidbody).name.ToLower().Contains("chest"))
					{
						continue;
					}
					_chest = item.rigidbody;
					_chestTransform = ((Component)item.rigidbody).transform;
					break;
				}
				if ((Object)(object)_chestTransform == (Object)null)
				{
					return;
				}
			}
			Vector3 forward = ((Component)_brain).transform.forward;
			forward.y = 0f;
			if (((Vector3)(ref forward)).sqrMagnitude < 0.001f)
			{
				forward = Vector3.forward;
			}
			((Vector3)(ref forward)).Normalize();
			Vector3[] array = (Vector3[])(object)new Vector3[6]
			{
				_chestTransform.forward,
				_chestTransform.up,
				_chestTransform.right,
				-_chestTransform.forward,
				-_chestTransform.up,
				-_chestTransform.right
			};
			float num = -2f;
			Vector3[] array2 = array;
			foreach (Vector3 val in array2)
			{
				float num2 = Vector3.Dot(val, forward);
				if (num2 > num)
				{
					num = num2;
					_chestFrontLocal = _chestTransform.InverseTransformDirection(val);
				}
			}
			_frontCalibrated = true;
		}

		private float BacknessNow()
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_chestTransform == (Object)null)
			{
				return 0f;
			}
			Vector3 val = (_frontCalibrated ? _chestTransform.TransformDirection(_chestFrontLocal) : _chestTransform.forward);
			return Vector3.Dot(val, Vector3.up);
		}

		public void ProcessHit()
		{
			if ((Object)(object)_brain == (Object)null || isSuffering)
			{
				return;
			}
			string text = ((Object)((Component)_brain).gameObject).name.ToLower();
			if (text.Contains("crab") || text.Contains("headcrab") || text.Contains("omni") || text.Contains("rat") || text.Contains("turret"))
			{
				isSuffering = false;
				return;
			}
			AudioSource[] array = Il2CppArrayBase<AudioSource>.op_Implicit(((Component)_brain).GetComponentsInChildren<AudioSource>());
			AudioSource[] array2 = array;
			foreach (AudioSource val in array2)
			{
				if ((Object)(object)val != (Object)(object)_agonySource)
				{
					val.Stop();
					val.volume = 0f;
				}
			}
			if (!_isInitialized)
			{
				InitializeBodyParts();
				_isInitialized = true;
			}
			initialPoseRots.Clear();
			mercyShotsLeft = Random.Range(2, 8);
			isSuffering = true;
			sufferingStartTime = Time.time;
			MelonCoroutines.Start(Struggle());
		}

		public void MercyKill()
		{
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: 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_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: 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_0108: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)lastHitBone != (Object)null) || (!((Object)lastHitBone).name.ToLower().Contains("head") && !((Object)lastHitBone).name.ToLower().Contains("neck")))
			{
				mercyShotsLeft--;
				if (mercyShotsLeft > 0)
				{
					if (Random.value > 0.1f && _knees != null && _knees.Count > 0)
					{
						Rigidbody val = _knees[Random.Range(0, _knees.Count)];
						if ((Object)(object)val != (Object)null)
						{
							Vector3 val2 = _pelvisTransform.up * 1f + Random.onUnitSphere * 0.3f;
							val.AddForce(val2 * (Main.pullForce * 0.4f), (ForceMode)1);
						}
					}
					return;
				}
			}
			if (Random.value > 0.1f && _knees != null && _knees.Count > 0)
			{
				Rigidbody val3 = _knees[Random.Range(0, _knees.Count)];
				if ((Object)(object)val3 != (Object)null)
				{
					float num = 0.8f;
					Vector3 val4 = _pelvisTransform.up * 1f + Random.onUnitSphere * 0.3f;
					val3.AddForce(val4 * (Main.pullForce * num), (ForceMode)1);
				}
			}
			isSuffering = false;
			if ((Object)(object)_agonySource != (Object)null && _agonySource.isPlaying)
			{
				_agonySource.Stop();
			}
		}

		private Vector3 DriveBone(Rigidbody bone, Vector3 targetPos, float kp, float kd, float maxF)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)bone == (Object)null)
			{
				return Vector3.zero;
			}
			Vector3 val = targetPos - bone.position;
			Vector3 val2 = val * kp - bone.velocity * kd;
			val2 = Vector3.ClampMagnitude(val2, maxF);
			bone.AddForce(val2, (ForceMode)0);
			return val2;
		}

		private void InitializeBodyParts()
		{
			_isSmallEnemy = false;
			_limbs.Clear();
			_legs.Clear();
			_knees.Clear();
			_feet.Clear();
			PuppetMaster puppetMaster = _brain.puppetMaster;
			if ((Object)(object)puppetMaster == (Object)null || puppetMaster.muscles == null || ((Il2CppArrayBase<Muscle>)(object)puppetMaster.muscles).Length == 0)
			{
				return;
			}
			_legsBehaviour = ((Component)_brain).gameObject.GetComponent<BehaviourPowerLegs>();
			if ((Object)(object)_legsBehaviour != (Object)null)
			{
				((Behaviour)_legsBehaviour).enabled = false;
			}
			string text = ((Object)((Component)_brain).gameObject).name.ToLower();
			if (text.Contains("crab") || text.Contains("headcrab") || text.Contains("omni") || text.Contains("rat") || text.Contains("turret"))
			{
				_isSmallEnemy = true;
				return;
			}
			_pelvis = ((Il2CppArrayBase<Muscle>)(object)puppetMaster.muscles)[0].rigidbody;
			foreach (Muscle item in (Il2CppArrayBase<Muscle>)(object)puppetMaster.muscles)
			{
				if ((Object)(object)item.rigidbody == (Object)null)
				{
					continue;
				}
				string text2 = ((Object)item.rigidbody).name.ToLower();
				if (text2.Contains("head"))
				{
					_head = item.rigidbody;
				}
				string[] array = pelvisKeywords;
				foreach (string value in array)
				{
					if (text2.Contains(value))
					{
						_pelvis = item.rigidbody;
						break;
					}
				}
				string[] array2 = coreKeywords;
				foreach (string value2 in array2)
				{
					if (text2.Contains(value2))
					{
						_chest = item.rigidbody;
						break;
					}
				}
				bool flag = false;
				string[] array3 = legKeywords;
				foreach (string value3 in array3)
				{
					if (text2.Contains(value3))
					{
						_legs.Add(item.rigidbody);
						flag = true;
						break;
					}
				}
				if (flag)
				{
					continue;
				}
				string[] array4 = armKeywords;
				foreach (string value4 in array4)
				{
					if (text2.Contains(value4))
					{
						_limbs.Add(item.rigidbody);
						break;
					}
				}
			}
			_spineChain.Clear();
			Rigidbody val = null;
			Rigidbody val2 = null;
			foreach (Muscle item2 in (Il2CppArrayBase<Muscle>)(object)puppetMaster.muscles)
			{
				if ((Object)(object)item2.rigidbody == (Object)null)
				{
					continue;
				}
				string text3 = ((Object)item2.rigidbody).name.ToLower();
				if (!text3.StartsWith("skn_") && (text3.Contains("spine") || text3.Contains("chest") || text3.Contains("neck")))
				{
					_spineChain.Add(item2.rigidbody);
					if (text3.Contains("chest"))
					{
						val = item2.rigidbody;
					}
					if (text3.Contains("spine"))
					{
						val2 = item2.rigidbody;
					}
				}
			}
			if ((Object)(object)val != (Object)null)
			{
				_chest = val;
			}
			else if ((Object)(object)val2 != (Object)null)
			{
				_chest = val2;
			}
			foreach (Muscle item3 in (Il2CppArrayBase<Muscle>)(object)puppetMaster.muscles)
			{
				if ((Object)(object)item3.rigidbody == (Object)null)
				{
					continue;
				}
				string text4 = ((Object)item3.rigidbody).name.ToLower();
				if (!text4.Contains("twist") && !text4.Contains("toe") && !text4.Contains("ball"))
				{
					if (text4.Contains("calf") || text4.Contains("lowerleg"))
					{
						_knees.Add(item3.rigidbody);
					}
					if (text4.Contains("foot"))
					{
						_feet.Add(item3.rigidbody);
					}
				}
			}
			if (_knees.Count < 2)
			{
				foreach (Muscle item4 in (Il2CppArrayBase<Muscle>)(object)puppetMaster.muscles)
				{
					if (!((Object)(object)item4.rigidbody == (Object)null))
					{
						string text5 = ((Object)item4.rigidbody).name.ToLower();
						if (!text5.Contains("twist") && !text5.Contains("toe") && !text5.Contains("ball") && (text5.Contains("knee") || (text5.Contains("leg") && !text5.Contains("up"))) && !_knees.Contains(item4.rigidbody))
						{
							_knees.Add(item4.rigidbody);
						}
					}
				}
			}
			if (_feet.Count < 2)
			{
				foreach (Muscle item5 in (Il2CppArrayBase<Muscle>)(object)puppetMaster.muscles)
				{
					if (!((Object)(object)item5.rigidbody == (Object)null))
					{
						string text6 = ((Object)item5.rigidbody).name.ToLower();
						if (text6.Contains("ankle") && !_feet.Contains(item5.rigidbody))
						{
							_feet.Add(item5.rigidbody);
						}
					}
				}
			}
			if ((Object)(object)_pelvis != (Object)null)
			{
				_pelvisTransform = ((Component)_pelvis).transform;
			}
			if ((Object)(object)_chest != (Object)null)
			{
				_chestTransform = ((Component)_chest).transform;
			}
		}

		private void CreateSlipperyMaterial()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			if ((Object)(object)_slipperyMaterial == (Object)null)
			{
				_slipperyMaterial = new PhysicMaterial();
				((Object)_slipperyMaterial).name = "SlipperyLegs";
				_slipperyMaterial.dynamicFriction = 0.05f;
				_slipperyMaterial.staticFriction = 0.05f;
				_slipperyMaterial.frictionCombine = (PhysicMaterialCombine)2;
				_slipperyMaterial.bounciness = 0f;
				_slipperyMaterial.bounceCombine = (PhysicMaterialCombine)2;
				((Object)_slipperyMaterial).hideFlags = (HideFlags)32;
			}
		}

		private void ApplyLowFriction()
		{
			CreateSlipperyMaterial();
			_originalMaterials.Clear();
			foreach (Rigidbody leg in _legs)
			{
				if ((Object)(object)leg == (Object)null)
				{
					continue;
				}
				Il2CppArrayBase<Collider> componentsInChildren = ((Component)leg).GetComponentsInChildren<Collider>(true);
				foreach (Collider item in componentsInChildren)
				{
					if (!((Object)(object)item == (Object)null))
					{
						if (!_originalMaterials.ContainsKey(item))
						{
							_originalMaterials[item] = item.sharedMaterial;
						}
						item.sharedMaterial = _slipperyMaterial;
					}
				}
			}
		}

		private void RestoreOriginalFriction()
		{
			foreach (KeyValuePair<Collider, PhysicMaterial> originalMaterial in _originalMaterials)
			{
				if ((Object)(object)originalMaterial.Key != (Object)null)
				{
					originalMaterial.Key.sharedMaterial = originalMaterial.Value;
				}
			}
			_originalMaterials.Clear();
		}

		private void SetupAudioSource()
		{
			if (!((Object)(object)_chest != (Object)null) || !((Object)(object)_agonySource == (Object)null))
			{
				return;
			}
			_agonySource = ((Component)_chest).gameObject.AddComponent<AudioSource>();
			_agonySource.spatialBlend = 1f;
			_agonySource.minDistance = 2f;
			_agonySource.maxDistance = 40f;
			_agonySource.rolloffMode = (AudioRolloffMode)0;
			_agonySource.playOnAwake = false;
			AudioMixer val = ((IEnumerable<AudioMixer>)Resources.FindObjectsOfTypeAll<AudioMixer>()).FirstOrDefault((Func<AudioMixer, bool>)((AudioMixer x) => ((Object)x).name == "Master"));
			if ((Object)(object)val != (Object)null)
			{
				Il2CppReferenceArray<AudioMixerGroup> val2 = val.FindMatchingGroups("SFX");
				if (((Il2CppArrayBase<AudioMixerGroup>)(object)val2).Length > 0)
				{
					_agonySource.outputAudioMixerGroup = ((Il2CppArrayBase<AudioMixerGroup>)(object)val2)[0];
				}
			}
		}

		private IEnumerator FadeOutAudio()
		{
			if (!((Object)(object)_agonySource == (Object)null))
			{
				float startVol = _agonySource.volume;
				float fadeTime = 1.2f;
				float t = 0f;
				while (t < fadeTime)
				{
					t += Time.deltaTime;
					_agonySource.volume = Mathf.Lerp(startVol, 0f, t / fadeTime);
					yield return null;
				}
				_agonySource.Stop();
				_agonySource.volume = startVol;
			}
		}

		private static float Frac(float x)
		{
			return x - Mathf.Floor(x);
		}

		private IEnumerator Struggle()
		{
			if (_isSmallEnemy)
			{
				isSuffering = false;
				yield break;
			}
			Il2CppArrayBase<AudioSource> localSources = ((Component)((Component)this).transform).GetComponentsInChildren<AudioSource>(true);
			foreach (AudioSource src in localSources)
			{
				if ((Object)(object)src != (Object)null && (Object)(object)src.clip != (Object)null && (Object)(object)src != (Object)(object)_agonySource)
				{
					string clipName = ((Object)src.clip).name.ToLower();
					if (clipName.Contains("die") || clipName.Contains("death") || clipName.Contains("pain") || clipName.Contains("vo_"))
					{
						src.mute = true;
					}
				}
			}
			Il2CppArrayBase<MonoBehaviour> allBehaviours = ((Component)((Component)this).transform).GetComponentsInChildren<MonoBehaviour>(true);
			foreach (MonoBehaviour mb in allBehaviours)
			{
				if (!((Object)(object)mb == (Object)null))
				{
					string typeName = ((object)mb).GetType().Name;
					string nameSpace = ((object)mb).GetType().Namespace ?? "";
					if ((nameSpace == "ModThatIsNotMod.MonoBehaviours" || nameSpace.Contains("SLZ")) && (typeName.IndexOf("sfx", StringComparison.OrdinalIgnoreCase) >= 0 || typeName.IndexOf("vocal", StringComparison.OrdinalIgnoreCase) >= 0 || typeName.IndexOf("voice", StringComparison.OrdinalIgnoreCase) >= 0))
					{
						((Behaviour)mb).enabled = false;
					}
				}
			}
			AudioSource[] allSources = Il2CppArrayBase<AudioSource>.op_Implicit(((Component)((Component)this).transform).GetComponentsInChildren<AudioSource>(true));
			List<AudioSource> sourcesToCheck = allSources.Where((AudioSource s) => (Object)(object)s != (Object)(object)_agonySource).ToList();
			_isVocal = Random.Range(0f, 100f) < 100f;
			yield return (object)new WaitForFixedUpdate();
			float elapsed = 0f;
			float roll = Random.Range(0f, 100f);
			bool isBicycle = roll < 11f;
			bool isCrawling = roll >= 11f && roll < 21f;
			if (_knees.Count > 1 && (Object)(object)_chestTransform != (Object)null)
			{
				float x0 = _chestTransform.InverseTransformPoint(_knees[0].position).x;
				float x1 = _chestTransform.InverseTransformPoint(_knees[1].position).x;
				if (x0 < x1)
				{
				}
			}
			int rollPick = Random.Range(0, 100);
			int settleRoll = ((rollPick >= 40) ? ((rollPick < 75) ? 1 : 2) : 0);
			int pairCount = Mathf.Max(_knees.Count, _feet.Count);
			int[] footForKnee = new int[pairCount];
			bool[] footTaken = new bool[_feet.Count];
			for (int k = 0; k < pairCount; k++)
			{
				footForKnee[k] = -1;
				if (k >= _knees.Count || (Object)(object)_knees[k] == (Object)null)
				{
					continue;
				}
				for (int f = 0; f < _feet.Count; f++)
				{
					if (f < footTaken.Length && !footTaken[f] && !((Object)(object)_feet[f] == (Object)null) && ((Component)_feet[f]).transform.IsChildOf(((Component)_knees[k]).transform))
					{
						footForKnee[k] = f;
						break;
					}
				}
				if (footForKnee[k] < 0)
				{
					float bestD = float.MaxValue;
					for (int f2 = 0; f2 < _feet.Count; f2++)
					{
						if (f2 < footTaken.Length && !footTaken[f2] && !((Object)(object)_feet[f2] == (Object)null))
						{
							float d = Vector3.Distance(_knees[k].position, _feet[f2].position);
							if (d < bestD)
							{
								bestD = d;
								footForKnee[k] = f2;
							}
						}
					}
				}
				if (footForKnee[k] >= 0)
				{
					footTaken[footForKnee[k]] = true;
				}
			}
			int legN = Mathf.Max(_knees.Count, _feet.Count);
			_footPrevPos = (Vector3[])(object)new Vector3[legN];
			_footPrevTarget = (Vector3[])(object)new Vector3[legN];
			_footStuckTime = new float[legN];
			_footUnsticking = new bool[legN];
			for (int i = 0; i < legN; i++)
			{
				if (i < _feet.Count && (Object)(object)_feet[i] != (Object)null)
				{
					_footPrevPos[i] = _feet[i].position;
				}
			}
			float rollSign = 1f;
			if ((Object)(object)_chestTransform != (Object)null)
			{
				float rightShoulderUp = Vector3.Dot(_chestTransform.right, Vector3.up);
				rollSign = ((rightShoulderUp >= 0f) ? 1f : (-1f));
			}
			if (isBicycle)
			{
				ApplyLowFriction();
			}
			Vector3 lockedCrawlDir = Vector3.forward;
			if ((Object)(object)_chest != (Object)null && (Object)(object)_pelvis != (Object)null)
			{
				lockedCrawlDir = _chest.position - _pelvis.position;
				lockedCrawlDir.y = 0f;
				if (((Vector3)(ref lockedCrawlDir)).sqrMagnitude < 0.0001f)
				{
					lockedCrawlDir = Vector3.forward;
				}
				else
				{
					((Vector3)(ref lockedCrawlDir)).Normalize();
				}
			}
			float audioCooldown = 0f;
			int lastAudioIndex = -1;
			float dynamicStruggleTime = Main.struggleTime;
			Vector3 val;
			while (isSuffering && elapsed < dynamicStruggleTime)
			{
				elapsed += Time.fixedDeltaTime;
				if (audioCooldown > 0f)
				{
					audioCooldown -= Time.fixedDeltaTime;
				}
				float fadeStartTime = Mathf.Max(0f, dynamicStruggleTime - 2.5f);
				if (elapsed > fadeStartTime)
				{
					float fadeProgress = (elapsed - fadeStartTime) / (dynamicStruggleTime - fadeStartTime);
					Mathf.Clamp01(1f - fadeProgress);
				}
				foreach (AudioSource src2 in sourcesToCheck)
				{
					if ((Object)(object)src2 != (Object)null && ((Behaviour)src2).enabled && (Object)(object)src2.clip != (Object)null)
					{
						string clipName2 = ((Object)src2.clip).name;
						if (clipName2.IndexOf("die", StringComparison.OrdinalIgnoreCase) >= 0 || clipName2.IndexOf("death", StringComparison.OrdinalIgnoreCase) >= 0 || clipName2.IndexOf("pain", StringComparison.OrdinalIgnoreCase) >= 0 || clipName2.IndexOf("hurt", StringComparison.OrdinalIgnoreCase) >= 0 || clipName2.IndexOf("vo_", StringComparison.OrdinalIgnoreCase) >= 0)
						{
							((Behaviour)src2).enabled = false;
							src2.mute = true;
						}
					}
				}
				bool canPlayAgony = isBicycle && Main.agonyClips.Count > 0;
				bool canPlayNormal = !isBicycle && Main.normalDeathClips.Count > 0;
				if (_isVocal && (canPlayAgony || canPlayNormal))
				{
					SetupAudioSource();
					if ((Object)(object)_agonySource != (Object)null && audioCooldown <= 0f)
					{
						_agonySource.Stop();
						_agonySource.loop = false;
						List<AudioClip> targetList = (isBicycle ? Main.agonyClips : Main.normalDeathClips);
						int index = 0;
						if (targetList.Count > 1)
						{
							do
							{
								index = Random.Range(0, targetList.Count);
							}
							while (index == lastAudioIndex);
						}
						lastAudioIndex = index;
						AudioClip chosenClip = targetList[index];
						_agonySource.clip = chosenClip;
						if (isBicycle)
						{
							if (Random.value <= 0.1f)
							{
								_agonySource.volume = 0f;
							}
							else
							{
								_agonySource.volume = Random.Range(0.85f, 1f);
								MelonLogger.Msg(ConsoleColor.Cyan, " | playing sound " + ((Object)chosenClip).name);
							}
						}
						else
						{
							_agonySource.volume = Random.Range(0.35f, 0.45f);
							MelonLogger.Msg(ConsoleColor.Cyan, " | playing sound " + ((Object)chosenClip).name);
						}
						_agonySource.pitch = Random.Range(0.8f, 1.05f);
						_agonySource.Play();
						float trueAudioLength = chosenClip.length / Mathf.Abs(_agonySource.pitch);
						audioCooldown = trueAudioLength;
						dynamicStruggleTime = Mathf.Max(0.1f, trueAudioLength - 1f);
					}
				}
				if (isBicycle)
				{
					float force = Main.pullForce;
					if ((Object)(object)_pelvis == (Object)null || (Object)(object)_pelvisTransform == (Object)null)
					{
						yield break;
					}
					Vector3 headDir = _chest.position - _pelvis.position;
					headDir.y = 0f;
					if (((Vector3)(ref headDir)).sqrMagnitude < 0.01f)
					{
						headDir = _chestTransform.forward;
					}
					((Vector3)(ref headDir)).Normalize();
					Vector3 feetDir = -headDir;
					Vector3 latAxis = Vector3.Cross(Vector3.up, headDir);
					if (((Vector3)(ref latAxis)).sqrMagnitude < 0.001f)
					{
						latAxis = _chestTransform.right;
					}
					((Vector3)(ref latAxis)).Normalize();
					bool isOnBackLegs = BacknessNow() > 0.5f;
					float randomSeed = Mathf.Abs((float)((long)((Object)_pelvis).GetInstanceID() * 73856L)) % 100f / 100f;
					float cycleSpeed = Mathf.Lerp(4f, 6.5f, randomSeed);
					float chaos = Mathf.Sin(elapsed * 4.5f) * 0.7f + Mathf.Cos(elapsed * 8.2f) * 0.4f;
					if (isOnBackLegs)
					{
						cycleSpeed = Mathf.Lerp(3.8f, 6f, randomSeed);
						chaos = Mathf.Sin(elapsed * 4f) * 0.6f + Mathf.Cos(elapsed * 7f) * 0.3f;
					}
					float pedalPhase = elapsed * cycleSpeed + chaos;
					float groundY = _pelvis.position.y - 0.28f;
					for (int i2 = 0; i2 < _knees.Count; i2++)
					{
						Rigidbody knee = _knees[i2];
						Rigidbody foot = ((i2 < footForKnee.Length && footForKnee[i2] >= 0) ? _feet[footForKnee[i2]] : null);
						if ((Object)(object)knee == (Object)null || (Object)(object)_pelvis == (Object)null)
						{
							continue;
						}
						float sideSign;
						float offset;
						if (isOnBackLegs)
						{
							float myDot = Vector3.Dot(knee.position - _pelvis.position, latAxis);
							Rigidbody otherKnee = ((_knees.Count > 1) ? _knees[(i2 + 1) % _knees.Count] : null);
							float otherDot = (((Object)(object)otherKnee != (Object)null) ? Vector3.Dot(otherKnee.position - _pelvis.position, latAxis) : (0f - myDot));
							sideSign = ((myDot >= otherDot) ? 1f : (-1f)) * 0.18f;
							offset = ((i2 == 0) ? 0f : 3.14159f);
						}
						else
						{
							sideSign = ((i2 % 2 == 0) ? (-0.14f) : 0.14f);
							offset = ((i2 % 2 == 0) ? 0f : 2.4f);
						}
						if (elapsed < 2f)
						{
							DriveBone(knee, knee.position + feetDir * 0.05f, 80f, 15f, 80f);
							if ((Object)(object)foot != (Object)null)
							{
								DriveBone(foot, foot.position + feetDir * 0.1f, 80f, 15f, 80f);
							}
							continue;
						}
						float rawDrive = Mathf.Sin(pedalPhase + offset) + chaos * 0.5f;
						float forwardDrive = Mathf.Clamp(rawDrive * 2f, -1f, 1f);
						float t = (forwardDrive + 1f) * 0.5f;
						float pistonExt = Mathf.Lerp(0.3f, 0.8f, t);
						Vector3 footTarget;
						Vector3 kneeTarget;
						if (isOnBackLegs)
						{
							float reach = Mathf.Lerp(0.3f, 0.55f, t);
							footTarget = _pelvis.position + feetDir * reach + latAxis * sideSign;
							footTarget.y = groundY + Mathf.Lerp(0.18f, 0.04f, t);
							float kneeUp = Mathf.Lerp(0.45f, 0.3f, t);
							Vector3 kneeMid = Vector3.Lerp(_pelvis.position, footTarget, 0.5f);
							kneeTarget = kneeMid + Vector3.up * kneeUp + latAxis * sideSign;
							Vector3 toTarget = footTarget - _pelvis.position;
							if (((Vector3)(ref toTarget)).magnitude > 0.7f)
							{
								footTarget = _pelvis.position + ((Vector3)(ref toTarget)).normalized * 0.7f;
							}
						}
						else
						{
							float footLift = Mathf.Lerp(0.05f, 0.25f, t);
							footTarget = _pelvis.position + feetDir * pistonExt + Vector3.up * footLift + latAxis * sideSign;
							Vector3 kneeMid2 = Vector3.Lerp(_pelvis.position, footTarget, 0.5f);
							kneeTarget = kneeMid2 + Vector3.up * 0.15f + latAxis * sideSign * 0.5f;
							if ((Object)(object)foot != (Object)null)
							{
								float footDist = Vector3.Distance(foot.position, _pelvis.position);
								if (footDist > 1.05f)
								{
									val = footTarget - _pelvis.position;
									Vector3 homeDir = ((Vector3)(ref val)).normalized;
									footTarget = _pelvis.position + homeDir * 0.95f;
								}
							}
						}
						bool unsticking = false;
						if ((Object)(object)foot != (Object)null)
						{
							float footMoved = Vector3.Distance(foot.position, _footPrevPos[i2]);
							_footPrevPos[i2] = foot.position;
							float targetMoved = Vector3.Distance(footTarget, _footPrevTarget[i2]);
							_footPrevTarget[i2] = footTarget;
							if (_footUnsticking[i2])
							{
								unsticking = true;
								_footStuckTime[i2] -= Time.fixedDeltaTime;
								if (_footStuckTime[i2] <= 0f)
								{
									_footUnsticking[i2] = false;
								}
							}
							else
							{
								if (targetMoved > 0.01f && footMoved < 0.002f)
								{
									_footStuckTime[i2] += Time.fixedDeltaTime;
								}
								else
								{
									_footStuckTime[i2] = 0f;
								}
								if (_footStuckTime[i2] > 0.35f)
								{
									_footUnsticking[i2] = true;
									_footStuckTime[i2] = 0.6f;
								}
							}
							if (unsticking)
							{
								footTarget = _pelvis.position + feetDir * 0.2f + latAxis * sideSign + Vector3.up * 0.35f;
								kneeTarget = _pelvis.position + feetDir * 0.15f + latAxis * sideSign + Vector3.up * 0.3f;
							}
						}
						Vector3 kneeF = DriveBone(knee, kneeTarget, isOnBackLegs ? 600f : 350f, 14f, isOnBackLegs ? 700f : 200f);
						_pelvis.AddForce(-kneeF * 0.15f, (ForceMode)0);
						if ((Object)(object)foot != (Object)null)
						{
							Vector3 footF = DriveBone(foot, footTarget, isOnBackLegs ? 700f : 500f, 16f, isOnBackLegs ? 800f : 320f);
							_pelvis.AddForce(-footF * 0.15f, (ForceMode)0);
							knee.velocity = _pelvis.velocity + Vector3.ClampMagnitude(knee.velocity - _pelvis.velocity, 4f);
							foot.velocity = _pelvis.velocity + Vector3.ClampMagnitude(foot.velocity - _pelvis.velocity, 5.5f);
							if (isOnBackLegs)
							{
								foot.angularVelocity *= 0.6f;
							}
						}
					}
					if ((Object)(object)_head != (Object)null)
					{
						if (isOnBackLegs)
						{
							Vector3 headTarget = _chest.position + headDir * 0.25f;
							headTarget.y = _pelvis.position.y - 0.28f + 0.16f;
							Vector3 headForce = (headTarget - _head.position) * 200f - (_head.velocity - _chest.velocity) * 8f;
							_head.AddForce(Vector3.ClampMagnitude(headForce, 150f), (ForceMode)0);
						}
						else
						{
							val = _chestTransform.forward * 0.5f + Vector3.down * 0.5f;
							Vector3 headDownDir = ((Vector3)(ref val)).normalized;
							_head.AddForce(headDownDir * (force * 1.2f), (ForceMode)0);
							Vector3 headFwd = ((Component)_head).transform.forward;
							Vector3 faceDownTorque = Vector3.Cross(headFwd, Vector3.down);
							_head.AddTorque(faceDownTorque * 60f, (ForceMode)0);
						}
						Vector3 headForward = ((Component)_head).transform.forward;
						Vector3 chestForward = _chestTransform.forward;
						Vector3 headTwistError = Vector3.Cross(headForward, chestForward);
						_head.AddTorque(headTwistError * 25f, (ForceMode)0);
						Rigidbody head = _head;
						head.angularVelocity *= 0.7f;
					}
					if ((Object)(object)_chest != (Object)null && (Object)(object)_pelvis != (Object)null && (Object)(object)_chestTransform != (Object)null)
					{
						float upDotC = BacknessNow();
						bool isOnBack = upDotC > 0.6f;
						bool isOnStomach = upDotC < -0.6f;
						if (Physics.Raycast(_pelvis.position, Vector3.down, 1.2f) && !isOnBackLegs && ((settleRoll == 1 && upDotC > -0.3f) || (settleRoll == 2 && upDotC > 0.25f)))
						{
							_chest.AddTorque(headDir * (rollSign * 50f), (ForceMode)0);
							_pelvis.AddTorque(headDir * (rollSign * 30f), (ForceMode)0);
							Rigidbody pelvis = _pelvis;
							pelvis.angularVelocity *= 0.92f;
							Rigidbody chest = _chest;
							chest.angularVelocity *= 0.92f;
						}
						else if (isOnStomach)
						{
							_pelvis.angularVelocity = Vector3.zero;
							_chest.angularVelocity = Vector3.zero;
							_chest.AddForce(Vector3.down * 120f, (ForceMode)0);
							_pelvis.AddForce(Vector3.down * 120f, (ForceMode)0);
						}
						else if (isOnBack)
						{
							if (Physics.Raycast(_pelvis.position, Vector3.down, 1.2f))
							{
								_chest.AddForce(Vector3.down * 150f, (ForceMode)0);
								_pelvis.AddForce(Vector3.down * 80f, (ForceMode)0);
								Rigidbody pelvis2 = _pelvis;
								pelvis2.angularVelocity *= 0.3f;
								Rigidbody chest2 = _chest;
								chest2.angularVelocity *= 0.3f;
							}
							else
							{
								Rigidbody pelvis3 = _pelvis;
								pelvis3.angularVelocity *= 0.9f;
								Rigidbody chest3 = _chest;
								chest3.angularVelocity *= 0.9f;
							}
						}
						else
						{
							Rigidbody pelvis4 = _pelvis;
							pelvis4.angularVelocity *= 0.8f;
							Rigidbody chest4 = _chest;
							chest4.angularVelocity *= 0.8f;
						}
						float thrashSpeedSeed = Mathf.Abs((float)((long)((Object)_pelvis).GetInstanceID() * 92341L)) % 100f / 100f;
						float baseThrashSpeed = Mathf.Lerp(2f, 4.5f, thrashSpeedSeed);
						float thrashChaos = Mathf.Sin(elapsed * 1.4f) * 0.8f;
						float thrashPhase = elapsed * baseThrashSpeed + thrashChaos;
						if (!isOnBack)
						{
							_chest.AddForce(_chestTransform.right * (Mathf.Sin(thrashPhase) * 70f), (ForceMode)0);
							_pelvis.AddForce(_pelvisTransform.right * (Mathf.Sin(thrashPhase - 0.75f) * 70f), (ForceMode)0);
							val = _pelvis.position - _chest.position;
							Vector3 crunchDir = ((Vector3)(ref val)).normalized;
							float currentDist = Vector3.Distance(_chest.position, _pelvis.position);
							if (currentDist > 0.42f)
							{
								Vector3 curlForce = crunchDir * ((currentDist - 0.42f) * 250f);
								_chest.AddForce(curlForce, (ForceMode)0);
								_pelvis.AddForce(-curlForce, (ForceMode)0);
							}
							Vector3 perfectStraightLinePos = _pelvis.position + _pelvisTransform.forward * 0.42f;
							Vector3 deviationVector = perfectStraightLinePos - _chest.position;
							Vector3 straightLineSpring = deviationVector * 300f;
							_chest.AddForce(straightLineSpring, (ForceMode)0);
							_pelvis.AddForce(-straightLineSpring, (ForceMode)0);
						}
						else
						{
							float groundY2 = _pelvis.position.y - 0.28f;
							Vector3 chestTarget = _pelvis.position + headDir * 0.42f;
							chestTarget.y = groundY2 + 0.18f;
							_chest.AddForce(Vector3.ClampMagnitude((chestTarget - _chest.position) * 250f, 200f), (ForceMode)0);
							Vector3 chestFront = (_frontCalibrated ? _chestTransform.TransformDirection(_chestFrontLocal) : _chestTransform.forward);
							_chest.AddTorque(Vector3.Cross(chestFront, Vector3.up) * 80f, (ForceMode)0);
							Rigidbody chest5 = _chest;
							chest5.angularVelocity *= 0.8f;
							Rigidbody pelvis5 = _pelvis;
							pelvis5.angularVelocity *= 0.8f;
						}
						_chest.AddForce(-_chest.velocity * 0.5f, (ForceMode)0);
						_pelvis.AddForce(-_pelvis.velocity * 0.5f, (ForceMode)0);
						Vector3 relativeChestVel = _chest.velocity - _pelvis.velocity;
						_chest.velocity = _pelvis.velocity + Vector3.ClampMagnitude(relativeChestVel, 3f);
					}
					foreach (Rigidbody hand in _limbs)
					{
						if (!((Object)(object)hand == (Object)null))
						{
							if ((Object)(object)lastHitBone != (Object)null)
							{
								val = lastHitBone.position - hand.position;
								Vector3 woundDir = ((Vector3)(ref val)).normalized;
								hand.AddForce(woundDir * (force * 0.5f), (ForceMode)0);
							}
							else if ((Object)(object)_chest != (Object)null)
							{
								val = _chest.position - hand.position;
								Vector3 chestDir = ((Vector3)(ref val)).normalized;
								hand.AddForce(chestDir * (force * 0.4f), (ForceMode)0);
							}
						}
					}
				}
				else if (isCrawling && (Object)(object)_chest != (Object)null && (Object)(object)_pelvis != (Object)null)
				{
					float timeSinceDeath = Time.time - sufferingStartTime;
					float settleFactor = Mathf.Clamp01(timeSinceDeath / 1f);
					float force2 = 45f;
					Vector3 crawlDir = lockedCrawlDir;
					float upDot = Vector3.Dot(_chestTransform.up, Vector3.up);
					if (upDot < -0.2f)
					{
						_chest.AddTorque(_chestTransform.forward * (force2 * 2f) * settleFactor, (ForceMode)0);
						_pelvis.AddTorque(_pelvisTransform.forward * (force2 * 2f) * settleFactor, (ForceMode)0);
					}
					else
					{
						Vector3 chestUpTorque = Vector3.Cross(_chestTransform.up, Vector3.up);
						_chest.AddTorque(chestUpTorque * (force2 * 2f) * settleFactor, (ForceMode)0);
						Vector3 pelvisUpTorque = Vector3.Cross(_pelvisTransform.up, Vector3.up);
						_pelvis.AddTorque(pelvisUpTorque * (force2 * 2f) * settleFactor, (ForceMode)0);
					}
					Vector3 currentSpineDir = _chest.position - _pelvis.position;
					currentSpineDir.y = 0f;
					if (((Vector3)(ref currentSpineDir)).sqrMagnitude > 0.0001f)
					{
						((Vector3)(ref currentSpineDir)).Normalize();
						Vector3 chestTorque = Vector3.Cross(currentSpineDir, crawlDir);
						_chest.AddTorque(chestTorque * (force2 * 4f) * settleFactor, (ForceMode)0);
						Vector3 pelvisTorque = Vector3.Cross(currentSpineDir, crawlDir);
						_pelvis.AddTorque(pelvisTorque * (force2 * 4f) * settleFactor, (ForceMode)0);
					}
					float crawlSpeed = 1.2f;
					float phase = Mathf.Sin(elapsed * (float)Math.PI * crawlSpeed);
					Vector3 rightDir = Vector3.Cross(crawlDir, Vector3.up);
					for (int i3 = 0; i3 < _limbs.Count; i3++)
					{
						Rigidbody hand2 = _limbs[i3];
						if ((Object)(object)hand2 == (Object)null)
						{
							continue;
						}
						float sidePhase = ((i3 % 2 == 0) ? phase : (0f - phase));
						float sideSign2 = ((i3 % 2 == 0) ? 1f : (-1f));
						Vector3 armSpread = rightDir * sideSign2;
						if (sidePhase > 0f)
						{
							float liftArc = Mathf.Sin(sidePhase * (float)Math.PI);
							Vector3 reachDir = crawlDir + armSpread * 0.4f + Vector3.up * (0.6f * liftArc);
							hand2.AddForce(((Vector3)(ref reachDir)).normalized * (force2 * 1.8f) * settleFactor, (ForceMode)0);
						}
						else
						{
							Vector3 pullDir = -crawlDir + armSpread * 0.2f - Vector3.up * 1.5f;
							hand2.AddForce(((Vector3)(ref pullDir)).normalized * (force2 * 1.5f) * settleFactor, (ForceMode)0);
							Vector3 forwardVel = Vector3.Project(_chest.velocity, crawlDir);
							if (((Vector3)(ref forwardVel)).sqrMagnitude < 1.44f)
							{
								float pullIntensity = 0f - sidePhase;
								float pulseMultiplier = pullIntensity * pullIntensity;
								_chest.AddForce(crawlDir * (force2 * 8f * pulseMultiplier) * settleFactor, (ForceMode)0);
								_chest.AddForce(Vector3.up * (force2 * 1.2f * pulseMultiplier) * settleFactor, (ForceMode)0);
							}
						}
						hand2.velocity = Vector3.Lerp(hand2.velocity, Vector3.zero, Time.fixedDeltaTime * 4.5f);
					}
				}
				else
				{
					float force3 = Main.pullForce;
					if ((Object)(object)_chest != (Object)null && (Object)(object)_pelvis != (Object)null)
					{
						float dampingFactor = 15f;
						float timeSinceDeath2 = Time.time - sufferingStartTime;
						float settleFactor2 = Mathf.Clamp01(timeSinceDeath2 / 1f);
						val = _chest.position - _pelvis.position;
						_ = ((Vector3)(ref val)).normalized;
						Vector3 spineDir = _chest.position - _pelvis.position;
						spineDir.y = 0f;
						if (((Vector3)(ref spineDir)).sqrMagnitude < 0.001f)
						{
							spineDir = _chestTransform.forward;
						}
						((Vector3)(ref spineDir)).Normalize();
						val = Vector3.Cross(Vector3.up, spineDir);
						_ = ((Vector3)(ref val)).normalized;
						bool onBackElse = BacknessNow() > 0.5f;
						bool onStomachElse = BacknessNow() < -0.7f;
						_ = -spineDir;
						float pelvisGroundY = _pelvis.position.y - 0.28f;
						Vector3 pelvisTarget = _pelvis.position;
						pelvisTarget.y = (onStomachElse ? (pelvisGroundY + 0.3f) : (pelvisGroundY + 0.15f));
						Vector3 chestTarget2;
						if (onBackElse)
						{
							chestTarget2 = _pelvis.position + spineDir * 0.42f;
							chestTarget2.y = pelvisGroundY + 0.12f;
						}
						else if (onStomachElse)
						{
							chestTarget2 = _pelvis.position + spineDir * 0.3f;
							chestTarget2.y = pelvisGroundY + 0.1f;
						}
						else
						{
							chestTarget2 = _pelvis.position + spineDir * 0.38f;
							chestTarget2.y = _pelvis.position.y + 0.05f;
						}
						Vector3 headTarget2 = Vector3.zero;
						if ((Object)(object)_head != (Object)null)
						{
							if (!onBackElse)
							{
								headTarget2 = ((!onStomachElse) ? (_chest.position + spineDir * 0.22f + Vector3.down * 0.1f) : (_chest.position + spineDir * 0.2f + Vector3.down * 0.15f));
							}
							else
							{
								headTarget2 = _chest.position + spineDir * 0.25f;
								headTarget2.y = pelvisGroundY + 0.1f;
							}
						}
						float pelvisKP = Mathf.Lerp(0f, onStomachElse ? 500f : 250f, settleFactor2);
						float pelvisMax = Mathf.Lerp(0f, onStomachElse ? 600f : 200f, settleFactor2);
						float chestKP = Mathf.Lerp(0f, onStomachElse ? 400f : 350f, settleFactor2);
						float chestMax = Mathf.Lerp(0f, onStomachElse ? 350f : 250f, settleFactor2);
						DriveBone(_pelvis, pelvisTarget, pelvisKP, dampingFactor, pelvisMax);
						DriveBone(_chest, chestTarget2, chestKP, dampingFactor, chestMax);
						if ((Object)(object)_head != (Object)null)
						{
							DriveBone(kp: Mathf.Lerp(0f, onStomachElse ? 350f : 300f, settleFactor2), maxF: Mathf.Lerp(0f, onStomachElse ? 300f : 200f, settleFactor2), bone: _head, targetPos: headTarget2, kd: dampingFactor * 0.8f);
							if (onStomachElse)
							{
								Vector3 headFwd2 = ((Component)_head).transform.forward;
								Vector3 faceDownTorque2 = Vector3.Cross(headFwd2, Vector3.down);
								float torqueMag = Mathf.Lerp(0f, 60f, settleFactor2);
								_head.AddTorque(faceDownTorque2 * torqueMag, (ForceMode)0);
								if ((Object)(object)_chest != (Object)null)
								{
									_chest.AddTorque(-faceDownTorque2 * torqueMag * 0.3f, (ForceMode)0);
								}
							}
							else if (!onBackElse)
							{
								_head.AddForce(Vector3.down * (force3 * 0.4f) * settleFactor2, (ForceMode)0);
							}
						}
						if (_limbs != null)
						{
							foreach (Rigidbody hand3 in _limbs)
							{
								if ((Object)(object)hand3 == (Object)null)
								{
									continue;
								}
								Rigidbody targetBone = (((Object)(object)lastHitBone != (Object)null) ? lastHitBone : (((Object)(object)_head != (Object)null) ? _head : _chest));
								if ((Object)(object)targetBone != (Object)null)
								{
									val = targetBone.position - hand3.position;
									Vector3 directionToTarget = ((Vector3)(ref val)).normalized;
									float armForce = force3 * 0.6f * settleFactor2;
									hand3.AddForce(directionToTarget * armForce, (ForceMode)0);
									Vector3 targetF = -directionToTarget * armForce;
									if (targetF.y < 0f)
									{
										targetF.y = 0f;
									}
									targetBone.AddForce(targetF, (ForceMode)0);
									Vector3 relHandVel = hand3.velocity - targetBone.velocity;
									hand3.AddForce(-relHandVel * (force3 * 0.1f) * settleFactor2, (ForceMode)0);
								}
							}
						}
						if (_knees != null && (Object)(object)_pelvis != (Object)null)
						{
							Vector3 headDir2 = _chest.position - _pelvis.position;
							headDir2.y = 0f;
							if (((Vector3)(ref headDir2)).sqrMagnitude < 0.01f)
							{
								headDir2 = _chestTransform.forward;
							}
							((Vector3)(ref headDir2)).Normalize();
							Vector3 feetDir2 = -headDir2;
							Vector3 latAxis2 = Vector3.Cross(Vector3.up, headDir2);
							if (((Vector3)(ref latAxis2)).sqrMagnitude < 0.001f)
							{
								latAxis2 = _chestTransform.right;
							}
							((Vector3)(ref latAxis2)).Normalize();
							bool isOnBackLegs2 = BacknessNow() > 0.5f;
							float groundY3 = _pelvis.position.y - 0.28f;
							for (int i4 = 0; i4 < _knees.Count; i4++)
							{
								Rigidbody knee2 = _knees[i4];
								Rigidbody foot2 = ((i4 < footForKnee.Length && footForKnee[i4] >= 0) ? _feet[footForKnee[i4]] : null);
								if (!((Object)(object)knee2 == (Object)null))
								{
									float sideSign3;
									if (isOnBackLegs2)
									{
										float myDot2 = Vector3.Dot(knee2.position - _pelvis.position, latAxis2);
										Rigidbody otherKnee2 = ((_knees.Count > 1) ? _knees[(i4 + 1) % _knees.Count] : null);
										float otherDot2 = (((Object)(object)otherKnee2 != (Object)null) ? Vector3.Dot(otherKnee2.position - _pelvis.position, latAxis2) : (0f - myDot2));
										sideSign3 = ((myDot2 >= otherDot2) ? 1f : (-1f)) * 0.18f;
									}
									else
									{
										sideSign3 = ((i4 % 2 == 0) ? (-0.14f) : 0.14f);
									}
									Vector3 footTarget2;
									Vector3 kneeTarget2;
									if (isOnBackLegs2)
									{
										footTarget2 = _pelvis.position + feetDir2 * 0.4f + latAxis2 * sideSign3;
										footTarget2.y = groundY3 + 0.06f;
										kneeTarget2 = _pelvis.position + feetDir2 * 0.25f + Vector3.up * 0.3f + latAxis2 * sideSign3;
									}
									else
									{
										kneeTarget2 = _pelvis.position + headDir2 * 0.1f + latAxis2 * sideSign3;
										kneeTarget2.y = groundY3 + 0.06f;
										footTarget2 = _pelvis.position + feetDir2 * 0.55f + Vector3.up * 0.25f + latAxis2 * sideSign3;
									}
									Vector3 toKneeTarget = kneeTarget2 - _pelvis.position;
									if (((Vector3)(ref toKneeTarget)).magnitude > 0.6f)
									{
										kneeTarget2 = _pelvis.position + ((Vector3)(ref toKneeTarget)).normalized * 0.6f;
									}
									Vector3 toFootTarget = footTarget2 - _pelvis.position;
									if (((Vector3)(ref toFootTarget)).magnitude > 0.7f)
									{
										footTarget2 = _pelvis.position + ((Vector3)(ref toFootTarget)).normalized * 0.7f;
									}
									Vector3 kneeF2 = DriveBone(kp: Mathf.Lerp(0f, 450f, settleFactor2), maxF: Mathf.Lerp(0f, 350f, settleFactor2), bone: knee2, targetPos: kneeTarget2, kd: 14f);
									_pelvis.AddForce(-kneeF2 * 0.3f, (ForceMode)0);
									if ((Object)(object)foot2 != (Object)null)
									{
										Vector3 footF2 = DriveBone(kp: Mathf.Lerp(0f, 500f, settleFactor2), maxF: Mathf.Lerp(0f, 400f, settleFactor2), bone: foot2, targetPos: footTarget2, kd: 16f);
										_pelvis.AddForce(-footF2 * 0.3f, (ForceMode)0);
										knee2.velocity = _pelvis.velocity + Vector3.ClampMagnitude(knee2.velocity - _pelvis.velocity, Mathf.Lerp(10f, 4f, settleFactor2));
										foot2.velocity = _pelvis.velocity + Vector3.ClampMagnitude(foot2.velocity - _pelvis.velocity, Mathf.Lerp(10f, 5.5f, settleFactor2));
									}
								}
							}
						}
					}
				}
				yield return (object)new WaitForFixedUpdate();
			}
			if (isSuffering && Random.Range(0f, 100f) <= 20f)
			{
				float spasmWindow = Random.Range(2f, 2.5f);
				int spasmCount = Random.Range(2, 4);
				float windowTimer = 0f;
				float spasmTimer = 0f;
				float nextSpasmAt = Random.Range(0.1f, 0.6f);
				int spasmsDone = 0;
				Rigidbody spasmBone = null;
				Rigidbody spasmBone2 = null;
				Vector3 spasmDir = Vector3.up;
				while (isSuffering && windowTimer < spasmWindow)
				{
					windowTimer += Time.fixedDeltaTime;
					if (spasmTimer > 0f)
					{
						spasmTimer -= Time.fixedDeltaTime;
						float intensity = Mathf.Clamp01(spasmTimer / 0.5f);
						float power = Main.pullForce * 2.5f * intensity;
						if ((Object)(object)spasmBone != (Object)null)
						{
							spasmBone.AddForce(spasmDir * power, (ForceMode)0);
						}
						if ((Object)(object)spasmBone2 != (Object)null)
						{
							spasmBone2.AddForce(spasmDir * (power * 0.8f), (ForceMode)0);
						}
					}
					else if (spasmsDone < spasmCount && windowTimer >= nextSpasmAt)
					{
						spasmsDone++;
						spasmTimer = 0.5f;
						nextSpasmAt = windowTimer + Random.Range(0.5f, 0.9f);
						spasmBone2 = null;
						float pick = Random.value;
						if (!(pick < 0.5f) || _knees.Count <= 0)
						{
							spasmBone = ((!(pick < 0.75f)) ? _pelvis : _chest);
						}
						else
						{
							int li = Random.Range(0, _knees.Count);
							spasmBone = _knees[li];
							if (li < _feet.Count)
							{
								spasmBone2 = _feet[li];
							}
						}
						Vector3 side = (((Object)(object)_pelvisTransform != (Object)null) ? _pelvisTransform.right : Vector3.right);
						float sideSign4 = ((Random.value > 0.5f) ? 1f : (-1f));
						if (Random.value < 0.5f)
						{
							val = side * sideSign4 + Random.onUnitSphere * 0.3f;
							spasmDir = ((Vector3)(ref val)).normalized;
						}
						else
						{
							val = Vector3.up * 0.8f + side * sideSign4 * 0.4f + Random.onUnitSphere * 0.2f;
							spasmDir = ((Vector3)(ref val)).normalized;
						}
					}
					yield return (object)new WaitForFixedUpdate();
				}
			}
			if (isSuffering && (Object)(object)_agonySource != (Object)null && _agonySource.isPlaying)
			{
				yield return FadeOutAudio();
			}
			yield return ResetSequence();
			isSuffering = false;
		}

		private IEnumerator ResetSequence()
		{
			RestoreOriginalFriction();
			if ((Object)(object)_agonySource != (Object)null)
			{
				_agonySource.Stop();
			}
			Il2CppArrayBase<AudioSource> allSources = ((Component)((Component)this).transform).GetComponentsInChildren<AudioSource>(true);
			foreach (AudioSource src in allSources)
			{
				if ((Object)(object)src != (Object)null && (Object)(object)src != (Object)(object)_agonySource)
				{
					src.mute = false;
				}
			}
			PuppetMaster pm = (((Object)(object)_brain != (Object)null) ? _brain.puppetMaster : null);
			OriginalPuppetProperties props = ((Component)this).GetComponent<OriginalPuppetProperties>();
			if (!((Object)(object)pm == (Object)null) && !((Object)(object)props == (Object)null))
			{
				if ((Object)(object)pm.targetAnimator != (Object)null)
				{
					((Behaviour)pm.targetAnimator).enabled = true;
					pm.targetAnimator.speed = 0f;
				}
				pm.muscleDamper = props.damper;
				pm.muscleWeight = props.weight;
				pm.stateSettings = props.stateSettings;
			}
			yield break;
		}
	}
}
namespace Procudeal_aimation
{
	public class Main : MelonMod
	{
		public static bool modEnabled = true;

		public static float pullForce = 35f;

		public static float struggleTime = 8f;

		private bool _isScannerRunning = false;

		public static List<AudioClip> agonyClips = new List<AudioClip>();

		public static List<AudioClip> normalDeathClips = new List<AudioClip>();

		public override void OnApplicationStart()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			MelonLogger.Msg(ConsoleColor.Cyan, "The Procedural Animation Mod IS ACTIVE");
			ClassInjector.RegisterTypeInIl2Cpp<AgonyLogic>();
			ClassInjector.RegisterTypeInIl2Cpp<OriginalPuppetProperties>();
			Harmony val = new Harmony("com.jeb.proceduralanimation");
			val.PatchAll();
			SetupMenu();
			MelonCoroutines.Start(LoadAudioFiles());
		}

		private IEnumerator LoadAudioFiles()
		{
			string agonyPath = Path.Combine(MelonUtils.UserDataDirectory, "strugglesounds");
			if (!Directory.Exists(agonyPath))
			{
				Directory.CreateDirectory(agonyPath);
			}
			else
			{
				LoadClipsFromFolder(agonyPath, agonyClips);
			}
			string normalPath = Path.Combine(MelonUtils.UserDataDirectory, "normaldeathsounds");
			if (!Directory.Exists(normalPath))
			{
				Directory.CreateDirectory(normalPath);
			}
			else
			{
				LoadClipsFromFolder(normalPath, normalDeathClips);
			}
			yield break;
		}

		private void LoadClipsFromFolder(string folderPath, List<AudioClip> targetList)
		{
			string[] files = Directory.GetFiles(folderPath, "*.wav");
			string[] array = files;
			foreach (string path in array)
			{
				try
				{
					AudioClip val = WavUtility.ToAudioClip(path);
					if ((Object)(object)val != (Object)null)
					{
						((Object)val).name = Path.GetFileName(path);
						((Object)val).hideFlags = (HideFlags)32;
						targetList.Add(val);
						MelonLogger.Msg(ConsoleColor.Green, $"Successfully loaded: {((Object)val).name} into {targetList.Count} clips");
					}
				}
				catch (Exception ex)
				{
					MelonLogger.Error("Failed to load " + Path.GetFileName(path) + ": " + ex.Message);
				}
			}
		}

		public override void OnSceneWasInitialized(int buildIndex, string sceneName)
		{
			if (!_isScannerRunning)
			{
				_isScannerRunning = true;
				MelonCoroutines.Start(OptimizedScanner());
			}
		}

		private IEnumerator OptimizedScanner()
		{
			WaitForSeconds waitTime = new WaitForSeconds(1.5f);
			while (true)
			{
				if (modEnabled)
				{
					try
					{
						Il2CppArrayBase<AIBrain> allBrains = Object.FindObjectsOfType<AIBrain>();
						foreach (AIBrain brain in allBrains)
						{
							if ((Object)(object)brain == (Object)null)
							{
								continue;
							}
							AgonyLogic logic = ((Component)brain).GetComponent<AgonyLogic>();
							if ((Object)(object)logic == (Object)null)
							{
								logic = ((Component)brain).gameObject.AddComponent<AgonyLogic>();
							}
							if ((Object)(object)logic != (Object)null && logic.isSuffering)
							{
								continue;
							}
							PuppetMaster pm = brain.puppetMaster;
							if (!((Object)(object)pm == (Object)null) && (int)pm.state != 1)
							{
								Animator anim = pm.targetAnimator;
								if ((Object)(object)anim != (Object)null && anim.speed == 0f)
								{
									((Behaviour)anim).enabled = true;
									anim.speed = 1f;
								}
							}
						}
					}
					catch (Exception)
					{
					}
				}
				yield return waitTime;
			}
		}

		private void SetupMenu()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: 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)
			MenuCategory val = MenuManager.CreateCategory("Procudeal aimation", Color.red);
			val.CreateBoolElement("Mod Active", Color.white, true, (Action<bool>)delegate(bool v)
			{
				modEnabled = v;
			});
			val.CreateFloatElement("Force", Color.red, 35f, (Action<float>)delegate(float v)
			{
				pullForce = v;
			}, 5f, -2.1474836E+09f, 2.1474836E+09f, false);
			val.CreateFloatElement("Duration", Color.white, 8f, (Action<float>)delegate(float v)
			{
				struggleTime = v;
			}, 1f, -2.1474836E+09f, 2.1474836E+09f, false);
		}
	}
	public static class WavUtility
	{
		public static AudioClip ToAudioClip(string path)
		{
			byte[] array = File.ReadAllBytes(path);
			int num = 44;
			for (int i = 12; i < array.Length - 4; i++)
			{
				if (array[i] == 100 && array[i + 1] == 97 && array[i + 2] == 116 && array[i + 3] == 97)
				{
					num = i + 8;
					break;
				}
			}
			int num2 = BitConverter.ToInt16(array, 20);
			int num3 = BitConverter.ToInt16(array, 22);
			int num4 = BitConverter.ToInt32(array, 24);
			int num5 = BitConverter.ToInt16(array, 34);
			int num6;
			float[] array2;
			switch (num5)
			{
			case 32:
			{
				num6 = (array.Length - num) / 4;
				array2 = new float[num6];
				for (int k = 0; k < num6; k++)
				{
					array2[k] = BitConverter.ToSingle(array, num + k * 4);
				}
				break;
			}
			case 24:
			{
				num6 = (array.Length - num) / 3;
				array2 = new float[num6];
				for (int l = 0; l < num6; l++)
				{
					int num8 = num + l * 3;
					int num9 = (array[num8] << 8) | (array[num8 + 1] << 16) | (array[num8 + 2] << 24);
					array2[l] = (float)num9 / 2.1474836E+09f;
				}
				break;
			}
			case 16:
			{
				num6 = (array.Length - num) / 2;
				array2 = new float[num6];
				for (int j = 0; j < num6; j++)
				{
					short num7 = BitConverter.ToInt16(array, num + j * 2);
					array2[j] = (float)num7 / 32768f;
				}
				break;
			}
			default:
				MelonLogger.Error($" bit depth aint supported ({num5}-bit) for da file {path}.  convert to 16, 24, or 32-bit PLEASE");
				return null;
			}
			AudioClip val = AudioClip.Create("LoadedAudio", num6 / num3, num3, num4, false);
			val.SetData(Il2CppStructArray<float>.op_Implicit(array2), 0);
			return val;
		}
	}
	[HarmonyPatch(typeof(Gun), "OnFire", new Type[] { })]
	public class GunFirePatch
	{
		[HarmonyPostfix]
		public static void Postfix(Gun __instance)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			if (!Main.modEnabled || (Object)(object)__instance.firePointTransform == (Object)null)
			{
				return;
			}
			Ray val = default(Ray);
			((Ray)(ref val))..ctor(__instance.firePointTransform.position, __instance.firePointTransform.forward);
			RaycastHit val2 = default(RaycastHit);
			if (!Physics.Raycast(val, ref val2, 500f))
			{
				return;
			}
			AIBrain componentInParent = ((Component)((RaycastHit)(ref val2)).collider).GetComponentInParent<AIBrain>();
			if (!((Object)(object)componentInParent != (Object)null))
			{
				return;
			}
			AgonyLogic component = ((Component)componentInParent).GetComponent<AgonyLogic>();
			if ((Object)(object)component != (Object)null)
			{
				if (component.isSuffering && Time.time - component.sufferingStartTime >= 2f)
				{
					component.MercyKill();
				}
				else
				{
					component.lastHitBone = ((Component)((RaycastHit)(ref val2)).collider).GetComponent<Rigidbody>();
				}
			}
		}
	}
	[HarmonyPatch(typeof(PuppetMaster), "Kill", new Type[] { })]
	public class PuppetMasterKillPatch
	{
		[HarmonyPrefix]
		public static void Prefix(PuppetMaster __instance)
		{
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			if (!Main.modEnabled)
			{
				return;
			}
			AIBrain componentInParent = ((Component)__instance).GetComponentInParent<AIBrain>();
			if ((Object)(object)componentInParent == (Object)null)
			{
				return;
			}
			OriginalPuppetProperties component = ((Component)componentInParent).GetComponent<OriginalPuppetProperties>();
			if ((Object)(object)component == (Object)null)
			{
				component = ((Component)componentInParent).gameObject.AddComponent<OriginalPuppetProperties>();
				component.damper = __instance.muscleDamper;
				component.weight = __instance.muscleWeight;
				component.stateSettings = __instance.stateSettings;
				if ((Object)(object)__instance.targetAnimator != (Object)null)
				{
					component.animSpeed = __instance.targetAnimator.speed;
				}
			}
			StateSettings stateSettings = __instance.stateSettings;
			stateSettings.deadMuscleWeight = 0f;
			stateSettings.deadMuscleDamper = 0f;
			__instance.stateSettings = stateSettings;
			__instance.muscleWeight = 0f;
			__instance.muscleDamper = 0f;
			AgonyLogic component2 = ((Component)componentInParent).GetComponent<AgonyLogic>();
			if ((Object)(object)component2 != (Object)null)
			{
				component2.ProcessHit();
			}
		}
	}
}