The pattern
A RESO TOC entry is
a (length, data_offset) pair (variant=1, 8 bytes per entry).
The format allows two TOC entries to carry the same
data_offset and length, in which case they
share a single physical payload. The engine reads the payload identically
regardless of which TOC entry index requested it.
Empirical scan across data/message/**/*.ofs:
| Metric | Value |
|---|---|
| Files scanned | 1,328 |
| Files using payload sharing | 703 (52.9%) |
| Distinct shared groups | 2,890 |
| Pre-canonicalisation row pairs | 13,422 (6,696 already consistent + 6,726 needing alignment) |
Example: msg51016.ofs
Original file: 3,472 bytes. RESO header variant=1, file_count=100.
Of the 100 TOC entries, only 27 distinct data_offset values.
| Entry range | Original data_offset | Payload length | Shared by N entries |
|---|---|---|---|
| 0..9 | 0x0330 | 158 | 10 |
| 10..19 | 0x03D0 | 22 | 10 |
| 20..29 | 0x03F0 | 468 | 10 |
| 30..39 | 0x05D0 | 34 | 10 |
| 40..49 | 0x0600 | 34 | 10 |
| 60..69 | 0x0630 | 472 | 10 |
| 73,83 | 0x08A0 | 60 | 2 |
| 75,85,95 | 0x08F0 | 16 | 3 |
| 76,86,92 | 0x0900 | 144 | 3 |
| 78,88 | 0x0A30 | 38 | 2 |
| 79,89,94 | 0x0A60 | 106 | 3 |
| 96..99 | 0x0D70 | 30 | 4 |
Unique payload bytes: 2,526. Phantom bytes saved by sharing: 11,412 (3.5Γ the payload section if expanded out).
Why this matters for re-emission
Without dedup, a fresh payload is written per TOC entry, so a
100-entry-but-27-payload original becomes a 90+ distinct-payload
rebuilt file. msg51016.ofs ballooned from
3,472 B β 19,728 B before the dedup fix. Across the corpus the unfixed
re-emit added β3.54 MB of pure layout waste.
Dedup logic in re-emit
From src/translator/reemit.py::rewrite_reso_container
(variant-1 header, 8-byte entries):
header_entry_size = 16 if h.variant == 0 else 8
payload_start = 0x10 + h.file_count * header_entry_size
new_header = bytearray()
payload_section = bytearray()
payload_offsets : dict[bytes, int] = {} # payload-bytes -> offset
for ei in range(h.file_count):
payload = new_payloads.get(ei, b"")
if len(payload) == 0:
new_header += struct.pack("<II", 0, 0)
elif payload in payload_offsets: # β REUSE OFFSET
offset = payload_offsets[payload]
new_header += struct.pack("<II", len(payload), offset)
else: # β NEW PAYLOAD
offset = payload_start + len(payload_section)
payload_offsets[payload] = offset
payload_section += payload
pad = (16 - (len(payload) % 16)) % 16 # β 16-B align
payload_section += b"\x00" * pad
new_header += struct.pack("<II", len(payload), offset)
if header_entry_size == 16: # variant-0: copy type_tag + unk
new_header += raw[0x10 + ei*16 + 8 : 0x10 + ei*16 + 16]
Canonicalisation
Dedup only helps when the per-entry EN payloads happen to be byte-identical. Because each entry was translated independently, two entries that shared a JP payload often produced different EN paraphrases. Canonicalisation walks each original shared group and forces all members to the same EN string before re-emit.
Selection rule per group (from shared_payload_canonicalization.md):
- If any row in the group is marked
manual, that row wins. - Else: longest
en_textwins (most likely to fit budget). - Tie-break: lowest
entry_id.
| Metric | Value |
|---|---|
| Rows changed by canonicalisation | 6,726 |
| Manual rows preserved | 3 |
| Structural mismatches | 0 |
| Bytes recovered from re-emit | ~1.52 MB (43% of bloat) |
Top growers (before dedup + canonicalisation)
| File | Original | Patched (naive) | Dedup savings |
|---|---|---|---|
msg51016 | 3,472 | 19,728 | 11,412 |
msg42016 | 3,184 | 19,312 | 10,510 |
msg49043 | 11,040 | 27,168 | 9,952 |
msg48043 | 12,368 | 28,464 | 10,836 |
msg50043 | 11,184 | 26,912 | 10,330 |
msg43043 | 13,008 | 28,656 | 8,144 |
msg41016 | 3,136 | 18,512 | 8,988 |
msg40016 | 3,200 | 18,384 | 8,878 |
msg47016 | 3,200 | 18,368 | 9,596 |
msg48016 | 3,344 | 18,192 | 9,132 |
All ten files are msg<N>016.ofs or msg<N>043.ofs
in the per-chapter career directories. The shared-group pattern is the
engine's "pick one variant by (npc_id mod N)" table.
Source
src/translator/reemit.pyβ dedup + emit logicnotes/msg51016_investigation.mdβ root-cause + numbersnotes/shared_payload_canonicalization.mdβ canon pass stats