From deac6f3697010e116eac8e5a3e48a3fadc441f66 Mon Sep 17 00:00:00 2001 From: Ethan Moffat Date: Sun, 30 Apr 2023 21:34:14 -0700 Subject: [PATCH] Fix integer overflow errors for values that can get very large --- EOLib.Config.Test/ConfigFileLoadActionsTest.cs | 3 --- EOLib/Domain/Character/CharacterSessionRepository.cs | 6 +++--- EOLib/PacketHandlers/NPC/NPCSpecHandler.cs | 2 +- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/EOLib.Config.Test/ConfigFileLoadActionsTest.cs b/EOLib.Config.Test/ConfigFileLoadActionsTest.cs index 9465bd426..a02aa381e 100644 --- a/EOLib.Config.Test/ConfigFileLoadActionsTest.cs +++ b/EOLib.Config.Test/ConfigFileLoadActionsTest.cs @@ -56,9 +56,6 @@ public void InvalidConfigFileThatExists_UsesConfigurationValueDefaults() Assert.IsTrue(_configurationRepository.ShowChatBubbles); Assert.IsFalse(_configurationRepository.ShowTransition); - Assert.AreEqual(ConfigDefaults.InGameWidth, _configurationRepository.InGameWidth); - Assert.AreEqual(ConfigDefaults.InGameHeight, _configurationRepository.InGameHeight); - Assert.IsFalse(_configurationRepository.MusicEnabled); Assert.IsFalse(_configurationRepository.SoundEnabled); diff --git a/EOLib/Domain/Character/CharacterSessionRepository.cs b/EOLib/Domain/Character/CharacterSessionRepository.cs index fee709c83..13b1b7207 100644 --- a/EOLib/Domain/Character/CharacterSessionRepository.cs +++ b/EOLib/Domain/Character/CharacterSessionRepository.cs @@ -11,7 +11,7 @@ public interface ICharacterSessionRepository : IResettable int LastKillExp { get; set; } - int TodayTotalExp { get; set; } + ulong TodayTotalExp { get; set; } } public interface ICharacterSessionProvider : IResettable @@ -22,7 +22,7 @@ public interface ICharacterSessionProvider : IResettable int LastKillExp { get; } - int TodayTotalExp { get; } + ulong TodayTotalExp { get; } } [AutoMappedType(IsSingleton = true)] @@ -34,7 +34,7 @@ public class CharacterSessionRepository : ICharacterSessionRepository, ICharacte public int LastKillExp { get; set; } - public int TodayTotalExp { get; set; } + public ulong TodayTotalExp { get; set; } public CharacterSessionRepository() { diff --git a/EOLib/PacketHandlers/NPC/NPCSpecHandler.cs b/EOLib/PacketHandlers/NPC/NPCSpecHandler.cs index b5a8f51ab..ad4fa638c 100644 --- a/EOLib/PacketHandlers/NPC/NPCSpecHandler.cs +++ b/EOLib/PacketHandlers/NPC/NPCSpecHandler.cs @@ -92,7 +92,7 @@ public override bool HandlePacket(IPacket packet) _characterSessionRepository.LastKillExp = expDifference; if (expDifference > _characterSessionRepository.BestKillExp) _characterSessionRepository.BestKillExp = expDifference; - _characterSessionRepository.TodayTotalExp += expDifference; + _characterSessionRepository.TodayTotalExp += Convert.ToUInt64(Math.Max(expDifference, 0)); } if (droppedItemID > 0)