fix(physics): AP-71 - port check_entry_restrictions at the head of indoor FindEnvCollisions

Campaign P Slice P4 item 1. Ports retail's CObjCell::check_entry_restrictions
(pc:308873-308912, 0x0052b6d0), called FIRST by CEnvCell::find_env_collisions
(pc:309576) before any BSP work, as ObjectInfo.CheckEntryRestrictions wired at
the top of the indoor branch of Transition.FindEnvCollisions.

Resolves the research doc's open question on restriction_obj's source: the
ACE cross-check (references/ACE/Source/ACE.DatLoader/FileTypes/EnvCell.cs:32,
66-67) plus an independent reflection probe of Chorizite.DatReaderWriter
2.1.7's own EnvCell.RestrictionObj field confirm it is a plain DAT-baked
uint32 gated by EnvCellFlags.HasRestrictionObj (0x8) - not a live wire
override. The BN pseudo-C's "count for an array alloc" read at the same
UnPack offset was the mis-attributed field-name collision
feedback_bn_decomp_field_names warned about.

CellPhysics.RestrictionObj is wired from envCell.RestrictionObj in BOTH the
dev/graph-fixture path (CacheCellStruct) and the production/prepared path
(CachePreparedCellStruct) - the latter already receives a live parsed
envCell for Position/EnvironmentId, so no bake-format change was needed.

The mover's own CanBypassMoveRestrictions (BF_ADMIN 0x100000 AND
BF_IMMUNE_CELL_RESTRICTIONS 0x400000, acclient.h:6452-6454) is decoded via
the same PWD-bitfield pipeline TS-23 established for PK/PKLite/Impenetrable
(EntityCollisionFlags -> ToMoverState -> ObjectInfoState moverFlags).

Remaining gap (filed as AP-129, replacing the retired AP-71 row): CanMoveInto
(house owner IID + guest/ban list) is unmodeled, so a genuinely restricted
cell fails CLOSED for everyone, not just intruders - matching retail's own
fallback when the restriction weenie can't be resolved (pc:704-716). Outdoor
CLandCell restriction (LandblockInfo.RestrictionTables, a separate DAT
structure) is explicitly out of scope for this gate.

Conformance: Ap71EntryRestrictionGateTests covers the pure gate logic
(NPC bypass, admin bypass, fail-closed, ordinary-cell no-op), the PWD-bitfield
two-bit AND decode, and three end-to-end Transition.FindEnvCollisions
scenarios proving zero behavior change for ordinary cells.

AcDream.Core.Tests: 4026 passed, 2 skipped, 0 failed.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Erik 2026-07-30 10:30:45 +02:00
parent eddad9cb38
commit d6c3f8657a
5 changed files with 380 additions and 2 deletions

View file

@ -49,6 +49,19 @@ public enum EntityCollisionFlags : byte
/// requires this distinction for ethereal targets.
/// </summary>
HasWeenie = 0x20,
/// <summary>
/// AP-71 (Campaign P Slice P4, 2026-07-30): set when BOTH
/// <c>BF_ADMIN (0x100000)</c> and <c>BF_IMMUNE_CELL_RESTRICTIONS
/// (0x400000)</c> are set in <c>pwd._bitfield</c> — the exact two-bit AND
/// retail's <c>ACCWeenieObject::CanBypassMoveRestrictions</c>
/// (0x0058c500) evaluates to let a mover through an access-restricted
/// (house-barrier) cell without an owner/guest-list check. Bit names
/// confirmed at <c>acclient.h:6452-6454</c>
/// (<c>PublicWeenieDesc::BitfieldIndex</c>); <c>BF_ADMIN</c> is
/// independently decoded the same way in
/// <see cref="AcDream.Core.Ui.RadarBlipColors"/>.
/// </summary>
CanBypassMoveRestrictions = 0x40,
}
/// <summary>Helpers to convert raw retail bitfields into <see cref="EntityCollisionFlags"/>.</summary>
@ -72,6 +85,10 @@ public static class EntityCollisionFlagsExt
if ((bitfield & 0x20u) != 0) flags |= EntityCollisionFlags.IsPK;
if ((bitfield & 0x200000u) != 0) flags |= EntityCollisionFlags.IsImpenetrable;
if ((bitfield & 0x2000000u) != 0) flags |= EntityCollisionFlags.IsPKLite;
// AP-71: BF_ADMIN (0x100000) AND BF_IMMUNE_CELL_RESTRICTIONS (0x400000),
// matching CanBypassMoveRestrictions' own AND (not OR) of the two bits.
if ((bitfield & 0x100000u) != 0 && (bitfield & 0x400000u) != 0)
flags |= EntityCollisionFlags.CanBypassMoveRestrictions;
return flags;
}
@ -95,6 +112,10 @@ public static class EntityCollisionFlagsExt
if ((flags & EntityCollisionFlags.IsPK) != 0) state |= ObjectInfoState.IsPK;
if ((flags & EntityCollisionFlags.IsPKLite) != 0) state |= ObjectInfoState.IsPKLite;
if ((flags & EntityCollisionFlags.IsImpenetrable) != 0) state |= ObjectInfoState.IsImpenetrable;
// AP-71 (Campaign P Slice P4): the mover's own house-restriction bypass,
// consumed by ObjectInfo.CheckEntryRestrictions.
if ((flags & EntityCollisionFlags.CanBypassMoveRestrictions) != 0)
state |= ObjectInfoState.CanBypassMoveRestrictions;
return state;
}

