Last active
January 18, 2017 20:38
Calculates checksum for a pikmin 2 save file entry
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import struct | |
import sys | |
""" | |
Extract Pikmin 2 save in dolphin as .gci, open gci in a hex editor | |
and search for string "PlVa" which signals the start of a save file. | |
Starting with the first symbol of the string, select 0xC000 bytes | |
and copy it into a separate file. Use this script with that file. | |
""" | |
try: | |
# Usage: python calc_pikmin2_checksum.py <file> | |
infile = sys.argv[1] | |
except Exception as er: | |
raise RuntimeException("Not enough arguments: {0}".format(sys.argv)) | |
print(infile) | |
with open(infile, "rb") as f: | |
data = f.read() | |
c1 = c2 = 0 | |
for i in range(0, len(data)-4, 2): | |
val1 = data[i] | |
val2 = data[i+1] | |
val = (val1 << 8) + val2 | |
if True: | |
c1 = (c1 + val) & 0xFFFF | |
c2 = (c2 + (val ^ 0xFFFF)) & 0xFFFF | |
if c1 == 0xFFFF: c1 = 0 | |
if c2 == 0xFFFF: c2 = 0 | |
# These two values together form the checksum for the save data. | |
# Replace the checksum in the save data with these. | |
print(hex(c1), hex(c2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment