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;
}
}