View file

@ -477,6 +477,13 @@ public sealed class PhysicsDataCache
// #107: retail CEnvCell.seen_outside — consumed by AdjustPosition's
// indoor not-found fallback (acclient :280037).
SeenOutside = envCell.Flags.HasFlag(DatReaderWriter.Enums.EnvCellFlags.SeenOutside),
// AP-71 (Campaign P Slice P4, 2026-07-30): retail CObjCell::
// restriction_obj — a DAT-baked uint32 gated by EnvCellFlags.
// HasRestrictionObj (0x8), confirmed via ACE.DatLoader.FileTypes.
// EnvCell.cs:66-67 and Chorizite.DatReaderWriter's own EnvCell
// field of the same name (reflection-confirmed 2026-07-30). Zero
// for every ordinary (non-house-barrier) cell.
RestrictionObj = envCell.RestrictionObj,
};
_cellStruct[envCellId] = cellPhysics;
@ -654,6 +661,14 @@ public sealed class PhysicsDataCache
VisibleCellIds = new HashSet<uint>(
preparedTopology.VisibleCellIds),
SeenOutside = preparedTopology.SeenOutside,
// AP-71 (Campaign P Slice P4, 2026-07-30): read straight from the
// locally-parsed live envCell, same as SeenOutside historically
// was before the bake pipeline existed — RestrictionObj is NOT
// (and does not need to be) part of the baked FlatEnvCellTopology
// payload; the caller (LandblockPhysicsPublisher.PublishCell)
// already has a real parsed DatReaderWriter.DBObjs.EnvCell in
// hand for Position/EnvironmentId, so this is free.
RestrictionObj = envCell.RestrictionObj,
});
}
@ -1062,4 +1077,19 @@ public sealed class CellPhysics
/// contain it AND this flag is set (retail acclient :280037-280046).
/// </summary>
public bool SeenOutside { get; init; }
/// <summary>
/// AP-71 (Campaign P Slice P4, 2026-07-30): retail <c>CObjCell::
/// restriction_obj</c> — the DAT-baked object IID (gated by
/// <c>EnvCellFlags.HasRestrictionObj</c>) that <c>CObjCell::
/// check_entry_restrictions</c> (0x0052b6d0) resolves and consults
/// before letting a player into this cell. Zero (the default) for
/// every ordinary cell — only house-barrier EnvCells set it. Consumed
/// by <see cref="ObjectInfo.CheckEntryRestrictions"/> via
/// <see cref="Transition.FindEnvCollisions"/>. Resolving the value into
/// a live restriction weenie (for the owner/guest-list
/// <c>CanMoveInto</c> check) is NOT modeled — see the AP-71 register
/// history for the narrower unfed-input row.
/// </summary>
public uint RestrictionObj { get; init; }
}

View file

