diff --git a/QSB/ShipSync/Patches/ShipAudioPatches.cs b/QSB/ShipSync/Patches/ShipAudioPatches.cs index 51f685179..f28aa2892 100644 --- a/QSB/ShipSync/Patches/ShipAudioPatches.cs +++ b/QSB/ShipSync/Patches/ShipAudioPatches.cs @@ -41,4 +41,27 @@ public static bool ShipThrusterAudio_Update(ShipThrusterAudio __instance) return true; } } + + [HarmonyPrefix] + [HarmonyPatch(typeof(TravelMusicController), nameof(TravelMusicController.Update))] + public static bool TravelMusicController_Update(TravelMusicController instance) + { + // only this line is changed + instance._isTraveling = PlayerState.IsInsideShip() + && ShipManager.Instance.CurrentFlyer != uint.MaxValue + && Locator.GetPlayerRulesetDetector().AllowTravelMusic(); + + if (instance._isTraveling && !instance._wasTraveling) + { + instance._audioSource.FadeIn(5f, false, false, 1f); + } + else if (!instance._isTraveling && instance._wasTraveling) + { + instance._audioSource.FadeOut(5f, OWAudioSource.FadeOutCompleteAction.PAUSE, 0f); + } + + instance._wasTraveling = instance._isTraveling; + + return false; + } } diff --git a/QSB/ShipSync/ShipManager.cs b/QSB/ShipSync/ShipManager.cs index 90e875b7b..0763e80d9 100644 --- a/QSB/ShipSync/ShipManager.cs +++ b/QSB/ShipSync/ShipManager.cs @@ -30,6 +30,10 @@ public class ShipManager : WorldObjectManager public ShipElectricalComponent ShipElectricalComponent; public ShipCockpitUI ShipCockpitUI; private GameObject _shipCustomAttach; + + /// + /// PlayerID of the person who is flying the ship. If no one is flying, this is . + /// public uint CurrentFlyer { get => _currentFlyer;