Decompiled source of SpinMod v1.0.0

Mods/spinmod.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BoneLib;
using BoneLib.BoneMenu;
using BoneLib.Notifications;
using Il2CppSLZ.Marrow;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using TimeStopPublic;
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(TimeStopPublicMod), "Spin", "1.6.31", "Tapochnik", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("ClassLibrary1")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ClassLibrary1")]
[assembly: AssemblyTitle("ClassLibrary1")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace TimeStopPublic
{
	public sealed class TimeStopPublicMod : MelonMod
	{
		private sealed class PublicSpinBodyState
		{
			public Rigidbody Body;

			public bool OriginalKinematic;

			public RigidbodyConstraints OriginalConstraints;

			public bool OriginalUseGravity;

			public float OriginalMaxAngularVelocity;
		}

		private sealed class PublicSpinReturnState
		{
			public bool LeftHand;

			public GameObject Root;

			public Rigidbody Body;

			public float ReturnAt;

			public float ExpiresAt;

			public bool Homing;
		}

		private MelonPreferences_Category _publicPreferences;

		private MelonPreferences_Entry<bool> _publicSpinEnabled;

		private MelonPreferences_Entry<float> _publicSpinArmTimeout;

		private MelonPreferences_Entry<float> _publicSpinHomingDelay;

		private MelonPreferences_Entry<float> _publicSpinHomingSpeed;

		private MelonPreferences_Entry<float> _publicSpinThrowSpeed;

		private readonly List<PublicSpinBodyState> _publicSpinBodies = new List<PublicSpinBodyState>();

		private readonly List<PublicSpinReturnState> _publicSpinReturns = new List<PublicSpinReturnState>();

		private int _publicSpinTapCount;

		private float _lastPublicSpinTap = -10f;

		private int _publicSpinLeftTapCount;

		private float _lastPublicSpinLeftTap = -10f;

		private bool _publicSpinLeft;

		private bool _publicSpinArmed;

		private float _publicSpinArmedUntil = -1f;

		private bool _publicSpinActive;

		private GameObject _publicSpinHeldObject;

		private Transform _publicSpinRoot;

		private Rigidbody _publicSpinPrimaryBody;

		private float _publicSpinAngularSpeedDegrees;

		internal static TimeStopPublicMod Instance { get; private set; }

		private Hand PublicSpinHand => _publicSpinLeft ? Player.LeftHand : Player.RightHand;

		private BaseController PublicSpinController => _publicSpinLeft ? Player.LeftController : Player.RightController;

		public override void OnInitializeMelon()
		{
			Instance = this;
			_publicPreferences = MelonPreferences.CreateCategory("PublicSpin");
			_publicSpinEnabled = _publicPreferences.CreateEntry<bool>("Enabled", true, (string)null, "Enable Spin.", false, false, (ValueValidator)null, (string)null);
			_publicSpinArmTimeout = _publicPreferences.CreateEntry<float>("ArmTimeout", 12f, (string)null, "Timeout.", false, false, (ValueValidator)null, (string)null);
			_publicSpinHomingDelay = _publicPreferences.CreateEntry<float>("HomingDelay", 0.3f, (string)null, "Delay before return.", false, false, (ValueValidator)null, (string)null);
			_publicSpinHomingSpeed = _publicPreferences.CreateEntry<float>("HomingSpeed", 35f, (string)null, "Homing speed.", false, false, (ValueValidator)null, (string)null);
			_publicSpinThrowSpeed = _publicPreferences.CreateEntry<float>("ThrowSpeed", 30f, (string)null, "Throw speed.", false, false, (ValueValidator)null, (string)null);
			SetupPublicBoneMenu();
			Hooking.OnLevelUnloaded += OnLevelUnloaded;
			((MelonBase)this).LoggerInstance.Msg("Spin Mod (100% Stable Shoot) ready!");
		}

		private void SetupPublicBoneMenu()
		{
			//IL_001a: 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_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			Page val = Page.Root.CreatePage("Spin", new Color(0.95f, 0.72f, 0.12f), 0, true);
			val.CreateBool("Enabled", Color.yellow, _publicSpinEnabled.Value, (Action<bool>)delegate(bool value)
			{
				_publicSpinEnabled.Value = value;
				if (!value)
				{
					CancelPublicSpin();
				}
				_publicPreferences.SaveToFile(false);
			});
			val.CreateFloat("Throw Speed", Color.white, _publicSpinThrowSpeed.Value, 5f, 5f, 60f, (Action<float>)delegate(float value)
			{
				_publicSpinThrowSpeed.Value = value;
				_publicPreferences.SaveToFile(false);
			});
			val.CreateFloat("Homing Speed", Color.white, _publicSpinHomingSpeed.Value, 5f, 5f, 60f, (Action<float>)delegate(float value)
			{
				_publicSpinHomingSpeed.Value = value;
				_publicPreferences.SaveToFile(false);
			});
		}

		public override void OnUpdate()
		{
			HandlePublicSpinInput();
			UpdatePublicSpin();
			UpdatePublicSpinReturns();
		}

		public override void OnLateUpdate()
		{
			//IL_005d: 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_0067: 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_008a: 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_009b: Unknown result type (might be due to invalid IL or missing references)
			if (_publicSpinActive && !((Object)(object)PublicSpinHand == (Object)null) && !((Object)(object)_publicSpinPrimaryBody == (Object)null))
			{
				Transform transform = ((Component)PublicSpinHand).transform;
				_publicSpinAngularSpeedDegrees += 3000f * Time.unscaledDeltaTime;
				Quaternion val = Quaternion.AngleAxis(_publicSpinAngularSpeedDegrees * Time.unscaledDeltaTime, transform.forward);
				((Component)_publicSpinPrimaryBody).transform.position = transform.position;
				((Component)_publicSpinPrimaryBody).transform.rotation = val * ((Component)_publicSpinPrimaryBody).transform.rotation;
			}
		}

		private void HandlePublicSpinInput()
		{
			if (_publicSpinEnabled != null && _publicSpinEnabled.Value && Player.ControllersExist)
			{
				bool bButtonDown = Player.LeftController.GetBButtonDown();
				bool bButtonDown2 = Player.RightController.GetBButtonDown();
				if (bButtonDown && RegisterTap(ref _publicSpinLeftTapCount, ref _lastPublicSpinLeftTap))
				{
					ArmPublicSpin(left: true);
				}
				if (bButtonDown2 && RegisterTap(ref _publicSpinTapCount, ref _lastPublicSpinTap))
				{
					ArmPublicSpin(left: false);
				}
			}
		}

		private bool RegisterTap(ref int count, ref float lastTime)
		{
			float realtimeSinceStartup = Time.realtimeSinceStartup;
			if (realtimeSinceStartup - lastTime > 0.55f)
			{
				count = 0;
			}
			lastTime = realtimeSinceStartup;
			if (++count < 4)
			{
				return false;
			}
			count = 0;
			lastTime = -10f;
			return true;
		}

		private void ArmPublicSpin(bool left)
		{
			//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_0056: 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_006f: 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_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_009b: 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_00a6: 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_00b6: 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_00c2: Expected O, but got Unknown
			if (!_publicSpinActive && (Object)(object)(left ? Player.LeftHand : Player.RightHand) != (Object)null)
			{
				_publicSpinLeft = left;
				_publicSpinArmed = true;
				_publicSpinArmedUntil = Time.realtimeSinceStartup + _publicSpinArmTimeout.Value;
				Notifier.Send(new Notification
				{
					Title = new NotificationText
					{
						Text = "SPIN READY",
						Color = Color.white
					},
					Message = new NotificationText
					{
						Text = (left ? "Hold Left Grab" : "Hold Right Grab"),
						Color = Color.white
					},
					PopupLength = 1.5f,
					Type = (NotificationType)0
				});
			}
		}

		private void UpdatePublicSpin()
		{
			float realtimeSinceStartup = Time.realtimeSinceStartup;
			if (_publicSpinArmed && realtimeSinceStartup > _publicSpinArmedUntil)
			{
				_publicSpinArmed = false;
			}
			if ((Object)(object)PublicSpinHand == (Object)null || (Object)(object)PublicSpinController == (Object)null)
			{
				if (_publicSpinActive)
				{
					EndPublicSpin(releasedNormally: false);
				}
				return;
			}
			bool flag = PublicSpinController.GetGripForce() >= 0.25f;
			if (_publicSpinArmed && !_publicSpinActive && flag)
			{
				GameObject objectInHand = Player.GetObjectInHand(PublicSpinHand);
				if ((Object)(object)objectInHand != (Object)null)
				{
					BeginPublicSpin(objectInHand);
				}
			}
			else if (_publicSpinActive && !flag)
			{
				EndPublicSpin(releasedNormally: true);
			}
		}

		private void BeginPublicSpin(GameObject held)
		{
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: 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_0137: 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_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: 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_015f: 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_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Expected O, but got Unknown
			_publicSpinArmed = false;
			_publicSpinHeldObject = held;
			_publicSpinRoot = (((Object)(object)held != (Object)null) ? held.transform.root : null);
			if ((Object)(object)_publicSpinRoot == (Object)null)
			{
				return;
			}
			_publicSpinPrimaryBody = held.GetComponentInParent<Rigidbody>() ?? ((Component)_publicSpinRoot).GetComponentInChildren<Rigidbody>();
			_publicSpinBodies.Clear();
			foreach (Rigidbody componentsInChild in ((Component)_publicSpinRoot).GetComponentsInChildren<Rigidbody>(true))
			{
				if (!((Object)(object)componentsInChild == (Object)null))
				{
					_publicSpinBodies.Add(new PublicSpinBodyState
					{
						Body = componentsInChild,
						OriginalKinematic = componentsInChild.isKinematic,
						OriginalConstraints = componentsInChild.constraints,
						OriginalUseGravity = componentsInChild.useGravity,
						OriginalMaxAngularVelocity = componentsInChild.maxAngularVelocity
					});
					componentsInChild.maxAngularVelocity = Mathf.Max(componentsInChild.maxAngularVelocity, 10000000f);
					componentsInChild.useGravity = false;
					componentsInChild.isKinematic = false;
				}
			}
			_publicSpinAngularSpeedDegrees = 3000f;
			_publicSpinActive = true;
			Notifier.Send(new Notification
			{
				Title = new NotificationText
				{
					Text = "SPIN!",
					Color = Color.yellow
				},
				Message = new NotificationText
				{
					Text = "Active",
					Color = Color.white
				},
				PopupLength = 1f,
				Type = (NotificationType)3
			});
		}

		private void EndPublicSpin(bool releasedNormally)
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: 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_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: 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_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			if (!_publicSpinActive)
			{
				return;
			}
			Vector3 val = (((Object)(object)Camera.main != (Object)null) ? ((Component)Camera.main).transform.forward : (((Object)(object)PublicSpinHand != (Object)null) ? ((Component)PublicSpinHand).transform.forward : Vector3.forward));
			((Vector3)(ref val)).Normalize();
			foreach (PublicSpinBodyState publicSpinBody in _publicSpinBodies)
			{
				if (!((Object)(object)publicSpinBody.Body == (Object)null))
				{
					publicSpinBody.Body.isKinematic = publicSpinBody.OriginalKinematic;
					publicSpinBody.Body.constraints = publicSpinBody.OriginalConstraints;
					publicSpinBody.Body.useGravity = publicSpinBody.OriginalUseGravity;
					publicSpinBody.Body.maxAngularVelocity = publicSpinBody.OriginalMaxAngularVelocity;
				}
			}
			if (releasedNormally && (Object)(object)_publicSpinPrimaryBody != (Object)null)
			{
				_publicSpinPrimaryBody.isKinematic = false;
				_publicSpinPrimaryBody.velocity = val * _publicSpinThrowSpeed.Value;
				_publicSpinPrimaryBody.angularVelocity = val * (_publicSpinAngularSpeedDegrees * ((float)Math.PI / 180f));
				_publicSpinPrimaryBody.WakeUp();
				_publicSpinReturns.Add(new PublicSpinReturnState
				{
					LeftHand = _publicSpinLeft,
					Root = (GameObject)(((Object)(object)_publicSpinRoot != (Object)null) ? ((object)((Component)_publicSpinRoot).gameObject) : ((object)_publicSpinHeldObject)),
					Body = _publicSpinPrimaryBody,
					ReturnAt = Time.realtimeSinceStartup + _publicSpinHomingDelay.Value,
					ExpiresAt = Time.realtimeSinceStartup + 30f
				});
			}
			_publicSpinActive = false;
			_publicSpinBodies.Clear();
			_publicSpinHeldObject = null;
			_publicSpinPrimaryBody = null;
		}

		private void UpdatePublicSpinReturns()
		{
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: 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_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: 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_0188: Unknown result type (might be due to invalid IL or missing references)
			float realtimeSinceStartup = Time.realtimeSinceStartup;
			for (int num = _publicSpinReturns.Count - 1; num >= 0; num--)
			{
				PublicSpinReturnState publicSpinReturnState = _publicSpinReturns[num];
				if ((Object)(object)publicSpinReturnState.Body == (Object)null || realtimeSinceStartup >= publicSpinReturnState.ExpiresAt)
				{
					_publicSpinReturns.RemoveAt(num);
				}
				else
				{
					Hand val = (publicSpinReturnState.LeftHand ? Player.LeftHand : Player.RightHand);
					BaseController val2 = (publicSpinReturnState.LeftHand ? Player.LeftController : Player.RightController);
					bool flag = (Object)(object)val2 != (Object)null && val2.GetGripForce() >= 0.25f;
					if (realtimeSinceStartup >= publicSpinReturnState.ReturnAt && flag)
					{
						publicSpinReturnState.Homing = true;
					}
					if (publicSpinReturnState.Homing && (Object)(object)val != (Object)null && (Object)(object)publicSpinReturnState.Body != (Object)null)
					{
						publicSpinReturnState.Body.useGravity = false;
						Vector3 val3 = ((Component)val).transform.position - publicSpinReturnState.Body.worldCenterOfMass;
						Vector3 velocity = ((Vector3)(ref val3)).normalized * Mathf.Clamp(((Vector3)(ref val3)).magnitude * 18f, 6f, _publicSpinHomingSpeed.Value);
						publicSpinReturnState.Body.velocity = velocity;
						if (((Vector3)(ref val3)).magnitude <= 0.35f)
						{
							publicSpinReturnState.Body.velocity = Vector3.zero;
							publicSpinReturnState.Body.angularVelocity = Vector3.zero;
							publicSpinReturnState.Body.useGravity = true;
							_publicSpinReturns.RemoveAt(num);
						}
					}
				}
			}
		}

		private void CancelPublicSpin()
		{
			EndPublicSpin(releasedNormally: false);
			_publicSpinReturns.Clear();
		}

		private void OnLevelUnloaded()
		{
			CancelPublicSpin();
		}

		public override void OnDeinitializeMelon()
		{
			CancelPublicSpin();
		}
	}
}