XPath patch - testing against a def from another mod

Started by Telkir, May 26, 2017, 05:20:42 AM

Previous topic - Next topic

Telkir

I'm trying to use a patch operation sequence to check whether a def from another mod is found, then apply an Add patch to XML within my own mod if it is. Should be pretty simple, but I'm having trouble. Here's the patch:

<Operation Class="PatchOperationSequence">
  <success>Always</success>
  <operations>
    <li Class="PatchOperationTest">
      <xpath>/Buildings/ThingDef[defName = "Anon2Dresser"]</xpath>
    </li>
    <li Class="PatchOperationAdd">
      <xpath>/Defs/ThingDef[@Name = "BedBase" or @Name = "DoubleBedBase" or @Name = "RoyalBedBase"]/comps/li[@Class = "CompProperties_AffectedByFacilities"]/linkableFacilities</xpath>
      <value>
        <li>Anon2Dresser</li>
        <li>Anon2EndTable</li>
        <li>Anon2EndTableLight</li>
        <li>Anon2RoyalEndTable</li>
        <li>Anon2RoyalEndTableLight</li>
      </value>
    </li>
  </operations>
</Operation>


The mod containing Anon2Dresser is More Furniture, whose def in question is here:
https://pastebin.com/0pEFDLWw

I'm trying to apply the patch to the abstract defs that my added beds inherit from, as shown here:
https://pastebin.com/SUM4g4gT

Problem as it stands is that with the patch as above, the patch isn't being applied when More Furniture is loaded. No errors are showing up in the console log.

Can anyone suggest what I'm doing wrong here?

EDIT: spdskatr on Discord has patiently explained that Shinzy is right, and I didn't need a <success>Invert</success> immediately after the PatchOperationTest xpath, so I've permanently removed it. However, now the patch seems not apply under any circumstance. See below for a small C# workaround.

Shinzy

Okay from what I understand: The Success Invert is a problem here
when the operation fails it will treat it as if it succeeds
and when it succeeds it will treat it as if it fails(citation may be required :p)

your patch tests if it can find the Dresser and if it does, it will stop there.
If the dresser is NOT found it will continue to the Add operation

Try removing the success invert entirely and see what happens?



Edit: Okay I showed this to some modders and it seems there's been others with issues trying to make "cross mod patching" or what you'd call it
This here may be of help https://github.com/cuproPanda/STN/issues/1

Telkir

No dice, though I should have mentioned I did try that already. :( Here's what I've tested:

* Remove <success>Invert</success> - gives no errors regardless of whether More Furniture is loaded or not, but when it is loaded, the patch isn't applied.

* Change "Invert" to "Never" - same as above.

* Remove <success>Always</success> - problem as originally described; patch applies regardless of whether More Furniture is loaded or not.

* Remove both <success>Always</success> and <success>Invert</success> - "Patch operation Verse.PatchOperationSequence failed", regardless of whether More Furniture is loaded or not.

I know some of these things are against logic but I'm just throwing stuff at the walls and seeing what sticks. So far nothing is. :D

skullywag

Telkir you got access to discord would be easier to help out with this sort of thing. Lots of discussions going on about the patching process in there right now as well.
Skullywag modded to death.
I'd never met an iterator I liked....until Zhentar saved me.
Why Unity5, WHY do you forsake me?

Telkir

Yes, I know :)

I'm asking in both places to maximise the chance of finding what's happening a little quicker.

Telkir

Just to update that Shinzy's link was super useful and fixed the problem with some workaround C#:

namespace RWModLoadedChecker
{
    class PatchOperationCheckForMoreFurniture : PatchOperation
    {
        protected override bool ApplyWorker(XmlDocument xml)
        {
            return ModsConfig.ActiveModsInLoadOrder.Any(mod => mod.Name == "More Furniture (A17)");
        }
    }
}


Then using <li Class="RWModLoadedChecker.PatchOperationCheckForMoreFurniture"></li> as the first operation, all works as expected.

Hopefully in the future this can be checked so the pure XML way works as expected, but meanwhile I'm happy :) Thanks to everyone who chimed in here and on Discord!