Exemple #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 (!ReflectionLibraries.Get(currUi, "_localMod", out localmod))
            {
                LogLibraries.Warn("No '_localMod' field in " + currUi.GetType());
                return(null);
            }

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

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

            int modBrowserMenuMode;

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

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

            UIState modBrowserUi;

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

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

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

                if (isLoading)
                {
                    return(true);
                }

                ModMenuLibraries.ApplyModBrowserFilter("", false, new List <string>());
                return(false);
            });
        }
Exemple #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 (!ReflectionLibraries.Get(ui, "_localMod", out uiLocalmodField) || uiLocalmodField == null)
            {
                LogLibraries.Warn("No '_localMod' field in " + ui.GetType());
                return(null);
            }

            object localmod = uiLocalmodField.GetValue(ui);

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

            LogLibraries.Alert("No mod loaded.");
            return(null);
        }
        /// <summary>
        /// Loads the mod browser menu with a given set of mods to one-click bulk download
        /// (via. `ModMenuLibaries.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 = ReflectionLibraries.GetMainAssembly()
                                 .GetType("Terraria.ModLoader.UI.Interface");

            int modBrowserMenuMode;

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

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

            UIState modBrowserUi;

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

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

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

                if (isLoading)
                {
                    return(true);
                }

                ModMenuLibraries.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/ModLibsUI.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( !ReflectionLibaries.GetField<int>( interfaceType, null, "downloadModsID", out menuMode ) ) {
             *      LogLibaries.Log( "Could not switch to downloads menu." );
             *      return;
             * }
             * Main.PlaySound( SoundID.MenuTick );
             * Main.menuMode = menuMode;*/
        }