MechanicaSaveFix, a BepInEx mod that replaces Mechanica’s save system with a single archive per world.
Demo video : https://youtu.be/NF6xDftQVgA
This isn’t my first time getting into this game! I’ve been trying things out, doing little tweaks, etc. on the game for years now. But this is my first and biggest completed project aimed at modding this game!
There are no resources online about the game’s structure, how it works, etc. So I spent way more time searching and understanding than actually coding! Working without documentation is really annoying :)
My goal here is to get a big Blåhaj! Will I pull it off? I don’t know…
The problem?
Mechanica saves every object, robot, weld, link, etc. into its own little file, stored in nested folders. A small test world already makes hundreds of folders, and large worlds reach thousands of files. On large worlds, you run into what I call “Infinite Save Loading” (ISL). The save never finishes, you have to restart the game, and you lose your progress. I suspect the number of files is the cause, but I haven’t proven it, because these freezes are very hard to reproduce.
However, during my testing, I didn’t have the issue. So at best, it improves things! Which is already pretty neat :3
What does the mod do?
The mod doesn’t rewrite the game’s save system, which wasn’t designed to be replaced. It sits on top of it:
It intercepts the game’s calls to files (File, Directory, FileInfo, DirectoryInfo) using Harmony;
It redirects them to a Virtual File System (VFS) that keeps everything in memory;
It then writes the result into a single .msa (Mechanica Save Archive) file, which is actually a zip containing the original files and folders.
The game therefore continues to believe it is writing thousands of small files, while it is actually writing only one file to disk. On the first save, a classic world is converted to .msa. The original folder is not touched, and you can extract the archive to get back a standard save.
I also rewrote the world selection menu (it lists classic folders and archives) and the world creation flow. I added a confirmation window, a config file, a backup system, and an optional update check.
Difficulties encountered:
- No centralized save code. Every system (objects, robots, welds, storage, links…) reads and writes its files in its own way. There was no single place to hook into;
- Incremental saving and cleanup. The game only rewrites what has changed, then deletes any file absent from its list of valid paths, compared as exact strings. The mod must therefore keep everything in memory and reproduce paths identically: mix of / and , case, spaces. Early on, a bug like this caused all files to be deleted by cleanup;
- Not everything goes through File/Directory. Some parts of the code use FileInfo/DirectoryInfo, which had to be intercepted separately;
- Implicitly created folders. The game checks for the existence of folders that are sometimes legitimately empty. After a bug where object categories were duplicated on every reload, I added explicit folder tracking in the VFS, with entries for empty folders in the archive;
- A very tangled save menu. It relies on dictionaries indexed by UI objects, with a large part of the interface hardwired in the Unity editor, so invisible in decompiled code. I had to inspect the layout at runtime and rewrite the menu entirely;
- Architecture issues. It took me a while to decide where to place the world swap function (it’s in the VFS).
- I think I didn’t forget anything :/
Unfortunately, I admit, this is just a band-aid on a gaping wound. It only improves or at best delays the problem. Not to mention the fact that other things like the game’s multiplayer are still completely broken ¯_(ツ)_/¯