From 0b65c852d2626c321e5394dcb804ca8ae477de09 Mon Sep 17 00:00:00 2001 From: josshmot Date: Thu, 10 Apr 2025 17:34:19 +1000 Subject: [PATCH] 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