[TUTORIAL] XML Patch Guide

The place to discuss scripting and game modifications for X Rebirth.

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

UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader » Thu, 12. Nov 15, 20:48

just checked myself: the lines you mentoined are not in that file, only available ones are:
XPath query for GM_Defend_Station.xml: //add_npc_line
Node add_npc_line speaker="$Client" line="3015" weight="50"
Node add_npc_line speaker="$Client" line="3016" weight="50"
Node add_npc_line speaker="$Client" line="3017" weight="50"
Node add_npc_line speaker="$Client" line="3018" weight="50"
Node add_npc_line speaker="$Client" line="3001" weight="50"
Node add_npc_line speaker="$Client" line="3002" weight="50"
Node add_npc_line line="12" comment="Goodbye."

where do you have your pasted Code from? possibly a Version prior to 3.61 or 4.0?
if not stated otherwise everything i post is licensed under WTFPL

Ich mache keine S&M-Auftragsarbeiten, aber wenn es fragen gibt wie man etwas umsetzen kann helfe ich gerne weiter ;)

I wont do Script&Mod Request work, but if there are questions how to do something i will GLaDly help ;)

w.evans
Posts: 2963
Joined: Tue, 18. Nov 14, 16:23
x4

Post by w.evans » Thu, 12. Nov 15, 21:08

Ah, that's right! Was wondering about this.

In GM_Defend_Station from 3.61, each of those numbers occurs only in one line each. In 4.00, there aren't any with line="13" and line="1031"

@pref, I'm guessing you unpacked 09.cat/dat, then updated to 4.00? If so, your diff is working with a different file.

pref
Posts: 5579
Joined: Sat, 10. Nov 12, 17:55
x4

Post by pref » Thu, 12. Nov 15, 21:22

I just ran XRCatToolGUI and took the md folder out.
Only have 3 occurrences there :o

How did you get that file? My XR is 4.x, says beta at splash screen.

UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader » Thu, 12. Nov 15, 21:36

which one did you use? possibly from an earlier catalog than 09? (where the current one is)

if you reference the one in the catalog 08 - that one is from an older Version and not used anymore.
if not stated otherwise everything i post is licensed under WTFPL

Ich mache keine S&M-Auftragsarbeiten, aber wenn es fragen gibt wie man etwas umsetzen kann helfe ich gerne weiter ;)

I wont do Script&Mod Request work, but if there are questions how to do something i will GLaDly help ;)

pref
Posts: 5579
Joined: Sat, 10. Nov 12, 17:55
x4

Post by pref » Fri, 13. Nov 15, 00:59

Yep, i used the ones from cat08.. would have never thought it has 2 instances of the whole md folder overwriting eachother.

Anyway another OT question: Is there a way to get rid of these diff errors?

Code: Select all

[General] ======================================
[=ERROR=] Error loading MD file extensions\SilenceYouAll\md\NPC_Shiptrader_Small.xml: Ignoring root node 'diff' in XML file 'extensions\SilenceYouAll\md\NPC_Shiptrader_Small.xml'.
The diff file has no errors and is exeecuted peroperly, but still i get one of these for each patch i have.

And thanks for pointing me to cat9, who knows how much time i would have wasted on google if not for you guys :)

Xuu42
Posts: 7
Joined: Mon, 22. Feb 16, 20:54

Post by Xuu42 » Mon, 22. Feb 16, 21:14

Hi all,
one question about changing single values in xml files via the diff / replace method.

The file i want to modify is "engineer.player.xml"
this is the source line i want to change:
<set_value name="$maxhullpercent" exact="60 + (30 * this.combinedskill / 100)" comment="between 60% and 100%"/>
to
exact="60 + (40 * this.combinedskill / 100)"
comment="between 60% and 100%"/>

My Problem is to find the right "Sel =" Value for adressing this.

I saw some mods doing this, but they all replace the complete script
even they change only this line:
<replace sel="/aiscript[@name='engineer.player']">

if i only need to change a single value, i dont want to replace the whole script
if possible.

as far is a understand the diff / replace xml patch there should be a way of ding this.

UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader » Mon, 22. Feb 16, 22:58

the single line is not enough to get a Path, you need the context , too ;)

two possibilities:
long variant:

Code: Select all

