81 lines
2.1 KiB
C#
81 lines
2.1 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
|
|
/*
|
|
* Marble It Up! Ultra Mod Loader using UnityDoorstop
|
|
* For more details about UnityDoorstop: https://github.com/NeighTools/UnityDoorstop
|
|
*
|
|
* The original mod loader for Marble It Up! Classic was written by Elomith. This mod loader uses that as a starting
|
|
* point, and is largely the same thing with maybe a bit more error checking.
|
|
*/
|
|
namespace Doorstop
|
|
{
|
|
class Entrypoint
|
|
{
|
|
public static void Start()
|
|
{
|
|
Log("MIUU Mod loader started");
|
|
|
|
string assemblyDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
|
string modsDirectory = Directory.GetParent(assemblyDirectory).FullName;
|
|
|
|
foreach (string dir in Directory.GetDirectories(modsDirectory))
|
|
{
|
|
// Don't load ourselves again
|
|
if (dir == assemblyDirectory)
|
|
continue;
|
|
|
|
Log("Loading mod directory: " + dir);
|
|
|
|
foreach (string filename in Directory.GetFiles(dir))
|
|
{
|
|
if (filename.EndsWith(".dll"))
|
|
{
|
|
Log("Loading: " + filename);
|
|
|
|
try
|
|
{
|
|
Assembly assembly = Assembly.LoadFrom(filename);
|
|
Type entrypointType = assembly.GetTypes().FirstOrDefault((Type t) => t.Name == "PatchEntryPoint");
|
|
|
|
if (entrypointType == null)
|
|
{
|
|
Log("Entrypoint type not found");
|
|
continue;
|
|
}
|
|
|
|
MethodInfo entrypoint = entrypointType.GetMethod("Start", BindingFlags.Static | BindingFlags.Public);
|
|
if (entrypoint == null)
|
|
{
|
|
Log("Start method not found");
|
|
continue;
|
|
}
|
|
|
|
Log("Invoking entrypoint");
|
|
entrypoint.Invoke(null, new object[0]);
|
|
|
|
Log("Assembly successfully loaded");
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Log("Exception while loading " + filename + "!! " + e);
|
|
}
|
|
}
|
|
}
|
|
|
|
Log("Done loading mod");
|
|
}
|
|
}
|
|
|
|
private static void Log(string message)
|
|
{
|
|
// I want this to show up in the Unity output log but I think it literally loads too early lol
|
|
//Debug.Log("[MIUU MOD LOADER] " + message);
|
|
|
|
// Maybe at least this will be useful?
|
|
Console.WriteLine("[MIUU MOD LOADER] " + message);
|
|
}
|
|
}
|
|
}
|