Skip to content

Native-width audit (PS2 4-byte pointers)

The port runs recovered PlayStation 2 code on a 64-bit host. Nothing that stores a pointer, a pointer-sized handle or a struct containing one may keep a PS2 byte count or offset. This is the audit of the places where the difference can reach running code, the tools that check them, and what is left.

Where the width matters

  1. A record crosses a message boundary. SendCommand/Call pass a pointer to a payload. If the receiver casts pData to another definition of the record, every field after the first pointer sits at the wrong offset. Both directions crashed: a PS2-offset receiver in CDoorBase::Command (CanPenetrate) and a host struct handed to a script without a guest layout (ActorDamage, ProjectileHit, CanPenetrate, BiteAttack, Action_GetActionList).
  2. A pointer array is walked with a PS2 element size. qsort and bsearch take the element size as an argument and the code passes a literal 4, or a memcpy/memset length uses a count of 4-byte entries. The two bomb sorts were the only qsort/bsearch call sites with a literal size.
  3. A record is copied between guest and host memory. The script interpreter is a 32-bit guest; its payloads must use guest offsets (SScriptMessageLayout) and host objects travel as handles (GuestHostHandle), never as host pointers.
  4. REF is not a pointer. REF is a 32-bit index and stays 4 bytes on the host. Code that stores a REF in a pointer field, or vice versa, reads two neighbours; the door's 0x18 field was exactly that shape after the padding shift.

Layouts of recovered structs (analysis/recovered-types.h, the unknown_ padding in headers) are a matching concern, not a width concern: the named fields after the padding are accessed through their real native offsets. The danger is only when raw PS2 bytes or a different type are reinterpreted.

Tools

  • tools/port/payload_scan.py — every SendCommand receiver type against the sender's payload type per message.
  • tools/port/payload_layout_check.py — for each differing pair, asks the host compiler for sizeof and every offsetof and prints fields whose offsets differ. It understands base classes, base-prefix receivers, a receiver that is the sender's first member, and the one discriminated payload (ProjectileHit/BiteAttack).
  • tools/port/payload_layout_audit.py — pointer-bearing messages and whether a script layout exists.
  • OPENBLOOD_TRACE_SCRIPT_MESSAGES=1 — runtime check; a clean session has no host payload of unknown layout not passed lines.
  • python3 tools/duplicate_classes.py --layouts — duplicate class definitions and their host layouts.
  • Grep for the fixed-size forms: qsort(/bsearch( with a literal element size, memset/memcpy lengths built from a literal 4, sizeof(...) == 4.

Fixed

Symptom Cause Fix
0x7500000001 in CDoorBase::Command when shooting a door door declared its own CanPenetrate record; the sender's base class padded its bool to a pointer boundary receiver uses the sender's SHM3ProjectilePenetrate (8c5d8e5c6)
actor damage and projectile messages reached scripts shifted or not at all host struct copied to a 32-bit guest SScriptMessageLayout with PS2 offsets, string and handle field kinds (2d16a4fe2)
0xb7ebcbf0000000b3 in QSortCompareFunc when a bomb exploded qsort(..., 4, ...) over ZBaseGeom*[30] sizeof(m_pTargets[0]) in both bomb sorts (3a4af69d0)
security camera visibility smashed UpdateVisible's stack canary three 32-bit words read through REF* endian_REF words (849ab8bc4)
perception payload shifted script commands REF fields widened the native struct endian_REF slots (ac249955f)
M02's bunny never cancelled her delayed evm02_trygovson request WalkToTargetState's enter copied the forked thread (ScriptState *) into an s32 and sent it as MSG_killthread's s32 thread, so payload->thread == pSS in the fork's handler never held on 64 bits; Bird, Rat and the M00 entrance bird sent a 4-byte zero the handler read as 8 bytes MSG_killthread_Payload.thread and the bunny's delayedMessageThread are ScriptState *, every sender sends a pointer
a turn on a useable's user wrote 8 bytes over a 4-byte REF Ambientub's TurnArgs and Touristwatchart's view of slot 50 (Alllevels_Human_CopyActorToReference, which turns to face its target) had a uptr target; the upper half landed on the callee's angletogeomdir REF target, and Touristwatchart uses the callee's own frame type

Reviewed and safe

  • qsort/bsearch call sites that pass sizeof(T) or sizeof(pointer) (reftab.cpp sorts const char * with sizeof(const char *); zttfont.cpp searches 8-byte kerning pairs).
  • Message payloads that are two REFs passed as a REF*/two-REF struct (DoorProtect, DoorProtectOpen), or a pointer written through a T** (GetRoomShatterList, GetRoomShotActivateList, MSG_GETINVENTORYLISTPTR).
  • CanPenetrate receivers that cast to SProjectilePenetrate read the base prefix of the sender; payload_layout_check.py proves the three offsets.
  • ProjectileHit carrying a ZHM3Damage (bite attack): ZHM3Actor reads it as damage only when rShot == 0, and ZHM3Damage begins with SHitInfo.
  • By-value REF payloads: SendCommand(..., reinterpret_cast<void *>(ref), ...) is a PS2 idiom because void * and REF are both 32 bits there. On the host the REF is zero-extended and the handler converts it back with reinterpret_cast<REF>(pData) without dereferencing it; that round-trips. Reviewed pairs: SetLinkedDoor, MSG_REGISTERKEYCARDREADER, MSG_USEKEYCARD (GetKeyCard), MSG_REMOVEITEMFROMINVENTORY, CamFollowGeom, ContainerOpen/ContainerClose (the handler ignores pData), and the elevator observer messages. The pointer-to-REF form (*static_cast<REF *>(pData)) is used only where the sender passes &ref (MainCameraControl_GetFollowGeom, DoorUnProtect).
  • ZBoneParticle::m_pPrims[16] is a 32-bit array despite its name and no recovered code dereferences it as a pointer.

Open

  • CCheckInside::SendMessage sends one REF to a message that declares two; the PS2 original over-reads by the same 4 bytes, so it is left matching.