Nenkai / FF16Tools

Tools for Final Fantasy XVI / 16.
MIT License
39 stars 4 forks source link

Some corrections #1

Closed yretenai closed 2 months ago

yretenai commented 2 months ago

https://github.com/Nenkai/FF16Pack/blob/ef67bbea9981159a38549f0c2cb7feb25808b7d9/FF16PackLib/FF16Pack.cs#L297-L327

The logic in this is just mixed boolean obfuscation caused by the DRM.

(u64s[0] ^ ~u64s[0]) & value is essentially 0xFFFFFFFF.... & value

The entire operation can be simplified as u64s[0] ^= value, same with the other branches.

The two byte branch is (ushort)(~u16s[0] ^ (u16s[0] ^ ~u16s[0]) & 0x7DB1) is equivalent to u16s[0] ^ 0x7DB1 ^ 0xFFFF (aka u16s[0] ^= 0x824E)

https://github.com/Nenkai/FF16Pack/blob/ef67bbea9981159a38549f0c2cb7feb25808b7d9/FF16PackLib/FF16PackFile.cs#L36-L38

is

    public uint FileNameHash { get; set; } // FNV1(fileName.ToLower())
    public uint Checksum { get; set; } // FNV1(data)
    public uint Reserved { get; set; }
    public uint UnknownGDeflateRelated { get; set; } // seems to be the size of chunk header

(GDeflateNet should now also have fixed DLLs)

Nenkai commented 2 months ago

Thanks for the info (& looking into GDeflateNet). The checksum ended up being a simple CRC, support for hash checking has been added in 0b0637a5

I'll see if i can swap to GDeflateNet (though ideally it should be available as a NuGet package)