[LIB] Harmony v1.2.0.1

Started by Brrainz, January 13, 2017, 04:59:21 PM

Previous topic - Next topic

DarthNihilus

*sigh*
can i ask for help with modding Oxy not included, using Harmony?

Brrainz

Join the Harmony discord, there are lot of ppl there willing to help and guide you through your process.
Discord: https://discord.gg/xXgghXR

SheiFoxy

I have read through this twice and I can't make heads or tails of it.
I am NOT a good coder. I make mods by replacing values, balancing systems, replacing art assets. That's the stuff I know how to do. Gradeschool modding.

My head doesn't wrap around code easily.

Is there anyone here who understands this harmony patching stuff well enough they'd be willing to help me patch in my Grim Reality mod. It's become rather popular and I get requests every day for a fix. It's not working well with the current version due to incompatibilities and apparently code that changed between versions. I've done everything I know how to do, and when I started working on xpathing it, people told me to stop that and come here instead.

Anyone want to help me get it set up? Hopefully during the process I'll learn enough I can also patch in my other mods.

This is the mod in question: https://steamcommunity.com/sharedfiles/filedetails/?id=1498550346

Thank you.
SheiFoxy's Mods on Steam Workshop
SF Grim Reality ⚝ SF Materials Rebalanced ⚝ SF Traits Expansion ⚝ SF Cave Life

Brrainz

I'd love to help you but I don't have the time right now. I need it to keep on working on the Harmony documentation. Maybe someone at the modder discord can help you.

Glacialis

Ran RCC against my mod list, then used PSH to check 0Harmony.dll versions myself. Looooots of people still using 1.0.9.1 and 1.1.0.0. I'd script emailing everyone, but without scriptable contact info in mod descriptions I think my only option is to post on each mod separately. Seems spammy and I've got 118 mods with out of date Harmony DLLs. <_<

What might the consequences be for running 1.0.9.1/1.1.0.0 on game 1.0?

Thanks

dburgdorf

Is there a "trick" that I'm missing when trying to patch a method in another mod instead of in the vanilla code?

I'm trying to patch a very minor change to "Work Tab," so that it and my "Pawns are Capable!" will (hopefully) once again work together nicely, just as a stop-gap until Fluffy can make the change properly. But the patch just seems to be ignored, even though all my other patches (to vanilla code) work just fine. And the Harmony debug log shows that the method I'm trying to patch is unaltered; there's no call added to it to either a prefix or a postfix (both of which I've tried).
- Rainbeau Flambe (aka Darryl Burgdorf) -
Old. Short. Grumpy. Bearded. "Yeah, I'm a dorf."



Buy me a Dr Pepper?

Kiame

What I've done in the past is make a second project and conditionally patched if the other mod was enabled.
https://github.com/KiameV/rimworld-changedresser/blob/master/Source/Mending/HarmonyPatches.cs

The mod would then have two dll's in the assembly along with harmony. There probably is a way to do this conditional check in the same project but once I got this to work I kept it  :P

notfood

I do it this way. You can use Prepare() to decide if you want to patch or not, no need for an extra DLL

https://github.com/notfood/RimWorld-SeedsPlease/blob/master/Source/SeedsPleaseMod.cs#L78-L115

dburgdorf

The conditional stuff will definitely be handy if I can actually get the patch working, but right now, it's just being ignored, and apparently, it's not just because there's something special about patching another mod. So I'll have to keep digging to try to figure out what's actually wrong.

For initial testing purposes, I just added WorkTab as a reference to PAC, and I'm trying to patch its method in exactly the same way I patch vanilla methods. (Before I did anything else, I wanted to make sure that the change I *think* will fix the incompatibility, actually *will* fix the incompatibility.) The vanilla patches all work, but the WorkTab patch does nothing.
- Rainbeau Flambe (aka Darryl Burgdorf) -
Old. Short. Grumpy. Bearded. "Yeah, I'm a dorf."



Buy me a Dr Pepper?

dburgdorf

What I'm trying to do:

WorkTab.Pawn_Extensions.AllowedToDo contains a couple of calls directly to CombinedDisabledWorkTags. I'm fairly certain that those calls are the source of the current incompatibility between "Work Tab" and "Pawns are Capable." Replacing them with calls to WorkTagIsDisabled *should* allow the mods to play together nicely.

So I'm trying to patch WorkTab as follows (and thanks, notfood, for the conditional framework)....


[HarmonyPatch]
static class WorkTab_Pawn_Extensions_AllowedToDo {
static MethodBase target;
static bool Prepare() {
var mod = LoadedModManager.RunningMods.FirstOrDefault(m => m.Name == "Work Tab");
if (mod == null) {
return false;
}
var type = mod.assemblies.loadedAssemblies.FirstOrDefault(a => a.GetName().Name == "WorkTab").GetType("WorkTab.Pawn_Extensions");
if (type == null) {
Log.Warning("PAC can't patch WorkTab; no Pawn_Extensions found!");
return false;
}
target = AccessTools.DeclaredMethod(type, "AllowedToDo");
if (target == null) {
Log.Warning("PAC can't patch WorkTab; no Pawn_Extensions.AllowedToDo found!");
return false;
}
return true;
}
static MethodBase TargetMethod() {
return target;
}
static void postfix(this Pawn pawn, WorkGiverDef workgiver, ref bool __result) {
Log.Message("Here!");
if (pawn.story != null) {
__result = !pawn.story.WorkTypeIsDisabled(workgiver.workType) &&
!pawn.story.WorkTagIsDisabled(workgiver.workTags) &&
!pawn.story.WorkTagIsDisabled(workgiver.workType.workTags);
}
}
}


The problem is, the patch never actually seems to be applied. Harmony's debug log includes the "AllowedToDo" method, so Harmony knows it's supposed to be patched, but it *isn't* patched. It never calls the postfix.

(I've also tried using a prefix, but it didn't make any difference.)

Anyone have any ideas what I'm missing here?
- Rainbeau Flambe (aka Darryl Burgdorf) -
Old. Short. Grumpy. Bearded. "Yeah, I'm a dorf."



Buy me a Dr Pepper?

Dingo

Could it be something as small as capitalizing "postfix"?

dburgdorf

Quote from: Dingo on December 08, 2018, 08:35:52 AMCould it be something as small as capitalizing "postfix"?

FFS....

I've been banging my head against a wall for three days, trying to figure out what was wrong, and completely missed that. :P

Thank you.
- Rainbeau Flambe (aka Darryl Burgdorf) -
Old. Short. Grumpy. Bearded. "Yeah, I'm a dorf."



Buy me a Dr Pepper?

Dingo


notfood

dburgdorf be careful, the "?" syntax after  is required in the situation that WorkTab is null so you don't get a null exception

change:
var type = mod.assemblies.loadedAssemblies.FirstOrDefault(a => a.GetName().Name == "WorkTab").GetType("WorkTab.Pawn_Extensions");

to:

var type = mod.assemblies.loadedAssemblies.FirstOrDefault(a => a.GetName().Name == "WorkTab")?.GetType("WorkTab.Pawn_Extensions");

dburgdorf

Quote from: notfood on December 09, 2018, 04:37:37 AMbe careful, the "?" syntax after  is required in the situation that WorkTab is null so you don't get a null exception

When I add the question mark to the line, it won't even compile; I get a syntax error.
- Rainbeau Flambe (aka Darryl Burgdorf) -
Old. Short. Grumpy. Bearded. "Yeah, I'm a dorf."



Buy me a Dr Pepper?