LogLoadingError() static private method

static private LogLoadingError ( string modFile, System.Version modBuildVersion, Exception e, bool recipes = false ) : void
modFile string
modBuildVersion System.Version
e System.Exception
recipes bool
return void
Ejemplo n.º 1
0
        private static bool VerifyNames(List <LoadingMod> mods)
        {
            var names = new HashSet <string>();

            foreach (var mod in mods)
            {
                try
                {
                    if (mod.Name.Length == 0)
                    {
                        throw new ModNameException("Mods must actually have stuff in their names");
                    }

                    if (mod.Name.Equals("Terraria", StringComparison.InvariantCultureIgnoreCase))
                    {
                        throw new ModNameException("Mods names cannot be named Terraria");
                    }

                    if (names.Contains(mod.Name))
                    {
                        throw new ModNameException("Two mods share the internal name " + mod.Name);
                    }

                    names.Add(mod.Name);
                }
                catch (Exception e)
                {
                    DisableMod(mod.modFile);
                    ErrorLogger.LogLoadingError(mod.Name, mod.modFile.tModLoaderVersion, e);
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 2
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);
            }
        }
Ejemplo n.º 3
0
        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)
            {
                foreach (var mod in modList.Where(mod => mod.properties.editAndContinue && mod.CanEaC))
                {
                    mod.EnableEaC();
                }
            }

            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);
                    var modType = mod.assembly.GetTypes().Single(t => t.IsSubclassOf(typeof(Mod)));
                    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);
        }
Ejemplo n.º 4
0
        internal static bool Load()
        {
            try
            {
                Interface.loadMods.SetLoadStage("tModLoader.MSIntializing", ModLoader.Mods.Length);
                LoadModContent(mod => {
                    mod.loading = true;
                    mod.File?.Read(TmodFile.LoadedState.Streaming, mod.LoadResourceFromStream);
                    mod.Autoload();
                    mod.Load();
                    mod.loading = false;
                });

                Interface.loadMods.SetLoadStage("tModLoader.MSSettingUp");
                ResizeArrays();
                RecipeGroupHelper.FixRecipeGroupLookups();

                Interface.loadMods.SetLoadStage("tModLoader.MSLoading", ModLoader.Mods.Length);
                LoadModContent(mod => {
                    mod.SetupContent();
                    mod.PostSetupContent();
                    mod.File?.UnloadAssets();
                });

                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();
                return(true);
            }
            catch (LoadingException e)
            {
                ModLoader.DisableMod(e.mod.Name);
                ErrorLogger.LogLoadingError(e.mod.Name, e.mod.Version, e.InnerException, e is AddRecipesException);
                Main.menuMode = Interface.errorMessageID;
                return(false);
            }
        }
Ejemplo n.º 5
0
        private static bool VerifyNames(List <LocalMod> mods)
        {
            var names = new HashSet <string>();

            foreach (var mod in mods)
            {
                try
                {
                    if (mod.Name.Length == 0)
                    {
                        throw new ModNameException(Language.GetTextValue("tModLoader.BuildErrorModNameEmpty"));
                    }

                    if (mod.Name.Equals("Terraria", StringComparison.InvariantCultureIgnoreCase))
                    {
                        throw new ModNameException(Language.GetTextValue("tModLoader.BuildErrorModNamedTerraria"));
                    }

                    if (names.Contains(mod.Name))
                    {
                        throw new ModNameException(Language.GetTextValue("tModLoader.BuildErrorTwoModsSameName", mod.Name));
                    }

                    if (mod.Name.IndexOf('.') >= 0)
                    {
                        throw new ModNameException(Language.GetTextValue("tModLoader.BuildErrorModNameHasPeriod"));
                    }

                    names.Add(mod.Name);
                }
                catch (Exception e)
                {
                    mod.Enabled = false;
                    ErrorLogger.LogLoadingError(mod.Name, mod.modFile.tModLoaderVersion, e);
                    Main.menuMode = Interface.errorMessageID;
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 6
0
        internal static void do_Load(object threadContext)
        {
            if (!LoadMods())
            {
                Main.menuMode = Interface.errorMessageID;
                return;
            }
            if (Main.dedServ)
            {
                Console.WriteLine(Language.GetTextValue("tModLoader.AddingModContent"));
            }
            int num = 0;

            foreach (Mod mod in mods.Values)
            {
                Interface.loadMods.SetProgressInit(mod.Name, num, mods.Count);
                try
                {
                    mod.loading = true;
                    mod.File?.Read(TmodFile.LoadedState.Streaming, mod.LoadResourceFromStream);
                    mod.Autoload();
                    Interface.loadMods.SetSubProgressInit("");
                    mod.Load();
                    mod.loading = false;
                }
                catch (Exception e)
                {
                    DisableMod(mod.Name);
                    ErrorLogger.LogLoadingError(mod.Name, mod.tModLoaderVersion, e);
                    Main.menuMode = Interface.errorMessageID;
                    return;
                }
                num++;
            }
            Interface.loadMods.SetProgressSetup(0f);
            ResizeArrays();
            RecipeGroupHelper.FixRecipeGroupLookups();
            num = 0;
            foreach (Mod mod in mods.Values)
            {
                Interface.loadMods.SetProgressLoad(mod.Name, num, mods.Count);
                try
                {
                    mod.SetupContent();
                    mod.PostSetupContent();
                    mod.File?.UnloadAssets();
                }
                catch (Exception e)
                {
                    DisableMod(mod.Name);
                    ErrorLogger.LogLoadingError(mod.Name, mod.tModLoaderVersion, e);
                    Main.menuMode = Interface.errorMessageID;
                    return;
                }
                num++;
            }
            RefreshModLanguage(Language.ActiveCulture);

            if (Main.dedServ)
            {
                ModNet.AssignNetIDs();
                //Main.player[0] = new Player();
            }
            Main.player[255] = new Player(false);             // setup inventory is unnecessary

            MapLoader.SetupModMap();
            ItemSorting.SetupWhiteLists();

            Interface.loadMods.SetProgressRecipes();
            for (int k = 0; k < Recipe.maxRecipes; k++)
            {
                Main.recipe[k] = new Recipe();
            }
            Recipe.numRecipes = 0;
            RecipeGroupHelper.ResetRecipeGroups();
            try
            {
                Recipe.SetupRecipes();
            }
            catch (AddRecipesException e)
            {
                ErrorLogger.LogLoadingError(e.modName, version, e.InnerException, true);
                Main.menuMode = Interface.errorMessageID;
                return;
            }

            if (PostLoad != null)
            {
                PostLoad();
                PostLoad = null;
            }
            else
            {
                Main.menuMode = 0;
            }
            GameInput.PlayerInput.ReInitialize();
        }
Ejemplo n.º 7
0
        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)
            {
                foreach (var mod in modList.Where(mod => mod.properties.editAndContinue && mod.CanEaC))
                {
                    mod.EnableEaC();
                }
            }

            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/bluemagic123/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);
        }
