Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Patches/Misc/PlayAudioFilesPatch.cs
Original file line number Diff line number Diff line change
@@ -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<string, float>), typeof(float))]
class EnergyCounterPatch {
static bool Prefix(string path, Dictionary<string, float> parameters, float volume, NAudioManager __instance) {
if (TestMode.IsOn) return true;
if (!path.StartsWith("res://")) return true;
AudioStream audioStream = GD.Load<AudioStream>(path);
if (audioStream is null) return true;
AudioStreamPlayer2D audioPlayer = new() {
Bus = "SFX",
VolumeDb = Mathf.LinearToDb(volume),
Stream = GD.Load<AudioStream>(path),
};
__instance.GetTree().Root.AddChild(audioPlayer);
audioPlayer.Finished += audioPlayer.QueueFree;
audioPlayer.Play();
return false;
}
}