[solved] How to patch another mod?

Started by battlemage64, February 18, 2021, 08:02:46 PM

Previous topic - Next topic

battlemage64

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.
I love to mod and boy am I bad at it

RawCode

and what exactly is wrong and or not working as intended?

documentation does not explain how because it exactly same compared to base game.

battlemage64

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.
I love to mod and boy am I bad at it

RawCode

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?