From 05d835ff331645eb2d4bca51d0402783119635d5 Mon Sep 17 00:00:00 2001 From: Erik Date: Sun, 12 Apr 2026 15:04:24 +0200 Subject: [PATCH] =?UTF-8?q?fix(core):=20Phase=20B.2=20=E2=80=94=20mask=20c?= =?UTF-8?q?ellId=20to=20low=2016=20bits=20in=20PhysicsEngine.Resolve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ROOT CAUSE of the fall-through-ground bug. The currentlyIndoor check compared the FULL 32-bit cell ID (0xA9B40001, includes landblock prefix) against 0x0100. Every outdoor cell ID with a landblock prefix is >= 0x0100, so the engine ALWAYS took the "stay indoors" path, snapping the player to the nearest EnvCell floor at Z=66 instead of the outdoor terrain at Z=94. ACE confirmed the bug: "AddWorldObjectInternal: couldn't spawn +Acdream at 0xA9B40121 [84.2 37.7 66.0]" — we were sending the server an indoor cell ID with a below-terrain Z position. Fix: mask cellId with 0xFFFF before the indoor check (outdoor cells are 0x0001–0x0040; indoor are 0x0100+; the high 16 bits are the landblock prefix and must be stripped). Also mask the returned targetCellId from CellSurface (which carries the full EnvCell dat id) to just the cell index. 265 tests still green. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/AcDream.Core/Physics/PhysicsEngine.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/AcDream.Core/Physics/PhysicsEngine.cs b/src/AcDream.Core/Physics/PhysicsEngine.cs index 984d5a8..29cdf9f 100644 --- a/src/AcDream.Core/Physics/PhysicsEngine.cs +++ b/src/AcDream.Core/Physics/PhysicsEngine.cs @@ -107,13 +107,20 @@ public sealed class PhysicsEngine float targetZ; uint targetCellId; - bool currentlyIndoor = cellId >= 0x0100; + // Only the low 16 bits of cellId carry the cell index. Outdoor + // cells are 0x0001–0x0040; indoor (EnvCell) cells are 0x0100+. + // The full 32-bit cellId includes the landblock prefix in the + // high 16 bits (e.g., 0xA9B40001), so we MUST mask before + // comparing. Without the mask, every cell looks "indoor" because + // 0xA9B40001 >= 0x0100 → the engine always takes the "stay + // indoors" path and snaps Z to an EnvCell floor 28m below. + bool currentlyIndoor = (cellId & 0xFFFFu) >= 0x0100; if (currentlyIndoor && bestCellZ is not null) { // Stay indoors on the best cell's floor. targetZ = bestCellZ.Value; - targetCellId = bestCell!.CellId; + targetCellId = bestCell!.CellId & 0xFFFFu; } else if (currentlyIndoor && bestCellZ is null) { @@ -126,7 +133,7 @@ public sealed class PhysicsEngine { // Walked into an indoor cell from outdoor — transition to indoor. targetZ = bestCellZ.Value; - targetCellId = bestCell!.CellId; + targetCellId = bestCell!.CellId & 0xFFFFu; } else {