Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Save State Information - re: compression, etc.
#1
Hello,

I'm a hobbyist who enjoys messing with save state data in hex editors, and occasionally writing tools (for Windows) like game editors, save state editors, etc... I downloaded mGBA with the hopes of being able to poke around in the save states of a particular game and write a guide or some software.

However, the save states are compressed, and vary in size - and apparently also contain image data and/or the *.sav file architecture, etc, all within the *.ss* file.

Does anyone know of any documentation regarding the compression methods or any other useful information about the save state architecture? (I've looked through some of the source code on GitHub but haven't found anything useful yet.)

I can't seem to find options to turn off SS compression in mGBA.

Cheers.
Reply

#2
You can turn off save state compression by disabling saving screenshot extra data. When enabled, save states are embedded in custom chunks in PNGs, namely gbAs (main save state) and gbAx (extra data, usually things like metadata, .sav file, etc). These custom chunks are compressed using zlib's default compression. When screenshots are disabled, everything is uncompressed with the raw save state followed by the extra data, as the raw save state is a fixed size based on the platform.

The format of the raw save state is documented in the appropriate header file for the platform in question:

GB: https://github.com/mgba-emu/mgba/blob/ma...erialize.h
GBA: https://github.com/mgba-emu/mgba/blob/ma...erialize.h

All data is stored in little endian byte order (even on the Wii).

The format of the extra data in an uncompressed file, is an array of extdata type, size, and offset into the file. In PNG save states, each datum has its own gbAx chunk, with a 4-byte tag, 4 byte (uncompressed) length, then compressed data.

The relevant code is in this file: https://github.com/mgba-emu/mgba/blob/ma...erialize.c, and the list of tag types is at the top of this file: https://github.com/mgba-emu/mgba/blob/ma...erialize.h
Reply

#3
I had disabled those options and noticed the size increase in the save state, but it seemed to only effect one of the saves - turns out it was just the file details in Explorer not refreshing appropriately... lead me to believe the options weren't having an effect.

Thanks for the fast reply, and appreciate pointing me to the appropriate code.

Nice emulator!
Reply

#4
(09-14-2023, 05:52 AM)endrift Wrote: You can turn off save state compression by disabling saving screenshot extra data. When enabled, save states are embedded in custom chunks in PNGs, namely gbAs (main save state) and gbAx (extra data, usually things like metadata, .sav file, etc). These custom chunks are compressed using zlib's default compression. When screenshots are disabled, everything is uncompressed with the raw save state followed by the extra data, as the raw save state is a fixed size based on the platform.

The format of the raw save state is documented in the appropriate header file for the platform in question:

GB: https://github.com/mgba-emu/mgba/blob/ma...erialize.h
GBA: https://github.com/mgba-emu/mgba/blob/ma...erialize.h

All data is stored in little endian byte order (even on the Wii).

The format of the extra data in an uncompressed file, is an array of extdata type, size, and offset into the file. In PNG save states, each datum has its own gbAx chunk, with a 4-byte tag, 4 byte (uncompressed) length, then compressed data.

The relevant code is in this file: https://github.com/mgba-emu/mgba/blob/ma...erialize.c, and the list of tag types is at the top of this file: https://github.com/mgba-emu/mgba/blob/ma...erialize.h
Hello! I disabled screenshot saving in order to make save states uncompressed, but opening them still shows a bunch of gibberish. Is this because I need to open the .ss files with a hex editor as opposed to something like notepad?
Reply

#5
Yes, the uncompressed savestates are still binary data and not editable with a text editor.
Reply

#6
(02-27-2024, 12:18 AM)endrift Wrote: Yes, the uncompressed savestates are still binary data and not editable with a text editor.

Alright, what would you recommend I use to view/edit them with then? I would like to make a script that can view the data and get certain information.
Reply



Forum Jump:


Users browsing this thread:
2 Guest(s)

Powered By MyBB, © 2002-2024 Melroy van den Berg.