37 lines
1.1 KiB
C#
37 lines
1.1 KiB
C#
using HarmonyLib;
|
|
using PluginLoader.Data;
|
|
using Sandbox.Definitions;
|
|
using VRage.Game;
|
|
|
|
namespace PluginLoader.Patch;
|
|
|
|
[HarmonyPatch(typeof(MyDefinitionManager), "LoadData")]
|
|
public static class Patch_MyDefinitionManager
|
|
{
|
|
public static void Prefix(ref List<MyObjectBuilder_Checkpoint.ModItem> mods)
|
|
{
|
|
try
|
|
{
|
|
var currentMods = new HashSet<ulong>(mods.Select(x => x.PublishedFileId));
|
|
var newMods = new List<MyObjectBuilder_Checkpoint.ModItem>(mods);
|
|
|
|
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 definitions for " + mod.WorkshopId);
|
|
newMods.Add(mod.GetModItem());
|
|
}
|
|
}
|
|
|
|
mods = newMods;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
LogFile.WriteLine("An error occured while loading client mods: " + e);
|
|
throw;
|
|
}
|
|
}
|
|
} |