World sector grids in levels.rpf: decoder and sector-grid command #194

Manually merged
github merged 2 commits from gh-pr/194/head into gh-pr/194/base 2026-11-26 20:17:05 +00:00
Owner

@⁠holdmysocks on GitHub · 2026-11-24 19:11 UTC · original
holdmysocks:claude/sector-grid → master · +397 −0 · 3 files · 2 commits · merged 2026-11-24 19:36 UTC

What

The first eight PSO files of levels.rpf are world sector grids (struct 9c834886, 32-byte records). They come in three cell sizes: 1024 m, 512 m and 60 m. Each size has two kinds of list:

  • a cell list: each cell appears once;
  • a map-group list: a map group's id, followed by the cells its entities reach.

The 60 m cell list is the world grid: 26,212 cells covering the playable area.

This PR adds a decoder to sixng-core (sectorgrid.rs) and a sixng sector-grid command. The command lists all eight grids with their kind, cell size and counts. It writes the world grid, or the grid that --entry picks, as CSV, JSON and a mask PNG with north up. --cell-m overrides the cell size.

Record layout (little endian):

offset type field meaning
0x00 i32 x cell column = floor(world x / cell size)
0x04 i32 y cell row = floor(world y / cell size)
0x08 u32 53149a19 always 0
0x0C u32 8fab3f0b bundle key
0x10 u32 56f5c799 index in the bundle
0x18 u64 f24b342d 0 in cell lists; map group id in map-group lists
file (archive order) records cell size kind
1 204 1024 m cells
2 63 1024 m map groups
3 765 512 m cells
4 and 6 75 each 512 m map groups (identical records except the bundle key)
5 135 512 m cells, a subset of file 3
7 26,212 60 m cells (world grid)
8 3,269 60 m map groups (1,308 distinct cells)

Measured

All of these were measured against the placements of every world map file (1.67 million entities).

  • Field names: x and y are real, because their joaat hashes match.
  • World grid at 60 m: 94.3 % of entities fall in a listed cell, and 96.8 % of cells hold one. At 64 m the figures are 87.8 % and 96.0 %; at 50 m, 64 % of entities fall in a listed cell. 98 % of cells hold an entity, a batch or a road node.
  • The 64-bit field is a map group id. It equals the map files' 64-bit field 65876a4d. For 37 of 46 of these values, the cells listed are exactly the cells under the map files' entity extents at 60 m. Every other cell size from 54 to 67 m scores 7 or fewer.
  • Cell origin: shifting the grid by half a cell drops the exact matches from 37 to 5. So a cell's origin is its south-west corner.
  • Coarse files: the same exact-match test peaks at 510 to 512 m (21 of 25) and at 1020 to 1024 m (23 of 25), so I took the powers of two.
    • File 5 must be 512 m: all its cells are cells of file 3, and at 1024 m it would reach past the world box.
    • File 5 is mostly the dense cells (a median of 5,056 entities per cell, against 254). No count threshold separates it better than 89 %.
  • Bundle key: in the world grid, records are sorted by the text of x and then y. The keys cut that order into runs of 1 to 63 cells with about equal content: 220 to 360 entities per bundle (median) at any bundle size.
    • So a key names a bundle of cells packed in name order up to a size budget.
    • In the other files, each record has its own key.

Checked

  • cargo test -p sixng-core --lib sectorgrid: 6 tests on synthetic PSO files (no game data). They cover decoding, the map-group kind, rejecting a wrong schema, the north-up mask and floor rounding at 60 and 1024 m.
  • sixng sector-grid -o … on the real archive finds all 8 grids, gives each its cell size, and puts every grid inside the height map's world box.

Not known, not done

  • The bundle key's name. It matches no recovered name, dictionary name or map file name hash. The archive's entry names are in its encrypted table of contents, which this project does not read.
  • File 5: what exactly selects its cells.
  • Files 4 and 6: why they differ only in their keys.
  • Coarse cell sizes: 512 vs 510 and 1024 vs 1020 are ties. I took the powers of two.
  • Unmatched map group ids: 210 of the 277 match no map file decoded by placements.
  • Cell sizes in code: they come from a table in archive order. They are measured, not read from the file.
  • Integration: nothing reads the grids yet (not Map 3D, the viewer or the map bake).
