AutoReload
Automatically reloads plugins by watching BepInEx/plugins/ for file changes. For developers.
About this mod Author’s original text
AutoReload
A BepInEx 5 plugin that automatically reloads plugins by watching BepInEx/plugins/ for file changes.
[!WARNING]
I have been informed that the FileSystemWatcher may work terribly on Windows. This plugin relies on FileSystemWatcher working properly. If you are having issues with it, try running under Linux.
Also, if BepInEx is not configured to hide plugin manager gameObject, this plugin will not work properly. Set HideManagerGameObject to true in BepInEx.cfg if this plugin is not working. This setting is enabled by default in BepInExPack for PEAK.
Implementing Support
To make your plugin work with reloading, it must implement the OnDestroy method in the main plugin class to clean up after itself. An example of a good plugin:
[BepInAutoPlugin]
public partial class Plugin: BaseUnityPlugin
{
void Awake()
{
// Apply all hooks
MonoDetourManager.InvokeHookInitializers(typeof(Plugin).Assembly);
Log.LogInfo($"Plugin {Name} is loaded!");
}
void OnDestroy()
{
// Dispose all hooks
DefaultMonoDetourManager.Instance.Dispose();
Log.LogInfo($"Plugin {Name} unloaded!");
}
}
[!TIP]
The above plugin uses Hamunii.BepInEx.AutoPlugin for the [BepInAutoPlugin] attribute, and MonoDetour for hooking.
Limitations
Fixable Limitations
- If mod A and B are both reloaded, and A depends on B, A will reference the first ever loaded version of B.
- AutoReload would need to detect that A depends B, and rewrite A's references to B to reference the latest B assembly before A is reloaded.
- Currently this can be worked around by using ILRepack or ILRepack.Lib.MSBuild.Task.
- Reloaded plugins don't retain any state.
Runtime Limitations
- Old assemblies are never actually unloaded because it's impossible.
Alternatives
-
- UnityHotReload preserves the existing runtime state by redirecting all active references to the original type definitions.
-
- AutoReload is a hard fork of this. For comparison, see the Credits below.
Credits
This is a hard fork of BepInEx.Debug ScriptEngine which dramatically changes how the plugin works.
Main changes are:
- scripts/ directory is gone
- assemblies are reloaded from plugins/
- LoadOnStart option is gone
- FileSystemWatcher option is gone, always enabled
- AutoReloadDelay option is gone
- ReloadKey option is gone
- IncludeSubdirectories option is gone, always enabled
- Only "file changed" and "file renamed" events are listened to
- DumpAssemblies option is gone, always enabled
- This is because you can get debug symbols this way
Install & use Install: BepInEx plugin
- The archive from playbuff is the mod itself — usually a BepInEx plugin (a .dll or a plugin folder once unzipped).
- Recommended: use a community mod manager (such as r2modman) — pick this game, import the mod, and the manager sets up BepInEx and its dependencies for you.
- Manual route: install the BepInEx loader in the game folder, then drop the unzipped .dll or plugin folder into BepInEx/plugins/.
- Launch the game — the BepInEx console logs every plugin it loads; seeing this mod in the log means it is installed.
Mods with listed dependencies need those installed too, or they will not load. Options are usually changed in-game or in the plugin's config file.
Install these first, or the mod will not work: