示例#1
0
        ////////////////

        private void SubmitIssue()
        {
            if (this.CurrentModListItem == null)
            {
                return;
            }
            if (!ModFeaturesHelpers.HasGithub(this.CurrentModListItem.Mod))
            {
                return;
            }

            UIModControlPanelTab self = this;
            string issueTitle         = this.IssueTitleInput.Text;
            string issueBody          = this.IssueBodyInput.Text;

            if (string.IsNullOrEmpty(issueTitle) || string.IsNullOrEmpty(issueBody))
            {
                return;
            }

            this.AwaitingReport = true;
            this.DisableIssueInput();

            self.Logic.ReportIssue(self.CurrentModListItem.Mod, issueTitle, issueBody, delegate {
                self.AwaitingReport  = false;
                self.ResetIssueInput = true;
                self.RequestClose    = true;
            });
        }
        ////////////////

        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            if (this.AwaitingReport || this.CurrentModListItem == null || !ModFeaturesHelpers.HasGithub(this.CurrentModListItem.Mod))
            {
                this.DisableIssueInput();
            }
            else
            {
                this.EnableIssueInput();
            }

            if (this.ResetIssueInput)
            {
                this.ResetIssueInput = false;
                this.IssueTitleInput.SetText("");
                this.IssueBodyInput.SetText("");
            }

            if (this.RequestClose)
            {
                this.RequestClose = false;
                ControlPanelTabs.CloseDialog();
                return;
            }

            this.UpdateElements();
        }
示例#3
0
        ////////////////

        /// <summary>
        /// Defines the sort order position of this element relative to another object (typically another UIModData element).
        /// </summary>
        /// <param name="obj">Other object to compare rank against.</param>
        /// <returns>Greater than (+1), less than (-1), or equal to (0) comparison status.</returns>
        public override int CompareTo(object obj)
        {
            var other = obj as UIModData;

            if (other == null)                  // Other object types are always sorted less than UIModData
            {
                return(1);
            }

            // Always sort own mod to top; this mod's configs should be available first
            if (other.Mod.Name == ModHelpersMod.Instance.Name)
            {
                return(1);
            }
            else if (this.Mod.Name == ModHelpersMod.Instance.Name)
            {
                return(-1);
            }

            try {
                // Prioritize github'd mods
                if (ModFeaturesHelpers.HasGithub(this.Mod) && !ModFeaturesHelpers.HasGithub(other.Mod))
                {
                    return(-1);
                }
                else if (!ModFeaturesHelpers.HasGithub(this.Mod) && ModFeaturesHelpers.HasGithub(other.Mod))
                {
                    return(1);
                }
            } catch { }

            return(string.Compare(other.Mod.Name, this.Mod.Name));
        }
        public static void ReportIssue(Mod mod, string issueTitle, string issueBody, Action <string> onSuccess, Action <Exception, string> onError, Action onCompletion = null)
        {
            if (!ModFeaturesHelpers.HasGithub(mod))
            {
                throw new HamstarException("Mod is not eligable for submitting issues.");
            }

            int maxLines = ModHelpersMod.Instance.Config.ModIssueReportErrorLogMaxLines;

            IEnumerable <Mod> mods       = ModListHelpers.GetAllLoadedModsPreferredOrder();
            string            bodyInfo   = string.Join("\n \n", InfoHelpers.GetGameData(mods).ToArray());
            string            bodyErrors = string.Join("\n", InfoHelpers.GetErrorLog(maxLines).ToArray());

            string url   = "http://hamstar.pw/hamstarhelpers/issue_submit/";
            string title = "Reported from in-game: " + issueTitle;
            string body  = bodyInfo;

            body += "\n \n \n \n" + "Recent error logs:\n```\n" + bodyErrors + "\n```";
            body += "\n \n" + issueBody;

            var json = new GithubModIssueReportData {
                githubuser    = ModFeaturesHelpers.GetGithubUserName(mod),
                githubproject = ModFeaturesHelpers.GetGithubProjectName(mod),
                title         = title,
                body          = body
            };
            string jsonStr = JsonConvert.SerializeObject(json, Formatting.Indented);

            byte[] jsonBytes = Encoding.UTF8.GetBytes(jsonStr);

            Action <String> onResponse = (output) => {
                JObject respJson = JObject.Parse(output);
                //JToken data = respJson.SelectToken( "Data.html_url" );
                JToken msg = respJson.SelectToken("Msg");

                /*if( data != null ) {
                 *      string post_at_url = data.ToObject<string>();
                 *      if( !string.IsNullOrEmpty( post_at_url ) ) {
                 *              SystemHelpers.Start( post_at_url );
                 *      }
                 * }*/

                if (msg == null)
                {
                    onSuccess("Failure.");
                }
                else
                {
                    onSuccess(msg.ToObject <string>());
                }
            };

            Action <Exception, string> wrappedOnError = (Exception e, string str) => {
                LogHelpers.Log("!ModHelpers.PostGithubModIssueReports.ReportIssue - Failed for POST to " + url + " : " + jsonStr);
                onError(e, str);
            };

            NetHelpers.MakePostRequestAsync(url, jsonBytes, onResponse, wrappedOnError, onCompletion);
        }