**@⁠holdmysocks** on GitHub · 2026-11-24 19:11 UTC · [original](https://github.com/holdmysocks/SixNG/pull/194) `holdmysocks:claude/sector-grid` → `master` · +397 −0 · 3 files · 2 commits · merged 2026-11-24 19:36 UTC ## What The first eight PSO files of `levels.rpf` are world sector grids (struct `9c834886`, 32-byte records). They come in three cell sizes: 1024 m, 512 m and 60 m. Each size has two kinds of list: - a **cell list**: each cell appears once; - a **map-group list**: a map group's id, followed by the cells its entities reach. The 60 m cell list is the world grid: 26,212 cells covering the playable area. This PR adds a decoder to `sixng-core` (`sectorgrid.rs`) and a `sixng sector-grid` command. The command lists all eight grids with their kind, cell size and counts. It writes the world grid, or the grid that `--entry` picks, as CSV, JSON and a mask PNG with north up. `--cell-m` overrides the cell size. Record layout (little endian): | offset | type | field | meaning | |---|---|---|---| | 0x00 | i32 | `x` | cell column = floor(world x / cell size) | | 0x04 | i32 | `y` | cell row = floor(world y / cell size) | | 0x08 | u32 | `53149a19` | always 0 | | 0x0C | u32 | `8fab3f0b` | bundle key | | 0x10 | u32 | `56f5c799` | index in the bundle | | 0x18 | u64 | `f24b342d` | 0 in cell lists; map group id in map-group lists | | file (archive order) | records | cell size | kind | |---|---|---|---| | 1 | 204 | 1024 m | cells | | 2 | 63 | 1024 m | map groups | | 3 | 765 | 512 m | cells | | 4 and 6 | 75 each | 512 m | map groups (identical records except the bundle key) | | 5 | 135 | 512 m | cells, a subset of file 3 | | 7 | 26,212 | 60 m | cells (world grid) | | 8 | 3,269 | 60 m | map groups (1,308 distinct cells) | ## Measured All of these were measured against the placements of every world map file (1.67 million entities). - **Field names:** `x` and `y` are real, because their joaat hashes match. - **World grid at 60 m:** 94.3 % of entities fall in a listed cell, and 96.8 % of cells hold one. At 64 m the figures are 87.8 % and 96.0 %; at 50 m, 64 % of entities fall in a listed cell. 98 % of cells hold an entity, a batch or a road node. - **The 64-bit field is a map group id.** It equals the map files' 64-bit field `65876a4d`. For 37 of 46 of these values, the cells listed are exactly the cells under the map files' entity extents at 60 m. Every other cell size from 54 to 67 m scores 7 or fewer. - **Cell origin:** shifting the grid by half a cell drops the exact matches from 37 to 5. So a cell's origin is its south-west corner. - **Coarse files:** the same exact-match test peaks at 510 to 512 m (21 of 25) and at 1020 to 1024 m (23 of 25), so I took the powers of two. - File 5 must be 512 m: all its cells are cells of file 3, and at 1024 m it would reach past the world box. - File 5 is mostly the dense cells (a median of 5,056 entities per cell, against 254). No count threshold separates it better than 89 %. - **Bundle key:** in the world grid, records are sorted by the text of x and then y. The keys cut that order into runs of 1 to 63 cells with about equal content: 220 to 360 entities per bundle (median) at any bundle size. - So a key names a bundle of cells packed in name order up to a size budget. - In the other files, each record has its own key. ## Checked - `cargo test -p sixng-core --lib sectorgrid`: 6 tests on synthetic PSO files (no game data). They cover decoding, the map-group kind, rejecting a wrong schema, the north-up mask and floor rounding at 60 and 1024 m. - `sixng sector-grid -o …` on the real archive finds all 8 grids, gives each its cell size, and puts every grid inside the height map's world box. ## Not known, not done - **The bundle key's name.** It matches no recovered name, dictionary name or map file name hash. The archive's entry names are in its encrypted table of contents, which this project does not read. - **File 5:** what exactly selects its cells. - **Files 4 and 6:** why they differ only in their keys. - **Coarse cell sizes:** 512 vs 510 and 1024 vs 1020 are ties. I took the powers of two. - **Unmatched map group ids:** 210 of the 277 match no map file decoded by `placements`. - **Cell sizes in code:** they come from a table in archive order. They are measured, not read from the file. - **Integration:** nothing reads the grids yet (not Map 3D, the viewer or the map bake).
The first eight PSO files of levels.rpf list cells of a 60 m world grid
(struct 9c834886, 32-byte records: x, y, group hash, index in group and
a 64-bit value). sixng-core gets sectorgrid.rs; the CLI gets sector-grid,
which lists the grids and writes CSV, JSON and a north-up mask PNG.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 20:17:03 +00:00
github manually merged commit a213cf51ed into gh-pr/194/base 2026-11-26 20:17:05 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.