Some mods might not play nice with hot reloading. That's on them. That's also why this feature is opt-in and unstable.
The game will consume more memory each reload. You can alleviate this by setting your mod's static fields to default in OnDisable. Note that you don't have to reset unmanaged fields because that wouldn't free any memory.
You don't have to undo any MonoMod hooks when unloading. Realm undoes them automatically.
Example
static Player player;
static int num;
void OnEnable() {
On.Player.ctor += (orig, plr, a, w) => {
orig(plr, a, w);
player = plr;
num++;
};
}
void OnDisable() {
// You needn't reset `num` because that frees no memory. You can if you want to, though.
// num = default;
// You should reset `player` because that frees a lot of memory.
player = default;
}To enable hot reloading:
- Ensure Rain World is closed.
- In the file
Rain World/BepInEx/config/Realm.cfg, set HotReloading under the General section totrue.
To hot reload:
- Enter the pause menu in-game.
- Put modified DLL files in
Rain World/BepInEx/plugins. - Click HOT RELOAD in-game.
Some mods pass information between reloads (e.g. SlugBase). If you don't need to do that, you can stop reading here.
Reveal
// Must not have a void return type or any parameters
// Must be named "GetReloadState"
// Must be public and instance
// Example:
public object GetReloadState() => new object();
// ⚠ Only return objects from the System assembly, like `int`, `List<>`, `Dictionary<,>`, and so on.
// Must have exactly one parameter and that parameter must be a System.Object
// Must be named "Reload"
// Must be public and instance
// Example:
public void Reload(object state) {}
// Both of these must be members of exactly one mod type per assemblyAs long as this contract is fulfilled, you can expect the following behavior:
- You reload your mods.
- GetReloadState() is called.
- Your mod's Disable method is called.
- A new copy of your mod is enabled.
- The result from GetReloadState() is passed into the new mod through Reload(object).
I suggest copy-pasting the examples above into your mod class and editing their method bodies to suit your needs.