upleb.uk

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

summaryrefslogtreecommitdiff
path: root/docs/rbf0.md
diff options
context:
space:
mode:
Diffstat (limited to 'docs/rbf0.md')
-rw-r--r--docs/rbf0.md178
1 files changed, 174 insertions, 4 deletions
diff --git a/docs/rbf0.md b/docs/rbf0.md
index a07d7962e..5322fda3d 100644
--- a/docs/rbf0.md
+++ b/docs/rbf0.md
@@ -15,6 +15,7 @@ payload, carved stream, path list or string dump is committed here.
15| Is there a name or hash table? | **No.** Schema names are inline UTF-8 with a u16 length. There is no hash table and no readable hash string. The 64-bit integers are mostly small codes; none is identified as a name hash. | 15| Is there a name or hash table? | **No.** Schema names are inline UTF-8 with a u16 length. There is no hash table and no readable hash string. The 64-bit integers are mostly small codes; none is identified as a name hash. |
16| What do the streams carry? | UI framework and UI data schemas, movie-subtitle containers, and three tuning/config schemas. No animation, mesh or audio payload. | 16| What do the streams carry? | UI framework and UI data schemas, movie-subtitle containers, and three tuning/config schemas. No animation, mesh or audio payload. |
17| Is it the same format as the `anim.rpf` rig blob? | **Yes, same container and grammar.** That blob is one `rage__crRigSetManager` resource; its 9 descriptors and 28,962 elements parse with the same rules. | 17| Is it the same format as the `anim.rpf` rig blob? | **Yes, same container and grammar.** That blob is one `rage__crRigSetManager` resource; its 9 descriptors and 28,962 elements parse with the same rules. |
18| Can it be decoded to a tree? | **Yes.** `tools/rbf0_tree.py` decodes all 1,263 resources to element/value/text trees. Unknown descriptors and record types fail closed. |
18| Compression inside `RBF0`? | **None observed.** The only compression is the outer RPF9 zlib framing. | 19| Compression inside `RBF0`? | **None observed.** The only compression is the outer RPF9 zlib framing. |
19 20
20## 1. Method and coverage 21## 1. Method and coverage
@@ -229,6 +230,12 @@ The rig blob's nine descriptors are `rage__crRigSetManager`, `RigSet`, `Item`, `
229strings. The element words are again `0, 0, attrs` (27,836 with 0, 1,126 with 1) and there are no attribute 230strings. The element words are again `0, 0, attrs` (27,836 with 0, 1,126 with 1) and there are no attribute
230mismatches. 231mismatches.
231 232
233The grammar-driven tree decoder in section 9 reproduces those counts and resolves the nesting. The root contains
234one `RigSet`, whose 1,126 `Item` elements each carry one `key` string attribute and one `Entries` element. Under
235`Entries`, the 6,677 entry `Item` elements contain a `Dictionary` text, a `Rig` text, a `Group` text and a
236`Priority` integer after the three child elements. Maximum element depth is 6. The decoder does not resolve the
237rig-to-skeleton link.
238
232So the container, prologue, record grammar and element header are shared. The difference is the root schema: 239So the container, prologue, record grammar and element header are shared. The difference is the root schema:
233`anim.rpf` carries a rig-set manager, while `data.rpf` carries UI and config schemas. No `data.rpf` resource has 240`anim.rpf` carries a rig-set manager, while `data.rpf` carries UI and config schemas. No `data.rpf` resource has
234the rig-set root, an `anim/` string or a `SKEL_` string. The `data.rpf` RBF0s are not animation data. 241the rig-set root, an `anim/` string or a `SKEL_` string. The `data.rpf` RBF0s are not animation data.
@@ -263,7 +270,163 @@ the rig-set root, an `anim/` string or a `SKEL_` string. The `data.rpf` RBF0s ar
2637. **Keep the compression boundary explicit.** The RBF0 bytes are uncompressed after the outer RPF9 zlib inflate. 2707. **Keep the compression boundary explicit.** The RBF0 bytes are uncompressed after the outer RPF9 zlib inflate.
264 There is no byte-blob value type and the parse consumes every byte, so there is no place for a nested frame. 271 There is no byte-blob value type and the parse consumes every byte, so there is no place for a nested frame.
265 272
266## 9. Reproduction 273The chunk join, descriptor/type pairing, width selection, attribute count and tree build are implemented in
274`tools/rbf0_tree.py`; section 9 records what that decoder measured and what it still cannot name.
275
276## 9. Tree decoder
277
278`tools/rbf0_tree.py` turns the record stream into a tree. It reads a carve directory or one complete resource,
279joins the 64 KiB continuations, and writes one JSON file with one object per resource, plus optional per-resource
280generic XML files. It is stdlib-only and uses no schema file.
281
282The full `data.rpf` carve decodes **1,263 of 1,263 resources with status `ok`**, and the totals are identical to the
283index counts in section 3: 475,461 elements, 254,935 text records, 85,924 string values, 160,490 value records,
28444,887 descriptors (698 distinct names) and maximum element depth 36. No unknown record type occurs in the corpus.
285
286### 9.1 Grammar used by the decoder
287
288| Bytes | Meaning |
289|---|---|
290| `RBF0` + `FB FF 01 00` | magic and the wide (64-bit integer/float) prologue; without the prologue values are 32-bit |
291| `idx type` | one record; `idx < descriptor_count` reuses a descriptor, `idx == descriptor_count` adds one |
292| `u16 len` + UTF-8 | descriptor name, present only when the record adds a descriptor |
293| `0x00` | element open; three u16 words follow, words 0 and 1 are zero and word 2 is the attribute count |
294| `0x10` | unsigned integer, 8 bytes wide or 4 bytes narrow |
295| `0x20` / `0x30` | true / false, no payload |
296| `0x40` | float, 8 bytes wide or 4 bytes narrow |
297| `0x50` | three floats, 3 x width (not present in this corpus) |
298| `0x60` | string; u16 length followed by that many UTF-8 bytes |
299| `FD FF` | text for the open element; u32 length followed by that many bytes (NUL-terminated in this corpus) |
300| `FF FF` | close the open element |
301
302A descriptor is a name index, not a type declaration. The decoder records the type that introduced the descriptor
303and all later types used with the same index.
304
305In every one of the 1,263 resources, the declared attributes are the first value records of their element: no child
306element or text record precedes them (0 violations). Values after the attribute prefix are content in stream order,
307and a value can follow a child element. A text record attaches to the open element.
308
309### 9.2 Measured tree facts
310
311| Measure | Value |
312|---|---:|
313| Resources decoded | 1,263 / 1,263 `ok` |
314| Elements | 475,461 |
315| Elements with 0 / 1 / 2 declared attributes | 389,525 / 84,541 / 1,395 |
316| Attribute values | 87,331: 85,924 string, 1,111 integer, 296 float |
317| Two-attribute type pairs | float/float 128, string/int 1,111, string/float 40, string/string 116 |
318| Non-attribute values | 73,159: 38,008 float, 28,289 integer, 6,862 boolean |
319| Non-attribute values after a child element | 22,977 |
320| Text records | 254,935, all NUL-terminated |
321| Text-only elements | 254,935; one text record, first content, no child or value |
322| String values | 85,924; all are attributes and none is NUL-terminated |
323| Text / string length | 2-1,006 / 1-126 bytes (the text length includes its trailing NUL) |
324| Descriptor instances reused with more than one type | 564 |
325| Root with an attribute | 1: `rage__SafeframeConfig` |
326| Descriptor names not usable as XML element names | 1: `xmlns:xi` |
327| Unknown record types | 0 |
328
329The single root attribute is `xmlns:xi` on the narrow `rage__SafeframeConfig` resource at archive offset
330`0x1c33e000` (18,317 inflated bytes). The same name is declared as descriptor 1 at offset `0x23` and is used 14 times
331in that resource. It is also the only descriptor name that cannot be used as an XML element name (the `xmlns`
332prefix is reserved), which is why the XML writer uses fixed tags and puts the exact name in a `name` attribute.
333
334Of the 26 text payloads that are not valid UTF-8, all are text records; no string value or descriptor name failed
335a strict UTF-8 decode. The decoder replaces invalid bytes with U+FFFD and sets `utf8_valid: false`; the original
336encoding is not established.
337
338### 9.3 Sample trees
339
340The three samples below are the smallest resources of their root schema that decode completely. Offsets are
341relative to the start of the joined resource.
342
343| Root schema | Archive offset | Inflated | Layout | Descriptors | Elements | Texts | Strings | Depth |
344|---|---|---:|---|---:|---:|---:|---:|---:|
345| `CMovieSubtitleContainer` | `0x9ed7280` | 490 | wide-64 | 13 | 11 | 3 | 3 | 4 |
346| `rage__fwuiPrefab` | `0x11dd8950` | 195 | wide-64 | 5 | 4 | 2 | 1 | 3 |
347| `UIScreen` | `0x12059180` | 385 | wide-64 | 9 | 9 | 6 | 0 | 3 |
348
349`CMovieSubtitleContainer` descriptor table:
350
351| ID | Name | First type | Uses |
352|---:|---|---|---:|
353| 0 | `CMovieSubtitleContainer` | open | 1 |
354| 1 | `TextBlockName` | open | 1 |
355| 2 | `pCutsceneEventArgsList` | open | 1 |
356| 3 | `Item` | open | 3 |
357| 4 | `type` | string | 3 |
358| 5 | `cName` | open | 2 |
359| 6 | `m_cOptionalActor` | open | 2 |
360| 7 | `fSubtitleDuration` | float | 2 |
361| 8 | `pCutsceneEventList` | open | 1 |
362| 9 | `fTime` | float | 1 |
363| 10 | `iEventId` | int | 1 |
364| 11 | `iEventArgsIndex` | int | 1 |
365| 12 | `iObjectId` | int | 1 |
366
367The tree shows the attribute/content split directly:
368
369```
3700x0008 element 0 CMovieSubtitleContainer attrs=0 end 0x01ea
3710x0029 element 1 TextBlockName
3720x0040 text length 8
3730x0050 element 2 pCutsceneEventArgsList
3740x0070 element 3 Item attrs=1
3750x007e value 4 type (string, attribute)
3760x009e element 5 cName
3770x00ad text length 12
3780x00c1 element 6 m_cOptionalActor
3790x00dd value 7 fSubtitleDuration (float, content after the child)
3800x0154 element 8 pCutsceneEventList
3810x0170 element 3 Item attrs=1
3820x018f value 9 fTime (float)
3830x01a0 value 10 iEventId (int)
3840x01b4 value 11 iEventArgsIndex (int)
3850x01cf value 12 iObjectId (int)
3860x01e8 close root; end 0x01ea
387```
388
389The 195-byte `rage__fwuiPrefab` uses descriptor IDs 0-4: root, `Id`, `PrefabObject`, `type` (string) and `Style`.
390Its root is at 0x08; `Id` at 0x22 with a 42-byte text at 0x2e; `PrefabObject` at 0x60 with one attribute `type`
391at 0x76; `Style` at 0x8f with a 25-byte text at 0x9e; root close at 0xc1, end 0xc3.
392
393The 385-byte `UIScreen` uses descriptor IDs 0-8: `UIScreen`, `LayoutParams`, `widthContentMode`,
394`heightContentMode`, `horizontalAlignment`, `verticalAlignment`, `Name`, `Screen` and `ID`. It has nine elements
395and six text leaves; `LayoutParams` contains four text-valued children and the root contains `Name`, `Screen` and
396`ID` siblings. No attribute is present.
397
398### 9.4 Output and failure behavior
399
400JSON carries one object per resource: `offset`, `size`, `chunks`, `layout`, `root_name`, `status`, `error`,
401`descriptors`, `counts` and `tree`. Every node has a `kind` and a byte `offset`. Elements carry `descriptor`,
402`attrs_declared`, `attributes`, ordered `content` and `end`; values carry `descriptor`, `type`, `payload_offset`,
403`size` and `value`; text nodes carry `length`, `nul_terminated`, `text` and `utf8_valid`.
404
405XML is a rendering, not a round-trip. Fixed tags avoid descriptor names that are not legal XML names:
406`<node name="...">`, `<attr>`, `<value>` and `<text>`. A string containing XML markup is escaped by the writer.
407
408The decoder fails closed. An index beyond the current descriptor table, an unknown record type, a non-zero element
409header word, a close or text with no open element, and a truncated payload stop that resource with `status` `bad`
410or `truncated`; the partial tree is kept and no value is invented. `status` `trailing` means the root closed before
411the last byte. The corpus has 0 bad, 0 truncated and 0 trailing resources.
412
413### 9.5 Remaining unknowns
414
415- There is no schema: descriptor names are fields, but value meaning, enum spelling and units are not stored.
416- The prologue's meaning is still not established; the decoder uses it only to select 4- or 8-byte values.
417- Element header words 0 and 1 are zero in all 475,461 elements. Their intended meaning is unknown; the decoder
418 rejects a non-zero value instead of guessing.
419- The attribute rule is measured, not proven universal: every corpus attribute leads its element and every text
420 element is a text-only leaf. The decoder marks `attribute_order_violation`, `multiple_text` and
421 `text_after_child` if a future resource departs from it; the corpus has none of these.
422- The 26 invalid UTF-8 text payloads have no established encoding. The XML writer replaces bad bytes, so it is
423 lossy for those records.
424- `xmlns:xi` is a literal field name. Its namespace meaning is not decoded.
425- `0x50` (three floats) is accepted by the grammar but never occurs in this corpus.
426- No external schema or XSD validates the tree; XML output is a structural rendering only.
427- A resource does not store its archive path. The source label is the carve offset or file name, not a game path.
428
429## 10. Reproduction
267 430
268```powershell 431```powershell
269# Index the archive: CSV or JSON, root/counts/strings; no payload is written 432# Index the archive: CSV or JSON, root/counts/strings; no payload is written
@@ -273,16 +436,23 @@ python -I tools/rbf0_index.py <package>\data.rpf <work>\rbf0.csv --quiet
273# Index a directory of already-carved streams (offsets from leading hex file names) 436# Index a directory of already-carved streams (offsets from leading hex file names)
274python -I tools/rbf0_index.py <work>\data-carve <work>\rbf0.json 437python -I tools/rbf0_index.py <work>\data-carve <work>\rbf0.json
275 438
276# Unit test: synthetic headers only 439# Decode trees from the same carve; JSON plus optional per-resource XML
440python -I tools/rbf0_tree.py <work>\data-carve <work>\rbf0-tree.json
441python -I tools/rbf0_tree.py <work>\data-carve <work>\rbf0-tree.json --xml <work>\rbf0-xml
442python -I tools/rbf0_tree.py <work>\data-carve <work>\subtitle.json --root CMovieSubtitleContainer --limit 1
443
444# Unit tests: synthetic headers and trees only
277python -I tests/test_rbf0_index.py 445python -I tests/test_rbf0_index.py
446python -I tests/test_rbf0_tree.py
278``` 447```
279 448
280The JSON summary carries the corpus totals used above (`streams`, `compressed_bytes`, `inflated_bytes`, 449The JSON summary carries the corpus totals used above (`streams`, `compressed_bytes`, `inflated_bytes`,
281`rbf0.resources`, `rbf0.multi_chunk`, `rbf0.by_root`, `rbf0.size_buckets`, record counts, string categories and 450`rbf0.resources`, `rbf0.multi_chunk`, `rbf0.by_root`, `rbf0.size_buckets`, record counts, string categories and
282keyword occurrences), so the numbers can be re-measured without committing an index. `--all-strings` writes the 451keyword occurrences), so the numbers can be re-measured without committing an index. `--all-strings` writes the
283full readable string list to JSON; that file is game data and must stay out of git. 452full readable string list to JSON; that file is game data and must stay out of git. The tree output and XML files
453contain names and payloads and are game data too.
284 454
285## 10. No-sharing rule 455## 11. No-sharing rule
286 456
287Game files, carved streams, inflated RBF0 blobs, readable string lists, parsed trees and reports that quote them 457Game files, carved streams, inflated RBF0 blobs, readable string lists, parsed trees and reports that quote them
288stay on the machine that owns the package. Do not commit them, attach them to an issue or pull request, or paste 458stay on the machine that owns the package. Do not commit them, attach them to an issue or pull request, or paste