Trouble with PatchOperationFindMod

Started by MrNekuromu, July 25, 2021, 08:30:58 PM

Previous topic - Next topic

MrNekuromu

Hi all, I'm having some issue with a patch I am currently making. I have tinkered with Rimworld modding a little before back in 2017 but really decided to get into it since I've been coding more and making my own games in Godot. Although XML is a whole different beast than writing a game so far.

Mainly the issues I am having atm revolve around Ideology's new Preferred Apparel and trying to add to it. (Not the roles but the general Religion Apparel)... and while I feel I have been making slow progress I am hindered at the moment by the start of my patch not finding the Mod in question.

so from the documentation here;

It explains that
QuoteFor a successful match, <li>ModName</li> has to match the <name>ModName</name> in the About.xml of the mod you base your patch behaviour on.

Here we have the <name> from the About.xml of Adeptus Mechanicus: Armoury
<ModMetaData>
<name>Adeptus Mechanicus: Armoury</name>
<packageId>Ogliss.AdMech.Armoury</packageId>


So my patch is written as so...
Operation Class="PatchOperationFindMod">
<mods>
<li>Adeptus Mechanicus: Armoury</li>
</mods>


When loaded I am getting this...

[Neku's Cult Mechanicus Role Apparel Unlocked Patch] Patch operation Verse.PatchOperationFindMod(Adeptus Mechanicus: Armoury) failed
file: (File Structure Here)\RimWorld\Mods\Neku's Cult Mechanicus Apparel Unlocked Patch\1.3\Patches\NekuPatch.xml
UnityEngine.StackTraceUtility:ExtractStackTrace ()
(wrapper dynamic-method) Verse.Log:Verse.Log.Error_Patch0 (string)
Verse.PatchOperation:Complete (string)
(wrapper dynamic-method) Verse.LoadedModManager:Verse.LoadedModManager.ClearCachedPatches_Patch0 ()
Verse.LoadedModManager:LoadAllActiveMods ()
Verse.PlayDataLoader:DoPlayLoad ()
Verse.PlayDataLoader:LoadAllPlayData (bool)
Verse.Root/<>c:<Start>b__6_1 ()
Verse.LongEventHandler:RunEventFromAnotherThread (System.Action)
Verse.LongEventHandler/<>c:<UpdateCurrentAsynchronousEvent>b__27_0 ()
System.Threading.ThreadHelper:ThreadStart_Context (object)
System.Threading.ExecutionContext:RunInternal (System.Threading.ExecutionContext,System.Threading.ContextCallback,object,bool)
System.Threading.ExecutionContext:Run (System.Threading.ExecutionContext,System.Threading.ContextCallback,object,bool)
System.Threading.ExecutionContext:Run (System.Threading.ExecutionContext,System.Threading.ContextCallback,object)
System.Threading.ThreadHelper:ThreadStart ()


From what I can gather (which admittedly probably isn't much compared to what I could) is that it's not finding this mod which to me tells me my naming must be incorrect. To which when checked it matches exactly. Any guidance with this would be extremely helpful as I have already had quite a lot of trouble figuring out just how the game builds the Preferred Apparel list from Ideology so I could add to it.

Thanks again for reading and hoping for the best!

RawCode

mod loading order?
other errors earlier?

MrNekuromu

[Mod list length: 17]
Harmony [https://steamcommunity.com/sharedfiles/filedetails/?id=2009463077]
Visual Exceptions [https://steamcommunity.com/sharedfiles/filedetails/?id=2538411704]
Core [https:// no link (local mod)]
Royalty [Official DLC] [https:// no link (local mod)]
Ideology [Official DLC] [https:// no link (local mod)]
Mod Manager [https://steamcommunity.com/sharedfiles/filedetails/?id=2552985369]
Startup impact [https://steamcommunity.com/sharedfiles/filedetails/?id=1684944322]
HugsLib [https://steamcommunity.com/sharedfiles/filedetails/?id=818773962]
Save/Load Ideos [https:// no link (local mod)]
ResearchPal - Forked [https://steamcommunity.com/sharedfiles/filedetails/?id=2351393394]
RimThemes [https://steamcommunity.com/sharedfiles/filedetails/?id=1668983184]
RimSaves [https://steamcommunity.com/sharedfiles/filedetails/?id=1713367505]
Eren's Face Replace [https://steamcommunity.com/sharedfiles/filedetails/?id=2547290057]
Adeptus Mechanicus: Armoury [https://steamcommunity.com/sharedfiles/filedetails/?id=1541438614]
Roles Apparel Unlocked [https:// no link (local mod)]
Neku's Cult Mechanicus Role Apparel Unlocked Patch [https:// no link (local mod)]


I removed most of my mods to bare minimum for a much cleaner work environment before I started development. That's the only error I am getting although since I have been tinkering around a bit more I have found that I can make it disappear by removing some of my patchwork. So I assume instead of it actually being that... it's actually my handiwork involving what I am trying to do instead of some odd naming error.

I believe where I am falling short now is just xpaths, they are pretty much brand new to me since two days ago. The Adeptus Mechanicus: Armoury mod, which has the apparel I am working with has stumped me atm. Not to mention I haven't quite yet worked out what makes things appear in the "Preferred Apparel" in Ideology. Oddly enough some things from AM:A mod are already in the list... just not the ones I am trying to patch. This seems more like a default than some accident I created, and I am using the differences to figure out what makes the ones I'd like to see in that list be exempted from it.

If I better understood xpathing when dealing with many Abstracts... I would be in better shape. By the looks of it most of the armor I am trying to work with has 3 abstracts in a row before getting to the specific armor set.

Like so... OG_Apparel_Base (Abstract: yes) OG_Mechanicus_Apparel_Base (Abstract: yes) --> OG_Mechanicus_Apparel_Armor_Base (Abstract: yes) --> OGAM_Apparel_EnginseerRobe (Abstract: no)

I am unsure of how the xpaths should be built so I am currently looking into it, and also just trying to understand what I am looking at lol.

MrNekuromu

#3
Currently my suspicion is that I may need to add <li>Apparel</li> to <thingCategories> ... Some of the apparel from the mod (some that do show up in Preferred Apparel) have it but I believe a lot of the more specific sets of armor do not. A lot of the Abstracts as it gets down more specific to the armor set has a couple of different <thingCategories> such as <li>OGAMSub</li> or <li>OGAMApparel</li>

but so far my attempts to implant <li>Apparel</li> haven't panned out... instead creating that same naming error. Currently before I call it for the night the patch looks like this...

<?xml version="1.0" encoding="utf-8"?>
<Patch>
  <!-- Adeptus Mechanicus: Armoury -->
  <Operation Class="PatchOperationFindMod">
<mods>
<li>Adeptus Mechanicus: Armoury</li>
</mods>

    <match Class="PatchOperationSequence">
<success>Normal</success>
<operations>
<li Class="PatchOperationAdd">
<xpath>Defs/ThingDefs[@Name="OG_Mechanicus_Apparel_Base"]/thingCategories</xpath>
<value>
<li>Apparel</li>
</value>
</li>
</operations>
    </match>
  </Operation>

</Patch>


This does not work, and at the moment I do not know why.

llunak

Your xpath has @Name= instead of Name=, isn't that the problem?

As a general rule, if something doesn't work, try to simplify it as much as possible. If you haven't tried that your PatchOperationAdd works on its own, do that first, without PatchOperationFindMod.


RawCode

start with something extra simple, like xpatch specific field of vanilla object
then do exactly same operation if specific mod is present

after understanding concept (and making sure that mod name and other data is okay) do what you originally planned.

also you may inject additional trace\debug output into classes like Verse.PatchOperationFindMod to make extra sure, that everything works as you intended.


MrNekuromu

Quote@ select by attribute. Useful for patching (Abstract) bases.
above from;

Last night since adding directly to the specific apparel I was attempting to patch the direct parent of it, I believe since it is abstract the @ is needed or at least by that line there from the modding tutorial page. If I can't make heads or tails of it by noon today I will probably try something a bit simpler and take a few steps back to make sure I am comprehending how it all should accurately work.

I was wondering if there was more I could do to tell if what I had injected was working or not. Now that I know the terminology for it I will be looking into how to inject debug traces like that. Thanks for the advice, both of you!

MrNekuromu

Alrighty so my patch seems to be working with no errors now and will be uploaded soon.

So
<canBeDesiredForIdeo></canBeDesiredForIdeo>
seems to have nothing to do with the Preferred Apparel list, turns out from what I can tell the reason it grabbed some but not all apparel from the mod is because of

<costStuffCount></costStuffCount>

and

<stuffCategories>
</stuffCategories>


After adding these and some respective values such as 120, then leathery & fabric they appeared in the Preferred Apparel list.

To be clear, these may not be the only requirements before they appear on any other apparel... I'd say more testing needs to be done on a more barebones apparel to see what matters and what doesn't.

Anyhow, Thanks for all the help everyone!