48 lines
1.6 KiB
C#
48 lines
1.6 KiB
C#
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.Log.Debug("Loading client mod scripts for " + mod.WorkshopId);
|
|
loadScripts(__instance, mod.ModLocation, mod.GetModContext());
|
|
}
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
LogFile.Log.Debug("An error occured while loading client mods: " + e);
|
|
throw;
|
|
}
|
|
}
|
|
} |