Skip to content

Instantly share code, notes, and snippets.

@LiEnby
Created February 18, 2023 08:07
Show Gist options
  • Save LiEnby/8db42e3e6f6618c8130706ea08c9f5ed to your computer and use it in GitHub Desktop.
Save LiEnby/8db42e3e6f6618c8130706ea08c9f5ed to your computer and use it in GitHub Desktop.
Worms 4 Mayhem (PS2) Checksum Calculator
#!/usr/bin/python3
# Worms 4: Mayhem (PS2) Checksum Calculator.
# Created by Li 2/18/2023.
import struct
# Read save file
save = open("BESLES-53096W4MA", "rb").read()
# Set count to 0
cnt = 0
# Get total length
ttl = len(save) - 4
for i in range(0, ttl, 4):
cnt += struct.unpack("i", save[i:i+4])[0]
# Keep only last 32 bits.
chk = cnt & 0xFFFFFFFF
print("Chk "+ hex(chk))
# Recalcuate save but with new checksum
bchk = struct.pack("I", chk)
save = save[:-4]+bchk
# Write new save to disk
open("BESLES-53096W4MA", "wb").write(save)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment