Decompiled source of DynamicRagdoll v1.2.2

Mods\DynamicRagdoll.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BoneLib.BoneMenu;
using EuphoriaLite;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSLZ.Marrow.PuppetMasta;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using RagdollOnHit;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(EuphoriaLiteMod), "DynamicRagdoll", "1.0.86", "skait5k", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: MelonAdditionalDependencies(new string[] { "DynamicRagdoll2" })]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("DynamicRagdoll")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("DynamicRagdoll")]
[assembly: AssemblyTitle("DynamicRagdoll")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace EuphoriaLite
{
	public class EuphoriaLiteMod : MelonMod
	{
		private sealed class Clutch
		{
			public PuppetMaster Pm;

			public SubBehaviourHealth Health;

			public Rigidbody Target;

			public Vector3 LocalPoint;

			public bool HasLocal;

			public Rigidbody Target2;

			public Vector3 LocalPoint2;

			public bool HasLocal2;

			public bool Split;

			public Rigidbody LeftHand;

			public Rigidbody RightHand;

			public Rigidbody HeadBody;

			public Rigidbody LeftElbow;

			public Rigidbody RightElbow;

			public Vector3 OffsetL;

			public Vector3 OffsetR;

			public float StartedAt;

			public float Until;

			public float DelayUntil;

			public float Loosen;
		}

		private sealed class Downed
		{
			public PuppetMaster Pm;

			public SubBehaviourHealth Health;

			public Rigidbody[] Bodies;

			public float Until;

			public float NextWrithe;

			public bool Landed;

			public float LandTime;

			public bool LastStand;

			public int Rolls;

			public MuscleRegion Region;

			public float NextStir;

			public Animator Anim;

			public float AnimSpeed = 1f;

			public bool HasAnim;
		}

		private sealed class Hang
		{
			public PuppetMaster Pm;

			public Rigidbody[] Bodies;

			public Rigidbody Hand;

			public bool Left;

			public Vector3 Point;

			public float Until;
		}

		private sealed class BalanceState
		{
			public float Loss;

			public float LastTime = -100f;

			public int WindowCount;

			public float LastWindowEnd = -100f;
		}

		private sealed class Stagger
		{
			public PuppetMaster Pm;

			public SubBehaviourHealth Health;

			public Animator TargetAnim;

			public float TargetSpeed = 1f;

			public Rigidbody[] Bodies;

			public Rigidbody Hips;

			public Rigidbody FootL;

			public Rigidbody FootR;

			public Vector3 Dir;

			public float StartedAt;

			public float HipsY0;

			public float V0;

			public float PeakDv;

			public float BornAt;

			public int Steps;

			public float BalancedSince = -1f;

			public float KickMul = 1f;

			public float Spin;

			public float SpinUntil;

			public float WhiplashUntil;

			public Vector3 WoundPos;

			public float HeadLookUntil;

			public bool HasWound;

			public float StepForceMul = 1f;

			public float StepLiftMul = 1f;

			public bool Bracing;

			public MuscleRegion Region;

			public int HitMuscle;

			public float ShoveMul = 1f;

			public bool Pellet;

			public float MassScale = 1f;

			public float GunMul = 1f;

			public string GunName = "?";

			public bool Melee;

			public bool Sharp;

			public bool Env;

			public float LastDSeg;

			public float LastDrop;

			public Vector3 StartPos;

			public float OrigArmL;

			public float OrigArmR;

			public bool Swinging;

			public bool SwingLeft;

			public Vector3 SwingTarget;

			public Vector3 SwingFrom;

			public float SwingStart;

			public float SwingUntil;

			public float NextStepAt;

			public float PlantUntil;

			public Rigidbody LastFoot;
		}

		private sealed class NpcWatch
		{
			public PuppetMaster Pm;

			public Rigidbody Hips;
		}

		private sealed class UnSnap
		{
			public Vector3 Dir;

			public float Due;

			public float ChestM;

			public float HeadM;

			public float HipsM;

			public float K;
		}

		private sealed class AnimThaw
		{
			public Animator Anim;

			public float To;

			public float Until;
		}

		private sealed class Scales
		{
			public PuppetMaster Pm;

			public float[] Original = new float[17];

			public float[] Factor = new float[17];

			public float[] Target = new float[17];

			public float[] Up = new float[17];

			public float[] Down = new float[17];

			public float[] LastSet = new float[17];

			public float[] OriginalMap = new float[17];

			public float[] FactorMap = new float[17];

			public float[] TargetMap = new float[17];

			public float[] LastSetMap = new float[17];

			public Scales(PuppetMaster pm)
			{
				Pm = pm;
				for (int i = 0; i < 17; i++)
				{
					Original[i] = float.NaN;
					LastSet[i] = float.NaN;
					Factor[i] = 1f;
					Target[i] = 1f;
					Up[i] = 2f;
					Down[i] = 4f;
					OriginalMap[i] = float.NaN;
					FactorMap[i] = 1f;
					TargetMap[i] = 1f;
					LastSetMap[i] = float.NaN;
				}
			}
		}

		private const int RootM = 0;

		private const int SpineM = 7;

		private const int AnkleL = 3;

		private const int AnkleR = 6;

		private const int ChestM = 8;

		private const int HeadM = 9;

		private const int JawM = 16;

		private const int WristL = 12;

		private const int WristR = 15;

		private const int MuscleCount = 17;

		private static readonly int[] LegMusclesL = new int[3] { 1, 2, 3 };

		private static readonly int[] LegMusclesR = new int[3] { 4, 5, 6 };

		private static readonly int[] ArmMusclesL = new int[3] { 10, 11, 12 };

		private static readonly int[] ArmMusclesR = new int[3] { 13, 14, 15 };

		private static readonly int[] TorsoMuscles = new int[4] { 7, 8, 9, 16 };

		private static readonly Dictionary<int, Hang> Hangs = new Dictionary<int, Hang>();

		private static int _hangLogs;

		private static int _hangRejectLogs;

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

		internal static MelonPreferences_Entry<bool> Enabled;

		internal static MelonPreferences_Entry<bool> BalanceEnabled;

		internal static MelonPreferences_Entry<bool> FlipDirection;

		internal static MelonPreferences_Entry<bool> VarietyEnabled;

		internal static MelonPreferences_Entry<bool> MeleeEnabled;

		internal static MelonPreferences_Entry<bool> WalkThrough;

		internal static MelonPreferences_Entry<float> ClutchSeconds;

		internal static MelonPreferences_Entry<float> ClutchAcceleration;

		internal static MelonPreferences_Entry<float> ArmLooseness;

		internal static MelonPreferences_Entry<float> ClutchDelay;

		internal static MelonPreferences_Entry<float> HeadClutchChance;

		internal static MelonPreferences_Entry<float> FallThreshold;

		internal static MelonPreferences_Entry<float> BalanceRecovery;

		internal static MelonPreferences_Entry<float> LegGiveWay;

		internal static MelonPreferences_Entry<float> FallSeconds;

		internal static MelonPreferences_Entry<float> FallShove;

		internal static MelonPreferences_Entry<float> FallArmSplay;

		internal static MelonPreferences_Entry<float> StaggerArmFling;

		internal static MelonPreferences_Entry<float> FlailForce;

		internal static MelonPreferences_Entry<float> BraceForce;

		internal static MelonPreferences_Entry<float> LimbKick;

		internal static MelonPreferences_Entry<float> WritheForce;

		internal static MelonPreferences_Entry<float> HandSpeedCap;

		internal static MelonPreferences_Entry<float> GunForce;

		internal static MelonPreferences_Entry<float> MeleeForce;

		internal static MelonPreferences_Entry<float> SharpForce;

		internal static MelonPreferences_Entry<float> SharpClutchSeconds;

		internal static MelonPreferences_Entry<float> PunchClutchMax;

		internal static MelonPreferences_Entry<float> HeavyClutchDamage;

		internal static MelonPreferences_Entry<float> GunMultEder;

		internal static MelonPreferences_Entry<float> GunMultPistol;

		internal static MelonPreferences_Entry<float> GunMultSMG;

		internal static MelonPreferences_Entry<float> GunMultRifle;

		internal static MelonPreferences_Entry<float> GunMultShotgun;

		internal static MelonPreferences_Entry<float> GunMultHeavy;

		internal static MelonPreferences_Entry<float> UnSnapInterval;

		internal static MelonPreferences_Entry<float> UnSnapRatio;

		internal static MelonPreferences_Entry<float> CounterRatio;

		internal static MelonPreferences_Entry<float> CounterDelay;

		internal static MelonPreferences_Entry<float> PivotBlend;

		internal static MelonPreferences_Entry<float> WhiplashSeconds;

		internal static MelonPreferences_Entry<float> WhiplashStiffness;

		internal static MelonPreferences_Entry<float> HeadLookSeconds;

		internal static MelonPreferences_Entry<float> HeadLookForce;

		internal static MelonPreferences_Entry<bool> HeadAvoid;

		internal static MelonPreferences_Entry<float> HangSeconds;

		internal static MelonPreferences_Entry<int> LastStandMaxRolls;

		internal static MelonPreferences_Entry<float> StaggerSeconds;

		internal static MelonPreferences_Entry<float> MinStaggerSeconds;

		internal static MelonPreferences_Entry<float> UpperBodyStun;

		internal static MelonPreferences_Entry<float> RecoverStun;

		internal static MelonPreferences_Entry<float> HipsKick;

		internal static MelonPreferences_Entry<float> ChestKick;

		internal static MelonPreferences_Entry<float> HeadKick;

		internal static MelonPreferences_Entry<float> SnapSeconds;

		internal static MelonPreferences_Entry<float> StaggerWeight;

		internal static MelonPreferences_Entry<float> StaggerMapping;

		internal static MelonPreferences_Entry<float> UpperMapWeight;

		internal static MelonPreferences_Entry<float> TorsoLift;

		internal static MelonPreferences_Entry<float> ForwardBend;

		internal static MelonPreferences_Entry<float> ShoveForce;

		internal static MelonPreferences_Entry<float> ShoveSeconds;

		internal static MelonPreferences_Entry<float> TorsoStrength;

		internal static MelonPreferences_Entry<float> HeadStrength;

		internal static MelonPreferences_Entry<float> MuscleRecoverSeconds;

		internal static MelonPreferences_Entry<float> MuscleLoosenSeconds;

		internal static MelonPreferences_Entry<float> LegStrength;

		internal static MelonPreferences_Entry<float> LegMapping;

		internal static MelonPreferences_Entry<float> LegHitStrength;

		internal static MelonPreferences_Entry<float> HipAssist;

		internal static MelonPreferences_Entry<float> LimpSway;

		internal static MelonPreferences_Entry<float> OrientToFall;

		internal static MelonPreferences_Entry<float> KneeChance;

		internal static MelonPreferences_Entry<float> DeathArch;

		internal static MelonPreferences_Entry<float> LastStandHp;

		internal static MelonPreferences_Entry<float> LastStandHpAbs;

		internal static MelonPreferences_Entry<float> LastStandChance;

		internal static MelonPreferences_Entry<float> AnimFreezeSeconds;

		internal static MelonPreferences_Entry<float> AdvanceForce;

		internal static MelonPreferences_Entry<int> MaxSteps;

		internal static MelonPreferences_Entry<int> CfgVersion;

		internal static MelonPreferences_Entry<float> MaxStepLength;

		internal static MelonPreferences_Entry<float> SwingSeconds;

		internal static MelonPreferences_Entry<float> SwingForce;

		internal static MelonPreferences_Entry<float> LiftForce;

		internal static MelonPreferences_Entry<float> PlantForce;

		internal static MelonPreferences_Entry<float> SwingLegStrength;

		internal static MelonPreferences_Entry<float> BalanceMargin;

		internal static MelonPreferences_Entry<float> StepMargin;

		internal static MelonPreferences_Entry<float> FallDistance;

		internal static MelonPreferences_Entry<float> FallDrop;

		internal static MelonPreferences_Entry<float> AssistRampSeconds;

		private static readonly Dictionary<int, Clutch> Clutches = new Dictionary<int, Clutch>();

		private static readonly Dictionary<int, Downed> DownedMap = new Dictionary<int, Downed>();

		private static readonly Dictionary<int, NpcWatch> KnownNpcs = new Dictionary<int, NpcWatch>();

		private static int _scanFrame;

		private static int _scanLogs;

		private static readonly Dictionary<int, BalanceState> Balances = new Dictionary<int, BalanceState>();

		private static readonly Dictionary<int, Stagger> Staggers = new Dictionary<int, Stagger>();

		private static readonly Dictionary<int, UnSnap> UnSnaps = new Dictionary<int, UnSnap>();

		private static readonly Dictionary<int, UnSnap> Counters = new Dictionary<int, UnSnap>();

		private static readonly List<int> Finished = new List<int>();

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

		private static readonly Dictionary<int, Vector2> WatchUp = new Dictionary<int, Vector2>();

		private static readonly Dictionary<int, AnimThaw> Thaws = new Dictionary<int, AnimThaw>();

		private static bool _loggedClutch;

		private static int _balanceLogs;

		private static int _staggerLogs;

		private static int _stepLogs;

		private static int _endLogs;

		private static int _styleLogs;

		private static int _strideLogs;

		private static int _rigLogs;

		private static int _meshLogs;

		private static int _clutchDbg;

		private static int _standLogs;

		private static int _peakLogs;

		private static int _floorLogs;

		private static int _floorLastTick;

		private static int _spamTick;

		private static readonly Dictionary<int, Scales> ScaleMap = new Dictionary<int, Scales>();

		private static int _propLogs;

		private static int _mapLogs;

		private static bool MeleeSharp(string attackType)
		{
			if (string.IsNullOrEmpty(attackType))
			{
				return false;
			}
			string text = attackType.ToLowerInvariant();
			if (!text.Contains("stab") && !text.Contains("slash") && !text.Contains("cut") && !text.Contains("claw") && !text.Contains("bite") && !text.Contains("whip"))
			{
				return text.Contains("chop");
			}
			return true;
		}

		private static bool MeleeAxe(string attackType)
		{
			if (string.IsNullOrEmpty(attackType))
			{
				return false;
			}
			return attackType.ToLowerInvariant().Contains("axe");
		}

		private static float MeleeVol(string attackType)
		{
			try
			{
				return MeleeSharp(attackType) ? SharpForce.Value : MeleeForce.Value;
			}
			catch
			{
				return 1f;
			}
		}

		private static bool IsMelee(string attackType)
		{
			if (string.IsNullOrEmpty(attackType))
			{
				return false;
			}
			string text = attackType.ToLowerInvariant();
			if (!text.Contains("blunt") && !text.Contains("stab") && !text.Contains("slash") && !text.Contains("punch") && !text.Contains("melee") && !text.Contains("claw") && !text.Contains("bite") && !text.Contains("cut") && !text.Contains("axe") && !text.Contains("blade") && !text.Contains("bat") && !text.Contains("whip"))
			{
				return text.Contains("chop");
			}
			return true;
		}

		private static bool PunchJab(NpcHitInfo info)
		{
			try
			{
				if (PunchClutchMax.Value <= 0f)
				{
					return false;
				}
				if (MeleeSharp(info.AttackType))
				{
					return false;
				}
				if (RagdollApi.IsEnvImpact(info.AttackType))
				{
					return info.Damage < PunchClutchMax.Value;
				}
				if (!IsMelee(info.AttackType))
				{
					return false;
				}
				return info.Damage < PunchClutchMax.Value;
			}
			catch
			{
				return false;
			}
		}

		private static bool UsesLastStand(PuppetMaster pm, SubBehaviourHealth h)
		{
			try
			{
				try
				{
					if (RagdollApi.IsExcluded(pm))
					{
						return false;
					}
				}
				catch
				{
				}
				if (RagdollApi.IsNullBody(pm))
				{
					return false;
				}
				if (h == null)
				{
					return false;
				}
				if (!IsLowHp(h))
				{
					return false;
				}
				float num;
				try
				{
					num = LastStandChance.Value;
				}
				catch
				{
					num = 0.25f;
				}
				if (num <= 0f)
				{
					return false;
				}
				if (num >= 1f)
				{
					return true;
				}
				int num2 = 0;
				try
				{
					num2 = ((Object)pm).GetInstanceID();
				}
				catch
				{
					return Random.value < num;
				}
				if (LastStandRolls.TryGetValue(num2, out var value))
				{
					return value;
				}
				if (LastStandRolls.Count > 256)
				{
					LastStandRolls.Clear();
				}
				bool flag = Random.value < num;
				LastStandRolls[num2] = flag;
				return flag;
			}
			catch
			{
				return false;
			}
		}

		private static bool IsLowHp(SubBehaviourHealth h)
		{
			try
			{
				if (h == null)
				{
					return false;
				}
				float num = RagdollApi.CurHp(h);
				bool flag = false;
				bool flag2 = false;
				try
				{
					flag = LastStandHpAbs.Value > 0f && num >= 0f && num <= LastStandHpAbs.Value;
				}
				catch
				{
					flag = num >= 0f && num <= 5f;
				}
				try
				{
					flag2 = LastStandHp.Value > 0f && HpFraction(h) < LastStandHp.Value;
				}
				catch
				{
					flag2 = false;
				}
				return flag || flag2;
			}
			catch
			{
				return false;
			}
		}

		private static float CaptureAnimSpeed(Animator ta)
		{
			try
			{
				float speed = ta.speed;
				return (speed > 0.01f) ? speed : 1f;
			}
			catch
			{
				return 1f;
			}
		}

		private static void RestoreAnimSpeed(Animator ta, float stored)
		{
			try
			{
				if ((Object)(object)ta != (Object)null)
				{
					ta.speed = ((stored > 0.01f) ? stored : 1f);
				}
			}
			catch
			{
			}
		}

		private static float DownedAnimSpeed(int id, float staggerBase, Animator ta)
		{
			try
			{
				if (Thaws.TryGetValue(id, out var value) && value.To > 0.01f)
				{
					return value.To;
				}
				if (staggerBase > 0.01f)
				{
					return staggerBase;
				}
				return CaptureAnimSpeed(ta);
			}
			catch
			{
				return 1f;
			}
		}

		public override void OnInitializeMelon()
		{
			//IL_13b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_13b8: Expected O, but got Unknown
			MelonPreferences_Category obj = MelonPreferences.CreateCategory("EuphoriaLite");
			Enabled = obj.CreateEntry<bool>("Enabled", true, "Euphoria layer on/off (clutch, stagger, falls)", (string)null, false, false, (ValueValidator)null, (string)null);
			ClutchSeconds = obj.CreateEntry<float>("ClutchSeconds", 2.5f, "How long the hands are pulled to the wound", (string)null, false, false, (ValueValidator)null, (string)null);
			ClutchAcceleration = obj.CreateEntry<float>("ClutchAcceleration", 60f, "Pull strength on the hands (m/s^2)", (string)null, false, false, (ValueValidator)null, (string)null);
			ArmLooseness = obj.CreateEntry<float>("ArmLooseness", 0.15f, "Arm stun level while clutching (0 = limp, 1 = normal)", (string)null, false, false, (ValueValidator)null, (string)null);
			ClutchDelay = obj.CreateEntry<float>("ClutchDelay", 0.15f, "RAGE CTaskNMShot: reach-for-wound delay 100-200ms (s)", (string)null, false, false, (ValueValidator)null, (string)null);
			HeadClutchChance = obj.CreateEntry<float>("HeadClutchChance", 1f, "Hands reach to head wounds (0-1, 1 = always clutch)", (string)null, false, false, (ValueValidator)null, (string)null);
			BalanceEnabled = obj.CreateEntry<bool>("BalanceEnabled", true, "Legs try to hold the NPC up (off = every medium hit knocks him down)", (string)null, false, false, (ValueValidator)null, (string)null);
			VarietyEnabled = obj.CreateEntry<bool>("VarietyEnabled", true, "No two hits play out the same (kick strength, spin, clutch side)", (string)null, false, false, (ValueValidator)null, (string)null);
			FlipDirection = obj.CreateEntry<bool>("FlipDirection", false, "Set true if NPCs are pushed TOWARD you when shot", (string)null, false, false, (ValueValidator)null, (string)null);
			WalkThrough = obj.CreateEntry<bool>("WalkThrough", true, "Shot NPCs keep walking at you: legs stay game-driven, only the upper body reacts (off = full takeover)", (string)null, false, false, (ValueValidator)null, (string)null);
			FallThreshold = obj.CreateEntry<float>("FallThreshold", 1.6f, "Balance loss at which he falls outright (0 = every hit)", (string)null, false, false, (ValueValidator)null, (string)null);
			GunForce = obj.CreateEntry<float>("GunForce", 0.75f, "Global gun volume: Eder22-level. All kicks, shoves and loss scale off this", (string)null, false, false, (ValueValidator)null, (string)null);
			GunMultEder = obj.CreateEntry<float>("GunMult_Eder", 0.85f, "Eder22 family: weak plinker, stays clearly below shotgun", (string)null, false, false, (ValueValidator)null, (string)null);
			GunMultPistol = obj.CreateEntry<float>("GunMult_Pistol", 1f, "9mm-class pistols (1911 + generic pistol/revolver names): baseline", (string)null, false, false, (ValueValidator)null, (string)null);
			GunMultSMG = obj.CreateEntry<float>("GunMult_SMG", 0.9f, "SMGs: small rounds, rate of fire does the work", (string)null, false, false, (ValueValidator)null, (string)null);
			GunMultRifle = obj.CreateEntry<float>("GunMult_Rifle", 1.15f, "Rifles: full-power rounds hit harder per shot", (string)null, false, false, (ValueValidator)null, (string)null);
			GunMultShotgun = obj.CreateEntry<float>("GunMult_Shotgun", 1.2f, "Shotguns: heavy per-pellet, multi-pellet stacking does the rest", (string)null, false, false, (ValueValidator)null, (string)null);
			GunMultHeavy = obj.CreateEntry<float>("GunMult_Heavy", 1.25f, "Hand cannons (desert/eagle, modded big iron)", (string)null, false, false, (ValueValidator)null, (string)null);
			UnSnapInterval = obj.CreateEntry<float>("UnSnapInterval", 0.12f, "Reverse snap delay after the kick in seconds (ERO unSnapInterval, 0 = next tick)", (string)null, false, false, (ValueValidator)null, (string)null);
			UnSnapRatio = obj.CreateEntry<float>("UnSnapRatio", 1f, "Reverse snap strength vs the kick (ERO unSnapRatio, 0 = off)", (string)null, false, false, (ValueValidator)null, (string)null);
			CounterRatio = obj.CreateEntry<float>("CounterRatio", 0.5f, "Pelvis counter-push vs the kick (ERO counterImpulseMag, 0 = off)", (string)null, false, false, (ValueValidator)null, (string)null);
			CounterDelay = obj.CreateEntry<float>("CounterDelay", 0.033f, "Pelvis counter-push delay after the kick in seconds (ERO counterImpulseDelay)", (string)null, false, false, (ValueValidator)null, (string)null);
			PivotBlend = obj.CreateEntry<float>("PivotBlend", 0.35f, "Feet planted: blend part kicks toward one push, translation over shear (ERO rbPivot, 0 = per-part)", (string)null, false, false, (ValueValidator)null, (string)null);
			WhiplashSeconds = obj.CreateEntry<float>("WhiplashSeconds", 0.25f, "Brief rigidity on impact before going loose (ERO whiplash start phase, 0 = off)", (string)null, false, false, (ValueValidator)null, (string)null);
			WhiplashStiffness = obj.CreateEntry<float>("WhiplashStiffness", 1.3f, "Muscle multiplier during the whiplash window (1 = normal)", (string)null, false, false, (ValueValidator)null, (string)null);
			HeadLookSeconds = obj.CreateEntry<float>("HeadLookSeconds", 0.5f, "Glance at the wound after a hit (ERO shotHeadLook, 0 = off)", (string)null, false, false, (ValueValidator)null, (string)null);
			HeadLookForce = obj.CreateEntry<float>("HeadLookForce", 6f, "Head turn torque toward the wound", (string)null, false, false, (ValueValidator)null, (string)null);
			HeadAvoid = obj.CreateEntry<bool>("HeadAvoid", true, "Keep the head off the ground on the way down (ERO hkHeadAvoid)", (string)null, false, false, (ValueValidator)null, (string)null);
			HangSeconds = obj.CreateEntry<float>("HangSeconds", 60f, "Hang on a grabbed ledge in seconds, then let go (0 = off)", (string)null, false, false, (ValueValidator)null, (string)null);
			MeleeEnabled = obj.CreateEntry<bool>("MeleeEnabled", true, "Melee hits run the same reactions as gunshots (off = skipped, old behavior)", (string)null, false, false, (ValueValidator)null, (string)null);
			MeleeForce = obj.CreateEntry<float>("MeleeForce", 0.65f, "Blunt-melee volume (fists included: Marrow labels those Blunt, indistinguishable)", (string)null, false, false, (ValueValidator)null, (string)null);
			PunchClutchMax = obj.CreateEntry<float>("PunchClutchMax", 1.5f, "Blunt hits below this damage skip the clutch (jabs snap, don't grab). 0 = always clutch", (string)null, false, false, (ValueValidator)null, (string)null);
			HeavyClutchDamage = obj.CreateEntry<float>("HeavyClutchDamage", 3f, "Melee hits at/above this damage clutch as long as stabs (machete chops, axe). 0 = off", (string)null, false, false, (ValueValidator)null, (string)null);
			SharpForce = obj.CreateEntry<float>("SharpForce", 0.4f, "Stab/slash volume: low launch, the wound does the work via SharpClutchSeconds", (string)null, false, false, (ValueValidator)null, (string)null);
			SharpClutchSeconds = obj.CreateEntry<float>("SharpClutchSeconds", 1.6f, "How long stabs are clutched (a cut stays; ~2x the gunshot clutch)", (string)null, false, false, (ValueValidator)null, (string)null);
			BalanceRecovery = obj.CreateEntry<float>("BalanceRecovery", 1f, "Balance loss that drains per second", (string)null, false, false, (ValueValidator)null, (string)null);
			LegGiveWay = obj.CreateEntry<float>("LegGiveWay", 0.5f, "He falls if a leg's stun level is below this (leg shot)", (string)null, false, false, (ValueValidator)null, (string)null);
			FallSeconds = obj.CreateEntry<float>("FallSeconds", 3f, "How long he stays down once he falls", (string)null, false, false, (ValueValidator)null, (string)null);
			FallShove = obj.CreateEntry<float>("FallShove", 3f, "Push on the hit body part when he falls outright", (string)null, false, false, (ValueValidator)null, (string)null);
			FallArmSplay = obj.CreateEntry<float>("FallArmSplay", 3f, "How hard the arms fling out wide as he falls (m/s, 0 = off)", (string)null, false, false, (ValueValidator)null, (string)null);
			StaggerArmFling = obj.CreateEntry<float>("StaggerArmFling", 0.6f, "Startle throw of the arms on every stagger hit (m/s, 0 = off)", (string)null, false, false, (ValueValidator)null, (string)null);
			FlailForce = obj.CreateEntry<float>("FlailForce", 0f, "RAGE armsWindmillAdaptive: slow tightrope sway once clutch lets go (m/s^2, 0 = off)", (string)null, false, false, (ValueValidator)null, (string)null);
			BraceForce = obj.CreateEntry<float>("BraceForce", 45f, "Arms stiffen and reach for the ground while falling (m/s^2, 0 = off)", (string)null, false, false, (ValueValidator)null, (string)null);
			LimbKick = obj.CreateEntry<float>("LimbKick", 2.6f, "Extra yank on the exact limb that was shot (m/s, 0 = off)", (string)null, false, false, (ValueValidator)null, (string)null);
			WritheForce = obj.CreateEntry<float>("WritheForce", 1.5f, "RAGE bodyWrithe: small fast writhe, mostly back/legs not arms (m/s, 0 = off)", (string)null, false, false, (ValueValidator)null, (string)null);
			HandSpeedCap = obj.CreateEntry<float>("HandSpeedCap", 8f, "Hands can never exceed this speed (m/s): makes joint-stretching impossible", (string)null, false, false, (ValueValidator)null, (string)null);
			StaggerSeconds = obj.CreateEntry<float>("StaggerSeconds", 2.6f, "RAGE onFire staggerTime direction: longest a stagger lasts (s)", (string)null, false, false, (ValueValidator)null, (string)null);
			MinStaggerSeconds = obj.CreateEntry<float>("MinStaggerSeconds", 1.5f, "Staggers always play out at least this long (visible reaction)", (string)null, false, false, (ValueValidator)null, (string)null);
			AnimFreezeSeconds = obj.CreateEntry<float>("AnimFreezeSeconds", 0.3f, "How long the animator stays frozen on impact before running again under physics (0 = never freeze)", (string)null, false, false, (ValueValidator)null, (string)null);
			AdvanceForce = obj.CreateEntry<float>("AdvanceForce", 6f, "Stagger drive toward you: shot NPCs keep coming instead of stopping (0 = old statue)", (string)null, false, false, (ValueValidator)null, (string)null);
			StaggerWeight = obj.CreateEntry<float>("StaggerWeight", 0.7f, "RAGE skeleton 100->35: whole-body strength in a stagger (low = floppy)", (string)null, false, false, (ValueValidator)null, (string)null);
			StaggerMapping = obj.CreateEntry<float>("StaggerMapping", 0.3f, "Whole-body animation glue in a stagger (low = physics owns the pose)", (string)null, false, false, (ValueValidator)null, (string)null);
			UpperMapWeight = obj.CreateEntry<float>("UpperMapWeight", 0.1f, "How glued torso/head/arms are to the frozen pose in a stagger (low = they whip and clutch)", (string)null, false, false, (ValueValidator)null, (string)null);
			TorsoLift = obj.CreateEntry<float>("TorsoLift", 18f, "Upward force on the chest during a stagger, stops it folding (m/s^2, 0 = off)", (string)null, false, false, (ValueValidator)null, (string)null);
			ForwardBend = obj.CreateEntry<float>("ForwardBend", 8f, "RAGE staggerFall.alwaysBendForwards: crouch forward at the hip while staggering", (string)null, false, false, (ValueValidator)null, (string)null);
			ShoveForce = obj.CreateEntry<float>("ShoveForce", 12f, "Sustained push along the shot during a stagger, carries him back (m/s^2, 0 = off)", (string)null, false, false, (ValueValidator)null, (string)null);
			ShoveSeconds = obj.CreateEntry<float>("ShoveSeconds", 0.45f, "How long the sustained push lasts", (string)null, false, false, (ValueValidator)null, (string)null);
			SnapSeconds = obj.CreateEntry<float>("SnapSeconds", 0.22f, "Upper-body snap on impact before the struggle starts (0 = off)", (string)null, false, false, (ValueValidator)null, (string)null);
			UpperBodyStun = obj.CreateEntry<float>("UpperBodyStun", 0.1f, "How limp the ARMS go in a stagger (0 = limp, 1 = stiff)", (string)null, false, false, (ValueValidator)null, (string)null);
			TorsoStrength = obj.CreateEntry<float>("TorsoStrength", 0.25f, "RAGE skeleton: spine/chest strength in a stagger (0 = limp, 1 = normal)", (string)null, false, false, (ValueValidator)null, (string)null);
			HeadStrength = obj.CreateEntry<float>("HeadStrength", 0.15f, "RAGE skeleton: head/neck strength in a stagger (neck 100->35-40)", (string)null, false, false, (ValueValidator)null, (string)null);
			LegStrength = obj.CreateEntry<float>("LegStrength", 0.6f, "RAGE lowerBodyStiffness 13->14: stance-leg strength (holds him up)", (string)null, false, false, (ValueValidator)null, (string)null);
			LegHitStrength = obj.CreateEntry<float>("LegHitStrength", 0.3f, "Shot-leg strength in a stagger (limps instead of ragdolling)", (string)null, false, false, (ValueValidator)null, (string)null);
			LegMapping = obj.CreateEntry<float>("LegMapping", 0.15f, "How glued legs are to the walk animation in a stagger (low = physics owns them)", (string)null, false, false, (ValueValidator)null, (string)null);
			MuscleRecoverSeconds = obj.CreateEntry<float>("MuscleRecoverSeconds", 1.6f, "How long spine/head take to stiffen back up afterwards", (string)null, false, false, (ValueValidator)null, (string)null);
			MuscleLoosenSeconds = obj.CreateEntry<float>("MuscleLoosenSeconds", 0.5f, "How fast spine/head go limp after a hit (higher = softer, less collapse)", (string)null, false, false, (ValueValidator)null, (string)null);
			HipAssist = obj.CreateEntry<float>("HipAssist", 30f, "RAGE removed hipLeanAcc/resistAcc cheats: small hip servo back over feet (m/s^2, 0 = off)", (string)null, false, false, (ValueValidator)null, (string)null);
			LimpSway = obj.CreateEntry<float>("LimpSway", 15f, "Side-to-side sway on leg hits, forces weight shifts and limping steps (m/s^2, 0 = off)", (string)null, false, false, (ValueValidator)null, (string)null);
			OrientToFall = obj.CreateEntry<float>("OrientToFall", 6f, "RAGE highFall.orientateBodyToFallDirection: chest steers toward travel dir", (string)null, false, false, (ValueValidator)null, (string)null);
			KneeChance = obj.CreateEntry<float>("KneeChance", 0.7f, "Gut shots (torso/hips) that would fall become a long stagger instead (0 = guts always trip, 1 = guts never trip)", (string)null, false, false, (ValueValidator)null, (string)null);
			LastStandHp = obj.CreateEntry<float>("LastStandHp", 0.15f, "Fallback fraction gate when absolute HP is unreadable (0 = off)", (string)null, false, false, (ValueValidator)null, (string)null);
			LastStandHpAbs = obj.CreateEntry<float>("LastStandHpAbs", 5f, "Absolute HP at/below which last stand triggers even above the fraction gate (0 = off)", (string)null, false, false, (ValueValidator)null, (string)null);
			LastStandChance = obj.CreateEntry<float>("LastStandChance", 0.25f, "Chance a near-dead NPC enters last stand at 5hp (0 = never, 1 = always). Roll is per-NPC; losers keep fighting", (string)null, false, false, (ValueValidator)null, (string)null);
			DeathArch = obj.CreateEntry<float>("DeathArch", 2f, "RAGE smartFall: brief rigid arch on death before going limp (m/s, 0 = off)", (string)null, false, false, (ValueValidator)null, (string)null);
			RecoverStun = obj.CreateEntry<float>("RecoverStun", 0.7f, "Where upper-body stiffness restarts from afterwards (higher = recovers faster)", (string)null, false, false, (ValueValidator)null, (string)null);
			HipsKick = obj.CreateEntry<float>("HipsKick", 1.4f, "Instant speed given to the hips along the push (m/s)", (string)null, false, false, (ValueValidator)null, (string)null);
			ChestKick = obj.CreateEntry<float>("ChestKick", 2.4f, "Instant speed given to the chest along the push (m/s)", (string)null, false, false, (ValueValidator)null, (string)null);
			HeadKick = obj.CreateEntry<float>("HeadKick", 2f, "Instant speed given to the head along the push (m/s)", (string)null, false, false, (ValueValidator)null, (string)null);
			MaxSteps = obj.CreateEntry<int>("MaxSteps", 8, "Most catch-steps before he gives up and falls", (string)null, false, false, (ValueValidator)null, (string)null);
			LastStandMaxRolls = obj.CreateEntry<int>("LastStandMaxRolls", 3, "How many times a last stand extends before he gets up anyway (0 = forever)", (string)null, false, false, (ValueValidator)null, (string)null);
			MaxStepLength = obj.CreateEntry<float>("MaxStepLength", 0.6f, "Longest single catch-step (m)", (string)null, false, false, (ValueValidator)null, (string)null);
			SwingSeconds = obj.CreateEntry<float>("SwingSeconds", 0.2f, "How long a foot swing takes", (string)null, false, false, (ValueValidator)null, (string)null);
			SwingForce = obj.CreateEntry<float>("SwingForce", 100f, "Force swinging the stepping foot (m/s^2)", (string)null, false, false, (ValueValidator)null, (string)null);
			LiftForce = obj.CreateEntry<float>("LiftForce", 55f, "Force lifting the stepping foot so steps stomp, not slide (m/s^2)", (string)null, false, false, (ValueValidator)null, (string)null);
			PlantForce = obj.CreateEntry<float>("PlantForce", 70f, "Force stomping the foot down to grip (m/s^2)", (string)null, false, false, (ValueValidator)null, (string)null);
			SwingLegStrength = obj.CreateEntry<float>("SwingLegStrength", 0.45f, "Muscle strength of the stepping leg while it swings (lower = freer)", (string)null, false, false, (ValueValidator)null, (string)null);
			BalanceMargin = obj.CreateEntry<float>("BalanceMargin", 0.12f, "Centre of mass this close to his feet counts as balanced (m)", (string)null, false, false, (ValueValidator)null, (string)null);
			StepMargin = obj.CreateEntry<float>("StepMargin", 0.05f, "Centre of mass this far out triggers a catch-step (lower = steps constantly)", (string)null, false, false, (ValueValidator)null, (string)null);
			FallDistance = obj.CreateEntry<float>("FallDistance", 0.9f, "Centre of mass this far outside his feet = he can't recover (m)", (string)null, false, false, (ValueValidator)null, (string)null);
			FallDrop = obj.CreateEntry<float>("FallDrop", 0.55f, "Hips dropping this much = he's falling (m)", (string)null, false, false, (ValueValidator)null, (string)null);
			AssistRampSeconds = obj.CreateEntry<float>("AssistRampSeconds", 1f, "Hip servo ramps up over this long (early = flies with the shot, late = caught)", (string)null, false, false, (ValueValidator)null, (string)null);
			CfgVersion = obj.CreateEntry<int>("CfgVersion", 62, "Do not edit: resets tuning when the mod updates", (string)null, false, false, (ValueValidator)null, (string)null);
			if (CfgVersion.Value < 49)
			{
				Enabled.Value = true;
				ClutchSeconds.Value = 0.8f;
				ClutchAcceleration.Value = 60f;
				ArmLooseness.Value = 0.15f;
				ClutchDelay.Value = 0.15f;
				HeadClutchChance.Value = 0.25f;
				BalanceEnabled.Value = true;
				VarietyEnabled.Value = true;
				FlipDirection.Value = false;
				FallThreshold.Value = 1.6f;
				BalanceRecovery.Value = 1f;
				LegGiveWay.Value = 0.5f;
				GunForce.Value = 0.65f;
				LastStandHp.Value = 0.15f;
				LastStandHpAbs.Value = 5f;
				FallSeconds.Value = 3f;
				FallShove.Value = 3f;
				FallArmSplay.Value = 3f;
				StaggerArmFling.Value = 0.6f;
				FlailForce.Value = 0f;
				BraceForce.Value = 45f;
				LimbKick.Value = 2.6f;
				WritheForce.Value = 1.5f;
				StaggerSeconds.Value = 2.6f;
				MinStaggerSeconds.Value = 1.5f;
				UpperBodyStun.Value = 0.1f;
				SnapSeconds.Value = 0.22f;
				StaggerWeight.Value = 0.7f;
				StaggerMapping.Value = 0.3f;
				UpperMapWeight.Value = 0.1f;
				TorsoLift.Value = 18f;
				ForwardBend.Value = 8f;
				ShoveForce.Value = 10f;
				ShoveSeconds.Value = 0.55f;
				TorsoStrength.Value = 0.25f;
				HeadStrength.Value = 0.15f;
				LegStrength.Value = 0.6f;
				LegHitStrength.Value = 0.3f;
				MuscleRecoverSeconds.Value = 1.6f;
				MuscleLoosenSeconds.Value = 0.5f;
				HipAssist.Value = 30f;
				RecoverStun.Value = 0.7f;
				OrientToFall.Value = 6f;
				KneeChance.Value = 0.28f;
				DeathArch.Value = 2f;
				HipsKick.Value = 1.8f;
				ChestKick.Value = 3.6f;
				HeadKick.Value = 2f;
				MaxSteps.Value = 8;
				MaxStepLength.Value = 0.6f;
				SwingSeconds.Value = 0.2f;
				SwingForce.Value = 100f;
				LiftForce.Value = 55f;
				PlantForce.Value = 70f;
				SwingLegStrength.Value = 0.45f;
				BalanceMargin.Value = 0.12f;
				StepMargin.Value = 0.05f;
				FallDistance.Value = 0.9f;
				FallDrop.Value = 0.55f;
				AssistRampSeconds.Value = 1f;
				CfgVersion.Value = 49;
				MelonPreferences.Save();
			}
			if (CfgVersion.Value < 50)
			{
				PunchClutchMax.Value = 1.5f;
				ShoveSeconds.Value = 0.45f;
				ChestKick.Value = 3f;
				CfgVersion.Value = 50;
				MelonPreferences.Save();
			}
			if (CfgVersion.Value < 51)
			{
				LastStandHpAbs.Value = 5f;
				LastStandChance.Value = 0.25f;
				CfgVersion.Value = 51;
				MelonPreferences.Save();
			}
			if (CfgVersion.Value < 52)
			{
				try
				{
					if (Math.Abs(GunForce.Value - 0.65f) < 0.01f)
					{
						GunForce.Value = 0.75f;
					}
				}
				catch
				{
				}
				CfgVersion.Value = 52;
				MelonPreferences.Save();
			}
			if (CfgVersion.Value < 53)
			{
				try
				{
					if (Math.Abs(HipsKick.Value - 1.8f) < 0.01f)
					{
						HipsKick.Value = 1.4f;
					}
				}
				catch
				{
				}
				try
				{
					if (Math.Abs(ChestKick.Value - 3f) < 0.01f)
					{
						ChestKick.Value = 2.4f;
					}
				}
				catch
				{
				}
				CfgVersion.Value = 53;
				MelonPreferences.Save();
			}
			if (CfgVersion.Value < 54)
			{
				try
				{
					if (Math.Abs(ClutchSeconds.Value - 0.8f) < 0.01f)
					{
						ClutchSeconds.Value = 2.5f;
					}
				}
				catch
				{
				}
				CfgVersion.Value = 54;
				MelonPreferences.Save();
			}
			if (CfgVersion.Value < 55)
			{
				try
				{
					if (Math.Abs(UnSnapRatio.Value - 0.6f) < 0.01f)
					{
						UnSnapRatio.Value = 0.75f;
					}
				}
				catch
				{
				}
				CfgVersion.Value = 55;
				MelonPreferences.Save();
			}
			if (CfgVersion.Value < 56)
			{
				try
				{
					if (Math.Abs(UnSnapRatio.Value - 0.75f) < 0.01f)
					{
						UnSnapRatio.Value = 0.9f;
					}
				}
				catch
				{
				}
				CfgVersion.Value = 56;
				MelonPreferences.Save();
			}
			if (CfgVersion.Value < 57)
			{
				try
				{
					if (Math.Abs(UnSnapRatio.Value - 0.9f) < 0.01f)
					{
						UnSnapRatio.Value = 1f;
					}
				}
				catch
				{
				}
				CfgVersion.Value = 57;
				MelonPreferences.Save();
			}
			if (CfgVersion.Value < 58)
			{
				try
				{
					if (Math.Abs(HangSeconds.Value - 5f) < 0.01f)
					{
						HangSeconds.Value = 6f;
					}
				}
				catch
				{
				}
				try
				{
					if (Math.Abs(HangSeconds.Value - 8f) < 0.01f)
					{
						HangSeconds.Value = 6f;
					}
				}
				catch
				{
				}
				CfgVersion.Value = 58;
				MelonPreferences.Save();
			}
			if (CfgVersion.Value < 59)
			{
				try
				{
					if (Math.Abs(HangSeconds.Value - 5f) < 0.01f)
					{
						HangSeconds.Value = 6f;
					}
				}
				catch
				{
				}
				CfgVersion.Value = 59;
				MelonPreferences.Save();
			}
			if (CfgVersion.Value < 60)
			{
				try
				{
					if (Math.Abs(HangSeconds.Value - 6f) < 0.01f)
					{
						HangSeconds.Value = 10f;
					}
				}
				catch
				{
				}
				CfgVersion.Value = 60;
				MelonPreferences.Save();
			}
			if (CfgVersion.Value < 61)
			{
				try
				{
					if (Math.Abs(KneeChance.Value - 0.28f) < 0.01f)
					{
						KneeChance.Value = 0.7f;
					}
				}
				catch
				{
				}
				CfgVersion.Value = 61;
				MelonPreferences.Save();
			}
			if (CfgVersion.Value < 62)
			{
				try
				{
					if (Math.Abs(HeadClutchChance.Value - 0.25f) < 0.01f)
					{
						HeadClutchChance.Value = 1f;
					}
				}
				catch
				{
				}
				CfgVersion.Value = 62;
				MelonPreferences.Save();
			}
			if (CfgVersion.Value < 63)
			{
				try
				{
					if (Math.Abs(HangSeconds.Value - 10f) < 0.01f)
					{
						HangSeconds.Value = 60f;
					}
				}
				catch
				{
				}
				CfgVersion.Value = 63;
				MelonPreferences.Save();
			}
			RagdollApi.AutoKnockdown = !BalanceEnabled.Value;
			RagdollApi.OnNpcHit += OnHit;
			try
			{
				RagdollApi.OnEnvHandTouch += OnHandTouch;
			}
			catch
			{
			}
			string value = "1.0.86";
			try
			{
				MelonInfoAttribute val = (MelonInfoAttribute)Attribute.GetCustomAttribute(typeof(EuphoriaLiteMod).Assembly, typeof(MelonInfoAttribute));
				if (val != null && !string.IsNullOrEmpty(val.Version))
				{
					value = val.Version;
				}
			}
			catch
			{
			}
			((MelonBase)this).LoggerInstance.Msg($"DynamicRagdoll {value} loaded (balance {(BalanceEnabled.Value ? "ON" : "off")}).");
			((MelonBase)this).LoggerInstance.Msg($"Tuning: torso={TorsoStrength.Value:F2} head={HeadStrength.Value:F2} steps={MaxSteps.Value} margin={BalanceMargin.Value:F2} fallDrop={FallDrop.Value:F2} hipAssist={HipAssist.Value:F0}");
		}

		public override void OnDeinitializeMelon()
		{
			RagdollApi.OnNpcHit -= OnHit;
			try
			{
				RagdollApi.OnEnvHandTouch -= OnHandTouch;
			}
			catch
			{
			}
			RagdollApi.AutoKnockdown = true;
		}

		public override void OnSceneWasLoaded(int buildIndex, string sceneName)
		{
			KnownNpcs.Clear();
			Balances.Clear();
			Staggers.Clear();
			UnSnaps.Clear();
			Counters.Clear();
			Hangs.Clear();
			Clutches.Clear();
			DownedMap.Clear();
			ScaleMap.Clear();
			Thaws.Clear();
			Finished.Clear();
			LastStandRolls.Clear();
			WatchUp.Clear();
			GrabbedAt.Clear();
			try
			{
				MenuPage.EnsureBuilt();
			}
			catch
			{
			}
		}

		public override void OnLateUpdate()
		{
			if (DownedMap.Count == 0 && Staggers.Count == 0)
			{
				return;
			}
			foreach (KeyValuePair<int, Downed> item in DownedMap)
			{
				Downed value = item.Value;
				if (!((Object)(object)value.Pm == (Object)null))
				{
					try
					{
						value.Pm.mappingWeight = 0.3f;
						value.Pm.muscleWeight = 0f;
					}
					catch
					{
					}
				}
			}
			foreach (KeyValuePair<int, Stagger> stagger in Staggers)
			{
				Stagger value2 = stagger.Value;
				if (!((Object)(object)value2.Pm == (Object)null))
				{
					try
					{
						value2.Pm.mappingWeight = StaggerMapping.Value;
					}
					catch
					{
					}
				}
			}
		}

		private static void OnHit(NpcHitInfo info)
		{
			//IL_032c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0332: Invalid comparison between Unknown and I4
			//IL_0335: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//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_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: 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_0295: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)info.Puppet == (Object)null || RagdollApi.IsExcluded(info.Puppet))
			{
				return;
			}
			try
			{
				Il2CppReferenceArray<Muscle> muscles = info.Puppet.muscles;
				if (muscles == null || ((Il2CppArrayBase<Muscle>)(object)muscles).Length != 17)
				{
					if (_rigLogs < 3)
					{
						_rigLogs++;
						string value = "?";
						try
						{
							value = ((Object)info.Puppet).name;
						}
						catch
						{
						}
						MelonLogger.Msg($"Rig gate: skipping non-humanoid '{value}' ({((Il2CppArrayBase<Muscle>)(object)muscles)?.Length ?? (-1)} muscles)");
					}
					return;
				}
			}
			catch
			{
			}
			try
			{
				int instanceID = ((Object)info.Puppet).GetInstanceID();
				if (!KnownNpcs.ContainsKey(instanceID))
				{
					if (KnownNpcs.Count > 64)
					{
						KnownNpcs.Clear();
					}
					KnownNpcs[instanceID] = new NpcWatch
					{
						Pm = info.Puppet,
						Hips = BodyOf(info.Puppet, 0)
					};
				}
			}
			catch
			{
			}
			if (info.IsDead)
			{
				try
				{
					if (DeathArch.Value > 0f && (Object)(object)info.Body != (Object)null)
					{
						Rigidbody val = BodyOf(info.Puppet, 8);
						if ((Object)(object)val != (Object)null)
						{
							Vector3 val2 = Vector3.up * 0.8f - info.Direction * 0.4f;
							val.AddForce(((Vector3)(ref val2)).normalized * DeathArch.Value, (ForceMode)2);
						}
						info.Body.AddForce(info.Direction * DeathArch.Value * 0.6f, (ForceMode)2);
					}
				}
				catch
				{
				}
				ReleaseAllNow(info.Puppet);
				try
				{
					if ((Object)(object)info.Puppet != (Object)null && !RagdollApi.IsExcluded(info.Puppet))
					{
						info.Puppet.muscleWeight = RagdollApi.DeathMuscle;
					}
					return;
				}
				catch
				{
					return;
				}
			}
			if (!Enabled.Value || (IsMelee(info.AttackType) && !MeleeEnabled.Value))
			{
				return;
			}
			try
			{
				int num = 0;
				try
				{
					num = (((Object)(object)info.Puppet != (Object)null) ? ((Object)info.Puppet).GetInstanceID() : 0);
				}
				catch
				{
				}
				if (num != 0 && Hangs.TryGetValue(num, out var value2) && value2 != null && Time.time < value2.Until)
				{
					if ((int)info.Tier == 0)
					{
						return;
					}
					Hangs.Remove(num);
					ReleaseHang(value2);
				}
			}
			catch
			{
			}
			if (Enabled.Value)
			{
				bool flag = false;
				try
				{
					flag = PunchJab(info);
				}
				catch
				{
				}
				if (!flag)
				{
					StartClutch(info);
				}
				else
				{
					try
					{
						SnapUpperBody(info.Puppet, info.Health);
					}
					catch
					{
					}
					try
					{
						FlingArms(info.Puppet, Mathf.Max(0.6f, StaggerArmFling.Value));
					}
					catch
					{
					}
				}
			}
			if (BalanceEnabled.Value && ((int)info.Tier == 1 || (int)info.Tier == 0))
			{
				HandleBalance(info);
			}
		}

		internal static void ReleaseAllNow(PuppetMaster pm)
		{
			int instanceID;
			try
			{
				instanceID = ((Object)pm).GetInstanceID();
			}
			catch
			{
				return;
			}
			if (!ScaleMap.TryGetValue(instanceID, out var value))
			{
				return;
			}
			try
			{
				for (int i = 0; i < 17; i++)
				{
					Muscle val = MuscleOf(pm, i);
					if (val != null)
					{
						if (!float.IsNaN(value.Original[i]))
						{
							val.props.muscleWeight = value.Original[i];
						}
						if (!float.IsNaN(value.OriginalMap[i]))
						{
							val.props.mappingWeight = value.OriginalMap[i];
						}
					}
				}
			}
			catch
			{
			}
			ScaleMap.Remove(instanceID);
		}

		private static int CarryRolls(int key)
		{
			try
			{
				if (DownedMap.TryGetValue(key, out var value) && value != null)
				{
					return value.Rolls;
				}
			}
			catch
			{
			}
			return 0;
		}

		private static void ExtendClutch(Clutch c, float until)
		{
			try
			{
				if (c != null)
				{
					UpgradeClutch(c);
					c.Until = Mathf.Max(c.Until, until);
				}
			}
			catch
			{
			}
		}

		private static void HandleBalance(NpcHitInfo info)
		{
			//IL_05be: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d3: 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_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Invalid comparison between Unknown and I4
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Invalid comparison between Unknown and I4
			//IL_04fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_024b: Invalid comparison between Unknown and I4
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0254: Invalid comparison between Unknown and I4
			PuppetMaster puppet = info.Puppet;
			int instanceID = ((Object)puppet).GetInstanceID();
			float time = Time.time;
			if (!Balances.TryGetValue(instanceID, out var value))
			{
				if (Balances.Count > 256)
				{
					Balances.Clear();
				}
				value = new BalanceState();
				Balances[instanceID] = value;
			}
			float num = time - value.LastTime;
			float num2 = Impulse(info);
			bool pellet = false;
			if (num < 0.12f)
			{
				value.WindowCount++;
				num2 *= 0.3f;
				if (value.WindowCount >= 3)
				{
					pellet = true;
				}
			}
			else
			{
				value.WindowCount = 1;
			}
			value.LastWindowEnd = time;
			value.Loss = Mathf.Max(0f, value.Loss - BalanceRecovery.Value * num) + num2;
			value.LastTime = time;
			bool flag = false;
			if (info.Health != null)
			{
				float limbStun = RagdollApi.GetLimbStun(info.Health, (MuscleRegion)6);
				float limbStun2 = RagdollApi.GetLimbStun(info.Health, (MuscleRegion)7);
				if ((int)info.Region == 6 || (int)info.Region == 7)
				{
					flag = limbStun < LegGiveWay.Value * 0.5f || limbStun2 < LegGiveWay.Value * 0.5f;
				}
				else
				{
					float num3 = LegGiveWay.Value * 0.5f;
					flag = Mathf.Min(limbStun, limbStun2) < num3;
				}
			}
			if ((int)info.Tier == 0)
			{
				flag = false;
			}
			bool flag2 = value.Loss >= FallThreshold.Value || flag;
			if (_balanceLogs < 15)
			{
				_balanceLogs++;
				MelonLogger.Msg($"Balance: region={info.Region} loss={value.Loss:F2}/{FallThreshold.Value:F2} legsGaveWay={flag} -> {(flag2 ? "FALL" : "STAGGER")}");
			}
			if (flag2)
			{
				if (((int)info.Region == 2 || (int)info.Region == 1) && KneeChance.Value > 0f && Random.value < KneeChance.Value)
				{
					value.Loss = FallThreshold.Value * 0.55f;
					if (_balanceLogs < 15)
					{
						_balanceLogs++;
						MelonLogger.Msg("Balance: gut-shot -> knees (long stagger instead of fall)");
					}
					StartStagger(info, instanceID, pellet);
					if (Staggers.TryGetValue(instanceID, out var value2))
					{
						value2.Steps = -2;
						value2.StartedAt -= 0.4f;
					}
					return;
				}
				value.Loss = 0f;
				bool flag3 = false;
				bool flag4 = false;
				try
				{
					flag4 = IsLowHp(info.Health);
				}
				catch
				{
				}
				try
				{
					flag3 = UsesLastStand(puppet, info.Health);
				}
				catch
				{
				}
				if (flag4 && !flag3)
				{
					bool flag5 = false;
					try
					{
						flag5 = RagdollApi.IsNullBody(puppet);
					}
					catch
					{
					}
					if (!flag5)
					{
						value.Loss = FallThreshold.Value * 0.55f;
						if (_balanceLogs < 15)
						{
							_balanceLogs++;
							MelonLogger.Msg($"Balance: 5hp roll lost (chance={LastStandChance.Value:F2}) -> keeps fighting (stagger, cur={RagdollApi.CurHp(info.Health):F0}hp)");
						}
						StartStagger(info, instanceID, pellet);
						return;
					}
				}
				if (Staggers.TryGetValue(instanceID, out var value3))
				{
					GiveBackStun(value3);
					Staggers.Remove(instanceID);
				}
				float num4 = FallSeconds.Value;
				try
				{
					if (flag3)
					{
						num4 *= 3f;
						if (_balanceLogs < 15)
						{
							_balanceLogs++;
							MelonLogger.Msg($"Balance: last stand (long floor clutch, cur={RagdollApi.CurHp(info.Health):F0}hp)");
						}
					}
				}
				catch
				{
				}
				RagdollApi.KnockDown(puppet, info.Health, num4);
				RagdollApi.HoldLoco(puppet, num4);
				RagdollApi.HoldNav(puppet, num4);
				RagdollApi.HoldLiteLoco(puppet, num4);
				if ((Object)(object)info.Body != (Object)null && FallShove.Value > 0f)
				{
					info.Body.AddForce(info.Direction * FallShove.Value * (IsMelee(info.AttackType) ? MeleeVol(info.AttackType) : GunForce.Value), (ForceMode)2);
				}
				FlingArms(puppet, FallArmSplay.Value);
				Rigidbody[] array = ((value3 != null) ? value3.Bodies : BodiesOf(puppet));
				if (array != null)
				{
					if (DownedMap.Count > 64)
					{
						DownedMap.Clear();
					}
					bool flag6 = false;
					try
					{
						flag6 = RagdollApi.SetGetupDisabled(puppet, true);
					}
					catch
					{
					}
					bool lastStand = flag3;
					Downed downed = new Downed
					{
						Pm = puppet,
						Health = info.Health,
						Bodies = array,
						Until = time + num4,
						NextWrithe = time + Random.Range(0.15f, 0.3f),
						Landed = false,
						LastStand = lastStand,
						Rolls = CarryRolls(instanceID),
						Region = info.Region,
						NextStir = time + Random.Range(2f, 3f)
					};
					try
					{
						Animator targetAnimator = puppet.targetAnimator;
						if ((Object)(object)targetAnimator != (Object)null)
						{
							downed.Anim = targetAnimator;
							downed.AnimSpeed = DownedAnimSpeed(instanceID, value3?.TargetSpeed ?? 0f, targetAnimator);
							downed.HasAnim = true;
						}
					}
					catch
					{
					}
					DownedMap[instanceID] = downed;
					Thaws.Remove(instanceID);
					if (_balanceLogs < 15)
					{
						_balanceLogs++;
						MelonLogger.Msg($"Downed: getup lock {(flag6 ? "HELD" : "FAILED")} for {num4:F0}s");
					}
				}
				if (Clutches.TryGetValue(instanceID, out var value4))
				{
					ExtendClutch(value4, time + num4);
				}
				else
				{
					if (!Enabled.Value || !((Object)(object)info.Body != (Object)null))
					{
						return;
					}
					try
					{
						StartClutch(info, force: true);
						if (Clutches.TryGetValue(instanceID, out var value5))
						{
							value5.Until = Mathf.Max(value5.Until, time + num4);
						}
					}
					catch
					{
					}
				}
			}
			else
			{
				StartStagger(info, instanceID, pellet);
			}
		}

		private static float GunMult(string gun)
		{
			if (string.IsNullOrEmpty(gun))
			{
				return 1f;
			}
			string text = gun.ToLowerInvariant();
			try
			{
				if (text.Contains("eder"))
				{
					return GunMultEder.Value;
				}
				if (text.Contains("mp5") || text.Contains("mp7") || text.Contains("uzi") || text.Contains("scorpion") || text.Contains("mac-"))
				{
					return GunMultSMG.Value;
				}
				if (text.Contains("m4") || text.Contains("mk18") || text.Contains("m16") || text.Contains("akm") || text.Contains("scar"))
				{
					return GunMultRifle.Value;
				}
				if (text.Contains("590") || text.Contains("shotgun"))
				{
					return GunMultShotgun.Value;
				}
				if (text.Contains("desert") || text.Contains("eagle"))
				{
					return GunMultHeavy.Value;
				}
				if (text.Contains("1911") || text.Contains("pistol") || text.Contains("revolver") || text.Contains("glock"))
				{
					return GunMultPistol.Value;
				}
				return 1f;
			}
			catch
			{
				return 1f;
			}
		}

		private static float VolMul(Stagger s)
		{
			try
			{
				return s.Env ? RagdollApi.EnvForce : (s.Sharp ? SharpForce.Value : (s.Melee ? MeleeForce.Value : (GunForce.Value * s.GunMul)));
			}
			catch
			{
				return 1f;
			}
		}

		private static float HpFraction(SubBehaviourHealth h)
		{
			try
			{
				return RagdollApi.HpFraction(h);
			}
			catch
			{
				return 1f;
			}
		}

		private static float Impulse(NpcHitInfo info)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected I4, but got Unknown
			float num = ((info.Damage > 0f) ? info.Damage : 0.9f);
			MuscleRegion region = info.Region;
			float num2;
			switch (region - 1)
			{
			case 2:
				num2 = 1.3f;
				break;
			case 3:
			case 4:
				num2 = 0.5f;
				break;
			case 5:
			case 6:
				num2 = 1.1f;
				break;
			case 0:
			case 1:
				num2 = 0.85f;
				break;
			default:
				num2 = 1f;
				break;
			}
			float num3 = num * num2;
			if (VarietyEnabled.Value)
			{
				num3 *= Random.Range(0.85f, 1.2f);
			}
			return num3 * (RagdollApi.IsEnvImpact(info.AttackType) ? RagdollApi.EnvForce : (IsMelee(info.AttackType) ? MeleeVol(info.AttackType) : GunForce.Value));
		}

		private static void OnHandTouch(EnvHandTouch t)
		{
			//IL_06e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_06eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_073f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0741: Unknown result type (might be due to invalid IL or missing references)
			//IL_02af: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_06f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0703: Unknown result type (might be due to invalid IL or missing references)
			//IL_0708: Unknown result type (might be due to invalid IL or missing references)
			//IL_070d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0373: Unknown result type (might be due to invalid IL or missing references)
			//IL_0381: 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_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_026a: Unknown result type (might be due to invalid IL or missing references)
			if (t == null || !t.HasPoint)
			{
				return;
			}
			PuppetMaster puppet = t.Puppet;
			if ((Object)(object)puppet == (Object)null)
			{
				return;
			}
			float num = 0f;
			try
			{
				num = HangSeconds.Value;
			}
			catch
			{
			}
			if (num <= 0f)
			{
				if (_hangRejectLogs < 6)
				{
					_hangRejectLogs++;
					MelonLogger.Msg("Hang reject: HangSeconds is 0 (off)");
				}
				return;
			}
			num = Mathf.Max(1f, num);
			float time = Time.time;
			int num2 = 0;
			try
			{
				num2 = ((Object)puppet).GetInstanceID();
			}
			catch
			{
				return;
			}
			try
			{
				if (!puppet.isAlive || puppet.isKilling || RagdollApi.IsExcluded(puppet))
				{
					return;
				}
				Il2CppReferenceArray<Muscle> muscles = puppet.muscles;
				if (muscles == null || ((Il2CppArrayBase<Muscle>)(object)muscles).Length != 17)
				{
					return;
				}
			}
			catch
			{
				return;
			}
			try
			{
				if (DownedMap.TryGetValue(num2, out var value) && value != null && time < value.Until)
				{
					if (_hangRejectLogs < 6)
					{
						_hangRejectLogs++;
						MelonLogger.Msg($"Hang reject npc={num2:X8}: downed");
					}
					return;
				}
				if (Hangs.TryGetValue(num2, out var value2) && value2 != null)
				{
					return;
				}
			}
			catch
			{
			}
			Rigidbody[] array = null;
			Rigidbody val = null;
			Rigidbody val2 = null;
			try
			{
				array = BodiesOf(puppet);
				if (array == null)
				{
					return;
				}
				val = array[0];
				val2 = array[(t.MuscleIndex == 15) ? 15 : 12];
			}
			catch
			{
			}
			if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null)
			{
				if (_hangRejectLogs < 6)
				{
					_hangRejectLogs++;
					MelonLogger.Msg($"Hang reject npc={num2:X8}: no bodies");
				}
				return;
			}
			try
			{
				Vector3 normal = t.Normal;
				float magnitude = ((Vector3)(ref normal)).magnitude;
				if (magnitude > 0.001f && Mathf.Abs(normal.y / magnitude) > 0.5f)
				{
					if (_hangRejectLogs < 6)
					{
						_hangRejectLogs++;
						MelonLogger.Msg($"Hang reject npc={num2:X8}: floor normal (ny={normal.y / magnitude:F2})");
					}
					return;
				}
			}
			catch
			{
			}
			bool flag = false;
			Stagger value3 = null;
			float num3 = 0f;
			try
			{
				num3 = val.velocity.y;
			}
			catch
			{
			}
			try
			{
				Staggers.TryGetValue(num2, out value3);
			}
			catch
			{
			}
			try
			{
				flag = ((value3 == null || !value3.Bracing) ? (num3 < -1f) : (num3 < -0.5f));
			}
			catch
			{
			}
			if (!flag)
			{
				if (_hangRejectLogs < 6)
				{
					_hangRejectLogs++;
					MelonLogger.Msg($"Hang reject npc={num2:X8}: not falling (vy={num3:F1})");
				}
				return;
			}
			try
			{
				float y = val.position.y;
				float y2 = val2.position.y;
				float num4 = Mathf.Min(((Object)(object)array[3] != (Object)null) ? array[3].position.y : 999f, ((Object)(object)array[6] != (Object)null) ? array[6].position.y : 999f);
				if (y2 < y + 0.35f)
				{
					if (_hangRejectLogs < 6)
					{
						_hangRejectLogs++;
						MelonLogger.Msg($"Hang reject npc={num2:X8}: geometry (hipsY={y:F2} handY={y2:F2})");
					}
					return;
				}
				if (y2 < num4 + 0.8f)
				{
					if (_hangRejectLogs < 6)
					{
						_hangRejectLogs++;
						MelonLogger.Msg($"Hang reject npc={num2:X8}: hand near ground (handY={y2:F2} feetY={num4:F2})");
					}
					return;
				}
				if (y < num4 + 0.4f)
				{
					if (_hangRejectLogs < 6)
					{
						_hangRejectLogs++;
						MelonLogger.Msg($"Hang reject npc={num2:X8}: body on ground (hipsY={y:F2} feetY={num4:F2})");
					}
					return;
				}
				if (FeetSupported(array))
				{
					if (_hangRejectLogs < 6)
					{
						_hangRejectLogs++;
						MelonLogger.Msg($"Hang reject npc={num2:X8}: feet supported");
					}
					return;
				}
				if (TorsoSupported(array))
				{
					if (_hangRejectLogs < 6)
					{
						_hangRejectLogs++;
						MelonLogger.Msg($"Hang reject npc={num2:X8}: torso grounded");
					}
					return;
				}
			}
			catch
			{
				return;
			}
			try
			{
				if (value3 != null)
				{
					GiveBackStun(value3);
					Staggers.Remove(num2);
				}
			}
			catch
			{
			}
			if (Hangs.Count > 64)
			{
				Hangs.Clear();
			}
			try
			{
				if (GrabbedAt.Count > 64)
				{
					GrabbedAt.Clear();
				}
				float value4 = -100f;
				if (GrabbedAt.TryGetValue(num2, out value4) && time - value4 < 20f)
				{
					return;
				}
			}
			catch
			{
			}
			bool flag2 = t.MuscleIndex != 15;
			Vector3 point = t.Point;
			try
			{
				point = t.Point + ((Vector3)(ref t.Normal)).normalized * 0.06f;
			}
			catch
			{
			}
			Hangs[num2] = new Hang
			{
				Pm = puppet,
				Bodies = array,
				Hand = val2,
				Left = flag2,
				Point = point,
				Until = time + num
			};
			try
			{
				GrabbedAt[num2] = time;
			}
			catch
			{
			}
			try
			{
				RagdollApi.HoldLoco(puppet, num + 0.5f);
				RagdollApi.HoldNav(puppet, num + 0.5f);
				RagdollApi.HoldLiteLoco(puppet, num + 0.5f);
				RagdollApi.HoldMapping(puppet, num + 0.6f, StaggerMapping.Value);
			}
			catch
			{
			}
			if (_hangLogs < 6)
			{
				_hangLogs++;
				MelonLogger.Msg($"Hang: {(flag2 ? "left" : "right")} hand grabbed a ledge for {num:F0}s npc={num2:X8}");
			}
		}

		private static bool FeetSupported(Rigidbody[] bodies)
		{
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: 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)
			try
			{
				int[] array = new int[2] { 3, 6 };
				foreach (int num in array)
				{
					Rigidbody val = ((bodies != null && num >= 0 && num < bodies.Length) ? bodies[num] : null);
					if ((Object)(object)val == (Object)null)
					{
						continue;
					}
					Collider[] array2 = null;
					try
					{
						array2 = Il2CppArrayBase<Collider>.op_Implicit((Il2CppArrayBase<Collider>)(object)Physics.OverlapSphere(val.position, 0.15f));
					}
					catch
					{
						continue;
					}
					if (array2 == null)
					{
						continue;
					}
					Collider[] array3 = array2;
					foreach (Collider val2 in array3)
					{
						if ((Object)(object)val2 == (Object)null)
						{
							continue;
						}
						try
						{
							if (val2.isTrigger)
							{
								continue;
							}
						}
						catch
						{
						}
						try
						{
							if ((Object)(object)((Component)val2).GetComponentInParent<PuppetMaster>() != (Object)null)
							{
								continue;
							}
						}
						catch
						{
						}
						try
						{
							if (IsPlayerRig(((Component)val2).gameObject))
							{
								continue;
							}
						}
						catch
						{
						}
						Vector3 position = val.position;
						try
						{
							position = val2.ClosestPoint(val.position);
						}
						catch
						{
							continue;
						}
						if (position.y < val.position.y - 0.05f)
						{
							return true;
						}
					}
				}
			}
			catch
			{
			}
			return false;
		}

		private static bool TorsoSupported(Rigidbody[] bodies)
		{
			//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_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: 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_003a: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				int[] array = new int[2] { 0, 8 };
				foreach (int num in array)
				{
					Rigidbody val = ((bodies != null && num >= 0 && num < bodies.Length) ? bodies[num] : null);
					if ((Object)(object)val == (Object)null)
					{
						continue;
					}
					Collider[] array2 = null;
					try
					{
						array2 = Il2CppArrayBase<Collider>.op_Implicit((Il2CppArrayBase<Collider>)(object)Physics.OverlapSphere(val.position, 0.25f));
					}
					catch
					{
						continue;
					}
					if (array2 == null)
					{
						continue;
					}
					Collider[] array3 = array2;
					foreach (Collider val2 in array3)
					{
						if ((Object)(object)val2 == (Object)null)
						{
							continue;
						}
						try
						{
							if (val2.isTrigger)
							{
								continue;
							}
						}
						catch
						{
						}
						try
						{
							if ((Object)(object)((Component)val2).GetComponentInParent<PuppetMaster>() != (Object)null)
							{
								continue;
							}
						}
						catch
						{
						}
						try
						{
							if (IsPlayerRig(((Component)val2).gameObject))
							{
								continue;
							}
						}
						catch
						{
						}
						Vector3 position = val.position;
						try
						{
							position = val2.ClosestPoint(val.position);
						}
						catch
						{
							continue;
						}
						if (position.y < val.position.y - 0.05f)
						{
							return true;
						}
					}
				}
			}
			catch
			{
			}
			return false;
		}

		private static bool IsPlayerRig(GameObject go)
		{
			try
			{
				Transform val = (((Object)(object)go != (Object)null) ? go.transform : null);
				for (int i = 0; i < 8; i++)
				{
					if (!((Object)(object)val != (Object)null))
					{
						break;
					}
					string text = null;
					try
					{
						text = ((Object)val).name;
					}
					catch
					{
					}
					if (!string.IsNullOrEmpty(text) && text.ToLowerInvariant().Contains("rigmanager"))
					{
						return true;
					}
					try
					{
						val = val.parent;
					}
					catch
					{
						break;
					}
				}
			}
			catch
			{
			}
			return false;
		}

		private static void ReleaseHang(Hang hg)
		{
			try
			{
				if (hg != null && (Object)(object)hg.Pm != (Object)null)
				{
					int[] armMusclesL = ArmMusclesL;
					foreach (int idx in armMusclesL)
					{
						ReleaseMuscle(hg.Pm, idx);
						ReleaseMapWeight(hg.Pm, idx);
					}
					armMusclesL = ArmMusclesR;
					foreach (int idx2 in armMusclesL)
					{
						ReleaseMuscle(hg.Pm, idx2);
						ReleaseMapWeight(hg.Pm, idx2);
					}
					armMusclesL = TorsoMuscles;
					foreach (int idx3 in armMusclesL)
					{
						ReleaseMuscle(hg.Pm, idx3);
						ReleaseMapWeight(hg.Pm, idx3);
					}
					armMusclesL = LegMusclesL;
					foreach (int idx4 in armMusclesL)
					{
						ReleaseMuscle(hg.Pm, idx4);
						ReleaseMapWeight(hg.Pm, idx4);
					}
					armMusclesL = LegMusclesR;
					foreach (int idx5 in armMusclesL)
					{
						ReleaseMuscle(hg.Pm, idx5);
						ReleaseMapWeight(hg.Pm, idx5);
					}
					try
					{
						RagdollApi.ReleaseAI(hg.Pm);
						return;
					}
					catch
					{
						return;
					}
				}
			}
			catch
			{
			}
		}

		private static void StartStagger(NpcHitInfo info, int id, bool pellet = false)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: 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_0074: 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_007a: 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_0091: 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_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: 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_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_09ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_09b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_09be: Unknown result type (might be due to invalid IL or missing references)
			//IL_09c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_09e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_09e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0405: Unknown result type (might be due to invalid IL or missing references)
			//IL_0411: Unknown result type (might be due to invalid IL or missing references)
			//IL_0544: Unknown result type (might be due to invalid IL or missing references)
			//IL_0545: Unknown result type (might be due to invalid IL or missing references)
			//IL_0563: Unknown result type (might be due to invalid IL or missing references)
			//IL_0575: Unknown result type (might be due to invalid IL or missing references)
			//IL_057a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0582: Unknown result type (might be due to invalid IL or missing references)
			//IL_0587: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_06fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_06f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0702: Unknown result type (might be due to invalid IL or missing references)
			PuppetMaster puppet = info.Puppet;
			Vector3 val = info.Direction;
			if (FlipDirection.Value)
			{
				val = -val;
			}
			val.y = 0f;
			if (((Vector3)(ref val)).sqrMagnitude < 0.01f)
			{
				return;
			}
			((Vector3)(ref val)).Normalize();
			float kickMul = 1f;
			float spin = 0f;
			if (VarietyEnabled.Value)
			{
				val = Quaternion.Euler(0f, Random.Range(-10f, 10f), 0f) * val;
				kickMul = Random.Range(0.8f, 1.3f);
				spin = LeverSpin(info, val);
			}
			float headM;
			float chestM;
			float hipsM;
			if (Staggers.TryGetValue(id, out var value))
			{
				value.Dir = val;
				value.Steps = 0;
				value.BalancedSince = -1f;
				value.KickMul = kickMul;
				value.Spin = spin;
				value.Region = info.Region;
				value.HitMuscle = info.MuscleIndex;
				KickProfile(value.HitMuscle, value.Region, out headM, out chestM, out hipsM, out var shoveM);
				value.ShoveMul = shoveM;
				if (pellet)
				{
					value.ShoveMul *= 0.5f;
					value.Pellet = true;
				}
				value.Melee = IsMelee(info.AttackType);
				value.Sharp = value.Melee && MeleeSharp(info.AttackType);
				value.Env = RagdollApi.IsEnvImpact(info.AttackType);
				value.GunMul = (value.Melee ? 1f : GunMult(info.Gun));
				value.GunName = (value.Env ? ("env:" + (info.AttackType ?? "?")) : (value.Melee ? ("melee:" + (info.AttackType ?? "?")) : (info.Gun ?? "?")));
				value.Bracing = false;
				try
				{
					if (HeadLookSeconds.Value > 0f && (Object)(object)info.Body != (Object)null)
					{
						value.HasWound = true;
						value.WoundPos = (info.HasHitPoint ? info.HitPoint : info.Body.position);
						value.HeadLookUntil = Time.time + HeadLookSeconds.Value;
					}
				}
				catch
				{
				}
				value.NextStepAt = Mathf.Min(value.NextStepAt, Time.time + 0.1f);
				float num = WhiplashWindow();
				if (num > 0f)
				{
					value.WhiplashUntil = Time.time + num;
				}
				if (SnapSeconds.Value > 0f && num <= 0f)
				{
					SnapUpperBody(puppet, value.Health);
				}
				Kick(value);
				if (!value.Env)
				{
					FlingArms(puppet, StaggerArmFling.Value);
				}
				RagdollApi.HoldMapping(puppet, StaggerSeconds.Value + 0.6f, StaggerMapping.Value);
				if (!WalkThrough.Value)
				{
					RagdollApi.HoldLimp(puppet, value.Health, StaggerWeight.Value, StaggerSeconds.Value + 0.6f);
				}
				if (!WalkThrough.Value)
				{
					RagdollApi.HoldLoco(puppet, StaggerSeconds.Value + 0.6f);
				}
				if (!WalkThrough.Value)
				{
					RagdollApi.HoldNav(puppet, StaggerSeconds.Value + 0.6f);
				}
				if (!WalkThrough.Value)
				{
					RagdollApi.HoldLiteLoco(puppet, StaggerSeconds.Value + 0.6f);
				}
				return;
			}
			Rigidbody[] array = (Rigidbody[])(object)new Rigidbody[17];
			for (int i = 0; i < 17; i++)
			{
				array[i] = BodyOf(puppet, i);
			}
			Rigidbody val2 = array[0];
			Rigidbody val3 = array[3];
			Rigidbody val4 = array[6];
			if ((Object)(object)val2 == (Object)null || (Object)(object)val3 == (Object)null || (Object)(object)val4 == (Object)null)
			{
				return;
			}
			if (val2.position.y - Mathf.Min(val3.position.y, val4.position.y) < 0.45f)
			{
				RagdollApi.KnockDown(puppet, info.Health, FallSeconds.Value);
				RagdollApi.HoldLoco(puppet, FallSeconds.Value);
				RagdollApi.HoldNav(puppet, FallSeconds.Value);
				RagdollApi.HoldLiteLoco(puppet, FallSeconds.Value);
				try
				{
					RagdollApi.SetGetupDisabled(puppet, true);
				}
				catch
				{
				}
				try
				{
					float time = Time.time;
					int instanceID = ((Object)puppet).GetInstanceID();
					if (Clutches.TryGetValue(instanceID, out var value2))
					{
						ExtendClutch(value2, time + FallSeconds.Value);
					}
					else if (Enabled.Value && (Object)(object)info.Body != (Object)null)
					{
						StartClutch(info, force: true);
						if (Clutches.TryGetValue(instanceID, out var value3))
						{
							value3.Until = Mathf.Max(value3.Until, time + FallSeconds.Value);
						}
					}
					return;
				}
				catch
				{
					return;
				}
			}
			value = new Stagger
			{
				Pm = puppet,
				Health = info.Health,
				Bodies = array,
				Hips = val2,
				FootL = val3,
				FootR = val4,
				Dir = val,
				StartedAt = Time.time,
				BornAt = Time.time,
				HipsY0 = val2.position.y,
				StartPos = val2.position,
				V0 = Vector3.Dot(val2.velocity, val),
				KickMul = kickMul,
				Spin = spin,
				Region = info.Region,
				HitMuscle = info.MuscleIndex
			};
			KickProfile(value.HitMuscle, value.Region, out hipsM, out chestM, out headM, out var shoveM2);
			value.ShoveMul = shoveM2;
			value.Melee = IsMelee(info.AttackType);
			value.Sharp = value.Melee && MeleeSharp(info.AttackType);
			value.Env = RagdollApi.IsEnvImpact(info.AttackType);
			value.GunMul = (value.Melee ? 1f : GunMult(info.Gun));
			value.GunName = (value.Env ? ("env:" + (info.AttackType ?? "?")) : (value.Melee ? ("melee:" + (info.AttackType ?? "?")) : (info.Gun ?? "?")));
			if (pellet)
			{
				value.ShoveMul *= 0.5f;
			}
			value.Pellet = pellet;
			try
			{
				if (HeadLookSeconds.Value > 0f && (Object)(object)info.Body != (Object)null)
				{
					value.HasWound = true;
					value.WoundPos = (info.HasHitPoint ? info.HitPoint : info.Body.position);
					value.HeadLookUntil = Time.time + HeadLookSeconds.Value;
				}
			}
			catch
			{
			}
			try
			{
				float num2 = 0f;
				Rigidbody[] bodies = value.Bodies;
				foreach (Rigidbody val5 in bodies)
				{
					if ((Object)(object)val5 != (Object)null)
					{
						num2 += val5.mass;
					}
				}
				if (num2 > 1f)
				{
					value.MassScale = Mathf.Clamp(80f / num2, 0.6f, 1.5f);
				}
			}
			catch
			{
			}
			if (!WalkThrough.Value)
			{
				RagdollApi.HoldLoco(puppet, StaggerSeconds.Value + 0.6f);
			}
			if (!WalkThrough.Value)
			{
				RagdollApi.HoldNav(puppet, StaggerSeconds.Value + 0.6f);
			}
			if (!WalkThrough.Value)
			{
				RagdollApi.HoldLiteLoco(puppet, StaggerSeconds.Value + 0.6f);
			}
			if (!WalkThrough.Value)
			{
				RagdollApi.HoldLimp(puppet, info.Health, StaggerWeight.Value, StaggerSeconds.Value + 0.6f);
			}
			try
			{
				Animator targetAnimator = puppet.targetAnimator;
				if ((Object)(object)targetAnimator != (Object)null && !WalkThrough.Value)
				{
					value.TargetAnim = targetAnimator;
					value.TargetSpeed = CaptureAnimSpeed(targetAnimator);
					targetAnimator.speed = 0f;
				}
			}
			catch
			{
			}
			if (info.Health != null)
			{
				value.OrigArmL = RagdollApi.GetLimbStun(info.Health, (MuscleRegion)4);
				value.OrigArmR = RagdollApi.GetLimbStun(info.Health, (MuscleRegion)5);
			}
			Staggers[id] = value;
			if (Thaws.TryGetValue(id, out var value4))
			{
				value.TargetSpeed = ((value4.To > 0.01f) ? value4.To : 1f);
				Thaws.Remove(id);
			}
			value.NextStepAt = Time.time + 0.12f;
			RagdollApi.HoldMapping(puppet, StaggerSeconds.Value + 0.6f, StaggerMapping.Value);
			RagdollApi.Diag(puppet);
			float num3 = WhiplashWindow();
			value.WhiplashUntil = Time.time + num3;
			if (SnapSeconds.Value > 0f && num3 <= 0f)
			{
				SnapUpperBody(puppet, info.Health);
			}
			Kick(value);
			if (!value.Env)
			{
				FlingArms(puppet, StaggerArmFling.Value);
			}
			if (_staggerLogs >= 8)
			{
				return;
			}
			_staggerLogs++;
			float value5 = float.NaN;
			Camera main = Camera.main;
			if ((Object)(object)main != (Object)null)
			{
				Vector3 val6 = val2.position - ((Component)main).transform.position;
				val6.y = 0f;
				if (((Vector3)(ref val6)).sqrMagnitude > 0.01f)
				{
					value5 = Vector3.Dot(((Vector3)(ref val6)).normalized, val);
				}
			}
			MelonLogger.Msg($"Stagger started: upper body limp, legs strong. direction vs 'away from you' = {value5:F2} (want about +1)");
		}

		private static float LeverSpin(NpcHitInfo info, Vector3 dir)
		{
			//IL_002d: 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_0055: 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_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: 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_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if ((Object)(object)info.Body != (Object)null && (Object)(object)info.Puppet != (Object)null)
				{
					Vector3 position = ((Component)info.Puppet).transform.position;
					position.y = 0f;
					Vector3 val = (info.HasHitPoint ? info.HitPoint : info.Body.position);
					val.y = 0f;
					Vector3 val2 = val - position;
					float magnitude = ((Vector3)(ref val2)).magnitude;
					if (!(magnitude > 0.03f))
					{
						return 0f;
					}
					Vector3 val3 = Vector3.Cross(Vector3.up, dir);
					if (((Vector3)(ref val3)).sqrMagnitude > 0.0001f)
					{
						float num = Vector3.Dot(val2 / (magnitude + 0.001f), ((Vector3)(ref val3)).normalized);
						float num2 = Mathf.Clamp(magnitude / 0.15f, 0f, 1.5f) * 1.6f;
						return Mathf.Clamp((0f - num) * num2 * Random.Range(0.85f, 1.15f), -2f, 2f);
					}
				}
			}
			catch
			{
			}
			if (Random.value < 0.5f)
			{
				return Random.Range(-0.8f, 0.8f);
			}
			return 0f;
		}

		private static float WhiplashWindow()
		{
			try
			{
				return Mathf.Max(0f, WhiplashSeconds.Value);
			}
			catch
			{
				return 0f;
			}
		}

		private static void KickProfile(int hitMuscle, MuscleRegion region, out float hipsM, out float chestM, out float headM, out float shoveM)
		{
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Invalid comparison between Unknown and I4
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Invalid comparison between Unknown and I4
			switch (hitMuscle)
			{
			case 10:
			case 13:
				hipsM = 0.2f;
				chestM = 0.5f;
				headM = 0.2f;
				shoveM = 0.2f;
				return;
			case 0:
			case 7:
				hipsM = 1.3f;
				chestM = 0.6f;
				headM = 0.35f;
				shoveM = 0.8f;
				return;
			case 8:
				hipsM = 0.3f;
				chestM = 1.25f;
				headM = 0.9f;
				shoveM = 0.3f;
				return;
			case 9:
			case 16:
				hipsM = 0.35f;
				chestM = 0.7f;
				headM = 1.5f;
				shoveM = 0.35f;
				return;
			case 1:
			case 2:
			case 3:
			case 4:
			case 5:
			case 6:
				hipsM = 0.6f;
				chestM = 0.4f;
				headM = 0.3f;
				shoveM = 0.6f;
				return;
			}
			if ((int)region == 4 || (int)region == 5)
			{
				hipsM = 0.25f;
				chestM = 0.4f;
				headM = 0.25f;
				shoveM = 0.25f;
			}
			else
			{
				hipsM = 1f;
				chestM = 1f;
				headM = 1f;
				shoveM = 1f;
			}
		}

		private static void Kick(Stagger s)
		{
			//IL_0043: 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_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: 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_0161: 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_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_0249: Invalid comparison between Unknown and I4
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: Invalid comparison between Unknown and I4
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: 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_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_0237: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_06f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_06f8: 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_02e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0778: Unknown result type (might be due to invalid IL or missing references)
			//IL_077d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0782: Unknown result type (might be due to invalid IL or missing references)
			//IL_0305: Unknown result type (might be due to invalid IL or missing references)
			//IL_030a: Unknown result type (might be due to invalid IL or missing references)
			//IL_029d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02af: Unknown result type (might be due to invalid IL or missing references)
			//IL_04cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_030d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0312: Unknown result type (might be due to invalid IL or missing references)
			//IL_0314: Unknown result type (might be due to invalid IL or missing references)
			//IL_0317: Unknown result type (might be due to invalid IL or missing references)
			//IL_032d: Expected I4, but got Unknown
			//IL_04f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0501: Unknown result type (might be due to invalid IL or missing references)
			//IL_0523: Unknown result type (might be due to invalid IL or missing references)
			//IL_052d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0409: Unknown result type (might be due to invalid IL or missing references)
			//IL_0413: Unknown result type (might be due to invalid IL or missing references)
			//IL_0418: Unknown result type (might be due to invalid IL or missing references)
			//IL_0422: Unknown result type (might be due to invalid IL or missing references)
			//IL_0427: Unknown result type (might be due to invalid IL or missing references)
			//IL_042c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0430: Unknown result type (might be due to invalid IL or missing references)
			//IL_043f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0445: Unknown result type (might be due to invalid IL or missing references)
			//IL_046d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0477: Unknown result type (might be due to invalid IL or missing references)
			//IL_047c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0486: Unknown result type (might be due to invalid IL or missing references)
			//IL_048b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0490: Unknown result type (might be due to invalid IL or missing references)
			//IL_0494: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a3: 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_034d: Unknown result type (might be due to invalid IL or missing references)
			//IL_034f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0354: Unknown result type (might be due to invalid IL or missing references)
			//IL_035e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0363: Unknown result type (might be due to invalid IL or missing references)
			//IL_0368: Unknown result type (might be due to invalid IL or missing references)
			//IL_036c: Unknown result type (might be due to invalid IL or missing references)
			//IL_037b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0381: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03db: Unknown result type (might be due to invalid IL or missing references)
			float num = s.KickMul * s.MassScale * VolMul(s);
			float num2 = Mathf.Clamp01(Mathf.Abs(s.Spin) / 2f);
			num *= 1f - num2 * 0.35f;
			KickProfile(s.HitMuscle, s.Region, out var hipsM, out var chestM, out var headM, out var _);
			float num3 = HipsKick.Value * hipsM;
			float num4 = ChestKick.Value * chestM;
			float num5 = HeadKick.Value * headM;
			float num6 = 0f;
			try
			{
				num6 = Mathf.Clamp01(PivotBlend.Value);
			}
			catch
			{
			}
			if (num6 > 0f)
			{
				float num7 = (num3 + num4 + num5) / 3f;
				num3 += (num7 - num3) * num6;
				num4 += (num7 - num4) * num6;
				num5 += (num7 - num5) * num6;
			}
			if ((Object)(object)s.Bodies[0] != (Object)null)
			{
				s.Bodies[0].AddForce(s.Dir * num3 * num, (ForceMode)2);
			}
			if ((Object)(object)s.Bodies[8] != (Object)null)
			{
				s.Bodies[8].AddForce(s.Dir * num4 * num, (ForceMode)2);
			}
			if ((Object)(object)s.Bodies[9] != (Object)null)
			{
				s.Bodies[9].AddForce(s.Dir * num5 * num, (ForceMode)2);
			}
			if (s.Pellet && (Object)(object)s.Bodies[8] != (Object)null)
			{
				s.Bodies[8].AddForce(Vector3.up * 1.2f * num, (ForceMode)2);
			}
			Vector3 val2;
			if (LimbKick.Value > 0f && (s.HitMuscle == 10 || s.HitMuscle == 13))
			{
				Rigidbody val = s.Bodies[s.HitMuscle];
				if ((Object)(object)val != (Object)null)
				{
					val2 = s.Dir * 1.4f + Vector3.down * 0.2f;
					val.AddForce(((Vector3)(ref val2)).normalized * LimbKick.Value * 1.4f * num, (ForceMode)2);
				}
			}
			float num8 = (((int)s.Region == 2 || (int)s.Region == 1) ? 0.5f : 1f);
			if ((Object)(object)s.Bodies[0] != (Object)null && Mathf.Abs(s.Spin) > 0.05f)
			{
				float time = Time.time;
				if (time >= s.SpinUntil)
				{
					s.Bodies[0].AddTorque(Vector3.up * s.Spin * num8, (ForceMode)2);
					s.SpinUntil = time + 0.12f;
				}
			}
			if (LimbKick.Value > 0f)
			{
				Vector3 val3 = Vector3.Cross(Vector3.up, s.Dir);
				if (((Vector3)(ref val3)).sqrMagnitude > 0.0001f)
				{
					((Vector3)(ref val3)).Normalize();
				}
				else
				{
					val3 = Vector3.right;
				}
				MuscleRegion region = s.Region;
				switch (region - 4)
				{
				case 2:
					if ((Object)(object)s.Bodies[3] != (Object)null)
					{
						Rigidbody obj5 = s.Bodies[3];
						val2 = -val3 + Vector3.down * 0.7f;
						obj5.AddForce(((Vector3)(ref val2)).normalized * LimbKick.Value * num, (ForceMode)2);
					}
					break;
				case 3:
					if ((Object)(object)s.Bodies[6] != (Object)null)
					{
						Rigidbody obj3 = s.Bodies[6];
						val2 = val3 + Vector3.down * 0.7f;
						obj3.AddForce(((Vector3)(ref val2)).normalized * LimbKick.Value * num, (ForceMode)2);
					}
					break;
				case 0:
					if ((Object)(object)s.Bodies[12] != (Object)null)
					{
						Rigidbody obj4 = s.Bodies[12];
						val2 = s.Dir * 1.2f + Vector3.up * 0.6f;
						obj4.AddForce(((Vector3)(ref val2)).normalized * LimbKick.Value * num, (ForceMode)2);
					}
					break;
				case 1:
					if ((Object)(object)s.Bodies[15] != (Object)null)
					{
						Rigidbody obj2 = s.Bodies[15];
						val2 = s.Dir * 1.2f + Vector3.up * 0.6f;
						obj2.AddForce(((Vector3)(ref val2)).normalized * LimbKick.Value * num, (ForceMode)2);
					}
					break;
				}
			}
			try
			{
				Rigidbody val4 = s.Bodies[0];
				if ((Object)(object)val4 != (Object)null)
				{
					val4.angularVelocity *= 0.55f;
				}
				Rigidbody val5 = s.Bodies[8];
				if ((Object)(object)val5 != (Object)null)
				{
					val5.angularVelocity *= 0.55f;
				}
				Rigidbody val6 = s.Bodies[9];
				if ((Object)(object)val6 != (Object)null)
				{
					val6.angularVelocity *= 0.7f;
				}
			}
			catch
			{
			}
			if (_styleLogs < 12)
			{
				_styleLogs++;
				MelonLogger.Msg($"Stagger style: kick x{num:F2}, spin {s.Spin:F2}, gun {s.GunName} x{s.GunMul:F2}, adv={AdvanceForce.Value:F1}");
			}
			try
			{
				if (!(UnSnapRatio.Value > 0f) && !(CounterRatio.Value > 0f))
				{
					return;
				}
				int num9 = 0;
				try
				{
					num9 = (((Object)(object)s.Pm != (Object)null) ? ((Object)s.Pm).GetInstanceID() : 0);
				}
				catch
				{
				}
				if (num9 == 0)
				{
					return;
				}
				float hipsM2 = ((HipsKick.Value > 0.01f) ? (num3 / HipsKick.Value) : hipsM);
				float chestM2 = ((ChestKick.Value > 0.01f) ? (num4 / ChestKick.Value) : chestM);
				float headM2 = ((HeadKick.Value > 0.01f) ? (num5 / HeadKick.Value) : headM);
				if (UnSnapRatio.Value > 0f)
				{
					if (UnSnaps.Count > 64)
					{
						UnSnaps.Clear();
					}
					UnSnaps[num9] = new UnSnap
					{
						Dir = -s.Dir,
						Due = Time.time + Mathf.Max(0f, UnSnapInterval.Value),
						ChestM = chestM2,
						HeadM = headM2,
						HipsM = hipsM2,
						K = num
					};
				}
				if (CounterRatio.Value > 0f)
				{
					if (Counters.Count > 64)
					{
						Counters.Clear();
					}
					Counters[num9] = new UnSnap
					{
						Dir = -s.Dir,
						Due = Time.time + Mathf.Max(0f, CounterDelay.Value),
						ChestM = 0f,
						HeadM = 0f,
						HipsM = hipsM2,
						K = num
					};
				}
			}
			catch
			{
			}
		}

		private static void SnapUpperBody(PuppetMaster pm, SubBehaviourHealth health)
		{
			if (health != null)
			{
				RagdollApi.SetLimbStun(health, (MuscleRegion)4, 0f);
				RagdollApi.SetLimbStun(health, (MuscleRegion)5, 0f);
			}
			ScaleMuscle(pm, 7, 0.25f, 1f, 25f);
			ScaleMuscle(pm, 8, 0.25f, 1f, 25f);
			ScaleMuscle(pm, 9, 0.25f, 1f, 25f);
			ScaleMuscle(pm, 16, 0.25f, 1f, 25f);
		}

		private static void FlingArms(PuppetMaster pm, float force)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: 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_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_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: 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_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			if (force <= 0f)
			{
				return;
			}
			Rigidbody val = BodyOf(pm, 0);
			Rigidbody val2 = BodyOf(pm, 12);
			Rigidbody val3 = BodyOf(pm, 15);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			Vector3 right = ((Component)pm).transform.right;
			if (((Vector3)(ref right)).sqrMagnitude < 0.01f)
			{
				right = Vector3.right;
			}
			Vector3 val5;
			if ((Object)(object)val2 != (Object)n

Mods\DynamicRagdoll2.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
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 Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSLZ.Marrow.PuppetMasta;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using RagdollOnHit;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(Main), "DynamicRagdoll2", "1.0.21", "skait5k", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("DynamicRagdoll2")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("DynamicRagdoll2")]
[assembly: AssemblyTitle("DynamicRagdoll2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace RagdollOnHit
{
	internal static class EnvImpactProbe
	{
		private sealed class Pending
		{
			public PuppetMaster Pm;

			public int BestIdx;

			public float BestRel;

			public float BestScore;

			public Vector3 Dir;

			public Vector3 Point;

			public bool HasPoint;

			public string Label;

			public float FirstTime;

			public Rigidbody Body;

			public MuscleRegion Region;
		}

		private sealed class Tracked
		{
			public PuppetMaster Pm;

			public Rigidbody[] Bodies;

			public Vector3[] Prev;

			public float LastLog = -100f;
		}

		private static MelonPreferences_Entry<bool> LogEnabled;

		private static MelonPreferences_Entry<float> MinDeltaV;

		private static MelonPreferences_Entry<float> Cooldown;

		private static MelonPreferences_Entry<int> MaxLogs;

		private static MelonPreferences_Entry<bool> ReactEnabled;

		private static MelonPreferences_Entry<float> ReactForce;

		private static MelonPreferences_Entry<float> MinRel;

		private static MelonPreferences_Entry<float> ReactCooldown;

		private static readonly Dictionary<int, Pending> PendingMap = new Dictionary<int, Pending>();

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

		private static int _reactLogs;

		private static readonly Dictionary<int, Tracked> TrackedMap = new Dictionary<int, Tracked>();

		private static int _envLogs;

		private static int _extLogs;

		private static int _selfSkipped;

		private static int _spikeLogs;

		private static float _nextScan;

		private static bool _dumpedMethods;

		private static int _collisionPatches;

		private static bool _loggedFirstTick;

		private static int _scanLogs;

		private static float _lastProbe = -100f;

		internal static void TryInstall()
		{
			try
			{
				MelonPreferences_Category obj = MelonPreferences.GetCategory("RagdollOnHit_Env") ?? MelonPreferences.CreateCategory("RagdollOnHit_Env");
				LogEnabled = obj.CreateEntry<bool>("EnvLogEnabled", true, "Log env impacts (wall slams, thrown props)", (string)null, false, false, (ValueValidator)null, (string)null);
				MinDeltaV = obj.CreateEntry<float>("EnvMinDeltaV", 2.5f, "Velocity jump in one physics step that counts as an impact (m/s)", (string)null, false, false, (ValueValidator)null, (string)null);
				Cooldown = obj.CreateEntry<float>("EnvLogCooldown", 0.8f, "Per-NPC log cooldown (s)", (string)null, false, false, (ValueValidator)null, (string)null);
				MaxLogs = obj.CreateEntry<int>("EnvMaxLogs", 200, "Max external env log lines per level (self-collisions don't count)", (string)null, false, false, (ValueValidator)null, (string)null);
				ReactEnabled = obj.CreateEntry<bool>("EnvReactions", true, "Env impacts trigger stagger/clutch/fall reactions (off = logs only)", (string)null, false, false, (ValueValidator)null, (string)null);
				ReactForce = obj.CreateEntry<float>("EnvForce", 0.4f, "Env reaction volume: scales stagger kicks and fall chance (0 = logs only)", (string)null, false, false, (ValueValidator)null, (string)null);
				MinRel = obj.CreateEntry<float>("EnvMinRel", 1.5f, "Collision speed below this never reacts (m/s)", (string)null, false, false, (ValueValidator)null, (string)null);
				ReactCooldown = obj.CreateEntry<float>("EnvReactCooldown", 0.6f, "Per-NPC reaction cooldown: multi-muscle hits collapse into one (s)", (string)null, false, false, (ValueValidator)null, (string)null);
				try
				{
					RagdollApi.EnvEnabledEntry = ReactEnabled;
				}
				catch
				{
				}
				try
				{
					RagdollApi.EnvForceEntry = ReactForce;
				}
				catch
				{
				}
				try
				{
					if (MaxLogs.Value <= 80)
					{
						MaxLogs.Value = 200;
					}
					if (Math.Abs(MinDeltaV.Value - 4f) < 0.01f)
					{
						MinDeltaV.Value = 2.5f;
					}
					if (Math.Abs(MinRel.Value - 3f) < 0.01f)
					{
						MinRel.Value = 1.5f;
					}
					MelonPreferences.Save();
				}
				catch
				{
				}
			}
			catch (Exception ex)
			{
				try
				{
					MelonLogger.Warning("[env] prefs failed: " + ex.Message);
				}
				catch
				{
				}
			}
			DumpBroadcasterMethods();
			TryPatchCollisions();
			try
			{
				MelonLogger.Msg($"[env] probe installed (collPatches={_collisionPatches}). Slam a head into a wall / throw a barrel, watch the log.");
			}
			catch
			{
			}
		}

		internal static void Clear()
		{
			TrackedMap.Clear();
			PendingMap.Clear();
			LastReact.Clear();
			_envLogs = 0;
			_extLogs = 0;
			_selfSkipped = 0;
			_spikeLogs = 0;
			_reactLogs = 0;
			_nextScan = 0f;
			_loggedFirstTick = false;
		}

		private static void DumpBroadcasterMethods()
		{
			if (_dumpedMethods)
			{
				return;
			}
			_dumpedMethods = true;
			try
			{
				Type? typeFromHandle = typeof(MuscleCollisionBroadcaster);
				List<string> list = new List<string>();
				MethodInfo[] methods = typeFromHandle.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				foreach (MethodInfo methodInfo in methods)
				{
					try
					{
						list.Add($"{methodInfo.ReturnType.Name} {methodInfo.Name}({string.Join(",", Array.ConvertAll(methodInfo.GetParameters(), (ParameterInfo p) => p.ParameterType.Name))})");
					}
					catch
					{
					}
				}
				MelonLogger.Msg($"[env] MuscleCollisionBroadcaster methods ({list.Count}): {string.Join(" | ", list.ToArray())}");
			}
			catch (Exception ex)
			{
				MelonLogger.Warning("[env] method dump failed: " + ex.Message);
			}
		}

		private static void TryPatchCollisions()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Expected O, but got Unknown
			try
			{
				Type typeFromHandle = typeof(MuscleCollisionBroadcaster);
				Harmony val = new Harmony("HitRagdoll.EnvProbe");
				string[] array = new string[3] { "OnCollisionEnter", "OnCollisionStay", "OnTriggerEnter" };
				foreach (string text in array)
				{
					MethodInfo methodInfo = null;
					try
					{
						MethodInfo[] methods = typeFromHandle.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
						foreach (MethodInfo methodInfo2 in methods)
						{
							if (methodInfo2.Name == text)
							{
								methodInfo = methodInfo2;
								break;
							}
						}
					}
					catch
					{
					}
					if (!(methodInfo == null))
					{
						try
						{
							HarmonyMethod val2 = new HarmonyMethod(typeof(EnvImpactProbe).GetMethod("CollisionPrefix", BindingFlags.Static | BindingFlags.NonPublic));
							val.Patch((MethodBase)methodInfo, val2, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
							_collisionPatches++;
							MelonLogger.Msg("[env] patched " + typeFromHandle.Name + "." + text);
						}
						catch (Exception ex)
						{
							MelonLogger.Warning("[env] patch " + text + " failed: " + ex.Message);
						}
						if (_collisionPatches >= 2)
						{
							break;
						}
					}
				}
				if (_collisionPatches == 0)
				{
					MelonLogger.Msg("[env] no OnCollision/OnTrigger found on broadcaster — velocity-spike probe only");
				}
			}
			catch (Exception ex2)
			{
				MelonLogger.Warning("[env] collision patch failed: " + ex2.Message);
			}
		}

		private static void CollisionPrefix(MuscleCollisionBroadcaster __instance, object __0)
		{
			//IL_0436: 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_043e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0440: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0402: Unknown result type (might be due to invalid IL or missing references)
			//IL_0406: Unknown result type (might be due to invalid IL or missing references)
			//IL_040b: Unknown result type (might be due to invalid IL or missing references)
			//IL_040f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0414: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				PuppetMaster val = (((Object)(object)__instance != (Object)null) ? __instance.puppetMaster : null);
				int num = -1;
				try
				{
					num = __instance.muscleIndex;
				}
				catch
				{
				}
				string text = "?";
				float num2 = -1f;
				string value = "?";
				try
				{
					Collision val2 = (Collision)((__0 is Collision) ? __0 : null);
					if (val2 != null)
					{
						try
						{
							Vector3 relativeVelocity = val2.relativeVelocity;
							num2 = ((Vector3)(ref relativeVelocity)).magnitude;
							value = num2.ToString("F1") + "m/s";
						}
						catch
						{
						}
						try
						{
							text = (((Object)(object)val2.collider != (Object)null) ? ((Object)val2.collider).name : "?");
						}
						catch
						{
						}
					}
					else
					{
						Collider val3 = (Collider)((__0 is Collider) ? __0 : null);
						if (val3 != null)
						{
							try
							{
								text = ((Object)val3).name;
							}
							catch
							{
							}
						}
						else if (__0 != null)
						{
							text = __0.ToString();
						}
					}
				}
				catch
				{
				}
				bool flag = false;
				try
				{
					if ((Object)(object)__instance.otherBroadcaster != (Object)null)
					{
						flag = true;
					}
				}
				catch
				{
				}
				if (!flag && !string.IsNullOrEmpty(text))
				{
					string text2 = text.ToLowerInvariant();
					if (text2.Contains("spine_m") || text2.Contains("shoulder_") || text2.Contains("hip_") || text2.Contains("chest_m") || text2.Contains("head_m") || text2.Contains("wrist_") || text2.Contains("elbow") || text2.Contains("knee") || text2.Contains("ankle") || text2.Contains("root") || text2.Contains("jaw") || text2.Contains("clavicle") || text2.Contains("neck") || text2.Contains("pelvis") || text2.Contains("thigh") || text2.Contains("shin"))
					{
						flag = true;
					}
				}
				bool flag2 = false;
				try
				{
					flag2 = IsPlayerObject(__0);
				}
				catch
				{
				}
				if (flag && num2 >= 0f && num2 < 2f)
				{
					_selfSkipped++;
					return;
				}
				int num3;
				try
				{
					num3 = MaxLogs.Value;
				}
				catch
				{
					num3 = 200;
				}
				if (LogEnabled != null && LogEnabled.Value && _extLogs < num3)
				{
					_extLogs++;
					_envLogs = _extLogs;
					string value2;
					try
					{
						value2 = (((Object)(object)val != (Object)null) ? (((Object)val).name + "#" + ((Object)val).GetInstanceID().ToString("X8")) : "?");
					}
					catch
					{
						value2 = "?";
					}
					MelonLogger.Msg($"[env-hit {_extLogs}/{num3}] npc={value2} muscle={num} rel={value} other={text} self={(flag ? "yes" : "NO")}{(flag2 ? " +PLAYER" : "")} excluded={BoolStr(val)}");
				}
				if (!flag && !flag2)
				{
					CollectReaction(__instance, val, num, __0, num2, text);
				}
				try
				{
					if (flag || flag2 || !((Object)(object)val != (Object)null) || (num != 12 && num != 15))
					{
						return;
					}
					Collision val4 = (Collision)((__0 is Collision) ? __0 : null);
					if (val4 != null && val4.contactCount > 0)
					{
						Vector3 point = Vector3.zero;
						Vector3 normal = Vector3.up;
						bool flag3 = false;
						try
						{
							ContactPoint contact = val4.GetContact(0);
							point = ((ContactPoint)(ref contact)).point;
							normal = ((ContactPoint)(ref contact)).normal;
							flag3 = true;
						}
						catch
						{
						}
						if (flag3)
						{
							RagdollApi.RaiseHandTouch(new EnvHandTouch
							{
								Puppet = val,
								MuscleIndex = num,
								Point = point,
								Normal = normal,
								HasPoint = true
							});
						}
					}
				}
				catch
				{
				}
			}
			catch
			{
			}
		}

		internal static void ProbeLedgeHands()
		{
			bool flag = false;
			try
			{
				if (TrackedMap.Count > 0)
				{
					flag = true;
					foreach (KeyValuePair<int, Tracked> item in TrackedMap)
					{
						PuppetMaster val = null;
						try
						{
							val = ((item.Value != null) ? item.Value.Pm : null);
						}
						catch
						{
							continue;
						}
						if (!((Object)(object)val == (Object)null))
						{
							ProbeOnePm(val);
						}
					}
				}
			}
			catch
			{
			}
			if (flag)
			{
				return;
			}
			PuppetMaster[] array = null;
			try
			{
				array = Il2CppArrayBase<PuppetMaster>.op_Implicit(Object.FindObjectsOfType<PuppetMaster>());
			}
			catch
			{
			}
			if (array == null)
			{
				return;
			}
			PuppetMaster[] array2 = array;
			foreach (PuppetMaster val2 in array2)
			{
				if (!((Object)(object)val2 == (Object)null))
				{
					ProbeOnePm(val2);
				}
			}
		}

		private static void ProbeOnePm(PuppetMaster pm)
		{
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0165: 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_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: 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_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: 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_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				try
				{
					if (!pm.isAlive || pm.isKilling)
					{
						return;
					}
				}
				catch
				{
					return;
				}
				try
				{
					if (RagdollApi.IsExcluded(pm))
					{
						return;
					}
				}
				catch
				{
				}
				Rigidbody val = null;
				Rigidbody val2 = null;
				Rigidbody val3 = null;
				try
				{
					val = MuscleBody(pm, 0);
					val2 = MuscleBody(pm, 12);
					val3 = MuscleBody(pm, 15);
				}
				catch
				{
					return;
				}
				if ((Object)(object)val == (Object)null)
				{
					return;
				}
				bool flag = false;
				try
				{
					flag = val.velocity.y < -1f;
				}
				catch
				{
					return;
				}
				if (!flag)
				{
					return;
				}
				Rigidbody[] array = (Rigidbody[])(object)new Rigidbody[2] { val2, val3 };
				for (int i = 0; i < 2; i++)
				{
					Rigidbody val4 = array[i];
					if ((Object)(object)val4 == (Object)null)
					{
						continue;
					}
					Collider[] array2 = null;
					try
					{
						array2 = Il2CppArrayBase<Collider>.op_Implicit((Il2CppArrayBase<Collider>)(object)Physics.OverlapSphere(val4.position, 0.3f));
					}
					catch
					{
						continue;
					}
					if (array2 == null)
					{
						continue;
					}
					Collider[] array3 = array2;
					foreach (Collider val5 in array3)
					{
						if ((Object)(object)val5 == (Object)null)
						{
							continue;
						}
						try
						{
							if (val5.isTrigger)
							{
								continue;
							}
						}
						catch
						{
						}
						try
						{
							if ((Object)(object)((Component)val5).GetComponentInParent<PuppetMaster>() != (Object)null)
							{
								continue;
							}
						}
						catch
						{
						}
						try
						{
							if (IsPlayerObject(val5))
							{
								continue;
							}
						}
						catch
						{
						}
						Vector3 position = val4.position;
						try
						{
							position = val5.ClosestPoint(val4.position);
						}
						catch
						{
							continue;
						}
						try
						{
							Vector3 val6 = position - val4.position;
							if (((Vector3)(ref val6)).magnitude > 0.3f)
							{
								continue;
							}
						}
						catch
						{
							continue;
						}
						Vector3 normal = val4.position - position;
						try
						{
							if (((Vector3)(ref normal)).sqrMagnitude < 1E-06f)
							{
								normal = Vector3.up;
							}
							else
							{
								((Vector3)(ref normal)).Normalize();
							}
						}
						catch
						{
							normal = Vector3.up;
						}
						try
						{
							RagdollApi.RaiseHandTouch(new EnvHandTouch
							{
								Puppet = pm,
								MuscleIndex = ((i == 0) ? 12 : 15),
								Point = position,
								Normal = normal,
								HasPoint = true
							});
						}
						catch
						{
						}
						break;
					}
				}
			}
			catch
			{
			}
		}

		private static Rigidbody MuscleBody(PuppetMaster pm, int idx)
		{
			try
			{
				Muscle val = ((Il2CppArrayBase<Muscle>)(object)pm.muscles)[idx];
				Transform val2 = ((val != null) ? val.transform : null);
				if ((Object)(object)val2 == (Object)null)
				{
					return null;
				}
				Rigidbody component = ((Component)val2).GetComponent<Rigidbody>();
				return ((Object)(object)component != (Object)null) ? component : ((Component)val2).GetComponentInParent<Rigidbody>();
			}
			catch
			{
				return null;
			}
		}

		private static bool IsPlayerObject(object colObj)
		{
			try
			{
				GameObject val = null;
				try
				{
					Collision val2 = (Collision)((colObj is Collision) ? colObj : null);
					if (val2 != null && (Object)(object)val2.collider != (Object)null)
					{
						val = ((Component)val2.collider).gameObject;
					}
					else
					{
						Collider val3 = (Collider)((colObj is Collider) ? colObj : null);
						if (val3 != null)
						{
							val = ((Component)val3).gameObject;
						}
					}
				}
				catch
				{
				}
				Transform val4 = (((Object)(object)val != (Object)null) ? val.transform : null);
				for (int i = 0; i < 8; i++)
				{
					if (!((Object)(object)val4 != (Object)null))
					{
						break;
					}
					string text = null;
					try
					{
						text = ((Object)val4).name;
					}
					catch
					{
					}
					if (!string.IsNullOrEmpty(text) && text.ToLowerInvariant().Contains("rigmanager"))
					{
						return true;
					}
					try
					{
						val4 = val4.parent;
					}
					catch
					{
						break;
					}
				}
			}
			catch
			{
			}
			return false;
		}

		private static float RegionWeight(int idx)
		{
			switch (idx)
			{
			case 9:
			case 16:
				return 3f;
			case 0:
			case 7:
			case 8:
				return 2f;
			default:
				return 1f;
			}
		}

		private static string ClassifyOther(string other)
		{
			try
			{
				string text = (other ?? "").ToLowerInvariant();
				if (text.Contains("mesh") || text.Contains("barrel") || text.Contains("tracker") || text.Contains("prop") || text.Contains("crate"))
				{
					return "impact:prop";
				}
			}
			catch
			{
			}
			return "impact:wall";
		}

		private static void CollectReaction(MuscleCollisionBroadcaster b, PuppetMaster pm, int idx, object colObj, float relMag, string other)
		{
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: 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_00e7: 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_0110: 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_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_02de: Unknown result type (might be due to invalid IL or missing references)
			//IL_02df: 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_02e7: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if ((Object)(object)pm == (Object)null || idx < 0 || (ReactEnabled != null && !ReactEnabled.Value))
				{
					return;
				}
				float num;
				try
				{
					num = MinRel.Value;
				}
				catch
				{
					num = 1.5f;
				}
				if (relMag < num)
				{
					return;
				}
				bool flag = false;
				try
				{
					flag = !pm.isAlive || pm.isKilling;
				}
				catch
				{
					flag = true;
				}
				if (flag)
				{
					return;
				}
				try
				{
					if (RagdollApi.IsExcluded(pm))
					{
						return;
					}
				}
				catch
				{
				}
				try
				{
					if (ClassifyOther(other ?? "?") == "impact:wall")
					{
						return;
					}
				}
				catch
				{
				}
				Vector3 dir = Vector3.zero;
				Vector3 point = Vector3.zero;
				bool hasPoint = false;
				try
				{
					Collision val = (Collision)((colObj is Collision) ? colObj : null);
					if (val != null)
					{
						try
						{
							dir = val.relativeVelocity;
						}
						catch
						{
						}
						try
						{
							if (val.contactCount > 0)
							{
								ContactPoint contact = val.GetContact(0);
								point = ((ContactPoint)(ref contact)).point;
								hasPoint = true;
							}
						}
						catch
						{
						}
						if (((Vector3)(ref dir)).sqrMagnitude < 0.25f)
						{
							try
							{
								if (val.contactCount > 0)
								{
									ContactPoint contact2 = val.GetContact(0);
									dir = -((ContactPoint)(ref contact2)).normal * relMag;
								}
							}
							catch
							{
							}
						}
					}
				}
				catch
				{
				}
				if (((Vector3)(ref dir)).sqrMagnitude < 0.25f)
				{
					return;
				}
				((Vector3)(ref dir)).Normalize();
				Rigidbody val2 = null;
				try
				{
					Muscle val3 = ((Il2CppArrayBase<Muscle>)(object)pm.muscles)[idx];
					Transform val4 = ((val3 != null) ? val3.transform : null);
					if ((Object)(object)val4 != (Object)null)
					{
						try
						{
							val2 = ((Component)val4).GetComponent<Rigidbody>();
						}
						catch
						{
						}
						if ((Object)(object)val2 == (Object)null)
						{
							try
							{
								val2 = ((Component)val4).GetComponentInParent<Rigidbody>();
							}
							catch
							{
							}
						}
					}
				}
				catch
				{
				}
				if ((Object)(object)val2 == (Object)null)
				{
					return;
				}
				int instanceID;
				try
				{
					instanceID = ((Object)pm).GetInstanceID();
				}
				catch
				{
					return;
				}
				float firstTime;
				try
				{
					firstTime = Time.time;
				}
				catch
				{
					firstTime = 0f;
				}
				float num2 = relMag * RegionWeight(idx);
				if (!PendingMap.TryGetValue(instanceID, out var value) || value == null)
				{
					if (PendingMap.Count > 64)
					{
						PendingMap.Clear();
					}
					PendingMap[instanceID] = new Pending
					{
						Pm = pm,
						BestIdx = idx,
						BestRel = relMag,
						BestScore = num2,
						Dir = dir,
						Point = point,
						HasPoint = hasPoint,
						Label = ClassifyOther(other),
						FirstTime = firstTime,
						Body = val2,
						Region = RagdollApi.RegionOf(idx)
					};
				}
				else
				{
					bool num3 = relMag > value.BestRel + 0.75f;
					bool flag2 = Math.Abs(relMag - value.BestRel) <= 0.75f && num2 > value.BestScore;
					if (num3 || flag2)
					{
						value.BestIdx = idx;
						value.BestRel = relMag;
						value.BestScore = num2;
						value.Dir = dir;
						value.Point = point;
						value.HasPoint = hasPoint;
						value.Label = ClassifyOther(other);
						value.Body = val2;
						value.Region = RagdollApi.RegionOf(idx);
					}
				}
			}
			catch
			{
			}
		}

		private static void FlushReactions(float now)
		{
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_02de: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_030b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0310: Unknown result type (might be due to invalid IL or missing references)
			if (PendingMap.Count == 0)
			{
				return;
			}
			float num;
			try
			{
				num = ReactCooldown.Value;
			}
			catch
			{
				num = 0.6f;
			}
			List<int> list = null;
			foreach (KeyValuePair<int, Pending> item in PendingMap)
			{
				Pending value = item.Value;
				if (value == null || (Object)(object)value.Pm == (Object)null)
				{
					(list ?? (list = new List<int>())).Add(item.Key);
				}
				else
				{
					if (now - value.FirstTime < 0.12f)
					{
						continue;
					}
					(list ?? (list = new List<int>())).Add(item.Key);
					try
					{
						if (LastReact.TryGetValue(item.Key, out var value2) && now - value2 < num)
						{
							continue;
						}
						bool flag = false;
						try
						{
							flag = !value.Pm.isAlive || value.Pm.isKilling;
						}
						catch
						{
							flag = true;
						}
						if (flag)
						{
							continue;
						}
						try
						{
							if (RagdollApi.IsExcluded(value.Pm))
							{
								continue;
							}
						}
						catch
						{
						}
						float num2;
						try
						{
							num2 = ReactForce.Value;
						}
						catch
						{
							num2 = 0.4f;
						}
						if (num2 <= 0f)
						{
							continue;
						}
						BehaviourPuppet behaviour = null;
						SubBehaviourHealth health = null;
						try
						{
							behaviour = Main.FindPuppet(value.Pm);
						}
						catch
						{
						}
						try
						{
							health = Main.FindHealth(value.Pm);
						}
						catch
						{
						}
						bool flag2 = false;
						try
						{
							Il2CppReferenceArray<Collider> val = Physics.OverlapSphere(value.HasPoint ? value.Point : (((Object)(object)value.Body != (Object)null) ? value.Body.position : ((Component)value.Pm).transform.position), 0.6f);
							if (val != null)
							{
								foreach (Collider item2 in (Il2CppArrayBase<Collider>)(object)val)
								{
									if (!((Object)(object)item2 == (Object)null))
									{
										string text;
										try
										{
											text = ((Object)item2).name.ToLowerInvariant();
										}
										catch
										{
											continue;
										}
										if (text.Contains("hand") || text.Contains("finger") || text.Contains("softhand"))
										{
											flag2 = true;
											break;
										}
									}
								}
							}
						}
						catch
						{
						}
						LastReact[item.Key] = now;
						bool flag3 = (value.Label ?? "").Contains("prop");
						float num3 = value.BestRel * (flag3 ? 0.5f : 0.3f);
						bool hasHitPoint = false;
						bool flag4 = value.Region == MuscleRegion.Head && (flag3 || flag2);
						NpcHitInfo info = new NpcHitInfo
						{
							Puppet = value.Pm,
							Behaviour = behaviour,
							Health = health,
							MuscleIndex = value.BestIdx,
							Region = value.Region,
							Body = value.Body,
							HitPoint = value.Point,
							HasHitPoint = hasHitPoint,
							AttackType = value.Label,
							Gun = "Env",
							Direction = value.Dir,
							Damage = num3,
							Tier = HitTier.Medium,
							IsDead = false,
							ForceClutch = flag4
						};
						try
						{
							RagdollApi.Raise(info);
						}
						catch
						{
						}
						if (_reactLogs < 30)
						{
							_reactLogs++;
							MelonLogger.Msg($"[env-react {_reactLogs}] npc={item.Key:X8} muscle={value.BestIdx}({value.Region}) rel={value.BestRel:F1} dmg={num3:F1} {value.Label}{(flag2 ? " +GRAB" : "")}{(flag4 ? " forceHead" : "")}");
						}
					}
					catch
					{
					}
				}
			}
			if (list == null)
			{
				return;
			}
			foreach (int item3 in list)
			{
				PendingMap.Remove(item3);
			}
		}

		private static string BoolStr(PuppetMaster pm)
		{
			try
			{
				return RagdollApi.IsExcluded(pm) ? "yes" : "no";
			}
			catch
			{
				return "?";
			}
		}

		internal static void OnFixedUpdate()
		{
			//IL_0252: Unknown result type (might be due to invalid IL or missing references)
			//IL_038c: 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_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: 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_01eb: Unknown result type (might be due to invalid IL or missing references)
			float time;
			try
			{
				time = Time.time;
			}
			catch
			{
				return;
			}
			if (!_loggedFirstTick)
			{
				_loggedFirstTick = true;
				try
				{
					MelonLogger.Msg("[env] fixedupdate ticking (velocity probe alive)");
				}
				catch
				{
				}
			}
			try
			{
				FlushReactions(time);
			}
			catch
			{
			}
			try
			{
				if (time - _lastProbe >= 0.15f)
				{
					_lastProbe = time;
					ProbeLedgeHands();
				}
			}
			catch
			{
			}
			bool flag = true;
			try
			{
				flag = LogEnabled != null && LogEnabled.Value;
			}
			catch
			{
				flag = true;
			}
			if (!flag)
			{
				return;
			}
			int num;
			try
			{
				num = MaxLogs.Value;
			}
			catch
			{
				num = 200;
			}
			if (_spikeLogs >= num)
			{
				return;
			}
			if (time >= _nextScan)
			{
				_nextScan = time + 2f;
				ScanForNpcs();
			}
			float num2;
			try
			{
				num2 = MinDeltaV.Value;
			}
			catch
			{
				num2 = 2.5f;
			}
			float num3;
			try
			{
				num3 = Cooldown.Value;
			}
			catch
			{
				num3 = 0.8f;
			}
			List<int> list = null;
			foreach (KeyValuePair<int, Tracked> item in TrackedMap)
			{
				Tracked value = item.Value;
				if (value == null || (Object)(object)value.Pm == (Object)null)
				{
					(list ?? (list = new List<int>())).Add(item.Key);
					continue;
				}
				bool flag2 = true;
				try
				{
					flag2 = value.Pm.isAlive && !value.Pm.isKilling;
				}
				catch
				{
					flag2 = false;
				}
				if (!flag2 || value.Bodies == null || value.Prev == null)
				{
					continue;
				}
				for (int i = 0; i < value.Bodies.Length; i++)
				{
					Rigidbody val = null;
					try
					{
						val = value.Bodies[i];
					}
					catch
					{
						continue;
					}
					if ((Object)(object)val == (Object)null)
					{
						continue;
					}
					Vector3 velocity;
					try
					{
						velocity = val.velocity;
					}
					catch
					{
						continue;
					}
					Vector3 val2 = value.Prev[i];
					value.Prev[i] = velocity;
					float magnitude;
					try
					{
						Vector3 val3 = velocity - val2;
						magnitude = ((Vector3)(ref val3)).magnitude;
					}
					catch
					{
						continue;
					}
					if (magnitude < num2)
					{
						continue;
					}
					if (!(time - value.LastLog < num3))
					{
						float value2;
						float value3;
						try
						{
							value2 = ((Vector3)(ref val2)).magnitude;
							value3 = ((Vector3)(ref velocity)).magnitude;
						}
						catch
						{
							value2 = -1f;
							value3 = -1f;
						}
						value.LastLog = time;
						_spikeLogs++;
						string value4 = NearNames(val.position);
						string value5;
						try
						{
							value5 = ((Object)value.Pm).name + "#" + item.Key.ToString("X8");
						}
						catch
						{
							value5 = item.Key.ToString("X8");
						}
						MuscleRegion value6 = MuscleRegion.Unknown;
						try
						{
							value6 = RagdollApi.RegionOf(i);
						}
						catch
						{
						}
						MelonLogger.Msg($"[env-spike {_spikeLogs}/{num}] npc={value5} muscle={i}({value6}) dV={magnitude:F1}m/s {value2:F1}->{value3:F1} pos={Fmt(val.position)} near=[{value4}] excluded={BoolStr(value.Pm)}");
					}
					break;
				}
			}
			if (list == null)
			{
				return;
			}
			foreach (int item2 in list)
			{
				TrackedMap.Remove(item2);
			}
		}

		private static void ScanForNpcs()
		{
			//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0296: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				PuppetMaster[] array = null;
				string value = "?";
				try
				{
					array = Il2CppArrayBase<PuppetMaster>.op_Implicit(Object.FindObjectsOfType<PuppetMaster>());
					value = "generic";
				}
				catch (Exception ex)
				{
					try
					{
						MelonLogger.Warning("[env] generic scan failed: " + ex.Message);
					}
					catch
					{
					}
				}
				if (array == null || array.Length == 0)
				{
					try
					{
						Il2CppReferenceArray<Object> val = Resources.FindObjectsOfTypeAll(Il2CppType.Of<PuppetMaster>());
						if (val != null && ((Il2CppArrayBase<Object>)(object)val).Length > 0)
						{
							List<PuppetMaster> list = new List<PuppetMaster>();
							foreach (Object item in (Il2CppArrayBase<Object>)(object)val)
							{
								try
								{
									PuppetMaster val2 = ((Il2CppObjectBase)item).TryCast<PuppetMaster>();
									if ((Object)(object)val2 != (Object)null)
									{
										list.Add(val2);
									}
								}
								catch
								{
								}
							}
							array = list.ToArray();
							value = "FindObjectsOfTypeAll";
						}
					}
					catch (Exception ex2)
					{
						try
						{
							MelonLogger.Warning("[env] all-scan failed: " + ex2.Message);
						}
						catch
						{
						}
					}
				}
				if (array == null)
				{
					return;
				}
				if (_scanLogs < 4)
				{
					_scanLogs++;
					MelonLogger.Msg($"[env] scan via {value}: {array.Length} puppets, tracking {TrackedMap.Count} (self-skipped so far: {_selfSkipped})");
				}
				PuppetMaster[] array2 = array;
				foreach (PuppetMaster val3 in array2)
				{
					if ((Object)(object)val3 == (Object)null)
					{
						continue;
					}
					int instanceID;
					try
					{
						instanceID = ((Object)val3).GetInstanceID();
					}
					catch
					{
						continue;
					}
					if (TrackedMap.ContainsKey(instanceID))
					{
						continue;
					}
					if (TrackedMap.Count > 64)
					{
						TrackedMap.Clear();
					}
					Rigidbody[] array3 = null;
					try
					{
						Il2CppReferenceArray<Muscle> muscles = val3.muscles;
						if (muscles == null)
						{
							continue;
						}
						array3 = (Rigidbody[])(object)new Rigidbody[((Il2CppArrayBase<Muscle>)(object)muscles).Length];
						for (int j = 0; j < ((Il2CppArrayBase<Muscle>)(object)muscles).Length; j++)
						{
							try
							{
								Muscle val4 = ((Il2CppArrayBase<Muscle>)(object)muscles)[j];
								Transform val5 = ((val4 != null) ? val4.transform : null);
								Rigidbody val6 = null;
								if ((Object)(object)val5 != (Object)null)
								{
									try
									{
										val6 = ((Component)val5).GetComponent<Rigidbody>();
									}
									catch
									{
									}
									if ((Object)(object)val6 == (Object)null)
									{
										try
										{
											val6 = ((Component)val5).GetComponentInParent<Rigidbody>();
										}
										catch
										{
										}
									}
								}
								array3[j] = val6;
							}
							catch
							{
								array3[j] = null;
							}
						}
						goto IL_0274;
					}
					catch
					{
					}
					continue;
					IL_0274:
					Vector3[] array4 = (Vector3[])(object)new Vector3[array3.Length];
					for (int k = 0; k < array3.Length; k++)
					{
						try
						{
							array4[k] = (((Object)(object)array3[k] != (Object)null) ? array3[k].velocity : Vector3.zero);
						}
						catch
						{
						}
					}
					TrackedMap[instanceID] = new Tracked
					{
						Pm = val3,
						Bodies = array3,
						Prev = array4
					};
				}
			}
			catch
			{
			}
		}

		private static string NearNames(Vector3 pos)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Il2CppReferenceArray<Collider> val = Physics.OverlapSphere(pos, 1.2f);
				if (val == null || ((Il2CppArrayBase<Collider>)(object)val).Length == 0)
				{
					return "nothing within 1.2m";
				}
				List<string> list = new List<string>();
				foreach (Collider item in (Il2CppArrayBase<Collider>)(object)val)
				{
					if ((Object)(object)item == (Object)null)
					{
						continue;
					}
					string name;
					try
					{
						name = ((Object)item).name;
					}
					catch
					{
						continue;
					}
					if (!string.IsNullOrEmpty(name))
					{
						if (list.Count < 3 && !list.Contains(name))
						{
							list.Add(name);
						}
						if (list.Count >= 3)
						{
							break;
						}
					}
				}
				return (list.Count > 0) ? string.Join(",", list.ToArray()) : "unnamed";
			}
			catch
			{
				return "?";
			}
		}

		private static string Fmt(Vector3 v)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				return $"({v.x:F1},{v.y:F1},{v.z:F1})";
			}
			catch
			{
				return "?";
			}
		}
	}
	public enum HitTier
	{
		Light,
		Medium,
		Kill
	}
	public enum MuscleRegion
	{
		Unknown,
		Hips,
		Torso,
		Head,
		ArmL,
		ArmR,
		LegL,
		LegR
	}
	public sealed class NpcHitInfo
	{
		public PuppetMaster Puppet;

		public BehaviourPuppet Behaviour;

		public SubBehaviourHealth Health;

		public int MuscleIndex;

		public MuscleRegion Region;

		public Rigidbody Body;

		public Vector3 HitPoint;

		public bool HasHitPoint;

		public string AttackType;

		public string Gun;

		public Vector3 Direction;

		public float Damage;

		public HitTier Tier;

		public bool IsDead;

		public bool ForceClutch;
	}
	public sealed class EnvHandTouch
	{
		public PuppetMaster Puppet;

		public int MuscleIndex;

		public Vector3 Point;

		public Vector3 Normal;

		public bool HasPoint;
	}
	public static class RagdollApi
	{
		public static bool AutoKnockdown = true;

		public static MelonPreferences_Entry<bool> EnabledEntry;

		public static MelonPreferences_Entry<bool> EnvEnabledEntry;

		public static MelonPreferences_Entry<float> EnvForceEntry;

		public static MelonPreferences_Entry<float> DeathMuscleEntry;

		private static readonly string[] ExcludedTokens = new string[10] { "omni", "turret", "crablet", "skeleton", "nullrat", "cultist", "mage", "steel", "fire", "projector" };

		private static int _lockDiagCount;

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

		private static int _excludeLogs;

		public static float DeathMuscle
		{
			get
			{
				try
				{
					return (DeathMuscleEntry != null) ? DeathMuscleEntry.Value : 0f;
				}
				catch
				{
					return 0f;
				}
			}
		}

		public static bool EnvReactions
		{
			get
			{
				try
				{
					return EnvEnabledEntry == null || EnvEnabledEntry.Value;
				}
				catch
				{
					return true;
				}
			}
		}

		public static float EnvForce
		{
			get
			{
				try
				{
					return (EnvForceEntry != null) ? EnvForceEntry.Value : 0.4f;
				}
				catch
				{
					return 0.4f;
				}
			}
		}

		public static event Action<NpcHitInfo> OnNpcHit;

		public static event Action<EnvHandTouch> OnEnvHandTouch;

		public static bool IsEnvImpact(string attackType)
		{
			try
			{
				if (string.IsNullOrEmpty(attackType))
				{
					return false;
				}
				return attackType.ToLowerInvariant().Contains("impact");
			}
			catch
			{
				return false;
			}
		}

		public static void HoldMapping(PuppetMaster pm, float seconds)
		{
			if (!((Object)(object)pm == (Object)null))
			{
				Main.HoldMapping(pm, seconds);
			}
		}

		public static void KnockDown(PuppetMaster pm, SubBehaviourHealth health, float seconds)
		{
			if (!((Object)(object)pm == (Object)null))
			{
				Main.KnockDown(pm, health, seconds);
			}
		}

		public static void HoldLimp(PuppetMaster pm, SubBehaviourHealth health, float weight, float seconds)
		{
			if (!((Object)(object)pm == (Object)null))
			{
				Main.HoldLimp(pm, health, weight, seconds);
			}
		}

		public static void HoldMapping(PuppetMaster pm, float seconds, float weight)
		{
			if (!((Object)(object)pm == (Object)null))
			{
				Main.HoldMapping(pm, seconds, weight);
			}
		}

		public static void HoldLoco(PuppetMaster pm, float seconds)
		{
			if (!((Object)(object)pm == (Object)null))
			{
				Main.HoldLoco(pm, seconds);
			}
		}

		public static void HoldNav(PuppetMaster pm, float seconds)
		{
			if (!((Object)(object)pm == (Object)null))
			{
				Main.HoldNav(pm, seconds);
			}
		}

		public static void HoldLiteLoco(PuppetMaster pm, float seconds)
		{
			if (!((Object)(object)pm == (Object)null))
			{
				Main.HoldLiteLoco(pm, seconds);
			}
		}

		public static void ReleaseAI(PuppetMaster pm)
		{
			if (!((Object)(object)pm == (Object)null))
			{
				Main.ReleaseAI(pm);
			}
		}

		public static void Diag(PuppetMaster pm)
		{
			if (!((Object)(object)pm == (Object)null))
			{
				Main.Diag(pm);
			}
		}

		internal static void RaiseHandTouch(EnvHandTouch touch)
		{
			Action<EnvHandTouch> onEnvHandTouch = RagdollApi.OnEnvHandTouch;
			if (onEnvHandTouch == null)
			{
				return;
			}
			Delegate[] invocationList = onEnvHandTouch.GetInvocationList();
			foreach (Delegate obj in invocationList)
			{
				try
				{
					((Action<EnvHandTouch>)obj)(touch);
				}
				catch (Exception value)
				{
					MelonLogger.Error($"RagdollApi handtouch subscriber threw: {value}");
				}
			}
		}

		public static MuscleRegion RegionOf(int muscleIndex)
		{
			switch (muscleIndex)
			{
			case 0:
				return MuscleRegion.Hips;
			case 1:
			case 2:
			case 3:
				return MuscleRegion.LegL;
			default:
				if (muscleIndex >= 4 && muscleIndex <= 6)
				{
					return MuscleRegion.LegR;
				}
				switch (muscleIndex)
				{
				case 7:
				case 8:
					return MuscleRegion.Torso;
				case 9:
				case 16:
					return MuscleRegion.Head;
				case 10:
				case 11:
				case 12:
					return MuscleRegion.ArmL;
				default:
					if (muscleIndex >= 13 && muscleIndex <= 15)
					{
						return MuscleRegion.ArmR;
					}
					return MuscleRegion.Unknown;
				}
			}
		}

		internal static string StunFieldOf(MuscleRegion region)
		{
			return region switch
			{
				MuscleRegion.ArmL => "stun_arm_lf", 
				MuscleRegion.ArmR => "stun_arm_rt", 
				MuscleRegion.LegL => "stun_leg_lf", 
				MuscleRegion.LegR => "stun_leg_rt", 
				_ => "stun_spine", 
			};
		}

		public static float GetLimbStun(SubBehaviourHealth h, MuscleRegion region)
		{
			if (!Reflect.TryGet<float>(h, StunFieldOf(region), out var value))
			{
				return 1f;
			}
			return value;
		}

		public static void SetLimbStun(SubBehaviourHealth h, MuscleRegion region, float level)
		{
			if (h != null)
			{
				string name = StunFieldOf(region);
				if (Reflect.TryGet<float>(h, name, out var value) && level < value)
				{
					Reflect.TrySet(h, name, level);
				}
			}
		}

		public static float CurHp(SubBehaviourHealth h)
		{
			try
			{
				if (h != null && Reflect.TryGet<float>(h, "cur_hp", out var value))
				{
					return value;
				}
			}
			catch
			{
			}
			return -1f;
		}

		public static float HpFraction(SubBehaviourHealth h)
		{
			try
			{
				if (h == null)
				{
					return 1f;
				}
				float num = -1f;
				float num2 = 0f;
				if (Reflect.TryGet<float>(h, "cur_hp", out var value))
				{
					num = value;
				}
				if (Reflect.TryGet<float>(h, "maxHitPoints", out var value2))
				{
					num2 = value2;
				}
				if (num2 > 0f && num >= 0f)
				{
					return Mathf.Clamp01(num / num2);
				}
			}
			catch
			{
			}
			return 1f;
		}

		public static bool SetGetupDisabled(PuppetMaster pm, bool disabled)
		{
			if ((Object)(object)pm == (Object)null)
			{
				return false;
			}
			try
			{
				if (Reflect.TrySetBool(pm, "getupDisabled", disabled) && Reflect.TryGet<bool>(pm, "getupDisabled", out var value) && value == disabled)
				{
					return true;
				}
				try
				{
					foreach (BehaviourBase item in (Il2CppArrayBase<BehaviourBase>)(object)pm.behaviours)
					{
						if (!((Object)(object)item == (Object)null))
						{
							object obj = null;
							try
							{
								obj = Reflect.ResolveRuntimeType((Il2CppObjectBase)(object)item, out var _);
							}
							catch
							{
							}
							object o = obj ?? item;
							if (Reflect.TrySetBool(o, "getupDisabled", disabled) && Reflect.TryGet<bool>(o, "getupDisabled", out var value2) && value2 == disabled)
							{
								return true;
							}
							if (Reflect.TrySetBool(o, "getUpDisabled", disabled) && Reflect.TryGet<bool>(o, "getUpDisabled", out var value3) && value3 == disabled)
							{
								return true;
							}
							if (Reflect.TrySetBool(o, "canGetUp", !disabled) && Reflect.TryGet<bool>(o, "canGetUp", out var value4) && value4 == !disabled)
							{
								return true;
							}
							if (Reflect.TrySetBool(o, "_blockAiTick", disabled) && Reflect.TryGet<bool>(o, "_blockAiTick", out var value5) && value5 == disabled)
							{
								return true;
							}
						}
					}
				}
				catch
				{
				}
			}
			catch
			{
			}
			try
			{
				if (_lockDiagCount < 2)
				{
					_lockDiagCount++;
					List<string> list = new List<string>();
					try
					{
						foreach (BehaviourBase item2 in (Il2CppArrayBase<BehaviourBase>)(object)pm.behaviours)
						{
							if ((Object)(object)item2 == (Object)null)
							{
								continue;
							}
							object obj5 = null;
							string className2 = "?";
							try
							{
								obj5 = Reflect.ResolveRuntimeType((Il2CppObjectBase)(object)item2, out className2);
							}
							catch
							{
							}
							object o2 = obj5 ?? item2;
							List<string> list2 = new List<string>();
							string[] array = new string[5] { "canGetUp", "getupDisabled", "getUpDisabled", "_blockAiTick", "getUpWhileResting" };
							foreach (string text in array)
							{
								try
								{
									if (Reflect.TryGet<bool>(o2, text, out var value6))
									{
										list2.Add(text + "=" + value6);
									}
									else
									{
										list2.Add(text + "=?");
									}
								}
								catch
								{
									list2.Add(text + "=?");
								}
							}
							list.Add("[" + className2 + "]: " + string.Join(",", list2));
						}
					}
					catch
					{
					}
					MelonLogger.Msg("Getup lock FAILED diag: " + string.Join(" ", list));
				}
			}
			catch
			{
			}
			return false;
		}

		public static void SetLimbStunLevel(SubBehaviourHealth h, MuscleRegion region, float level)
		{
			if (h != null)
			{
				Reflect.TrySet(h, StunFieldOf(region), Mathf.Clamp01(level));
			}
		}

		internal static void ClearNpcCache()
		{
			ExcludedCache.Clear();
		}

		private static string NormName(string s)
		{
			if (string.IsNullOrEmpty(s))
			{
				return "";
			}
			char[] array = new char[s.Length];
			int length = 0;
			foreach (char c in s)
			{
				if (c >= 'a' && c <= 'z')
				{
					array[length++] = c;
				}
				else if (c >= 'A' && c <= 'Z')
				{
					array[length++] = (char)(c + 32);
				}
				else if (c >= '0' && c <= '9')
				{
					array[length++] = c;
				}
			}
			return new string(array, 0, length);
		}

		public static bool IsExcluded(PuppetMaster pm)
		{
			int instanceID;
			try
			{
				instanceID = ((Object)pm).GetInstanceID();
			}
			catch
			{
				return true;
			}
			if (ExcludedCache.TryGetValue(instanceID, out var value))
			{
				return value;
			}
			bool flag = CheckExcluded(pm);
			if (ExcludedCache.Count > 256)
			{
				ExcludedCache.Clear();
			}
			ExcludedCache[instanceID] = flag;
			return flag;
		}

		private static bool CheckExcluded(PuppetMaster pm)
		{
			try
			{
				Transform val = ((Component)pm).transform;
				for (int i = 0; i < 6; i++)
				{
					if (!((Object)(object)val != (Object)null))
					{
						break;
					}
					string text = null;
					try
					{
						text = ((Object)val).name;
					}
					catch
					{
					}
					string text2 = NormName(text);
					if (text2.Length > 0)
					{
						string[] excludedTokens = ExcludedTokens;
						foreach (string value in excludedTokens)
						{
							if (text2.Contains(value))
							{
								if (_excludeLogs < 6)
								{
									_excludeLogs++;
									MelonLogger.Msg($"NPC gate: skipping '{text}' (matched '{value}')");
								}
								return true;
							}
						}
					}
					try
					{
						val = val.parent;
					}
					catch
					{
						break;
					}
				}
			}
			catch
			{
			}
			return false;
		}

		public static bool IsNullBody(PuppetMaster pm)
		{
			try
			{
				Transform val = ((Component)pm).transform;
				for (int i = 0; i < 6; i++)
				{
					if (!((Object)(object)val != (Object)null))
					{
						break;
					}
					try
					{
						if (NormName(((Object)val).name).Contains("nullbodyagent"))
						{
							return true;
						}
					}
					catch
					{
					}
					try
					{
						val = val.parent;
					}
					catch
					{
						break;
					}
				}
			}
			catch
			{
			}
			return false;
		}

		internal static void Raise(NpcHitInfo info)
		{
			Action<NpcHitInfo> onNpcHit = RagdollApi.OnNpcHit;
			if (onNpcHit == null)
			{
				return;
			}
			Delegate[] invocationList = onNpcHit.GetInvocationList();
			foreach (Delegate obj in invocationList)
			{
				try
				{
					((Action<NpcHitInfo>)obj)(info);
				}
				catch (Exception value)
				{
					MelonLogger.Error($"RagdollApi subscriber threw: {value}");
				}
			}
		}
	}
	public class Main : MelonMod
	{
		private sealed class Reaction
		{
			public float Original;

			public float Weight;

			public float HoldUntil;

			public SubBehaviourHealth Health;

			public float[] Held;
		}

		private sealed class MapHold
		{
			public float Original;

			public float Weight;

			public float Until;
		}

		private sealed class FlagHold
		{
			public object Beh;

			public bool Original;

			public float Until;
		}

		private sealed class FloatHold
		{
			public object Target;

			public float Original;

			public float Until;
		}

		private static MelonPreferences_Entry<float> GetUpDelay;

		private static MelonPreferences_Entry<float> KnockbackForce;

		private static MelonPreferences_Entry<float> KnockdownDamage;

		private static MelonPreferences_Entry<bool> UseGameStun;

		private static MelonPreferences_Entry<float> LightStunLevel;

		private static MelonPreferences_Entry<float> LightMuscleWeight;

		private static MelonPreferences_Entry<float> LightSeconds;

		private static MelonPreferences_Entry<float> RecoverSeconds;

		private static MelonPreferences_Entry<float> SlowMoScale;

		private static MelonPreferences_Entry<float> SlowMoSeconds;

		private static MelonPreferences_Entry<bool> LogHits;

		private static MelonPreferences_Entry<bool> Enabled;

		private static MelonPreferences_Entry<float> DeathMuscle;

		private static MelonPreferences_Entry<float> GunDamageScale;

		private static MelonPreferences_Entry<float> MeleeDamageScale;

		internal static MelonPreferences_Entry<bool> HeadshotKill;

		private const float ReactCooldown = 0.25f;

		private const float DropSpeed = 20f;

		private static readonly string[] StunFields = new string[5] { "stun_spine", "stun_arm_lf", "stun_arm_rt", "stun_leg_lf", "stun_leg_rt" };

		private static readonly Dictionary<int, Reaction> Reactions = new Dictionary<int, Reaction>();

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

		private static readonly Dictionary<int, SubBehaviourHealth> HealthCache = new Dictionary<int, SubBehaviourHealth>();

		private static readonly HashSet<int> NoHealth = new HashSet<int>();

		private static bool _dumpedAttack;

		private static bool _dumpedStructure;

		private static bool _loggedHealth;

		private static bool _loggedNoHealth;

		private static bool _loggedStun;

		private static bool _loggedLightDip;

		private static bool _loggedMedium;

		private static bool _loggedUnpin;

		private static bool _loggedKill;

		private static bool _slowActive;

		private static int _hitLogCount;

		private static int _locoLogs;

		private static int _originLogs;

		private static int _sourceLogs;

		private static readonly HashSet<string> _attackTypeLogs = new HashSet<string>();

		internal static int _scaleLogs;

		internal static int _headshotLogs;

		private static readonly Dictionary<int, MapHold> MapHolds = new Dictionary<int, MapHold>();

		private static readonly Dictionary<string, FlagHold> FlagHolds = new Dictionary<string, FlagHold>();

		private static readonly Dictionary<string, FloatHold> FloatHolds = new Dictionary<string, FloatHold>();

		private static int _diagCount;

		public override void OnInitializeMelon()
		{
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Expected O, but got Unknown
			MelonPreferences_Category obj = MelonPreferences.CreateCategory("RagdollOnHit");
			GetUpDelay = obj.CreateEntry<float>("GetUpDelay", 3f, "Seconds a knocked-down NPC stays limp", (string)null, false, false, (ValueValidator)null, (string)null);
			KnockbackForce = obj.CreateEntry<float>("KnockbackForce", 4f, "Shove on hit (0 = none)", (string)null, false, false, (ValueValidator)null, (string)null);
			KnockdownDamage = obj.CreateEntry<float>("KnockdownDamage", 0.5f, "Hits at/above this damage knock the NPC down (0 = every hit)", (string)null, false, false, (ValueValidator)null, (string)null);
			UseGameStun = obj.CreateEntry<bool>("UseGameStun", true, "Light hits use the game's own per-limb stun (false = whole-body muscle dip)", (string)null, false, false, (ValueValidator)null, (string)null);
			LightStunLevel = obj.CreateEntry<float>("LightStunLevel", 0.15f, "Light hits: how limp the hit limb goes (0 = fully limp, 1 = normal)", (string)null, false, false, (ValueValidator)null, (string)null);
			LightMuscleWeight = obj.CreateEntry<float>("LightMuscleWeight", 0.3f, "Fallback dip: muscle strength during a light hit (0 = limp, 1 = normal)", (string)null, false, false, (ValueValidator)null, (string)null);
			LightSeconds = obj.CreateEntry<float>("LightSeconds", 0.4f, "Fallback dip: how long a light hit lasts", (string)null, false, false, (ValueValidator)null, (string)null);
			RecoverSeconds = obj.CreateEntry<float>("RecoverSeconds", 0.8f, "How long it takes to stiffen back up afterwards", (string)null, false, false, (ValueValidator)null, (string)null);
			SlowMoScale = obj.CreateEntry<float>("SlowMoScale", 1f, "Time scale on a kill (1 = off, 0.3 = slow-mo)", (string)null, false, false, (ValueValidator)null, (string)null);
			SlowMoSeconds = obj.CreateEntry<float>("SlowMoSeconds", 1f, "Slow-mo length in real seconds", (string)null, false, false, (ValueValidator)null, (string)null);
			LogHits = obj.CreateEntry<bool>("LogHits", true, "Log the first 50 hits (damage, muscle, tier)", (string)null, false, false, (ValueValidator)null, (string)null);
			Enabled = obj.CreateEntry<bool>("Enabled", true, "Master switch: base reactions + API events on/off", (string)null, false, false, (ValueValidator)null, (string)null);
			DeathMuscle = obj.CreateEntry<float>("DeathMuscle", 0f, "Muscle left on death (0 = limp corpse, no death animation; excluded NPCs keep theirs)", (string)null, false, false, (ValueValidator)null, (string)null);
			GunDamageScale = obj.CreateEntry<float>("GunDamageScale", 0.5f, "Gun damage multiplier before the game applies it (1 = vanilla lethal, 0.3 = ~3x longer to die so reactions play)", (string)null, false, false, (ValueValidator)null, (string)null);
			MeleeDamageScale = obj.CreateEntry<float>("MeleeDamageScale", 0.65f, "Melee/prop-weapon damage multiplier (1 = vanilla, 0.65 = gentler than guns)", (string)null, false, false, (ValueValidator)null, (string)null);
			HeadshotKill = obj.CreateEntry<bool>("HeadshotKill", true, "Headshots always kill: gun hits to the head use lethal damage (off = scaled like body hits)", (string)null, false, false, (ValueValidator)null, (string)null);
			RagdollApi.EnabledEntry = Enabled;
			try
			{
				RagdollApi.DeathMuscleEntry = DeathMuscle;
			}
			catch
			{
			}
			string text = "1.0.21";
			try
			{
				MelonInfoAttribute val = (MelonInfoAttribute)Attribute.GetCustomAttribute(typeof(Main).Assembly, typeof(MelonInfoAttribute));
				if (val != null && !string.IsNullOrEmpty(val.Version))
				{
					text = val.Version;
				}
			}
			catch
			{
			}
			((MelonBase)this).LoggerInstance.Msg("DynamicRagdoll2 " + text + " loaded.");
			GunHook.TryInstall();
			EnvImpactProbe.TryInstall();
		}

		public override void OnFixedUpdate()
		{
			try
			{
				EnvImpactProbe.OnFixedUpdate();
			}
			catch
			{
			}
		}

		public override void OnSceneWasLoaded(int buildIndex, string sceneName)
		{
			LastReact.Clear();
			HealthCache.Clear();
			NoHealth.Clear();
			RagdollApi.ClearNpcCache();
			EnvImpactProbe.Clear();
		}

		private static string SafeName(PuppetMaster pm)
		{
			try
			{
				return ((Object)pm).name + "#" + ((Object)pm).GetInstanceID().ToString("X8");
			}
			catch
			{
				return "?";
			}
		}

		internal static bool IsGunHit(string attackType)
		{
			try
			{
				if (string.IsNullOrEmpty(attackType))
				{
					return false;
				}
				string text = attackType.ToLowerInvariant();
				if (text.Contains("impact"))
				{
					return false;
				}
				return text.Contains("pierc") || text.Contains("bullet") || text.Contains("projectile") || text.Contains("gunshot");
			}
			catch
			{
				return false;
			}
		}

		internal static float GunScale()
		{
			try
			{
				if (GunDamageScale == null)
				{
					return 1f;
				}
				float value = GunDamageScale.Value;
				if (!(value > 0.01f))
				{
					return 1f;
				}
				return Mathf.Clamp(value, 0.05f, 1f);
			}
			catch
			{
				return 1f;
			}
		}

		internal static bool IsMeleeHit(string attackType)
		{
			try
			{
				if (string.IsNullOrEmpty(attackType))
				{
					return false;
				}
				string text = attackType.ToLowerInvariant();
				if (text.Contains("impact"))
				{
					return false;
				}
				return text.Contains("blunt") || text.Contains("stab") || text.Contains("slash") || text.Contains("punch") || text.Contains("melee") || text.Contains("claw") || text.Contains("bite") || text.Contains("cut") || text.Contains("axe") || text.Contains("blade") || text.Contains("bat") || text.Contains("whip") || text.Contains("chop") || text.Contains("prop");
			}
			catch
			{
				return false;
			}
		}

		internal static float MeleeScale()
		{
			try
			{
				if (MeleeDamageScale == null)
				{
					return 1f;
				}
				float value = MeleeDamageScale.Value;
				if (!(value > 0.01f))
				{
					return 1f;
				}
				return Mathf.Clamp(value, 0.05f, 1f);
			}
			catch
			{
				return 1f;
			}
		}

		internal static void HandleHit(MuscleCollisionBroadcaster b, object attack)
		{
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_0317: Unknown result type (might be due to invalid IL or missing references)
			//IL_031c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0335: Unknown result type (might be due to invalid IL or missing references)
			//IL_0341: Unknown result type (might be due to invalid IL or missing references)
			//IL_0346: Unknown result type (might be due to invalid IL or missing references)
			//IL_034b: Unknown result type (might be due to invalid IL or missing references)
			//IL_034f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0354: Unknown result type (might be due to invalid IL or missing references)
			//IL_030e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0313: Unknown result type (might be due to invalid IL or missing references)
			//IL_0512: Unknown result type (might be due to invalid IL or missing references)
			//IL_054c: Unknown result type (might be due to invalid IL or missing references)
			//IL_054e: Unknown result type (might be due to invalid IL or missing references)
			//IL_056f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0571: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_024b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0250: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			PuppetMaster puppetMaster = b.puppetMaster;
			if ((Object)(object)puppetMaster == (Object)null || !Enabled.Value || RagdollApi.IsExcluded(puppetMaster))
			{
				return;
			}
			if (!_dumpedAttack && attack != null)
			{
				_dumpedAttack = true;
				Reflect.LogMembers(attack, "Attack members", includeBases: false);
			}
			int muscleIndex = b.muscleIndex;
			if (!_dumpedStructure)
			{
				_dumpedStructure = true;
				DumpStructure(puppetMaster);
			}
			Rigidbody val = ((Component)b).GetComponent<Rigidbody>();
			if ((Object)(object)val == (Object)null)
			{
				val = ((Component)b).GetComponentInParent<Rigidbody>();
			}
			if (!Reflect.TryGet<float>(attack, "damage", out var value))
			{
				value = -1f;
			}
			string text = "Unknown";
			try
			{
				if (attack != null && Reflect.TryGetObj(attack, "attackType", out var value2) && value2 != null)
				{
					text = value2.ToString();
					if (_attackTypeLogs.Count < 5 && _attackTypeLogs.Add(text))
					{
						MelonLogger.Msg("AttackType seen: " + text);
					}
				}
			}
			catch
			{
			}
			if (_sourceLogs < 24)
			{
				bool flag = false;
				try
				{
					flag = !puppetMaster.isAlive || puppetMaster.isKilling;
				}
				catch
				{
				}
				if (value >= KnockdownDamage.Value || flag)
				{
					_sourceLogs++;
					string value3 = "?";
					string value4 = "?";
					try
					{
						if (attack != null && Reflect.TryGetObj(attack, "collider", out var value5) && value5 != null)
						{
							object value6 = null;
							try
							{
								Reflect.TryGetObj(value5, "name", out value6);
							}
							catch
							{
							}
							value3 = (value6 ?? value5.ToString())?.ToString() ?? "?";
						}
						if (attack != null && Reflect.TryGetObj(attack, "proxy", out var value7) && value7 != null)
						{
							value4 = value7.ToString();
						}
					}
					catch
					{
					}
					MelonLogger.Msg($"Hit source: type={text} collider={value3} proxy={value4} dmg={value:F2}");
				}
			}
			Vector3 hitPoint = Vector3.zero;
			bool flag2 = false;
			Vector3 val2;
			try
			{
				if (attack != null && Reflect.TryGet<Vector3>(attack, "origin", out var value8))
				{
					val2 = value8 - ((Component)b).transform.position;
					float magnitude = ((Vector3)(ref val2)).magnitude;
					if (magnitude < 1.5f)
					{
						hitPoint = value8;
						flag2 = true;
					}
					if (_originLogs < 5)
					{
						_originLogs++;
						MelonLogger.Msg($"[hit-origin {_originLogs}/5] origin->muscle dist={magnitude:F2}m {(flag2 ? "TRUSTED" : "rejected (muzzle?)")}");
					}
				}
			}
			catch
			{
			}
			Vector3 val3;
			if (Reflect.TryGet<Vector3>(attack, "direction", out var value9) && ((Vector3)(ref value9)).sqrMagnitude > 0.0001f)
			{
				val3 = ((Vector3)(ref value9)).normalized;
			}
			else
			{
				val3 = Vector3.up;
				Camera main = Camera.main;
				if ((Object)(object)main != (Object)null)
				{
					val2 = ((Component)b).transform.position - ((Component)main).transform.position;
					val3 = ((Vector3)(ref val2)).normalized;
				}
			}
			bool flag3 = !puppetMaster.isAlive || puppetMaster.isKilling;
			float num = value;
			try
			{
				bool flag4 = IsGunHit(text);
				bool flag5 = !flag4 && IsMeleeHit(text);
				if (!flag4 && !flag5 && text == "Unknown" && GunHook.Attribute() != "Unknown")
				{
					flag4 = true;
				}
				float num2 = (flag4 ? GunScale() : (flag5 ? MeleeScale() : 1f));
				if (num2 < 0.999f && num2 > 0.001f && value > 0f)
				{
					num = value / num2;
				}
			}
			catch
			{
			}
			HitTier hitTier = (flag3 ? HitTier.Kill : ((!(num >= 0f) || !(num < KnockdownDamage.Value)) ? HitTier.Medium : HitTier.Light));
			MuscleRegion muscleRegion = RagdollApi.RegionOf(muscleIndex);
			if (LogHits.Value && _hitLogCount < 50)
			{
				_hitLogCount++;
				MelonLogger.Msg($"[hit {_hitLogCount}/50] muscle={muscleIndex} ({muscleRegion}) damage={num:F2} tier={hitTier} dead={flag3} npc={SafeName(puppetMaster)}");
			}
			BehaviourPuppet val4 = FindPuppet(puppetMaster);
			SubBehaviourHealth health = FindHealth(puppetMaster);
			React(puppetMaster, val4, health, hitTier, muscleRegion, val, val3);
			RagdollApi.Raise(new NpcHitInfo
			{
				Puppet = puppetMaster,
				Behaviour = val4,
				Health = health,
				MuscleIndex = muscleIndex,
				Region = muscleRegion,
				Body = val,
				HitPoint = hitPoint,
				HasHitPoint = flag2,
				AttackType = text,
				Gun = GunHook.Attribute(),
				Direction = val3,
				Damage = num,
				Tier = hitTier,
				IsDead = flag3
			});
		}

		internal static BehaviourPuppet FindPuppet(PuppetMaster pm)
		{
			BehaviourPuppet componentInChildren = ((Component)pm).GetComponentInChildren<BehaviourPuppet>(true);
			if ((Object)(object)componentInChildren != (Object)null)
			{
				return componentInChildren;
			}
			try
			{
				Il2CppReferenceArray<BehaviourBase> behaviours = pm.behaviours;
				if (behaviours != null)
				{
					foreach (BehaviourBase item in (Il2CppArrayBase<BehaviourBase>)(object)behaviours)
					{
						if (!((Object)(object)item == (Object)null))
						{
							BehaviourPuppet val = ((Il2CppObjectBase)item).TryCast<BehaviourPuppet>();
							if ((Object)(object)val != (Object)null)
							{
								return val;
							}
						}
					}
				}
			}
			catch
			{
			}
			return null;
		}

		internal static SubBehaviourHealth FindHealth(PuppetMaster pm)
		{
			int instanceID = ((Object)pm).GetInstanceID();
			if (HealthCache.TryGetValue(instanceID, out var value) && value != null)
			{
				return value;
			}
			if (NoHealth.Contains(instanceID))
			{
				return null;
			}
			try
			{
				foreach (BehaviourBase item in (Il2CppArrayBase<BehaviourBase>)(object)pm.behaviours)
				{
					if ((Object)(object)item == (Object)null)
					{
						continue;
					}
					string className;
					string memberName;
					SubBehaviourHealth val = Reflect.FindMemberOfType<SubBehaviourHealth>(Reflect.ResolveRuntimeType((Il2CppObjectBase)(object)item, out className), out memberName);
					if (val != null)
					{
						if (HealthCache.Count > 512)
						{
							HealthCache.Clear();
						}
						HealthCache[instanceID] = val;
						if (!_loggedHealth)
						{
							_loggedHealth = true;
							MelonLogger.Msg("Found SubBehaviourHealth at " + memberName);
							Reflect.LogValues(val, "SubBehaviourHealth values");
						}
						return val;
					}
				}
			}
			catch (Exception ex)
			{
				MelonLogger.Warning("FindHealth failed: " + ex.Message);
			}
			if (NoHealth.Count > 512)
			{
				NoHealth.Clear();
			}
			NoHealth.Add(instanceID);
			if (!_loggedNoHealth)
			{
				_loggedNoHealth = true;
				MelonLogger.Msg("No SubBehaviourHealth found on this NPC; light hits use the muscle dip instead.");
			}
			return null;
		}

		private static void React(PuppetMaster pm, BehaviourPuppet bp, SubBehaviourHealth health, HitTier tier, MuscleRegion region, Rigidbody body, Vector3 dir)
		{
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			int instanceID = ((Object)pm).GetInstanceID();
			float time = Time.time;
			if (tier != HitTier.Kill && LastReact.TryGetValue(instanceID, out var value) && time - value < 0.25f)
			{
				return;
			}
			LastReact[instanceID] = time;
			float num = 0f;
			switch (tier)
			{
			case HitTier.Light:
				num = 0.25f;
				if (health != null && UseGameStun.Value)
				{
					RagdollApi.SetLimbStun(health, region, LightStunLevel.Value);
					if (!_loggedStun)
					{
						_loggedStun = true;
						MelonLogger.Msg($"Light hit -> limb stun on {region}");
					}
				}
				else
				{
					Dip(pm, null, LightMuscleWeight.Value, LightSeconds.Value);
					if (!_loggedLightDip)
					{
						_loggedLightDip = true;
						MelonLogger.Msg("Light hit -> muscleWeight dip");
					}
				}
				break;
			case HitTier.Medium:
				if (!RagdollApi.AutoKnockdown)
				{
					break;
				}
				num = 1f;
				if ((Object)(object)bp != (Object)null)
				{
					bp.canGetUp = true;
					bp.getUpDelay = GetUpDelay.Value;
					bp.Unpin();
					if (!_loggedUnpin)
					{
						_loggedUnpin = true;
						MelonLogger.Msg("Medium hit -> BehaviourPuppet.Unpin()");
					}
				}
				else
				{
					Dip(pm, health, 0f, GetUpDelay.Value);
					if (!_loggedMedium)
					{
						_loggedMedium = true;
						MelonLogger.Msg("Medium hit -> muscleWeight drop (limb stun frozen while down)");
					}
				}
				break;
			case HitTier.Kill:
				ReleaseNow(pm);
				num = 1.5f;
				SlowMo(SlowMoSeconds.Value, SlowMoScale.Value);
				if (!_loggedKill)
				{
					_loggedKill = true;
					Reflect.TryGet<object>(pm, "state", out var value2);
					MelonLogger.Msg($"Kill -> PuppetMaster state={value2}");
				}
				break;
			}
			if ((Object)(object)body != (Object)null && num > 0f && KnockbackForce.Value > 0f)
			{
				body.AddForce(dir * KnockbackForce.Value * num, (ForceMode)2);
			}
		}

		internal static void HoldMapping(PuppetMaster pm, float seconds)
		{
			HoldMapping(pm, seconds, 1f);
		}

		internal static void HoldMapping(PuppetMaster pm, float seconds, float weight)
		{
			int instanceID = ((Object)pm).GetInstanceID();
			float num = Time.time + seconds;
			if (MapHolds.TryGetValue(instanceID, out var value))
			{
				value.Until = Mathf.Max(value.Until, num);
				value.Weight = Mathf.Min(value.Weight, weight);
				return;
			}
			value = new MapHold
			{
				Original = pm.mappingWeight,
				Weight = weight,
				Until = num
			};
			MapHolds[instanceID] = value;
			MelonCoroutines.Start(MapRoutine(pm, instanceID, value));
		}

		private static IEnumerator MapRoutine(PuppetMaster pm, int id, MapHold h)
		{
			while ((Object)(object)pm != (Object)null && pm.isAlive && Time.time < h.Until)
			{
				pm.mappingWeight = h.Weight;
				yield return null;
			}
			if ((Object)(object)pm != (Object)null)
			{
				try
				{
					pm.mappingWeight = h.Original;
				}
				catch
				{
				}
			}
			MapHolds.Remove(id);
		}

		internal static void HoldBoolFlag(PuppetMaster pm, string field, bool value, float seconds)
		{
			string key = ((Object)pm).GetInstanceID() + ":" + field;
			float num = Time.time + seconds;
			if (FlagHolds.TryGetValue(key, out var value2))
			{
				value2.Until = Mathf.Max(value2.Until, num);
				return;
			}
			object obj = null;
			bool flag = !value;
			try
			{
				foreach (BehaviourBase item in (Il2CppArrayBase<BehaviourBase>)(object)pm.behaviours)
				{
					if (!((Object)(object)item == (Object)null))
					{
						string className;
						object obj2 = Reflect.ResolveRuntimeType((Il2CppObjectBase)(object)item, out className) ?? item;
						if (Reflect.TryGet<bool>(obj2, field, out var value3))
						{
							obj = obj2;
							flag = value3;
							break;
						}
					}
				}
			}
			catch
			{
			}
			if (obj == null)
			{
				if (_locoLogs < 8)
				{
					_locoLogs++;
					MelonLogger.Msg("HoldFlag: no " + field + " found on this NPC, nothing held");
				}
				return;
			}
			value2 = new FlagHold
			{
				Beh = obj,
				Original = flag,
				Until = num
			};
			FlagHolds[key] = value2;
			Reflect.TrySetBool(obj, field, value);
			bool value4;
			bool flag2 = Reflect.TryGet<bool>(obj, field, out value4);
			if (_locoLogs < 8)
			{
				_locoLogs++;
				MelonLogger.Msg($"HoldFlag: {field} was {flag}, now reads {(flag2 ? value4.ToString() : "?")} -> {((flag2 && value4 == value) ? "held" : "WRITE FAILED")}");
			}
			MelonCoroutines.Start(FlagRoutine(pm, key, value2, field, value));
		}

		private static IEnumerator FlagRoutine(PuppetMaster pm, string key, FlagHold h, string field, bool value)
		{
			int frame = 0;
			while (((Object)(object)pm == (Object)null || pm.isAlive) && Time.time < h.Until)
			{
				if (h.Beh != null && (frame++ & 0xF) == 0)
				{
					Reflect.TrySetBool(h.Beh, field, value);
				}
				yield return null;
			}
			if (h.Beh != null && ((Object)(object)pm == (Object)null || pm.isAlive))
			{
				Reflect.TrySetBool(h.Beh, field, h.Original);
			}
			FlagHolds.Remove(key);
		}

		internal static void HoldLoco(PuppetMaster pm, float seconds)
		{
			HoldBoolFlag(pm, "followPlayer", value: false, seconds);
		}

		internal static void HoldNav(PuppetMaster pm, float seconds)
		{
			HoldBoolFlag(pm, "_isNavAgentStopped", value: true, seconds);
		}

		internal static void HoldLiteLoco(PuppetMaster pm, float seconds)
		{
			string key = ((Object)pm).GetInstanceID() + ":liteloco.weight";
			float num = Time.time + seconds;
			if (FloatHolds.TryGetValue(key, out var value))
			{
				value.Until = Mathf.Max(value.Until, num);
				return;
			}
			object obj = null;
			float num2 = 1f;
			try
			{
				foreach (BehaviourBase item in (Il2CppArrayBase<BehaviourBase>)(object)pm.behaviours)
				{
					if (!((Object)(object)item == (Object)null) && Reflect.TryGetObj(Reflect.ResolveRuntimeType((Il2CppObjectBase)(object)item, out var _) ?? item, "_liteLoco", out var value2) && value2 != null)
					{
						obj = value2;
						break;
					}
				}
			}
			catch
			{
			}
			if (obj == null)
			{
				if (_locoLogs < 10)
				{
					_locoLogs++;
					MelonLogger.Msg("HoldLiteLoco: no _liteLoco on this NPC, nothing held");
				}
				return;
			}
			if (!Reflect.TryGet<float>(obj, "weight", out var value3))
			{
				value3 = 1f;
			}
			num2 = value3;
			value = new FloatHold
			{
				Target = obj,
				Original = num2,
				Until = num
			};
			FloatHolds[key] = value;
			Reflect.TrySet(obj, "weight", 0f);
			float value4;
			bool flag = Reflect.TryGet<float>(obj, "weight", out value4);
			if (_locoLogs < 10)
			{
				_locoLogs++;
				MelonLogger.Msg($"HoldLiteLoco: weight was {num2:F2}, now reads {(flag ? value4.ToString("F2") : "?")} -> {((flag && value4 < 0.01f) ? "held" : "WRITE FAILED")}");
			}
			MelonCoroutines.Start(FloatRoutine(pm, key, value));
		}

		private static IEnumerator FloatRoutine(PuppetMaster pm, string key, FloatHold h)
		{
			int frame = 0;
			while (((Object)(object)pm == (Object)null || pm.isAlive) && Time.time < h.Until)
			{
				if (h.Target != null && (frame++ & 0xF) == 0)
				{
					Reflect.TrySet(h.Target, "weight", 0f);
				}
				yield return null;
			}
			if (h.Target != null && ((Object)(object)pm == (Object)null || pm.isAlive))
			{
				Reflect.TrySet(h.Target, "weight", h.Original);
			}
			FloatHolds.Remove(key);
		}

		internal static void ReleaseAI(PuppetMaster pm)
		{
			int instanceID;
			try
			{
				instanceID = ((Object)pm).GetInstanceID();
			}
			catch
			{
				return;
			}
			string[] array = new string[2] { "followPlayer", "_isNavAgentStopped" };
			foreach (string text in array)
			{
				string key = instanceID + ":" + text;
				if (FlagHolds.TryGetValue(key, out var value))
				{
					value.Until = 0f;
				}
			}
			string key2 = instanceID + ":liteloco.weight";
			if (FloatHolds.TryGetValue(key2, out var value2))
			{
				value2.Until = 0f;
			}
		}

		internal static void KnockDown(PuppetMaster pm, SubBehaviourHealth health, float seconds)
		{
			Dip(pm, health, 0f, seconds);
		}

		internal static void HoldLimp(PuppetMaster pm, SubBehaviourHealth health, float weight, float seconds)
		{
			Dip(pm, health, weight, seconds);
		}

		internal static void ReleaseNow(PuppetMaster pm)
		{
			int instanceID;
			try
			{
				instanceID = ((Object)pm).GetInstanceID();
			}
			catch
			{
				return;
			}
			if (Reactions.TryGetValue(instanceID, out var value))
			{
				try
				{
					pm.muscleWeight = value.Original;
				}
				catch
				{
				}
				Reactions.Remove(instanceID);
			}
			if (MapHolds.TryGetValue(instanceID, out var value2))
			{
				try
				{
					pm.mappingWeight = value2.Original;
				}
				catch
				{
				}
				MapHolds.Remove(instanceID);
			}
		}

		internal static void Diag(PuppetMaster pm)
		{
			if ((Object)(object)pm == (Object)null || _diagCount >= 8)
			{
				return;
			}
			_diagCount++;
			try
			{
				MelonLogger.Msg($"Diag #{_diagCount}: muscleWeight={pm.muscleWeight:F2} mappingWeight={pm.mappingWeight:F2} spring={pm.muscleSpring:F2} damper={pm.muscleDamper:F2}");
				foreach (BehaviourBase item in (Il2CppArrayBase<BehaviourBase>)(object)pm.behaviours)
				{
					if ((Object)(object)item == (Object)null)
					{
						continue;
					}
					string className;
					object o = Reflect.ResolveRuntimeType((Il2CppObjectBase)(object)item, out className) ?? item;
					List<string> list = new List<string>();
					string[] array = new string[9] { "followPlayer", "_isNavAgentStopped", "engagedMode", "locoState", "mentalState", "useAiLocoController", "aggression", "_unbalancedTimer", "_dyingTime" };
					foreach (string text in array)
					{
						if (Reflect.TryGetObj(o, text, out var value))
						{
							list.Add($"{text}={value}");
						}
					}
					MelonLogger.Msg($"Diag #{_diagCount} [{className}]: {string.Join(", ", list)}");
					if (_diagCount != 1)
					{
						continue;
					}
					array = new string[2] { "aiLocoController", "_liteLoco" };
					foreach (string text2 in array)
					{
						try
						{
							if (!Reflect.TryGetObj(o, text2, out var value2))
							{
								goto IL_0281;
							}
							Il2CppObjectBase val = (Il2CppObjectBase)((value2 is Il2CppObjectBase) ? value2 : null);
							if (val == null || val == null)
							{
								goto IL_0281;
							}
							Reflect.LogMembers(Reflect.ResolveRuntimeType(val, out var className2) ?? value2, "Loco [" + className2 + "]", includeBases: false);
							goto end_IL_023b;
							IL_0281:
							MelonLogger.Msg("Loco [" + text2 + "]: null/unreadable");
							end_IL_023b:;
						}
						catch (Exception ex)
						{
							MelonLogger.Msg("Loco [" + text2 + "]: " + ex.Message);
						}
					}
				}
				try
				{
					Muscle val2 = ((Il2CppArrayBase<Muscle>)(object)pm.muscles)[1];
					if (val2 != null && val2.props != null)
					{
						Reflect.LogMembers(val2.props, "MuscleProps members", includeBases: false);
					}
					int[] array2 = new int[2] { 1, 4 };
					foreach (int num in array2)
					{
						Muscle val3 = ((Il2CppArrayBase<Muscle>)(object)pm.muscles)[num];
						if (val3 == null || val3.props == null)
						{
							continue;
						}
						List<string> list2 = new List<string>();
						string[] array = new string[4] { "muscleWeight", "pinWeight", "mappingWeight", "muscleDamper" };
						foreach (string text3 in array)
						{
							if (Reflect.TryGetObj(val3.props, text3, out var value3))
							{
								list2.Add($"{text3}={value3}");
							}
						}
						MelonLogger.Msg($"Diag #{_diagCount} muscle[{num}]: {string.Join(", ", list2)}");
					}
				}
				catch (Exception ex2)
				{
					MelonLogger.Msg($"Diag #{_diagCount} muscles: unreadable ({ex2.Message})");
				}
			}
			catch (Exception ex3)
			{
				MelonLogger.Warning("Diag failed: " + ex3.Message);
			}
		}

		private static void Dip(PuppetMaster pm, SubBehaviourHealth health, float weight, float hold)
		{
			int instanceID = ((Object)pm).GetInstanceID();
			float time = Time.time;
			if (Reactions.TryGetValue(instanceID, out var value))
			{
				bool flag = time < value.HoldUntil;
				if (!flag || !(weight > value.Weight))
				{
					value.Weight = weight;
					value.HoldUntil = (flag ? Mathf.Max(value.HoldUntil, time + hold) : (time + hold));
				}
				return;
			}
			value = new Reaction
			{
				Original = ((pm.muscleWeight > 0.01f) ? pm.muscleWeight : 1f),
				Weight = weight,
				HoldUntil = time + hold,
				Health = health,
				Held = ((health != null) ? new float[StunFields.Length] : null)
			};
			if (health != null)
			{
				ReadStun(health, value.Held);
			}
			Reactions[instanceID] = value;
			MelonCoroutines.Start(ReactionRoutine(pm, instanceID, value));
		}

		private static IEnumerator ReactionRoutine(PuppetMaster pm, int id, Reaction r)
		{
			float current = pm.muscleWeight;
			while ((Object)(object)pm != (Object)null)
			{
				if (!pm.isAlive || pm.isKilling)
				{
					try
					{
						pm.muscleWeight = r.Original;
					}
					catch
					{
					}
					Reactions.Remove(id);
					yield break;
				}
				if (Time.time < r.HoldUntil)
				{
					current = Mathf.MoveTowards(current, r.Weight, 20f * Time.deltaTime);
					if (r.Health != null)
					{
						HoldStun(r);
					}
				}
				else
				{
					if (r.Health != null)
					{
						ReadStun(r.Health, r.Held);
					}
					float num = r.Original / Mathf.Max(0.05f, RecoverSeconds.Value);
					current = Mathf.MoveTowards(current, r.Original, num * Time.deltaTime);
					if (Mathf.Approximately(current, r.Original))
					{
						break;
					}
				}
				pm.muscleWeight = current;
				HoldMapping(pm, 0.15f);
				yield return null;
			}
			if ((Object)(object)pm != (Object)null && pm.isAlive)
			{
				pm.muscleWeight = r.Original;
			}
			Reactions.Remove(id);
		}

		private static void ReadStun(SubBehaviourHealth h, float[] into)
		{
			for (int i = 0; i < StunFields.Length; i++)
			{
				into[i] = (Reflect.TryGet<float>(h, StunFields[i], out var value) ? value : 1f);
			}
		}

		private static void HoldStun(Reaction r)
		{
			for (int i = 0; i < StunFields.Length; i++)
			{
				if (Reflect.TryGet<float>(r.Health, StunFields[i], out var value))
				{
					float num = Mathf.Min(r.Held[i], value);
					r.Held[i] = num;
					if (value > num)
					{
						Reflect.TrySet(r.Health, StunFields[i], num);
					}
				}
			}
		}

		private static void SlowMo(float seconds, float scale)
		{
			if (!(seconds <= 0f) && !(scale >= 1f) && !_slowActive)
			{
				MelonCoroutines.Start(SlowRoutine(seconds, scale));
			}
		}

		private static IEnumerator SlowRoutine(float seconds, float scale)
		{
			_slowActive = true;
			float previous = Time.timeScale;
			Time.timeScale = scale;
			float t = 0f;
			while (t < seconds)
			{
				t += Time.unscaledDeltaTime;
				yield return null;
			}
			if (Mathf.Approximately(Time.timeScale, scale))
			{
				Time.timeScale = previous;
			}
			_slowActive = false;
		}

		private static void DumpStructure(PuppetMaster pm)
		{
			try
			{
				foreach (BehaviourBase item in (Il2CppArrayBase<BehaviourBase>)(object)pm.behaviours)
				{
					if (!((Object)(object)item == (Object)null))
					{
						string className;
						object obj = Reflect.ResolveRuntimeType((Il2CppObjectBase)(object)item, out className);
						MelonLogger.Msg($"Behaviour runtime class: {className} (wrapper found: {obj != null})");
						if (obj != null)
						{
							Reflect.LogMembers(obj, "Behaviour members", includeBases: true);
						}
					}
				}
			}
			catch (Exception ex)
			{
				MelonLogger.Warning("Structure dump failed: " + ex.Message);
			}
		}
	}
	internal static class GunHook
	{
		internal static string LastGun = "Unknown";

		internal static float LastGunTime = -100f;

		private static readonly HashSet<string> Seen = new HashSet<string>();

		private static readonly string[] KnownGuns = new string[4] { "Il2CppSLZ.Marrow.Gun", "Il2CppSLZ.Bonelab.ObjectiveGun", "Il2CppSLZ.Bonelab.GunHeat", "Il2CppSLZ.Bonelab.SpawnGun" };

		private static readonly string[] KnownAssemblies = new string[4] { "Il2CppSLZ.Marrow", "Il2CppSLZ.Bonelab", "Assembly-CSharp", "Assembly-CSharp-firstpass" };

		private static Type FindGunType(string fullName)
		{
			try
			{
				string[] knownAssemblies = KnownAssemblies;
				foreach (string text in knownAssemblies)
				{
					Assembly assembly = null;
					try
					{
						Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
						foreach (Assembly assembly2 in assemblies)
						{
							string name;
							try
							{
								name = assembly2.GetName().Name;
							}
							catch
							{
								continue;
							}
							if (name == text)
							{
								assembly = assembly2;
								break;
							}
						}
					}
					catch
					{
						continue;
					}
					if (!(assembly == null) && !assembly.IsDynamic)
					{
						Type type = null;
						try
						{
							type = assembly.GetType(fullName, throwOnError: false, ignoreCase: false);
						}
						catch
						{
						}
						if (type != null)
						{
							return type;
						}
					}
				}
			}
			catch
			{
			}
			return null;
		}

		private static int PatchOnFire(Type t, Harmony harmony, HarmonyMethod post)
		{
			MethodInfo[] array = null;
			try
			{
				array = t.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
			}
			catch
			{
				return 0;
			}
			int num = 0;
			MethodInfo[] array2 = array;
			foreach (MethodInfo methodInfo in array2)
			{
				if (methodInfo == null || methodInfo.Name != "OnFire")
				{
					continue;
				}
				try
				{
					harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, post, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
					num++;
					try
					{
						MelonLogger.Msg("Gun hook: " + t.FullName + ".OnFire");
					}
					catch
					{
					}
				}
				catch (Exception ex)
				{
					MelonLogger.Warning("Gun hook failed on " + t.FullName + ": " + ex.Message);
				}
				if (num >= 2)
				{
					break;
				}
			}
			return num;
		}

		internal static void TryInstall()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Expected O, but got Unknown
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			try
			{
				int num = 0;
				Harmony harmony = new Harmony("HitRagdoll.GunHook");
				HarmonyMethod val = null;
				try
				{
					val = new HarmonyMethod(typeof(GunHook).GetMethod("Fired", BindingFlags.Static | BindingFlags.NonPublic));
				}
				catch
				{
				}
				if (val != null)
				{
					string[] knownGuns = KnownGuns;
					foreach (string fullName in knownGuns)
					{
						Type type = null;
						try
						{
							type = FindGunType(fullName);
						}
						catch
						{
						}
						if (!(type == null))
						{
							try
							{
								num += PatchOnFire(type, harmony, val);
							}
							catch
							{
							}
							if (num >= 6)
							{
								break;
							}
						}
					}
				}
				if (num == 0)
				{
					num = LegacyScan();
				}
				MelonLogger.Msg((num > 0) ? $"Gun hook: {num} OnFire patched" : "Gun hook: no OnFire found, damage bands only");
			}
			catch (Exception ex)
			{
				MelonLogger.Warning("Gun hook install failed: " + ex.Message);
			}
		}

		private static int LegacyScan()
		{
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Expected O, but got Unknown
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			int num = 0;
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			foreach (Assembly assembly in assemblies)
			{
				try
				{
					if (assembly.IsDynamic)
					{
						continue;
					}
				}
				catch
				{
					continue;
				}
				string name;
				try
				{
					name = assembly.GetName().Name;
				}
				catch
				{
					continue;
				}
				if (!name.StartsWith("Il2Cpp") && !(name == "Assembly-CSharp") && !(name == "Assembly-CSharp-firstpass"))
				{
					continue;
				}
				Type[] types;
				try
				{
					types = assembly.GetTypes();
				}
				catch
				{
					continue;
				}
				Type[] array = types;
				foreach (Type type in array)
				{
					try
					{
						if (type.IsAbstract || type.IsInterface || type.IsEnum || (type.Name ?? "").IndexOf("Gun", StringComparison.OrdinalIgnoreCase) < 0)
						{
							continue;
						}
						MethodInfo[] methods = type.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
						foreach (MethodInfo methodInfo in methods)
						{
							if (methodInfo.Name != "OnFire")
							{
								continue;
							}
							try
							{
								HarmonyMethod val = new HarmonyMethod(typeof(GunHook).GetMethod("Fired", BindingFlags.Static | BindingFlags.NonPublic));
								new Harmony("HitRagdoll.GunHook").Patch((MethodBase)methodInfo, (HarmonyMethod)null, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
								num++;
								try
								{
									MelonLogger.Msg("Gun hook: " + type.FullName + ".OnFire");
								}
								catch
								{
								}
							}
							catch (Exception ex)
							{
								MelonLogger.Warning("Gun hook failed on " + type.FullName + ": " + ex.Message);
							}
							if (num >= 6)
							{
								break;
							}
						}
						goto IL_01a3;
					}
					catch
					{
						goto IL_01a3;
					}
					IL_01a3:
					if (num >= 6)
					{
						break;
					}
				}
				if (num >= 6)
				{
					break;
				}
			}
			return num;
		}

		private static void Fired(object __instance)
		{
			try
			{
				string text = null;
				try
				{
					if (__instance != null && Reflect.TryGetObj(__instance, "name", out var value) && value != null)
					{
						text = value.ToString();
					}
				}
				catch
				{
				}
				if (string.IsNullOrEmpty(text))
				{
					try
					{
						text = __instance?.GetType().Name;
					}
					catch
					{
					}
				}
				if (!string.IsNullOrEmpty(text))
				{
					LastGun = text;
					LastGunTime = Time.time;
					if (Seen.Count < 8 && Seen.Add(text))
					{
						MelonLogger.Msg("Gun seen: " + text);
					}
				}
			}
			catch
			{
			}
		}

		internal static string Attribute()
		{
			try
			{
				if (Time.time - LastGunTime < 0.6f)
				{
					return LastGun;
				}
			}
			catch
			{
			}
			return "Unknown";
		}
	}
	[HarmonyPatch(typeof(MuscleCollisionBroadcaster), "ReceiveAttack")]
	internal static class HitPatch
	{
		private static void Prefix(MuscleCollisionBroadcaster __instance, object __0)
		{
			try
			{
				if (__0 == null)
				{
					return;
				}
				string text = "Unknown";
				try
				{
					if (Reflect.TryGetObj(__0, "attackType", out var value) && value != null)
					{
						text = value.ToString();
					}
				}
				catch
				{
				}
				try
				{
					if (Main.HeadshotKill != null && Main.HeadshotKill.Value && !RagdollApi.IsEnvImpact(text) && (Object)(object)__instance != (Object)null && RagdollApi.RegionOf(__instance.muscleIndex) == MuscleRegion.Head)
					{
						bool flag = Main.IsGunHit(text);
						if (!flag && text == "Unknown")
						{
							try
							{
								if (GunHook.Attribute() != "Unknown")
								{
									flag = true;
								}
							}
							catch
							{
							}
						}
						if (flag && Reflect.TryGet<float>(__0, "damage", out var value2) && Reflect.TrySet(__0, "damage", 99999f))
						{
							if (Main._headshotLogs < 5)
							{
								Main._headshotLogs++;
								try
								{
									MelonLogger.Msg($"[headshot-kill {Main._headshotLogs}/5] {text} head dmg={value2:F1} -> lethal");
									return;
								}
								catch
								{
									return;
								}
							}
							return;
						}
					}
				}
				catch
				{
				}
				float num = 1f;
				bool num2 = Main.IsGunHit(text);
				bool flag2 = !num2 && Main.IsMeleeHit(text);
				if (num2)
				{
					num = Main.GunScale();
				}
				else if (flag2)
				{
					num = Main.MeleeScale();
				}
				else
				{
					try
					{
						if (text != "Unknown" || RagdollApi.IsEnvImpact(text) || GunHook.Attribute() == "Unknown")
						{
							return;
						}
						num = Main.GunScale();
					}
					catch
					{
						return;
					}
				}
				if (num >= 0.999f || !Reflect.TryGet<float>(__0, "damage", out var value3) || !(value3 > 0f) || !Reflect.TrySet(__0, "damage", value3 * num) || Main._scaleLogs >= 5)
				{
					return;
				}
				Main._scaleLogs++;
				try
				{
					MelonLogger.Msg($"[dmg-scale {Main._scaleLogs}/5] {text} {value3:F1} -> {value3 * num:F1} (x{num:F2})");
				}
				catch
				{
				}
			}
			catch
			{
			}
		}

		private static void Postfix(MuscleCollisionBroadcaster __instance, object __0)
		{
			try
			{
				Main.HandleHit(__instance, __0);
			}
			catch (Exception value)
			{
				MelonLogger.Error($"RagdollOnHit: {value}");
			}
		}
	}
	internal static class Reflect
	{
		private const BindingFlags Flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;

		private static bool IsEngineNamespace(string ns)
		{
			ns = ns ?? "";
			if (!ns.StartsWith("System") && !ns.StartsWith("UnityEngine") && !ns.StartsWith("Il2CppSystem"))
			{
				return ns.StartsWith("Il2CppInterop");
			}
			return true;
		}

		internal static bool TryGetObj(object o, string name, out object value)
		{
			value = null;
			if (o == null)
			{
				return false;
			}
			try
			{
				Type type = o.GetType();
				PropertyInfo property = type.GetProperty(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (property != null && property.CanRead && property.GetIndexParameters().Length == 0)
				{
					value = property.GetValue(o);
					return true;
				}
				FieldInfo field = type.GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (field != null)
				{
					value = field.GetValue(o);
					return true;
				}
			}
			catch
			{
			}
			return false;
		}

		internal static bool TryGet<T>(object o, string name, out T value)
		{
			value = default(T);
			if (o == null)
			{
				return false;
			}
			try
			{
				for (Type type = o.GetType(); type != null && !IsEngineNamespace(type.Namespace); type = type.BaseType)
				{
					BindingFlags bindingAttr = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
					object obj = null;
					bool flag = false;
					PropertyInfo property = type.GetProperty(name, bindingAttr);
					if (property != null && property.CanRead && property.GetIndexParameters().Length == 0)
					{
						obj = property.GetValue(o);
						flag = true;
					}
					else
					{
						FieldInfo field = type.GetField(name, bindingAttr);
						if (field == null)
						{
							continue;
						}
						obj = field.GetValue(o);
						flag = true;
					}
					if (flag)
					{
						if (obj is T val)
						{
							value = val;
							return true;
						}
						if (typeof(T) == typeof(float) && obj is IConvertible convertible)
						{
							value = (T)(object)convertible.ToSingle(null);
							return true;
						}
						return false;
					}
				}
			}
			catch
			{
			}
			return false;
		}

		internal static bool TrySet(object o, string name, float value)
		{
			return TrySetRaw(o, name, value);
		}

		internal static bool TrySetBool(object o, string name, bool value)
		{
			return TrySetRaw(o, name, value);
		}

		private static bool TrySetRaw(object o, string name, object value)
		{
			if (o == null)
			{
				return false;
			}
			try
			{
				Type type = o.GetType();
				while (type != null && !IsEngineNamespace(type.Namespace))
				{
					BindingFlags bindingAttr = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
					PropertyInfo property = type.GetProperty(name, bindingAttr);
					if (property != null && property.CanWrite && property.GetIndexParameters().Length == 0)
					{
						property.SetValue(o, Convert.ChangeType(value, property.PropertyType));
						return true;
					}
					FieldInfo field = type.GetField(name, bindingAttr);
					if (field != null)
					{
						field.SetValue(o, Convert.ChangeType(value, field.FieldType));
						return true;
					}
					type = type.BaseType;
				}
			}
			catch (Exception ex)
			{
				MelonLogger.Warning("Couldn't set " + name + ": " + ex.Message);
			}
			return false;
		}

		internal static T FindMemberOfType<T>(object o, out string memberName) where T : class
		{
			memberName = null;
			if (o == null)
			{
				return null;
			}
			Type type = o.GetType();
			while (type != null && !IsEngineNamespace(type.Namespace))
			{
				BindingFlags bindingAttr = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
				PropertyInfo[] properties = type.GetProperties(bindingAttr);
				foreach (PropertyInfo propertyInfo in properties)
				{
					if (!typeof(T).IsAssignableFrom(propertyInfo.PropertyType) || !propertyInfo.CanRead || propertyInfo.GetIndexParameters().Length != 0)
					{
						continue;
					}
					try
					{
						if (propertyInfo.GetValue(o) is T result)
						{
							memberName = type.Name + "." + propertyInfo.Name;
							return result;
						}
					}
					catch
					{
					}
				}
				FieldInfo[] fields = type.GetFields(bindingAttr);
				foreach (FieldInfo fieldInfo in fields)
				{
					if (!typeof(T).IsAssignableFrom(fieldInfo.FieldType))
					{
						continue;
					}
					try
					{
						if (fieldInfo.GetValue(o) is T result2)
						{
							memberName = type.Name + "." + fieldInfo.Name;
							return result2;
						}
					}
					catch
					{
					}
				}
				type = type.BaseType;
			}
			return null;
		}

		internal static void LogMembers(object o, string label, bool includeBases)
		{
			Type type = o.GetType();
			while (type != null && !IsEngineNamespace(type.Namespace))
			{
				BindingFlags bindingAttr = Bindi