private static bool LoadMods() { //load all referenced assemblies before mods for compiling ModCompile.LoadReferences(); Interface.loadMods.SetProgressFinding(); var modsToLoad = FindMods() .Where(IsEnabled) .Select(mod => new LoadingMod(mod, BuildProperties.ReadModFile(mod))) .Where(mod => LoadSide(mod.properties.side)) .ToList(); if (!VerifyNames(modsToLoad)) { return(false); } try { EnsureDependenciesExist(modsToLoad, false); EnsureTargetVersionsMet(modsToLoad); modsToLoad = Sort(modsToLoad); } catch (ModSortingException e) { foreach (var mod in e.errored) { DisableMod(mod.modFile); } ErrorLogger.LogDependencyError(e.Message); return(false); } var modInstances = AssemblyManager.InstantiateMods(modsToLoad); if (modInstances == null) { return(false); } modInstances.Insert(0, new ModLoaderMod()); loadedMods = modInstances.ToArray(); foreach (var mod in modInstances) { loadOrder.Push(mod.Name); mods[mod.Name] = mod; } return(true); }
internal static bool BuildAll(string[] modFolders, IBuildStatus status) { var modList = new List <LoadingMod>(); foreach (var modFolder in modFolders) { var mod = ReadProperties(modFolder, status); if (mod == null) { return(false); } modList.Add(mod); } foreach (var modFile in FindMods()) { if (modList.Exists(m => m.Name == modFile.name)) { continue; } modList.Add(new LoadingMod(modFile, BuildProperties.ReadModFile(modFile))); } List <BuildingMod> modsToBuild; try { EnsureDependenciesExist(modList, true); EnsureTargetVersionsMet(modList); var sortedModList = Sort(modList); modsToBuild = sortedModList.OfType <BuildingMod>().ToList(); } catch (ModSortingException e) { ErrorLogger.LogDependencyError(e.Message); return(false); } int num = 0; foreach (var mod in modsToBuild) { status.SetProgress(num++, modsToBuild.Count); if (!Build(mod, status)) { return(false); } } return(true); }
private static bool FindReferencedMods(BuildProperties properties, Dictionary <string, LoadingMod> mods) { foreach (var refName in properties.RefNames(true)) { if (mods.ContainsKey(refName)) { continue; } var modFile = new TmodFile(Path.Combine(ModPath, refName + ".tmod")); modFile.Read(); var ex = modFile.ValidMod(); if (ex != null) { ErrorLogger.LogBuildError("Mod reference " + refName + " " + ex); return(false); } var mod = new LoadingMod(modFile, BuildProperties.ReadModFile(modFile)); mods[refName] = mod; FindReferencedMods(mod.properties, mods); } return(true); }
internal static bool BuildAll(string[] modFolders, IBuildStatus status) { var modList = new List <LoadingMod>(); //read mod sources folder foreach (var modFolder in modFolders) { var mod = ReadProperties(modFolder, status); if (mod == null) { return(false); } modList.Add(mod); } //figure out which of the installed mods are required for building var installedMods = FindMods() .Where(mod => !modList.Exists(m => m.Name == mod.name)) .Select(mod => new LoadingMod(mod, BuildProperties.ReadModFile(mod))) .ToList(); var requiredFromInstall = new HashSet <LoadingMod>(); Action <LoadingMod> require = null; require = (mod) => { foreach (var dep in mod.properties.RefNames(true)) { var depMod = installedMods.SingleOrDefault(m => m.Name == dep); if (depMod != null && requiredFromInstall.Add(depMod)) { require(depMod); } } }; foreach (var mod in modList) { require(mod); } modList.AddRange(requiredFromInstall); //sort and version check List <BuildingMod> modsToBuild; try { EnsureDependenciesExist(modList, true); EnsureTargetVersionsMet(modList); var sortedModList = Sort(modList); modsToBuild = sortedModList.OfType <BuildingMod>().ToList(); } catch (ModSortingException e) { ErrorLogger.LogDependencyError(e.Message); return(false); } //build int num = 0; foreach (var mod in modsToBuild) { status.SetProgress(num++, modsToBuild.Count); if (!Build(mod, status)) { return(false); } } return(true); }
private static bool LoadMods() { //load all referenced assemblies before mods for compiling ModCompile.LoadReferences(); if (!CommandLineModPackOverride()) { return(false); } Interface.loadMods.SetProgressFinding(); var modsToLoad = FindMods() .Where(IsEnabled) .Select(mod => new LoadingMod(mod, BuildProperties.ReadModFile(mod))) .Where(mod => 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()) { modsToLoad.Clear(); } if (!VerifyNames(modsToLoad)) { return(false); } try { EnsureDependenciesExist(modsToLoad, false); EnsureTargetVersionsMet(modsToLoad); modsToLoad = Sort(modsToLoad); } catch (ModSortingException e) { foreach (var mod in e.errored) { DisableMod(mod.modFile); } ErrorLogger.LogDependencyError(e.Message); return(false); } var modInstances = AssemblyManager.InstantiateMods(modsToLoad); if (modInstances == null) { return(false); } modInstances.Insert(0, new ModLoaderMod()); loadedMods = modInstances.ToArray(); loadedModsWeakReferences = loadedMods.Skip(1).Select(x => new WeakReference(x)).ToArray(); foreach (var mod in modInstances) { loadOrder.Push(mod.Name); mods[mod.Name] = mod; } return(true); }
internal static void ServerModMenu() { bool exit = false; while (!exit) { Console.WriteLine("Terraria Server " + Main.versionNumber2 + " - " + ModLoader.versionedName); Console.WriteLine(); TmodFile[] mods = ModLoader.FindMods(); for (int k = 0; k < mods.Length; k++) { BuildProperties properties = BuildProperties.ReadModFile(mods[k]); string name = properties.displayName; name = mods[k].name; string line = (k + 1) + "\t\t" + name + "("; line += (ModLoader.IsEnabled(mods[k]) ? "enabled" : "disabled") + ")"; Console.WriteLine(line); } Console.WriteLine("e\t\tEnable All"); Console.WriteLine("d\t\tDisable All"); Console.WriteLine("r\t\tReload and return to world menu"); Console.WriteLine("Type a number to switch between enabled/disabled"); Console.WriteLine(); Console.WriteLine("Type a command: "); string command = Console.ReadLine(); if (command == null) { command = ""; } command = command.ToLower(); Console.Clear(); if (command == "e") { foreach (TmodFile mod in mods) { ModLoader.EnableMod(mod); } } else if (command == "d") { foreach (TmodFile mod in mods) { ModLoader.DisableMod(mod); } } else if (command == "r") { Console.WriteLine("Unloading mods..."); ModLoader.Unload(); ModLoader.do_Load(null); exit = true; } else { int value; if (Int32.TryParse(command, out value)) { value--; if (value >= 0 && value < mods.Length) { ModLoader.SetModActive(mods[value], !ModLoader.IsEnabled(mods[value])); } } } } }
private static bool LoadMods() { Interface.loadMods.SetProgressFinding(); TmodFile[] modFiles = FindMods(); List <TmodFile> enabledMods = new List <TmodFile>(); foreach (TmodFile modFile in modFiles) { if (IsEnabled(modFile.Name)) { enabledMods.Add(modFile); } } IDictionary <string, BuildProperties> properties = new Dictionary <string, BuildProperties>(); List <TmodFile> modsToLoad = new List <TmodFile>(); foreach (TmodFile modFile in enabledMods) { properties[modFile.Name] = BuildProperties.ReadModFile(modFile); modsToLoad.Add(modFile); } int previousCount = 0; int num = 0; Mod defaultMod = new ModLoaderMod(); defaultMod.Init(); mods[defaultMod.Name] = defaultMod; loadedMods.Add(defaultMod.Name); while (modsToLoad.Count > 0 && modsToLoad.Count != previousCount) { previousCount = modsToLoad.Count; int k = 0; while (k < modsToLoad.Count) { bool canLoad = true; foreach (string reference in properties[modsToLoad[k].Name].modReferences) { if (!ModLoaded(ModPath + Path.DirectorySeparatorChar + reference + ".tmod")) { canLoad = false; break; } } if (canLoad) { Interface.loadMods.SetProgressCompatibility(Path.GetFileNameWithoutExtension(modsToLoad[k].Name), num, enabledMods.Count); try { LoadMod(modsToLoad[k], properties[modsToLoad[k].Name]); } catch (Exception e) { DisableMod(modsToLoad[k].Name); ErrorLogger.LogLoadingError(modsToLoad[k].Name, e); return(false); } loadedMods.Add(modsToLoad[k].Name); num++; modsToLoad.RemoveAt(k); } else { k++; } } } if (modsToLoad.Count > 0) { foreach (TmodFile modFile in modsToLoad) { DisableMod(modFile.Name); } ErrorLogger.LogMissingLoadReference(modsToLoad); return(false); } return(true); }
internal static void ServerModMenu() { bool exit = false; while (!exit) { Console.WriteLine("Terraria Server " + Main.versionNumber2 + " - " + ModLoader.versionedName); Console.WriteLine(); TmodFile[] mods = ModLoader.FindMods(); for (int k = 0; k < mods.Length; k++) { BuildProperties properties = BuildProperties.ReadModFile(mods[k]); string name = properties.displayName; name = mods[k].name; string line = (k + 1) + "\t\t" + name + "("; line += (ModLoader.IsEnabled(mods[k]) ? "enabled" : "disabled") + ")"; Console.WriteLine(line); } if (mods.Length == 0) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine($"No mods were found in: \"{ModLoader.ModPath}\"\nIf you are running a dedicated server, you may wish to use the 'modpath' command line switch or server config setting to specify a custom mods directory.\n"); Console.ResetColor(); } Console.WriteLine("e\t\tEnable All"); Console.WriteLine("d\t\tDisable All"); Console.WriteLine("r\t\tReload and return to world menu"); Console.WriteLine("Type a number to switch between enabled/disabled"); Console.WriteLine(); Console.WriteLine("Type a command: "); string command = Console.ReadLine(); if (command == null) { command = ""; } command = command.ToLower(); Console.Clear(); if (command == "e") { foreach (TmodFile mod in mods) { ModLoader.EnableMod(mod); } } else if (command == "d") { foreach (TmodFile mod in mods) { ModLoader.DisableMod(mod); } } else if (command == "r") { Console.WriteLine("Unloading mods..."); ModLoader.Unload(); ModLoader.do_Load(null); exit = true; } else { int value; if (Int32.TryParse(command, out value)) { value--; if (value >= 0 && value < mods.Length) { ModLoader.SetModActive(mods[value], !ModLoader.IsEnabled(mods[value])); } } } } }