LazyDuchess-SaveDataAPI icon

SaveDataAPI

API that allows modders to more easily save and load custom data associated to save slots, without breaking compatibility.

Last updated 2 years ago
Total downloads 679
Total rating 0 
Categories Libraries
Dependency string LazyDuchess-SaveDataAPI-1.0.1
Dependants 0 other packages depend on this package

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

BRC-SaveDataAPI

API for saving and loading custom mod data from save slots in Bomb Rush Cyberfunk.

This lets you have custom saved data per savegame which works just like normal save data, autosaved in a different thread and using the game's platform specific API, allowing for cloud saving on Steam and such.

To build the project, Assembly-CSharp.dll from Bomb Rush Cyberfunk must be placed in a "lib" directory. Uses BepinEx and Harmony.

How to use

Simply add this assembly as a reference and dependency in your BepinEx project, then create a class that inherits from SaveDataAPI.ADataSaver. This class will be instantiated with the default constructor everytime content is saved to and loaded from a savegame slot, so make sure all default values are set how you'd like them to be on a fresh save.

From there you have a few methods you can override:

PrepareSave()

This method gets called on the main thread prior to writing the save file. Here you're meant to copy any variables you need to write to the save file into the ADataSaver object.

Example:

private int _somethingToSave = 0;

public override void PrepareSave()
{
  _somethingToSave = ObjectToSave.Get().SomethingToSave;
}

Write()

This method gets called on the storage thread after PrepareSave(), and is what actually writes to the file. Here you can use the passed BinaryWriter to serialize your content.

Example:

public override void Write(BinaryWriter writer)
{
  writer.Write(_somethingToSave);
}

Read()

This method gets called on the storage thread prior to OnLoad(), and is what actually reads from the file. Here you can use the passed BinaryReader to deserialize your content and read it into the ADataSaver object. Make sure you write a version and make checks in case you end up updating your mod and changing the content it saves.

Example:

public override void Read(BinaryReader reader)
{
  _somethingToSave = reader.ReadInt32();
}

OnLoad()

This method gets called on the main thread, after the stage is initialized when loading a savegame. Here you can use the variables we've read with the Read() method.

Example:

public override void OnLoad()
{
  ObjectToSave.Get().SomethingToSave = _somethingToSave;
}

For an example plugin, check out BRC-SaveDataAPIExample