52 lines
2.6 KiB
Markdown
52 lines
2.6 KiB
Markdown
# TEXT chunk (textures)
|
||
|
||
Source: groove.exe `FUN_004067b0` (size pass), `FUN_004071d0` → `FUN_00406880` (palettes),
|
||
`FUN_00406ab0` (pages), `FUN_00406a10` (RLE), `FUN_00406d30` (texture list),
|
||
`FUN_00406e40` (texture animations), `FUN_00407240`/`FUN_00408470` (upload/conversion).
|
||
Tools: `tools/textchunk.py`, `tools/text_export.py`. Parse + rebuild is **byte-identical
|
||
for all level WADs** (the RLE encoder also reproduces the original data exactly).
|
||
|
||
## Layout
|
||
```
|
||
u32 nPal (0 in all WADs)
|
||
nPal × { u32 id, u32 n, u16 colour[n], u8 extra[n] }
|
||
u32 nPages (13–22 per level, all 256×256)
|
||
nPages × { u32 flags, u32 w, u32 h, data }
|
||
flags == 0 : w·h bytes (8 bit, palette) – unused
|
||
flags & 0x80 : u32 length, RLE16 – all original pages
|
||
otherwise : w·h u16 raw
|
||
u32 nTex (~180–1260)
|
||
nTex × 8 bytes { u16 flags, u8 page, u8 clut(0xff), u8 x0, u8 x1, u8 y0, u8 y1 } (edges inclusive)
|
||
u32 nAnim
|
||
nAnim × { u16 texIndex, u8 type, payload per type }
|
||
type 1,2 : 3 bytes type 7,9 : u16,u16,u8,u8
|
||
type 8 : u8, u8 nFrames, u8, nFrames × u16 texIndex (flipbook)
|
||
type 10,11: u8,u8,u8,u8 n, n × u16 texIndex
|
||
```
|
||
RLE16: sequence of s16 n; n>0 → n literal u16; n<0 → next u16 repeated (−n) times.
|
||
|
||
## Pixels
|
||
16 bit **PS1 order**: bits 0–4 R, 5–9 G, 10–14 B, bit 15 = STP.
|
||
`0x0000` = transparent (the converter writes 0 for pixel 0, everything else is converted).
|
||
STP=0 with colour≠0 occurs on pages with a blend mode (semi-transparent pixels).
|
||
Export: alpha 0 = 0x0000, alpha 128 = STP 0, alpha 255 = STP 1.
|
||
|
||
Page flags & 0x7f = format/blend class (table 0x570370, 0x20 bytes each):
|
||
1 = opaque, 2 = own converter (0x409640), 3 = opaque+flag, 4/7 = alpha (blend 1),
|
||
5 = blend 3, 6 = same as 1. (Modes 1/2/3 ≈ PS1 semi-transparency modes; details open.)
|
||
|
||
## Texture list
|
||
Model faces (TRAK/STPC, face+8 u16) reference an index into the texture list;
|
||
entry = rectangle on a page. `flags` low byte 4/5/6/0xc6, high byte 1/4/17/20/36/…
|
||
(meaning open; probably blend/size class). For replacing: leave the list unchanged
|
||
and only swap pixels in the pages → no cross references affected.
|
||
|
||
## Export / replace
|
||
```
|
||
text_export.py export level.wad folder # pageNN_fXX.png + texinfo.txt (≈370 KB per level)
|
||
text_export.py import level.wad folder new.wad
|
||
```
|
||
Import only changes pixels whose RGBA differs from the export → unchanged pages stay
|
||
bit-exact. Size must stay 256×256. Appending new pages/textures is possible
|
||
(increase nTex/nPages), but then faces in TRAK/STPC must use the new indices.
|