Ejemplo n.º 1
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
            {
                modsToLoad = TopoSort(modsToLoad, false);
            }
            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);
        }
Ejemplo n.º 2
0
        private static void AddNoSyncDeps(List <Mod> syncMods)
        {
            var queue = new Queue <Mod>(syncMods.Where(m => m.Side == ModSide.Both));

            while (queue.Count > 0)
            {
                foreach (var dep in AssemblyManager.GetDependencies(queue.Dequeue()))
                {
                    if (dep.Side == ModSide.NoSync && !syncMods.Contains(dep))
                    {
                        syncMods.Add(dep);
                        queue.Enqueue(dep);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        internal static void RemoveAll(Mod mod)
        {
            if (mod is ModLoaderMod)
            {
                return;
            }

            int hooks = 0, detours = 0, ndetours = 0;

            bool OnHookUndo(object obj)
            {
                hooks++;
                return(true);
            }

            bool OnDetourUndo(object obj)
            {
                detours++;
                return(true);
            }

            bool OnNativeDetourUndo(object obj)
            {
                ndetours++;
                return(true);
            }

            Hook.OnUndo         += OnHookUndo;
            Detour.OnUndo       += OnDetourUndo;
            NativeDetour.OnUndo += OnNativeDetourUndo;

            foreach (var asm in AssemblyManager.GetModAssemblies(mod.Name))
            {
                manager.Unload(asm);
            }

            Hook.OnUndo         -= OnHookUndo;
            Detour.OnUndo       -= OnDetourUndo;
            NativeDetour.OnUndo -= OnNativeDetourUndo;

            if (hooks > 0 || detours > 0 || ndetours > 0)
            {
                Logging.tML.Debug($"Unloaded {hooks} hooks, {detours} detours and {ndetours} native detours from {mod.Name}");
            }
        }
Ejemplo n.º 4
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));
        }
Ejemplo n.º 5
0
        public static void PrettifyStackTraceSources(StackFrame[] frames)
        {
            if (frames == null)
            {
                return;
            }

            foreach (var frame in frames)
            {
                string filename = frame.GetFileName();
                var    assembly = frame.GetMethod()?.DeclaringType?.Assembly;
                if (filename == null || assembly == null)
                {
                    continue;
                }

                string trim;
                if (AssemblyManager.GetAssemblyOwner(assembly, out var modName))
                {
                    trim = modName;
                }
                else if (assembly == TerrariaAssembly)
                {
                    trim = "tModLoader";
                }
                else
                {
                    continue;
                }

                int idx = filename.LastIndexOf(trim, StringComparison.InvariantCultureIgnoreCase);
                if (idx > 0)
                {
                    filename = filename.Substring(idx);
                    f_fileName.SetValue(frame, filename);
                }
            }
        }
Ejemplo n.º 6
0
        private static ModuleDefinition GenerateCecilModule(AssemblyName name)
        {
            string resourceName = name.Name + ".dll";

            resourceName = Array.Find(typeof(Program).Assembly.GetManifestResourceNames(), element => element.EndsWith(resourceName));
            if (resourceName != null)
            {
                Logging.tML.DebugFormat("Generating ModuleDefinition for {0}", name);
                using (Stream stream = typeof(Program).Assembly.GetManifestResourceStream(resourceName))
                    return(ModuleDefinition.ReadModule(stream, new ReaderParameters(ReadingMode.Immediate)));
            }

            var modAssemblyBytes = AssemblyManager.GetAssemblyBytes(name.Name);

            if (modAssemblyBytes != null)
            {
                Logging.tML.DebugFormat("Generating ModuleDefinition for {0}", name);
                using (MemoryStream stream = new MemoryStream(modAssemblyBytes))
                    return(ModuleDefinition.ReadModule(stream, new ReaderParameters(ReadingMode.Immediate)));
            }

            return(null);
        }
Ejemplo n.º 7
0
        public static List <Mod> LoadMods()
        {
            CommandLineModPackOverride();

            // Alternate fix for updating enabled mods
            //foreach (string fileName in Directory.GetFiles(ModLoader.ModPath, "*.tmod.update", SearchOption.TopDirectoryOnly)) {
            //	File.Copy(fileName, Path.GetFileNameWithoutExtension(fileName), true);
            //	File.Delete(fileName);
            //}
            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() || ModLoader.skipLoad)
            {
                ModLoader.skipLoad = false;
                modsToLoad.Clear();
                Interface.loadMods.SetLoadStage("Loading Cancelled");
            }

            VerifyNames(modsToLoad);

            try {
                EnsureDependenciesExist(modsToLoad, false);
                EnsureTargetVersionsMet(modsToLoad);
                modsToLoad      = Sort(modsToLoad);
                dependencyCache = modsToLoad.ToDictionary(m => m.Name, m => m.properties.RefNames(false).ToList());
            }
            catch (ModSortingException e) {
                e.Data["mods"]           = e.errored.Select(m => m.Name).ToArray();
                e.Data["hideStackTrace"] = true;
                throw;
            }

            return(AssemblyManager.InstantiateMods(modsToLoad));
        }
Ejemplo n.º 8
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(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();
            foreach (var mod in modInstances)
            {
                loadOrder.Push(mod.Name);
                mods[mod.Name] = mod;
            }

            return(true);
        }