示例#5
0
        public void UnloadModules()
        {
            this.Loadables.OnModsUnload();

            this.Loadables                  = null;
            this.ReflectionHelpers          = null;
            this.PacketProtocolMngr         = null;
            this.ExceptionMngr              = null;
            this.Timers                     = null;
            this.LogHelpers                 = null;
            this.ModFeaturesHelpers         = null;
            this.BuffHelpers                = null;
            this.NetHelpers                 = null;
            this.NPCAttributeHelpers        = null;
            this.ProjectileAttributeHelpers = null;
            this.BuffIdentityHelpers        = null;
            this.NPCBannerHelpers           = null;
            this.RecipeFinderHelpers        = null;
            this.RecipeGroupHelpers         = null;
            this.PlayerHooks                = null;
            this.LoadHelpers                = null;
            this.GetModInfo                 = null;
            this.GetModTags                 = null;
            this.WorldStateHelpers          = null;
            this.ModLock                    = null;
            this.EntityGroups               = null;
            this.AnimatedColors             = null;
            this.AnimatedTextures           = null;
            this.PlayerMessages             = null;
            this.Inbox                 = null;
            this.ControlPanel          = null;
            this.MenuItemMngr          = null;
            this.MenuContextMngr       = null;
            this.MusicHelpers          = null;
            this.PlayerIdentityHelpers = null;
            this.LoadHooks             = null;
            this.CustomLoadHooks       = null;
            this.DataStore             = null;
            this.CustomHotkeys         = null;
            this.XnaHelpers            = null;
            this.Server                = null;
            //this.PlayerDataMngr = null;
            this.SupportInfo          = null;
            this.RecipeHack           = null;
            this.ModListHelpers       = null;
            this.ItemAttributeHelpers = null;
            this.WorldTimeHooks       = null;

            this.ControlPanelHotkey = null;
            this.DataDumpHotkey     = null;
        }
        public static void RefreshConfigs()
        {
            if (Main.netMode != 0)
            {
                throw new UsageException("Cannot refresh configs in multiplayer.", Color.Red);
            }

            var mymod = ModHelpersMod.Instance;

            foreach (var kv in mymod.ModFeaturesHelpers.ConfigMods)
            {
                ModFeaturesHelpers.ReloadConfigFromFile(kv.Value);
            }
        }
        public void UnloadOuter()
        {
            this.ReflectionHelpers         = null;
            this.PacketProtocolMngr        = null;
            this.ExceptionMngr             = null;
            this.Timers                    = null;
            this.ConfigJson                = null;
            this.LogHelpers                = null;
            this.ModFeaturesHelpers        = null;
            this.BuffHelpers               = null;
            this.NetHelpers                = null;
            this.ItemIdentityHelpers       = null;
            this.NPCIdentityHelpers        = null;
            this.ProjectileIdentityHelpers = null;
            this.BuffIdentityHelpers       = null;
            this.NPCBannerHelpers          = null;
            this.RecipeIdentityHelpers     = null;
            this.RecipeGroupHelpers        = null;
            this.PlayerHooks               = null;
            this.LoadHelpers               = null;
            this.GetModInfo                = null;
            this.GetModTags                = null;
            this.WorldStateHelpers         = null;
            this.ModLock                   = null;
            this.EntityGroups              = null;
            this.AnimatedColors            = null;
            this.PlayerMessages            = null;
            this.Inbox                 = null;
            this.ControlPanel          = null;
            this.MenuItemMngr          = null;
            this.MenuContextMngr       = null;
            this.MusicHelpers          = null;
            this.PlayerIdentityHelpers = null;
            this.CustomEntMngr         = null;
            this.Promises              = null;
            this.DataStore             = null;
            this.CustomHotkeys         = null;
            this.XnaHelpers            = null;
            this.ServerInfo            = null;
            //this.PlayerDataMngr = null;
            this.SupportInfo    = null;
            this.RecipeHack     = null;
            this.ModListHelpers = null;

            this.ControlPanelHotkey = null;
            this.DataDumpHotkey     = null;
        }
