The above method blocks the entire Tile class of the game. Advanced HarmonyĮven though the above will work, and opens up for good mod compatibility between DLL mods, there is a better way. If two mods try to patch the same method, there will be a conflict and only one will work. Harmony also allows other DLL mods as long as each mod patches different methods. Where Harmony shines is that you can have as many patches as you need in your mod. I can then define my own tile class methods, such as blocking the urban tile requirement of founding a city so settlers can found anywhere.īelow is the custom Tile class that my patch is using to allow settlers to found a city anywhere. In this instance I am replaceing the creation of a new tile object, with my custom tile class. The postfix method contains code to replace the result of the original method. The prefix method does nothing in this instance (I don't want to execute anything before the original code). In the below code, the first line attaches a patch to the GameFactory class, CreateTile method, then the class contains the prefix and postfix methods of the patch. įor this tutorial I will show how to capture the execution of "CreateTile" from the GameFactory class. Please refer to Harmony documentation for full details: or the Harmony Wiki. A prefix is code to execute before the original code (with an option to block the original code from executing) and a postfix is code to execute after the original code. Each patch needs to be attached to a method in a class within the original code, and then a prefix and postfix defined for each patch. You can have unlimited patches but each patch can only alter one original method. In Harmony terms, a patch is the manipulation of a single method of the original code. The next step after initalising a Harmony instance is to setup each patch. This will ensure we all avoid duplications amongst the community of Modders. In the example above I used "", I strongly advise that everyone who mods for Old World uses the format "". Note: when creating your new Harmony instance it needs to have a unique name. You also need to shut down the Harmony instance via your Mod's Shutdown method. Then, in your Mod's Initalise method, instead of creating a new GameFactory instance, create a new Harmony instance. When adding Harmony, make sure to add the using statement to your cs files. In both cases you must also copy 0Harmony.dll to your Mod folder (where the modinfo.xml and your built dll reside). If you downloaded Harmony from Github you will have to add 0Harmony.dll as a reference in your project. If you have Nuget then you can install Harmony into your solution via Nuget, otherwise head to their Github page: and get the Harmony DLL that way. Harmony is a C# library that will need to be added to your project. It works great in games and is well established in titles like 7 Days To Die, BattleTech, Besiege, Cities:Skylines, Kerbal Space Program, Oxygen Not Included, Ravenfield, Rimworld, Sheltered, Stardew Valley, Staxel, Subnautica, The Ultimate Nerd Game, Total Miner, Unturned and many more. Harmony gives you an elegant and high level way to alter the functionality in applications written in C#. Harmony allows the mod maker to inject their custom code into the existing code structure, without the requirement of having to override Old World's GameFactory class. The answer comes in the form of a neat little library called Harmony. How can we get around this? As a mod maker, how can we support other DLL mods to work with ours? If, for example, the player wanted to enable two DLL mods then only one DLL mod would actually work correctly. Players in Old World are allowed to enable multiple mods for their game setups. However this does present an issue in Old World as only one mod is able to completely override the GameFactory class. This allowed you to have your own custom classes and methods to override the default ones. ModSettings.Factory = new CharacterListGameFactory() In the previous tutorial Putting it all Together we did this by the following line of code. Up to now, the DLL modding I have demonstrated on this site required the overriding of the GameFactory class to create your own separate GameFactory object. Harmony is a 3rd party library for patching, replacing and decorating. Using the principles learnt in the Creating Old World Mods tutorial, this tutorial will take you through the requirements of setting up a DLL mod that supports Harmony.
0 Comments
Leave a Reply. |