From d7e8314eb9fc3323665d448ca2dfe3af1be4cbfb Mon Sep 17 00:00:00 2001 From: Strelkasaurus Date: Tue, 26 Jul 2022 22:26:26 +0200 Subject: [PATCH 1/3] Handle looping correctly for the woods and the bus --- CHANGELOG.md | 5 +++++ SoundLoopMod/ModEntry.cs | 29 ++++++++++++++++++++++++++++- SoundLoopMod/manifest.json | 2 +- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d852e25..bddd80f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## Unreleased +### Fixed +- Don't try to restart the music while on the bus. +- Handle the specific secret woods case; play it's specific song instead of the generic seasonal. + ## [1.0.0] - 2022-07-26 ### Added - Restart in-game "morning" song when it is not playing and player is outside. diff --git a/SoundLoopMod/ModEntry.cs b/SoundLoopMod/ModEntry.cs index eb1f395..07971ca 100644 --- a/SoundLoopMod/ModEntry.cs +++ b/SoundLoopMod/ModEntry.cs @@ -34,9 +34,12 @@ namespace SoundLoopMod private void CheckMusicNeedsRestarting(object? sender, OneSecondUpdateTickingEventArgs e) { + // Don't do anything if we're at the title screen if (!Context.IsWorldReady) return; + // Music won't play again in the mines if this timestamp is lower than 150000. Set to some arbitrary large value. + // The skull cavern is considered an extension of the mines, so this should affect that as well. MineShaft.timeSinceLastMusic = 999999; // Avoid playing morning song in the mines etc. @@ -46,10 +49,34 @@ namespace SoundLoopMod // The game keeps trying to stop the music if it's dark. We won't fight it for now if (Game1.isDarkOut()) return; + + // Don't start music while on the bus + // shouldHideCharacters seems to only be used for the bus, seems to be the nicest way to get this info + if (Game1.currentLocation.shouldHideCharacters()) + return; + + // Be extra-safe about not doing anything during an event (to protect the special cases below) + if (Game1.eventUp) + return; + // Seems to be safe to touch the current song, check if it has finished if (Game1.currentSong == null || Game1.currentSong.IsStopped || Game1.requestedMusicTrack.ToLower().Contains("ambient")) { - Game1.playMorningSong(); + if (Game1.currentLocation.Name == "Woods") + { + // The music for the secret woods is a bit of a special case. + // Handle this in a way similar to the game when entering the woods. + + // The game doesn't start the woods song after 1800, do the same here + if (Game1.timeOfDay >= 1800) + return; + Game1.changeMusicTrack("woodsTheme"); + } + else + { + // General case, let the game figure out what song to play. + Game1.playMorningSong(); + } this.Monitor.Log("Restarted music"); } } diff --git a/SoundLoopMod/manifest.json b/SoundLoopMod/manifest.json index b2b9aa6..292dd7e 100644 --- a/SoundLoopMod/manifest.json +++ b/SoundLoopMod/manifest.json @@ -1,7 +1,7 @@ { "Name": "SoundLoop Mod", "Author": "strelkasaur", - "Version": "1.0.0", + "Version": "1.0.1-beta1", "Description": "Loops the in-game music", "UniqueID": "com.strelkasaurus.sm.soundloop", "EntryDll": "SoundLoopMod.dll", From e7075c1c7dbf0c787a4d4ace07e412ee38bf741c Mon Sep 17 00:00:00 2001 From: Strelkasaurus Date: Wed, 27 Jul 2022 03:29:49 +0200 Subject: [PATCH 2/3] Reset the secret woods music whenever it is entered The game only does this before 1800, afterwards it is expected that no sound will play. However, with this mod installed having silence 1800-2000 is a bit jarring, so we keep the woods theme playing until 2000. We need to handle playing this in the time range 1800-2000. --- SoundLoopMod/ModEntry.cs | 23 ++++++++++++++++------- SoundLoopMod/manifest.json | 2 +- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/SoundLoopMod/ModEntry.cs b/SoundLoopMod/ModEntry.cs index 07971ca..75722ed 100644 --- a/SoundLoopMod/ModEntry.cs +++ b/SoundLoopMod/ModEntry.cs @@ -30,8 +30,11 @@ namespace SoundLoopMod public override void Entry(IModHelper helper) { helper.Events.GameLoop.OneSecondUpdateTicking += this.CheckMusicNeedsRestarting; + helper.Events.Player.Warped += this.ResetMusicSecretWoods; } - + + private const string WoodsName = "Woods"; + private void CheckMusicNeedsRestarting(object? sender, OneSecondUpdateTickingEventArgs e) { // Don't do anything if we're at the title screen @@ -62,14 +65,9 @@ namespace SoundLoopMod // Seems to be safe to touch the current song, check if it has finished if (Game1.currentSong == null || Game1.currentSong.IsStopped || Game1.requestedMusicTrack.ToLower().Contains("ambient")) { - if (Game1.currentLocation.Name == "Woods") + if (Game1.currentLocation.Name == WoodsName) { // The music for the secret woods is a bit of a special case. - // Handle this in a way similar to the game when entering the woods. - - // The game doesn't start the woods song after 1800, do the same here - if (Game1.timeOfDay >= 1800) - return; Game1.changeMusicTrack("woodsTheme"); } else @@ -80,5 +78,16 @@ namespace SoundLoopMod this.Monitor.Log("Restarted music"); } } + + private void ResetMusicSecretWoods(object? sender, WarpedEventArgs e) + { + // The game won't touch the music when entering the woods after 1800, causing the previously playing + // music to keep playing. Hence we stop it and let CheckMusicNeedsRestarting play the woods theme. + // However, after dark, let it keep playing the ambient night sound. + if (e.IsLocalPlayer && e.NewLocation.Name == WoodsName && !Game1.isDarkOut()) + { + Game1.changeMusicTrack("none"); + } + } } } diff --git a/SoundLoopMod/manifest.json b/SoundLoopMod/manifest.json index 292dd7e..d2d4a73 100644 --- a/SoundLoopMod/manifest.json +++ b/SoundLoopMod/manifest.json @@ -1,7 +1,7 @@ { "Name": "SoundLoop Mod", "Author": "strelkasaur", - "Version": "1.0.1-beta1", + "Version": "1.0.1-beta2", "Description": "Loops the in-game music", "UniqueID": "com.strelkasaurus.sm.soundloop", "EntryDll": "SoundLoopMod.dll", From 96de8284ac4ed3c55b7c7d8389ec504900358d98 Mon Sep 17 00:00:00 2001 From: Strelkasaurus Date: Wed, 27 Jul 2022 03:31:14 +0200 Subject: [PATCH 3/3] Release 1.0.1 --- CHANGELOG.md | 2 +- SoundLoopMod/manifest.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bddd80f..6d950b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -## Unreleased +## [1.0.1] - 2022-07-27 ### Fixed - Don't try to restart the music while on the bus. - Handle the specific secret woods case; play it's specific song instead of the generic seasonal. diff --git a/SoundLoopMod/manifest.json b/SoundLoopMod/manifest.json index d2d4a73..bab1e73 100644 --- a/SoundLoopMod/manifest.json +++ b/SoundLoopMod/manifest.json @@ -1,7 +1,7 @@ { "Name": "SoundLoop Mod", "Author": "strelkasaur", - "Version": "1.0.1-beta2", + "Version": "1.0.1", "Description": "Loops the in-game music", "UniqueID": "com.strelkasaurus.sm.soundloop", "EntryDll": "SoundLoopMod.dll",