From 0720ab508dd960ed55e5e624cad8d0f321e9ff25 Mon Sep 17 00:00:00 2001 From: NotAKidoS <37721153+NotAKidoS@users.noreply.github.com> Date: Mon, 2 Dec 2024 20:07:01 -0600 Subject: [PATCH] ScrollFlight: fixed error spam on launch, added reset on exit flight option --- ScrollFlight/Main.cs | 25 ++++++++++++++++++++++--- ScrollFlight/Properties/AssemblyInfo.cs | 2 +- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/ScrollFlight/Main.cs b/ScrollFlight/Main.cs index e446609..98fdabd 100644 --- a/ScrollFlight/Main.cs +++ b/ScrollFlight/Main.cs @@ -23,6 +23,10 @@ public class ScrollFlightMod : MelonMod Category.CreateEntry("use_scroll_flight", true, "Use Scroll Flight", description: "Toggle Scroll Flight."); + private static readonly MelonPreferences_Entry EntryResetOnExitFlight = + Category.CreateEntry("reset_on_exit_flight", false, + "Reset On Exit Flight", description: "Reset Scroll Flight speed on exit flight."); + #endregion Melon Preferences #region Private Fields @@ -39,14 +43,29 @@ public class ScrollFlightMod : MelonMod CVRWorld.GameRulesUpdated += OnApplyMovementSettings; // thank you kafe for using actions } + bool wasFlying = false; + // stole from LucMod :3 public override void OnUpdate() { if (!EntryUseScrollFlight.Value) return; - if (BetterBetterCharacterController.Instance == null - || !BetterBetterCharacterController.Instance.IsFlying() + if (BetterBetterCharacterController.Instance == null) + return; + + bool isFlying = BetterBetterCharacterController.Instance.IsFlying(); + + if (EntryResetOnExitFlight.Value + && (wasFlying && !isFlying)) + { + BetterBetterCharacterController.Instance.worldFlightSpeedMultiplier = _originalWorldFlightSpeedMultiplier; + _currentWorldFlightSpeedMultiplier = _originalWorldFlightSpeedMultiplier; + } + + wasFlying = isFlying; + + if (!isFlying || Input.GetKey(KeyCode.Mouse2) // scroll zoom || Input.GetKey(KeyCode.LeftControl) // third person / better interact desktop || Cursor.lockState != CursorLockMode.Locked) // unity explorer / in menu @@ -58,7 +77,7 @@ public class ScrollFlightMod : MelonMod private static void AdjustFlightModifier(float adjustValue) { - _currentWorldFlightSpeedMultiplier = Math.Max(0f, _currentWorldFlightSpeedMultiplier + adjustValue); + _currentWorldFlightSpeedMultiplier = Mathf.Max(0f, _currentWorldFlightSpeedMultiplier + adjustValue); if (_currentWorldFlightSpeedMultiplier <= 0f) { diff --git a/ScrollFlight/Properties/AssemblyInfo.cs b/ScrollFlight/Properties/AssemblyInfo.cs index c659f5b..3aeb6cb 100644 --- a/ScrollFlight/Properties/AssemblyInfo.cs +++ b/ScrollFlight/Properties/AssemblyInfo.cs @@ -27,6 +27,6 @@ using System.Reflection; namespace NAK.ScrollFlight.Properties; internal static class AssemblyInfoParams { - public const string Version = "1.0.0"; + public const string Version = "1.0.1"; public const string Author = "NotAKidoS"; } \ No newline at end of file