From 9f57d393bfe41289178c8ff556e95cf90aa6028f Mon Sep 17 00:00:00 2001 From: Clansty Date: Wed, 4 Sep 2024 15:32:11 +0800 Subject: [PATCH] [F] LoadJacketPng and RandomBgm crash when LocalAssets not exists --- AquaMai/UX/LoadJacketPng.cs | 13 +++++++------ AquaMai/UX/RandomBgm.cs | 4 +++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/AquaMai/UX/LoadJacketPng.cs b/AquaMai/UX/LoadJacketPng.cs index ee04038e..0a2b712a 100644 --- a/AquaMai/UX/LoadJacketPng.cs +++ b/AquaMai/UX/LoadJacketPng.cs @@ -59,12 +59,13 @@ public static void LoadMusicPostfix(List ____targetDirs) } } - foreach (var laFile in Directory.EnumerateFiles(Path.Combine(Environment.CurrentDirectory, "LocalAssets"))) - { - var match = localAssetsJacketExt.Match(Path.GetFileName(laFile)); - if (!match.Success) continue; - jacketPaths[match.Groups[1].Value] = laFile; - } + if (Directory.Exists(Path.Combine(Environment.CurrentDirectory, "LocalAssets"))) + foreach (var laFile in Directory.EnumerateFiles(Path.Combine(Environment.CurrentDirectory, "LocalAssets"))) + { + var match = localAssetsJacketExt.Match(Path.GetFileName(laFile)); + if (!match.Success) continue; + jacketPaths[match.Groups[1].Value] = laFile; + } MelonLogger.Msg($"Loaded {jacketPaths.Count} custom jacket images."); } diff --git a/AquaMai/UX/RandomBgm.cs b/AquaMai/UX/RandomBgm.cs index e763a320..0f62a15a 100644 --- a/AquaMai/UX/RandomBgm.cs +++ b/AquaMai/UX/RandomBgm.cs @@ -18,6 +18,7 @@ public class RandomBgm [HarmonyPatch(typeof(SoundManager), "Initialize")] public static void Init() { + if (!Directory.Exists(Path.Combine(Environment.CurrentDirectory, "LocalAssets", "Mai2Cue"))) return; var files = Directory.EnumerateFiles(Path.Combine(Environment.CurrentDirectory, "LocalAssets", "Mai2Cue")); foreach (var file in files) { @@ -34,6 +35,7 @@ public static void Init() public static void PrePlay(ref SoundManager.AcbID acbID, int cueID) { if (acbID != SoundManager.AcbID.Default) return; + if (_acbs.Count == 0) return; var cueIndex = (Cue)cueID; switch (cueIndex) { @@ -69,4 +71,4 @@ public static bool PrePlayBGM(ref int target) } } } -} \ No newline at end of file +}