Log() public static method

public static Log ( string message ) : void
message string
return void
Example #1
0
 internal static void ActivateExceptionReporting()
 {
     if (exceptionReportingActive)
     {
         return;
     }
     exceptionReportingActive = true;
     AppDomain.CurrentDomain.FirstChanceException += delegate(object sender, FirstChanceExceptionEventArgs exceptionArgs)
     {
         if (exceptionArgs.Exception.Source == "MP3Sharp")
         {
             return;
         }
         float soundVolume = Main.soundVolume;
         Main.soundVolume = 0f;
         Main.NewText(exceptionArgs.Exception.Message + exceptionArgs.Exception.StackTrace, Microsoft.Xna.Framework.Color.OrangeRed);
         ErrorLogger.Log("Silently Caught Exception: " + exceptionArgs.Exception.Message + exceptionArgs.Exception.StackTrace);
         Main.soundVolume = soundVolume;
     };
 }
Example #2
0
        /// <summary>
        /// Several arrays and other fields hold references to various classes from mods, we need to clean them up to give properly coded mods a chance to be completely free of references
        /// so that they can be collected by the garbage collection. For most things eventually they will be replaced during gameplay, but we want the old instance completely gone quickly.
        /// </summary>
        internal static void CleanupModReferences()
        {
            // Clear references to ModPlayer instances
            for (int i = 0; i < 256; i++)
            {
                Main.player[i] = new Player();
            }
            // TODO: This breaks net reload. Restore this cleanup step later?
            // Main.ActivePlayerFileData = new Terraria.IO.PlayerFileData();
            Main._characterSelectMenu._playerList?.Clear();
            Main.PlayerList.Clear();

            foreach (var npc in Main.npc)
            {
                npc.SetDefaults(0);
            }

            foreach (var item in Main.item)
            {
                item.SetDefaults(0);
            }
            ItemSlot.singleSlotArray[0]?.SetDefaults(0);

            for (int i = 0; i < Main.chest.Length; i++)
            {
                Main.chest[i] = new Chest();
            }

            // TODO: Display this warning to modders
            GC.Collect();
            if (ModLoader.isModder)
            {
                foreach (var weakReference in loadedModsWeakReferences)
                {
                    if (weakReference.IsAlive)
                    {
                        ErrorLogger.Log((weakReference.Target as Mod).Name + " not fully unloaded during unload.");
                    }
                }
            }
        }
Example #3
0
        /// <summary>
        /// Automatically sets certain static defaults. Override this if you do not want the properties to be set for you.
        /// </summary>
        public virtual void AutoStaticDefaults()
        {
            Main.npcTexture[npc.type] = ModLoader.GetTexture(Texture);
            if (banner != 0 && bannerItem != 0)
            {
                NPCLoader.bannerToItem[banner] = bannerItem;
            }
            else if (banner != 0 || bannerItem != 0)
            {
                ErrorLogger.Log($"{mod.DisplayName}: {Name}. You have set ModNPC.banner or ModNPC.bannerItem, but not the other. Make sure you set both, check your spelling, and that the item exists if you are using mod.ItemType(). Report this to the {mod.DisplayName} developers.");
            }
            if (npc.lifeMax > 32767 || npc.boss)
            {
                Main.npcLifeBytes[npc.type] = 4;
            }
            else if (npc.lifeMax > 127)
            {
                Main.npcLifeBytes[npc.type] = 2;
            }
            else
            {
                Main.npcLifeBytes[npc.type] = 1;
            }

            string[] altTextures     = AltTextures;
            int      altTextureCount = altTextures.Length;

            NPCID.Sets.ExtraTextureCount[npc.type] = altTextureCount;
            Main.npcAltTextures[npc.type]          = new Texture2D[altTextureCount + 1];
            if (altTextureCount > 0)
            {
                Main.npcAltTextures[npc.type][0] = Main.npcTexture[npc.type];
            }
            for (int k = 1; k <= altTextureCount; k++)
            {
                Main.npcAltTextures[npc.type][k] = ModLoader.GetTexture(altTextures[k - 1]);
            }

            DisplayName.SetDefault(Regex.Replace(GetType().Name, "([A-Z])", " $1").Trim());
        }