feat(net): CreateObject body parser — GUID + Position + SetupId extracted (Phase 4.7d)

Decodes the CreateObject (0xF745) game message body far enough to hand
an entity off to acdream's existing IGameState/MeshRenderer pipeline.
Ported from ACE's WorldObject_Networking.cs (SerializeCreateObject,
SerializeModelData, SerializePhysicsData) and Position.cs.

Scope: the parser extracts exactly three fields —
  - GUID (u32 right after the opcode)
  - ServerPosition (landblockId + XYZ + rotation quaternion), if the
    Position bit is set in the PhysicsDescriptionFlag
  - SetupTableId (setup dat id for the visual mesh chain), if the
    CSetup bit is set

Everything else in a CreateObject body (weenie header, object description,
motion tables, palettes, texture overrides, animation frames, velocity,
acceleration, omega, scale, friction, elasticity, translucency,
default scripts, sequence timestamps, ...) is consumed-or-skipped with
just enough bytes to advance past the correct flag-gated sections.
The parser stops at the end of PhysicsData — we don't need weenie-header
fields for rendering placement.

Components parsed in order (all from ACE's serialize routines):
  1. Opcode u32 (must be 0xF745)
  2. u32 GUID
  3. ModelData header (byte 0x11 marker, byte subPaletteCount,
     byte textureChangeCount, byte animPartChangeCount), followed by
     PackedDword palette/subPalette fields, texture change records,
     anim part change records, aligned to 4 bytes at end
  4. u32 PhysicsDescriptionFlag
  5. u32 PhysicsState (skipped)
  6. Conditional Movement/AnimationFrame section
  7. Conditional Position section (LandblockId, X, Y, Z, RW, RX, RY, RZ)
  8. Conditional MTable/STable/PeTable u32 ids (all skipped)
  9. Conditional CSetup u32 (extracted as SetupTableId)

The PackedDword reader is a new helper: AC's variable-width uint format
where values ≤ 32767 encode as a u16, larger values use a marker bit in
the top of the first u16 and a continuation u16. Ported from
Extensions.WritePackedDword.

LIVE RUN AGAINST THE ACE SERVER (test account, Holtburg):

  step 4: CharacterList received account=testaccount count=2
    character: id=0x5000000A name=+Acdream
    character: id=0x50000008 name=+Wdw
  sent CharacterEnterWorldRequest
  step 6: CharacterEnterWorldServerReady received
  sent CharacterEnterWorld(guid=0x5000000A)
  step 8 summary: 83 GameMessages assembled, 68 CreateObject,
                  68 parsed, 52 w/position, 68 w/setup

  First 10 parsed CreateObjects:
    guid=0x5000000A lb=0xA9B40021 xyz=(104.89,15.05,94.01) setup=0x02000001
    guid=0x80000600 no position setup=0x02000181
    guid=0x800005FF no position setup=0x02000B77
    guid=0x80000603 no position setup=0x02000176
    guid=0x80000604 no position setup=0x02000D5C
    guid=0x80000694 no position setup=0x020005FF
    guid=0x80000697 no position setup=0x02000921
    guid=0x80000601 no position setup=0x02000179
    guid=0x80000605 no position setup=0x02000155
    guid=0x80000695 no position setup=0x020005FF

The first line is +Acdream himself — GUID matches what we picked from
CharacterList, landblock 0xA9B4 is Holtburg (the area we already render),
setup 0x02000001 is the default humanoid player mesh. The other 67 are
NPCs/weenies/scenery-weenies in the same area; the 16 without positions
are inventory items whose position is inherited from the parent.

ALL 68 CreateObjects parsed cleanly — no short reads, no format errors.
Phase 4.7d proves byte-level compatibility with ACE's outbound network
serialization format. The remaining Phase 4 work (WorldSession type +
GameWindow wiring) is glue code above a codec that now speaks the real
AC wire format.

Tests: 77 core + 83 net (+1 live test) = 161 passing, all green.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Erik 2026-04-11 15:18:54 +02:00
parent 94da385ff4
commit 9e4313f3d3
2 changed files with 295 additions and 6 deletions

View file

@ -406,10 +406,14 @@ public class LiveHandshakeTests
CharacterEnterWorld.BuildEnterWorldBody(chosen.Id, user),
$"CharacterEnterWorld(guid=0x{chosen.Id:X8})");
// ---- Step 8: receive the CreateObject flood. ----
// ---- Step 8: receive the CreateObject flood + parse bodies. ----
int totalMessages = 0;
int createObjectCount = 0;
int createObjectParsed = 0;
int createObjectWithPosition = 0;
int createObjectWithSetup = 0;
var seenOpcodes = new HashSet<uint>();
var parsedCreateObjects = new List<CreateObject.Parsed>();
var d8 = DateTime.UtcNow + TimeSpan.FromSeconds(10);
while (DateTime.UtcNow < d8)
{
@ -428,19 +432,41 @@ public class LiveHandshakeTests
uint op = BinaryPrimitives.ReadUInt32LittleEndian(body);
seenOpcodes.Add(op);
totalMessages++;
if (op == 0xF745u) // CreateObject
if (op == CreateObject.Opcode)
{
createObjectCount++;
var parsed = CreateObject.TryParse(body);
if (parsed is not null)
{
createObjectParsed++;
parsedCreateObjects.Add(parsed.Value);
if (parsed.Value.Position is not null) createObjectWithPosition++;
if (parsed.Value.SetupTableId is not null) createObjectWithSetup++;
}
}
}
}
Console.WriteLine($"[live] step 8 summary: {totalMessages} GameMessages assembled, " +
$"{createObjectCount} CreateObject");
$"{createObjectCount} CreateObject, " +
$"{createObjectParsed} parsed, " +
$"{createObjectWithPosition} w/position, " +
$"{createObjectWithSetup} w/setup");
Console.WriteLine("[live] unique opcodes seen: " +
string.Join(", ", seenOpcodes.Select(o => $"0x{o:X8}")));
// MILESTONE: if we got at least one CreateObject, the server considers
// us logged into the world. That's the Phase 4.7 win condition.
// Dump the first 10 parsed CreateObjects so we can eyeball whether
// the positions match Holtburg and the setup ids look like dat ids.
foreach (var co in parsedCreateObjects.Take(10))
{
string posStr = co.Position is { } p
? $"lb=0x{p.LandblockId:X8} xyz=({p.PositionX:F2},{p.PositionY:F2},{p.PositionZ:F2})"
: "no position";
string setupStr = co.SetupTableId is { } s ? $"setup=0x{s:X8}" : "no setup";
Console.WriteLine($"[live] CreateObject guid=0x{co.Guid:X8} {posStr} {setupStr}");
}
Assert.True(createObjectCount > 0,
$"Expected at least one CreateObject message post-login, got {createObjectCount}");
$"Expected at least one CreateObject post-login, got {createObjectCount}");
}
}