Skip to content

Commit d8cbbe0

Browse files
authored
Merge pull request #34 from KaBooMa/bleeding-edge
Bleeding edge
2 parents f69a393 + b3cd304 commit d8cbbe0

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

S1API/UI/UIFactory.cs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
using System;
1111
using UnityEngine.Events;
1212
using System.Collections.Generic;
13+
using MelonLoader;
14+
using Object = UnityEngine.Object;
1315

1416
namespace S1API.UI
1517
{
@@ -239,8 +241,26 @@ public static void CreateRowButton(GameObject go, UnityAction clickHandler, bool
239241
/// <param name="parent">The transform whose child objects will be destroyed.</param>
240242
public static void ClearChildren(Transform parent)
241243
{
242-
foreach (Transform child in parent)
243-
GameObject.Destroy(child.gameObject);
244+
if (parent == null)
245+
{
246+
return;
247+
}
248+
249+
try
250+
{
251+
int count = parent.childCount;
252+
for (int i = count - 1; i >= 0; i--)
253+
{
254+
var child = parent.GetChild(i);
255+
if (child != null)
256+
Object.Destroy(child.gameObject);
257+
}
258+
259+
}
260+
catch (System.Exception e)
261+
{
262+
return;
263+
}
244264
}
245265

246266
/// Configures a GameObject to use a VerticalLayoutGroup with specified spacing and padding.

S1APILoader/S1APILoader.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.IO;
3+
using System.Reflection;
34
using MelonLoader;
45

56
[assembly: MelonInfo(typeof(S1APILoader.S1APILoader), "S1APILoader", "{VERSION_NUMBER}", "KaBooMa")]
@@ -12,24 +13,25 @@ public class S1APILoader : MelonPlugin
1213

1314
public override void OnPreModsLoaded()
1415
{
15-
string? pluginsFolder = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
16+
string? pluginsFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
1617
if (pluginsFolder == null)
1718
throw new Exception("Failed to identify plugins folder.");
1819

19-
string gameFolder = Path.Combine(pluginsFolder, "..");
20-
string modsFolder = Path.Combine(gameFolder, "Mods");
21-
2220
string buildsFolder = Path.Combine(pluginsFolder, BuildFolderName);
2321

2422
string activeBuild = MelonUtils.IsGameIl2Cpp() ? "Il2Cpp" : "Mono";
2523
MelonLogger.Msg($"Loading S1API for {activeBuild}...");
2624

2725
string s1APIBuildFile = Path.Combine(buildsFolder, $"S1API.{activeBuild}.dll");
28-
2926

30-
string s1APIModFile = Path.Combine(modsFolder, "S1API.dll");
27+
// FIX: https://github.com/KaBooMa/S1API/issues/30
28+
// Manual assembly loading versus file manipulation.
29+
// Thunderstore doesn't pick it up if we do file manipulation.
30+
Assembly assembly = Assembly.LoadFile(s1APIBuildFile);
31+
MelonAssembly melonAssembly = MelonAssembly.LoadMelonAssembly(s1APIBuildFile, assembly);
32+
foreach (MelonBase melon in melonAssembly.LoadedMelons)
33+
melon.Register();
3134

32-
File.Copy(s1APIBuildFile, s1APIModFile, true);
3335
MelonLogger.Msg($"Successfully loaded S1API for {activeBuild}!");
3436
}
3537
}

S1APILoader/S1APILoader.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
</PropertyGroup>
1515

1616
<ItemGroup>
17+
<Reference Include="0Harmony">
18+
<HintPath>$(MelonLoaderAssembliesPath)\0Harmony.dll</HintPath>
19+
</Reference>
1720
<PackageReference Include="LavaGang.MelonLoader" Version="0.7.0" />
1821
</ItemGroup>
1922

0 commit comments

Comments
 (0)