mGBA Forums
Save State Information - re: compression, etc. - Printable Version

+- mGBA Forums (https://forums.mgba.io)
+-- Forum: mGBA (https://forums.mgba.io/forumdisplay.php?fid=1)
+--- Forum: General (https://forums.mgba.io/forumdisplay.php?fid=3)
+--- Thread: Save State Information - re: compression, etc. (/showthread.php?tid=5624)



Save State Information - re: compression, etc. - wuvo - 09-14-2023

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.


RE: Save State Information - re: compression, etc. - endrift - 09-14-2023

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/master/include/mgba/internal/gb/serialize.h
GBA: https://github.com/mgba-emu/mgba/blob/master/include/mgba/internal/gba/serialize.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/master/src/core/serialize.c, and the list of tag types is at the top of this file: https://github.com/mgba-emu/mgba/blob/master/include/mgba/core/serialize.h


RE: Save State Information - re: compression, etc. - wuvo - 09-14-2023

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!


RE: Save State Information - re: compression, etc. - Other - 02-26-2024

(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/master/include/mgba/internal/gb/serialize.h
GBA: https://github.com/mgba-emu/mgba/blob/master/include/mgba/internal/gba/serialize.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/master/src/core/serialize.c, and the list of tag types is at the top of this file: https://github.com/mgba-emu/mgba/blob/master/include/mgba/core/serialize.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?


RE: Save State Information - re: compression, etc. - endrift - 02-27-2024

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


RE: Save State Information - re: compression, etc. - Other - 02-27-2024

(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.