diff --git a/CalamityMod.cs b/CalamityMod.cs index 88ad657958..ec7526c385 100644 --- a/CalamityMod.cs +++ b/CalamityMod.cs @@ -1,17 +1,15 @@ using System; -using System.Collections.Generic; using System.IO; -using System.Reflection; using System.Runtime.CompilerServices; using CalamityMod.FluidSimulation; using CalamityMod.Items; using CalamityMod.MainMenu; using CalamityMod.Particles; using CalamityMod.Projectiles; +using log4net; using Microsoft.Xna.Framework; using Terraria; using Terraria.ModLoader; -using Terraria.ModLoader.Config; [assembly: InternalsVisibleTo("CalTestHelpers")] [assembly: InternalsVisibleTo("InfernumMode")] @@ -30,6 +28,9 @@ namespace CalamityMod internal static CalamityMod Instance => _Instance ??= ModContent.GetInstance(); private static CalamityMod _Instance; + // This should not be named as 'Logger' as it hides Instance Property 'Logger' + internal static ILog Log => Instance.Logger; + #region Load public override void Load() { diff --git a/CalamityNetcode.cs b/CalamityNetcode.cs index ab0d9f11b7..5911518441 100644 --- a/CalamityNetcode.cs +++ b/CalamityNetcode.cs @@ -29,7 +29,7 @@ namespace CalamityMod var existingHandler = _PacketRegistry[msgType]; if (existingHandler != null) { - CalamityMod.Instance.Logger.Error($"Packet instance has already registered by other type!" + + CalamityMod.Log.Error($"Packet instance has already registered by other type!" + $" [Failed On: '{type.FullName}'" + $" Current Owner: '{existingHandler.GetType().FullName}'," + $" msgTypeToRegister: '{msgType}']"); @@ -48,7 +48,7 @@ namespace CalamityMod } else { - CalamityMod.Instance.Logger.Error($"Packet instance's 'Instance' property is not asssignable with given type!" + + CalamityMod.Log.Error($"Packet instance's 'Instance' property is not asssignable with given type!" + $" [Failed On: '{type.FullName}']"); } } @@ -61,7 +61,7 @@ namespace CalamityMod } catch (Exception e) { - CalamityMod.Instance.Logger.Error($"Exception was thrown while loading for Packets! {e}"); + CalamityMod.Log.Error($"Exception was thrown while loading for Packets! {e}"); return; } }); @@ -102,18 +102,18 @@ namespace CalamityMod // Throw an exception now instead of allowing the network stream to corrupt. // - CalamityMod.Instance.Logger.Error($"Failed to parse Calamity packet: No Calamity packet exists with ID {msgType}."); + CalamityMod.Log.Error($"Failed to parse Calamity packet: No Calamity packet exists with ID {msgType}."); throw new Exception("Failed to parse Calamity packet: Invalid Calamity packet ID."); } } catch (Exception e) { if (e is EndOfStreamException eose) - CalamityMod.Instance.Logger.Error("Failed to parse Calamity packet: Packet was too short, missing data, or otherwise corrupt.", eose); + CalamityMod.Log.Error("Failed to parse Calamity packet: Packet was too short, missing data, or otherwise corrupt.", eose); else if (e is ObjectDisposedException ode) - CalamityMod.Instance.Logger.Error("Failed to parse Calamity packet: Packet reader disposed or destroyed.", ode); + CalamityMod.Log.Error("Failed to parse Calamity packet: Packet reader disposed or destroyed.", ode); else if (e is IOException ioe) - CalamityMod.Instance.Logger.Error("Failed to parse Calamity packet: An unknown I/O error occurred.", ioe); + CalamityMod.Log.Error("Failed to parse Calamity packet: An unknown I/O error occurred.", ioe); else throw; // this either will crash the game or be caught by TML's packet policing } diff --git a/Cooldowns/CooldownInstance.cs b/Cooldowns/CooldownInstance.cs index ca8d98120a..44f6687745 100644 --- a/Cooldowns/CooldownInstance.cs +++ b/Cooldowns/CooldownInstance.cs @@ -40,7 +40,7 @@ namespace CalamityMod.Cooldowns // It is possible this cooldown does not exist. If this occurs, log it, even though it will be (mostly) harmless. if (cd is null) { - CalamityMod.Instance.Logger.Warn($"Cooldown \"{id}\" loaded from NBT, but was not found. This cooldown will not be applied to the player."); + CalamityMod.Log.Warn($"Cooldown \"{id}\" loaded from NBT, but was not found. This cooldown will not be applied to the player."); return; } @@ -51,7 +51,7 @@ namespace CalamityMod.Cooldowns if (netID != registeredNetID) { // Log when this occurs, even though it should be harmless. - CalamityMod.Instance.Logger.Warn($"Cooldown \"{id}\" loaded from NBT with discrepant netID {netID}. This cooldown was registered with netID {registeredNetID}"); + CalamityMod.Log.Warn($"Cooldown \"{id}\" loaded from NBT with discrepant netID {netID}. This cooldown was registered with netID {registeredNetID}"); netID = registeredNetID; } player = p; diff --git a/ILEditing/ILHelperMethods.cs b/ILEditing/ILHelperMethods.cs index fe90e30043..bca6463ec7 100644 --- a/ILEditing/ILHelperMethods.cs +++ b/ILEditing/ILHelperMethods.cs @@ -124,7 +124,7 @@ namespace CalamityMod.ILEditing } } - public static void DumpToLog(ILContext il) => CalamityMod.Instance.Logger.Debug(il.ToString()); - public static void LogFailure(string name, string reason) => CalamityMod.Instance.Logger.Warn($"IL edit \"{name}\" failed! {reason}"); + public static void DumpToLog(ILContext il) => CalamityMod.Log.Debug(il.ToString()); + public static void LogFailure(string name, string reason) => CalamityMod.Log.Warn($"IL edit \"{name}\" failed! {reason}"); } } diff --git a/ILEditing/MechanicILChanges.cs b/ILEditing/MechanicILChanges.cs index e4e0c1caff..0b586ff7db 100644 --- a/ILEditing/MechanicILChanges.cs +++ b/ILEditing/MechanicILChanges.cs @@ -365,7 +365,7 @@ namespace CalamityMod.ILEditing if (!cursor.TryGotoNext(MoveType.Before, i => i.MatchCallOrCallvirt
("UpdateTime_SpawnTownNPCs"))) { - CalamityMod.Instance.Logger.Warn("Town NPC spawn editing code failed."); + CalamityMod.Log.Warn("Town NPC spawn editing code failed."); return; } diff --git a/ILEditing/NetProtectionILChanges.cs b/ILEditing/NetProtectionILChanges.cs index 6ba19e43a5..86adfaf4a5 100644 --- a/ILEditing/NetProtectionILChanges.cs +++ b/ILEditing/NetProtectionILChanges.cs @@ -40,8 +40,8 @@ namespace CalamityMod.ILEditing { if (Main.netMode == NetmodeID.MultiplayerClient) { - CalamityMod.Instance.Logger.Error($"NETCODE SAFETY VIOLATION DETECTED: {nameof(NPC.NewNPC)} was called from a Multiplayer Client"); - CalamityMod.Instance.Logger.Error(GetSimplifiedStackTrace()); + CalamityMod.Log.Error($"NETCODE SAFETY VIOLATION DETECTED: {nameof(NPC.NewNPC)} was called from a Multiplayer Client"); + CalamityMod.Log.Error(GetSimplifiedStackTrace()); return Main.maxNPCs; } @@ -54,8 +54,8 @@ namespace CalamityMod.ILEditing // So we simply stop that from happening if (msgType == MessageID.SyncNPC && Main.netMode == NetmodeID.MultiplayerClient) { - CalamityMod.Instance.Logger.Error($"NETCODE SAFETY VIOLATION DETECTED: {nameof(NetMessage.SendData)} ({nameof(MessageID.SyncNPC)}) was called from a Multiplayer Client"); - CalamityMod.Instance.Logger.Error(GetSimplifiedStackTrace()); + CalamityMod.Log.Error($"NETCODE SAFETY VIOLATION DETECTED: {nameof(NetMessage.SendData)} ({nameof(MessageID.SyncNPC)}) was called from a Multiplayer Client"); + CalamityMod.Log.Error(GetSimplifiedStackTrace()); return; } diff --git a/Items/Fishing/GlimmeringGemfish.cs b/Items/Fishing/GlimmeringGemfish.cs index b9921dc101..104d5559ac 100644 --- a/Items/Fishing/GlimmeringGemfish.cs +++ b/Items/Fishing/GlimmeringGemfish.cs @@ -62,13 +62,13 @@ namespace CalamityMod.Items.Fishing if (aquamarine is not null) itemLoot.Add(aquamarine.Type, 4, gemMin, gemMax); else - CalamityMod.Instance.Logger.Warn("Could not find Thorium Aquamarine gem. This item will not be added to Glimmering Gemfish."); + CalamityMod.Log.Warn("Could not find Thorium Aquamarine gem. This item will not be added to Glimmering Gemfish."); var opal = thorium.Find("Opal"); if (opal is not null) itemLoot.Add(opal.Type, 4, gemMin, gemMax); else - CalamityMod.Instance.Logger.Warn("Could not find Thorium Opal gem. This item will not be added to Glimmering Gemfish."); + CalamityMod.Log.Warn("Could not find Thorium Opal gem. This item will not be added to Glimmering Gemfish."); } public override void ModifyTooltips(List list) diff --git a/Items/Fishing/StuffedFish.cs b/Items/Fishing/StuffedFish.cs index 1c179ef7e2..658d83fb17 100644 --- a/Items/Fishing/StuffedFish.cs +++ b/Items/Fishing/StuffedFish.cs @@ -111,7 +111,7 @@ namespace CalamityMod.Items.Fishing itemLoot.Add(marineKelpSeeds.Type, 10, seedMin, seedMax); } else - CalamityMod.Instance.Logger.Warn("Could not find either Marine Kelp or Marine Kelp Seeds from Thorium. These items will not be added to Stuffed Fish."); + CalamityMod.Log.Warn("Could not find either Marine Kelp or Marine Kelp Seeds from Thorium. These items will not be added to Stuffed Fish."); // Ozzatron 30DEC2022: It is unlikely SoA will ever be ported to 1.4 and beyond. Commenting this out indefinitely. /* @@ -133,7 +133,7 @@ namespace CalamityMod.Items.Fishing } catch { - CalamityMod.Instance.Logger.Debug("One of the items in this file got renamed internally. Please report this in the #bugs-read-pins channel of the official Calamity discord server."); + CalamityMod.Log.Debug("One of the items in this file got renamed internally. Please report this in the #bugs-read-pins channel of the official Calamity discord server."); } } */ diff --git a/Items/Weapons/Melee/FourSeasonsGalaxia.cs b/Items/Weapons/Melee/FourSeasonsGalaxia.cs index 046c14ccfa..ad0b842dca 100644 --- a/Items/Weapons/Melee/FourSeasonsGalaxia.cs +++ b/Items/Weapons/Melee/FourSeasonsGalaxia.cs @@ -87,7 +87,7 @@ namespace CalamityMod.Items.Weapons.Melee //.. but just in case if (mainAttunement == null) { - CalamityMod.Instance.Logger.Error("No main attunement on galaxia, couldn't edit its tooltip properly. How the hell did that happen."); + CalamityMod.Log.Error("No main attunement on galaxia, couldn't edit its tooltip properly. How the hell did that happen."); return; } diff --git a/ModSupport/ModCalls.cs b/ModSupport/ModCalls.cs index 98fd3607af..6bd2d2a32e 100644 --- a/ModSupport/ModCalls.cs +++ b/ModSupport/ModCalls.cs @@ -2045,11 +2045,11 @@ namespace CalamityMod return null; case "LoadParticleInstances": - CalamityMod.Instance.Logger.Warn("This mod call is deprecated. Calamity automatically registers particles."); + CalamityMod.Log.Warn("This mod call is deprecated. Calamity automatically registers particles."); return null; case "RegisterModCooldowns": - CalamityMod.Instance.Logger.Warn("This mod call is deprecated. Calamity automatically registers cooldowns."); + CalamityMod.Log.Warn("This mod call is deprecated. Calamity automatically registers cooldowns."); return null; case "GetSummonerNerfDisabledByItem": diff --git a/NPCs/CalamityNetImportantNPC.cs b/NPCs/CalamityNetImportantNPC.cs index 065b2138d8..b5030c33ed 100644 --- a/NPCs/CalamityNetImportantNPC.cs +++ b/NPCs/CalamityNetImportantNPC.cs @@ -76,7 +76,7 @@ namespace CalamityMod.NPCs } catch (Exception e) { - CalamityMod.Instance.Logger.Error($"Exception thrown while evaluating type \"{type.Name}\": {e}"); + CalamityMod.Log.Error($"Exception thrown while evaluating type \"{type.Name}\": {e}"); } } diff --git a/NPCs/CalamityPierceResistance.cs b/NPCs/CalamityPierceResistance.cs index 88b16dbaba..d87462fb4c 100644 --- a/NPCs/CalamityPierceResistance.cs +++ b/NPCs/CalamityPierceResistance.cs @@ -103,7 +103,7 @@ namespace CalamityMod.NPCs } catch (Exception e) { - CalamityMod.Instance.Logger.Error($"Exception thrown while evaluating type \"{type.Name}\": {e}"); + CalamityMod.Log.Error($"Exception thrown while evaluating type \"{type.Name}\": {e}"); } } @@ -128,7 +128,7 @@ namespace CalamityMod.NPCs } catch (Exception e) { - CalamityMod.Instance.Logger.Error($"Exception thrown while evaluating type \"{type.Name}\": {e}"); + CalamityMod.Log.Error($"Exception thrown while evaluating type \"{type.Name}\": {e}"); } } } diff --git a/Packets/Worlds/SwitchToDifficultyPacket.cs b/Packets/Worlds/SwitchToDifficultyPacket.cs index 93f9c766dc..9ed50149c7 100644 --- a/Packets/Worlds/SwitchToDifficultyPacket.cs +++ b/Packets/Worlds/SwitchToDifficultyPacket.cs @@ -35,7 +35,7 @@ namespace CalamityMod.Packets } else { - CalamityMod.Instance.Logger.Error($"Packet: [{nameof(SwitchToDifficultyPacket)}] has failed! Name: [{modeName}] is not a valid {nameof(DifficultyMode)} name!"); + CalamityMod.Log.Error($"Packet: [{nameof(SwitchToDifficultyPacket)}] has failed! Name: [{modeName}] is not a valid {nameof(DifficultyMode)} name!"); } } } diff --git a/Projectiles/Summon/CnidarianJellyfishOnTheString.cs b/Projectiles/Summon/CnidarianJellyfishOnTheString.cs index a26b46828f..c7f56ba848 100644 --- a/Projectiles/Summon/CnidarianJellyfishOnTheString.cs +++ b/Projectiles/Summon/CnidarianJellyfishOnTheString.cs @@ -289,7 +289,7 @@ namespace CalamityMod.Projectiles.Summon } catch (Exception) { - CalamityMod.Instance.Logger.Warn("IbanPlay Victide Cnidarian Position Netcode failed safely"); + CalamityMod.Log.Warn("IbanPlay Victide Cnidarian Position Netcode failed safely"); } } } diff --git a/Schematics/CalamitySchematicIO.cs b/Schematics/CalamitySchematicIO.cs index 8705364156..898286bf53 100644 --- a/Schematics/CalamitySchematicIO.cs +++ b/Schematics/CalamitySchematicIO.cs @@ -772,7 +772,7 @@ PostAreaIteration: // This is an intentional "fail gracefully" case. else if (isTML13Schematic) { - CalamityMod.Instance.Logger.Error(TML13ValidString); + CalamityMod.Log.Error(TML13ValidString); SchematicMetaTile[,] empty = new SchematicMetaTile[0, 0]; return empty; } diff --git a/Schematics/SchematicManager.cs b/Schematics/SchematicManager.cs index 0f52794ac9..71c79ad915 100644 --- a/Schematics/SchematicManager.cs +++ b/Schematics/SchematicManager.cs @@ -272,7 +272,7 @@ namespace CalamityMod.Schematics // If no schematic exists with this name, cancel with a helpful log message. if (!TileMaps.TryGetValue(name, out SchematicMetaTile[,] schematic)) { - CalamityMod.Instance.Logger.Warn($"Tried to place a schematic with name \"{name}\". No matching schematic file found."); + CalamityMod.Log.Warn($"Tried to place a schematic with name \"{name}\". No matching schematic file found."); return; } @@ -331,7 +331,7 @@ namespace CalamityMod.Schematics // Make sure that all four corners of the target area are actually in the world. if (!WorldGen.InWorld(cornerX, cornerY) || !WorldGen.InWorld(cornerX + width, cornerY + height)) { - CalamityMod.Instance.Logger.Warn("Schematic failed to place: Part of the target location is outside the game world."); + CalamityMod.Log.Warn("Schematic failed to place: Part of the target location is outside the game world."); return; } diff --git a/Systems/GlobalSaveDataSystem.cs b/Systems/GlobalSaveDataSystem.cs index 3f4b0116f8..ff1efe1b16 100644 --- a/Systems/GlobalSaveDataSystem.cs +++ b/Systems/GlobalSaveDataSystem.cs @@ -74,7 +74,7 @@ namespace CalamityMod.Systems // If the key already exists, log it as a warning and don't run any code. if (GlobalSaveDataKeys.Contains(key)) { - CalamityMod.Instance.Logger.Error($"WARNING! A global save data key \"{key}\" which has already been registered is attempting to be registered again. " + + CalamityMod.Log.Error($"WARNING! A global save data key \"{key}\" which has already been registered is attempting to be registered again. " + "Please report this to the Calamity Mod Team if you see this!"); return; } diff --git a/Systems/TileMerging/TileBlendMergeSystem.cs b/Systems/TileMerging/TileBlendMergeSystem.cs index 9c8a3e1f0c..0d531a9c80 100644 --- a/Systems/TileMerging/TileBlendMergeSystem.cs +++ b/Systems/TileMerging/TileBlendMergeSystem.cs @@ -122,7 +122,7 @@ namespace CalamityMod.Systems if (blendTextureSlot == TileBlendTextureLoader.EmptySlot) { var tileName = TileLoader.GetTile(blendTileType)?.FullName ?? "Vanilla Tile"; - CalamityMod.Instance.Logger.Error($"[BlendMergeSystem] BlendTileType: {blendTileType} ({tileName}) does not have TileBlendTexture! StackTrace:\n{Environment.StackTrace}"); + CalamityMod.Log.Error($"[BlendMergeSystem] BlendTileType: {blendTileType} ({tileName}) does not have TileBlendTexture! StackTrace:\n{Environment.StackTrace}"); return; } diff --git a/Tiles/GlowMaskTile.cs b/Tiles/GlowMaskTile.cs index 8cbef860ca..22bc7d9db2 100644 --- a/Tiles/GlowMaskTile.cs +++ b/Tiles/GlowMaskTile.cs @@ -35,7 +35,7 @@ namespace CalamityMod.Tiles { if (GlowMask != null) { - CalamityMod.Instance.Logger.Error($"{Name} has called {nameof(SetStaticDefaults)} themselve! This is not allowed!"); + CalamityMod.Log.Error($"{Name} has called {nameof(SetStaticDefaults)} themselve! This is not allowed!"); return; } diff --git a/World/AstralChestGeneration.cs b/World/AstralChestGeneration.cs index e3e5a2faef..3781e96764 100644 --- a/World/AstralChestGeneration.cs +++ b/World/AstralChestGeneration.cs @@ -22,7 +22,7 @@ namespace CalamityMod.World bool invalidHeightData = top >= bottom; if (invalidWidthData || invalidHeightData) { - CalamityMod.Instance.Logger.Warn("The generated dungeon was found to have unusable area bounds. As a result, the astral chest could not be generated."); + CalamityMod.Log.Warn("The generated dungeon was found to have unusable area bounds. As a result, the astral chest could not be generated."); return; } @@ -67,7 +67,7 @@ namespace CalamityMod.World // If a chest was NOT placed, that means that the loop somehow failed. // Log this. else - CalamityMod.Instance.Logger.Warn("The astral chest loop could not find a valid generation location. As a result, it has not generated."); + CalamityMod.Log.Warn("The astral chest loop could not find a valid generation location. As a result, it has not generated."); } } } diff --git a/World/DraedonStructures.cs b/World/DraedonStructures.cs index d4f69609b4..083849c346 100644 --- a/World/DraedonStructures.cs +++ b/World/DraedonStructures.cs @@ -589,7 +589,7 @@ namespace CalamityMod.World contents.Add(new ChestItem(marineKelpPlanterBox.Type, WorldGen.genRand.Next(5, 9 + 1))); } else - CalamityMod.Instance.Logger.Warn("Could not find Thorium Marine Kelp Planter Box. This item will not be added to the Draedon Planetoid Lab."); + CalamityMod.Log.Warn("Could not find Thorium Marine Kelp Planter Box. This item will not be added to the Draedon Planetoid Lab."); //Adds the Jungle Seeking Mechanism contents.Insert(0, new ChestItem(ModContent.ItemType(), 1)); diff --git a/World/SulphurousSea.cs b/World/SulphurousSea.cs index 34ec893c17..640cb48d16 100644 --- a/World/SulphurousSea.cs +++ b/World/SulphurousSea.cs @@ -959,7 +959,7 @@ namespace CalamityMod.World // Create a log message if for some reason the schematic in question doesn't exist. if (!wrappedSchematicArea.HasValue) { - CalamityMod.Instance.Logger.Warn($"Tried to place a schematic with name \"{schematicName}\". No matching schematic file found."); + CalamityMod.Log.Warn($"Tried to place a schematic with name \"{schematicName}\". No matching schematic file found."); continue; } diff --git a/World/UndergroundShrines.cs b/World/UndergroundShrines.cs index b5b3f95e9d..74d6402623 100644 --- a/World/UndergroundShrines.cs +++ b/World/UndergroundShrines.cs @@ -941,7 +941,7 @@ namespace CalamityMod.World break; } } while (tries <= 100000); - CalamityMod.Instance.Logger.Debug("Rox Shrine failed to generate"); + CalamityMod.Log.Debug("Rox Shrine failed to generate"); } #endregion