acdream/tests/AcDream.Core.Net.Tests/Messages/SetStateTests.cs
Erik 2459f287e4 feat(phys L.2g slice 1): inbound SetState (0xF74B) parser
DTO + TryParse for the GameMessageSetState wire message. The server
broadcasts this when an already-spawned entity's PhysicsState changes
post-CreateObject — chiefly when a door's Ethereal bit toggles on Use.

Wire format per holtburger SetStateData (validated against retail-format
servers): u32 opcode + u32 guid + u32 state + u16 instanceSequence + u16
stateSequence = 16 bytes total. Mirrors the existing VectorUpdate.cs
template.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-12 22:15:31 +02:00

43 lines
1.4 KiB
C#

using System;
using System.Buffers.Binary;
using AcDream.Core.Net.Messages;
using Xunit;
namespace AcDream.Core.Net.Tests.Messages;
public class SetStateTests
{
[Fact]
public void TryParse_WellFormedBody_ReturnsParsed()
{
var buf = new byte[16];
BinaryPrimitives.WriteUInt32LittleEndian(buf.AsSpan(0, 4), 0xF74Bu);
BinaryPrimitives.WriteUInt32LittleEndian(buf.AsSpan(4, 4), 0x000F4244u); // door guid
BinaryPrimitives.WriteUInt32LittleEndian(buf.AsSpan(8, 4), 0x00000004u); // ETHEREAL bit
BinaryPrimitives.WriteUInt16LittleEndian(buf.AsSpan(12, 2), (ushort)355);
BinaryPrimitives.WriteUInt16LittleEndian(buf.AsSpan(14, 2), (ushort)42);
var parsed = SetState.TryParse(buf);
Assert.NotNull(parsed);
Assert.Equal(0x000F4244u, parsed.Value.Guid);
Assert.Equal(0x00000004u, parsed.Value.PhysicsState);
Assert.Equal((ushort)355, parsed.Value.InstanceSequence);
Assert.Equal((ushort)42, parsed.Value.StateSequence);
}
[Fact]
public void TryParse_Truncated_ReturnsNull()
{
var buf = new byte[10];
Assert.Null(SetState.TryParse(buf));
}
[Fact]
public void TryParse_WrongOpcode_ReturnsNull()
{
var buf = new byte[16];
BinaryPrimitives.WriteUInt32LittleEndian(buf.AsSpan(0, 4), 0xF74Cu);
Assert.Null(SetState.TryParse(buf));
}
}