From 7eeef3483dfd18cecaaed02c8812df94fde9465c Mon Sep 17 00:00:00 2001 From: _nebula <41904486+misternebula@users.noreply.github.com> Date: Fri, 9 Feb 2024 00:51:11 +0000 Subject: [PATCH] fix music patches for ship --- QSB/ShipSync/Patches/ShipAudioPatches.cs | 50 ++++++++++++++++++------ 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/QSB/ShipSync/Patches/ShipAudioPatches.cs b/QSB/ShipSync/Patches/ShipAudioPatches.cs index 6cb8f2fbf..e981b7f3f 100644 --- a/QSB/ShipSync/Patches/ShipAudioPatches.cs +++ b/QSB/ShipSync/Patches/ShipAudioPatches.cs @@ -43,25 +43,53 @@ public static bool ShipThrusterAudio_Update(ShipThrusterAudio __instance) } [HarmonyPrefix] - [HarmonyPatch(typeof(TravelMusicController), nameof(TravelMusicController.Update))] - public static bool TravelMusicController_Update(TravelMusicController __instance) + [HarmonyPatch(typeof(GlobalMusicController), nameof(GlobalMusicController.UpdateTravelMusic))] + public static bool GlobalMusicController_UpdateTravelMusic(GlobalMusicController __instance) { // only this line is changed - __instance._isTraveling = PlayerState.IsInsideShip() - && ShipManager.Instance.CurrentFlyer != uint.MaxValue - && Locator.GetPlayerRulesetDetector().AllowTravelMusic(); + bool flag = PlayerState.IsInsideShip() + && ShipManager.Instance.CurrentFlyer != uint.MaxValue + && Locator.GetPlayerRulesetDetector().AllowTravelMusic() + && !PlayerState.IsHullBreached() + && !__instance._playingFinalEndTimes; - if (__instance._isTraveling && !__instance._wasTraveling) + + bool flag2 = __instance._travelSource.isPlaying && !__instance._travelSource.IsFadingOut(); + if (flag && !flag2) { - __instance._audioSource.FadeIn(5f, false, false, 1f); + __instance._travelSource.FadeIn(5f, false, false, 1f); + return false; } - else if (!__instance._isTraveling && __instance._wasTraveling) + if (!flag && flag2) { - __instance._audioSource.FadeOut(5f, OWAudioSource.FadeOutCompleteAction.PAUSE, 0f); + __instance._travelSource.FadeOut(5f, OWAudioSource.FadeOutCompleteAction.PAUSE, 0f); } - __instance._wasTraveling = __instance._isTraveling; - return false; } + + [HarmonyPrefix] + [HarmonyPatch(typeof(GlobalMusicController), nameof(GlobalMusicController.UpdateBrambleMusic))] + public static bool GlobalMusicController_UpdateBrambleMusic(GlobalMusicController __instance) + { + bool flag = Locator.GetPlayerSectorDetector().InBrambleDimension() + && !Locator.GetPlayerSectorDetector().InVesselDimension() + && PlayerState.IsInsideShip() + && ShipManager.Instance.CurrentFlyer != uint.MaxValue + && !PlayerState.IsHullBreached() + && !__instance._playingFinalEndTimes; + + bool flag2 = __instance._darkBrambleSource.isPlaying && !__instance._darkBrambleSource.IsFadingOut(); + + if (flag && !flag2) + { + __instance._darkBrambleSource.FadeIn(5f, false, false, 1f); + return false; + } + + if (!flag && flag2) + { + __instance._darkBrambleSource.FadeOut(5f, OWAudioSource.FadeOutCompleteAction.STOP, 0f); + } + } }