2022-01-31 02:11:47 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import argparse
|
|
|
|
import hashlib
|
|
|
|
import os
|
|
|
|
|
|
|
|
os.chdir(os.path.dirname(__file__) + "/..")
|
|
|
|
|
|
|
|
def hash_bytes(b):
|
2022-06-12 11:15:02 +00:00
|
|
|
return f"0x{hashlib.sha256(b).hexdigest()[:8]}"
|
2022-01-31 02:11:47 +00:00
|
|
|
|
|
|
|
def hash_file(filename):
|
|
|
|
with open(filename, "rb") as f:
|
|
|
|
return hash_bytes(f.read())
|
|
|
|
|
|
|
|
def main():
|
|
|
|
p = argparse.ArgumentParser(description="Checksums source files")
|
|
|
|
p.add_argument("list_file", metavar="LIST_FILE", help="File listing all the files to hash")
|
|
|
|
p.add_argument("extra_file", metavar="EXTRA_FILE", help="File containing extra strings to be hashed")
|
|
|
|
args = p.parse_args()
|
|
|
|
|
2022-06-12 11:15:02 +00:00
|
|
|
with open(args.list_file, encoding="utf-8") as f:
|
2022-01-31 02:11:47 +00:00
|
|
|
files = f.read().splitlines()
|
|
|
|
with open(args.extra_file, "rb") as f:
|
|
|
|
extra = f.read().splitlines()
|
|
|
|
hashes_files = [hash_file(file) for file in files]
|
|
|
|
hashes_extra = [hash_bytes(line) for line in extra]
|
|
|
|
hashes = hashes_files + hashes_extra
|
|
|
|
print("""\
|
|
|
|
#include <engine/client/checksum.h>
|
|
|
|
|
|
|
|
void CChecksumData::InitFiles()
|
|
|
|
{
|
|
|
|
""", end="")
|
2022-06-12 11:15:02 +00:00
|
|
|
print(f"\tm_NumFiles = {len(hashes_files)};")
|
|
|
|
print(f"\tm_NumExtra = {len(hashes_extra)};")
|
2022-01-31 02:11:47 +00:00
|
|
|
for i, h in enumerate(hashes):
|
2022-06-12 11:15:02 +00:00
|
|
|
print(f"\tm_aFiles[0x{i:03x}] = {h};")
|
2022-01-31 02:11:47 +00:00
|
|
|
print("}")
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|