Exemple #1
0
        internal static List <Mod> InstantiateMods(List <LocalMod> modsToLoad)
        {
            var modList = new List <LoadedMod>();

            foreach (var loading in modsToLoad)
            {
                if (!loadedMods.TryGetValue(loading.Name, out LoadedMod mod))
                {
                    mod = loadedMods[loading.Name] = new LoadedMod();
                }

                mod.SetMod(loading);
                modList.Add(mod);
            }

            RecalculateReferences();

            if (Debugger.IsAttached)
            {
                ModLoader.SetModderMode();
                foreach (var mod in modList.Where(mod => mod.properties.editAndContinue && mod.CanEaC))
                {
                    mod.EnableEaC();
                }
            }

            try
            {
                //load all the assemblies in parallel.
                Interface.loadMods.SetLoadStage("tModLoader.MSSandboxing", modsToLoad.Count);
                int i = 0;
                Parallel.ForEach(modList, mod =>
                {
                    Interface.loadMods.SetCurrentMod(i++, mod.Name);
                    mod.LoadAssemblies();
                });

                Interface.loadMods.SetLoadStage("tModLoader.MSInstantiating");
                //Assemblies must be loaded before any instantiation occurs to satisfy dependencies
                return(modList.Select(Instantiate).ToList());
            }
            catch (AggregateException ae)
            {
                ae.Data["mods"] = ae.InnerExceptions.Select(e => (string)e.Data["mod"]);
                throw;
            }
        }