<replace sel='/aiscript/attention/actions/set_value[@name="$maxhullpercent"]/@exact'>60 + (40 * this.combinedskill / 100)</replace>
short Variant ( since //set_value[@name="$maxhullpercent"] is unique in this Script):

Code: Select all

<replace sel='//set_value[@name="$maxhullpercent"]/@exact'>60 + (40 * this.combinedskill / 100)</replace>
you can confirm the sel paths by using » Extensions/XML Tools/Evaluate XPath Expression « in NPP, or similiar functions in other XML Editors ;)
if not stated otherwise everything i post is licensed under WTFPL

Ich mache keine S&M-Auftragsarbeiten, aber wenn es fragen gibt wie man etwas umsetzen kann helfe ich gerne weiter ;)

I wont do Script&Mod Request work, but if there are questions how to do something i will GLaDly help ;)

jth
Posts: 296
Joined: Tue, 3. Jan 06, 23:31
x3

Post by jth » Tue, 23. Feb 16, 13:26

UniTrader wrote:you can confirm the sel paths by using » Extensions/XML Tools/Evaluate XPath Expression « in NPP, or similiar functions in other XML Editors ;)
I didn't realise that you could do this so gave it a try on a small diff file of mine using NPP

It came back with

Validation of current file using XML schema:


ERROR: Element 'diff': This element is not expected.

I have a feeling that the diff element is missing from my rfc5261.xsd https://www.dropbox.com/s/94t86p236o5b4 ... h.xsd?dl=0

I found one from MadJoker my copy https://www.dropbox.com/s/p29kj66zbin45 ... 1.xsd?dl=0 that gets a bit further, it has a diff element at the bottom

ERROR: Element 'add': This element is not expected.


Do you have a working link to your rfc5261.xsd file please ?

Thanks

jth

UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader » Tue, 23. Feb 16, 15:17

jth wrote:
UniTrader wrote:you can confirm the sel paths by using » Extensions/XML Tools/Evaluate XPath Expression « in NPP, or similiar functions in other XML Editors ;)
I didn't realise that you could do this so gave it a try on a small diff file of mine using NPP

It came back with

Validation of current file using XML schema: Element 'diff': This element is not expected.
Thats not what I meant - I meant opening the original file and making an XPath query there - for valid sel expressions there must be exactly one result ;)

And although I have an rfc5261.xsd lying around somewhere I have not used it yet.. The 4 possible nodes it contains can be written from memory and the anycontent in the add node also isn't much help (checking if its well-formed is a must though - but this does not require an xsd)
if not stated otherwise everything i post is licensed under WTFPL

Ich mache keine S&M-Auftragsarbeiten, aber wenn es fragen gibt wie man etwas umsetzen kann helfe ich gerne weiter ;)

I wont do Script&Mod Request work, but if there are questions how to do something i will GLaDly help ;)

UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader » Tue, 23. Feb 16, 15:18

jth wrote:
UniTrader wrote:you can confirm the sel paths by using » Extensions/XML Tools/Evaluate XPath Expression « in NPP, or similiar functions in other XML Editors ;)
I didn't realise that you could do this so gave it a try on a small diff file of mine using NPP

It came back with

Validation of current file using XML schema: Element 'diff': This element is not expected.
Thats not what I meant - I meant opening the original file and making an XPath query there - for valid sel expressions there must be exactly one result ;)

And although I have an rfc5261.xsd lying around somewhere I have not used it yet.. The 4 possible nodes it contains can be written from memory and the anycontent in the add node also isn't much help (checking if its well-formed is a must though - but this does not require an xsd)
if not stated otherwise everything i post is licensed under WTFPL

Ich mache keine S&M-Auftragsarbeiten, aber wenn es fragen gibt wie man etwas umsetzen kann helfe ich gerne weiter ;)

I wont do Script&Mod Request work, but if there are questions how to do something i will GLaDly help ;)

jth
Posts: 296
Joined: Tue, 3. Jan 06, 23:31
x3

Post by jth » Tue, 23. Feb 16, 15:28

UniTrader wrote:
jth wrote:
UniTrader wrote:you can confirm the sel paths by using » Extensions/XML Tools/Evaluate XPath Expression « in NPP, or similiar functions in other XML Editors ;)
I didn't realise that you could do this so gave it a try on a small diff file of mine using NPP

