Skip to content

Commit

Permalink
Fix AudioClip duration
Browse files Browse the repository at this point in the history
  • Loading branch information
doombubbles committed Oct 23, 2024
1 parent 034a1a0 commit a7818ec
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
10 changes: 6 additions & 4 deletions BloonsTD6 Mod Helper/Api/Display/ModBloonOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public abstract class ModBloonOverlay : ModDisplay
/// </summary>
protected static SerializableDictionary<string, BloonOverlayScriptable> AllOverlayTypes =>
GameData.Instance.bloonOverlays.overlayTypes;

/// <summary>
/// The overlay class that this is for
/// </summary>
Expand All @@ -37,7 +37,7 @@ public abstract class ModBloonOverlay : ModDisplay
/// <br/>
/// These come from the <see cref="ProjectileBehaviorWithOverlayModel.overlayType"/> fields of certain projectile behavior models
/// <br/>
/// To not copy from any Base Overlay, override this to be null/empty and modify <see cref="ModDisplay.BaseDisplay"/> or <see cref="ModDisplay.BaseDisplayReference"/> instead
/// To not copy from any Base Overlay, keep this as null/empty and modify <see cref="ModDisplay.BaseDisplay"/> or <see cref="ModDisplay.BaseDisplayReference"/> instead
/// </summary>
public virtual string BaseOverlay => null;

Expand Down Expand Up @@ -91,8 +91,10 @@ public abstract class ModBloonOverlay : ModDisplay
/// Which overlay type this Overlay uses
/// </summary>
public string OverlayType => WorksOnCurrentMelonLoader ? BaseId : BaseOverlay;

/// <inheritdoc />

/// <summary>
/// Load different instances of this type for each difference BloonOverlayClass within <see cref="BloonOverlayClasses"/>
/// </summary>
public override IEnumerable<ModContent> Load() => WorksOnCurrentMelonLoader
? BloonOverlayClasses.Select(bc =>
{
Expand Down
8 changes: 4 additions & 4 deletions BloonsTD6 Mod Helper/Api/Internal/ResourceHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down Expand Up @@ -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))
{
Expand Down
6 changes: 3 additions & 3 deletions BloonsTD6 Mod Helper/LATEST.md
Original file line number Diff line number Diff line change
@@ -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
- 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

0 comments on commit a7818ec

Please sign in to comment.