Skip to content

Instantly share code, notes, and snippets.

@apocalyptech
Created May 16, 2024 19:14
Show Gist options
  • Save apocalyptech/1c53fb0fdc65e812a62ff415bca32c0c to your computer and use it in GitHub Desktop.
Save apocalyptech/1c53fb0fdc65e812a62ff415bca32c0c to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# vim: set expandtab tabstop=4 shiftwidth=4:
import struct
# My seemingly-known room row start
start = 0x628C
# Rows to fill in
rows = 24
# How far up to fill in rows
row_offset = -11
# Amount of data in each row
row_data_len = 5*22*20
###
###
###
offset = start + (row_offset*row_data_len)
bytes_to_write = rows*row_data_len
print(f'Writing {rows} row(s) starting at offset 0x{offset:X} for length {bytes_to_write}')
with open('AnimalWell.sav', 'r+b') as df:
df.seek(offset)
for _ in range(bytes_to_write):
df.write(b'\xFF')
print(f'... ended at 0x{df.tell():X}')
# Rather sick of doing this manually...
print('Also turning off scanlines...')
df.seek(0x75048)
df.write(b'\12')
# Fix checksum
df.seek(0)
data = df.read()
total = 0
for byte in data[:13] + data[14:]:
total ^= byte
if total == data[0xD]:
print(f'No need to write checksum -- 0x{total:02X} is already correct')
else:
packed = struct.pack('<B', total)
df.seek(0xD)
df.write(packed)
print(f'Wrote new checksum 0x{total:02X} (previous: 0x{data[0xD]:02X})')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment