From a7818ec4e036316e5b9f2c77e7229c7459189d46 Mon Sep 17 00:00:00 2001 From: doombubbles Date: Tue, 22 Oct 2024 22:39:46 -0700 Subject: [PATCH] Fix AudioClip duration --- BloonsTD6 Mod Helper/Api/Display/ModBloonOverlay.cs | 10 ++++++---- BloonsTD6 Mod Helper/Api/Internal/ResourceHandler.cs | 8 ++++---- BloonsTD6 Mod Helper/LATEST.md | 6 +++--- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/BloonsTD6 Mod Helper/Api/Display/ModBloonOverlay.cs b/BloonsTD6 Mod Helper/Api/Display/ModBloonOverlay.cs index a0b7e6e74..056da1736 100644 --- a/BloonsTD6 Mod Helper/Api/Display/ModBloonOverlay.cs +++ b/BloonsTD6 Mod Helper/Api/Display/ModBloonOverlay.cs @@ -26,7 +26,7 @@ public abstract class ModBloonOverlay : ModDisplay /// protected static SerializableDictionary AllOverlayTypes => GameData.Instance.bloonOverlays.overlayTypes; - + /// /// The overlay class that this is for /// @@ -37,7 +37,7 @@ public abstract class ModBloonOverlay : ModDisplay ///
/// These come from the fields of certain projectile behavior models ///
- /// To not copy from any Base Overlay, override this to be null/empty and modify or instead + /// To not copy from any Base Overlay, keep this as null/empty and modify or instead /// public virtual string BaseOverlay => null; @@ -91,8 +91,10 @@ public abstract class ModBloonOverlay : ModDisplay /// Which overlay type this Overlay uses /// public string OverlayType => WorksOnCurrentMelonLoader ? BaseId : BaseOverlay; - - /// + + /// + /// Load different instances of this type for each difference BloonOverlayClass within + /// public override IEnumerable Load() => WorksOnCurrentMelonLoader ? BloonOverlayClasses.Select(bc => { diff --git a/BloonsTD6 Mod Helper/Api/Internal/ResourceHandler.cs b/BloonsTD6 Mod Helper/Api/Internal/ResourceHandler.cs index 1666e1310..48fe42420 100644 --- a/BloonsTD6 Mod Helper/Api/Internal/ResourceHandler.cs +++ b/BloonsTD6 Mod Helper/Api/Internal/ResourceHandler.cs @@ -153,9 +153,9 @@ public static AudioClip CreateAudioClip(WaveFileReader reader, string id) var totalSamples = (int) (reader.SampleCount * waveFormat.Channels); var data = new float[totalSamples]; - reader.ToSampleProvider().Read(data, 0, totalSamples); + var readSamples = reader.ToSampleProvider().Read(data, 0, totalSamples); - var audioClip = AudioClip.Create(id, totalSamples, waveFormat.Channels, waveFormat.SampleRate, false); + var audioClip = AudioClip.Create(id, readSamples / 2, waveFormat.Channels, waveFormat.SampleRate, false); if (audioClip.SetData(data, 0)) { @@ -188,9 +188,9 @@ public static AudioClip CreateAudioClip(Mp3FileReader reader, string id) var totalSamples = (int) (reader.Length / (waveFormat.BitsPerSample / 8)) * waveFormat.Channels; var data = new float[totalSamples]; - reader.ToSampleProvider().Read(data, 0, totalSamples); + var readSamples = reader.ToSampleProvider().Read(data, 0, totalSamples); - var audioClip = AudioClip.Create(id, totalSamples, waveFormat.Channels, waveFormat.SampleRate, false); + var audioClip = AudioClip.Create(id, readSamples / 2, waveFormat.Channels, waveFormat.SampleRate, false); if (audioClip.SetData(data, 0)) { diff --git a/BloonsTD6 Mod Helper/LATEST.md b/BloonsTD6 Mod Helper/LATEST.md index 8ffaf9412..3451325d1 100644 --- a/BloonsTD6 Mod Helper/LATEST.md +++ b/BloonsTD6 Mod Helper/LATEST.md @@ -1,3 +1,3 @@ -- Fixed a TimeManager patch for BTD6 v45.2 (fixes Faster Forward) -- Made some methods in ResourceHandler public -- Fixed a bug with the Shift+Shift to open console setting \ No newline at end of file +- Added a ModBloonOverlay class for making custom Bloon Overlays + - NOTE: Due to a MelonLoader bug, these won't properly display unless you're on ML 0.6.6 or higher +- Accounted for a Unity bug that was affecting the internal durations of embedded AudioClips \ No newline at end of file