CPK

From Spiral Framework
Jump to navigation Jump to search
CPK
Type Archive Format
System Vita & Steam
Applicable Titles Danganronpa: Trigger Happy Havoc (Vita), Danganronpa 2: Goodbye Despair (Vita) Danganronpa AE: UDG (Vita & Steam), Danganronpa V3: Killing Harmony (Vita & Steam)
Credit hcs/utf_tab suite
Default Signedness Unsigned
Default Endianness Big-Endian
Implementation Status Extraction 100%/Compilation 0%

Specification

CPK File
Offset Size Data Type Function Example Value Notes
0x00 4 Bytes String/Data Magic Number CPK or 0x43 0x50 0x4B 0x20
0x10 Varying UTF Table Header Table Can only contain 1 row
Header Table#TocOffset 4 Bytes String/Data Magic Number TOC or 0x54 0x4F 0x43 0x20
Header Table#TocOffset+0x10 Varying UTF Table File Listing
min(Header Table#ContentOffset, HeaderTable#TocOffset) Rest of file Data File data Seek from the smaller of ContentOffset or TocOffset to the file offset per file
UTF Table
Offset Size Data Type Function Example Value Notes
0x00 4 Bytes String/Data Magic Number @UTF or 0x40 0x55 0x54 0x46
0x04 4 Bytes Int Table Size 8784
0x08 4 Bytes Int Rows Offset 63
0x0C 4 Bytes Int String Table Offset 4711
0x10 4 Bytes Int Data Offset 8784
0x14 4 Bytes Int Table Name 7
0x18 2 Bytes Short/Int Columns 7
0x1C 2 Bytes Short/Int Row Width 28
0x20 4 Bytes Int Rows 166
0x24 5-13 Bytes UTF Column Columns
...
String Table Offset Data Offset - String Table Offset + 1 String String Table See String Tables
...
Table offset + 8 + Rows Offset Varying Row Data Rows See Rows
UTF Column
Offset Size Data Type Function Example Value Notes
0x00 1 Byte Byte Column Type
0x01 4 Bytes Int Column Name See String Tables
0x05 Varying Data Column Data Only present if Column Type & 0xF0 == 0xF0; see Rows

String Tables

Instead of using individual string values, CPK files (and UTF tables, more specifically) use a single string with a number of NULL terminators. This one behemoth string contains all the names needed for the values in that table. These tend to be the name of the table, the column names, and things like filenames.

You should be able to obtain the correct string for an index by taking the substring from the provided index, up until the next NULL terminator.

Rows

There are two ways to read the data for a row, depending on the "type" of column the row is for.

If Column Type & 0xF0 == 0xF0, then the data is stored at a constant offset for the column. This offset should be stored when reading the column information.

If this is not the case, as it is for most columns, then the offset for your row is:

tableOffset + 8 + rowsOffset + (i * rowWidth)