Example #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);
        }
Example #2
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);
        }