TGQ movies: decoding evidence and playback#
October 9, 2026; video decoding updated October 16, 2026. Status: CPU container/audio/video decoding for the nine local Data/Movies/*.tgq files, plus streaming playback (--play-movie <name>) with audio, A/V sync and GPU presentation, and the start-up movie sequence (bf, then a trailer by day of the month) before the front end. Audio PCM matches an external FFmpeg 8.0.1 oracle bit-exactly (over the samples FFmpeg emits). Video is now tp.exe's own decoder: the dequantisation matrix, the transposed scan, the two transform passes and the colour tables of the PC movie player are reproduced, and the samples match the original routines run in the x86 oracle (see "The live PC decoder"). No in-game The triggers are proven on the PC executable tp.exe (see "Where the original plays movies", "The PC build"): two start-up movies, nothing else. How the PC player ends a movie, paces it and puts it on the screen is read there too; what it does with the 12.9 s of plan.tgq audio after the last frame is not. No dependency or movie data is added.
Code: source/OpenTPW.Files/Formats/Video/TgqMovieFile.cs, source/OpenTPW.Files/Formats/Video/TqiDecoder.cs, source/OpenTPW.Files/Formats/Video/TgqAudioReader.cs, source/OpenTPW.Files/Formats/Sound/EaXaAdpcmDecoder.cs, playback in source/OpenTPW/Client/Movie/; tests: source/OpenTPW.Tests/TgqMovieFileTests.cs, source/OpenTPW.Tests/MoviePlaybackTests.cs.
Container#
Little-endian EA chunks: ASCII FourCC, u32 size including the 8-byte preamble. All nine files parse exactly to EOF. Observed and enforced order: SCHl first (once), then interleaved pIQT video and SCDl audio, one 4-byte SCCl (audio block count, before the first SCDl, must equal the SCDl count), empty SCEl last with nothing after it. Any other FourCC (including the documented but unobserved SCLl) is rejected as unsupported.
| File | Bytes | pIQT | SCDl (=SCCl) | Audio samples/channel | Audio s | Video s @30 |
|---|---|---|---|---|---|---|
bf.tgq | 2,462,896 | 255 | 265 | 194,815 | 8.83 | 8.50 |
bub.tgq | 20,099,276 | 1,174 | 1,174 | 862,999 | 39.14 | 39.13 |
buc.tgq | 19,926,420 | 1,141 | 1,142 | 839,443 | 38.07 | 38.03 |
grav.tgq | 20,301,804 | 1,212 | 1,213 | 891,701 | 40.44 | 40.40 |
jug.tgq | 25,925,296 | 1,150 | 1,151 | 846,094 | 38.37 | 38.33 |
mir.tgq | 15,862,512 | 1,360 | 1,361 | 1,000,591 | 45.38 | 45.33 |
plan.tgq | 14,828,744 | 1,138 | 1,525 | 1,120,542 | 50.82 | 37.93 |
roc.tgq | 14,301,112 | 990 | 991 | 728,347 | 33.03 | 33.00 |
roll.tgq | 17,553,568 | 992 | 993 | 729,817 | 33.10 | 33.07 |
Totals: 9,412 video frames, 9,815 audio blocks. Every file has exactly one SCHl, SCCl and SCEl. plan.tgq audio continues ~12.9 s past its last video frame; playback behaviour after the last frame is unknown.
SCHl audio header#
Identical in all files except the sample count: PT, platform u16 0 (PC), then the patch substream (tag, length byte, big-endian value; 0xFC–0xFE carry no data, 0xFF ends; 0xFF length means a 4-byte BE length follows):
00:02 06:65 1B:1E FD 85:<samples> 82:02 83:07 8A:00000000 FF
0x1B= 30: frame rate per the SCxl page. The multimedia.cx TQI page says 15 fps; the corpus contradicts it (8 of 9 files: audio and 30 fps video durations agree within 0.34 s; FFprobe also reports 30 fps).0x82= 2 channels,0x83= 7 (EA-XA ADPCM),0x85= per-channel sample count. No0x84(rate) tag: the documented default 22,050 Hz applies; no0x80(revision) tag.0x00=2,0x06=0x65 have no verified meaning;0x8Ais documented as data-less but here carries a 4-byte zero value. Tags are retained raw.
Audio: EA-XA ADPCM, stereo#
Each SCDl payload: u32 sample frames, then per channel int16 current and int16 previous predictor state (left then right), then 30-byte frames: byte 0 = predictor indexes (left high nibble, right low), byte 1 = shifts (nibble + 8), 28 bytes each holding one left (high) and one right (low) 4-bit sample. sample = ((nibble << 28) >> shift + cur*c1 + prev*c2 + 0x80) >> 8, clamped, with (c1, c2) = (0,0) (240,0) (460,-208) (392,-220). The predictor state is reset by every block header. The final frame of the final block is partial (e.g. bf.tgq 775 = 27×28 + 19); after the encoded frames, 0 or 2 zero alignment bytes are observed. Stricter than observed, the decoder rejects predictor indexes > 3, nonzero padding or ≥ 4 slack bytes.
Verification: per file, the sum of block sample counts equals the header 0x85 value, and decoded PCM equals FFmpeg's adpcm_ea output on every sample FFmpeg emits. FFmpeg drops the partial last frame (3–25 samples per file and logs "invalid number of samples in packet"); OpenTPW keeps the header count.
Video: TQI#
pIQT payload: u16 width, u16 height, u8 quantizer, 3 unknown bytes. All 9,412 frames: 320×352, quantizer 99, unknown bytes 14 16 03 (the wiki says "always zero"; meaning unknown, retained as UnknownBytes). Every frame is intra-coded.
Bitstream (verified against the corpus and the oracle): MSB-first bits read from little-endian 32-bit words. Macroblocks in raster order, each Y0 Y1 Y2 Y3 Cb Cr with no macroblock header. Each block is an MPEG-1 intra block: dct_dc_size_luminance/chrominance VLC (ISO/IEC 11172-2 B.12/B.13, sizes 0–8), DC differential with per-component predictors starting at 0, then Table B.14 run/level codes + sign, MPEG-1 escape (6-bit run, 8-bit level, 0x00/0x80 extension), end-of-block 10, standard zigzag. The wiki claims a different run/level table; the standard MPEG-1 values are what match the oracle (PSNR ~55 dB versus ~21–40 dB for wrong scan variants during investigation).
Dequantisation (the reading before tp.exe's decoder was found; superseded by "The live PC decoder"): F[0] = dc × 8, F[i] = level × W[i] × (107.5 − q) × 0.625 / 8 with W the MPEG-1 default intra matrix (wiki "base_table2"); in integer form qscale = (215 − 2q) × 5 and F[i] = level × W[i] × qscale / 128. DC is in pixel units (no +128 offset). Every frame ends within its final 32-bit word with zero padding bits; the decoder requires that.
IDCT: integer variants measured against the oracle (history)#
This section records the search before tp.exe's live decoder was read; the decoder no longer uses any of these variants. FFmpeg approximates the transform with its own integer constants, so it was a closeness measure only.
Oracle: FFmpeg 8.0.1 tqi, -pix_fmt yuv420p, run locally only; no FFmpeg or other third-party decoder source was consulted or copied. Each candidate was implemented from the published algorithms and compared sample-by-sample (scratch harness outside the repository):
| Candidate | bf identical / PSNR | plan identical / PSNR |
|---|---|---|
| Orthonormal float IDCT, round half up (previous decoder) | 84.9 % / 56.16 dB | 82.3 % / 55.48 dB |
| IJG-style AAN IDCT (float, prescaled) | ≈ float | — |
| MPEG reference Chen–Wang 11-bit IDCT (4 dequant roundings) | 80.4–82.2 % / ≤55.6 dB (2 frames) | — |
| IJG-style integer AAN, best of ~4,000 precision/order/rounding variants | 94.6 % / 60.8 dB (1 frame) | — |
| Transposed AAN (adjoint of the AAN forward DCT), integer, selected | 94.6 % / 60.70 dB | 90.4 % / 58.22 dB |
Selected arithmetic (TqiDecoder.InverseTransform): AAN prescale folded into the dequantisation table, floor(round(2^17·s(u)·s(v)) × W × qscale / 2^18) (6 fraction bits; s(0) = 1/(2√2), s(k) = 1/(4 cos(kπ/16))); the transposed AAN flowgraph with 12-bit rotation constants (2896, 2217, 5352,
and floor products; columns first with a 1-bit floor shift, then rows; output
(x + 8) >> 5, clipped. Precision (6–9 bits tested), pass order, the mid shift and the quarter-LSB bias were chosen by search; constant precision (9–12 bits) barely matters. The quarter-LSB bias is unexplained: the oracle rounds slightly downward relative to round-half-up in every variant tried.
All 9,412 frames (this decoder vs the oracle), re-measured on the merged main for this revision. Identical samples count Y, Cb and Cr together. Per-frame PSNR uses all three planes with peak 255; the mean and worst are taken over the frames that differ (516 frames match exactly and are excluded from the PSNR columns). Max abs diff is over all samples:
| File | Identical samples | Mean PSNR | Worst frame | Max abs diff |
|---|---|---|---|---|
bf | 94.6 % | 60.93 dB | 57.98 dB | 4 |
bub | 88.2 % | 57.30 dB | 55.69 dB | 4 |
buc | 87.0 % | 56.92 dB | 54.53 dB | 4 |
grav | 87.2 % | 56.98 dB | 55.02 dB | 4 |
jug | 83.9 % | 56.06 dB | 54.53 dB | 4 |
mir | 90.9 % | 58.53 dB | 56.04 dB | 4 |
plan | 90.4 % | 58.17 dB | 56.49 dB | 4 |
roc | 90.0 % | 58.02 dB | 56.13 dB | 4 |
roll | 87.7 % | 57.17 dB | 54.70 dB | 4 |
The mean PSNR differs from the earlier table by up to 0.1 dB; the decoder is unchanged. (Previous float decoder over bf, bub, mir, plan, roll: 79–85 % identical, 54.6–56.2 dB, max difference 5.) Still not bit-exact. Evidence of the remaining gap: for blocks with one AC coefficient the oracle output is a deterministic function of the level, so the residual is IDCT rounding, not bitstream or dequantisation. Of the plan blocks holding one horizontal or vertical frequency-1 coefficient, 93,921 of 95,345 (20 of 29 distinct levels) reproduce exactly, and 6,332 of 6,334 frequency-2 blocks; the misses are ±1 in one or two columns. Frequency-1 patterns over all levels fit neither IJG-AAN nor transposed-AAN arithmetic with any tested precision, product rounding (floor, ceil, nearest, toward zero) or bias, so the original uses a different factorisation or rounding order. The synthetic test pins two of those oracle patterns.
Colour (history): before the original's tables were read, TqiFrame.ToRgb24() and the GPU path used full-range BT.601 with nearest-neighbour chroma; "The live PC decoder" below describes the conversion now used.
Original TQI decoder: static analysis of the PC executable#
(History: the cseg routines this section describes turned out to be unreachable; the movies use the .text decoder of "The live PC decoder" below.)
Static reads only (llvm-objdump, byte reads, no execution) of the decrypted Sim Theme Park World v2.0 no-CD tp.exe that COMPLETION-PLAN.md allows for analysis (3,734,528 bytes, SHA-256 5472f97b5eb28f58…, image base 0x400000). Its code and its initialised data are present. (An earlier review in this document read a damaged extraction, SHA-256 85eef533…, whose data sections were empty; its conclusions that the constants are zero or encrypted, and that 0x67832e is the movie IDCT, are withdrawn.)
The executable links EA's movie library: the chunk dispatcher at 0x66e5f0 handles MADe, TGVf, TGVk, TGQp, pIQT, UV2f and more (pIQT is frame type 4). Two separate 8×8 transforms exist:
0x67832e(data in sectionidct_dat, block decode0x677c00with an 8-bit DC and table0xfbd54cbuilt at0x676bc0) belongs to another EA codec, not TQI. It shares the flowgraph below but rounds with the1.5·2⁵²trick (0xfbc028= 6755399441055744.0).TQI has its own copy in section
csegwith data intqia_dat.
Verified TQI arithmetic:
| Step | Address | What it does |
|---|---|---|
| Block decode | 0x6f61e8 | VLC run/level decode (tables in tqia_dat, zigzag at 0xfbf0e4); every coefficient, the DC included (after prediction), is level × M[pos] with a plain 32-bit imul; M is 64 dwords at 0xfac690 |
| Pass 1 (rows) | 0x6f6510 | AAN butterfly, see below; if all seven AC inputs are zero, the DC is copied unchanged to all eight outputs; writes a 9-dword-stride temporary |
| Pass 2 (columns) | 0x6f6670 | the same butterfly without the zero shortcut; no shift between the passes |
| Driver | 0x6f6770 | per macroblock: decode, eight row passes, eight column passes into an integer macroblock buffer (0xfacab0, 256-byte rows) |
| Output | 0x6f6db4 | each sample is (v + 0x8000) >> 16 (round half up), used as an index into colour tables (0xfae930, 0xfaf930, 0xfb0930) that produce 16-bit RGB directly; the player never stores 8-bit YUV |
The butterfly (inputs x0…x7, all 32-bit integers):
even part:
t10 = x0 + x4,t11 = x0 − x4,t13 = x2 + x6,r = 2·hi32((x2 − x6) · 0x5A82799A)(Q31 √2/2,imul, high dword doubled),e = t13 + r; outputs combinet10 ± eandt11 ± r;odd part:
z13 = x3 + x5,z10 = x5 − x3,z11 = x1 + x7,z12 = x1 − x7,t7 = z11 + z13,t11o = 2·hi32((z11 − z13) · 0x5A82799A); in x87:z5 = (z10 + z12) · 0.3826834f,a = z10 · 0.5411961f + z5,b = z12 · 1.3065630f − z5(thefsubrpat0x6f6586encodes IntelFSUBP ST(2),ST(0):ST(2) − ST(0)), both converted withfistpin the current rounding mode; thenp = round(a) + t11o,q = t11o + round(b),w = round(b) + t7;outputs (index order of the row stores):
0: (t10+e)+w,7: (t10+e)−w,1: q+(t11+r),6: (t11+r)−q,2: (t11−r)+p,5: (t11−r)−p,3: (t10−e)+round(a),4: (t10−e)−round(a).
Constants (tqia_dat, identical in idct_dat): 0xfbf038 = 0x5A82799A, 0xfbf03c = 0.5411961, 0xfbf040 = 1.3065630, 0xfbf044 = 0.3826834.
Still open, so the decoder is not changed yet:
The TQI matrix builder: no instruction writes
0xfac690by absolute address, so the code that fillsMfrom the frame's quantiser was not found. The sibling codec's builder (0x676bc0) computesM[k] = round_half_up(S[k] · ((W[k] · q) << 12) / 2¹⁶)with the AAN prescaleS(×8192, at0xfbc24c), the MPEG-1 intra matrixW(.rdata0x706fb8) andM[0]fromW[0] = 8withoutq; whether TQI uses the same rule and scale is unverified.x87 precision control: the odd-part products are rounded according to the FPU's precision setting at movie time (Direct3D often selects 24-bit); which setting the movie player runs with is not established.
Colour tables: their builders are not read.
Measured against FFmpeg: FFmpeg's TQI path approximates this transform with integer constants, so a faithful port is expected to differ slightly from it; the FFmpeg table above is a closeness measure, not the bit-exactness gate.
Mac route: no TQI decoder in the Mac build (verified, negative)#
The Mac build was checked as the candidate source of the original TQI arithmetic, because its code is readable. It is not one. Static reads only: the player is 0x1009B1DC (552 bytes; its callers 0x101C0DF0 and 0x101C0F40 are confirmed by call references).
The player calls only QuickTime movie glue:
NewMovieFromFileandOpenMovieFile(glue at0x101C6534–0x101C6564),GetGWorldDevice,SetMovieGWorld,SetMovieBox,PrerollMovie,SetMovieVolume,MoviesTaskandStartMovie. Its whole movie import surface is theQuickTimeLibset (OpenMovieFile…IsMovieDone).Neither
SimThemePark.datanor the 15 shared libraries containTQI,pIQTor an EA codec string. The only IDCT in the libraries is IJGlibjpeg's, which is unrelated to movies.The Mac movies are not the
.tgqfiles. The HFS volumemac-feral/hfs.img(Theme Park Data/data/Movies) holds the nine.movfiles with the same names, plusbfj.movandBFj2.mov. Their QuickTimemoovatoms (raw inbf.movandbfj.mov, zlib-compressedcmovin the rest) declareSVQ1(Sorenson Video 1) video andima4audio. TheExtrastrailer isSVQ1withtwosaudio. Sorenson decoding is Apple's QuickTime component, which is not in the game data.So the Mac player decodes re-encoded Sorenson video through QuickTime, never an EA TQI bitstream. Nothing in the Mac build can supply the
.tgqIDCT, and no Mac arithmetic was ported. The decoder and the table above are unchanged.
The volume was read with a scratch HFS catalogue walker outside the repository (the image does not mount with hdiutil). Nothing from it is committed.
Pinned hashes (SHA-256)#
Files:
| File | SHA-256 |
|---|---|
bf.tgq | 174723130d5f3f03da58c26f6b162b886267f9ba694792df6bc534847704a32d |
bub.tgq | 338764e9d40e3e9b49cf8356ea62c4bea6e6701a79d74fcedd8fbb6f9683e5e1 |
buc.tgq | 50f751e8195dbe6784037a29776b46480b75ccae542bf1ee77373dd3bbff6a44 |
grav.tgq | fe6531e19fa0a9aea2c9ea88428898e11fba91034515818076e036061e85ebfd |
jug.tgq | acbde3241eb1268f525c4e50af2fcefbfef057cb0583e8831c2d63bafa2d4e69 |
mir.tgq | ffbceb6864ddda516922aceaf4ed2c55e463e663d49230ea03a2e14e4bea55a7 |
plan.tgq | 9ac41b21b05527b76be611bcb6951d05f461092a20906fa732701e864abd0ff1 |
roc.tgq | 0906c4862f9fb594b60b9c11afd7f657fc97de82d60ef3cc4d7cd210d404e72d |
roll.tgq | 2bb0194447ae9dce24d6e15c7d9c53177fff1356e85bb6d8902dc68a69cb3fe0 |
Decoded PCM (interleaved s16le) — bf 9f7b0e0d…647c8, bub bd5cf5a5…3255f, plan 91839600…fadcf; all nine are pinned in full in the tests.
Decoded planes (Y‖Cb‖Cr, the original decoder's 7-bit samples; not FFmpeg's bytes):
| Frame | SHA-256 |
|---|---|
bf.tgq #0 | ad49f57f0436b8e67345865bba896140cebbfd7494a31c93e3396b7a63600d8f |
bf.tgq #127 | 81fd09cd01a2d442c68dbf4367abceb9ee7c49550ff6720c57565cf988d72904 |
bub.tgq #0 (identical first frame in the other 7 non-bf files) | 2dafcbc172a0d393b69d27ab1016be34a775ae8171bc0b475342250662bd9223 |
bub.tgq #587 | 0b57596136931bd07ef0c5841cf5e510773fc33cf5411292eec715756775abc2 |
plan.tgq #569 | 58ca5c38fd4cca74a124eb0c51a0ac6b26189898e5bf3d2871439fc45b4b4836 |
Limits and strictness#
Input ≤ 64 MiB, chunk ≤ 1 MiB, ≤ 65,536 chunks, ≤ 16 Mi samples/channel, frame dimensions multiples of 16 up to 1024, quantizer ≤ 107. Bitstream words must be whole; invalid VLCs, DC sizes > 8, more than 63 AC positions, forbidden escape levels, truncated bitstreams, whole unused trailing words and nonzero padding bits are rejected. Only PC/stereo/EA-XA (no revision tag or revision 1) audio decodes; other variants throw NotSupportedException. Caller streams stay open; nonseekable short reads are supported. Asset tests are inconclusive (not passing) without OPENTPW_GAME_PATH; the all-frames test takes ~1 min in Debug.
Container robustness audit (2026-10-13)#
PT numeric tags exposed as signed int metadata reject values greater than int.MaxValue instead of wrapping negative (frame rate, compression/revision, channels and sample rate). This is OpenTPW's typed representation policy, not a new inferred codec limit; representable unknown metadata remains available to callers, whose supported-variant checks still apply. The sample count stays a long with its existing supported bound. No transform or quantizer math changed.
TgqAudioReader advances its block ordinal only after a successful decode. A malformed block with a valid encoded length therefore remains the failing block on retry rather than being silently skipped. Reads that throw restore the complete entry cursor (block ordinal, cached frame count, cached position and buffer), so Position still names the samples returned by earlier successful reads. A caller buffer may already contain a copied prefix and must be discarded; retrying copies that same prefix again before reaching the malformed block. If a failed decode overwrote the cached PCM, the reader reconstructs its already validated block from the immutable movie data. EA-XA current/previous predictor arrays are local to each block decode and seeded from that block's header; no filter state persists between calls and no codec transform changes are required.
Synthetic regressions failed on the unsigned-tag wraparound and failed-decode retry paths before the fixes. Tests preserve the largest representable metadata, reject every truncated prefix of a valid miniature container, and decode its valid patch/audio/bitstream padding. The audit also checked that chunk sizes and file offsets are bounded before slicing, PT extended lengths are bounded before copying, audio sums use long, and frame dimensions bound plane allocation. Existing file/chunk/count/dimension limits remain unchanged.
Independent review target 9e56fba340a54896a26caad70f6dcab0c7d09956 against 72a1febf: ACCEPT after retry rollback correction. A new red regression showed that the original block-index fix alone lost the valid prefix of a failed read while leaving public Position unchanged. Added cases exercise retry from both an empty cache and a partially consumed cache, including a later-frame predictor failure that overwrites the reused PCM buffer before throwing. Independent parser checks cover 1–4-byte big-endian numeric values, big-endian extended lengths, little-endian platform values, opaque unknown tags (including embedded terminator bytes), no-data tags, duplicates, malformed lengths, and nonzero post-terminator padding. Typed representability checks preserve int.MaxValue and refuse unsigned values from 0x80000000; no new arbitrary format cap is imposed.
Fresh independent verification: 71 synthetic container/decoder/playback/intro cases pass, including fourteen container robustness cases; nineteen original-data rows skip with the corpus environment unset. Build/typecheck, changed-file style and whitespace checks, CRLF-aware diff check, fidelity register check and its eleven Python tests pass. No original asset reads were attempted. Original corpus compatibility and original-player malformed-input behavior were not requalified because USBSSD reads are blocked. Existing codec-fidelity gates above remain open.
Playback#
bash scripts/run.sh --game-path <install> --play-movie bf plays Data/Movies/bf.tgq (name or name.tgq, case-insensitive, no paths) in the game window and exits when it ends; any new key press or mouse click skips. --mute plays without audio; --headless runs the decode-and-clock simulation with a simulated real-time audio device at 60 updates/s and prints statistics and a hash of the presented planes (no window, GPU or audio device); --smoke-test is the native GPU check below.
Streaming / memory: the compressed file stays in memory (≤ 64 MiB limit; largest movie 25 MiB); video frames are decoded on demand, one at a time; audio is decoded one SCDl block at a time (
TgqAudioReader) and kept at most 0.25 s + 1,024 frames ahead of the device.Audio: SDL2's push queue (
SDL_QueueAudio) through the SDL2 library Veldrid already loads (Sdl2Native.LoadFunction), s16 stereo at the movie rate, SDL converting to the device format. The game had no audio backend before this (NAudio is only used by the Windows-only ModKit MP2 preview). If SDL audio cannot open, playback logs a warning and runs without audio.Clock: with audio, movie time is the device's played position minus its buffer latency; because the position moves a device buffer (~46 ms) at a time, elapsed time fills in between steps, capped at one buffer and never running backwards. Without audio (or after a shorter soundtrack drains) the existing 60 Hz
FixedStepClockadvances it, so hitches longer than 16 ticks lose time instead of jumping ahead.Frame policy: the frame due at
floor(time × 30)is decoded; frames passed in between are dropped without decoding (every TQI frame is intra-coded); otherwise the current frame is held. Playback ends at the later of the last video frame and the end of the audio, holding the last frame:plan.tgqshows its final frame for ~12.9 s while its audio finishes. The original player's behaviour here is unknown.Presentation: the original player's colour tables (
TqiColour) at full 8-bit colour ([EXT:movie-full-color]; the original's 16-bit packing is documented below and kept as a tested helper) on the CPU to RGBA, uploaded to a 320×352 texture and drawn with the existing fullscreen-triangle blit shader into a centred viewport at the original's display aspect 640:352 (the 320×352 frames are shown at twice their width, as the original's movie box does; see below), letter/pillarboxed in other windows.
Measured: headless bf and plan at 60 Hz with audio decode every frame (255, 1,138) with no drops and end within one update after the audio; at 12 Hz bf drops > 100 frames but keeps audio time. A real run of bf with SDL audio (macOS, Metal) showed all 255 frames with 0 drops and ended at 8.84 s (audio 8.83 s); before smoothing the stepped audio position it dropped 71.
Native check: --play-movie bf --smoke-test (audio off for determinism) plays to frame 60, reads the resolved framebuffer back at frames ≥ 15 and ≥ 60 and requires the mean RGB inside the movie rectangle to match the CPU-converted frame within 6/255 per channel, black bars outside it and a changed picture between the two reads; it saves artifacts/native-movie-bf-*.png.
Where the original plays movies#
Source: static analysis of the Mac PowerPC build (SimThemePark, QuickTime .mov files; Ghidra, never executed) for the first part, and of the PC executable tp.exe for "The PC build" below, which confirms every trigger on the .tgq side. Addresses are function entry points of the main code fragment; nothing here is decompiled text.
Mechanism (proven)#
One movie player routine at
0x1009B1DC(name, target surface, x/y): it resolves the file, opens it with QuickTime, binds it to the game surface, sets the movie box, prerolls, sets the movie volume, runs a fewMoviesTasksteps and starts it. Companions:0x1009B404(task + is-done),0x1009B45C(stop and dispose),0x1009B4D8(EnterMovies, called once from the start-up routine0x101C0B28),0x1009B4FC(shutdown).This player has exactly two callers in the whole fragment (no data references to it):
0x101C0DF0(the logo) and0x101C0F40(the trailer). Both are called from one place each, the start-up states of the main state machine0x101C1208. No other code (theme entry, golden tickets, rides, advisor) starts a movie. Indirect calls cannot be excluded statically, but no movie string or QuickTime import is referenced outside this player.Both callers first look the file up (
0x100036B0); a missing movie is skipped silently and the state still advances.
Start-up sequence (proven)#
Main state machine (0x101C1208, 16-entry jump table): start-up routine 0x101C0B28 sets state 4 when the start-up flag (bit 0x200 of the global flag word) is set, else state 9. State 4 continues to 5, which is the logo.
| State | Does |
|---|---|
| 5 | if a skip input is down: go to 7; else play Data:Movies:bf.mov and go to 6 |
| 6 | pump the movie; when done or a skip input is down: stop it, go to 7 |
| 7 | if a skip input is down: go to 1 (front-end loading); else play the day trailer, go to 8 |
| 8 | pump; when done or skip: stop it, go to 1 |
| 1 | splash plus normal loading (game data, lobby), then on to the lobby |
| 9 | the same loading without movies (flag clear), ending in the running state |
Logo:
bfat every start-up (0x101C0DF0).Trailer (
0x101C0F40):localtime()day of the month, modulo 8, indexes the eight other movies in the alphabetical order of the path table (pool entries+0x57…+0xE5of the data block behind TOC slot-0x3880):
| day % 8 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|---|---|---|---|---|---|---|---|---|
| movie | bub | buc | grav | jug | mir | plan | roc | roll |
The choice is deterministic by date (days 8, 16, 24 play bub; days 7, 15, 23, 31 roll), not random. All nine names are the Data:Movies:<name>.mov strings; bf sits at pool offset +0x44.
Skip (proven): the skip inputs are Esc, Space (virtual-key style codes
0x1B,0x20) and the mouse button (global at0x101EDD34, polled through0x10171DA0), sampled by level, not by edge, both before a movie starts and while it plays. A button still held when the next movie is due therefore skips that movie too: a normal click usually ends the whole intro.Every start: no first-run or "seen" flag is read on this path. Whether it plays is the start-up flag, set by default in the defaults routine
0x1004CAD0(called from0x1004CE40just before the start-up routine) and changeable by the graphics settings block field+0x2C(0x1004C2BC, values 0 clear, 1 set) or the developer file named "debug options" (0x1004BFE4, resource byte 3). Inferred: the settings field behind+0x2Cis not identified, so whether the player can switch the intro off in a menu is unknown; the shipped default plays it.Movie volume (proven on the PC build): the sound-options apply routine (tp.exe
0x423dd0) passes the movie setter0x51b3c0percent × 1023 / 100 (C division; 0 while Movie sound is off), which keeps the low ten bits in0x802ba8. Opening a movie (0x51b010) and the setter's re-apply (0x51b2bc) call the library's volume call0x66f520withv × 10000 / 1023 − 10000, which forwards to the movie's DirectSound bufferSetVolume(vtable+0x3C): attenuation in hundredths of a decibel, so 100 % is unattenuated, 75 % is about −25 dB, 50 % about −50 dB and 0 % or off is DirectSound's silence (−10000). OpenTPW applies exactly this curve (MovieVolumeCurve) to the PCM; the earlier linear mapping came from the Mac build's QuickTime volume (a linear 0…256), which the PC player does not use. (The Mac routine0x10126460, kept for reference, set that linear volume.)Picture box (proven): the movie is placed at y = screen height × 64/480 and sized to the screen width by screen height × 352/480, i.e. 640×352 in a 640×480 screen, with black above and below. The
.tgqframes are 320×352, so the original shows them horizontally doubled (non-square pixels); OpenTPW does the same inside a letterboxed window. (The original stretches to the window width because it only ran fixed 4:3 modes; OpenTPW runs any window size and keeps the 640:352 aspect,[EXT:movie-letterbox], a design decision.)Corroboration from
sound.sam(DefaultVolume.MOVIE 100) and the options string "Movie volume:" in the data directory.
The PC build (tp.exe, October 17, 2026)#
Static reads of the decrypted tp.exe (REA and byte reads, nothing executed); every address below is a tp.exe address.
Only two triggers. The nine
Data\Movies\<name>.tgqpath strings (0x764FF4bf, thenroll,roc,plan,mir,jug,grav,buc,bubdown to0x7650A0) are referenced only by two routines:0x54DF20(the logo,bf) and0x54E070(the trailer). Both start the movie through the single movie start0x51B010(its only callers), which calls the library's open0x66F4E0(also its only caller).0x54DF20and0x54E070are each called once, from the main state machine0x54E360at0x54E478(state 5) and0x54E514(state 7). No theme intro, ending, award or golden-ticket movie exists in the PC build; the original has these nine movies and these two triggers. The string "MOVIE" (0x746E20) and the directory names are unrelated (theMoviesstring at0x747AECis a data-directory component).Trailer choice.
0x54E070callstime(0x67D3F0) andlocaltime(0x67D8E0), takestm_mday(+0xC), makes it non-negative, keeps& 7and indexes the jump table at0x54E288: 0bub, 1buc, 2grav, 3jug, 4mir, 5plan, 6roc, 7roll. This is the Mac table (above) exactly;IntroPlaylistmatches it.State machine.
0x54E360dispatches on[0x87906C]through the 16-entry table0x5503A4; state 4 goes to 5. State 5 returns without doing anything while Esc (0x1B), Space (0x20) or the mouse-button bit mask at0xFAA5BC(set by the UI library's button-down handler, cleared by its button-up one) reads down (GetAsyncKeyStatefor the two keys, so a tap since the previous call counts too,test ax, ax), otherwise starts the logo and goes to 6. State 6 pumps0x51B300; when it reports done, state 7, and when a skip input is down it stops the movie (0x51B350) and goes to 7. State 7 is state 5 for the trailer (to 8); state 8 is state 6 (to state 1, the front-end loading). So a skip input held at a state-5 or state-7 moment waits for its release, and a press while a movie plays ends only that movie: the trailer needs a second press. The Mac reading above (a held input goes straight to the next state) does not hold on the PC; this is whatIntroSkipGatehas implemented since UI-035.Start-up flag. The init routine
0x54DCF0ends by writing the state:[0x7A1A8C] & 0x200set gives 4 (movies), clear gives 9 (loading without movies). The flag word is initialised to0xC0E15at0x449E1C, which has0x200set, so the movies play by default. Only the presence of a configuration file nameddialog.tcf(0x74CE84, read through0x424A60) can replace the whole word (copied from0x78D950), and nothing writes the bit afterwards: there is no menu setting for the intro on the PC. The file's layout (0x424560) is not read, so what it can switch is unknown; the file is not in the game's data, it belongs to the launcher.Picture box.
0x54DFB5…0x54E03E(logo) and0x54E1DE…0x54E25D(trailer) pass y = screen height × 64 / 480 and, in a window, offset the box by the client area's screen origin (ScreenToClientthrough0x6FD318on (0, 0) for the window handle0x7A130C, negated: the movie is placed in screen coordinates); the movie start sizes the picture to the screen width (0x7A1968) by height ×0x160/0x1E0(0x51B0ED,0x51B0FC). The screen sizes are the modes of0x449F38(160×120, 320×240, 400×300, 512×384, 800×600, 1024×768, 1280×1024, 1600×1200). On every 4:3 mode this is the 640:352 aspect OpenTPW letterboxes to (MoviePresenter.OriginalBox, tested); at 1280×1024 the original stretches to 1280×750.Pacing and sound. The player runs its own thread (
0x66F090, priority 15 clock thread0x6724A0). With audio the clock is the movie's DirectSound buffer play cursor (GetCurrentPosition,0x672730), without it a synthetic clock; the video rings 24 frame slots (0x1E8, 16 bytes each). A movie that is playing is polled by0x51B300with a 10 msSleepper call. The volume is a DirectSound attenuation (see "Movie volume" above andMovieVolumeCurve).End of a movie.
0x51B300reports done when the library's playing test0x66F540is false. With sound (the open0x66F4E0always sets the sound flag at +0x3E0) a movie is playing until its status word (+0x9C) is 7, which the player thread sets in0x66EEF0after it left its decode loop and stopped the clock thread (0x672800). The natural end does not call the explicit stop0x51B350. Whether the decode loop ends at the last video frame or only after the file's last audio chunk, and so whether the 12.9 s audio tail ofplan.tgqplays out or is cut when the player releases its sound buffer, is not established (the loop that reads chunks was not followed to its exit). OpenTPW plays the tail out.
Not in the data directory#
No data file names a trigger (the 18,734 files, WAD and SDT archives, and all English .str tables were searched), which is why the executable was needed.
Wired in OpenTPW#
The PC build has these two triggers and no others (above), so everything the original starts a movie for is wired. IntroPlaylist / IntroSequence: every normal start plays bf, then the day trailer, then opens the front end. Esc, Space or a mouse button (left, right or middle) skips. Before each movie the PC waits until all of those are released (0x54e360 states 5-8), so input held at launch or after skipping the logo delays the next movie rather than skipping it, and an input held during a movie stops it. The order and the trailer table were confirmed in the Windows tp.exe (UI-035 is retired). A missing or unreadable movie is skipped. --no-intro or OPENTPW_NO_INTRO=1 goes straight to the front end; smoke tests never play it; --mute silences it.
Selected CPU frame export#
--export-tgq-png <local.tgq> <0-based video-frame index> <new.png> exports one video frame through TgqMovieFile.DecodeVideoFrame, TqiFrame.WriteRgba32 and the existing PNG encoder. It runs before game/profile/window initialization and requires no installed game. All container and frame-header checks remain; only the selected video payload is decoded, and audio is not decoded. A malformed unselected video body can therefore remain unexamined when its header is valid.
The PNG has the encoded width and height, with opaque alpha and the current colour conversion. It does not reproduce movie display stretching or establish native IDCT/colour parity. Decode and PNG encoding finish before output creation; a privately owned CreateNew temporary file is flushed, moved without overwrite, and cleaned on failure. Existing output and foreign temporary files are preserved.
Independent CPU controls additionally distinguish video ordinals from three interleaved undecodable audio chunks, reject every truncated container prefix and invalid unselected chunk sizes/trailing bytes, and verify actual early CLI export preserves renderer/asset identity without profile creation. A Darwin-only CLI FIFO handshake also creates a foreign destination after the initial precheck and before valid input is delivered: the non-overwriting move refuses, foreign bytes remain unchanged and the owned temporary is removed. This qualifies that controlled host race, not cross-platform crash durability or original movie behavior.
TgqPngExportTests checks first/last and distinct frames, square/non-square raster readback against current codec pixels, invalid indices and selected payloads, strict unselected-header refusal, undecoded audio/unselected bodies, source-byte identity, output refusal/late-move cleanup and the real early Game.Run route. These are synthetic CPU tests; original movies and GPU/native-player parity were not exercised for this export slice.
The live PC decoder (tp.exe, October 16, 2026)#
A new static pass over the decrypted tp.exe found that the cseg routines described above (0x6F61E8…0x6F6770, matrix at 0xFAC690) are never called: no call, jump or pointer reaches them. The movies go through .text: dispatcher 0x66E5F0 (pIQT and UV2f are frame type 4), header 0x670900 (quantiser = header byte 4; byte 7 bits 0 and 1 are flags, the second choosing the pixel writer), frame decode 0x670C20, matrix builder 0x6710C0, block decoder 0x6747D0, transform passes 0x67673C/0x676965, colour tables 0x670350. TqiDecoder and TqiColour now reproduce them:
Matrix (
TqiDecoder.BuildMatrix, one for luma and chroma): for q ≠ 100,M[k] = (S[k] · trunc(W[k] · (float)((107 − q) · 0.0625) · 65536) + 0x8000) >> 16with the Q13 AAN prescalesSat 0x705C88 and the MPEG-1 intra matrixWat 0x705D88 (_ftol0x67A830 truncates); q = 100 givesM = 8 · S;M[0] = 2^16always.Block decoder (0x6747D0): the DC is the predictor times
M[0]; each AC level is stored at the transposed scan positionT[s](the table 0xFBB5B0, read from its end) and multiplied byM[T[s]], plain 32-bit products. The weights are not transposed with the scan, so 21 asymmetric weights apply to the transposed frequency.Transform: the first pass (0x67673C) runs the AAN butterfly along each stored row, copies the first input to all eight outputs when the other seven are zero, and writes its outputs down a column of a 9-wide buffer; the second (0x676965) runs the same butterfly along those columns and shifts each output right by 17, without a bias. The two transposes cancel the transposed scan, so the samples come out in natural order. The butterfly's √2/2 rotations are the doubled high dwords of
x · 0x5A82799A; its odd part is computed in the FPU,a = z10 · 0.5411961 + z5,b = z12 · 1.306563 − z5,z5 = (z10 + z12) · 0.3826834(single-precision constants), each rounded half to even by adding 1.5 · 2^52 and taking the low dword of the stored double.Samples are 7-bit (0–127, chroma zero at 64).
TqiFrame.Y/Cb/Crhold them clamped to 0–127, which is what the colour tables do for every value the decoder produces (341 of all samples fall below 0 and 2 above 127 over the nine movies; the tables cover −192…319).Colour (
TqiColour, 0x670350 with the row writer 0x675D90 that every shipped frame uses: header byte 7 is 3): a pixel's luma termclamp(y − 64) · 0x800801 + 0x4883D8A9, its Cb termtrunc(0.5 − x · 0.3441)(green, bit 11) andtrunc(0.5 + x · 1.772)(blue, bit 0), and its Cr termtrunc(0.5 − x · 0.7141)(green) andtrunc(0.5 + x · 1.402)(red, bit 23), withx = c − 64 + 0.5, add into three 9-bit fields; each fieldngives the channel valueclamp(brightness · (2n − base) / 100, 0, 255)with bases 177 (red), 133 (green) and 225 (blue). The brightness is the library's default 100 (the open writes it at 0x6701A2 unless its flags carry 0x100000). Neutral grey 64 becomes (115, 113, 115) and the brightest neutral (241, 239, 241): the original never shows full white. No field leaves its table over the 1,060,167,680 pixels of the nine movies. A field that wraps below zero (a dark pixel with extreme chroma, such as Y 0 with Cr 0) would read the next table in the original, landing in another channel's bits of the display format; OpenTPW draws that channel as 0. The values are the colour before the player packs it into the display surface. Packing (read October 17, 2026): three more tables (red0xFBA730, green0xFBABF8, blue0xFBB010, built by0x670350from the surface's channel bit counts and shifts, with the same brightness) turn each channel valuevinto a 16-bit field. The low half of an entry is the rounded field,min((v + 2^(7−b)) >> (8−b), 2^b − 1); when the surface has at most 16 bits per pixel the high half is the truncated fieldv >> (8−b). The row writer0x675D90handles two pixels per 32-bit word and takes the low half for the first (even column) and the high half for the second (odd column), so even columns round and odd columns truncate. OpenTPW reproduces this for a 5-6-5 display (TqiColour.Pack,TqiFrame.WriteDisplayRgba32, fields expanded back to 8 bits by bit replication) as a tested helper, but presents movies at full colour by default ([EXT:movie-full-color], user-approved 2026-10-17: the original packs to its 16-bit surface, which bands the gradients and does not suit upscaled movies;MoviePresenter.DisplayFormatis null unless set). Display depth (read): the window setup0x44E080passes16 + 16 × (start-up flag 0x200000)as the DirectDraw display depth (0x44DF20toSetDisplayModein0x563460), and the option routine0x44D8F0sets that flag fromRENDER32(0x7858A8, betweenMIPMAPandTEXTURE32in the key table at0x7445F0), so the Low, Medium and High presets (RENDER32 0) run 16 bits and only an edited file or the Enhanced preset (1) a 32-bit display. The colour mode0x670C20picks the 16-bit writers (0x671800,0x671940, row writers0x67519D/0x675579) for a surface of at most 16 bits and the 32-bit writers (0x6718A0, rows0x67538B/0x675767, one pixel per word) otherwise; with 8-bit fields the same tables hold the value unchanged, so a 32-bit display shows no banding (MoviePresenter.OriginalDisplayFormat: packed forRENDER320, unpacked for 1). A windowed start-up (flag bit 0) takes the desktop format instead, which is not modelled. Replacement movies: the only mechanism is a.tgqof the same name in a Movies folder of the--cd-dataoverlay (MovieLibrary, searched after the install's own folder, so it only fills a missing movie); there is no loader for other formats or for the texture pack's recorded movies (a separate manual download). The presenter sizes its texture from the file and fits it into the original box and the[EXT:movie-letterbox]letterbox, so a higher-resolution.tgqis shown at its own resolution. The 5-6-5 layout is an assumption (the masks come from the DirectDraw surface; every common 16-bit display is 5-6-5); the export tools (--export-tgq-png) keep the unpacked 8-bit values.
Verification. The x86 oracle (docs/reverse/ORACLE.md, X26) runs the matrix builder for every quantiser and the first transform pass on 500 coefficient rows, both against Python readings of the C# rules: the matrix agrees for every quantiser and the pass on every row; rows whose odd-part products end within 0.1 of a half are left out, because the emulator's x87 does not round those as hardware does, so the half-way rounding itself rests on the IEEE semantics of the fadd/fstp pair, not on the oracle. Whole frames were compared too, outside the test suite: the original block decoder and writer (0x67519D with 0x6747D0) run per macroblock in the oracle's sandbox over 51 frames sampled from all nine movies (every 97th frame) matched TqiDecoder in every one of 8.6 million samples but one. That one is a half-way odd-part rounding: Unicorn's x87 rounds values whose fraction lies between about 0.45 and 0.5 away from zero in about one case of twenty, which no IEEE precision does; real hardware at 53-bit or 64-bit precision gives the C# value there. The decoder follows 53-bit precision (the MSVC default); at 64-bit precision a double rounding of a + 1.5 · 2^52 would differ in rare ties (30 of the odd-part roundings in six sampled roll frames), so the FPU precision the game runs movies at stays an assumption.
Remaining gates#
The x87 precision control the game runs movies with (53-bit assumed, see above), the display's channel layout for the original packing (read; 5-6-5 is assumed, the masks come from the DirectDraw surface; OpenTPW presents full colour either way), the 0x100000 open flag that would replace the default brightness, what the original does with the audio of plan.tgq after its last frame (see "End of a movie"), the layout of dialog.tcf and what it can switch, and the window-mode origin correction of the picture box (a window is not an original mode). None of these are verified.
Sources#
OpenTPW docs
c077cc9a12aaaac93caac52673ab3080f631fbd9,src/formats/tqi.md.multimedia.cx wiki: Electronic Arts TQI (rev 15985), Electronic Arts TGQ (rev 15826), Electronic Arts SCxl (rev 15794).
ISO/IEC 11172-2 (MPEG-1 video) VLC tables B.12–B.14 and default intra matrix.
FFmpeg 8.0.1
ffprobe/ffmpegbinaries used only as an external oracle for counts, PCM and plane comparison; no FFmpeg source consulted or copied, no original game binary executed.
Source: docs/TGQ-MOVIES.md in the project repository.