[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 » Fri, 13. May 16, 13:02

2 possibilities:

either use brackets as i initially said:

Code: Select all

  <remove sel="//library[@name='CheckObject']/actions/do_if/do_if/do_if[@value='md.$AllowMultiMissions or not @$HasMission']/do_all/do_if[@value='$Object.isclass.ship_l or $Object.isclass.ship_xl']/do_if[do_if/do_if/signal_cue_instantly[@cue='md.Upkeep.Deliver_Unit_Start']]"/>
  <remove sel="//library[@name='CheckObject']/actions/do_if/do_if/do_if[@value='md.$AllowMultiMissions or not @$HasMission']/do_all/do_if[@value='$Object.isclass.ship_l or $Object.isclass.ship_xl']/do_if[do_if/do_if/signal_cue_instantly[@cue='md.Upkeep.Deliver_Unit_Start']]"/>
or go down the Path a few more levels and then go back up:

Code: Select all

  <remove sel="//library[@name='CheckObject']/actions/do_if/do_if/do_if[@value='md.$AllowMultiMissions or not @$HasMission']/do_all/do_if[@value='$Object.isclass.ship_l or $Object.isclass.ship_xl']/do_if/do_if/do_if/signal_cue_instantly[@cue='md.Upkeep.Deliver_Unit_Start']/../../.."/>
  <remove sel="//library[@name='CheckObject']/actions/do_if/do_if/do_if[@value='md.$AllowMultiMissions or not @$HasMission']/do_all/do_if[@value='$Object.isclass.ship_l or $Object.isclass.ship_xl']/do_if/do_if/do_if/signal_cue_instantly[@cue='md.Upkeep.Deliver_Unit_Start']/../../.."/>
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 » Fri, 13. May 16, 14:25

I see! Thank you again UniTrader! :)

ns88ns
Posts: 90
Joined: Sun, 11. Sep 11, 22:00
x4

Post by ns88ns » Mon, 19. Dec 16, 20:00

Hi, folks.

There is directive <patch/> in MD scripts. I checked XR Wiki and Google but I found almost nothing... So the questions are:

- What is it?
- What it does?
- How it works?

Perhaps I missed somethig so if you point me to the threads/resources where <patch/> is described - then it will be nice.

Thank you in advance.

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

Post by UniTrader » Mon, 19. Dec 16, 20:10

patch nodes in md are basically actions performed when the version of the cue in the md script file has increased compared to the version stored in the savegame. you can also filtler if the respective patch node should be performed when the cue is complete, canceled, waiting etc.

see also the libraries/md.xsd:

Code: Select all

      <xs:element name="patch" minOccurs="0" maxOccurs="unbounded">
        <xs:annotation>
          <xs:documentation>
            Actions for patching a cue of an older version (will be performed when loading the MD script from a save).
            Patches are applied to waiting, active or complete cues (see state attribute).
            This includes library users and instances, except for completed instances that have already been deleted.
          </xs:documentation>
        </xs:annotation>
        <xs:complexType>
          <xs:group ref="actions" />
          <xs:attribute name="sinceversion" use="required" type="xs:positiveInteger">
            <xs:annotation>
              <xs:documentation>
                Cue version at which this patch element was added (it will only be applied when loading a cue of an older version)
              </xs:documentation>
            </xs:annotation>
          </xs:attribute>
          <xs:attribute name="state">
            <xs:annotation>
              <xs:documentation>
                Required state that this cue must be in for this patch to be applied (default is complete)
              </xs:documentation>
            </xs:annotation>
            <xs:simpleType>
              <xs:restriction base="xs:string">
                <xs:enumeration value="complete">
                  <xs:annotation>
                    <xs:documentation>
                      Apply patch only if this cue is complete (default)
                    </xs:documentation>
                  </xs:annotation>
                </xs:enumeration>
                <xs:enumeration value="waiting">
                  <xs:annotation>
                    <xs:documentation>
                      Apply patch only if this cue is waiting (conditions are being checked)
                    </xs:documentation>
                  </xs:annotation>
                </xs:enumeration>
                <xs:enumeration value="active">
                  <xs:annotation>
                    <xs:documentation>
                      Apply patch only if this cue is active (not complete yet because of a delay)
                    </xs:documentation>
                  </xs:annotation>
                </xs:enumeration>
              </xs:restriction>
            </xs:simpleType>
          </xs:attribute>
          <xs:attribute name="comment" type="comment" />
        </xs:complexType>
      </xs:element>
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 ;)

