Repository navigation
SPR
SPR files are used within Project DIVA games to manage a collection of texture atlases and the individual sub-textures within them, called SCRs. Within Project Mirai these exclusively use single-texture CTPK files, a well documented format shared among many 3DS games.
SPR likely stands for SPRite sheet, while it's unclear what SCR stands for. Possibly Sprite Coordinate Region?
| Offset | Length | Description |
|---|---|---|
0x0 |
0x4 |
Signature 0x00000000
|
0x4 |
0x4 |
Pointer to CTPKs array |
0x8 |
0x4 |
Number of CTPKs |
0xc |
0x4 |
Pointer to CTPK names array (0x20 length allocated strings) |
0x10 |
0x8 |
Padding |
0x18 |
0x4 |
Number of SCRs |
0x1c |
0x4 |
Pointer to SCRs array |
CTPKs are in the standard format described here, except for the 0x4 bytes before the signature which are used as an end-relative pointer to the next CTPK in the array.
| Offset | Length | Description |
|---|---|---|
0x0 |
0x4 |
End-relative pointer to next CTPK |
0x4 |
??? |
CTPK file |
Note that CTPK files within Project Mirai only ever have one texture, so this detail can be used to simplify a Mirai-exclusive CTPK reader.
SCRs are used to define named sub-textures within a single CTPK, creating a texture atlas.
| Offset | Length | Description |
|---|---|---|
0x0 |
0x1 |
CTPK index within the containing SPR |
0x1 |
0x47 |
Name (allocated string) |
0x48 |
0x4 |
Top left U coordinate float (top-left origin) |
0x4c |
0x4 |
Top left V coordinate float (top-left origin) |
0x50 |
0x4 |
Bottom right U coordinate float (top-left origin) |
0x54 |
0x4 |
Bottom right V coordinate float (top-left origin) |
0x58 |
0x2 |
Top left U coordinate in pixels (top-left origin) |
0x5a |
0x2 |
Top left V coordinate in pixels (top-left origin) |
0x5c |
0x2 |
Width in pixels |
0x5e |
0x2 |
Height in pixels |
Note that although UV coordinates are provided, they use a top-left origin, which is opposite to OpenGL's bottom-left origin.
Strings with SPR files are stored within a fixed-length allocated space, surrounded by a variable number of terminator characters on either side. For example:
0000 0000 0000 0000 5350 525f 4145 5f41 ........SPR_AE_A
4456 5f45 5443 415f 3000 0000 0000 0000 DV_ETCA_0.......
The most reliable way to read these is to scan the entire allocated space, and only accept non-terminator characters.