Esempio n. 1
0
        ////////////////

        private void Initialize(string msg)
        {
            string context  = DebugHelpers.GetCurrentContext(3);
            var    msgCount = ModHelpersMod.Instance.ExceptionMngr.MsgCount;
            int    count    = 0;

            lock (HamstarExceptionManager.MyLock) {
                if (msgCount.TryGetValue(msg, out count))
                {
                    if (count > 10 && (Math.Log10(count) % 1) != 0)
                    {
                        return;
                    }
                }
                else
                {
                    msgCount[msg] = 0;
                }
                msgCount[msg]++;
            }

            if (this.InnerException != null)
            {
                LogHelpers.Log("!" + context + " (E#" + count + ") - " + msg + " | " + this.InnerException.Message);
            }
            else
            {
                LogHelpers.Log("!" + context + " (E#" + count + ") - " + msg);
            }
        }
        ////////////////

        /// <summary>
        /// Draws to the main SpriteBatch by way of a callback. Attempts to resolve when to draw based on the SpriteBatch's
        /// `Begun()` state.
        /// </summary>
        /// <param name="draw"></param>
        /// <param name="isBegun">Indicates that the SpriteBatch was already `Begun()`.</param>
        /// <param name="forceDraw">Forces drawing even wehn the SpriteBatch is already `Begun()`.</param>
        /// <returns>`true` if no issues occurred with the drawing.</returns>
        public static bool DrawBatch(Action <SpriteBatch> draw, out bool isBegun, bool forceDraw = true)
        {
            if (!XNAHelpers.IsMainSpriteBatchBegun(out isBegun))
            {
                return(false);                // take no chances
            }

            if (!isBegun)
            {
                Main.spriteBatch.Begin();

                try {
                    draw(Main.spriteBatch);
                } catch (Exception e) {
                    LogHelpers.WarnOnce(e.ToString());
                }

                Main.spriteBatch.End();
            }
            else
            {
                if (forceDraw)
                {
                    LogHelpers.WarnOnce(DebugHelpers.GetCurrentContext(2) + " - SpriteBatch already begun. Drawing anyway...");
                    try {
                        draw(Main.spriteBatch);
                    } catch (Exception e) {
                        LogHelpers.WarnOnce(e.ToString());
                    }
                }
            }

            return(true);
        }
        /// <summary>
        /// Draws to the main SpriteBatch by way of a callback. Attempts to resolve when to draw based on the SpriteBatch's
        /// `Begun()` state. If the SpriteBatch needs to be begun anew, the given set of relevant parameters will be applied.
        /// </summary>
        /// <param name="draw"></param>
        /// <param name="sortMode"></param>
        /// <param name="blendState"></param>
        /// <param name="samplerState"></param>
        /// <param name="depthStencilState"></param>
        /// <param name="rasterizerState"></param>
        /// <param name="effect"></param>
        /// <param name="transformMatrix"></param>
        /// <param name="isBegun">Indicates that the SpriteBatch was already `Begun()`.</param>
        /// <param name="forceBeginAnew">Forces the SpriteBatch to `Begin()`.</param>
        /// <param name="forceDraw">Forces drawing even wehn the SpriteBatch is already `Begun()`.</param>
        /// <returns></returns>
        public static bool DrawBatch(Action <SpriteBatch> draw,
                                     SpriteSortMode sortMode,
                                     BlendState blendState,
                                     SamplerState samplerState,
                                     DepthStencilState depthStencilState,
                                     RasterizerState rasterizerState,
                                     Effect effect,
                                     Matrix transformMatrix,
                                     out bool isBegun,
                                     bool forceBeginAnew = false,
                                     bool forceDraw      = true)
        {
            if (!XNAHelpers.IsMainSpriteBatchBegun(out isBegun))
            {
                return(false);                // take no chances
            }

            if (isBegun && forceBeginAnew)
            {
                isBegun = false;
                Main.spriteBatch.End();
            }

            if (!isBegun)
            {
                Main.spriteBatch.Begin(sortMode, blendState, samplerState, depthStencilState, rasterizerState, effect, transformMatrix);

                try {
                    draw(Main.spriteBatch);
                } catch (Exception e) {
                    LogHelpers.WarnOnce(e.ToString());
                }

                Main.spriteBatch.End();
            }
            else
            {
                if (forceDraw)
                {
                    LogHelpers.WarnOnce(DebugHelpers.GetCurrentContext(2) + " - SpriteBatch already begun. Drawing anyway...");
                    try {
                        draw(Main.spriteBatch);
                    } catch (Exception e) {
                        LogHelpers.WarnOnce(e.ToString());
                    }
                }
            }

            return(true);
        }
