Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions S1API/UI/UIFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
using System;
using UnityEngine.Events;
using System.Collections.Generic;
using MelonLoader;
using Object = UnityEngine.Object;

namespace S1API.UI
{
Expand Down Expand Up @@ -239,15 +241,33 @@
/// <param name="parent">The transform whose child objects will be destroyed.</param>
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)

Check warning on line 260 in S1API/UI/UIFactory.cs

View workflow job for this annotation

GitHub Actions / Build and Release

The variable 'e' is declared but never used
{
return;
}
}

/// Configures a GameObject to use a VerticalLayoutGroup with specified spacing and padding.
/// <param name="go">The GameObject to which a VerticalLayoutGroup will be added or configured.</param>
/// <param name="spacing">The spacing between child objects within the VerticalLayoutGroup. Default is 10.</param>
/// <param name="padding">The padding around the edges of the VerticalLayoutGroup. If null, a default RectOffset of (10, 10, 10, 10) will be used.</param>
public static void VerticalLayoutOnGO(GameObject go, int spacing = 10, RectOffset padding = null)

Check warning on line 270 in S1API/UI/UIFactory.cs

View workflow job for this annotation

GitHub Actions / Build and Release

Cannot convert null literal to non-nullable reference type.

Check warning on line 270 in S1API/UI/UIFactory.cs

View workflow job for this annotation

GitHub Actions / Build and Release

Cannot convert null literal to non-nullable reference type.
{
var layout = go.AddComponent<VerticalLayoutGroup>();
layout.spacing = spacing;
Expand Down Expand Up @@ -322,7 +342,7 @@
/// <param name="rightButtonText">The text to display on the optional button. Defaults to "Action" if not specified.</param>
/// <returns>The created GameObject representing the top bar.</returns>
public static GameObject TopBar(string name, Transform parent, string title,float buttonWidth,float buttonHeight,float topbarSize,int rectleft,int rectright,int recttop,int rectbottom,
Action onRightButtonClick = null,

Check warning on line 345 in S1API/UI/UIFactory.cs

View workflow job for this annotation

GitHub Actions / Build and Release

Cannot convert null literal to non-nullable reference type.

Check warning on line 345 in S1API/UI/UIFactory.cs

View workflow job for this annotation

GitHub Actions / Build and Release

Cannot convert null literal to non-nullable reference type.
string rightButtonText = "Action")
{
var topBar = Panel(name, parent, new Color(0.15f, 0.15f, 0.15f),
Expand Down
19 changes: 8 additions & 11 deletions S1APILoader/S1APILoader.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Reflection;
using MelonLoader;

[assembly: MelonInfo(typeof(S1APILoader.S1APILoader), "S1APILoader", "{VERSION_NUMBER}", "KaBooMa")]
Expand All @@ -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}!");
}
}
Expand Down
3 changes: 3 additions & 0 deletions S1APILoader/S1APILoader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
</PropertyGroup>

<ItemGroup>
<Reference Include="0Harmony">
<HintPath>$(MelonLoaderAssembliesPath)\0Harmony.dll</HintPath>
</Reference>
<PackageReference Include="LavaGang.MelonLoader" Version="0.7.0" />
</ItemGroup>

Expand Down
Loading