Decompiled source of Ragdoll Player v1.2.1

Mods/RagdollPlayer.dll

Decompiled 3 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BoneLib;
using BoneLib.BoneMenu;
using Il2CppSLZ.Bonelab;
using Il2CppSLZ.Marrow;
using MelonLoader;
using MelonLoader.Preferences;
using RagdollPlayer;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("945622a5-4786-4c52-87f3-624bc6542a09")]
[assembly: MelonInfo(typeof(RagdollPlayerMod), "Ragdoll Player", "1.2.1", "Lakatrazz", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: AssemblyDescription("A BONELAB mod that allows you to ragdoll your player with an input.")]
[assembly: AssemblyTitle("Ragdoll Player")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.1.0")]
[module: UnverifiableCode]
namespace RagdollPlayer;

public class RagdollPlayerMod : MelonMod
{
	public enum RagdollBinding
	{
		THUMBSTICK_PRESS,
		DOUBLE_TAP_B
	}

	public enum RagdollHand
	{
		RIGHT_HAND,
		LEFT_HAND
	}

	public const string Version = "1.2.1";

	private const float DoubleTapTimer = 0.32f;

	private static float _lastTimeInput;

	private static bool _ragdollNextButton;

	private static bool _preferencesSetup;

	public static MelonPreferences_Category MelonPrefCategory { get; private set; }

	public static MelonPreferences_Entry<bool> MelonPrefEnabled { get; private set; }

	public static MelonPreferences_Entry<RagdollBinding> MelonPrefBinding { get; private set; }

	public static MelonPreferences_Entry<RagdollHand> MelonPrefHand { get; private set; }

	public static bool IsEnabled { get; private set; }

	public static RagdollBinding Binding { get; private set; }

	public static RagdollHand Hand { get; private set; }

	public static Page MainPage { get; private set; }

	public static BoolElement EnabledElement { get; private set; }

	public static EnumElement BindingElement { get; private set; }

	public static EnumElement HandElement { get; private set; }

	public override void OnInitializeMelon()
	{
		SetupMelonPrefs();
		SetupBoneMenu();
	}

	public static void SetupMelonPrefs()
	{
		MelonPrefCategory = MelonPreferences.CreateCategory("Ragdoll Player");
		MelonPrefEnabled = MelonPrefCategory.CreateEntry<bool>("IsEnabled", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		MelonPrefBinding = MelonPrefCategory.CreateEntry<RagdollBinding>("Binding", RagdollBinding.THUMBSTICK_PRESS, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		MelonPrefHand = MelonPrefCategory.CreateEntry<RagdollHand>("Hand", RagdollHand.RIGHT_HAND, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		IsEnabled = MelonPrefEnabled.Value;
		Binding = MelonPrefBinding.Value;
		Hand = MelonPrefHand.Value;
		_preferencesSetup = true;
	}

	public static void SetupBoneMenu()
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		MainPage = Page.Root.CreatePage("Ragdoll Player", Color.green, 0, true);
		EnabledElement = MainPage.CreateBool("Mod Toggle", Color.yellow, IsEnabled, (Action<bool>)OnSetEnabled);
		BindingElement = MainPage.CreateEnum("Binding", Color.yellow, (Enum)Binding, (Action<Enum>)OnSetBinding);
		HandElement = MainPage.CreateEnum("Hand", Color.yellow, (Enum)Hand, (Action<Enum>)OnSetHand);
	}

	public static void OnSetEnabled(bool value)
	{
		IsEnabled = value;
		MelonPrefEnabled.Value = value;
		MelonPrefCategory.SaveToFile(false);
	}

	public static void OnSetBinding(Enum value)
	{
		RagdollBinding value2 = (Binding = (RagdollBinding)(object)value);
		MelonPrefBinding.Value = value2;
		MelonPrefCategory.SaveToFile(false);
	}

	public static void OnSetHand(Enum value)
	{
		RagdollHand value2 = (Hand = (RagdollHand)(object)value);
		MelonPrefHand.Value = value2;
		MelonPrefCategory.SaveToFile(false);
	}

	public override void OnPreferencesLoaded()
	{
		if (_preferencesSetup)
		{
			IsEnabled = MelonPrefEnabled.Value;
			Binding = MelonPrefBinding.Value;
			Hand = MelonPrefHand.Value;
			EnabledElement.Value = IsEnabled;
			BindingElement.Value = Binding;
			HandElement.Value = Hand;
		}
	}

	public override void OnUpdate()
	{
		if (!IsEnabled)
		{
			return;
		}
		RigManager rigManager = Player.RigManager;
		if (Object.op_Implicit((Object)(object)rigManager) && !Object.op_Implicit((Object)(object)rigManager.activeSeat) && !UIRig.Instance.popUpMenu.m_IsCursorShown && GetInput(GetController()))
		{
			if (!Player.PhysicsRig.torso.shutdown)
			{
				RagdollRig(rigManager);
			}
			else
			{
				UnragdollRig(rigManager);
			}
		}
	}

	public static void RagdollRig(RigManager rig)
	{
		PhysicsRig physicsRig = rig.physicsRig;
		physicsRig.ShutdownRig();
		physicsRig.RagdollRig();
	}

	public static void UnragdollRig(RigManager rig)
	{
		//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_003d: 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_0045: 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_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		PhysicsRig physicsRig = rig.physicsRig;
		Transform transform = physicsRig.feet.transform;
		Transform transform2 = physicsRig.knee.transform;
		Transform transform3 = ((Component)((Rig)physicsRig).m_pelvis).transform;
		physicsRig.TurnOnRig();
		physicsRig.UnRagdollRig();
		Vector3 position = transform3.position;
		Quaternion rotation = transform3.rotation;
		transform2.SetPositionAndRotation(position, rotation);
		transform.SetPositionAndRotation(position, rotation);
	}

	private static BaseController GetController()
	{
		if (Hand == RagdollHand.LEFT_HAND)
		{
			return Player.LeftController;
		}
		return Player.RightController;
	}

	private static bool GetInput(BaseController controller)
	{
		RagdollBinding binding = Binding;
		if (binding == RagdollBinding.THUMBSTICK_PRESS || binding != RagdollBinding.DOUBLE_TAP_B)
		{
			_lastTimeInput = 0f;
			_ragdollNextButton = false;
			return controller.GetThumbStickDown();
		}
		bool bButtonDown = controller.GetBButtonDown();
		float realtimeSinceStartup = Time.realtimeSinceStartup;
		if (bButtonDown && _ragdollNextButton)
		{
			if (realtimeSinceStartup - _lastTimeInput <= 0.32f)
			{
				return true;
			}
			_ragdollNextButton = false;
			_lastTimeInput = 0f;
		}
		else if (bButtonDown)
		{
			_lastTimeInput = realtimeSinceStartup;
			_ragdollNextButton = true;
		}
		else if (realtimeSinceStartup - _lastTimeInput > 0.32f)
		{
			_ragdollNextButton = false;
			_lastTimeInput = 0f;
		}
		return false;
	}
}