![]() ![]() RimWorldModGuide on Harmony - OUTDATED (Harmony 1) gives some concrete examples and helpful explanations With approximately 180 patches, it's considered a good reference as it contains examples of all Harmony patch types. Harmony 2 Documentation - Official documentation for Harmony 2.Īlien races - The Alien Races framework HarmonyPatches class. Create your harmony instance in there, and use it to call PatchAll() or do your manual patching. Remember the Hello World tutorial? The is a perfect starting point. Are you doing everything right? If the method you're patching is small, it may have been inlined. If you are trying to patch something that runs during game loading, you may need to bootstrap differently. You will need to specify arguments for overloaded methods.ĭoes your Log.Message() not show up? Set HarmonyInstance.DEBUG = true and check the new. The most reliable way of specifying the method to patch is by providing the Patch() method with MethodInfo. } Getting the right method to patch ĪccessTools is a nice wrapper for reflection. Return false //return false to skip execution of the original. Static bool Prefix(ref bool _result) //pass the _result by ref to alter it. Static class Building_Trap_KnowsOfTrap_Patch annotation boiler plate to tell Harmony what to patch. Consider the following destructive prefix, which gives everyone perfect knowledge of trap locations: Harmony disconnects its own return type from the return type of the original method. How do I return a value from a void or prefix? Can you subclass? Can you use a ThingComp? A MapComponent? There may be viable alternatives without the added dependency. Before you do that, consider the alternatives. ![]() Harmony is a fantastic tool, that you'll soon want to use for everything. If the original method has a return type, you can alter its _result by passing it by ref. If you must use a transpiler, you might find useful notes here. Transpilers are difficult to debug and therefor hard to create/maintain/update. Refer to MSDN and Harmony documentation for more info. They use low-level IL-code, from System.Reflection and. These alter the inner working of the method. Use these for greatest compatibility.Ī transpiler is a set of CodeInstructions. This type of prefix may also prevent other prefixes from running.Ī postfix is a method that runs after the original method. This will cause compatibility issues if you're not very careful. If a bool returns false, the original method is skipped. It can have a return type of void or bool. It offers three ways of doing this: prefixes, postfixes, and transpilers.Ī prefix is a method that runs before the original method. Harmony can alter the workings of any method. You don't need to know the inner workings of JIT-compilation, reflection and inlining, but a basic understanding of C# and/or programming in general is assumed in this article.You need to be able to write a Hello World program.If you still haven't set up a solution, you're not ready for Harmony.4.3 How do I return a value from a void or prefix?.This article is mostly a "this is what you can do" summary in 5 minutes. Refer to the original documentation ( here). The snippets on this page are not meant as an exhaustive document on all things Harmony. Because this does not change existing functionality of RimWorld, it MOST LIKELY does not impact other mods and runs in parallel with other Harmony patches. Usually this is all you need for your Mod. Harmony is great for running code patches before (Prefix) or after (Postfix) an existing method. Please only use HugsLib when you want to utilize some of its features! This is a bad practice, especially for beginners new to RimWorld Modding. Simply add Harmony as a dependency on Steam instead.Īdditionally, please DO NOT use HugsLib for an "easy" Harmony implementation due to the fact that HugsLib becomes an unnecessary and unutilized dependency for mods and beginners grow accustomed to using HugsLib in all their mods even if they never touch HugsLib's API in their code. Please do not include the dll (0Harmony.dll) in your mod's assemblies folder! Outdated versions of Harmony can cause issues. To integrate Harmony into your mod for use, download the latest stable release and add it as a reference to your C# project. ![]() Harmony is the current best practice for changing the runtime execution of code in RimWorld. Harmony - A library for patching, replacing and decorating. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |