FrogDataLib
A straightforward library for managing mod save data
| Last updated | 3 days ago |
| Total downloads | 71 |
| Total rating | 0 |
| Categories | Mods Libraries Host Only |
| Dependency string | Robyn-FrogDataLib-0.1.0 |
| Dependants | 0 other packages depend on this package |
This mod requires the following mods to function
BepInEx-BepInExPack
BepInEx pack for Mono Unity games. Preconfigured and ready to use.
Preferred version: 5.4.2304README
🐸 FrogDataLib for YAPYAP
FrogDataLib is a lightweight data persistence framework for YAPYAP mods. It allows developers to save and load custom mod data into "sidecar" files, preventing save game pollution and ensuring mod data stays synchronized with the user's active save slot.
Features
- Zero Pollution: Mod data is stored in
%AppData%/LocalLow/maisonbap/YAPYAP/FrogData/, keeping vanilla saves clean. - Slot Synchronization: Automatically handles saving, loading, and deleting data based on the user's active save slot.
- Type Safety: Uses a generic
FrogDataContainer<T>pattern for easy serialization. - Corrupt-Data Protection: Includes a "Sentinel" check to detect failed Unity JSON deserialization.
- Two-Tier Deserialization: Internally stores mod saves as strings and serializes them just in time to avoid TypeLoadExceptions when mods are modified on an active save (not recommended!)
For Developers: How to Use
See the full Example Project for more in-depth usage tips!
Define your Data Model
Your data class must inherit from FrogDataModel and be marked with the [Serializable] attribute.
using FrogDataLib.DataManagement;
using System;
[Serializable]
public class MyModData : FrogDataModel
{
public int PlayerKills;
public string FavoriteFrogName;
}
Initialize the Container
Create a container using a unique GUID (usually your mod's ID).
private FrogDataContainer<MyModData> _dataContainer;
void Awake()
{
_dataContainer = new FrogDataContainer<MyModData>("com.yourname.mymod");
// Subscribe to FrogDataLib events
FrogDataManager.OnBeginSaving += SaveMyData;
FrogDataManager.OnLoadCompleted += LoadMyData;
}
Use Your Object Like Normal
myData.FavoriteFrogName = "Gertrude";
Saving and Loading
Use the provided events to stay in sync with the game session.
// Called when the user clicks "Save" in-game
private void SaveMyData() =>
_dataContainer.SaveModData(myData);
// Called when a save slot is finished loading
private void LoadMyData()
{
MyModData data = _dataContainer.GetModData();
Debug.Log($"Loaded: {data.FavoriteFrogName}");
}
Important Notes
- The Frog Sentinel:
FrogDataLibuses an internal integer (8675309) to verify that Unity'sJsonUtilitydidn't silently fail. If your model isn't marked[Serializable], the sentinel will be0, and the frogs will refuse to save/load to prevent data loss. - Session Cleanup: Use the
OnSessionEndedevent to clear your local variables when a user returns to the Main Menu.