diff --git a/README.md b/README.md index 0710608d4d..91d429c42b 100644 --- a/README.md +++ b/README.md @@ -117,6 +117,9 @@ xcl shaders D:\data\shaders.rpf --top 50 # pack statistics; --recomp / --compi xcl rpf D:\data\shaders.rpf --extract NAME --out folder ``` +- `xcl rpf` scans plain-name RPF9 records without decrypting the table of contents; + even a compact final record needs no trailing padding. + - **Without a command line** (xcl.exe opened from Explorer) XCL shows a small menu: *Choose a game…* (pick its exe or `MicrosoftGame.config`) or *Run again* (the last one). On an error the window stays open until Enter. diff --git a/crates/xcl/src/gpu/pack.rs b/crates/xcl/src/gpu/pack.rs index 6d8df3d462..edadf7085c 100644 --- a/crates/xcl/src/gpu/pack.rs +++ b/crates/xcl/src/gpu/pack.rs @@ -43,7 +43,8 @@ fn rd32(b: &[u8], o: usize) -> u32 { pub fn scan(d: &[u8], from: usize) -> Vec { let mut out = Vec::new(); let mut i = from; - while i < d.len().saturating_sub(32) { + // Minimum: length byte + three name bytes + 18 header bytes + nonempty payload. + while i < d.len().saturating_sub(1 + 3 + 18) { let len = d[i] as usize; let Some(p) = i.checked_add(len) else { break }; let Some(header_end) = p.checked_add(18) else { break }; @@ -131,6 +132,21 @@ mod tests { assert_eq!(name_stage("ptfx_x"), None); } + #[test] + fn short_records_do_not_need_trailing_padding() { + for name in ["PS_", "PS_ABCD"] { + for prefix in [0, 0x40] { + let mut bytes = vec![0xAA; prefix]; + bytes.extend(record(name, b"DXBC")); + let records = scan(&bytes, prefix); + let [r] = records.as_slice() else { panic!("missing short record {name} at {prefix}") }; + assert_eq!(r.name, name); + assert_eq!(r.offset, prefix); + assert_eq!(inflate(&bytes, r).as_deref(), Some(b"DXBC".as_slice())); + } + } + } + /// An effect-qualified name is one record under its full name, also when the `:` byte /// equals the length of the rest of the name (which makes the tail look like a record). #[test]