diff --git a/docs/embedded_shaders.md b/docs/embedded_shaders.md index 6ccdbaf417..3ce02e6a5d 100644 --- a/docs/embedded_shaders.md +++ b/docs/embedded_shaders.md @@ -245,6 +245,16 @@ chunk ends exactly at that total; that is what rejects the FSR DLL's `DXBC` imme `tests/test_pe_shader_containers.py` build containers by hand (no game data) and cover the accepted layout, a bare magic, a truncated chunk, an `ACCC`/`FSPX` container, the `ILDN` name and the extraction index. +A console program can also be stored compressed, and then the image has no `DXBC` magic for it. The record is a u32 +stored size, the u32 constant `0x000DDCE7`, the stored size again, the u32 size of the container and a raw deflate +stream of the whole container; both stored sizes count from the constant, so they include those 12 bytes. It is the +layout the five-star-recomp project describes for the shader records of the effect tables (its note on shader +containers). The tool takes such a record only when both sizes agree and fit, the stream ends exactly where the record +does and inflates to exactly one container of the named size, and that container holds an `XBCH` program. It lists the +record after the plain containers, which keep their order and file names, with the `offset` of the constant, +`stored_size`, and the `size` and `sha256` of the inflated container, which `--extract` writes. The tests build such +records by hand and cover the rejected forms. + ## 7. Build step and run-time lookup **Build (D3D-557).** `make_game.py`'s `shaders` stage, after the game's own shaders and the FidelityFX step, runs diff --git a/tests/test_pe_shader_containers.py b/tests/test_pe_shader_containers.py index 718d99987b..618a45517a 100644 --- a/tests/test_pe_shader_containers.py +++ b/tests/test_pe_shader_containers.py @@ -6,6 +6,7 @@ """ import contextlib +import hashlib import io import json import os @@ -75,6 +76,111 @@ def ildn(name: str) -> bytes: return b"\x00\x00" + struct.pack(" bytes: + """A compressed container as the image stores it: the stored size, the constant 0x000DDCE7, the stored size + again, the inflated size and a raw deflate stream. Both stored sizes count from the constant.""" + compressor = zlib.compressobj(level, wbits=-15) + stream = compressor.compress(dxbc) + compressor.flush() + trailing + first, second = stored or (12 + len(stream),) * 2 + return struct.pack("= 16: + at = rng.randrange(0, len(data) - 15) + n = rng.randrange(0, 64) + data[at : at + 16] = struct.pack(" tuple[list[dict], list[int]]: records, _ = inspect_raw(dxbc, image) if records and records[0]["offset"] == 0 and records[0]["has_xbch"]: record = records[0] - record.update(offset=offset, stored_size=u32(data, offset + 4)) + stored = u32(data, offset + 4) + # An uncompressed deflate block may have been found by the plain scan. + if any(offset < r["offset"] < offset + stored and r["sha256"] == record["sha256"] for r in found): + continue + record.update(offset=offset, stored_size=stored) found.append(record) return found, rejected