Decompiled source of Ragdoll Player v1.1.0

Mods/RagdollPlayer.dll

Decompiled 2 years 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 BoneLib.BoneMenu.Elements;
using MelonLoader;
using MelonLoader.Preferences;
using RagdollPlayer;
using SLZ.Rig;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Ragdoll Player")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Ragdoll Player")]
[assembly: AssemblyCopyright("Copyright ©  2022")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("945622a5-4786-4c52-87f3-624bc6542a09")]
[assembly: AssemblyFileVersion("1.1.0")]
[assembly: MelonInfo(typeof(RagdollPlayerMod), "Ragdoll Player", "1.1.0", "Lakatrazz", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.0.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.1.0";

	private const float DoubleTapTimer = 0.32f;

	private static float _lastTimeInput;

	private static bool _ragdollNextButton;

	public static MelonPreferences_Category MelonPrefCategory { get; private set; }

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

	public static MelonPreferences_Entry<bool> MelonPrefKeepArmControl { 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 bool KeepArmControl { get; private set; }

	public static RagdollBinding Binding { get; private set; }

	public static RagdollHand Hand { get; private set; }

	public static MenuCategory BoneMenuCategory { get; private set; }

	public static BoolElement EnabledElement { get; private set; }

	public static BoolElement KeepArmControlElement { get; private set; }

	public static EnumElement<RagdollBinding> BindingElement { get; private set; }

	public static EnumElement<RagdollHand> 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);
		MelonPrefKeepArmControl = MelonPrefCategory.CreateEntry<bool>("KeepArmControl", false, (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;
		KeepArmControl = MelonPrefKeepArmControl.Value;
		Binding = MelonPrefBinding.Value;
		Hand = MelonPrefHand.Value;
	}

	public static void SetupBoneMenu()
	{
		//IL_0005: 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_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		BoneMenuCategory = MenuManager.CreateCategory("Ragdoll Player", Color.green);
		EnabledElement = BoneMenuCategory.CreateBoolElement("Mod Toggle", Color.yellow, IsEnabled, (Action<bool>)OnSetEnabled);
		KeepArmControlElement = BoneMenuCategory.CreateBoolElement("Keep Arm Control", Color.yellow, KeepArmControl, (Action<bool>)OnSetArmControl);
		BindingElement = BoneMenuCategory.CreateEnumElement<RagdollBinding>("Binding", Color.yellow, Binding, (Action<RagdollBinding>)OnSetBinding);
		HandElement = BoneMenuCategory.CreateEnumElement<RagdollHand>("Hand", Color.yellow, Hand, (Action<RagdollHand>)OnSetHand);
	}

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

	public static void OnSetArmControl(bool value)
	{
		KeepArmControl = value;
		MelonPrefKeepArmControl.Value = value;
		MelonPrefCategory.SaveToFile(false);
	}

	public static void OnSetBinding(RagdollBinding binding)
	{
		Binding = binding;
		MelonPrefBinding.Value = binding;
		MelonPrefCategory.SaveToFile(false);
	}

	public static void OnSetHand(RagdollHand hand)
	{
		Hand = hand;
		MelonPrefHand.Value = hand;
		MelonPrefCategory.SaveToFile(false);
	}

	public override void OnPreferencesLoaded()
	{
		IsEnabled = MelonPrefEnabled.Value;
		KeepArmControl = MelonPrefKeepArmControl.Value;
		Binding = MelonPrefBinding.Value;
		Hand = MelonPrefHand.Value;
		((GenericElement<bool>)(object)EnabledElement).SetValue(IsEnabled);
		((GenericElement<bool>)(object)KeepArmControlElement).SetValue(KeepArmControl);
		((GenericElement<RagdollBinding>)(object)BindingElement).SetValue(Binding);
		((GenericElement<RagdollHand>)(object)HandElement).SetValue(Hand);
	}

	public override void OnUpdate()
	{
		if (!IsEnabled)
		{
			return;
		}
		PhysicsRig physicsRig = Player.physicsRig;
		if (!Object.op_Implicit((Object)(object)physicsRig) || Object.op_Implicit((Object)(object)((Rig)physicsRig).manager.activeSeat) || ((Rig)physicsRig).manager.uiRig.popUpMenu.m_IsCursorShown || !GetInput(GetController()))
		{
			return;
		}
		if (physicsRig.torso.spineInternalMult != 0f)
		{
			physicsRig.RagdollRig();
			if (KeepArmControl)
			{
				physicsRig.leftHand.physHand.forceMultiplier = 1f;
				physicsRig.rightHand.physHand.forceMultiplier = 1f;
			}
		}
		else
		{
			physicsRig.UnRagdollRig();
		}
	}

	private static BaseController GetController()
	{
		RagdollHand hand = Hand;
		if (hand == RagdollHand.RIGHT_HAND || hand != RagdollHand.LEFT_HAND)
		{
			return Player.rightController;
		}
		return Player.leftController;
	}

	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;
	}
}