ns88ns
Posts: 90
Joined: Sun, 11. Sep 11, 22:00
x4

Post by ns88ns » Mon, 19. Dec 16, 20:50

Clear... Will read the XDS more attentively.
Thanks a lot.

ns88ns
Posts: 90
Joined: Sun, 11. Sep 11, 22:00
x4

Post by ns88ns » Sat, 3. Mar 18, 03:53

Hi.

I would like to ask is there a way to perform mass-replacement? Take a look on data below:
source is:

Code: Select all

<alpha>
  <bravo>
    <chalie attr="a_class_1" />
      <delta attr="b_class_1" />
    </charlie>
    <chalie attr="a_class_2" />
      <delta attr="b_class_2" />
    </charlie>
    <chalie attr="a_class_3" />
      <delta attr="b_class_3" />
    </charlie>
    <chalie attr="a_class_4" />
      <delta attr="c_class_1" />
    </charlie>
    <chalie attr="a_class_5" />
      <delta attr="c_class_2" />
    </charlie>
  </bravo>
</alpha>
Now I''m trying to replace all

Code: Select all

<delta attr="b_class_*" />
with

Code: Select all

<delta attr="e_class_0" />
I tried code below:

Code: Select all

<diff>
  <replace sel="//delta[starts-with(@attr,'b_class_')]">
    <delta attr="e_class_0" />
  </replace>
</diff>
It is just example and selector properly returns set of elements to replace but XR doesn't allow. It logs error:

Code: Select all

["message"]="Error: Multiple matching nodes for path '//macro[starts-with(@ref,'struct_econ_prod_') and contains(@ref,'_stor_')]' in patch file 'extensions\\long_path_here'. Skipping node.",
Thank you.

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

Post by UniTrader » Sat, 3. Mar 18, 10:59

nope, no mass replacements. (there is an inofficial Extension which has an msel Attribute, but EGO has not implemented it)

but you can make the sel to apply to the first occurence and duplicate/copy the line as often as needed:
<replace sel="(//delta[starts-with(@attr,'b_class_')])[1]">
if the Path still applies after the change also increase the number in square brackets ;)
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 ;)

ns88ns
Posts: 90
Joined: Sun, 11. Sep 11, 22:00
x4

Post by ns88ns » Sat, 3. Mar 18, 14:27

Clear. Nice workarround. It will work for me.
Thank you a lot for explanation.

user1679
Posts: 756
Joined: Fri, 20. Jul 18, 23:20

Re: [TUTORIAL] XML Patch Guide

Post by user1679 » Thu, 20. Aug 20, 05:04

How would I patch an MD script from another mod?

