From 6e0743af16f1217a89af8e4f90e41e1f096fcbea Mon Sep 17 00:00:00 2001 From: Moriz82 <72836413+Moriz82@users.noreply.github.com> Date: Tue, 24 Nov 2026 15:13:18 -0600 Subject: [PATCH] pe_shader_containers: find console programs stored compressed (TOOLS-PE-SHADER-CONTAINERS) The scan found only containers that lie in the image as they are. A console program can also be stored as a compressed record: a stored size, the constant 0x000DDCE7, the stored size again, the size of the container and a raw deflate stream of the whole DXBC container. Such a program was not listed and not extracted. inspect() now also looks for that record. It is taken only when both stored 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 is listed after the plain containers, which keep their order and file names, with the offset of the constant, stored_size, and the size and SHA-256 of the inflated container. --extract writes the inflated container. A container that a stream of stored blocks holds as it is stays listed once. tests/test_pe_shader_containers.py gets five tests with hand-built records; three of them fail on the base. The standard-library tests and the translator suite add no failing file. No game file was read for this change: the record layout is taken from the integration branch, and it is exercised here on synthetic records only. AI-assisted (Claude Code). Co-authored-by: Plaaasma <47513553+Plaaasma@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 --- docs/embedded_shaders.md | 10 +++ tests/test_pe_shader_containers.py | 106 +++++++++++++++++++++++++++++ tools/pe_shader_containers.py | 6 +- 3 files changed, 121 insertions(+), 1 deletion(-) 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