Decompiled source of SimpleFlight v1.0.0

Mods/BoneFly.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 BoneLib;
using BoneLib.BoneMenu;
using Il2CppSLZ.Marrow;
using MelonLoader;
using Microsoft.CodeAnalysis;
using StickFlyBonelab;
using UnityEngine;
using UnityEngine.XR;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(StickFlyMod), "StickFly BONELAB", "1.2.1", "AuthorName", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("BoneFly")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BoneFly")]
[assembly: AssemblyTitle("BoneFly")]
[assembly: AssemblyVersion("1.0.0.0")]
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 StickFlyBonelab
{
	public enum ToggleKeybind
	{
		LeftStickClick,
		DoubleTap_B,
		DoubleTap_Y
	}
	public class StickFlyMod : MelonMod
	{
		public static float NormalFlySpeed = 32f;

		public static float VerticalFlySpeed = 22f;

		public static bool isFlyEnabled = false;

		public static ToggleKeybind currentKeybind = ToggleKeybind.LeftStickClick;

		private bool cachedLeftStickClick = false;

		private bool cachedRightB = false;

		private bool cachedLeftY = false;

		private float lastBPressTime = 0f;

		private float lastYPressTime = 0f;

		private const float DoubleTapThreshold = 0.35f;

		private Vector3 currentFlyVelocity = Vector3.zero;

		private Dictionary<Collider, bool> originalColliderStates = new Dictionary<Collider, bool>();

		private Dictionary<Rigidbody, bool> originalGravityStates = new Dictionary<Rigidbody, bool>();

		public override void OnInitializeMelon()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: 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_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: 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)
			Page val = Page.Root.CreatePage("StickFly", Color.white, 0, true);
			val.CreateBool("Enable Fly & Noclip", Color.white, isFlyEnabled, (Action<bool>)OnFlyMenuToggled);
			val.CreateEnum("Toggle Keybind", Color.cyan, (Enum)currentKeybind, (Action<Enum>)delegate(Enum obj)
			{
				currentKeybind = (ToggleKeybind)(object)obj;
			});
			FloatElement normalSpeedElement = val.CreateFloat("Normal Fly Speed", Color.yellow, NormalFlySpeed, 1f, 1f, 100f, (Action<float>)delegate(float normalFlySpeed)
			{
				NormalFlySpeed = normalFlySpeed;
			});
			FloatElement verticalSpeedElement = val.CreateFloat("Vertical Fly Speed", Color.yellow, VerticalFlySpeed, 1f, 1f, 100f, (Action<float>)delegate(float verticalFlySpeed)
			{
				VerticalFlySpeed = verticalFlySpeed;
			});
			val.CreateFunction("Reset to Default Speed", Color.red, (Action)delegate
			{
				NormalFlySpeed = 32f;
				VerticalFlySpeed = 22f;
				if (normalSpeedElement != null)
				{
					normalSpeedElement.Value = 32f;
				}
				if (verticalSpeedElement != null)
				{
					verticalSpeedElement.Value = 22f;
				}
			});
		}

		private void OnFlyMenuToggled(bool value)
		{
			isFlyEnabled = value;
			ToggleFlyAndNoclip(isFlyEnabled);
		}

		public override void OnUpdate()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: 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_0022: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Player.RigManager == (Object)null)
			{
				return;
			}
			InputDevice deviceAtXRNode = InputDevices.GetDeviceAtXRNode((XRNode)4);
			InputDevice deviceAtXRNode2 = InputDevices.GetDeviceAtXRNode((XRNode)5);
			bool flag = false;
			switch (currentKeybind)
			{
			case ToggleKeybind.LeftStickClick:
			{
				bool flag3 = default(bool);
				((InputDevice)(ref deviceAtXRNode)).TryGetFeatureValue(CommonUsages.primary2DAxisClick, ref flag3);
				if (flag3 && !cachedLeftStickClick)
				{
					flag = true;
				}
				cachedLeftStickClick = flag3;
				break;
			}
			case ToggleKeybind.DoubleTap_B:
			{
				bool flag4 = default(bool);
				((InputDevice)(ref deviceAtXRNode2)).TryGetFeatureValue(CommonUsages.secondaryButton, ref flag4);
				if (flag4 && !cachedRightB)
				{
					if (Time.unscaledTime - lastBPressTime <= 0.35f)
					{
						flag = true;
						lastBPressTime = 0f;
					}
					else
					{
						lastBPressTime = Time.unscaledTime;
					}
				}
				cachedRightB = flag4;
				break;
			}
			case ToggleKeybind.DoubleTap_Y:
			{
				bool flag2 = default(bool);
				((InputDevice)(ref deviceAtXRNode)).TryGetFeatureValue(CommonUsages.secondaryButton, ref flag2);
				if (flag2 && !cachedLeftY)
				{
					if (Time.unscaledTime - lastYPressTime <= 0.35f)
					{
						flag = true;
						lastYPressTime = 0f;
					}
					else
					{
						lastYPressTime = Time.unscaledTime;
					}
				}
				cachedLeftY = flag2;
				break;
			}
			}
			if (flag)
			{
				isFlyEnabled = !isFlyEnabled;
				ToggleFlyAndNoclip(isFlyEnabled);
			}
		}

		public override void OnFixedUpdate()
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: 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_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: 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_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: 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_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: 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_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: 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_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)Player.RigManager == (Object)null) && isFlyEnabled)
			{
				InputDevice deviceAtXRNode = InputDevices.GetDeviceAtXRNode((XRNode)4);
				InputDevice deviceAtXRNode2 = InputDevices.GetDeviceAtXRNode((XRNode)5);
				Vector2 val = default(Vector2);
				((InputDevice)(ref deviceAtXRNode)).TryGetFeatureValue(CommonUsages.primary2DAxis, ref val);
				Vector2 val2 = default(Vector2);
				((InputDevice)(ref deviceAtXRNode2)).TryGetFeatureValue(CommonUsages.primary2DAxis, ref val2);
				float num = ((Mathf.Abs(val.x) > 0.2f) ? val.x : 0f);
				float num2 = ((Mathf.Abs(val.y) > 0.2f) ? val.y : 0f);
				float num3 = ((Mathf.Abs(val2.y) > 0.2f) ? val2.y : 0f);
				Transform head = Player.Head;
				Vector3 val3 = head.forward * num2 * NormalFlySpeed;
				Vector3 val4 = head.right * num * NormalFlySpeed;
				Vector3 val5 = Vector3.up * num3 * VerticalFlySpeed;
				Vector3 val6 = val3 + val4 + val5;
				Rigidbody component = ((Component)((Rig)Player.PhysicsRig).m_pelvis).GetComponent<Rigidbody>();
				if ((Object)(object)component != (Object)null)
				{
					currentFlyVelocity = Vector3.Lerp(component.velocity, val6, 14f * Time.fixedDeltaTime);
					component.velocity = currentFlyVelocity;
				}
			}
		}

		private void ToggleFlyAndNoclip(bool enable)
		{
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Player.PhysicsRig == (Object)null)
			{
				return;
			}
			if (enable)
			{
				originalColliderStates.Clear();
				foreach (Collider componentsInChild in ((Component)Player.PhysicsRig).GetComponentsInChildren<Collider>())
				{
					originalColliderStates[componentsInChild] = componentsInChild.isTrigger;
					componentsInChild.isTrigger = true;
				}
				originalGravityStates.Clear();
				{
					foreach (Rigidbody componentsInChild2 in ((Component)Player.PhysicsRig).GetComponentsInChildren<Rigidbody>())
					{
						originalGravityStates[componentsInChild2] = componentsInChild2.useGravity;
						componentsInChild2.useGravity = false;
					}
					return;
				}
			}
			foreach (KeyValuePair<Collider, bool> originalColliderState in originalColliderStates)
			{
				if ((Object)(object)originalColliderState.Key != (Object)null)
				{
					originalColliderState.Key.isTrigger = originalColliderState.Value;
				}
			}
			originalColliderStates.Clear();
			foreach (KeyValuePair<Rigidbody, bool> originalGravityState in originalGravityStates)
			{
				if ((Object)(object)originalGravityState.Key != (Object)null)
				{
					originalGravityState.Key.useGravity = originalGravityState.Value;
					originalGravityState.Key.velocity = currentFlyVelocity;
					originalGravityState.Key.ResetCenterOfMass();
					originalGravityState.Key.WakeUp();
				}
			}
			originalGravityStates.Clear();
		}
	}
}