@ -42,6 +42,15 @@ public enum ObjectInfoState : uint
/// retail's <c>OBJECTINFO::state</c> bits (acclient.h:6190-6194).</summary>
IsPK = 0x800,
IsPKLite = 0x1000,
/// <summary>
/// AP-71 (Campaign P Slice P4, 2026-07-30): the mover's own PWD-bitfield
/// <c>BF_ADMIN &amp; BF_IMMUNE_CELL_RESTRICTIONS</c> AND (see
/// <c>EntityCollisionFlags.CanBypassMoveRestrictions</c>), consumed by
/// <see cref="ObjectInfo.CheckEntryRestrictions"/> exactly like
/// <see cref="IsPK"/>/<see cref="IsPKLite"/> flow through the same
/// moverFlags OR-in.
/// </summary>
CanBypassMoveRestrictions = 0x2000,
}
/// <summary>
@ -97,6 +106,7 @@ public sealed class ObjectInfo
public bool EdgeSlide => (State & ObjectInfoState.EdgeSlide) != 0;
public bool PathClipped => (State & ObjectInfoState.PathClipped) != 0;
public bool FreeRotate => (State & ObjectInfoState.FreeRotate) != 0;
public bool CanBypassMoveRestrictions => (State & ObjectInfoState.CanBypassMoveRestrictions) != 0;
/// <summary>
/// Verbatim decision tree from retail <c>OBJECTINFO::missile_ignore</c>
@ -124,6 +134,59 @@ public sealed class ObjectInfo
&& (targetFlags & EntityCollisionFlags.IsCreature) != 0;
}
/// <summary>
/// AP-71 (Campaign P Slice P4, 2026-07-30). Retail <c>CObjCell::
/// check_entry_restrictions</c> (named-retail pc:308873-308912,
/// 0x0052b6d0) — called FIRST by both <c>CEnvCell::find_env_collisions</c>
/// (pc:309576) and <c>CLandCell::find_env_collisions</c> (pc:317075),
/// before any BSP/terrain collision work. Ported here for the indoor
/// (EnvCell) call site only; the outdoor <c>CLandCell</c> equivalent
/// reads a completely separate DAT structure
/// (<c>LandblockInfo.RestrictionTables</c>, a per-landblock packed hash
/// table — confirmed via <c>references/ACE/Source/ACE.Server/Physics/
/// Common/Landblock.cs:508-520</c> and <c>ACE.DatLoader.FileTypes.
/// LandblockInfo.cs:43</c>) that acdream does not parse; that scope gap
/// is filed separately (see the AP-71 register history), not ported here.
///
/// <para>
/// Gate order, verbatim from the decompile except for the "mover is
/// null" branch: acdream's <see cref="ObjectInfo"/> is never invoked on
/// a null mover (unlike retail's <c>t-&gt;object_info.object</c>
/// pointer, which is defensively null-checked but never actually null
/// for a live transition — <c>CPhysicsObj::transition</c> 0x00512dc0
/// always seeds <c>object_info.object = this</c>), so that branch and
/// the parallel <c>moverWeenie == 0</c> check have no acdream analog and
/// are omitted. What remains: NPCs/props (not <see cref="IsPlayer"/>)
/// bypass entirely (retail's <c>state &amp; 0x100</c> test); a mover
/// whose own PWD bitfield grants <see cref="CanBypassMoveRestrictions"/>
/// bypasses; an ordinary cell (<paramref name="cellRestrictionObj"/> ==
/// 0 — the overwhelmingly common case, DAT-gated by
/// <c>EnvCellFlags.HasRestrictionObj</c>) is a no-op.
/// </para>
///
/// <para>
/// Otherwise (a restriction IS authored on this cell and the mover
/// cannot bypass): retail resolves the live restriction weenie
/// (<c>CPhysicsObj::GetObjectA</c>) and asks <c>CanMoveInto</c> (house
/// owner IID + guest/ban list, <c>ACCWeenieObject::CanMoveInto</c>
/// 0x0058da40). acdream has no restriction-weenie resolution or
/// guest-list wire model yet (see the AP-71 register history for the
/// narrower unfed-input row this leaves), so it cannot correctly answer
/// <c>CanMoveInto</c> — it fails CLOSED (<see
/// cref="TransitionState.Collided"/>), exactly matching retail's own
/// fallback when the restriction object can't be resolved (pc:704-716
/// falls through to <c>COLLIDED_TS</c>).
/// </para>
/// </summary>
public TransitionState CheckEntryRestrictions(uint cellRestrictionObj)
{
if (!IsPlayer) return TransitionState.OK; // NPCs/props bypass entirely
if (CanBypassMoveRestrictions) return TransitionState.OK;
if (cellRestrictionObj == 0) return TransitionState.OK; // ordinary cell — no-op
return TransitionState.Collided;
}
/// <summary>
/// Return the Z threshold for a walkable surface appropriate to the
/// current movement context.
@ -2965,6 +3028,20 @@ public sealed class Transition
if (cellLow >= 0x0100 && engine.DataCache is not null)
{
var cellPhysics = engine.DataCache.GetCellStruct(sp.CheckCellId);
// AP-71 (Campaign P Slice P4, 2026-07-30): retail CEnvCell::
// find_env_collisions (pc:309576) calls check_entry_restrictions
// as its FIRST statement — before any HasPhysics/BSP dispatch.
// cellPhysics is null-safe: an uncached/BSP-less cell has no
// authored restriction data either.
var restrictionState = ObjectInfo.CheckEntryRestrictions(cellPhysics?.RestrictionObj ?? 0);
if (restrictionState != TransitionState.OK)
{
if ((ObjectInfo.State & ObjectInfoState.Contact) == 0)
ci.CollidedWithEnvironment = true;
return restrictionState;
}
if (cellPhysics is not null &&
CollisionTraversal.HasPhysics(engine.DataCache!, cellPhysics))
{