mirror of
https://github.com/islehorse/HISP.git
synced 2025-05-24 12:06:25 +12:00
Make commands more accurate
This commit is contained in:
parent
997be8573d
commit
55c0f29914
14 changed files with 415 additions and 342 deletions
20
HorseIsleServer/LibHISP/Modding/IMod.cs
Normal file
20
HorseIsleServer/LibHISP/Modding/IMod.cs
Normal file
|
@ -0,0 +1,20 @@
|
|||
namespace HISP.Modding
|
||||
{
|
||||
public interface IMod
|
||||
{
|
||||
public void OnModLoad();
|
||||
public void OnModUnload();
|
||||
public string ModName
|
||||
{
|
||||
get;
|
||||
}
|
||||
public string ModVersion
|
||||
{
|
||||
get;
|
||||
}
|
||||
public string ModId
|
||||
{
|
||||
get;
|
||||
}
|
||||
}
|
||||
}
|
77
HorseIsleServer/LibHISP/Modding/ModLoader.cs
Normal file
77
HorseIsleServer/LibHISP/Modding/ModLoader.cs
Normal file
|
@ -0,0 +1,77 @@
|
|||
using HISP.Server;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace HISP.Modding
|
||||
{
|
||||
public class ModLoader
|
||||
{
|
||||
private static List<IMod> modList = new List<IMod>();
|
||||
public static IMod[] ModList
|
||||
{
|
||||
get
|
||||
{
|
||||
return modList.ToArray();
|
||||
}
|
||||
}
|
||||
public static void LoadMod(IMod mod)
|
||||
{
|
||||
mod.OnModLoad(); // Call OnModLoad();
|
||||
modList.Add(mod); // add to the list of mods
|
||||
Logger.InfoPrint("Loaded mod: "+mod.ModName + " v" + mod.ModVersion + " SUCCESS.");
|
||||
}
|
||||
public static void UnloadMod(IMod mod)
|
||||
{
|
||||
mod.OnModUnload();
|
||||
modList.Remove(mod);
|
||||
Logger.InfoPrint("Unloading mod: " + mod.ModName);
|
||||
}
|
||||
public static void UnloadAllMods()
|
||||
{
|
||||
foreach (IMod loadedMod in ModList)
|
||||
{
|
||||
UnloadMod(loadedMod);
|
||||
}
|
||||
}
|
||||
public static void LoadModFromFilesystem(string dllfile)
|
||||
{
|
||||
try
|
||||
{
|
||||
Assembly assembly = Assembly.LoadFile(dllfile);
|
||||
Type[] types = assembly.GetTypes();
|
||||
// Search for classes that implement IMod
|
||||
foreach (Type type in types)
|
||||
{
|
||||
if (type.GetInterfaces().Contains(typeof(IMod)))
|
||||
{
|
||||
IMod mod = (IMod)Activator.CreateInstance(type); // Crate an instance of the class
|
||||
LoadMod(mod); // Load it into memory
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.ErrorPrint("Failed to load mod: " + dllfile + " - [EXCEPTION]" + e.Message + " " + e.InnerException + "\n" + e.StackTrace);
|
||||
}
|
||||
}
|
||||
public static void OnShutdown()
|
||||
{
|
||||
UnloadAllMods();
|
||||
}
|
||||
public static void ReloadModsFromFilesystem()
|
||||
{
|
||||
UnloadAllMods();
|
||||
if (Directory.Exists(ConfigReader.ModsFolder))
|
||||
{
|
||||
string[] filelist = Directory.GetFiles(ConfigReader.ModsFolder, "*.dll", SearchOption.TopDirectoryOnly);
|
||||
foreach (string file in filelist)
|
||||
{
|
||||
LoadModFromFilesystem(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue