Decompiled source of Flight v1.0.1

Mods/Flight.dll

Decompiled 2 weeks ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using Flight;
using Il2Cpp;
using Il2CppHexabodyVR.PlayerController;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
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(Core), "Flight", "1.0.0", "Mjdo0", null)]
[assembly: MelonGame("Kubunautilus", "BrutalistickVR")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("Flight")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Flight")]
[assembly: AssemblyTitle("Flight")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Flight
{
	public class Core : MelonMod
	{
		public static bool isMainMenu = true;

		public static bool isFlying = false;

		public static Rigidbody[] rigidBodies;

		public static HVRHexaBodyInputs playerInputs;

		public static InputDevice leftHand;

		public static InputDevice rightHand;

		private bool lastJump;

		private float lastClickTime;

		private float doubleClickThreshold = 0.3f;

		public static MelonPreferences_Category category;

		public static MelonPreferences_Entry<float> maxSpeedV;

		public static float flightForce = 1.5f;

		public override void OnInitializeMelon()
		{
			((MelonBase)this).LoggerInstance.Msg("Initialized.");
			category = MelonPreferences.CreateCategory("Flight", "Flight Mod Settings");
			maxSpeedV = category.CreateEntry<float>("MaxSpeed", 16f, "Max Speed", "Maximum flight speed (higher is faster, but less controllable)", false, false, (ValueValidator)null, (string)null);
			category.SaveToFile(true);
		}

		public override void OnSceneWasLoaded(int buildIndex, string sceneName)
		{
			isFlying = false;
			if (sceneName != "MainMenuScene")
			{
				playerInputs = GameObject.Find("HexaBody").GetComponent<HVRHexaBodyInputs>();
				rigidBodies = (Rigidbody[])(object)new Rigidbody[5];
				rigidBodies[0] = GameObject.Find("PlayerUpperChest").GetComponent<Rigidbody>();
				rigidBodies[1] = GameObject.Find("PlayerPelvis").GetComponent<Rigidbody>();
				rigidBodies[2] = GameObject.Find("Knee").GetComponent<Rigidbody>();
				rigidBodies[3] = GameObject.Find("PlayerHexaPelvis").GetComponent<Rigidbody>();
				rigidBodies[4] = GameObject.Find("LocoBall").GetComponent<Rigidbody>();
				isMainMenu = false;
			}
			else
			{
				isMainMenu = true;
			}
		}

		public static void ToggleFlight()
		{
			isFlying = !isFlying;
			if (isFlying)
			{
				Rigidbody[] array = rigidBodies;
				foreach (Rigidbody val in array)
				{
					val.useGravity = false;
				}
			}
			else
			{
				Rigidbody[] array2 = rigidBodies;
				foreach (Rigidbody val2 in array2)
				{
					val2.useGravity = true;
				}
			}
		}

		public override void OnUpdate()
		{
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//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_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: 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)
			//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_00b2: 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_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: 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_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: 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_0183: 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)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			if (isMainMenu)
			{
				return;
			}
			if (isFlying)
			{
				Vector3 linearVelocity;
				if (((HexaBodyInputsBase)playerInputs).MovementMagnitude > 0.01f)
				{
					Rigidbody[] array = rigidBodies;
					foreach (Rigidbody val in array)
					{
						Transform transform = ((Component)Camera.main).transform;
						Vector3 forward = transform.forward;
						Vector3 right = transform.right;
						forward.y = 0f;
						right.y = 0f;
						((Vector3)(ref forward)).Normalize();
						((Vector3)(ref right)).Normalize();
						Vector3 val2 = right * ((HexaBodyInputsBase)playerInputs).MovementAxis.x + forward * ((HexaBodyInputsBase)playerInputs).MovementAxis.y;
						float value = maxSpeedV.Value;
						linearVelocity = val.linearVelocity;
						float magnitude = ((Vector3)(ref linearVelocity)).magnitude;
						float num = Mathf.Clamp01(1f - magnitude / value);
						val.AddForce(val2 * flightForce * num, (ForceMode)2);
					}
				}
				if (((HexaBodyInputsBase)playerInputs).TurnAxis.y > 0.01f || ((HexaBodyInputsBase)playerInputs).TurnAxis.y < -0.01f)
				{
					Rigidbody[] array2 = rigidBodies;
					foreach (Rigidbody val3 in array2)
					{
						float value2 = maxSpeedV.Value;
						linearVelocity = val3.linearVelocity;
						float magnitude2 = ((Vector3)(ref linearVelocity)).magnitude;
						float num2 = Mathf.Clamp01(1f - magnitude2 / value2);
						val3.AddForce(new Vector3(0f, ((HexaBodyInputsBase)playerInputs).TurnAxis.y, 0f) * flightForce * num2, (ForceMode)2);
					}
				}
			}
			bool jumpPressed = ((HexaBodyInputsBase)playerInputs).JumpPressed;
			if (jumpPressed && !lastJump)
			{
				if (Time.time - lastClickTime < doubleClickThreshold)
				{
					ToggleFlight();
				}
				lastClickTime = Time.time;
			}
			lastJump = jumpPressed;
		}
	}
}