From 0ba65eb9e0908b42decc3d4b0180d1a47d32a59f Mon Sep 17 00:00:00 2001 From: sorokya Date: Sun, 27 Mar 2022 13:47:54 +0200 Subject: [PATCH 01/12] Rename AutoRefresh to CharacterMapInfo Rename AutoRefresh2 to NPCMapInfo Rename Appear to MapInfo Change NPCEnterMapHandler to MapInfoHandler Make MapInfoHandler read character data --- EOLib/Net/PacketFamily.cs | 6 +- EOLib/PacketHandlers/MapInfoHandler.cs | 73 ++++++++++++++++++++++ EOLib/PacketHandlers/NPCEnterMapHandler.cs | 49 --------------- 3 files changed, 76 insertions(+), 52 deletions(-) create mode 100644 EOLib/PacketHandlers/MapInfoHandler.cs delete mode 100644 EOLib/PacketHandlers/NPCEnterMapHandler.cs diff --git a/EOLib/Net/PacketFamily.cs b/EOLib/Net/PacketFamily.cs index a81b0bba1..79de2bccf 100644 --- a/EOLib/Net/PacketFamily.cs +++ b/EOLib/Net/PacketFamily.cs @@ -26,9 +26,9 @@ public enum PacketFamily : byte Party = (byte)24, Refresh = (byte)25, NPC = (byte)26, - AutoRefresh = (byte)27, - AutoRefresh2 = (byte)28, - Appear = (byte)29, + CharacterMapInfo = (byte)27, + NPCMapInfo = (byte)28, + MapInfo = (byte)29, PaperDoll = (byte)30, Effect = (byte)31, Trade = (byte)32, diff --git a/EOLib/PacketHandlers/MapInfoHandler.cs b/EOLib/PacketHandlers/MapInfoHandler.cs new file mode 100644 index 000000000..4d0c3a8db --- /dev/null +++ b/EOLib/PacketHandlers/MapInfoHandler.cs @@ -0,0 +1,73 @@ +using AutomaticTypeMapper; +using EOLib.Domain.Extensions; +using EOLib.Domain.Login; +using EOLib.Domain.Map; +using EOLib.Domain.NPC; +using EOLib.IO.Extensions; +using EOLib.IO.Repositories; +using EOLib.Net; +using EOLib.Net.Handlers; +using EOLib.Net.Translators; + +namespace EOLib.PacketHandlers +{ + [AutoMappedType] + public class MapInfoHandler : InGameOnlyPacketHandler + { + private readonly ICurrentMapStateRepository _currentMapStateRepository; + private readonly ICharacterFromPacketFactory _characterFromPacketFactory; + private readonly IEIFFileProvider _eifFileProvider; + + public override PacketFamily Family => PacketFamily.MapInfo; + + public override PacketAction Action => PacketAction.Reply; + + public MapInfoHandler(IPlayerInfoProvider playerInfoProvider, + ICurrentMapStateRepository currentMapStateRepository, + ICharacterFromPacketFactory characterFromPacketFactory, + IEIFFileProvider eifFileProvider + ) + : base(playerInfoProvider) + { + _currentMapStateRepository = currentMapStateRepository; + _characterFromPacketFactory = characterFromPacketFactory; + } + + public override bool HandlePacket(IPacket packet) + { + var num_entities = packet.ReadChar(); + + if (packet.PeekByte() == 0xFF) + { + for (var i = 0; i < num_entities; i++) + { + var character = _characterFromPacketFactory.CreateCharacter(packet); + if (_currentMapStateRepository.Characters.ContainsKey(character.ID)) + { + var existingCharacter = _currentMapStateRepository.Characters[character.ID]; + var isRangedWeapon = _eifFileProvider.EIFFile.IsRangedWeapon(character.RenderProperties.WeaponGraphic); + character = existingCharacter.WithAppliedData(character, isRangedWeapon); + } + _currentMapStateRepository.Characters[character.ID] = character; + } + } + + while (packet.ReadPosition < packet.Length) + { + var index = packet.ReadChar(); + var id = packet.ReadShort(); + var x = packet.ReadChar(); + var y = packet.ReadChar(); + var direction = (EODirection)packet.ReadChar(); + + INPC npc = new NPC(id, index); + npc = npc.WithX(x).WithY(y).WithDirection(direction).WithFrame(NPCFrame.Standing); + + _currentMapStateRepository.NPCs.RemoveWhere(n => n.Index == index); + _currentMapStateRepository.NPCs.Add(npc); + } + + return true; + } + } +} diff --git a/EOLib/PacketHandlers/NPCEnterMapHandler.cs b/EOLib/PacketHandlers/NPCEnterMapHandler.cs deleted file mode 100644 index fd7feb790..000000000 --- a/EOLib/PacketHandlers/NPCEnterMapHandler.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System.Linq; -using AutomaticTypeMapper; -using EOLib.Domain.Login; -using EOLib.Domain.Map; -using EOLib.Domain.NPC; -using EOLib.Net; -using EOLib.Net.Handlers; - -namespace EOLib.PacketHandlers -{ - [AutoMappedType] - public class NPCEnterMapHandler : InGameOnlyPacketHandler - { - private readonly ICurrentMapStateRepository _currentMapStateRepository; - - public override PacketFamily Family => PacketFamily.Appear; - - public override PacketAction Action => PacketAction.Reply; - - public NPCEnterMapHandler(IPlayerInfoProvider playerInfoProvider, - ICurrentMapStateRepository currentMapStateRepository) - : base(playerInfoProvider) - { - _currentMapStateRepository = currentMapStateRepository; - } - - public override bool HandlePacket(IPacket packet) - { - if (packet.Length - packet.ReadPosition != 8) - throw new MalformedPacketException("Invalid packet length for new NPC in map.", packet); - if (!packet.ReadBytes(2).SequenceEqual(new byte[] {1, 255})) - throw new MalformedPacketException("Invalid header data for new NPC in map. Expected byte values 0x01, 0xff.", packet); - - var index = packet.ReadChar(); - var id = packet.ReadShort(); - var x = packet.ReadChar(); - var y = packet.ReadChar(); - var direction = (EODirection) packet.ReadChar(); - - INPC npc = new NPC(id, index); - npc = npc.WithX(x).WithY(y).WithDirection(direction).WithFrame(NPCFrame.Standing); - - _currentMapStateRepository.NPCs.RemoveWhere(n => n.Index == index); - _currentMapStateRepository.NPCs.Add(npc); - - return true; - } - } -} From 31cc6d942b7449b93ddff092528bb5e96cb70b88 Mon Sep 17 00:00:00 2001 From: sorokya Date: Sun, 27 Mar 2022 13:52:44 +0200 Subject: [PATCH 02/12] Read ClassID in CharacterFromPacketFactory --- EOLib/Net/Translators/CharacterFromPacketFactory.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/EOLib/Net/Translators/CharacterFromPacketFactory.cs b/EOLib/Net/Translators/CharacterFromPacketFactory.cs index 8cb94e0d2..bf9cd2877 100644 --- a/EOLib/Net/Translators/CharacterFromPacketFactory.cs +++ b/EOLib/Net/Translators/CharacterFromPacketFactory.cs @@ -27,7 +27,7 @@ public ICharacter CreateCharacter(IPacket packet) var yLoc = packet.ReadShort(); var direction = (EODirection)packet.ReadChar(); - packet.ReadChar(); //value is always 6? Unknown use + var classID = packet.ReadChar(); var guildTag = packet.ReadString(3); var level = packet.ReadChar(); @@ -78,6 +78,7 @@ public ICharacter CreateCharacter(IPacket packet) return new Character() .WithName(name) .WithID(id) + .WithClassID(classID) .WithMapID(mapID) .WithGuildTag(guildTag) .WithStats(stats) From 2803ca9bc56aa5487d12f829d770963be05320d7 Mon Sep 17 00:00:00 2001 From: sorokya Date: Sun, 27 Mar 2022 14:02:20 +0200 Subject: [PATCH 03/12] Create NPCFromPacketFactory --- EOLib/Net/Translators/NPCFromPacketFactory.cs | 31 +++++++++++++++++++ EOLib/PacketHandlers/MapInfoHandler.cs | 17 +++------- 2 files changed, 36 insertions(+), 12 deletions(-) create mode 100644 EOLib/Net/Translators/NPCFromPacketFactory.cs diff --git a/EOLib/Net/Translators/NPCFromPacketFactory.cs b/EOLib/Net/Translators/NPCFromPacketFactory.cs new file mode 100644 index 000000000..b23248822 --- /dev/null +++ b/EOLib/Net/Translators/NPCFromPacketFactory.cs @@ -0,0 +1,31 @@ +using AutomaticTypeMapper; +using EOLib.Domain.NPC; + +namespace EOLib.Net.Translators +{ + [AutoMappedType] + public class NPCFromPacketFactory : INPCFromPacketFactory + { + public NPCFromPacketFactory() + { + } + + public INPC CreateNPC(IPacket packet) + { + var index = packet.ReadChar(); + var id = packet.ReadShort(); + var x = packet.ReadChar(); + var y = packet.ReadChar(); + var direction = (EODirection)packet.ReadChar(); + + INPC npc = new NPC(id, index); + npc = npc.WithX(x).WithY(y).WithDirection(direction).WithFrame(NPCFrame.Standing); + return npc; + } + } + + public interface INPCFromPacketFactory + { + INPC CreateNPC(IPacket packet); + } +} diff --git a/EOLib/PacketHandlers/MapInfoHandler.cs b/EOLib/PacketHandlers/MapInfoHandler.cs index 4d0c3a8db..0dcd5ff59 100644 --- a/EOLib/PacketHandlers/MapInfoHandler.cs +++ b/EOLib/PacketHandlers/MapInfoHandler.cs @@ -2,7 +2,6 @@ using EOLib.Domain.Extensions; using EOLib.Domain.Login; using EOLib.Domain.Map; -using EOLib.Domain.NPC; using EOLib.IO.Extensions; using EOLib.IO.Repositories; using EOLib.Net; @@ -16,6 +15,7 @@ public class MapInfoHandler : InGameOnlyPacketHandler { private readonly ICurrentMapStateRepository _currentMapStateRepository; private readonly ICharacterFromPacketFactory _characterFromPacketFactory; + private readonly INPCFromPacketFactory _npcFromPacketFactory; private readonly IEIFFileProvider _eifFileProvider; public override PacketFamily Family => PacketFamily.MapInfo; @@ -25,12 +25,13 @@ public class MapInfoHandler : InGameOnlyPacketHandler public MapInfoHandler(IPlayerInfoProvider playerInfoProvider, ICurrentMapStateRepository currentMapStateRepository, ICharacterFromPacketFactory characterFromPacketFactory, - IEIFFileProvider eifFileProvider + INPCFromPacketFactory npcFromPacketFactory ) : base(playerInfoProvider) { _currentMapStateRepository = currentMapStateRepository; _characterFromPacketFactory = characterFromPacketFactory; + _npcFromPacketFactory = npcFromPacketFactory; } public override bool HandlePacket(IPacket packet) @@ -54,16 +55,8 @@ public override bool HandlePacket(IPacket packet) while (packet.ReadPosition < packet.Length) { - var index = packet.ReadChar(); - var id = packet.ReadShort(); - var x = packet.ReadChar(); - var y = packet.ReadChar(); - var direction = (EODirection)packet.ReadChar(); - - INPC npc = new NPC(id, index); - npc = npc.WithX(x).WithY(y).WithDirection(direction).WithFrame(NPCFrame.Standing); - - _currentMapStateRepository.NPCs.RemoveWhere(n => n.Index == index); + var npc = _npcFromPacketFactory.CreateNPC(packet); + _currentMapStateRepository.NPCs.RemoveWhere(n => n.Index == npc.Index); _currentMapStateRepository.NPCs.Add(npc); } From 278c31f86729eea8e34ad152dca0d03168b1d8a8 Mon Sep 17 00:00:00 2001 From: sorokya Date: Sun, 27 Mar 2022 14:45:21 +0200 Subject: [PATCH 04/12] Request map info for new characters/npcs in the walk reply --- EOLib/PacketHandlers/MainPlayerWalkHandler.cs | 63 ++++++++++++++++++- EOLib/PacketHandlers/MapInfoHandler.cs | 7 ++- 2 files changed, 65 insertions(+), 5 deletions(-) diff --git a/EOLib/PacketHandlers/MainPlayerWalkHandler.cs b/EOLib/PacketHandlers/MainPlayerWalkHandler.cs index 2783ae533..99dd1e6ae 100644 --- a/EOLib/PacketHandlers/MainPlayerWalkHandler.cs +++ b/EOLib/PacketHandlers/MainPlayerWalkHandler.cs @@ -2,7 +2,10 @@ using EOLib.Domain.Login; using EOLib.Domain.Map; using EOLib.Net; +using EOLib.Net.Communication; using EOLib.Net.Handlers; +using System.Collections.Generic; +using System.Linq; namespace EOLib.PacketHandlers { @@ -10,21 +13,35 @@ namespace EOLib.PacketHandlers public class MainPlayerWalkHandler : InGameOnlyPacketHandler { private readonly ICurrentMapStateRepository _currentMapStateRepository; + private readonly IPacketSendService _packetSendService; public override PacketFamily Family => PacketFamily.Walk; public override PacketAction Action => PacketAction.Reply; public MainPlayerWalkHandler(IPlayerInfoProvider playerInfoProvider, - ICurrentMapStateRepository currentMapStateRepository) + ICurrentMapStateRepository currentMapStateRepository, + IPacketSendService packetSendService) : base(playerInfoProvider) { _currentMapStateRepository = currentMapStateRepository; + _packetSendService = packetSendService; } public override bool HandlePacket(IPacket packet) { - if (packet.ReadByte() != 255 || packet.ReadByte() != 255) - return false; + var playerIDs = new List(); + while (packet.PeekByte() != 0xFF) + { + playerIDs.Add(packet.ReadShort()); + } + packet.ReadByte(); + + var npcIndexes = new List(); + while (packet.PeekByte() != 0xFF) + { + npcIndexes.Add(packet.ReadChar()); + } + packet.ReadByte(); var numberOfMapItems = packet.PeekEndString().Length / 9; for (int i = 0; i < numberOfMapItems; ++i) @@ -39,6 +56,46 @@ public override bool HandlePacket(IPacket packet) _currentMapStateRepository.MapItems.Add(newItem); } + var newPlayerIDs = playerIDs + .Where(id => !_currentMapStateRepository.Characters.ContainsKey(id)) + .ToList(); + + var newNPCIndxes = npcIndexes + .Where(index => !_currentMapStateRepository.NPCs.Any((npc) => npc.Index == index)) + .ToList(); + + if (newPlayerIDs.Count > 0 || newNPCIndxes.Count > 0) + { + IPacketBuilder builder = new PacketBuilder(PacketFamily.MapInfo, PacketAction.Request); + + if (newPlayerIDs.Count > 0) + { + foreach (var playerId in newPlayerIDs) + { + builder = builder.AddShort(playerId); + } + } + + if (newNPCIndxes.Count > 0) + { + builder.AddByte(0xFF); + foreach (var npcIndex in newNPCIndxes) + { + builder = builder.AddChar(npcIndex); + } + } + + try + { + var request = builder.Build(); + _packetSendService.SendPacket(request); + } + catch (NoDataSentException) + { + return false; + } + } + return true; } } diff --git a/EOLib/PacketHandlers/MapInfoHandler.cs b/EOLib/PacketHandlers/MapInfoHandler.cs index 0dcd5ff59..ebf0ab556 100644 --- a/EOLib/PacketHandlers/MapInfoHandler.cs +++ b/EOLib/PacketHandlers/MapInfoHandler.cs @@ -25,13 +25,15 @@ public class MapInfoHandler : InGameOnlyPacketHandler public MapInfoHandler(IPlayerInfoProvider playerInfoProvider, ICurrentMapStateRepository currentMapStateRepository, ICharacterFromPacketFactory characterFromPacketFactory, - INPCFromPacketFactory npcFromPacketFactory + INPCFromPacketFactory npcFromPacketFactory, + IEIFFileProvider eifFileProvider ) : base(playerInfoProvider) { _currentMapStateRepository = currentMapStateRepository; _characterFromPacketFactory = characterFromPacketFactory; _npcFromPacketFactory = npcFromPacketFactory; + _eifFileProvider = eifFileProvider; } public override bool HandlePacket(IPacket packet) @@ -40,6 +42,7 @@ public override bool HandlePacket(IPacket packet) if (packet.PeekByte() == 0xFF) { + packet.ReadByte(); for (var i = 0; i < num_entities; i++) { var character = _characterFromPacketFactory.CreateCharacter(packet); @@ -53,7 +56,7 @@ public override bool HandlePacket(IPacket packet) } } - while (packet.ReadPosition < packet.Length) + while (num_entities > 0 && packet.ReadPosition < packet.Length) { var npc = _npcFromPacketFactory.CreateNPC(packet); _currentMapStateRepository.NPCs.RemoveWhere(n => n.Index == npc.Index); From b2d72c5f993e01d9a7f29cb4615d709907224209 Mon Sep 17 00:00:00 2001 From: sorokya Date: Sun, 27 Mar 2022 15:17:58 +0200 Subject: [PATCH 05/12] Store unknown Players/NPC in MapState repository --- EOLib/Domain/Map/CurrentMapStateRepository.cs | 14 +++++ EOLib/PacketHandlers/AdminHideHandler.cs | 18 ++++-- EOLib/PacketHandlers/AdminShowHandler.cs | 17 ++++-- .../Effects/PlayerSpikeDamageHandler.cs | 19 +++--- EOLib/PacketHandlers/ItemEquipHandler.cs | 5 ++ EOLib/PacketHandlers/MainPlayerWalkHandler.cs | 61 ++++--------------- EOLib/PacketHandlers/NPCActionHandler.cs | 10 ++- EOLib/PacketHandlers/NPCLeaveMapHandler.cs | 4 ++ EOLib/PacketHandlers/NPCTakeDamageHandler.cs | 10 ++- EOLib/PacketHandlers/PlayerAttackHandler.cs | 24 +++++--- .../PlayerAvatarChangeHandler.cs | 1 + EOLib/PacketHandlers/PlayerLeaveMapHandler.cs | 16 +++-- EOLib/PacketHandlers/PlayerSitHandler.cs | 1 + EOLib/PacketHandlers/PlayerStandHandler.cs | 1 + .../PlayerTargetOtherSpellHandler.cs | 1 + EOLib/PacketHandlers/PlayerWalkHandler.cs | 38 +++++++----- 16 files changed, 138 insertions(+), 102 deletions(-) diff --git a/EOLib/Domain/Map/CurrentMapStateRepository.cs b/EOLib/Domain/Map/CurrentMapStateRepository.cs index 8770e6917..44a8a7047 100644 --- a/EOLib/Domain/Map/CurrentMapStateRepository.cs +++ b/EOLib/Domain/Map/CurrentMapStateRepository.cs @@ -24,6 +24,10 @@ public interface ICurrentMapStateRepository HashSet VisibleSpikeTraps { get; set; } WarpState MapWarpState { get; set; } + + HashSet UnknownPlayerIDs { get; set; } + + HashSet UnknownNPCIndexes { get; set; } } public interface ICurrentMapStateProvider @@ -45,6 +49,10 @@ public interface ICurrentMapStateProvider IReadOnlyCollection VisibleSpikeTraps { get; } WarpState MapWarpState { get; set; } + + HashSet UnknownPlayerIDs { get; } + + HashSet UnknownNPCIndexes { get; } } [AutoMappedType(IsSingleton = true)] @@ -68,6 +76,10 @@ public class CurrentMapStateRepository : ICurrentMapStateRepository, ICurrentMap public WarpState MapWarpState { get; set; } + public HashSet UnknownPlayerIDs { get; set; } + + public HashSet UnknownNPCIndexes { get; set; } + IReadOnlyDictionary ICurrentMapStateProvider.Characters => Characters; IReadOnlyCollection ICurrentMapStateProvider.NPCs => NPCs; @@ -96,6 +108,8 @@ public void ResetState() OpenDoors = new HashSet(); PendingDoors = new HashSet(); VisibleSpikeTraps = new HashSet(); + UnknownPlayerIDs = new HashSet(); + UnknownNPCIndexes = new HashSet(); MapWarpState = WarpState.None; } diff --git a/EOLib/PacketHandlers/AdminHideHandler.cs b/EOLib/PacketHandlers/AdminHideHandler.cs index 4a6f3f386..979ab0edc 100644 --- a/EOLib/PacketHandlers/AdminHideHandler.cs +++ b/EOLib/PacketHandlers/AdminHideHandler.cs @@ -33,12 +33,18 @@ public override bool HandlePacket(IPacket packet) _characterRepository.MainCharacter = Hidden(_characterRepository.MainCharacter); else { - if (!_currentMapStateRepository.Characters.ContainsKey(id)) - return false; - var character = _currentMapStateRepository.Characters[id]; - - var updatedCharacter = Hidden(character); - _currentMapStateRepository.Characters[id] = updatedCharacter; + if (_currentMapStateRepository.Characters.ContainsKey(id)) + { + var character = _currentMapStateRepository.Characters[id]; + + var updatedCharacter = Hidden(character); + _currentMapStateRepository.Characters[id] = updatedCharacter; + } + else + { + _currentMapStateRepository.UnknownPlayerIDs.Add(id); + } + } return true; diff --git a/EOLib/PacketHandlers/AdminShowHandler.cs b/EOLib/PacketHandlers/AdminShowHandler.cs index 79591fd22..368aa4b76 100644 --- a/EOLib/PacketHandlers/AdminShowHandler.cs +++ b/EOLib/PacketHandlers/AdminShowHandler.cs @@ -33,12 +33,17 @@ public override bool HandlePacket(IPacket packet) _characterRepository.MainCharacter = Shown(_characterRepository.MainCharacter); else { - if (!_currentMapStateRepository.Characters.ContainsKey(id)) - return false; - var character = _currentMapStateRepository.Characters[id]; - - var updatedCharacter = Shown(character); - _currentMapStateRepository.Characters[id] = updatedCharacter; + if (_currentMapStateRepository.Characters.ContainsKey(id)) + { + var character = _currentMapStateRepository.Characters[id]; + + var updatedCharacter = Shown(character); + _currentMapStateRepository.Characters[id] = updatedCharacter; + } + else + { + _currentMapStateRepository.UnknownPlayerIDs.Add(id); + } } return true; diff --git a/EOLib/PacketHandlers/Effects/PlayerSpikeDamageHandler.cs b/EOLib/PacketHandlers/Effects/PlayerSpikeDamageHandler.cs index b88623cf1..136d2234f 100644 --- a/EOLib/PacketHandlers/Effects/PlayerSpikeDamageHandler.cs +++ b/EOLib/PacketHandlers/Effects/PlayerSpikeDamageHandler.cs @@ -35,16 +35,21 @@ public override bool HandlePacket(IPacket packet) var isDead = packet.ReadChar() != 0; var damageTaken = packet.ReadThree(); - if (!_currentMapStateRepository.Characters.ContainsKey(characterId)) - return false; - - var updatedCharacter = _currentMapStateRepository.Characters[characterId].WithDamage(damageTaken, isDead); - _currentMapStateRepository.Characters[characterId] = updatedCharacter; + if (_currentMapStateRepository.Characters.ContainsKey(characterId)) + { + var updatedCharacter = _currentMapStateRepository.Characters[characterId].WithDamage(damageTaken, isDead); + _currentMapStateRepository.Characters[characterId] = updatedCharacter; - foreach (var notifier in _otherCharacterEventNotifiers) + foreach (var notifier in _otherCharacterEventNotifiers) + { + notifier.OtherCharacterTakeDamage(characterId, playerPercentHealth, damageTaken); + } + } + else { - notifier.OtherCharacterTakeDamage(characterId, playerPercentHealth, damageTaken); + _currentMapStateRepository.UnknownPlayerIDs.Add(characterId); } + return true; } diff --git a/EOLib/PacketHandlers/ItemEquipHandler.cs b/EOLib/PacketHandlers/ItemEquipHandler.cs index abdd49227..9efa9882c 100644 --- a/EOLib/PacketHandlers/ItemEquipHandler.cs +++ b/EOLib/PacketHandlers/ItemEquipHandler.cs @@ -107,6 +107,11 @@ protected bool HandlePaperdollPacket(IPacket packet, bool itemUnequipped) } }); + update.MatchNone(() => + { + _currentMapStateRepository.UnknownPlayerIDs.Add(playerId); + }); + return true; } } diff --git a/EOLib/PacketHandlers/MainPlayerWalkHandler.cs b/EOLib/PacketHandlers/MainPlayerWalkHandler.cs index 99dd1e6ae..8df46d5f4 100644 --- a/EOLib/PacketHandlers/MainPlayerWalkHandler.cs +++ b/EOLib/PacketHandlers/MainPlayerWalkHandler.cs @@ -2,9 +2,7 @@ using EOLib.Domain.Login; using EOLib.Domain.Map; using EOLib.Net; -using EOLib.Net.Communication; using EOLib.Net.Handlers; -using System.Collections.Generic; using System.Linq; namespace EOLib.PacketHandlers @@ -13,33 +11,36 @@ namespace EOLib.PacketHandlers public class MainPlayerWalkHandler : InGameOnlyPacketHandler { private readonly ICurrentMapStateRepository _currentMapStateRepository; - private readonly IPacketSendService _packetSendService; public override PacketFamily Family => PacketFamily.Walk; public override PacketAction Action => PacketAction.Reply; public MainPlayerWalkHandler(IPlayerInfoProvider playerInfoProvider, - ICurrentMapStateRepository currentMapStateRepository, - IPacketSendService packetSendService) + ICurrentMapStateRepository currentMapStateRepository) : base(playerInfoProvider) { _currentMapStateRepository = currentMapStateRepository; - _packetSendService = packetSendService; } public override bool HandlePacket(IPacket packet) { - var playerIDs = new List(); while (packet.PeekByte() != 0xFF) { - playerIDs.Add(packet.ReadShort()); + var playerID = packet.ReadShort(); + if (!_currentMapStateRepository.Characters.ContainsKey(playerID)) + { + _currentMapStateRepository.UnknownPlayerIDs.Add(playerID); + } } packet.ReadByte(); - var npcIndexes = new List(); while (packet.PeekByte() != 0xFF) { - npcIndexes.Add(packet.ReadChar()); + var index = packet.ReadChar(); + if (!_currentMapStateRepository.NPCs.Any((npc) => npc.Index == index)) + { + _currentMapStateRepository.UnknownNPCIndexes.Add(index); + } } packet.ReadByte(); @@ -56,46 +57,6 @@ public override bool HandlePacket(IPacket packet) _currentMapStateRepository.MapItems.Add(newItem); } - var newPlayerIDs = playerIDs - .Where(id => !_currentMapStateRepository.Characters.ContainsKey(id)) - .ToList(); - - var newNPCIndxes = npcIndexes - .Where(index => !_currentMapStateRepository.NPCs.Any((npc) => npc.Index == index)) - .ToList(); - - if (newPlayerIDs.Count > 0 || newNPCIndxes.Count > 0) - { - IPacketBuilder builder = new PacketBuilder(PacketFamily.MapInfo, PacketAction.Request); - - if (newPlayerIDs.Count > 0) - { - foreach (var playerId in newPlayerIDs) - { - builder = builder.AddShort(playerId); - } - } - - if (newNPCIndxes.Count > 0) - { - builder.AddByte(0xFF); - foreach (var npcIndex in newNPCIndxes) - { - builder = builder.AddChar(npcIndex); - } - } - - try - { - var request = builder.Build(); - _packetSendService.SendPacket(request); - } - catch (NoDataSentException) - { - return false; - } - } - return true; } } diff --git a/EOLib/PacketHandlers/NPCActionHandler.cs b/EOLib/PacketHandlers/NPCActionHandler.cs index a5b9d99a0..5204682cc 100644 --- a/EOLib/PacketHandlers/NPCActionHandler.cs +++ b/EOLib/PacketHandlers/NPCActionHandler.cs @@ -69,7 +69,11 @@ public override bool HandlePacket(IPacket packet) { npc = _currentMapStateRepository.NPCs.Single(n => n.Index == index); } - catch (InvalidOperationException) { return false; } + catch (InvalidOperationException) + { + _currentMapStateRepository.UnknownNPCIndexes.Add(index); + return false; + } var updatedNpc = Option.None(); switch (num255s) @@ -142,6 +146,10 @@ private INPC HandleNPCAttack(IPacket packet, INPC npc) foreach (var notifier in _otherCharacterNotifiers) notifier.OtherCharacterTakeDamage(characterID, playerPercentHealth, damageTaken); } + else + { + _currentMapStateRepository.UnknownPlayerIDs.Add(characterID); + } foreach (var notifier in _npcAnimationNotifiers) notifier.StartNPCAttackAnimation(npc.Index); diff --git a/EOLib/PacketHandlers/NPCLeaveMapHandler.cs b/EOLib/PacketHandlers/NPCLeaveMapHandler.cs index 3ccf6a1b2..d4aa52bd7 100644 --- a/EOLib/PacketHandlers/NPCLeaveMapHandler.cs +++ b/EOLib/PacketHandlers/NPCLeaveMapHandler.cs @@ -113,6 +113,10 @@ private void UpdatePlayerDirection(short playerID, EODirection playerDirection) var updatedCharacter = _currentMapStateRepository.Characters[playerID].WithRenderProperties(updatedRenderProps); _currentMapStateRepository.Characters[playerID] = updatedCharacter; } + else + { + _currentMapStateRepository.UnknownPlayerIDs.Add(playerID); + } } private void UpdateCharacterStat(CharacterStat whichStat, int statValue) diff --git a/EOLib/PacketHandlers/NPCTakeDamageHandler.cs b/EOLib/PacketHandlers/NPCTakeDamageHandler.cs index 1bd3f2073..f3a93b7d4 100644 --- a/EOLib/PacketHandlers/NPCTakeDamageHandler.cs +++ b/EOLib/PacketHandlers/NPCTakeDamageHandler.cs @@ -68,6 +68,10 @@ public override bool HandlePacket(IPacket packet) var updatedCharacter = _currentMapStateRepository.Characters[fromPlayerId].WithRenderProperties(renderProps); _currentMapStateRepository.Characters[fromPlayerId] = updatedCharacter; } + else + { + _currentMapStateRepository.UnknownPlayerIDs.Add(fromPlayerId); + } // todo: this has the potential to bug out if the opponent ID is never reset and the player dies/leaves try @@ -79,7 +83,11 @@ public override bool HandlePacket(IPacket packet) foreach (var notifier in _npcNotifiers) notifier.NPCTakeDamage(npcIndex, fromPlayerId, damageToNpc, npcPctHealth, spellId); } - catch (InvalidOperationException) { return false; } + catch (InvalidOperationException) + { + _currentMapStateRepository.UnknownNPCIndexes.Add((byte)npcIndex); + return false; + } return true; } diff --git a/EOLib/PacketHandlers/PlayerAttackHandler.cs b/EOLib/PacketHandlers/PlayerAttackHandler.cs index e292f584f..cd9249d66 100644 --- a/EOLib/PacketHandlers/PlayerAttackHandler.cs +++ b/EOLib/PacketHandlers/PlayerAttackHandler.cs @@ -32,18 +32,22 @@ public override bool HandlePacket(IPacket packet) var playerID = packet.ReadShort(); var direction = (EODirection)packet.ReadChar(); - if (!_currentMapStateRepository.Characters.ContainsKey(playerID)) - return false; - - var character = _currentMapStateRepository.Characters[playerID]; - if (character.RenderProperties.Direction != direction) + if (_currentMapStateRepository.Characters.ContainsKey(playerID)) { - var renderProperties = character.RenderProperties.WithDirection(direction); - _currentMapStateRepository.Characters[playerID] = character.WithRenderProperties(renderProperties); + var character = _currentMapStateRepository.Characters[playerID]; + if (character.RenderProperties.Direction != direction) + { + var renderProperties = character.RenderProperties.WithDirection(direction); + _currentMapStateRepository.Characters[playerID] = character.WithRenderProperties(renderProperties); + } + + foreach (var notifier in _otherCharacterAnimationNotifiers) + notifier.StartOtherCharacterAttackAnimation(playerID); + } + else + { + _currentMapStateRepository.UnknownPlayerIDs.Add(playerID); } - - foreach (var notifier in _otherCharacterAnimationNotifiers) - notifier.StartOtherCharacterAttackAnimation(playerID); return true; } diff --git a/EOLib/PacketHandlers/PlayerAvatarChangeHandler.cs b/EOLib/PacketHandlers/PlayerAvatarChangeHandler.cs index 6c74a4ef1..c1badaa00 100644 --- a/EOLib/PacketHandlers/PlayerAvatarChangeHandler.cs +++ b/EOLib/PacketHandlers/PlayerAvatarChangeHandler.cs @@ -46,6 +46,7 @@ public override bool HandlePacket(IPacket packet) } else { + _currentMapStateRepository.UnknownPlayerIDs.Add(playerID); return false; } diff --git a/EOLib/PacketHandlers/PlayerLeaveMapHandler.cs b/EOLib/PacketHandlers/PlayerLeaveMapHandler.cs index cee526c38..8c7180b93 100644 --- a/EOLib/PacketHandlers/PlayerLeaveMapHandler.cs +++ b/EOLib/PacketHandlers/PlayerLeaveMapHandler.cs @@ -39,12 +39,16 @@ public override bool HandlePacket(IPacket packet) notifier.NotifyWarpLeaveEffect(id, anim); } - if (!_currentMapStateRepository.Characters.ContainsKey(id)) - return false; - - var character = _currentMapStateRepository.Characters[id]; - _currentMapStateRepository.Characters.Remove(id); - _currentMapStateRepository.VisibleSpikeTraps.Remove(new MapCoordinate(character.RenderProperties.MapX, character.RenderProperties.MapY)); + if (_currentMapStateRepository.Characters.ContainsKey(id)) + { + var character = _currentMapStateRepository.Characters[id]; + _currentMapStateRepository.Characters.Remove(id); + _currentMapStateRepository.VisibleSpikeTraps.Remove(new MapCoordinate(character.RenderProperties.MapX, character.RenderProperties.MapY)); + } + else + { + _currentMapStateRepository.UnknownPlayerIDs.Add(id); + } return true; } diff --git a/EOLib/PacketHandlers/PlayerSitHandler.cs b/EOLib/PacketHandlers/PlayerSitHandler.cs index 9c1a39008..6a67eaa72 100644 --- a/EOLib/PacketHandlers/PlayerSitHandler.cs +++ b/EOLib/PacketHandlers/PlayerSitHandler.cs @@ -56,6 +56,7 @@ public override bool HandlePacket(IPacket packet) } else { + _currentMapStateRepository.UnknownPlayerIDs.Add(playerId); return false; } diff --git a/EOLib/PacketHandlers/PlayerStandHandler.cs b/EOLib/PacketHandlers/PlayerStandHandler.cs index de06041d1..034eafb68 100644 --- a/EOLib/PacketHandlers/PlayerStandHandler.cs +++ b/EOLib/PacketHandlers/PlayerStandHandler.cs @@ -48,6 +48,7 @@ public override bool HandlePacket(IPacket packet) } else { + _currentMapStateRepository.UnknownPlayerIDs.Add(playerId); return false; } diff --git a/EOLib/PacketHandlers/PlayerTargetOtherSpellHandler.cs b/EOLib/PacketHandlers/PlayerTargetOtherSpellHandler.cs index f1a382eec..451961dea 100644 --- a/EOLib/PacketHandlers/PlayerTargetOtherSpellHandler.cs +++ b/EOLib/PacketHandlers/PlayerTargetOtherSpellHandler.cs @@ -52,6 +52,7 @@ public override bool HandlePacket(IPacket packet) } else { + _currentMapStateRepository.UnknownPlayerIDs.Add(sourcePlayerId); return false; } diff --git a/EOLib/PacketHandlers/PlayerWalkHandler.cs b/EOLib/PacketHandlers/PlayerWalkHandler.cs index d410ed3af..23410dd3c 100644 --- a/EOLib/PacketHandlers/PlayerWalkHandler.cs +++ b/EOLib/PacketHandlers/PlayerWalkHandler.cs @@ -8,6 +8,7 @@ using EOLib.Domain.Map; using EOLib.Domain.Notifiers; using EOLib.Net; +using EOLib.Net.Communication; using EOLib.Net.Handlers; namespace EOLib.PacketHandlers @@ -17,6 +18,7 @@ public class PlayerWalkHandler : InGameOnlyPacketHandler { private readonly ICurrentMapStateRepository _currentMapStateRepository; private readonly IEnumerable _otherCharacterAnimationNotifiers; + private readonly IPacketSendService _packetSendService; public override PacketFamily Family => PacketFamily.Walk; @@ -24,37 +26,43 @@ public class PlayerWalkHandler : InGameOnlyPacketHandler public PlayerWalkHandler(IPlayerInfoProvider playerInfoProvider, ICurrentMapStateRepository currentMapStateRepository, - IEnumerable otherCharacterAnimationNotifiers) + IEnumerable otherCharacterAnimationNotifiers, + IPacketSendService packetSendService) : base(playerInfoProvider) { _currentMapStateRepository = currentMapStateRepository; _otherCharacterAnimationNotifiers = otherCharacterAnimationNotifiers; + _packetSendService = packetSendService; } public override bool HandlePacket(IPacket packet) { var characterID = packet.ReadShort(); - if (!_currentMapStateRepository.Characters.ContainsKey(characterID)) - return false; + if (_currentMapStateRepository.Characters.ContainsKey(characterID)) + { + var dir = (EODirection)packet.ReadChar(); + var x = packet.ReadChar(); + var y = packet.ReadChar(); - var dir = (EODirection)packet.ReadChar(); - var x = packet.ReadChar(); - var y = packet.ReadChar(); + var character = _currentMapStateRepository.Characters[characterID]; - var character = _currentMapStateRepository.Characters[characterID]; + // if character is walking, that means animator is handling position of character + // if character is not walking (this is true in EOBot), update the domain model here + if (!character.RenderProperties.IsActing(CharacterActionState.Walking)) + { + var renderProperties = EnsureCorrectXAndY(character.RenderProperties.WithDirection(dir), x, y); + _currentMapStateRepository.Characters[characterID] = character.WithRenderProperties(renderProperties); + } - // if character is walking, that means animator is handling position of character - // if character is not walking (this is true in EOBot), update the domain model here - if (!character.RenderProperties.IsActing(CharacterActionState.Walking)) + foreach (var notifier in _otherCharacterAnimationNotifiers) + notifier.StartOtherCharacterWalkAnimation(characterID, x, y, dir); + } + else { - var renderProperties = EnsureCorrectXAndY(character.RenderProperties.WithDirection(dir), x, y); - _currentMapStateRepository.Characters[characterID] = character.WithRenderProperties(renderProperties); + _currentMapStateRepository.UnknownPlayerIDs.Add(characterID); } - foreach (var notifier in _otherCharacterAnimationNotifiers) - notifier.StartOtherCharacterWalkAnimation(characterID, x, y, dir); - return true; } From 4b0758bbba35b4ca4b37bc3455f40e38575d6d4e Mon Sep 17 00:00:00 2001 From: sorokya Date: Sun, 27 Mar 2022 16:06:37 +0200 Subject: [PATCH 06/12] Add UnknownEntitiesRequester to game --- EOLib/PacketHandlers/MapInfoHandler.cs | 2 + EOLib/PacketHandlers/PlayerWalkHandler.cs | 10 +- .../HUD/Controls/HudControlIdentifier.cs | 1 + .../HUD/Controls/HudControlsFactory.cs | 13 ++- .../Network/UnknownEntitiesRequester.cs | 104 ++++++++++++++++++ 5 files changed, 121 insertions(+), 9 deletions(-) create mode 100644 EndlessClient/Network/UnknownEntitiesRequester.cs diff --git a/EOLib/PacketHandlers/MapInfoHandler.cs b/EOLib/PacketHandlers/MapInfoHandler.cs index ebf0ab556..053154310 100644 --- a/EOLib/PacketHandlers/MapInfoHandler.cs +++ b/EOLib/PacketHandlers/MapInfoHandler.cs @@ -53,6 +53,8 @@ public override bool HandlePacket(IPacket packet) character = existingCharacter.WithAppliedData(character, isRangedWeapon); } _currentMapStateRepository.Characters[character.ID] = character; + if (packet.ReadByte() != 255) + throw new MalformedPacketException("Missing 255 byte after character data", packet); } } diff --git a/EOLib/PacketHandlers/PlayerWalkHandler.cs b/EOLib/PacketHandlers/PlayerWalkHandler.cs index 23410dd3c..257e82a39 100644 --- a/EOLib/PacketHandlers/PlayerWalkHandler.cs +++ b/EOLib/PacketHandlers/PlayerWalkHandler.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using System.Collections.Generic; using AutomaticTypeMapper; using EOLib.Domain.Character; using EOLib.Domain.Extensions; @@ -8,7 +6,6 @@ using EOLib.Domain.Map; using EOLib.Domain.Notifiers; using EOLib.Net; -using EOLib.Net.Communication; using EOLib.Net.Handlers; namespace EOLib.PacketHandlers @@ -18,7 +15,6 @@ public class PlayerWalkHandler : InGameOnlyPacketHandler { private readonly ICurrentMapStateRepository _currentMapStateRepository; private readonly IEnumerable _otherCharacterAnimationNotifiers; - private readonly IPacketSendService _packetSendService; public override PacketFamily Family => PacketFamily.Walk; @@ -26,13 +22,11 @@ public class PlayerWalkHandler : InGameOnlyPacketHandler public PlayerWalkHandler(IPlayerInfoProvider playerInfoProvider, ICurrentMapStateRepository currentMapStateRepository, - IEnumerable otherCharacterAnimationNotifiers, - IPacketSendService packetSendService) + IEnumerable otherCharacterAnimationNotifiers) : base(playerInfoProvider) { _currentMapStateRepository = currentMapStateRepository; _otherCharacterAnimationNotifiers = otherCharacterAnimationNotifiers; - _packetSendService = packetSendService; } public override bool HandlePacket(IPacket packet) diff --git a/EndlessClient/HUD/Controls/HudControlIdentifier.cs b/EndlessClient/HUD/Controls/HudControlIdentifier.cs index 4d98ce989..f1181ea08 100644 --- a/EndlessClient/HUD/Controls/HudControlIdentifier.cs +++ b/EndlessClient/HUD/Controls/HudControlIdentifier.cs @@ -69,6 +69,7 @@ public enum HudControlIdentifier UserInputHandler, CharacterAnimator, NPCAnimator, + UnknownEntitiesRequester, PreviousUserInputTracker = Int32.MaxValue, //this should always be last! } diff --git a/EndlessClient/HUD/Controls/HudControlsFactory.cs b/EndlessClient/HUD/Controls/HudControlsFactory.cs index b22523fcd..ca01f980a 100644 --- a/EndlessClient/HUD/Controls/HudControlsFactory.cs +++ b/EndlessClient/HUD/Controls/HudControlsFactory.cs @@ -10,6 +10,7 @@ using EndlessClient.HUD.Panels; using EndlessClient.HUD.StatusBars; using EndlessClient.Input; +using EndlessClient.Network; using EndlessClient.Rendering; using EndlessClient.Rendering.Character; using EndlessClient.Rendering.Factories; @@ -19,6 +20,7 @@ using EOLib.Domain.Map; using EOLib.Graphics; using EOLib.Localization; +using EOLib.Net.Communication; using Microsoft.Xna.Framework; using XNAControls; @@ -53,6 +55,7 @@ public class HudControlsFactory : IHudControlsFactory private readonly IPathFinder _pathFinder; private readonly ICharacterActions _characterActions; private readonly IWalkValidationActions _walkValidationActions; + private readonly IPacketSendService _packetSendService; private IChatController _chatController; public HudControlsFactory(IHudButtonController hudButtonController, @@ -76,7 +79,8 @@ public HudControlsFactory(IHudButtonController hudButtonController, IArrowKeyController arrowKeyController, IPathFinder pathFinder, ICharacterActions characterActions, - IWalkValidationActions walkValidationActions) + IWalkValidationActions walkValidationActions, + IPacketSendService packetSendService) { _hudButtonController = hudButtonController; _hudPanelFactory = hudPanelFactory; @@ -100,6 +104,7 @@ public HudControlsFactory(IHudButtonController hudButtonController, _pathFinder = pathFinder; _characterActions = characterActions; _walkValidationActions = walkValidationActions; + _packetSendService = packetSendService; } public void InjectChatController(IChatController chatController) @@ -158,6 +163,7 @@ public IReadOnlyDictionary CreateHud() {HudControlIdentifier.UserInputHandler, CreateUserInputHandler()}, {HudControlIdentifier.CharacterAnimator, CreateCharacterAnimator()}, {HudControlIdentifier.NPCAnimator, CreateNPCAnimator()}, + {HudControlIdentifier.UnknownEntitiesRequester, CreateUnknownEntitiesRequester()}, {HudControlIdentifier.PreviousUserInputTracker, CreatePreviousUserInputTracker()} }; @@ -359,6 +365,11 @@ private UsageTrackerComponent CreateUsageTracker() return new UsageTrackerComponent(_endlessGameProvider, _characterRepository); } + private UnknownEntitiesRequester CreateUnknownEntitiesRequester() + { + return new UnknownEntitiesRequester(_endlessGameProvider, _currentMapStateRepository, _packetSendService); + } + private StatusBarLabel CreateStatusLabel() { return new StatusBarLabel(_clientWindowSizeProvider, _statusLabelTextProvider) { DrawOrder = HUD_CONTROL_LAYER }; diff --git a/EndlessClient/Network/UnknownEntitiesRequester.cs b/EndlessClient/Network/UnknownEntitiesRequester.cs new file mode 100644 index 000000000..1fe841b1b --- /dev/null +++ b/EndlessClient/Network/UnknownEntitiesRequester.cs @@ -0,0 +1,104 @@ +using EndlessClient.GameExecution; +using EOLib.Domain.Map; +using EOLib.Net; +using EOLib.Net.Communication; +using Microsoft.Xna.Framework; +using System; + +namespace EndlessClient.Network +{ + public class UnknownEntitiesRequester : GameComponent + { + private readonly ICurrentMapStateRepository _currentMapStateRepository; + private readonly IPacketSendService _packetSendService; + private DateTime _lastRequestTime; + private const double REQUEST_INTERVAL_SECONDS = 1; + + public UnknownEntitiesRequester(IEndlessGameProvider gameProvider, + ICurrentMapStateRepository currentMapStateRepository, + IPacketSendService packetSendService) + : base((Game) gameProvider.Game) + { + _currentMapStateRepository = currentMapStateRepository; + _packetSendService = packetSendService; + _lastRequestTime = DateTime.Now; + } + + public override void Update(GameTime gameTime) + { + if ((DateTime.Now - _lastRequestTime).TotalSeconds >= REQUEST_INTERVAL_SECONDS) + { + IPacket request = null; + if (_currentMapStateRepository.UnknownNPCIndexes.Count > 0 && _currentMapStateRepository.UnknownPlayerIDs.Count > 0) + { + request = CreateRequestForBoth(); + } + else if (_currentMapStateRepository.UnknownNPCIndexes.Count > 0) + { + request = CreateRequestForNPCs(); + } + else if (_currentMapStateRepository.UnknownPlayerIDs.Count > 0) + { + request = CreateRequestForPlayers(); + } + + try + { + if (request != null) + _packetSendService.SendPacket(request); + } + catch (NoDataSentException) + { + // do nothing.. should we log these? + } + finally + { + _currentMapStateRepository.UnknownNPCIndexes.Clear(); + _currentMapStateRepository.UnknownPlayerIDs.Clear(); + _lastRequestTime = DateTime.Now; + } + } + + base.Update(gameTime); + } + + private IPacket CreateRequestForBoth() + { + IPacketBuilder builder = new PacketBuilder(PacketFamily.MapInfo, PacketAction.Request); + foreach (var id in _currentMapStateRepository.UnknownPlayerIDs) + { + builder = builder.AddShort(id); + } + builder = builder.AddByte(0xFF); + foreach (var index in _currentMapStateRepository.UnknownNPCIndexes) + { + builder = builder.AddChar(index); + } + + return builder.Build(); + } + + private IPacket CreateRequestForNPCs() + { + IPacketBuilder builder = new PacketBuilder(PacketFamily.NPCMapInfo, PacketAction.Request) + .AddChar((byte)_currentMapStateRepository.UnknownNPCIndexes.Count) + .AddByte(0xFF); + + foreach (var index in _currentMapStateRepository.UnknownNPCIndexes) + { + builder = builder.AddChar(index); + } + return builder.Build(); + } + + private IPacket CreateRequestForPlayers() + { + IPacketBuilder builder = new PacketBuilder(PacketFamily.CharacterMapInfo, PacketAction.Request); + foreach (var id in _currentMapStateRepository.UnknownPlayerIDs) + { + builder = builder.AddShort(id); + } + return builder.Build(); + } + } +} From 0532a5eec8faf761cf268f40afdea34e3f1fc2ee Mon Sep 17 00:00:00 2001 From: sorokya Date: Sun, 27 Mar 2022 17:30:57 +0200 Subject: [PATCH 07/12] remove blank lines --- EOLib/PacketHandlers/AdminHideHandler.cs | 1 - EOLib/PacketHandlers/Effects/PlayerSpikeDamageHandler.cs | 1 - 2 files changed, 2 deletions(-) diff --git a/EOLib/PacketHandlers/AdminHideHandler.cs b/EOLib/PacketHandlers/AdminHideHandler.cs index 979ab0edc..13b5a172e 100644 --- a/EOLib/PacketHandlers/AdminHideHandler.cs +++ b/EOLib/PacketHandlers/AdminHideHandler.cs @@ -44,7 +44,6 @@ public override bool HandlePacket(IPacket packet) { _currentMapStateRepository.UnknownPlayerIDs.Add(id); } - } return true; diff --git a/EOLib/PacketHandlers/Effects/PlayerSpikeDamageHandler.cs b/EOLib/PacketHandlers/Effects/PlayerSpikeDamageHandler.cs index 136d2234f..6546a7162 100644 --- a/EOLib/PacketHandlers/Effects/PlayerSpikeDamageHandler.cs +++ b/EOLib/PacketHandlers/Effects/PlayerSpikeDamageHandler.cs @@ -49,7 +49,6 @@ public override bool HandlePacket(IPacket packet) { _currentMapStateRepository.UnknownPlayerIDs.Add(characterId); } - return true; } From 3e5279dcb1b355e29c88abe5f705079047a1c6d4 Mon Sep 17 00:00:00 2001 From: sorokya Date: Mon, 28 Mar 2022 15:51:18 +0200 Subject: [PATCH 08/12] Make MapWarpState readonly for provider --- EOLib/Domain/Map/CurrentMapStateRepository.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EOLib/Domain/Map/CurrentMapStateRepository.cs b/EOLib/Domain/Map/CurrentMapStateRepository.cs index 44a8a7047..31b113ad9 100644 --- a/EOLib/Domain/Map/CurrentMapStateRepository.cs +++ b/EOLib/Domain/Map/CurrentMapStateRepository.cs @@ -48,7 +48,7 @@ public interface ICurrentMapStateProvider IReadOnlyCollection VisibleSpikeTraps { get; } - WarpState MapWarpState { get; set; } + WarpState MapWarpState { get; } HashSet UnknownPlayerIDs { get; } From a4f5f93fbdfd565d0d413be9bd76b41844037d8c Mon Sep 17 00:00:00 2001 From: sorokya Date: Mon, 28 Mar 2022 15:51:51 +0200 Subject: [PATCH 09/12] remove default constructor from NPCFromPacketFactory --- EOLib/Net/Translators/NPCFromPacketFactory.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/EOLib/Net/Translators/NPCFromPacketFactory.cs b/EOLib/Net/Translators/NPCFromPacketFactory.cs index b23248822..51afe8bfd 100644 --- a/EOLib/Net/Translators/NPCFromPacketFactory.cs +++ b/EOLib/Net/Translators/NPCFromPacketFactory.cs @@ -6,10 +6,6 @@ namespace EOLib.Net.Translators [AutoMappedType] public class NPCFromPacketFactory : INPCFromPacketFactory { - public NPCFromPacketFactory() - { - } - public INPC CreateNPC(IPacket packet) { var index = packet.ReadChar(); From f909bb2d2d0845a3db931b366cfa2831bf913596 Mon Sep 17 00:00:00 2001 From: sorokya Date: Mon, 28 Mar 2022 15:56:30 +0200 Subject: [PATCH 10/12] return true instead of false when adding unknowns --- EOLib/PacketHandlers/NPCActionHandler.cs | 2 +- EOLib/PacketHandlers/NPCTakeDamageHandler.cs | 2 +- EOLib/PacketHandlers/PlayerAvatarChangeHandler.cs | 2 +- EOLib/PacketHandlers/PlayerSitHandler.cs | 2 +- EOLib/PacketHandlers/PlayerStandHandler.cs | 1 - EOLib/PacketHandlers/PlayerTargetOtherSpellHandler.cs | 2 +- 6 files changed, 5 insertions(+), 6 deletions(-) diff --git a/EOLib/PacketHandlers/NPCActionHandler.cs b/EOLib/PacketHandlers/NPCActionHandler.cs index 5204682cc..533ae8469 100644 --- a/EOLib/PacketHandlers/NPCActionHandler.cs +++ b/EOLib/PacketHandlers/NPCActionHandler.cs @@ -72,7 +72,7 @@ public override bool HandlePacket(IPacket packet) catch (InvalidOperationException) { _currentMapStateRepository.UnknownNPCIndexes.Add(index); - return false; + return true; } var updatedNpc = Option.None(); diff --git a/EOLib/PacketHandlers/NPCTakeDamageHandler.cs b/EOLib/PacketHandlers/NPCTakeDamageHandler.cs index f3a93b7d4..2cc6fd01a 100644 --- a/EOLib/PacketHandlers/NPCTakeDamageHandler.cs +++ b/EOLib/PacketHandlers/NPCTakeDamageHandler.cs @@ -86,7 +86,7 @@ public override bool HandlePacket(IPacket packet) catch (InvalidOperationException) { _currentMapStateRepository.UnknownNPCIndexes.Add((byte)npcIndex); - return false; + return true; } return true; diff --git a/EOLib/PacketHandlers/PlayerAvatarChangeHandler.cs b/EOLib/PacketHandlers/PlayerAvatarChangeHandler.cs index c1badaa00..c5ea97d30 100644 --- a/EOLib/PacketHandlers/PlayerAvatarChangeHandler.cs +++ b/EOLib/PacketHandlers/PlayerAvatarChangeHandler.cs @@ -47,7 +47,7 @@ public override bool HandlePacket(IPacket packet) else { _currentMapStateRepository.UnknownPlayerIDs.Add(playerID); - return false; + return true; } var currentRenderProps = currentCharacter.RenderProperties; diff --git a/EOLib/PacketHandlers/PlayerSitHandler.cs b/EOLib/PacketHandlers/PlayerSitHandler.cs index 6a67eaa72..4db159986 100644 --- a/EOLib/PacketHandlers/PlayerSitHandler.cs +++ b/EOLib/PacketHandlers/PlayerSitHandler.cs @@ -57,7 +57,7 @@ public override bool HandlePacket(IPacket packet) else { _currentMapStateRepository.UnknownPlayerIDs.Add(playerId); - return false; + return true; } return true; diff --git a/EOLib/PacketHandlers/PlayerStandHandler.cs b/EOLib/PacketHandlers/PlayerStandHandler.cs index 034eafb68..7a925f7cb 100644 --- a/EOLib/PacketHandlers/PlayerStandHandler.cs +++ b/EOLib/PacketHandlers/PlayerStandHandler.cs @@ -49,7 +49,6 @@ public override bool HandlePacket(IPacket packet) else { _currentMapStateRepository.UnknownPlayerIDs.Add(playerId); - return false; } return true; diff --git a/EOLib/PacketHandlers/PlayerTargetOtherSpellHandler.cs b/EOLib/PacketHandlers/PlayerTargetOtherSpellHandler.cs index 451961dea..96673451f 100644 --- a/EOLib/PacketHandlers/PlayerTargetOtherSpellHandler.cs +++ b/EOLib/PacketHandlers/PlayerTargetOtherSpellHandler.cs @@ -53,7 +53,7 @@ public override bool HandlePacket(IPacket packet) else { _currentMapStateRepository.UnknownPlayerIDs.Add(sourcePlayerId); - return false; + return true; } if (packet.ReadPosition != packet.Length) From db8216448b84edbec574c06c281dd1dcb87daf61 Mon Sep 17 00:00:00 2001 From: sorokya Date: Mon, 28 Mar 2022 15:58:56 +0200 Subject: [PATCH 11/12] only clear unknowns if the packet was sent successfully --- EndlessClient/Network/UnknownEntitiesRequester.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/EndlessClient/Network/UnknownEntitiesRequester.cs b/EndlessClient/Network/UnknownEntitiesRequester.cs index 1fe841b1b..696f9be80 100644 --- a/EndlessClient/Network/UnknownEntitiesRequester.cs +++ b/EndlessClient/Network/UnknownEntitiesRequester.cs @@ -45,16 +45,16 @@ public override void Update(GameTime gameTime) try { if (request != null) + { _packetSendService.SendPacket(request); + _currentMapStateRepository.UnknownNPCIndexes.Clear(); + _currentMapStateRepository.UnknownPlayerIDs.Clear(); + } } catch (NoDataSentException) - { - // do nothing.. should we log these? - } + { } // Swallow error. Will try again on next interval finally { - _currentMapStateRepository.UnknownNPCIndexes.Clear(); - _currentMapStateRepository.UnknownPlayerIDs.Clear(); _lastRequestTime = DateTime.Now; } } From 0e81e93645e11855bc3bc081c695a43fc22add8e Mon Sep 17 00:00:00 2001 From: sorokya Date: Mon, 28 Mar 2022 16:20:32 +0200 Subject: [PATCH 12/12] allow NPCs to still appear while connected to EOSERV/ETHEOS --- EOLib/PacketHandlers/MapInfoHandler.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/EOLib/PacketHandlers/MapInfoHandler.cs b/EOLib/PacketHandlers/MapInfoHandler.cs index 053154310..f247d7979 100644 --- a/EOLib/PacketHandlers/MapInfoHandler.cs +++ b/EOLib/PacketHandlers/MapInfoHandler.cs @@ -38,12 +38,12 @@ IEIFFileProvider eifFileProvider public override bool HandlePacket(IPacket packet) { - var num_entities = packet.ReadChar(); + var numOfEntities = packet.ReadChar(); if (packet.PeekByte() == 0xFF) { packet.ReadByte(); - for (var i = 0; i < num_entities; i++) + for (var i = 0; i < numOfEntities; i++) { var character = _characterFromPacketFactory.CreateCharacter(packet); if (_currentMapStateRepository.Characters.ContainsKey(character.ID)) @@ -58,7 +58,7 @@ public override bool HandlePacket(IPacket packet) } } - while (num_entities > 0 && packet.ReadPosition < packet.Length) + while (packet.ReadPosition < packet.Length) { var npc = _npcFromPacketFactory.CreateNPC(packet); _currentMapStateRepository.NPCs.RemoveWhere(n => n.Index == npc.Index);