////////////////

        public void LoadModListAsync()
        {
            ThreadPool.QueueUserWorkItem(_ => {
                this.IsPopulatingList = true;

                lock (UIModControlPanelTab.ModDataListLock) {
                    this.ModDataList.Clear();
                }

                var mymod = ModHelpersMod.Instance;
                int i     = 1;

                foreach (var mod in ModListHelpers.GetAllLoadedModsPreferredOrder())
                {
                    UIModData moditem = this.CreateModListItem(i++, mod);

                    lock (UIModControlPanelTab.ModDataListLock) {
                        this.ModDataList.Add(moditem);
                    }

                    if (!ModHelpersMod.Config.DisableModMenuUpdates)
                    {
                        moditem.CheckForNewVersionAsync();
                    }
                }

                this.ModListUpdateRequired = true;
                this.IsPopulatingList      = false;
            });
        }
示例#2
0
        /// <summary>
        /// Locks the current world.
        /// </summary>
        public static void LockWorld()
        {
            var mymod    = ModHelpersMod.Instance;
            var modlock  = mymod.ModLock;
            var modworld = ModContent.GetInstance <ModHelpersWorld>();

            IEnumerable <Mod> allMods  = ModListHelpers.GetAllLoadedModsPreferredOrder();
            ISet <string>     modNames = new HashSet <string>();

            foreach (Mod mod in allMods)
            {
                modNames.Add(mod.Name);
            }

            modlock.WorldModLocks[modworld.ObsoleteId2] = modNames;

            modlock.ScanMods(modworld);

            if (ModHelpersMod.Config.WorldModLockMinimumOnly)
            {
                Main.NewText("Your world now requires exactly these mods: " + string.Join(", ", modNames));
            }
            else
            {
                Main.NewText("Your world now requires at least these mods: " + string.Join(", ", modNames));
            }
        }
        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);
        }
        ////////////////

        /// @private
        public override void Action(CommandCaller caller, string input, string[] args)
        {
            IList <Mod> mods   = ModListHelpers.GetAllLoadedModsPreferredOrder().ToList();
            int         argIdx = 1;

            string title;

            if (!CommandsHelpers.GetQuotedStringFromArgsAt(args, argIdx, out argIdx, out title))
            {
                caller.Reply("Invalid issue report title string", Color.Red);
                return;
            }

            string body;

            if (!CommandsHelpers.GetQuotedStringFromArgsAt(args, argIdx, out argIdx, out body))
            {
                caller.Reply("Invalid issue report description string", Color.Red);
                return;
            }

            int modIdx;

            if (!int.TryParse(args[0], out modIdx))
            {
                caller.Reply(args[argIdx] + " is not an integer", Color.Red);
                return;
            }
            if (modIdx <= 0 || modIdx > mods.Count)
            {
                caller.Reply(args[argIdx] + " is not a mod entry; out of range", Color.Red);
                return;
            }

            Action <bool, string> onCompletion = (success, output) => {
                if (output != "Done?")
                {
                    caller.Reply(output, Color.Lime);
                }
                else
                {
                    caller.Reply("Issue report was not sent", Color.Red);
                }
            };
            Action <Exception, string> onFail = (e, output) => {
                caller.Reply(e.Message, Color.Red);
            };

            PostGithubModIssueReports.ReportIssue(mods[modIdx - 1], title, body, onFail, onCompletion);
        }
示例#5
0
        ////////////////

        private void ScanMods(ModHelpersWorld modworld)
        {
            this.FoundModNames   = new HashSet <string>();
            this.MissingModNames = new HashSet <string>();
            this.ExtraModNames   = new HashSet <string>();

            if (!this.WorldModLocks.ContainsKey(modworld.ObsoleteId2))
            {
                this.IsMismatched = false;
                return;
            }

            ISet <string>     reqModNames     = this.WorldModLocks[modworld.ObsoleteId2];
            ISet <string>     checkedModNames = new HashSet <string>();
            IEnumerable <Mod> allMods         = ModListHelpers.GetAllLoadedModsPreferredOrder();

            foreach (Mod mod in allMods)
            {
                if (!reqModNames.Contains(mod.Name))
                {
                    this.ExtraModNames.Add(mod.Name);
                }
                else
                {
                    this.FoundModNames.Add(mod.Name);
                }
                checkedModNames.Add(mod.Name);
            }

            foreach (string modName in reqModNames)
            {
                if (!checkedModNames.Contains(modName))
                {
                    this.MissingModNames.Add(modName);
                }
            }

            this.IsMismatched = ModLockService.IsModMismatchFound();
//LogHelpers.Log( "req_modNames:"+string.Join(",",req_modNames)+
//", extra:"+string.Join(",",this.ExtraModNames)+
//", found:"+string.Join(",",this.FoundModNames)+
//", missing:"+string.Join(",",this.MissingModNames ) );
//LogHelpers.Log( "IsInitialized:"+this.IsInitialized+" IsMismatched:"+this.IsMismatched+ ", ExitDuration:" + this.ExitDuration);
        }
示例#6
0
        ////////////////

        internal void DrawWarning(SpriteBatch sb)
        {
            if (!this.IsInitialized)
            {
                return;
            }
            if (!this.IsMismatched)
            {
                return;
            }

            int eta = this.ExitDuration / 60;
            IEnumerable <Mod> mods = ModListHelpers.GetAllLoadedModsPreferredOrder();

            string warning = "World mod mismatch! Auto-exiting in " + eta;

            Vector2 pos     = new Vector2(Main.screenWidth / 2, Main.screenHeight / 2);
            Vector2 dim     = Main.fontDeathText.MeasureString(warning);
            Vector2 mainPos = pos - (dim / 2);

            sb.DrawString(Main.fontDeathText, warning, mainPos, Color.Red);

            if (this.FoundModNames.Count > 0)
            {
                string needed = "Needed mods: " + string.Join(", ", this.FoundModNames.ToArray());
                mainPos.X += 128;
                mainPos.Y += 48;
                sb.DrawString(Main.fontMouseText, needed, mainPos, Color.White);
            }

            if (this.MissingModNames.Count > 0)
            {
                string missing = "Missing mods: " + string.Join(", ", this.MissingModNames.ToArray());
                mainPos.Y += 24;
                sb.DrawString(Main.fontMouseText, missing, mainPos, Color.White);
            }

            if (this.ExtraModNames.Count > 0)
            {
                string extra = "Extra mods: " + string.Join(", ", this.ExtraModNames.ToArray());
                mainPos.Y += 24;
                sb.DrawString(Main.fontMouseText, extra, mainPos, Color.White);
            }
        }
        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);
        }