This example plugin demonstrates how to create a simple plugin for BepInEx IL2CPP.
All the plugin does is remove all stamina from player actions. The code is fully commented to help you understand how it
works.
- .NET 6.0 SDK or later
- A C# IDE (e.g., Visual Studio, JetBrains Rider, etc.)
- BepInEx IL2CPP Plugin Template ( optional, but highly recommended)
- dnSpy (to inspect game assemblies and find methods to hook into(and see classes, enums, variables etc.))
- BepInEx (installed in your game folder and run at least once, see the BepInEx documentation for instructions). You will need it for the decompiled DLL's.
You can fork this repository and use it as a starting point, or create a new project with the BepInEx IL2CPP plugin template.
I recommended starting from scratch with the BepInEx template, as it sets up the plugin info for you and helps you learn how to add assemblies.
- Decompiling Game Code:
The actual function code will not be readable in dnSpy due to it being compiled in il2CPP. You will need to use Ghidra to decompile the code.
Note that the decompiled code will be in C, so if you are unfamiliar with C, it may be hard to understand. - Adding Assemblies(this allows you to access game classes and methods):
To add assemblies(only Rider and Visual Studio are covered here):- Rider - Right-click on the Dependencies option in the Explorer tab and select "Reference... -> Add From.." and select where your games DLL's are
- Visual Studio - Right-click on the Dependencies option in the Solution Explorer and select "Add Project Reference... -> Browse...".
- Browse to the DLL you want to add (these will be in the
BepInEx/interopfolder, but I recommend moving them to another folder outside the game). - Select the DLL and click OK. (You can check if it was added by expanding the Dependencies and looking in assemblies(In Rider under .NET 6.0 -> Assemblies))
The.csprojfile also contains comments for clarification on what they add.
- Building the Plugin:
To build the plugin, just build the project in your IDE. The output DLL will be located in thebin/Debug/net6.0orbin/Release/net6.0folder of your project, depending on your build configuration.
You can then copy this DLL to theBepInEx/pluginsfolder of your game(The DLL will be named, ex.yourPLUGIN_GUID.DLL).
Only move that DLL, nothing else.
There is also a post-build event in the.csprojfile that will copy the DLL to theBepInEx/pluginsfolder of your game automatically when you build the project. You will need to change the path to your game folder in the.csprojfile, though. It is commented where that is in the file.
If you need help, you can join the Story of Seasons Modding Discord.
There is a tutorial available there that explains how to set up a plugin from scratch using the BepInEx IL2CPP template.