Mods\FlipMod.dll

Decompiled 15 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BoneLib;
using BoneLib.BoneMenu;
using Flip;
using Il2CppSLZ.Marrow;
using MelonLoader;
using MelonLoader.Preferences;
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(FlipMod), "Flip", "1.0.0", "Spoon1606", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: MelonOptionalDependencies(new string[] { "RagdollPlayer" })]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyVersion("0.0.0.0")]
namespace Flip;

public class FlipMod : MelonMod
{
	private static MelonPreferences_Category _prefCategory;

	private static MelonPreferences_Entry<bool> _prefEnabled;

	private static MelonPreferences_Entry<int> _prefStrength;

	private static bool _enabled = true;

	private static int _strength = 6;

	private static Page _mainPage;

	private static BoolElement _enabledElement;

	private static IntElement _strengthElement;

	private const float Deadzone = 0.3f;

	private const float StrengthMultiplier = 100f;

	public override void OnInitializeMelon()
	{
		SetupPreferences();
		SetupBoneMenu();
		MelonLogger.Msg("Flip by Spoon1606 loaded! Only works when Ragdoll Player mod is active. Move left thumbstick forward/back while ragdolled.");
	}

	private void SetupPreferences()
	{
		_prefCategory = MelonPreferences.CreateCategory("Flip");
		_prefEnabled = _prefCategory.CreateEntry<bool>("IsEnabled", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		_prefStrength = _prefCategory.CreateEntry<int>("Strength", 6, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		_enabled = _prefEnabled.Value;
		_strength = _prefStrength.Value;
	}

	private void SetupBoneMenu()
	{
		//IL_001a: 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_005f: Unknown result type (might be due to invalid IL or missing references)
		_mainPage = Page.Root.CreatePage("Flip", new Color(0f, 0.8f, 1f), 0, true);
		_enabledElement = _mainPage.CreateBool("Enabled", Color.yellow, _enabled, (Action<bool>)OnSetEnabled);
		_strengthElement = _mainPage.CreateInt("Strength", Color.white, _strength, 1, 1, 50, (Action<int>)OnSetStrength);
	}

	private void OnSetEnabled(bool value)
	{
		_enabled = value;
		_prefEnabled.Value = value;
		_prefCategory.SaveToFile(false);
	}

	private void OnSetStrength(int value)
	{
		_strength = value;
		_prefStrength.Value = value;
		_prefCategory.SaveToFile(false);
	}

	private bool IsRagdollActive()
	{
		PhysicsRig physicsRig = Player.PhysicsRig;
		if ((Object)(object)physicsRig == (Object)null)
		{
			return false;
		}
		bool flag = (Object)(object)physicsRig.torso != (Object)null && physicsRig.torso.shutdown;
		bool flag2 = !physicsRig.ballLocoEnabled;
		return flag || flag2;
	}

	public override void OnUpdate()
	{
		//IL_005c: 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_0062: Unknown result type (might be due to invalid IL or missing references)
		if (!_enabled || (Object)(object)Player.RigManager == (Object)null || (Object)(object)Player.PhysicsRig == (Object)null || !IsRagdollActive())
		{
			return;
		}
		BaseController leftController = Player.LeftController;
		if (!((Object)(object)leftController == (Object)null))
		{
			Vector2 thumbStickAxis = leftController.GetThumbStickAxis();
			float y = thumbStickAxis.y;
			if (!(Mathf.Abs(y) < 0.3f))
			{
				PerformFlip(y);
			}
		}
	}

	private void PerformFlip(float direction)
	{
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		PhysicsRig physicsRig = Player.PhysicsRig;
		if ((Object)(object)physicsRig == (Object)null)
		{
			return;
		}
		Transform pelvis = ((Rig)physicsRig).m_pelvis;
		if (!((Object)(object)pelvis == (Object)null))
		{
			Rigidbody component = ((Component)pelvis).GetComponent<Rigidbody>();
			if (!((Object)(object)component == (Object)null))
			{
				float num = direction * (float)_strength * 100f;
				component.angularVelocity = ((Component)pelvis).transform.right * num;
			}
		}
	}

	public override void OnPreferencesLoaded()
	{
		_enabled = _prefEnabled.Value;
		_strength = _prefStrength.Value;
		if (_enabledElement != null)
		{
			_enabledElement.Value = _enabled;
		}
		if (_strengthElement != null)
		{
			_strengthElement.Value = _strength;
		}
	}
}