From 9dbf4cda643b63eb6a3d3e61cf109a363fcd8742 Mon Sep 17 00:00:00 2001 From: Ozzatron Date: Tue, 3 Oct 2023 20:00:45 -0400 Subject: [PATCH] Cooldown instantiation cannot error out. Players can be loaded safely across cooldown redefines. --- Cooldowns/CooldownInstance.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Cooldowns/CooldownInstance.cs b/Cooldowns/CooldownInstance.cs index d1d7542d1a..7a71c25f61 100644 --- a/Cooldowns/CooldownInstance.cs +++ b/Cooldowns/CooldownInstance.cs @@ -35,10 +35,19 @@ namespace CalamityMod.Cooldowns internal CooldownInstance(Player p, string id, TagCompound tag) { netID = (ushort)tag.GetAsInt(NetIDSaveKey); + Cooldown cd = CooldownRegistry.Get(id); + + // 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."); + return; + } + // Correct for netID mismatch if for some reason this occurs. // The string ID of the cooldown overrides whatever the netID may have been saved as. - Cooldown cd = CooldownRegistry.Get(id); ushort registeredNetID = cd.netID; + if (netID != registeredNetID) { // Log when this occurs, even though it should be harmless.