0x0022 InventoryPutObjInContainer carries 4 u32s per ACE GameEventItemServerSaysContainId.cs: itemGuid, containerGuid, placement, containerType. The parser was reading only 3 (12 bytes) and silently dropping containerType. Fixed the record struct to add ContainerType and raised the length guard to 16. GameEventWiring caller uses only .ItemGuid/.ContainerGuid/.Placement — adding a positional field is source-compatible. 1 new test in GameEventsInventoryTests. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
62 lines
2.5 KiB
C#
62 lines
2.5 KiB
C#
using System.Buffers.Binary;
|
||
using AcDream.Core.Net.Messages;
|
||
using Xunit;
|
||
|
||
namespace AcDream.Core.Net.Tests.Messages;
|
||
|
||
public sealed class GameEventsInventoryTests
|
||
{
|
||
[Fact]
|
||
public void ParseViewContents_twoEntries_returnsContainerAndItems()
|
||
{
|
||
// containerGuid + count(2) + 2×{guid, containerType}
|
||
var b = new byte[4 + 4 + 2 * 8];
|
||
BinaryPrimitives.WriteUInt32LittleEndian(b.AsSpan(0), 0x500000C9u); // containerGuid
|
||
BinaryPrimitives.WriteUInt32LittleEndian(b.AsSpan(4), 2u); // count
|
||
BinaryPrimitives.WriteUInt32LittleEndian(b.AsSpan(8), 0x50000A01u); // guid 1
|
||
BinaryPrimitives.WriteUInt32LittleEndian(b.AsSpan(12), 0u); // type 1 (item)
|
||
BinaryPrimitives.WriteUInt32LittleEndian(b.AsSpan(16), 0x50000A02u);// guid 2
|
||
BinaryPrimitives.WriteUInt32LittleEndian(b.AsSpan(20), 1u); // type 2 (container)
|
||
|
||
var p = GameEvents.ParseViewContents(b);
|
||
Assert.NotNull(p);
|
||
Assert.Equal(0x500000C9u, p!.Value.ContainerGuid);
|
||
Assert.Equal(2, p.Value.Items.Count);
|
||
Assert.Equal(0x50000A01u, p.Value.Items[0].Guid);
|
||
Assert.Equal(0u, p.Value.Items[0].ContainerType);
|
||
Assert.Equal(0x50000A02u, p.Value.Items[1].Guid);
|
||
Assert.Equal(1u, p.Value.Items[1].ContainerType);
|
||
}
|
||
|
||
[Fact]
|
||
public void ParseViewContents_zeroCount_returnsEmptyList()
|
||
{
|
||
var b = new byte[8];
|
||
BinaryPrimitives.WriteUInt32LittleEndian(b.AsSpan(0), 0x500000C9u);
|
||
BinaryPrimitives.WriteUInt32LittleEndian(b.AsSpan(4), 0u);
|
||
var p = GameEvents.ParseViewContents(b);
|
||
Assert.NotNull(p);
|
||
Assert.Empty(p!.Value.Items);
|
||
}
|
||
|
||
[Fact]
|
||
public void ParseViewContents_truncated_returnsNull()
|
||
=> Assert.Null(GameEvents.ParseViewContents(new byte[4]));
|
||
|
||
[Fact]
|
||
public void ParsePutObjInContainer_readsAllFourFields()
|
||
{
|
||
var b = new byte[16];
|
||
BinaryPrimitives.WriteUInt32LittleEndian(b.AsSpan(0), 0x50000A01u); // itemGuid
|
||
BinaryPrimitives.WriteUInt32LittleEndian(b.AsSpan(4), 0x500000C9u); // containerGuid
|
||
BinaryPrimitives.WriteUInt32LittleEndian(b.AsSpan(8), 3u); // placement
|
||
BinaryPrimitives.WriteUInt32LittleEndian(b.AsSpan(12), 1u); // containerType
|
||
|
||
var p = GameEvents.ParsePutObjInContainer(b);
|
||
Assert.NotNull(p);
|
||
Assert.Equal(0x50000A01u, p!.Value.ItemGuid);
|
||
Assert.Equal(0x500000C9u, p.Value.ContainerGuid);
|
||
Assert.Equal(3u, p.Value.Placement);
|
||
Assert.Equal(1u, p.Value.ContainerType);
|
||
}
|
||
}
|