Example #1
0
        internal static void BuildModCommandLine(string modFolder)
        {
            // Once we get to this point, the application is guaranteed to exit
            var lockFile = AcquireConsoleBuildLock();

            try
            {
                var modCompile = new ModCompile(new ConsoleBuildStatus());
                if (!modCompile.Build(modFolder))
                {
                    Environment.Exit(1);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                Environment.Exit(1);
            }
            finally
            {
                lockFile.Close();
            }
            // Mod was built with success, exit code 0 indicates success.
            Environment.Exit(0);
        }
Example #2
0
 internal static void BuildAllMods()
 {
     ThreadPool.QueueUserWorkItem(_ =>
     {
         PostBuildMenu(ModCompile.BuildAll(FindModSources(), Interface.buildMod));
     });
 }
Example #3
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.isModder = true;
                foreach (var mod in modList.Where(mod => mod.properties.editAndContinue && mod.CanEaC))
                {
                    mod.EnableEaC();
                }
            }
            if (ModLoader.alwaysLogExceptions)
            {
                ModCompile.ActivateExceptionReporting();
            }

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

                //Assemblies must be loaded before any instantiation occurs to satisfy dependencies
                return(modList.Select(Instantiate).ToList());
            }
            catch (AggregateException ae)
            {
                ErrorLogger.LogMulti(ae.InnerExceptions.Select(e => new Action(() => {
                    var mod = modList.Single(m => m.Name == (string)e.Data["mod"]);
                    ModLoader.DisableMod(mod.Name);
                    ErrorLogger.LogLoadingError(mod.Name, mod.modFile.tModLoaderVersion, e);
                })));
                return(null);
            }
            catch (Exception e)
            {
                var mod = modList.Single(m => m.Name == (string)e.Data["mod"]);
                ModLoader.DisableMod(mod.Name);
                ErrorLogger.LogLoadingError(mod.Name, mod.modFile.tModLoaderVersion, e);
                return(null);
            }
        }
Example #4
0
        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(mod => 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())
            {
                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)
                {
                    mod.Enabled = false;
                }

                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);
        }
Example #5
0
        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);
        }
Example #6
0
 internal static void BuildMod()
 {
     Interface.buildMod.SetProgress(0, 1);
     ThreadPool.QueueUserWorkItem(_ =>
     {
         try
         {
             PostBuildMenu(ModCompile.Build(modToBuild, Interface.buildMod));
         }
         catch (Exception e)
         {
             ErrorLogger.LogException(e);
         }
     }, 1);
 }
Example #7
0
        public static List <Mod> LoadMods()
        {
            //load all referenced assemblies before mods for compiling
            ModCompile.LoadReferences();

            if (!CommandLineModPackOverride())
            {
                return(null);
            }

            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())
            {
                modsToLoad.Clear();
            }

            if (!VerifyNames(modsToLoad))
            {
                return(null);
            }

            try
            {
                EnsureDependenciesExist(modsToLoad, false);
                EnsureTargetVersionsMet(modsToLoad);
                modsToLoad = Sort(modsToLoad);
            }
            catch (ModSortingException e)
            {
                foreach (var mod in e.errored)
                {
                    mod.Enabled = false;
                }

                ErrorLogger.LogDependencyError(e.Message);
                Main.menuMode = Interface.errorMessageID;
                return(null);
            }

            return(AssemblyManager.InstantiateMods(modsToLoad));
        }
        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)
            {
                ModLoader.isModder = true;
                foreach (var mod in modList.Where(mod => mod.properties.editAndContinue && mod.CanEaC))
                {
                    mod.EnableEaC();
                }
            }
            if (ModLoader.alwaysLogExceptions)
            {
                ModCompile.ActivateExceptionReporting();
            }

            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);
                    Type modType;
                    try
                    {
                        modType = mod.assembly.GetTypes().Single(t => t.IsSubclassOf(typeof(Mod)));
                    }
                    catch (Exception e)
                    {
                        throw new Exception("It looks like this mod doesn't have a class extending Mod. Mods need a Mod class to function.", e)
                              {
                                  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.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);
        }