embed plugin loader directly into the launcher
This commit is contained in:
48
PluginLoader/Patch/Patch_MyScriptManager.cs
Normal file
48
PluginLoader/Patch/Patch_MyScriptManager.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using System.Reflection;
|
||||
using HarmonyLib;
|
||||
using PluginLoader.Data;
|
||||
using Sandbox.Game.World;
|
||||
using VRage.Game;
|
||||
|
||||
namespace PluginLoader.Patch;
|
||||
|
||||
[HarmonyPatch(typeof(MyScriptManager), "LoadData")]
|
||||
public static class Patch_MyScripManager
|
||||
{
|
||||
private static readonly Action<MyScriptManager, string, MyModContext> loadScripts;
|
||||
|
||||
static Patch_MyScripManager()
|
||||
{
|
||||
loadScripts = (Action<MyScriptManager, string, MyModContext>)Delegate.CreateDelegate(
|
||||
typeof(Action<MyScriptManager, string, MyModContext>),
|
||||
typeof(MyScriptManager).GetMethod("LoadScripts", BindingFlags.Instance | BindingFlags.NonPublic));
|
||||
}
|
||||
|
||||
public static void Postfix(MyScriptManager __instance)
|
||||
{
|
||||
try
|
||||
{
|
||||
HashSet<ulong> currentMods;
|
||||
if (MySession.Static.Mods != null)
|
||||
currentMods = new(MySession.Static.Mods.Select(x => x.PublishedFileId));
|
||||
else
|
||||
currentMods = new();
|
||||
|
||||
var list = Main.Instance.List;
|
||||
foreach (var id in Main.Instance.Config.EnabledPlugins)
|
||||
{
|
||||
var data = list[id];
|
||||
if (data is ModPlugin mod && !currentMods.Contains(mod.WorkshopId) && mod.Exists)
|
||||
{
|
||||
LogFile.WriteLine("Loading client mod scripts for " + mod.WorkshopId);
|
||||
loadScripts(__instance, mod.ModLocation, mod.GetModContext());
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogFile.WriteLine("An error occured while loading client mods: " + e);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user