[TOOL] Verify your XML Patching without running the game

The place to discuss scripting and game modifications for X4: Foundations.

Moderators: Scripting / Modding Moderators, Moderators for English X Forum

SpaceCadet11864
Posts: 476
Joined: Tue, 4. Dec 18, 02:14
x4

[TOOL] Verify your XML Patching without running the game

Post by SpaceCadet11864 »

I really don't want to test whether or not I got the right xpath by running this game, so I set out to find the xml-patch lib, that way I can at least test that I'm patching the files properly, instead of wondering if that's one of the reasons why my code isnt working!

Requires Cygwin or WSL

Download Source
GNU Library or Lesser General Public License version 2.0 (LGPLv2)

Compile from source to use.

Usage:

Code: Select all

xml-patch [OPTIONS] -f <doc> -p <patch>

OPTIONS:
  -v == verbose output
  -o <file> == dumb output to file

returns 0 if succeeds, 1 for an error
Last edited by SpaceCadet11864 on Sat, 15. Dec 18, 19:45, edited 2 times in total.
celludriel
Posts: 163
Joined: Thu, 12. Sep 13, 11:29
x4

Re: [TOOL] Verify your XML Patching without running the game

Post by celludriel »

Doesn't work out of the box though. It assumes Cygwin is installed it seemed. Can it run on just x64 ?

I also found this one https://github.com/dnault/xml-patch it's a java implementation should be multiplatform.
Last edited by celludriel on Sat, 15. Dec 18, 15:04, edited 2 times in total.
SpaceCadet11864
Posts: 476
Joined: Tue, 4. Dec 18, 02:14
x4

Re: [TOOL] Verify your XML Patching without running the game

Post by SpaceCadet11864 »

celludriel wrote: Sat, 15. Dec 18, 14:23 Doesn't work out of the box though. It assumes Cygwin is installed it seemed. Can it run on just x64 ?

I also found this one https://github.com/dnault/xml-patch it's a java implementation should be multiplatform
Oh that's a shame it requires Cygwin, I didn't know that.. You could grab the jar from that one and run it right away if youre using java 8. I couldn't figure out how to compile the source into an exe without using some third party app - I suppose you can run jars if you just have the JRE installed?
https://jcenter.bintray.com/com/github/ ... -0.3.1.jar
celludriel
Posts: 163
Joined: Thu, 12. Sep 13, 11:29
x4

Re: [TOOL] Verify your XML Patching without running the game

Post by celludriel »

SpaceCadet11864 wrote: Sat, 15. Dec 18, 14:55
celludriel wrote: Sat, 15. Dec 18, 14:23 Doesn't work out of the box though. It assumes Cygwin is installed it seemed. Can it run on just x64 ?

I also found this one https://github.com/dnault/xml-patch it's a java implementation should be multiplatform
Oh that's a shame it requires Cygwin, I didn't know that.. You could grab the jar from that one and run it right away if youre using java 8. I couldn't figure out how to compile the source into an exe without using some third party app - I suppose you can run jars if you just have the JRE installed?
https://jcenter.bintray.com/com/github/ ... -0.3.1.jar
I'm not sure about this jar implementation it should have found a match in my example and it didn't ... might be broken

Code: Select all

D:\tools\x4diff\bin>xml-patch FactionLogic.xml FactionLogicDiff.xml result.xml
Exception in thread "main" com.github.dnault.xmlpatch.PatchException: no matches for selector "//cue[@name='FindFactionHeadquarters']/actions/do_if[@exact='faction.argon']/find_cluster/@macro"
        at com.github.dnault.xmlpatch.Patcher.selectNodes(Patcher.java:441)
        at com.github.dnault.xmlpatch.Patcher.replace(Patcher.java:106)
        at com.github.dnault.xmlpatch.Patcher.patch(Patcher.java:88)
        at com.github.dnault.xmlpatch.Patcher.patch(Patcher.java:65)
        at com.github.dnault.xmlpatch.CommandLineDriver.main(CommandLineDriver.java:62)
INPUT:

Code: Select all

...
        <cue name="FindFactionHeadquarters">
          <actions>
            <!-- Preferred Faction HQ depends on the faction -->
            <!-- Argon Federation -->
            <do_if value="$Faction" exact="faction.argon">
              <debug_text text="'Finding Faction HQ for Argon Federation'" chance="$DebugChance" />

              <find_cluster name="$ArgonPrime" macro="macro.cluster_14_macro" />
