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 BoneLib.Notifications; using DynamicFlight; using Il2CppInterop.Runtime.InteropTypes.Arrays; using Il2CppSLZ.Marrow; using MelonLoader; using MelonLoader.Preferences; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: MelonInfo(typeof(DynamicFlightMod), "DynamicFlight", "1.0.0", "Astronoz", null)] [assembly: MelonGame("Stress Level Zero", "BONELAB")] [assembly: AssemblyTitle("DynamicFlight")] [assembly: AssemblyDescription("Dynamic flight mod for BONELAB")] [assembly: TargetFramework(".NETCoreApp,Version=v8.0", FrameworkDisplayName = ".NET 8.0")] [assembly: AssemblyVersion("1.0.0.0")] [module: RefSafetyRules(11)] namespace DynamicFlight; public class DynamicFlightMod : MelonMod { private const string CategoryName = "DynamicFlight"; private MelonPreferences_Category _prefCat; private MelonPreferences_Entry _prefEnabled; private MelonPreferences_Entry _prefMoveSpeed; private MelonPreferences_Entry _prefVerticalSpeed; private MelonPreferences_Entry _prefDamping; private MelonPreferences_Entry _prefNoclipEnabled; private bool _isFlying; private Vector3 _currentVelocity = Vector3.zero; private float _lastBPressTime; private float _doubleTapDelay = 0.35f; private bool _isNoclip; private float _lastThumbstickPressTime; private List _disabledColliders = new List(); private float[] _savedDrags; private bool _physicsModified; public override void OnInitializeMelon() { _prefCat = MelonPreferences.CreateCategory("DynamicFlight"); _prefEnabled = _prefCat.CreateEntry("Enabled", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null); _prefMoveSpeed = _prefCat.CreateEntry("MoveSpeed", 15f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null); _prefVerticalSpeed = _prefCat.CreateEntry("VerticalSpeed", 10f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null); _prefDamping = _prefCat.CreateEntry("Damping", 3f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null); _prefNoclipEnabled = _prefCat.CreateEntry("NoclipEnabled", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null); try { SetupBoneMenu(); } catch (Exception value) { ((MelonBase)this).LoggerInstance.Error($"BoneMenu FAILED: {value}"); } ((MelonBase)this).LoggerInstance.Msg("DynamicFlight initialized! Double-tap B to fly. Double-tap R-stick to noclip."); } private void SetupBoneMenu() { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_007b: 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_00e8: Unknown result type (might be due to invalid IL or missing references) Page obj = Menu.CurrentPage.CreatePage("Dynamic Flight", Color.cyan, 0, true); obj.CreateBool("Mod Enabled", Color.green, _prefEnabled.Value, (Action)delegate(bool val) { _prefEnabled.Value = val; _prefCat.SaveToFile(true); if (!val && _isFlying) { StopFlying(); } }); obj.CreateFloat("Move Speed", Color.white, _prefMoveSpeed.Value, 5f, 5f, 50f, (Action)delegate(float val) { _prefMoveSpeed.Value = val; _prefCat.SaveToFile(true); }); obj.CreateFloat("Vertical Speed", Color.white, _prefVerticalSpeed.Value, 5f, 5f, 50f, (Action)delegate(float val) { _prefVerticalSpeed.Value = val; _prefCat.SaveToFile(true); }); obj.CreateFloat("Damping", Color.white, _prefDamping.Value, 1f, 0f, 30f, (Action)delegate(float val) { _prefDamping.Value = val; _prefCat.SaveToFile(true); }); obj.CreateBool("Noclip Enabled", Color.green, _prefNoclipEnabled.Value, (Action)delegate(bool val) { _prefNoclipEnabled.Value = val; _prefCat.SaveToFile(true); if (!val && _isNoclip) { DisableNoclip(); } }); ((MelonBase)this).LoggerInstance.Msg("BoneMenu created!"); } public override void OnUpdate() { if (!_prefEnabled.Value || !Player.HandsExist) { return; } if (Player.RightController.GetBButtonDown()) { float unscaledTime = Time.unscaledTime; if (unscaledTime - _lastBPressTime <= _doubleTapDelay) { if (_isFlying) { StopFlying(); } else { StartFlying(); } _lastBPressTime = 0f; } else { _lastBPressTime = unscaledTime; } } if (!_prefNoclipEnabled.Value || !_isFlying || !Player.RightController.GetThumbStickDown()) { return; } float unscaledTime2 = Time.unscaledTime; if (unscaledTime2 - _lastThumbstickPressTime <= _doubleTapDelay) { if (_isNoclip) { DisableNoclip(); } else { EnableNoclip(); } _lastThumbstickPressTime = 0f; } else { _lastThumbstickPressTime = unscaledTime2; } } public override void OnFixedUpdate() { //IL_001f: 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_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_0030: 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_003b: 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_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0052: 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_006c: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0070: 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_0077: Unknown result type (might be due to invalid IL or missing references) //IL_0087: 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) //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_0093: 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_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: 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_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might be due to invalid IL or missing references) if (!_isFlying) { return; } PhysicsRig physicsRig = Player.PhysicsRig; if ((Object)(object)physicsRig == (Object)null) { return; } Transform head = Player.Head; Vector3 forward = head.forward; Vector3 right = head.right; Vector2 thumbStickAxis = Player.LeftController.GetThumbStickAxis(); Vector2 thumbStickAxis2 = Player.RightController.GetThumbStickAxis(); Vector3 zero = Vector3.zero; zero += forward * thumbStickAxis.y * _prefMoveSpeed.Value; zero += right * thumbStickAxis.x * _prefMoveSpeed.Value; zero += Vector3.up * thumbStickAxis2.y * _prefVerticalSpeed.Value; float value = _prefDamping.Value; _currentVelocity = Vector3.Lerp(_currentVelocity, zero, Time.fixedDeltaTime * value * 2f); Rigidbody[] allBodyRigidbodies = GetAllBodyRigidbodies(physicsRig); foreach (Rigidbody val in allBodyRigidbodies) { if ((Object)(object)val != (Object)null) { val.velocity = _currentVelocity; val.useGravity = false; val.angularVelocity = Vector3.zero; } } } private Rigidbody[] GetAllBodyRigidbodies(PhysicsRig physRig) { List list = new List(); if ((Object)(object)physRig.torso != (Object)null) { AddIfNotNull(list, physRig.torso.rbPelvis); AddIfNotNull(list, physRig.torso.rbSpine); AddIfNotNull(list, physRig.torso.rbChest); AddIfNotNull(list, physRig.torso.rbNeck); AddIfNotNull(list, physRig.torso.rbHead); } if ((Object)(object)physRig.softbody != (Object)null) { AddIfNotNull(list, physRig.softbody.rbArmUpperLf); AddIfNotNull(list, physRig.softbody.rbArmUpperRt); AddIfNotNull(list, physRig.softbody.rbForearmLf); AddIfNotNull(list, physRig.softbody.rbForearmRt); AddIfNotNull(list, physRig.softbody.rbSoftHandLf); AddIfNotNull(list, physRig.softbody.rbSoftHandRt); } AddIfNotNull(list, physRig.rbKnee); AddIfNotNull(list, physRig.rbFeet); return list.ToArray(); } private void AddIfNotNull(List list, Rigidbody rb) { if ((Object)(object)rb != (Object)null) { list.Add(rb); } } private void StartFlying() { //IL_0018: 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_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00af: 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_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Expected O, but got Unknown PhysicsRig physicsRig = Player.PhysicsRig; if (!((Object)(object)physicsRig == (Object)null)) { _isFlying = true; _currentVelocity = Vector3.zero; Rigidbody[] allBodyRigidbodies = GetAllBodyRigidbodies(physicsRig); _savedDrags = new float[allBodyRigidbodies.Length]; for (int i = 0; i < allBodyRigidbodies.Length; i++) { _savedDrags[i] = allBodyRigidbodies[i].drag; allBodyRigidbodies[i].useGravity = false; allBodyRigidbodies[i].drag = 0f; } _physicsModified = true; ((MelonBase)this).LoggerInstance.Msg("FLY ON - Fly where you look! R-stick up/down for vertical."); Notifier.Send(new Notification { Title = NotificationText.op_Implicit("Dynamic Flight"), Message = NotificationText.op_Implicit("Flight ON"), ShowTitleOnPopup = true, PopupLength = 1f, Type = (NotificationType)3 }); } } private void StopFlying() { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003b: 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_0046: Unknown result type (might be due to invalid IL or missing references) //IL_004b: 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_0057: 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_0064: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Expected O, but got Unknown _isFlying = false; if (_isNoclip) { DisableNoclip(); } RestorePhysics(); ((MelonBase)this).LoggerInstance.Msg("FLY OFF"); Notifier.Send(new Notification { Title = NotificationText.op_Implicit("Dynamic Flight"), Message = NotificationText.op_Implicit("Flight OFF"), ShowTitleOnPopup = true, PopupLength = 1f, Type = (NotificationType)2 }); } private void RestorePhysics() { if (!_physicsModified) { return; } PhysicsRig physicsRig = Player.PhysicsRig; if (!((Object)(object)physicsRig == (Object)null)) { Rigidbody[] allBodyRigidbodies = GetAllBodyRigidbodies(physicsRig); for (int i = 0; i < allBodyRigidbodies.Length && i < _savedDrags.Length; i++) { allBodyRigidbodies[i].useGravity = true; allBodyRigidbodies[i].drag = _savedDrags[i]; } _physicsModified = false; } } private void EnableNoclip() { //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: 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_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Expected O, but got Unknown PhysicsRig physicsRig = Player.PhysicsRig; if ((Object)(object)physicsRig == (Object)null) { return; } _disabledColliders.Clear(); Collider[] array = Il2CppArrayBase.op_Implicit(((Component)physicsRig).gameObject.GetComponentsInChildren(true)); foreach (Collider val in array) { if ((Object)(object)val != (Object)null && val.enabled) { val.enabled = false; _disabledColliders.Add(val); } } _isNoclip = true; ((MelonBase)this).LoggerInstance.Msg($"NOCLIP ON - disabled {_disabledColliders.Count} colliders"); Notifier.Send(new Notification { Title = NotificationText.op_Implicit("Dynamic Flight"), Message = NotificationText.op_Implicit("Noclip ON"), ShowTitleOnPopup = true, PopupLength = 1f, Type = (NotificationType)3 }); } private void DisableNoclip() { //IL_0061: 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_006c: 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_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007c: 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_0086: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Expected O, but got Unknown foreach (Collider disabledCollider in _disabledColliders) { if ((Object)(object)disabledCollider != (Object)null) { disabledCollider.enabled = true; } } _disabledColliders.Clear(); _isNoclip = false; ((MelonBase)this).LoggerInstance.Msg("NOCLIP OFF"); Notifier.Send(new Notification { Title = NotificationText.op_Implicit("Dynamic Flight"), Message = NotificationText.op_Implicit("Noclip OFF"), ShowTitleOnPopup = true, PopupLength = 1f, Type = (NotificationType)2 }); } }