diff --git a/Patches/Misc/PlayAudioFilesPatch.cs b/Patches/Misc/PlayAudioFilesPatch.cs new file mode 100644 index 0000000..b79f02e --- /dev/null +++ b/Patches/Misc/PlayAudioFilesPatch.cs @@ -0,0 +1,25 @@ +using Godot; +using HarmonyLib; +using MegaCrit.Sts2.Core.Nodes.Audio; +using MegaCrit.Sts2.Core.TestSupport; + +namespace BaseLib.Patches.Misc; + +[HarmonyPatch(typeof(NAudioManager), nameof(NAudioManager.PlayOneShot), typeof(string), typeof(Dictionary), typeof(float))] +class EnergyCounterPatch { + static bool Prefix(string path, Dictionary parameters, float volume, NAudioManager __instance) { + if (TestMode.IsOn) return true; + if (!path.StartsWith("res://")) return true; + AudioStream audioStream = GD.Load(path); + if (audioStream is null) return true; + AudioStreamPlayer2D audioPlayer = new() { + Bus = "SFX", + VolumeDb = Mathf.LinearToDb(volume), + Stream = GD.Load(path), + }; + __instance.GetTree().Root.AddChild(audioPlayer); + audioPlayer.Finished += audioPlayer.QueueFree; + audioPlayer.Play(); + return false; + } +} \ No newline at end of file