From 2ac822a4872dd1d5ebbd7c71f5c114b611e1d81f Mon Sep 17 00:00:00 2001 From: Terry Hearst Date: Mon, 4 Sep 2023 00:57:33 -0400 Subject: [PATCH] Solidify mod from config/directory errors --- Config.cs | 32 ++++++++++++++++++++------------ PatchEntryPoint.cs | 5 +++++ Shared.cs | 10 +++++----- 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/Config.cs b/Config.cs index a04cdc5..2640880 100644 --- a/Config.cs +++ b/Config.cs @@ -29,9 +29,13 @@ namespace CustomCosmeticLoader public static void Init() { - if (File.Exists(GetConfigPath())) + bool configExists = File.Exists(GetConfigPath()); + if (configExists) ReadConfig(); - else + + ensureSkinSelected(); + + if (!configExists && enabled) SaveConfig(); } @@ -62,16 +66,6 @@ namespace CustomCosmeticLoader if (data[PROPERTY_CURRENT_SKIN] != null) currentSkin = data[PROPERTY_CURRENT_SKIN].Value; - if (currentSkin == null || !skins.ContainsKey(currentSkin)) - { - if (skins.Count == 0) - { - Debug.LogWarning("No custom skins found, disabling"); - enabled = false; - return; - } - currentSkin = skins.Keys.ToList()[0]; - } if (data[PROPERTY_SKIN_NAME_TO_HIJACK] != null) skinNameToHijack = data[PROPERTY_SKIN_NAME_TO_HIJACK].Value; @@ -96,5 +90,19 @@ namespace CustomCosmeticLoader File.WriteAllText(GetConfigPath(), node.ToString()); } + + public static void ensureSkinSelected() + { + if (currentSkin == null || !skins.ContainsKey(currentSkin)) + { + if (skins.Count == 0) + { + Debug.LogWarning("No custom skins found, disabling"); + enabled = false; + return; + } + currentSkin = skins.Keys.ToList()[0]; + } + } } } diff --git a/PatchEntryPoint.cs b/PatchEntryPoint.cs index fbdf384..b6d0a00 100644 --- a/PatchEntryPoint.cs +++ b/PatchEntryPoint.cs @@ -32,6 +32,11 @@ namespace CustomCosmeticLoader { string skinsPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); skinsPath = Path.Combine(skinsPath, "skins"); + if (!Directory.Exists(skinsPath)) + { + Debug.Log(skinsPath + " directory does not exist, no skins to load"); + return; + } string printStr = "Loaded custom skins: "; foreach (string skinFile in Directory.GetFiles(skinsPath)) { diff --git a/Shared.cs b/Shared.cs index ef9403b..34e7a8c 100644 --- a/Shared.cs +++ b/Shared.cs @@ -6,21 +6,21 @@ namespace CustomCosmeticLoader public static class Shared { private static Cosmetic skinToHijack; - private static bool noSkinToHijack = false; public static Cosmetic SkinToHijack { get { - if (noSkinToHijack) - return null; if (skinToHijack == null) { DetermineSkinToHijack(); if (skinToHijack == null) - Debug.LogWarning("Couldn't hijack skin " + Config.skinNameToHijack); + { + Debug.LogWarning("Couldn't find skin " + Config.skinNameToHijack + " to hijack"); + Config.skinNameToHijack = "Swirl_M"; + DetermineSkinToHijack(); + } } - return skinToHijack; } }