It came back with

Validation of current file using XML schema: Element 'diff': This element is not expected.
Thats not what I meant - I meant opening the original file and making an XPath query there - for valid sel expressions there must be exactly one result ;)

And although I have an rfc5261.xsd lying around somewhere I have not used it yet.. The 4 possible nodes it contains can be written from memory and the anycontent in the add node also isn't much help (checking if its well-formed is a must though - but this does not require an xsd)
Oops misunderstood :( Will continue to write my diff files in MS Visual C# to get the syntax checked there.

jth

Xuu42
Posts: 7
Joined: Mon, 22. Feb 16, 20:54

Post by Xuu42 » Tue, 23. Feb 16, 22:28

big thx for the fast answer.
coding xml is (was) a bit new for me
i got myself some xml editors, an read a lot about XR modding
btw anaylsing "engineer.player.xml" i discovered that the onboard
egineer only repairs components.
so even it got my first solution running with changing only some values
via diff/replace doesent help for my target:
"onboad engineer repairs hull too"
at last i learned how to replace some values and not to replace the whole script. (great tutorial at beginning of this thread, big thx)

in my 2nd solution i had to add and reorganize some code , change debug infos etc. , so v2 replaces the whole script. ("engineer.player.xml")
Now my onboard engineer on the skunk repairs my hull, after he
repaired all other stuff. repairpercentage depends on his skills.
i also reduced the repair speed, original took only seconds, far
away from realism, at last on my opinion.

and now looking forward to 25.feb what will bring the XR 4.0 patch
and the new dlc :)

UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader » Tue, 23. Feb 16, 22:47

currently cannt look in the original file but if you are going for a complete rewrite of a vanilla Script (not preserving Blocking actions or dont want to care about them) i would suggest to copy the original Script to a completely new Script where you can do all your canges freely and call this script from the original Script either as interrupt script or as called Script (latter case only works if there are deactivated blocking actions from before a major overhaul) - this way you dont have to care about the Script Structure and when you remove your changed script it will go back to the old behavior without problems. this may not be the case if you change the original Script and additionally may introduce compatibility issues if ego ecides to update this Script..
if not stated otherwise everything i post is licensed under WTFPL

Ich mache keine S&M-Auftragsarbeiten, aber wenn es fragen gibt wie man etwas umsetzen kann helfe ich gerne weiter ;)

I wont do Script&Mod Request work, but if there are questions how to do something i will GLaDly help ;)

Xuu42
Posts: 7
Joined: Mon, 22. Feb 16, 20:54

Post by Xuu42 » Wed, 24. Feb 16, 19:25

Hi Unitrader,
i copied the the script "engineer.player.xml" from the original game (V3.161)
then i added diff / replace code to replace the complete script,
so i am using a modified original script.
- changed debug statements , added "Filter=error", set chance to 100
to get debug info.
- adde new code for the hull repair with debugstatements.

Blocking actions are new for me, can you provide a linke where
to get detailed infos ?

"Call the script from the original script as interrupt or as called script"
sounds interesting. would like to see some code examples
any links for infos ?

btw thanks

User avatar
Simoom
Posts: 1110
Joined: Sat, 30. Oct 10, 14:14
x4

Post by Simoom » Thu, 28. Apr 16, 17:07

Hey everyone, got a question for you...

What do I do if I wish to patch a part of a file that's being added to by another extension?

Case and point: I want to patch weaponmods.xml in the libraries folder. Obviously this includes patching the weaponmods that come with the two DLC's as well. But the DLC's themselves are also considered extensions and they are adding the weaponmods for the new weapons via <add sel= >

I am guessing for my patch to work, it will have to load after the Egosoft extensions... but how do I ensure that?

UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader » Thu, 28. Apr 16, 17:25

1. you can change the load order with an
<dependency id="***ID of other mod" optional="true" />
to make sure your mod is loaded after another mod if present (if you leave out the optional the other mod is a requirement and it wont work without)

2. then just do your changes as if the other patch file already did its work. if some f the operations might not be possible because of missing Extensions (or Extensions breaking them) mark them with an optional="true" to suppress related errors (or was it silent="true" ? :gruebel: )
like this:
<add sel="///////////" optional="true"><Your_additional_stuff/></add>
if not stated otherwise everything i post is licensed under WTFPL

