You are viewing a potentially older version of this package. View all versions.
RadDude-ModSaveBackups-1.1.1 icon

ModSaveBackups

This Sailwind mod creates separate save files for you mod data and also handles making and loading backups.

Date uploaded a month ago
Version 1.1.1
Download link RadDude-ModSaveBackups-1.1.1.zip
Downloads 141
Dependency string RadDude-ModSaveBackups-1.1.1

This mod requires the following mods to function

BepInEx-BepInExPack-5.4.2100 icon
BepInEx-BepInExPack

BepInEx pack for Mono Unity games. Preconfigured and ready to use.

Preferred version: 5.4.2100

README

ModSaveBackups

Intended to be used mainly by modders as a dependency, but can also be used by players. Incorporates the ModSave class from SailwindModdingHelper by App24 so now this can be more thought of as ModSave with Backups.

Using this mod will allow you to create a save file for you Sailwind mod data separate from the main save file for the game. This mod will also create backups of that mod save file when the game makes backups of the main save file. If you load a backup save then the corresponding backup mod save file will be loaded.

Usage

Make a Serializable save container class to hold the data you wish to save:

[Serializable]
public class ExampleSaveContainer
{
    public Dictionary<string, int> exampleDict;
    public bool exampleBool;
}

Then make a patch to save the data on save and a patch to load the data on load:

[HarmonyPatch(typeof(SaveLoadManager))]
private class SaveLoadManagerPatches
{
    [HarmonyPostfix]
    [HarmonyPatch("SaveModData")]
    public static void DoSaveGamePatch()
    {
        var saveContainer = new ExampleSaveContainer();
        saveContainer.exampleDict = MyModGameObject.instance.exampleDict.ToDictionary(
            entry => entry.Key,
            entry => entry.Value);

        saveContainer.exampleBool = MyModGameObject.instance.exampleBool;
    }

    [HarmonyPostfix]
    [HarmonyPatch("LoadModData")]
    public static void LoadModDataPatch()
    {
        if (!ModSave.Load(Plugin.instance.Info, out ExampleSaveContainer saveContainer))
        {
            Plugin.logger.LogWarning("Save file loading failed. If this is the first time loading this save with this mod, this is normal.");
            return;
        }

        if (saveContainer.portBadges != null)
        {
            LoadDictionary(saveContainer.portBadges, PortsVisitedUI.instance.portBadges);
            foreach (KeyValuePair<string, int> item in saveContainer.exampleDict)
            {
                if (MyModGameObject.instance.exampleDict.ContainsKey(item.Key))
                {
                    MyModGameObject.instance.exampleDict[item.Key] = item.Value;
                    continue;
                }
                Plugin.logger.LogWarning($"LoadData: {item.Key} not found in game");
            }
        }

        if (saveContainer.exampleBool != null)
            MyModGameObject.instance.exampleBool = saveContainer.exampleBool
    }
}

Requires

Installation

Place the ModSaveBackups.dll into the Sailwind/BepInEx/Plugins folder.

CHANGELOG

Changelog

All notable changes to this project will be documented in this file.

[v1.1.1] - 2025-02-27

Added

Removed

  • Dependency on SailwindModdingHelper

Updated

  • icon

[v1.0.2] - 2024-09-20

Updated

  • SailwindModdingHelper dependency version to 2.1.1

[v1.0.1] - 2024-09-06

Fixed

  • Bug where continuing from a backup and then saving saves over that backup instead of saving a current save

[v1.0.0] - 2024-09-06

Added

  • Backup creation for ModSave files
  • Loading of backup ModSave file when backup save slot loaded