static private InstantiateMods ( List |
||
modsToLoad | List |
|
return | List |
internal static List<Mod> InstantiateMods(List<ModLoader.LoadingMod> modsToLoad) {
var modList = new List<LoadedMod>();
foreach (var loading in modsToLoad) {
LoadedMod mod;
if (!loadedMods.TryGetValue(loading.Name, out mod))
mod = loadedMods[loading.Name] = new LoadedMod();
mod.SetMod(loading);
modList.Add(mod);
}
RecalculateReferences();
if (Debugger.IsAttached) {
foreach (var mod in modList.Where(mod => mod.properties.editAndContinue && mod.CanEaC))
mod.EnableEaC();
}
var modInstances = new List<Mod>();
int i = 0;
foreach (var mod in modList) {
Interface.loadMods.SetProgressCompatibility(mod.Name, i++, modsToLoad.Count);
try {
Interface.loadMods.SetProgressReading(mod.Name, 0, 1);
mod.LoadAssemblies();
Interface.loadMods.SetProgressReading(mod.Name, 1, 2);
var modType = mod.assembly.GetTypes().Single(t => t.IsSubclassOf(typeof(Mod)));
var m = (Mod)Activator.CreateInstance(modType);
m.File = mod.modFile;
m.Code = mod.assembly;
m.Side = mod.properties.side;
m.DisplayName = mod.properties.displayName;
modInstances.Add(m);
}
catch (Exception e) {
ModLoader.DisableMod(mod.modFile);
ErrorLogger.LogLoadingError(mod.Name, mod.modFile.tModLoaderVersion, e);
return null;
}
}
return modInstances;
}
}
public static List <Mod> LoadMods() { CommandLineModPackOverride(); Interface.loadMods.SetLoadStage("tModLoader.MSFinding"); var modsToLoad = FindMods().Where(mod => ModLoader.IsEnabled(mod.Name) && LoadSide(mod.properties.side)).ToList(); // Press shift while starting up tModLoader or while trapped in a reload cycle to skip loading all mods. if (Main.oldKeyState.PressingShift() || ModLoader.skipLoad) { ModLoader.skipLoad = false; modsToLoad.Clear(); Interface.loadMods.SetLoadStage("Loading Cancelled"); } VerifyNames(modsToLoad); try { EnsureDependenciesExist(modsToLoad, false); EnsureTargetVersionsMet(modsToLoad); modsToLoad = Sort(modsToLoad); dependencyCache = modsToLoad.ToDictionary(m => m.Name, m => m.properties.RefNames(false).ToList()); } catch (ModSortingException e) { e.Data["mods"] = e.errored.Select(m => m.Name).ToArray(); e.Data["hideStackTrace"] = true; throw; } return(AssemblyManager.InstantiateMods(modsToLoad)); }