Prelude
Hi, everyone. I want to be super clear up front: I do not currently have an issue, and I am not seeking an answer to any question. What I would like to do is document a large problem I discovered and how I solved it. I did extensive searching while trying to find a resolution, and either no one has run into the problem before (doubtful), or a certain past bug in the engine itself is “clogging” up the google search results, making it difficult to discover the discussion history of my actual problem.Mods, if I’ve misunderstood where a thread such as this should go, apologies, but this seemed like the most appropriate place.
So, without further ado…
The Problem
A few weekends ago, I attempted to turn Steam Auto-Cloud on for my in-development game. From reading the Steam documentation, it seemed pretty straightforward. RPG Maker MZ stores its save files in the save directory under the root project, and all of those files have the.rmmzsave suffix. There’s global.rmmzsave, config.rmmzsave, and then a bunch of files corresponding to numbered save slots, file#.rmmzsave. I added a Steam Auto-Cloud rule to sync all files in the save directory that end in .rmmzsave, and I figured that was a wrap.It was not.
If you watch the Steam console when exiting the game, you’ll get a message like this:
Upload I/O Operation Failed for file save/file1.rmmzsave src\clientdll\remotestoragefilesynccontext.cpp (288) : Assertion Failed: Failed to read file 'save/file1.rmmzsave' for upload (2)Further, the Steam client will indicate a “cloud desync” error, and hitting the retry button won’t resolve the issue.
Interestingly, I started playing around with specifying rules on file-by-file basis, and
config.rmmzsave would sync with Auto-Cloud, along with a custom file I’m generating as part of a custom feature I wrote, but global and the save files won’t… which kind of defeats the whole point.The Search
My attempts to find out who had done what with RPG Maker MZ and Steam Auto-Cloud were thwarted when using both this forum’s search feature and Google. The problem is that, at some point in the past, the RPG Maker engine itself utilized Steam Cloud for backing up game projects, and this led to a bunch of frustration on these forums and, it seems in some cases, weeks or months of lost work. As a result, searches for anything with “steam cloud” in the key words turns up all these grievances, which are unrelated to my issue of setting up Steam Cloud to work with save files for my game.If anyone has posted on this forum before about how to solve Steam Auto-Cloud backup of save files for RPG Maker games, I couldn’t find it. The closest I got was this reference on Reddit to someone saying they “read somewhere” that RPG Maker games can’t use Steam Cloud.
Well, if that’s true, then I’ve figured out a thing that Omori devs didn't, so there’s a feather in my cap for sure.
The Solution
After hours of fighting with Auto-Cloud, I decided to see if I could make a manual implementation work and was eventually successful. I discovered that you can manually sync files to the Steam Cloud using Greenworks. I had already spent a weekend some months ago pulling my hair out in order to get Greenworks properly integrated into my game project so that I could support Steam achievements. My description of the solution will assume that Greenworks is integrated already.- Upload save files to the cloud whenever StorageManager.fsWriteFile is called. This is the function that is invoked whenever any file in the save directory is written to. You want to wire up
greenworks.saveFilesToCloudto this function so that whenever your game changes a save file, that file gets synced to the cloud. - Update Scene_Boot to include an additional pre-load step. This is a manual implementation, and so we will need to check the Steam Cloud at application start up and see if we need to download any files. I hooked into
Scene_Boot.prototype.isReadyand added a check to ensure that all my synced files had completed their download callbacks before proceeding. - Update Scene_Boot to walk the list of cloud files and update local files with anything missing from the list. For this you need two Greenworks functions:
greenworks.getFileCountandgreenworks.getFileNameAndSize. Use the number you get from the file count to iterate overgetFileNameAndSize. Wire this into the previous step, so thatScene_Bootdoesn’t proceed until everything is in sync. - Turn off save file compression. Unfortunately, Greenworks doesn’t support reading and writing binary data, only text. RPG Maker MZ compresses save files with gzip by default, which is a binary format. Saving and writing the files as text will make them incompatible with the editor. And so, in order to make this work, that feature had to go. The simplest way to achieve it is to overwrite
StorageManager.jsonToZipandStorageManager.zipToJsonso that they are merely pass-throughs (e.g. they just receive the text data and return it without compressing it). This increased save file size about 9x in my project, but save files are relatively small. Even for a mid-game save, I’m still only in the 500k range. This does also make the save files trivial to hack, but we’re largely not making multiplayer or tournament-type games here, so this seems like an acceptable solution. It certainly is for my project. - Finally, use greenworks.readTextFromFile to get the contents of any files that are missing and write the file (or files) using RPG Maker's StorageManager.saveToLocalFile. There's a bit of callback hell that has to be endured here, because they are asynchronous calls, but the end result works.
Closing Thoughts
I thought that turning on Steam Auto-Cloud would be a really simple process, but it wasn’t. Building a manual Steam Cloud solution ended up taking a whole weekend. I hope this post helps someone else save some time.I’d be curious to know: a) if anyone knows why Steam Auto-Cloud fails to sync RPG Maker save files; and b) if anyone has come up with any solution before, either similar to mine or different from it.
If anyone wants more detail on the code that does this, I’d be happy to oblige. I think some might also be interested in a write up of all the work it took to get Greenworks integrated. That’s a separate topic, but I’m happy to start another thread if there’s interest.