private static Mod Instantiate(LoadedMod mod) { try { Type modType = mod.assembly.GetTypes().SingleOrDefault(t => t.IsSubclassOf(typeof(Mod))); if (modType == null) { throw new Exception(mod.Name + " does not have a class extending Mod. Mods need a Mod class to function.") { HelpLink = "https://github.com/blushiemagic/tModLoader/wiki/Basic-tModLoader-Modding-FAQ#sequence-contains-no-matching-element-error" } } ; var m = (Mod)Activator.CreateInstance(modType); m.File = mod.modFile; m.Code = mod.assembly; m.Logger = LogManager.GetLogger(m.Name); m.Side = mod.properties.side; m.DisplayName = mod.properties.displayName; m.tModLoaderVersion = mod.properties.buildVersion; return(m); } catch (Exception e) { e.Data["mod"] = mod.Name; throw; } finally { MemoryTracking.Update(mod.Name).code += mod.bytesLoaded; } }
private static void LoadModContent(CancellationToken token, ref List <Mod> mods, Action <Mod> loadAction) { MemoryTracking.Checkpoint(); int num = 0; foreach (var mod in ModLoader.Mods) { Interface.loadModsProgress.SetCurrentMod(num++, $"{mod.Name} v{mod.Version}"); try { if (!mods.Contains(mod)) { mods.Add(mod); } token.ThrowIfCancellationRequested(); LoadingMod = mod; loadAction(mod); token.ThrowIfCancellationRequested(); } catch (Exception e) { e.Data["mods"] = mods.Select(x => x.Name).ToArray(); throw; } finally { LoadingMod = null; MemoryTracking.Update(mod.Name); } } }
internal static void Load(CancellationToken token) { CacheVanillaState(); Interface.loadMods.SetLoadStage("tModLoader.MSIntializing", ModLoader.Mods.Length); LoadModContent(token, mod => { ContentInstance.Register(mod); mod.loading = true; mod.AutoloadConfig(); mod.PrepareAssets(); mod.Autoload(); mod.Load(); SystemHooks.OnModLoad(mod); mod.loading = false; }); Interface.loadMods.SetLoadStage("tModLoader.MSSettingUp"); ResizeArrays(); RecipeGroupHelper.FixRecipeGroupLookups(); Interface.loadMods.SetLoadStage("tModLoader.MSLoading", ModLoader.Mods.Length); LoadModContent(token, mod => { mod.SetupContent(); mod.PostSetupContent(); SystemHooks.PostSetupContent(mod); }); MemoryTracking.Finish(); if (Main.dedServ) { ModNet.AssignNetIDs(); } Main.player[255] = new Player(false); // setup inventory is unnecessary RefreshModLanguage(Language.ActiveCulture); MapLoader.SetupModMap(); RarityLoader.Initialize(); ContentSamples.Initialize(); PlayerInput.reinitialize = true; SetupBestiary(token); SetupRecipes(token); ContentSamples.RebuildItemCreativeSortingIDsAfterRecipesAreSetUp(); ItemSorting.SetupWhiteLists(); MenuLoader.GotoSavedModMenu(); BossBarLoader.GotoSavedStyle(); }
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 !MONO //as far as we know, mono doesn't support edit and continue anyway if (Debugger.IsAttached) { ModCompile.DeveloperMode = true; foreach (var mod in modList.Where(mod => mod.properties.editAndContinue && mod.CanEaC)) { mod.EnableEaC(); } } #endif 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(); }); //Assemblies must be loaded before any instantiation occurs to satisfy dependencies Interface.loadMods.SetLoadStage("tModLoader.MSInstantiating"); MemoryTracking.Checkpoint(); return(modList.Select(Instantiate).ToList()); } catch (AggregateException ae) { ae.Data["mods"] = ae.InnerExceptions.Select(e => (string)e.Data["mod"]).ToArray(); throw; } }
internal static void Load() { CacheVanillaState(); Interface.loadMods.SetLoadStage("tModLoader.MSIntializing", ModLoader.Mods.Length); MemoryTracking.Start(); LoadModContent(mod => { mod.AutoloadConfig(); mod.loading = true; mod.LoadResources(); mod.Autoload(); mod.Load(); mod.loading = false; MemoryTracking.Load(mod); }); Interface.loadMods.SetLoadStage("tModLoader.MSSettingUp"); ResizeArrays(); RecipeGroupHelper.FixRecipeGroupLookups(); MemoryTracking.MidReset(); Interface.loadMods.SetLoadStage("tModLoader.MSLoading", ModLoader.Mods.Length); LoadModContent(mod => { mod.SetupContent(); mod.PostSetupContent(); MemoryTracking.Finish(mod); }); if (Main.dedServ) { ModNet.AssignNetIDs(); } Main.player[255] = new Player(false); // setup inventory is unnecessary RefreshModLanguage(Language.ActiveCulture); MapLoader.SetupModMap(); ItemSorting.SetupWhiteLists(); PlayerInput.ReInitialize(); SetupRecipes(); }
private static void LoadModContent(Action <Mod> loadAction) { MemoryTracking.Checkpoint(); int num = 0; foreach (var mod in ModLoader.Mods) { Interface.loadMods.SetCurrentMod(num++, mod.Name); try { LoadingMod = mod; loadAction(mod); } catch (Exception e) { e.Data["mod"] = mod.Name; throw; } finally { LoadingMod = null; MemoryTracking.Update(mod.Name); } } }
private static void LoadModContent(CancellationToken token, Action <Mod> loadAction) { MemoryTracking.Checkpoint(); int num = 0; foreach (var mod in ModLoader.Mods) { token.ThrowIfCancellationRequested(); Interface.loadMods.SetCurrentMod(num++, $"{mod.Name} v{mod.Version}"); try { LoadingMod = mod; loadAction(mod); } catch (Exception e) { e.Data["mod"] = mod.Name; throw; } finally { LoadingMod = null; MemoryTracking.Update(mod.Name); } } }