Last active
September 24, 2018 02:12
-
-
Save 3096/aa19f0ed5b089bc968a7a2f1793e9882 to your computer and use it in GitHub Desktop.
Fix Splatoon 2 save file CRC in the header (for plaintext body)
This file contains hidden or 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 zlib | |
import struct | |
import os | |
import sys | |
DEFAULT_FILENAME = "save.dat" | |
def fixcrc(fileName): | |
HEADER_SIZE = 0x10 | |
FOOTER_SIZE = 0x30 | |
BODY_SIZES = [0x483A0, 0x86800, 0x88D50] | |
HASH_OFFSET = 0x8 | |
if not os.path.isfile(fileName): | |
print "Cannot access file", fileName | |
return | |
file_body_size = os.path.getsize(fileName) | |
if file_body_size-HEADER_SIZE not in BODY_SIZES: | |
file_body_size = file_body_size - FOOTER_SIZE | |
if file_body_size-HEADER_SIZE not in BODY_SIZES: | |
print "The save data size (", hex(file_body_size), ") is incorrect." | |
return | |
with open(fileName, mode='r+') as file: | |
file.seek(HEADER_SIZE, 0) | |
hashValue = zlib.crc32(file.read(file_body_size)) & 0xffffffff | |
hashValueLE = struct.pack('<I', hashValue) | |
file.seek(HASH_OFFSET, 0) | |
file.write(hashValueLE) | |
print "CRC has been set to", hashValueLE.encode('hex') | |
if len(sys.argv) > 1: | |
fixcrc(sys.argv[1]) | |
else: | |
fixcrc(DEFAULT_FILENAME) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment