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¶
- A record crosses a message boundary.
SendCommand/Callpass a pointer to a payload. If the receiver castspDatato another definition of the record, every field after the first pointer sits at the wrong offset. Both directions crashed: a PS2-offset receiver inCDoorBase::Command(CanPenetrate) and a host struct handed to a script without a guest layout (ActorDamage,ProjectileHit,CanPenetrate,BiteAttack,Action_GetActionList). - A pointer array is walked with a PS2 element size.
qsortandbsearchtake the element size as an argument and the code passes a literal 4, or amemcpy/memsetlength uses a count of 4-byte entries. The two bomb sorts were the only qsort/bsearch call sites with a literal size. - 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. REFis not a pointer.REFis a 32-bit index and stays 4 bytes on the host. Code that stores aREFin 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— everySendCommandreceiver type against the sender's payload type per message.tools/port/payload_layout_check.py— for each differing pair, asks the host compiler forsizeofand everyoffsetofand 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 nohost payload of unknown layout not passedlines.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/memcpylengths 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/bsearchcall sites that passsizeof(T)orsizeof(pointer)(reftab.cppsortsconst char *withsizeof(const char *);zttfont.cppsearches 8-byte kerning pairs).- Message payloads that are two
REFs passed as aREF*/two-REFstruct (DoorProtect,DoorProtectOpen), or a pointer written through aT**(GetRoomShatterList,GetRoomShotActivateList,MSG_GETINVENTORYLISTPTR). CanPenetratereceivers that cast toSProjectilePenetrateread the base prefix of the sender;payload_layout_check.pyproves the three offsets.ProjectileHitcarrying aZHM3Damage(bite attack):ZHM3Actorreads it as damage only whenrShot == 0, andZHM3Damagebegins withSHitInfo.- By-value
REFpayloads:SendCommand(..., reinterpret_cast<void *>(ref), ...)is a PS2 idiom becausevoid *andREFare both 32 bits there. On the host the REF is zero-extended and the handler converts it back withreinterpret_cast<REF>(pData)without dereferencing it; that round-trips. Reviewed pairs:SetLinkedDoor,MSG_REGISTERKEYCARDREADER,MSG_USEKEYCARD(GetKeyCard),MSG_REMOVEITEMFROMINVENTORY,CamFollowGeom,ContainerOpen/ContainerClose(the handler ignorespData), and the elevator observer messages. The pointer-to-REFform (*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::SendMessagesends one REF to a message that declares two; the PS2 original over-reads by the same 4 bytes, so it is left matching.