Page 1 of 1

[Q4] Checksum calculation?

Posted: Sat May 27, 2006 12:11 pm
by Foo
Trying to calculate the checksum for PK4s manually (in PHP) but can't find any information on the kind of crc check which Q4 performs.

It's not crc32, I get a different checksum than Q4 gets with the 'path' command on the same file.

Any ideas?

Posted: Tue Oct 03, 2006 2:20 pm
by kaffeedoktor
Maybe I replay a bit late, but the checksum used to identify PK4s is an MD5, which you can create in PHP using the md5_file( ) method.

Posted: Tue Oct 03, 2006 2:22 pm
by Foo
The MD5 output I'm familiar with is a 128-bit hash, whereas the checksums listed for quake 4 are in the format 0xAC34CA, and soforth?

Posted: Tue Oct 03, 2006 2:42 pm
by kaffeedoktor
Sorry, I got sth wrong.

For ingame usage Q4 uses an 8 byte MD5 blockchecksum, which is build as:

val = digest[0] ^ digest[1] ^ digest[2] ^ digest[3];

(that's code from idlib, val & digest are unsigned long values).

E.g. a 32 byte MD5 0x0123456789ABCDEF0123456789ABCDEF will get split into

0x01234567, 0x89ABCDEF, 0x01234567, 0x89ABCDEF

These 4 parts will are used to calculate the resulting 8-byte blockchecksum using the OR operation.