Message payload layouts¶
Two kinds of message payloads can be read at the wrong offsets:
- Host sender and host receiver use different record definitions. The
sender builds the native struct; a receiver reconstructed from PS2 offsets
(an
unknown_prefix with the real fields after it) reads fields where the wider native struct put something else. A separately declared copy of the sender's members is just as dangerous when the sender derives from a base class: the base's size rounds up to its alignment, so the fields after it move even though the declaration order is identical.CDoorBase's CanPenetrate query crashed that way on 15 November 2026: the sender'snHitCountsat at 0x18, where the door's private record hadpOperator, so the door dereferenced the hit count plus stale stack (0x7500000001). - A payload crosses between the engine and a script. A script reads its
own record: the PS2 field order with 4-byte
REFs, and on a 64-bit host 8-byte pointers. The engine's struct has pointer-sizedREFs. Without anSScriptMessageLayoutthe bytes pass unconverted, which shifts every field after the firstREFor pointer.
Both crashed during the 15 November stability pass: CDoorBase's CanPenetrate
query and ZHM3Actor's ActorDamage message.
Tools¶
tools/port/payload_scan.py finds mechanism 1. It maps each ZMessageResolver
symbol to its message name per file, records the struct each Command handler
casts pData to, records the struct each SendCommand(..., &variable, ...)
passes, and prints messages where the two type sets differ.
tools/port/payload_layout_check.py answers the next question: do the two
structs actually agree at the same native offsets? It flattens base classes,
generates a small probe that prints sizeof and offsetof for every member
from the host compiler, and reports every field whose offset differs between
the sender and the receiver. Receiver/sender pairs that are the same type are
skipped; a receiver that is a base of the sender is proved on the prefix it
reads; a receiver that is the sender's first member is safe by construction.
The one message whose payload has two shapes (ProjectileHit carries SHitInfo
from a projectile and a ZHM3Damage from a bite attack, told apart by
rShot == 0) is listed in the tool's reviewed pairs.
tools/port/payload_layout_audit.py finds mechanism 2. It lists every message
whose payload struct contains a pointer or REF, whether scriptmessagessdl.cpp
or scriptmessagesrecovered.cpp has a layout for it, and whether a scene script
handles it (a handler named after the message, _on_evm02_partydrink or
_on_message_9a1, or a case on its name or number). Its structs come from the
headers and from the .cpp files, so a record local to its sender counts. The
exit status is 1 when a script handles a message that has no layout.
Where payloads are converted¶
port/engine/zstdlib/_sdl/scriptfunctionssdl.cpp converts a payload that has a
layout, field by field, at every crossing:
SF.SendCommandandSF.SendScriptCommand: script to engine before the send, and back into the script's record after it, since a handler may answer in the payload.- The 11 interface thunks that take a
ZSC_EVENTdo the same around the call (ScriptPayloadFromScript,ScriptPayloadBackToScript). ScriptDeliverMessage, whichScriptEnginecalls for every message a script's state or handler receives: engine to script before the handler, back after it.- The message cue stores the engine's record, so it copies
GetNativeMessageBodySizebytes rather than the PS2 size.
The converted record is zeroed first, so padding and unlisted fields read as
zero. A REF that does not fit 32 bits aborts with the message name.
Fixed here¶
| Message | Payload | Fix |
|---|---|---|
ActorDamage (0x921) |
zmsg_actordamage |
layout; the hit animation name is a SCRIPT_FIELD_STRING, 8 bytes in the 64-bit script record, so the fields after it sit 4 bytes later than in the PS2 record |
ProjectileHit (0x10) |
SHitInfo |
layout; the COLI* is a SCRIPT_FIELD_HANDLE |
CanPenetrate (0x4b) |
SHM3ProjectilePenetrate |
layout; three handles, the answer and the hit count |
BiteAttack (0x11) |
ZHM3Damage |
layout for the hit record and damage scalars; the embedded COLI is zeroed, its pointer is a handle |
Action_GetActionList (0x1a) |
ActionArray** |
one handle field |
RemoveNamedAction (0x3f) |
const char * |
SCRIPT_FIELD_STRING |
The door's CanPenetrate receiver is not a script layout: CDoorBase::Command
now casts pData to the projectile's SHM3ProjectilePenetrate and uses
pWeapon/nHitCount, so sender and receiver are one type and no padding can
separate them (8c5d8e5c6). The PS2 field offsets are unchanged.
payload_layout_check.py reports three pairs after that change and all three
are proved safe:
CanPenetrate:SProjectilePenetratereceivers read a base prefix of theSHM3ProjectilePenetratesender (3 fields, same offsets).ProjectileHit: theZHM3Damagesender starts with anSHitInfo, andZHM3Actoronly reads it asZHM3DamagewhenrShot == 0(a bite attack).ProjectileHit: the reverse pair,SHitInfosender toZHM3Damagereceiver, is that same discriminated case.
Every other receiver/sender pair is either the same type or a REF/one-word
payload the tool skips because it is not a struct.
Field kinds in scriptmessagessdl.h:
SCRIPT_FIELD_STRING: the pointer passes as it is; scripts and engine share one address space.SCRIPT_FIELD_HANDLE: a host object the script can only pass back (aCOLI, a projectile, a weapon) travels as a small integer fromScriptHostHandle, andScriptHostPointerturns it back into the object.SCRIPT_FIELD_LOOSE_REF: a REF the sender leaves unset on some paths; the script gets its low half instead of an abort.
REF-width audit (16 November 2026)¶
REF is uintptr: eight bytes on a 64-bit host, one word in the PS2 record.
The first audit only looked at messages resolved by name; the ones the game
sends by number (0x800 and up) were not covered, and their payloads go wrong
in both directions:
- Host to script. A record with a field after a REF is read four bytes
early:
itemplaced(0x8b4) gave scripts the high half of the item REF as the rig,firealarm(0x85d) gave them padding as the panic area, andlevelctrl_lightswitchchanged(0x857) shifted all sixteen REFs and the state. - Script to host. A receiver reading
*static_cast<REF *>(pData)takes eight bytes from a four-byte script record, the REF plus whatever the script's stack held next. Every level controller's..._sendacticaterecursive, the M00 coke guard and container messages, M04's change-clothes check, M05's knock and pour, M06's walkie speech (whose locale string pointer was read from the wrong slot entirely), M08's guard death, M11's karaoke and spitting messages and the movie-with-activator start (0x80c) all read REFs this way.
scriptmessagesrecovered.cpp adds layouts for these 35 messages: 27 whose
payload is a single REF, and 8 records declared there member for member as
their host units declare them (only the light-switch record has a shared
header). The PS2 record sizes all equal ZMSG_Sizes. FindScriptMessageLayout
searches that table after the generated one. A lone REF sent host to script
was already correct on little-endian hosts; it gets a layout anyway so that the
script-to-host direction converts.
ZHM3LevelControlM00's container-changed handler read the watch type as
int32[1], the PS2 offset. On the port the native record puts it after an
eight-byte REF, so the non-PS2 build reads the second REF-sized slot.
Messages that were checked and need nothing:
objectvisible,objectnotvisibleandobjectvisibleupdate(0x808, 0x809, 0x922) are sent asuint32[3]andendian_REFrecords.perception(0x91f) is built from the script header'ssPerception, whose REFs areendian_REF.- The sound notifications (0x85f, 0x860) use
uint32references. lnkanimend,decalvisibleandscriptlnkubanimendhold no REF (for the PC version's longerdecalvisiblerecord see below).
Other fixes from the same pass:
RemoveNamedAction's string payload was recognised by the id0x3f, but ids below 0x800 are handed out at registration (it was 0xd3 in a Windows run), so the action name was dropped. It is now recognised by name.- 0x92f is
actorhurtin the script message table; the layout entry added for the disarm crash is now named that.
M02's party and the door protectors (25 November 2026)¶
The first audit read structs from headers only, and ZM02_PartyController
declares its records in M02_PartyController.cpp. The view test crashed M02
on them (docs/development/port/native-scripts.md, "The crashes the view test
found"): evM02_PartyDrink (0x9a1) sends SDrink { bool bOnPier; REF rDrinkPos;
REF rGlass; REF rBartender; }, and with 8-byte REFs and no layout the guest's
handler read the drink waypoint as its glass, consumed it and called
Item__Clearfooddrinkinfection on a geom that is no item. The audit with the
.cpp structs and the script handlers listed four more, and reading the engine
receivers of what the scripts send found two in the other direction:
| Message | Record (sender) | Layout |
|---|---|---|
evm02_partycontroller_init (0x99f) |
SPC { bool bVip; REF rThis; } |
byte at 0, REF at 4 |
evm02_walktoparty (0x9a0) |
SParty { REF rElevatorPier; REF rElevatorUpstairs; } |
REFs at 0 and 4 |
evm02_partydrink (0x9a1) |
SDrink |
byte at 0, REF at 4, loose REFs at 8 and 12 |
evm02_party_talk (0x9a6) |
STalk { REF rPartner; bool bFemalePartner; } |
REF at 0, byte at 4 |
doorprotectopen (0x829) |
doors.cpp's SData { REF rBaseGeom; REF rOperator; }, to the guard that protects the door |
REFs at 0 and 4 |
doorprotect (0x827) |
a script's REF; CDoorBase::Command reads an SDoorProtect |
one REF |
evm02_actionfinished (0x9ac) |
a guest's REF; ZM02_PartyController::Command reads *static_cast<REF *>(pData) |
one REF |
SDrink fills the glass on the pier and the bartender at the party, and leaves
the other uninitialised; on a 64-bit host that word is often wider than 32 bits,
which the converter aborts on. SCRIPT_FIELD_LOOSE_REF passes such a field's
low half to the script, as the PS2 script got whatever word the sender's stack
held, and converts it back as a REF. evM02_Party_Lapdance (SLD, two REFs)
has no script handler (the script message table has no name for it).
Msg_SoundEvent sends a host REFTAB of event pointers to non-actor
listeners. A script cannot use the table, so it stays unpassed.
The PC version's decal record¶
MSG_DecalVisible (0x80d) is two records. The PS2's zmsg_decalvisible
(src/external/j/jamout_hitman3/scriptc/headers/messages/decalvisible.h) is
{ int id; int type; v3 pos; }, 0x14 bytes. The PC release's
ZCheckVisible::UpdateVisible (PC 0x0052da30, through FUN_0052cab0) adds the
frame time it was sent at, in seconds: { int id; int type; v3 pos; float
fSentTime; }, 0x18 bytes, and its perception converter reads that word
(docs/development/port/pc-data.md, "Scene scripts with the PC data").
With pc_scripts the port sends the PC's record (SDecalVisiblePc,
port/engine/eventsbase/_sdl/decalvisiblepcsdl.h, from the port's copy of
UpdateVisible in checkvisibleoverridesdl.cpp) and the scripts run the PC's
handler (PcDecalVisible in port/engine/zstdlib/_sdl/pcscripts/perceptionconverter.c);
without it, the PS2's record and handler. Neither record holds a REF or a
pointer, so both pass to the scripts as they are, with no layout. The message
cue copies GetNativeMessageBodySize bytes, which is 0x18 for this message with
pc_scripts (scriptfunctionssdl.cpp), so a cued record keeps its time and a
handler that takes it later sees an older one, as on the PC.
Reviewed host-only payloads¶
These messages send a pointer-bearing struct between host objects that share the same header type, so their layouts agree by construction. They need a layout only if a script ever handles the message:
ActorRequestElevator, CanOperateObject (ZAction *), Collision (COLI),
CutSequenceRequestInfo, GETACTIONFORFLOOR,
GetCombineWithItem, GetRoomShatterList, GetRoomShotActivateList,
GetUserInFrontOfMe, IsLinkedDoorBlocked, MSG_DETERMINELNKOBJLOC,
MSG_GETINVENTORYLISTPTR, MSG_MOVEMODIFY, MSG_PICKLOCKREQUEST,
RegisterNearbyUser, RequestDoorInfo, RequestElevatorInfo,
RequestFloorDef.
Rule¶
A struct passed through SendCommand that holds a pointer or REF must either
- be the same type on both the sending and receiving side (host to host), or
- have an
SScriptMessageLayout(host to script), whose script offsets and size are those of the scripts' record: the PS2 order and offsets, moved where a pointer before the field is 8 bytes on a 64-bit host.
Same member order is not enough. Use the sender's type, including its base
classes; if the receiver cannot name that type, prove every offset with
payload_layout_check.py and record the reason in the tool's reviewed pairs.
Never reconstruct a receiver from PS2 offsets while the sender builds the
native struct. payload_scan.py finds the different types,
payload_layout_check.py proves or disproves their offsets,
payload_layout_audit.py covers the script case.