From 0b65c852d2626c321e5394dcb804ca8ae477de09 Mon Sep 17 00:00:00 2001 From: josshmot Date: Thu, 10 Apr 2025 17:34:19 +1000 Subject: [PATCH 1/5] Fixed undefined behaviour when custom credits attributes aren't specified --- NewHorizons/Components/NHGameOverManager.cs | 9 ++++++++- NewHorizons/External/Modules/GameOverModule.cs | 13 +++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/NewHorizons/Components/NHGameOverManager.cs b/NewHorizons/Components/NHGameOverManager.cs index 0fe3dc08..acc3080d 100644 --- a/NewHorizons/Components/NHGameOverManager.cs +++ b/NewHorizons/Components/NHGameOverManager.cs @@ -165,7 +165,14 @@ namespace NewHorizons.Components // Patch new music clip var musicSource = Locator.FindObjectsOfType().Where(x => x.name == "AudioSource").Single(); // AudioSource that plays the credits music is literally called "AudioSource", luckily it's the only one called that. Lazy OW devs do be lazy. - AudioUtilities.SetAudioClip(musicSource, gameOver.audio, mod); + if (gameOver.audio != string.Empty) // string.Empty is default value for "audio" in GameOverModule, means no audio is specified. + { + AudioUtilities.SetAudioClip(musicSource, gameOver.audio, mod); // Load audio if specified + } + else + { + musicSource.AssignAudioLibraryClip(AudioType.PLACEHOLDER); // Otherwise default custom credits are silent + } musicSource.loop = gameOver.audioLooping; musicSource._maxSourceVolume = gameOver.audioVolume; diff --git a/NewHorizons/External/Modules/GameOverModule.cs b/NewHorizons/External/Modules/GameOverModule.cs index 7bb884e1..d9dba70b 100644 --- a/NewHorizons/External/Modules/GameOverModule.cs +++ b/NewHorizons/External/Modules/GameOverModule.cs @@ -22,34 +22,31 @@ namespace NewHorizons.External.Modules /// Condition that must be true for this game over to trigger. If this is on a LoadCreditsVolume, leave empty to always trigger this game over. /// Note this is a regular dialogue condition, not a persistent condition. /// - public string condition; + public string condition; /// /// Path to the audio file to use as custom music for the credits. /// Note: only applies when creditsType is set to "custom". /// - public string audio; + public string audio = string.Empty; // Explicitly declaring this for condition in NHGameOverManager /// /// The length of the fade in and out for the credits music. /// Note: only applies when creditsType is set to "custom". /// - [DefaultValue(1f)] - public float audioVolume; + [DefaultValue(1f)] public float audioVolume = 1f; /// /// Determines if the credits music should loop. /// Note: only applies when creditsType is set to "custom". /// - [DefaultValue(false)] - public bool audioLooping; + [DefaultValue(false)] public bool audioLooping = false; /// /// Duration of the credits scroll in seconds. /// Note: only applies when creditsType is set to "custom". /// - [DefaultValue(120f)] - public float length; + [DefaultValue(120f)] public float length = 120f; /// /// The type of credits that will run after the game over message is shown From 3cae688e2c14ece815b63ca77d00d3877317d74d Mon Sep 17 00:00:00 2001 From: josshmot Date: Fri, 11 Apr 2025 04:58:30 +1000 Subject: [PATCH 2/5] Replaced != string.Empty with string.IsNullOrEmpty() in NHGameOverManager --- NewHorizons/Components/NHGameOverManager.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NewHorizons/Components/NHGameOverManager.cs b/NewHorizons/Components/NHGameOverManager.cs index acc3080d..1586755d 100644 --- a/NewHorizons/Components/NHGameOverManager.cs +++ b/NewHorizons/Components/NHGameOverManager.cs @@ -165,13 +165,13 @@ namespace NewHorizons.Components // Patch new music clip var musicSource = Locator.FindObjectsOfType().Where(x => x.name == "AudioSource").Single(); // AudioSource that plays the credits music is literally called "AudioSource", luckily it's the only one called that. Lazy OW devs do be lazy. - if (gameOver.audio != string.Empty) // string.Empty is default value for "audio" in GameOverModule, means no audio is specified. + if (string.IsNullOrEmpty(gameOver.audio)) // string.Empty is default value for "audio" in GameOverModule, means no audio is specified. { AudioUtilities.SetAudioClip(musicSource, gameOver.audio, mod); // Load audio if specified } else { - musicSource.AssignAudioLibraryClip(AudioType.PLACEHOLDER); // Otherwise default custom credits are silent + musicSource.AssignAudioLibraryClip(AudioType.PLACEHOLDER); // Otherwise default custom credits are silent - AudioType.PLACEHOLDER is silence (apparently) } musicSource.loop = gameOver.audioLooping; From ad3802d383febc14efa43abfcc57a8920c602011 Mon Sep 17 00:00:00 2001 From: josshmot Date: Fri, 11 Apr 2025 05:07:49 +1000 Subject: [PATCH 3/5] Added intended behaviour when unspecified to json description for GameOverModule.audio --- NewHorizons/External/Modules/GameOverModule.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NewHorizons/External/Modules/GameOverModule.cs b/NewHorizons/External/Modules/GameOverModule.cs index d9dba70b..2f62a5b6 100644 --- a/NewHorizons/External/Modules/GameOverModule.cs +++ b/NewHorizons/External/Modules/GameOverModule.cs @@ -25,7 +25,7 @@ namespace NewHorizons.External.Modules public string condition; /// - /// Path to the audio file to use as custom music for the credits. + /// Path to the audio file to use as custom music for the credits. When creditsType is set to "custom", credits will be silent unless this is specified. /// Note: only applies when creditsType is set to "custom". /// public string audio = string.Empty; // Explicitly declaring this for condition in NHGameOverManager @@ -37,7 +37,7 @@ namespace NewHorizons.External.Modules [DefaultValue(1f)] public float audioVolume = 1f; /// - /// Determines if the credits music should loop. + /// Determines if the credits music should loop () /// Note: only applies when creditsType is set to "custom". /// [DefaultValue(false)] public bool audioLooping = false; From a8d944a4c9e4bf867b344b7b1d55c76db69234f8 Mon Sep 17 00:00:00 2001 From: josshmot Date: Fri, 11 Apr 2025 05:09:46 +1000 Subject: [PATCH 4/5] Fixed typo in GameOverModule --- NewHorizons/External/Modules/GameOverModule.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NewHorizons/External/Modules/GameOverModule.cs b/NewHorizons/External/Modules/GameOverModule.cs index 2f62a5b6..859e9d3b 100644 --- a/NewHorizons/External/Modules/GameOverModule.cs +++ b/NewHorizons/External/Modules/GameOverModule.cs @@ -25,7 +25,7 @@ namespace NewHorizons.External.Modules public string condition; /// - /// Path to the audio file to use as custom music for the credits. When creditsType is set to "custom", credits will be silent unless this is specified. + /// Path to the audio file to use as custom music for the credits. When creditsType is set to "custom", credits will be silent unless this attribute is specified. /// Note: only applies when creditsType is set to "custom". /// public string audio = string.Empty; // Explicitly declaring this for condition in NHGameOverManager @@ -37,7 +37,7 @@ namespace NewHorizons.External.Modules [DefaultValue(1f)] public float audioVolume = 1f; /// - /// Determines if the credits music should loop () + /// Determines if the credits music should loop. /// Note: only applies when creditsType is set to "custom". /// [DefaultValue(false)] public bool audioLooping = false; From 539ef61c534be2feccc2d48b4992143f5b2c7642 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Thu, 10 Apr 2025 15:11:34 -0400 Subject: [PATCH 5/5] correction --- NewHorizons/Components/NHGameOverManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/Components/NHGameOverManager.cs b/NewHorizons/Components/NHGameOverManager.cs index 1586755d..37661562 100644 --- a/NewHorizons/Components/NHGameOverManager.cs +++ b/NewHorizons/Components/NHGameOverManager.cs @@ -165,7 +165,7 @@ namespace NewHorizons.Components // Patch new music clip var musicSource = Locator.FindObjectsOfType().Where(x => x.name == "AudioSource").Single(); // AudioSource that plays the credits music is literally called "AudioSource", luckily it's the only one called that. Lazy OW devs do be lazy. - if (string.IsNullOrEmpty(gameOver.audio)) // string.Empty is default value for "audio" in GameOverModule, means no audio is specified. + if (!string.IsNullOrEmpty(gameOver.audio)) // string.Empty is default value for "audio" in GameOverModule, means no audio is specified. { AudioUtilities.SetAudioClip(musicSource, gameOver.audio, mod); // Load audio if specified }