Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/NosCore.Packets/Serializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ private Expression PacketSerializer(Expression injectedPacket, PacketIndexAttrib

return Expression.Condition(
Expression.Equal(specificTypeExpression, Expression.Constant(null, typeof(object))),
Expression.Constant(indexAttr.IsOptional ? null : "-1", typeof(object)),
Expression.Constant(indexAttr.IsOptional ? null : $"{discriminator}-1", typeof(object)),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's supposed to be there we have attribute to handle those edge case

Expression.Convert(propExp, typeof(object))
);
}
Expand Down
21 changes: 21 additions & 0 deletions test/NosCore.Packets.Tests/SerializerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public class SerializationTests
typeof(MallPacket),
typeof(FtptPacket),
typeof(ScpIndicatorPacket),
typeof(ScnPacket),
typeof(EsfPacket),
typeof(SopenPacket),
typeof(StbmPacket),
Expand Down Expand Up @@ -518,6 +519,26 @@ public void SerializeWithNullFirstParam()
packet);
}

[TestMethod]
public void SerializeWithNullSubPacketKeepsTheSeparator()
{
var packet = Serializer.Serialize(new ScnPacket
{
PetId = 1,
NpcMonsterVNum = 319,
TransportId = 26719,
Level = 50,
Loyalty = 1000,
Experience = 1536,
WeaponInstanceDetails = new ScnPacket.ScEquipmentDetails { ItemId = 990 },
Name = "Kliff",
MorphId = -1
});

Assert.IsTrue(packet.StartsWith("sc_n 1 319 26719 50 1000 1536 990.0.0 -1 -1 -1 "),
$"the -1 of a null sub-packet must not be glued to the field before it: {packet}");
}

[TestMethod]
public void SerializeWithSpecialSeparator()
{
Expand Down
Loading