Skip to content

Commit ac7f978

Browse files
erwan-jolyclaude
andauthored
fix: model gidx's family id as a nullable id and revert the serializer patch (#494)
#493 patched the serializer so a null sub-packet emits its discriminator with the -1. That was the wrong level: NullableSerializer already carries the splitter into the null branch for a nullable value, and gidx only needed the engine change because the packet was modelled wrong. The server gidx declared FamilyIdentifier as a two-field sub-packet rendering serverId.familyId. The client gidx next to it already declares a plain long FamilyId at the same index, and a capture writes a single id. Flattened to long?, so a null family now serialises as "gidx 1 741328 -1 - 0" through the ordinary nullable path with no serializer change at all. ScnPacket index 9 was missing the SpecialSeparator its three siblings carry, so the boots slot went out as three space-separated fields instead of dotted. Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 338e963 commit ac7f978

5 files changed

Lines changed: 33 additions & 36 deletions

File tree

‎src/NosCore.Packets/Serializer.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ private Expression PacketSerializer(Expression injectedPacket, PacketIndexAttrib
273273

274274
return Expression.Condition(
275275
Expression.Equal(specificTypeExpression, Expression.Constant(null, typeof(object))),
276-
Expression.Constant(indexAttr.IsOptional ? null : $"{discriminator}-1", typeof(object)),
276+
Expression.Constant(indexAttr.IsOptional ? null : "-1", typeof(object)),
277277
Expression.Convert(propExp, typeof(object))
278278
);
279279
}

‎src/NosCore.Packets/ServerPackets/Families/GidxFamilySubPacket.cs‎

Lines changed: 0 additions & 19 deletions
This file was deleted.

‎src/NosCore.Packets/ServerPackets/Families/GidxPacket.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ public class GidxPacket : PacketBase
2020
[PacketIndex(1)]
2121
public long VisualId { get; set; }
2222

23-
[PacketIndex(2, SpecialSeparator = ".")]
24-
public GidxFamilySubPacket? FamilyIdentifier { get; set; }
23+
[PacketIndex(2)]
24+
public long? FamilyId { get; set; }
2525

2626
[PacketIndex(3)]
2727
public string? FamilyName { get; set; }

‎src/NosCore.Packets/ServerPackets/Mates/ScnPacket.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class ScnPacket : PacketBase
4242
[PacketIndex(8, SpecialSeparator = ".")]
4343
public ScEquipmentDetails? GauntletInstanceDetails { get; set; }
4444

45-
[PacketIndex(9)]
45+
[PacketIndex(9, SpecialSeparator = ".")]
4646
public ScEquipmentDetails? BootsInstanceDetails { get; set; }
4747

4848
[PacketIndex(10)]

‎test/NosCore.Packets.Tests/SerializerTest.cs‎

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
using NosCore.Shared.Enumerations;
3535
using System.Collections.Generic;
3636
using System.Linq;
37+
using ServerGidxPacket = NosCore.Packets.ServerPackets.Families.GidxPacket;
3738

3839
namespace NosCore.Packets.Tests
3940
{
@@ -519,24 +520,39 @@ public void SerializeWithNullFirstParam()
519520
packet);
520521
}
521522

523+
// gidx exists on both sides with different shapes, and the serializer keys on the simple
524+
// type name, so the server one needs its own instance.
525+
private static readonly ISerializer ServerSerializer =
526+
new Serializer(new[] { typeof(ServerGidxPacket) });
527+
528+
[TestMethod]
529+
public void SerializeGidxWithoutFamily()
530+
{
531+
var packet = ServerSerializer.Serialize(new ServerGidxPacket
532+
{
533+
VisualType = VisualType.Player,
534+
VisualId = 741328,
535+
FamilyId = null,
536+
FamilyName = "-",
537+
FamilyLevel = 0
538+
});
539+
540+
Assert.AreEqual("gidx 1 741328 -1 - 0 ", packet);
541+
}
542+
522543
[TestMethod]
523-
public void SerializeWithNullSubPacketKeepsTheSeparator()
544+
public void SerializeGidxWithFamily()
524545
{
525-
var packet = Serializer.Serialize(new ScnPacket
546+
var packet = ServerSerializer.Serialize(new ServerGidxPacket
526547
{
527-
PetId = 1,
528-
NpcMonsterVNum = 319,
529-
TransportId = 26719,
530-
Level = 50,
531-
Loyalty = 1000,
532-
Experience = 1536,
533-
WeaponInstanceDetails = new ScnPacket.ScEquipmentDetails { ItemId = 990 },
534-
Name = "Kliff",
535-
MorphId = -1
548+
VisualType = VisualType.Player,
549+
VisualId = 741328,
550+
FamilyId = 5052,
551+
FamilyName = "-Nemesis-",
552+
FamilyLevel = 7
536553
});
537554

538-
Assert.IsTrue(packet.StartsWith("sc_n 1 319 26719 50 1000 1536 990.0.0 -1 -1 -1 "),
539-
$"the -1 of a null sub-packet must not be glued to the field before it: {packet}");
555+
Assert.AreEqual("gidx 1 741328 5052 -Nemesis- 7 ", packet);
540556
}
541557

542558
[TestMethod]

0 commit comments

Comments
 (0)