diff --git a/NewHorizons/Patches/GlobalMusicControllerPatches.cs b/NewHorizons/Patches/GlobalMusicControllerPatches.cs new file mode 100644 index 00000000..776cb8e8 --- /dev/null +++ b/NewHorizons/Patches/GlobalMusicControllerPatches.cs @@ -0,0 +1,38 @@ +using HarmonyLib; +using UnityEngine; + +namespace NewHorizons.Patches; + +[HarmonyPatch(typeof(GlobalMusicController))] +public class GlobalMusicControllerPatches +{ + private static AudioDetector _audioDetector; + + [HarmonyPrefix] + [HarmonyPatch(nameof(GlobalMusicController.UpdateBrambleMusic))] + public static bool GlobalMusicController_UpdateBrambleMusic(GlobalMusicController __instance) + { + // is this too hacky? + if (_audioDetector == null) _audioDetector = Object.FindObjectOfType(); + + + var shouldBePlaying = Locator.GetPlayerSectorDetector().InBrambleDimension() && + !Locator.GetPlayerSectorDetector().InVesselDimension() && + PlayerState.AtFlightConsole() && + !PlayerState.IsHullBreached() && + !__instance._playingFinalEndTimes && + _audioDetector._activeVolumes.Count == 0; // change - don't play if in another audio volume + var playing = __instance._darkBrambleSource.isPlaying && + !__instance._darkBrambleSource.IsFadingOut(); + if (shouldBePlaying && !playing) + { + __instance._darkBrambleSource.FadeIn(5f); + } + else if (!shouldBePlaying && playing) + { + __instance._darkBrambleSource.FadeOut(5f); + } + + return false; + } +}