Ich mache keine S&M-Auftragsarbeiten, aber wenn es fragen gibt wie man etwas umsetzen kann helfe ich gerne weiter ;)

I wont do Script&Mod Request work, but if there are questions how to do something i will GLaDly help ;)

pref
Posts: 5579
Joined: Sat, 10. Nov 12, 17:55
x4

Post by pref » Thu, 28. Apr 16, 19:20

You have to set a dependency on the DLCs.

If you want to affect only the load order, but not depend on other extensions, then you can add a line like this in content.xml (note the optional attribute):

Code: Select all

<content ... >
  <dependency id="ws_xxxxxxxx" optional="true" name="ModName"></dependency> 
</content>
However it only works for workshop mods - iirc not even DLCs, so it might be that you have to set a dependency then. If this is the case, you might have to release a compatibility mod for the DLC(s) separately which depends on the DLC(s) and your original mod.

User avatar
Simoom
Posts: 1110
Joined: Sat, 30. Oct 10, 14:14
x4

Post by Simoom » Fri, 29. Apr 16, 00:29

Okay, thank you! :)

I am trying to find a way to customize the attributes of spawned weaponmods for my cheat script (and since there's no way to specify the attributes of spawned inventory ware directly through script at the moment... had to resort to patching).

So I wrote this as a test (for libraries/weaponmods.xml)
Replacing this:

Code: Select all

    <weapon macro="weapon_player_impulse_mk1_macro" weight="10"><!--0.135-->
      <damage min="1.05" max="1.1" weight="18"/>
      <cooling min="0.92" max="1.77" weight="2"/>
      <reload min="0.6" max="1.04" weight="13"/>
      <speed min="0.4" max="1.1" weight="3"/>
      <lifetime min="1.05" max="2.0" weight="14"/>
    </weapon>
With:

Code: Select all

  <replace sel="/weaponmods/weapons/weapon[@macro='weapon_player_impulse_mk1_macro']/damage">
    <damage exact="1.5" weight="18"/>
  </replace>
  <replace sel="/weaponmods/weapons/weapon[@macro='weapon_player_impulse_mk1_macro']/cooling">
    <cooling exact="3" weight="2"/>
  </replace>
  <replace sel="/weaponmods/weapons/weapon[@macro='weapon_player_impulse_mk1_macro']/reload">
    <reload exact="1.5" weight="13"/>
  </replace>
  <replace sel="/weaponmods/weapons/weapon[@macro='weapon_player_impulse_mk1_macro']/speed">
    <speed exact="1.5" weight="3"/>
  </replace>
  <replace sel="/weaponmods/weapons/weapon[@macro='weapon_player_impulse_mk1_macro']/lifetime">
    <lifetime exact="2.0" weight="14"/>
  </replace>
The weaponmods now spawn with no attributes at all... but I am not sure what's wrong with it. :( Is the game expecting ONLY min-max values or something?

UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader » Fri, 29. Apr 16, 00:36

Simoom wrote:The weaponmods now spawn with no attributes at all... but I am not sure what's wrong with it. :( Is the game expecting ONLY min-max values or something?
according to xsd file yes.
if not stated otherwise everything i post is licensed under WTFPL

Ich mache keine S&M-Auftragsarbeiten, aber wenn es fragen gibt wie man etwas umsetzen kann helfe ich gerne weiter ;)

I wont do Script&Mod Request work, but if there are questions how to do something i will GLaDly help ;)

User avatar
Simoom
Posts: 1110
Joined: Sat, 30. Oct 10, 14:14
x4

Post by Simoom » Wed, 4. May 16, 02:22

Hey everyone, sorry for so many questions... :oops:
  1. I am trying to patch some more files right now, and am wondering if there's an easier way to patch an entire block of text, or if I have to do it line by line? I see that <remove> has a ws attribute that allows me to remove a whole node block... but can I do something similar with <replace>?
  2. Does the line I replace always have to be closed? I need to replace this (from Upkeep.xml) with some values of my own:

    Code: Select all

    <do_if value="not $Ship.buildmodule and $Ship.primarypurpose != objectpurpose.mine">
    But as you can see this tag is not closed, and Visual Studio flags it.

Post Reply

Return to “X Rebirth - Scripts and Modding”