Retroarch Save Data Management with Git
A few days ago I lost half the progress in The Legend Of Zelda: The Minish Cap due to an error while checking an old save state.
Let’s say I was on point B (almost at the end of the game) and I wanted to check something from point A (50% of the game). To do so, I restored that save and when I finished, I pressed the rewind button on the emulator to undo the changes. After that, I saw I was back on point B, so I closed the emulator because I was done playing for that day.
What was the mistake then? Well, when a savestate is restored, the SRAM / EEPROM of the game is overwritten. However, when you press the rewind button, the emulator “visually” behaves like an old VHS but never undoes any SRAM overwrite.
After beating the game, I thought it would be great if any Version Control System could be applied to game saves.
- A normal person: "Just take backups, lol".
The problem with backups is that if you want to store more info than a simple timestamp, you have to keep track of which file name corresponds to which description about the save state. All of that is solved in a elegant way by using Git and commit messages.
So I decided to set up a Git repository that acts as a game save database to never lose a big part of the progress again.
Setting up a Git Repository§
On the server§
I will create a repository on a dedicated server because I want to synchronize the game saves with all of my computers running RetroArch, but you also can set it up on the same machine. In my case I will name the repository "srm-db" so the folder I need to create in the server is "srm-db.git"
# Change to a directory you have write permissions
&&
# Then we have to initialize our repository
On the first client§
&&
Then, initialize the local git repository and point it to the remote repository on the server:
# Now we can check if the remote repository was set up properly with:
# Finally set master branch as upstream branch:
Now you will be able to make commmits an push them to the remote repository.
On successive clients§
Clone the repository and everything will be ready.
Using the DB with RetroArch§
The emulator frontend that I use to play old games is called RetroArch. This software is highly customizable. By pressing the F5 key, you will switch from the XMB (PS3-alike) interface to a GUI in which is easier to change settings.
Selecting View -> Settings -> Directory will open the following window:
In the 'Savefile' text box put the path to the git repository. After that, all the '.srm' files will be stored in the repository.
Commiting changes into the repository§
Because we are using git, updating a save file is as easy as making a git commit.
The moment we press 'Close content' the SRAM is overwritten. Now we just have to add the files into the staging area, create a commit and push it to the remote repository.
If you want to insert more than one line, instead of closing the message with a quotation mark, press enter and you will be able to insert more lines. To end the message, insert a quotation mark at the end of the last line.
This is a structure I like to follow in order to categorize games:
To conclude§
If you use a GUI to manage the Git repository, you can get a result similar to this:
For me, this has helped me to keep track of the progress of the games I play (on emulators) and keep each save organized. If you find this post useful or your approach to solve this problem is completely different, feel free to contact me on social networks.
Have a nice day!