...
DIFF:

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<diff>
    <replace sel="//cue[@name='FactionLogicManagers']/conditions/check_value/@value">player.galaxy.macro.ismacro.{macro.x3g_galaxy_macro}</replace>
    <replace sel="//cue[@name='FindFactionHeadquarters']/actions/do_if[@exact='faction.argon']/find_cluster/@macro">macro.x3g_cluster01_macro</replace>
    <replace sel="//cue[@name='SetUpNewHeadquarters']/actions/do_if[@exact='faction.argon']/find_cluster/@macro">macro.x3g_cluster01_macro</replace>
    <replace sel="//cue[@name='FindFactionHeadquarters']/actions/do_if[@exact='faction.antigone']/find_cluster/@macro">macro.x3g_cluster16_macro</replace>
    <replace sel="//cue[@name='SetUpNewHeadquarters']/actions/do_elseif[@exact='faction.antigone']/find_cluster/@macro">macro.x3g_cluster16_macro</replace>
    <replace sel="//cue[@name='FindFactionHeadquarters']/actions/do_if[@exact='faction.alliance']/find_cluster/@macro">macro.x3g_cluster31_macro</replace>
    <replace sel="//cue[@name='SetUpNewHeadquarters']/actions/do_elseif[@exact='faction.alliance']/find_cluster/@macro">macro.x3g_cluster31_macro</replace>
    <replace sel="//cue[@name='FindFactionHeadquarters']/actions/do_if[@exact='faction.paranid']/find_cluster/@macro">macro.x3g_cluster32_macro</replace>
    <replace sel="//cue[@name='SetUpNewHeadquarters']/actions/do_elseif[@exact='faction.paranid']/find_cluster/@macro">macro.x3g_cluster32_macro</replace>
    <replace sel="//cue[@name='FindFactionHeadquarters']/actions/do_if[@exact='faction.teladi']/find_cluster/@macro">macro.x3g_cluster41_macro</replace>
    <replace sel="//cue[@name='SetUpNewHeadquarters']/actions/do_elseif[@exact='faction.teladi']/find_cluster/@macro">macro.x3g_cluster41_macro</replace>
    <replace sel="//cue[@name='FindFactionHeadquarters']/actions/do_if[@exact='faction.hatikvah']/find_cluster/@macro">macro.x3g_cluster43_macro</replace>
    <replace sel="//cue[@name='SetUpNewHeadquarters']/actions/do_elseif[@exact='faction.hatikvah']/find_cluster/@macro">macro.x3g_cluster43_macro</replace>
    <replace sel="//cue[@name='FindFactionHeadquarters']/actions/do_if[@exact='faction.scaleplate']/find_cluster/@macro">macro.x3g_cluster44_macro</replace>
    <replace sel="//cue[@name='SetUpNewHeadquarters']/actions/do_elseif[@exact='faction.scaleplate']/find_cluster/@macro">macro.x3g_cluster44_macro</replace>
    <replace sel="//cue[@name='FindFactionHeadquarters']/actions/do_if[@exact='faction.ministry']/find_cluster/@macro">macro.x3g_cluster57_macro</replace>
    <replace sel="//cue[@name='SetUpNewHeadquarters']/actions/do_elseif[@exact='faction.ministry']/find_cluster/@macro">macro.x3g_cluster57_macro</replace>
    <replace sel="//cue[@name='FindFactionHeadquarters']/actions/do_if[@exact='faction.holyorder']/find_cluster/@macro">macro.x3g_cluster67_macro</replace>
    <replace sel="//cue[@name='SetUpNewHeadquarters']/actions/do_elseif[@exact='faction.holyorder']/find_cluster/@macro">macro.x3g_cluster67_macro</replace>
</diff>
it should have found it
SpaceCadet11864
Posts: 476
Joined: Tue, 4. Dec 18, 02:14
x4

Re: [TOOL] Verify your XML Patching without running the game

Post by SpaceCadet11864 »

I think you just need the cygwin dll, which should be very small. If you run the installer and then dont select any packages it would be a fast download, maybe try that?
SpaceCadet11864
Posts: 476
Joined: Tue, 4. Dec 18, 02:14
x4

Re: [TOOL] Verify your XML Patching without running the game

Post by SpaceCadet11864 »

Issue is because context is empty, it looks like they're using a standard xpath library (maybe I'm wrong but im assuming this)
https://github.com/dnault/xml-patch/blo ... #L426-L465

What might be the culprit is:
`bindNamespacePrefixes` - would need to step through the debugger to find out, but really - I'm not sure, it looks like a fun recursion function (selectNodes method)

EDIT: It's possibly a character encoding issue. Like it might be using something different (ISO-whatever something i see java use all the time) instead of UTF-8?
celludriel
Posts: 163
Joined: Thu, 12. Sep 13, 11:29
x4

Re: [TOOL] Verify your XML Patching without running the game

Post by celludriel »

