MonoMod Patches
Jump to navigation
Jump to search
Legacy article
This article contains information that is only relevant for legacy versions of the game (1.5 or lower)
|
Cleanup needed
This article needs structural or tonal clean-up to meet quality standards. Feel free to help improve it.
|
MonoModPatches or MMPatches are one of the simplest ways of modifying vanilla code. They can be used with current version of our BepInEx package.
MonoMod's README contains a description of this method. Short summary and RW-specific aspects are presented below.
Creation[edit source]
- Create a project referencing both
MonoMod.exe
andAssemblyCSharp.dll
- Create a type deriving from target class
- Mark your class for patching. This can be done in two ways:
- Place your class in the exact same namespace and name it
patch_OriginalNamehere
(patch_Player
to patchPlayer
) - Denote your class with
MonoModPatch
attribute like the following example
- Place your class in the exact same namespace and name it
[MonoModPatch("global::Player")]
//"global::" is the namespace for classes appearing "without a namespace"
public class CustomPlayer : Player { }
- For every method to patch, use the following pattern:
[MonoModPatch("global::Player")]
public class CustomPlayer : Player {
public extern void orig_Update(bool eu);
public override void Update(bool eu)
{
//do your things
orig_Update(eu); // original method body is inserted at the site of this call. Omit to not use original code at all (also disables layering MMPatches).
//do your things
}
}
To access a private member, create one with matching signature (type / name / params etc) and denote it with MonoModIgnore
attribute. To patch a non-override public method, use new
to hide the vanilla method for the compiler.
Things to note[edit source]
- MMPatches should not be shipped in the same assembly as partmods/BepInPlugins. If that is done, there is only a small chance doing that will not turn your game into an firecracker plant.
MonoModRules
described in MonoMod readme does not seem to coexist nicely with BepInEx. More testing is required to narrow down where things go terribly wrong.
Usage[edit source]
MMPatches have to be named as following: AssemblyCSharp.[modName].mm.dll
. They are loaded from Rain World/BepInEx/monomod/
at preloader time. BOI renames files automatically in a futile attempt to make the process more intuitive for the end user.