From f2f26daeecc42ee310d4620db9ddd5556f347ec8 Mon Sep 17 00:00:00 2001 From: MagicJinn Date: Sun, 3 Nov 2024 18:52:26 +0100 Subject: [PATCH 1/7] custom tips and misc fixes --- Plugin.cs | 49 +++++++++++++++++++++++++++++---------------- SSSLoadingHelper.cs | 23 ++++++++++++++------- 2 files changed, 48 insertions(+), 24 deletions(-) diff --git a/Plugin.cs b/Plugin.cs index bdf15a5..498158b 100644 --- a/Plugin.cs +++ b/Plugin.cs @@ -13,17 +13,15 @@ namespace SSSoftcoded { - [BepInPlugin("mod.clevercrumbish.SSSoftcoded", "Sunless Sea Softcoded", "1.0.0")] + [BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)] public class Plugin : BaseUnityPlugin { - private void Start() - { - SSSLoadingHelper.Initialise(); - SSSLoadingHelper.DocumentAllCustomContent(); - } private void Awake() { Logger.LogInfo($"Loaded {PluginInfo.PLUGIN_GUID} {PluginInfo.PLUGIN_VERSION}!"); + SSSLoadingHelper.Initialise(); + SSSLoadingHelper.DocumentAllCustomContent(); + DoPatching(); } @@ -35,22 +33,39 @@ private void DoPatching() Harmony.CreateAndPatchAll(typeof(StopAmbientFXPatch)); Harmony.CreateAndPatchAll(typeof(PlayRegularSFXPatch)); Harmony.CreateAndPatchAll(typeof(StopRegularSFXPatch)); + CustomLoadingScreenTips(); + } + + private static void CustomLoadingScreenTips() + { + string[] oldTips = StaticEntities.LoadingScreenTips; + string[] customTips = SSSLoadingHelper.GetCustomLoadingScreenTips(); + + List newTips = customTips.ToList(); + + if (!SSSLoadingHelper.ignoreVanillaLoadingScreenTips) + { + // Add old tips to the loading tips list + newTips.AddRange(oldTips); + } + StaticEntities.LoadingScreenTips = newTips.ToArray(); } } +} - [HarmonyPatch(typeof(LoadingScreen), "SetupBackground")] - class SetupBackgroundPatch +[HarmonyPatch(typeof(LoadingScreen), "SetupBackground")] +class SetupBackgroundPatch +{ + static bool Prefix(LoadingScreen __instance) { - static bool Prefix(LoadingScreen __instance) + GameObject gameObject = GameObject.Find("Wallpaper"); + SSSLoadableResource[] wallpapers = SSSLoadingHelper.GetCustomWallPapers(); + SSSLoadableResource chosenWallpaper = wallpapers[UnityEngine.Random.Range(0, wallpapers.Length - 1)]; + Texture2D texture2D; + if (chosenWallpaper.GetExtension() != "") { - GameObject gameObject = GameObject.Find("Wallpaper"); - SSSLoadableResource[] wallpapers = SSSLoadingHelper.GetCustomWallPapers(); - SSSLoadableResource chosenWallpaper = wallpapers[UnityEngine.Random.Range(0, wallpapers.Length - 1)]; - Texture2D texture2D; - if (chosenWallpaper.GetExtension() != "") - { - texture2D = SSSLoadingHelper.LoadWallpaperTexture(chosenWallpaper); - } else + texture2D = SSSLoadingHelper.LoadWallpaperTexture(chosenWallpaper); + } else { texture2D = UnityEngine.Resources.Load("UI/Loading/Backgrounds/" + chosenWallpaper.GetName()) as Texture2D; } diff --git a/SSSLoadingHelper.cs b/SSSLoadingHelper.cs index eefa6a3..e007fb8 100644 --- a/SSSLoadingHelper.cs +++ b/SSSLoadingHelper.cs @@ -18,12 +18,15 @@ public static class SSSLoadingHelper private static string regularSFXFilePath = GameProvider.Instance.GetApplicationPath("audio/sfx/"); private static bool ignoreVanillaWallpapers = false; + public static bool ignoreVanillaLoadingScreenTips = false; private static SSSLoadableResource[] customWallpapers; private static SSSLoadableResource[] customMusicTracks; private static SSSLoadableResource[] customAmbientSFX; private static SSSLoadableResource[] customRegularSFX; + private static string[] customLoadingScreenTips; + private static List loadedAmbientSFX = new List(); private static List loadedRegularSFX = new List(); @@ -36,19 +39,16 @@ public static void Initialise() foreach (var s in lines) { - s.Trim(); + string line = s.Trim(); - if (s.StartsWith("#") || s.StartsWith("[")) - { - continue; - } - else if (s.Contains("=")) + if (line.Contains("=")) { - string[] split = s.Split('='); + string[] split = line.Split('='); optionsDict.Add(split[0], split[1]); } } + if (optionsDict["customWallpapers"] != "") { wallpaperFilePath = CorrectFilePath(optionsDict["customWallpapers"]); @@ -69,6 +69,10 @@ public static void Initialise() { ignoreVanillaWallpapers = true; } + if (optionsDict["ignoreVanillaLoadingScreenTips"] == "true") + { + ignoreVanillaLoadingScreenTips = true; + } } else { System.Console.WriteLine("Couldn't find SSSConfig.ini in the Sunless Sea root folder. Only default settings will be available"); @@ -253,6 +257,11 @@ public static SSSLoadableResource[] GetCustomWallPapers() return customWallpapers; } + public static string[] GetCustomLoadingScreenTips() + { + return customLoadingScreenTips; + } + public static SSSLoadableResource[] GetCustomMusicTracks() { return customMusicTracks; From ba9a45e9eb121294355b26040bc772653ab3d03a Mon Sep 17 00:00:00 2001 From: MagicJinn Date: Sun, 3 Nov 2024 18:53:41 +0100 Subject: [PATCH 2/7] Update SSSLoadingHelper.cs --- SSSLoadingHelper.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/SSSLoadingHelper.cs b/SSSLoadingHelper.cs index e007fb8..84a366a 100644 --- a/SSSLoadingHelper.cs +++ b/SSSLoadingHelper.cs @@ -48,7 +48,6 @@ public static void Initialise() } } - if (optionsDict["customWallpapers"] != "") { wallpaperFilePath = CorrectFilePath(optionsDict["customWallpapers"]); From e712d668dc52180f50fee2ab1cc3408f0f152b60 Mon Sep 17 00:00:00 2001 From: MagicJinn Date: Mon, 4 Nov 2024 00:57:33 +0100 Subject: [PATCH 3/7] Update SSSoftcoded.csproj --- SSSoftcoded.csproj | 1 - 1 file changed, 1 deletion(-) diff --git a/SSSoftcoded.csproj b/SSSoftcoded.csproj index 37539d0..5634dcf 100644 --- a/SSSoftcoded.csproj +++ b/SSSoftcoded.csproj @@ -3,7 +3,6 @@ net35 SSSoftcoded - My first plugin 1.0.0 true latest From caf00d6318734a5e0022e8e556034007b99975a4 Mon Sep 17 00:00:00 2001 From: MagicJinn Date: Mon, 4 Nov 2024 01:00:29 +0100 Subject: [PATCH 4/7] fixed incorrect bracket --- Plugin.cs | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/Plugin.cs b/Plugin.cs index 498158b..93f3c84 100644 --- a/Plugin.cs +++ b/Plugin.cs @@ -51,21 +51,22 @@ private static void CustomLoadingScreenTips() StaticEntities.LoadingScreenTips = newTips.ToArray(); } } -} -[HarmonyPatch(typeof(LoadingScreen), "SetupBackground")] -class SetupBackgroundPatch -{ - static bool Prefix(LoadingScreen __instance) + + [HarmonyPatch(typeof(LoadingScreen), "SetupBackground")] + class SetupBackgroundPatch { - GameObject gameObject = GameObject.Find("Wallpaper"); - SSSLoadableResource[] wallpapers = SSSLoadingHelper.GetCustomWallPapers(); - SSSLoadableResource chosenWallpaper = wallpapers[UnityEngine.Random.Range(0, wallpapers.Length - 1)]; - Texture2D texture2D; - if (chosenWallpaper.GetExtension() != "") + static bool Prefix(LoadingScreen __instance) { - texture2D = SSSLoadingHelper.LoadWallpaperTexture(chosenWallpaper); - } else + GameObject gameObject = GameObject.Find("Wallpaper"); + SSSLoadableResource[] wallpapers = SSSLoadingHelper.GetCustomWallPapers(); + SSSLoadableResource chosenWallpaper = wallpapers[UnityEngine.Random.Range(0, wallpapers.Length - 1)]; + Texture2D texture2D; + if (chosenWallpaper.GetExtension() != "") + { + texture2D = SSSLoadingHelper.LoadWallpaperTexture(chosenWallpaper); + } + else { texture2D = UnityEngine.Resources.Load("UI/Loading/Backgrounds/" + chosenWallpaper.GetName()) as Texture2D; } From 980239da904ab71a4f2172db3f91acd5381e0783 Mon Sep 17 00:00:00 2001 From: MagicJinn Date: Thu, 7 Nov 2024 19:50:25 +0100 Subject: [PATCH 5/7] Fix Awake using game functions, causing Zubmariner disabling --- Plugin.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Plugin.cs b/Plugin.cs index 93f3c84..9eb2564 100644 --- a/Plugin.cs +++ b/Plugin.cs @@ -19,10 +19,14 @@ public class Plugin : BaseUnityPlugin private void Awake() { Logger.LogInfo($"Loaded {PluginInfo.PLUGIN_GUID} {PluginInfo.PLUGIN_VERSION}!"); + DoPatching(); + } + + private void Start() + { SSSLoadingHelper.Initialise(); SSSLoadingHelper.DocumentAllCustomContent(); - - DoPatching(); + CustomLoadingScreenTips(); } private void DoPatching() @@ -33,7 +37,6 @@ private void DoPatching() Harmony.CreateAndPatchAll(typeof(StopAmbientFXPatch)); Harmony.CreateAndPatchAll(typeof(PlayRegularSFXPatch)); Harmony.CreateAndPatchAll(typeof(StopRegularSFXPatch)); - CustomLoadingScreenTips(); } private static void CustomLoadingScreenTips() From 346f2a08e185454258b818dcd4b685dac6632413 Mon Sep 17 00:00:00 2001 From: MagicJinn Date: Thu, 7 Nov 2024 19:54:51 +0100 Subject: [PATCH 6/7] Add fallback for when 0 tips are provided --- Plugin.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Plugin.cs b/Plugin.cs index 9eb2564..6be47c1 100644 --- a/Plugin.cs +++ b/Plugin.cs @@ -51,6 +51,12 @@ private static void CustomLoadingScreenTips() // Add old tips to the loading tips list newTips.AddRange(oldTips); } + else if (customTips.Length == 0) // if the user ignores vanilla tips, but doesn't provide their own + { + // Add a fallback tip to prevent a crash, and to inform the user of the fact they've disabled vanilla tips without providing new ones + newTips.Add("Ignore Vanilla Loading Screen Tips is enabled, but no custom tips have been provided."); + } + StaticEntities.LoadingScreenTips = newTips.ToArray(); } } From 66c14c24d42e2d1c90090b5f9b64718910955b21 Mon Sep 17 00:00:00 2001 From: MagicJinn Date: Thu, 7 Nov 2024 20:01:54 +0100 Subject: [PATCH 7/7] Fix minor config edge case --- SSSLoadingHelper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SSSLoadingHelper.cs b/SSSLoadingHelper.cs index 84a366a..c0fc04a 100644 --- a/SSSLoadingHelper.cs +++ b/SSSLoadingHelper.cs @@ -39,7 +39,7 @@ public static void Initialise() foreach (var s in lines) { - string line = s.Trim(); + string line = s.Replace(" ", ""); if (line.Contains("=")) {