Skip to content

Instantly share code, notes, and snippets.

@RenolY2
Last active January 18, 2017 20:38
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save RenolY2/e0d93dde832b63f9197ef60861f22d89 to your computer and use it in GitHub Desktop.
Calculates checksum for a pikmin 2 save file entry
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