init files
This commit is contained in:
parent
ccf325cf85
commit
54b9fd7596
9 changed files with 88180 additions and 0 deletions
64
src/Loader.cs
Normal file
64
src/Loader.cs
Normal file
|
@ -0,0 +1,64 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
namespace ModLoader
|
||||
{
|
||||
public static class Loader
|
||||
{
|
||||
public static void Log(string output)
|
||||
{
|
||||
Console.WriteLine("[BWML]" + output);
|
||||
//UnityEngine.Debug.Log("[BWML]" + output);
|
||||
}
|
||||
public static void Load()
|
||||
{
|
||||
Log("Starting mod loader...");
|
||||
|
||||
string dllpath = new System.Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).LocalPath;
|
||||
string Path = new FileInfo(dllpath).Directory.FullName;
|
||||
string modsPath = Path + "\\Mods";
|
||||
string assetsPath = modsPath + "\\Assets";
|
||||
|
||||
Log("Dll dir: "+Path);
|
||||
Log("Mods dir: "+modsPath);
|
||||
|
||||
if (!Directory.Exists(modsPath))
|
||||
{
|
||||
Directory.CreateDirectory(modsPath);
|
||||
}
|
||||
|
||||
if (!Directory.Exists(assetsPath))
|
||||
{
|
||||
Directory.CreateDirectory(assetsPath);
|
||||
}
|
||||
|
||||
DirectoryInfo d = new DirectoryInfo(modsPath);
|
||||
|
||||
GameObject modObjects = new GameObject();
|
||||
|
||||
//For each DLL in "Blackwake/Blackwake_Data/Managed/Mods/"
|
||||
//Open them, Get the mod class, then add it in the game.
|
||||
foreach (var file in d.GetFiles("*.dll"))
|
||||
{
|
||||
Assembly modDll = Assembly.LoadFrom(modsPath + "/" + file.Name);
|
||||
Type[] modType = modDll.GetTypes();
|
||||
foreach (Type t in modType)
|
||||
{
|
||||
Log("Found type in " + file.Name + ": " + t.Name);
|
||||
if (t.IsClass && t.IsSubclassOf(typeof(MonoBehaviour)))
|
||||
{
|
||||
Log("Loaded '" + t.Name + "' in " + file.Name);
|
||||
modObjects.AddComponent(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
Log("All Mods have been Loaded!");
|
||||
modObjects.AddComponent<ModGUI.ModGUI>();
|
||||
Log("GUI has been loaded");
|
||||
|
||||
//Keep mods active
|
||||
UnityEngine.Object.DontDestroyOnLoad(modObjects);
|
||||
}
|
||||
}
|
||||
}
|
14
src/ModGUI.cs
Normal file
14
src/ModGUI.cs
Normal file
|
@ -0,0 +1,14 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
namespace ModGUI
|
||||
{
|
||||
public class ModGUI : MonoBehaviour
|
||||
{
|
||||
void OnGUI()
|
||||
{
|
||||
GUI.color = Color.red;
|
||||
GUI.Label(new Rect(5f, 0f, 200f, 20f), "ModLoader v0.3");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue