From 4679c8e710e349f7c34dcb878d671124e0e0760a Mon Sep 17 00:00:00 2001 From: erwan-joly Date: Mon, 31 Aug 2026 10:56:51 +1200 Subject: [PATCH] fix(einfo): escape the spaces in the monster name Name ends the e_info line, and a last field keeps its spaces so free text like a chat message survives. A monster name is a value, not free text, and EscapeSpaces already exists for exactly that - GInfoPacket, MlInfoBrPacket and MlintroPacket declare it. This one did not, so consumers were left to call Replace(' ', '^') themselves before handing the value over. 929 of the 1109 monster-info lines in a capture carry a name with a space. Test asserts the serialised tail, and fails on the raw name without the attribute. Co-Authored-By: Claude Opus 5 --- src/NosCore.Packets/NosCore.Packets.csproj | 2 +- .../Inventory/EInfoNpcMonsterPacket.cs | 2 +- test/NosCore.Packets.Tests/SerializerTest.cs | 18 +++++++++++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/NosCore.Packets/NosCore.Packets.csproj b/src/NosCore.Packets/NosCore.Packets.csproj index 08e8e3f8..2e106d62 100644 --- a/src/NosCore.Packets/NosCore.Packets.csproj +++ b/src/NosCore.Packets/NosCore.Packets.csproj @@ -12,7 +12,7 @@ https://github.com/NosCoreIO/NosCore.Packets.git nostale, noscore, chickenapi, nostale private server source, nostale emulator - 21.1.1 + 21.1.2 false NosCore's Packets (Nostale packets) defined over classes MIT diff --git a/src/NosCore.Packets/ServerPackets/Inventory/EInfoNpcMonsterPacket.cs b/src/NosCore.Packets/ServerPackets/Inventory/EInfoNpcMonsterPacket.cs index 62af08e0..db567cbc 100644 --- a/src/NosCore.Packets/ServerPackets/Inventory/EInfoNpcMonsterPacket.cs +++ b/src/NosCore.Packets/ServerPackets/Inventory/EInfoNpcMonsterPacket.cs @@ -92,7 +92,7 @@ public class EInfoNpcMonsterPacket : PacketBase [PacketIndex(24)] public int Unknown { get; set; } = -1; - [PacketIndex(25)] + [PacketIndex(25, EscapeSpaces = true)] public string? Name { get; set; } } } diff --git a/test/NosCore.Packets.Tests/SerializerTest.cs b/test/NosCore.Packets.Tests/SerializerTest.cs index 805efb77..94c813f1 100644 --- a/test/NosCore.Packets.Tests/SerializerTest.cs +++ b/test/NosCore.Packets.Tests/SerializerTest.cs @@ -104,9 +104,25 @@ public class SerializationTests typeof(Stp2Packet), typeof(TbfPacket), typeof(QrPacket), - typeof(SqstPacket) + typeof(SqstPacket), + typeof(EInfoNpcMonsterPacket) }); + // The monster name ends the line, and a last field keeps its spaces unless it asks not + // to. 929 of the 1109 monster-info lines in a capture carry a name with a space in it. + [TestMethod] + public void SerializeEInfoNpcMonsterPacketEscapesTheName() + { + var testPacket = new EInfoNpcMonsterPacket + { + Unknown = -1, + Name = "Fire Cannoneer" + }; + + var packet = Serializer.Serialize(testPacket); + Assert.IsTrue(packet.EndsWith("-1 Fire^Cannoneer"), packet); + } + [TestMethod] public void AllPacketsAreSerializable() {