upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/docs/coder.md
diff options
context:
space:
mode:
authorToeesh Chaudhary <300860448+toeeshchaudhary@users.noreply.github.com>2026-11-22 13:17:34 +0530
committerToeesh Chaudhary <300860448+toeeshchaudhary@users.noreply.github.com>2026-11-22 13:17:34 +0530
commit2e39817ea2ce94aa81d420121a44db3862025692 (patch)
tree28393b028a3189487c78e46b5e1b035557e2c6ea /docs/coder.md
parent43d470316ec6cbcd64002bc3792998d9f5745dac (diff)
docs: measure the story-archive compressor and the mission state tables
Two new format pages, both measured over the user's own copy with no payload stored. docs/coder.md - the 51.5 MB compressed mass in story000_script.rpf. Two interleaved populations (105 zlib blocks, 767 unidentified). Entry framing is u16 tag + 6 header bytes, zero pad, payload at align16(entry+8) - confirmed 10/10 on pad length and %16 alignment, which is why earlier scans that assumed the entry start found nothing. A 32-value tag alphabet that correlates with nothing. The payload is deflate-shaped but proprietary (popcount correlation +0.632 against zlib-9's +0.676, plane bias +0.0083 vs +0.0138; lzma -0.065 and bz2 -0.432 are excluded, and AES is excluded by the ~40 sigma plane bias). Codes are variable-length and LSB-first: 7 and 8 bit lengths measured from the bit spacing of single-symbol runs. No table is stored, so the symbol->length array is static in the executable; the Kraft constraint narrows it to a 129-140 byte vector of 7s and 8s, most likely n7=116 + n8=24. docs/mission_logic.md - the mission containers are state machines, not instruction streams: 32-byte records keyed by joaat, 40,804 of them across 2,309 containers. Records the details that cost a false start (the band field is a counter, not zero; offsets are file-absolute for most records), the 64-byte pool element carrying world transforms, the case-folding behaviour of joaat (340/340 folding vs 91/340 case-sensitive, so lookups must fold), and the flow shapes. 113 identical-state-set clusters cover 82.4% of the files, so naming one cluster names dozens of files. docs/README.md gets both rows.
Diffstat (limited to 'docs/coder.md')
-rw-r--r--docs/coder.md110
1 files changed, 110 insertions, 0 deletions
diff --git a/docs/coder.md b/docs/coder.md
new file mode 100644
index 000000000..cd20845aa
--- /dev/null
+++ b/docs/coder.md
@@ -0,0 +1,110 @@
1# The compressed mass in the story script archives
2
3`story000_script.rpf` and `script.rpf` hold data in a framing the rest of the package does not use.
4Most of it is ordinary zlib, but a large part of `story000_script.rpf` is compressed by an encoder that
5no standard decoder reproduces. This page records what was measured about it, so the next attempt starts
6from the numbers instead of from a guess. Everything below is counts, offsets, constants and
7statistics over the user's own copy — no payload is stored here.
8
9Subject: `story000_script.rpf`, region `0x2000..0x3127000` (51,531,776 bytes), 905 page-blocks.
10
11## Two populations
12
13| population | blocks | bytes | share | decoder |
14|---|---:|---:|---:|---|
15| `78 DA` zlib at block start | 105 | 893,535 | 1.79 % | standard zlib, raw deflate at +2 with a 32 KiB window |
16| anything else | 767 | 49,095,163 | 98.21 % | unidentified |
17
18The two are **interleaved**, not separated by region: 211 population switches across the first 120
19blocks. The zlib blocks yield ~2 MB of plaintext that is plainly structured data (8-byte aligned records,
20`0x50000000`-space pointers, `FFFFFFFF` sentinels, ascending u32 tables). The other 767 do not decode yet.
21
22## Entry framing
23
24Each entry is:
25
26```
27u16 tag + 6 class-biased header bytes │ zero pad │ payload at the next 16-byte FILE boundary
28```
29
30i.e. `payload_offset = align16(entry_offset + 8)`, which is `+16` for 766 of the 800 entries measured.
31The rule was confirmed 10/10: the predicted pad length equals the observed zero run every time, and the
32absolute payload offset is `%16 == 0` every time. This is why earlier scans that assumed payloads start at
33the entry start, or that stopped at skip +12, found nothing.
34
35Header shape (distinct byte values per position over the 800 unknown entries):
36`52, 65, 191, 198, 171, 148, 176, 188, 219, 239, 243, 243, …` — i.e. bytes 0..7 are structured and byte 8
37onwards is noise. There is no size field in the header (60 width/endianness combinations tested, all
38`|r| < 0.10` against the block length).
39
40The first two bytes form a **32-value tag alphabet**: 75 distinct u16 in total, but 32 codes carry nearly
41all 800 entries at 15–33 each (800/32 = 25 expected). It is not a bitfield (byte 0 has 52 values, byte 1
42has 65, joint 75 ≪ 3380), and it correlates with nothing measured: length (`r = -0.035`), gap to the next
43entry (`-0.036`), offset (`+0.035`), or neighbours' population. Codes never cluster in file order (881 runs
44over 905 entries), so it is not a file or stream id.
45
46## What the payload is not
47
48Every decoder below was run at the **correct** `align16(entry+8)` offset, with a positive control that
49passes on data compressed by that same decoder, and against a same-geometry random baseline.
50
51| family | result |
52|---|---|
53| deflate (raw, and raw with a 32 KiB zero window) | 0 of 800 entries give even 4 KiB of partial output |
54| zlib, both framing and preset-dictionary (all 32 fcheck-valid CMF/FLG, FDICT set) | 0 — payloads never begin with a `78 xx` header at all |
55| zstd (magicless and framed), brotli, snappy, lz4 (two decoders), LZAV, FastLZ, LZF, LZJB, bz2, xz, lzma-alone, lzma-raw | 0 |
56| Oodle (oo2core 2.9.10, positive control bit-exact) | 0 over 11 offsets × 19 destination sizes × fuzzSafe 0/1 |
57| 21 byte/bit transforms (bit-reverse, nibble-swap, rotates, delta, xor-prev, transposes, block reversal) × 4 decoders | 5 hits against a 2-hit random baseline, 4 degenerate |
58
59## What the payload is
60
61Statistical shape, measured against the same statistics computed on data compressed by each family:
62
63| statistic | zlib level 9 | lzma | bz2 | this payload |
64|---|---:|---:|---:|---:|
65| popcount correlation | +0.676 | −0.065 | −0.432 | **+0.632** |
66| bit-plane bias | +0.0138 | −0.0007 | −0.0110 | **+0.0083** |
67
68So it is **deflate-shaped but proprietary**: an LZ+entropy coder in the deflate family, not LZMA and not a
69BWT coder. AES-class output is excluded because all eight bit planes are biased the same way at ~40σ,
70which ciphertext cannot do. Bit autocorrelation is +0.006 *inside* a byte and exactly 0 at byte boundaries,
71so the stream is bit-domain with no byte framing.
72
73The code is **variable-length and LSB-first**. That was established from runs of one repeated symbol: a run
74emits the same code repeatedly, so the bit spacing of a run equals the code length. Across the region,
7521 non-zero period-7 runs show a uniform **7-bit** spacing and 6 show **8 bits**, in LSB-first order
76(MSB-first gives 9, 9, 9, 9, 9, 2, 7 on the same patterns — inconsistent).
77
78The only visible structure in the 331,760-byte single-block sample at `script.rpf+0x2010` is a 496-byte
79field at payload+0x14460, 16-byte aligned at both ends, made of exact period-7 repeats in two groups
80(54 and 16 copies). Decomposed as 8 symbols × 7 bits, each group is **one plaintext u32 repeated**:
81
82```
83group A: 63 30 48 16 | 63 30 48 16
84group B: 2 7 115 102 | 2 7 115 102
85```
86
87at 28 bits per 4 bytes = **7.00 bits/byte**. So the field is a table of ~140 identical 4-byte entries
88(default records), the repeats are literals rather than matches, and the coder achieves roughly 1/8
89compression on repeated data. The eight 7-bit code values read out are `2, 7, 16, 30, 48, 63, 102, 115`.
90
91## The one missing piece
92
93The coder stores **no table**: the longest run of identical bytes anywhere in 331 KB is the 32-byte zero
94tail, and a canonical-Kraft scan over 8,192 offsets finds nothing. With variable-length codes of 7 and 8
95bits and no stored table, the symbol→length mapping is a **static array in the executable**.
96
97That array is narrow enough to search for. A Kraft-exact length vector for 7- and 8-bit codes satisfies
98`2·n7 + n8 = 256`; with the largest observed code value 115 requiring `n7 ≥ 116`, the candidate families
99are `n7 = 116..127`, i.e. a **129–140 byte vector of 7s and 8s**, most likely `n7 = 116, n8 = 24`
100(140 symbols). Search the executable for a 129–140 byte run of values in `{7,8}` satisfying that equation.
101It is not in the package: the 16 bundled DLLs and the whole 348 MB `gameos.xvd` contain no such run
102(byte-exact search), and no `oo2core`/`Oodle`/codec string exists in either.
103
104## Recovered plaintext, for calibration
105
106Two independent extractions recovered 1,961,559 bytes and 855,961 bytes of payload (the second from
107entries whose zlib part is buried behind the aligned header). The 0x88-byte record structure in it is
108described in the mission notes; the useful calibration here is that a correct decode of the remaining
109767 entries should produce the same record discipline: 8-byte alignment, pointers of the form
110`0x50000000 | offset` with the high dword 0, and 96.7 % of pointers at even dword indices.