DXT1_FORMAT = 13
DXT3_FORMAT = 14
DXT5_FORMAT = 15
def generate_VTF72_hash(file_path ) -> str:
file_size = os.path.getsize( file_path )
with open(file_path, "rb") as file:
data = file.read(80)
sig = data[0:4]
major_ver = int.from_bytes(data[4:8], "little")
minor_ver = int.from_bytes(data[8:12], "little")
header_size = int.from_bytes(data[12:16], "little")
pfFlags = int.from_bytes(data[20:24], "little")
mipmap_count = int.from_bytes(data[56:57], "little")
lowWidth = int.from_bytes(data[61:62], "little")
lowHeight = int.from_bytes(data[62:63], "little")
dwWidth = int.from_bytes(data[16:18], "little")
dwHeight = int.from_bytes(data[18:20], "little")
highres_format = int.from_bytes(data[52:56], "little")
act_width = ( dwWidth / 4 )
act_height = ( dwHeight / 4 )
mipsize = int( act_width * act_height )
if highres_format == DXT1_FORMAT:
mipsize *= 8
elif highres_format == DXT5_FORMAT:
mipsize *= 16
with open(file_path, "rb") as file:
file.seek(file_size - mipsize)
data = file.read(mipsize)
hash_value = xxhash.xxh3_64(data).hexdigest()
return hash_value.upper()```
Some inspiration for your implementation @old halo