Decompiled source of AvatarRagdollSpawner9000 v1.0.0

AvatarRagdollSpawner.dll

Decompiled 10 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using AvatarRagdollSpawner;
using BoneLib;
using BoneLib.BoneMenu;
using Il2CppSLZ.Marrow;
using Il2CppSLZ.VRMK;
using MelonLoader;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("AvatarRagdollSpawner")]
[assembly: AssemblyDescription("Bonelab Avatar Ragdoll Spawner Mod")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Dillo")]
[assembly: AssemblyProduct("AvatarRagdollSpawner")]
[assembly: AssemblyCopyright("Copyright © 2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: MelonInfo(typeof(Main), "AvatarRagdollSpawner", "1.0.0", "Dillo", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: TargetFramework(".NETCoreApp,Version=v8.0", FrameworkDisplayName = ".NET 8.0")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace AvatarRagdollSpawner;

public static class BuildInfo
{
	public const string Name = "AvatarRagdollSpawner";

	public const string Author = "Dillo";

	public const string Version = "1.0.0";
}
public enum HotkeyBind
{
	RightStickClick,
	LeftStickClick,
	SecondaryButton_B_Y,
	PrimaryButton_A_X,
	Disabled
}
public static class BoneMenuManager
{
	public static HotkeyBind CurrentHotkey;

	public static void InitializeMenu()
	{
		//IL_000a: 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)
		//IL_004c: 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_00c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_010a: Unknown result type (might be due to invalid IL or missing references)
		//IL_014e: 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)
		try
		{
			Page obj = Page.Root.CreatePage("Avatar Ragdoll Spawner", Color.cyan, 0, true);
			obj.CreateFunction("Spawn Avatar Ragdoll", Color.yellow, (Action)delegate
			{
				RagdollSpawner.SpawnRagdoll();
			});
			obj.CreateEnum("Hotkey Trigger", Color.white, (Enum)HotkeyBind.RightStickClick, (Action<Enum>)delegate(Enum selected)
			{
				CurrentHotkey = (HotkeyBind)(object)selected;
				MelonLogger.Msg($"[AvatarRagdollSpawner] Hotkey changed to: {selected}");
			});
			obj.CreateFloat("Spawn Distance (m)", Color.white, 1.2f, 0.2f, 0.5f, 3.5f, (Action<float>)delegate(float dist)
			{
				RagdollSpawner.SpawnDistance = dist;
			});
			obj.CreateFloat("Push Force", Color.white, 2f, 0.5f, 0f, 10f, (Action<float>)delegate(float force)
			{
				RagdollSpawner.PushForce = force;
			});
			obj.CreateFloat("Ragdoll Stiffness", Color.white, 1f, 0.25f, 0.1f, 4f, (Action<float>)delegate(float stiff)
			{
				RagdollSpawner.Stiffness = stiff;
				RagdollSpawner.RefreshStiffness();
			});
			obj.CreateInt("Max Clones (Budget)", Color.white, 10, 1, 1, 20, (Action<int>)delegate(int max)
			{
				RagdollSpawner.MaxClones = max;
			});
			obj.CreateFunction("Clear All Clones", Color.red, (Action)delegate
			{
				RagdollSpawner.ClearAllClones();
			});
			MelonLogger.Msg("[AvatarRagdollSpawner] BoneMenu setup complete.");
		}
		catch (Exception ex)
		{
			MelonLogger.Error("[AvatarRagdollSpawner] BoneMenu setup error: " + ex.Message);
		}
	}
}
public class Main : MelonMod
{
	private bool _wasHotkeyPressed;

	private float _lastSpawnTime;

	private const float COOLDOWN_SECONDS = 0.35f;

	public override void OnInitializeMelon()
	{
		MelonLogger.Msg("[AvatarRagdollSpawner] Initializing Avatar Ragdoll Spawner Mod v1.0.0...");
		BoneMenuManager.InitializeMenu();
	}

	public override void OnUpdate()
	{
		if (BoneMenuManager.CurrentHotkey != HotkeyBind.Disabled)
		{
			bool flag = CheckHotkeyInput(BoneMenuManager.CurrentHotkey);
			if (flag && !_wasHotkeyPressed && Time.time - _lastSpawnTime >= 0.35f)
			{
				_lastSpawnTime = Time.time;
				RagdollSpawner.SpawnRagdoll();
			}
			_wasHotkeyPressed = flag;
		}
	}

	private bool CheckHotkeyInput(HotkeyBind bind)
	{
		try
		{
			BaseController rightController = Player.RightController;
			BaseController leftController = Player.LeftController;
			switch (bind)
			{
			case HotkeyBind.RightStickClick:
				if ((Object)(object)rightController != (Object)null && rightController.GetThumbStickDown())
				{
					return true;
				}
				break;
			case HotkeyBind.LeftStickClick:
				if ((Object)(object)leftController != (Object)null && leftController.GetThumbStickDown())
				{
					return true;
				}
				break;
			case HotkeyBind.SecondaryButton_B_Y:
				if ((Object)(object)rightController != (Object)null && rightController.GetSecondaryInteractionButton())
				{
					return true;
				}
				if ((Object)(object)leftController != (Object)null && leftController.GetSecondaryInteractionButton())
				{
					return true;
				}
				break;
			case HotkeyBind.PrimaryButton_A_X:
				if ((Object)(object)rightController != (Object)null && rightController.GetAButton())
				{
					return true;
				}
				if ((Object)(object)leftController != (Object)null && leftController.GetAButton())
				{
					return true;
				}
				break;
			}
		}
		catch
		{
		}
		return false;
	}
}
public static class RagdollSpawner
{
	private struct PartDef
	{
		public HumanBodyBones Bone;

		public HumanBodyBones Child;

		public HumanBodyBones Parent;

		public float Radius;

		public float Mass;

		public float MinLength;
	}

	public static float SpawnDistance = 1.2f;

	public static float PushForce = 2f;

	public static int MaxClones = 10;

	public static float Stiffness = 1f;

	private static readonly List<GameObject> _activeClones = new List<GameObject>();

	private static readonly PartDef[] Parts = new PartDef[16]
	{
		new PartDef
		{
			Bone = (HumanBodyBones)0,
			Child = (HumanBodyBones)7,
			Parent = (HumanBodyBones)55,
			Radius = 0.1f,
			Mass = 12f,
			MinLength = 0.18f
		},
		new PartDef
		{
			Bone = (HumanBodyBones)7,
			Child = (HumanBodyBones)8,
			Parent = (HumanBodyBones)0,
			Radius = 0.09f,
			Mass = 8f,
			MinLength = 0.14f
		},
		new PartDef
		{
			Bone = (HumanBodyBones)8,
			Child = (HumanBodyBones)9,
			Parent = (HumanBodyBones)7,
			Radius = 0.11f,
			Mass = 11f,
			MinLength = 0.18f
		},
		new PartDef
		{
			Bone = (HumanBodyBones)10,
			Child = (HumanBodyBones)55,
			Parent = (HumanBodyBones)8,
			Radius = 0.11f,
			Mass = 5f,
			MinLength = 0.24f
		},
		new PartDef
		{
			Bone = (HumanBodyBones)13,
			Child = (HumanBodyBones)15,
			Parent = (HumanBodyBones)8,
			Radius = 0.05f,
			Mass = 2f,
			MinLength = 0.2f
		},
		new PartDef
		{
			Bone = (HumanBodyBones)14,
			Child = (HumanBodyBones)16,
			Parent = (HumanBodyBones)8,
			Radius = 0.05f,
			Mass = 2f,
			MinLength = 0.2f
		},
		new PartDef
		{
			Bone = (HumanBodyBones)15,
			Child = (HumanBodyBones)17,
			Parent = (HumanBodyBones)13,
			Radius = 0.045f,
			Mass = 1.4f,
			MinLength = 0.2f
		},
		new PartDef
		{
			Bone = (HumanBodyBones)16,
			Child = (HumanBodyBones)18,
			Parent = (HumanBodyBones)14,
			Radius = 0.045f,
			Mass = 1.4f,
			MinLength = 0.2f
		},
		new PartDef
		{
			Bone = (HumanBodyBones)17,
			Child = (HumanBodyBones)55,
			Parent = (HumanBodyBones)15,
			Radius = 0.04f,
			Mass = 0.6f,
			MinLength = 0.16f
		},
		new PartDef
		{
			Bone = (HumanBodyBones)18,
			Child = (HumanBodyBones)55,
			Parent = (HumanBodyBones)16,
			Radius = 0.04f,
			Mass = 0.6f,
			MinLength = 0.16f
		},
		new PartDef
		{
			Bone = (HumanBodyBones)1,
			Child = (HumanBodyBones)3,
			Parent = (HumanBodyBones)0,
			Radius = 0.07f,
			Mass = 7f,
			MinLength = 0.28f
		},
		new PartDef
		{
			Bone = (HumanBodyBones)2,
			Child = (HumanBodyBones)4,
			Parent = (HumanBodyBones)0,
			Radius = 0.07f,
			Mass = 7f,
			MinLength = 0.28f
		},
		new PartDef
		{
			Bone = (HumanBodyBones)3,
			Child = (HumanBodyBones)5,
			Parent = (HumanBodyBones)1,
			Radius = 0.06f,
			Mass = 4f,
			MinLength = 0.28f
		},
		new PartDef
		{
			Bone = (HumanBodyBones)4,
			Child = (HumanBodyBones)6,
			Parent = (HumanBodyBones)2,
			Radius = 0.06f,
			Mass = 4f,
			MinLength = 0.28f
		},
		new PartDef
		{
			Bone = (HumanBodyBones)5,
			Child = (HumanBodyBones)19,
			Parent = (HumanBodyBones)3,
			Radius = 0.05f,
			Mass = 1.2f,
			MinLength = 0.2f
		},
		new PartDef
		{
			Bone = (HumanBodyBones)6,
			Child = (HumanBodyBones)20,
			Parent = (HumanBodyBones)4,
			Radius = 0.05f,
			Mass = 1.2f,
			MinLength = 0.2f
		}
	};

	public static void SpawnRagdoll()
	{
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0134: Unknown result type (might be due to invalid IL or missing references)
		//IL_0136: Unknown result type (might be due to invalid IL or missing references)
		//IL_013b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0145: Unknown result type (might be due to invalid IL or missing references)
		//IL_014a: Unknown result type (might be due to invalid IL or missing references)
		//IL_016c: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			RigManager rigManager = Player.RigManager;
			if ((Object)(object)rigManager == (Object)null)
			{
				MelonLogger.Warning("[AvatarRagdollSpawner] RigManager is null.");
				return;
			}
			Avatar avatar = rigManager.avatar;
			if ((Object)(object)avatar == (Object)null)
			{
				MelonLogger.Warning("[AvatarRagdollSpawner] Player avatar is null.");
				return;
			}
			Animator componentInChildren = ((Component)avatar).GetComponentInChildren<Animator>();
			if ((Object)(object)componentInChildren == (Object)null || !componentInChildren.isHuman)
			{
				MelonLogger.Warning("[AvatarRagdollSpawner] Avatar has no humanoid Animator - cannot build ragdoll.");
				return;
			}
			Vector3 playerBasePosition = GetPlayerBasePosition(rigManager);
			Quaternion playerYawRotation = GetPlayerYawRotation(rigManager);
			Vector3 val = playerBasePosition + playerYawRotation * Vector3.forward * SpawnDistance;
			val.y += 0.1f;
			GameObject val2 = Object.Instantiate<GameObject>(((Component)avatar).gameObject);
			((Object)val2).name = $"AvatarRagdoll_{Time.time:F1}";
			val2.transform.position = val;
			val2.transform.rotation = playerYawRotation;
			StripNonVisualComponents(val2);
			if (!BuildRagdoll(val2, componentInChildren, out List<Rigidbody> bodies))
			{
				MelonLogger.Error("[AvatarRagdollSpawner] Ragdoll build failed - missing key bones.");
				Object.Destroy((Object)(object)val2);
				return;
			}
			if (PushForce > 0.01f)
			{
				Vector3 velocity = playerYawRotation * Vector3.forward * PushForce;
				foreach (Rigidbody item in bodies)
				{
					if ((Object)(object)item != (Object)null)
					{
						item.velocity = velocity;
					}
				}
			}
			val2.SetActive(true);
			_activeClones.Add(val2);
			MelonLogger.Msg($"[AvatarRagdollSpawner] Spawned ragdoll at {val} ({bodies.Count} parts, Active: {_activeClones.Count})");
			EnforceMaxCloneLimit();
		}
		catch (Exception ex)
		{
			MelonLogger.Error("[AvatarRagdollSpawner] Spawn error: " + ex.Message + "\n" + ex.StackTrace);
		}
	}

	private static void StripNonVisualComponents(GameObject root)
	{
		foreach (Rigidbody componentsInChild in root.GetComponentsInChildren<Rigidbody>(true))
		{
			try
			{
				Object.Destroy((Object)(object)componentsInChild);
			}
			catch
			{
			}
		}
		foreach (Collider componentsInChild2 in root.GetComponentsInChildren<Collider>(true))
		{
			try
			{
				Object.Destroy((Object)(object)componentsInChild2);
			}
			catch
			{
			}
		}
		foreach (Animator componentsInChild3 in root.GetComponentsInChildren<Animator>(true))
		{
			try
			{
				Object.Destroy((Object)(object)componentsInChild3);
			}
			catch
			{
			}
		}
		foreach (MonoBehaviour componentsInChild4 in root.GetComponentsInChildren<MonoBehaviour>(true))
		{
			try
			{
				if ((Object)(object)componentsInChild4 != (Object)null)
				{
					Object.Destroy((Object)(object)componentsInChild4);
				}
			}
			catch
			{
			}
		}
		foreach (LODGroup componentsInChild5 in root.GetComponentsInChildren<LODGroup>(true))
		{
			try
			{
				Object.Destroy((Object)(object)componentsInChild5);
			}
			catch
			{
			}
		}
	}

	private static bool BuildRagdoll(GameObject root, Animator sourceAnimator, out List<Rigidbody> bodies)
	{
		//IL_02b3: 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_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Invalid comparison between Unknown and I4
		//IL_0132: 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_0155: Unknown result type (might be due to invalid IL or missing references)
		//IL_015c: Invalid comparison between Unknown and I4
		//IL_0313: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_021b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0220: Unknown result type (might be due to invalid IL or missing references)
		//IL_0226: Unknown result type (might be due to invalid IL or missing references)
		//IL_022b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0161: Unknown result type (might be due to invalid IL or missing references)
		//IL_017a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0180: Invalid comparison between Unknown and I4
		//IL_0333: Unknown result type (might be due to invalid IL or missing references)
		//IL_033a: Invalid comparison between Unknown and I4
		//IL_0342: Unknown result type (might be due to invalid IL or missing references)
		//IL_0364: Unknown result type (might be due to invalid IL or missing references)
		//IL_0380: Unknown result type (might be due to invalid IL or missing references)
		//IL_0385: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a3: 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_03ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_03cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d5: Unknown result type (might be due to invalid IL or missing references)
		bodies = new List<Rigidbody>();
		Dictionary<HumanBodyBones, Transform> dictionary = new Dictionary<HumanBodyBones, Transform>();
		foreach (HumanBodyBones value9 in Enum.GetValues(typeof(HumanBodyBones)))
		{
			if ((int)value9 == 55)
			{
				break;
			}
			try
			{
				Transform boneTransform = sourceAnimator.GetBoneTransform(value9);
				if (!((Object)(object)boneTransform == (Object)null))
				{
					Transform val2 = FindDeepChild(root.transform, ((Object)boneTransform).name);
					if ((Object)(object)val2 != (Object)null)
					{
						dictionary[value9] = val2;
					}
				}
			}
			catch
			{
			}
		}
		if (!dictionary.ContainsKey((HumanBodyBones)0))
		{
			return false;
		}
		float num = 1f;
		if (dictionary.TryGetValue((HumanBodyBones)10, out var value) && dictionary.TryGetValue((HumanBodyBones)7, out var _))
		{
			float num2 = Vector3.Distance(dictionary[(HumanBodyBones)7].position, value.position);
			if (num2 > 0.01f)
			{
				num = Mathf.Clamp(num2 / 0.5f, 0.5f, 2.5f);
			}
		}
		Dictionary<HumanBodyBones, Rigidbody> dictionary2 = new Dictionary<HumanBodyBones, Rigidbody>();
		Dictionary<HumanBodyBones, Vector3> dictionary3 = new Dictionary<HumanBodyBones, Vector3>();
		List<Collider> list = new List<Collider>();
		PartDef[] parts = Parts;
		for (int i = 0; i < parts.Length; i++)
		{
			PartDef partDef = parts[i];
			if (!dictionary.TryGetValue(partDef.Bone, out var value3) || (Object)(object)value3 == (Object)null)
			{
				continue;
			}
			Transform value4 = null;
			if ((int)partDef.Child != 55)
			{
				dictionary.TryGetValue(partDef.Child, out value4);
				if ((Object)(object)value4 == (Object)null && (int)partDef.Bone == 8)
				{
					dictionary.TryGetValue((HumanBodyBones)10, out value4);
				}
			}
			Rigidbody val3 = ((Component)value3).gameObject.AddComponent<Rigidbody>();
			val3.mass = partDef.Mass;
			val3.drag = 0.3f;
			val3.angularDrag = 2.5f;
			val3.maxAngularVelocity = 5f;
			val3.interpolation = (RigidbodyInterpolation)1;
			val3.collisionDetectionMode = (CollisionDetectionMode)3;
			dictionary2[partDef.Bone] = val3;
			bodies.Add(val3);
			CapsuleCollider val4 = ((Component)value3).gameObject.AddComponent<CapsuleCollider>();
			Vector3 value5 = ConfigureCapsule(val4, value3, value4, partDef.Radius * num, partDef.MinLength * num);
			dictionary3[partDef.Bone] = value5;
			((Component)value3).gameObject.layer = 32768;
			list.Add((Collider)(object)val4);
			try
			{
				SphereCollider obj2 = ((Component)value3).gameObject.AddComponent<SphereCollider>();
				((Collider)obj2).isTrigger = true;
				obj2.radius = Mathf.Max(0.12f * num, partDef.Radius * num + 0.05f);
				((Grip)((Component)value3).gameObject.AddComponent<GenericGrip>()).gripDistance = 0.3f;
			}
			catch (Exception ex)
			{
				MelonLogger.Warning($"[AvatarRagdollSpawner] Grip setup failed on {partDef.Bone}: {ex.Message}");
			}
		}
		parts = Parts;
		for (int i = 0; i < parts.Length; i++)
		{
			PartDef partDef2 = parts[i];
			if (dictionary2.TryGetValue(partDef2.Bone, out var value6) && !((Object)(object)value6 == (Object)null) && (int)partDef2.Parent != 55 && dictionary2.TryGetValue(partDef2.Parent, out var value7) && !((Object)(object)value7 == (Object)null))
			{
				if (!dictionary3.TryGetValue(partDef2.Bone, out var value8) || ((Vector3)(ref value8)).sqrMagnitude < 0.001f)
				{
					value8 = Vector3.up;
				}
				CharacterJoint obj3 = ((Component)value6).gameObject.AddComponent<CharacterJoint>();
				((Joint)obj3).connectedBody = value7;
				((Joint)obj3).enablePreprocessing = false;
				((Joint)obj3).axis = value8;
				Vector3 val5 = Vector3.Cross(value8, (Mathf.Abs(value8.y) < 0.9f) ? Vector3.up : Vector3.right);
				obj3.swingAxis = ((Vector3)(ref val5)).normalized;
				ApplyStiffness(obj3);
				obj3.enableProjection = true;
				obj3.projectionDistance = 0.03f;
				obj3.projectionAngle = 15f;
			}
		}
		for (int j = 0; j < list.Count; j++)
		{
			for (int k = j + 1; k < list.Count; k++)
			{
				Physics.IgnoreCollision(list[j], list[k], true);
			}
		}
		return true;
	}

	private static void ApplyStiffness(CharacterJoint joint)
	{
		//IL_0013: 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_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		float num = Mathf.Max(0.05f, Stiffness);
		SoftJointLimit val = default(SoftJointLimit);
		((SoftJointLimit)(ref val)).limit = -5f * num;
		joint.lowTwistLimit = val;
		val = default(SoftJointLimit);
		((SoftJointLimit)(ref val)).limit = 10f * num;
		joint.highTwistLimit = val;
		val = default(SoftJointLimit);
		((SoftJointLimit)(ref val)).limit = 15f * num;
		joint.swing1Limit = val;
		val = default(SoftJointLimit);
		((SoftJointLimit)(ref val)).limit = 15f * num;
		joint.swing2Limit = val;
		SoftJointLimitSpring val2 = default(SoftJointLimitSpring);
		((SoftJointLimitSpring)(ref val2)).spring = 120f * num * num;
		((SoftJointLimitSpring)(ref val2)).damper = 25f * num;
		joint.twistLimitSpring = val2;
		val2 = default(SoftJointLimitSpring);
		((SoftJointLimitSpring)(ref val2)).spring = 120f * num * num;
		((SoftJointLimitSpring)(ref val2)).damper = 25f * num;
		joint.swingLimitSpring = val2;
	}

	public static void RefreshStiffness()
	{
		int num = 0;
		foreach (GameObject activeClone in _activeClones)
		{
			if ((Object)(object)activeClone == (Object)null)
			{
				continue;
			}
			foreach (CharacterJoint componentsInChild in activeClone.GetComponentsInChildren<CharacterJoint>(true))
			{
				try
				{
					ApplyStiffness(componentsInChild);
					num++;
				}
				catch
				{
				}
			}
		}
		MelonLogger.Msg($"[AvatarRagdollSpawner] Stiffness {Stiffness:F2} applied to {num} joints.");
	}

	private static Vector3 ConfigureCapsule(CapsuleCollider cap, Transform bone, Transform child, float radius, float minLength)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		//IL_013b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0145: Unknown result type (might be due to invalid IL or missing references)
		//IL_0112: 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_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		cap.radius = radius;
		Vector3 up = Vector3.up;
		float num = minLength;
		if ((Object)(object)child != (Object)null)
		{
			Vector3 val = child.position - bone.position;
			Vector3 val2 = bone.InverseTransformDirection(val);
			num = Mathf.Max(((Vector3)(ref val2)).magnitude, minLength);
			float num2 = Math.Abs(val2.x);
			float num3 = Math.Abs(val2.y);
			float num4 = Math.Abs(val2.z);
			if (num2 >= num3 && num2 >= num4)
			{
				cap.direction = 0;
				((Vector3)(ref up))..ctor(Mathf.Sign(val2.x), 0f, 0f);
			}
			else if (num3 >= num4)
			{
				cap.direction = 1;
				((Vector3)(ref up))..ctor(0f, Mathf.Sign(val2.y), 0f);
			}
			else
			{
				cap.direction = 2;
				((Vector3)(ref up))..ctor(0f, 0f, Mathf.Sign(val2.z));
			}
		}
		else if (((Object)bone).name.ToLower().Contains("head"))
		{
			cap.direction = 1;
			up = Vector3.up;
			num = minLength;
		}
		float num5 = num * 0.5f;
		cap.height = Mathf.Max(num + radius, radius * 2f);
		cap.center = up * num5;
		return up;
	}

	private static Transform FindDeepChild(Transform parent, string name)
	{
		if (((Object)parent).name == name)
		{
			return parent;
		}
		for (int i = 0; i < parent.childCount; i++)
		{
			Transform val = FindDeepChild(parent.GetChild(i), name);
			if ((Object)(object)val != (Object)null)
			{
				return val;
			}
		}
		return null;
	}

	public static void ClearAllClones()
	{
		int num = 0;
		for (int num2 = _activeClones.Count - 1; num2 >= 0; num2--)
		{
			if ((Object)(object)_activeClones[num2] != (Object)null)
			{
				Object.Destroy((Object)(object)_activeClones[num2]);
				num++;
			}
		}
		_activeClones.Clear();
		MelonLogger.Msg($"[AvatarRagdollSpawner] Cleared {num} ragdoll clones.");
	}

	private static void EnforceMaxCloneLimit()
	{
		_activeClones.RemoveAll((GameObject go) => (Object)(object)go == (Object)null);
		while (_activeClones.Count > MaxClones && _activeClones.Count > 0)
		{
			GameObject val = _activeClones[0];
			_activeClones.RemoveAt(0);
			if ((Object)(object)val != (Object)null)
			{
				Object.Destroy((Object)(object)val);
			}
		}
	}

	private static Vector3 GetPlayerBasePosition(RigManager rig)
	{
		//IL_0038: 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)
		if ((Object)(object)rig.physicsRig != (Object)null && (Object)(object)((Rig)rig.physicsRig).m_pelvis != (Object)null)
		{
			return ((Rig)rig.physicsRig).m_pelvis.position;
		}
		return ((Component)rig).transform.position;
	}

	private static Quaternion GetPlayerYawRotation(RigManager rig)
	{
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: 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_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_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)rig.physicsRig != (Object)null && (Object)(object)((Rig)rig.physicsRig).m_pelvis != (Object)null)
		{
			Quaternion rotation = ((Rig)rig.physicsRig).m_pelvis.rotation;
			Vector3 eulerAngles = ((Quaternion)(ref rotation)).eulerAngles;
			return Quaternion.Euler(0f, eulerAngles.y, 0f);
		}
		Vector3 eulerAngles2 = ((Component)rig).transform.eulerAngles;
		return Quaternion.Euler(0f, eulerAngles2.y, 0f);
	}
}