www_Day_Dream-Instance_Method_Injector icon

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.

Last updated 9 months ago
Total downloads 331
Total rating 1 
Categories Libraries
Dependency string www_Day_Dream-Instance_Method_Injector-1.0.0
Dependants 0 other packages depend on this package

This mod requires the following mods to function

BepInEx-BepInExPack-5.4.2100 icon
BepInEx-BepInExPack

BepInEx pack for Mono Unity games. Preconfigured and ready to use.

Preferred version: 5.4.2100

README

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<string, bool>))]

These methods turn into the following code snippets, respectively:

public override void OnMessageName()
{
}
public override void OnMessageName(string pString, Action<string, bool> 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.