Decompiled source of Ultimate Ragdoll v7.0.0

Mods/UltimateRagdoll.dll

Decompiled 3 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BoneLib;
using BoneLib.BoneMenu;
using BoneLib.Notifications;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSLZ.Marrow;
using Il2CppSLZ.Marrow.AI;
using Il2CppSLZ.Marrow.Audio;
using Il2CppSLZ.Marrow.PuppetMasta;
using MelonLoader;
using MelonLoader.Preferences;
using UltimateRagdoll;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(UltimateRagdollMod), "Ultimate Ragdoll", "5.0.0", "Int_Void", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("UltimateRagdoll")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("UltimateRagdoll")]
[assembly: AssemblyTitle("UltimateRagdoll")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace UltimateRagdoll;

public class UltimateRagdollMod : MelonMod
{
	public enum RagdollMode
	{
		Limp,
		ArmControl
	}

	public enum ControllerSide
	{
		Left,
		Right,
		Both
	}

	public enum InputMode
	{
		ThumbstickPress,
		DoubleTapB
	}

	public const string Version = "5.0.0";

	private static MelonPreferences_Category _cat;

	public static MelonPreferences_Entry<bool> PrefEnabled;

	public static MelonPreferences_Entry<RagdollMode> PrefMode;

	public static MelonPreferences_Entry<ControllerSide> PrefSide;

	public static MelonPreferences_Entry<InputMode> PrefInputMode;

	public static MelonPreferences_Entry<KeyCode> PrefKeyboardKey;

	public static MelonPreferences_Entry<bool> PrefDropItems;

	public static MelonPreferences_Entry<bool> PrefFastExit;

	public static MelonPreferences_Entry<float> PrefRagdollCooldown;

	public static MelonPreferences_Entry<bool> PrefPreventUnragdollMoving;

	public static MelonPreferences_Entry<float> PrefUnragdollMaxVelocity;

	public static MelonPreferences_Entry<bool> PrefResetCooldownOnDamage;

	public static MelonPreferences_Entry<float> PrefMaxRagdollTime;

	public static MelonPreferences_Entry<bool> PrefTwoTapDamage;

	public static MelonPreferences_Entry<float> PrefTwoTapTimeWindow;

	public static MelonPreferences_Entry<bool> PrefDownedEnabled;

	public static MelonPreferences_Entry<float> PrefDownedDuration;

	public static MelonPreferences_Entry<bool> PrefStayRagdolledOnDeath;

	public static MelonPreferences_Entry<bool> PrefFallEnabled;

	public static MelonPreferences_Entry<float> PrefFallThresh;

	public static MelonPreferences_Entry<bool> PrefImpactEnabled;

	public static MelonPreferences_Entry<float> PrefImpactThresh;

	public static MelonPreferences_Entry<bool> PrefLaunchEnabled;

	public static MelonPreferences_Entry<float> PrefLaunchThresh;

	public static MelonPreferences_Entry<bool> PrefSlipEnabled;

	public static MelonPreferences_Entry<float> PrefSlipFriction;

	public static MelonPreferences_Entry<float> PrefSlipVelocity;

	public static MelonPreferences_Entry<bool> PrefWallPushEnabled;

	public static MelonPreferences_Entry<float> PrefWallPushVelocity;

	public static MelonPreferences_Entry<bool> PrefDynamicSizeScaling;

	public static MelonPreferences_Entry<bool> PrefImpactDamageEnabled;

	public static MelonPreferences_Entry<float> PrefImpactDamageMultiplier;

	public static MelonPreferences_Entry<float> PrefImpactDamageThreshold;

	public static MelonPreferences_Entry<bool> PrefDragEnabled;

	public static MelonPreferences_Entry<float> PrefDragStrength;

	public static MelonPreferences_Entry<float> PrefDragMaxForce;

	public static MelonPreferences_Entry<bool> PrefFloppyLeftArm;

	public static MelonPreferences_Entry<bool> PrefFloppyRightArm;

	public static MelonPreferences_Entry<bool> PrefFixEnabled;

	public static MelonPreferences_Entry<bool> PrefFixFly;

	public static MelonPreferences_Entry<bool> PrefFixVel;

	public static MelonPreferences_Entry<float> PrefFixVelLimit;

	public static MelonPreferences_Entry<bool> PrefFixTeleport;

	private Vector3 _lastVelocity;

	private Vector3 _prevVelocity;

	private float _nextRagdollTime;

	private float _unragdollTime;

	private bool _isDowned;

	private bool _isDead;

	private float _deathTime;

	private float _downedStartTime;

	private float _lastInputTime;

	private bool _doubleTapReady;

	private bool _wasRagdolled;

	private float _ragdollStartTime;

	private bool _levelLoaded;

	private int _damageHits;

	private float _lastDamageTime;

	private float _safeDamageTime;

	private float _safeRagdollTime;

	private int _framesSinceUnragdoll;

	private bool _fixPending;

	private Vector3 _savedPelvisPos;

	private float _savedPelvisY;

	private float _lastImpactDamageTime;

	private const float IMPACT_DAMAGE_IMMUNITY = 0.5f;

	private bool _cachedSupported;

	private float _cachedFriction;

	private int _cachedGroundFrame = -1000;

	private const int GROUND_CHECK_INTERVAL = 3;

	private static readonly Collider[] _colliderBuffer = (Collider[])(object)new Collider[8];

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

	private PropertyInfo _cachedIsProxyProp;

	private bool _fusionChecked;

	private bool _jumpBuffered;

	private bool _ragdollBuffered;

	private static int _groundLayerMask;

	private BoolElement _uiEnabled;

	private BoolElement _uiDropItems;

	private BoolElement _uiFastExit;

	private EnumElement _uiMode;

	private EnumElement _uiInputMode;

	private EnumElement _uiSide;

	private FloatElement _uiRagdollCooldown;

	private FloatElement _uiUnragdollMaxVelocity;

	private FloatElement _uiMaxRagdollTime;

	private BoolElement _uiPreventUnragdollMoving;

	private BoolElement _uiResetCooldownOnDamage;

	private BoolElement _uiTwoTapDamage;

	private BoolElement _uiDownedEnabled;

	private BoolElement _uiStayRagdolledOnDeath;

	private FloatElement _uiTwoTapTimeWindow;

	private FloatElement _uiDownedDuration;

	private BoolElement _uiFallEnabled;

	private BoolElement _uiImpactEnabled;

	private BoolElement _uiLaunchEnabled;

	private BoolElement _uiSlipEnabled;

	private BoolElement _uiWallPushEnabled;

	private BoolElement _uiDynamicSizeScaling;

	private FloatElement _uiFallThresh;

	private FloatElement _uiImpactThresh;

	private FloatElement _uiLaunchThresh;

	private FloatElement _uiSlipFriction;

	private FloatElement _uiSlipVelocity;

	private FloatElement _uiWallPushVelocity;

	private BoolElement _uiImpactDamageEnabled;

	private FloatElement _uiImpactDamageMultiplier;

	private FloatElement _uiImpactDamageThreshold;

	private BoolElement _uiDragEnabled;

	private BoolElement _uiFloppyLeft;

	private BoolElement _uiFloppyRight;

	private BoolElement _uiFixEnabled;

	private BoolElement _uiFixFly;

	private BoolElement _uiFixVel;

	private BoolElement _uiFixTeleport;

	private FloatElement _uiDragStrength;

	private FloatElement _uiDragMaxForce;

	private FloatElement _uiFixVelLimit;

	private static readonly Vector3[] _sphereDirections;

	public static bool IsPlayerRagdolled { get; private set; }

	public override void OnInitializeMelon()
	{
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Expected O, but got Unknown
		SetupPreferences();
		BuildBoneMenu();
		Hooking.OnLevelLoaded += OnLevelLoaded;
		Hooking.OnPlayerDamageReceived += OnPlayerDamageReceived;
		Hooking.OnPlayerDeath += OnPlayerDeath;
		_groundLayerMask = -1025;
		try
		{
			Harmony val = new Harmony("com.intvoid.ultimateragdoll");
			val.PatchAll();
			((MelonBase)this).LoggerInstance.Msg("Harmony patches applied.");
		}
		catch (Exception ex)
		{
			((MelonBase)this).LoggerInstance.Warning("Harmony failed: " + ex.Message);
		}
		((MelonBase)this).LoggerInstance.Msg("UltimateRagdoll v5.0.0 initialized.");
	}

	public override void OnDeinitializeMelon()
	{
		Hooking.OnLevelLoaded -= OnLevelLoaded;
		Hooking.OnPlayerDamageReceived -= OnPlayerDamageReceived;
		Hooking.OnPlayerDeath -= OnPlayerDeath;
		_savedWeights.Clear();
	}

	private void SetupPreferences()
	{
		_cat = MelonPreferences.CreateCategory("UltimateRagdoll", "Ultimate Ragdoll");
		PrefEnabled = _cat.CreateEntry<bool>("Enabled", true, "Mod Enabled", (string)null, false, false, (ValueValidator)null, (string)null);
		PrefMode = _cat.CreateEntry<RagdollMode>("RagdollMode", RagdollMode.Limp, "Ragdoll Mode", (string)null, false, false, (ValueValidator)null, (string)null);
		PrefSide = _cat.CreateEntry<ControllerSide>("ControllerSide", ControllerSide.Right, "Controller Side", (string)null, false, false, (ValueValidator)null, (string)null);
		PrefInputMode = _cat.CreateEntry<InputMode>("InputMode", InputMode.ThumbstickPress, "Input Mode", (string)null, false, false, (ValueValidator)null, (string)null);
		PrefKeyboardKey = _cat.CreateEntry<KeyCode>("KeyboardFallbackKey", (KeyCode)306, "Keyboard Key", (string)null, false, false, (ValueValidator)null, (string)null);
		PrefDropItems = _cat.CreateEntry<bool>("DropItemsOnRagdoll", true, "Drop Items", (string)null, false, false, (ValueValidator)null, (string)null);
		PrefFastExit = _cat.CreateEntry<bool>("FastExitVehicles", true, "Fast Exit Vehicles", (string)null, false, false, (ValueValidator)null, (string)null);
		PrefRagdollCooldown = _cat.CreateEntry<float>("RagdollCooldown", 1.5f, "StandUp Cooldown", (string)null, false, false, (ValueValidator)null, (string)null);
		PrefPreventUnragdollMoving = _cat.CreateEntry<bool>("PreventUnragdollMoving", true, "Freeze Timer In Air", (string)null, false, false, (ValueValidator)null, (string)null);
		PrefUnragdollMaxVelocity = _cat.CreateEntry<float>("UnragdollMaxVelocity", 2.5f, "Max Velocity To Stand", (string)null, false, false, (ValueValidator)null, (string)null);
		PrefResetCooldownOnDamage = _cat.CreateEntry<bool>("ResetCooldownOnDamage", true, "Reset On Damage", (string)null, false, false, (ValueValidator)null, (string)null);
		PrefMaxRagdollTime = _cat.CreateEntry<float>("MaxRagdollTime", 8f, "Max Ragdoll Time", (string)null, false, false, (ValueValidator)null, (string)null);
		PrefTwoTapDamage = _cat.CreateEntry<bool>("TwoTapDamage", false, "Two-Tap Damage", (string)null, false, false, (ValueValidator)null, (string)null);
		PrefTwoTapTimeWindow = _cat.CreateEntry<float>("TwoTapTimeWindow", 4f, "Two-Tap Window", (string)null, false, false, (ValueValidator)null, (string)null);
		PrefDownedEnabled = _cat.CreateEntry<bool>("DownedEnabled", false, "Downed Enabled", (string)null, false, false, (ValueValidator)null, (string)null);
		PrefDownedDuration = _cat.CreateEntry<float>("DownedDuration", 6f, "Downed Duration", (string)null, false, false, (ValueValidator)null, (string)null);
		PrefStayRagdolledOnDeath = _cat.CreateEntry<bool>("StayRagdolledOnDeath", true, "Stay Ragdolled On Death", (string)null, false, false, (ValueValidator)null, (string)null);
		PrefFallEnabled = _cat.CreateEntry<bool>("FallEnabled", true, "Fall Enabled", (string)null, false, false, (ValueValidator)null, (string)null);
		PrefFallThresh = _cat.CreateEntry<float>("FallThreshold", 9f, "Fall Threshold", (string)null, false, false, (ValueValidator)null, (string)null);
		PrefImpactEnabled = _cat.CreateEntry<bool>("ImpactEnabled", true, "Impact Enabled", (string)null, false, false, (ValueValidator)null, (string)null);
		PrefImpactThresh = _cat.CreateEntry<float>("ImpactThreshold", 3.5f, "Impact Threshold", (string)null, false, false, (ValueValidator)null, (string)null);
		PrefLaunchEnabled = _cat.CreateEntry<bool>("LaunchEnabled", true, "Launch Enabled", (string)null, false, false, (ValueValidator)null, (string)null);
		PrefLaunchThresh = _cat.CreateEntry<float>("LaunchThreshold", 6f, "Launch Threshold", (string)null, false, false, (ValueValidator)null, (string)null);
		PrefSlipEnabled = _cat.CreateEntry<bool>("SlipEnabled", true, "Slip Enabled", (string)null, false, false, (ValueValidator)null, (string)null);
		PrefSlipFriction = _cat.CreateEntry<float>("SlipFriction", 0.25f, "Slip Friction", (string)null, false, false, (ValueValidator)null, (string)null);
		PrefSlipVelocity = _cat.CreateEntry<float>("SlipVelocity", 2.5f, "Slip Velocity", (string)null, false, false, (ValueValidator)null, (string)null);
		PrefWallPushEnabled = _cat.CreateEntry<bool>("WallPushEnabled", true, "Wall Push Enabled", (string)null, false, false, (ValueValidator)null, (string)null);
		PrefWallPushVelocity = _cat.CreateEntry<float>("WallPushVelocity", 2.5f, "Wall Push Velocity", (string)null, false, false, (ValueValidator)null, (string)null);
		PrefDynamicSizeScaling = _cat.CreateEntry<bool>("DynamicSizeScaling", true, "Scale Physics by Avatar Size", (string)null, false, false, (ValueValidator)null, (string)null);
		PrefImpactDamageEnabled = _cat.CreateEntry<bool>("ImpactDamageEnabled", false, "Impact Damage Enabled", (string)null, false, false, (ValueValidator)null, (string)null);
		PrefImpactDamageMultiplier = _cat.CreateEntry<float>("ImpactDamageMultiplier", 5f, "Damage Multiplier", (string)null, false, false, (ValueValidator)null, (string)null);
		PrefImpactDamageThreshold = _cat.CreateEntry<float>("ImpactDamageThreshold", 20f, "Damage Threshold", (string)null, false, false, (ValueValidator)null, (string)null);
		PrefDragEnabled = _cat.CreateEntry<bool>("DragEnabled", true, "Drag/Crawl Enabled", (string)null, false, false, (ValueValidator)null, (string)null);
		PrefDragStrength = _cat.CreateEntry<float>("DragStrength", 3f, "Drag Strength", (string)null, false, false, (ValueValidator)null, (string)null);
		PrefDragMaxForce = _cat.CreateEntry<float>("DragMaxForce", 50f, "Drag Max Force", (string)null, false, false, (ValueValidator)null, (string)null);
		PrefFloppyLeftArm = _cat.CreateEntry<bool>("FloppyLeftArm", false, "Floppy Left Arm", (string)null, false, false, (ValueValidator)null, (string)null);
		PrefFloppyRightArm = _cat.CreateEntry<bool>("FloppyRightArm", false, "Floppy Right Arm", (string)null, false, false, (ValueValidator)null, (string)null);
		PrefFixEnabled = _cat.CreateEntry<bool>("RagdollFixEnabled", true, "Ragdoll Fix Enabled", (string)null, false, false, (ValueValidator)null, (string)null);
		PrefFixFly = _cat.CreateEntry<bool>("RagdollFixFly", true, "Flight Fix", (string)null, false, false, (ValueValidator)null, (string)null);
		PrefFixVel = _cat.CreateEntry<bool>("RagdollFixVelocity", true, "Velocity Fix", (string)null, false, false, (ValueValidator)null, (string)null);
		PrefFixVelLimit = _cat.CreateEntry<float>("RagdollFixVelLimit", 5f, "Velocity Limit", (string)null, false, false, (ValueValidator)null, (string)null);
		PrefFixTeleport = _cat.CreateEntry<bool>("RagdollFixTeleport", true, "Use Teleport Fix", (string)null, false, false, (ValueValidator)null, (string)null);
	}

	private void ResetToDefault()
	{
		((MelonPreferences_Entry)PrefEnabled).ResetToDefault();
		((MelonPreferences_Entry)PrefMode).ResetToDefault();
		((MelonPreferences_Entry)PrefSide).ResetToDefault();
		((MelonPreferences_Entry)PrefInputMode).ResetToDefault();
		((MelonPreferences_Entry)PrefKeyboardKey).ResetToDefault();
		((MelonPreferences_Entry)PrefDropItems).ResetToDefault();
		((MelonPreferences_Entry)PrefFastExit).ResetToDefault();
		((MelonPreferences_Entry)PrefRagdollCooldown).ResetToDefault();
		((MelonPreferences_Entry)PrefPreventUnragdollMoving).ResetToDefault();
		((MelonPreferences_Entry)PrefUnragdollMaxVelocity).ResetToDefault();
		((MelonPreferences_Entry)PrefResetCooldownOnDamage).ResetToDefault();
		((MelonPreferences_Entry)PrefMaxRagdollTime).ResetToDefault();
		((MelonPreferences_Entry)PrefTwoTapDamage).ResetToDefault();
		((MelonPreferences_Entry)PrefTwoTapTimeWindow).ResetToDefault();
		((MelonPreferences_Entry)PrefDownedEnabled).ResetToDefault();
		((MelonPreferences_Entry)PrefDownedDuration).ResetToDefault();
		((MelonPreferences_Entry)PrefStayRagdolledOnDeath).ResetToDefault();
		((MelonPreferences_Entry)PrefFallEnabled).ResetToDefault();
		((MelonPreferences_Entry)PrefFallThresh).ResetToDefault();
		((MelonPreferences_Entry)PrefImpactEnabled).ResetToDefault();
		((MelonPreferences_Entry)PrefImpactThresh).ResetToDefault();
		((MelonPreferences_Entry)PrefLaunchEnabled).ResetToDefault();
		((MelonPreferences_Entry)PrefLaunchThresh).ResetToDefault();
		((MelonPreferences_Entry)PrefSlipEnabled).ResetToDefault();
		((MelonPreferences_Entry)PrefSlipFriction).ResetToDefault();
		((MelonPreferences_Entry)PrefSlipVelocity).ResetToDefault();
		((MelonPreferences_Entry)PrefWallPushEnabled).ResetToDefault();
		((MelonPreferences_Entry)PrefWallPushVelocity).ResetToDefault();
		((MelonPreferences_Entry)PrefDynamicSizeScaling).ResetToDefault();
		((MelonPreferences_Entry)PrefImpactDamageEnabled).ResetToDefault();
		((MelonPreferences_Entry)PrefImpactDamageMultiplier).ResetToDefault();
		((MelonPreferences_Entry)PrefImpactDamageThreshold).ResetToDefault();
		((MelonPreferences_Entry)PrefDragEnabled).ResetToDefault();
		((MelonPreferences_Entry)PrefDragStrength).ResetToDefault();
		((MelonPreferences_Entry)PrefDragMaxForce).ResetToDefault();
		((MelonPreferences_Entry)PrefFloppyLeftArm).ResetToDefault();
		((MelonPreferences_Entry)PrefFloppyRightArm).ResetToDefault();
		((MelonPreferences_Entry)PrefFixEnabled).ResetToDefault();
		((MelonPreferences_Entry)PrefFixFly).ResetToDefault();
		((MelonPreferences_Entry)PrefFixVel).ResetToDefault();
		((MelonPreferences_Entry)PrefFixVelLimit).ResetToDefault();
		((MelonPreferences_Entry)PrefFixTeleport).ResetToDefault();
		_cat.SaveToFile(false);
		((MelonBase)this).LoggerInstance.Msg("Settings reset to default.");
		RefreshUI();
	}

	private void RefreshUI()
	{
		try
		{
			_uiEnabled.Value = PrefEnabled.Value;
			_uiMode.Value = PrefMode.Value;
			_uiSide.Value = PrefSide.Value;
			_uiInputMode.Value = PrefInputMode.Value;
			_uiDropItems.Value = PrefDropItems.Value;
			_uiFastExit.Value = PrefFastExit.Value;
			_uiRagdollCooldown.Value = PrefRagdollCooldown.Value;
			_uiMaxRagdollTime.Value = PrefMaxRagdollTime.Value;
			_uiPreventUnragdollMoving.Value = PrefPreventUnragdollMoving.Value;
			_uiUnragdollMaxVelocity.Value = PrefUnragdollMaxVelocity.Value;
			_uiResetCooldownOnDamage.Value = PrefResetCooldownOnDamage.Value;
			_uiTwoTapDamage.Value = PrefTwoTapDamage.Value;
			_uiTwoTapTimeWindow.Value = PrefTwoTapTimeWindow.Value;
			_uiDownedEnabled.Value = PrefDownedEnabled.Value;
			_uiDownedDuration.Value = PrefDownedDuration.Value;
			_uiStayRagdolledOnDeath.Value = PrefStayRagdolledOnDeath.Value;
			_uiFallEnabled.Value = PrefFallEnabled.Value;
			_uiFallThresh.Value = PrefFallThresh.Value;
			_uiImpactEnabled.Value = PrefImpactEnabled.Value;
			_uiImpactThresh.Value = PrefImpactThresh.Value;
			_uiLaunchEnabled.Value = PrefLaunchEnabled.Value;
			_uiLaunchThresh.Value = PrefLaunchThresh.Value;
			_uiSlipEnabled.Value = PrefSlipEnabled.Value;
			_uiSlipFriction.Value = PrefSlipFriction.Value;
			_uiSlipVelocity.Value = PrefSlipVelocity.Value;
			_uiWallPushEnabled.Value = PrefWallPushEnabled.Value;
			_uiWallPushVelocity.Value = PrefWallPushVelocity.Value;
			_uiDynamicSizeScaling.Value = PrefDynamicSizeScaling.Value;
			_uiImpactDamageEnabled.Value = PrefImpactDamageEnabled.Value;
			_uiImpactDamageMultiplier.Value = PrefImpactDamageMultiplier.Value;
			_uiImpactDamageThreshold.Value = PrefImpactDamageThreshold.Value;
			_uiDragEnabled.Value = PrefDragEnabled.Value;
			_uiDragStrength.Value = PrefDragStrength.Value;
			_uiDragMaxForce.Value = PrefDragMaxForce.Value;
			_uiFloppyLeft.Value = PrefFloppyLeftArm.Value;
			_uiFloppyRight.Value = PrefFloppyRightArm.Value;
			_uiFixEnabled.Value = PrefFixEnabled.Value;
			_uiFixFly.Value = PrefFixFly.Value;
			_uiFixVel.Value = PrefFixVel.Value;
			_uiFixVelLimit.Value = PrefFixVelLimit.Value;
			_uiFixTeleport.Value = PrefFixTeleport.Value;
		}
		catch
		{
		}
	}

	private void BuildBoneMenu()
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: 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_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0116: 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_0199: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d7: 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)
		//IL_0239: Unknown result type (might be due to invalid IL or missing references)
		//IL_0287: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c6: 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_0352: Unknown result type (might be due to invalid IL or missing references)
		//IL_0366: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0432: Unknown result type (might be due to invalid IL or missing references)
		//IL_0480: Unknown result type (might be due to invalid IL or missing references)
		//IL_04cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_04f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0532: Unknown result type (might be due to invalid IL or missing references)
		//IL_0581: Unknown result type (might be due to invalid IL or missing references)
		//IL_05ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_05e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0623: Unknown result type (might be due to invalid IL or missing references)
		//IL_0639: Unknown result type (might be due to invalid IL or missing references)
		//IL_0679: Unknown result type (might be due to invalid IL or missing references)
		//IL_06c8: 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_0756: Unknown result type (might be due to invalid IL or missing references)
		//IL_076c: Unknown result type (might be due to invalid IL or missing references)
		//IL_07ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_07fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_084a: Unknown result type (might be due to invalid IL or missing references)
		//IL_088a: Unknown result type (might be due to invalid IL or missing references)
		//IL_08d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_08ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_092e: Unknown result type (might be due to invalid IL or missing references)
		//IL_097b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0991: Unknown result type (might be due to invalid IL or missing references)
		//IL_09d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0a20: Unknown result type (might be due to invalid IL or missing references)
		//IL_0a6d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0a82: Unknown result type (might be due to invalid IL or missing references)
		//IL_0aa0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0abe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0adc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0af9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0b0f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0b4f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0b8f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0bcf: Unknown result type (might be due to invalid IL or missing references)
		//IL_0c0f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0c5e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0c8b: Unknown result type (might be due to invalid IL or missing references)
		Page val = Page.Root.CreatePage("Ultimate Ragdoll", Color.green, 0, true);
		val.CreateFunction("RESET ALL TO DEFAULT", Color.red, (Action)ResetToDefault);
		_uiEnabled = val.CreateBool("Mod Enabled", Color.green, PrefEnabled.Value, (Action<bool>)delegate(bool v)
		{
			PrefEnabled.Value = v;
			_cat.SaveToFile(false);
		});
		Page val2 = val.CreatePage("1. General Controls", Color.white, 0, true);
		_uiMode = val2.CreateEnum("Ragdoll Mode", Color.white, (Enum)PrefMode.Value, (Action<Enum>)delegate(Enum v)
		{
			PrefMode.Value = (RagdollMode)(object)v;
			_cat.SaveToFile(false);
		});
		_uiInputMode = val2.CreateEnum("Button Mode", Color.white, (Enum)PrefInputMode.Value, (Action<Enum>)delegate(Enum v)
		{
			PrefInputMode.Value = (InputMode)(object)v;
			_cat.SaveToFile(false);
		});
		_uiSide = val2.CreateEnum("Controller Side", Color.white, (Enum)PrefSide.Value, (Action<Enum>)delegate(Enum v)
		{
			PrefSide.Value = (ControllerSide)(object)v;
			_cat.SaveToFile(false);
		});
		_uiDropItems = val2.CreateBool("Drop Items On Ragdoll", Color.white, PrefDropItems.Value, (Action<bool>)delegate(bool v)
		{
			PrefDropItems.Value = v;
			_cat.SaveToFile(false);
		});
		_uiFastExit = val2.CreateBool("Fast Exit Vehicles", Color.white, PrefFastExit.Value, (Action<bool>)delegate(bool v)
		{
			PrefFastExit.Value = v;
			_cat.SaveToFile(false);
		});
		Page val3 = val.CreatePage("2. Cooldowns & StandUp", Color.yellow, 0, true);
		_uiRagdollCooldown = val3.CreateFloat("StandUp Cooldown (Sec)", Color.white, PrefRagdollCooldown.Value, 0.1f, 0f, 10f, (Action<float>)delegate(float v)
		{
			PrefRagdollCooldown.Value = v;
			_cat.SaveToFile(false);
		});
		_uiMaxRagdollTime = val3.CreateFloat("MAX Ragdoll Time (Force Stand)", Color.red, PrefMaxRagdollTime.Value, 1f, 2f, 30f, (Action<float>)delegate(float v)
		{
			PrefMaxRagdollTime.Value = v;
			_cat.SaveToFile(false);
		});
		_uiPreventUnragdollMoving = val3.CreateBool("Freeze Timer In Air/Moving", Color.yellow, PrefPreventUnragdollMoving.Value, (Action<bool>)delegate(bool v)
		{
			PrefPreventUnragdollMoving.Value = v;
			_cat.SaveToFile(false);
		});
		_uiUnragdollMaxVelocity = val3.CreateFloat("Max Velocity To StandUp", Color.white, PrefUnragdollMaxVelocity.Value, 0.5f, 0.1f, 10f, (Action<float>)delegate(float v)
		{
			PrefUnragdollMaxVelocity.Value = v;
			_cat.SaveToFile(false);
		});
		_uiResetCooldownOnDamage = val3.CreateBool("Reset Timer On Damage", Color.red, PrefResetCooldownOnDamage.Value, (Action<bool>)delegate(bool v)
		{
			PrefResetCooldownOnDamage.Value = v;
			_cat.SaveToFile(false);
		});
		Page val4 = val.CreatePage("3. Damage & Health", Color.red, 0, true);
		_uiTwoTapDamage = val4.CreateBool("Two-Tap Damage Ragdoll", Color.white, PrefTwoTapDamage.Value, (Action<bool>)delegate(bool v)
		{
			PrefTwoTapDamage.Value = v;
			_cat.SaveToFile(false);
		});
		_uiTwoTapTimeWindow = val4.CreateFloat("Two-Tap Time Window (Sec)", Color.white, PrefTwoTapTimeWindow.Value, 0.1f, 1f, 10f, (Action<float>)delegate(float v)
		{
			PrefTwoTapTimeWindow.Value = v;
			_cat.SaveToFile(false);
		});
		_uiDownedEnabled = val4.CreateBool("Downed (Injured) Enabled", Color.red, PrefDownedEnabled.Value, (Action<bool>)delegate(bool v)
		{
			PrefDownedEnabled.Value = v;
			_cat.SaveToFile(false);
		});
		_uiDownedDuration = val4.CreateFloat("Downed Duration", Color.red, PrefDownedDuration.Value, 1f, 1f, 15f, (Action<float>)delegate(float v)
		{
			PrefDownedDuration.Value = v;
			_cat.SaveToFile(false);
		});
		_uiStayRagdolledOnDeath = val4.CreateBool("Stay Ragdolled On Death", Color.red, PrefStayRagdolledOnDeath.Value, (Action<bool>)delegate(bool v)
		{
			PrefStayRagdolledOnDeath.Value = v;
			_cat.SaveToFile(false);
		});
		Page val5 = val4.CreatePage("Impact Damage (Fling-style)", new Color(1f, 0.65f, 0f), 0, true);
		_uiImpactDamageEnabled = val5.CreateBool("Impact Damage Enabled", new Color(1f, 0.65f, 0f), PrefImpactDamageEnabled.Value, (Action<bool>)delegate(bool v)
		{
			PrefImpactDamageEnabled.Value = v;
			_cat.SaveToFile(false);
		});
		_uiImpactDamageMultiplier = val5.CreateFloat("Damage Multiplier", Color.white, PrefImpactDamageMultiplier.Value, 0.5f, 1f, 50f, (Action<float>)delegate(float v)
		{
			PrefImpactDamageMultiplier.Value = v;
			_cat.SaveToFile(false);
		});
		_uiImpactDamageThreshold = val5.CreateFloat("Damage Threshold", Color.white, PrefImpactDamageThreshold.Value, 1f, 1f, 100f, (Action<float>)delegate(float v)
		{
			PrefImpactDamageThreshold.Value = v;
			_cat.SaveToFile(false);
		});
		Page val6 = val.CreatePage("4. Auto-Ragdoll Physics", Color.cyan, 0, true);
		_uiDynamicSizeScaling = val6.CreateBool("Scale Thresholds By Avatar Size", Color.green, PrefDynamicSizeScaling.Value, (Action<bool>)delegate(bool v)
		{
			PrefDynamicSizeScaling.Value = v;
			_cat.SaveToFile(false);
		});
		Page val7 = val6.CreatePage("Fall & Impact", Color.white, 0, true);
		_uiFallEnabled = val7.CreateBool("Fall Enabled", Color.white, PrefFallEnabled.Value, (Action<bool>)delegate(bool v)
		{
			PrefFallEnabled.Value = v;
			_cat.SaveToFile(false);
		});
		_uiFallThresh = val7.CreateFloat("Fall Velocity", Color.white, PrefFallThresh.Value, 0.5f, 1f, 30f, (Action<float>)delegate(float v)
		{
			PrefFallThresh.Value = v;
			_cat.SaveToFile(false);
		});
		_uiImpactEnabled = val7.CreateBool("Impact Enabled", Color.white, PrefImpactEnabled.Value, (Action<bool>)delegate(bool v)
		{
			PrefImpactEnabled.Value = v;
			_cat.SaveToFile(false);
		});
		_uiImpactThresh = val7.CreateFloat("Impact Threshold", Color.white, PrefImpactThresh.Value, 0.5f, 1f, 40f, (Action<float>)delegate(float v)
		{
			PrefImpactThresh.Value = v;
			_cat.SaveToFile(false);
		});
		Page val8 = val6.CreatePage("Slip & Launch", Color.white, 0, true);
		_uiSlipEnabled = val8.CreateBool("Slip Enabled", Color.blue, PrefSlipEnabled.Value, (Action<bool>)delegate(bool v)
		{
			PrefSlipEnabled.Value = v;
			_cat.SaveToFile(false);
		});
		_uiSlipFriction = val8.CreateFloat("Slip Friction", Color.blue, PrefSlipFriction.Value, 0.01f, 0f, 1f, (Action<float>)delegate(float v)
		{
			PrefSlipFriction.Value = v;
			_cat.SaveToFile(false);
		});
		_uiSlipVelocity = val8.CreateFloat("Slip Velocity", Color.blue, PrefSlipVelocity.Value, 0.5f, 1f, 10f, (Action<float>)delegate(float v)
		{
			PrefSlipVelocity.Value = v;
			_cat.SaveToFile(false);
		});
		_uiLaunchEnabled = val8.CreateBool("Launch Enabled", Color.magenta, PrefLaunchEnabled.Value, (Action<bool>)delegate(bool v)
		{
			PrefLaunchEnabled.Value = v;
			_cat.SaveToFile(false);
		});
		_uiLaunchThresh = val8.CreateFloat("Launch Threshold", Color.magenta, PrefLaunchThresh.Value, 0.5f, 1f, 50f, (Action<float>)delegate(float v)
		{
			PrefLaunchThresh.Value = v;
			_cat.SaveToFile(false);
		});
		Page val9 = val6.CreatePage("Wall Crashes", Color.white, 0, true);
		_uiWallPushEnabled = val9.CreateBool("Wall Crash Enabled", Color.gray, PrefWallPushEnabled.Value, (Action<bool>)delegate(bool v)
		{
			PrefWallPushEnabled.Value = v;
			_cat.SaveToFile(false);
		});
		_uiWallPushVelocity = val9.CreateFloat("Wall Crash Velocity", Color.gray, PrefWallPushVelocity.Value, 0.5f, 1f, 20f, (Action<float>)delegate(float v)
		{
			PrefWallPushVelocity.Value = v;
			_cat.SaveToFile(false);
		});
		Page val10 = val.CreatePage("5. Crawl (Drag) System", Color.magenta, 0, true);
		_uiDragEnabled = val10.CreateBool("Crawl Enabled", Color.cyan, PrefDragEnabled.Value, (Action<bool>)delegate(bool v)
		{
			PrefDragEnabled.Value = v;
			_cat.SaveToFile(false);
		});
		_uiDragStrength = val10.CreateFloat("Crawl Strength", Color.cyan, PrefDragStrength.Value, 0.5f, 1f, 20f, (Action<float>)delegate(float v)
		{
			PrefDragStrength.Value = v;
			_cat.SaveToFile(false);
		});
		_uiDragMaxForce = val10.CreateFloat("Crawl Max Force", Color.yellow, PrefDragMaxForce.Value, 1f, 1f, 200f, (Action<float>)delegate(float v)
		{
			PrefDragMaxForce.Value = v;
			_cat.SaveToFile(false);
		});
		Page val11 = val.CreatePage("6. NPC Ragdoll Tools", Color.yellow, 0, true);
		val11.CreateFunction("Ragdoll Nearest NPC", Color.cyan, (Action)RagdollNearestNPC);
		val11.CreateFunction("Restore Nearest NPC", Color.green, (Action)RestoreNearestNPC);
		val11.CreateFunction("Ragdoll All NPCs", Color.red, (Action)RagdollAllNPCs);
		val11.CreateFunction("Restore All NPCs", Color.green, (Action)RestoreAllNPCs);
		Page val12 = val.CreatePage("7. Bug Fixes & Visuals", Color.blue, 0, true);
		_uiFixEnabled = val12.CreateBool("Ragdoll Fix Enabled", Color.green, PrefFixEnabled.Value, (Action<bool>)delegate(bool v)
		{
			PrefFixEnabled.Value = v;
			_cat.SaveToFile(false);
		});
		_uiFixFly = val12.CreateBool("Flight Fix (Recommended: ON)", Color.white, PrefFixFly.Value, (Action<bool>)delegate(bool v)
		{
			PrefFixFly.Value = v;
			_cat.SaveToFile(false);
		});
		_uiFixVel = val12.CreateBool("Velocity Fix (Recommended: ON)", Color.white, PrefFixVel.Value, (Action<bool>)delegate(bool v)
		{
			PrefFixVel.Value = v;
			_cat.SaveToFile(false);
		});
		_uiFixTeleport = val12.CreateBool("Use Teleport Fix", Color.yellow, PrefFixTeleport.Value, (Action<bool>)delegate(bool v)
		{
			PrefFixTeleport.Value = v;
			_cat.SaveToFile(false);
		});
		_uiFixVelLimit = val12.CreateFloat("Velocity Limit", Color.yellow, PrefFixVelLimit.Value, 1f, 0f, 200f, (Action<float>)delegate(float v)
		{
			PrefFixVelLimit.Value = v;
			_cat.SaveToFile(false);
		});
		_uiFloppyLeft = val12.CreateBool("Floppy Left Arm", Color.white, PrefFloppyLeftArm.Value, (Action<bool>)delegate(bool v)
		{
			PrefFloppyLeftArm.Value = v;
			_cat.SaveToFile(false);
			ApplyFloppyArms();
		});
		_uiFloppyRight = val12.CreateBool("Floppy Right Arm", Color.white, PrefFloppyRightArm.Value, (Action<bool>)delegate(bool v)
		{
			PrefFloppyRightArm.Value = v;
			_cat.SaveToFile(false);
			ApplyFloppyArms();
		});
	}

	private void OnLevelLoaded(LevelInfo info)
	{
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		ResetState();
		_levelLoaded = true;
		_fusionChecked = false;
		_cachedIsProxyProp = null;
		_safeDamageTime = Time.time + 3f;
		_safeRagdollTime = Time.time + 3f;
		try
		{
			((MelonBase)this).LoggerInstance.Msg("Level loaded: " + info.title);
		}
		catch
		{
			((MelonBase)this).LoggerInstance.Msg("Level loaded.");
		}
	}

	private void ResetState()
	{
		//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_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		_isDowned = false;
		_isDead = false;
		_wasRagdolled = false;
		_nextRagdollTime = 0f;
		_unragdollTime = 0f;
		_lastVelocity = Vector3.zero;
		_prevVelocity = Vector3.zero;
		_damageHits = 0;
		_lastDamageTime = 0f;
		_cachedGroundFrame = -1000;
		_savedWeights.Clear();
		_fixPending = false;
		_framesSinceUnragdoll = 0;
		_savedPelvisPos = Vector3.zero;
		_savedPelvisY = 0f;
		_lastImpactDamageTime = 0f;
		_jumpBuffered = false;
		_ragdollBuffered = false;
		IsPlayerRagdolled = false;
	}

	private bool IsLocalPlayer()
	{
		try
		{
			if ((Object)(object)Player.RigManager == (Object)null)
			{
				return false;
			}
			if (!_fusionChecked)
			{
				Component component = ((Component)Player.RigManager).GetComponent("Fusion.NetworkObject");
				if ((Object)(object)component != (Object)null)
				{
					_cachedIsProxyProp = ((object)component).GetType().GetProperty("IsProxy");
				}
				_fusionChecked = true;
			}
			if (_cachedIsProxyProp != null)
			{
				Component component2 = ((Component)Player.RigManager).GetComponent("Fusion.NetworkObject");
				if ((Object)(object)component2 != (Object)null)
				{
					object value = _cachedIsProxyProp.GetValue(component2);
					bool flag = default(bool);
					int num;
					if (value is bool)
					{
						flag = (bool)value;
						num = 1;
					}
					else
					{
						num = 0;
					}
					if (((uint)num & (flag ? 1u : 0u)) != 0)
					{
						return false;
					}
				}
			}
			return true;
		}
		catch
		{
			return true;
		}
	}

	private bool FindGround(Vector3 startPos, float maxDistance, Transform playerRoot, out Vector3 groundPos)
	{
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0004: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_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)
		groundPos = startPos;
		Il2CppStructArray<RaycastHit> val = Physics.RaycastAll(startPos, Vector3.down, maxDistance, _groundLayerMask, (QueryTriggerInteraction)1);
		float num = float.MaxValue;
		bool result = false;
		for (int i = 0; i < ((Il2CppArrayBase<RaycastHit>)(object)val).Length; i++)
		{
			RaycastHit val2 = ((Il2CppArrayBase<RaycastHit>)(object)val)[i];
			if ((Object)(object)((RaycastHit)(ref val2)).collider != (Object)null && (Object)(object)((Component)((RaycastHit)(ref val2)).collider).transform.root != (Object)(object)playerRoot && ((RaycastHit)(ref val2)).distance < num)
			{
				num = ((RaycastHit)(ref val2)).distance;
				groundPos = ((RaycastHit)(ref val2)).point;
				result = true;
			}
		}
		return result;
	}

	private bool CheckSupported360(PhysicsRig phys, out float friction)
	{
		//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_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_0138: Unknown result type (might be due to invalid IL or missing references)
		//IL_0140: Unknown result type (might be due to invalid IL or missing references)
		//IL_0252: Unknown result type (might be due to invalid IL or missing references)
		//IL_0257: Unknown result type (might be due to invalid IL or missing references)
		//IL_0259: Unknown result type (might be due to invalid IL or missing references)
		//IL_025b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0164: Unknown result type (might be due to invalid IL or missing references)
		//IL_0169: Unknown result type (might be due to invalid IL or missing references)
		//IL_027f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0284: Unknown result type (might be due to invalid IL or missing references)
		//IL_017e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0183: Unknown result type (might be due to invalid IL or missing references)
		//IL_0299: Unknown result type (might be due to invalid IL or missing references)
		//IL_029e: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f0: Unknown result type (might be due to invalid IL or missing references)
		int frameCount = Time.frameCount;
		if (frameCount - _cachedGroundFrame < 3 && frameCount > 0)
		{
			friction = _cachedFriction;
			return _cachedSupported;
		}
		friction = 1f;
		bool flag = false;
		if ((Object)(object)phys == (Object)null || (Object)(object)((Rig)phys).m_pelvis == (Object)null)
		{
			_cachedSupported = false;
			_cachedFriction = 1f;
			_cachedGroundFrame = frameCount;
			return false;
		}
		Vector3 position = ((Rig)phys).m_pelvis.position;
		Transform root = ((Component)phys).transform.root;
		int num = Physics.OverlapSphereNonAlloc(position, 0.6f, Il2CppReferenceArray<Collider>.op_Implicit(_colliderBuffer), _groundLayerMask, (QueryTriggerInteraction)1);
		for (int i = 0; i < num; i++)
		{
			Collider val = _colliderBuffer[i];
			if (!((Object)(object)val == (Object)null) && !((Object)(object)((Component)val).transform.root == (Object)(object)root))
			{
				flag = true;
				if ((Object)(object)val.sharedMaterial != (Object)null)
				{
					friction = val.sharedMaterial.dynamicFriction;
				}
				break;
			}
		}
		RaycastHit val3;
		if (!flag)
		{
			for (int j = 0; j < _sphereDirections.Length; j++)
			{
				Il2CppStructArray<RaycastHit> val2 = Physics.RaycastAll(position, _sphereDirections[j], 1f, _groundLayerMask, (QueryTriggerInteraction)1);
				for (int k = 0; k < ((Il2CppArrayBase<RaycastHit>)(object)val2).Length; k++)
				{
					val3 = ((Il2CppArrayBase<RaycastHit>)(object)val2)[k];
					if (!((Object)(object)((RaycastHit)(ref val3)).collider != (Object)null))
					{
						continue;
					}
					val3 = ((Il2CppArrayBase<RaycastHit>)(object)val2)[k];
					if ((Object)(object)((Component)((RaycastHit)(ref val3)).collider).transform.root != (Object)(object)root)
					{
						flag = true;
						val3 = ((Il2CppArrayBase<RaycastHit>)(object)val2)[k];
						if ((Object)(object)((RaycastHit)(ref val3)).collider.sharedMaterial != (Object)null)
						{
							val3 = ((Il2CppArrayBase<RaycastHit>)(object)val2)[k];
							friction = ((RaycastHit)(ref val3)).collider.sharedMaterial.dynamicFriction;
						}
						break;
					}
				}
				if (flag)
				{
					break;
				}
			}
		}
		if (!flag && (Object)(object)phys.feet != (Object)null)
		{
			Vector3 position2 = phys.feet.transform.position;
			Il2CppStructArray<RaycastHit> val4 = Physics.RaycastAll(position2, Vector3.down, 0.8f, _groundLayerMask, (QueryTriggerInteraction)1);
			for (int l = 0; l < ((Il2CppArrayBase<RaycastHit>)(object)val4).Length; l++)
			{
				val3 = ((Il2CppArrayBase<RaycastHit>)(object)val4)[l];
				if (!((Object)(object)((RaycastHit)(ref val3)).collider != (Object)null))
				{
					continue;
				}
				val3 = ((Il2CppArrayBase<RaycastHit>)(object)val4)[l];
				if ((Object)(object)((Component)((RaycastHit)(ref val3)).collider).transform.root != (Object)(object)root)
				{
					flag = true;
					val3 = ((Il2CppArrayBase<RaycastHit>)(object)val4)[l];
					if ((Object)(object)((RaycastHit)(ref val3)).collider.sharedMaterial != (Object)null)
					{
						val3 = ((Il2CppArrayBase<RaycastHit>)(object)val4)[l];
						friction = ((RaycastHit)(ref val3)).collider.sharedMaterial.dynamicFriction;
					}
					break;
				}
			}
		}
		_cachedSupported = flag;
		_cachedFriction = friction;
		_cachedGroundFrame = frameCount;
		return flag;
	}

	private bool CheckGroundBelow(PhysicsRig phys)
	{
		//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_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d5: 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_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_00f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0102: Unknown result type (might be due to invalid IL or missing references)
		//IL_0107: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0141: Unknown result type (might be due to invalid IL or missing references)
		//IL_0146: 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_014f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_015e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0162: Unknown result type (might be due to invalid IL or missing references)
		//IL_0181: Unknown result type (might be due to invalid IL or missing references)
		//IL_0186: Unknown result type (might be due to invalid IL or missing references)
		//IL_019a: Unknown result type (might be due to invalid IL or missing references)
		//IL_019f: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)phys == (Object)null || (Object)(object)((Rig)phys).m_pelvis == (Object)null)
		{
			return false;
		}
		Vector3 position = ((Rig)phys).m_pelvis.position;
		Transform root = ((Component)phys).transform.root;
		Il2CppStructArray<RaycastHit> val = Physics.RaycastAll(position, Vector3.down, 1.2f, _groundLayerMask, (QueryTriggerInteraction)1);
		RaycastHit val2;
		for (int i = 0; i < ((Il2CppArrayBase<RaycastHit>)(object)val).Length; i++)
		{
			val2 = ((Il2CppArrayBase<RaycastHit>)(object)val)[i];
			if ((Object)(object)((RaycastHit)(ref val2)).collider != (Object)null)
			{
				val2 = ((Il2CppArrayBase<RaycastHit>)(object)val)[i];
				if ((Object)(object)((Component)((RaycastHit)(ref val2)).collider).transform.root != (Object)(object)root)
				{
					return true;
				}
			}
		}
		Vector3[] array = new Vector3[4];
		Vector3 val3 = new Vector3(0.5f, -1f, 0f);
		array[0] = ((Vector3)(ref val3)).normalized;
		val3 = new Vector3(-0.5f, -1f, 0f);
		array[1] = ((Vector3)(ref val3)).normalized;
		val3 = new Vector3(0f, -1f, 0.5f);
		array[2] = ((Vector3)(ref val3)).normalized;
		val3 = new Vector3(0f, -1f, -0.5f);
		array[3] = ((Vector3)(ref val3)).normalized;
		Vector3[] array2 = (Vector3[])(object)array;
		for (int j = 0; j < array2.Length; j++)
		{
			val = Physics.RaycastAll(position, array2[j], 1f, _groundLayerMask, (QueryTriggerInteraction)1);
			for (int k = 0; k < ((Il2CppArrayBase<RaycastHit>)(object)val).Length; k++)
			{
				val2 = ((Il2CppArrayBase<RaycastHit>)(object)val)[k];
				if ((Object)(object)((RaycastHit)(ref val2)).collider != (Object)null)
				{
					val2 = ((Il2CppArrayBase<RaycastHit>)(object)val)[k];
					if ((Object)(object)((Component)((RaycastHit)(ref val2)).collider).transform.root != (Object)(object)root)
					{
						return true;
					}
				}
			}
		}
		return false;
	}

	private bool IsHoldingNimbus(PhysicsRig phys)
	{
		try
		{
			if ((Object)(object)phys.leftHand != (Object)null && CheckForNimbus(phys.leftHand.m_CurrentAttachedGO))
			{
				return true;
			}
			if ((Object)(object)phys.rightHand != (Object)null && CheckForNimbus(phys.rightHand.m_CurrentAttachedGO))
			{
				return true;
			}
		}
		catch
		{
		}
		return false;
		static bool CheckForNimbus(GameObject attachedGO)
		{
			if ((Object)(object)attachedGO == (Object)null)
			{
				return false;
			}
			Transform val = attachedGO.transform;
			while ((Object)(object)val != (Object)null)
			{
				if (((Object)val).name.IndexOf("nimbus", StringComparison.OrdinalIgnoreCase) >= 0)
				{
					return true;
				}
				val = val.parent;
			}
			return false;
		}
	}

	private static AIBrain GetClosestBrain(Il2CppArrayBase<AIBrain> brains, Vector3 playerPos)
	{
		//IL_0061: 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)
		AIBrain result = null;
		float num = float.MaxValue;
		if (brains == null)
		{
			return null;
		}
		for (int i = 0; i < brains.Length; i++)
		{
			AIBrain val = brains[i];
			if (!((Object)(object)val == (Object)null) && !((Object)(object)val.puppetMaster == (Object)null) && ((Component)val).gameObject.activeInHierarchy)
			{
				float num2 = Vector3.SqrMagnitude(playerPos - ((Component)val).transform.position);
				if (num2 < num)
				{
					num = num2;
					result = val;
				}
			}
		}
		return result;
	}

	private static void RagdollBrain(AIBrain brain)
	{
		if ((Object)(object)brain == (Object)null || (Object)(object)brain.puppetMaster == (Object)null)
		{
			return;
		}
		PuppetMaster puppetMaster = brain.puppetMaster;
		int instanceID = ((Object)puppetMaster).GetInstanceID();
		if (!_savedWeights.ContainsKey(instanceID))
		{
			_savedWeights[instanceID] = puppetMaster.muscleWeight;
		}
		puppetMaster.muscleWeight = 0f;
		Il2CppArrayBase<Behaviour> componentsInChildren = ((Component)((Component)brain).transform.root).GetComponentsInChildren<Behaviour>(true);
		if (componentsInChildren == null)
		{
			return;
		}
		for (int i = 0; i < componentsInChildren.Length; i++)
		{
			Behaviour val = componentsInChildren[i];
			if ((Object)(object)val != (Object)null && ((object)val).GetType().Name.Contains("Animator"))
			{
				val.enabled = false;
			}
		}
	}

	private static void RestoreBrain(AIBrain brain)
	{
		if ((Object)(object)brain == (Object)null || (Object)(object)brain.puppetMaster == (Object)null)
		{
			return;
		}
		PuppetMaster puppetMaster = brain.puppetMaster;
		int instanceID = ((Object)puppetMaster).GetInstanceID();
		if (_savedWeights.TryGetValue(instanceID, out var value))
		{
			puppetMaster.muscleWeight = value;
			_savedWeights.Remove(instanceID);
		}
		else
		{
			puppetMaster.muscleWeight = 1f;
		}
		Il2CppArrayBase<Behaviour> componentsInChildren = ((Component)((Component)brain).transform.root).GetComponentsInChildren<Behaviour>(true);
		if (componentsInChildren == null)
		{
			return;
		}
		for (int i = 0; i < componentsInChildren.Length; i++)
		{
			Behaviour val = componentsInChildren[i];
			if ((Object)(object)val != (Object)null && ((object)val).GetType().Name.Contains("Animator"))
			{
				val.enabled = true;
			}
		}
	}

	private static void RagdollNearestNPC()
	{
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_00df: Expected O, but got Unknown
		//IL_0063: 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_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: 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_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Expected O, but got Unknown
		try
		{
			if (!((Object)(object)Player.RigManager == (Object)null) && !((Object)(object)Player.RigManager.physicsRig == (Object)null))
			{
				Vector3 position = ((Rig)Player.RigManager.physicsRig).m_pelvis.position;
				Il2CppArrayBase<AIBrain> brains = Object.FindObjectsOfType<AIBrain>();
				AIBrain closestBrain = GetClosestBrain(brains, position);
				if ((Object)(object)closestBrain != (Object)null)
				{
					RagdollBrain(closestBrain);
					Notifier.Send(new Notification
					{
						Title = NotificationText.op_Implicit("NPC"),
						Message = NotificationText.op_Implicit("Ragdolled!"),
						Type = (NotificationType)3,
						PopupLength = 2f
					});
				}
				else
				{
					Notifier.Send(new Notification
					{
						Title = NotificationText.op_Implicit("NPC"),
						Message = NotificationText.op_Implicit("No NPCs found."),
						Type = (NotificationType)1,
						PopupLength = 2f
					});
				}
			}
		}
		catch (Exception ex)
		{
			MelonLogger.Warning("RagdollNearestNPC: " + ex.Message);
		}
	}

	private static void RestoreNearestNPC()
	{
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_00df: Expected O, but got Unknown
		//IL_0063: 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_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: 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_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Expected O, but got Unknown
		try
		{
			if (!((Object)(object)Player.RigManager == (Object)null) && !((Object)(object)Player.RigManager.physicsRig == (Object)null))
			{
				Vector3 position = ((Rig)Player.RigManager.physicsRig).m_pelvis.position;
				Il2CppArrayBase<AIBrain> brains = Object.FindObjectsOfType<AIBrain>();
				AIBrain closestBrain = GetClosestBrain(brains, position);
				if ((Object)(object)closestBrain != (Object)null)
				{
					RestoreBrain(closestBrain);
					Notifier.Send(new Notification
					{
						Title = NotificationText.op_Implicit("NPC"),
						Message = NotificationText.op_Implicit("Restored!"),
						Type = (NotificationType)3,
						PopupLength = 2f
					});
				}
				else
				{
					Notifier.Send(new Notification
					{
						Title = NotificationText.op_Implicit("NPC"),
						Message = NotificationText.op_Implicit("No NPCs found."),
						Type = (NotificationType)1,
						PopupLength = 2f
					});
				}
			}
		}
		catch (Exception ex)
		{
			MelonLogger.Warning("RestoreNearestNPC: " + ex.Message);
		}
	}

	private static void RagdollAllNPCs()
	{
		//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_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Expected O, but got Unknown
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: 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_0108: Unknown result type (might be due to invalid IL or missing references)
		//IL_010d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0112: Unknown result type (might be due to invalid IL or missing references)
		//IL_0114: Unknown result type (might be due to invalid IL or missing references)
		//IL_0119: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: Expected O, but got Unknown
		try
		{
			Il2CppArrayBase<AIBrain> val = Object.FindObjectsOfType<AIBrain>();
			if (val == null || val.Length == 0)
			{
				Notifier.Send(new Notification
				{
					Title = NotificationText.op_Implicit("NPC"),
					Message = NotificationText.op_Implicit("No NPCs."),
					Type = (NotificationType)1,
					PopupLength = 2f
				});
				return;
			}
			int num = 0;
			for (int i = 0; i < val.Length; i++)
			{
				AIBrain val2 = val[i];
				if ((Object)(object)val2 != (Object)null && (Object)(object)val2.puppetMaster != (Object)null && ((Component)val2).gameObject.activeInHierarchy)
				{
					RagdollBrain(val2);
					num++;
				}
			}
			Notifier.Send(new Notification
			{
				Title = NotificationText.op_Implicit("NPC"),
				Message = NotificationText.op_Implicit($"Ragdolled {num}!"),
				Type = (NotificationType)3,
				PopupLength = 2f
			});
		}
		catch (Exception ex)
		{
			MelonLogger.Warning("RagdollAllNPCs: " + ex.Message);
		}
	}

	private static void RestoreAllNPCs()
	{
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_00d1: 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_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Expected O, but got Unknown
		try
		{
			Il2CppArrayBase<AIBrain> val = Object.FindObjectsOfType<AIBrain>();
			if (val == null || val.Length == 0)
			{
				return;
			}
			int num = 0;
			for (int i = 0; i < val.Length; i++)
			{
				AIBrain val2 = val[i];
				if ((Object)(object)val2 != (Object)null && (Object)(object)val2.puppetMaster != (Object)null)
				{
					RestoreBrain(val2);
					num++;
				}
			}
			_savedWeights.Clear();
			Notifier.Send(new Notification
			{
				Title = NotificationText.op_Implicit("NPC"),
				Message = NotificationText.op_Implicit($"Restored {num}!"),
				Type = (NotificationType)3,
				PopupLength = 2f
			});
		}
		catch (Exception ex)
		{
			MelonLogger.Warning("RestoreAllNPCs: " + ex.Message);
		}
	}

	private bool CheckJumpInput()
	{
		if (Input.GetKeyDown((KeyCode)32))
		{
			return true;
		}
		if (Input.GetKeyDown((KeyCode)330))
		{
			return true;
		}
		try
		{
			if ((Object)(object)Player.RightController != (Object)null && Player.RightController.GetAButtonDown())
			{
				return true;
			}
			if ((Object)(object)Player.LeftController != (Object)null && Player.LeftController.GetAButtonDown())
			{
				return true;
			}
		}
		catch
		{
		}
		return false;
	}

	private bool CheckRagdollInput()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		if (Input.GetKeyDown(PrefKeyboardKey.Value))
		{
			return true;
		}
		bool flag = false;
		try
		{
			BaseController rightController = Player.RightController;
			BaseController leftController = Player.LeftController;
			if (PrefInputMode.Value == InputMode.ThumbstickPress)
			{
				if ((PrefSide.Value == ControllerSide.Right || PrefSide.Value == ControllerSide.Both) && (Object)(object)rightController != (Object)null)
				{
					flag |= rightController.GetThumbStickDown();
				}
				if ((PrefSide.Value == ControllerSide.Left || PrefSide.Value == ControllerSide.Both) && (Object)(object)leftController != (Object)null)
				{
					flag |= leftController.GetThumbStickDown();
				}
			}
			else if (PrefInputMode.Value == InputMode.DoubleTapB)
			{
				bool flag2 = false;
				if ((PrefSide.Value == ControllerSide.Right || PrefSide.Value == ControllerSide.Both) && (Object)(object)rightController != (Object)null)
				{
					flag2 |= rightController.GetBButtonDown();
				}
				if ((PrefSide.Value == ControllerSide.Left || PrefSide.Value == ControllerSide.Both) && (Object)(object)leftController != (Object)null)
				{
					flag2 |= leftController.GetBButtonDown();
				}
				float unscaledTime = Time.unscaledTime;
				if (flag2 && _doubleTapReady)
				{
					if (unscaledTime - _lastInputTime <= 0.35f)
					{
						flag = true;
					}
					_doubleTapReady = false;
					_lastInputTime = 0f;
				}
				else if (flag2)
				{
					_lastInputTime = unscaledTime;
					_doubleTapReady = true;
				}
				else if (unscaledTime - _lastInputTime > 0.35f)
				{
					_doubleTapReady = false;
					_lastInputTime = 0f;
				}
			}
		}
		catch
		{
		}
		return flag;
	}

	public override void OnUpdate()
	{
		if (!PrefEnabled.Value || !_levelLoaded || !IsLocalPlayer() || (Object)(object)Player.RigManager == (Object)null)
		{
			return;
		}
		RigManager rigManager = Player.RigManager;
		PhysicsRig physicsRig = rigManager.physicsRig;
		if ((Object)(object)physicsRig == (Object)null)
		{
			return;
		}
		if (CheckRagdollInput())
		{
			_ragdollBuffered = true;
		}
		if (CheckJumpInput())
		{
			_jumpBuffered = true;
		}
		bool flag = (IsPlayerRagdolled = IsRagdolled(physicsRig));
		HandleRespawn(rigManager, physicsRig, flag);
		if (_isDead)
		{
			return;
		}
		if (_ragdollBuffered)
		{
			_ragdollBuffered = false;
			ProcessRagdollInput(rigManager, physicsRig, flag);
			return;
		}
		if (_jumpBuffered && flag)
		{
			_jumpBuffered = false;
			if (CanUnragdoll(physicsRig))
			{
				UnragdollRig(rigManager);
			}
			return;
		}
		if (_jumpBuffered)
		{
			_jumpBuffered = false;
		}
		if (!((Object)(object)rigManager.activeSeat != (Object)null) && _isDowned && Time.time - _downedStartTime >= PrefDownedDuration.Value && CanUnragdoll(physicsRig))
		{
			UnragdollRig(rigManager);
		}
	}

	private void HandleRespawn(RigManager rig, PhysicsRig phys, bool isRagdolled)
	{
		//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)rig.health == (Object)null)
		{
			return;
		}
		bool flag = _isDead || _isDowned;
		bool flag2 = rig.health.curr_Health >= rig.health.max_Health * 0.9f;
		if (flag && flag2 && (!_isDead || !(Time.time - _deathTime < 4f)))
		{
			_isDead = false;
			_isDowned = false;
			_unragdollTime = 0f;
			_safeDamageTime = Time.time + 3f;
			_safeRagdollTime = Time.time + 3f;
			if ((Object)(object)phys != (Object)null)
			{
				_lastVelocity = phys.wholeBodyVelocity;
				_prevVelocity = phys.wholeBodyVelocity;
			}
			if (isRagdolled)
			{
				UnragdollRig(rig);
			}
		}
	}

	private void ProcessRagdollInput(RigManager rig, PhysicsRig phys, bool isRagdolled)
	{
		if ((Object)(object)rig.activeSeat != (Object)null && PrefFastExit.Value)
		{
			try
			{
				rig.activeSeat.EgressRig(true);
			}
			catch
			{
			}
			if (Time.time >= _nextRagdollTime)
			{
				ExecuteRagdoll(rig);
			}
		}
		else
		{
			if ((Object)(object)rig.activeSeat != (Object)null)
			{
				return;
			}
			if (isRagdolled)
			{
				if (CanUnragdoll(phys))
				{
					UnragdollRig(rig);
				}
			}
			else if (Time.time >= _nextRagdollTime)
			{
				ExecuteRagdoll(rig);
			}
		}
	}

	public override void OnFixedUpdate()
	{
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: 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_00c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01de: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
		if (!PrefEnabled.Value || !_levelLoaded || !IsLocalPlayer() || (Object)(object)Player.RigManager == (Object)null)
		{
			return;
		}
		RigManager rigManager = Player.RigManager;
		PhysicsRig physicsRig = rigManager.physicsRig;
		if ((Object)(object)physicsRig == (Object)null || (Object)(object)rigManager.activeSeat != (Object)null)
		{
			return;
		}
		bool flag = (IsPlayerRagdolled = IsRagdolled(physicsRig));
		HandleRagdollFix(rigManager, physicsRig, flag);
		if (flag)
		{
			Vector3 wholeBodyVelocity = physicsRig.wholeBodyVelocity;
			Vector3 val = wholeBodyVelocity - _lastVelocity;
			_prevVelocity = _lastVelocity;
			_lastVelocity = wholeBodyVelocity;
			if (_isDead)
			{
				return;
			}
			TryApplyImpactDamage(rigManager, ((Vector3)(ref val)).magnitude);
			if (PrefDragEnabled.Value)
			{
				HandleDrag(physicsRig);
			}
			if (!PrefPreventUnragdollMoving.Value)
			{
				return;
			}
			float num = Time.time - _ragdollStartTime;
			if (num < PrefMaxRagdollTime.Value)
			{
				float friction;
				bool flag3 = CheckSupported360(physicsRig, out friction);
				float magnitude = ((Vector3)(ref wholeBodyVelocity)).magnitude;
				if (!flag3 || magnitude > PrefUnragdollMaxVelocity.Value)
				{
					float num2 = Time.time + PrefRagdollCooldown.Value;
					float num3 = _ragdollStartTime + PrefMaxRagdollTime.Value;
					_unragdollTime = Mathf.Min(num2, num3);
				}
			}
		}
		else if (Time.time >= _nextRagdollTime && !_isDead)
		{
			HandleAutoRagdoll(rigManager, physicsRig);
			_prevVelocity = _lastVelocity;
			_lastVelocity = physicsRig.wholeBodyVelocity;
		}
	}

	private bool IsRagdolled(PhysicsRig phys)
	{
		try
		{
			if ((Object)(object)phys == (Object)null)
			{
				return false;
			}
			bool flag = (Object)(object)phys.torso != (Object)null && phys.torso.shutdown;
			bool flag2 = !phys.ballLocoEnabled;
			return flag || flag2;
		}
		catch
		{
			return false;
		}
	}

	private bool CanUnragdoll(PhysicsRig phys)
	{
		if (_isDead)
		{
			return false;
		}
		float num = Time.time - _ragdollStartTime;
		if (num >= PrefMaxRagdollTime.Value)
		{
			return true;
		}
		return Time.time >= _unragdollTime;
	}

	private void HandleRagdollFix(RigManager rig, PhysicsRig phys, bool isRagdolled)
	{
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		//IL_0124: Unknown result type (might be due to invalid IL or missing references)
		//IL_0117: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: Unknown result type (might be due to invalid IL or missing references)
		//IL_015c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0170: Unknown result type (might be due to invalid IL or missing references)
		//IL_0175: Unknown result type (might be due to invalid IL or missing references)
		//IL_017a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0150: Unknown result type (might be due to invalid IL or missing references)
		//IL_0152: Unknown result type (might be due to invalid IL or missing references)
		if (_wasRagdolled == isRagdolled)
		{
			if (_fixPending)
			{
				ProcessFix(rig, phys);
			}
			return;
		}
		if (!_wasRagdolled && isRagdolled)
		{
			_ragdollStartTime = Time.time;
			_fixPending = false;
			_framesSinceUnragdoll = 0;
		}
		else if (_wasRagdolled && !isRagdolled && !_fixPending && PrefFixEnabled.Value)
		{
			Vector3 wholeBodyVelocity = phys.wholeBodyVelocity;
			float magnitude = ((Vector3)(ref wholeBodyVelocity)).magnitude;
			bool flag = magnitude > PrefFixVelLimit.Value;
			if (!PrefFixVel.Value || !flag)
			{
				float num = (((Object)(object)rig.avatar != (Object)null && rig.avatar.height > 0.1f) ? rig.avatar.height : 1.8f);
				Vector3 val = (((Object)(object)((Rig)phys).m_pelvis != (Object)null) ? ((Rig)phys).m_pelvis.position : ((Component)phys).transform.position);
				if (FindGround(val, num * 1.5f, ((Component)phys).transform.root, out var groundPos))
				{
					_savedPelvisPos = groundPos;
				}
				else
				{
					_savedPelvisPos = val - new Vector3(0f, num * 0.45f, 0f);
				}
				_savedPelvisY = _savedPelvisPos.y;
				_fixPending = true;
				_framesSinceUnragdoll = 0;
			}
		}
		_wasRagdolled = isRagdolled;
	}

	private void ProcessFix(RigManager rig, PhysicsRig phys)
	{
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		_framesSinceUnragdoll++;
		if (_framesSinceUnragdoll >= 1 && _framesSinceUnragdoll <= 6)
		{
			if (PrefFixEnabled.Value)
			{
				ZeroVelocities(phys);
				if (PrefFixTeleport.Value)
				{
					rig.Teleport(_savedPelvisPos, true);
				}
			}
		}
		else
		{
			_fixPending = false;
		}
	}

	private void ZeroVelocities(PhysicsRig phys)
	{
		//IL_0041: 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)
		if ((Object)(object)phys == (Object)null)
		{
			return;
		}
		try
		{
			Il2CppArrayBase<Rigidbody> componentsInChildren = ((Component)phys).GetComponentsInChildren<Rigidbody>();
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				Rigidbody val = componentsInChildren[i];
				if ((Object)(object)val != (Object)null && !val.isKinematic)
				{
					val.velocity = Vector3.zero;
					val.angularVelocity = Vector3.zero;
				}
			}
		}
		catch
		{
		}
	}

	private float GetPlayerScale(RigManager rig)
	{
		if (!PrefDynamicSizeScaling.Value)
		{
			return 1f;
		}
		if ((Object)(object)rig != (Object)null && (Object)(object)rig.avatar != (Object)null && rig.avatar.height > 0.1f)
		{
			return Mathf.Clamp(rig.avatar.height / 1.8f, 0.2f, 5f);
		}
		return 1f;
	}

	private void HandleAutoRagdoll(RigManager rig, PhysicsRig phys)
	{
		//IL_0391: Unknown result type (might be due to invalid IL or missing references)
		//IL_0392: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b6: 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_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: 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_0230: Unknown result type (might be due to invalid IL or missing references)
		//IL_0235: Unknown result type (might be due to invalid IL or missing references)
		//IL_013f: 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_0279: Unknown result type (might be due to invalid IL or missing references)
		//IL_027a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0288: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
		if (Time.time < _safeRagdollTime || IsHoldingNimbus(phys))
		{
			return;
		}
		Vector3 wholeBodyVelocity = phys.wholeBodyVelocity;
		Vector3 val = wholeBodyVelocity - _lastVelocity;
		float y = wholeBodyVelocity.y;
		float magnitude = ((Vector3)(ref val)).magnitude;
		bool flag = CheckGroundBelow(phys);
		float friction;
		bool flag2 = CheckSupported360(phys, out friction);
		float playerScale = GetPlayerScale(rig);
		float num = PrefFallThresh.Value * playerScale;
		float num2 = PrefImpactThresh.Value * playerScale;
		float num3 = PrefLaunchThresh.Value * playerScale;
		float num4 = PrefWallPushVelocity.Value * playerScale;
		float num5 = PrefSlipVelocity.Value * playerScale;
		if (PrefFallEnabled.Value && !flag && y < 0f - num)
		{
			ExecuteRagdoll(rig);
			TryApplyImpactDamage(rig, magnitude);
			return;
		}
		Vector3 val2 = wholeBodyVelocity - _prevVelocity;
		float magnitude2 = ((Vector3)(ref val2)).magnitude;
		if (magnitude > 0.3f)
		{
			if (PrefImpactEnabled.Value && ((Vector3)(ref _lastVelocity)).sqrMagnitude > 0.01f)
			{
				float num6 = Vector3.Dot(((Vector3)(ref val)).normalized, ((Vector3)(ref _lastVelocity)).normalized);
				if (num6 < -0.05f && magnitude > num2)
				{
					ExecuteRagdoll(rig);
					TryApplyImpactDamage(rig, magnitude);
					return;
				}
			}
			if (PrefLaunchEnabled.Value && ((Vector3)(ref wholeBodyVelocity)).sqrMagnitude > 0.01f)
			{
				float num7 = Vector3.Dot(((Vector3)(ref val)).normalized, ((Vector3)(ref wholeBodyVelocity)).normalized);
				if ((num7 > 0.4f || val.y > 0.4f) && magnitude > num3)
				{
					ExecuteRagdoll(rig);
					TryApplyImpactDamage(rig, magnitude);
					return;
				}
			}
		}
		if (PrefImpactEnabled.Value && magnitude2 > num2 * 1.3f && ((Vector3)(ref _lastVelocity)).sqrMagnitude > 0.5f)
		{
			float num8 = Vector3.Angle(_lastVelocity, wholeBodyVelocity);
			if (num8 > 80f)
			{
				ExecuteRagdoll(rig);
				TryApplyImpactDamage(rig, magnitude2);
				return;
			}
		}
		if (PrefSlipEnabled.Value && flag2)
		{
			Vector3 val3 = wholeBodyVelocity;
			val3.y = 0f;
			bool flag3 = Mathf.Abs(val.y) > 3f * playerScale && y < 0f - 1.5f * playerScale;
			if ((friction < PrefSlipFriction.Value && ((Vector3)(ref val3)).magnitude > num5) || (friction < PrefSlipFriction.Value && flag3))
			{
				ExecuteRagdoll(rig);
				return;
			}
		}
		if (!PrefWallPushEnabled.Value)
		{
			return;
		}
		bool flag4 = false;
		try
		{
			bool flag5 = false;
			bool flag6 = false;
			if ((Object)(object)phys.leftHand != (Object)null && (Object)(object)phys.leftHand.physHand != (Object)null)
			{
				flag5 = phys.leftHand.physHand._colliding;
			}
			if ((Object)(object)phys.rightHand != (Object)null && (Object)(object)phys.rightHand.physHand != (Object)null)
			{
				flag6 = phys.rightHand.physHand._colliding;
			}
			flag4 = flag5 || flag6;
		}
		catch
		{
		}
		Vector3 val4 = wholeBodyVelocity;
		val4.y = 0f;
		Vector3 lastVelocity = _lastVelocity;
		lastVelocity.y = 0f;
		Vector3 val5 = val4 - lastVelocity;
		float magnitude3 = ((Vector3)(ref val5)).magnitude;
		if (flag4 && !flag2 && ((Vector3)(ref val4)).magnitude > num4)
		{
			ExecuteRagdoll(rig);
			TryApplyImpactDamage(rig, ((Vector3)(ref val4)).magnitude);
		}
		else if (flag4 && magnitude3 > 1.2f * playerScale && ((Vector3)(ref lastVelocity)).magnitude > num4)
		{
			ExecuteRagdoll(rig);
			TryApplyImpactDamage(rig, magnitude3);
		}
		else if (magnitude3 > 3f * playerScale && ((Vector3)(ref lastVelocity)).magnitude > num4)
		{
			ExecuteRagdoll(rig);
			TryApplyImpactDamage(rig, magnitude3);
		}
	}

	private void TryApplyImpactDamage(RigManager rig, float velocityDelta)
	{
		if (!PrefImpactDamageEnabled.Value || (Object)(object)rig == (Object)null || (Object)(object)rig.health == (Object)null || _isDead || Time.time < _safeDamageTime || velocityDelta < 1f || Time.time - _lastImpactDamageTime < 0.5f)
		{
			return;
		}
		float playerScale = GetPlayerScale(rig);
		float num = PrefImpactDamageMultiplier.Value / playerScale;
		float num2 = PrefImpactDamageThreshold.Value * playerScale;
		float num3 = velocityDelta * num;
		float num4 = num3 - num2;
		if (!(num4 > 0f))
		{
			return;
		}
		try
		{
			rig.health.TAKEDAMAGE(num4);
			_lastImpactDamageTime = Time.time;
		}
		catch (Exception ex)
		{
			((MelonBase)this).LoggerInstance.Warning("ImpactDamage: " + ex.Message);
		}
	}

	private void HandleDrag(PhysicsRig phys)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0107: Unknown result type (might be due to invalid IL or missing references)
		//IL_010c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0241: Unknown result type (might be due to invalid IL or missing references)
		//IL_0238: 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_025b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0252: Unknown result type (might be due to invalid IL or missing references)
		//IL_0260: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_029f: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_032c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0330: 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_0346: Unknown result type (might be due to invalid IL or missing references)
		//IL_0315: Unknown result type (might be due to invalid IL or missing references)
		//IL_0370: Unknown result type (might be due to invalid IL or missing references)
		//IL_0377: 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_03ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_03df: Unknown result type (might be due to invalid IL or missing references)
		Vector2 val = Vector2.zero;
		try
		{
			BaseController leftController = Player.LeftController;
			if ((Object)(object)leftController != (Object)null)
			{
				val = leftController.GetThumbStickAxis();
			}
		}
		catch
		{
		}
		if (((Vector2)(ref val)).magnitude <= 0.1f)
		{
			if (Input.GetKey((KeyCode)119) || Input.GetKey((KeyCode)273))
			{
				val.y += 1f;
			}
			if (Input.GetKey((KeyCode)115) || Input.GetKey((KeyCode)274))
			{
				val.y -= 1f;
			}
			if (Input.GetKey((KeyCode)100) || Input.GetKey((KeyCode)275))
			{
				val.x += 1f;
			}
			if (Input.GetKey((KeyCode)97) || Input.GetKey((KeyCode)276))
			{
				val.x -= 1f;
			}
			if (((Vector2)(ref val)).sqrMagnitude > 1f)
			{
				val = ((Vector2)(ref val)).normalized;
			}
		}
		if (((Vector2)(ref val)).magnitude <= 0.1f)
		{
			return;
		}
		try
		{
			Rigidbody val2 = null;
			if ((Object)(object)((Rig)phys).m_pelvis != (Object)null)
			{
				val2 = ((Component)((Rig)phys).m_pelvis).GetComponent<Rigidbody>();
			}
			if ((Object)(object)val2 == (Object)null || val2.isKinematic)
			{
				return;
			}
			Vector3 wholeBodyVelocity = phys.wholeBodyVelocity;
			if (!(((Vector3)(ref wholeBodyVelocity)).magnitude > 8f))
			{
				Rigidbody val3 = null;
				Rigidbody val4 = null;
				Rigidbody val5 = null;
				if ((Object)(object)((Rig)phys).m_chest != (Object)null)
				{
					val3 = ((Component)((Rig)phys).m_chest).GetComponent<Rigidbody>();
				}
				if ((Object)(object)phys.leftHand != (Object)null)
				{
					val4 = ((Component)phys.leftHand).GetComponent<Rigidbody>();
				}
				if ((Object)(object)phys.rightHand != (Object)null)
				{
					val5 = ((Component)phys.rightHand).GetComponent<Rigidbody>();
				}
				Transform val6 = null;
				if ((Object)(object)Player.RigManager != (Object)null && (Object)(object)Player.RigManager.ControllerRig != (Object)null)
				{
					val6 = ((Rig)Player.RigManager.ControllerRig).m_head;
				}
				Vector3 val7 = (((Object)(object)val6 != (Object)null) ? val6.forward : Vector3.forward);
				Vector3 val8 = (((Object)(object)val6 != (Object)null) ? val6.right : Vector3.right);
				val7.y = 0f;
				((Vector3)(ref val7)).Normalize();
				val8.y = 0f;
				((Vector3)(ref val8)).Normalize();
				if (((Vector3)(ref val7)).sqrMagnitude < 0.01f)
				{
					val7 = Vector3.forward;
					val8 = Vector3.right;
				}
				Vector3 val9 = val7 * val.y + val8 * val.x;
				Vector3 normalized = ((Vector3)(ref val9)).normalized;
				float friction;
				bool flag = !CheckSupported360(phys, out friction);
				float num = PrefDragStrength.Value * 15f;
				if (flag)
				{
					num *= 0.2f;
				}
				if (flag)
				{
					normalized.y = Mathf.Min(normalized.y, 0f);
				}
				Vector3 val10 = normalized * num;
				float value = PrefDragMaxForce.Value;
				ApplyForceClamped(val2, val10, value);
				if ((Object)(object)val3 != (Object)null && !val3.isKinematic)
				{
					ApplyForceClamped(val3, val10 * 0.8f, value);
				}
				if ((Object)(object)val4 != (Object)null && !val4.isKinematic)
				{
					ApplyForceClamped(val4, val10 * 0.4f, value);
				}
				if ((Object)(object)val5 != (Object)null && !val5.isKinematic)
				{
					ApplyForceClamped(val5, val10 * 0.4f, value);
				}
			}
		}
		catch (Exception ex)
		{
			((MelonBase)this).LoggerInstance.Warning("HandleDrag: " + ex.Message);
		}
	}

	private void ApplyForceClamped(Rigidbody rb, Vector3 force, float maxForce)
	{
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		if (((Vector3)(ref force)).magnitude > maxForce)
		{
			force = ((Vector3)(ref force)).normalized * maxForce;
		}
		rb.AddForce(force, (ForceMode)5);
	}

	private void OnPlayerDamageReceived(RigManager rigManager, float damage)
	{
		if (!PrefEnabled.Value || _isDead || (Object)(object)rigManager == (Object)null || (Object)(object)rigManager.physicsRig == (Object)null)
		{
			return;
		}
		PhysicsRig physicsRig = rigManager.physicsRig;
		if (IsRagdolled(physicsRig))
		{
			if (PrefResetCooldownOnDamage.Value)
			{
				float num = Time.time + PrefRagdollCooldown.Value;
				float num2 = _ragdollStartTime + PrefMaxRagdollTime.Value;
				_unragdollTime = Mathf.Min(num, num2);
			}
			return;
		}
		if (PrefTwoTapDamage.Value)
		{
			if (Time.time - _lastDamageTime < PrefTwoTapTimeWindow.Value)
			{
				_damageHits++;
			}
			else
			{
				_damageHits = 1;
			}
			_lastDamageTime = Time.time;
			if (_damageHits >= 2)
			{
				_damageHits = 0;
				ExecuteRagdoll(rigManager);
				return;
			}
		}
		if (damage >= 30f)
		{
			ExecuteRagdoll(rigManager);
		}
		else
		{
			if (!PrefDownedEnabled.Value)
			{
				return;
			}
			try
			{
				if ((Object)(object)rigManager.health != (Object)null && rigManager.health.curr_Health <= 0f)
				{
					HandleDownedOrDeath(rigManager);
				}
			}
			catch (Exception ex)
			{
				((MelonBase)this).LoggerInstance.Warning("Damage: " + ex.Message);
			}
		}
	}

	private void HandleDownedOrDeath(RigManager rigManager)
	{
		if (_isDowned)
		{
			_isDead = true;
			_deathTime = Time.time;
			try
			{
				if ((Object)(object)rigManager.health != (Object)null)
				{
					rigManager.health.Dying(5f);
				}
				return;
			}
			catch
			{
				return;
			}
		}
		if (_isDead)
		{
			return;
		}
		_isDowned = true;
		_downedStartTime = Time.time;
		try
		{
			TryInvokeLifeSavingDamageDealt(rigManager.health);
			if ((Object)(object)rigManager.health != (Object)null)
			{
				rigManager.health.curr_Health = rigManager.health.max_Health * 0.25f;
			}
		}
		catch
		{
		}
		ExecuteRagdoll(rigManager);
	}

	private void OnPlayerDeath(RigManager rigManager)
	{
		if (!PrefEnabled.Value)
		{
			return;
		}
		_isDowned = false;
		_isDead = true;
		_deathTime = Time.time;
		if (PrefStayRagdolledOnDeath.Value)
		{
			if ((Object)(object)rigManager != (Object)null && (Object)(object)rigManager.physicsRig != (Object)null && !IsRagdolled(rigManager.physicsRig))
			{
				ExecuteRagdoll(rigManager);
			}
			_unragdollTime = float.MaxValue;
		}
		else if ((Object)(object)rigManager != (Object)null)
		{
			UnragdollRig(rigManager);
		}
	}

	private void ExecuteRagdoll(RigManager rig)
	{
		if ((Object)(object)rig == (Object)null)
		{
			return;
		}
		try
		{
			PhysicsRig physicsRig = rig.physicsRig;
			if ((Object)(object)physicsRig == (Object)null)
			{
				return;
			}
			if (PrefDropItems.Value)
			{
				ForceDrop(physicsRig.leftHand);
				ForceDrop(physicsRig.rightHand);
			}
			if (PrefMode.Value == RagdollMode.Limp)
			{
				physicsRig.ShutdownRig();
			}
			physicsRig.RagdollRig();
			if (PrefMode.Value == RagdollMode.ArmControl)
			{
				physicsRig.DisableBallLoco();
				physicsRig.PhysicalLegs();
				if ((Object)(object)physicsRig.legLf != (Object)null)
				{
					physicsRig.legLf.ShutdownLimb();
				}
				if ((Object)(object)physicsRig.legRt != (Object)null)
				{
					physicsRig.legRt.ShutdownLimb();
				}
			}
			_ragdollStartTime = Time.time;
			_nextRagdollTime = Time.time + 1f;
			float num = Time.time + PrefRagdollCooldown.Value;
			float num2 = _ragdollStartTime + PrefMaxRagdollTime.Value;
			_unragdollTime = Mathf.Min(num, num2);
			_fixPending = false;
			_framesSinceUnragdoll = 0;
		}
		catch (Exception ex)
		{
			((MelonBase)this).LoggerInstance.Warning("ExecuteRagdoll: " + ex.Message);
		}
	}

	private void ForceDrop(Hand hand)
	{
		try
		{
			if ((Object)(object)hand == (Object)null || !hand.HasAttachedObject())
			{
				return;
			}
			HandReciever attachedReceiver = hand.AttachedReceiver;
			if (!((Object)(object)attachedReceiver == (Object)null))
			{
				Grip val = ((Il2CppObjectBase)attachedReceiver).TryCast<Grip>();
				if ((Object)(object)val != (Object)null)
				{
					val.ForceDetach(true);
				}
				else
				{
					hand.DetachObject();
				}
			}
		}
		catch
		{
		}
	}

	private void UnragdollRig(RigManager rig)
	{
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: 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_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a9: 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_00d5: 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_00f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_019d: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f1: 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_0239: 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)
		if ((Object)(object)rig == (Object)null)
		{
			return;
		}
		try
		{
			PhysicsRig physicsRig = rig.physicsRig;
			if (!((Object)(object)physicsRig == (Object)null))
			{
				float num = (((Object)(object)rig.avatar != (Object)null && rig.avatar.height > 0.1f) ? rig.avatar.height : 1.8f);
				Vector3 val = (((Object)(object)((Rig)physicsRig).m_pelvis != (Object)null) ? ((Rig)physicsRig).m_pelvis.position : ((Component)physicsRig).transform.position);
				Quaternion val2 = (((Object)(object)((Rig)physicsRig).m_pelvis != (Object)null) ? ((Rig)physicsRig).m_pelvis.rotation : Quaternion.identity);
				Vector3 val3 = val;
				val3 = ((!FindGround(val, num * 1.5f, ((Component)physicsRig).transform.root, out var groundPos)) ? (val - new Vector3(0f, num * 0.45f, 0f)) : groundPos);
				Vector3 wholeBodyVelocity = physicsRig.wholeBodyVelocity;
				float magnitude = ((Vector3)(ref wholeBodyVelocity)).magnitude;
				bool flag = magnitude > PrefFixVelLimit.Value;
				bool flag2 = PrefFixEnabled.Value && (!PrefFixVel.Value || !flag);
				if (flag2)
				{
					ZeroVelocities(physicsRig);
				}
				physicsRig.TurnOnRig();
				physicsRig.UnRagdollRig();
				if (!physicsRig.ballLocoEnabled)
				{
					physicsRig.EnableBallLoco();
				}
				if ((Object)(object)physicsRig.knee != (Object)null && (Object)(object)physicsRig.feet != (Object)null)
				{
					physicsRig.knee.transform.SetPositionAndRotation(val3 + new Vector3(0f, num * 0.25f, 0f), val2);
					physicsRig.feet.transform.SetPositionAndRotation(val3, val2);
				}
				if (flag2 && PrefFixTeleport.Value)
				{
					rig.Teleport(val3, true);
					ZeroVelocities(physicsRig);
				}
				ApplyFloppyArms();
				_nextRagdollTime = Time.time + 1f;
				_unragdollTime = 0f;
				if (flag2)
				{
					_fixPending = true;
					_savedPelvisPos = val3;
					_savedPelvisY = val3.y;
					_framesSinceUnragdoll = 0;
				}
				else
				{
					_fixPending = false;
				}
				_isDowned = false;
				_isDead = false;
			}
		}
		catch (Exception ex)
		{
			((MelonBase)this).LoggerInstance.Warning("UnragdollRig: " + ex.Message);
		}
	}

	private void ApplyFloppyArms()
	{
		try
		{
			if (!((Object)(object)Player.PhysicsRig == (Object)null))
			{
				if ((Object)(object)Player.PhysicsRig.leftHand != (Object)null && (Object)(object)Player.PhysicsRig.leftHand.physHand != (Object)null)
				{
					Player.PhysicsRig.leftHand.physHand._forceMultiplier = (PrefFloppyLeftArm.Value ? 0f : 1f);
				}
				if ((Object)(object)Player.PhysicsRig.rightHand != (Object)null && (Object)(object)Player.PhysicsRig.rightHand.physHand != (Object)null)
				{
					Player.PhysicsRig.rightHand.physHand._forceMultiplier = (PrefFloppyRightArm.Value ? 0f : 1f);
				}
			}
		}
		catch (Exception ex)
		{
			((MelonBase)this).LoggerInstance.Warning("ApplyFloppyArms: " + ex.Message);
		}
	}

	private static void TryInvokeLifeSavingDamageDealt(object health)
	{
		try
		{
			if (health != null)
			{
				MethodInfo method = health.GetType().GetMethod("LifeSavingDamgeDealt", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (method != null)
				{
					method.Invoke(health, null);
				}
			}
		}
		catch
		{
		}
	}

	static UltimateRagdollMod()
	{
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: 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_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//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_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_00c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e4: 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_0103: Unknown result type (might be due to invalid IL or missing references)
		//IL_0108: Unknown result type (might be due to invalid IL or missing references)
		//IL_010b: 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_0127: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: Unknown result type (might be due to invalid IL or missing references)
		//IL_012f: 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_014b: 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_0153: Unknown result type (might be due to invalid IL or missing references)
		//IL_0158: Unknown result type (might be due to invalid IL or missing references)
		//IL_016f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0174: Unknown result type (might be due to invalid IL or missing references)
		//IL_0177: 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)
		Vector3[] obj = new Vector3[14]
		{
			Vector3.down,
			Vector3.up,
			Vector3.left,
			Vector3.right,
			Vector3.f