For example, I use the mod Rise of the Ossian Raider and usually set it to difficulty Normal or Hard. Since this defaults to "very easy", how would I patch the MD script instead of having to package the whole 300 Mb mod into a separate version? Would I use a DIFF patching method or could I package my modified \md\ror_setup.xml into a 'sub_01.cat' (I don't know what sub cats are)?

The line I'm interested in changing is:

Code: Select all

<mdscript xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Ror_setup" xsi:noNamespaceSchemaLocation="md.xsd">
	<cues>	
		<cue name="Ror_Setup_root" version="3">
			<conditions>
			<!--	<event_cue_signalled cue="md.Setup.GameStart"/> -->
				<event_player_created/>
			</conditions>
			<delay exact="10s"/>
			<actions>
			<set_value name="global.$RorSetting.$Difficulty" exact="0" comment="Very Easy - No Invasions"/>
and I want to create two patches that can be enabled as mods that change it to:

Code: Select all

<set_value name="global.$RorSetting.$Difficulty" exact="2" comment="Normal - Invasions"/>

Code: Select all

<set_value name="global.$RorSetting.$Difficulty" exact="3" comment="Hard - Invasions"/>

Clownmug
Posts: 418
Joined: Wed, 11. Dec 13, 02:39
x4

Re: [TUTORIAL] XML Patch Guide

Post by Clownmug » Thu, 20. Aug 20, 14:06

user1679 wrote:
Thu, 20. Aug 20, 05:04
How would I patch an MD script from another mod?

For example, I use the mod Rise of the Ossian Raider and usually set it to difficulty Normal or Hard. Since this defaults to "very easy", how would I patch the MD script instead of having to package the whole 300 Mb mod into a separate version? Would I use a DIFF patching method or could I package my modified \md\ror_setup.xml into a 'sub_01.cat' (I don't know what sub cats are)?

The line I'm interested in changing is:

Code: Select all

<mdscript xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Ror_setup" xsi:noNamespaceSchemaLocation="md.xsd">
	<cues>	
		<cue name="Ror_Setup_root" version="3">
			<conditions>
			<!--	<event_cue_signalled cue="md.Setup.GameStart"/> -->
				<event_player_created/>
			</conditions>
			<delay exact="10s"/>
			<actions>
			<set_value name="global.$RorSetting.$Difficulty" exact="0" comment="Very Easy - No Invasions"/>
and I want to create two patches that can be enabled as mods that change it to:

Code: Select all

<set_value name="global.$RorSetting.$Difficulty" exact="2" comment="Normal - Invasions"/>

Code: Select all

<set_value name="global.$RorSetting.$Difficulty" exact="3" comment="Hard - Invasions"/>
I don't think you need to patch their file since the difficulty is set as a global variable, it should be accessible from other mdscripts.

If you do need to make a patch though, you would have to create an extensions folder within your own mod, then put the file being patched from the other mod in there.

Example: your_mod\extensions\ror\md\ror_setup.xml

user1679
Posts: 756
Joined: Fri, 20. Jul 18, 23:20

Re: [TUTORIAL] XML Patch Guide

Post by user1679 » Fri, 21. Aug 20, 08:58

Clownmug wrote:
Thu, 20. Aug 20, 14:06
user1679 wrote:
Thu, 20. Aug 20, 05:04
How would I patch an MD script from another mod?

For example, I use the mod Rise of the Ossian Raider and usually set it to difficulty Normal or Hard. Since this defaults to "very easy", how would I patch the MD script instead of having to package the whole 300 Mb mod into a separate version? Would I use a DIFF patching method or could I package my modified \md\ror_setup.xml into a 'sub_01.cat' (I don't know what sub cats are)?

The line I'm interested in changing is:

Code: Select all

<mdscript xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Ror_setup" xsi:noNamespaceSchemaLocation="md.xsd">
	<cues>	
		<cue name="Ror_Setup_root" version="3">
			<conditions>
			<!--	<event_cue_signalled cue="md.Setup.GameStart"/> -->
				<event_player_created/>
			</conditions>
			<delay exact="10s"/>
			<actions>
			<set_value name="global.$RorSetting.$Difficulty" exact="0" comment="Very Easy - No Invasions"/>
and I want to create two patches that can be enabled as mods that change it to:

Code: Select all

<set_value name="global.$RorSetting.$Difficulty" exact="2" comment="Normal - Invasions"/>

Code: Select all

<set_value name="global.$RorSetting.$Difficulty" exact="3" comment="Hard - Invasions"/>
I don't think you need to patch their file since the difficulty is set as a global variable, it should be accessible from other mdscripts.

If you do need to make a patch though, you would have to create an extensions folder within your own mod, then put the file being patched from the other mod in there.

Example: your_mod\extensions\ror\md\ror_setup.xml
I made my own basic gamestart where I start at an Argon wharf with the cheapest ship and no money. I was thinking I could add this 'extensions' folder to that but is there anything I need to do to tell the game to prioritize the load order?

Thanks!

Clownmug
Posts: 418
Joined: Wed, 11. Dec 13, 02:39
x4

Re: [TUTORIAL] XML Patch Guide

Post by Clownmug » Fri, 21. Aug 20, 14:02

user1679 wrote:
Fri, 21. Aug 20, 08:58
Clownmug wrote:
Thu, 20. Aug 20, 14:06
user1679 wrote:
Thu, 20. Aug 20, 05:04
I don't think you need to patch their file since the difficulty is set as a global variable, it should be accessible from other mdscripts.

If you do need to make a patch though, you would have to create an extensions folder within your own mod, then put the file being patched from the other mod in there.

Example: your_mod\extensions\ror\md\ror_setup.xml
I made my own basic gamestart where I start at an Argon wharf with the cheapest ship and no money. I was thinking I could add this 'extensions' folder to that but is there anything I need to do to tell the game to prioritize the load order?

Thanks!
In the your mod's content.xml file you can add a dependency for the Rise of the Ossian Raider mod.

Something like this:

Code: Select all

<?xml version="1.0" encoding="utf-8" ?>
<content id="example_id" name="Example" description="Example Description" version="100">
  <dependency id="ws_1705279348" optional="true" name="Rise of the Ossian Raider" />
</content>

user1679
Posts: 756
Joined: Fri, 20. Jul 18, 23:20

Re: [TUTORIAL] XML Patch Guide

Post by user1679 » Sat, 22. Aug 20, 09:25

Clownmug wrote:
Fri, 21. Aug 20, 14:02
user1679 wrote:
Fri, 21. Aug 20, 08:58
Clownmug wrote:
Thu, 20. Aug 20, 14:06


I don't think you need to patch their file since the difficulty is set as a global variable, it should be accessible from other mdscripts.

If you do need to make a patch though, you would have to create an extensions folder within your own mod, then put the file being patched from the other mod in there.

Example: your_mod\extensions\ror\md\ror_setup.xml
I made my own basic gamestart where I start at an Argon wharf with the cheapest ship and no money. I was thinking I could add this 'extensions' folder to that but is there anything I need to do to tell the game to prioritize the load order?

Thanks!
In the your mod's content.xml file you can add a dependency for the Rise of the Ossian Raider mod.

Something like this:

Code: Select all

<?xml version="1.0" encoding="utf-8" ?>
<content id="example_id" name="Example" description="Example Description" version="100">
  <dependency id="ws_1705279348" optional="true" name="Rise of the Ossian Raider" />
</content>
Thank you.

BigGreenThugs
Posts: 89
Joined: Thu, 26. Mar 20, 16:50
x4

Re: [TUTORIAL] XML Patch Guide

Post by BigGreenThugs » Thu, 10. Sep 20, 03:45

how do I make this:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <bar>
    <foo a="1" b="taco elephant rocket spade shoe"/>
  </bar>
</root>
into this:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <bar>
    <foo a="1" b="taco elephant bicycle rocket spade shoe"/>
  </bar>
</root>
EDIT: My apologies if this question seems obtuse. I read the entire thread and did not see this specific example. Maybe it was covered by a different example but I didn't find anything close enough for me to feel comfortable. What I'd really like to do is add mining to the types of weapons that can be mounted on a small ship. The Theseus can do this already and I'd like have that capability on more than one ship. This makes early money in game more easily obtained if you choose to mine crystals as it then allows you to destroy the asteroids for unstable crystals, lodestones, and spacefly eggs.

For example: The Callisto is cheap, has 2 weapon mount points, and even if ARG/ANT hates you you can get one from ALI. What you can't do is mount a mining laser. so how do I make:

Code: Select all

<connection name="con_weapon_005" tags="weapon small standard missile platformcollision symmetry symmetry_right symmetry_top ">
into

Code: Select all

<connection name="con_weapon_005" tags="weapon small standard mining missile platformcollision symmetry symmetry_right symmetry_top ">

BigGreenThugs
Posts: 89
Joined: Thu, 26. Mar 20, 16:50
x4

Re: [TUTORIAL] XML Patch Guide

Post by BigGreenThugs » Mon, 21. Sep 20, 21:46

My question was answered in the unofficial discord by UniTrader. The answer is quoted below. All Credit to UniTrader.

@BigGreenThugs you can only replace the full content of an attribute

Code: Select all

<replace sel="//connection[@name='con_weapon_005']/@tags">weapon small standard mining missile platformcollision symmetry symmetry_right symmetry_top</replace>

Dev disco
Posts: 33
Joined: Wed, 2. Dec 20, 16:35

Re: [TUTORIAL] XML Patch Guide

Post by Dev disco » Wed, 17. Feb 21, 17:09

I think this should go here.... if not I will make a separate post.

I want to add a bit more variety to the pirate spawns. I am good friends with all the 'normal' factions, and I am a bit fed up capping yet another Rahanas hybrid or Sahanar.
So I decided to try my hand on modding. I figured out that I need shipgroups.xml, and used this code:

Code: Select all

	
<replace sel="/groups/group[@name='sov_trader_l_grp']"> 	
	  <group name="sov_trader_l_grp">
		<select macro="units_size_l_kit_container_02_macro" weight="20"/> 
		<select macro="units_size_l_kit_bulk_01_macro" weight="20"/>
		<select macro="units_size_l_kit_energy_01_macro" weight="20"/>
		<select macro="units_size_l_kit_liquid_01_macro" weight="20"/>
		<select macro="units_size_l_silicon_collector_macro" weight="10"/>
		<select macro="units_size_l_hydrogen_collector_macro" weight="10"/>	
	</group>
</replace>   
This works fine, just like the other groups that came with the original game.
However, I can't get those bloody Atlas Pirates to be a bit more inclusive in their taste in ships.

Code: Select all

 <replace sel="/groups/group[@name='atl_trader_l_grp']"> 	
	  <group name="atl_trader_l_grp">
		<select macro="units_size_l_kit_container_02_macro" weight="20"/> 
		<select macro="units_size_l_kit_bulk_01_macro" weight="20"/>
		<select macro="units_size_l_kit_energy_01_macro" weight="20"/>
		<select macro="units_size_l_kit_liquid_01_macro" weight="20"/>
		<select macro="units_size_l_te_kit_bulk_03_macro" weight="5"/>
		<select macro="units_size_l_te_kit_container_03_macro" weight="5"/>		
		<select macro="units_size_l_te_kit_energy_03_macro" weight="5"/>		
		<select macro="units_size_l_te_kit_liquid_03_macro" weight="5"/>		
	  </group>
</replace> 
This doesn't do a thing, and I bet because the official extensions are giving me the finger.
I thought that I was the one in charge here, at least that's what I hear all the time...
How do I solve this?

PS1 Would this be the 'group' that spawns these endless Phoenixes:

Code: Select all

sel="/groups/group[@name='te_destroyer_light_grp']"> 
PS2 Is there a way to figure out which Albatros (vanilla or xl) belongs to which macro?

User avatar
KrYcHokE
Posts: 259
Joined: Wed, 2. Dec 15, 13:15
x4

Re: [TUTORIAL] XML Patch Guide

Post by KrYcHokE » Thu, 18. Feb 21, 20:25

Your extension should have dependency to dlc

Dev disco
Posts: 33
Joined: Wed, 2. Dec 20, 16:35

Re: [TUTORIAL] XML Patch Guide

Post by Dev disco » Sat, 20. Feb 21, 16:24

Thanks!

User avatar
Xkuka
Posts: 207
Joined: Sun, 14. Mar 10, 19:25
x4

Re: [TUTORIAL] XML Patch Guide

Post by Xkuka » Fri, 31. Mar 23, 07:53

So according to what i have experienced and what i read, and please correct me if necessary,

1) A file without <diff> is handled as "merge", and from painful trial and error, you cant combine merging with patching <- This should be right on the top of the first post, it confused me why some mods do "merge" and others "diff" patches and has cost me quite some time.

2) /edit: I had trouble removing stuff, i got it working now. Don't know exactly why it did not work before.

3) Might be not fitting to this topic entirely, but i am curious if some of the patching could be avoided by creating "redirections". Like if i replace an item and my item has a different ID, but the original ID is called by other files, would there be a way to link the old ID to my new one instead of patching every file?

4) Are there operators that can be used? Any source where i can look for?
***Never not modified***
Specs: I9 9900k, 32GB DDR4, ASUS RTX2060 12GB, Sys drive: 1TB Nvme SSD, Games drive: 1TB Nvme SSD, Win10 pro 21H2

user1679
Posts: 756
Joined: Fri, 20. Jul 18, 23:20

Re: [TUTORIAL] XML Patch Guide

Post by user1679 » Sat, 1. Apr 23, 09:53

I think it would also make things easier if there was a load order that users could assign to mods like Mod Organizer uses for Skyrim. That way if I have two mods that make a bunch of changes with some of them overlapping, I can easily tell the game to load MOD A before MOD B without having to edit the XML files and add a bunch of dependencies.

Post Reply

Return to “X Rebirth - Scripts and Modding”