Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 5 additions & 1 deletion src/NosCore.Packets/Serializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,13 @@ private Expression PacketSerializer(Expression injectedPacket, PacketIndexAttrib
incrementExpr = Expression.Constant(!isFromList || !isOptionalSerie);
}

// A null sub-packet is written as -1, and it has to carry the same leading separator

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.

don't need this comment

// the non-null path gets from the discriminator. Without it the -1 is glued to the
// field before it and the client cannot split the packet into fields at all:
// sc_n ... 1536-1-1-1 -1 ... instead of sc_n ... 1536 -1 -1 -1 ...
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
20 changes: 20 additions & 0 deletions test/NosCore.Packets.Tests/SerializerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,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