Commit Graph

11 Commits

Author SHA1 Message Date
52dc48074d tools/imhex: ImHex pattern for PSIN containers
psin.hexpat lays out a container as docs/psin.md describes it: the
big-endian first-section offset, the instance-data block table (rows,
the pppppppp end) and its blocks as raw bytes, the section chain, LSCH
struct headers and members and LENM enums and values (header count by
the fill-exact rule psin_index.py uses), the LSNS block table with
opaque 16-byte records, the LRSC 0DRP version and root block, and the
CHKS file size. A section past the end of a truncated stream is shown
as raw bytes.

tests/test_imhex_patterns.py builds a synthetic container from the
invented schema in test_psin_index.py, checks it with psin_index.parse
and psin_data.block_table, and when ImHex is installed compares the
pattern's output with both, plus a container cut inside LENM.
2026-11-22 11:14:51 -03:00
58919a9faa tools: resolve PSIN name-hash members against known resource names
psin_names.py walks PSIN instance data with psin_data.py and looks up every
u32 hash member (joaat of the lower-cased name) and u64 hash member
(MurmurHash3 x64 low 64 bits) in a dictionary from rpf9_names.py or name
lists, with a salted control. docs/psin.md no longer says PSIN has no model
names. Synthetic tests only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 13:46:28 +01:00
5805570920 psin_index: read the LSNS block layout; document its records as opaque
LSNS is a u32 block count, a (u32 kind, u32 bytes) table, then the blocks,
each a whole number of 16-byte records; the empty form is 12 bytes.
psin_index.py now checks that layout per section and reports blocks,
record counts and errors. Over 5,217 sections in five archives it holds
with 0 errors.

The records are uniform bytes, occur nowhere else in their container, and
match no tested 32/64/128-bit name hash (joaat, FNV, CRC-32, Murmur3,
xxHash, MD5, BLAKE2b, SHA). psin.md records the layout and these negative
results; the contents may be encrypted and are left unread.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 13:02:42 +01:00
67f8a5338d psin_data: reject block tables that run past the region; read 0x62 enums both ways
Review on #1077 (@kapitche): block sizes came straight from the table, so a
damaged size made the walker allocate gigabytes. block_table now rejects
blocks that end past the first section. Every real container fills the region
exactly, so no counts change.

The same review asked why 0x62 was read as s32. LENM lists values on both
sides of the sign bit for 0x62 enums, so a value now counts as listed under
either reading. Unlisted enum values drop from 31,624 to 827; the 30,577
'hash-like' values in story000_script were this.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 06:57:44 +00:00
eabcb993a7 psin_data: decode PSIN instance data through the LSCH schema (PROC-46)
The region between the PSIN header and LSCH is a block table plus its data
blocks: 16-byte rows {u32 type, u32 size, 0xaa x 8}, 8 bytes of 0x70 padding,
then the blocks, each 16-byte aligned, ending exactly at the first section.
LRSC's 0DRP header names the root block at +0x10. Pointers are u64 with the
block number in the low 20 bits and the byte offset above.

tools/psin_data.py walks every value reachable from the root (embedded
structs, struct and string pointers, the 0x5c/0x52/0x54/0x50 arrays, the 0x71
binary map, the 0x75 SwissTable and the 0x73 open-addressed table, the 16-byte
0x44 string with its in-place form) and reports counts and checks only.
Unknown member types are counted and skipped.

Over the 17,507 complete containers with LSCH and LRSC in package 1.0.2.1 the
block tables fill the region 17,507 times and the walk reaches 129,100,004 of
129,117,812 block bytes (99.986%). The rest is behind the three member types
it does not decode (0x5a, 0x76, 0x77).

docs/psin.md gets an "Instance data" section. The header's +8 "version" and
+12 "hash table bytes" are the first block-table row: 22 is a 0x16 block,
found on 1,010 of 18,640 streams. The type-code readings the instance data
confirms are updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 06:34:55 +00:00
caf4a6ea4c psin_index: --schema no longer crashes on a truncated PSIN
parse() returned early, before setting record["schema"], when the
first section was outside the file or its header was cut short, and
main() then read r["schema"] (KeyError). With --json --schema those
records had no schema key at all. Every record now gets the same
{structs, enums, lsch, lenm, reason} entry; text mode prints the
reason. Reported by @kapitche on #776.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 04:03:01 +00:00
0317b8d5fb docs/psin: LSCH/LENM layouts measured over every archive (ASSET-50)
All 18,640 PSIN streams in package 1.0.2.1 (every archive but the raw
AWC audio.rpf): 17,664 whole LSCH and 17,641 whole LENM sections, all
decoded with no schema error. Counts and layouts only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 02:55:05 +00:00
55d42a90f2 psin_index: decode LSCH (type schema) and LENM (enums) (ASSET-50)
LSCH holds 32-byte struct headers followed by 16-byte members; LENM
holds 24-byte enum headers followed by 16-byte values. Neither stores
the header count; it is the one count that fills the payload. Names
are case-sensitive joaat. Counts and layouts only, no game data.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 02:35:20 +00:00
76b7b5b329 Index tools: refuse --limit/--start values that scan nothing, survive empty archives
bvh_index, page_index, story_index, navmesh_index and psin_index:

- --limit 0 meant "no limit" (0 is falsy) and a negative --limit scanned
  nothing and still exited 0 with an empty index. --limit must now be at
  least 1 and --start 0 or more; argparse rejects anything else (rc 2).
- An empty .rpf crashed in mmap ("cannot mmap an empty file") and a file
  shorter than the header word crashed in struct.unpack_from. bvh, page and
  story now treat both as an archive with no streams.
- bvh_index directory mode: one bad archive no longer aborts the scan and
  loses the results of the others; it is reported and skipped.
- A --start past the end of the archive is a one-line error (rc 2) instead
  of a traceback (bvh also checked nothing and reported a negative span).
- page_index checks the output extension before the scan, not after it.

Docs: the accepted ranges and the empty-archive behaviour are written next
to each tool's usage in docs/{bvh,navmesh,page_directory,psin,story}.md.

Tests: synthetic cases for each tool; they fail on main and pass here.
2026-11-21 23:21:29 +01:00
78af668e01 Tools: report PSIN LRSC and CHKS fields 2026-11-21 20:02:19 +00:00
a87d11cacd Tools: index the PSIN metadata container 2026-11-21 19:22:22 +00:00