Skip to content

Fix read_resource returning empty bytes for uncompressed resources#4

Open
Wawax007 wants to merge 1 commit into
7akeem0:mainfrom
Wawax007:fix-uncompressed-read
Open

Fix read_resource returning empty bytes for uncompressed resources#4
Wawax007 wants to merge 1 commit into
7akeem0:mainfrom
Wawax007:fix-uncompressed-read

Conversation

@Wawax007

Copy link
Copy Markdown

Problem

rpkg.read_resource() returns empty bytes (b"") for any resource stored uncompressed in the chunks. When the low 30 bits of table1's sizeField are 0, the resource is stored uncompressed on disk (dsz bytes from table2, possibly still XOR-scrambled when bit 31 is set), but the function passes comp = 0 straight to f.read().

All TEXT/TEXD texture resources in both retail chunks are stored this way, so texture extraction is currently impossible through the library.

Fix

Read dsz bytes when comp == 0. One-line change in read_resource, keeps the existing XOR + LZ4 paths untouched.

Validation

Used this fix to extract, edit and re-inject several TEXT/TEXD pairs (BC1/BC3/BC7, full mip chains) on retail chunk0/chunk1 — round-trips verified byte-exact and the textures render fine in-game. LOCR/DLGE extraction (compressed path) is unaffected.

When sizeField's low 30 bits are 0 the resource is stored uncompressed
(dsz bytes on disk, still XOR-scrambled when bit31 is set), but
read_resource passed comp=0 to f.read() and returned 0 bytes.
TEXT/TEXD resources are stored this way in both retail chunks.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant