Skip to content

Writing Code

You should have a project that looks like this:

  • .gitignore
  • CHANGELOG.md
  • Directory.Build.targets
  • icon.png
  • LICENSE
  • README.md
  • ResoniteMod.sln
  • thunderstore.toml
  • Directory.config/
    • dotnet-tools.json
  • DirectoryResoniteMod/
    • Plugin.cs
    • ResoniteMod.csproj
    • DirectoryProperties/
      • launchSettings.json

Open the project in your IDE of choice where the .sln file is, and then open the Plugin.cs file. It should look something like this:

Plugin.cs
using BepInEx;
using BepInEx.Logging;
using BepInEx.NET.Common;
using BepInExResoniteShim;
using BepisResoniteWrapper;
namespace ProjectName;
[ResonitePlugin(PluginMetadata.GUID, PluginMetadata.NAME, PluginMetadata.VERSION, PluginMetadata.AUTHORS, PluginMetadata.REPOSITORY_URL)]
[BepInDependency(BepInExResoniteShim.PluginMetadata.GUID, BepInDependency.DependencyFlags.HardDependency)]
public class Plugin : BasePlugin
{
internal static new ManualLogSource Log = null!;
public override void Load()
{
Log = base.Log;
ResoniteHooks.OnEngineReady += OnEngineReady;
Log.LogInfo($"Plugin {PluginMetadata.GUID} is loaded!");
}
private void OnEngineReady()
{
// The Resonite engine is now fully initialized
// Safe to access FrooxEngine classes and functionality
Log.LogInfo("Engine is ready!");
}
}

This is a very basic BepInEx 6 plugin that uses BepisResoniteWrapper - a library that provides commonly-used hooks and events for Resonite mods.

BepisResoniteWrapper is already included in the template as a dependency. This library simplifies mod development by providing ready-to-use events for common Resonite modding scenarios. In the example above, we’re using the OnEngineReady event to safely access FrooxEngine functionality after the engine has fully initialized.

  • ResoniteHooks.OnEngineReady - Fired when the Resonite engine has finished initializing
    • Safe to access Engine.Current and all FrooxEngine classes
    • This is where most of your mod’s initialization should happen

To use additional events or hooks, check the BepisResoniteWrapper documentation or explore other mods for examples.

Work in progress documentation, more will be added.

For now, for more info, see BepInEx’s own documentation:

Creating a new plugin project—Plugin structure

You can also follow the links to learn more about each thing mentioned:

Logging: lethal.wiki

Custom Configs: lethal.wiki

Patching Code: lethal.wiki

For patching/hooking methods, you can use MonoMod or HarmonyX. See lethal.wiki for more in-depth introductions on using them.

All of these libraries are compatible with each other as HarmonyX and MonoDetour simply use MonoMod.RuntimeDetour under the hood.