diff --git a/S1API/UI/UIFactory.cs b/S1API/UI/UIFactory.cs index 831f68ab..fc3795a3 100644 --- a/S1API/UI/UIFactory.cs +++ b/S1API/UI/UIFactory.cs @@ -10,6 +10,8 @@ using System; using UnityEngine.Events; using System.Collections.Generic; +using MelonLoader; +using Object = UnityEngine.Object; namespace S1API.UI { @@ -239,8 +241,26 @@ public static void CreateRowButton(GameObject go, UnityAction clickHandler, bool /// The transform whose child objects will be destroyed. public static void ClearChildren(Transform parent) { - foreach (Transform child in parent) - GameObject.Destroy(child.gameObject); + if (parent == null) + { + return; + } + + try + { + int count = parent.childCount; + for (int i = count - 1; i >= 0; i--) + { + var child = parent.GetChild(i); + if (child != null) + Object.Destroy(child.gameObject); + } + + } + catch (System.Exception e) + { + return; + } } /// Configures a GameObject to use a VerticalLayoutGroup with specified spacing and padding. diff --git a/S1APILoader/S1APILoader.cs b/S1APILoader/S1APILoader.cs index 61a0d1ac..4c53f247 100644 --- a/S1APILoader/S1APILoader.cs +++ b/S1APILoader/S1APILoader.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using System.Reflection; using MelonLoader; [assembly: MelonInfo(typeof(S1APILoader.S1APILoader), "S1APILoader", "{VERSION_NUMBER}", "KaBooMa")] @@ -12,29 +13,25 @@ public class S1APILoader : MelonPlugin public override void OnPreModsLoaded() { - string? pluginsFolder = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); + string? pluginsFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); if (pluginsFolder == null) throw new Exception("Failed to identify plugins folder."); - string gameFolder = Path.Combine(pluginsFolder, ".."); - string modsFolder = Path.Combine(gameFolder, "Mods"); - string buildsFolder = Path.Combine(pluginsFolder, BuildFolderName); string activeBuild = MelonUtils.IsGameIl2Cpp() ? "Il2Cpp" : "Mono"; MelonLogger.Msg($"Loading S1API for {activeBuild}..."); string s1APIBuildFile = Path.Combine(buildsFolder, $"S1API.{activeBuild}.dll"); - - - string s1APIModFile = Path.Combine(modsFolder, "S1API.dll"); // FIX: https://github.com/KaBooMa/S1API/issues/30 - // Create the Mods directory. - // Thunderstore doesn't by default like MelonLoader in your base installation folder. - Directory.CreateDirectory(modsFolder); + // Manual assembly loading versus file manipulation. + // Thunderstore doesn't pick it up if we do file manipulation. + Assembly assembly = Assembly.LoadFile(s1APIBuildFile); + MelonAssembly melonAssembly = MelonAssembly.LoadMelonAssembly(s1APIBuildFile, assembly); + foreach (MelonBase melon in melonAssembly.LoadedMelons) + melon.Register(); - File.Copy(s1APIBuildFile, s1APIModFile, true); MelonLogger.Msg($"Successfully loaded S1API for {activeBuild}!"); } } diff --git a/S1APILoader/S1APILoader.csproj b/S1APILoader/S1APILoader.csproj index fd88de01..8d79d7be 100644 --- a/S1APILoader/S1APILoader.csproj +++ b/S1APILoader/S1APILoader.csproj @@ -14,6 +14,9 @@ + + $(MelonLoaderAssembliesPath)\0Harmony.dll +