SpaceCadet11864 wrote: Sat, 15. Dec 18, 15:18 Issue is because context is empty, it looks like they're using a standard xpath library (maybe I'm wrong but im assuming this)
https://github.com/dnault/xml-patch/blo ... #L426-L465

What might be the culprit is:
`bindNamespacePrefixes` - would need to step through the debugger to find out, but really - I'm not sure, it looks like a fun recursion function (selectNodes method)

EDIT: It's possibly a character encoding issue. Like it might be using something different (ISO-whatever something i see java use all the time) instead of UTF-8?
I've build the thing with gradle in IDEA. Haven't looked at the code yet but indeed it could be a char encoding issue. Cause the xpath works ingame. Now installing cygwin I can do just the dll in windows. But I need to know to which cygwin version you compiled. I can't just add any cygwin dll, or it won't work I fear.
SpaceCadet11864
Posts: 476
Joined: Tue, 4. Dec 18, 02:14
x4

Re: [TOOL] Verify your XML Patching without running the game

Post by SpaceCadet11864 »

celludriel wrote: Sat, 15. Dec 18, 15:46
SpaceCadet11864 wrote: Sat, 15. Dec 18, 15:18 Issue is because context is empty, it looks like they're using a standard xpath library (maybe I'm wrong but im assuming this)
https://github.com/dnault/xml-patch/blo ... #L426-L465

What might be the culprit is:
`bindNamespacePrefixes` - would need to step through the debugger to find out, but really - I'm not sure, it looks like a fun recursion function (selectNodes method)

EDIT: It's possibly a character encoding issue. Like it might be using something different (ISO-whatever something i see java use all the time) instead of UTF-8?
I've build the thing with gradle in IDEA. Haven't looked at the code yet but indeed it could be a char encoding issue. Cause the xpath works ingame. Now installing cygwin I can do just the dll in windows. But I need to know to which cygwin version you compiled. I can't just add any cygwin dll, or it won't work I fear.
Ohh Ok, I just installed cygwin the day I posted this (i used cygwin to compile to windows, assumed it wouldn't be a dependency!)

Ok so looked at the dll files and it appears to be version 2.11.2
celludriel
Posts: 163
Joined: Thu, 12. Sep 13, 11:29
x4

Re: [TOOL] Verify your XML Patching without running the game

Post by celludriel »

I fully installed the latest cygwin version but it's still not running . There is no log or debug, just application can't run ... ok ... Not sure how we can debug this any better
sobfiggis
Posts: 2
Joined: Sat, 1. Dec 18, 08:51
x4

Re: [TOOL] Verify your XML Patching without running the game

Post by sobfiggis »

For anyone curious. You do not need cygwin to build this. You can use windows subsystem for linux. (Bash for windows..)

Just install dependencies and build using the instructions provided in the README.

Code: Select all

> sudo apt install build-essential pkg-config libxml2-dev xmldiff
If you get the following error:

Code: Select all

xml-diff: error while loading shared libraries: libxmlpatch.so.0: cannot open shared object file: No such file or directory
You will need to update your path (may want to put this in your bashrc..)

Code: Select all

> export LD_LIBRARY_PATH=/lib:/usr/lib:/usr/local/lib
SpaceCadet11864
Posts: 476
Joined: Tue, 4. Dec 18, 02:14
x4

Re: [TOOL] Verify your XML Patching without running the game

Post by SpaceCadet11864 »

Thanks sob, I was trying to set it up so people didn't have to build it, but it looks like that is probably going to be the only way. So I went ahead and updated the initial post! Thanks!
kuertee
EGOSOFT
EGOSOFT
Posts: 818
Joined: Sun, 14. Dec 03, 13:05
x4

Re: [TOOL] Verify your XML Patching without running the game

Post by kuertee »

Here's a simple online tool that I found: https://extendsclass.com/xpath-tester.html
Simply paste the XML code, and your XPath expression, it'll tell you the block that it finds.

E.g. I pasted the factionlogic_economy.xml, I typed in my XPath: "//cue[@name='Request_Commandeerable_Freighter']/actions/do_if[@value='$TestJob']/do_if[@value='$Ship.exists']/do_if[@value='$Miner']",
and it returned this correct block:

Code: Select all

<do_if value="$Miner">
                  <!-- Miner -->
                  <create_order id="'MiningRoutine'" object="$Ship" immediate="true">
                    <param name="warebasket" value="[$Ware]"/>
                    <param name="range" value="$RequestSector"/>
                    <param name="minbuy" value="0"/>
                    <param name="maxbuy" value="5"/>
                    <param name="minsell" value="0"/>
                    <param name="maxsell" value="0"/>
                    <param name="duration" value="$Duration"/>
                    <param name="debugchance" value="$AIDebugChance"/>
                  </create_order>
                </do_if>

Return to “X4: Foundations - Scripts and Modding”