import hashlib

print("=== FolderMill 5.5 Patcher ===")
target_file = "FolderMill Processor.exe"
expected_hash = "741392E3F07EB9437EF2CC3F27D19EB88340B28845BAA37CF6B7AF04BC3438C2"
patch_offset = 0x269C
original_byte = b'\x17'
patch_byte = b'\x16'

with open(target_file, "rb") as f:
    file_data = f.read()
    file_hash = hashlib.sha256(file_data).hexdigest()

if file_hash.upper() != expected_hash:
    print("File hash does not match! Aborting patch.")
    exit(1)

if file_data[patch_offset:patch_offset+1] != original_byte:
    print(f"Byte at offset {hex(patch_offset)} is not {original_byte.hex()}. Nothing patched.")
    exit(1)

file_data = file_data[:patch_offset] + patch_byte + file_data[patch_offset+1:]

with open(target_file, "wb") as f:
    f.write(file_data)

print(f"File patched successfully at offset {hex(patch_offset)}!")
