44 lines
894 B
Python
44 lines
894 B
Python
#!/usr/bin/env python3
|
|
import sys
|
|
|
|
# Rango del checksum
|
|
desp = 0x2000
|
|
numBytes = 0x2000
|
|
firstByte = desp + 0x200
|
|
lastByte = desp + numBytes - 1
|
|
checksum1 = desp + 0x270
|
|
checksum2 = desp + 0x271
|
|
|
|
# Offset del contador de armarios
|
|
CONTADOR = 0x0295C
|
|
|
|
def calc_checksum(buffer):
|
|
total = 0
|
|
for i in range(firstByte, lastByte + 1):
|
|
if i not in (checksum1, checksum2):
|
|
total += buffer[i]
|
|
total += 3328
|
|
buffer[checksum1] = total % 256
|
|
buffer[checksum2] = (total >> 8) % 256
|
|
|
|
if len(sys.argv) != 3:
|
|
print("Uso: python3 set_contador_armarios.py save_in.srm save_out.srm")
|
|
sys.exit(1)
|
|
|
|
infile = sys.argv[1]
|
|
outfile = sys.argv[2]
|
|
|
|
with open(infile, "rb") as f:
|
|
buf = bytearray(f.read())
|
|
|
|
# Poner el contador a 0x80
|
|
buf[CONTADOR] = 0x4F
|
|
|
|
# Recalcular checksum
|
|
calc_checksum(buf)
|
|
|
|
with open(outfile, "wb") as f:
|
|
f.write(buf)
|
|
|
|
print("Hecho:", outfile)
|