A CityHash (using the old GZ algo) is made from the filename of the LUA file, including file extension. The NOT of this hash is used as the XOR key for the file, the key also changes as the file is decrypted.
Some code I wrote up quick which should explain it better:
Code: Select all
public byte[] DecryptFPKLUAFile(string filePath)
{
var filename = Path.GetFileName(filePath).ToLower();
var hash = HashFileNameLegacy(filename, false);
var key = BitConverter.GetBytes(~hash);
var fileData = File.ReadAllBytes(filePath);
var decData = new byte[fileData.Length - 1];
for(int i = 0; i < fileData.Length - 1; i++)
{
key[i & 7] ^= fileData[i + 1];
decData[i] = key[i & 7];
}
return decData;
}
Going to look into adding this into GzsTool later, AFAIK the reverse isn't needed since the game should run fine with decrypted LUAs.
A lot of these LUAs also mention other FPK filepaths too, so we might have a big update to the dictionary soon
EDIT: Added to my fork, when extracting from an FPK it'll automatically try decrypting any files that look encrypted. You can download it from https://github.com/emoose/GzsTool/relea ... Decryption
EDIT2: Just pushed a quick fix for some files not decrypting properly, grab it from https://github.com/emoose/GzsTool/relea ... Decryption
EDIT3: Another quick fix (hopefully the last!) for QARs not extracting properly: https://github.com/emoose/GzsTool/relea ... Decryption