Ejemplo n.º 8
0
        internal static void do_Load(object threadContext)
        {
            if (!LoadMods())
            {
                Main.menuMode = Interface.errorMessageID;
                return;
            }
            if (Main.dedServ)
            {
                Console.WriteLine("Adding mod content...");
            }
            int num = 0;

            foreach (Mod mod in mods.Values)
            {
                Interface.loadMods.SetProgressInit(mod.Name, num, mods.Count);
                try
                {
                    mod.Autoload();
                    mod.Load();
                }
                catch (Exception e)
                {
                    DisableMod(mod.File);
                    ErrorLogger.LogLoadingError(mod.Name, mod.tModLoaderVersion, e);
                    Main.menuMode = Interface.errorMessageID;
                    return;
                }
                num++;
            }
            Interface.loadMods.SetProgressSetup(0f);
            ResizeArrays();
            num = 0;
            foreach (Mod mod in mods.Values)
            {
                Interface.loadMods.SetProgressLoad(mod.Name, num, mods.Count);
                try
                {
                    mod.SetupContent();
                    mod.PostSetupContent();
                }
                catch (Exception e)
                {
                    DisableMod(mod.File);
                    ErrorLogger.LogLoadingError(mod.Name, mod.tModLoaderVersion, e);
                    Main.menuMode = Interface.errorMessageID;
                    return;
                }
                num++;
            }

            if (Main.dedServ)
            {
                ModNet.AssignNetIDs();
            }

            MapLoader.SetupModMap();
            ItemSorting.SetupWhiteLists();

            Interface.loadMods.SetProgressRecipes();
            for (int k = 0; k < Recipe.maxRecipes; k++)
            {
                Main.recipe[k] = new Recipe();
            }
            Recipe.numRecipes = 0;
            RecipeGroupHelper.ResetRecipeGroups();
            try
            {
                Recipe.SetupRecipes();
            }
            catch (AddRecipesException e)
            {
                ErrorLogger.LogLoadingError(e.modName, version, e.InnerException, true);
                Main.menuMode = Interface.errorMessageID;
                return;
            }
            if (PostLoad != null)
            {
                PostLoad();
                PostLoad = null;
            }
            else
            {
                Main.menuMode = 0;
            }
            GameInput.PlayerInput.ReInitialize();
        }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
        private static void do_Load(object threadContext)
        {
            if (!LoadMods())
            {
                Main.menuMode = Interface.errorMessageID;
                return;
            }
            int num = 0;

            foreach (Mod mod in mods.Values)
            {
                Interface.loadMods.SetProgressInit(mod.Name, num, mods.Count);
                try
                {
                    mod.Autoload();
                    mod.Load();
                }
                catch (Exception e)
                {
                    DisableMod(mod.file);
                    ErrorLogger.LogLoadingError(mod.file, e);
                    Main.menuMode = Interface.errorMessageID;
                    return;
                }
                num++;
            }
            Interface.loadMods.SetProgressSetup(0f);
            ResizeArrays();
            num = 0;
            foreach (Mod mod in mods.Values)
            {
                Interface.loadMods.SetProgressLoad(mod.Name, num, mods.Count);
                try
                {
                    mod.SetupContent();
                    mod.PostSetupContent();
                }
                catch (Exception e)
                {
                    DisableMod(mod.file);
                    ErrorLogger.LogLoadingError(mod.file, e);
                    Main.menuMode = Interface.errorMessageID;
                    return;
                }
                num++;
            }
            MapLoader.SetupModMap();
            Interface.loadMods.SetProgressRecipes();
            for (int k = 0; k < Recipe.maxRecipes; k++)
            {
                Main.recipe[k] = new Recipe();
            }
            Recipe.numRecipes = 0;
            try
            {
                CraftGroup.ResetVanillaGroups();
                AddCraftGroups();
                Recipe.SetupRecipes();
            }
            catch (Exception e)
            {
                ErrorLogger.LogLoadingError("recipes", e);
                Main.menuMode = Interface.errorMessageID;
                return;
            }
            Main.menuMode = 0;
        }