Modding:Monkey patching

From Vintage Story Wiki
Revision as of 22:37, 13 July 2021 by Egocarib (talk | contribs) (add navbox)

Monkey Patching

Overview

Monkey patching (changing code at runtime) in Vintage Story is available through Harmony. With Harmony you can change methods, constructors and properties. Documentation on harmony is available here..

Getting started

To use Harmony in you Vintage Story mod you first have to reference the 0harmony.dll in the Vintage Story lib directory (VintageStory\Lib\0Harmony.dll).

Then you have to create a Harmony-instance by calling the constructor with you a unique identifier, preferrably you modid (this let's harmoy differentiate between different patches and allows other people to patch your patches).

var harmony = new Harmony("MyModId");

Now you are all set to patch everything inside the game like described in the documentation.

Remarks

  • Just because you can use monkey patching, does not mean you should. Patches are often fragile and break easily (especially if you access internal private methods). So if you can use normal means of modding you probably should.
  • You can't use harmony to patch fields (because they are not called), so in order to change field access you have to patch all calls to this field with patches.
Icon Sign.png

Wondering where some links have gone?
The modding navbox is going through some changes! Check out Navigation Box Updates for more info and help finding specific pages.

Modding
Modding Introduction Getting Started Theme Pack
Content Modding Content Mods Developing a Content Mod Basic Tutorials Intermediate Tutorials Advanced Tutorials Content Mod Concepts
Code Modding Code Mods Setting up your Development Environment
Property Overview ItemEntityBlockBlock BehaviorsBlock ClassesBlock EntitiesBlock Entity BehaviorsWorld properties
Workflows & Infrastructure Modding Efficiency TipsMod-engine compatibilityMod ExtensibilityVS Engine
Additional Resources Community Resources Modding API Updates Programming Languages List of server commandsList of client commandsClient startup parametersServer startup parameters
Example ModsAPI DocsGitHub Repository