How To Write A Simple Clone Hero Mod (BepInEx) - Biendeo/My-Clone-Hero-Tweaks GitHub Wiki
How does BepInEx work?
BepInEx is loaded into your program through a bootstrap library (in this case, winhttp.dll
which is directly next to Clone Hero.exe
). This library is automatically loaded, and then from that it initialises all of BepInEx's configurations and such in the background. BepInEx then looks recursively inside the BepInEx\plugins
folder, scans each .dll
file, and instantiates anything that contains a BepInPlugin
attribute and extends BaseUnityPlugin
. These are all instantiated as components to a manager object, so, unlike CHLoader, you don't need to create an object and set its lifetime before starting a mod.
How to write your own BepInEx mod
First of all, set up a new project for a C# class library using .NET Framework. I personally pick 4.8, although any version 4.x should do fine. You also must add BepInEx.dll
as a reference to your library so that you can access BepInEx's classes.
BepInEx loads any class that is in this format:
using BepInEx;
namespace MyCoolMod {
[BepInPlugin("com.biendeo.mycoolmod", "My Cool Mod", "1.0.0.0")]
public class MyCoolMod : BaseUnityPlugin {
public void Awake() {
Logger.LogDebug("Hello world!");
}
}
}
It is important that your class contains an attribute BepInPlugin
and extends BaseUnityPlugin
. BaseUnityPlugin
is a BepInEx class that ultimately inherits from MonoBehaviour
, so you can assume your class is being used as a Component.
The attribute takes in three strings, a GUID (a unique identifier for your mod), a name, and a version number. The GUID just needs to not collide with any other mods, and is used as the default name of the config file for your mod. I personally use the reverse domain name notation. The name is just a readable name for your mod. The version must be parsable as a System.Version
.
What can else can BepInEx do?
BepInEx contains quite a few additional things that'll make your life easier:
Configs
Logging
Dependencies
Patching
Other Tools
Since BepInEx is a generic Unity mod loader, there exists a few other plugins that can assist you in making mods:
Runtime Unity Editor
DISCLAIMER: This plugin is incredibly powerful as it exposes a lot of the underlying Clone Hero structures. Please do not use this to pretend you're better at Clone Hero than you really are.
This plugin allows you to press F12 to bring up a list of all objects in the scene, as well as what components they have, and what values and methods are in that component. It's an excellent tool for debugging your own mods, as well as observing how it affects the existing structures in-game.
Configuration Manager
This plugin lets you press F1 to view and modify all the configuration items of all the currently loaded plugins. Since it is easy to use, you can encourage users to change settings using this menu if you don't want to create your own configuration menu.
Additional reference
- The BepInEx wiki has an excellent and more fleshed out tutorial on various things you can do. It is highly recommended to refer to it for some more technical tasks.