Esempio n. 4
0
        protected override void ReceiveOnClient()
        {
            if (this.PlayerWho < 0 || this.PlayerWho >= Main.player.Length)
            {
                //throw new HamstarException( "ModHelpers.PlayerDataProtocol.ReceiveWithClient - Invalid player index " + this.PlayerWho );
                throw new ModHelpersException("Invalid player index " + this.PlayerWho);
            }

            Player player = Main.player[this.PlayerWho];

            if (player == null || !player.active)
            {
                //LogHelpers.Log( "ModHelpers.PlayerDataProtocol.ReceiveWithClient - Inactive player indexed as " + this.PlayerWho );
                LogHelpers.Log(DebugHelpers.GetCurrentContext() + " - Inactive player indexed as " + this.PlayerWho);
                return;
            }

            var myplayer = player.GetModPlayer <ModHelpersPlayer>();

            myplayer.Logic.NetReceiveDataOnClient(this.PermaBuffsById, this.HasBuffIds, this.EquipSlotsToItemTypes);
        }
Esempio n. 5
0
        /// <summary>
        /// Indicates if a given world is being played (at least 1 active player), and that player has finished all of their
        /// own in-game "loading" stuff (attempts to account for any Terraria/mod hidden loading behaviors).
        /// </summary>
        /// <returns></returns>
        public static bool IsWorldSafelyBeingPlayed()
        {
            var mymod = ModHelpersMod.Instance;

            if (mymod.LoadHelpers == null)
            {
                return(false);
            }

            bool notSafelyPlayed = mymod.LoadHelpers.WorldStartupDelay >= (60 * 2);

            if (ModHelpersMod.Config.DebugModeHelpersInfo && !notSafelyPlayed)
            {
                if (Main.netMode != 2 && !Main.dedServ)
                {
                    var myplayer = (ModHelpersPlayer)TmlHelpers.SafelyGetModPlayer(Main.LocalPlayer, mymod, "ModHelpersPlayer");

                    LogHelpers.LogOnce(DebugHelpers.GetCurrentContext(2) + " - IsWorldSafelyBeingPlayed - "
                                       + "StartupDelay: " + !(mymod.LoadHelpers.WorldStartupDelay < (60 * 2))
                                       + ", IsClientPlaying_Hackish: " + mymod.LoadHelpers.IsClientPlaying_Hackish + " (true?)"
                                       + ", IsSynced: " + (myplayer?.Logic.IsSynced.ToString() ?? "null") + " (true?)");
                }
                else
                {
                    var myworld = ModContent.GetInstance <ModHelpersWorld>();
                    LogHelpers.LogOnce(DebugHelpers.GetCurrentContext(2) + " - IsWorldSafelyBeingPlayed - "
                                       + "StartupDelay: " + !(mymod.LoadHelpers.WorldStartupDelay < (60 * 2))
                                       + ", IsModLoaded(): " + LoadHelpers.IsModLoaded() + " (true?)"
                                       + ", HasObsoleteId: " + myworld.HasObsoleteId + " (false?)"
                                       + ", HasServerBegunHavingPlayers_Hackish: " + mymod.LoadHelpers.HasServerBegunHavingPlayers_Hackish + " (true?)"
                                       + ", HasSetupContent: " + mymod.HasSetupContent + " (true?)"
                                       + ", HasAddedRecipeGroups: " + mymod.HasAddedRecipeGroups + " (true?)"
                                       + ", HasAddedRecipes: " + mymod.HasAddedRecipes + " (true?)");
                }
            }
            return(notSafelyPlayed);
        }