Skip to content

Commit

Permalink
Start MelonHandler.cs, Streamlined Generics setup for Melons
Browse files Browse the repository at this point in the history
  • Loading branch information
RinLovesYou committed Jan 7, 2024
1 parent 1b8a553 commit df74724
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 2 deletions.
3 changes: 3 additions & 0 deletions MelonLoader/MelonLoader.Shared/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Text;
using HarmonyLib;
using MelonLoader.Interfaces;
using MelonLoader.Melons;
using MelonLoader.Properties;

namespace MelonLoader
Expand Down Expand Up @@ -36,6 +37,8 @@ public static void Startup(string engineModulePath)
module.Initialize();

MelonUtils.Setup(AppDomain.CurrentDomain);

MelonHandler.LoadMelonsFromDirectory<MelonPlugin>(MelonEnvironment.PluginsDirectory);
}

public static void OnApplicationPreStart()
Expand Down
11 changes: 9 additions & 2 deletions MelonLoader/MelonLoader.Shared/Melons/MelonBase.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
using HarmonyLib;

namespace MelonLoader.Melons;

public abstract class MelonBase
public abstract class MelonBase<T> where T : MelonBase<T>
{
private MelonInfoAttribute[] _games = new MelonInfoAttribute[0];
public MelonInfoAttribute Info { get; private set; }
public Harmony HarmonyInstance { get; private set; }

public static string TypeName { get; protected internal set; }

static MelonBase() => System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(typeof(T).TypeHandle);

public virtual void OnEarlyInitializeMelon() { }
public virtual void OnInitializeMelon() { }
Expand Down
12 changes: 12 additions & 0 deletions MelonLoader/MelonLoader.Shared/Melons/MelonHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using MelonLoader.Utils;

namespace MelonLoader.Melons;

public static class MelonHandler
{
public static void LoadMelonsFromDirectory<T>(string path) where T : MelonBase<T>
{
MelonLogger.WriteSpacer();
MelonLogger.Msg($"Loading {MelonBase<T>.TypeName}s from '{path}'...");
}
}
7 changes: 7 additions & 0 deletions MelonLoader/MelonLoader.Shared/Melons/MelonMod.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace MelonLoader.Melons;

public abstract class MelonMod : MelonBase<MelonMod>
{
static MelonMod() => TypeName = "Mod";

}
6 changes: 6 additions & 0 deletions MelonLoader/MelonLoader.Shared/Melons/MelonPlugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace MelonLoader.Melons;

public abstract class MelonPlugin : MelonBase<MelonPlugin>
{
static MelonPlugin() => TypeName = "Plugin";
}

0 comments on commit df74724

Please sign in to comment.