Instance Method Injector
A preload patcher that injects *blank* Unity Event methods, or really any method name, onto mod-requested objects for use with typical MonoMod patching.
About this mod Author’s original text
Instance Method Injector Preloader
A Preload Patcher that adds blank-public-instance methods as requested by any mods utilizing an assembly attribute into 'Assembly-CSharp.dll', primarily for relaying default Unity Messages such as Awake, Start, OnEnable, OnCollision, etc.. This is only needed when the target object you're patching doesn't contain a definition for a typical Unity Method as listed here.
How to Create Methods
First include a reference to the dll located under your profile: BepInEx/patchers/Daydream.InstanceMethodInjector. At the top of your Plugin.cs, or whatever file you use as your main BepInPlugin, ensuring you're outside of the scope of any namespaces, you'll add your method requirements.
using Daydream.InstanceMethodInjector;
[assembly: RequiresMethod(typeof(SomeTypeInAssemblyCSharp), "OnMessageName")]
If the message requires parameters then you can continue inserting typeof(xyz) statements in the params as follows:...
[assembly: RequiresMethod(typeof(SomeTypeInAssemblyCSharp), "OnMessageName", typeof(string), typeof(Action))]
These methods turn into the following code snippets, respectively:
public override void OnMessageName()
{
}
public override void OnMessageName(string pString, Action pAction)
{
}
Naming of Parameters
You can see the methods you've created in dnSpy by opening /BepInEx/cache/Assembly-CSharp.dll, but generally your parameter names will be p[TypeNamePascalCase] and in the event of multiple parameters of the same type they will be formatted as p[TypeNamePascaleCase]_0, with the last number incrementing per parameter of that type.
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: