PowerPC evidence: format decoder mechanics#
2026-10-09. Static reading of the Feral Mac PowerPC build (Sim Theme Park); the original program was not run. Original .data files, the HFS image, extracted assets, expanded sections and disassembly stay outside this repository. Facts below are Mac-build facts unless a PC/Patch 2 variant check is stated; Mac static evidence alone does not prove PC runtime behaviour.
Reproduce#
From the repository root, with Python 3 and no third-party packages:
python3 -m unittest discover -s tools/ppc-analysis/lanes/formats -p 'test_*.py' -v
python3 -I tools/ppc-analysis/lanes/formats/format_witness.py /Users/sander/server/game-assets/mac-feral/bin
python3 -I tools/ppc-analysis/lanes/formats/corpus_check.py /Users/sander/server/game-assets/theme-park-world/Data
python3 -I tools/ppc-analysis/lanes/formats/corpus_check.py /Users/sander/server/game-assets/theme-park-world-patch2/Data
# C# parser (synthetic) and corpus cross-check of the decoders in "Implemented in the parser"
dotnet test source/OpenTPW.Tests --filter "FullyQualifiedName~Md2|FullyQualifiedName~ObjectVertexAnimation"
OPENTPW_GAME_PATH=/Users/sander/server/game-assets/theme-park-world dotnet test source/OpenTPW.Tests --filter "FullyQualifiedName~Md2|FullyQualifiedName~ObjectVertexAnimation"
# two dynamic vertex buffers read back from Metal (macOS)
OPENTPW_NATIVE_SHADER_TESTS=1 dotnet test source/OpenTPW.Tests --filter "FullyQualifiedName~NativeDynamicVertexBuffers"
format_witness.pyrefuses any container whose SHA-256 differs from the pins below, then makes 1,539 checks (the clock-selector witness reruns the 130 copy-back checks) of instruction fields, branch conditions, relocated TOC slots, literal constants and label strings at the offsets cited here, and prints interpreted JSON (labels, widths, constants, offsets). It never executes code and does not print bytes or instruction text. It bypassesanalyze.pyand its heuristic function boundaries; every function start cited here is an export transition vector, a directbltarget or both.corpus_check.pycross-checks the code-derived models (models.py) against a private PCDatatree using its own bounded DWFB/RefPack/zlib reader and prints counts only (about 50 s).models.pyrestates each decoder path in Python with the code offset in its docstring; synthetic tests pin the semantics, including an instruction-level emulation of the packed-vertex conversion that must agree with the model on 2,008 words.
| Container | SHA-256 |
|---|---|
SimThemePark.data | 04809cd4ccee5433c7fb0b7c93d32f6a7aa629c1849181c0b7906415e5e295f5 |
libraries/engine_shared.data | c549123f647dcf33c3e2c3d515bffe2cfcb19d11680f743f02ca42bb09dbd73b |
libraries/ltms_shared.data | 2b0f7ac92c1f8b67761d271dd5832fca1bd19a8dd8d494b7b89b6ffa693e6ee8 |
Offsets are section offsets (code = section 0, data = section 1). TOC bases: SimThemePark 0x8000 (main vector), engine_shared 0x8000 (export vectors). All Mac loaders byte-swap little-endian files, so the Mac build consumes the same byte layout as the PC files.
Variant checks#
| Input | Mac HFS copy vs PC baseline | Patch 2 |
|---|---|---|
levels/jungle/Easymode.TPWI | byte-identical (6d89303d…) | not changed |
levels/jungle/rides/wateride.wad (both 207.201 members) | byte-identical (77c6a09f…) | not changed |
levels/*/terrain.wad base.map, terrain.map, base.MD2 | decoded members identical (77/80, 92/95, 103/106, 73/76 members equal; only three .wct differ) | not changed |
| MD2 corpus invariants below | — | all counts identical (2,118 members) |
The Mac data:Language:American fonts differ from PC English files (locale), so BF4 statements below are code facts, not corpus comparisons.
MD2 (M3D2)#
Loader gating (engine_shared LoadM3D2Header, code 0x3f9d8)#
The loader opens the file ("rb"), reads it whole, byte-swaps the header, checks magic 0x1CD15D46 (addis −7377 / cmplwi 23878 at 0x3fc38), then gates on the major word (+4) and minor word (+8). Status labels are printed as "%s (Label)" from a table at code 0x44101:
| Condition (in order) | Label | Result |
|---|---|---|
| magic mismatch | BadFileType | NULL |
| major > 221 | OldCode | NULL |
| major < 221 and argument bit 1 clear | DeadMesh | NULL |
| argument bit 2 clear and trailer pointer (+0x98) ≠ 0 | Master is Anim | NULL |
| argument bit 2 set and trailer pointer = 0 | Anim is Master | NULL |
| trailer and minor > 203 | OldCode | header returned, trailer pointer and header flag 0x20 cleared |
| trailer and minor < 203 | DeadAnim | header returned, trailer pointer cleared, header word 0x30 zeroed |
| no trailer and major < 221 | OldMesh | header returned |
| otherwise | Ok | header returned |
The application imports it through one glue stub with exactly two call sites: 0x58f04 passes flags 0, 0x99ad8 passes 2 or 6. No call site sets bit 1, so in this build every major-207 member, including wr_tunnel.md2 and wr_tunnelm.md2 (Mac copies byte-identical to PC), is refused with DeadMesh before any layout is interpreted. OpenTPW's rejection of 207.201 matches the Mac loader; no 207.201 layout needs to be supported for parity with this build. Model: models.load_status; corpus: 2,116 Ok, 2 DeadMesh (baseline and Patch 2).
Header/trailer field roles from the swap and relocation code#
Header u32 fields 0x00–0x14, 0x2C and 0x30 and u16 0x34–0x4A are swapped; 0x40bc8 relocates 0x4C–0x7C, 0x98 (trailer) and 0xAC (a table swapped with the same routine as animation position headers, 0x40664); 0x9C is overwritten with the header's own address at load. Trailer (72 bytes): words 0–2 u32, 12–28 nine u16, 32–68 pointers relocated by 0x4123c. The trailer helpers (call site → callee, pointer, count) establish:
| Trailer pointer | Count | Helper | Content |
|---|---|---|---|
| +32 (word 8) | u16 +12 | 0x40664 | position headers (16-byte) |
| +36 (word 9) | u16 +14 | 0x41604 | scale keys (u16 tick, u16, 3×f32), 192 files |
| +40 (word 10) | u16 +16 | 0x4171c | rotation keys (20-byte) |
| +44 (word 11) | u16 +18 | 0x413b4 | 64-byte records |
| +48 (word 12) | u16 +24 (word 6 low half, previously "opaque") | 0x412e0 | texture-frame tracks: 8-byte {u16 slot, u16 count, ptr→count × (u16 tick, u16 frame)}, 229 files |
| +56 (word 14) | u16 +26 | 0x417c4 | node list (u16) |
| +52 (word 13) | — | relocated only | zero in corpus |
Texture-frame tracks: the clip update 0xa56f8 calls 0xa4160 only when trailer word 0 bit 0x2 is set (bt eq skip at 0xa5768) and global option bit 0x8 (+16396 of the global block) is clear (bf eq skip at 0xa5778; the word is only ever stored as 0, see "Gate inputs"). 0xa4160 scans each track from its last key backwards and takes the first key with tick ≤ trunc(time) (so of two equal ticks the later entry wins; none found → slot unchanged); when the frame differs it stores it in that slot's 8-byte runtime entry (array pointed to by instance +80) and sets the entry's dirty bit 0x400. Corpus: trailer word 0 bit 0x2 is set exactly in the 229 files that have tracks (1,278/1,278 agree); 459 tracks (4 with a repeated tick), 458 index a slot of the paired base model with every frame below that slot's frame count (one track has no in-range slot).
Record (64 bytes) pointers relocated by 0x41574: +24 position header, +28 rotation keys, +32 scale keys, +36 path-parameter block, +44 0x10000 block, +48 u16 list (count u16 +22), +52 easing curves. +40 (vertex block) is relocated by 0x41a98 only after the 0x4000 test; +60 is swapped but not relocated and +56 is left untouched.
Record sampler (SimThemePark 0xa4f68)#
Inputs: player state (float time +32, float duration +28), instance (the geometry M3D2 header), node state (the record's runtime +60 word: a mesh or dummy record of that header), record. If time > the player's duration (clip duration, not the record's +12) the record is skipped. Then, in order:
0x20000 node-flag toggle list (
u16at +22 entries of signedi16at +48): scanning from the last entry backwards, the first entry whose|value| ≤ trunc(time)(unsigned compare; −32768 never matches) decides; a positive entry clears node-state bit 0x10, a zero/negative entry sets it; none found → unchanged. Corpus: 2,536 lists, all sorted by magnitude and|value| ≤record duration. What bit 0x10 controls is not traced (often read as visibility).0x1000 vertex animation, only when 0x4000 is clear → 0xa4a58 (below) with the node state as its object (
mr r3, r27at 0xa5054) and add mode = header flags (+0x30) bit 0x4 ("relative animation", see "Instance, node state and clip bind"); afterwards the header gets flag 0x00040000 (0xa5070). 0x4000 records (30 in corpus) are not handled by this sampler.0x8 rotation keys (kind 2, stride 20, wrap flag set) → optional easing → 0xa820c.
0x80 scale keys (kind 4, stride 16, no wrap) → per-component linear.
0x1 position: header kind bit 2 → Bézier (0xa85ac, base index
3·key+1); kind bit 8 → linear (0xa88fc); otherwise 0xa89f0. Result is written to the node translation, or added when header flag 0x4 is set.0x200 path parameter (used when 0x200 is set, the position flag 0x1 is clear and the node state's bit 8 is set): block +36 is
{u32 start, u32 count, u32, ptr→count f32}; withinstart ≤ time ≤ start+countthe sampled valuevbecomesfmod(1000 + v, 100)percent along a spline selected through the header 0xAC table, evaluated with the same three evaluators. 0x400 additionally derives an orientation (0xa3b50) from a normalised vector from 0xa8758/0xa8994 or, for the third kind, 0xa89f0 at fraction + 0.1. The table and node-selection details are only partly traced.
Key search (0xa3ff0, kinds 1/2/4 = strides 4/20/16): tick = trunc(time) via the runtime double→unsigned routine 0x1c3fbc (negative → 0). It takes the last key with key.tick ≤ tick; if none, the channel is left unchanged. At the last key a wrapping search pairs with key 0, otherwise with itself at tick + 1. Fraction = (time − tick₀)/(tick₁ − tick₀). Rotation interpolation (0xa820c) then overrides the partner index to min(i + 1, count − 1), so a final rotation key holds. Model: find_key, rotation_pair.
Easing (0xa50d4): an index of 0xFFFF means none; otherwise the 8-byte curve at +52 + 8·index is evaluated as s = fraction × 8.999995 (single precision, literal at TOC 0x5198), segment i = trunc(s), local s − i, linear between 0 / b0 (i = 0), b[i−1] / b[i] (1 ≤ i ≤ 7) or b7 / 1.0 (i ≥ 8), bytes divided by 255.0. This proves the "(0,0), eight samples, (1,1)" reading and adds the 8.999995 scale. Model: ease.
Rotation interpolation (0xa820c): with global option bit 0x2 (+16396 of the global block at data 0x1577c0) clear it calls table-sine slerp 0xa7fc8 (threshold 0.001 on 1 ± dot, no sign flip of the second quaternion); with the bit set the components are blended linearly, (1 − t)·a + (t·b). Either result goes through 0xa7ef8, a quaternion-to-matrix conversion using s = 2/|q|², which normalises the blended quaternion implicitly. The only store to the option word writes 0 at setup (see "Gate inputs"), so the original uses the table slerp; OpenTPW's slerp does not reproduce its sine table.
Bézier (0xa85ac): with k = trunc(t), s = t − k, i = base + 3k, the cubic Bézier over P[i−1], P[i], P[i+1], P[i+2] (indices modulo the point count in header u16 +4). With base = 3·key + 1 this is exactly P[3k] … P[3k+3], confirming the existing P0, (C, C, P)… reading. Model: bezier.
Instance, node state and clip bind (identities)#
Instance = the geometry M3D2 header. The geometry loader 0x99aa4 passes model object +4 to
CMesh::Init(tag_sM3D2Header *)(0x99b84/0x99b88); both record-sampler call sites take the instance as model object +4 (0xa573c, 0xa7238). The fields the runtime uses are header fields ofModelFile: +0x30 flags (+48), +0x42 node count (+66), +0x44 mesh count (+68), +0x50 texture-slot table (+80; the texture-frame tracks write its 8-byte entries, the same entries materials point at), +0x70 mesh records (+112, 160 bytes) and +0x74 dummy records (+116, 88 bytes).Node state = that header's mesh record (dummy record past the mesh count; 0xa5a08–0xa5a2c). So the vertex array at node state +96 is the mesh record's vertex block (
VertexOffset, count u16 +88), stored in blocks of four (48 bytes), and group 0's vectors at +120/+132 overwrite the record's stored bounds fields (Mesh.BoundsMin/BoundsMax). A scratch corpus check (not in the checker) found the tick-0 box equal to the stored bounds in 0 of 1,735 blocks and containing them in 811, so the stored bounds are not the animated box. Which renderer or culling code reads the bounds was not traced. After a vertex pass the record gets flag 0x00010000 (0xa4f44); its consumer was not traced.Relative animation (header flag 0x4). The ride loader 0x58a3c strips the flag (clears 0x4, sets 0x01000000) and prints
"Ride %s has relative animation incorrectly set / Stripping flag, animation will not work!"unless its argument has bit 0x20000 (bf eqat 0x58bd4). Its constant call sites pass 0x50120 (0x29180), 8 (0x4da20, 0x4da44) and 0 (0x59704); 0x596b0 passes a word built by 0x594c8 that gets 0x20000 only from bit 0x01000000 of its r7 flag word (0x595f8), whose source in ride data was not traced. So in this build set mode is the default and add mode needs that explicit flag. Corpus: 27 geometry members carry 0x4 (coaster pylons, carts, track), 31 vertex clips pair with them, and no object-catalog model has it.Clip bind 0xa5894 (target and base header, each as object +8 → +4): for every record of the clip being replaced it clears node-state flags 0x00800000 (with header flag 0x4) or 0x00F40000 (without), which includes the static-group/cursor-reset flag. Then, only when header flag 0x4 is set or global option bit 0 (+16396) is clear and the object does not have flag 0x00100000 with 0x8 clear (0xa58c8–0xa5948, gate 0xa5a5c–0xa5a6c; 11c1003 described the copy-back as unconditional), channels the replaced clip animated but the new one does not (
old & ~newper node, 0xa5aa8; all of the old clip's channels when there is no new clip) are copied back from the base header: matrix rows for 0x289, the vertex block ((n + 3)/4 × 48bytes viamemcpy) plus the four bounds words for 0x1000, and the array at +104 (count +94, i.e. texture coordinates per corner) for 0x10000. The last is a lead that the 0x10000 block animates texture coordinates; it is not proven.Gate inputs (witness
md2_copy_back_flags). Option word +16396: of the eleven displacement-16396 accesses only 0xa7eec stores it, its argument; its one call (0x54c08, in setup routine 0x54be4 called from 0x1c1c44) passes 0. The two address computations in the animation code are only read through, and 0x112230 is a range comparison. So bits 0, 0x2 and 0x8 are clear unless a bulk write of the global block (not excluded) sets them. Object flags +4: the ride loader 0x58a3c clears a 252-byte object (memset), ORs ride-flag bits into +4 (ride 0x100 → 0x8, ride 0x1000 → 0x00100000; also 0x2000 → 0x02000000, 0x8000 → 0x10000000, 0x00800000 → 0x20000000, 0x20 → 0x01000000, 2 with 4 → 0x4; no other stores; the callees it hands the object to add only object bit 0x10 or a header bit, and of the sevenoris …, 0x10in the code only this one reaches an object +4 word) and copies it out (memcpy). Its direct callers pass 0x50120, 8, 8 and 0, none with ride 0x1000. The builder 0x594c8 maps its r7 word (caller 0x200 → ride 0x100, caller 0x40000 → ride 0x1000, 12 other bits) for eleven callers whose words are 0xC0, 0x01013405 (twice), 0x12423/0x112423, 0x10422 (twice), 0x422, 0xC0/0x40C0, 0x50C00/0x450C00, 0xB24A9/0x4B24A9 and 0xC0. Only 0x119ac0 passes 0x40000 without 0x200: it is in the ride catalog loader 0x119328 ("Too many rides loaded"), which picks that word when the ride descriptor's word +56 is non-zero and 0xB24A9 otherwise.Descriptor word +56 is
Info.DontApplyOffset(witnessmd2_ride_descriptor_fields). 0x119328 allocates the 2,056-byte descriptor, stores the vtable 0x46030 (type nameCRideBalance) at +8 and calls the schema layout 0x16f4c on +4. Its vtable returns field record0x39b64 + 60 × i(+8) and the field data at schema +8, i.e. descriptor +12 (+12). 0x16f4c counts records up to kind 12 (0x197a4) and gives each record of kind 4–11 the word atdata + 4 × n, n from 1; kinds 0 and 1 get none. The records up to theInfogroup are kinds 0, 5, 6, 10 and 11 (no arrays), so the 35Info.*keys take words +16 … +152 in table order:Id+16,Shape+24,Hoarding+28,EngineFootprintWidth/HeightOverride+40/+44,DontApplyOffset+56 (kind 6, bound 2) andDoHeadProcessing+132. Every descriptor read of the loader matches: Id (+16) selects the record, Shape and Hoarding go to the object builder, the footprint overrides are passed only on the +56 path, and +132 adds caller flag 0x00400000.So, with the option word at 0, the original copies the stored mesh back on a clip change for every object except the catalog object of a fixed item (
Info.DontApplyOffset 1), which keeps the replaced clip's last pose (header flag 0x4 would still copy back). The only 0x58a3c objects are those of the creators above (advisor, level base, track pieces, queue models, lobby globe, catalog objects and their sub-models); no other code allocates the 252-byte object this way. Placed instances are copies of it (see "Instances and placement" below); whether the gate holds for an instance over its whole lifetime is not settled.The record +60 binding itself (where a clip's records are pointed at the header's records) was not found among direct stores; the sampler and the bind routine agree on the record layout above.
Normals after a vertex pass: 0xa772c recomputes each face normal (mesh record +100, indexed by face word >> 1) from the cross product of the face's corner positions, normalised. It runs for mesh records with flag 0x00010000 from 0xa7960 only for relative-animation models (header flag 0x4), from 0xa78ec (all meshes; at placement and at 0x567e4) and from the walk at 0x19ac0c when record flag 0x10000000 is also set. Set-mode objects keep stored normals on the 0xa7960 path; for the other routes see "Face-normal routes" below.
0xa4a58 computes
modf(time)and a decremented integer part on entry (0xa4a88–0xa4abc) that nothing reads.
Animation clock: 30 ticks per second (proven for this build)#
0xa6484 (update):
time = speed × (30.0 × (now − start) / 1000.0)withspeedat player +12,now/startinteger milliseconds at +20/+16; literals 30.0 and 1000.0 at TOC 0x516c/0x5170.0xa6398 (set clip): duration =
(float)(clip+8 − clip+4)(trailer words 2 and 1; word 1 is 0 in all trailers); a start time in ticks is converted back with1000 × t / 30 / speed. 0xa65a0 returns remaining time as(duration − time) × 33.333332ms.now/startcome from one of two scene clocks in the global block, chosen per channel by bit 0x40 of channel word +0 (not a player flag; see "Clock selection" below).0xa6484 itself has two callers, both in the frame-capture loop 0x4f584 (0x4f8b4, 0x4faf0), which pass the time through a pointer. The per-update clock step of normal objects is inline in the channel update 0xa7190, with the same arithmetic. 0xa64e0 (one caller, 0x5b860) rebinds a clip and computes
30 × elapsed / 1000 / speed, dividing by the speed; it is not modelled.One caller (0x4f888) starts a clip with speed 1.0.
So, at speed 1.0 and an unscaled scene clock, MD2 ticks advance at 30 per second. Clock A's rate, its hold and the pause callers are traced in "Scene clock controls" below.
Clock selection (proven for this build)#
Witness md2_channel_clock_selector (259 checks); reference model clip_clock_reference.py with its tests.
Consumers. All three channel reads of a scene clock test channel word +0 bit 0x40 and read global +16408 (clock B) when it is set, +16400 (clock A) otherwise: the fresh start in 0xa6398 (0xa63ec), the per-update step in 0xa7190 (0xa728c) and the all-ended check 0xa7000 (0xa7074). The global block is TOC −0x7684 in all three. 0xa7190 stores the selected value in AnimTime (+20) and NoPauseAnimTime (+24). If channel bit 0x2 is set it instead keeps AnimTime = StartAnimTime with frame 0. If only 0x4 is set it uses AnimTime = start + trunc(1000 × TotalAnimFrames / 30 / speed) with frame = TotalAnimFrames. In both frozen cases NoPauseAnimTime still follows the selected clock. When a clip is current, 0xa67d8 sets 0x2 for AnimID 13 and 0x14 for AnimID 14. It clears 0x6 when it starts another existing clip, and maps its flags 0x1 → loop and 0x4 → 0x20. It never touches 0x40.
Quirk. 0xa7000 loads the channel array pointer once and never advances it, so it tests channel 0 once per channel. It runs from 0xa7960 when object flags 0x8004 are clear.
Refresh. 0xa6f70 (callers 0x5ba44, 0x11b550, 0x1c16f4, 0x1c22ac) reads both clocks from the clock object (TOC −0x75d8). It stores A in +16400, the single-precision
(A − previous A) / 1000in +16404 and B in +16408. Channels read the stored integers, so every channel in one update sees the same pair.Clock A (timer at object +0):
LbTime_GetClocksteps (unsigned) times a double rate (+0x18) are accumulated in a double (+0x10, 0x127cd0) and truncated to whole units. Paused time (+0x24) is subtracted (flag +0x28, value at pause +0x20), then offset +0x38 is added. While held (+0x2c), A returns +0x30 instead of that sum (a fixed-step mode; see "Scene clock controls"). Offset +0x3c is added in both cases. The snapshot 0x10e9ec (caller 0x11dbac) keeps the current A in +0x40. Restore 0x10ea28 (caller 0x11b54c, followed directly by the refresh 0xa6f70) sets +0x3c so that A continues from that value (0x11a5bc).Clock B (timer at object +0x44): the same steps accumulated without a rate (
fadd, 0x10edb4), with paused time +0x10 (flag +0x14). Its snapshot is in +0x1c and its restore offset in +0x18. There is no hold.Pause. 0x10e888 (pause), 0x10e8bc (resume) and 0x10e8f0 (toggle) each drive both timers. Each of the six timer routines has only that caller, so the clocks pause and resume together. Rate and hold apply only to A.
Producers. In the animation code (0xa3000–0xa9000) the only store of channel bit 0x40 is 0xa7bfc. There, the channel reset 0xa7bb8(object, stop, use_b, r6) ORs 0x40 into every channel when use_b ≠ 0, and nothing in that code clears it. A scan control finds the known set/clear pair at 0x150a10 and 0x150a20. Its four callers pass:
0x291ac: use_b = 1. This is the advisor creator 0x29084 (
Advisor%s.md2/Advisor.md2). It loads the model through 0x58a3c, instantiates it through 0x543cc and resets the instance.0x4f5fc: use_b = 0 (frame capture).
0x5a0ec: use_b = 0 (placement).
0x591ec: use_b = ride flag 0x40000 in the ride loader. The loader keeps the flag in r17, and the call happens only when ride flags 0x2 or 0x8 are set. No loader call reaches it with 0x40000. The direct words are 0x50120 (the advisor, without 0x2/0x8), 8, 8 and 0. The builder 0x594c8 has no source of ride 0x40000 or 0x8, and none of its eleven creator words maps to ride 0x2.
Result. In this build only the advisor's channels run on clock B; every catalog and placed object's channels start with 0x40 clear and run on clock A. Writers outside the animation code are excluded only by the scan of that range and the memcpy search below. Stores through other code that receives a channel pointer, and channel words restored from a save, are not excluded.
Requirements for a faithful reimplementation (Mac build; not a PC claim):
Two scene clocks, sampled once per update and shared by every channel. A is rate-scaled and can be held; B is unscaled. Pause, resume and toggle act on both.
A per-channel selector fixed before the channel's start time is taken. Start, AnimTime and the elapsed difference use the same clock, and the difference is unsigned, so mixing clocks wraps (reference test).
The selector is a property of the object's channels, set at creation and copied to instances. It is not derived from the clip, the model file or the placement.
A's rate is not a ticks-per-second value. It scales whole-millisecond accumulation from the last read, so a rate change does not rescale time already elapsed. The truncation also makes rate 1.5 differ from 45 ticks/s (both are reference tests). OpenTPW's per-animator
TicksPerSecondis therefore not this mechanism, and treating it as game speed would be a separate, unproven choice. The rate's setters are now known (below), but that does not make a custom ticks-per-second value equal the original speed.Frozen channels (0x2/0x4) ignore the clock for AnimTime but not for NoPauseAnimTime.
Scene clock controls (proven for this build)#
Witness md2_scene_clock_controls (317 checks); the reference model clip_clock_reference.py adds the rate steps, the hold and the release.
Every route to the clock object. Only one data pointer points into the clock object (0x11f340–0x11f3a3): the TOC slot −0x75d8. A straight-line scan from each of its 55 loads to the next
blrfollows copies of the pointer. It finds no store of the pointer. Its only direct stores are in the initializer 0x10ea5c (caller 0xf0, static initialization): +0x20–+0x30, +0x38, +0x3c and +0x50–+0x5c are set to 0, so hold +0x2c and +0x38 start at 0. The pointer is passed (in r3, at offset 0, or +0x44 for the B timer init) to 19 routines only: the A/B getters, the paused-flag getter, the rate init/set/step/get, hold, release, the held step, the three pause wrappers and four save routines. The scan does not follow branches, so it is a bounded witness, not a data-flow proof.Rate (timer +0x18, double). It is 1.0 at start (0x127c08). It changes only in 0x127c40 (store), 0x127c48 (×1.25) and 0x127c88 (÷1.25). Both steps then clamp to [0.25, 2.0] (
fcmpo; a NaN rate becomes 0.25). With the init these are all six +0x18 stores in the timer code (0x127c08–0x127d3b), and the route scan above reaches the object only through them. Each has one caller, a handler that is never called directly: 0x11315c (÷1.25), 0x113184 (×1.25) and 0x1131ac (= 1.0). Each handler's transition vector is referenced only by entries 6, 7 and 8 of the 15-entry "game" key table (0x4524c, built by 0x114d50). Their key words 0x6d00, 0x6b00 and 0x6a00 have no character byte. Whether these are Mac key codes (F10/F14/F16) or Win32 virtual keys under MacDoze (numpad −, +, *) was not traced. Nor was the table dispatcher, so whether anything other than a key press invokes those entries is not known. With the clamp the rate depends on the path taken: 1.0 → 1.25 → 1.5625 → 1.953125 → 2.0, but ÷1.25 from 2.0 gives 1.6 (reference test). The rate is read directly only at 0xbd298/0xbd2b4/0xbd2cc, where per-pass counters add0.4 × rateandtrunc(rate)unless A is paused. Their meaning was not traced.Hold = fixed-step mode. 0x10ec60(object, n) does nothing if already held. Otherwise it stores the current A in +0x30 and
1000 divwu nin +0x34, then sets +0x2c. The step 0x10ed10 (one caller, 0x1104d8, once per main-loop pass via 0x1162d0 ← 0x1c11b4) adds +0x34 to +0x30 unless A is paused. Release 0x10ecc0 sets +0x38 = held − timer, so A continues from the held value without a jump. Both hold call sites pass n = 32, a step of 31 ms (31.25 truncated), so 0.93 MD2 ticks per pass at speed 1:0x1c0b64, at main-loop entry. It is released at 0x1c15d0 in the same routine, just before the advisor is created (0x1c1608).
0x1c229c, on each pass while the capture flag (TOC −0x5e24) is set, and released on the first pass after the flag is cleared. The flag is cleared at main-loop entry and toggled only by "system" key 3 (key word 0x77, modifiers 0x3f0000; key 2 with the same key word and no modifiers takes one shot). While set, each pass calls
CCapture::SetCaptureon the importedgei_Captureobject withScr%05ld.tga.
While A is held, clock B keeps real time, so the advisor (clock B) and everything else (clock A) drift apart during capture (reference test).
Pause is global; frozen bits are per channel. The only callers of the pause, resume and toggle wrappers are three methods of the game-state object (TOC −0x764c, data 0x11f42c): 0x110518 (pause, 8 callers), 0x110598 (resume, 8 callers) and 0x110604 (toggle, callers 0x1128a0 and 0x1576ec). Each acts only when that object's +0x3c is 1 (other writers not traced; the main routine stores 0 at 0x1c1694, right after its load-end resume at 0x1c1688). The toggle at 0x1128a0 is the handler of "system" key 0, named
pause(key word 0x50). The other callers were not identified: pause 0xc50, seven pause and seven resume callers in 0x153000–0x1ba400, and the toggle 0x1576ec. The difference:Global pause (wrappers) Hold (fixed step) Channel bit 0x2 / 0x4 Scope clocks A and B, every channel clock A only one channel AnimTime stops (its clock stops) moves 31 ms per pass fixed at start / end NoPauseAnimTime stops too (it is the selected clock) as AnimTime follows the clock On release paused time subtracted, no jump +0x38 offset, no jump cleared by 0xa67d8 on the next clip "NoPauseAnimTime" therefore does not keep running through a global pause in this build; it only differs from AnimTime for frozen channels.
Save. The save writes (0x10e944) and reads (0x10e998) only the two snapshots, 4 bytes each (A +0x40, B +0x44 + 0x1c). The rate and the hold are not saved: a loaded game keeps whatever rate the session has.
Not implied: none of this sets a game speed for OpenTPW. The original range is 0.25–2.0 in ×1.25 steps on accumulated milliseconds, behind unidentified key bindings. A per-animator ticks-per-second value is not equivalent (see requirement 4), and PC key bindings and UI routes are unknown.
Instances and placement (proven for this build, partly)#
0x543cc (callers 0x29198 advisor, 0x4f5d8 capture, 0x59f90/0x59fa8 placement) allocates
252 + 56 × countbytes without zero-fill. It copies the whole 252-byte template (31 double words plus the word at +248), so template +4 flags carry over. It then sets +0 = template, +8 = an object header built by 0x53004 from the template's (copy depth below), +16 = its own channel array right after the object, andmemcpys the template's channels. That is the onlymemcpyof acount × 56size in the image.The ride loader allocates template and channels with 0x55b54(size, 1), which passes flag 0x40 to
GlobalAlloc__10NS_MacDozeFUiUl(GMEM_ZEROINIT in the Win32 convention MacDoze follows; its implementation was not read). Template channels therefore start at 0.The builder 0x594c8 appends each loaded object to the object table (TOC −0x739c). The placement routine 0x59f00 takes its template from that table by id, or from template +0xd0 when placement flag 0x400 is set. It instantiates with constructor flags 0x211f (|0x200 for placement flag 0x800) and stores the placement flags at +0xe4. On the instance's +4 it clears only bit 0x1 and adds 0x4, 0x4000 and 0x8000 (placement 0x1, 0x2, 0x80). It then resets with use_b = 0 and, when clip 0 exists, calls 0xa6cc0 on channel 0 with AnimID 0 and then 13. Placement flags are a separate word from the catalog's object flags. The catalog flags reach the instance only through the copy.
So a placed instance starts with its catalog object's copy-back gate bits (0x8, 0x00100000) and clock selector. Placement does not clear them, and 0xa7bb8 only adds +4 bit 0x10. Later writers of instance +4 over its lifetime, the +0xd0 alternate template and save restoration are not traced. Placement qualification therefore remains open.
Copy depth of 0x53004, partly (witness
md2_normal_recompute_routes). The constructor passes its flags minus 0x800. With placement's 0x211f the instance gets its own 64-byte object header (a copy, with bit 0x1 cleared), its own 184-byte geometry header (object header +4) and its own copies of the 160-byte mesh records (flag 0x1) and the face-normal array (+0x5c, 12 bytes each; flag 0x8). Record +100 is rebased into that array only when flags 0x4 and 0x100 are set and the template geometry header +0x58 is non-null (838/838 geometry members). The object-header copy keeps the template's +0x28 pointer (below). Whether clip data and group cursors are per instance is still not traced.
Face-normal routes (proven for this build, partly)#
Witness md2_normal_recompute_routes (106 checks); corpus counts from corpus_check.py (geometry_checks; PC base and Patch 2 identical).
0xa78ec(geometry header) runs 0xa772c on every mesh record with flag 0x00010000 (+0x70, count +0x44, 160-byte stride). It then clears header +0x30 bit 0x40000. Its only callers are 0x5a4b4 and 0x567e4.
Placement (0x5a4b4). On every successful path of 0x59f00 (its only branches past this block are the three failures returning 0, and it has no early
blr), placement ORs 0x00010000 into every mesh record of the instance's own geometry header. It sets header +0x30 bit 0x40000 and calls 0xa78ec. So each placed object's face normals are recomputed once from its vertex positions at that moment. That is after the reset and the AnimID 0/13 starts at 0x5a120/0x5a13c. Whether those starts have written a vertex pose by then was not traced. The writes go to the instance's copies (see "Instances and placement"). The flag stays set on the instance's records, so any later route that tests 0x00010000 treats all of its meshes as recomputable. Whether the recomputed normals differ from the stored ones was not measured.0x567e4 runs only when the geometry header has both 0x40000 and 0x20000. Stored headers have neither (838/838 clear). 0x40000 is set after a vertex pass (0xa5070) and by placement, and cleared by 0xa78ec and the object update (0xa7b60). Setters of 0x20000 and the context of 0x567e4 were not traced.
Record flag 0x10000000. There are four
oris …, 0x1000in the image and nolis/addisof 0x1000. Only 0x19aef0 stores to a mesh record. It is in 0x19adf0, which the ride loader calls once (0x59274) for every object it loads; only a load failure skips the call. If the geometry header has entries (+0x48 count, +0x7c table, 20 bytes each), 0x19adf0 allocates a table and stores it at object header +0x28. Entry i selects record +0x46 + i (a mesh record below +0x44, else an 88-byte record at +0x74). When the entry's flags have any bit of 0x40040, the record that the selected record's +4 points to gets 0x10000000. Entry flags 0x30 set 0x20000000 on the selected record, and then table bit 0x1. Corpus: 2,452 entries; 248 in 28 geometry members (ride and feature models such asbigapple,ghostshp,creature,StdPylon) have 0x40040. All 248 select an 88-byte record whose +4 is a mesh record. The bit is set on the loaded file's records, so instances copy it.The walk. 0x19b08c (callers 0x2a110, 0x3bb4c, placement 0x5a35c and the object update 0xa7b9c) needs object-header bit 0x1 and table bit 0x1. It then walks the nodes (0x19a65c) and recomputes records with 0x10000000 and 0x00010000 (0x19ac0c). The object update calls it when the table exists, object +4 bit 0x20000000 (ride 0x00800000) is clear, and either r5 bit 0x8 is clear or header flag 0x4 is set. Placement calls it under the same table and 0x20000000 tests. Because 0x53004 clears the copied header's bit 0x1, the walk returns at once for a fresh instance unless something sets that bit again. Setters of object-header bit 0x1 were not traced, so whether placed rides ever take this route is open. 0x2a110 and 0x3bb4c were not identified.
Clip lifecycle: loop replay and cursor reset (proven for this build)#
Channel fields are labelled by the debug dump near 0x1c98fa: AnimID +4, SubAnim +8, StartAnimTime +16, AnimTime +20, NoPauseAnimTime +24, TotalAnimFrames +28, AnimFrame +32, DeferredAnimID +36, DeferredSubAnim +40 (12 = none).
The object update 0xa7960(object, r4, r5) runs the channel update 0xa7190 for each channel with r4 as its third argument (r27). 0xa7190 recomputes AnimFrame and, when AnimFrame > TotalAnimFrames (strict, 0xa7360), no clip is deferred and object flags 0x18 are clear, replays the same AnimID/SubAnim through 0xa67d8 if channel bit 0x1 (loop) is set, with flags
1when r27 ≠ 0 and9when r27 = 0. A deferred clip is started the same way; other cases stop (0x8) or hold (0x10) and are not modelled here.0xa67d8 carries
AnimFrame − TotalAnimFrames(0xa6904) as the start time, which 0xa6398 caps at the duration and converts to a whole-millisecond start (the original's AnimFrame after a wrap is that carry rounded through integer milliseconds). It calls the bind 0xa5894 with old clip = current clip only whenflags & 0xCis 0 (0xa6994), so with flags 1 the replay rebinds the same clip: 0x00800000 is cleared on its nodes and the next sample (normally later in the same update, 0xa7574) resets every group cursor to key 0.Mesh-record flag 0x00800000 is cleared only by the bind and by the frame-capture loop 0x4f584 (which steps a local clock by 30 ms and clears it on every mesh record after each frame); the other 12
rlwinmclears of that bit act on object or header words or unrelated structures. Stored state starts reset: every group cursor (+16) is 0 (1,736/1,736 blocks) and every mesh record has the flag clear (838/838 geometry members).Callers: 0x4d39c, 0x4d4b0 and the other direct callers pass r4 = 1, except 0x4d2fc (its caller's argument, with r5 = 8 when that is 0). The object-list update 0x4d354 passes r4 = 0 with r5 = 8 (0x4d420) for listed objects without flag 0x00200000; there a wrap replays without a bind, so the cursors stay on the last segment, and the channel samples only when object flag 0x00400000 is set (0xa7644–0xa7650). Such a sample at a smaller time would extrapolate from the kept segment (
AdvanceKeyreproduces it). Which objects take that path is not traced.Channel clock (0xa6484, 0xa6398, 0xa67d8; witness
md2_clip_clock): StartAnimTime (+16) and AnimTime (+20) are whole milliseconds andAnimFrame = speed × (30 × (float)(now − start) / 1000), each step in single precision, the difference converted as unsigned (bias 2^52). A fresh start (r5 ≠ 0) sets start = now = scene clock, so the frame is 0. The replay passes r5 = 0 only with a carry: 0xa6398 caps the carry at the duration, converts1000 × carry / 30 / speedthrough 0x1c3fbc (fctiwz, truncation; negative gives 0) and sets start = AnimTime − that. Unless object flag 0x8000 is set, 0xa67d8 then recomputes AnimFrame from the new start, so the wrapped frame is30 × ms / 1000. A replay happens at most once per update and the carry is capped, so one update far past the end lands at or below the duration, not attime mod duration, and a clip whose duration is not a whole number of milliseconds drifts (10 ticks: a 334 ms period).
So with r4 = 1 the cursor at every sample equals a fresh search from key 0: between binds AnimFrame does not decrease (unless the untraced scene-clock rate is negative), and the search only moves forward. This assumes the cursor (stored in the clip's group, +16) and the flag (in the header's mesh record) are not shared with another object sampling the same clip at a different time; whether clips and headers are per object was not traced.
Vertex animation (record +40)#
Quantised groups (flag 0x4000 clear; 1,736 records). Block (44 bytes): u16 flags, u16 groups, u16, u16 count2, u16 (+10 pad), ptr groups (+12), ptr pairs (+16, count2 × (u16, u16)), vec3 offset (+20), vec3 scale (+32). Group (20 bytes): u16 keys, u16 vertices, ptr→u16[vertices] vertex indices, ptr→u16[keys] ticks, ptr→keys×vertices packed words, u32 runtime key cursor.
Packed word (engine 0x41cac swap + application extraction): signed 10-bit X/Y/Z in little-endian bits 0–9/10–19/20–29; bits 30–31 discarded.
value = q × scale + offsetper axis (0xa446cfmadds).Packed words are key-major: the row of key
cstarts atpacked + 4·c·vertices(mullwat 0xa436c).Dispatcher 0xa4a58 (object = node state): while node-state flag 0x00800000 is clear it first resets every group's cursor (+16) to 0; then per group the cursor advances while
ticks[c+1] < time(no upper bound: a time past the last tick reads beyond the array); fraction(time − ticks[c])/(ticks[c+1] − ticks[c])in single precision, so a time on a key tick stays on the earlier segment with fraction 1 and a time before the first tick extrapolates. Values arecur·(1 − t) + (next·t)(fmulsthenfmadds). Destination is the node state's position array (+96, the mesh record's vertex block), laid out like the stored blocks (48·(v/4) + 4·(v%4)for X, +16 Y, +32 Z); add mode adds, else sets.Group 0 is always handled by 0xa468c and uses both of its vertices (words 0 and 1 of each key row):
lerp(v0) − scale − 0.25→ node state +120..+128 andscale + lerp(v1) + 0.25→ node state +132..+140 (set or add). Corpus: group 0 lists exactly(positions, positions + 1)(1,735/1,735 paired),v0 ≤ v1on every axis at every key (63,465 keys), and every key of another group at a group-0 tick lies between them (713,695 animated and 7,308 static vertex keys, none outside). So group 0 is a per-key bounding box padded by one quantisation step plus 0.25, written over the mesh record's stored bounds fields (see "Instance, node state and clip bind"); their reader was not traced. (b0935b4 described only vertex 0 as an instance translation; that was wrong.)Header flag 0x2: group 1 is static (key 0, no interpolation), applied only while node-state flag 0x00800000 is clear; a set-mode pass then sets that flag (0xa4ddc), so cursors persist and the static group is not re-applied until the clip is replaced (0xa5894 clears the flag on the replaced clip's nodes). Corpus: flags are 1 (1,338) or 3 (398); static groups have 1 (365) or 2 (33) keys.
Corpus: fields +4/+6/+8 and the +16 pointer are zero in all 1,736 (the dispatcher does not read them); animated groups (group 0 included) have ≥ 2 keys with strictly increasing ticks starting at 0, and each reaches the clip end (1,736/1,736), so sampling never runs past a tick array within a clip; the latest group tick equals the record duration (1,736/1,736); packed bits 30–31 are zero; no vertex index repeats. A scratch check (not in the checker) found static-group key 0 within one quantisation step of the paired base position for 89% of 6,945 vertices, so the static group is not simply a copy of the base mesh.
12-byte variant (flag 0x4000 set; 30 records, plane_anim etc.). Block {ptr, u32 count, ptr→count × 3 u32}; the first pointer is relocated but not swapped. Its consumer is not in the record sampler and was not found.
0x10000 block (record +44, one 20-byte header): {u32 n, ptr→n × (u16, u16), u32 m, ptr→u16[m], ptr→2m u32}. Consumer not traced.
MAP (TP2M terrain attributes)#
0x107f1c builds a chunk-file reader with file tag
TP2Mand registers aCMapChunkHandler(RTTI name at code 0x1ce3a5) for chunkMAP.Handler 0xd7e6c reads width (+0) and height (+4) of the chunk payload, then cells from +28. The five values at +8…+24 are stored to stack slots that are never read (raw +8 at −60; swapped +12…+24 at −64, −76, −88, −100): the Mac loader ignores them. All five PC fixtures hold
8,8,8,8,8.For file row
r(slow axis) and columnc:x = r − originX,y = c − originY(globals at data 0x54860 +1348/+1352); cells outside 0–127 are skipped; the byte is stored atcells[(y·128 + x)].+38(68-byte map cells). This confirms row → X, column → Y and adds the origin offset.+38of the map cell is the field the save writer serialises asmStatusFlags(0xd8144 passes cell +38), so the MAP attribute byte is the map cell's status flags.0x107f1c has one caller (0x4db74), with the path
"%s:Terrain:Base.map". No code path namesterrain.map: the jungleterrain.mapis not loaded by this build's terrain loader. (Absence is bounded to this single loader.)Bit 0x04: a bounded search for loads of
+38followed by a bit test found only a 0x08 test (bit tests at 0x74d0c/0x74df4). The 0x04 consumer remains unresolved.
TPWS/TPWI save payload#
Section framing is a trailing delimiter (correction)#
The save writer 0x11cb60 calls each subsystem writer and then writes its 4-byte tag (byte-swapped constant; e.g. WRLD is stored as DLRW), logging "<Name>: saved %d bytes". The bytes before a tag belong to that tag's subsystem. docs/TPWS-PAYLOAD.md currently reads each tag as the start of the following data; that attribution is shifted by one section.
| Delimiter (file bytes) | Writer | Block (Easymode bytes) | Notes |
|---|---|---|---|
| — | 0x10bc1c action recording | 8 + 1,171 | u32 mLoadedPublishedPark, u32 recording_size, recording |
DLRW | 0x105d3c World | rest of the 1,495,462-byte prefix | world vars, control manager, macro AI, map, things |
CSPS | 0xb7f54 Scripts | 5,452 | starts TPCS |
TRAP | 0x9c2c0 Particles | 76,252 | starts LCTP |
SSEM | 0x116a20 MessageCentre | 266 | |
KOLC | 0x10e944 Clock | 8 | two 4-byte timer fields (values consistent with milliseconds) |
TNAV | 0x127ac8 VanillaTime | 4 | raw LbTime_GetClock() at save time (the value previously called "pointer-like") |
SYSG | 0x1c2e00 GameSystem | 36 | 4-byte fields |
SYSR | 0x5ae70 RideSystem | 17,526 | the placed-object records attributed to "SYSG" today |
KART | 0x1a424 TrackRides | 44 | chunk headers {1,12,44}, {2,32,32}, then build __TIME__ + __DATE__\0 (PC file: 20:25:29Oct 21 1999; the Mac writer emits its own build stamp) |
RYLF | 0x674bc FlyingRides | 452 | starts FLY_ |
ESSR | 0xb3868 RSSE scripts | 10,856 | starts with its own RSSE |
EMAK | 0x2cb90 Camera | 40 | 3×4 + 12 + 12 + 4 |
SAOC | 0x394b8 Coasters | 16 | 4×4 |
SVDA | 0x78c8 (tag ADVS) | 372 | starts ADV_; log label reuses "Coasters" |
NUOS | 0xbbad0 Sound | 1,445 | cat_* paths |
STHC | 0x10e5a8 + 0x10e788 Cheat | 2 | |
CSDA | 0xcfd4 / 0xe834 AdvisorScoring | 4 | |
| (none) | 0x18f738 | 4 (zero) | final untagged block; log label reuses "UI" |
Payload offset 0 is the action record, so the "untagged prefix" is action recording + World, not a separate header. Model: split_sections.
Labelled schemas (debug labels passed to the save helpers)#
Helper widths (bytes written by each helper's LbFile_Write): 0xbefc 2, 0xc90c/0xc7f8/0xc6e4/0xcd1b0/0x10a4a4/0xcdf5c/0xd8ecc 4, 0xcabc4 1, 0xcde50/0xcdd44/0xce070 2, 0xcd704 12.
World vars (Easymode offset 1,179–1,243): version 4 (=2), mArrivalVehicle_Size1..3 2 each, mBankAccount 2, mCurrentArrivalVehicle 2, mGameTick 4 (=755), mMechanicHQ, mParkAnalyser 2, mParkClosed 4, mNumberOfVisitorsToDate 4, mParkGates, mTrafficLights 2, mRandomSeed 4, mResearchLab, mStaffHQ, mTagSystem, mUIMsgReceiver, mWeather 2 each, mWorldState 4, mFirstHandyman, mFirstMechanic, mFirstEntertainer, mFirstGuard, mFirstResearcher, mFirstObject 2 each. The 2-byte fields hold small distinct thing indices in the fixture (e.g. gates 11, lights 12). Then mControlManager, mMacroAI, mMap, Used Thing Head/Next and thingmodel blocks follow (not decoded here).
Cell grid (map writer 0xd6c90, 16,384 cells, X-fastest): per cell a status byte (bit 1 map cell, bit 2 track cell, bit 4 region-effect cell) followed by the flagged sub-records. Shared cell base (29 bytes): mDirection 1, mFlags 2, mMeshInstance 4, mNeighbours 1, mOverlapCounter 2, mParentID 2, mTileData 12, mType 4, mHoardingNeighbours 1. Map cell = base + mLitter 4, mLitterCollector 2, mLitterScript 4, mLitterScript 4, mPylonIndex 2, mStatusFlags 1, mTimeMarkedForLitterCollection 4, mWho 2 (52). Track cell = base + mSegmentNumber 2 (31). Region-effect cell = mpEffect[5], 5 × u16 (10). Hence 1 + 52 + 31 = 84 and +10 = 94 bytes — the two observed record sizes. This names the previously opaque offsets:
| Record offset | Field | Former observation |
|---|---|---|
| +0 | status (3 = map+track, 7 = +region effect) | "type byte" |
| +2 | map mFlags low byte | 0x40/0x00 regions |
| +8 | map mNeighbours | path connection bits |
| +11/+12 | map mParentID (u16) | "+12 ≠ 0 occupied" (49 nonzero cells) |
| +13, +17, +21 | map mTileData bytes 0, 4, 8 | path bit, PathTex index, orientation |
| +25 | map mType (u32) | 1 = path on exactly the 78 tile-bit-0 cells; 2 = water (240) |
| +46 | map mStatusFlags | MAP attribute byte |
| +56 | track mMeshInstance | "running index" |
| +77 | track mType | 12/25 fence-like values |
| +82 | track mSegmentNumber | FF FF |
| +84… | mpEffect[0..4] | the 11×11 camera patterns are mpEffect[3] |
corpus_check.py parses all 16,384 cells from 6,765 to 1,385,521 with this model (16,134 × 84 + 250 × 94). The meaning of individual status/flag bits and of the other subsystem blocks remains open.
MTR#
No Mac container references MTR: no .mtr/.MTR string and no AF 15 59 2E magic in either byte order in any code/data section of all 16 containers, and the Mac data volume has no .mtr file (it does ship bankrupt/congrats/paused.MD2). Static evidence that the Mac build never loads MTR; a PC runtime file-access trace would still be needed for the PC build.
BF4 fonts (ltms_shared)#
TbIRLE4bitFontconstructor (0x2f80) swaps the glyph record as u16 +0, u16 +2, u32 +4, u32 +8, u32 +12, u16 +16, u16 +18, leaves bytes +20/+21, swaps u16 +22. This confirms OpenTPW's widths (encoding is a u32 at +12; offsets are bytes; advance is 16-bit); +2 is an unused/unknown u16.TbOneColour4BitFontRenderMethod::DrawCharTo8888(0xb41c): with colour alpha 255, each channel becomesD + q,q = mulhwu(0x88888889, n·(C − D)) >> 3. ForC ≥ Dthis is exactlyfloor(n·(C − D)/15), i.e. the same weightn/15as OpenTPW'sn × 17 / 255. ForC < Dthe unsigned multiply makes the result one coverage step short (255 → 17, not 0, at full coverage). Other alpha values first scalenbytrunc(n·A/255)(0x80808081 division). Which render method/pixel format the game selects at run time was not traced, and the PC build's font code was not readable, so PC equivalence is unverified. Model:bf4_blend_channel.
TGQ/TQI movies#
The Mac build has no TQI decoder: it imports QuickTime (NewMovieFromFile, StartMovie, …), names Data:Movies:<name>.mov, and its data volume ships .mov files (plus bfj.mov, BFj2.mov). No pIQT/SCHl constant occurs in any container. The PC TP.ICD (baseline and Patch 2) keeps section names such as IDCT_DAT, TQIA_DAT and LBMPEG_D, but its .text and .data are high-entropy (7.99 and 7.34 bits/byte) and were not decoded. The residual IDCT rounding therefore cannot be resolved from either binary statically here.
Implemented in the parser (source/OpenTPW.Files/Formats/Model)#
Parser and sampling helpers; the runtime use is in the next section.
| Proof above | C# |
|---|---|
| quantised block, groups, key-major packed words | ModelVertexAnimation, ModelVertexGroup (ModelAnimationTrack.VertexAnimation) |
signed 10:10:10, fused q·scale + offset | ModelVertexAnimation.Unpack, Dequantise |
cursor search, cur·(1 − t) + next·t | ModelVertexGroup.AdvanceKey (kept cursor), FindKey (reset cursor), ApplyAnimatedGroups(time, positions, add) |
| group 0 padded lower/upper vectors | SampleBounds |
| static group (key 0) | ApplyStaticGroup(positions, add) |
| texture-frame tracks and their gate | ModelAnimation.TextureFrameTracks, TextureFramesEnabled, ModelTextureFrameTrack.FrameAt |
| 0x20000 toggle list | ModelAnimationTrack.NodeFlagToggles, SampleNodeFlag |
easing scale 8.999995, (1 − s)·lo + (s·hi) | ModelAnimationTrack.Ease, EaseScale |
| key search: before the first key → unchanged (null); last rotation/scale key holds | SampleTranslation/Rotation/Scale (the player substitutes the stored node component for null) |
scale (1 − t)·a + (t·b) | SampleScale |
| set-mode pose (static key 0, then animated groups) and its preconditions | ModelVertexAnimation.ApplyPose, GetPoseLimitation |
| header flag 0x4 | ModelFile.RelativeAnimationFlag |
Explicitly unsupported (not decoded, reported by ModelAnimationTrack.UnsupportedFlags, 1,122 corpus records): the 12-byte vertex layout (0x4000), the 0x10000 block, 0x2000 and the path parameters (0x200/0x400). HasUndecodedPayload keeps its earlier meaning ("more than rigid tracks"). Rejected as malformed: a missing bounds or static group, a group-0 vertex count below 2, an animated group with fewer than 2 keys or non-increasing ticks, a static group without keys, non-finite offset/scale, and pointers or counts outside the payload. Sampling a vertex group past its last tick, NaN times, and negative times for the TRS channels throw instead of guessing. The C# corpus test checks 1,736 decoded blocks, 1,735 paired (virtual pair, coverage, whole-clip sampling, 713,683 bracketed animated keys and none outside), 2,536 toggle lists, 1,278 clip gates and 459 texture-frame tracks; these agree with corpus_check.py.
Runtime integration (objects)#
ObjectAnimator keeps per instance one position array per mesh and fills it from the winning clip's vertex track (same most-recent-channel rule as the node matrices, an OpenTPW choice) with ApplyPose at the channel tick; without one the mesh shows its stored positions. Equivalence argument: when GetPoseLimitation is null the static and animated groups write every position of the mesh, so the array equals the original's after its set-mode passes since the bind. The kept cursor is replaced by a fresh search from key 0, which equals it on the r4 = 1 update path (see "Clip lifecycle"): the loop replay rebinds and resets it. The channel clock follows the trace at speed 1.0: per instance a clock in whole milliseconds (accumulated Advance time, floored), a start per channel, the single-precision frame, the last key at exactly the duration, and a looping replay strictly past the end from the capped carry truncated to whole milliseconds, once per Advance (one object update). A non-looping clip is marked finished only past its end; the hold itself stays RIDES-003. A test on the synthetic clip pins 999/1000/1000.5/1100 ms on a 30-tick clip (29.97, 30, 30, 3), one 2,500 ms update (30, then 3 after 100 ms), the 10-tick drift (0 at 334 ms, 9.99 at 667 ms) and the strict non-looping end; it fails against 6382736 (frame 0 at 1,000 ms). Not modelled: the object-list path (r4 = 0) that keeps cursors across a wrap and replays without a bind (unsupported; a separate profile would need the kept-cursor sampler AdvanceKey), object flag 0x8000, speeds other than 1.0, and per-object ownership of clip and header state. How the original's scene clock reaches whole milliseconds (0xa6f70 stores the integer result of 0x10e844) belongs to the clock lane. There is also no clock selector. Every animator accumulates its own Advance time, which matches clock A at rate 1 with no pause or hold. The advisor's clock B is not distinguished, and the instance TicksPerSecond is not clock A's rate (see "Clock selection", requirement 4). A model whose meshes share a node is rejected (a parsed model gives mesh i node i; a track drives one mesh record). When a mesh loses its track the animator shows the stored positions, except on fixed items (ObjectCatalogEntry.IsFixedItem, passed by OriginalObjectRuntime), which keep the last pose; this is the copy-back gate above with the option word at 0 and the creator flags of the catalog loader. In the catalog only the fantasy gates' three clips (gatese, gatesm, gatess) give a fixed item a vertex track (baseline and Patch 2); the corpus test checks that StopAll keeps their pose and restores every other object's stored mesh. Played: 599 of the 609 catalog clips that carry vertex tracks; the 10 others hold only the 12-byte layout (23 tracks) and are listed in VertexLimitations with the stored mesh shown. Also listed instead of guessed: relative-animation models, blocks that do not list every position once, and groups that end before the clip (none in the catalog).
ObjectRenderParts.WritePositions maps positions through the corner order into the part's own vertex array (engine axes; stored normals kept), and OriginalObject refreshes a fixed-size Dynamic vertex buffer (Model.UpdateVertices) through the frame command list only when the mesh's pose version changes. The parsed ModelFile is shared through the model cache and is never written. Tests: two Belly Bounce instances at ticks 30 and 105 hold different poses, each equal to a direct sample; the shared positions are unchanged; each Build gets its own arrays; stopping one instance restores its stored mesh only; a Metal readback of two dynamic buffers keeps each instance's upload over three frames with no buffer growth. Native jungle smoke (baseline and Patch 2 data) passes, 3,808 frames each; it does not assert vertex-animated pixels.
Not wired, because the runtime binding is not proven: group-0 bounds (no consumer of the mesh-record bounds traced), node-flag toggles (bit 0x10's consumer), texture-frame tracks (the header slot entries are identified, but the engine's frame-to-texture use and option bit 0x8 at run time are not), the 0x10000 block, and add mode (relative-animation models: per-update base restore through 0xa5894 without a new clip, add, then face normals by 0xa772c; traced but not implemented). Stored normals are kept after a vertex pass, which matches the 0xa7960 path for set-mode models; the 0xa78ec and renderer routes are open.
Code replacement handoffs (root to verify and integrate)#
MD2 animation runtime: vertex tracks are wired for objects (section above;
docs/MD2-MODELS.mdupdated). Still open: texture-frame tracks to texture slot frames, the 0x20000 bit, group-0 bounds, once their consumers are known. Keep 30 ticks/s but cite this proof. Gate PC claims behind a PC capture.Fidelity register / RIDES-001: tick rate is proven (Mac, speed 1.0); the loop policy is traced (replay past the end with a carried start, see "Clip lifecycle"); clock selection is traced (only the advisor uses clock B; see "Clock selection"). Clock A's rate is traced: 1.0 by default, and 0.25–2.0 in ×1.25 steps only through three key handlers. The hold is a 31 ms fixed step used while loading and during screenshot capture (see "Scene clock controls"). The physical keys, the dispatcher and the PC bindings remain open. This is not a basis for treating a per-animator ticks-per-second value as the original game speed. The stored-mesh rule after a vertex clip is now derived (fixed items keep the last pose; see "Gate inputs"), so the stored-mesh approximation entry proposed in 2760acb is withdrawn; it was never registered, and no register change is needed for it.
TPWS (
SavePayloadLayout,TPWS-PAYLOAD.md, importer naming): treat tags as trailing delimiters; rename sections by owner (RideSystem holds the placed objects); adopt the cell schema and world-var names; the importer's offsets (+8, +11/12, +13, +25, +46, +82) keep working but can use field names.MAP: document
OpaqueHeaderValuesas ignored by the original loader;terrain.mapunused by the Mac terrain loader.MTR: mark "not loaded by the Mac build".
BF4: optional exact-blend mode reproducing the
C < Dlag; current alpha mapping is weight-equivalent forC ≥ D.
Unresolved, with exact dependencies#
Consumers of the mesh-record bounds (+120/+132, written by group 0) and of node flag 0x00010000; where record +60 is bound to the header's records; the ride-data source of the 0x594c8 flag word that permits relative animation.
Degenerate inputs absent from the corpus and not modelled: a single-key rotation track (the wrapping search divides by zero, so the original produces NaN), times past a vertex group's last tick, and position-time entries whose upper u16 is nonzero (the search reads
lhzat +0 of each 4-byte entry; all upper halves are zero in the corpus).OpenTPW rejects animation members whose tables together read more than four times the payload (shared spans counted each time) and checks each span before allocating. The Mac loader has no such check; the limit is a resource bound for malformed or modded input, and no corpus member comes near it.
12-byte vertex variant (flag 0x4000), 0x10000 block and node-state bit 0x10: consumers not found; need a traced caller of these record fields. The node list (trailer +56) is read by 0xa65b8, which sets bit 0x10 in listed node records whose type word has bit 31 clear; what bit 0x10 controls is not traced.
Path parameter (0x200/0x400) and header 0xAC table: selection via node +82 and the third evaluator 0xa89f0 only partly read.
No-reset replay: which objects use the object-list update (r4 = 0) and carry flag 0x00400000 (the replay without a bind that keeps cursors).
Placement qualification: instances copy the catalog object and its channels (0x543cc) and placement only clears +4 bit 0x1. The geometry header, mesh records and face normals are per instance (0x53004 with 0x211f). Still open: later writers of instance +4, whether clip data and group cursors are per instance, the +0xd0 alternate template and state restored from a save. Bulk writes of the global block are also open (the option word has one direct store, 0).
Scene clocks: which physical keys (Mac or Win32 codes) and which dispatcher reach "game" key entries 6–8; the meaning of the rate-scaled per-pass counters at 0xbd298; the writers of game-state +0x3c, which gates pause and resume; the identity of the 16 unidentified pause, resume and toggle callers; and stores of channel bit 0x40 outside 0xa3000–0xa9000 through a passed channel pointer.
Face-normal recomputation: whether the 0xa6cc0 starts write a pose before placement's recompute; whether recomputed normals differ from the stored ones; setters of geometry-header bit 0x20000 (0x567e4) and of object-header bit 0x1 (which gates the 0x19b08c walk for instances); the callers 0x2a110 and 0x3bb4c.
MAP bit 0x04 and the remaining cell/status bits; World sub-blocks after the world vars; all other subsystem payloads.
PC equivalence of everything above: PC
TP.ICDcode is not readable statically; a PC runtime capture is required before PC-only replacements.TGQ IDCT rounding: needs readable PC TQI decoder code or player captures.
Source: docs/reverse/PPC-formats.md in the project repository.