示例#8
0
        private void LoadModules()
        {
            this.Loadables.OnModsLoad();

            this.ReflectionHelpers = new ReflectionHelpers();
            this.DataStore         = new DataStore();
            this.LoadHooks         = new LoadHooks();
            this.CustomLoadHooks   = new CustomLoadHooks();
            this.LoadHelpers       = new LoadHelpers();

            this.Timers             = new Timers();
            this.LogHelpers         = new LogHelpers();
            this.ModFeaturesHelpers = new ModFeaturesHelpers();
            this.PacketProtocolMngr = new PacketProtocolManager();

            this.BuffHelpers                = new BuffHelpers();
            this.NetHelpers                 = new NetPlayHelpers();
            this.NPCAttributeHelpers        = new NPCAttributeHelpers();
            this.ProjectileAttributeHelpers = new ProjectileAttributeHelpers();
            this.BuffIdentityHelpers        = new BuffAttributesHelpers();
            this.NPCBannerHelpers           = new NPCBannerHelpers();
            this.RecipeFinderHelpers        = new RecipeFinderHelpers();
            this.RecipeGroupHelpers         = new RecipeGroupHelpers();
            this.PlayerHooks                = new ExtendedPlayerHooks();
            this.WorldTimeHooks             = new WorldTimeHooks();
            this.WorldStateHelpers          = new WorldStateHelpers();
            this.ControlPanel               = new UIControlPanel();
            this.ModLock               = new ModLockService();
            this.EntityGroups          = new EntityGroups();
            this.PlayerMessages        = new PlayerMessages();
            this.Inbox                 = new InboxControl();
            this.GetModInfo            = new GetModInfo();
            this.GetModTags            = new GetModTags();
            this.MenuItemMngr          = new MenuItemManager();
            this.MenuContextMngr       = new MenuContextServiceManager();
            this.MusicHelpers          = new MusicHelpers();
            this.PlayerIdentityHelpers = new PlayerIdentityHelpers();
            this.CustomHotkeys         = new CustomHotkeys();
            this.XnaHelpers            = new XNAHelpers();
            this.Server                = new Server();
            //this.PlayerDataMngr = new PlayerDataManager();
            this.SupportInfo          = new SupportInfoDisplay();
            this.RecipeHack           = new RecipeHack();
            this.ModListHelpers       = new ModListHelpers();
            this.ItemAttributeHelpers = new ItemAttributeHelpers();
        }
        ////////////////

        private void SelectModFromList(UIModData listItem)
        {
            Mod mod = listItem.Mod;

            if (this.CurrentModListItem != null)
            {
                this.Theme.ApplyListItem(this.CurrentModListItem);
            }
            this.Theme.ApplyListItemSelected(listItem);
            this.CurrentModListItem = listItem;

            this.Logic.SetCurrentMod(mod);

            if (!ModFeaturesHelpers.HasGithub(mod))
            {
                this.DisableIssueInput();
            }
            else
            {
                this.EnableIssueInput();
            }
        }
        public static void ReportIssue(Mod mod, string issueTitle, string issueBody,
                                       Action <Exception, string> onError,
                                       Action <bool, string> onCompletion)
        {
            if (!ModFeaturesHelpers.HasGithub(mod))
            {
                throw new ModHelpersException("Mod is not eligable for submitting issues.");
            }

            int maxLines = ModHelpersMod.Config.ModIssueReportErrorLogMaxLines;

            IEnumerable <Mod> mods       = ModListHelpers.GetAllLoadedModsPreferredOrder();
            string            bodyInfo   = string.Join("\n \n", FormattedGameInfoHelpers.GetFormattedGameInfo(mods).ToArray());
            string            bodyErrors = string.Join("\n", GameInfoHelpers.GetErrorLog(maxLines).ToArray());

            string url   = "http://hamstar.pw/hamstarhelpers/issue_submit/";
            string title = "Reported from in-game: " + issueTitle;
            string body  = bodyInfo;

            body += "\n \n \n \n" + "Recent error logs:\n```\n" + bodyErrors + "\n```";
            body += "\n \n" + issueBody;

            var json = new GithubModIssueReportData {
                githubuser    = ModFeaturesHelpers.GetGithubUserName(mod),
                githubproject = ModFeaturesHelpers.GetGithubProjectName(mod),
                title         = title,
                body          = body
            };
            string jsonStr = JsonConvert.SerializeObject(json, Formatting.Indented);

            Action <bool, string> wrappedOnCompletion = (success, output) => {
                string processedOutput = "";

                if (success)
                {
                    JObject respJson = JObject.Parse(output);
                    JToken  data     = respJson.SelectToken("Data.html_url");
                    JToken  msg      = respJson.SelectToken("Msg");

                    if (data != null)
                    {
                        string issueUrl = data.ToObject <string>();
                        if (!string.IsNullOrEmpty(issueUrl))
                        {
                            SystemHelpers.OpenUrl(issueUrl);
                        }
                    }

                    success = msg != null;
                    if (success)
                    {
                        processedOutput = msg.ToObject <string>();
                    }
                    else
                    {
                        processedOutput = "Failure.";
                    }
                }

                onCompletion(success, processedOutput);
            };

            Action <Exception, string> wrappedOnError = (Exception e, string str) => {
                LogHelpers.Log("!ModHelpers.PostGithubModIssueReports.ReportIssue - Failed for POST to " + url + " : " + jsonStr);
                onError(e, str);
            };

            WebConnectionHelpers.MakePostRequestAsync(url, jsonStr, e => wrappedOnError(e, ""), wrappedOnCompletion);
        }
 public static bool HasGithub(Mod mod)
 {
     return(ModFeaturesHelpers.HasGithub(mod));
 }
        private void InitializeMe(UITheme theme, int?idx, Mod mod, bool willDrawOwnHoverElements = true)
        {
            var      self    = this;
            TmodFile modfile = mod.File;

            this.Mod = mod;
            this.WillDrawOwnHoverElements = willDrawOwnHoverElements;

            this.Author                 = null;
            this.HomepageUrl            = null;
            this.HasIconLoaded          = false;
            this.LatestAvailableVersion = default(Version);

            if (ModHelpersMod.Instance.Config.IsCheckingModVersions)
            {
                Services.Tml.BuildPropertiesEditor props = modfile != null?
                                                           Services.Tml.BuildPropertiesEditor.GetBuildPropertiesForModFile(modfile) :
                                                               (Services.Tml.BuildPropertiesEditor)null;

                if (props != null)
                {
                    this.Author      = (string)props.GetField("author");
                    this.HomepageUrl = (string)props.GetField("homepage");
                }
            }

            // Container

            this.SetPadding(4f);
            this.Width.Set(0f, 1f);
            this.Height.Set(64, 0f);

            float titleOffset = 72f;

            // Mod index

            if (idx != null)
            {
                var modIdxElem = new UIText((int)idx + "");
                modIdxElem.Left.Set(titleOffset, 0f);
                this.Append((UIElement)modIdxElem);

                titleOffset += 16f;
            }

            // Mod title

            string modTitle = this.Mod.DisplayName + " " + this.Mod.Version.ToString();

            if (!String.IsNullOrEmpty(this.HomepageUrl))
            {
                this.TitleElem = new UIWebUrl(theme, modTitle, this.HomepageUrl, false);
            }
            else
            {
                this.TitleElem = new UIText(modTitle);
            }
            this.TitleElem.Left.Set(88f, 0f);
            this.Append((UIElement)this.TitleElem);

            // Mod author

            if (this.Author != null)
            {
                this.AuthorElem = new UIText("By: " + this.Author, 0.7f);
                this.AuthorElem.Top.Set(20f, 0f);
                this.AuthorElem.Left.Set(titleOffset, 0f);
                this.Append((UIElement)this.AuthorElem);
            }

            // Mod icon

            if (modfile != null && modfile.HasFile("icon.png"))
            {
                if (!Main.dedServ)                      //...?
                {
                    try {
                        var stream  = new MemoryStream(modfile.GetFile("icon.png"));
                        var iconTex = Texture2D.FromStream(Main.graphics.GraphicsDevice, stream);

                        if (iconTex.Width == 80 && iconTex.Height == 80)
                        {
                            this.IconElem = new UIImage(iconTex);
                            this.IconElem.Top.Set(-4f, 0f);
                            this.IconElem.Left.Set(-4f, 0f);
                            this.IconElem.MarginTop  = -8f;
                            this.IconElem.MarginLeft = -4f;
                            this.IconElem.ImageScale = 0.7f;
                            this.Append(this.IconElem);
                        }
                    } catch (Exception e) {
                        LogHelpers.Warn(e.ToString());
                    }
                }
            }

            // Mod config button

            if (ModFeaturesHelpers.HasConfig(mod))
            {
                if (Main.netMode == 0)
                {
                    if (ModFeaturesHelpers.HasConfigDefaultsReset(mod))
                    {
                        this.ConfigResetButton = new UITextPanelButton(theme, "Reset Config File");
                        this.ConfigResetButton.Width.Set(160f, 0f);
                        this.ConfigResetButton.Left.Set(-320f, 1f);
                        this.ConfigResetButton.Top.Set(28, 0f);
                        this.Append(this.ConfigResetButton);

                        this.ConfigResetButton.OnClick += delegate(UIMouseEvent evt, UIElement fromElem) {
                            string msg = mod.DisplayName + " config file reset to defaults.";

                            ModFeaturesHelpers.ResetDefaultsConfig(mod);
                            Main.NewText(msg, Color.Lime);
                            LogHelpers.Log(msg);
                        };
                    }

                    this.ConfigOpenButton = new UITextPanelButton(theme, "Open Config File");
                    this.ConfigOpenButton.Width.Set(160f, 0f);
                    this.ConfigOpenButton.Top.Set(28, 0f);
                    this.ConfigOpenButton.HAlign = 1f;
                    this.Append(this.ConfigOpenButton);

                    this.ConfigOpenButton.OnClick += delegate(UIMouseEvent evt, UIElement fromElem) {
                        string path     = ModFeaturesHelpers.GetConfigRelativePath(mod);
                        string fullpath = Main.SavePath + Path.DirectorySeparatorChar + path;

                        try {
                            Process.Start(fullpath);
                        } catch (Exception e) {
                            try {
                                string dir = new FileInfo(fullpath).Directory.FullName;
                                Process.Start(dir);
                            } catch (Exception) { }

                            Main.NewText("Couldn't open config file " + path + ": " + e.Message, Color.Red);
                        }
                    };
                }
            }
        }
 public static bool HasConfig(Mod mod)
 {
     return(ModFeaturesHelpers.HasConfig(mod));
 }
 public static bool DetectGithub(Mod mod)
 {
     return(ModFeaturesHelpers.DetectGithub(mod));
 }
 public static bool DetectConfig(Mod mod)
 {
     return(ModFeaturesHelpers.DetectConfig(mod));
 }
 public static string GetGithubProjectName(Mod mod)
 {
     return(ModFeaturesHelpers.GetGithubProjectName(mod));
 }
 public static void ResetDefaultsConfig(Mod mod)
 {
     ModFeaturesHelpers.ResetDefaultsConfig(mod);
 }
 public static void ReloadConfigFromFile(Mod mod)
 {
     ModFeaturesHelpers.ReloadConfigFromFile(mod);
 }
 public static string GetConfigRelativePath(Mod mod)
 {
     return(ModFeaturesHelpers.GetConfigRelativePath(mod));
 }
 public static bool HasConfigDefaultsReset(Mod mod)
 {
     return(ModFeaturesHelpers.HasConfigDefaultsReset(mod));
 }