-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6f2b868
commit 2aaf064
Showing
8 changed files
with
252 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +0,0 @@ | ||
- Fixed key rebinding not working when done from in game. | ||
- Default key can now be set using enum. | ||
- Added tooltip provider. | ||
- Settings entries can now have headers and spacing. | ||
- Settings entries will now show the description in a tooltip. | ||
- New splash screen. | ||
- Mods can have loader version constraints now. | ||
- Mod list will show if (and why) a mod isn't loaded. | ||
- Added support for saving custom data to save files. | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Adding custom data to a save file | ||
Red Loader has utilities if you want your mod to persist data in save games. | ||
This is useful if you want to save settings or other data that you want to persist between game sessions for a particular save. | ||
|
||
## Serializer class | ||
Your mod needs some kind of class to serialize and deserialize your data. | ||
A common way is to have some kind of "manager" class that holds all the data you want to save. | ||
|
||
```csharp | ||
public class MyModManager : ICustomSaveable<MyModManager.MyModSaveData> | ||
{ | ||
public string Name => "MyModManager"; | ||
|
||
// Used to determine if the data should also be saved in multiplayer saves | ||
public bool IncludeInPlayerSave => true; | ||
|
||
public MyModSaveData Save() | ||
{ | ||
// Serialize your data from game state here | ||
return new MyModSaveData(); | ||
} | ||
|
||
public void Load(MyModSaveData obj) | ||
{ | ||
// Apply game state from your data here | ||
} | ||
|
||
public class MyModSaveData | ||
{ | ||
public Color SomeColor; | ||
public Vector3 SomeVector; | ||
} | ||
} | ||
``` | ||
|
||
The important parts here are the `ICustomSaveable` interface that `MyModManager` implements, and the `MyModSaveData` class that is used to serialize and deserialize the data. | ||
The `Save` and `Load` methods from the `ICustomSaveable` interface are used to serialize and deserialize the data. | ||
Red Loader will call them when a save game gets loaded or the user requests a save. | ||
|
||
## Registering your serializer | ||
Registering the serializer is as easy as calling the following in `OnSdkInitialized`: | ||
```csharp | ||
var manager = new MyModManager(); | ||
SonsSaveTools.Register(manager); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
<!DOCTYPE html> | ||
<!--[if IE]><![endif]--> | ||
<html> | ||
|
||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> | ||
<title>Adding custom data to a save file | RedLoader Docs </title> | ||
<meta name="viewport" content="width=device-width"> | ||
<meta name="title" content="Adding custom data to a save file | RedLoader Docs "> | ||
<meta name="generator" content="docfx "> | ||
|
||
<link rel="shortcut icon" href="../https://github.com/ToniMacaroni/RedLoader/blob/16cc6bb13745526a451eab0fd1ce02f7b128916f/Resources/favicon.ico?raw=true"> | ||
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&display=swap" rel="stylesheet"> | ||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/styles/night-owl.min.css"> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css" integrity="sha384-EvBWSlnoFgZlXJvpzS+MAUEjvN7+gcCwH+qh7GRFOGgZO0PuwOFro7qPOJnLfe7l" crossorigin="anonymous"> | ||
<link rel="stylesheet" href="../styles/config.css"> | ||
<link rel="stylesheet" href="../styles/discord.css"> | ||
<link rel="stylesheet" href="../styles/singulink.css"> | ||
<link rel="stylesheet" href="../styles/main.css"> | ||
<meta property="docfx:navrel" content="../toc.html"> | ||
<meta property="docfx:tocrel" content="toc.html"> | ||
|
||
<meta property="docfx:rel" content="../"> | ||
|
||
</head> | ||
<body> | ||
<div class="top-navbar"> | ||
<a class="burger-icon" onclick="toggleMenu()"> | ||
<svg name="Hamburger" style="vertical-align: middle;" width="34" height="34" viewbox="0 0 24 24"><path fill="currentColor" fill-rule="evenodd" clip-rule="evenodd" d="M20 6H4V9H20V6ZM4 10.999H20V13.999H4V10.999ZM4 15.999H20V18.999H4V15.999Z"></path></svg> | ||
</a> | ||
|
||
|
||
<a class="brand" href="../index.html"> | ||
<img src="../https://github.com/ToniMacaroni/RedLoader/blob/cd2308cbe9b7b8c68eb6217ecb557ab417479208/Resources/redlogo.png?raw=true" alt="" class="logomark"> | ||
<span class="brand-title"></span> | ||
</a> </div> | ||
|
||
<div class="body-content"> | ||
<div id="blackout" class="blackout" onclick="toggleMenu()"></div> | ||
|
||
<nav id="sidebar" role="navigation"> | ||
<div class="sidebar"> | ||
|
||
<div> | ||
<div class="mobile-hide"> | ||
|
||
<a class="brand" href="../index.html"> | ||
<img src="../https://github.com/ToniMacaroni/RedLoader/blob/cd2308cbe9b7b8c68eb6217ecb557ab417479208/Resources/redlogo.png?raw=true" alt="" class="logomark"> | ||
<span class="brand-title"></span> | ||
</a> </div> | ||
|
||
<div class="sidesearch"> | ||
<form id="search" role="search" class="search"> | ||
<i class="bi bi-search search-icon"></i> | ||
<input type="text" id="search-query" placeholder="Search" autocomplete="off"> | ||
</form> | ||
</div> | ||
|
||
<div id="navbar"> | ||
</div> | ||
</div> <div class="sidebar-item-separator"></div> | ||
|
||
<div id="sidetoggle"> | ||
<div id="sidetoc"></div> | ||
</div> | ||
</div> | ||
</nav> | ||
|
||
<main class="main-panel"> | ||
|
||
<div id="search-results" style="display: none;"> | ||
<h1 class="search-list">Search Results for <span></span></h1> | ||
<div class="sr-items"> | ||
<p><i class="bi bi-hourglass-split index-loading"></i></p> | ||
</div> | ||
<ul id="pagination" data-first="First" data-prev="Previous" data-next="Next" data-last="Last"></ul> | ||
</div> | ||
|
||
|
||
<div role="main" class="hide-when-search"> | ||
|
||
<div class="subnav navbar navbar-default"> | ||
<div class="container hide-when-search" id="breadcrumb"> | ||
<ul class="breadcrumb"> | ||
<li></li> | ||
</ul> | ||
</div> | ||
</div> | ||
|
||
|
||
<article class="content wrap" id="_content" data-uid=""> | ||
<h1 id="adding-custom-data-to-a-save-file">Adding custom data to a save file</h1> | ||
|
||
<p>Red Loader has utilities if you want your mod to persist data in save games. | ||
This is useful if you want to save settings or other data that you want to persist between game sessions for a particular save.</p> | ||
<h2 id="serializer-class">Serializer class</h2> | ||
<p>Your mod needs some kind of class to serialize and deserialize your data. | ||
A common way is to have some kind of "manager" class that holds all the data you want to save.</p> | ||
<pre><code class="lang-csharp">public class MyModManager : ICustomSaveable<MyModManager.MyModSaveData> | ||
{ | ||
public string Name => "MyModManager"; | ||
|
||
// Used to determine if the data should also be saved in multiplayer saves | ||
public bool IncludeInPlayerSave => true; | ||
|
||
public MyModSaveData Save() | ||
{ | ||
// Serialize your data from game state here | ||
return new MyModSaveData(); | ||
} | ||
|
||
public void Load(MyModSaveData obj) | ||
{ | ||
// Apply game state from your data here | ||
} | ||
|
||
public class MyModSaveData | ||
{ | ||
public Color SomeColor; | ||
public Vector3 SomeVector; | ||
} | ||
} | ||
</code></pre> | ||
<p>The important parts here are the <code>ICustomSaveable</code> interface that <code>MyModManager</code> implements, and the <code>MyModSaveData</code> class that is used to serialize and deserialize the data. | ||
The <code>Save</code> and <code>Load</code> methods from the <code>ICustomSaveable</code> interface are used to serialize and deserialize the data. | ||
Red Loader will call them when a save game gets loaded or the user requests a save.</p> | ||
<h2 id="registering-your-serializer">Registering your serializer</h2> | ||
<p>Registering the serializer is as easy as calling the following in <code>OnSdkInitialized</code>:</p> | ||
<pre><code class="lang-csharp">var manager = new MyModManager(); | ||
SonsSaveTools.Register(manager); | ||
</code></pre> | ||
</article> | ||
</div> | ||
|
||
</main> | ||
</div> | ||
|
||
|
||
<script src="https://code.jquery.com/jquery-3.6.3.min.js" integrity="sha256-pvPw+upLPUjgMXY0G+8O0xUf+/Im1MZjXxxgOcBQBXU=" crossorigin="anonymous"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-+sLIOodYLS7CIrQpBjl+C7nPvqq+FbNUBDunl/OZv93DB7Ln/533i8e/mZXLi/P+" crossorigin="anonymous"></script> | ||
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/highlight.min.js"></script> | ||
<script type="text/javascript" src="../styles/jquery.twbsPagination.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.mark.min.js"></script> | ||
<script type="text/javascript" src="../styles/url.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/anchor.min.js"></script> | ||
<script type="text/javascript" src="../styles/docfx.js"></script> | ||
<script type="text/javascript" src="../styles/main.js"></script> | ||
<script type="text/javascript" src="../styles/singulink.js"></script> </body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters