Skip to content

KFUS: File Checksum Algorithm

IvanDSM edited this page Dec 4, 2020 · 1 revision

King's Field uses a custom checksum system to check for file integrity in each of the files contained in its .T data archives. Each file's checksum is 4 bytes long and is stored at the end of the file's block.

Algorithm

The game's algorithm for calculating a file's checksum is as follows:

  • Declare an unsigned 32-bit integer variable for the checksum. Initialize it with 0x12345678 (yes, really).
  • Interpret every 4 bytes of the file as an unsigned 32-bit integer and add it to the checksum variable.
  • Profit.

Keep in mind that since King's Field is a PlayStation game, the files are stored in little-endian byte order.

Implementing

A simple 36 line long C++/Qt version of this algorithm is implemented in checksum_tool. It can also be represented in pseudocode as follows:

uint32 CheckSum = 0x12345678
while (not file.atEnd):
    CheckSum += file.readUInt32()

Clone this wiki locally