Ludeon Forums

RimWorld => Mods => Help => Topic started by: battlemage64 on February 18, 2021, 08:02:46 PM

Title: [solved] How to patch another mod?
Post by: battlemage64 on February 18, 2021, 08:02:46 PM
My mod has a conflict with the mod Dubs Apparel Tweaks (henceforth DAT). I can fix the error by using Harmony to add a Postfix to one of the mod's methods, but I'm not sure how to set up the patch. If I have my code reference DAT's .dll file with using QuickFast (QuickFast is the dll filename), then the code throws an error when the mod is not loaded and often fails to load it even if DAT is active. If I do not include this line, the code does not compile at all because I can't run the patching operation:
harmony.Patch(typeof(bs).GetMethod("SwitchInside"), postfix: new HarmonyMethod(typeof(RBHarmonyDubsRendererPatch).GetMethod("Postfix")));
(Note that bs is the type containing the method SwitchInside that I want to patch, defined in QuickFast.dll, so without the using statement the type is not recognized. RBHarmonyDubsRendererPatch is defined in my code.)

What is the proper way to add a Harmony patch to another mod's code? The documentation claims it can be done but does not explain how.
Title: Re: How to patch another mod?
Post by: RawCode on February 20, 2021, 02:17:13 AM
and what exactly is wrong and or not working as intended?

documentation does not explain how because it exactly same compared to base game.
Title: Re: How to patch another mod?
Post by: battlemage64 on February 21, 2021, 04:40:25 PM
Never mind, this post helped me:
https://ludeon.com/forums/index.php?topic=29517.msg448123;topicseen#msg448123

I just needed to use Prepare() and TargetMethods() to check if the method exists and patch it.
Title: Re: [solved] How to patch another mod?
Post by: RawCode on February 22, 2021, 05:14:43 AM
do you understand that both methods literally do nothing (useful) and check can be done via
Type.GetType Method
https://docs.microsoft.com/en-us/dotnet/api/system.type.gettype?view=net-5.0

as single line?