From 861bd6d794f6cbeb2878976340271f552b941dec Mon Sep 17 00:00:00 2001 From: Samuel Tulach Date: Thu, 13 Jan 2022 17:44:42 +0100 Subject: [PATCH] Proper handling of invalid config --- .../SoundReplacer/Properties/AssemblyInfo.cs | 4 +-- SoundReplacer/SoundReplacer/SoundLoader.cs | 32 +++++++++++++++---- SoundReplacer/SoundReplacer/manifest.json | 2 +- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/SoundReplacer/SoundReplacer/Properties/AssemblyInfo.cs b/SoundReplacer/SoundReplacer/Properties/AssemblyInfo.cs index cca0837..00fc392 100644 --- a/SoundReplacer/SoundReplacer/Properties/AssemblyInfo.cs +++ b/SoundReplacer/SoundReplacer/Properties/AssemblyInfo.cs @@ -14,5 +14,5 @@ [assembly: AssemblyCulture("")] [assembly: ComVisible(false)] [assembly: Guid("ca60fd0d-b67b-4fd6-8081-3d8349bdcc89")] -[assembly: AssemblyVersion("0.0.5")] -[assembly: AssemblyFileVersion("0.0.5")] +[assembly: AssemblyVersion("0.0.6")] +[assembly: AssemblyFileVersion("0.0.6")] diff --git a/SoundReplacer/SoundReplacer/SoundLoader.cs b/SoundReplacer/SoundReplacer/SoundLoader.cs index 42d2a13..3e8384f 100644 --- a/SoundReplacer/SoundReplacer/SoundLoader.cs +++ b/SoundReplacer/SoundReplacer/SoundLoader.cs @@ -37,14 +37,14 @@ public static void GetSoundLists() } } - public static string GetFullPath(string name) + private static string GetFullPath(string name) { var path = Environment.CurrentDirectory + "\\UserData\\SoundReplacer\\" + name; var fileInfo = new FileInfo(path); return fileInfo.FullName; } - public static UnityWebRequest GetRequest(string fullPath) + private static UnityWebRequest GetRequest(string fullPath) { var fileUrl = "file:///" + fullPath; var fileInfo = new FileInfo(fullPath); @@ -62,6 +62,23 @@ public static UnityWebRequest GetRequest(string fullPath) } } + private static void ReplaceMissing(string name) + { + const string text = "Default"; + if (Plugin.CurrentConfig.GoodHitSound == name) + Plugin.CurrentConfig.GoodHitSound = text; + if (Plugin.CurrentConfig.BadHitSound == name) + Plugin.CurrentConfig.BadHitSound = text; + if (Plugin.CurrentConfig.ClickSound == name) + Plugin.CurrentConfig.ClickSound = text; + if (Plugin.CurrentConfig.FailSound == name) + Plugin.CurrentConfig.FailSound = text; + if (Plugin.CurrentConfig.SuccessSound == name) + Plugin.CurrentConfig.SuccessSound = text; + if (Plugin.CurrentConfig.MenuMusic == name) + Plugin.CurrentConfig.MenuMusic = text; + } + public static AudioClip LoadAudioClip(string name) { var fullPath = GetFullPath(name); @@ -75,11 +92,14 @@ public static AudioClip LoadAudioClip(string name) // basically instant success or error while (!task.isDone) { } - if (request.isNetworkError) - Plugin.Log.Error("Failed to load audio: " + request.error); - else - loadedAudio = DownloadHandlerAudioClip.GetContent(request); + if (request.isNetworkError || request.isHttpError) + { + Plugin.Log.Error($"Failed to load file {name} with error {request.error}"); + ReplaceMissing(name); + return GetEmptyClip(); + } + loadedAudio = DownloadHandlerAudioClip.GetContent(request); return loadedAudio; } diff --git a/SoundReplacer/SoundReplacer/manifest.json b/SoundReplacer/SoundReplacer/manifest.json index ee110e3..1f4837f 100644 --- a/SoundReplacer/SoundReplacer/manifest.json +++ b/SoundReplacer/SoundReplacer/manifest.json @@ -3,7 +3,7 @@ "id": "SoundReplacer", "name": "SoundReplacer", "author": "Otiosum", - "version": "0.0.5", + "version": "0.0.6", "description": "Easily replace in-game sounds", "gameVersion": "1.19.0", "dependsOn": {