public static void LoadMods() { FileSystem.CheckDirectory(FileSystem.ModPath); HashSet <ProtoMod> foundMods = new HashSet <ProtoMod>(new ProtoMod.Comparer()); foreach (var jsonFile in Directory.GetFiles(FileSystem.ModPath, ModJson, SearchOption.AllDirectories)) { var mod = ProtoMod.ParseFromJson(jsonFile); if (!foundMods.Add(mod)) { throw new Exception("Found mod with duplicate id '" + mod.id + "' in " + jsonFile + "!"); } } DependencyChecker.CheckDependencies(foundMods); DiscoverAndLoadAssemblies(foundMods); }
/// <summary> /// Searches for valid mods and their assemblies, and decides the load order based on their settings /// </summary> internal static void InitializeMods() { FileSystem.CheckDirectory(FileSystem.ModPath); HashSet <ProtoMod> foundMods = new HashSet <ProtoMod>(new ProtoMod.Comparer()); // process mods without embedded modinfo.jsons foreach (var jsonFile in Directory.GetFiles(FileSystem.ModPath, ModJson, SearchOption.AllDirectories)) { var mod = ProtoMod.ParseFromJson(jsonFile); if (!foundMods.Add(mod)) { throw new Exception("Found mod with duplicate id '" + mod.id + "' in " + jsonFile + "!"); } } // process mods with embedded modinfo.jsons foreach (var dllFile in Directory.GetFiles(FileSystem.ModPath, "*.dll", SearchOption.AllDirectories)) { if (!ProtoMod.TryParseFromDLL(dllFile, out var mod) || mod.id == null) { continue; } if (!foundMods.Add(mod)) { throw new Exception("Found mod with duplicate id '" + mod.id + "' in " + dllFile + "!"); } } // Make sure all dependencies are in order, otherwise throw an exception from checkdependencies DependencyChecker.CheckDependencies(foundMods); DependencyChecker.CalculateLoadOrder(foundMods, loadOrder); // Start loading the assemblies DiscoverAndLoadAssemblies(foundMods); }