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

        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;
            });
        }
Exemple #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));
            }
        }
        ////////////////

        /// @private
        public override void Action(CommandCaller caller, string input, string[] args)
        {
            if (args.Length == 0)
            {
                throw new UsageException("No arguments supplied.");
            }

            bool isVerbose;

            if (!bool.TryParse(args[0], out isVerbose))
            {
                throw new UsageException("Invalid 'verbose' argument supplied (must be boolean).");
            }

            IList <string> reply = new List <string>(ModLoader.Mods.Length);
            IDictionary <BuildPropertiesViewer, Mod> modList = ModListHelpers.GetLoadedModsAndBuildInfo();

            foreach (var kv in modList)
            {
                string modInfo = ModListCommand.GetBasicModInfo(kv.Value, kv.Key);

                if (isVerbose)
                {
                    string verboseModInfo = ModListCommand.GetVerboseModInfo(kv.Value, kv.Key);
                    if (!string.IsNullOrEmpty(verboseModInfo))
                    {
                        modInfo += ", " + verboseModInfo;
                    }
                }

                reply.Add(modInfo);
            }

            caller.Reply(string.Join("\n", reply));
        }
        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);
        }
Exemple #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;
        }
        ////////////////

        /// @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);
        }
        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;
        }
Exemple #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();
        }
Exemple #9
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);
        }
Exemple #10
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);
        }