Ejemplo n.º 1
0
        /// <summary>
        /// Gets the mod name of a mod-representing menu UI (sometimes needs the previous UI for context).
        /// </summary>
        /// <param name="prevUi"></param>
        /// <param name="currUi"></param>
        /// <returns></returns>
        public static string GetModName(UIState prevUi, UIState currUi)
        {
            // = uiType.GetField( "_localMod", BindingFlags.NonPublic | BindingFlags.Instance );
            object localmod;                    // <- is a LocalMod class

            if (!ReflectionHelpers.Get(currUi, "_localMod", out localmod))
            {
                LogHelpers.Warn("No '_localMod' field in " + currUi.GetType());
                return(null);
            }

            if (localmod != null)
            {
                return(ModMenuHelpers.GetLocalMod(localmod).name);
            }
            else
            {
                if (prevUi?.GetType().Name == "UIModBrowser")
                {
                    return(ModMenuHelpers.GetSelectedModBrowserModName(prevUi));
                }
            }

            LogHelpers.Alert("No mod loaded.");
            return(null);
        }
        /// <summary>
        /// Loads the mod browser menu.
        /// </summary>
        public static void OpenModBrowserMenu()
        {
            Type interfaceType = ReflectionHelpers.GetMainAssembly()
                                 .GetType("Terraria.ModLoader.UI.Interface");

            int modBrowserMenuMode;

            if (!ReflectionHelpers.Get(interfaceType, null, "modBrowserID", out modBrowserMenuMode))
            {
                LogHelpers.Warn("Could not switch to mod browser menu context.");
                return;
            }

            Main.PlaySound(SoundID.MenuTick);
            Main.menuMode = modBrowserMenuMode;

            UIState modBrowserUi;

            if (!ReflectionHelpers.Get(interfaceType, null, "modBrowser", out modBrowserUi))
            {
                LogHelpers.Warn("Could not acquire mod browser UI.");
                return;
            }

            Timers.SetTimer("ModHelpersModDownloadPrompt", 5, () => {
                if (MenuContextService.GetCurrentMenuUI()?.GetType().Name != "UIModBrowser")
                {
                    return(false);
                }

                bool isLoading;
                if (!ReflectionHelpers.Get(modBrowserUi, "loading", out isLoading))
                {
                    return(false);
                }

                if (isLoading)
                {
                    return(true);
                }

                ModMenuHelpers.ApplyModBrowserFilter("", false, new List <string>());
                return(false);
            });
        }
Ejemplo n.º 3
0
        ////////////////

        /// <summary>
        /// Retrieves the file data for a given mod within a given mod-representing menu UI (typically the Mod Info menu page).
        /// </summary>
        /// <param name="ui"></param>
        /// <returns></returns>
        public static TmodFile GetModFile(UIState ui)
        {
            FieldInfo uiLocalmodField;            // = uiType.GetField( "_localMod", BindingFlags.NonPublic | BindingFlags.Instance );

            if (!ReflectionHelpers.Get(ui, "_localMod", out uiLocalmodField) || uiLocalmodField == null)
            {
                LogHelpers.Warn("No '_localMod' field in " + ui.GetType());
                return(null);
            }

            object localmod = uiLocalmodField.GetValue(ui);

            if (localmod != null)
            {
                return(ModMenuHelpers.GetLocalMod(localmod));
            }

            LogHelpers.Alert("No mod loaded.");
            return(null);
        }
        /// <summary>
        /// Loads the mod browser menu with a given set of mods to one-click bulk download
        /// (via. `ModMenuHelpers.ApplyModBrowserFilter(...)`).
        /// </summary>
        /// <param name="packTitle">Name of the set.</param>
        /// <param name="modNames">Mod (internal) names of the set.</param>
        public static void OpenModBrowserWithDownloadList(string packTitle, List <string> modNames)
        {
            Type interfaceType = ReflectionHelpers.GetMainAssembly()
                                 .GetType("Terraria.ModLoader.UI.Interface");

            int modBrowserMenuMode;

            if (!ReflectionHelpers.Get(interfaceType, null, "modBrowserID", out modBrowserMenuMode))
            {
                LogHelpers.Warn("Could not switch to mod browser menu context.");
                return;
            }

            Main.PlaySound(SoundID.MenuTick);
            Main.menuMode = modBrowserMenuMode;

            UIState modBrowserUi;

            if (!ReflectionHelpers.Get(interfaceType, null, "modBrowser", out modBrowserUi))
            {
                LogHelpers.Warn("Could not acquire mod browser UI.");
                return;
            }

            Timers.SetTimer("ModHelpersModDownloadPrompt", 5, () => {
                if (MenuContextService.GetCurrentMenuUI()?.GetType().Name != "UIModBrowser")
                {
                    return(false);
                }

                bool isLoading;
                if (!ReflectionHelpers.Get(modBrowserUi, "loading", out isLoading))
                {
                    return(false);
                }

                if (isLoading)
                {
                    return(true);
                }

                ModMenuHelpers.ApplyModBrowserFilter(packTitle, true, modNames);
                return(false);
            });

            /*Assembly tmlAsm = typeof( ModLoader ).Assembly;
             * Type interfaceType = tmlAsm.GetType( "Interface" );
             *
             * Type uiModDlType = tmlAsm.GetType( "UIModDownloadItem" );
             * object uiModDl = Activator.CreateInstance( uiModDlType, "ModName", "0.0.0", "hamstar", "", ModSide.Both, "", "http://javid.ddns.net/tModLoader/download.php?Down=mods/HamstarHelpers.tmod", 0, 0, "", false, false, null );
             * //UIModDownloadItem modItem = new UIModDownloadItem( displayname, name, version, author, modreferences, modside, modIconURL, download, downloads, hot, timeStamp, update, updateIsDowngrade, installed );
             * items.Add( modItem );
             *
             * Interface.downloadMods.SetDownloading( packTitle );
             * Interface.downloadMods.SetModsToDownload( modFilter, items );
             * Interface.modBrowser.updateNeeded = true;
             *
             * int menuMode;
             * if( !ReflectionHelpers.GetField<int>( interfaceType, null, "downloadModsID", out menuMode ) ) {
             *      LogHelpers.Log( "Could not switch to downloads menu." );
             *      return;
             * }
             * Main.PlaySound( SoundID.MenuTick );
             * Main.menuMode = menuMode;*/
        }