Difference between revisions of "Hey! Pikmin save file"

From Pikmin Technical Knowledge Base
Jump to navigation Jump to search
(Better offsets.)
(→‎Checksum: add info on the checksum algorithm)
Line 199: Line 199:
  
 
== Checksum ==
 
== Checksum ==
Although the checksum is unknown, it's known that it's NOT the following:
+
The checksum seems to be a CRC32 of the 0xd87 bytes that follow after the checksum (i.e. just one byte short of the entire remaining data), with crc32 as implemented by e.g. zlib.
  
* CRC32 of:
+
The following python code can recalculate the checksum if the data after the checksum is modified:
** The bytes after the checksum.
+
import struct
** The bytes before and after the checksum.
+
from zlib import crc32
** The bytes after the checksum, but excluding section start magic words.
+
** The bytes before and after the checksum, but excluding section start magic words.
+
filepath = "radish0.sav"  # put the script in the same folder as the save file
* SHA1 of the previous.
+
with open(filepath, "rb") as f:
* MD5 of the previous.
+
    header = f.read(0xC)
 +
    chksum = struct.unpack("I", f.read(4))[0]
 +
   
 +
    data = f.read()
 +
 +
calculated_chksum = crc32(data[0:0xd87])
 +
with open(filepath, "wb") as f:
 +
    f.write(header)
 +
    f.write(struct.pack("I", calculated_chksum))
 +
    f.write(data)
  
 
[[Category:File formats]]
 
[[Category:File formats]]
 
[[Category:Hey! Pikmin]]
 
[[Category:Hey! Pikmin]]

Revision as of 15:45, 26 November 2017

This article is a stub.

The file format for a Hey! Pikmin saved game. Note: this comes from analyses of the .sav files generated by Citra.

Format

The save data is split into several blocks that start with 4-byte magic words.

SAVE

Offset Length Field Notes
File Block
0000 0000 4 bytes Block magic word Always SAVE.
000C 000C 4 bytes Save data checksum Calculated using an unknown algorithm.[unsure]

NEWS

Offset Length Field Notes
File Block
0010 0000 4 bytes Block magic word Always NEWS.

OPTI

Offset Length Field Notes
File Block
0020 0000 4 bytes Block magic word Always OPTI.
0028 0008 1 byte Music volume 01, 02, or 03.

PBUF

Offset Length Field Notes
File Block
002C 0000 4 bytes Block magic word Always PBUF.

PARK

Offset Length Field Notes
File Block
0080 0000 4 bytes Block magic word Always PARK.

MINI

Offset Length Field Notes
File Block
04A4 0000 4 bytes Block magic word Always MINI.

CRNT

Offset Length Field Notes
File Block
0588 0000 4 bytes Block magic word Always CRNT.

GAME

Offset Length Field Notes
File Block
09A8 0000 4 bytes Block magic word Always GAME.

EVNT

Offset Length Field Notes
File Block
09E0 0000 4 bytes Block magic word Always EVNT.

HELP

Offset Length Field Notes
File Block
0AE8 0000 4 bytes Block magic word Always HELP.

RINF

Offset Length Field Notes
File Block
0BF0 0000 4 bytes Block magic word Always RINF.

RSLT

Offset Length Field Notes
File Block
0C2C 0000 4 bytes Block magic word Always RSLT.

SPER

Offset Length Field Notes
File Block
0C38 0000 4 bytes Block magic word Always SPER.

STRE

Offset Length Field Notes
File Block
0C48 0000 4 bytes Block magic word Always STRE.

PLRP

Offset Length Field Notes
File Block
0C90 0000 4 bytes Block magic word Always PLRP.

DATE

Offset Length Field Notes
File Block
0CE0 0000 4 bytes Block magic word Always DATE.

TTDS

Offset Length Field Notes
File Block
0CFC 0000 4 bytes Block magic word Always TTDS.

WMAP

Offset Length Field Notes
File Block
0D08 0000 4 bytes Block magic word Always WMAP.

SAMI

Offset Length Field Notes
File Block
0D80 0000 4 bytes Block magic word Always SAMI.

Checksum

The checksum seems to be a CRC32 of the 0xd87 bytes that follow after the checksum (i.e. just one byte short of the entire remaining data), with crc32 as implemented by e.g. zlib.

The following python code can recalculate the checksum if the data after the checksum is modified:

import struct
from zlib import crc32

filepath = "radish0.sav"  # put the script in the same folder as the save file
with open(filepath, "rb") as f:
    header = f.read(0xC)
    chksum = struct.unpack("I", f.read(4))[0]
    
    data = f.read()

calculated_chksum = crc32(data[0:0xd87])
with open(filepath, "wb") as f:
    f.write(header)
    f.write(struct.pack("I", calculated_chksum))
    f.write(data)