<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://rimworldwiki.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Lilwhitemouse</id>
	<title>RimWorld Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://rimworldwiki.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Lilwhitemouse"/>
	<link rel="alternate" type="text/html" href="https://rimworldwiki.com/wiki/Special:Contributions/Lilwhitemouse"/>
	<updated>2026-04-06T04:20:14Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.35.8</generator>
	<entry>
		<id>https://rimworldwiki.com/index.php?title=Modding_Tutorials/Translation&amp;diff=141467</id>
		<title>Modding Tutorials/Translation</title>
		<link rel="alternate" type="text/html" href="https://rimworldwiki.com/index.php?title=Modding_Tutorials/Translation&amp;diff=141467"/>
		<updated>2024-01-20T18:36:52Z</updated>

		<summary type="html">&lt;p&gt;Lilwhitemouse: Because I searched for Translation first&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[Modding Tutorials/Localization]]&lt;/div&gt;</summary>
		<author><name>Lilwhitemouse</name></author>
	</entry>
	<entry>
		<id>https://rimworldwiki.com/index.php?title=File:NPD-Royalty.png&amp;diff=136304</id>
		<title>File:NPD-Royalty.png</title>
		<link rel="alternate" type="text/html" href="https://rimworldwiki.com/index.php?title=File:NPD-Royalty.png&amp;diff=136304"/>
		<updated>2023-09-10T18:57:47Z</updated>

		<summary type="html">&lt;p&gt;Lilwhitemouse: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;A nutrient paste dispenser VERY CLOSE to a royal throne room, but not in the throne room where NPDs are not allowed&lt;/div&gt;</summary>
		<author><name>Lilwhitemouse</name></author>
	</entry>
	<entry>
		<id>https://rimworldwiki.com/index.php?title=Time&amp;diff=72090</id>
		<title>Time</title>
		<link rel="alternate" type="text/html" href="https://rimworldwiki.com/index.php?title=Time&amp;diff=72090"/>
		<updated>2020-06-11T23:08:20Z</updated>

		<summary type="html">&lt;p&gt;Lilwhitemouse: rare and long tick conversion&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;noinclude&amp;gt;&amp;lt;!--Top Nav Box--&amp;gt;&lt;br /&gt;
{| align=center&lt;br /&gt;
| {{Gameplay_Nav}}&lt;br /&gt;
|}&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;!-- End of Nav --&amp;gt;&lt;br /&gt;
&amp;lt;/noinclude&amp;gt;&lt;br /&gt;
'''Time''' in RimWorld passes as a series of ticks. On normal game speed, there are 60 such ticks to a real second; there are always 2,500 ticks to one in-game hour.&lt;br /&gt;
&lt;br /&gt;
The game starts in the year 5500. The in-game clock is in 24-hour format with the hours displayed in military time from 0h to 23h. &lt;br /&gt;
&lt;br /&gt;
Time proceeds as one would expect except that the four months are named &amp;quot;quadrums.&amp;quot; They are named as portmanteaus of terrestrial months, suggesting seasonal associations: &amp;quot;Decembary,&amp;quot; &amp;quot;Aprimay,&amp;quot; &amp;quot;Jugust,&amp;quot; and &amp;quot;Septober.&amp;quot; Each individual quadrum is always 15 days, after which you proceed into the next quadrum.&lt;br /&gt;
&lt;br /&gt;
Time of day is modeled on the planet view; local time of day corresponds to how the sunlight hits the planet.&lt;br /&gt;
&lt;br /&gt;
{{asof|A17}} season names could no longer be consistently applied to the entire globe, necessitating that they be named as month-like &amp;quot;quadrums.&amp;quot; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;noinclude&amp;gt;&lt;br /&gt;
{| {{STDT|c_01 text-right}}&lt;br /&gt;
! colspan='2' | In-Game Time&lt;br /&gt;
! colspan='1' | Ticks&lt;br /&gt;
! colspan='1' | Real Time&lt;br /&gt;
|-&lt;br /&gt;
! 1.44 Min&lt;br /&gt;
|           ||     60 || 1s&lt;br /&gt;
|-&lt;br /&gt;
! 1 Hour&lt;br /&gt;
| 60 Min    ||     2,500 || ~{{Time| 60000/60/24 }}&lt;br /&gt;
|-&lt;br /&gt;
! 1 Day&lt;br /&gt;
| 24 Hours  ||    60,000 || {{Time| 60000/60 }}&lt;br /&gt;
|-&lt;br /&gt;
! 1 Quadrum&lt;br /&gt;
| 15 Days  ||   900,000 || {{Time| 60000/60*15 }}&lt;br /&gt;
|-&lt;br /&gt;
! 1 Year&lt;br /&gt;
| 4 Quadrums || 3,600,000 || {{Time| 60000/60*15*4 }}&lt;br /&gt;
|}&lt;br /&gt;
{| {{STDT|c_01 text-right}}&lt;br /&gt;
|-&lt;br /&gt;
! colspan='3' | Technical details for modders&lt;br /&gt;
|-&lt;br /&gt;
!&lt;br /&gt;
! Ticks&lt;br /&gt;
! Game Time&lt;br /&gt;
|-&lt;br /&gt;
| 1 tick || 1 tick || 1/60th second&lt;br /&gt;
|-&lt;br /&gt;
| 1 rare tick || 250 ticks || 4.16 seconds&lt;br /&gt;
|-&lt;br /&gt;
| 1 long tick || 2000 ticks || 33.33 seconds&lt;br /&gt;
|}&lt;br /&gt;
[[Category:Game mechanics]]&lt;br /&gt;
&amp;lt;/noinclude&amp;gt;&lt;/div&gt;</summary>
		<author><name>Lilwhitemouse</name></author>
	</entry>
	<entry>
		<id>https://rimworldwiki.com/index.php?title=Trade&amp;diff=72064</id>
		<title>Trade</title>
		<link rel="alternate" type="text/html" href="https://rimworldwiki.com/index.php?title=Trade&amp;diff=72064"/>
		<updated>2020-06-08T11:33:37Z</updated>

		<summary type="html">&lt;p&gt;Lilwhitemouse: /* Retreat */ goodwill loss on strip&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;!--Top Nav Box--&amp;gt;&lt;br /&gt;
{| align=center&lt;br /&gt;
| {{Gameplay_Nav}}&lt;br /&gt;
|}&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;!-- End of Nav --&amp;gt;&lt;br /&gt;
{{TOCright}}&lt;br /&gt;
&amp;lt;onlyinclude&amp;gt;&lt;br /&gt;
Colonies can trade with other factions by using [[caravan]]s and orbital trade ships via a comms console. Tradeable commodities include [[colonists|slaves]]/[[prisoners]], [[furniture]], [[gear]], [[resources]], [[food]], [[drugs]], and [[sculptures|works of art]].&lt;br /&gt;
&lt;br /&gt;
The trade interface shows what commodities are available to trade, the colony's stock, the trader's stock, and the prices to buy and sell.&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: center;&amp;quot;&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|BUY&lt;br /&gt;
!QUANTITY&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|SELL&lt;br /&gt;
|-&lt;br /&gt;
|ALL||ONE||&amp;lt;tt&amp;gt;positive = buy&amp;lt;br/&amp;gt;negative = sell&amp;lt;/tt&amp;gt;||ONE||ALL&lt;br /&gt;
|-&lt;br /&gt;
|'''{{key|&amp;lt;&amp;lt;}}'''||'''{{key|&amp;lt;}}'''||&amp;lt;tt&amp;gt;may type # here&amp;lt;/tt&amp;gt;||'''{{key|&amp;gt;}}'''||'''{{key|&amp;gt;&amp;gt;}}'''&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* Trade is influenced by your trader's ability to speak and hear. Damage to any such parts will ruin trade prices.&lt;br /&gt;
* Prices listed in green are cheap (does not appear with base-game traders), while prices listed in red are expensive.&lt;br /&gt;
* Items that the foreign trader has no interest in are shown grayed out at the bottom of the list; other traders may want them instead.&lt;br /&gt;
* Animals that have been downed are not listed for trade.&lt;br /&gt;
* All traders carry a limited amount of silver, so they may not be able to buy everything you wish to sell. You can still give them things but everything they receive will be for free, as they cannot afford to pay.&lt;br /&gt;
* Selling a prisoner is profitable, but has a [[Thoughts#A prisoner was sold|negative impact on the happiness]] of all colonists (excludes psychopaths).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Game progression ==&lt;br /&gt;
&lt;br /&gt;
=== Early game ===&lt;br /&gt;
&lt;br /&gt;
Caravans consist of one or more faction members often with pack animals and/or tamed animals in tow. Players can either form their own caravan or wait for others to visit their own colony. To trade with a foreign passing caravan, direct a colonist (preferably with high social skill as he/she can get better prices) to speak with the caravan member who has a yellow question mark above the head. Stored items will be eligible to sell and appear in the trade window. Purchased items will be dropped in the location where the trader was standing and will need to be hauled.&lt;br /&gt;
&lt;br /&gt;
Sometimes, foreign caravan members may fight each other and accidentally drop items from their gear inventory.&lt;br /&gt;
&lt;br /&gt;
=== Later game ===&lt;br /&gt;
&lt;br /&gt;
After finishing the required research, a [[comms console]] and an [[orbital trade beacon]] can be built, which allow:&lt;br /&gt;
&lt;br /&gt;
* Satellite calls to request caravans to allied factions at a cost of 15 goodwill (or 700/1100 silver prior to 1.0). You can only call for a caravan from a given friendly faction once every four days.&lt;br /&gt;
&lt;br /&gt;
* Interaction with orbital trade ships which will stay around for a limited time. A blue notification will appear at the right of your screen to announce the trade ship and its type. After it's gone, a simple notice at the top of the screen will note when the same vessel leaves comms range and can no longer be traded with. Each trade ship varies in type, which determines its inventory.&lt;br /&gt;
&lt;br /&gt;
To trade, order a colonist to interact with the comms console. Only items located within range of an orbital trade beacon can be traded. Purchases will be sent via drop pods to a beacon's open-air tiles, drop pods will phase through constructed roofs otherwise. If all beacon tiles are covered, drop pods will land at the nearest eligible tile. Colonists with a higher social skill using the comms console will negotiate lower buying prices and higher selling prices for everything (1.5% per social skill point). [[Prisoner]]s can be sold directly from their cell even if not in range of a beacon and tamed [[animals]] can be sold from anywhere on the map. The trade value of a prisoner or animal is based on their capabilities, injuries and skills.&lt;br /&gt;
&lt;br /&gt;
== Trade prices ==&lt;br /&gt;
&lt;br /&gt;
Hovering over an item's price opens a tooltip that displays price modifiers. Usually, goods from the colony are sold at 60% market value, and bought at 140% market value. These are further affected by the difficulty setting; see [[AI Storytellers#Challenge Scale|Challenge Scale]].&lt;br /&gt;
&lt;br /&gt;
Actual trade prices are also dependent on the [[Trade Price Improvement]] stat of chosen colonist, listed on the tooltip as &amp;lt;tt&amp;gt;&amp;quot;Your negotiator bonus: -''x''%&amp;quot;&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Some traders will charge 2x the price of a good, in addition to the multiplier on buying. Selling remains at normal price.&lt;br /&gt;
Faction bases don't have any goods-specific price penalties and will even offer a 2% discount when trading at a base.&lt;br /&gt;
&lt;br /&gt;
== Types of Traders ==&lt;br /&gt;
&lt;br /&gt;
=== Land Convoy ===&lt;br /&gt;
&lt;br /&gt;
*'''Visitors''' are small groups that carry all of their goods on their person. They may or may not have items for trade; even if they do, they often have few items and little silver to trade with.&lt;br /&gt;
*'''Trade caravans''' are large groups that carry their goods on pack [[muffalo]] or [[dromedary|dromedaries]], depending on climate. They have a moderate amount of items and silver to buy trade with.&lt;br /&gt;
&lt;br /&gt;
Land convoys will leave the area if the temperature is deemed too dangerous for them to continue trading.&lt;br /&gt;
&lt;br /&gt;
[[File:Visitors but not traders.png|400px|thumb|none|Visitors but not traders, no character with ('''?''') sign overhead]].&lt;br /&gt;
&lt;br /&gt;
=== Technological Level ===&lt;br /&gt;
&lt;br /&gt;
* '''Neolithic''' traders are tribal in nature and will be limited to selling neolithic level items.&lt;br /&gt;
* '''Outlander''' traders come from other faction settlements and are not restricted to a specific technology level of items.&lt;br /&gt;
&lt;br /&gt;
=== Faction Bases ===&lt;br /&gt;
&lt;br /&gt;
Large faction settlements that engage in trading. They buy/sell everything within their technology level, have the most extensive stocks and offer a 2% discount.&lt;br /&gt;
&lt;br /&gt;
=== Physical presence ===&lt;br /&gt;
&lt;br /&gt;
*'''Outlander traders''' have a physical presence on the map and offer a small to medium amount of items and silver.&lt;br /&gt;
*'''Orbital traders''' have no physical presence. They have large amounts of items and silver to trade with, and have the same trader types as outlanders.&lt;br /&gt;
&lt;br /&gt;
''While the game does not specify where orbital traders hail from, the technologically advanced nature of items that they carry generally indicates that they are from midworlds, urbworlds or glitterworlds.''&lt;br /&gt;
&lt;br /&gt;
=== By inventory ===&lt;br /&gt;
&lt;br /&gt;
==== Bulk goods trader ====&lt;br /&gt;
&lt;br /&gt;
'''Bulk goods traders''' deal in [[food]] and basic materials, such as [[steel]], [[wood]], [[component]]s, [[gold]], [[textiles]], as well as [[clothing]], [[furniture]] and domesticated animals.&lt;br /&gt;
&lt;br /&gt;
==== Combat supplier ====&lt;br /&gt;
&lt;br /&gt;
'''Combat suppliers''' deal in [[weapons]], [[armor]], [[mortar shell]]s, and [[medicine]].&lt;br /&gt;
&lt;br /&gt;
The tribal variant of this is the '''War merchant'''.&lt;br /&gt;
&lt;br /&gt;
==== Exotic Goods Trader ====&lt;br /&gt;
&lt;br /&gt;
'''Exotic Goods Traders''' deal in rare and valuable items such as artifacts, [[Joy|televisions]], [[Joy|telescopes]], [[Gear|apparel]], [[Medical Items|bionic body parts]], [[neurotrainer]]s, some [[furniture]], [[plasteel]], [[gold]], [[uranium]], and [[glitterworld medicine]]. The may also carry animals of the wilder variety.&lt;br /&gt;
&lt;br /&gt;
The tribal variant of this is the '''Shaman merchant'''.&lt;br /&gt;
&lt;br /&gt;
==== Pirate Merchant ====&lt;br /&gt;
&lt;br /&gt;
'''Pirate Merchants''' and its derivatives deal in slaves/prisoners, weapons, body parts, medicine, and drugs. The chance of traders carrying prisoners should go down as colony population goes up.&lt;br /&gt;
&lt;br /&gt;
The tribal variant of this is the '''Slaver'''.&lt;br /&gt;
&lt;br /&gt;
== Trader inventories ==&lt;br /&gt;
&lt;br /&gt;
=== Faction base ===&lt;br /&gt;
&lt;br /&gt;
Faction bases have an extensive inventory and deal with most things.&lt;br /&gt;
&lt;br /&gt;
==== Outlander base ====&lt;br /&gt;
&lt;br /&gt;
{| {{STDT|sortable c_03}}&lt;br /&gt;
! Name !! Price !! Min Stock !! Max Stock&lt;br /&gt;
|-&lt;br /&gt;
! [[Silver]]&lt;br /&gt;
| N/A || 800 || 3000&lt;br /&gt;
|-&lt;br /&gt;
! [[Component]]&lt;br /&gt;
| x1 || 20 || 70&lt;br /&gt;
|-&lt;br /&gt;
! [[Steel]]&lt;br /&gt;
| x1 || 300 || 600&lt;br /&gt;
|-&lt;br /&gt;
! [[Wood]]&lt;br /&gt;
| x1 || 200 || 400&lt;br /&gt;
|-&lt;br /&gt;
! [[Plasteel]]&lt;br /&gt;
| x1 || -50 || 200&lt;br /&gt;
|-&lt;br /&gt;
! [[Cloth]]&lt;br /&gt;
| x1 || 100 || 300&lt;br /&gt;
|-&lt;br /&gt;
! [[Gold]]&lt;br /&gt;
| x1 || -50 || 200&lt;br /&gt;
|-&lt;br /&gt;
! [[Neutroamine]]&lt;br /&gt;
| x1 || 50 || 200&lt;br /&gt;
|-&lt;br /&gt;
! [[Chemfuel]]&lt;br /&gt;
| x1 || 300 || 500&lt;br /&gt;
|-&lt;br /&gt;
! [[Chocolate]]&lt;br /&gt;
| x1 || -30 || 70&lt;br /&gt;
|-&lt;br /&gt;
! [[Beer]]&lt;br /&gt;
| x1 || -40 || 100&lt;br /&gt;
|-&lt;br /&gt;
! [[Medicine]]&lt;br /&gt;
| x1 || 25 || 50&lt;br /&gt;
|-&lt;br /&gt;
![[Telescope]]&lt;br /&gt;
| x1 || 0 || 1&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
'''Groups of items:'''&lt;br /&gt;
{| {{STDT|sortable c_03}}&lt;br /&gt;
! Group !! Price !! Variety !! Min Stock !! Max Stock !! Items&lt;br /&gt;
|-&lt;br /&gt;
! Mortar shells&lt;br /&gt;
| x1 || 1 - 2 kinds || 20 each || 40 each || All [[mortar shell]]s except [[antigrain warhead]]&lt;br /&gt;
|-&lt;br /&gt;
! Textiles&lt;br /&gt;
| x1 || 1 - 2 kinds || 400 {{icon|silver}} || 800 {{icon|silver}} || All [[Textiles]]&lt;br /&gt;
|-&lt;br /&gt;
! Resources&lt;br /&gt;
| x1 || 2 - 4 kinds || 400 {{icon|silver}} || 800 {{icon|silver}} || All resources except [[silver]]&lt;br /&gt;
|-&lt;br /&gt;
! Raw food&lt;br /&gt;
| x1 || 2 - 4 kinds || 400 {{icon|silver}} || 800 {{icon|silver}} || All except fertilized eggs&lt;br /&gt;
|-&lt;br /&gt;
! Meals&lt;br /&gt;
| x1 || 1 - 2 kinds || 12 each || 50 each || All [[meal]]s&lt;br /&gt;
|-&lt;br /&gt;
! Furniture&lt;br /&gt;
| x1 || 3 - 4 kinds || 1 each || 2 each || All [[furniture]]&lt;br /&gt;
|-&lt;br /&gt;
! Animals&lt;br /&gt;
| x1 || 2 - 4 kinds || 3 each || 8 each || Most animals&lt;br /&gt;
|-&lt;br /&gt;
! Clothing&lt;br /&gt;
| x1 || 10 - 16 kinds || 1 each || 1 each|| All [[clothing]]&lt;br /&gt;
|-&lt;br /&gt;
! Drugs&lt;br /&gt;
| x1 || 3 - 4 kinds || 750 {{icon|silver}} || 1500 {{icon|silver}} || All [[drugs]]&lt;br /&gt;
|-&lt;br /&gt;
!Ranged weapons&lt;br /&gt;
| x1 || 3 - 6 kinds || 1 each || 1 each || All ranged weapons&lt;br /&gt;
|-&lt;br /&gt;
!Melee weapons&lt;br /&gt;
| x1 || 3 - 4 kinds || 1 each || 2 each || All melee weapons&lt;br /&gt;
|-&lt;br /&gt;
!Armor&lt;br /&gt;
| x1 || 2 - 4 kinds || 1 each || 1 each || All [[armor]]&lt;br /&gt;
|-&lt;br /&gt;
!Body parts/ Implants&lt;br /&gt;
| x1 || 2 - 4 kinds || 1 each || 1 each || All body parts or implants&lt;br /&gt;
|-&lt;br /&gt;
!Exotic items&lt;br /&gt;
| x1 || 1 - 4 kinds || 1 each || 2 each || Rare items&lt;br /&gt;
|-&lt;br /&gt;
!Artifacts&lt;br /&gt;
| x1 || 1 - 4 kinds || 1 each || 1 each || All artifacts&lt;br /&gt;
|-&lt;br /&gt;
!Apparel&lt;br /&gt;
| x1 || 3 - 6 kinds || 1 each || 10 each || All [[apparel]]&lt;br /&gt;
|-&lt;br /&gt;
!Art&lt;br /&gt;
| x1 || 5 - 10 kinds || 1 each || 1 each || [[Sculptures]]&lt;br /&gt;
|-&lt;br /&gt;
!Televisions&lt;br /&gt;
| x1 || 1 - 2 kinds || 1 each || 2 each || [[Tube television]], [[Flatscreen television]], [[Megascreen television]]&lt;br /&gt;
|-&lt;br /&gt;
! Slaves&lt;br /&gt;
| x1 || -1 - 2 || 1 each || 1 each || ---&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Neolithic base ====&lt;br /&gt;
&lt;br /&gt;
{| {{STDT|sortable c_03}}&lt;br /&gt;
! Name !! Price !! Min Stock !! Max Stock&lt;br /&gt;
|-&lt;br /&gt;
! [[Silver]]&lt;br /&gt;
| N/A || 800 || 3000&lt;br /&gt;
|-&lt;br /&gt;
! [[Component]]&lt;br /&gt;
| x2 || 3 || 10&lt;br /&gt;
|-&lt;br /&gt;
! [[Steel]]&lt;br /&gt;
| x1 || 200 || 300&lt;br /&gt;
|-&lt;br /&gt;
! [[Wood]]&lt;br /&gt;
| x1 || 500 || 600&lt;br /&gt;
|-&lt;br /&gt;
! [[Cloth]]&lt;br /&gt;
| x1 || 200 || 300&lt;br /&gt;
|-&lt;br /&gt;
! [[Gold]]&lt;br /&gt;
| x1 || -40 || 120&lt;br /&gt;
|-&lt;br /&gt;
! [[Pemmican]]&lt;br /&gt;
| x1 || 500 || 1000&lt;br /&gt;
|-&lt;br /&gt;
! [[Herbal medicine]]&lt;br /&gt;
| x1 || 15 || 30&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
'''Groups of items:'''&lt;br /&gt;
{| {{STDT|sortable c_03}}&lt;br /&gt;
! Group !! Price !! Variety !! Min Stock !! Max Stock !! Items&lt;br /&gt;
|-&lt;br /&gt;
! Textiles&lt;br /&gt;
| x1 || 1 - 2 kinds || 300 {{icon|silver}} || 700 {{icon|silver}} || All [[Textiles]]&lt;br /&gt;
|-&lt;br /&gt;
! Resources&lt;br /&gt;
| x1 || 3 kinds || 200 {{icon|silver}} || 600 {{icon|silver}} || All resources except [[silver]]&lt;br /&gt;
|-&lt;br /&gt;
! Raw food&lt;br /&gt;
| x1 || 3 - 5 kinds || 300 {{icon|silver}} || 800 {{icon|silver}} || All except fertilized eggs&lt;br /&gt;
|-&lt;br /&gt;
! Clothing&lt;br /&gt;
| x1 || 4 - 12 kinds || 1 each || 1 each|| Neolithic [[clothing]]&lt;br /&gt;
|-&lt;br /&gt;
! Animals&lt;br /&gt;
| x1 || 2 - 4 kinds || 1 each || 5 each || Wildness below 70%&lt;br /&gt;
|-&lt;br /&gt;
! Animals&lt;br /&gt;
| x1 || 1 - 2 kinds || 1 each || 4 each || Powerful &amp;lt;!-- badass --&amp;gt; animals&lt;br /&gt;
|-&lt;br /&gt;
! Drugs&lt;br /&gt;
| x1 || 1 - 2 kinds || 400 {{icon|silver}} || 1000 {{icon|silver}} || [[Beer]], [[smokeleaf joint]], [[psychoid pekoe]]&lt;br /&gt;
|-&lt;br /&gt;
!Ranged weapons&lt;br /&gt;
| x1 || 2 - 4 kinds || 1 each || 1 each || Neolithic ranged&lt;br /&gt;
|-&lt;br /&gt;
!Melee weapons&lt;br /&gt;
| x1 || 2 - 4 kinds || 1 each || 2 each || Neolithic melee&lt;br /&gt;
|-&lt;br /&gt;
! Slaves&lt;br /&gt;
| x1 || -1 - 2 || 1 each || 1 each || ---&lt;br /&gt;
|-&lt;br /&gt;
!Artifacts&lt;br /&gt;
| x1 || 0 - 3 kinds || 1 each || 1 each || All artifacts&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=== Orbital ===&lt;br /&gt;
&lt;br /&gt;
Orbital traders usually come with large stocks corresponding to their trader type.&lt;br /&gt;
&lt;br /&gt;
==== Bulk goods trader ====&lt;br /&gt;
&lt;br /&gt;
{| {{STDT|sortable c_03}}&lt;br /&gt;
! Name !! Price !! Min Stock !! Max Stock&lt;br /&gt;
|-&lt;br /&gt;
! [[Silver]]&lt;br /&gt;
| N/A || 2000 || 4000&lt;br /&gt;
|-&lt;br /&gt;
! [[Component]]&lt;br /&gt;
| x1 || 15 || 30&lt;br /&gt;
|-&lt;br /&gt;
! [[Steel]]&lt;br /&gt;
| x1 || 500 || 800&lt;br /&gt;
|-&lt;br /&gt;
! [[Wood]]&lt;br /&gt;
| x1 || 500 || 800&lt;br /&gt;
|-&lt;br /&gt;
! [[Plasteel]]&lt;br /&gt;
| x1 || 100 || 400&lt;br /&gt;
|-&lt;br /&gt;
! [[Cloth]]&lt;br /&gt;
| x1 || 200 || 600&lt;br /&gt;
|-&lt;br /&gt;
! [[Medicine]]&lt;br /&gt;
| x2 || 20 || 30&lt;br /&gt;
|-&lt;br /&gt;
! [[Gold]]&lt;br /&gt;
| x1 || 50 || 200&lt;br /&gt;
|-&lt;br /&gt;
! [[Neutroamine]]&lt;br /&gt;
| x1 || 100 || 200&lt;br /&gt;
|-&lt;br /&gt;
! [[Chemfuel]]&lt;br /&gt;
| x1 || 200 || 600&lt;br /&gt;
|-&lt;br /&gt;
! [[Chocolate]]&lt;br /&gt;
| x1 || -70 || 100&lt;br /&gt;
|-&lt;br /&gt;
! [[Beer]]&lt;br /&gt;
| x1 || -70 || 100&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
'''Groups of items:'''&lt;br /&gt;
{| {{STDT|sortable c_03}}&lt;br /&gt;
! Group !! Price !! Variety !! Min Stock !! Max Stock !! Items&lt;br /&gt;
|-&lt;br /&gt;
! Textiles&lt;br /&gt;
| x1 || 1 - 2 kinds || 2200 {{icon|silver}} || 4000 {{icon|silver}} || All [[Textiles]]&lt;br /&gt;
|-&lt;br /&gt;
! Resources&lt;br /&gt;
| x1 || 2 - 4 kinds || 800 {{icon|silver}} || 1500 {{icon|silver}} || All resources except [[silver]]&lt;br /&gt;
|-&lt;br /&gt;
! Raw food&lt;br /&gt;
| x1 || 2 - 4 kinds || 800 {{icon|silver}} || 1500 {{icon|silver}} || All except fertilized eggs&lt;br /&gt;
|-&lt;br /&gt;
! Meals&lt;br /&gt;
| x1 || 1 - 2 kinds || 15 each || 30 each || All [[meal]]s&lt;br /&gt;
|-&lt;br /&gt;
! Furniture&lt;br /&gt;
| x1 || 0 - 3 kinds || 1 each || 2 each || All [[furniture]]&lt;br /&gt;
|-&lt;br /&gt;
! Clothing&lt;br /&gt;
| x1 || 10 - 20 kinds || 1 each || 1 each|| All [[clothing]]&lt;br /&gt;
|-&lt;br /&gt;
! Drugs&lt;br /&gt;
| x1 || 2 - 4 kinds || 1000 {{icon|silver}} || 2000 {{icon|silver}} || All [[drugs]]&lt;br /&gt;
|-&lt;br /&gt;
! Animals&lt;br /&gt;
| x1 || 2 - 4 kinds || 10 each || 20 each || Animals with wildness below 70%&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Commonality: 2&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Combat supplier ====&lt;br /&gt;
&lt;br /&gt;
{| {{STDT|sortable c_03}}&lt;br /&gt;
! Name !! Price !! Min Stock !! Max Stock&lt;br /&gt;
|-&lt;br /&gt;
! [[Silver]]&lt;br /&gt;
| N/A || 2000 || 4000&lt;br /&gt;
|-&lt;br /&gt;
! [[Component]]&lt;br /&gt;
| x2 || 5 || 10&lt;br /&gt;
|-&lt;br /&gt;
! [[Medicine]]&lt;br /&gt;
| x1 || 30 || 50&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
'''Groups of items:'''&lt;br /&gt;
{| {{STDT|sortable c_03}}&lt;br /&gt;
! Group !! Price !! Variety !! Min Stock !! Max Stock !! Items&lt;br /&gt;
|-&lt;br /&gt;
! Mortar shells&lt;br /&gt;
| x1 || 1 - 2 kinds || 20 each || 40 each || All [[mortar shell]]s except [[antigrain warhead]]&lt;br /&gt;
|-&lt;br /&gt;
!Ranged weapons&lt;br /&gt;
| x1 || 5 - 6 kinds || 1 each || 1 each || All ranged weapons&lt;br /&gt;
|-&lt;br /&gt;
!Melee weapons&lt;br /&gt;
| x1 || 5 - 6 kinds || 2 each || 3 each || All melee weapons&lt;br /&gt;
|-&lt;br /&gt;
!Armor&lt;br /&gt;
| x1 || 8 - 10 kinds || 1 each || 1 each || All [[armor]]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Commonality: 1&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Exotic goods trader ====&lt;br /&gt;
&lt;br /&gt;
{| {{STDT|sortable c_03}}&lt;br /&gt;
! Name !! Price !! Min Stock !! Max Stock&lt;br /&gt;
|-&lt;br /&gt;
! [[Silver]]&lt;br /&gt;
| N/A || 2000 || 4000&lt;br /&gt;
|-&lt;br /&gt;
! [[Component]]&lt;br /&gt;
| x2 || 5 || 30&lt;br /&gt;
|-&lt;br /&gt;
! [[Gold]]&lt;br /&gt;
| x1 || 200 || 400&lt;br /&gt;
|-&lt;br /&gt;
! [[Plasteel]]&lt;br /&gt;
| x1 || 100 || 400&lt;br /&gt;
|-&lt;br /&gt;
! [[Glitterworld medicine]]&lt;br /&gt;
| x1 || 5 || 30&lt;br /&gt;
|-&lt;br /&gt;
! [[Neutroamine]]&lt;br /&gt;
| x1 || 100 || 500&lt;br /&gt;
|-&lt;br /&gt;
![[Telescope]]&lt;br /&gt;
| x1 || 1  || 1&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
'''Groups of items:'''&lt;br /&gt;
{| {{STDT|sortable c_03}}&lt;br /&gt;
! Group !! Price !! Variety !! Min Stock !! Max Stock !! Items&lt;br /&gt;
|-&lt;br /&gt;
!Drugs&lt;br /&gt;
| x1 || 3 - 4 kinds || 2000 {{icon|silver}} || 3000 {{icon|silver}} || All drugs&lt;br /&gt;
|-&lt;br /&gt;
!Exotic items&lt;br /&gt;
| x1 || 3 - 5 kinds || 1 each || 2 each || Rare items&lt;br /&gt;
|-&lt;br /&gt;
!Body parts/ Implants&lt;br /&gt;
| x1 || 3 - 5 kinds || 1 each || 1 each || All body parts or implants&lt;br /&gt;
|-&lt;br /&gt;
!Artifacts&lt;br /&gt;
| x1 || 2 - 4 kinds || 1 each || 1 each || All artifacts&lt;br /&gt;
|-&lt;br /&gt;
!Art&lt;br /&gt;
| x1 || 4 - 8 kinds || 1 each || 1 each || [[Sculptures]]&lt;br /&gt;
|-&lt;br /&gt;
!Televisions&lt;br /&gt;
| x1 || 1 - 3 kinds || 1 each || 1 each || [[Tube television]], [[Flatscreen television]], [[Megascreen television]]&lt;br /&gt;
|-&lt;br /&gt;
! Furniture&lt;br /&gt;
| x1 || 1 - 4 kinds || 1 each || 2 each || All [[furniture]]&lt;br /&gt;
|-&lt;br /&gt;
! Animals&lt;br /&gt;
| x1 || 1 - 2 kinds || 2 each || 3 each || Animals with wildness above 60%&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Commonality: 1&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
==== Pirate merchant ====&lt;br /&gt;
&lt;br /&gt;
{| {{STDT|sortable c_03}}&lt;br /&gt;
! Name !! Price !! Min Stock !! Max Stock&lt;br /&gt;
|-&lt;br /&gt;
! [[Silver]]&lt;br /&gt;
| N/A || 2000 || 4000&lt;br /&gt;
|-&lt;br /&gt;
! [[Component]]&lt;br /&gt;
| x2 || 5 || 10&lt;br /&gt;
|-&lt;br /&gt;
! [[Beer]]&lt;br /&gt;
| x1 || -300 || 300&lt;br /&gt;
|-&lt;br /&gt;
! [[Medicine]]&lt;br /&gt;
| x2 || 5 || 15&lt;br /&gt;
|-&lt;br /&gt;
! [[Neutroamine]]&lt;br /&gt;
| x2 || 100 || 400&lt;br /&gt;
|-&lt;br /&gt;
! [[Chemfuel]]&lt;br /&gt;
| x2 || 50 || 200&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
'''Groups of items:'''&lt;br /&gt;
{| {{STDT|sortable c_03}}&lt;br /&gt;
! Group !! Price !! Variety !! Min Stock !! Max Stock !! Items&lt;br /&gt;
|-&lt;br /&gt;
! Slaves&lt;br /&gt;
| x1 || 2 - 3 || 1 each || 1 each || ---&lt;br /&gt;
|-&lt;br /&gt;
!Ranged weapons&lt;br /&gt;
| x1 || -1 - 2 kinds || 1 each || 1 each || All ranged weapons&lt;br /&gt;
|-&lt;br /&gt;
!Armor&lt;br /&gt;
| x1 || -2 - 2 kinds || 1 each || 1 each || All armor&lt;br /&gt;
|-&lt;br /&gt;
!Body parts/ Implants&lt;br /&gt;
| x1 || -4 - 5 kinds || 1 each || 1 each || All body parts or implants&lt;br /&gt;
|-&lt;br /&gt;
!Artifacts&lt;br /&gt;
| x1 || -5 - 1 kinds || 1 each || 1 each || All artifacts&lt;br /&gt;
|-&lt;br /&gt;
!Drugs&lt;br /&gt;
| x1 || 3 - 6 kinds || 2000 {{icon|silver}} || 3000 {{icon|silver}} || All drugs&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Commonality: 1&lt;br /&gt;
&lt;br /&gt;
== Trader behavior ==&lt;br /&gt;
&lt;br /&gt;
Trade caravans that come to your colony usually pick a random spot where they will simply wander around and wait for your colonists to send a negotiator for trade. When hungry they may use the colony's tables and chairs for dining, and will sleep on the floor when exhausted.&lt;br /&gt;
&lt;br /&gt;
=== Retreat ===&lt;br /&gt;
&lt;br /&gt;
Sometimes, certain occurrences can cause foreign characters to leave your map before you have the chance to interact with them. They can just fight each other just like your own people do. In other occasions, they may get attacked by wild animals. They may leave the map on their own if the temperature becomes too high or too low for them or their animals. Some of them might get killed and others may only get downed, leaving a chance for rescue either by their own or by yourself. Items they drop can be unforbidden for you to take. As of the May 27, 2020 version of the game, stripping clothes from anyone unconscious causes a loss of goodwill.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;gallery widths=&amp;quot;400px&amp;quot; heights=&amp;quot;400px&amp;quot; class=&amp;quot;center&amp;quot; mode=&amp;quot;nolines&amp;quot;&amp;gt;&lt;br /&gt;
File:Foreign traders taking a downed guest.png|'''Foreign traders taking a wounded guest (wild animal attack) back to their base.'''&lt;br /&gt;
File:Foreign trader downed due to overdose.png|'''Foreign trader downed due to overdose.'''&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&lt;br /&gt;
* You cannot buy back prisoners you just sold as a way to insta-recruit anyone (exploit prevention).&lt;br /&gt;
* You can trade your expensive items (weapons, sculptures) for other desirable items if the trade ship doesn't have enough silver to complete the transaction. Of course, the amount of silver you can gain is lower, but it is usually better to have a lot of cheap items than an expensive one in your store. Sometimes you have items so expensive that no trader can buy them.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Trade]]&lt;/div&gt;</summary>
		<author><name>Lilwhitemouse</name></author>
	</entry>
	<entry>
		<id>https://rimworldwiki.com/index.php?title=Modding_Tutorials/PatchOperations&amp;diff=67430</id>
		<title>Modding Tutorials/PatchOperations</title>
		<link rel="alternate" type="text/html" href="https://rimworldwiki.com/index.php?title=Modding_Tutorials/PatchOperations&amp;diff=67430"/>
		<updated>2020-01-23T18:53:26Z</updated>

		<summary type="html">&lt;p&gt;Lilwhitemouse: /* PatchOperationConditional */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{BackToTutorials}}&lt;br /&gt;
&lt;br /&gt;
RimWorld Alpha 17 added a new modding feature: '''XML PatchOperations'''. Using these allows mods to edit specific elements of XML defs, rather than simply overwriting the old def with a new one, which was the required approach until A17. This greatly reduces mod conflicts, because mods that make separate changes to the same def won't necessarily overwrite one another's changes. Mods using PatchOperations can avoid requiring special compatibility mods, and can even add special features conditional on other mods being loaded.&lt;br /&gt;
&lt;br /&gt;
Here's a simple example of replacing the texture path for deep water:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot; ?&amp;gt;&lt;br /&gt;
&amp;lt;Patch&amp;gt;&lt;br /&gt;
  &amp;lt;Operation Class=&amp;quot;PatchOperationReplace&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;/Defs/TerrainDef[defName=&amp;quot;WaterDeep&amp;quot;]/texturePath&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;value&amp;gt;&lt;br /&gt;
      &amp;lt;texturePath&amp;gt;Your/Texture/Path/Here&amp;lt;/texturePath&amp;gt;&lt;br /&gt;
    &amp;lt;/value&amp;gt;&lt;br /&gt;
  &amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/Patch&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
This xml file simply goes inside YourMod/Patches/ and you're done.&lt;br /&gt;
&lt;br /&gt;
== Overview of available PatchOperations ==&lt;br /&gt;
These are the available PatchOperation types:&lt;br /&gt;
&lt;br /&gt;
* Four do basic operations on XML nodes:&lt;br /&gt;
** '''[[#PatchOperationAdd|PatchOperationAdd]]''' adds a provided child node to the selected node&lt;br /&gt;
** '''[[#PatchOperationInsert|PatchOperationInsert]]''' adds a provided sibling node to the selected node&lt;br /&gt;
** '''[[#PatchOperationRemove|PatchOperationRemove]]''' deletes the selected node&lt;br /&gt;
** '''[[#PatchOperationReplace|PatchOperationReplace]]''' replaces the selected node with the provided node&lt;br /&gt;
* Three do basic operations on XML attributes:&lt;br /&gt;
** '''[[#PatchOperationAttributeAdd|PatchOperationAttributeAdd]]''' adds a provided attribute to the selected node if and only if the attribute name is not already present&lt;br /&gt;
** '''[[#PatchOperationAttributeSet|PatchOperationAttributeSet]]''' sets a provided attribute for the selected node, overwriting the attribute value if the attribute name is already present&lt;br /&gt;
** '''[[#PatchOperationAttributeRemove|PatchOperationAttributeRemove]]''' removes an attribute for the selected node&lt;br /&gt;
* Three allow for more complex operations:&lt;br /&gt;
** '''[[#PatchOperationAddModExtension|PatchOperationAddModExtension]]''' adds a ModExtension.&lt;br /&gt;
** '''[[#PatchOperationSetName|PatchOperationSetName]]''' changes the name of a node.&lt;br /&gt;
** '''[[#PatchOperationSequence|PatchOperationSequence]]''' contains a set of other PatchOperations, and aborts upon any operation failing&lt;br /&gt;
* Three allow for conditional operations:&lt;br /&gt;
** '''[[#PatchOperationTest|PatchOperationTest]]''' tests nodes, which is useful inside a PatchOperationSequence&lt;br /&gt;
** '''[[#PatchOperationConditional|PatchOperationConditional]]''' tests nodes, and can do different operations depending on the result.&lt;br /&gt;
** '''[[#PatchOperationFindMod|PatchOperationFindMod]]''' tests for the presence of another mod, and can do different operations depending on the result.&lt;br /&gt;
&lt;br /&gt;
==XPath syntax==&lt;br /&gt;
Each PatchOperation must specify an XML node to modify. It uses XPaths to specify them. An XPath is a &amp;quot;path&amp;quot; for the patch to follow when trying to find XML nodes matching the description. It will follow each part of the path from left to right. Note that these &amp;quot;paths&amp;quot; have zero relation to the file path or folder structure: They follow the structure of the XML nodes.&lt;br /&gt;
&lt;br /&gt;
XPaths start at the root node. Since the root node of all Defs is enforced to be &amp;lt;Defs&amp;gt;, so &amp;lt;code&amp;gt;/Defs/&amp;lt;/code&amp;gt; is the start of our xpath. &amp;lt;code&amp;gt;*/&amp;lt;/code&amp;gt; is also valid, as it uses the &amp;lt;code&amp;gt;*&amp;lt;/code&amp;gt; wildcard: &amp;lt;code&amp;gt;*&amp;lt;/code&amp;gt; matches any element, so it'll match the root (the top level) of the XML tree. &amp;lt;code&amp;gt;//&amp;lt;/code&amp;gt; is technically also valid, but because that construct selects ''all'' the elements in the XML tree, it's an expensive operation that makes game loading exponentially slower.&lt;br /&gt;
&lt;br /&gt;
Once the root is selected, the XPath lets the system walk down specific branches of the tree. If we use the example from the lead, we get a specific path:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;/Defs/TerrainDef[defName=&amp;quot;WaterDeep&amp;quot;]/texturePath&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# The root node is selected&lt;br /&gt;
# All child nodes of the root node called &amp;quot;TerrainDef&amp;quot; are selected&lt;br /&gt;
# We narrow down from &amp;quot;all TerrainDefs&amp;quot; to only those with the child &amp;quot;defName&amp;quot; node whose value is &amp;quot;WaterDeep&amp;quot;, which should give us exactly one node because defNames must be unique&lt;br /&gt;
# We select the child node &amp;quot;texturePath&amp;quot; from this node&lt;br /&gt;
## Note that we cannot put &amp;lt;code&amp;gt;.../texturePath/&amp;lt;/code&amp;gt; to specify the content of the texturePath node.  If we want to replace texturePath, we have to replace it with &amp;lt;code&amp;gt;&amp;lt;texturePath&amp;gt;/new/path/to/texture&amp;lt;/texturePath&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more info, see this {{LudeonThread|32785}}. XPath is a [https://www.w3schools.com/xml/xml_xpath.asp well-documented industry standard] (good resource, too); there are plenty of resources available on the subject ranging from exhaustive tutorials to simple [https://stackoverflow.com/questions/tagged/xpath StackOverflow] questions.&lt;br /&gt;
&lt;br /&gt;
==&amp;quot;Success&amp;quot; option==&lt;br /&gt;
The ''&amp;lt;code&amp;gt;&amp;lt;success&amp;gt;...&amp;lt;/success&amp;gt;&amp;lt;/code&amp;gt;'' term specifies whether the entire operation is considered a success or not.  If the overall patch operation is not considered a success, an error is thrown. This is particularly used in Sequences and Tests, where you'd not want to throw an error on a simple test.&lt;br /&gt;
&lt;br /&gt;
Options available are:&lt;br /&gt;
* Always - this patch operation is considered a success - sometimes used for Sequences so that if an early test in the sequence fails, an error is not reported (because the sequence is still a successful patch)&lt;br /&gt;
* Normal - this patch operation is considered a success if it succeeded (content patched, test passed, etc)&lt;br /&gt;
* Invert - If the patch failed (e.g., a test), then it's considered a success (useful for a negative test in a sequence)&lt;br /&gt;
* Never - this patch operation &amp;quot;failed.&amp;quot;  Even if it patched whatever it was supposed to correctly.  If you ever use this, leave a note here for the curious.&lt;br /&gt;
&lt;br /&gt;
==Overview of individual PatchOperations==&lt;br /&gt;
===PatchOperationAdd===&lt;br /&gt;
''PatchOperationAdd'' adds a child node to the selected node.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationAdd&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;/Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleList&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;value&amp;gt;&lt;br /&gt;
        &amp;lt;li&amp;gt;Foo&amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;li&amp;gt;Bar&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;/value&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList&amp;gt;&lt;br /&gt;
            &amp;lt;li&amp;gt;Foo&amp;lt;/li&amp;gt;&lt;br /&gt;
            &amp;lt;li&amp;gt;Bar&amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;/exampleList&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationInsert===&lt;br /&gt;
''PatchOperationInsert'' adds a sibling to the selected node.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
  &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
    &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
    &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
    &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
  &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationInsert&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;xpath&amp;gt;/Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
  &amp;lt;value&amp;gt;&lt;br /&gt;
    &amp;lt;anotherExample&amp;gt;A new sibling&amp;lt;/anotherExample&amp;gt;&lt;br /&gt;
  &amp;lt;/value&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
  &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
    &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
    &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
    &amp;lt;anotherExample&amp;gt;A new sibling&amp;lt;/anotherExample&amp;gt;&lt;br /&gt;
    &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
  &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationRemove===&lt;br /&gt;
''PatchOperationRemove'' removes the selected node.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationRemove&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;/Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationReplace===&lt;br /&gt;
''PatchOperationReplace'' replaces the selected node.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationReplace&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;/Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;value&amp;gt;&lt;br /&gt;
        &amp;lt;anotherExample&amp;gt;An alternate node&amp;lt;/anotherExample&amp;gt;&lt;br /&gt;
    &amp;lt;/value&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;anotherExample&amp;gt;An alternate node&amp;lt;/anotherExample&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationAttributeAdd===&lt;br /&gt;
''PatchOperationAttributeAdd'' will add an attribute and set its value, but only if that attribute is not yet present.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationAttributeAdd&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;/Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;attribute&amp;gt;ExampleAttribute&amp;lt;/attribute&amp;gt;&lt;br /&gt;
    &amp;lt;value&amp;gt;ExampleValue&amp;lt;/value&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode ExampleAttribute&amp;quot;ExampleValue&amp;quot;&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationAttributeSet===&lt;br /&gt;
''PatchOperationAttributeSet'' will add an attribute and set its value. Unlike PatchAttributeAdd, PatchOperationAttributeSet will overwrite any existing value. &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode ExampleAttribute=&amp;quot;ExampleValue&amp;quot;&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationAttributeSet&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;/Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;attribute&amp;gt;ExampleAttribute&amp;lt;/attribute&amp;gt;&lt;br /&gt;
    &amp;lt;value&amp;gt;DifferentExampleValue&amp;lt;/value&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode ExampleAttribute=&amp;quot;DifferentExampleValue&amp;quot;&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationAttributeRemove===&lt;br /&gt;
''PatchOperationAttributeRemove'' removes the specified attribute.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode ExampleAttribute&amp;quot;ExampleValue&amp;quot;&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationAttributeRemove&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;/Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;attribute&amp;gt;ExampleAttribute&amp;lt;/attribute&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationAddModExtension===&lt;br /&gt;
{{Main|Modding Tutorials/DefModExtension}}&lt;br /&gt;
''PatchOperationAddModExtension'' adds a [[Modding Tutorials/DefModExtension|Mod Extension]].&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationAddModExtension&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;/Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;value&amp;gt;&lt;br /&gt;
        &amp;lt;li Class=&amp;quot;ExampleNameSpace.ExampleModExtension&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;exampleValue&amp;gt;true&amp;lt;/exampleValue&amp;gt;&lt;br /&gt;
        &amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;/value&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
        &amp;lt;modExtensions&amp;gt;&lt;br /&gt;
            &amp;lt;li Class=&amp;quot;ExampleNameSpace.ExampleModExtension&amp;quot;&amp;gt;&lt;br /&gt;
                &amp;lt;exampleValue&amp;gt;true&amp;lt;/exampleValue&amp;gt;&lt;br /&gt;
            &amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;/modExtensions&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationSetName===&lt;br /&gt;
''PatchOperationSetName'' changes the name of a node.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationSetName&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;/Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;name&amp;gt;newExampleName&amp;lt;/name&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;newExampleName&amp;gt;Some text&amp;lt;/newExampleName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationSequence===&lt;br /&gt;
''PatchOperationSequence'' will complete all operations in the order of their listing, and stop when any of them fails.&lt;br /&gt;
&lt;br /&gt;
Modders will often specify &amp;lt;code&amp;gt;&amp;lt;success&amp;gt;Always&amp;lt;/success&amp;gt;&amp;lt;/code&amp;gt;, which will mean that even if one part of the sequence fails (e.g., a test), the whole is still considered a success and no unneeded errors show up.&lt;br /&gt;
&lt;br /&gt;
'''Patch Operation'''&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationSequence&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;!-- put &amp;lt;success&amp;gt;Always&amp;lt;/success&amp;gt; if using tests?  Leave out for simple sequences --&amp;gt;&lt;br /&gt;
  &amp;lt;operations&amp;gt;&lt;br /&gt;
    &amp;lt;li Class=&amp;quot;PatchOperationInsert&amp;quot;&amp;gt;&amp;lt;!-- Always happens! --&amp;gt;&lt;br /&gt;
      &amp;lt;xpath&amp;gt;/Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
      &amp;lt;value&amp;gt;&lt;br /&gt;
        &amp;lt;anotherExample&amp;gt;A new sibling&amp;lt;/anotherExample&amp;gt;&lt;br /&gt;
      &amp;lt;/value&amp;gt;&lt;br /&gt;
    &amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;li Class=&amp;quot;PatchOperationAdd&amp;quot;&amp;gt;&amp;lt;!-- Always happens! --&amp;gt;&lt;br /&gt;
      &amp;lt;xpath&amp;gt;/Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]&amp;lt;/xpath&amp;gt;&lt;br /&gt;
      &amp;lt;value&amp;gt;&amp;lt;label&amp;gt;I'm a node&amp;lt;/label&amp;gt;&amp;lt;/value&amp;gt;&lt;br /&gt;
    &amp;lt;li&amp;gt;&lt;br /&gt;
    &amp;lt;!-- etc --&amp;gt;&lt;br /&gt;
  &amp;lt;operations&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Effect'''&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
  &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
    &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
  &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
  &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
    &amp;lt;label&amp;gt;I'm a node&amp;lt;/label&amp;gt;&lt;br /&gt;
    &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
    &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
    &amp;lt;anotherExample&amp;gt;A new sibling&amp;lt;/anotherExample&amp;gt;&lt;br /&gt;
    &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
  &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
'''Another Example''': Maybe you don't like the &amp;quot;Example&amp;quot; ExampleDef...&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationSequence&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;success&amp;gt;Always&amp;lt;/success&amp;gt;&amp;lt;!-- No errors thrown --&amp;gt;&lt;br /&gt;
  &amp;lt;operations&amp;gt;&lt;br /&gt;
    &amp;lt;li Class=&amp;quot;PatchOperationRemove&amp;quot;&amp;gt;&amp;lt;!-- :o  ...this returns true --&amp;gt;&lt;br /&gt;
      &amp;lt;xpath&amp;gt;/Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]&amp;lt;xpath&amp;gt;&lt;br /&gt;
    &amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;li Class=&amp;quot;PatchOperationAdd&amp;quot;&amp;gt;&amp;lt;!-- so this runs --&amp;gt;&lt;br /&gt;
      &amp;lt;xpath&amp;gt;/Defs&amp;lt;/xpath&amp;gt;&lt;br /&gt;
      &amp;lt;value&amp;gt;&lt;br /&gt;
        &amp;lt;ExampleDef&amp;gt;&amp;lt;defName&amp;gt;MyBetterExample&amp;lt;/defName&amp;gt;&amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
      &amp;lt;/value&amp;gt;&lt;br /&gt;
  &amp;lt;/operations&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If ExampleDef were already gone, MyBetterExample would not get added.&lt;br /&gt;
&lt;br /&gt;
===PatchOperationTest===&lt;br /&gt;
''PatchOperationTest'' tests for the existence/validity of an xpath. Useful to stop a PatchOperationSequence. Often used as a simpler, less powerful version of PatchOperationConditional.&lt;br /&gt;
The following example patch is from Apparello, by Shinzy. &lt;br /&gt;
&amp;lt;source lang =&amp;quot;xml&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationSequence&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;!-- check for worn graphics and if none found, add one --&amp;gt;&lt;br /&gt;
    &amp;lt;success&amp;gt;Always&amp;lt;/success&amp;gt;&lt;br /&gt;
    &amp;lt;operations&amp;gt;&lt;br /&gt;
        &amp;lt;li Class=&amp;quot;PatchOperationTest&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;xpath&amp;gt;/Defs/ThingDef[defName = &amp;quot;Apparel_Pants&amp;quot;]/apparel/wornGraphicPath&amp;lt;/xpath&amp;gt;&lt;br /&gt;
            &amp;lt;success&amp;gt;Invert&amp;lt;/success&amp;gt;&lt;br /&gt;
        &amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;li Class=&amp;quot;PatchOperationAdd&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;xpath&amp;gt;/Defs/ThingDef[defName = &amp;quot;Apparel_Pants&amp;quot;]/apparel&amp;lt;/xpath&amp;gt;&lt;br /&gt;
            &amp;lt;value&amp;gt;&lt;br /&gt;
                &amp;lt;wornGraphicPath&amp;gt;Accessorello/Pants/Pants&amp;lt;/wornGraphicPath&amp;gt;&lt;br /&gt;
            &amp;lt;/value&amp;gt;&lt;br /&gt;
        &amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;/operations&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===PatchOperationConditional===&lt;br /&gt;
''PatchOperationConditional'' can branch logic based on a match/nomatch. The following example patch adds a &amp;lt;comps&amp;gt; node if it does not yet exist, and adds itself&lt;br /&gt;
&lt;br /&gt;
''Important Note:'' If the xpath does not match and &amp;lt;nomatch&amp;gt; has not been specified, this will return 'false' - which may throw an error to the user.  Likewise, if the xpath does match and there is no &amp;lt;match&amp;gt;, a failure. You may specify &amp;lt;success&amp;gt;Always&amp;lt;/success&amp;gt; to avoid any errors.&lt;br /&gt;
&lt;br /&gt;
This patch is courtesy Mehni. [https://github.com/Mehni/MoreFactionInteraction/blob/ab3ab2a22ee529ee4e38a471fe150fd48fd07ce9/Patches/MoreFactionInteraction.xml#L40-L62 See original.]&lt;br /&gt;
&amp;lt;source lang =&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!-- Add /comps/li/compClass if there are no comps yet. --&amp;gt;&lt;br /&gt;
&amp;lt;!-- Add /li/compClass to /comps if exists (i.e. other mod already added the comps field first) --&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationConditional&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;/Defs/WorldObjectDef[defName=&amp;quot;Caravan&amp;quot;]/comps&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;nomatch Class=&amp;quot;PatchOperationAdd&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;xpath&amp;gt;/Defs/WorldObjectDef[defName=&amp;quot;Caravan&amp;quot;]&amp;lt;/xpath&amp;gt;&lt;br /&gt;
        &amp;lt;value&amp;gt;&lt;br /&gt;
            &amp;lt;comps&amp;gt;&lt;br /&gt;
                &amp;lt;li&amp;gt;&lt;br /&gt;
                    &amp;lt;compClass&amp;gt;MoreFactionInteraction.WorldObjectComp_CaravanComp&amp;lt;/compClass&amp;gt;&lt;br /&gt;
                &amp;lt;/li&amp;gt;&lt;br /&gt;
            &amp;lt;/comps&amp;gt;&lt;br /&gt;
        &amp;lt;/value&amp;gt;&lt;br /&gt;
    &amp;lt;/nomatch&amp;gt;&lt;br /&gt;
    &amp;lt;match Class=&amp;quot;PatchOperationAdd&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;xpath&amp;gt;/Defs/WorldObjectDef[defName=&amp;quot;Caravan&amp;quot;]/comps&amp;lt;/xpath&amp;gt;&lt;br /&gt;
        &amp;lt;value&amp;gt;&lt;br /&gt;
            &amp;lt;li&amp;gt;&lt;br /&gt;
                &amp;lt;compClass&amp;gt;MoreFactionInteraction.WorldObjectComp_CaravanComp&amp;lt;/compClass&amp;gt;&lt;br /&gt;
            &amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;/value&amp;gt;&lt;br /&gt;
    &amp;lt;/match&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===PatchOperationFindMod===&lt;br /&gt;
''PatchOperationFindMod'' searches the list of active mods for the mods listed in &amp;lt;nowiki&amp;gt;&amp;lt;li&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/nowiki&amp;gt; tags.&lt;br /&gt;
&lt;br /&gt;
For a successful match, &amp;lt;nowiki&amp;gt;&amp;lt;li&amp;gt;ModName&amp;lt;/li&amp;gt;&amp;lt;/nowiki&amp;gt; has to match the &amp;lt;name&amp;gt;ModName&amp;lt;/name&amp;gt; in the About.xml of the mod you base your patch behaviour on. It only needs to find ''one'' of the mods in the list for a successful match.&lt;br /&gt;
This (shortened) patch is courtesy Mehni. [https://github.com/Mehni/MoreFactionInteraction/blob/ab3ab2a22ee529ee4e38a471fe150fd48fd07ce9/Patches/MoreFactionInteraction.xml#L64 See original.]&lt;br /&gt;
&lt;br /&gt;
The following Patch adds the RimQuest mod extension to the listed Defs when RimQuest is found.&lt;br /&gt;
&amp;lt;source lang =&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationFindMod&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;mods&amp;gt;&lt;br /&gt;
        &amp;lt;li&amp;gt;RimQuest&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;/mods&amp;gt;&lt;br /&gt;
    &amp;lt;match Class=&amp;quot;PatchOperationAddModExtension&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;xpath&amp;gt;/Defs/IncidentDef[defName=&amp;quot;MFI_DiplomaticMarriage&amp;quot; or defName=&amp;quot;MFI_HuntersLodge&amp;quot; or defName=&amp;quot;MFI_Quest_PeaceTalks&amp;quot;]&amp;lt;/xpath&amp;gt;&lt;br /&gt;
        &amp;lt;value&amp;gt;&lt;br /&gt;
            &amp;lt;li Class = &amp;quot;RimQuest.RimQuest_ModExtension&amp;quot;&amp;gt;&lt;br /&gt;
                &amp;lt;canBeARimQuest&amp;gt;false&amp;lt;/canBeARimQuest&amp;gt;&lt;br /&gt;
            &amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;/value&amp;gt;&lt;br /&gt;
    &amp;lt;/match&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following Patch replace the tabWindowClass of the xpath when Relations Tab is '''not''' found. &lt;br /&gt;
&amp;lt;source lang =&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationFindMod&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;mods&amp;gt;&lt;br /&gt;
        &amp;lt;li&amp;gt;Relations Tab&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;/mods&amp;gt;&lt;br /&gt;
    &amp;lt;nomatch Class=&amp;quot;PatchOperationReplace&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;xpath&amp;gt;/Defs/MainButtonDef[defName=&amp;quot;Factions&amp;quot;]/tabWindowClass&amp;lt;/xpath&amp;gt;&lt;br /&gt;
        &amp;lt;value&amp;gt;&lt;br /&gt;
            &amp;lt;tabWindowClass&amp;gt;MyNameSpace.MyTabWindowClass&amp;lt;/tabWindowClass&amp;gt;&lt;br /&gt;
        &amp;lt;/value&amp;gt;&lt;br /&gt;
    &amp;lt;/nomatch&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Common issues==&lt;br /&gt;
Spelling matters, and XPath is case sensitive. It's ''very'' case sensitive. If you've written something that doesn't work but you're convinced it should, put it through some XPath validator. Case sensitivity includes but is not limited to the &amp;lt;Operation Class=&amp;quot;PatchOperationWhatever&amp;quot;&amp;gt;, the XPath, the value, every tag -- spell it right.&lt;br /&gt;
&lt;br /&gt;
Another common issue is swapping Insert and Add, which leads to a different position in the node. A common misconception is trying to account for file paths. The file path is completely irrelevant to the expression you're writing. XPath is used to search XML content, not files themselves.&lt;br /&gt;
&lt;br /&gt;
Still beating your head against a wall? The main RimWorld [https://discord.gg/RimWorld discord] has helpful people and a bot where you can test XPath, and the forums have a [https://ludeon.com/forums/index.php?board=14.0 help] section as well.&lt;br /&gt;
&lt;br /&gt;
==Some advanced examples==&lt;br /&gt;
This (shortened) patch is courtesy XeoNovaDan. [https://github.com/XeoNovaDan/SurvivalTools/blob/62a4316c81733dde417257bf4bc5c34e3e781c7d/Patches/ExpandedWoodworkingVGP/Patch.xml See original]. Viewer discretion is advised. Parents please take precautions if young children are present.&lt;br /&gt;
&amp;lt;source lang = &amp;quot;XML&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationFindMod&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;mods&amp;gt;&lt;br /&gt;
        &amp;lt;li&amp;gt;Expanded Woodworking for Vegetable Garden Project&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;/mods&amp;gt;&lt;br /&gt;
    &amp;lt;match Class=&amp;quot;PatchOperationSequence&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;success&amp;gt;Always&amp;lt;/success&amp;gt;&lt;br /&gt;
        &amp;lt;operations&amp;gt;&lt;br /&gt;
            &amp;lt;!-- Nested PatchOpFindMod. Used because Expanded Woodworking adds more Wood when VGP Xtra is installed. --&amp;gt;&lt;br /&gt;
            &amp;lt;li Class=&amp;quot;PatchOperationFindMod&amp;quot;&amp;gt;&lt;br /&gt;
                &amp;lt;mods&amp;gt;&lt;br /&gt;
                    &amp;lt;li&amp;gt;VGP Xtra Trees and Flowers&amp;lt;/li&amp;gt;&lt;br /&gt;
                &amp;lt;/mods&amp;gt;&lt;br /&gt;
                &amp;lt;match Class=&amp;quot;PatchOperationSequence&amp;quot;&amp;gt;&lt;br /&gt;
                    &amp;lt;success&amp;gt;Always&amp;lt;/success&amp;gt;&lt;br /&gt;
                    &amp;lt;operations&amp;gt;&lt;br /&gt;
                        &amp;lt;!-- Processed camellia lumber. Mostly useful for building long-lasting, simple structures and furniture.--&amp;gt;&lt;br /&gt;
                        &amp;lt;li Class=&amp;quot;PatchOperationAddModExtension&amp;quot;&amp;gt;&lt;br /&gt;
                            &amp;lt;xpath&amp;gt;/Defs/ThingDef[defName=&amp;quot;LumberCamellia&amp;quot;]&amp;lt;/xpath&amp;gt;&lt;br /&gt;
                            &amp;lt;value&amp;gt;&lt;br /&gt;
                                &amp;lt;li Class=&amp;quot;SurvivalTools.StuffPropsTool&amp;quot;&amp;gt;&lt;br /&gt;
                                    &amp;lt;toolStatFactors&amp;gt;&lt;br /&gt;
                                        &amp;lt;ConstructionSpeed&amp;gt;0.55&amp;lt;/ConstructionSpeed&amp;gt;&lt;br /&gt;
                                    &amp;lt;/toolStatFactors&amp;gt;&lt;br /&gt;
                                &amp;lt;/li&amp;gt;&lt;br /&gt;
                            &amp;lt;/value&amp;gt;&lt;br /&gt;
                        &amp;lt;/li&amp;gt;&lt;br /&gt;
                    &amp;lt;/operations&amp;gt;&lt;br /&gt;
                &amp;lt;/match&amp;gt;&lt;br /&gt;
            &amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;/operations&amp;gt;&lt;br /&gt;
    &amp;lt;/match&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Random stuff===&lt;br /&gt;
* @ select by attribute. Useful for patching (Abstract) bases. &amp;lt;source lang = &amp;quot;xml&amp;quot;&amp;gt;/Defs/ThingDef[@Name=&amp;quot;BuildingBase&amp;quot;]&amp;lt;/source&amp;gt;&lt;br /&gt;
* ''or'' is inclusive. &amp;lt;source lang = &amp;quot;xml&amp;quot;&amp;gt;/Defs/ThingDef[defName=&amp;quot;Cassowary&amp;quot; or defName = &amp;quot;Emu&amp;quot; or defName = &amp;quot;Ostrich&amp;quot; or defName = &amp;quot;Turkey&amp;quot;]&amp;lt;/source&amp;gt; selects all of those in a single (faster) operation.&lt;br /&gt;
* PatchOperationAdd and PatchOperationInsert have an ''order'' tag which allows you to either Prepend or Append your add. Default behaviour of Add is to Append, insert Prepends.&lt;br /&gt;
* There is a ''success'' tag whose values can be Normal, Invert, Always and Never. This is used for the sake of error reporting: by default an error is logged when a patch fails to apply. For PatchOperationSequences and PatchOperationTests, you can set success to Always to avoid error logging.&lt;br /&gt;
* More useful things:&lt;br /&gt;
** Select nodes by text &amp;lt;source lang = &amp;quot;xml&amp;quot;&amp;gt;ExampleTag/li[text()=&amp;quot;Submit&amp;quot;]&amp;lt;/source&amp;gt;&lt;br /&gt;
** Select nodes by text with a type of wildcard &amp;lt;source lang = &amp;quot;xml&amp;quot;&amp;gt;ExampleTag[contains(text(), &amp;quot;MFI_&amp;quot;)]&amp;lt;/source&amp;gt;&lt;br /&gt;
** Exclude nodes with not() &amp;lt;source lang = &amp;quot;xml&amp;quot;&amp;gt;[not(xxxxx)]&amp;lt;/source&amp;gt;&lt;br /&gt;
** Can't think of an example but I'm sure someone will find a use for &amp;lt;source lang = &amp;quot;xml&amp;quot;&amp;gt;[count(li)]&amp;lt;/source&amp;gt;&lt;br /&gt;
** Go back to parentnode with &amp;lt;source lang = &amp;quot;xml&amp;quot;&amp;gt;..&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Write your own ==&lt;br /&gt;
Outside the scope of this wiki, but it's possible to write your own PatchOperation.&amp;lt;/br&amp;gt;&lt;br /&gt;
- [https://github.com/NoImageAvailable/CombatExtended/blob/88ef1f86d30e6c285e3370bd9faafa92c84195b0/Source/CombatExtended/CombatExtended/PatchOperationMakeGunCECompatible.cs Example PatchOperationMakeGunCECompatible]&amp;lt;/br&amp;gt;&lt;br /&gt;
- [https://gist.github.com/Lanilor/e326e33e268e78f68a2f5cd3cdbbe8c0 Example PatchOperationAddOrReplace]&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Resources ==&lt;br /&gt;
&lt;br /&gt;
The best tutorial on PatchOperations created by Zhentar: [https://gist.github.com/Zhentar/4a1b71cea45b9337f70b30a21d868782 Introduction to PatchOperation]&lt;br /&gt;
&lt;br /&gt;
You can also learn about XPaths here: [https://www.w3schools.com/xml/xpath_intro.asp XPath tutorial]&lt;br /&gt;
&lt;br /&gt;
There is also an [https://github.com/roxxploxx/RimWorldModGuide/wiki/SHORTTUTORIAL:-DefPatches Overview of PatchOperations]  on the [https://github.com/roxxploxx/RimWorldModGuide/wiki RimWorldModGuide].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Modding]]&lt;br /&gt;
[[Category:Modding tutorials]]&lt;/div&gt;</summary>
		<author><name>Lilwhitemouse</name></author>
	</entry>
	<entry>
		<id>https://rimworldwiki.com/index.php?title=Modding_Tutorials/PatchOperations&amp;diff=67421</id>
		<title>Modding Tutorials/PatchOperations</title>
		<link rel="alternate" type="text/html" href="https://rimworldwiki.com/index.php?title=Modding_Tutorials/PatchOperations&amp;diff=67421"/>
		<updated>2020-01-12T14:43:42Z</updated>

		<summary type="html">&lt;p&gt;Lilwhitemouse: /* PatchOperationAttributeSet */ put in = for attriubute examples&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{BackToTutorials}}&lt;br /&gt;
&lt;br /&gt;
RimWorld Alpha 17 added a new modding feature: '''XML PatchOperations'''. Using these allows mods to edit specific elements of XML defs, rather than simply overwriting the old def with a new one, which was the required approach until A17. This greatly reduces mod conflicts, because mods that make separate changes to the same def won't necessarily overwrite one another's changes. Mods using PatchOperations can avoid requiring special compatibility mods, and can even add special features conditional on other mods being loaded.&lt;br /&gt;
&lt;br /&gt;
Here's a simple example of replacing the texture path for deep water:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot; ?&amp;gt;&lt;br /&gt;
&amp;lt;Patch&amp;gt;&lt;br /&gt;
  &amp;lt;Operation Class=&amp;quot;PatchOperationReplace&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;/Defs/TerrainDef[defName=&amp;quot;WaterDeep&amp;quot;]/texturePath&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;value&amp;gt;&lt;br /&gt;
      &amp;lt;texturePath&amp;gt;Your/Texture/Path/Here&amp;lt;/texturePath&amp;gt;&lt;br /&gt;
    &amp;lt;/value&amp;gt;&lt;br /&gt;
  &amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/Patch&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
This xml file simply goes inside YourMod/Patches/ and you're done.&lt;br /&gt;
&lt;br /&gt;
== Overview of available PatchOperations ==&lt;br /&gt;
These are the available PatchOperation types:&lt;br /&gt;
&lt;br /&gt;
* Four do basic operations on XML nodes:&lt;br /&gt;
** '''[[#PatchOperationAdd|PatchOperationAdd]]''' adds a provided child node to the selected node&lt;br /&gt;
** '''[[#PatchOperationInsert|PatchOperationInsert]]''' adds a provided sibling node to the selected node&lt;br /&gt;
** '''[[#PatchOperationRemove|PatchOperationRemove]]''' deletes the selected node&lt;br /&gt;
** '''[[#PatchOperationReplace|PatchOperationReplace]]''' replaces the selected node with the provided node&lt;br /&gt;
* Three do basic operations on XML attributes:&lt;br /&gt;
** '''[[#PatchOperationAttributeAdd|PatchOperationAttributeAdd]]''' adds a provided attribute to the selected node if and only if the attribute name is not already present&lt;br /&gt;
** '''[[#PatchOperationAttributeSet|PatchOperationAttributeSet]]''' sets a provided attribute for the selected node, overwriting the attribute value if the attribute name is already present&lt;br /&gt;
** '''[[#PatchOperationAttributeRemove|PatchOperationAttributeRemove]]''' removes an attribute for the selected node&lt;br /&gt;
* Three allow for more complex operations:&lt;br /&gt;
** '''[[#PatchOperationAddModExtension|PatchOperationAddModExtension]]''' adds a ModExtension.&lt;br /&gt;
** '''[[#PatchOperationSetName|PatchOperationSetName]]''' changes the name of a node.&lt;br /&gt;
** '''[[#PatchOperationSequence|PatchOperationSequence]]''' contains a set of other PatchOperations, and aborts upon any operation failing&lt;br /&gt;
* Three allow for conditional operations:&lt;br /&gt;
** '''[[#PatchOperationTest|PatchOperationTest]]''' tests nodes, which is useful inside a PatchOperationSequence&lt;br /&gt;
** '''[[#PatchOperationConditional|PatchOperationConditional]]''' tests nodes, and can do different operations depending on the result.&lt;br /&gt;
** '''[[#PatchOperationFindMod|PatchOperationFindMod]]''' tests for the presence of another mod, and can do different operations depending on the result.&lt;br /&gt;
&lt;br /&gt;
==XPath syntax==&lt;br /&gt;
Each PatchOperation must specify an XML node to modify. It uses XPaths to specify them. An XPath is a &amp;quot;path&amp;quot; for the patch to follow when trying to find XML nodes matching the description. It will follow each part of the path from left to right. Note that these &amp;quot;paths&amp;quot; have zero relation to the file path or folder structure: They follow the structure of the XML nodes.&lt;br /&gt;
&lt;br /&gt;
XPaths start at the root node. Since the root node of all Defs is enforced to be &amp;lt;Defs&amp;gt;, so &amp;lt;code&amp;gt;/Defs/&amp;lt;/code&amp;gt; is the start of our xpath. &amp;lt;code&amp;gt;*/&amp;lt;/code&amp;gt; is also valid, as it uses the &amp;lt;code&amp;gt;*&amp;lt;/code&amp;gt; wildcard: &amp;lt;code&amp;gt;*&amp;lt;/code&amp;gt; matches any element, so it'll match the root (the top level) of the XML tree. &amp;lt;code&amp;gt;//&amp;lt;/code&amp;gt; is technically also valid, but because that construct selects ''all'' the elements in the XML tree, it's an expensive operation that makes game loading exponentially slower.&lt;br /&gt;
&lt;br /&gt;
Once the root is selected, the XPath lets the system walk down specific branches of the tree. If we use the example from the lead, we get a specific path:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;/Defs/TerrainDef[defName=&amp;quot;WaterDeep&amp;quot;]/texturePath&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# The root node is selected&lt;br /&gt;
# All child nodes of the root node called &amp;quot;TerrainDef&amp;quot; are selected&lt;br /&gt;
# We narrow down from &amp;quot;all TerrainDefs&amp;quot; to only those with the child &amp;quot;defName&amp;quot; node whose value is &amp;quot;WaterDeep&amp;quot;, which should give us exactly one node because defNames must be unique&lt;br /&gt;
# We select the child node &amp;quot;texturePath&amp;quot; from this node&lt;br /&gt;
## Note that we cannot put &amp;lt;code&amp;gt;.../texturePath/&amp;lt;/code&amp;gt; to specify the content of the texturePath node.  If we want to replace texturePath, we have to replace it with &amp;lt;code&amp;gt;&amp;lt;texturePath&amp;gt;/new/path/to/texture&amp;lt;/texturePath&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more info, see this {{LudeonThread|32785}}. XPath is a [https://www.w3schools.com/xml/xml_xpath.asp well-documented industry standard] (good resource, too); there are plenty of resources available on the subject ranging from exhaustive tutorials to simple [https://stackoverflow.com/questions/tagged/xpath StackOverflow] questions.&lt;br /&gt;
&lt;br /&gt;
==&amp;quot;Success&amp;quot; option==&lt;br /&gt;
The ''&amp;lt;code&amp;gt;&amp;lt;success&amp;gt;...&amp;lt;/success&amp;gt;&amp;lt;/code&amp;gt;'' term specifies whether the entire operation is considered a success or not.  If the overall patch operation is not considered a success, an error is thrown. This is particularly used in Sequences and Tests, where you'd not want to throw an error on a simple test.&lt;br /&gt;
&lt;br /&gt;
Options available are:&lt;br /&gt;
* Always - this patch operation is considered a success - sometimes used for Sequences so that if an early test in the sequence fails, an error is not reported (because the sequence is still a successful patch)&lt;br /&gt;
* Normal - this patch operation is considered a success if it succeeded (content patched, test passed, etc)&lt;br /&gt;
* Invert - If the patch failed (e.g., a test), then it's considered a success (useful for a negative test in a sequence)&lt;br /&gt;
* Never - this patch operation &amp;quot;failed.&amp;quot;  Even if it patched whatever it was supposed to correctly.  If you ever use this, leave a note here for the curious.&lt;br /&gt;
&lt;br /&gt;
==Overview of individual PatchOperations==&lt;br /&gt;
===PatchOperationAdd===&lt;br /&gt;
''PatchOperationAdd'' adds a child node to the selected node.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationAdd&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;/Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleList&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;value&amp;gt;&lt;br /&gt;
        &amp;lt;li&amp;gt;Foo&amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;li&amp;gt;Bar&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;/value&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList&amp;gt;&lt;br /&gt;
            &amp;lt;li&amp;gt;Foo&amp;lt;/li&amp;gt;&lt;br /&gt;
            &amp;lt;li&amp;gt;Bar&amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;/exampleList&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationInsert===&lt;br /&gt;
''PatchOperationInsert'' adds a sibling to the selected node.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
  &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
    &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
    &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
    &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
  &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationInsert&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;xpath&amp;gt;/Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
  &amp;lt;value&amp;gt;&lt;br /&gt;
    &amp;lt;anotherExample&amp;gt;A new sibling&amp;lt;/anotherExample&amp;gt;&lt;br /&gt;
  &amp;lt;/value&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
  &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
    &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
    &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
    &amp;lt;anotherExample&amp;gt;A new sibling&amp;lt;/anotherExample&amp;gt;&lt;br /&gt;
    &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
  &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationRemove===&lt;br /&gt;
''PatchOperationRemove'' removes the selected node.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationRemove&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;/Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationReplace===&lt;br /&gt;
''PatchOperationReplace'' replaces the selected node.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationReplace&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;/Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;value&amp;gt;&lt;br /&gt;
        &amp;lt;anotherExample&amp;gt;An alternate node&amp;lt;/anotherExample&amp;gt;&lt;br /&gt;
    &amp;lt;/value&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;anotherExample&amp;gt;An alternate node&amp;lt;/anotherExample&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationAttributeAdd===&lt;br /&gt;
''PatchOperationAttributeAdd'' will add an attribute and set its value, but only if that attribute is not yet present.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationAttributeAdd&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;/Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;attribute&amp;gt;ExampleAttribute&amp;lt;/attribute&amp;gt;&lt;br /&gt;
    &amp;lt;value&amp;gt;ExampleValue&amp;lt;/value&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode ExampleAttribute&amp;quot;ExampleValue&amp;quot;&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationAttributeSet===&lt;br /&gt;
''PatchOperationAttributeSet'' will add an attribute and set its value. Unlike PatchAttributeAdd, PatchOperationAttributeSet will overwrite any existing value. &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode ExampleAttribute=&amp;quot;ExampleValue&amp;quot;&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationAttributeSet&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;/Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;attribute&amp;gt;ExampleAttribute&amp;lt;/attribute&amp;gt;&lt;br /&gt;
    &amp;lt;value&amp;gt;DifferentExampleValue&amp;lt;/value&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode ExampleAttribute=&amp;quot;DifferentExampleValue&amp;quot;&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationAttributeRemove===&lt;br /&gt;
''PatchOperationAttributeRemove'' removes the specified attribute.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode ExampleAttribute&amp;quot;ExampleValue&amp;quot;&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationAttributeRemove&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;/Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;attribute&amp;gt;ExampleAttribute&amp;lt;/attribute&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationAddModExtension===&lt;br /&gt;
{{Main|Modding Tutorials/DefModExtension}}&lt;br /&gt;
''PatchOperationAddModExtension'' adds a [[Modding Tutorials/DefModExtension|Mod Extension]].&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationAddModExtension&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;/Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;value&amp;gt;&lt;br /&gt;
        &amp;lt;li Class=&amp;quot;ExampleNameSpace.ExampleModExtension&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;exampleValue&amp;gt;true&amp;lt;/exampleValue&amp;gt;&lt;br /&gt;
        &amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;/value&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
        &amp;lt;modExtensions&amp;gt;&lt;br /&gt;
            &amp;lt;li Class=&amp;quot;ExampleNameSpace.ExampleModExtension&amp;quot;&amp;gt;&lt;br /&gt;
                &amp;lt;exampleValue&amp;gt;true&amp;lt;/exampleValue&amp;gt;&lt;br /&gt;
            &amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;/modExtensions&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationSetName===&lt;br /&gt;
''PatchOperationSetName'' changes the name of a node.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationSetName&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;/Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;name&amp;gt;newExampleName&amp;lt;/name&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;newExampleName&amp;gt;Some text&amp;lt;/newExampleName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationSequence===&lt;br /&gt;
''PatchOperationSequence'' will complete all operations in the order of their listing, and stop when any of them fails.&lt;br /&gt;
&lt;br /&gt;
Modders will often specify &amp;lt;code&amp;gt;&amp;lt;success&amp;gt;Always&amp;lt;/success&amp;gt;&amp;lt;/code&amp;gt;, which will mean that even if one part of the sequence fails (e.g., a test), the whole is still considered a success and no unneeded errors show up.&lt;br /&gt;
&lt;br /&gt;
'''Patch Operation'''&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationSequence&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;!-- put &amp;lt;success&amp;gt;Always&amp;lt;/success&amp;gt; if using tests?  Leave out for simple sequences --&amp;gt;&lt;br /&gt;
  &amp;lt;operations&amp;gt;&lt;br /&gt;
    &amp;lt;li Class=&amp;quot;PatchOperationInsert&amp;quot;&amp;gt;&amp;lt;!-- Always happens! --&amp;gt;&lt;br /&gt;
      &amp;lt;xpath&amp;gt;/Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
      &amp;lt;value&amp;gt;&lt;br /&gt;
        &amp;lt;anotherExample&amp;gt;A new sibling&amp;lt;/anotherExample&amp;gt;&lt;br /&gt;
      &amp;lt;/value&amp;gt;&lt;br /&gt;
    &amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;li Class=&amp;quot;PatchOperationAdd&amp;quot;&amp;gt;&amp;lt;!-- Always happens! --&amp;gt;&lt;br /&gt;
      &amp;lt;xpath&amp;gt;/Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]&amp;lt;/xpath&amp;gt;&lt;br /&gt;
      &amp;lt;value&amp;gt;&amp;lt;label&amp;gt;I'm a node&amp;lt;/label&amp;gt;&amp;lt;/value&amp;gt;&lt;br /&gt;
    &amp;lt;li&amp;gt;&lt;br /&gt;
    &amp;lt;!-- etc --&amp;gt;&lt;br /&gt;
  &amp;lt;operations&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Effect'''&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
  &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
    &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
  &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
  &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
    &amp;lt;label&amp;gt;I'm a node&amp;lt;/label&amp;gt;&lt;br /&gt;
    &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
    &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
    &amp;lt;anotherExample&amp;gt;A new sibling&amp;lt;/anotherExample&amp;gt;&lt;br /&gt;
    &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
  &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
'''Another Example''': Maybe you don't like the &amp;quot;Example&amp;quot; ExampleDef...&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationSequence&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;success&amp;gt;Always&amp;lt;/success&amp;gt;&amp;lt;!-- No errors thrown --&amp;gt;&lt;br /&gt;
  &amp;lt;operations&amp;gt;&lt;br /&gt;
    &amp;lt;li Class=&amp;quot;PatchOperationRemove&amp;quot;&amp;gt;&amp;lt;!-- :o  ...this returns true --&amp;gt;&lt;br /&gt;
      &amp;lt;xpath&amp;gt;/Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]&amp;lt;xpath&amp;gt;&lt;br /&gt;
    &amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;li Class=&amp;quot;PatchOperationAdd&amp;quot;&amp;gt;&amp;lt;!-- so this runs --&amp;gt;&lt;br /&gt;
      &amp;lt;xpath&amp;gt;/Defs&amp;lt;/xpath&amp;gt;&lt;br /&gt;
      &amp;lt;value&amp;gt;&lt;br /&gt;
        &amp;lt;ExampleDef&amp;gt;&amp;lt;defName&amp;gt;MyBetterExample&amp;lt;/defName&amp;gt;&amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
      &amp;lt;/value&amp;gt;&lt;br /&gt;
  &amp;lt;/operations&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If ExampleDef were already gone, MyBetterExample would not get added.&lt;br /&gt;
&lt;br /&gt;
===PatchOperationTest===&lt;br /&gt;
''PatchOperationTest'' tests for the existence/validity of an xpath. Useful to stop a PatchOperationSequence. Often used as a simpler, less powerful version of PatchOperationConditional.&lt;br /&gt;
The following example patch is from Apparello, by Shinzy. &lt;br /&gt;
&amp;lt;source lang =&amp;quot;xml&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationSequence&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;!-- check for worn graphics and if none found, add one --&amp;gt;&lt;br /&gt;
    &amp;lt;success&amp;gt;Always&amp;lt;/success&amp;gt;&lt;br /&gt;
    &amp;lt;operations&amp;gt;&lt;br /&gt;
        &amp;lt;li Class=&amp;quot;PatchOperationTest&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;xpath&amp;gt;/Defs/ThingDef[defName = &amp;quot;Apparel_Pants&amp;quot;]/apparel/wornGraphicPath&amp;lt;/xpath&amp;gt;&lt;br /&gt;
            &amp;lt;success&amp;gt;Invert&amp;lt;/success&amp;gt;&lt;br /&gt;
        &amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;li Class=&amp;quot;PatchOperationAdd&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;xpath&amp;gt;/Defs/ThingDef[defName = &amp;quot;Apparel_Pants&amp;quot;]/apparel&amp;lt;/xpath&amp;gt;&lt;br /&gt;
            &amp;lt;value&amp;gt;&lt;br /&gt;
                &amp;lt;wornGraphicPath&amp;gt;Accessorello/Pants/Pants&amp;lt;/wornGraphicPath&amp;gt;&lt;br /&gt;
            &amp;lt;/value&amp;gt;&lt;br /&gt;
        &amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;/operations&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===PatchOperationConditional===&lt;br /&gt;
''PatchOperationConditional'' can branch logic based on a match/nomatch. The following example patch adds a &amp;lt;comps&amp;gt; node if it does not yet exist, and adds itself &lt;br /&gt;
&lt;br /&gt;
This patch is courtesy Mehni. [https://github.com/Mehni/MoreFactionInteraction/blob/ab3ab2a22ee529ee4e38a471fe150fd48fd07ce9/Patches/MoreFactionInteraction.xml#L40-L62 See original.]&lt;br /&gt;
&amp;lt;source lang =&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!-- Add /comps/li/compClass if there are no comps yet. --&amp;gt;&lt;br /&gt;
&amp;lt;!-- Add /li/compClass to /comps if exists (i.e. other mod already added the comps field first) --&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationConditional&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;/Defs/WorldObjectDef[defName=&amp;quot;Caravan&amp;quot;]/comps&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;nomatch Class=&amp;quot;PatchOperationAdd&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;xpath&amp;gt;/Defs/WorldObjectDef[defName=&amp;quot;Caravan&amp;quot;]&amp;lt;/xpath&amp;gt;&lt;br /&gt;
        &amp;lt;value&amp;gt;&lt;br /&gt;
            &amp;lt;comps&amp;gt;&lt;br /&gt;
                &amp;lt;li&amp;gt;&lt;br /&gt;
                    &amp;lt;compClass&amp;gt;MoreFactionInteraction.WorldObjectComp_CaravanComp&amp;lt;/compClass&amp;gt;&lt;br /&gt;
                &amp;lt;/li&amp;gt;&lt;br /&gt;
            &amp;lt;/comps&amp;gt;&lt;br /&gt;
        &amp;lt;/value&amp;gt;&lt;br /&gt;
    &amp;lt;/nomatch&amp;gt;&lt;br /&gt;
    &amp;lt;match Class=&amp;quot;PatchOperationAdd&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;xpath&amp;gt;/Defs/WorldObjectDef[defName=&amp;quot;Caravan&amp;quot;]/comps&amp;lt;/xpath&amp;gt;&lt;br /&gt;
        &amp;lt;value&amp;gt;&lt;br /&gt;
            &amp;lt;li&amp;gt;&lt;br /&gt;
                &amp;lt;compClass&amp;gt;MoreFactionInteraction.WorldObjectComp_CaravanComp&amp;lt;/compClass&amp;gt;&lt;br /&gt;
            &amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;/value&amp;gt;&lt;br /&gt;
    &amp;lt;/match&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===PatchOperationFindMod===&lt;br /&gt;
''PatchOperationFindMod'' searches the list of active mods for the mods listed in &amp;lt;nowiki&amp;gt;&amp;lt;li&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/nowiki&amp;gt; tags.&lt;br /&gt;
&lt;br /&gt;
For a successful match, &amp;lt;nowiki&amp;gt;&amp;lt;li&amp;gt;ModName&amp;lt;/li&amp;gt;&amp;lt;/nowiki&amp;gt; has to match the &amp;lt;name&amp;gt;ModName&amp;lt;/name&amp;gt; in the About.xml of the mod you base your patch behaviour on. It only needs to find ''one'' of the mods in the list for a successful match.&lt;br /&gt;
This (shortened) patch is courtesy Mehni. [https://github.com/Mehni/MoreFactionInteraction/blob/ab3ab2a22ee529ee4e38a471fe150fd48fd07ce9/Patches/MoreFactionInteraction.xml#L64 See original.]&lt;br /&gt;
&lt;br /&gt;
The following Patch adds the RimQuest mod extension to the listed Defs when RimQuest is found.&lt;br /&gt;
&amp;lt;source lang =&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationFindMod&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;mods&amp;gt;&lt;br /&gt;
        &amp;lt;li&amp;gt;RimQuest&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;/mods&amp;gt;&lt;br /&gt;
    &amp;lt;match Class=&amp;quot;PatchOperationAddModExtension&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;xpath&amp;gt;/Defs/IncidentDef[defName=&amp;quot;MFI_DiplomaticMarriage&amp;quot; or defName=&amp;quot;MFI_HuntersLodge&amp;quot; or defName=&amp;quot;MFI_Quest_PeaceTalks&amp;quot;]&amp;lt;/xpath&amp;gt;&lt;br /&gt;
        &amp;lt;value&amp;gt;&lt;br /&gt;
            &amp;lt;li Class = &amp;quot;RimQuest.RimQuest_ModExtension&amp;quot;&amp;gt;&lt;br /&gt;
                &amp;lt;canBeARimQuest&amp;gt;false&amp;lt;/canBeARimQuest&amp;gt;&lt;br /&gt;
            &amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;/value&amp;gt;&lt;br /&gt;
    &amp;lt;/match&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following Patch replace the tabWindowClass of the xpath when Relations Tab is '''not''' found. &lt;br /&gt;
&amp;lt;source lang =&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationFindMod&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;mods&amp;gt;&lt;br /&gt;
        &amp;lt;li&amp;gt;Relations Tab&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;/mods&amp;gt;&lt;br /&gt;
    &amp;lt;nomatch Class=&amp;quot;PatchOperationReplace&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;xpath&amp;gt;/Defs/MainButtonDef[defName=&amp;quot;Factions&amp;quot;]/tabWindowClass&amp;lt;/xpath&amp;gt;&lt;br /&gt;
        &amp;lt;value&amp;gt;&lt;br /&gt;
            &amp;lt;tabWindowClass&amp;gt;MyNameSpace.MyTabWindowClass&amp;lt;/tabWindowClass&amp;gt;&lt;br /&gt;
        &amp;lt;/value&amp;gt;&lt;br /&gt;
    &amp;lt;/nomatch&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Common issues==&lt;br /&gt;
Spelling matters, and XPath is case sensitive. It's ''very'' case sensitive. If you've written something that doesn't work but you're convinced it should, put it through some XPath validator. Case sensitivity includes but is not limited to the &amp;lt;Operation Class=&amp;quot;PatchOperationWhatever&amp;quot;&amp;gt;, the XPath, the value, every tag -- spell it right.&lt;br /&gt;
&lt;br /&gt;
Another common issue is swapping Insert and Add, which leads to a different position in the node. A common misconception is trying to account for file paths. The file path is completely irrelevant to the expression you're writing. XPath is used to search XML content, not files themselves.&lt;br /&gt;
&lt;br /&gt;
Still beating your head against a wall? The main RimWorld [https://discord.gg/RimWorld discord] has helpful people and a bot where you can test XPath, and the forums have a [https://ludeon.com/forums/index.php?board=14.0 help] section as well.&lt;br /&gt;
&lt;br /&gt;
==Some advanced examples==&lt;br /&gt;
This (shortened) patch is courtesy XeoNovaDan. [https://github.com/XeoNovaDan/SurvivalTools/blob/62a4316c81733dde417257bf4bc5c34e3e781c7d/Patches/ExpandedWoodworkingVGP/Patch.xml See original]. Viewer discretion is advised. Parents please take precautions if young children are present.&lt;br /&gt;
&amp;lt;source lang = &amp;quot;XML&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationFindMod&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;mods&amp;gt;&lt;br /&gt;
        &amp;lt;li&amp;gt;Expanded Woodworking for Vegetable Garden Project&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;/mods&amp;gt;&lt;br /&gt;
    &amp;lt;match Class=&amp;quot;PatchOperationSequence&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;success&amp;gt;Always&amp;lt;/success&amp;gt;&lt;br /&gt;
        &amp;lt;operations&amp;gt;&lt;br /&gt;
            &amp;lt;!-- Nested PatchOpFindMod. Used because Expanded Woodworking adds more Wood when VGP Xtra is installed. --&amp;gt;&lt;br /&gt;
            &amp;lt;li Class=&amp;quot;PatchOperationFindMod&amp;quot;&amp;gt;&lt;br /&gt;
                &amp;lt;mods&amp;gt;&lt;br /&gt;
                    &amp;lt;li&amp;gt;VGP Xtra Trees and Flowers&amp;lt;/li&amp;gt;&lt;br /&gt;
                &amp;lt;/mods&amp;gt;&lt;br /&gt;
                &amp;lt;match Class=&amp;quot;PatchOperationSequence&amp;quot;&amp;gt;&lt;br /&gt;
                    &amp;lt;success&amp;gt;Always&amp;lt;/success&amp;gt;&lt;br /&gt;
                    &amp;lt;operations&amp;gt;&lt;br /&gt;
                        &amp;lt;!-- Processed camellia lumber. Mostly useful for building long-lasting, simple structures and furniture.--&amp;gt;&lt;br /&gt;
                        &amp;lt;li Class=&amp;quot;PatchOperationAddModExtension&amp;quot;&amp;gt;&lt;br /&gt;
                            &amp;lt;xpath&amp;gt;/Defs/ThingDef[defName=&amp;quot;LumberCamellia&amp;quot;]&amp;lt;/xpath&amp;gt;&lt;br /&gt;
                            &amp;lt;value&amp;gt;&lt;br /&gt;
                                &amp;lt;li Class=&amp;quot;SurvivalTools.StuffPropsTool&amp;quot;&amp;gt;&lt;br /&gt;
                                    &amp;lt;toolStatFactors&amp;gt;&lt;br /&gt;
                                        &amp;lt;ConstructionSpeed&amp;gt;0.55&amp;lt;/ConstructionSpeed&amp;gt;&lt;br /&gt;
                                    &amp;lt;/toolStatFactors&amp;gt;&lt;br /&gt;
                                &amp;lt;/li&amp;gt;&lt;br /&gt;
                            &amp;lt;/value&amp;gt;&lt;br /&gt;
                        &amp;lt;/li&amp;gt;&lt;br /&gt;
                    &amp;lt;/operations&amp;gt;&lt;br /&gt;
                &amp;lt;/match&amp;gt;&lt;br /&gt;
            &amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;/operations&amp;gt;&lt;br /&gt;
    &amp;lt;/match&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Random stuff===&lt;br /&gt;
* @ select by attribute. Useful for patching (Abstract) bases. &amp;lt;source lang = &amp;quot;xml&amp;quot;&amp;gt;/Defs/ThingDef[@Name=&amp;quot;BuildingBase&amp;quot;]&amp;lt;/source&amp;gt;&lt;br /&gt;
* ''or'' is inclusive. &amp;lt;source lang = &amp;quot;xml&amp;quot;&amp;gt;/Defs/ThingDef[defName=&amp;quot;Cassowary&amp;quot; or defName = &amp;quot;Emu&amp;quot; or defName = &amp;quot;Ostrich&amp;quot; or defName = &amp;quot;Turkey&amp;quot;]&amp;lt;/source&amp;gt; selects all of those in a single (faster) operation.&lt;br /&gt;
* PatchOperationAdd and PatchOperationInsert have an ''order'' tag which allows you to either Prepend or Append your add. Default behaviour of Add is to Append, insert Prepends.&lt;br /&gt;
* There is a ''success'' tag whose values can be Normal, Invert, Always and Never. This is used for the sake of error reporting: by default an error is logged when a patch fails to apply. For PatchOperationSequences and PatchOperationTests, you can set success to Always to avoid error logging.&lt;br /&gt;
* More useful things:&lt;br /&gt;
** Select nodes by text &amp;lt;source lang = &amp;quot;xml&amp;quot;&amp;gt;ExampleTag/li[text()=&amp;quot;Submit&amp;quot;]&amp;lt;/source&amp;gt;&lt;br /&gt;
** Select nodes by text with a type of wildcard &amp;lt;source lang = &amp;quot;xml&amp;quot;&amp;gt;ExampleTag[contains(text(), &amp;quot;MFI_&amp;quot;)]&amp;lt;/source&amp;gt;&lt;br /&gt;
** Exclude nodes with not() &amp;lt;source lang = &amp;quot;xml&amp;quot;&amp;gt;[not(xxxxx)]&amp;lt;/source&amp;gt;&lt;br /&gt;
** Can't think of an example but I'm sure someone will find a use for &amp;lt;source lang = &amp;quot;xml&amp;quot;&amp;gt;[count(li)]&amp;lt;/source&amp;gt;&lt;br /&gt;
** Go back to parentnode with &amp;lt;source lang = &amp;quot;xml&amp;quot;&amp;gt;..&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Write your own ==&lt;br /&gt;
Outside the scope of this wiki, but it's possible to write your own PatchOperation.&amp;lt;/br&amp;gt;&lt;br /&gt;
- [https://github.com/NoImageAvailable/CombatExtended/blob/88ef1f86d30e6c285e3370bd9faafa92c84195b0/Source/CombatExtended/CombatExtended/PatchOperationMakeGunCECompatible.cs Example PatchOperationMakeGunCECompatible]&amp;lt;/br&amp;gt;&lt;br /&gt;
- [https://gist.github.com/Lanilor/e326e33e268e78f68a2f5cd3cdbbe8c0 Example PatchOperationAddOrReplace]&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Resources ==&lt;br /&gt;
&lt;br /&gt;
The best tutorial on PatchOperations created by Zhentar: [https://gist.github.com/Zhentar/4a1b71cea45b9337f70b30a21d868782 Introduction to PatchOperation]&lt;br /&gt;
&lt;br /&gt;
You can also learn about XPaths here: [https://www.w3schools.com/xml/xpath_intro.asp XPath tutorial]&lt;br /&gt;
&lt;br /&gt;
There is also an [https://github.com/roxxploxx/RimWorldModGuide/wiki/SHORTTUTORIAL:-DefPatches Overview of PatchOperations]  on the [https://github.com/roxxploxx/RimWorldModGuide/wiki RimWorldModGuide].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Modding]]&lt;br /&gt;
[[Category:Modding tutorials]]&lt;/div&gt;</summary>
		<author><name>Lilwhitemouse</name></author>
	</entry>
	<entry>
		<id>https://rimworldwiki.com/index.php?title=Modding_Tutorials/PatchOperations&amp;diff=67380</id>
		<title>Modding Tutorials/PatchOperations</title>
		<link rel="alternate" type="text/html" href="https://rimworldwiki.com/index.php?title=Modding_Tutorials/PatchOperations&amp;diff=67380"/>
		<updated>2019-12-24T00:26:07Z</updated>

		<summary type="html">&lt;p&gt;Lilwhitemouse: /Defs slightly faster than Defs: see https://ludeon.com/forums/index.php?topic=32785.msg458062#msg458062&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{BackToTutorials}}&lt;br /&gt;
&lt;br /&gt;
RimWorld Alpha 17 added a new modding feature: '''XML PatchOperations'''. Using these allows mods to edit specific elements of XML defs, rather than simply overwriting the old def with a new one, which was the required approach until A17. This greatly reduces mod conflicts, because mods that make separate changes to the same def won't necessarily overwrite one another's changes. Mods using PatchOperations can avoid requiring special compatibility mods, and can even add special features conditional on other mods being loaded.&lt;br /&gt;
&lt;br /&gt;
Here's a simple example of replacing the texture path for deep water:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot; ?&amp;gt;&lt;br /&gt;
&amp;lt;Patch&amp;gt;&lt;br /&gt;
  &amp;lt;Operation Class=&amp;quot;PatchOperationReplace&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;/Defs/TerrainDef[defName=&amp;quot;WaterDeep&amp;quot;]/texturePath&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;value&amp;gt;&lt;br /&gt;
      &amp;lt;texturePath&amp;gt;Your/Texture/Path/Here&amp;lt;/texturePath&amp;gt;&lt;br /&gt;
    &amp;lt;/value&amp;gt;&lt;br /&gt;
  &amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/Patch&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
This xml file simply goes inside YourMod/Patches/ and you're done.&lt;br /&gt;
&lt;br /&gt;
== Overview of available PatchOperations ==&lt;br /&gt;
These are the available PatchOperation types:&lt;br /&gt;
&lt;br /&gt;
* Four do basic operations on XML nodes:&lt;br /&gt;
** '''[[#PatchOperationAdd|PatchOperationAdd]]''' adds a provided child node to the selected node&lt;br /&gt;
** '''[[#PatchOperationInsert|PatchOperationInsert]]''' adds a provided sibling node to the selected node&lt;br /&gt;
** '''[[#PatchOperationRemove|PatchOperationRemove]]''' deletes the selected node&lt;br /&gt;
** '''[[#PatchOperationReplace|PatchOperationReplace]]''' replaces the selected node with the provided node&lt;br /&gt;
* Three do basic operations on XML attributes:&lt;br /&gt;
** '''[[#PatchOperationAttributeAdd|PatchOperationAttributeAdd]]''' adds a provided attribute to the selected node if and only if the attribute name is not already present&lt;br /&gt;
** '''[[#PatchOperationAttributeSet|PatchOperationAttributeSet]]''' sets a provided attribute for the selected node, overwriting the attribute value if the attribute name is already present&lt;br /&gt;
** '''[[#PatchOperationAttributeRemove|PatchOperationAttributeRemove]]''' removes an attribute for the selected node&lt;br /&gt;
* Three allow for more complex operations:&lt;br /&gt;
** '''[[#PatchOperationAddModExtension|PatchOperationAddModExtension]]''' adds a ModExtension.&lt;br /&gt;
** '''[[#PatchOperationSetName|PatchOperationSetName]]''' changes the name of a node.&lt;br /&gt;
** '''[[#PatchOperationSequence|PatchOperationSequence]]''' contains a set of other PatchOperations, and aborts upon any operation failing&lt;br /&gt;
* Three allow for conditional operations:&lt;br /&gt;
** '''[[#PatchOperationTest|PatchOperationTest]]''' tests nodes, which is useful inside a PatchOperationSequence&lt;br /&gt;
** '''[[#PatchOperationConditional|PatchOperationConditional]]''' tests nodes, and can do different operations depending on the result.&lt;br /&gt;
** '''[[#PatchOperationFindMod|PatchOperationFindMod]]''' tests for the presence of another mod, and can do different operations depending on the result.&lt;br /&gt;
&lt;br /&gt;
==XPath syntax==&lt;br /&gt;
Each PatchOperation must specify an XML node to modify. It uses XPaths to specify them. An XPath is a &amp;quot;path&amp;quot; for the patch to follow when trying to find XML nodes matching the description. It will follow each part of the path from left to right. Note that these &amp;quot;paths&amp;quot; have zero relation to the file path or folder structure: They follow the structure of the XML nodes.&lt;br /&gt;
&lt;br /&gt;
XPaths start at the root node. Since the root node of all Defs is enforced to be &amp;lt;Defs&amp;gt;, so &amp;lt;code&amp;gt;/Defs/&amp;lt;/code&amp;gt; is the start of our xpath. &amp;lt;code&amp;gt;*/&amp;lt;/code&amp;gt; is also valid, as it uses the &amp;lt;code&amp;gt;*&amp;lt;/code&amp;gt; wildcard: &amp;lt;code&amp;gt;*&amp;lt;/code&amp;gt; matches any element, so it'll match the root (the top level) of the XML tree. &amp;lt;code&amp;gt;//&amp;lt;/code&amp;gt; is technically also valid, but because that construct selects ''all'' the elements in the XML tree, it's an expensive operation that makes game loading exponentially slower.&lt;br /&gt;
&lt;br /&gt;
Once the root is selected, the XPath lets the system walk down specific branches of the tree. If we use the example from the lead, we get a specific path:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;/Defs/TerrainDef[defName=&amp;quot;WaterDeep&amp;quot;]/texturePath&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# The root node is selected&lt;br /&gt;
# All child nodes of the root node called &amp;quot;TerrainDef&amp;quot; are selected&lt;br /&gt;
# We narrow down from &amp;quot;all TerrainDefs&amp;quot; to only those with the child &amp;quot;defName&amp;quot; node whose value is &amp;quot;WaterDeep&amp;quot;, which should give us exactly one node because defNames must be unique&lt;br /&gt;
# We select the child node &amp;quot;texturePath&amp;quot; from this node&lt;br /&gt;
## Note that we cannot put &amp;lt;code&amp;gt;.../texturePath/&amp;lt;/code&amp;gt; to specify the content of the texturePath node.  If we want to replace texturePath, we have to replace it with &amp;lt;code&amp;gt;&amp;lt;texturePath&amp;gt;/new/path/to/texture&amp;lt;/texturePath&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more info, see this {{LudeonThread|32785}}. XPath is a [https://www.w3schools.com/xml/xml_xpath.asp well-documented industry standard] (good resource, too); there are plenty of resources available on the subject ranging from exhaustive tutorials to simple [https://stackoverflow.com/questions/tagged/xpath StackOverflow] questions.&lt;br /&gt;
&lt;br /&gt;
==&amp;quot;Success&amp;quot; option==&lt;br /&gt;
The ''&amp;lt;code&amp;gt;&amp;lt;success&amp;gt;...&amp;lt;/success&amp;gt;&amp;lt;/code&amp;gt;'' term specifies whether the entire operation is considered a success or not.  If the overall patch operation is not considered a success, an error is thrown. This is particularly used in Sequences and Tests, where you'd not want to throw an error on a simple test.&lt;br /&gt;
&lt;br /&gt;
Options available are:&lt;br /&gt;
* Always - this patch operation is considered a success - sometimes used for Sequences so that if an early test in the sequence fails, an error is not reported (because the sequence is still a successful patch)&lt;br /&gt;
* Normal - this patch operation is considered a success if it succeeded (content patched, test passed, etc)&lt;br /&gt;
* Invert - If the patch failed (e.g., a test), then it's considered a success (useful for a negative test in a sequence)&lt;br /&gt;
* Never - this patch operation &amp;quot;failed.&amp;quot;  Even if it patched whatever it was supposed to correctly.  If you ever use this, leave a note here for the curious.&lt;br /&gt;
&lt;br /&gt;
==Overview of individual PatchOperations==&lt;br /&gt;
===PatchOperationAdd===&lt;br /&gt;
''PatchOperationAdd'' adds a child node to the selected node.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationAdd&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;/Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleList&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;value&amp;gt;&lt;br /&gt;
        &amp;lt;li&amp;gt;Foo&amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;li&amp;gt;Bar&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;/value&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList&amp;gt;&lt;br /&gt;
            &amp;lt;li&amp;gt;Foo&amp;lt;/li&amp;gt;&lt;br /&gt;
            &amp;lt;li&amp;gt;Bar&amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;/exampleList&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationInsert===&lt;br /&gt;
''PatchOperationInsert'' adds a sibling to the selected node.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
  &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
    &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
    &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
    &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
  &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationInsert&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;xpath&amp;gt;/Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
  &amp;lt;value&amp;gt;&lt;br /&gt;
    &amp;lt;anotherExample&amp;gt;A new sibling&amp;lt;/anotherExample&amp;gt;&lt;br /&gt;
  &amp;lt;/value&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
  &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
    &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
    &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
    &amp;lt;anotherExample&amp;gt;A new sibling&amp;lt;/anotherExample&amp;gt;&lt;br /&gt;
    &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
  &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationRemove===&lt;br /&gt;
''PatchOperationRemove'' removes the selected node.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationRemove&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;/Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationReplace===&lt;br /&gt;
''PatchOperationReplace'' replaces the selected node.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationReplace&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;/Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;value&amp;gt;&lt;br /&gt;
        &amp;lt;anotherExample&amp;gt;An alternate node&amp;lt;/anotherExample&amp;gt;&lt;br /&gt;
    &amp;lt;/value&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;anotherExample&amp;gt;An alternate node&amp;lt;/anotherExample&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationAttributeAdd===&lt;br /&gt;
''PatchOperationAttributeAdd'' will add an attribute and set its value, but only if that attribute is not yet present.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationAttributeAdd&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;/Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;attribute&amp;gt;ExampleAttribute&amp;lt;/attribute&amp;gt;&lt;br /&gt;
    &amp;lt;value&amp;gt;ExampleValue&amp;lt;/value&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode ExampleAttribute&amp;quot;ExampleValue&amp;quot;&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationAttributeSet===&lt;br /&gt;
''PatchOperationAttributeSet'' will add an attribute and set its value. Unlike PatchAttributeAdd, PatchOperationAttributeSet will overwrite any existing value. &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode ExampleAttribute&amp;quot;ExampleValue&amp;quot;&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationAttributeSet&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;/Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;attribute&amp;gt;ExampleAttribute&amp;lt;/attribute&amp;gt;&lt;br /&gt;
    &amp;lt;value&amp;gt;DifferentExampleValue&amp;lt;/value&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode ExampleAttribute&amp;quot;DifferentExampleValue&amp;quot;&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationAttributeRemove===&lt;br /&gt;
''PatchOperationAttributeRemove'' removes the specified attribute.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode ExampleAttribute&amp;quot;ExampleValue&amp;quot;&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationAttributeRemove&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;/Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;attribute&amp;gt;ExampleAttribute&amp;lt;/attribute&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationAddModExtension===&lt;br /&gt;
{{Main|Modding Tutorials/DefModExtension}}&lt;br /&gt;
''PatchOperationAddModExtension'' adds a [[Modding Tutorials/DefModExtension|Mod Extension]].&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationAddModExtension&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;/Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;value&amp;gt;&lt;br /&gt;
        &amp;lt;li Class=&amp;quot;ExampleNameSpace.ExampleModExtension&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;exampleValue&amp;gt;true&amp;lt;/exampleValue&amp;gt;&lt;br /&gt;
        &amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;/value&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
        &amp;lt;modExtensions&amp;gt;&lt;br /&gt;
            &amp;lt;li Class=&amp;quot;ExampleNameSpace.ExampleModExtension&amp;quot;&amp;gt;&lt;br /&gt;
                &amp;lt;exampleValue&amp;gt;true&amp;lt;/exampleValue&amp;gt;&lt;br /&gt;
            &amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;/modExtensions&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationSetName===&lt;br /&gt;
''PatchOperationSetName'' changes the name of a node.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationSetName&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;/Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;name&amp;gt;newExampleName&amp;lt;/name&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;newExampleName&amp;gt;Some text&amp;lt;/newExampleName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationSequence===&lt;br /&gt;
''PatchOperationSequence'' will complete all operations in the order of their listing, and stop when any of them fails.&lt;br /&gt;
&lt;br /&gt;
Modders will often specify &amp;lt;code&amp;gt;&amp;lt;success&amp;gt;Always&amp;lt;/success&amp;gt;&amp;lt;/code&amp;gt;, which will mean that even if one part of the sequence fails (e.g., a test), the whole is still considered a success and no unneeded errors show up.&lt;br /&gt;
&lt;br /&gt;
'''Patch Operation'''&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationSequence&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;!-- put &amp;lt;success&amp;gt;Always&amp;lt;/success&amp;gt; if using tests?  Leave out for simple sequences --&amp;gt;&lt;br /&gt;
  &amp;lt;operations&amp;gt;&lt;br /&gt;
    &amp;lt;li Class=&amp;quot;PatchOperationInsert&amp;quot;&amp;gt;&amp;lt;!-- Always happens! --&amp;gt;&lt;br /&gt;
      &amp;lt;xpath&amp;gt;/Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
      &amp;lt;value&amp;gt;&lt;br /&gt;
        &amp;lt;anotherExample&amp;gt;A new sibling&amp;lt;/anotherExample&amp;gt;&lt;br /&gt;
      &amp;lt;/value&amp;gt;&lt;br /&gt;
    &amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;li Class=&amp;quot;PatchOperationAdd&amp;quot;&amp;gt;&amp;lt;!-- Always happens! --&amp;gt;&lt;br /&gt;
      &amp;lt;xpath&amp;gt;/Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]&amp;lt;/xpath&amp;gt;&lt;br /&gt;
      &amp;lt;value&amp;gt;&amp;lt;label&amp;gt;I'm a node&amp;lt;/label&amp;gt;&amp;lt;/value&amp;gt;&lt;br /&gt;
    &amp;lt;li&amp;gt;&lt;br /&gt;
    &amp;lt;!-- etc --&amp;gt;&lt;br /&gt;
  &amp;lt;operations&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Effect'''&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
  &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
    &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
  &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
  &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
    &amp;lt;label&amp;gt;I'm a node&amp;lt;/label&amp;gt;&lt;br /&gt;
    &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
    &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
    &amp;lt;anotherExample&amp;gt;A new sibling&amp;lt;/anotherExample&amp;gt;&lt;br /&gt;
    &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
  &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
'''Another Example''': Maybe you don't like the &amp;quot;Example&amp;quot; ExampleDef...&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationSequence&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;success&amp;gt;Always&amp;lt;/success&amp;gt;&amp;lt;!-- No errors thrown --&amp;gt;&lt;br /&gt;
  &amp;lt;operations&amp;gt;&lt;br /&gt;
    &amp;lt;li Class=&amp;quot;PatchOperationRemove&amp;quot;&amp;gt;&amp;lt;!-- :o  ...this returns true --&amp;gt;&lt;br /&gt;
      &amp;lt;xpath&amp;gt;/Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]&amp;lt;xpath&amp;gt;&lt;br /&gt;
    &amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;li Class=&amp;quot;PatchOperationAdd&amp;quot;&amp;gt;&amp;lt;!-- so this runs --&amp;gt;&lt;br /&gt;
      &amp;lt;xpath&amp;gt;/Defs&amp;lt;/xpath&amp;gt;&lt;br /&gt;
      &amp;lt;value&amp;gt;&lt;br /&gt;
        &amp;lt;ExampleDef&amp;gt;&amp;lt;defName&amp;gt;MyBetterExample&amp;lt;/defName&amp;gt;&amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
      &amp;lt;/value&amp;gt;&lt;br /&gt;
  &amp;lt;/operations&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If ExampleDef were already gone, MyBetterExample would not get added.&lt;br /&gt;
&lt;br /&gt;
===PatchOperationTest===&lt;br /&gt;
''PatchOperationTest'' tests for the existence/validity of an xpath. Useful to stop a PatchOperationSequence. Often used as a simpler, less powerful version of PatchOperationConditional.&lt;br /&gt;
The following example patch is from Apparello, by Shinzy. &lt;br /&gt;
&amp;lt;source lang =&amp;quot;xml&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationSequence&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;!-- check for worn graphics and if none found, add one --&amp;gt;&lt;br /&gt;
    &amp;lt;success&amp;gt;Always&amp;lt;/success&amp;gt;&lt;br /&gt;
    &amp;lt;operations&amp;gt;&lt;br /&gt;
        &amp;lt;li Class=&amp;quot;PatchOperationTest&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;xpath&amp;gt;/Defs/ThingDef[defName = &amp;quot;Apparel_Pants&amp;quot;]/apparel/wornGraphicPath&amp;lt;/xpath&amp;gt;&lt;br /&gt;
            &amp;lt;success&amp;gt;Invert&amp;lt;/success&amp;gt;&lt;br /&gt;
        &amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;li Class=&amp;quot;PatchOperationAdd&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;xpath&amp;gt;/Defs/ThingDef[defName = &amp;quot;Apparel_Pants&amp;quot;]/apparel&amp;lt;/xpath&amp;gt;&lt;br /&gt;
            &amp;lt;value&amp;gt;&lt;br /&gt;
                &amp;lt;wornGraphicPath&amp;gt;Accessorello/Pants/Pants&amp;lt;/wornGraphicPath&amp;gt;&lt;br /&gt;
            &amp;lt;/value&amp;gt;&lt;br /&gt;
        &amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;/operations&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===PatchOperationConditional===&lt;br /&gt;
''PatchOperationConditional'' can branch logic based on a match/nomatch. The following example patch adds a &amp;lt;comps&amp;gt; node if it does not yet exist, and adds itself &lt;br /&gt;
&lt;br /&gt;
This patch is courtesy Mehni. [https://github.com/Mehni/MoreFactionInteraction/blob/ab3ab2a22ee529ee4e38a471fe150fd48fd07ce9/Patches/MoreFactionInteraction.xml#L40-L62 See original.]&lt;br /&gt;
&amp;lt;source lang =&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!-- Add /comps/li/compClass if there are no comps yet. --&amp;gt;&lt;br /&gt;
&amp;lt;!-- Add /li/compClass to /comps if exists (i.e. other mod already added the comps field first) --&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationConditional&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;/Defs/WorldObjectDef[defName=&amp;quot;Caravan&amp;quot;]/comps&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;nomatch Class=&amp;quot;PatchOperationAdd&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;xpath&amp;gt;/Defs/WorldObjectDef[defName=&amp;quot;Caravan&amp;quot;]&amp;lt;/xpath&amp;gt;&lt;br /&gt;
        &amp;lt;value&amp;gt;&lt;br /&gt;
            &amp;lt;comps&amp;gt;&lt;br /&gt;
                &amp;lt;li&amp;gt;&lt;br /&gt;
                    &amp;lt;compClass&amp;gt;MoreFactionInteraction.WorldObjectComp_CaravanComp&amp;lt;/compClass&amp;gt;&lt;br /&gt;
                &amp;lt;/li&amp;gt;&lt;br /&gt;
            &amp;lt;/comps&amp;gt;&lt;br /&gt;
        &amp;lt;/value&amp;gt;&lt;br /&gt;
    &amp;lt;/nomatch&amp;gt;&lt;br /&gt;
    &amp;lt;match Class=&amp;quot;PatchOperationAdd&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;xpath&amp;gt;/Defs/WorldObjectDef[defName=&amp;quot;Caravan&amp;quot;]/comps&amp;lt;/xpath&amp;gt;&lt;br /&gt;
        &amp;lt;value&amp;gt;&lt;br /&gt;
            &amp;lt;li&amp;gt;&lt;br /&gt;
                &amp;lt;compClass&amp;gt;MoreFactionInteraction.WorldObjectComp_CaravanComp&amp;lt;/compClass&amp;gt;&lt;br /&gt;
            &amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;/value&amp;gt;&lt;br /&gt;
    &amp;lt;/match&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===PatchOperationFindMod===&lt;br /&gt;
''PatchOperationFindMod'' searches the list of active mods for the mods listed in &amp;lt;nowiki&amp;gt;&amp;lt;li&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/nowiki&amp;gt; tags.&lt;br /&gt;
&lt;br /&gt;
For a successful match, &amp;lt;nowiki&amp;gt;&amp;lt;li&amp;gt;ModName&amp;lt;/li&amp;gt;&amp;lt;/nowiki&amp;gt; has to match the &amp;lt;name&amp;gt;ModName&amp;lt;/name&amp;gt; in the About.xml of the mod you base your patch behaviour on. It only needs to find ''one'' of the mods in the list for a successful match.&lt;br /&gt;
This (shortened) patch is courtesy Mehni. [https://github.com/Mehni/MoreFactionInteraction/blob/ab3ab2a22ee529ee4e38a471fe150fd48fd07ce9/Patches/MoreFactionInteraction.xml#L64 See original.]&lt;br /&gt;
&lt;br /&gt;
The following Patch adds the RimQuest mod extension to the listed Defs when RimQuest is found.&lt;br /&gt;
&amp;lt;source lang =&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationFindMod&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;mods&amp;gt;&lt;br /&gt;
        &amp;lt;li&amp;gt;RimQuest&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;/mods&amp;gt;&lt;br /&gt;
    &amp;lt;match Class=&amp;quot;PatchOperationAddModExtension&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;xpath&amp;gt;/Defs/IncidentDef[defName=&amp;quot;MFI_DiplomaticMarriage&amp;quot; or defName=&amp;quot;MFI_HuntersLodge&amp;quot; or defName=&amp;quot;MFI_Quest_PeaceTalks&amp;quot;]&amp;lt;/xpath&amp;gt;&lt;br /&gt;
        &amp;lt;value&amp;gt;&lt;br /&gt;
            &amp;lt;li Class = &amp;quot;RimQuest.RimQuest_ModExtension&amp;quot;&amp;gt;&lt;br /&gt;
                &amp;lt;canBeARimQuest&amp;gt;false&amp;lt;/canBeARimQuest&amp;gt;&lt;br /&gt;
            &amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;/value&amp;gt;&lt;br /&gt;
    &amp;lt;/match&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following Patch replace the tabWindowClass of the xpath when Relations Tab is '''not''' found. &lt;br /&gt;
&amp;lt;source lang =&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationFindMod&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;mods&amp;gt;&lt;br /&gt;
        &amp;lt;li&amp;gt;Relations Tab&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;/mods&amp;gt;&lt;br /&gt;
    &amp;lt;nomatch Class=&amp;quot;PatchOperationReplace&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;xpath&amp;gt;/Defs/MainButtonDef[defName=&amp;quot;Factions&amp;quot;]/tabWindowClass&amp;lt;/xpath&amp;gt;&lt;br /&gt;
        &amp;lt;value&amp;gt;&lt;br /&gt;
            &amp;lt;tabWindowClass&amp;gt;MyNameSpace.MyTabWindowClass&amp;lt;/tabWindowClass&amp;gt;&lt;br /&gt;
        &amp;lt;/value&amp;gt;&lt;br /&gt;
    &amp;lt;/nomatch&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Common issues==&lt;br /&gt;
Spelling matters, and XPath is case sensitive. It's ''very'' case sensitive. If you've written something that doesn't work but you're convinced it should, put it through some XPath validator. Case sensitivity includes but is not limited to the &amp;lt;Operation Class=&amp;quot;PatchOperationWhatever&amp;quot;&amp;gt;, the XPath, the value, every tag -- spell it right.&lt;br /&gt;
&lt;br /&gt;
Another common issue is swapping Insert and Add, which leads to a different position in the node. A common misconception is trying to account for file paths. The file path is completely irrelevant to the expression you're writing. XPath is used to search XML content, not files themselves.&lt;br /&gt;
&lt;br /&gt;
Still beating your head against a wall? The main RimWorld [https://discord.gg/RimWorld discord] has helpful people and a bot where you can test XPath, and the forums have a [https://ludeon.com/forums/index.php?board=14.0 help] section as well.&lt;br /&gt;
&lt;br /&gt;
==Some advanced examples==&lt;br /&gt;
This (shortened) patch is courtesy XeoNovaDan. [https://github.com/XeoNovaDan/SurvivalTools/blob/62a4316c81733dde417257bf4bc5c34e3e781c7d/Patches/ExpandedWoodworkingVGP/Patch.xml See original]. Viewer discretion is advised. Parents please take precautions if young children are present.&lt;br /&gt;
&amp;lt;source lang = &amp;quot;XML&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationFindMod&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;mods&amp;gt;&lt;br /&gt;
        &amp;lt;li&amp;gt;Expanded Woodworking for Vegetable Garden Project&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;/mods&amp;gt;&lt;br /&gt;
    &amp;lt;match Class=&amp;quot;PatchOperationSequence&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;success&amp;gt;Always&amp;lt;/success&amp;gt;&lt;br /&gt;
        &amp;lt;operations&amp;gt;&lt;br /&gt;
            &amp;lt;!-- Nested PatchOpFindMod. Used because Expanded Woodworking adds more Wood when VGP Xtra is installed. --&amp;gt;&lt;br /&gt;
            &amp;lt;li Class=&amp;quot;PatchOperationFindMod&amp;quot;&amp;gt;&lt;br /&gt;
                &amp;lt;mods&amp;gt;&lt;br /&gt;
                    &amp;lt;li&amp;gt;VGP Xtra Trees and Flowers&amp;lt;/li&amp;gt;&lt;br /&gt;
                &amp;lt;/mods&amp;gt;&lt;br /&gt;
                &amp;lt;match Class=&amp;quot;PatchOperationSequence&amp;quot;&amp;gt;&lt;br /&gt;
                    &amp;lt;success&amp;gt;Always&amp;lt;/success&amp;gt;&lt;br /&gt;
                    &amp;lt;operations&amp;gt;&lt;br /&gt;
                        &amp;lt;!-- Processed camellia lumber. Mostly useful for building long-lasting, simple structures and furniture.--&amp;gt;&lt;br /&gt;
                        &amp;lt;li Class=&amp;quot;PatchOperationAddModExtension&amp;quot;&amp;gt;&lt;br /&gt;
                            &amp;lt;xpath&amp;gt;/Defs/ThingDef[defName=&amp;quot;LumberCamellia&amp;quot;]&amp;lt;/xpath&amp;gt;&lt;br /&gt;
                            &amp;lt;value&amp;gt;&lt;br /&gt;
                                &amp;lt;li Class=&amp;quot;SurvivalTools.StuffPropsTool&amp;quot;&amp;gt;&lt;br /&gt;
                                    &amp;lt;toolStatFactors&amp;gt;&lt;br /&gt;
                                        &amp;lt;ConstructionSpeed&amp;gt;0.55&amp;lt;/ConstructionSpeed&amp;gt;&lt;br /&gt;
                                    &amp;lt;/toolStatFactors&amp;gt;&lt;br /&gt;
                                &amp;lt;/li&amp;gt;&lt;br /&gt;
                            &amp;lt;/value&amp;gt;&lt;br /&gt;
                        &amp;lt;/li&amp;gt;&lt;br /&gt;
                    &amp;lt;/operations&amp;gt;&lt;br /&gt;
                &amp;lt;/match&amp;gt;&lt;br /&gt;
            &amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;/operations&amp;gt;&lt;br /&gt;
    &amp;lt;/match&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Random stuff===&lt;br /&gt;
* @ select by attribute. Useful for patching (Abstract) bases. &amp;lt;source lang = &amp;quot;xml&amp;quot;&amp;gt;/Defs/ThingDef[@Name=&amp;quot;BuildingBase&amp;quot;]&amp;lt;/source&amp;gt;&lt;br /&gt;
* ''or'' is inclusive. &amp;lt;source lang = &amp;quot;xml&amp;quot;&amp;gt;/Defs/ThingDef[defName=&amp;quot;Cassowary&amp;quot; or defName = &amp;quot;Emu&amp;quot; or defName = &amp;quot;Ostrich&amp;quot; or defName = &amp;quot;Turkey&amp;quot;]&amp;lt;/source&amp;gt; selects all of those in a single (faster) operation.&lt;br /&gt;
* PatchOperationAdd and PatchOperationInsert have an ''order'' tag which allows you to either Prepend or Append your add. Default behaviour of Add is to Append, insert Prepends.&lt;br /&gt;
* There is a ''success'' tag whose values can be Normal, Invert, Always and Never. This is used for the sake of error reporting: by default an error is logged when a patch fails to apply. For PatchOperationSequences and PatchOperationTests, you can set success to Always to avoid error logging.&lt;br /&gt;
* More useful things:&lt;br /&gt;
** Select nodes by text &amp;lt;source lang = &amp;quot;xml&amp;quot;&amp;gt;ExampleTag/li[text()=&amp;quot;Submit&amp;quot;]&amp;lt;/source&amp;gt;&lt;br /&gt;
** Select nodes by text with a type of wildcard &amp;lt;source lang = &amp;quot;xml&amp;quot;&amp;gt;ExampleTag[contains(text(), &amp;quot;MFI_&amp;quot;)]&amp;lt;/source&amp;gt;&lt;br /&gt;
** Exclude nodes with not() &amp;lt;source lang = &amp;quot;xml&amp;quot;&amp;gt;[not(xxxxx)]&amp;lt;/source&amp;gt;&lt;br /&gt;
** Can't think of an example but I'm sure someone will find a use for &amp;lt;source lang = &amp;quot;xml&amp;quot;&amp;gt;[count(li)]&amp;lt;/source&amp;gt;&lt;br /&gt;
** Go back to parentnode with &amp;lt;source lang = &amp;quot;xml&amp;quot;&amp;gt;..&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Write your own ==&lt;br /&gt;
Outside the scope of this wiki, but it's possible to write your own PatchOperation.&amp;lt;/br&amp;gt;&lt;br /&gt;
- [https://github.com/NoImageAvailable/CombatExtended/blob/88ef1f86d30e6c285e3370bd9faafa92c84195b0/Source/CombatExtended/CombatExtended/PatchOperationMakeGunCECompatible.cs Example PatchOperationMakeGunCECompatible]&amp;lt;/br&amp;gt;&lt;br /&gt;
- [https://gist.github.com/Lanilor/e326e33e268e78f68a2f5cd3cdbbe8c0 Example PatchOperationAddOrReplace]&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Resources ==&lt;br /&gt;
&lt;br /&gt;
The best tutorial on PatchOperations created by Zhentar: [https://gist.github.com/Zhentar/4a1b71cea45b9337f70b30a21d868782 Introduction to PatchOperation]&lt;br /&gt;
&lt;br /&gt;
You can also learn about XPaths here: [https://www.w3schools.com/xml/xpath_intro.asp XPath tutorial]&lt;br /&gt;
&lt;br /&gt;
There is also an [https://github.com/roxxploxx/RimWorldModGuide/wiki/SHORTTUTORIAL:-DefPatches Overview of PatchOperations]  on the [https://github.com/roxxploxx/RimWorldModGuide/wiki RimWorldModGuide].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Modding]]&lt;br /&gt;
[[Category:Modding tutorials]]&lt;/div&gt;</summary>
		<author><name>Lilwhitemouse</name></author>
	</entry>
	<entry>
		<id>https://rimworldwiki.com/index.php?title=Modding_Tutorials/Hello_World&amp;diff=66390</id>
		<title>Modding Tutorials/Hello World</title>
		<link rel="alternate" type="text/html" href="https://rimworldwiki.com/index.php?title=Modding_Tutorials/Hello_World&amp;diff=66390"/>
		<updated>2019-08-11T05:33:01Z</updated>

		<summary type="html">&lt;p&gt;Lilwhitemouse: /* But why can't I make my StaticConstructorOnStartup inherit from mod? */  Resent research: two condoms not working is a bit of a myth?&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{BackToTutorials}}&lt;br /&gt;
&lt;br /&gt;
In this tutorial you will learn how to make a mod that runs on startup and writes &amp;quot;Hello World&amp;quot; to the dev console.&lt;br /&gt;
&lt;br /&gt;
=Requirements=&lt;br /&gt;
* This tutorial requires you to have [[Modding Tutorials/Setting up a solution|set up a solution]].&lt;br /&gt;
* This tutorial requires a Mod folder (here called: MyMod) and the mod folder will need an About folder containing a valid About.xml and an Assemblies folder where we will put our HelloWorld.dll file. For more info, see [[Modding_Tutorials/Mod_folder_structure | Mod folder structure]]&lt;br /&gt;
&lt;br /&gt;
=Bootstrapping=&lt;br /&gt;
There are two acceptable ways of making RimWorld load your mod. One is by using the StaticConstructorOnStartup annotation, the other is by inheriting from the Mod class. We will be using the StaticConstructorOnStartup annotation, for reasons explained below.&lt;br /&gt;
&lt;br /&gt;
=Hello World=&lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
using RimWorld;&lt;br /&gt;
using Verse;&lt;br /&gt;
&lt;br /&gt;
namespace TestMod&lt;br /&gt;
{&lt;br /&gt;
    [StaticConstructorOnStartup]&lt;br /&gt;
    public static class MyMod&lt;br /&gt;
    {&lt;br /&gt;
        static MyMod() //our constructor&lt;br /&gt;
        {&lt;br /&gt;
            Log.Message(&amp;quot;Hello World!&amp;quot;); //Outputs &amp;quot;Hello World!&amp;quot; to the dev console.&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
* The [StaticConstructorOnStartup] annotation does what it says on the tin. At startup, it runs the Static Constructor of any class with that annotation. For a thorough explanation of what a static constructor is, refer to [https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/static-constructors official C# documentation.] What you need to know: It's a method without a return type, has the same name as the class and doesn't take any arguments.&lt;br /&gt;
&lt;br /&gt;
=Common pitfalls=&lt;br /&gt;
* Your constructor isn't static.&lt;br /&gt;
* Your constructor isn't a constructor. Refer once more to the [https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/static-constructors official C# documentation.]&lt;br /&gt;
* There are red squiggles under [StaticConstructorOnStartup] (or anywhere else): you either typo'd, are missing ''using'' statements or don't have a reference to ''Assembly-Csharp.dll''. Read how to [[Modding Tutorials/Setting up a solution|set up a solution]] again.&lt;br /&gt;
* You did not compile, and if you did compile, your IDE placed the resulting assembly in some far away folder. Set the output path of your build to something more sane. Read how to [[Modding Tutorials/Setting up a solution|set up a solution]] again.&lt;br /&gt;
* There are lot of yellow errors along the line of &amp;quot;x already has short hash&amp;quot;: You did not set &amp;quot;Copy local&amp;quot; to false. Read how to [[Modding Tutorials/Setting up a solution|set up a solution]] again.&lt;br /&gt;
&lt;br /&gt;
=StaticConstructorOnStartup vs inheriting from Mod=&lt;br /&gt;
Subclasses of the Mod class are loaded extremely early during launch. As such, it is less suitable for most purposes (most notably: using Defs or anything that uses Defs). Classes with the StaticConstructorOnStartup are initialised just before the Main Menu is shown. Classes with this annotation are loaded in the main thread: a requirement for loading any Texture, Material, Shader, Graphic, GameObject or MaterialPropertyBlock.&lt;br /&gt;
&lt;br /&gt;
Inheriting from Mod is necessary if you want [[Modding Tutorials/ModSettings|Mod Settings]], or if you need to run really early in the loading process.&lt;br /&gt;
&lt;br /&gt;
For the exact order of initialisation, look up Verse.PlayDataLoader.DoPlayLoad.&lt;br /&gt;
&lt;br /&gt;
==But why can't I make my StaticConstructorOnStartup inherit from mod?==&lt;br /&gt;
That's like wearing two condoms. You might think you're extra safe, in reality it puts you in a worse position.  Okay, two condoms might actually be safe enough, but you can't both inherit from the mod and expect the StaticConstructorOnStartup to work.&lt;br /&gt;
&lt;br /&gt;
When C# tries to instantiate a type (like your Mod class) for the very first time, it first runs the static constructor and then an instance constructor. The static constructor in this case is the StaticConstructorOnStartup: meaning it'll try to load your textures outside the main thread and run your Harmony patches using Defs the game doesn't know exist yet. Subsequent new instances of your Mod class will not have their static constructor called again: they run once and only once. Likewise, if the StaticConstructorOnStartup then tries to call the static constructor again, nothing will happen as the static constructor already ran once.&lt;br /&gt;
&lt;br /&gt;
Sometimes you need both a StaticConstructorOnStartup and a class that inherits from Mod. The correct way of doing that is by making two separate classes; one that inherits from Mod and the other with a StaticConstructorOnStartup attribute.&lt;br /&gt;
&lt;br /&gt;
[[Category: Modding]]&lt;br /&gt;
[[Category: Modding tutorials]]&lt;/div&gt;</summary>
		<author><name>Lilwhitemouse</name></author>
	</entry>
	<entry>
		<id>https://rimworldwiki.com/index.php?title=Modding_Tutorials/Harmony&amp;diff=66389</id>
		<title>Modding Tutorials/Harmony</title>
		<link rel="alternate" type="text/html" href="https://rimworldwiki.com/index.php?title=Modding_Tutorials/Harmony&amp;diff=66389"/>
		<updated>2019-08-11T05:17:21Z</updated>

		<summary type="html">&lt;p&gt;Lilwhitemouse: /* Bootstrapping */ It's &amp;quot;Startup&amp;quot; not &amp;quot;StartUp&amp;quot; - big difference, very important.  Easy to miss.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{BackToTutorials}}&lt;br /&gt;
&lt;br /&gt;
'''[http://rimworldwiki.com/index.php?title=Modding_Tutorials/Injection&amp;amp;action=edit&amp;amp;redlink=1 Harmony] - A library for patching, replacing and decorating .NET and Mono methods during runtime'''&lt;br /&gt;
&lt;br /&gt;
Harmony is the current best practice for changing the runtime execution of code in RimWorld.&lt;br /&gt;
&lt;br /&gt;
To integrate Harmony into your mod for use, download the latest stable release and add it as a reference to your C# project. Make sure that you also include the dll, (0Harmony.dll) in your mod's assemblies folder. Please DO NOT use HugsLib for an &amp;quot;easy&amp;quot; Harmony implementation due to the fact that HugsLib becomes an unnecessary and unutilized dependency for mods and beginners grow accustomed to using HugsLib in all their mods even if they never touch HugsLib's API in their code. This is a bad practice, especially for beginners new to RimWorld Modding. Please only use HugsLib when you want to utilize some of its features!&lt;br /&gt;
&lt;br /&gt;
Harmony is great for running code patches before (Prefix) or after (Postfix) an existing method. Usually this is all you need for your Mod. Because this does not change existing functionality of RimWorld, it MOST LIKELY does not impact other mods and runs in parallel with other Harmony patches.&lt;br /&gt;
&lt;br /&gt;
''The snippets on this page are not meant as an exhaustive document on all things Harmony. Refer to the original documentation.'' This article is mostly a &amp;quot;this is what you can do&amp;quot; summary in 5 minutes.&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
* If you still haven't [[Modding_Tutorials/Setting up a solution|set up a solution]], you're not ready for Harmony.&lt;br /&gt;
* You need to be able to write a [[Modding_Tutorials/Hello World|Hello World]] program.&lt;br /&gt;
* You don't need to know the inner workings of JIT-compilation, reflection and inlining, but a basic understanding of C# and/or programming in general is assumed in this article.&lt;br /&gt;
&lt;br /&gt;
==Summary==&lt;br /&gt;
Harmony can alter the workings of any method. It offers three ways of doing this: prefixes, postfixes, and transpilers.&lt;br /&gt;
&lt;br /&gt;
===Prefix===&lt;br /&gt;
A prefix is a method that runs before the original method. It can have a return type of void or bool. If a bool returns false, the original method is skipped. This will cause compatibility issues if you're not very careful. This type of prefix may also prevent other prefixes from running.&lt;br /&gt;
&lt;br /&gt;
===Postfix===&lt;br /&gt;
A postfix is a method that runs after the original method. They are guaranteed to run. Postfixes can also alter the result. Use these for greatest compatibility.&lt;br /&gt;
&lt;br /&gt;
===Transpilers===&lt;br /&gt;
A transpiler is a set of CodeInstructions. These alter the inner working of the method. They use low-level IL-code, from System.Reflection and System.Reflection.Emit. Refer to MSDN and Harmony documentation for more info. Transpilers are difficult to debug and therefor hard to create/maintain/update.&lt;br /&gt;
&lt;br /&gt;
If you must use a transpiler, you might find useful notes [[Modding_Tutorials/Transpiler Hints|here]].&lt;br /&gt;
&lt;br /&gt;
==Altering the result==&lt;br /&gt;
If the original method has a return type, you can alter its ''__result'' by passing it by ''ref''.&lt;br /&gt;
&lt;br /&gt;
==Pitfalls==&lt;br /&gt;
===Overuse===&lt;br /&gt;
Harmony is a fantastic tool, that you'll soon want to use for everything. Before you do that, consider the alternatives. Can you subclass? Can you use a ThingComp? A MapComponent? There may be viable alternatives without the added dependency.&lt;br /&gt;
===Not changing the result?===&lt;br /&gt;
Forgot to pass by ref.&lt;br /&gt;
===How do I return a value from a void or prefix?===&lt;br /&gt;
That's the magic. Harmony disconnects its own return type from the return type of the original method. Consider the following destructive prefix, which gives everyone perfect knowledge of trap locations:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
	[HarmonyPatch(typeof(Building_Trap))]&lt;br /&gt;
	[HarmonyPatch(nameof(Building_Trap.KnowsOfTrap)] //annotation boiler plate to tell Harmony what to patch. Refer to docs.&lt;br /&gt;
	static class Building_Trap_KnowsOfTrap_Patch&lt;br /&gt;
	{&lt;br /&gt;
		static bool Prefix(ref bool __result) //pass the __result by ref to alter it.&lt;br /&gt;
		{&lt;br /&gt;
			__result = true; //alter the result.&lt;br /&gt;
			return false; //return false to skip execution of the original.&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
===Getting the right method to patch===&lt;br /&gt;
'''AccessTools''' is a nice wrapper for reflection. The most reliable way of specifying the method to patch is by providing the Patch() method with MethodInfo. Standard System.Reflection also works. You will need to specify arguments for overloaded methods.&lt;br /&gt;
===Doesn't seem to get patched?===&lt;br /&gt;
Does your Log.Message() not show up? Set HarmonyInstance.DEBUG = true and check the new .txt file Harmony placed on your desktop. If you are trying to patch something that runs during game loading, you [[Modding_Tutorials/Hello_World#StaticConstructorOnStartup_vs_inheriting_from_Mod| may need to bootstrap differently]]. Are you doing everything right? If the method you're patching is small, it may have been [https://en.wikipedia.org/wiki/Inline_expansion inlined.]&lt;br /&gt;
&lt;br /&gt;
==Bootstrapping==&lt;br /&gt;
Remember the [[Modding Tutorials/Hello World|Hello World]] tutorial? The [StaticConstructorOnStartup] is a perfect starting point. Create your harmony instance in there, and use it to call PatchAll() or do your manual patching.&lt;br /&gt;
&lt;br /&gt;
== Links == &lt;br /&gt;
&lt;br /&gt;
[https://github.com/pardeike/Harmony/releases Harmony's Releases] - Link to Harmony's latest release(s) for download.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/pardeike/Harmony/wiki Harmony's Wiki] - General outline of how to use Harmony&lt;br /&gt;
&lt;br /&gt;
[https://github.com/roxxploxx/RimWorldModGuide/wiki/SHORTTUTORIAL%3A-Harmony RimWorldModGuide on Harmony] - gives some concrete examples and helpful explanations&lt;br /&gt;
&lt;br /&gt;
[https://gist.github.com/pardeike/c02e29f9e030e6a016422ca8a89eefc9 Harmony's Author's Transpiler tutorial] - Tutorial and example of using Harmony Transpiler, with helpful links (inject your code inside a RimWorld class's code - #DeepMagic)&lt;br /&gt;
&lt;br /&gt;
[https://ludeon.com/forums/index.php?topic=29517 Harmony Thread] - Harmony thread on Ludeon Studio's Forum.  Announcements of new versions, and the forum in general is a reasonable place to ask questions.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/RimWorld-CCL-Reborn/AlienRaces/blob/master/Source/AlienRace/AlienRace/HarmonyPatches.cs Alien races] - The unofficial Harmony encyclopedia. Dozens, if not hundreds of patches for all your cargo cult programming needs.&lt;/div&gt;</summary>
		<author><name>Lilwhitemouse</name></author>
	</entry>
	<entry>
		<id>https://rimworldwiki.com/index.php?title=Modding_Tutorials/Harmony&amp;diff=65685</id>
		<title>Modding Tutorials/Harmony</title>
		<link rel="alternate" type="text/html" href="https://rimworldwiki.com/index.php?title=Modding_Tutorials/Harmony&amp;diff=65685"/>
		<updated>2019-07-16T03:08:03Z</updated>

		<summary type="html">&lt;p&gt;Lilwhitemouse: /* Doesn't seem to get patched? */ added &amp;quot;to&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{BackToTutorials}}&lt;br /&gt;
&lt;br /&gt;
'''[http://rimworldwiki.com/index.php?title=Modding_Tutorials/Injection&amp;amp;action=edit&amp;amp;redlink=1 Harmony] - A library for patching, replacing and decorating .NET and Mono methods during runtime'''&lt;br /&gt;
&lt;br /&gt;
Harmony is the current best practice for changing the runtime execution of code in RimWorld.&lt;br /&gt;
&lt;br /&gt;
To integrate Harmony into your mod for use, download the latest stable release and add it as a reference to your C# project. Make sure that you also include the dll, (0Harmony.dll) in your mod's assemblies folder. Please DO NOT use HugsLib for an &amp;quot;easy&amp;quot; Harmony implementation due to the fact that HugsLib becomes an unnecessary and unutilized dependency for mods and beginners grow accustomed to using HugsLib in all their mods even if they never touch HugsLib's API in their code. This is a bad practice, especially for beginners new to RimWorld Modding. Please only use HugsLib when you want to utilize some of its features!&lt;br /&gt;
&lt;br /&gt;
Harmony is great for running code patches before (Prefix) or after (Postfix) an existing method. Usually this is all you need for your Mod. Because this does not change existing functionality of RimWorld, it MOST LIKELY does not impact other mods and runs in parallel with other Harmony patches.&lt;br /&gt;
&lt;br /&gt;
''The snippets on this page are not meant as an exhaustive document on all things Harmony. Refer to the original documentation.'' This article is mostly a &amp;quot;this is what you can do&amp;quot; summary in 5 minutes.&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
* If you still haven't [[Modding_Tutorials/Setting up a solution|set up a solution]], you're not ready for Harmony.&lt;br /&gt;
* You need to be able to write a [[Modding_Tutorials/Hello World|Hello World]] program.&lt;br /&gt;
* You don't need to know the inner workings of JIT-compilation, reflection and inlining, but a basic understanding of C# and/or programming in general is assumed in this article.&lt;br /&gt;
&lt;br /&gt;
==Summary==&lt;br /&gt;
Harmony can alter the workings of any method. It offers three ways of doing this: prefixes, postfixes, and transpilers.&lt;br /&gt;
&lt;br /&gt;
===Prefix===&lt;br /&gt;
A prefix is a method that runs before the original method. It can have a return type of void or bool. If a bool returns false, the original method is skipped. This will cause compatibility issues if you're not very careful. This type of prefix may also prevent other prefixes from running.&lt;br /&gt;
&lt;br /&gt;
===Postfix===&lt;br /&gt;
A postfix is a method that runs after the original method. They are guaranteed to run. Postfixes can also alter the result. Use these for greatest compatibility.&lt;br /&gt;
&lt;br /&gt;
===Transpilers===&lt;br /&gt;
A transpiler is a set of CodeInstructions. These alter the inner working of the method. They use low-level IL-code, from System.Reflection and System.Reflection.Emit. Refer to MSDN and Harmony documentation for more info. Transpilers are difficult to debug and therefor hard to create/maintain/update.&lt;br /&gt;
&lt;br /&gt;
If you must use a transpiler, you might find useful notes [[Modding_Tutorials/Transpiler Hints|here]].&lt;br /&gt;
&lt;br /&gt;
==Altering the result==&lt;br /&gt;
If the original method has a return type, you can alter its ''__result'' by passing it by ''ref''.&lt;br /&gt;
&lt;br /&gt;
==Pitfalls==&lt;br /&gt;
===Overuse===&lt;br /&gt;
Harmony is a fantastic tool, that you'll soon want to use for everything. Before you do that, consider the alternatives. Can you subclass? Can you use a ThingComp? A MapComponent? There may be viable alternatives without the added dependency.&lt;br /&gt;
===Not changing the result?===&lt;br /&gt;
Forgot to pass by ref.&lt;br /&gt;
===How do I return a value from a void or prefix?===&lt;br /&gt;
That's the magic. Harmony disconnects its own return type from the return type of the original method. Consider the following destructive prefix, which gives everyone perfect knowledge of trap locations:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
	[HarmonyPatch(typeof(Building_Trap))]&lt;br /&gt;
	[HarmonyPatch(nameof(Building_Trap.KnowsOfTrap)] //annotation boiler plate to tell Harmony what to patch. Refer to docs.&lt;br /&gt;
	static class Building_Trap_KnowsOfTrap_Patch&lt;br /&gt;
	{&lt;br /&gt;
		static bool Prefix(ref bool __result) //pass the __result by ref to alter it.&lt;br /&gt;
		{&lt;br /&gt;
			__result = true; //alter the result.&lt;br /&gt;
			return false; //return false to skip execution of the original.&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
===Getting the right method to patch===&lt;br /&gt;
'''AccessTools''' is a nice wrapper for reflection. The most reliable way of specifying the method to patch is by providing the Patch() method with MethodInfo. Standard System.Reflection also works. You will need to specify arguments for overloaded methods.&lt;br /&gt;
===Doesn't seem to get patched?===&lt;br /&gt;
Does your Log.Message() not show up? Set HarmonyInstance.DEBUG = true and check the new .txt file Harmony placed on your desktop. If you are trying to patch something that runs during game loading, you [[Modding_Tutorials/Hello_World#StaticConstructorOnStartup_vs_inheriting_from_Mod| may need to bootstrap differently]]. Are you doing everything right? If the method you're patching is small, it may have been [https://en.wikipedia.org/wiki/Inline_expansion inlined.]&lt;br /&gt;
&lt;br /&gt;
==Bootstrapping==&lt;br /&gt;
Remember the [[Modding Tutorials/Hello World|Hello World]] tutorial? The [StaticConstructorOnStartUp] is a perfect starting point. Create your harmony instance in there, and use it to call PatchAll() or do your manual patching.&lt;br /&gt;
&lt;br /&gt;
== Links == &lt;br /&gt;
&lt;br /&gt;
[https://github.com/pardeike/Harmony/releases Harmony's Releases] - Link to Harmony's latest release(s) for download.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/pardeike/Harmony/wiki Harmony's Wiki] - General outline of how to use Harmony&lt;br /&gt;
&lt;br /&gt;
[https://github.com/roxxploxx/RimWorldModGuide/wiki/SHORTTUTORIAL%3A-Harmony RimWorldModGuide on Harmony] - gives some concrete examples and helpful explanations&lt;br /&gt;
&lt;br /&gt;
[https://gist.github.com/pardeike/c02e29f9e030e6a016422ca8a89eefc9 Harmony's Author's Transpiler tutorial] - Tutorial and example of using Harmony Transpiler, with helpful links (inject your code inside a RimWorld class's code - #DeepMagic)&lt;br /&gt;
&lt;br /&gt;
[https://ludeon.com/forums/index.php?topic=29517 Harmony Thread] - Harmony thread on Ludeon Studio's Forum.  Announcements of new versions, and the forum in general is a reasonable place to ask questions.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/RimWorld-CCL-Reborn/AlienRaces/blob/master/Source/AlienRace/AlienRace/HarmonyPatches.cs Alien races] - The unofficial Harmony encyclopedia. Dozens, if not hundreds of patches for all your cargo cult programming needs.&lt;/div&gt;</summary>
		<author><name>Lilwhitemouse</name></author>
	</entry>
	<entry>
		<id>https://rimworldwiki.com/index.php?title=Topic:V2wkppkulu3vltal&amp;topic_postId=v33xqjlhkivnkjgt&amp;topic_revId=v33xqjlhkivnkjgt&amp;action=single-view</id>
		<title>Topic:V2wkppkulu3vltal</title>
		<link rel="alternate" type="text/html" href="https://rimworldwiki.com/index.php?title=Topic:V2wkppkulu3vltal&amp;topic_postId=v33xqjlhkivnkjgt&amp;topic_revId=v33xqjlhkivnkjgt&amp;action=single-view"/>
		<updated>2019-07-08T15:27:31Z</updated>

		<summary type="html">&lt;span class=&quot;plainlinks&quot;&gt;&lt;a href=&quot;/index.php?title=User:Lilwhitemouse&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new mw-userlink&quot; title=&quot;User:Lilwhitemouse (page does not exist)&quot;&gt;&lt;bdi&gt;Lilwhitemouse&lt;/bdi&gt;&lt;/a&gt; &lt;span class=&quot;mw-usertoollinks&quot;&gt;(&lt;a href=&quot;/index.php?title=User_talk:Lilwhitemouse&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new mw-usertoollinks-talk&quot; title=&quot;User talk:Lilwhitemouse (page does not exist)&quot;&gt;talk&lt;/a&gt; | &lt;a href=&quot;/wiki/Special:Contributions/Lilwhitemouse&quot; class=&quot;mw-usertoollinks-contribs&quot; title=&quot;Special:Contributions/Lilwhitemouse&quot;&gt;contribs&lt;/a&gt;)&lt;/span&gt; &lt;a rel=&quot;nofollow&quot; class=&quot;external text&quot; href=&quot;https://rimworldwiki.com/index.php?title=Topic:V2wkppkulu3vltal&amp;amp;topic_showPostId=v33xqjlhkivnkjgt#flow-post-v33xqjlhkivnkjgt&quot;&gt;commented&lt;/a&gt; on &quot;Logging hint&quot; (&lt;em&gt;As some ppl say here in the south, harmony.what now? I&amp;#039;m not familiar with what harmony.DEBUG does is the advantage - there&amp;#039;s no document...&lt;/em&gt;)&lt;/span&gt;</summary>
		<author><name>Lilwhitemouse</name></author>
	</entry>
	<entry>
		<id>https://rimworldwiki.com/index.php?title=Modding_Tutorials/Linking_XML_and_C&amp;diff=64036</id>
		<title>Modding Tutorials/Linking XML and C</title>
		<link rel="alternate" type="text/html" href="https://rimworldwiki.com/index.php?title=Modding_Tutorials/Linking_XML_and_C&amp;diff=64036"/>
		<updated>2019-07-03T05:30:04Z</updated>

		<summary type="html">&lt;p&gt;Lilwhitemouse: /* DefDatabase */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{BackToTutorials}}&lt;br /&gt;
&lt;br /&gt;
[[Modding Tutorials/Writing custom code|Writing custom code]] is all well and good if you can't force RimWorld to use it! Here are three ways of linking your Code to the XML and vice versa.&lt;br /&gt;
&lt;br /&gt;
=Using your C# from XML=&lt;br /&gt;
==A classy design pattern==&lt;br /&gt;
RimWorld leans heavily on Object Oriented Programming and will often expose the specific class of a Def to the XML. They're often called a workerClass, thingClass, but obviously can be named anything. Keep a look out for these, they're sometimes subtle.&lt;br /&gt;
&lt;br /&gt;
===Examples===&lt;br /&gt;
&amp;lt;source lang =&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;BiomeDef&amp;gt;&lt;br /&gt;
  &amp;lt;defName&amp;gt;BorealForest&amp;lt;/defName&amp;gt;&lt;br /&gt;
  &amp;lt;workerClass&amp;gt;BiomeWorker_BorealForest&amp;lt;/workerClass&amp;gt;&lt;br /&gt;
&amp;lt;/BiomeDef&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang =&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;inspectorTabs&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt;ITab_Art&amp;lt;/li&amp;gt;&amp;lt;!-- That's a class! --&amp;gt;&lt;br /&gt;
&amp;lt;/inspectorTabs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==A &amp;quot;Classy&amp;quot; pattern==&lt;br /&gt;
It is possible to overwrite the default class associated with a Def (or field in a def) by specifying the Class by attribute. The most common usage of this you've undoubtedly seen before is in Components: &amp;lt;source lang = &amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;comps&amp;gt;&lt;br /&gt;
  &amp;lt;li Class=&amp;quot;CompProperties_Forbiddable&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/comps&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This class override is more widely applicable than just [[Modding Tutorials/Custom Comp Classes|comps]]. It's possible to overwrite or specify almost any type you wish. Keep [[Modding Tutorials/Compatibility|Compatibility]] in mind when doing this: in the end each object can only be one [[Modding Tutorials/Def classes|Class]].&lt;br /&gt;
&lt;br /&gt;
===Example===&lt;br /&gt;
&amp;lt;source lang =&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!-- Generate faction base --&amp;gt;&lt;br /&gt;
&amp;lt;GenStepDef Class = &amp;quot;MyNameSpace.MyCustomGenStepDefClass&amp;quot;&amp;gt; &amp;lt;!-- Overwrite the GenStepDef Class --&amp;gt;&lt;br /&gt;
  &amp;lt;defName&amp;gt;Settlement&amp;lt;/defName&amp;gt;&lt;br /&gt;
  &amp;lt;order&amp;gt;400&amp;lt;/order&amp;gt;&lt;br /&gt;
  &amp;lt;genStep Class=&amp;quot;GenStep_Settlement&amp;quot;&amp;gt; &amp;lt;!-- you can overwrite almost any type you wish. --&amp;gt;&lt;br /&gt;
    &amp;lt;count&amp;gt;1&amp;lt;/count&amp;gt;&lt;br /&gt;
    &amp;lt;nearMapCenter&amp;gt;true&amp;lt;/nearMapCenter&amp;gt;&lt;br /&gt;
  &amp;lt;/genStep&amp;gt;&lt;br /&gt;
  &amp;lt;modExtensions&amp;gt;&lt;br /&gt;
    &amp;lt;li Class=&amp;quot;MyNameSpace.MyCustomModExtension&amp;quot;&amp;gt; &amp;lt;!-- Aah, the classic li Class. --&amp;gt;&lt;br /&gt;
       &amp;lt;isACustomGenStepDefClassAndAModExtensionOverkill&amp;gt;false&amp;lt;/isACustomGenStepDefClassAndAModExtensionOverkill&amp;gt;&lt;br /&gt;
    &amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;/modExtensions&amp;gt;&lt;br /&gt;
&amp;lt;/GenStepDef&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==You define yourself==&lt;br /&gt;
Another possibility is to supply your own type in the XML. The most well-known example of this is [https://github.com/RimWorld-CCL-Reborn/AlienRaces/wiki/Let%27s-Start Alienraces]. The [https://github.com/RimWorld-CCL-Reborn/AlienRaces/blob/master/Source/AlienRace/AlienRace/ThingDef_AlienRace.cs ThingDef_AlienRace] inherits from regular [[Modding Tutorials/ThingDef|ThingDef]], and adds the alienRace tag to it. The alienRace tag then holds more information, a sample of which is shown below.&lt;br /&gt;
&lt;br /&gt;
One benefit of this over the annotation method above (the &amp;quot;Classy&amp;quot; pattern) is that the added control and restriction of scope is increased compatibility with over mods. It's theoretically also easier to further subclass the AlienRace def by annotation.&lt;br /&gt;
&lt;br /&gt;
===Example===&lt;br /&gt;
&amp;lt;source lang = &amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;AlienRace.ThingDef_AlienRace ParentName=&amp;quot;BasePawn&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;defName&amp;gt;ExampleAlien&amp;lt;/defName&amp;gt;&lt;br /&gt;
  &amp;lt;label&amp;gt;Alien for example&amp;lt;/label&amp;gt;&lt;br /&gt;
  &amp;lt;description&amp;gt;This alien is really special.. because it is used as an example&amp;lt;/description&amp;gt;&lt;br /&gt;
  &amp;lt;!-- regular ThingDef tags go here. --&amp;gt;&lt;br /&gt;
  &amp;lt;alienRace&amp;gt;&lt;br /&gt;
      &amp;lt;!-- specific alien stuff goes inside the alienRace tag. --&amp;gt;&lt;br /&gt;
      &amp;lt;generalSettings&amp;gt;&lt;br /&gt;
&lt;br /&gt;
      &amp;lt;/generalSettings&amp;gt;&lt;br /&gt;
      &amp;lt;raceRestriction&amp;gt;&lt;br /&gt;
&lt;br /&gt;
      &amp;lt;/raceRestriction&amp;gt;&lt;br /&gt;
  &amp;lt;/alienRace&amp;gt;&lt;br /&gt;
&amp;lt;/AlienRace.ThingDef_AlienRace&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Serialising custom classes==&lt;br /&gt;
It may sometimes be required to read/write your own datatype to XML. While we all love long strings with comma separated values, there are many cases where this is not a good idea. For that, RimWorld offers a ''LoadDataFromXmlCustom'' method. When RimWorld comes across your type during load, and the class defining that type contains the ''LoadDataFromXmlCustom'', RimWorld will use that method to parse the XML. This is done through the magic of reflection.&lt;br /&gt;
&lt;br /&gt;
Note that this method fails on types that can't have a constructor. In practice, this means you can't serialise [https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/structs structs].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang = &amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
//example taken from https://github.com/LocoNeko/RoadsOfTheRim/blob/master/Source/DefModExtension_RotR_RoadDef.cs&lt;br /&gt;
public class RotR_cost&lt;br /&gt;
{&lt;br /&gt;
    public string name;&lt;br /&gt;
    public int count;&lt;br /&gt;
&lt;br /&gt;
    public void LoadDataFromXmlCustom(XmlNode xmlRoot)&lt;br /&gt;
    {&lt;br /&gt;
        if (xmlRoot.ChildNodes.Count != 1)&lt;br /&gt;
        {&lt;br /&gt;
            Log.Error(&amp;quot;Misconfigured RotR_cost: &amp;quot; + xmlRoot.OuterXml, false);&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
        name = xmlRoot.Name;&lt;br /&gt;
        count = (int)ParseHelper.FromString(xmlRoot.FirstChild.Value, typeof(int));&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Common issues==&lt;br /&gt;
You need to specify your exact Namespace.Class. There are no two ways around it. You also need to supply RimWorld with the assembly containing the type and namespace specified.&lt;br /&gt;
&lt;br /&gt;
=Using your XML from C#=&lt;br /&gt;
There are times you'll need to use a Def or other value defined in XML.&lt;br /&gt;
&lt;br /&gt;
==DefOf==&lt;br /&gt;
Any class with the [DefOf] annotation will automatically have its fields filled with their corresponding Def. You can then access it in other code like you'd access any DefOf, like ThingDefOf. The below example would be used as ''SomeDef def = MyDefOf.JustOneExampleDefName;''.&lt;br /&gt;
&lt;br /&gt;
'''Advantages''':&lt;br /&gt;
* It's run-time fast.&lt;br /&gt;
* It's easy.&lt;br /&gt;
* It moves errors to startup, rather than at runtime. Early warnings save considerable testing and debugging!&lt;br /&gt;
** If there's an error in your code (like a typo in the defName, or a missing Def), it will detect that as soon as the game starts, rather than when it's trying to use it.&lt;br /&gt;
&lt;br /&gt;
'''Disadvantages''': &lt;br /&gt;
* DefOfs don't get their fields filled until after the game is done loading Defs.&lt;br /&gt;
** This means using a DefOf before it is properly initialised gets you ''null'' - which the DefOf class is supposed to prevent.&lt;br /&gt;
* Has a negative influence on startup times. &amp;lt;ref&amp;gt;It uses reflection to find and fill the fields. This probably isn't the quickest, but the extent of it hasn't been measured.&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang = &amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
[DefOf]&lt;br /&gt;
public static class MyDefOf&lt;br /&gt;
{&lt;br /&gt;
    public static SomeDef JustOneExampleDefName;&lt;br /&gt;
    public static SomeDef AnotherExampleDefName;&lt;br /&gt;
    public static SomeDef YetMoreExampleDefName;&lt;br /&gt;
&lt;br /&gt;
    static MyDefOf()&lt;br /&gt;
    {&lt;br /&gt;
        DefOfHelper.EnsureInitializedInCtor(typeof(MyDefOf));&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
The fields have to be static and public.&lt;br /&gt;
&lt;br /&gt;
===That weird constructor===&lt;br /&gt;
It's there for your own good. If you're trying to use a Def before RimWorld had a chance to fill the field with a proper reference, it will return null. You don't want that. This constructor warns against that.&lt;br /&gt;
&lt;br /&gt;
==DefDatabase==&lt;br /&gt;
If you only need to use a certain Def occasionally, you can look it up in the DefDatabase directly.&lt;br /&gt;
&amp;lt;source lang = &amp;quot;csharp&amp;quot;&amp;gt;SomeDef def = DefDatabase&amp;lt;SomeDef&amp;gt;.GetNamed(&amp;quot;JustOneExampleDefName&amp;quot;);&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Advantages''':&lt;br /&gt;
* Is allowed to return null (silent failure is an option).&lt;br /&gt;
* Does not require an entire class.&lt;br /&gt;
* Is open to string based shenanigans.&lt;br /&gt;
&lt;br /&gt;
'''Disadvantages''':&lt;br /&gt;
* Is allowed to return null. If you're not prepared for it to return null, Bad Things Happen.&lt;br /&gt;
* Slower than a DefOf. (Altho if you put the def in a static variable, this is somewhat negated)&lt;br /&gt;
* Prone to typos.&lt;br /&gt;
&lt;br /&gt;
=See also=&lt;br /&gt;
[[Modding Tutorials/Hello World|Hello World]] - For when your code shouldn't be linked to XML, but does need to be bootstrapped.&lt;br /&gt;
&lt;br /&gt;
[[Category: Modding tutorials]]&lt;/div&gt;</summary>
		<author><name>Lilwhitemouse</name></author>
	</entry>
	<entry>
		<id>https://rimworldwiki.com/index.php?title=Modding_Tutorials/Transpiler_Hints&amp;diff=63993</id>
		<title>Modding Tutorials/Transpiler Hints</title>
		<link rel="alternate" type="text/html" href="https://rimworldwiki.com/index.php?title=Modding_Tutorials/Transpiler_Hints&amp;diff=63993"/>
		<updated>2019-06-30T18:02:46Z</updated>

		<summary type="html">&lt;p&gt;Lilwhitemouse: link&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Debugging Transpilers can seem impossible.  It's very difficult to count exactly correctly, and any mistakes will likely throw a system exception.&lt;br /&gt;
&lt;br /&gt;
==Helpful examples==&lt;br /&gt;
One way to get an idea of how to use the Transpiler is to [https://github.com/search?o=desc&amp;amp;q=Rimworld+Harmony+Transpiler&amp;amp;s=indexed&amp;amp;type=Code search github for Harmony Transpilers].&lt;br /&gt;
&lt;br /&gt;
==Useful debugging tools.==&lt;br /&gt;
&lt;br /&gt;
===See what your IL code is===&lt;br /&gt;
One thing that can potentially help is to print out your entire modified IL code, to make sure you've got it correct:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
        public static IEnumerable&amp;lt;CodeInstruction&amp;gt; Transpiler(IEnumerable&amp;lt;CodeInstruction&amp;gt; instructions, ILGenerator generator) {&lt;br /&gt;
            var l=XTranspiler(instructions, generator).ToList(); // name your actual transpiler XTranspiler&lt;br /&gt;
            string s=&amp;quot;Code:&amp;quot;;&lt;br /&gt;
            int i=0;&lt;br /&gt;
            foreach (var c in l) {&lt;br /&gt;
                if (c.opcode==OpCodes.Call ||&lt;br /&gt;
                    c.opcode==OpCodes.Callvirt) { // you can make certain operations more visible&lt;br /&gt;
                    Log.Warning(&amp;quot;&amp;quot;+i+&amp;quot;: &amp;quot;+c);&lt;br /&gt;
                } else {&lt;br /&gt;
                    Log.Message(&amp;quot;&amp;quot;+i+&amp;quot;: &amp;quot;+c);&lt;br /&gt;
                }&lt;br /&gt;
                s+=&amp;quot;\n&amp;quot;+i+&amp;quot;: &amp;quot;+c;&lt;br /&gt;
                i++;&lt;br /&gt;
                yield return c;&lt;br /&gt;
            }&lt;br /&gt;
            Log.Error(s); // or just print the entire thing out to copy to a text editor.&lt;br /&gt;
        }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>Lilwhitemouse</name></author>
	</entry>
	<entry>
		<id>https://rimworldwiki.com/index.php?title=Modding_Tutorials/Transpiler_Hints&amp;diff=63992</id>
		<title>Modding Tutorials/Transpiler Hints</title>
		<link rel="alternate" type="text/html" href="https://rimworldwiki.com/index.php?title=Modding_Tutorials/Transpiler_Hints&amp;diff=63992"/>
		<updated>2019-06-30T17:58:42Z</updated>

		<summary type="html">&lt;p&gt;Lilwhitemouse: Useful tool in some certain circumstances &amp;gt;&amp;lt;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Debugging Transpilers can seem impossible.  It's very difficult to count exactly correctly, and any mistakes will likely throw a system exception.&lt;br /&gt;
&lt;br /&gt;
==Helpful examples==&lt;br /&gt;
One way to get an idea of how to use the Transpiler is to search github for Harmony Transpilers.&lt;br /&gt;
&lt;br /&gt;
==Useful debugging tools.==&lt;br /&gt;
&lt;br /&gt;
===See what your IL code is===&lt;br /&gt;
One thing that can potentially help is to print out your entire modified IL code, to make sure you've got it correct:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
        public static IEnumerable&amp;lt;CodeInstruction&amp;gt; Transpiler(IEnumerable&amp;lt;CodeInstruction&amp;gt; instructions, ILGenerator generator) {&lt;br /&gt;
            var l=XTranspiler(instructions, generator).ToList(); // name your actual transpiler XTranspiler&lt;br /&gt;
            string s=&amp;quot;Code:&amp;quot;;&lt;br /&gt;
            int i=0;&lt;br /&gt;
            foreach (var c in l) {&lt;br /&gt;
                if (c.opcode==OpCodes.Call ||&lt;br /&gt;
                    c.opcode==OpCodes.Callvirt) { // you can make certain operations more visible&lt;br /&gt;
                    Log.Warning(&amp;quot;&amp;quot;+i+&amp;quot;: &amp;quot;+c);&lt;br /&gt;
                } else {&lt;br /&gt;
                    Log.Message(&amp;quot;&amp;quot;+i+&amp;quot;: &amp;quot;+c);&lt;br /&gt;
                }&lt;br /&gt;
                s+=&amp;quot;\n&amp;quot;+i+&amp;quot;: &amp;quot;+c;&lt;br /&gt;
                i++;&lt;br /&gt;
                yield return c;&lt;br /&gt;
            }&lt;br /&gt;
            Log.Error(s); // or just print the entire thing out to copy to a text editor.&lt;br /&gt;
        }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>Lilwhitemouse</name></author>
	</entry>
	<entry>
		<id>https://rimworldwiki.com/index.php?title=Modding_Tutorials/Harmony&amp;diff=63991</id>
		<title>Modding Tutorials/Harmony</title>
		<link rel="alternate" type="text/html" href="https://rimworldwiki.com/index.php?title=Modding_Tutorials/Harmony&amp;diff=63991"/>
		<updated>2019-06-30T17:57:08Z</updated>

		<summary type="html">&lt;p&gt;Lilwhitemouse: /* Transpilers */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{BackToTutorials}}&lt;br /&gt;
&lt;br /&gt;
'''[http://rimworldwiki.com/index.php?title=Modding_Tutorials/Injection&amp;amp;action=edit&amp;amp;redlink=1 Harmony] - A library for patching, replacing and decorating .NET and Mono methods during runtime'''&lt;br /&gt;
&lt;br /&gt;
Harmony is the current best practice for changing the runtime execution of code in RimWorld.&lt;br /&gt;
&lt;br /&gt;
To integrate Harmony into your mod for use, download the latest stable release and add it as a reference to your C# project. Make sure that you also include the dll, (0Harmony.dll) in your mod's assemblies folder. Please DO NOT use HugsLib for an &amp;quot;easy&amp;quot; Harmony implementation due to the fact that HugsLib becomes an unnecessary and unutilized dependency for mods and beginners grow accustomed to using HugsLib in all their mods even if they never touch HugsLib's API in their code. This is a bad practice, especially for beginners new to RimWorld Modding. Please only use HugsLib when you want to utilize some of its features!&lt;br /&gt;
&lt;br /&gt;
Harmony is great for running code patches before (Prefix) or after (Postfix) an existing method. Usually this is all you need for your Mod. Because this does not change existing functionality of RimWorld, it MOST LIKELY does not impact other mods and runs in parallel with other Harmony patches.&lt;br /&gt;
&lt;br /&gt;
''The snippets on this page are not meant as an exhaustive document on all things Harmony. Refer to the original documentation.'' This article is mostly a &amp;quot;this is what you can do&amp;quot; summary in 5 minutes.&lt;br /&gt;
&lt;br /&gt;
==Requirements==&lt;br /&gt;
* If you still haven't [[Modding_Tutorials/Setting up a solution|set up a solution]], you're not ready for Harmony.&lt;br /&gt;
* You need to be able to write a [[Modding_Tutorials/Hello World|Hello World]] program.&lt;br /&gt;
* You don't need to know the inner workings of JIT-compilation, reflection and inlining, but a basic understanding of C# and/or programming in general is assumed in this article.&lt;br /&gt;
&lt;br /&gt;
==Summary==&lt;br /&gt;
Harmony can alter the workings of any method. It offers three ways of doing this: prefixes, postfixes, and transpilers.&lt;br /&gt;
&lt;br /&gt;
===Prefix===&lt;br /&gt;
A prefix is a method that runs before the original method. It can have a return type of void or bool. If a bool returns false, the original method is skipped. This will cause compatibility issues if you're not very careful. This type of prefix may also prevent other prefixes from running.&lt;br /&gt;
&lt;br /&gt;
===Postfix===&lt;br /&gt;
A postfix is a method that runs after the original method. They are guaranteed to run. Postfixes can also alter the result. Use these for greatest compatibility.&lt;br /&gt;
&lt;br /&gt;
===Transpilers===&lt;br /&gt;
A transpiler is a set of CodeInstructions. These alter the inner working of the method. They use low-level IL-code, from System.Reflection and System.Reflection.Emit. Refer to MSDN and Harmony documentation for more info. Transpilers are difficult to debug and therefor hard to create/maintain/update.&lt;br /&gt;
&lt;br /&gt;
If you must use a transpiler, you might find useful notes [[Modding_Tutorials/Transpiler Hints|here]].&lt;br /&gt;
&lt;br /&gt;
==Altering the result==&lt;br /&gt;
If the original method has a return type, you can alter its ''__result'' by passing it by ''ref''.&lt;br /&gt;
&lt;br /&gt;
==Pitfalls==&lt;br /&gt;
===Overuse===&lt;br /&gt;
Harmony is a fantastic tool, that you'll soon want to use for everything. Before you do that, consider the alternatives. Can you subclass? Can you use a ThingComp? A MapComponent? There may be viable alternatives without the added dependency.&lt;br /&gt;
===Not changing the result?===&lt;br /&gt;
Forgot to pass by ref.&lt;br /&gt;
===How do I return a value from a void or prefix?===&lt;br /&gt;
That's the magic. Harmony disconnects its own return type from the return type of the original method. Consider the following destructive prefix, which gives everyone perfect knowledge of trap locations:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
	[HarmonyPatch(typeof(Building_Trap))]&lt;br /&gt;
	[HarmonyPatch(nameof(Building_Trap.KnowsOfTrap)] //annotation boiler plate to tell Harmony what to patch. Refer to docs.&lt;br /&gt;
	static class Building_Trap_KnowsOfTrap_Patch&lt;br /&gt;
	{&lt;br /&gt;
		static bool Prefix(ref bool __result) //pass the __result by ref to alter it.&lt;br /&gt;
		{&lt;br /&gt;
			__result = true; //alter the result.&lt;br /&gt;
			return false; //return false to skip execution of the original.&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
===Getting the right method to patch===&lt;br /&gt;
'''AccessTools''' is a nice wrapper for reflection. The most reliable way of specifying the method to patch is by providing the Patch() method with MethodInfo. Standard System.Reflection also works. You will need to specify arguments for overloaded methods.&lt;br /&gt;
===Doesn't seem to get patched?===&lt;br /&gt;
Does your Log.Message() not show up? Set HarmonyInstance.DEBUG = true and check the new .txt file Harmony placed on your desktop. If you are trying to patch something that runs during game loading, you [[Modding_Tutorials/Hello_World#StaticConstructorOnStartup_vs_inheriting_from_Mod| may need bootstrap differently]]. Are you doing everything right? If the method you're patching is small, it may have been [https://en.wikipedia.org/wiki/Inline_expansion inlined.]&lt;br /&gt;
&lt;br /&gt;
==Bootstrapping==&lt;br /&gt;
Remember the [[Modding Tutorials/Hello World|Hello World]] tutorial? The [StaticConstructorOnStartUp] is a perfect starting point. Create your harmony instance in there, and use it to call PatchAll() or do your manual patching.&lt;br /&gt;
&lt;br /&gt;
== Links == &lt;br /&gt;
&lt;br /&gt;
[https://github.com/pardeike/Harmony/releases Harmony's Releases] - Link to Harmony's latest release(s) for download.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/pardeike/Harmony/wiki Harmony's Wiki] - General outline of how to use Harmony&lt;br /&gt;
&lt;br /&gt;
[https://github.com/roxxploxx/RimWorldModGuide/wiki/SHORTTUTORIAL%3A-Harmony RimWorldModGuide on Harmony] - gives some concrete examples and helpful explanations&lt;br /&gt;
&lt;br /&gt;
[https://gist.github.com/pardeike/c02e29f9e030e6a016422ca8a89eefc9 Harmony's Author's Transpiler tutorial] - Tutorial and example of using Harmony Transpiler, with helpful links (inject your code inside a RimWorld class's code - #DeepMagic)&lt;br /&gt;
&lt;br /&gt;
[https://ludeon.com/forums/index.php?topic=29517 Harmony Thread] - Harmony thread on Ludeon Studio's Forum.  Announcements of new versions, and the forum in general is a reasonable place to ask questions.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/RimWorld-CCL-Reborn/AlienRaces/blob/master/Source/AlienRace/AlienRace/HarmonyPatches.cs Alien races] - The unofficial Harmony encyclopedia. Dozens, if not hundreds of patches for all your cargo cult programming needs.&lt;/div&gt;</summary>
		<author><name>Lilwhitemouse</name></author>
	</entry>
	<entry>
		<id>https://rimworldwiki.com/index.php?title=Modding&amp;diff=62714</id>
		<title>Modding</title>
		<link rel="alternate" type="text/html" href="https://rimworldwiki.com/index.php?title=Modding&amp;diff=62714"/>
		<updated>2019-02-17T15:06:30Z</updated>

		<summary type="html">&lt;p&gt;Lilwhitemouse: /* I want my mod to...: */ save data, as per https://ludeon.com/forums/index.php?topic=48046.0&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;!--Top Nav Box--&amp;gt;&lt;br /&gt;
{| align=center&lt;br /&gt;
| {{Basics_Nav}}&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{See also|List of mods}}&lt;br /&gt;
'''Mods''' (short for modifications) are small packages that add to or otherwise affect gameplay in RimWorld. They include art packs (for reskinning the game), more weapons, more incidents, furniture, and game-balancing mods. RimWorld mods may make use of XML and C#.&lt;br /&gt;
&lt;br /&gt;
This page is about making mods. For info about using mods, see [[Installing mods]].&lt;br /&gt;
&lt;br /&gt;
==Mod-making tutorials== &lt;br /&gt;
Mod-making tutorials are available at the [[Modding Tutorials]] page. If you can't find what you need, you should try looking in [https://ludeon.com/forums/index.php?board=14.0 the forums help section on modding] to check if the information you're looking for has been asked previously, before starting your own thread.&lt;br /&gt;
&lt;br /&gt;
===Mod-making Templates===&lt;br /&gt;
*[https://ludeon.com/forums/index.php?topic=39038.0 Mod Development Cookiecutter (automatically build your mod development environment)]&lt;br /&gt;
&lt;br /&gt;
==What you can mod==&lt;br /&gt;
RimWorld does not limit what you can or can't do. The only limit is skills and motivation, or patience and willpower. You can mod everything, from defs, to code, images, and sounds. Some examples:&lt;br /&gt;
&lt;br /&gt;
* '''Defs''': XML files containing lists of definitions for use by the game. There are a lot of these. They define every thing, skills, storyteller, and many other types of data. Find them in YourModName/Defs. More about this later.&lt;br /&gt;
* '''Code''': You can add .NET assemblies and the game will load them. Place your DLLs in YourModName/Assemblies. There is no API for RimWorld modding,  you can make full use of RimWorld's functions. You also have the full power of the .NET Framework 3.5 available. More about this later.&lt;br /&gt;
* '''Images''': You can add images.&lt;br /&gt;
* '''Sounds''': You can add sound files.&lt;br /&gt;
* '''Patches''': Using xpath, you can edit Defs with pinpoint precision to change only the values you need to change while staying as compatible as possible with other mods.&lt;br /&gt;
* '''Jobs''':  A useful link here https://github.com/Mehni/ExampleJob/wiki - covers JobGivers WorkGivers and Toils&lt;br /&gt;
** Higher level, explanation on how pawns think:  https://github.com/roxxploxx/RimWorldModGuide/wiki/SHORTTUTORIAL%3A-How-Pawns-Think&lt;br /&gt;
&lt;br /&gt;
==The basics: Defs==&lt;br /&gt;
The most basic kind of RimWorld modding is done by editing '''Defs'''.&lt;br /&gt;
&lt;br /&gt;
Definitions each define some piece of the game. Different kinds of definitions can define:&lt;br /&gt;
&lt;br /&gt;
* '''Weapons'''&lt;br /&gt;
* '''Buildings'''&lt;br /&gt;
* '''Plants'''&lt;br /&gt;
* '''Animals'''&lt;br /&gt;
* '''Sound'''&lt;br /&gt;
* '''Research'''&lt;br /&gt;
* '''Biomes'''&lt;br /&gt;
* '''Much much more'''&lt;br /&gt;
&lt;br /&gt;
When the game runs, it collects all the definitions into a database. It then draws from these pools in when appropriate. It will randomly draw guns of a certain category to arm a new enemy mercenary. Or, it will randomly spawn an animal type on the edge of the map. Modding the game with Defs means adding your definitions to these pools and watching the game use them.&lt;br /&gt;
&lt;br /&gt;
A mod could be a pack of new weapons, a new animal, or a total conversion of the game. A mod will usually contain several Defs of various types, as well as content like images and sounds.&lt;br /&gt;
&lt;br /&gt;
The base game is defined in a single mod called Core.&lt;br /&gt;
&lt;br /&gt;
Players can choose which mods to activate. Most players often have several mods active at once. You could use a medieval mod to replace the core mod, and add on a weapons pack created by someone else. The game will run with the medieval mod content, and also randomly spawn in weapons from the extra weapons pack.&lt;br /&gt;
&lt;br /&gt;
==Mod file structure==&lt;br /&gt;
For defining new game content, '''[[wikipedia:XML|XML]]''' files are used. Here is an example of the format, that applies to most of the definitions:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot; ?&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
   &amp;lt;SomeDef&amp;gt;&lt;br /&gt;
      &amp;lt;defName&amp;gt;MyNewDefinitionOfContent&amp;lt;/defName&amp;gt;&lt;br /&gt;
      &amp;lt;!-- more tags will appear depending on what are you defining --&amp;gt;&lt;br /&gt;
   &amp;lt;/SomeDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
All rootnodes for Defs start with '''&amp;amp;lt;Defs&amp;amp;gt;'''. Remember, that the word '''Some''' must be replaced by the name of whatever are you defining. For thing it's '''&amp;amp;lt;ThingDef&amp;amp;gt;'''.&lt;br /&gt;
&lt;br /&gt;
The RimWorld mods use the following directory structure. Root folders have to follow the naming pattern (About, Assemblies, Defs, Sounds, Patches, Textures, Languages) for them to be read by RimWorld. Apart from the Languages Folder, subfolders can have any structure. For the sake of organisation, it is recommended to keep things categorised:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
┌About (Your mod MUST have an About folder containing an About.xml file. Case sensitive)&lt;br /&gt;
├─About.xml (Contains info about the mod)&lt;br /&gt;
├─Preview.png (Image that appears above the mod info in game)&lt;br /&gt;
│&lt;br /&gt;
├Assemblies (If your mod uses any DLL files put them here)&lt;br /&gt;
├─MyMod.dll&lt;br /&gt;
│&lt;br /&gt;
├Defs (Contains xml definitions of the mod)&lt;br /&gt;
├┬ThingDefs&lt;br /&gt;
│├─Things.xml&lt;br /&gt;
│└─Buildings.xml&lt;br /&gt;
│&lt;br /&gt;
├┬ResearchProjectDefs&lt;br /&gt;
│└─MyProjects.xml&lt;br /&gt;
│&lt;br /&gt;
│&lt;br /&gt;
├┬Sounds (Put any sound files here. Universally supported formats are .ogg and .wav. .mp3 files are not guaranteed to work)&lt;br /&gt;
├─MySound.wav&lt;br /&gt;
|&lt;br /&gt;
├Source&lt;br /&gt;
├─MyMod.cs (Optionally, put the source code of your mod here)&lt;br /&gt;
│&lt;br /&gt;
├Patches&lt;br /&gt;
├─MyPatch.xml&lt;br /&gt;
│&lt;br /&gt;
├Languages&lt;br /&gt;
├┬English (Replace with the language name)&lt;br /&gt;
│├┬Keyed&lt;br /&gt;
││└─Keys.xml&lt;br /&gt;
│├┬Strings&lt;br /&gt;
││└┬Names&lt;br /&gt;
││  └─PawnNames.xml&lt;br /&gt;
│├┬DefInjected (NOTE: the folder (and subfolder) names must be specific here, and follow the XML structure of the mod)&lt;br /&gt;
││└┬ThingDef&lt;br /&gt;
││  └─Thing.xml&lt;br /&gt;
│├─LanguageInfo.xml&lt;br /&gt;
│└─LangIcon.png&lt;br /&gt;
│&lt;br /&gt;
├Textures (Put any image textures here, preferably in .png format.)&lt;br /&gt;
├┬Things&lt;br /&gt;
│├─MyMod_ImageA.png&lt;br /&gt;
│└─MyMod_ImageB.png&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Mod info===&lt;br /&gt;
This is found in &amp;lt;code&amp;gt;MODNAME/About&amp;lt;/code&amp;gt;&lt;br /&gt;
*The contents of About.xml are plain text. HTML Markup tags cause NullRef's.&lt;br /&gt;
*You can have an image for your mod. Restrict the image size to 1 MB.&lt;br /&gt;
&lt;br /&gt;
===Textures===&lt;br /&gt;
These are found in &amp;lt;code&amp;gt;MODNAME/Textures&amp;lt;/code&amp;gt;&lt;br /&gt;
*You can have any path you want from this point on.&lt;br /&gt;
*When referencing textures in your mod, using &amp;lt;graphicPath&amp;gt;, have the complete path relative to your mod, including the filename (but not the file extension). Example for the RoyalBed Testmod: &amp;lt;code&amp;gt;&amp;lt;graphicPath&amp;gt;Things/Building/RoyalBed&amp;lt;/graphicPath&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For textures that have multiple faces, like animals and furniture which can be rotated; You can use the Graphic_Multi class. Immediately following your &amp;lt;graphicPath&amp;gt;&amp;lt;/graphicPath&amp;gt;. Your Path should point to the folder containing the different textures: Texturename_east (for both east- and west-facing), Texturename_south (front-facing), and Texturename_north (back-facing). &lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot; &amp;gt;&lt;br /&gt;
&amp;lt;graphicPath&amp;gt;Things/Buildings/RoyalCouch/RoyalCouch&amp;lt;/graphicPath&amp;gt;&lt;br /&gt;
&amp;lt;graphicClass&amp;gt;Graphic_Multi&amp;lt;/graphicClass&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Inside your folder:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
┌Textures&lt;br /&gt;
└┬Things&lt;br /&gt;
 └┬Buildings&lt;br /&gt;
  └┬RoyalCouch&lt;br /&gt;
   ├╴RoyalCouch_east&lt;br /&gt;
   ├╴RoyalCouch_south&lt;br /&gt;
   └╴RoyalCouch_north&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For plant textures that have multiple growth stages and/or utilize the Graphic_Random class, the different images for each stage must be in separate folders. These images within must also share the same filenames. For example, the [[corn plant]] has one immature form, and two different mature forms that appear at random once the plant is fully grown. Similarly to Graphic_Multi, when using the Graphic_Random class, you will always want to reference the folder containing the images rather than the images themselves. It should be noted that only harvestable plants are able to display an immature image.&lt;br /&gt;
&lt;br /&gt;
An example of how retexturing a plant could work:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot; &amp;gt;&lt;br /&gt;
&amp;lt;graphicPath&amp;gt;Things/Plants/CornPlant&amp;lt;/graphicPath&amp;gt;&lt;br /&gt;
&amp;lt;graphicClass&amp;gt;Graphic_Random&amp;lt;/graphicClass&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Your folder structure:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
┌Textures&lt;br /&gt;
└┬Things&lt;br /&gt;
 └┬Plants&lt;br /&gt;
  └┬CornPlant&lt;br /&gt;
   ├╴CornPlant_A&lt;br /&gt;
   └╴CornPlant_B&lt;br /&gt;
  └┬CornPlant_Immature&lt;br /&gt;
   ├╴CornPlant_A&lt;br /&gt;
   └╴CornPlant_B&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Even though there is only one image used for the immature corn plant, we must have two copies of it with the same filenames as the mature plant images in order to prevent broken textures in-game.&lt;br /&gt;
If you wanted to add a leafless variant to a plant (such as the leafless trees in winter), another folder would be added.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
┌Textures&lt;br /&gt;
└┬Things&lt;br /&gt;
 └┬Plants&lt;br /&gt;
  └┬CornPlant&lt;br /&gt;
   ├╴CornPlant_A&lt;br /&gt;
   └╴CornPlant_B&lt;br /&gt;
  └┬CornPlant_Immature&lt;br /&gt;
   ├╴CornPlant_A&lt;br /&gt;
   └╴CornPlant_B&lt;br /&gt;
  └┬CornPlant_Leafless&lt;br /&gt;
   ├╴CornPlant_A&lt;br /&gt;
   └╴CornPlant_B&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Interactive &amp;quot;Things&amp;quot;===&lt;br /&gt;
A Thing is anything that exists in the game world. It includes resources, races (humanoid and animal), buildings, furniture, and many others.&lt;br /&gt;
&lt;br /&gt;
These are defined in &amp;lt;code&amp;gt;MODNAME/Defs/ThingDefs&amp;lt;/code&amp;gt;&lt;br /&gt;
If you make a new workbench, you'll need to define a recipe for it. This is a list, so you can have many new recipes listed. Note that new workbenches also need a WorkGiver tied to them, otherwise pawns will ignore your new bench.&lt;br /&gt;
&lt;br /&gt;
The recipes themselves are defined in: &amp;lt;code&amp;gt;MODNAME/Defs/RecipeDefs&amp;lt;/code&amp;gt;&lt;br /&gt;
In here you can define what ingredients/resources are required, what can be used, and what the default recipe is.&lt;br /&gt;
&lt;br /&gt;
Any new resources will need to be defined in: &amp;lt;code&amp;gt;MODNAME/Defs/ThingDefs&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Turrets===&lt;br /&gt;
These are defined in two files in: &amp;lt;code&amp;gt;MODNAME/Defs/ThingDefs/Buildings_Big.xml&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Weapons_Guns.xml&amp;lt;/code&amp;gt; (Remember, these can be named anything)&lt;br /&gt;
&lt;br /&gt;
Buildings_Big.xml defines the structure of the turret itself. For example:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot; &amp;gt;&lt;br /&gt;
&amp;lt;building&amp;gt;&lt;br /&gt;
	&amp;lt;turretGunDef&amp;gt;Gun_MiniTurret&amp;lt;/turretGunDef&amp;gt;&lt;br /&gt;
	&amp;lt;turretBurstCooldownTime&amp;gt;4.8&amp;lt;/turretBurstCooldownTime&amp;gt;&lt;br /&gt;
&amp;lt;/building&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Weapons_Gun.xml defines the weapon the turret uses. Anything can be used as a weapon for turrets, including grenades.&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
These are defined in: &amp;lt;code&amp;gt;MODNAME/Defs/ThingDefs/Resources.xml&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Research projects===&lt;br /&gt;
These are found in: &amp;lt;code&amp;gt;MODNAME/Defs/ResearchProjectDefs&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can have research trees as well, where additional research projects get unlocked as you move through.&lt;br /&gt;
This is how to add prerequisites:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot; &amp;gt;&lt;br /&gt;
&amp;lt;prerequisites&amp;gt;&lt;br /&gt;
	&amp;lt;li&amp;gt;-this is the &amp;lt;defName&amp;gt; of the prerequisite-&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/prerequisites&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Because it's a list, you can have multiple prerequisites for a research project.&lt;br /&gt;
&lt;br /&gt;
==Advice==&lt;br /&gt;
*The tilde key (` or ~) brings up the development console, which will report any errors or warnings it encounters when a mod loads or during gameplay. This is the quickest way to see what, if any, errors exist in your mod. (You don't need to turn on development mode for this.)&lt;br /&gt;
*Use development mode (found in the options menu) to help debug your mod, spawn items related to your mod, or fire incidents at will. (Or just mess around, if you'd like.)&lt;br /&gt;
&lt;br /&gt;
==I want to make a mod that can...:==&lt;br /&gt;
'''Or, how do I make my mod do ''this''?'''&lt;br /&gt;
&lt;br /&gt;
You can find links to tutorials on the [[Modding Tutorials]] page. There's also more tutorials about the basics there, so don't miss out on that.&lt;br /&gt;
&lt;br /&gt;
* Save/Load information.  See a very useful guide at [https://spdskatr.github.io/RWModdingResources/saving-guide this page]&lt;br /&gt;
** For saving settings for your mod, either use a class that extends ModSettings or use HugsLib.&lt;br /&gt;
** For saving per-world data, make a [[Modding_Tutorials/GameComponent|Game Component]] and override ExposeData&lt;br /&gt;
* Add a new value to a def&lt;br /&gt;
** See [[Modding_Tutorials/ThingComp|ThingComp]]&lt;br /&gt;
** Also helpful: [[Modding Tutorials/DefModExtension|DefModExtension]]s&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
*[https://github.com/roxxploxx/RimWorldModGuide/wiki A good guide to assist people trying to mod RimWorld]&lt;br /&gt;
*[https://spdskatr.github.io/RWModdingResources/ A good collection of guides for RimWorld modders]&lt;br /&gt;
*[https://ludeon.com/forums/index.php?topic=39038.0 Mod Development Cookiecutter (automatically build your mod development environment)]&lt;br /&gt;
*[https://ludeon.com/forums/index.php?topic=2325.0 RimWorld core art source thread]&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
*You can have as many mods as you like, however too many mods may affect performance.&lt;br /&gt;
*If the game crashes due to a mod-related reason on startup, or mods conflict with each other, then the game will reset the mods.&lt;br /&gt;
*Mods for previous versions may be usable, however most of the time they are not compatible.&lt;br /&gt;
&lt;br /&gt;
[[Category:Modding]]&lt;/div&gt;</summary>
		<author><name>Lilwhitemouse</name></author>
	</entry>
	<entry>
		<id>https://rimworldwiki.com/index.php?title=Modding_Tutorials/Linking_XML_and_C&amp;diff=62651</id>
		<title>Modding Tutorials/Linking XML and C</title>
		<link rel="alternate" type="text/html" href="https://rimworldwiki.com/index.php?title=Modding_Tutorials/Linking_XML_and_C&amp;diff=62651"/>
		<updated>2019-02-11T16:46:41Z</updated>

		<summary type="html">&lt;p&gt;Lilwhitemouse: /* Examples */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{BackToTutorials}}&lt;br /&gt;
&lt;br /&gt;
[[Modding Tutorials/Writing custom code|Writing custom code]] is all well and good if you can't force RimWorld to use it! Here are three ways of linking your Code to the XML and vice versa.&lt;br /&gt;
&lt;br /&gt;
=A classy design pattern=&lt;br /&gt;
RimWorld leans heavily on Object Oriented Programming and will often expose the specific class of a Def to the XML. They're often called a workerClass, thingClass, but obviously can be named anything. Keep a look out for these, they're sometimes subtle.&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
&amp;lt;source lang =&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;BiomeDef&amp;gt;&lt;br /&gt;
  &amp;lt;defName&amp;gt;BorealForest&amp;lt;/defName&amp;gt;&lt;br /&gt;
  &amp;lt;workerClass&amp;gt;BiomeWorker_BorealForest&amp;lt;/workerClass&amp;gt;&lt;br /&gt;
&amp;lt;/BiomeDef&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang =&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;inspectorTabs&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt;ITab_Art&amp;lt;/li&amp;gt;&amp;lt;!-- That's a class! --&amp;gt;&lt;br /&gt;
&amp;lt;/inspectorTabs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=A &amp;quot;Classy&amp;quot; pattern=&lt;br /&gt;
It is possible to overwrite the default class associated with a Def (or field in a def) by specifying the Class by attribute. The most common usage of this you've undoubtedly seen before is in Components: &amp;lt;source lang = &amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;comps&amp;gt;&lt;br /&gt;
  &amp;lt;li Class=&amp;quot;CompProperties_Forbiddable&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/comps&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This class override is more widely applicable than just [[Modding Tutorials/Custom Comp Classes|comps]]. It's possible to overwrite or specify almost any type you wish. Keep [[Modding Tutorials/Compatibility|Compatibility]] in mind when doing this: in the end each object can only be one [[Modding Tutorials/Def classes|Class]].&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
&amp;lt;source lang =&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!-- Generate faction base --&amp;gt;&lt;br /&gt;
&amp;lt;GenStepDef Class = &amp;quot;MyNameSpace.MyCustomGenStepDefClass&amp;quot;&amp;gt; &amp;lt;!-- Overwrite the GenStepDef Class --&amp;gt;&lt;br /&gt;
  &amp;lt;defName&amp;gt;Settlement&amp;lt;/defName&amp;gt;&lt;br /&gt;
  &amp;lt;order&amp;gt;400&amp;lt;/order&amp;gt;&lt;br /&gt;
  &amp;lt;genStep Class=&amp;quot;GenStep_Settlement&amp;quot;&amp;gt; &amp;lt;!-- you can overwrite almost any type you wish. --&amp;gt;&lt;br /&gt;
    &amp;lt;count&amp;gt;1&amp;lt;/count&amp;gt;&lt;br /&gt;
    &amp;lt;nearMapCenter&amp;gt;true&amp;lt;/nearMapCenter&amp;gt;&lt;br /&gt;
  &amp;lt;/genStep&amp;gt;&lt;br /&gt;
  &amp;lt;modExtensions&amp;gt;&lt;br /&gt;
    &amp;lt;li Class=&amp;quot;MyNameSpace.MyCustomModExtension&amp;quot;&amp;gt; &amp;lt;!-- Aah, the classic li Class. --&amp;gt;&lt;br /&gt;
       &amp;lt;isACustomGenStepDefClassAndAModExtensionOverkill&amp;gt;false&amp;lt;/isACustomGenStepDefClassAndAModExtensionOverkill&amp;gt;&lt;br /&gt;
    &amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;/modExtensions&amp;gt;&lt;br /&gt;
&amp;lt;/GenStepDef&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=You define yourself=&lt;br /&gt;
Another possibility is to supply your own type in the XML. The most well-known example of this is [https://github.com/RimWorld-CCL-Reborn/AlienRaces/wiki/Let%27s-Start Alienraces]. The [https://github.com/RimWorld-CCL-Reborn/AlienRaces/blob/master/Source/AlienRace/AlienRace/ThingDef_AlienRace.cs ThingDef_AlienRace] inherits from regular [[Modding Tutorials/ThingDef|ThingDef]], and adds the alienRace tag to it. The alienRace tag then holds more information, a sample of which is shown below.&lt;br /&gt;
&lt;br /&gt;
One benefit of this over the annotation method above (the &amp;quot;Classy&amp;quot; pattern) is that the added control and restriction of scope is increased compatibility with over mods. It's theoretically also easier to further subclass the AlienRace def by annotation.&lt;br /&gt;
&lt;br /&gt;
While most implementations have limited themselves to Defs, there is no known technical reason to believe this pattern can't be applied to fields directly.&lt;br /&gt;
&lt;br /&gt;
==Example==&lt;br /&gt;
&amp;lt;source lang = &amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;AlienRace.ThingDef_AlienRace ParentName=&amp;quot;BasePawn&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;defName&amp;gt;ExampleAlien&amp;lt;/defName&amp;gt;&lt;br /&gt;
  &amp;lt;label&amp;gt;Alien for example&amp;lt;/label&amp;gt;&lt;br /&gt;
  &amp;lt;description&amp;gt;This alien is really special.. because it is used as an example&amp;lt;/description&amp;gt;&lt;br /&gt;
  &amp;lt;!-- regular ThingDef tags go here. --&amp;gt;&lt;br /&gt;
  &amp;lt;alienRace&amp;gt;&lt;br /&gt;
      &amp;lt;!-- specific alien stuff goes inside the alienRace tag. --&amp;gt;&lt;br /&gt;
      &amp;lt;generalSettings&amp;gt;&lt;br /&gt;
&lt;br /&gt;
      &amp;lt;/generalSettings&amp;gt;&lt;br /&gt;
      &amp;lt;raceRestriction&amp;gt;&lt;br /&gt;
&lt;br /&gt;
      &amp;lt;/raceRestriction&amp;gt;&lt;br /&gt;
  &amp;lt;/alienRace&amp;gt;&lt;br /&gt;
&amp;lt;/AlienRace.ThingDef_AlienRace&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Serialising custom classes=&lt;br /&gt;
It may sometimes be required to read/write your own datatype to XML. While we all love long strings with comma separated values, there are many cases where this is not a good idea. For that, RimWorld offers a ''LoadDataFromXmlCustom'' method. When RimWorld comes across your type during load, and the class defining that type contains the ''LoadDataFromXmlCustom'', RimWorld will use that method to parse the XML. This is done through the magic of reflection.&lt;br /&gt;
&lt;br /&gt;
Note that this method fails on types that can't have a constructor. In practice, this means you can't serialise [https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/structs structs].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang = &amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
//example taken from https://github.com/LocoNeko/RoadsOfTheRim/blob/master/Source/DefModExtension_RotR_RoadDef.cs&lt;br /&gt;
public class RotR_cost&lt;br /&gt;
{&lt;br /&gt;
    public string name;&lt;br /&gt;
    public int count;&lt;br /&gt;
&lt;br /&gt;
    public void LoadDataFromXmlCustom(XmlNode xmlRoot)&lt;br /&gt;
    {&lt;br /&gt;
        if (xmlRoot.ChildNodes.Count != 1)&lt;br /&gt;
        {&lt;br /&gt;
            Log.Error(&amp;quot;Misconfigured RotR_cost: &amp;quot; + xmlRoot.OuterXml, false);&lt;br /&gt;
            return;&lt;br /&gt;
        }&lt;br /&gt;
        name = xmlRoot.Name;&lt;br /&gt;
        count = (int)ParseHelper.FromString(xmlRoot.FirstChild.Value, typeof(int));&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Common issues=&lt;br /&gt;
You need to specify your exact Namespace.Class. There are no two ways around it. You also need to supply RimWorld with the assembly containing the type and namespace specified.&lt;br /&gt;
&lt;br /&gt;
=See also=&lt;br /&gt;
[[Modding Tutorials/Hello World|Hello World]] - For when your code shouldn't be linked to XML, but does need to be bootstrapped.&lt;br /&gt;
&lt;br /&gt;
[[Category: Modding tutorials]]&lt;/div&gt;</summary>
		<author><name>Lilwhitemouse</name></author>
	</entry>
	<entry>
		<id>https://rimworldwiki.com/index.php?title=Modding_Tutorials/PatchOperations&amp;diff=62522</id>
		<title>Modding Tutorials/PatchOperations</title>
		<link rel="alternate" type="text/html" href="https://rimworldwiki.com/index.php?title=Modding_Tutorials/PatchOperations&amp;diff=62522"/>
		<updated>2019-02-04T18:01:56Z</updated>

		<summary type="html">&lt;p&gt;Lilwhitemouse: /* PatchOperationSequence */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{BackToTutorials}}&lt;br /&gt;
&lt;br /&gt;
RimWorld Alpha 17 added a new modding feature: '''XML PatchOperations'''. Using these allows mods to edit specific elements of XML defs, rather than simply overwriting the old def with a new one, which was the required approach until A17. This greatly reduces mod conflicts, because mods that make separate changes to the same def won't necessarily overwrite one another's changes. Mods using PatchOperations can avoid requiring special compatibility mods, and can even add special features conditional on other mods being loaded.&lt;br /&gt;
&lt;br /&gt;
Here's a simple example of replacing the texture path for deep water:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot; ?&amp;gt;&lt;br /&gt;
&amp;lt;Patch&amp;gt;&lt;br /&gt;
  &amp;lt;Operation Class=&amp;quot;PatchOperationReplace&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;/Defs/TerrainDef[defName=&amp;quot;WaterDeep&amp;quot;]/texturePath&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;value&amp;gt;&lt;br /&gt;
      &amp;lt;texturePath&amp;gt;Your/Texture/Path/Here&amp;lt;/texturePath&amp;gt;&lt;br /&gt;
    &amp;lt;/value&amp;gt;&lt;br /&gt;
  &amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/Patch&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
This xml file simply goes inside YourMod/Patches/ and you're done.&lt;br /&gt;
&lt;br /&gt;
== Overview of available PatchOperations ==&lt;br /&gt;
These are the available PatchOperation types:&lt;br /&gt;
&lt;br /&gt;
* Four do basic operations on XML nodes:&lt;br /&gt;
** '''[[#PatchOperationAdd|PatchOperationAdd]]''' adds a provided child node to the selected node&lt;br /&gt;
** '''[[#PatchOperationInsert|PatchOperationInsert]]''' adds a provided sibling node to the selected node&lt;br /&gt;
** '''[[#PatchOperationRemove|PatchOperationRemove]]''' deletes the selected node&lt;br /&gt;
** '''[[#PatchOperationReplace|PatchOperationReplace]]''' replaces the selected node with the provided node&lt;br /&gt;
* Three do basic operations on XML attributes:&lt;br /&gt;
** '''[[#PatchOperationAttributeAdd|PatchOperationAttributeAdd]]''' adds a provided attribute to the selected node if and only if the attribute name is not already present&lt;br /&gt;
** '''[[#PatchOperationAttributeSet|PatchOperationAttributeSet]]''' sets a provided attribute for the selected node, overwriting the attribute value if the attribute name is already present&lt;br /&gt;
** '''[[#PatchOperationAttributeRemove|PatchOperationAttributeRemove]]''' removes an attribute for the selected node&lt;br /&gt;
* Three allow for more complex operations:&lt;br /&gt;
** '''[[#PatchOperationAddModExtension|PatchOperationAddModExtension]]''' adds a ModExtension.&lt;br /&gt;
** '''[[#PatchOperationSetName|PatchOperationSetName]]''' changes the name of a node.&lt;br /&gt;
** '''[[#PatchOperationSequence|PatchOperationSequence]]''' contains a set of other PatchOperations, and aborts upon any operation failing&lt;br /&gt;
* Three allow for conditional operations&lt;br /&gt;
** '''[[#PatchOperationTest|PatchOperationTest]]''' tests nodes, which is useful inside a PatchOperationSequence&lt;br /&gt;
** '''[[#PatchOperationConditional|PatchOperationConditional]]''' tests nodes, and can do different operations depending on the result.&lt;br /&gt;
** '''[[#PatchOperationFindMod|PatchOperationFindMod]]''' tests for the presence of another mod, and can do different operations depending on the result.&lt;br /&gt;
&lt;br /&gt;
==XPath syntax==&lt;br /&gt;
Each PatchOperation must specify an XML node to modify. It uses XPaths to specify them. An XPath is a &amp;quot;path&amp;quot; for the patch to follow when trying to find XML nodes matching the description. It will follow each part of the path from left to right. Note that these &amp;quot;paths&amp;quot; have zero relation to the file path or folder structure: They follow the structure of the XML nodes.&lt;br /&gt;
&lt;br /&gt;
XPaths start at the root node. Since the root node of all Defs is enforced to be &amp;lt;Defs&amp;gt;, so &amp;lt;code&amp;gt;/Defs/&amp;lt;/code&amp;gt; is the start of our xpath. &amp;lt;code&amp;gt;*/&amp;lt;/code&amp;gt; is also valid, as it uses the &amp;lt;code&amp;gt;*&amp;lt;/code&amp;gt; wildcard: &amp;lt;code&amp;gt;*&amp;lt;/code&amp;gt; matches any element, so it'll match the root (the top level) of the XML tree. &amp;lt;code&amp;gt;//&amp;lt;/code&amp;gt; is technically also valid, but because that construct selects ''all'' the elements in the XML tree, it's an expensive operation that makes game loading exponentially slower.&lt;br /&gt;
&lt;br /&gt;
Once the root is selected, the XPath lets the system walk down specific branches of the tree. If we use the example from the lead, we get a specific path:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;/Defs/TerrainDef[defName=&amp;quot;WaterDeep&amp;quot;]/texturePath&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# The root node is selected&lt;br /&gt;
# All child nodes of the root node called &amp;quot;TerrainDef&amp;quot; are selected&lt;br /&gt;
# We narrow down from &amp;quot;all TerrainDefs&amp;quot; to only those with the child &amp;quot;defName&amp;quot; node whose value is &amp;quot;WaterDeep&amp;quot;, which should give us exactly one node because defNames must be unique&lt;br /&gt;
# We select the child node &amp;quot;texturePath&amp;quot; from this node&lt;br /&gt;
## Note that we cannot put &amp;lt;code&amp;gt;.../texturePath/&amp;lt;/code&amp;gt; to specify the content of the texturePath node.  If we want to replace texturePath, we have to replace it with &amp;lt;code&amp;gt;&amp;lt;texturePath&amp;gt;/new/path/to/texture&amp;lt;/texturePath&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more info, see this {{LudeonThread|32785}}. XPath is a [https://www.w3schools.com/xml/xml_xpath.asp well-documented industry standard] (good resource, too); there are plenty of resources available on the subject ranging from exhaustive tutorials to simple [https://stackoverflow.com/questions/tagged/xpath StackOverflow] questions.&lt;br /&gt;
&lt;br /&gt;
==&amp;quot;Success&amp;quot; option==&lt;br /&gt;
The ''&amp;lt;code&amp;gt;&amp;lt;success&amp;gt;...&amp;lt;/success&amp;gt;&amp;lt;/code&amp;gt;'' term specifies whether the entire operation is considered a success or not.  If the overall patch operation is not considered a success, an error is thrown.  This is particularly used in Sequences and Tests.&lt;br /&gt;
&lt;br /&gt;
Options available are:&lt;br /&gt;
* Always - this patch operation is considered a success - sometimes used for Sequences so that if an early test in the sequence fails, an error is not reported (because the sequence is still a successful patch)&lt;br /&gt;
* Normal - this patch operation is considered a success if it succeeded (content patched, test passed, etc)&lt;br /&gt;
* Invert - If the patch failed (e.g., a test), then it's considered a success (useful for a negative test in a sequence)&lt;br /&gt;
* Never - this patch operation &amp;quot;failed.&amp;quot;  Even if it patched whatever it was supposed to correctly.  If you ever use this, leave a note here for the curious.&lt;br /&gt;
&lt;br /&gt;
==Overview of individual PatchOperations==&lt;br /&gt;
===PatchOperationAdd===&lt;br /&gt;
''PatchOperationAdd'' adds a child node to the selected node.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationAdd&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleList&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;value&amp;gt;&lt;br /&gt;
        &amp;lt;li&amp;gt;Foo&amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;li&amp;gt;Bar&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;/value&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList&amp;gt;&lt;br /&gt;
            &amp;lt;li&amp;gt;Foo&amp;lt;/li&amp;gt;&lt;br /&gt;
            &amp;lt;li&amp;gt;Bar&amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;/exampleList&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationInsert===&lt;br /&gt;
''PatchOperationInsert'' adds a sibling to the selected node.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
  &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
    &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
    &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
    &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
  &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationInsert&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;xpath&amp;gt;Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
  &amp;lt;value&amp;gt;&lt;br /&gt;
    &amp;lt;anotherExample&amp;gt;A new sibling&amp;lt;/anotherExample&amp;gt;&lt;br /&gt;
  &amp;lt;/value&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
  &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
    &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
    &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
    &amp;lt;anotherExample&amp;gt;A new sibling&amp;lt;/anotherExample&amp;gt;&lt;br /&gt;
    &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
  &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationRemove===&lt;br /&gt;
''PatchOperationRemove'' removes the selected node.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationRemove&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationReplace===&lt;br /&gt;
''PatchOperationReplace'' replaces the selected node.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationReplace&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;value&amp;gt;&lt;br /&gt;
        &amp;lt;anotherExample&amp;gt;An alternate node&amp;lt;/anotherExample&amp;gt;&lt;br /&gt;
    &amp;lt;/value&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;anotherExample&amp;gt;An alternate node&amp;lt;/anotherExample&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationAttributeAdd===&lt;br /&gt;
''PatchOperationAttributeAdd'' will add an attribute and set its value, but only if that attribute is not yet present.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationAttributeAdd&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;attribute&amp;gt;ExampleAttribute&amp;lt;/attribute&amp;gt;&lt;br /&gt;
    &amp;lt;value&amp;gt;ExampleValue&amp;lt;/value&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode ExampleAttribute&amp;quot;ExampleValue&amp;quot;&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationAttributeSet===&lt;br /&gt;
''PatchOperationAttributeSet'' will add an attribute and set its value. Unlike PatchAttributeAdd, PatchOperationAttributeSet will overwrite any existing value. &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode ExampleAttribute&amp;quot;ExampleValue&amp;quot;&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationAttributeSet&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;attribute&amp;gt;ExampleAttribute&amp;lt;/attribute&amp;gt;&lt;br /&gt;
    &amp;lt;value&amp;gt;DifferentExampleValue&amp;lt;/value&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode ExampleAttribute&amp;quot;DifferentExampleValue&amp;quot;&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationAttributeRemove===&lt;br /&gt;
''PatchOperationAttributeRemove'' removes the specified attribute.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode ExampleAttribute&amp;quot;ExampleValue&amp;quot;&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationAttributeRemove&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;attribute&amp;gt;ExampleAttribute&amp;lt;/attribute&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationAddModExtension===&lt;br /&gt;
{{Main|Modding Tutorials/DefModExtension}}&lt;br /&gt;
''PatchOperationAddModExtension'' adds a [[Modding Tutorials/DefModExtension|Mod Extension]].&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationAddModExtension&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;value&amp;gt;&lt;br /&gt;
        &amp;lt;li Class=&amp;quot;ExampleNameSpace.ExampleModExtension&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;exampleValue&amp;gt;true&amp;lt;/exampleValue&amp;gt;&lt;br /&gt;
        &amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;/value&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
        &amp;lt;modExtensions&amp;gt;&lt;br /&gt;
            &amp;lt;li Class=&amp;quot;ExampleNameSpace.ExampleModExtension&amp;quot;&amp;gt;&lt;br /&gt;
                &amp;lt;exampleValue&amp;gt;true&amp;lt;/exampleValue&amp;gt;&lt;br /&gt;
            &amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;/modExtensions&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationSetName===&lt;br /&gt;
''PatchOperationSetName'' changes the name of a node.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationSetName&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;name&amp;gt;newExampleName&amp;lt;/name&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;newExampleName&amp;gt;Some text&amp;lt;/newExampleName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationSequence===&lt;br /&gt;
''PatchOperationSequence'' will complete all operations in the order of their listing, and stop when any of them fails.&lt;br /&gt;
&lt;br /&gt;
Modders will often specify &amp;lt;code&amp;gt;&amp;lt;success&amp;gt;Always&amp;lt;/success&amp;gt;&amp;lt;/code&amp;gt;, which will mean that even if one part of the sequence fails (e.g., a test), the whole is still considered a success and no unneeded errors show up.&lt;br /&gt;
&lt;br /&gt;
'''Patch Operation'''&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationSequence&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;!-- put &amp;lt;success&amp;gt;Always&amp;lt;/success&amp;gt; if using tests?  Leave out for simple sequences --&amp;gt;&lt;br /&gt;
  &amp;lt;operations&amp;gt;&lt;br /&gt;
    &amp;lt;li Class=&amp;quot;PatchOperationInsert&amp;quot;&amp;gt;&amp;lt;!-- Always happens! --&amp;gt;&lt;br /&gt;
      &amp;lt;xpath&amp;gt;/Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
      &amp;lt;value&amp;gt;&lt;br /&gt;
        &amp;lt;anotherExample&amp;gt;A new sibling&amp;lt;/anotherExample&amp;gt;&lt;br /&gt;
      &amp;lt;/value&amp;gt;&lt;br /&gt;
    &amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;li Class=&amp;quot;PatchOperationAdd&amp;quot;&amp;gt;&amp;lt;!-- Always happens! --&amp;gt;&lt;br /&gt;
      &amp;lt;xpath&amp;gt;/Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]&amp;lt;/xpath&amp;gt;&lt;br /&gt;
      &amp;lt;value&amp;gt;&amp;lt;label&amp;gt;I'm a node&amp;lt;/label&amp;gt;&amp;lt;/value&amp;gt;&lt;br /&gt;
    &amp;lt;li&amp;gt;&lt;br /&gt;
    &amp;lt;!-- etc --&amp;gt;&lt;br /&gt;
  &amp;lt;operations&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Effect'''&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
  &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
    &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
  &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
  &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
    &amp;lt;label&amp;gt;I'm a node&amp;lt;/label&amp;gt;&lt;br /&gt;
    &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
    &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
    &amp;lt;anotherExample&amp;gt;A new sibling&amp;lt;/anotherExample&amp;gt;&lt;br /&gt;
    &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
  &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
'''Another Example''': Maybe you don't like the &amp;quot;Example&amp;quot; ExampleDef...&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationSequence&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;success&amp;gt;Always&amp;lt;/success&amp;gt;&amp;lt;!-- No errors thrown --&amp;gt;&lt;br /&gt;
  &amp;lt;operations&amp;gt;&lt;br /&gt;
    &amp;lt;li Class=&amp;quot;PatchOperationRemove&amp;quot;&amp;gt;&amp;lt;!-- :o  ...this returns true --&amp;gt;&lt;br /&gt;
      &amp;lt;xpath&amp;gt;/Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]&amp;lt;xpath&amp;gt;&lt;br /&gt;
    &amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;li Class=&amp;quot;PatchOperationAdd&amp;quot;&amp;gt;&amp;lt;!-- so this runs --&amp;gt;&lt;br /&gt;
      &amp;lt;xpath&amp;gt;/Defs&amp;lt;/xpath&amp;gt;&lt;br /&gt;
      &amp;lt;value&amp;gt;&lt;br /&gt;
        &amp;lt;ExampleDef&amp;gt;&amp;lt;defName&amp;gt;MyBetterExample&amp;lt;/defName&amp;gt;&amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
      &amp;lt;/value&amp;gt;&lt;br /&gt;
  &amp;lt;/operations&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If ExampleDef were already gone, MyBetterExample would not get added.&lt;br /&gt;
&lt;br /&gt;
===PatchOperationTest===&lt;br /&gt;
''PatchOperationTest'' tests for the existence/validity of an xpath. Useful to stop a PatchOperationSequence. Often used as a simpler, less powerful version of PatchOperationConditional.&lt;br /&gt;
The following example patch is from Apparello, by Shinzy. &lt;br /&gt;
&amp;lt;source lang =&amp;quot;xml&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationSequence&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;!-- check for worn graphics and if none found, add one --&amp;gt;&lt;br /&gt;
    &amp;lt;success&amp;gt;Always&amp;lt;/success&amp;gt;&lt;br /&gt;
    &amp;lt;operations&amp;gt;&lt;br /&gt;
        &amp;lt;li Class=&amp;quot;PatchOperationTest&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;xpath&amp;gt;/Defs/ThingDef[defName = &amp;quot;Apparel_Pants&amp;quot;]/apparel/wornGraphicPath&amp;lt;/xpath&amp;gt;&lt;br /&gt;
            &amp;lt;success&amp;gt;Invert&amp;lt;/success&amp;gt;&lt;br /&gt;
        &amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;li Class=&amp;quot;PatchOperationAdd&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;xpath&amp;gt;/Defs/ThingDef[defName = &amp;quot;Apparel_Pants&amp;quot;]/apparel&amp;lt;/xpath&amp;gt;&lt;br /&gt;
            &amp;lt;value&amp;gt;&lt;br /&gt;
                &amp;lt;wornGraphicPath&amp;gt;Accessorello/Pants/Pants&amp;lt;/wornGraphicPath&amp;gt;&lt;br /&gt;
            &amp;lt;/value&amp;gt;&lt;br /&gt;
        &amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;/operations&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===PatchOperationConditional===&lt;br /&gt;
''PatchOperationConditional'' can branch logic based on a match/nomatch. The following example patch adds a &amp;lt;comps&amp;gt; node if it does not yet exist, and adds itself &lt;br /&gt;
&lt;br /&gt;
This patch is courtesy Mehni. [https://github.com/Mehni/MoreFactionInteraction/blob/ab3ab2a22ee529ee4e38a471fe150fd48fd07ce9/Patches/MoreFactionInteraction.xml#L40-L62 See original.]&lt;br /&gt;
&amp;lt;source lang =&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!-- Add /comps/li/compClass if there are no comps yet. --&amp;gt;&lt;br /&gt;
&amp;lt;!-- Add /li/compClass to /comps if exists (i.e. other mod already added the comps field first) --&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationConditional&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;/Defs/WorldObjectDef[defName=&amp;quot;Caravan&amp;quot;]/comps&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;nomatch Class=&amp;quot;PatchOperationAdd&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;xpath&amp;gt;/Defs/WorldObjectDef[defName=&amp;quot;Caravan&amp;quot;]&amp;lt;/xpath&amp;gt;&lt;br /&gt;
        &amp;lt;value&amp;gt;&lt;br /&gt;
            &amp;lt;comps&amp;gt;&lt;br /&gt;
                &amp;lt;li&amp;gt;&lt;br /&gt;
                    &amp;lt;compClass&amp;gt;MoreFactionInteraction.WorldObjectComp_CaravanComp&amp;lt;/compClass&amp;gt;&lt;br /&gt;
                &amp;lt;/li&amp;gt;&lt;br /&gt;
            &amp;lt;/comps&amp;gt;&lt;br /&gt;
        &amp;lt;/value&amp;gt;&lt;br /&gt;
    &amp;lt;/nomatch&amp;gt;&lt;br /&gt;
    &amp;lt;match Class=&amp;quot;PatchOperationAdd&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;xpath&amp;gt;/Defs/WorldObjectDef[defName=&amp;quot;Caravan&amp;quot;]/comps&amp;lt;/xpath&amp;gt;&lt;br /&gt;
        &amp;lt;value&amp;gt;&lt;br /&gt;
            &amp;lt;li&amp;gt;&lt;br /&gt;
                &amp;lt;compClass&amp;gt;MoreFactionInteraction.WorldObjectComp_CaravanComp&amp;lt;/compClass&amp;gt;&lt;br /&gt;
            &amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;/value&amp;gt;&lt;br /&gt;
    &amp;lt;/match&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===PatchOperationFindMod===&lt;br /&gt;
''PatchOperationFindMod'' searches the list of active mods for the mods listed in &amp;lt;nowiki&amp;gt;&amp;lt;li&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/nowiki&amp;gt; tags.&lt;br /&gt;
&lt;br /&gt;
For a successful match, &amp;lt;nowiki&amp;gt;&amp;lt;li&amp;gt;ModName&amp;lt;/li&amp;gt;&amp;lt;/nowiki&amp;gt; has to match the &amp;lt;name&amp;gt;ModName&amp;lt;/name&amp;gt; in the About.xml of the mod you base your patch behaviour on.&lt;br /&gt;
This (shortened) patch is courtesy Mehni. [https://github.com/Mehni/MoreFactionInteraction/blob/ab3ab2a22ee529ee4e38a471fe150fd48fd07ce9/Patches/MoreFactionInteraction.xml#L64 See original.]&lt;br /&gt;
&lt;br /&gt;
The following Patch adds the RimQuest mod extension to the listed Defs when RimQuest is found.&lt;br /&gt;
&amp;lt;source lang =&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationFindMod&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;mods&amp;gt;&lt;br /&gt;
        &amp;lt;li&amp;gt;RimQuest&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;/mods&amp;gt;&lt;br /&gt;
    &amp;lt;match Class=&amp;quot;PatchOperationAddModExtension&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;xpath&amp;gt;Defs/IncidentDef[defName=&amp;quot;MFI_DiplomaticMarriage&amp;quot; or defName=&amp;quot;MFI_HuntersLodge&amp;quot; or defName=&amp;quot;MFI_Quest_PeaceTalks&amp;quot;]&amp;lt;/xpath&amp;gt;&lt;br /&gt;
        &amp;lt;value&amp;gt;&lt;br /&gt;
            &amp;lt;li Class = &amp;quot;RimQuest.RimQuest_ModExtension&amp;quot;&amp;gt;&lt;br /&gt;
                &amp;lt;canBeARimQuest&amp;gt;false&amp;lt;/canBeARimQuest&amp;gt;&lt;br /&gt;
            &amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;/value&amp;gt;&lt;br /&gt;
    &amp;lt;/match&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following Patch replace the tabWindowClass of the xpath when Relations Tab is '''not''' found. &lt;br /&gt;
&amp;lt;source lang =&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationFindMod&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;mods&amp;gt;&lt;br /&gt;
        &amp;lt;li&amp;gt;Relations Tab&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;/mods&amp;gt;&lt;br /&gt;
    &amp;lt;nomatch Class=&amp;quot;PatchOperationReplace&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;xpath&amp;gt;/Defs/MainButtonDef[defName=&amp;quot;Factions&amp;quot;]/tabWindowClass&amp;lt;/xpath&amp;gt;&lt;br /&gt;
        &amp;lt;value&amp;gt;&lt;br /&gt;
            &amp;lt;tabWindowClass&amp;gt;MyNameSpace.MyTabWindowClass&amp;lt;/tabWindowClass&amp;gt;&lt;br /&gt;
        &amp;lt;/value&amp;gt;&lt;br /&gt;
    &amp;lt;/nomatch&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Some advanced examples==&lt;br /&gt;
This (shortened) patch is courtesy XeoNovaDan. [https://github.com/XeoNovaDan/SurvivalTools/blob/62a4316c81733dde417257bf4bc5c34e3e781c7d/Patches/ExpandedWoodworkingVGP/Patch.xml See original]. Viewer discretion is advised. Parents please take precautions if young children are present.&lt;br /&gt;
&amp;lt;source lang = &amp;quot;XML&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationFindMod&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;mods&amp;gt;&lt;br /&gt;
        &amp;lt;li&amp;gt;Expanded Woodworking for Vegetable Garden Project&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;/mods&amp;gt;&lt;br /&gt;
    &amp;lt;match Class=&amp;quot;PatchOperationSequence&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;success&amp;gt;Always&amp;lt;/success&amp;gt;&lt;br /&gt;
        &amp;lt;operations&amp;gt;&lt;br /&gt;
            &amp;lt;!-- Nested PatchOpFindMod. Used because Expanded Woodworking adds more Wood when VGP Xtra is installed. --&amp;gt;&lt;br /&gt;
            &amp;lt;li Class=&amp;quot;PatchOperationFindMod&amp;quot;&amp;gt;&lt;br /&gt;
                &amp;lt;mods&amp;gt;&lt;br /&gt;
                    &amp;lt;li&amp;gt;VGP Xtra Trees and Flowers&amp;lt;/li&amp;gt;&lt;br /&gt;
                &amp;lt;/mods&amp;gt;&lt;br /&gt;
                &amp;lt;match Class=&amp;quot;PatchOperationSequence&amp;quot;&amp;gt;&lt;br /&gt;
                    &amp;lt;success&amp;gt;Always&amp;lt;/success&amp;gt;&lt;br /&gt;
                    &amp;lt;operations&amp;gt;&lt;br /&gt;
                        &amp;lt;!-- Processed camellia lumber. Mostly useful for building long-lasting, simple structures and furniture.--&amp;gt;&lt;br /&gt;
                        &amp;lt;li Class=&amp;quot;PatchOperationAddModExtension&amp;quot;&amp;gt;&lt;br /&gt;
                            &amp;lt;xpath&amp;gt;Defs/ThingDef[defName=&amp;quot;LumberCamellia&amp;quot;]&amp;lt;/xpath&amp;gt;&lt;br /&gt;
                            &amp;lt;value&amp;gt;&lt;br /&gt;
                                &amp;lt;li Class=&amp;quot;SurvivalTools.StuffPropsTool&amp;quot;&amp;gt;&lt;br /&gt;
                                    &amp;lt;toolStatFactors&amp;gt;&lt;br /&gt;
                                        &amp;lt;ConstructionSpeed&amp;gt;0.55&amp;lt;/ConstructionSpeed&amp;gt;&lt;br /&gt;
                                    &amp;lt;/toolStatFactors&amp;gt;&lt;br /&gt;
                                &amp;lt;/li&amp;gt;&lt;br /&gt;
                            &amp;lt;/value&amp;gt;&lt;br /&gt;
                        &amp;lt;/li&amp;gt;&lt;br /&gt;
                    &amp;lt;/operations&amp;gt;&lt;br /&gt;
                &amp;lt;/match&amp;gt;&lt;br /&gt;
            &amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;/operations&amp;gt;&lt;br /&gt;
    &amp;lt;/match&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Random stuff===&lt;br /&gt;
* @ select by attribute. Useful for patching (Abstract) bases. &amp;lt;source lang = &amp;quot;xml&amp;quot;&amp;gt;/Defs/ThingDef[@Name=&amp;quot;BuildingBase&amp;quot;]&amp;lt;/source&amp;gt;&lt;br /&gt;
* ''or'' is inclusive. &amp;lt;source lang = &amp;quot;xml&amp;quot;&amp;gt;/Defs/ThingDef[defName=&amp;quot;Cassowary&amp;quot; or defName = &amp;quot;Emu&amp;quot; or defName = &amp;quot;Ostrich&amp;quot; or defName = &amp;quot;Turkey&amp;quot;]&amp;lt;/source&amp;gt; selects all of those in a single (faster) operation.&lt;br /&gt;
* PatchOperationAdd and PatchOperation insert have an ''order'' tag which allows you to either Prepend or Append your add. Default behaviour of Add is to Append, insert Prepends.&lt;br /&gt;
* There is a ''success'' tag whose values can be Normal, Invert, Always and Never. This is used for the sake of error reporting: by default an error is logged when a patch fails to apply. For PatchOperationSequences and PatchOperationTests, you can set success to Always to avoid error logging.&lt;br /&gt;
&lt;br /&gt;
== Write your own ==&lt;br /&gt;
Outside the scope of this wiki, but it's possible to write your own PatchOperation.&amp;lt;/br&amp;gt;&lt;br /&gt;
- [https://github.com/NoImageAvailable/CombatExtended/blob/88ef1f86d30e6c285e3370bd9faafa92c84195b0/Source/CombatExtended/CombatExtended/PatchOperationMakeGunCECompatible.cs Example PatchOperationMakeGunCECompatible]&amp;lt;/br&amp;gt;&lt;br /&gt;
- [https://gist.github.com/Lanilor/e326e33e268e78f68a2f5cd3cdbbe8c0 Example PatchOperationAddOrReplace]&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Resources ==&lt;br /&gt;
&lt;br /&gt;
The best tutorial on PatchOperations created by Zhentar: [https://gist.github.com/Zhentar/4a1b71cea45b9337f70b30a21d868782 Introduction to PatchOperation]&lt;br /&gt;
&lt;br /&gt;
You can also learn about XPaths here: [https://www.w3schools.com/xml/xpath_intro.asp XPath tutorial]&lt;br /&gt;
&lt;br /&gt;
There is also an [https://github.com/roxxploxx/RimWorldModGuide/wiki/SHORTTUTORIAL:-DefPatches Overview of PatchOperations]  on the [https://github.com/roxxploxx/RimWorldModGuide/wiki RimWorldModGuide].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Modding]]&lt;/div&gt;</summary>
		<author><name>Lilwhitemouse</name></author>
	</entry>
	<entry>
		<id>https://rimworldwiki.com/index.php?title=Modding_Tutorials/PatchOperations&amp;diff=62521</id>
		<title>Modding Tutorials/PatchOperations</title>
		<link rel="alternate" type="text/html" href="https://rimworldwiki.com/index.php?title=Modding_Tutorials/PatchOperations&amp;diff=62521"/>
		<updated>2019-02-04T17:38:57Z</updated>

		<summary type="html">&lt;p&gt;Lilwhitemouse: /* PatchOperationInsert */ Reduced number of spaces to try and make it fit better on some screens.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{BackToTutorials}}&lt;br /&gt;
&lt;br /&gt;
RimWorld Alpha 17 added a new modding feature: '''XML PatchOperations'''. Using these allows mods to edit specific elements of XML defs, rather than simply overwriting the old def with a new one, which was the required approach until A17. This greatly reduces mod conflicts, because mods that make separate changes to the same def won't necessarily overwrite one another's changes. Mods using PatchOperations can avoid requiring special compatibility mods, and can even add special features conditional on other mods being loaded.&lt;br /&gt;
&lt;br /&gt;
Here's a simple example of replacing the texture path for deep water:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot; ?&amp;gt;&lt;br /&gt;
&amp;lt;Patch&amp;gt;&lt;br /&gt;
  &amp;lt;Operation Class=&amp;quot;PatchOperationReplace&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;/Defs/TerrainDef[defName=&amp;quot;WaterDeep&amp;quot;]/texturePath&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;value&amp;gt;&lt;br /&gt;
      &amp;lt;texturePath&amp;gt;Your/Texture/Path/Here&amp;lt;/texturePath&amp;gt;&lt;br /&gt;
    &amp;lt;/value&amp;gt;&lt;br /&gt;
  &amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/Patch&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
This xml file simply goes inside YourMod/Patches/ and you're done.&lt;br /&gt;
&lt;br /&gt;
== Overview of available PatchOperations ==&lt;br /&gt;
These are the available PatchOperation types:&lt;br /&gt;
&lt;br /&gt;
* Four do basic operations on XML nodes:&lt;br /&gt;
** '''[[#PatchOperationAdd|PatchOperationAdd]]''' adds a provided child node to the selected node&lt;br /&gt;
** '''[[#PatchOperationInsert|PatchOperationInsert]]''' adds a provided sibling node to the selected node&lt;br /&gt;
** '''[[#PatchOperationRemove|PatchOperationRemove]]''' deletes the selected node&lt;br /&gt;
** '''[[#PatchOperationReplace|PatchOperationReplace]]''' replaces the selected node with the provided node&lt;br /&gt;
* Three do basic operations on XML attributes:&lt;br /&gt;
** '''[[#PatchOperationAttributeAdd|PatchOperationAttributeAdd]]''' adds a provided attribute to the selected node if and only if the attribute name is not already present&lt;br /&gt;
** '''[[#PatchOperationAttributeSet|PatchOperationAttributeSet]]''' sets a provided attribute for the selected node, overwriting the attribute value if the attribute name is already present&lt;br /&gt;
** '''[[#PatchOperationAttributeRemove|PatchOperationAttributeRemove]]''' removes an attribute for the selected node&lt;br /&gt;
* Three allow for more complex operations:&lt;br /&gt;
** '''[[#PatchOperationAddModExtension|PatchOperationAddModExtension]]''' adds a ModExtension.&lt;br /&gt;
** '''[[#PatchOperationSetName|PatchOperationSetName]]''' changes the name of a node.&lt;br /&gt;
** '''[[#PatchOperationSequence|PatchOperationSequence]]''' contains a set of other PatchOperations, and aborts upon any operation failing&lt;br /&gt;
* Three allow for conditional operations&lt;br /&gt;
** '''[[#PatchOperationTest|PatchOperationTest]]''' tests nodes, which is useful inside a PatchOperationSequence&lt;br /&gt;
** '''[[#PatchOperationConditional|PatchOperationConditional]]''' tests nodes, and can do different operations depending on the result.&lt;br /&gt;
** '''[[#PatchOperationFindMod|PatchOperationFindMod]]''' tests for the presence of another mod, and can do different operations depending on the result.&lt;br /&gt;
&lt;br /&gt;
==XPath syntax==&lt;br /&gt;
Each PatchOperation must specify an XML node to modify. It uses XPaths to specify them. An XPath is a &amp;quot;path&amp;quot; for the patch to follow when trying to find XML nodes matching the description. It will follow each part of the path from left to right. Note that these &amp;quot;paths&amp;quot; have zero relation to the file path or folder structure: They follow the structure of the XML nodes.&lt;br /&gt;
&lt;br /&gt;
XPaths start at the root node. Since the root node of all Defs is enforced to be &amp;lt;Defs&amp;gt;, so &amp;lt;code&amp;gt;/Defs/&amp;lt;/code&amp;gt; is the start of our xpath. &amp;lt;code&amp;gt;*/&amp;lt;/code&amp;gt; is also valid, as it uses the &amp;lt;code&amp;gt;*&amp;lt;/code&amp;gt; wildcard: &amp;lt;code&amp;gt;*&amp;lt;/code&amp;gt; matches any element, so it'll match the root (the top level) of the XML tree. &amp;lt;code&amp;gt;//&amp;lt;/code&amp;gt; is technically also valid, but because that construct selects ''all'' the elements in the XML tree, it's an expensive operation that makes game loading exponentially slower.&lt;br /&gt;
&lt;br /&gt;
Once the root is selected, the XPath lets the system walk down specific branches of the tree. If we use the example from the lead, we get a specific path:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;/Defs/TerrainDef[defName=&amp;quot;WaterDeep&amp;quot;]/texturePath&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# The root node is selected&lt;br /&gt;
# All child nodes of the root node called &amp;quot;TerrainDef&amp;quot; are selected&lt;br /&gt;
# We narrow down from &amp;quot;all TerrainDefs&amp;quot; to only those with the child &amp;quot;defName&amp;quot; node whose value is &amp;quot;WaterDeep&amp;quot;, which should give us exactly one node because defNames must be unique&lt;br /&gt;
# We select the child node &amp;quot;texturePath&amp;quot; from this node&lt;br /&gt;
## Note that we cannot put &amp;lt;code&amp;gt;.../texturePath/&amp;lt;/code&amp;gt; to specify the content of the texturePath node.  If we want to replace texturePath, we have to replace it with &amp;lt;code&amp;gt;&amp;lt;texturePath&amp;gt;/new/path/to/texture&amp;lt;/texturePath&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more info, see this {{LudeonThread|32785}}. XPath is a [https://www.w3schools.com/xml/xml_xpath.asp well-documented industry standard] (good resource, too); there are plenty of resources available on the subject ranging from exhaustive tutorials to simple [https://stackoverflow.com/questions/tagged/xpath StackOverflow] questions.&lt;br /&gt;
&lt;br /&gt;
==&amp;quot;Success&amp;quot; option==&lt;br /&gt;
The ''&amp;lt;code&amp;gt;&amp;lt;success&amp;gt;...&amp;lt;/success&amp;gt;&amp;lt;/code&amp;gt;'' term specifies whether the entire operation is considered a success or not.  If the overall patch operation is not considered a success, an error is thrown.  This is particularly used in Sequences and Tests.&lt;br /&gt;
&lt;br /&gt;
Options available are:&lt;br /&gt;
* Always - this patch operation is considered a success - sometimes used for Sequences so that if an early test in the sequence fails, an error is not reported (because the sequence is still a successful patch)&lt;br /&gt;
* Normal - this patch operation is considered a success if it succeeded (content patched, test passed, etc)&lt;br /&gt;
* Invert - If the patch failed (e.g., a test), then it's considered a success (useful for a negative test in a sequence)&lt;br /&gt;
* Never - this patch operation &amp;quot;failed.&amp;quot;  Even if it patched whatever it was supposed to correctly.  If you ever use this, leave a note here for the curious.&lt;br /&gt;
&lt;br /&gt;
==Overview of individual PatchOperations==&lt;br /&gt;
===PatchOperationAdd===&lt;br /&gt;
''PatchOperationAdd'' adds a child node to the selected node.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationAdd&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleList&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;value&amp;gt;&lt;br /&gt;
        &amp;lt;li&amp;gt;Foo&amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;li&amp;gt;Bar&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;/value&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList&amp;gt;&lt;br /&gt;
            &amp;lt;li&amp;gt;Foo&amp;lt;/li&amp;gt;&lt;br /&gt;
            &amp;lt;li&amp;gt;Bar&amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;/exampleList&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationInsert===&lt;br /&gt;
''PatchOperationInsert'' adds a sibling to the selected node.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
  &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
    &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
    &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
    &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
  &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationInsert&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;xpath&amp;gt;Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
  &amp;lt;value&amp;gt;&lt;br /&gt;
    &amp;lt;anotherExample&amp;gt;A new sibling&amp;lt;/anotherExample&amp;gt;&lt;br /&gt;
  &amp;lt;/value&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
  &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
    &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
    &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
    &amp;lt;anotherExample&amp;gt;A new sibling&amp;lt;/anotherExample&amp;gt;&lt;br /&gt;
    &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
  &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationRemove===&lt;br /&gt;
''PatchOperationRemove'' removes the selected node.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationRemove&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationReplace===&lt;br /&gt;
''PatchOperationReplace'' replaces the selected node.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationReplace&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;value&amp;gt;&lt;br /&gt;
        &amp;lt;anotherExample&amp;gt;An alternate node&amp;lt;/anotherExample&amp;gt;&lt;br /&gt;
    &amp;lt;/value&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;anotherExample&amp;gt;An alternate node&amp;lt;/anotherExample&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationAttributeAdd===&lt;br /&gt;
''PatchOperationAttributeAdd'' will add an attribute and set its value, but only if that attribute is not yet present.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationAttributeAdd&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;attribute&amp;gt;ExampleAttribute&amp;lt;/attribute&amp;gt;&lt;br /&gt;
    &amp;lt;value&amp;gt;ExampleValue&amp;lt;/value&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode ExampleAttribute&amp;quot;ExampleValue&amp;quot;&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationAttributeSet===&lt;br /&gt;
''PatchOperationAttributeSet'' will add an attribute and set its value. Unlike PatchAttributeAdd, PatchOperationAttributeSet will overwrite any existing value. &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode ExampleAttribute&amp;quot;ExampleValue&amp;quot;&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationAttributeSet&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;attribute&amp;gt;ExampleAttribute&amp;lt;/attribute&amp;gt;&lt;br /&gt;
    &amp;lt;value&amp;gt;DifferentExampleValue&amp;lt;/value&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode ExampleAttribute&amp;quot;DifferentExampleValue&amp;quot;&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationAttributeRemove===&lt;br /&gt;
''PatchOperationAttributeRemove'' removes the specified attribute.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode ExampleAttribute&amp;quot;ExampleValue&amp;quot;&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationAttributeRemove&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;attribute&amp;gt;ExampleAttribute&amp;lt;/attribute&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationAddModExtension===&lt;br /&gt;
{{Main|Modding Tutorials/DefModExtension}}&lt;br /&gt;
''PatchOperationAddModExtension'' adds a [[Modding Tutorials/DefModExtension|Mod Extension]].&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationAddModExtension&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;value&amp;gt;&lt;br /&gt;
        &amp;lt;li Class=&amp;quot;ExampleNameSpace.ExampleModExtension&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;exampleValue&amp;gt;true&amp;lt;/exampleValue&amp;gt;&lt;br /&gt;
        &amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;/value&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
        &amp;lt;modExtensions&amp;gt;&lt;br /&gt;
            &amp;lt;li Class=&amp;quot;ExampleNameSpace.ExampleModExtension&amp;quot;&amp;gt;&lt;br /&gt;
                &amp;lt;exampleValue&amp;gt;true&amp;lt;/exampleValue&amp;gt;&lt;br /&gt;
            &amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;/modExtensions&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationSetName===&lt;br /&gt;
''PatchOperationSetName'' changes the name of a node.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationSetName&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;name&amp;gt;newExampleName&amp;lt;/name&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;newExampleName&amp;gt;Some text&amp;lt;/newExampleName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationSequence===&lt;br /&gt;
''PatchOperationSequence'' will complete all operations in the order of their listing, and stop when any of them fails.&lt;br /&gt;
&lt;br /&gt;
===PatchOperationTest===&lt;br /&gt;
''PatchOperationTest'' tests for the existence/validity of an xpath. Useful to stop a PatchOperationSequence. Often used as a simpler, less powerful version of PatchOperationConditional.&lt;br /&gt;
The following example patch is from Apparello, by Shinzy. &lt;br /&gt;
&amp;lt;source lang =&amp;quot;xml&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationSequence&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;!-- check for worn graphics and if none found, add one --&amp;gt;&lt;br /&gt;
    &amp;lt;success&amp;gt;Always&amp;lt;/success&amp;gt;&lt;br /&gt;
    &amp;lt;operations&amp;gt;&lt;br /&gt;
        &amp;lt;li Class=&amp;quot;PatchOperationTest&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;xpath&amp;gt;/Defs/ThingDef[defName = &amp;quot;Apparel_Pants&amp;quot;]/apparel/wornGraphicPath&amp;lt;/xpath&amp;gt;&lt;br /&gt;
            &amp;lt;success&amp;gt;Invert&amp;lt;/success&amp;gt;&lt;br /&gt;
        &amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;li Class=&amp;quot;PatchOperationAdd&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;xpath&amp;gt;/Defs/ThingDef[defName = &amp;quot;Apparel_Pants&amp;quot;]/apparel&amp;lt;/xpath&amp;gt;&lt;br /&gt;
            &amp;lt;value&amp;gt;&lt;br /&gt;
                &amp;lt;wornGraphicPath&amp;gt;Accessorello/Pants/Pants&amp;lt;/wornGraphicPath&amp;gt;&lt;br /&gt;
            &amp;lt;/value&amp;gt;&lt;br /&gt;
        &amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;/operations&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===PatchOperationConditional===&lt;br /&gt;
''PatchOperationConditional'' can branch logic based on a match/nomatch. The following example patch adds a &amp;lt;comps&amp;gt; node if it does not yet exist, and adds itself &lt;br /&gt;
&lt;br /&gt;
This patch is courtesy Mehni. [https://github.com/Mehni/MoreFactionInteraction/blob/ab3ab2a22ee529ee4e38a471fe150fd48fd07ce9/Patches/MoreFactionInteraction.xml#L40-L62 See original.]&lt;br /&gt;
&amp;lt;source lang =&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!-- Add /comps/li/compClass if there are no comps yet. --&amp;gt;&lt;br /&gt;
&amp;lt;!-- Add /li/compClass to /comps if exists (i.e. other mod already added the comps field first) --&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationConditional&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;/Defs/WorldObjectDef[defName=&amp;quot;Caravan&amp;quot;]/comps&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;nomatch Class=&amp;quot;PatchOperationAdd&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;xpath&amp;gt;/Defs/WorldObjectDef[defName=&amp;quot;Caravan&amp;quot;]&amp;lt;/xpath&amp;gt;&lt;br /&gt;
        &amp;lt;value&amp;gt;&lt;br /&gt;
            &amp;lt;comps&amp;gt;&lt;br /&gt;
                &amp;lt;li&amp;gt;&lt;br /&gt;
                    &amp;lt;compClass&amp;gt;MoreFactionInteraction.WorldObjectComp_CaravanComp&amp;lt;/compClass&amp;gt;&lt;br /&gt;
                &amp;lt;/li&amp;gt;&lt;br /&gt;
            &amp;lt;/comps&amp;gt;&lt;br /&gt;
        &amp;lt;/value&amp;gt;&lt;br /&gt;
    &amp;lt;/nomatch&amp;gt;&lt;br /&gt;
    &amp;lt;match Class=&amp;quot;PatchOperationAdd&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;xpath&amp;gt;/Defs/WorldObjectDef[defName=&amp;quot;Caravan&amp;quot;]/comps&amp;lt;/xpath&amp;gt;&lt;br /&gt;
        &amp;lt;value&amp;gt;&lt;br /&gt;
            &amp;lt;li&amp;gt;&lt;br /&gt;
                &amp;lt;compClass&amp;gt;MoreFactionInteraction.WorldObjectComp_CaravanComp&amp;lt;/compClass&amp;gt;&lt;br /&gt;
            &amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;/value&amp;gt;&lt;br /&gt;
    &amp;lt;/match&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===PatchOperationFindMod===&lt;br /&gt;
''PatchOperationFindMod'' searches the list of active mods for the mods listed in &amp;lt;nowiki&amp;gt;&amp;lt;li&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/nowiki&amp;gt; tags.&lt;br /&gt;
&lt;br /&gt;
For a successful match, &amp;lt;nowiki&amp;gt;&amp;lt;li&amp;gt;ModName&amp;lt;/li&amp;gt;&amp;lt;/nowiki&amp;gt; has to match the &amp;lt;name&amp;gt;ModName&amp;lt;/name&amp;gt; in the About.xml of the mod you base your patch behaviour on.&lt;br /&gt;
This (shortened) patch is courtesy Mehni. [https://github.com/Mehni/MoreFactionInteraction/blob/ab3ab2a22ee529ee4e38a471fe150fd48fd07ce9/Patches/MoreFactionInteraction.xml#L64 See original.]&lt;br /&gt;
&lt;br /&gt;
The following Patch adds the RimQuest mod extension to the listed Defs when RimQuest is found.&lt;br /&gt;
&amp;lt;source lang =&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationFindMod&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;mods&amp;gt;&lt;br /&gt;
        &amp;lt;li&amp;gt;RimQuest&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;/mods&amp;gt;&lt;br /&gt;
    &amp;lt;match Class=&amp;quot;PatchOperationAddModExtension&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;xpath&amp;gt;Defs/IncidentDef[defName=&amp;quot;MFI_DiplomaticMarriage&amp;quot; or defName=&amp;quot;MFI_HuntersLodge&amp;quot; or defName=&amp;quot;MFI_Quest_PeaceTalks&amp;quot;]&amp;lt;/xpath&amp;gt;&lt;br /&gt;
        &amp;lt;value&amp;gt;&lt;br /&gt;
            &amp;lt;li Class = &amp;quot;RimQuest.RimQuest_ModExtension&amp;quot;&amp;gt;&lt;br /&gt;
                &amp;lt;canBeARimQuest&amp;gt;false&amp;lt;/canBeARimQuest&amp;gt;&lt;br /&gt;
            &amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;/value&amp;gt;&lt;br /&gt;
    &amp;lt;/match&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following Patch replace the tabWindowClass of the xpath when Relations Tab is '''not''' found. &lt;br /&gt;
&amp;lt;source lang =&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationFindMod&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;mods&amp;gt;&lt;br /&gt;
        &amp;lt;li&amp;gt;Relations Tab&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;/mods&amp;gt;&lt;br /&gt;
    &amp;lt;nomatch Class=&amp;quot;PatchOperationReplace&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;xpath&amp;gt;/Defs/MainButtonDef[defName=&amp;quot;Factions&amp;quot;]/tabWindowClass&amp;lt;/xpath&amp;gt;&lt;br /&gt;
        &amp;lt;value&amp;gt;&lt;br /&gt;
            &amp;lt;tabWindowClass&amp;gt;MyNameSpace.MyTabWindowClass&amp;lt;/tabWindowClass&amp;gt;&lt;br /&gt;
        &amp;lt;/value&amp;gt;&lt;br /&gt;
    &amp;lt;/nomatch&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Some advanced examples==&lt;br /&gt;
This (shortened) patch is courtesy XeoNovaDan. [https://github.com/XeoNovaDan/SurvivalTools/blob/62a4316c81733dde417257bf4bc5c34e3e781c7d/Patches/ExpandedWoodworkingVGP/Patch.xml See original]. Viewer discretion is advised. Parents please take precautions if young children are present.&lt;br /&gt;
&amp;lt;source lang = &amp;quot;XML&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationFindMod&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;mods&amp;gt;&lt;br /&gt;
        &amp;lt;li&amp;gt;Expanded Woodworking for Vegetable Garden Project&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;/mods&amp;gt;&lt;br /&gt;
    &amp;lt;match Class=&amp;quot;PatchOperationSequence&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;success&amp;gt;Always&amp;lt;/success&amp;gt;&lt;br /&gt;
        &amp;lt;operations&amp;gt;&lt;br /&gt;
            &amp;lt;!-- Nested PatchOpFindMod. Used because Expanded Woodworking adds more Wood when VGP Xtra is installed. --&amp;gt;&lt;br /&gt;
            &amp;lt;li Class=&amp;quot;PatchOperationFindMod&amp;quot;&amp;gt;&lt;br /&gt;
                &amp;lt;mods&amp;gt;&lt;br /&gt;
                    &amp;lt;li&amp;gt;VGP Xtra Trees and Flowers&amp;lt;/li&amp;gt;&lt;br /&gt;
                &amp;lt;/mods&amp;gt;&lt;br /&gt;
                &amp;lt;match Class=&amp;quot;PatchOperationSequence&amp;quot;&amp;gt;&lt;br /&gt;
                    &amp;lt;success&amp;gt;Always&amp;lt;/success&amp;gt;&lt;br /&gt;
                    &amp;lt;operations&amp;gt;&lt;br /&gt;
                        &amp;lt;!-- Processed camellia lumber. Mostly useful for building long-lasting, simple structures and furniture.--&amp;gt;&lt;br /&gt;
                        &amp;lt;li Class=&amp;quot;PatchOperationAddModExtension&amp;quot;&amp;gt;&lt;br /&gt;
                            &amp;lt;xpath&amp;gt;Defs/ThingDef[defName=&amp;quot;LumberCamellia&amp;quot;]&amp;lt;/xpath&amp;gt;&lt;br /&gt;
                            &amp;lt;value&amp;gt;&lt;br /&gt;
                                &amp;lt;li Class=&amp;quot;SurvivalTools.StuffPropsTool&amp;quot;&amp;gt;&lt;br /&gt;
                                    &amp;lt;toolStatFactors&amp;gt;&lt;br /&gt;
                                        &amp;lt;ConstructionSpeed&amp;gt;0.55&amp;lt;/ConstructionSpeed&amp;gt;&lt;br /&gt;
                                    &amp;lt;/toolStatFactors&amp;gt;&lt;br /&gt;
                                &amp;lt;/li&amp;gt;&lt;br /&gt;
                            &amp;lt;/value&amp;gt;&lt;br /&gt;
                        &amp;lt;/li&amp;gt;&lt;br /&gt;
                    &amp;lt;/operations&amp;gt;&lt;br /&gt;
                &amp;lt;/match&amp;gt;&lt;br /&gt;
            &amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;/operations&amp;gt;&lt;br /&gt;
    &amp;lt;/match&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Random stuff===&lt;br /&gt;
* @ select by attribute. Useful for patching (Abstract) bases. &amp;lt;source lang = &amp;quot;xml&amp;quot;&amp;gt;/Defs/ThingDef[@Name=&amp;quot;BuildingBase&amp;quot;]&amp;lt;/source&amp;gt;&lt;br /&gt;
* ''or'' is inclusive. &amp;lt;source lang = &amp;quot;xml&amp;quot;&amp;gt;/Defs/ThingDef[defName=&amp;quot;Cassowary&amp;quot; or defName = &amp;quot;Emu&amp;quot; or defName = &amp;quot;Ostrich&amp;quot; or defName = &amp;quot;Turkey&amp;quot;]&amp;lt;/source&amp;gt; selects all of those in a single (faster) operation.&lt;br /&gt;
* PatchOperationAdd and PatchOperation insert have an ''order'' tag which allows you to either Prepend or Append your add. Default behaviour of Add is to Append, insert Prepends.&lt;br /&gt;
* There is a ''success'' tag whose values can be Normal, Invert, Always and Never. This is used for the sake of error reporting: by default an error is logged when a patch fails to apply. For PatchOperationSequences and PatchOperationTests, you can set success to Always to avoid error logging.&lt;br /&gt;
&lt;br /&gt;
== Write your own ==&lt;br /&gt;
Outside the scope of this wiki, but it's possible to write your own PatchOperation.&amp;lt;/br&amp;gt;&lt;br /&gt;
- [https://github.com/NoImageAvailable/CombatExtended/blob/88ef1f86d30e6c285e3370bd9faafa92c84195b0/Source/CombatExtended/CombatExtended/PatchOperationMakeGunCECompatible.cs Example PatchOperationMakeGunCECompatible]&amp;lt;/br&amp;gt;&lt;br /&gt;
- [https://gist.github.com/Lanilor/e326e33e268e78f68a2f5cd3cdbbe8c0 Example PatchOperationAddOrReplace]&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Resources ==&lt;br /&gt;
&lt;br /&gt;
The best tutorial on PatchOperations created by Zhentar: [https://gist.github.com/Zhentar/4a1b71cea45b9337f70b30a21d868782 Introduction to PatchOperation]&lt;br /&gt;
&lt;br /&gt;
You can also learn about XPaths here: [https://www.w3schools.com/xml/xpath_intro.asp XPath tutorial]&lt;br /&gt;
&lt;br /&gt;
There is also an [https://github.com/roxxploxx/RimWorldModGuide/wiki/SHORTTUTORIAL:-DefPatches Overview of PatchOperations]  on the [https://github.com/roxxploxx/RimWorldModGuide/wiki RimWorldModGuide].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Modding]]&lt;/div&gt;</summary>
		<author><name>Lilwhitemouse</name></author>
	</entry>
	<entry>
		<id>https://rimworldwiki.com/index.php?title=Modding_Tutorials/PatchOperations&amp;diff=62520</id>
		<title>Modding Tutorials/PatchOperations</title>
		<link rel="alternate" type="text/html" href="https://rimworldwiki.com/index.php?title=Modding_Tutorials/PatchOperations&amp;diff=62520"/>
		<updated>2019-02-04T17:32:33Z</updated>

		<summary type="html">&lt;p&gt;Lilwhitemouse: Added another leading / - keeps xpath from looking for &amp;quot;Defs&amp;quot; in subnodes &amp;gt;&amp;lt;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{BackToTutorials}}&lt;br /&gt;
&lt;br /&gt;
RimWorld Alpha 17 added a new modding feature: '''XML PatchOperations'''. Using these allows mods to edit specific elements of XML defs, rather than simply overwriting the old def with a new one, which was the required approach until A17. This greatly reduces mod conflicts, because mods that make separate changes to the same def won't necessarily overwrite one another's changes. Mods using PatchOperations can avoid requiring special compatibility mods, and can even add special features conditional on other mods being loaded.&lt;br /&gt;
&lt;br /&gt;
Here's a simple example of replacing the texture path for deep water:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot; ?&amp;gt;&lt;br /&gt;
&amp;lt;Patch&amp;gt;&lt;br /&gt;
  &amp;lt;Operation Class=&amp;quot;PatchOperationReplace&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;/Defs/TerrainDef[defName=&amp;quot;WaterDeep&amp;quot;]/texturePath&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;value&amp;gt;&lt;br /&gt;
      &amp;lt;texturePath&amp;gt;Your/Texture/Path/Here&amp;lt;/texturePath&amp;gt;&lt;br /&gt;
    &amp;lt;/value&amp;gt;&lt;br /&gt;
  &amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/Patch&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
This xml file simply goes inside YourMod/Patches/ and you're done.&lt;br /&gt;
&lt;br /&gt;
== Overview of available PatchOperations ==&lt;br /&gt;
These are the available PatchOperation types:&lt;br /&gt;
&lt;br /&gt;
* Four do basic operations on XML nodes:&lt;br /&gt;
** '''[[#PatchOperationAdd|PatchOperationAdd]]''' adds a provided child node to the selected node&lt;br /&gt;
** '''[[#PatchOperationInsert|PatchOperationInsert]]''' adds a provided sibling node to the selected node&lt;br /&gt;
** '''[[#PatchOperationRemove|PatchOperationRemove]]''' deletes the selected node&lt;br /&gt;
** '''[[#PatchOperationReplace|PatchOperationReplace]]''' replaces the selected node with the provided node&lt;br /&gt;
* Three do basic operations on XML attributes:&lt;br /&gt;
** '''[[#PatchOperationAttributeAdd|PatchOperationAttributeAdd]]''' adds a provided attribute to the selected node if and only if the attribute name is not already present&lt;br /&gt;
** '''[[#PatchOperationAttributeSet|PatchOperationAttributeSet]]''' sets a provided attribute for the selected node, overwriting the attribute value if the attribute name is already present&lt;br /&gt;
** '''[[#PatchOperationAttributeRemove|PatchOperationAttributeRemove]]''' removes an attribute for the selected node&lt;br /&gt;
* Three allow for more complex operations:&lt;br /&gt;
** '''[[#PatchOperationAddModExtension|PatchOperationAddModExtension]]''' adds a ModExtension.&lt;br /&gt;
** '''[[#PatchOperationSetName|PatchOperationSetName]]''' changes the name of a node.&lt;br /&gt;
** '''[[#PatchOperationSequence|PatchOperationSequence]]''' contains a set of other PatchOperations, and aborts upon any operation failing&lt;br /&gt;
* Three allow for conditional operations&lt;br /&gt;
** '''[[#PatchOperationTest|PatchOperationTest]]''' tests nodes, which is useful inside a PatchOperationSequence&lt;br /&gt;
** '''[[#PatchOperationConditional|PatchOperationConditional]]''' tests nodes, and can do different operations depending on the result.&lt;br /&gt;
** '''[[#PatchOperationFindMod|PatchOperationFindMod]]''' tests for the presence of another mod, and can do different operations depending on the result.&lt;br /&gt;
&lt;br /&gt;
==XPath syntax==&lt;br /&gt;
Each PatchOperation must specify an XML node to modify. It uses XPaths to specify them. An XPath is a &amp;quot;path&amp;quot; for the patch to follow when trying to find XML nodes matching the description. It will follow each part of the path from left to right. Note that these &amp;quot;paths&amp;quot; have zero relation to the file path or folder structure: They follow the structure of the XML nodes.&lt;br /&gt;
&lt;br /&gt;
XPaths start at the root node. Since the root node of all Defs is enforced to be &amp;lt;Defs&amp;gt;, so &amp;lt;code&amp;gt;/Defs/&amp;lt;/code&amp;gt; is the start of our xpath. &amp;lt;code&amp;gt;*/&amp;lt;/code&amp;gt; is also valid, as it uses the &amp;lt;code&amp;gt;*&amp;lt;/code&amp;gt; wildcard: &amp;lt;code&amp;gt;*&amp;lt;/code&amp;gt; matches any element, so it'll match the root (the top level) of the XML tree. &amp;lt;code&amp;gt;//&amp;lt;/code&amp;gt; is technically also valid, but because that construct selects ''all'' the elements in the XML tree, it's an expensive operation that makes game loading exponentially slower.&lt;br /&gt;
&lt;br /&gt;
Once the root is selected, the XPath lets the system walk down specific branches of the tree. If we use the example from the lead, we get a specific path:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;/Defs/TerrainDef[defName=&amp;quot;WaterDeep&amp;quot;]/texturePath&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# The root node is selected&lt;br /&gt;
# All child nodes of the root node called &amp;quot;TerrainDef&amp;quot; are selected&lt;br /&gt;
# We narrow down from &amp;quot;all TerrainDefs&amp;quot; to only those with the child &amp;quot;defName&amp;quot; node whose value is &amp;quot;WaterDeep&amp;quot;, which should give us exactly one node because defNames must be unique&lt;br /&gt;
# We select the child node &amp;quot;texturePath&amp;quot; from this node&lt;br /&gt;
## Note that we cannot put &amp;lt;code&amp;gt;.../texturePath/&amp;lt;/code&amp;gt; to specify the content of the texturePath node.  If we want to replace texturePath, we have to replace it with &amp;lt;code&amp;gt;&amp;lt;texturePath&amp;gt;/new/path/to/texture&amp;lt;/texturePath&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more info, see this {{LudeonThread|32785}}. XPath is a [https://www.w3schools.com/xml/xml_xpath.asp well-documented industry standard] (good resource, too); there are plenty of resources available on the subject ranging from exhaustive tutorials to simple [https://stackoverflow.com/questions/tagged/xpath StackOverflow] questions.&lt;br /&gt;
&lt;br /&gt;
==&amp;quot;Success&amp;quot; option==&lt;br /&gt;
The ''&amp;lt;code&amp;gt;&amp;lt;success&amp;gt;...&amp;lt;/success&amp;gt;&amp;lt;/code&amp;gt;'' term specifies whether the entire operation is considered a success or not.  If the overall patch operation is not considered a success, an error is thrown.  This is particularly used in Sequences and Tests.&lt;br /&gt;
&lt;br /&gt;
Options available are:&lt;br /&gt;
* Always - this patch operation is considered a success - sometimes used for Sequences so that if an early test in the sequence fails, an error is not reported (because the sequence is still a successful patch)&lt;br /&gt;
* Normal - this patch operation is considered a success if it succeeded (content patched, test passed, etc)&lt;br /&gt;
* Invert - If the patch failed (e.g., a test), then it's considered a success (useful for a negative test in a sequence)&lt;br /&gt;
* Never - this patch operation &amp;quot;failed.&amp;quot;  Even if it patched whatever it was supposed to correctly.  If you ever use this, leave a note here for the curious.&lt;br /&gt;
&lt;br /&gt;
==Overview of individual PatchOperations==&lt;br /&gt;
===PatchOperationAdd===&lt;br /&gt;
''PatchOperationAdd'' adds a child node to the selected node.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationAdd&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleList&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;value&amp;gt;&lt;br /&gt;
        &amp;lt;li&amp;gt;Foo&amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;li&amp;gt;Bar&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;/value&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList&amp;gt;&lt;br /&gt;
            &amp;lt;li&amp;gt;Foo&amp;lt;/li&amp;gt;&lt;br /&gt;
            &amp;lt;li&amp;gt;Bar&amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;/exampleList&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationInsert===&lt;br /&gt;
''PatchOperationInsert'' adds a sibling to the selected node.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationInsert&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;value&amp;gt;&lt;br /&gt;
        &amp;lt;anotherExample&amp;gt;A new sibling&amp;lt;/anotherExample&amp;gt;&lt;br /&gt;
    &amp;lt;/value&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;anotherExample&amp;gt;A new sibling&amp;lt;/anotherExample&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationRemove===&lt;br /&gt;
''PatchOperationRemove'' removes the selected node.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationRemove&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationReplace===&lt;br /&gt;
''PatchOperationReplace'' replaces the selected node.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationReplace&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;value&amp;gt;&lt;br /&gt;
        &amp;lt;anotherExample&amp;gt;An alternate node&amp;lt;/anotherExample&amp;gt;&lt;br /&gt;
    &amp;lt;/value&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;anotherExample&amp;gt;An alternate node&amp;lt;/anotherExample&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationAttributeAdd===&lt;br /&gt;
''PatchOperationAttributeAdd'' will add an attribute and set its value, but only if that attribute is not yet present.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationAttributeAdd&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;attribute&amp;gt;ExampleAttribute&amp;lt;/attribute&amp;gt;&lt;br /&gt;
    &amp;lt;value&amp;gt;ExampleValue&amp;lt;/value&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode ExampleAttribute&amp;quot;ExampleValue&amp;quot;&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationAttributeSet===&lt;br /&gt;
''PatchOperationAttributeSet'' will add an attribute and set its value. Unlike PatchAttributeAdd, PatchOperationAttributeSet will overwrite any existing value. &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode ExampleAttribute&amp;quot;ExampleValue&amp;quot;&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationAttributeSet&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;attribute&amp;gt;ExampleAttribute&amp;lt;/attribute&amp;gt;&lt;br /&gt;
    &amp;lt;value&amp;gt;DifferentExampleValue&amp;lt;/value&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode ExampleAttribute&amp;quot;DifferentExampleValue&amp;quot;&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationAttributeRemove===&lt;br /&gt;
''PatchOperationAttributeRemove'' removes the specified attribute.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode ExampleAttribute&amp;quot;ExampleValue&amp;quot;&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationAttributeRemove&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;attribute&amp;gt;ExampleAttribute&amp;lt;/attribute&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationAddModExtension===&lt;br /&gt;
{{Main|Modding Tutorials/DefModExtension}}&lt;br /&gt;
''PatchOperationAddModExtension'' adds a [[Modding Tutorials/DefModExtension|Mod Extension]].&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationAddModExtension&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;value&amp;gt;&lt;br /&gt;
        &amp;lt;li Class=&amp;quot;ExampleNameSpace.ExampleModExtension&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;exampleValue&amp;gt;true&amp;lt;/exampleValue&amp;gt;&lt;br /&gt;
        &amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;/value&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
        &amp;lt;modExtensions&amp;gt;&lt;br /&gt;
            &amp;lt;li Class=&amp;quot;ExampleNameSpace.ExampleModExtension&amp;quot;&amp;gt;&lt;br /&gt;
                &amp;lt;exampleValue&amp;gt;true&amp;lt;/exampleValue&amp;gt;&lt;br /&gt;
            &amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;/modExtensions&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationSetName===&lt;br /&gt;
''PatchOperationSetName'' changes the name of a node.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationSetName&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;name&amp;gt;newExampleName&amp;lt;/name&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;newExampleName&amp;gt;Some text&amp;lt;/newExampleName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationSequence===&lt;br /&gt;
''PatchOperationSequence'' will complete all operations in the order of their listing, and stop when any of them fails.&lt;br /&gt;
&lt;br /&gt;
===PatchOperationTest===&lt;br /&gt;
''PatchOperationTest'' tests for the existence/validity of an xpath. Useful to stop a PatchOperationSequence. Often used as a simpler, less powerful version of PatchOperationConditional.&lt;br /&gt;
The following example patch is from Apparello, by Shinzy. &lt;br /&gt;
&amp;lt;source lang =&amp;quot;xml&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationSequence&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;!-- check for worn graphics and if none found, add one --&amp;gt;&lt;br /&gt;
    &amp;lt;success&amp;gt;Always&amp;lt;/success&amp;gt;&lt;br /&gt;
    &amp;lt;operations&amp;gt;&lt;br /&gt;
        &amp;lt;li Class=&amp;quot;PatchOperationTest&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;xpath&amp;gt;/Defs/ThingDef[defName = &amp;quot;Apparel_Pants&amp;quot;]/apparel/wornGraphicPath&amp;lt;/xpath&amp;gt;&lt;br /&gt;
            &amp;lt;success&amp;gt;Invert&amp;lt;/success&amp;gt;&lt;br /&gt;
        &amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;li Class=&amp;quot;PatchOperationAdd&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;xpath&amp;gt;/Defs/ThingDef[defName = &amp;quot;Apparel_Pants&amp;quot;]/apparel&amp;lt;/xpath&amp;gt;&lt;br /&gt;
            &amp;lt;value&amp;gt;&lt;br /&gt;
                &amp;lt;wornGraphicPath&amp;gt;Accessorello/Pants/Pants&amp;lt;/wornGraphicPath&amp;gt;&lt;br /&gt;
            &amp;lt;/value&amp;gt;&lt;br /&gt;
        &amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;/operations&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===PatchOperationConditional===&lt;br /&gt;
''PatchOperationConditional'' can branch logic based on a match/nomatch. The following example patch adds a &amp;lt;comps&amp;gt; node if it does not yet exist, and adds itself &lt;br /&gt;
&lt;br /&gt;
This patch is courtesy Mehni. [https://github.com/Mehni/MoreFactionInteraction/blob/ab3ab2a22ee529ee4e38a471fe150fd48fd07ce9/Patches/MoreFactionInteraction.xml#L40-L62 See original.]&lt;br /&gt;
&amp;lt;source lang =&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!-- Add /comps/li/compClass if there are no comps yet. --&amp;gt;&lt;br /&gt;
&amp;lt;!-- Add /li/compClass to /comps if exists (i.e. other mod already added the comps field first) --&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationConditional&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;/Defs/WorldObjectDef[defName=&amp;quot;Caravan&amp;quot;]/comps&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;nomatch Class=&amp;quot;PatchOperationAdd&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;xpath&amp;gt;/Defs/WorldObjectDef[defName=&amp;quot;Caravan&amp;quot;]&amp;lt;/xpath&amp;gt;&lt;br /&gt;
        &amp;lt;value&amp;gt;&lt;br /&gt;
            &amp;lt;comps&amp;gt;&lt;br /&gt;
                &amp;lt;li&amp;gt;&lt;br /&gt;
                    &amp;lt;compClass&amp;gt;MoreFactionInteraction.WorldObjectComp_CaravanComp&amp;lt;/compClass&amp;gt;&lt;br /&gt;
                &amp;lt;/li&amp;gt;&lt;br /&gt;
            &amp;lt;/comps&amp;gt;&lt;br /&gt;
        &amp;lt;/value&amp;gt;&lt;br /&gt;
    &amp;lt;/nomatch&amp;gt;&lt;br /&gt;
    &amp;lt;match Class=&amp;quot;PatchOperationAdd&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;xpath&amp;gt;/Defs/WorldObjectDef[defName=&amp;quot;Caravan&amp;quot;]/comps&amp;lt;/xpath&amp;gt;&lt;br /&gt;
        &amp;lt;value&amp;gt;&lt;br /&gt;
            &amp;lt;li&amp;gt;&lt;br /&gt;
                &amp;lt;compClass&amp;gt;MoreFactionInteraction.WorldObjectComp_CaravanComp&amp;lt;/compClass&amp;gt;&lt;br /&gt;
            &amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;/value&amp;gt;&lt;br /&gt;
    &amp;lt;/match&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===PatchOperationFindMod===&lt;br /&gt;
''PatchOperationFindMod'' searches the list of active mods for the mods listed in &amp;lt;nowiki&amp;gt;&amp;lt;li&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/nowiki&amp;gt; tags.&lt;br /&gt;
&lt;br /&gt;
For a successful match, &amp;lt;nowiki&amp;gt;&amp;lt;li&amp;gt;ModName&amp;lt;/li&amp;gt;&amp;lt;/nowiki&amp;gt; has to match the &amp;lt;name&amp;gt;ModName&amp;lt;/name&amp;gt; in the About.xml of the mod you base your patch behaviour on.&lt;br /&gt;
This (shortened) patch is courtesy Mehni. [https://github.com/Mehni/MoreFactionInteraction/blob/ab3ab2a22ee529ee4e38a471fe150fd48fd07ce9/Patches/MoreFactionInteraction.xml#L64 See original.]&lt;br /&gt;
&lt;br /&gt;
The following Patch adds the RimQuest mod extension to the listed Defs when RimQuest is found.&lt;br /&gt;
&amp;lt;source lang =&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationFindMod&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;mods&amp;gt;&lt;br /&gt;
        &amp;lt;li&amp;gt;RimQuest&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;/mods&amp;gt;&lt;br /&gt;
    &amp;lt;match Class=&amp;quot;PatchOperationAddModExtension&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;xpath&amp;gt;Defs/IncidentDef[defName=&amp;quot;MFI_DiplomaticMarriage&amp;quot; or defName=&amp;quot;MFI_HuntersLodge&amp;quot; or defName=&amp;quot;MFI_Quest_PeaceTalks&amp;quot;]&amp;lt;/xpath&amp;gt;&lt;br /&gt;
        &amp;lt;value&amp;gt;&lt;br /&gt;
            &amp;lt;li Class = &amp;quot;RimQuest.RimQuest_ModExtension&amp;quot;&amp;gt;&lt;br /&gt;
                &amp;lt;canBeARimQuest&amp;gt;false&amp;lt;/canBeARimQuest&amp;gt;&lt;br /&gt;
            &amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;/value&amp;gt;&lt;br /&gt;
    &amp;lt;/match&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following Patch replace the tabWindowClass of the xpath when Relations Tab is '''not''' found. &lt;br /&gt;
&amp;lt;source lang =&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationFindMod&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;mods&amp;gt;&lt;br /&gt;
        &amp;lt;li&amp;gt;Relations Tab&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;/mods&amp;gt;&lt;br /&gt;
    &amp;lt;nomatch Class=&amp;quot;PatchOperationReplace&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;xpath&amp;gt;/Defs/MainButtonDef[defName=&amp;quot;Factions&amp;quot;]/tabWindowClass&amp;lt;/xpath&amp;gt;&lt;br /&gt;
        &amp;lt;value&amp;gt;&lt;br /&gt;
            &amp;lt;tabWindowClass&amp;gt;MyNameSpace.MyTabWindowClass&amp;lt;/tabWindowClass&amp;gt;&lt;br /&gt;
        &amp;lt;/value&amp;gt;&lt;br /&gt;
    &amp;lt;/nomatch&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Some advanced examples==&lt;br /&gt;
This (shortened) patch is courtesy XeoNovaDan. [https://github.com/XeoNovaDan/SurvivalTools/blob/62a4316c81733dde417257bf4bc5c34e3e781c7d/Patches/ExpandedWoodworkingVGP/Patch.xml See original]. Viewer discretion is advised. Parents please take precautions if young children are present.&lt;br /&gt;
&amp;lt;source lang = &amp;quot;XML&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationFindMod&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;mods&amp;gt;&lt;br /&gt;
        &amp;lt;li&amp;gt;Expanded Woodworking for Vegetable Garden Project&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;/mods&amp;gt;&lt;br /&gt;
    &amp;lt;match Class=&amp;quot;PatchOperationSequence&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;success&amp;gt;Always&amp;lt;/success&amp;gt;&lt;br /&gt;
        &amp;lt;operations&amp;gt;&lt;br /&gt;
            &amp;lt;!-- Nested PatchOpFindMod. Used because Expanded Woodworking adds more Wood when VGP Xtra is installed. --&amp;gt;&lt;br /&gt;
            &amp;lt;li Class=&amp;quot;PatchOperationFindMod&amp;quot;&amp;gt;&lt;br /&gt;
                &amp;lt;mods&amp;gt;&lt;br /&gt;
                    &amp;lt;li&amp;gt;VGP Xtra Trees and Flowers&amp;lt;/li&amp;gt;&lt;br /&gt;
                &amp;lt;/mods&amp;gt;&lt;br /&gt;
                &amp;lt;match Class=&amp;quot;PatchOperationSequence&amp;quot;&amp;gt;&lt;br /&gt;
                    &amp;lt;success&amp;gt;Always&amp;lt;/success&amp;gt;&lt;br /&gt;
                    &amp;lt;operations&amp;gt;&lt;br /&gt;
                        &amp;lt;!-- Processed camellia lumber. Mostly useful for building long-lasting, simple structures and furniture.--&amp;gt;&lt;br /&gt;
                        &amp;lt;li Class=&amp;quot;PatchOperationAddModExtension&amp;quot;&amp;gt;&lt;br /&gt;
                            &amp;lt;xpath&amp;gt;Defs/ThingDef[defName=&amp;quot;LumberCamellia&amp;quot;]&amp;lt;/xpath&amp;gt;&lt;br /&gt;
                            &amp;lt;value&amp;gt;&lt;br /&gt;
                                &amp;lt;li Class=&amp;quot;SurvivalTools.StuffPropsTool&amp;quot;&amp;gt;&lt;br /&gt;
                                    &amp;lt;toolStatFactors&amp;gt;&lt;br /&gt;
                                        &amp;lt;ConstructionSpeed&amp;gt;0.55&amp;lt;/ConstructionSpeed&amp;gt;&lt;br /&gt;
                                    &amp;lt;/toolStatFactors&amp;gt;&lt;br /&gt;
                                &amp;lt;/li&amp;gt;&lt;br /&gt;
                            &amp;lt;/value&amp;gt;&lt;br /&gt;
                        &amp;lt;/li&amp;gt;&lt;br /&gt;
                    &amp;lt;/operations&amp;gt;&lt;br /&gt;
                &amp;lt;/match&amp;gt;&lt;br /&gt;
            &amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;/operations&amp;gt;&lt;br /&gt;
    &amp;lt;/match&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Random stuff===&lt;br /&gt;
* @ select by attribute. Useful for patching (Abstract) bases. &amp;lt;source lang = &amp;quot;xml&amp;quot;&amp;gt;/Defs/ThingDef[@Name=&amp;quot;BuildingBase&amp;quot;]&amp;lt;/source&amp;gt;&lt;br /&gt;
* ''or'' is inclusive. &amp;lt;source lang = &amp;quot;xml&amp;quot;&amp;gt;/Defs/ThingDef[defName=&amp;quot;Cassowary&amp;quot; or defName = &amp;quot;Emu&amp;quot; or defName = &amp;quot;Ostrich&amp;quot; or defName = &amp;quot;Turkey&amp;quot;]&amp;lt;/source&amp;gt; selects all of those in a single (faster) operation.&lt;br /&gt;
* PatchOperationAdd and PatchOperation insert have an ''order'' tag which allows you to either Prepend or Append your add. Default behaviour of Add is to Append, insert Prepends.&lt;br /&gt;
* There is a ''success'' tag whose values can be Normal, Invert, Always and Never. This is used for the sake of error reporting: by default an error is logged when a patch fails to apply. For PatchOperationSequences and PatchOperationTests, you can set success to Always to avoid error logging.&lt;br /&gt;
&lt;br /&gt;
== Write your own ==&lt;br /&gt;
Outside the scope of this wiki, but it's possible to write your own PatchOperation.&amp;lt;/br&amp;gt;&lt;br /&gt;
- [https://github.com/NoImageAvailable/CombatExtended/blob/88ef1f86d30e6c285e3370bd9faafa92c84195b0/Source/CombatExtended/CombatExtended/PatchOperationMakeGunCECompatible.cs Example PatchOperationMakeGunCECompatible]&amp;lt;/br&amp;gt;&lt;br /&gt;
- [https://gist.github.com/Lanilor/e326e33e268e78f68a2f5cd3cdbbe8c0 Example PatchOperationAddOrReplace]&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Resources ==&lt;br /&gt;
&lt;br /&gt;
The best tutorial on PatchOperations created by Zhentar: [https://gist.github.com/Zhentar/4a1b71cea45b9337f70b30a21d868782 Introduction to PatchOperation]&lt;br /&gt;
&lt;br /&gt;
You can also learn about XPaths here: [https://www.w3schools.com/xml/xpath_intro.asp XPath tutorial]&lt;br /&gt;
&lt;br /&gt;
There is also an [https://github.com/roxxploxx/RimWorldModGuide/wiki/SHORTTUTORIAL:-DefPatches Overview of PatchOperations]  on the [https://github.com/roxxploxx/RimWorldModGuide/wiki RimWorldModGuide].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Modding]]&lt;/div&gt;</summary>
		<author><name>Lilwhitemouse</name></author>
	</entry>
	<entry>
		<id>https://rimworldwiki.com/index.php?title=Modding_Tutorials/PatchOperations&amp;diff=62519</id>
		<title>Modding Tutorials/PatchOperations</title>
		<link rel="alternate" type="text/html" href="https://rimworldwiki.com/index.php?title=Modding_Tutorials/PatchOperations&amp;diff=62519"/>
		<updated>2019-02-04T17:31:28Z</updated>

		<summary type="html">&lt;p&gt;Lilwhitemouse: Added &amp;quot;Success&amp;quot; options&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{BackToTutorials}}&lt;br /&gt;
&lt;br /&gt;
RimWorld Alpha 17 added a new modding feature: '''XML PatchOperations'''. Using these allows mods to edit specific elements of XML defs, rather than simply overwriting the old def with a new one, which was the required approach until A17. This greatly reduces mod conflicts, because mods that make separate changes to the same def won't necessarily overwrite one another's changes. Mods using PatchOperations can avoid requiring special compatibility mods, and can even add special features conditional on other mods being loaded.&lt;br /&gt;
&lt;br /&gt;
Here's a simple example of replacing the texture path for deep water:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot; ?&amp;gt;&lt;br /&gt;
&amp;lt;Patch&amp;gt;&lt;br /&gt;
  &amp;lt;Operation Class=&amp;quot;PatchOperationReplace&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;Defs/TerrainDef[defName=&amp;quot;WaterDeep&amp;quot;]/texturePath&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;value&amp;gt;&lt;br /&gt;
      &amp;lt;texturePath&amp;gt;Your/Texture/Path/Here&amp;lt;/texturePath&amp;gt;&lt;br /&gt;
    &amp;lt;/value&amp;gt;&lt;br /&gt;
  &amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/Patch&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
This xml file simply goes inside YourMod/Patches/ and you're done.&lt;br /&gt;
&lt;br /&gt;
== Overview of available PatchOperations ==&lt;br /&gt;
These are the available PatchOperation types:&lt;br /&gt;
&lt;br /&gt;
* Four do basic operations on XML nodes:&lt;br /&gt;
** '''[[#PatchOperationAdd|PatchOperationAdd]]''' adds a provided child node to the selected node&lt;br /&gt;
** '''[[#PatchOperationInsert|PatchOperationInsert]]''' adds a provided sibling node to the selected node&lt;br /&gt;
** '''[[#PatchOperationRemove|PatchOperationRemove]]''' deletes the selected node&lt;br /&gt;
** '''[[#PatchOperationReplace|PatchOperationReplace]]''' replaces the selected node with the provided node&lt;br /&gt;
* Three do basic operations on XML attributes:&lt;br /&gt;
** '''[[#PatchOperationAttributeAdd|PatchOperationAttributeAdd]]''' adds a provided attribute to the selected node if and only if the attribute name is not already present&lt;br /&gt;
** '''[[#PatchOperationAttributeSet|PatchOperationAttributeSet]]''' sets a provided attribute for the selected node, overwriting the attribute value if the attribute name is already present&lt;br /&gt;
** '''[[#PatchOperationAttributeRemove|PatchOperationAttributeRemove]]''' removes an attribute for the selected node&lt;br /&gt;
* Three allow for more complex operations:&lt;br /&gt;
** '''[[#PatchOperationAddModExtension|PatchOperationAddModExtension]]''' adds a ModExtension.&lt;br /&gt;
** '''[[#PatchOperationSetName|PatchOperationSetName]]''' changes the name of a node.&lt;br /&gt;
** '''[[#PatchOperationSequence|PatchOperationSequence]]''' contains a set of other PatchOperations, and aborts upon any operation failing&lt;br /&gt;
* Three allow for conditional operations&lt;br /&gt;
** '''[[#PatchOperationTest|PatchOperationTest]]''' tests nodes, which is useful inside a PatchOperationSequence&lt;br /&gt;
** '''[[#PatchOperationConditional|PatchOperationConditional]]''' tests nodes, and can do different operations depending on the result.&lt;br /&gt;
** '''[[#PatchOperationFindMod|PatchOperationFindMod]]''' tests for the presence of another mod, and can do different operations depending on the result.&lt;br /&gt;
&lt;br /&gt;
==XPath syntax==&lt;br /&gt;
Each PatchOperation must specify an XML node to modify. It uses XPaths to specify them. An XPath is a &amp;quot;path&amp;quot; for the patch to follow when trying to find XML nodes matching the description. It will follow each part of the path from left to right. Note that these &amp;quot;paths&amp;quot; have zero relation to the file path or folder structure: They follow the structure of the XML nodes.&lt;br /&gt;
&lt;br /&gt;
XPaths start at the root node. Since the root node of all Defs is enforced to be &amp;lt;Defs&amp;gt;, so &amp;lt;code&amp;gt;/Defs/&amp;lt;/code&amp;gt; is the start of our xpath. &amp;lt;code&amp;gt;*/&amp;lt;/code&amp;gt; is also valid, as it uses the &amp;lt;code&amp;gt;*&amp;lt;/code&amp;gt; wildcard: &amp;lt;code&amp;gt;*&amp;lt;/code&amp;gt; matches any element, so it'll match the root (the top level) of the XML tree. &amp;lt;code&amp;gt;//&amp;lt;/code&amp;gt; is technically also valid, but because that construct selects ''all'' the elements in the XML tree, it's an expensive operation that makes game loading exponentially slower.&lt;br /&gt;
&lt;br /&gt;
Once the root is selected, the XPath lets the system walk down specific branches of the tree. If we use the example from the lead, we get a specific path:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;/Defs/TerrainDef[defName=&amp;quot;WaterDeep&amp;quot;]/texturePath&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# The root node is selected&lt;br /&gt;
# All child nodes of the root node called &amp;quot;TerrainDef&amp;quot; are selected&lt;br /&gt;
# We narrow down from &amp;quot;all TerrainDefs&amp;quot; to only those with the child &amp;quot;defName&amp;quot; node whose value is &amp;quot;WaterDeep&amp;quot;, which should give us exactly one node because defNames must be unique&lt;br /&gt;
# We select the child node &amp;quot;texturePath&amp;quot; from this node&lt;br /&gt;
## Note that we cannot put &amp;lt;code&amp;gt;.../texturePath/&amp;lt;/code&amp;gt; to specify the content of the texturePath node.  If we want to replace texturePath, we have to replace it with &amp;lt;code&amp;gt;&amp;lt;texturePath&amp;gt;/new/path/to/texture&amp;lt;/texturePath&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more info, see this {{LudeonThread|32785}}. XPath is a [https://www.w3schools.com/xml/xml_xpath.asp well-documented industry standard] (good resource, too); there are plenty of resources available on the subject ranging from exhaustive tutorials to simple [https://stackoverflow.com/questions/tagged/xpath StackOverflow] questions.&lt;br /&gt;
&lt;br /&gt;
==&amp;quot;Success&amp;quot; option==&lt;br /&gt;
The ''&amp;lt;code&amp;gt;&amp;lt;success&amp;gt;...&amp;lt;/success&amp;gt;&amp;lt;/code&amp;gt;'' term specifies whether the entire operation is considered a success or not.  If the overall patch operation is not considered a success, an error is thrown.  This is particularly used in Sequences and Tests.&lt;br /&gt;
&lt;br /&gt;
Options available are:&lt;br /&gt;
* Always - this patch operation is considered a success - sometimes used for Sequences so that if an early test in the sequence fails, an error is not reported (because the sequence is still a successful patch)&lt;br /&gt;
* Normal - this patch operation is considered a success if it succeeded (content patched, test passed, etc)&lt;br /&gt;
* Invert - If the patch failed (e.g., a test), then it's considered a success (useful for a negative test in a sequence)&lt;br /&gt;
* Never - this patch operation &amp;quot;failed.&amp;quot;  Even if it patched whatever it was supposed to correctly.  If you ever use this, leave a note here for the curious.&lt;br /&gt;
&lt;br /&gt;
==Overview of individual PatchOperations==&lt;br /&gt;
===PatchOperationAdd===&lt;br /&gt;
''PatchOperationAdd'' adds a child node to the selected node.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationAdd&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleList&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;value&amp;gt;&lt;br /&gt;
        &amp;lt;li&amp;gt;Foo&amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;li&amp;gt;Bar&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;/value&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList&amp;gt;&lt;br /&gt;
            &amp;lt;li&amp;gt;Foo&amp;lt;/li&amp;gt;&lt;br /&gt;
            &amp;lt;li&amp;gt;Bar&amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;/exampleList&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationInsert===&lt;br /&gt;
''PatchOperationInsert'' adds a sibling to the selected node.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationInsert&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;value&amp;gt;&lt;br /&gt;
        &amp;lt;anotherExample&amp;gt;A new sibling&amp;lt;/anotherExample&amp;gt;&lt;br /&gt;
    &amp;lt;/value&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;anotherExample&amp;gt;A new sibling&amp;lt;/anotherExample&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationRemove===&lt;br /&gt;
''PatchOperationRemove'' removes the selected node.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationRemove&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationReplace===&lt;br /&gt;
''PatchOperationReplace'' replaces the selected node.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationReplace&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;value&amp;gt;&lt;br /&gt;
        &amp;lt;anotherExample&amp;gt;An alternate node&amp;lt;/anotherExample&amp;gt;&lt;br /&gt;
    &amp;lt;/value&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;anotherExample&amp;gt;An alternate node&amp;lt;/anotherExample&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationAttributeAdd===&lt;br /&gt;
''PatchOperationAttributeAdd'' will add an attribute and set its value, but only if that attribute is not yet present.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationAttributeAdd&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;attribute&amp;gt;ExampleAttribute&amp;lt;/attribute&amp;gt;&lt;br /&gt;
    &amp;lt;value&amp;gt;ExampleValue&amp;lt;/value&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode ExampleAttribute&amp;quot;ExampleValue&amp;quot;&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationAttributeSet===&lt;br /&gt;
''PatchOperationAttributeSet'' will add an attribute and set its value. Unlike PatchAttributeAdd, PatchOperationAttributeSet will overwrite any existing value. &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode ExampleAttribute&amp;quot;ExampleValue&amp;quot;&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationAttributeSet&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;attribute&amp;gt;ExampleAttribute&amp;lt;/attribute&amp;gt;&lt;br /&gt;
    &amp;lt;value&amp;gt;DifferentExampleValue&amp;lt;/value&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode ExampleAttribute&amp;quot;DifferentExampleValue&amp;quot;&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationAttributeRemove===&lt;br /&gt;
''PatchOperationAttributeRemove'' removes the specified attribute.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode ExampleAttribute&amp;quot;ExampleValue&amp;quot;&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationAttributeRemove&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;attribute&amp;gt;ExampleAttribute&amp;lt;/attribute&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationAddModExtension===&lt;br /&gt;
{{Main|Modding Tutorials/DefModExtension}}&lt;br /&gt;
''PatchOperationAddModExtension'' adds a [[Modding Tutorials/DefModExtension|Mod Extension]].&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationAddModExtension&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;value&amp;gt;&lt;br /&gt;
        &amp;lt;li Class=&amp;quot;ExampleNameSpace.ExampleModExtension&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;exampleValue&amp;gt;true&amp;lt;/exampleValue&amp;gt;&lt;br /&gt;
        &amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;/value&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
        &amp;lt;modExtensions&amp;gt;&lt;br /&gt;
            &amp;lt;li Class=&amp;quot;ExampleNameSpace.ExampleModExtension&amp;quot;&amp;gt;&lt;br /&gt;
                &amp;lt;exampleValue&amp;gt;true&amp;lt;/exampleValue&amp;gt;&lt;br /&gt;
            &amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;/modExtensions&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationSetName===&lt;br /&gt;
''PatchOperationSetName'' changes the name of a node.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationSetName&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;name&amp;gt;newExampleName&amp;lt;/name&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;newExampleName&amp;gt;Some text&amp;lt;/newExampleName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationSequence===&lt;br /&gt;
''PatchOperationSequence'' will complete all operations in the order of their listing, and stop when any of them fails.&lt;br /&gt;
&lt;br /&gt;
===PatchOperationTest===&lt;br /&gt;
''PatchOperationTest'' tests for the existence/validity of an xpath. Useful to stop a PatchOperationSequence. Often used as a simpler, less powerful version of PatchOperationConditional.&lt;br /&gt;
The following example patch is from Apparello, by Shinzy. &lt;br /&gt;
&amp;lt;source lang =&amp;quot;xml&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationSequence&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;!-- check for worn graphics and if none found, add one --&amp;gt;&lt;br /&gt;
    &amp;lt;success&amp;gt;Always&amp;lt;/success&amp;gt;&lt;br /&gt;
    &amp;lt;operations&amp;gt;&lt;br /&gt;
        &amp;lt;li Class=&amp;quot;PatchOperationTest&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;xpath&amp;gt;/Defs/ThingDef[defName = &amp;quot;Apparel_Pants&amp;quot;]/apparel/wornGraphicPath&amp;lt;/xpath&amp;gt;&lt;br /&gt;
            &amp;lt;success&amp;gt;Invert&amp;lt;/success&amp;gt;&lt;br /&gt;
        &amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;li Class=&amp;quot;PatchOperationAdd&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;xpath&amp;gt;/Defs/ThingDef[defName = &amp;quot;Apparel_Pants&amp;quot;]/apparel&amp;lt;/xpath&amp;gt;&lt;br /&gt;
            &amp;lt;value&amp;gt;&lt;br /&gt;
                &amp;lt;wornGraphicPath&amp;gt;Accessorello/Pants/Pants&amp;lt;/wornGraphicPath&amp;gt;&lt;br /&gt;
            &amp;lt;/value&amp;gt;&lt;br /&gt;
        &amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;/operations&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===PatchOperationConditional===&lt;br /&gt;
''PatchOperationConditional'' can branch logic based on a match/nomatch. The following example patch adds a &amp;lt;comps&amp;gt; node if it does not yet exist, and adds itself &lt;br /&gt;
&lt;br /&gt;
This patch is courtesy Mehni. [https://github.com/Mehni/MoreFactionInteraction/blob/ab3ab2a22ee529ee4e38a471fe150fd48fd07ce9/Patches/MoreFactionInteraction.xml#L40-L62 See original.]&lt;br /&gt;
&amp;lt;source lang =&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!-- Add /comps/li/compClass if there are no comps yet. --&amp;gt;&lt;br /&gt;
&amp;lt;!-- Add /li/compClass to /comps if exists (i.e. other mod already added the comps field first) --&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationConditional&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;/Defs/WorldObjectDef[defName=&amp;quot;Caravan&amp;quot;]/comps&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;nomatch Class=&amp;quot;PatchOperationAdd&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;xpath&amp;gt;/Defs/WorldObjectDef[defName=&amp;quot;Caravan&amp;quot;]&amp;lt;/xpath&amp;gt;&lt;br /&gt;
        &amp;lt;value&amp;gt;&lt;br /&gt;
            &amp;lt;comps&amp;gt;&lt;br /&gt;
                &amp;lt;li&amp;gt;&lt;br /&gt;
                    &amp;lt;compClass&amp;gt;MoreFactionInteraction.WorldObjectComp_CaravanComp&amp;lt;/compClass&amp;gt;&lt;br /&gt;
                &amp;lt;/li&amp;gt;&lt;br /&gt;
            &amp;lt;/comps&amp;gt;&lt;br /&gt;
        &amp;lt;/value&amp;gt;&lt;br /&gt;
    &amp;lt;/nomatch&amp;gt;&lt;br /&gt;
    &amp;lt;match Class=&amp;quot;PatchOperationAdd&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;xpath&amp;gt;/Defs/WorldObjectDef[defName=&amp;quot;Caravan&amp;quot;]/comps&amp;lt;/xpath&amp;gt;&lt;br /&gt;
        &amp;lt;value&amp;gt;&lt;br /&gt;
            &amp;lt;li&amp;gt;&lt;br /&gt;
                &amp;lt;compClass&amp;gt;MoreFactionInteraction.WorldObjectComp_CaravanComp&amp;lt;/compClass&amp;gt;&lt;br /&gt;
            &amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;/value&amp;gt;&lt;br /&gt;
    &amp;lt;/match&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===PatchOperationFindMod===&lt;br /&gt;
''PatchOperationFindMod'' searches the list of active mods for the mods listed in &amp;lt;nowiki&amp;gt;&amp;lt;li&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/nowiki&amp;gt; tags.&lt;br /&gt;
&lt;br /&gt;
For a successful match, &amp;lt;nowiki&amp;gt;&amp;lt;li&amp;gt;ModName&amp;lt;/li&amp;gt;&amp;lt;/nowiki&amp;gt; has to match the &amp;lt;name&amp;gt;ModName&amp;lt;/name&amp;gt; in the About.xml of the mod you base your patch behaviour on.&lt;br /&gt;
This (shortened) patch is courtesy Mehni. [https://github.com/Mehni/MoreFactionInteraction/blob/ab3ab2a22ee529ee4e38a471fe150fd48fd07ce9/Patches/MoreFactionInteraction.xml#L64 See original.]&lt;br /&gt;
&lt;br /&gt;
The following Patch adds the RimQuest mod extension to the listed Defs when RimQuest is found.&lt;br /&gt;
&amp;lt;source lang =&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationFindMod&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;mods&amp;gt;&lt;br /&gt;
        &amp;lt;li&amp;gt;RimQuest&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;/mods&amp;gt;&lt;br /&gt;
    &amp;lt;match Class=&amp;quot;PatchOperationAddModExtension&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;xpath&amp;gt;Defs/IncidentDef[defName=&amp;quot;MFI_DiplomaticMarriage&amp;quot; or defName=&amp;quot;MFI_HuntersLodge&amp;quot; or defName=&amp;quot;MFI_Quest_PeaceTalks&amp;quot;]&amp;lt;/xpath&amp;gt;&lt;br /&gt;
        &amp;lt;value&amp;gt;&lt;br /&gt;
            &amp;lt;li Class = &amp;quot;RimQuest.RimQuest_ModExtension&amp;quot;&amp;gt;&lt;br /&gt;
                &amp;lt;canBeARimQuest&amp;gt;false&amp;lt;/canBeARimQuest&amp;gt;&lt;br /&gt;
            &amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;/value&amp;gt;&lt;br /&gt;
    &amp;lt;/match&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following Patch replace the tabWindowClass of the xpath when Relations Tab is '''not''' found. &lt;br /&gt;
&amp;lt;source lang =&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationFindMod&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;mods&amp;gt;&lt;br /&gt;
        &amp;lt;li&amp;gt;Relations Tab&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;/mods&amp;gt;&lt;br /&gt;
    &amp;lt;nomatch Class=&amp;quot;PatchOperationReplace&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;xpath&amp;gt;/Defs/MainButtonDef[defName=&amp;quot;Factions&amp;quot;]/tabWindowClass&amp;lt;/xpath&amp;gt;&lt;br /&gt;
        &amp;lt;value&amp;gt;&lt;br /&gt;
            &amp;lt;tabWindowClass&amp;gt;MyNameSpace.MyTabWindowClass&amp;lt;/tabWindowClass&amp;gt;&lt;br /&gt;
        &amp;lt;/value&amp;gt;&lt;br /&gt;
    &amp;lt;/nomatch&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Some advanced examples==&lt;br /&gt;
This (shortened) patch is courtesy XeoNovaDan. [https://github.com/XeoNovaDan/SurvivalTools/blob/62a4316c81733dde417257bf4bc5c34e3e781c7d/Patches/ExpandedWoodworkingVGP/Patch.xml See original]. Viewer discretion is advised. Parents please take precautions if young children are present.&lt;br /&gt;
&amp;lt;source lang = &amp;quot;XML&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationFindMod&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;mods&amp;gt;&lt;br /&gt;
        &amp;lt;li&amp;gt;Expanded Woodworking for Vegetable Garden Project&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;/mods&amp;gt;&lt;br /&gt;
    &amp;lt;match Class=&amp;quot;PatchOperationSequence&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;success&amp;gt;Always&amp;lt;/success&amp;gt;&lt;br /&gt;
        &amp;lt;operations&amp;gt;&lt;br /&gt;
            &amp;lt;!-- Nested PatchOpFindMod. Used because Expanded Woodworking adds more Wood when VGP Xtra is installed. --&amp;gt;&lt;br /&gt;
            &amp;lt;li Class=&amp;quot;PatchOperationFindMod&amp;quot;&amp;gt;&lt;br /&gt;
                &amp;lt;mods&amp;gt;&lt;br /&gt;
                    &amp;lt;li&amp;gt;VGP Xtra Trees and Flowers&amp;lt;/li&amp;gt;&lt;br /&gt;
                &amp;lt;/mods&amp;gt;&lt;br /&gt;
                &amp;lt;match Class=&amp;quot;PatchOperationSequence&amp;quot;&amp;gt;&lt;br /&gt;
                    &amp;lt;success&amp;gt;Always&amp;lt;/success&amp;gt;&lt;br /&gt;
                    &amp;lt;operations&amp;gt;&lt;br /&gt;
                        &amp;lt;!-- Processed camellia lumber. Mostly useful for building long-lasting, simple structures and furniture.--&amp;gt;&lt;br /&gt;
                        &amp;lt;li Class=&amp;quot;PatchOperationAddModExtension&amp;quot;&amp;gt;&lt;br /&gt;
                            &amp;lt;xpath&amp;gt;Defs/ThingDef[defName=&amp;quot;LumberCamellia&amp;quot;]&amp;lt;/xpath&amp;gt;&lt;br /&gt;
                            &amp;lt;value&amp;gt;&lt;br /&gt;
                                &amp;lt;li Class=&amp;quot;SurvivalTools.StuffPropsTool&amp;quot;&amp;gt;&lt;br /&gt;
                                    &amp;lt;toolStatFactors&amp;gt;&lt;br /&gt;
                                        &amp;lt;ConstructionSpeed&amp;gt;0.55&amp;lt;/ConstructionSpeed&amp;gt;&lt;br /&gt;
                                    &amp;lt;/toolStatFactors&amp;gt;&lt;br /&gt;
                                &amp;lt;/li&amp;gt;&lt;br /&gt;
                            &amp;lt;/value&amp;gt;&lt;br /&gt;
                        &amp;lt;/li&amp;gt;&lt;br /&gt;
                    &amp;lt;/operations&amp;gt;&lt;br /&gt;
                &amp;lt;/match&amp;gt;&lt;br /&gt;
            &amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;/operations&amp;gt;&lt;br /&gt;
    &amp;lt;/match&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Random stuff===&lt;br /&gt;
* @ select by attribute. Useful for patching (Abstract) bases. &amp;lt;source lang = &amp;quot;xml&amp;quot;&amp;gt;/Defs/ThingDef[@Name=&amp;quot;BuildingBase&amp;quot;]&amp;lt;/source&amp;gt;&lt;br /&gt;
* ''or'' is inclusive. &amp;lt;source lang = &amp;quot;xml&amp;quot;&amp;gt;/Defs/ThingDef[defName=&amp;quot;Cassowary&amp;quot; or defName = &amp;quot;Emu&amp;quot; or defName = &amp;quot;Ostrich&amp;quot; or defName = &amp;quot;Turkey&amp;quot;]&amp;lt;/source&amp;gt; selects all of those in a single (faster) operation.&lt;br /&gt;
* PatchOperationAdd and PatchOperation insert have an ''order'' tag which allows you to either Prepend or Append your add. Default behaviour of Add is to Append, insert Prepends.&lt;br /&gt;
* There is a ''success'' tag whose values can be Normal, Invert, Always and Never. This is used for the sake of error reporting: by default an error is logged when a patch fails to apply. For PatchOperationSequences and PatchOperationTests, you can set success to Always to avoid error logging.&lt;br /&gt;
&lt;br /&gt;
== Write your own ==&lt;br /&gt;
Outside the scope of this wiki, but it's possible to write your own PatchOperation.&amp;lt;/br&amp;gt;&lt;br /&gt;
- [https://github.com/NoImageAvailable/CombatExtended/blob/88ef1f86d30e6c285e3370bd9faafa92c84195b0/Source/CombatExtended/CombatExtended/PatchOperationMakeGunCECompatible.cs Example PatchOperationMakeGunCECompatible]&amp;lt;/br&amp;gt;&lt;br /&gt;
- [https://gist.github.com/Lanilor/e326e33e268e78f68a2f5cd3cdbbe8c0 Example PatchOperationAddOrReplace]&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Resources ==&lt;br /&gt;
&lt;br /&gt;
The best tutorial on PatchOperations created by Zhentar: [https://gist.github.com/Zhentar/4a1b71cea45b9337f70b30a21d868782 Introduction to PatchOperation]&lt;br /&gt;
&lt;br /&gt;
You can also learn about XPaths here: [https://www.w3schools.com/xml/xpath_intro.asp XPath tutorial]&lt;br /&gt;
&lt;br /&gt;
There is also an [https://github.com/roxxploxx/RimWorldModGuide/wiki/SHORTTUTORIAL:-DefPatches Overview of PatchOperations]  on the [https://github.com/roxxploxx/RimWorldModGuide/wiki RimWorldModGuide].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Modding]]&lt;/div&gt;</summary>
		<author><name>Lilwhitemouse</name></author>
	</entry>
	<entry>
		<id>https://rimworldwiki.com/index.php?title=Modding_Tutorials/PatchOperations&amp;diff=62518</id>
		<title>Modding Tutorials/PatchOperations</title>
		<link rel="alternate" type="text/html" href="https://rimworldwiki.com/index.php?title=Modding_Tutorials/PatchOperations&amp;diff=62518"/>
		<updated>2019-02-04T17:12:31Z</updated>

		<summary type="html">&lt;p&gt;Lilwhitemouse: /* XPath syntax */ put leading / in front of Defs,which is fastest; note on final /&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{BackToTutorials}}&lt;br /&gt;
&lt;br /&gt;
RimWorld Alpha 17 added a new modding feature: '''XML PatchOperations'''. Using these allows mods to edit specific elements of XML defs, rather than simply overwriting the old def with a new one, which was the required approach until A17. This greatly reduces mod conflicts, because mods that make separate changes to the same def won't necessarily overwrite one another's changes. Mods using PatchOperations can avoid requiring special compatibility mods, and can even add special features conditional on other mods being loaded.&lt;br /&gt;
&lt;br /&gt;
Here's a simple example of replacing the texture path for deep water:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot; ?&amp;gt;&lt;br /&gt;
&amp;lt;Patch&amp;gt;&lt;br /&gt;
  &amp;lt;Operation Class=&amp;quot;PatchOperationReplace&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;Defs/TerrainDef[defName=&amp;quot;WaterDeep&amp;quot;]/texturePath&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;value&amp;gt;&lt;br /&gt;
      &amp;lt;texturePath&amp;gt;Your/Texture/Path/Here&amp;lt;/texturePath&amp;gt;&lt;br /&gt;
    &amp;lt;/value&amp;gt;&lt;br /&gt;
  &amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/Patch&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
This xml file simply goes inside YourMod/Patches/ and you're done.&lt;br /&gt;
&lt;br /&gt;
== Overview of available PatchOperations ==&lt;br /&gt;
These are the available PatchOperation types:&lt;br /&gt;
&lt;br /&gt;
* Four do basic operations on XML nodes:&lt;br /&gt;
** '''[[#PatchOperationAdd|PatchOperationAdd]]''' adds a provided child node to the selected node&lt;br /&gt;
** '''[[#PatchOperationInsert|PatchOperationInsert]]''' adds a provided sibling node to the selected node&lt;br /&gt;
** '''[[#PatchOperationRemove|PatchOperationRemove]]''' deletes the selected node&lt;br /&gt;
** '''[[#PatchOperationReplace|PatchOperationReplace]]''' replaces the selected node with the provided node&lt;br /&gt;
* Three do basic operations on XML attributes:&lt;br /&gt;
** '''[[#PatchOperationAttributeAdd|PatchOperationAttributeAdd]]''' adds a provided attribute to the selected node if and only if the attribute name is not already present&lt;br /&gt;
** '''[[#PatchOperationAttributeSet|PatchOperationAttributeSet]]''' sets a provided attribute for the selected node, overwriting the attribute value if the attribute name is already present&lt;br /&gt;
** '''[[#PatchOperationAttributeRemove|PatchOperationAttributeRemove]]''' removes an attribute for the selected node&lt;br /&gt;
* Three allow for more complex operations:&lt;br /&gt;
** '''[[#PatchOperationAddModExtension|PatchOperationAddModExtension]]''' adds a ModExtension.&lt;br /&gt;
** '''[[#PatchOperationSetName|PatchOperationSetName]]''' changes the name of a node.&lt;br /&gt;
** '''[[#PatchOperationSequence|PatchOperationSequence]]''' contains a set of other PatchOperations, and aborts upon any operation failing&lt;br /&gt;
* Three allow for conditional operations&lt;br /&gt;
** '''[[#PatchOperationTest|PatchOperationTest]]''' tests nodes, which is useful inside a PatchOperationSequence&lt;br /&gt;
** '''[[#PatchOperationConditional|PatchOperationConditional]]''' tests nodes, and can do different operations depending on the result.&lt;br /&gt;
** '''[[#PatchOperationFindMod|PatchOperationFindMod]]''' tests for the presence of another mod, and can do different operations depending on the result.&lt;br /&gt;
&lt;br /&gt;
==XPath syntax==&lt;br /&gt;
Each PatchOperation must specify an XML node to modify. It uses XPaths to specify them. An XPath is a &amp;quot;path&amp;quot; for the patch to follow when trying to find XML nodes matching the description. It will follow each part of the path from left to right. Note that these &amp;quot;paths&amp;quot; have zero relation to the file path or folder structure: They follow the structure of the XML nodes.&lt;br /&gt;
&lt;br /&gt;
XPaths start at the root node. Since the root node of all Defs is enforced to be &amp;lt;Defs&amp;gt;, so &amp;lt;code&amp;gt;/Defs/&amp;lt;/code&amp;gt; is the start of our xpath. &amp;lt;code&amp;gt;*/&amp;lt;/code&amp;gt; is also valid, as it uses the &amp;lt;code&amp;gt;*&amp;lt;/code&amp;gt; wildcard: &amp;lt;code&amp;gt;*&amp;lt;/code&amp;gt; matches any element, so it'll match the root (the top level) of the XML tree. &amp;lt;code&amp;gt;//&amp;lt;/code&amp;gt; is technically also valid, but because that construct selects ''all'' the elements in the XML tree, it's an expensive operation that makes game loading exponentially slower.&lt;br /&gt;
&lt;br /&gt;
Once the root is selected, the XPath lets the system walk down specific branches of the tree. If we use the example from the lead, we get a specific path:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;/Defs/TerrainDef[defName=&amp;quot;WaterDeep&amp;quot;]/texturePath&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# The root node is selected&lt;br /&gt;
# All child nodes of the root node called &amp;quot;TerrainDef&amp;quot; are selected&lt;br /&gt;
# We narrow down from &amp;quot;all TerrainDefs&amp;quot; to only those with the child &amp;quot;defName&amp;quot; node whose value is &amp;quot;WaterDeep&amp;quot;, which should give us exactly one node because defNames must be unique&lt;br /&gt;
# We select the child node &amp;quot;texturePath&amp;quot; from this node&lt;br /&gt;
## Note that we cannot put &amp;lt;code&amp;gt;.../texturePath/&amp;lt;/code&amp;gt; to specify the content of the texturePath node.  If we want to replace texturePath, we have to replace it with &amp;lt;code&amp;gt;&amp;lt;texturePath&amp;gt;/new/path/to/texture&amp;lt;/texturePath&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more info, see this {{LudeonThread|32785}}. XPath is a [https://www.w3schools.com/xml/xml_xpath.asp well-documented industry standard] (good resource, too); there are plenty of resources available on the subject ranging from exhaustive tutorials to simple [https://stackoverflow.com/questions/tagged/xpath StackOverflow] questions.&lt;br /&gt;
&lt;br /&gt;
==Overview of individual PatchOperations==&lt;br /&gt;
===PatchOperationAdd===&lt;br /&gt;
''PatchOperationAdd'' adds a child node to the selected node.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationAdd&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleList&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;value&amp;gt;&lt;br /&gt;
        &amp;lt;li&amp;gt;Foo&amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;li&amp;gt;Bar&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;/value&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList&amp;gt;&lt;br /&gt;
            &amp;lt;li&amp;gt;Foo&amp;lt;/li&amp;gt;&lt;br /&gt;
            &amp;lt;li&amp;gt;Bar&amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;/exampleList&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationInsert===&lt;br /&gt;
''PatchOperationInsert'' adds a sibling to the selected node.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationInsert&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;value&amp;gt;&lt;br /&gt;
        &amp;lt;anotherExample&amp;gt;A new sibling&amp;lt;/anotherExample&amp;gt;&lt;br /&gt;
    &amp;lt;/value&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;anotherExample&amp;gt;A new sibling&amp;lt;/anotherExample&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationRemove===&lt;br /&gt;
''PatchOperationRemove'' removes the selected node.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationRemove&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationReplace===&lt;br /&gt;
''PatchOperationReplace'' replaces the selected node.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationReplace&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;value&amp;gt;&lt;br /&gt;
        &amp;lt;anotherExample&amp;gt;An alternate node&amp;lt;/anotherExample&amp;gt;&lt;br /&gt;
    &amp;lt;/value&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;anotherExample&amp;gt;An alternate node&amp;lt;/anotherExample&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationAttributeAdd===&lt;br /&gt;
''PatchOperationAttributeAdd'' will add an attribute and set its value, but only if that attribute is not yet present.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationAttributeAdd&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;attribute&amp;gt;ExampleAttribute&amp;lt;/attribute&amp;gt;&lt;br /&gt;
    &amp;lt;value&amp;gt;ExampleValue&amp;lt;/value&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode ExampleAttribute&amp;quot;ExampleValue&amp;quot;&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationAttributeSet===&lt;br /&gt;
''PatchOperationAttributeSet'' will add an attribute and set its value. Unlike PatchAttributeAdd, PatchOperationAttributeSet will overwrite any existing value. &lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode ExampleAttribute&amp;quot;ExampleValue&amp;quot;&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationAttributeSet&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;attribute&amp;gt;ExampleAttribute&amp;lt;/attribute&amp;gt;&lt;br /&gt;
    &amp;lt;value&amp;gt;DifferentExampleValue&amp;lt;/value&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode ExampleAttribute&amp;quot;DifferentExampleValue&amp;quot;&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationAttributeRemove===&lt;br /&gt;
''PatchOperationAttributeRemove'' removes the specified attribute.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode ExampleAttribute&amp;quot;ExampleValue&amp;quot;&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationAttributeRemove&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;attribute&amp;gt;ExampleAttribute&amp;lt;/attribute&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationAddModExtension===&lt;br /&gt;
{{Main|Modding Tutorials/DefModExtension}}&lt;br /&gt;
''PatchOperationAddModExtension'' adds a [[Modding Tutorials/DefModExtension|Mod Extension]].&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationAddModExtension&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;value&amp;gt;&lt;br /&gt;
        &amp;lt;li Class=&amp;quot;ExampleNameSpace.ExampleModExtension&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;exampleValue&amp;gt;true&amp;lt;/exampleValue&amp;gt;&lt;br /&gt;
        &amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;/value&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
        &amp;lt;modExtensions&amp;gt;&lt;br /&gt;
            &amp;lt;li Class=&amp;quot;ExampleNameSpace.ExampleModExtension&amp;quot;&amp;gt;&lt;br /&gt;
                &amp;lt;exampleValue&amp;gt;true&amp;lt;/exampleValue&amp;gt;&lt;br /&gt;
            &amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;/modExtensions&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationSetName===&lt;br /&gt;
''PatchOperationSetName'' changes the name of a node.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;margin-left: auto; margin-right: auto;&amp;quot;&lt;br /&gt;
! Def before patch !! Patch operation !! Def after patch&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleNode&amp;gt;Some text&amp;lt;/exampleNode&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationSetName&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;Defs/ExampleDef[defName=&amp;quot;Example&amp;quot;]/exampleNode&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;name&amp;gt;newExampleName&amp;lt;/name&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
| style=&amp;quot;vertical-align: top;&amp;quot; |&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Defs&amp;gt;&lt;br /&gt;
    &amp;lt;ExampleDef&amp;gt;&lt;br /&gt;
        &amp;lt;defName&amp;gt;Example&amp;lt;/defName&amp;gt;&lt;br /&gt;
        &amp;lt;newExampleName&amp;gt;Some text&amp;lt;/newExampleName&amp;gt;&lt;br /&gt;
        &amp;lt;exampleList /&amp;gt;&lt;br /&gt;
    &amp;lt;/ExampleDef&amp;gt;&lt;br /&gt;
&amp;lt;/Defs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===PatchOperationSequence===&lt;br /&gt;
''PatchOperationSequence'' will complete all operations in the order of their listing, and stop when any of them fails.&lt;br /&gt;
&lt;br /&gt;
===PatchOperationTest===&lt;br /&gt;
''PatchOperationTest'' tests for the existence/validity of an xpath. Useful to stop a PatchOperationSequence. Often used as a simpler, less powerful version of PatchOperationConditional.&lt;br /&gt;
The following example patch is from Apparello, by Shinzy. &lt;br /&gt;
&amp;lt;source lang =&amp;quot;xml&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationSequence&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;!-- check for worn graphics and if none found, add one --&amp;gt;&lt;br /&gt;
    &amp;lt;success&amp;gt;Always&amp;lt;/success&amp;gt;&lt;br /&gt;
    &amp;lt;operations&amp;gt;&lt;br /&gt;
        &amp;lt;li Class=&amp;quot;PatchOperationTest&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;xpath&amp;gt;/Defs/ThingDef[defName = &amp;quot;Apparel_Pants&amp;quot;]/apparel/wornGraphicPath&amp;lt;/xpath&amp;gt;&lt;br /&gt;
            &amp;lt;success&amp;gt;Invert&amp;lt;/success&amp;gt;&lt;br /&gt;
        &amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;li Class=&amp;quot;PatchOperationAdd&amp;quot;&amp;gt;&lt;br /&gt;
            &amp;lt;xpath&amp;gt;/Defs/ThingDef[defName = &amp;quot;Apparel_Pants&amp;quot;]/apparel&amp;lt;/xpath&amp;gt;&lt;br /&gt;
            &amp;lt;value&amp;gt;&lt;br /&gt;
                &amp;lt;wornGraphicPath&amp;gt;Accessorello/Pants/Pants&amp;lt;/wornGraphicPath&amp;gt;&lt;br /&gt;
            &amp;lt;/value&amp;gt;&lt;br /&gt;
        &amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;/operations&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===PatchOperationConditional===&lt;br /&gt;
''PatchOperationConditional'' can branch logic based on a match/nomatch. The following example patch adds a &amp;lt;comps&amp;gt; node if it does not yet exist, and adds itself &lt;br /&gt;
&lt;br /&gt;
This patch is courtesy Mehni. [https://github.com/Mehni/MoreFactionInteraction/blob/ab3ab2a22ee529ee4e38a471fe150fd48fd07ce9/Patches/MoreFactionInteraction.xml#L40-L62 See original.]&lt;br /&gt;
&amp;lt;source lang =&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!-- Add /comps/li/compClass if there are no comps yet. --&amp;gt;&lt;br /&gt;
&amp;lt;!-- Add /li/compClass to /comps if exists (i.e. other mod already added the comps field first) --&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationConditional&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;xpath&amp;gt;/Defs/WorldObjectDef[defName=&amp;quot;Caravan&amp;quot;]/comps&amp;lt;/xpath&amp;gt;&lt;br /&gt;
    &amp;lt;nomatch Class=&amp;quot;PatchOperationAdd&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;xpath&amp;gt;/Defs/WorldObjectDef[defName=&amp;quot;Caravan&amp;quot;]&amp;lt;/xpath&amp;gt;&lt;br /&gt;
        &amp;lt;value&amp;gt;&lt;br /&gt;
            &amp;lt;comps&amp;gt;&lt;br /&gt;
                &amp;lt;li&amp;gt;&lt;br /&gt;
                    &amp;lt;compClass&amp;gt;MoreFactionInteraction.WorldObjectComp_CaravanComp&amp;lt;/compClass&amp;gt;&lt;br /&gt;
                &amp;lt;/li&amp;gt;&lt;br /&gt;
            &amp;lt;/comps&amp;gt;&lt;br /&gt;
        &amp;lt;/value&amp;gt;&lt;br /&gt;
    &amp;lt;/nomatch&amp;gt;&lt;br /&gt;
    &amp;lt;match Class=&amp;quot;PatchOperationAdd&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;xpath&amp;gt;/Defs/WorldObjectDef[defName=&amp;quot;Caravan&amp;quot;]/comps&amp;lt;/xpath&amp;gt;&lt;br /&gt;
        &amp;lt;value&amp;gt;&lt;br /&gt;
            &amp;lt;li&amp;gt;&lt;br /&gt;
                &amp;lt;compClass&amp;gt;MoreFactionInteraction.WorldObjectComp_CaravanComp&amp;lt;/compClass&amp;gt;&lt;br /&gt;
            &amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;/value&amp;gt;&lt;br /&gt;
    &amp;lt;/match&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===PatchOperationFindMod===&lt;br /&gt;
''PatchOperationFindMod'' searches the list of active mods for the mods listed in &amp;lt;nowiki&amp;gt;&amp;lt;li&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/nowiki&amp;gt; tags.&lt;br /&gt;
&lt;br /&gt;
For a successful match, &amp;lt;nowiki&amp;gt;&amp;lt;li&amp;gt;ModName&amp;lt;/li&amp;gt;&amp;lt;/nowiki&amp;gt; has to match the &amp;lt;name&amp;gt;ModName&amp;lt;/name&amp;gt; in the About.xml of the mod you base your patch behaviour on.&lt;br /&gt;
This (shortened) patch is courtesy Mehni. [https://github.com/Mehni/MoreFactionInteraction/blob/ab3ab2a22ee529ee4e38a471fe150fd48fd07ce9/Patches/MoreFactionInteraction.xml#L64 See original.]&lt;br /&gt;
&lt;br /&gt;
The following Patch adds the RimQuest mod extension to the listed Defs when RimQuest is found.&lt;br /&gt;
&amp;lt;source lang =&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationFindMod&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;mods&amp;gt;&lt;br /&gt;
        &amp;lt;li&amp;gt;RimQuest&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;/mods&amp;gt;&lt;br /&gt;
    &amp;lt;match Class=&amp;quot;PatchOperationAddModExtension&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;xpath&amp;gt;Defs/IncidentDef[defName=&amp;quot;MFI_DiplomaticMarriage&amp;quot; or defName=&amp;quot;MFI_HuntersLodge&amp;quot; or defName=&amp;quot;MFI_Quest_PeaceTalks&amp;quot;]&amp;lt;/xpath&amp;gt;&lt;br /&gt;
        &amp;lt;value&amp;gt;&lt;br /&gt;
            &amp;lt;li Class = &amp;quot;RimQuest.RimQuest_ModExtension&amp;quot;&amp;gt;&lt;br /&gt;
                &amp;lt;canBeARimQuest&amp;gt;false&amp;lt;/canBeARimQuest&amp;gt;&lt;br /&gt;
            &amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;/value&amp;gt;&lt;br /&gt;
    &amp;lt;/match&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following Patch replace the tabWindowClass of the xpath when Relations Tab is '''not''' found. &lt;br /&gt;
&amp;lt;source lang =&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationFindMod&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;mods&amp;gt;&lt;br /&gt;
        &amp;lt;li&amp;gt;Relations Tab&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;/mods&amp;gt;&lt;br /&gt;
    &amp;lt;nomatch Class=&amp;quot;PatchOperationReplace&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;xpath&amp;gt;/Defs/MainButtonDef[defName=&amp;quot;Factions&amp;quot;]/tabWindowClass&amp;lt;/xpath&amp;gt;&lt;br /&gt;
        &amp;lt;value&amp;gt;&lt;br /&gt;
            &amp;lt;tabWindowClass&amp;gt;MyNameSpace.MyTabWindowClass&amp;lt;/tabWindowClass&amp;gt;&lt;br /&gt;
        &amp;lt;/value&amp;gt;&lt;br /&gt;
    &amp;lt;/nomatch&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Some advanced examples==&lt;br /&gt;
This (shortened) patch is courtesy XeoNovaDan. [https://github.com/XeoNovaDan/SurvivalTools/blob/62a4316c81733dde417257bf4bc5c34e3e781c7d/Patches/ExpandedWoodworkingVGP/Patch.xml See original]. Viewer discretion is advised. Parents please take precautions if young children are present.&lt;br /&gt;
&amp;lt;source lang = &amp;quot;XML&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;Operation Class=&amp;quot;PatchOperationFindMod&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;mods&amp;gt;&lt;br /&gt;
        &amp;lt;li&amp;gt;Expanded Woodworking for Vegetable Garden Project&amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;/mods&amp;gt;&lt;br /&gt;
    &amp;lt;match Class=&amp;quot;PatchOperationSequence&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;success&amp;gt;Always&amp;lt;/success&amp;gt;&lt;br /&gt;
        &amp;lt;operations&amp;gt;&lt;br /&gt;
            &amp;lt;!-- Nested PatchOpFindMod. Used because Expanded Woodworking adds more Wood when VGP Xtra is installed. --&amp;gt;&lt;br /&gt;
            &amp;lt;li Class=&amp;quot;PatchOperationFindMod&amp;quot;&amp;gt;&lt;br /&gt;
                &amp;lt;mods&amp;gt;&lt;br /&gt;
                    &amp;lt;li&amp;gt;VGP Xtra Trees and Flowers&amp;lt;/li&amp;gt;&lt;br /&gt;
                &amp;lt;/mods&amp;gt;&lt;br /&gt;
                &amp;lt;match Class=&amp;quot;PatchOperationSequence&amp;quot;&amp;gt;&lt;br /&gt;
                    &amp;lt;success&amp;gt;Always&amp;lt;/success&amp;gt;&lt;br /&gt;
                    &amp;lt;operations&amp;gt;&lt;br /&gt;
                        &amp;lt;!-- Processed camellia lumber. Mostly useful for building long-lasting, simple structures and furniture.--&amp;gt;&lt;br /&gt;
                        &amp;lt;li Class=&amp;quot;PatchOperationAddModExtension&amp;quot;&amp;gt;&lt;br /&gt;
                            &amp;lt;xpath&amp;gt;Defs/ThingDef[defName=&amp;quot;LumberCamellia&amp;quot;]&amp;lt;/xpath&amp;gt;&lt;br /&gt;
                            &amp;lt;value&amp;gt;&lt;br /&gt;
                                &amp;lt;li Class=&amp;quot;SurvivalTools.StuffPropsTool&amp;quot;&amp;gt;&lt;br /&gt;
                                    &amp;lt;toolStatFactors&amp;gt;&lt;br /&gt;
                                        &amp;lt;ConstructionSpeed&amp;gt;0.55&amp;lt;/ConstructionSpeed&amp;gt;&lt;br /&gt;
                                    &amp;lt;/toolStatFactors&amp;gt;&lt;br /&gt;
                                &amp;lt;/li&amp;gt;&lt;br /&gt;
                            &amp;lt;/value&amp;gt;&lt;br /&gt;
                        &amp;lt;/li&amp;gt;&lt;br /&gt;
                    &amp;lt;/operations&amp;gt;&lt;br /&gt;
                &amp;lt;/match&amp;gt;&lt;br /&gt;
            &amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;/operations&amp;gt;&lt;br /&gt;
    &amp;lt;/match&amp;gt;&lt;br /&gt;
&amp;lt;/Operation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Random stuff===&lt;br /&gt;
* @ select by attribute. Useful for patching (Abstract) bases. &amp;lt;source lang = &amp;quot;xml&amp;quot;&amp;gt;/Defs/ThingDef[@Name=&amp;quot;BuildingBase&amp;quot;]&amp;lt;/source&amp;gt;&lt;br /&gt;
* ''or'' is inclusive. &amp;lt;source lang = &amp;quot;xml&amp;quot;&amp;gt;/Defs/ThingDef[defName=&amp;quot;Cassowary&amp;quot; or defName = &amp;quot;Emu&amp;quot; or defName = &amp;quot;Ostrich&amp;quot; or defName = &amp;quot;Turkey&amp;quot;]&amp;lt;/source&amp;gt; selects all of those in a single (faster) operation.&lt;br /&gt;
* PatchOperationAdd and PatchOperation insert have an ''order'' tag which allows you to either Prepend or Append your add. Default behaviour of Add is to Append, insert Prepends.&lt;br /&gt;
* There is a ''success'' tag whose values can be Normal, Invert, Always and Never. This is used for the sake of error reporting: by default an error is logged when a patch fails to apply. For PatchOperationSequences and PatchOperationTests, you can set success to Always to avoid error logging.&lt;br /&gt;
&lt;br /&gt;
== Write your own ==&lt;br /&gt;
Outside the scope of this wiki, but it's possible to write your own PatchOperation.&amp;lt;/br&amp;gt;&lt;br /&gt;
- [https://github.com/NoImageAvailable/CombatExtended/blob/88ef1f86d30e6c285e3370bd9faafa92c84195b0/Source/CombatExtended/CombatExtended/PatchOperationMakeGunCECompatible.cs Example PatchOperationMakeGunCECompatible]&amp;lt;/br&amp;gt;&lt;br /&gt;
- [https://gist.github.com/Lanilor/e326e33e268e78f68a2f5cd3cdbbe8c0 Example PatchOperationAddOrReplace]&amp;lt;/br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Resources ==&lt;br /&gt;
&lt;br /&gt;
The best tutorial on PatchOperations created by Zhentar: [https://gist.github.com/Zhentar/4a1b71cea45b9337f70b30a21d868782 Introduction to PatchOperation]&lt;br /&gt;
&lt;br /&gt;
You can also learn about XPaths here: [https://www.w3schools.com/xml/xpath_intro.asp XPath tutorial]&lt;br /&gt;
&lt;br /&gt;
There is also an [https://github.com/roxxploxx/RimWorldModGuide/wiki/SHORTTUTORIAL:-DefPatches Overview of PatchOperations]  on the [https://github.com/roxxploxx/RimWorldModGuide/wiki RimWorldModGuide].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Modding]]&lt;/div&gt;</summary>
		<author><name>Lilwhitemouse</name></author>
	</entry>
	<entry>
		<id>https://rimworldwiki.com/index.php?title=Topic:Utertmmn0n8ctg25&amp;topic_postId=utgtnk1tcrmyqk5p&amp;topic_revId=utgtnk1tcrmyqk5p&amp;action=single-view</id>
		<title>Topic:Utertmmn0n8ctg25</title>
		<link rel="alternate" type="text/html" href="https://rimworldwiki.com/index.php?title=Topic:Utertmmn0n8ctg25&amp;topic_postId=utgtnk1tcrmyqk5p&amp;topic_revId=utgtnk1tcrmyqk5p&amp;action=single-view"/>
		<updated>2019-02-02T19:43:01Z</updated>

		<summary type="html">&lt;span class=&quot;plainlinks&quot;&gt;&lt;a href=&quot;/index.php?title=User:Lilwhitemouse&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new mw-userlink&quot; title=&quot;User:Lilwhitemouse (page does not exist)&quot;&gt;&lt;bdi&gt;Lilwhitemouse&lt;/bdi&gt;&lt;/a&gt; &lt;span class=&quot;mw-usertoollinks&quot;&gt;(&lt;a href=&quot;/index.php?title=User_talk:Lilwhitemouse&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new mw-usertoollinks-talk&quot; title=&quot;User talk:Lilwhitemouse (page does not exist)&quot;&gt;talk&lt;/a&gt; | &lt;a href=&quot;/wiki/Special:Contributions/Lilwhitemouse&quot; class=&quot;mw-usertoollinks-contribs&quot; title=&quot;Special:Contributions/Lilwhitemouse&quot;&gt;contribs&lt;/a&gt;)&lt;/span&gt; &lt;a rel=&quot;nofollow&quot; class=&quot;external text&quot; href=&quot;https://rimworldwiki.com/index.php?title=Topic:Utertmmn0n8ctg25&amp;amp;topic_showPostId=utgtnk1tcrmyqk5p#flow-post-utgtnk1tcrmyqk5p&quot;&gt;commented&lt;/a&gt; on &quot;You took out Default Comp Class?&quot; (&lt;em&gt;I was talking about the Initialize check (https://rimworldwiki.com/index.php?title=Modding_Tutorials/Custom_Comp_Classes&amp;amp;oldid=62377 - ve...&lt;/em&gt;)&lt;/span&gt;</summary>
		<author><name>Lilwhitemouse</name></author>
	</entry>
	<entry>
		<id>https://rimworldwiki.com/index.php?title=Topic:Uteryyravthkibgt&amp;topic_postId=utgtbkvn2b8sla4t&amp;topic_revId=utgtbkvn2b8sla4t&amp;action=single-view</id>
		<title>Topic:Uteryyravthkibgt</title>
		<link rel="alternate" type="text/html" href="https://rimworldwiki.com/index.php?title=Topic:Uteryyravthkibgt&amp;topic_postId=utgtbkvn2b8sla4t&amp;topic_revId=utgtbkvn2b8sla4t&amp;action=single-view"/>
		<updated>2019-02-02T19:37:02Z</updated>

		<summary type="html">&lt;span class=&quot;plainlinks&quot;&gt;&lt;a href=&quot;/index.php?title=User:Lilwhitemouse&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new mw-userlink&quot; title=&quot;User:Lilwhitemouse (page does not exist)&quot;&gt;&lt;bdi&gt;Lilwhitemouse&lt;/bdi&gt;&lt;/a&gt; &lt;span class=&quot;mw-usertoollinks&quot;&gt;(&lt;a href=&quot;/index.php?title=User_talk:Lilwhitemouse&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new mw-usertoollinks-talk&quot; title=&quot;User talk:Lilwhitemouse (page does not exist)&quot;&gt;talk&lt;/a&gt; | &lt;a href=&quot;/wiki/Special:Contributions/Lilwhitemouse&quot; class=&quot;mw-usertoollinks-contribs&quot; title=&quot;Special:Contributions/Lilwhitemouse&quot;&gt;contribs&lt;/a&gt;)&lt;/span&gt; &lt;a rel=&quot;nofollow&quot; class=&quot;external text&quot; href=&quot;https://rimworldwiki.com/index.php?title=Topic:Uteryyravthkibgt&amp;amp;topic_showPostId=utgtbkvn2b8sla4t#flow-post-utgtbkvn2b8sla4t&quot;&gt;commented&lt;/a&gt; on &quot;Removed example?&quot; (&lt;em&gt;I think a more complicated example is actually fairly useful. I see what you mean by the potentially unsafe casting - I wrote the example...&lt;/em&gt;)&lt;/span&gt;</summary>
		<author><name>Lilwhitemouse</name></author>
	</entry>
	<entry>
		<id>https://rimworldwiki.com/index.php?title=Topic:Uteryyravthkibgt&amp;topic_postId=uteryyre02cv6owd&amp;topic_revId=uteryyre02cv6owd&amp;action=single-view</id>
		<title>Topic:Uteryyravthkibgt</title>
		<link rel="alternate" type="text/html" href="https://rimworldwiki.com/index.php?title=Topic:Uteryyravthkibgt&amp;topic_postId=uteryyre02cv6owd&amp;topic_revId=uteryyre02cv6owd&amp;action=single-view"/>
		<updated>2019-02-01T21:39:56Z</updated>

		<summary type="html">&lt;span class=&quot;plainlinks&quot;&gt;&lt;a href=&quot;/index.php?title=User:Lilwhitemouse&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new mw-userlink&quot; title=&quot;User:Lilwhitemouse (page does not exist)&quot;&gt;&lt;bdi&gt;Lilwhitemouse&lt;/bdi&gt;&lt;/a&gt; &lt;span class=&quot;mw-usertoollinks&quot;&gt;(&lt;a href=&quot;/index.php?title=User_talk:Lilwhitemouse&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new mw-usertoollinks-talk&quot; title=&quot;User talk:Lilwhitemouse (page does not exist)&quot;&gt;talk&lt;/a&gt; | &lt;a href=&quot;/wiki/Special:Contributions/Lilwhitemouse&quot; class=&quot;mw-usertoollinks-contribs&quot; title=&quot;Special:Contributions/Lilwhitemouse&quot;&gt;contribs&lt;/a&gt;)&lt;/span&gt; &lt;a rel=&quot;nofollow&quot; class=&quot;external text&quot; href=&quot;https://rimworldwiki.com/index.php?title=Topic:Uteryyravthkibgt&amp;amp;topic_showPostId=uteryyre02cv6owd#flow-post-uteryyre02cv6owd&quot;&gt;commented&lt;/a&gt; on &quot;Removed example?&quot; (&lt;em&gt;Any particular reason you removed the examples of how to access parts of the comp properties? I know those would have been very useful to...&lt;/em&gt;)&lt;/span&gt;</summary>
		<author><name>Lilwhitemouse</name></author>
	</entry>
	<entry>
		<id>https://rimworldwiki.com/index.php?title=Topic:Utertmmn0n8ctg25&amp;topic_postId=utertmmq4w3nhthp&amp;topic_revId=utertmmq4w3nhthp&amp;action=single-view</id>
		<title>Topic:Utertmmn0n8ctg25</title>
		<link rel="alternate" type="text/html" href="https://rimworldwiki.com/index.php?title=Topic:Utertmmn0n8ctg25&amp;topic_postId=utertmmq4w3nhthp&amp;topic_revId=utertmmq4w3nhthp&amp;action=single-view"/>
		<updated>2019-02-01T21:37:16Z</updated>

		<summary type="html">&lt;span class=&quot;plainlinks&quot;&gt;&lt;a href=&quot;/index.php?title=User:Lilwhitemouse&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new mw-userlink&quot; title=&quot;User:Lilwhitemouse (page does not exist)&quot;&gt;&lt;bdi&gt;Lilwhitemouse&lt;/bdi&gt;&lt;/a&gt; &lt;span class=&quot;mw-usertoollinks&quot;&gt;(&lt;a href=&quot;/index.php?title=User_talk:Lilwhitemouse&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new mw-usertoollinks-talk&quot; title=&quot;User talk:Lilwhitemouse (page does not exist)&quot;&gt;talk&lt;/a&gt; | &lt;a href=&quot;/wiki/Special:Contributions/Lilwhitemouse&quot; class=&quot;mw-usertoollinks-contribs&quot; title=&quot;Special:Contributions/Lilwhitemouse&quot;&gt;contribs&lt;/a&gt;)&lt;/span&gt; &lt;a rel=&quot;nofollow&quot; class=&quot;external text&quot; href=&quot;https://rimworldwiki.com/index.php?title=Topic:Utertmmn0n8ctg25&amp;amp;topic_showPostId=utertmmq4w3nhthp#flow-post-utertmmq4w3nhthp&quot;&gt;commented&lt;/a&gt; on &quot;You took out Default Comp Class?&quot; (&lt;em&gt;@Mehni, I noticed you took out the workaround for having a default CompClass for objects. Why? It&amp;#039;s entirely possible to create objects t...&lt;/em&gt;)&lt;/span&gt;</summary>
		<author><name>Lilwhitemouse</name></author>
	</entry>
	<entry>
		<id>https://rimworldwiki.com/index.php?title=Modding_Tutorials/Custom_Comp_Classes&amp;diff=62033</id>
		<title>Modding Tutorials/Custom Comp Classes</title>
		<link rel="alternate" type="text/html" href="https://rimworldwiki.com/index.php?title=Modding_Tutorials/Custom_Comp_Classes&amp;diff=62033"/>
		<updated>2019-01-06T03:50:06Z</updated>

		<summary type="html">&lt;p&gt;Lilwhitemouse: More complicated example...&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Creating a custom comp class is a convenient way to add new functionality to RimWorld.&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
* You need to have [[Modding Tutorials/Setting up a solution|set up your editor and environment]]&lt;br /&gt;
* You need to know [[Modding Tutorials/Writing custom code|how to write custom code]]&lt;br /&gt;
* You should probably understand Defs at least somewhat.&lt;br /&gt;
&lt;br /&gt;
== def (xml) and C# structure ==&lt;br /&gt;
&lt;br /&gt;
=== Setup, Defs, and Classes ===&lt;br /&gt;
You will have some custom def and it will have something like this:&lt;br /&gt;
==== Defs (xml) ====&lt;br /&gt;
  &amp;lt;ThingDef ...&amp;gt;&lt;br /&gt;
    ...&lt;br /&gt;
    ...&lt;br /&gt;
    &amp;lt;comps&amp;gt;&lt;br /&gt;
      &amp;lt;&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt; Class=&amp;quot;MyNamespace.MyCompProperties&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;myCustomCompProperty&amp;gt;some value&amp;lt;/myCustomCompProperty&amp;gt;&lt;br /&gt;
        &amp;lt;mySecondCompProp&amp;gt;4&amp;lt;/mySecondCompProp&amp;gt;&lt;br /&gt;
      &amp;lt;/&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt;&amp;gt;&lt;br /&gt;
      &amp;lt;&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt;&amp;gt;&lt;br /&gt;
        ''&amp;lt;&amp;lt;nowiki&amp;gt;!--&amp;lt;/nowiki&amp;gt; this is kind of like &amp;lt;tag&amp;gt;MN.MyCustomTag&amp;lt;/tag&amp;gt;:--&amp;gt;''&lt;br /&gt;
        &amp;lt;compClass&amp;gt;MyNamespace.MyCustomThingComp&amp;lt;/compClass&amp;gt;&lt;br /&gt;
      &amp;lt;/&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt;&amp;gt;&lt;br /&gt;
    &amp;lt;/comps&amp;gt;&lt;br /&gt;
  &amp;lt;/ThingDef&amp;gt;&lt;br /&gt;
==== C# ====&lt;br /&gt;
  namespace MyNamespace ''// For example, LWM.ModName - by using your ''&lt;br /&gt;
                        ''//   handle/name/etc, you almost certainly guarantee uniqueness''&lt;br /&gt;
  {&lt;br /&gt;
  '''//////////// &amp;lt;&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt; Class=&amp;quot;MyNamespace.MyCompProperties&amp;quot;&amp;gt; ////////////'''&lt;br /&gt;
  public class MyCompProperties : CompProperties ''// Name this as you wish, of course''&lt;br /&gt;
  {&lt;br /&gt;
    public Properties() {&lt;br /&gt;
      this.compClass = typeof(MyNamespace.MyLinkedCompThing); ''// rename as appropriate''&lt;br /&gt;
    }&lt;br /&gt;
    public string myCustomCompProperty; ''// Name matches def, of course''&lt;br /&gt;
    public int mySecondCompProp = 1; ''// Can set default values''&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  ''// this ThingComp is used to actually access the comp property defined above''&lt;br /&gt;
  '''''// this is not &amp;quot;&amp;lt;compClass&amp;gt;MyNamespace.MyCustomThingComp&amp;lt;/compClass&amp;gt;&amp;quot;'''''&lt;br /&gt;
  public class MyLinkedCompThing : ThingComp&lt;br /&gt;
  {&lt;br /&gt;
    public string myCustomCompProperty&lt;br /&gt;
    {&lt;br /&gt;
      get&lt;br /&gt;
      {&lt;br /&gt;
        return ((MyCompProperties)this.props).myCustomCompProperty;&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    public int mySecondCompProperty ''// Have to get all the names right''&lt;br /&gt;
    { get  { return ((MyCompProperties)this.props).mySecondCompProperty; } } ''//etc''&lt;br /&gt;
  }&lt;br /&gt;
  '''//////////// &amp;lt;compClass&amp;gt;MyNamespace.MyCustomThingComp&amp;lt;/compClass&amp;gt; ////////////'''&lt;br /&gt;
  public class MyCustomThingComp : ThingComp&lt;br /&gt;
  {&lt;br /&gt;
    public override void CompTick()&lt;br /&gt;
    {&lt;br /&gt;
      // do stuff&lt;br /&gt;
    }&lt;br /&gt;
    public override void CompTickRare() //etc&lt;br /&gt;
    public override ... // Check out Verse/ThingComp.cs for more ideas&lt;br /&gt;
  }&lt;br /&gt;
  } // end MyNamespace&lt;br /&gt;
&lt;br /&gt;
=== Accessing your Comps ===&lt;br /&gt;
Just setting up your custom comps doesn't do you a lot of good if you can't access them!&lt;br /&gt;
&lt;br /&gt;
==== Accessing CompProperty directly ====&lt;br /&gt;
This is the &amp;quot;hard&amp;quot; way, but doable if you want:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;C#&amp;quot;&amp;gt;&lt;br /&gt;
    int importantProperty = ((MyCompProperties)((ThingWithComps)myObject)&lt;br /&gt;
                             .GetComp&amp;lt;MyLinkedCompThing&amp;gt;().props).mySecondCompProp;&lt;br /&gt;
    //     The &amp;quot;(ThingWithComps)&amp;quot; cast may or may not be needed&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use the &amp;quot;get&amp;quot; method we created ====&lt;br /&gt;
Easier approach:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;C#&amp;quot;&amp;gt;&lt;br /&gt;
    // real world example:&lt;br /&gt;
    SlotGroup slotGroup = GetSlotGroupInEarlierCode();&lt;br /&gt;
    MyLinkedCompThing comp = ((ThingWithComps)slotGroup.parent).GetComp&amp;lt;MyLinkedCompThing&amp;gt;();&lt;br /&gt;
    if (comp != null) {&lt;br /&gt;
        string s = comp.myCustomCompProperty;&lt;br /&gt;
        int x = otherObject.GetComp&amp;lt;MyLinkedCompThing&amp;gt;().mySecondCompProp; // be sure it exists, etc&lt;br /&gt;
    } else { /* not a thing with my comp, etc */ }&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== More Complicated ===&lt;br /&gt;
You can do a lot of complicated things...&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;comps&amp;gt;&lt;br /&gt;
      &amp;lt;li Class=&amp;quot;MyNS.Properties&amp;gt;&lt;br /&gt;
        &amp;lt;myThingFilters&amp;gt;&lt;br /&gt;
          &amp;lt;li&amp;gt;&amp;lt;!-- These are a list, see? --&amp;gt;&lt;br /&gt;
            &amp;lt;filter&amp;gt;&lt;br /&gt;
              &amp;lt;categories&amp;gt;&lt;br /&gt;
                &amp;lt;li&amp;gt;Apparel&amp;lt;/li&amp;gt;&lt;br /&gt;
              &amp;lt;/categories&amp;gt;&lt;br /&gt;
            &amp;lt;/filter&amp;gt;&lt;br /&gt;
          &amp;lt;/li&amp;gt;&lt;br /&gt;
          &amp;lt;li&amp;gt;&lt;br /&gt;
            &amp;lt;filter&amp;gt;&lt;br /&gt;
              &amp;lt;categories&amp;gt;&lt;br /&gt;
                &amp;lt;li&amp;gt;Drugs&amp;lt;/li&amp;gt;&lt;br /&gt;
              &amp;lt;/categories&amp;gt;&lt;br /&gt;
              &amp;lt;thingDefs&amp;gt;&lt;br /&gt;
                &amp;lt;li&amp;gt;ChunkSlagSteel&amp;lt;/li&amp;gt;&lt;br /&gt;
              &amp;lt;/thingDefs&amp;gt;&lt;br /&gt;
            &amp;lt;/filter&amp;gt;&lt;br /&gt;
          &amp;lt;/li&amp;gt;&lt;br /&gt;
        &amp;lt;/myThingFilters&amp;gt;&lt;br /&gt;
      &amp;lt;/li&amp;gt;&lt;br /&gt;
    &amp;lt;/comps&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And then&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;C#&amp;quot;&amp;gt;&lt;br /&gt;
    namespace MyNS {&lt;br /&gt;
    public class Properties : CompProperties {&lt;br /&gt;
      public Properties() { this.compClass=typeof(ComplicatedComp); }&lt;br /&gt;
      public List&amp;lt;ThingFilter&amp;gt; myThingFilters = new List&amp;lt;ThingFilter&amp;gt;;&lt;br /&gt;
    }&lt;br /&gt;
    public class ComplicatedComp : ThingComp {&lt;br /&gt;
      // set up getter as before:&lt;br /&gt;
      public List&amp;lt;ThingFilter&amp;gt; myThingFilters { get { return ((Properties)this.props).myThingFilters;&lt;br /&gt;
    &lt;br /&gt;
    public class MyWeirdCode {&lt;br /&gt;
      // etc&lt;br /&gt;
        List&amp;lt;ThingFilter&amp;gt; listOfThingFilters = (ThingWithComps)thing.GetComp&amp;lt;ComplicatedComp&amp;gt;().myThingFilters;&lt;br /&gt;
        // why you would want a list of thing filters is beyond me?&lt;br /&gt;
        // what could you even do with it?&lt;br /&gt;
        // but you can have it.&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cautions, traps, etc ===&lt;br /&gt;
If you have the same comp in an abstract (XML) def and attempt to redefine it in a (XML) child def, it will get counted twice.  It's possible to get around this in the code, if you want to have default comps:&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;ThingDef Name=ParentWithDefault ... Abstract=true&amp;gt;&lt;br /&gt;
    ...&lt;br /&gt;
    &amp;lt;comps&amp;gt;&lt;br /&gt;
      &amp;lt;l&amp;lt;nowiki&amp;gt;i&amp;lt;/nowiki&amp;gt; Class=&amp;quot;MyCompPropertiesWithDefault&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;myValue&amp;gt;3&amp;lt;/myValue&amp;gt;&amp;lt;!--default!--&amp;gt;&lt;br /&gt;
      &amp;lt;/l&amp;lt;nowiki&amp;gt;i&amp;lt;/nowiki&amp;gt;&amp;gt;&lt;br /&gt;
    &amp;lt;/comps&amp;gt;&lt;br /&gt;
  &amp;lt;/ThingDef&amp;gt;&lt;br /&gt;
  &amp;lt;ThingDef ParentName=&amp;quot;ParentWihtDefault&amp;quot;&amp;gt;&lt;br /&gt;
    ...&lt;br /&gt;
    &amp;lt;comps&amp;gt;&lt;br /&gt;
      &amp;lt;l&amp;lt;nowiki&amp;gt;i&amp;lt;/nowiki&amp;gt; Class=&amp;quot;MyCompPropertiesWithDefault&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;myValue&amp;gt;5&amp;lt;/myValue&amp;gt;&amp;lt;!-- override default!--&amp;gt;&lt;br /&gt;
      &amp;lt;/&amp;lt;nowiki&amp;gt;l&amp;lt;/nowiki&amp;gt;i&amp;gt;&lt;br /&gt;
    &amp;lt;/comps&amp;gt;&lt;br /&gt;
  &amp;lt;/ThingDef&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  public class MyLinkedCompThing : ThingComp&lt;br /&gt;
  {&lt;br /&gt;
    public string myCustomCompProperty //etc&lt;br /&gt;
    &lt;br /&gt;
    public override void Initialize (CompProperties props) {&lt;br /&gt;
      base.Initialize(props);&lt;br /&gt;
      // Remove duplicate entries and ensure the last entry is the only one left&lt;br /&gt;
      //   This allows a default abstract def with the comp&lt;br /&gt;
      //   and child def to change the comp value:&lt;br /&gt;
      MyCompProprtiesWithDefault[] list = this.parent.GetComps&amp;lt;MyCompPropertiesWithDefault&amp;gt;().ToArray();&lt;br /&gt;
      // Remove everything but the last entry; harmless if only one entry:&lt;br /&gt;
      for (var i = 0; i &amp;lt; list.Length-1; i++)&lt;br /&gt;
      {&lt;br /&gt;
        this.parent.AllComps.Remove(list[i]);&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
  &lt;br /&gt;
  ///etc&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
[[Category:Modding tutorials]][[Category:Modding]][[Category:Defs]]&lt;/div&gt;</summary>
		<author><name>Lilwhitemouse</name></author>
	</entry>
	<entry>
		<id>https://rimworldwiki.com/index.php?title=Modding_Tutorials/Custom_Comp_Classes&amp;diff=62032</id>
		<title>Modding Tutorials/Custom Comp Classes</title>
		<link rel="alternate" type="text/html" href="https://rimworldwiki.com/index.php?title=Modding_Tutorials/Custom_Comp_Classes&amp;diff=62032"/>
		<updated>2019-01-06T03:36:00Z</updated>

		<summary type="html">&lt;p&gt;Lilwhitemouse: /* Accessing your Comps */ Stupid formatting with no documentation :p&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Creating a custom comp class is a convenient way to add new functionality to RimWorld.&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
* You need to have [[Modding Tutorials/Setting up a solution|set up your editor and environment]]&lt;br /&gt;
* You need to know [[Modding Tutorials/Writing custom code|how to write custom code]]&lt;br /&gt;
* You should probably understand Defs at least somewhat.&lt;br /&gt;
&lt;br /&gt;
== def (xml) and C# structure ==&lt;br /&gt;
&lt;br /&gt;
=== Setup, Defs, and Classes ===&lt;br /&gt;
You will have some custom def and it will have something like this:&lt;br /&gt;
==== Defs (xml) ====&lt;br /&gt;
  &amp;lt;ThingDef ...&amp;gt;&lt;br /&gt;
    ...&lt;br /&gt;
    ...&lt;br /&gt;
    &amp;lt;comps&amp;gt;&lt;br /&gt;
      &amp;lt;&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt; Class=&amp;quot;MyNamespace.MyCompProperties&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;myCustomCompProperty&amp;gt;some value&amp;lt;/myCustomCompProperty&amp;gt;&lt;br /&gt;
        &amp;lt;mySecondCompProp&amp;gt;4&amp;lt;/mySecondCompProp&amp;gt;&lt;br /&gt;
      &amp;lt;/&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt;&amp;gt;&lt;br /&gt;
      &amp;lt;&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt;&amp;gt;&lt;br /&gt;
        ''&amp;lt;&amp;lt;nowiki&amp;gt;!--&amp;lt;/nowiki&amp;gt; this is kind of like &amp;lt;tag&amp;gt;MN.MyCustomTag&amp;lt;/tag&amp;gt;:--&amp;gt;''&lt;br /&gt;
        &amp;lt;compClass&amp;gt;MyNamespace.MyCustomThingComp&amp;lt;/compClass&amp;gt;&lt;br /&gt;
      &amp;lt;/&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt;&amp;gt;&lt;br /&gt;
    &amp;lt;/comps&amp;gt;&lt;br /&gt;
  &amp;lt;/ThingDef&amp;gt;&lt;br /&gt;
==== C# ====&lt;br /&gt;
  namespace MyNamespace ''// For example, LWM.ModName - by using your ''&lt;br /&gt;
                        ''//   handle/name/etc, you almost certainly guarantee uniqueness''&lt;br /&gt;
  {&lt;br /&gt;
  '''//////////// &amp;lt;&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt; Class=&amp;quot;MyNamespace.MyCompProperties&amp;quot;&amp;gt; ////////////'''&lt;br /&gt;
  public class MyCompProperties : CompProperties ''// Name this as you wish, of course''&lt;br /&gt;
  {&lt;br /&gt;
    public Properties() {&lt;br /&gt;
      this.compClass = typeof(MyNamespace.MyLinkedCompThing); ''// rename as appropriate''&lt;br /&gt;
    }&lt;br /&gt;
    public string myCustomCompProperty; ''// Name matches def, of course''&lt;br /&gt;
    public int mySecondCompProp = 1; ''// Can set default values''&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  ''// this ThingComp is used to actually access the comp property defined above''&lt;br /&gt;
  '''''// this is not &amp;quot;&amp;lt;compClass&amp;gt;MyNamespace.MyCustomThingComp&amp;lt;/compClass&amp;gt;&amp;quot;'''''&lt;br /&gt;
  public class MyLinkedCompThing : ThingComp&lt;br /&gt;
  {&lt;br /&gt;
    public string myCustomCompProperty&lt;br /&gt;
    {&lt;br /&gt;
      get&lt;br /&gt;
      {&lt;br /&gt;
        return ((MyCompProperties)this.props).myCustomCompProperty;&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    public int mySecondCompProperty ''// Have to get all the names right''&lt;br /&gt;
    { get  { return ((MyCompProperties)this.props).mySecondCompProperty; } } ''//etc''&lt;br /&gt;
  }&lt;br /&gt;
  '''//////////// &amp;lt;compClass&amp;gt;MyNamespace.MyCustomThingComp&amp;lt;/compClass&amp;gt; ////////////'''&lt;br /&gt;
  public class MyCustomThingComp : ThingComp&lt;br /&gt;
  {&lt;br /&gt;
    public override void CompTick()&lt;br /&gt;
    {&lt;br /&gt;
      // do stuff&lt;br /&gt;
    }&lt;br /&gt;
    public override void CompTickRare() //etc&lt;br /&gt;
    public override ... // Check out Verse/ThingComp.cs for more ideas&lt;br /&gt;
  }&lt;br /&gt;
  } // end MyNamespace&lt;br /&gt;
&lt;br /&gt;
=== Accessing your Comps ===&lt;br /&gt;
Just setting up your custom comps doesn't do you a lot of good if you can't access them!&lt;br /&gt;
&lt;br /&gt;
==== Accessing CompProperty directly ====&lt;br /&gt;
This is the &amp;quot;hard&amp;quot; way, but doable if you want:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;C#&amp;quot;&amp;gt;&lt;br /&gt;
    int importantProperty = ((MyCompProperties)((ThingWithComps)myObject)&lt;br /&gt;
                             .GetComp&amp;lt;MyLinkedCompThing&amp;gt;().props).mySecondCompProp;&lt;br /&gt;
    //     The &amp;quot;(ThingWithComps)&amp;quot; cast may or may not be needed&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use the &amp;quot;get&amp;quot; method we created ====&lt;br /&gt;
&amp;lt;source lang=&amp;quot;C#&amp;quot;&amp;gt;&lt;br /&gt;
    // real world example:&lt;br /&gt;
    SlotGroup slotGroup = GetSlotGroupInEarlierCode();&lt;br /&gt;
    MyLinkedCompThing comp = ((ThingWithComps)slotGroup.parent).GetComp&amp;lt;MyLinkedCompThing&amp;gt;();&lt;br /&gt;
    if (comp != null) {&lt;br /&gt;
        string s = comp.myCustomCompProperty;&lt;br /&gt;
        int x = otherObject.GetComp&amp;lt;MyLinkedCompThing&amp;gt;().mySecondCompProp; // be sure it exists, etc&lt;br /&gt;
    } else { /* not a thing with my comp, etc */ }&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cautions, traps, etc ===&lt;br /&gt;
If you have the same comp in an abstract (XML) def and attempt to redefine it in a (XML) child def, it will get counted twice.  It's possible to get around this in the code, if you want to have default comps:&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;ThingDef Name=ParentWithDefault ... Abstract=true&amp;gt;&lt;br /&gt;
    ...&lt;br /&gt;
    &amp;lt;comps&amp;gt;&lt;br /&gt;
      &amp;lt;l&amp;lt;nowiki&amp;gt;i&amp;lt;/nowiki&amp;gt; Class=&amp;quot;MyCompPropertiesWithDefault&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;myValue&amp;gt;3&amp;lt;/myValue&amp;gt;&amp;lt;!--default!--&amp;gt;&lt;br /&gt;
      &amp;lt;/l&amp;lt;nowiki&amp;gt;i&amp;lt;/nowiki&amp;gt;&amp;gt;&lt;br /&gt;
    &amp;lt;/comps&amp;gt;&lt;br /&gt;
  &amp;lt;/ThingDef&amp;gt;&lt;br /&gt;
  &amp;lt;ThingDef ParentName=&amp;quot;ParentWihtDefault&amp;quot;&amp;gt;&lt;br /&gt;
    ...&lt;br /&gt;
    &amp;lt;comps&amp;gt;&lt;br /&gt;
      &amp;lt;l&amp;lt;nowiki&amp;gt;i&amp;lt;/nowiki&amp;gt; Class=&amp;quot;MyCompPropertiesWithDefault&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;myValue&amp;gt;5&amp;lt;/myValue&amp;gt;&amp;lt;!-- override default!--&amp;gt;&lt;br /&gt;
      &amp;lt;/&amp;lt;nowiki&amp;gt;l&amp;lt;/nowiki&amp;gt;i&amp;gt;&lt;br /&gt;
    &amp;lt;/comps&amp;gt;&lt;br /&gt;
  &amp;lt;/ThingDef&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  public class MyLinkedCompThing : ThingComp&lt;br /&gt;
  {&lt;br /&gt;
    public string myCustomCompProperty //etc&lt;br /&gt;
    &lt;br /&gt;
    public override void Initialize (CompProperties props) {&lt;br /&gt;
      base.Initialize(props);&lt;br /&gt;
      // Remove duplicate entries and ensure the last entry is the only one left&lt;br /&gt;
      //   This allows a default abstract def with the comp&lt;br /&gt;
      //   and child def to change the comp value:&lt;br /&gt;
      MyCompProprtiesWithDefault[] list = this.parent.GetComps&amp;lt;MyCompPropertiesWithDefault&amp;gt;().ToArray();&lt;br /&gt;
      // Remove everything but the last entry; harmless if only one entry:&lt;br /&gt;
      for (var i = 0; i &amp;lt; list.Length-1; i++)&lt;br /&gt;
      {&lt;br /&gt;
        this.parent.AllComps.Remove(list[i]);&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
  &lt;br /&gt;
  ///etc&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
[[Category:Modding tutorials]][[Category:Modding]][[Category:Defs]]&lt;/div&gt;</summary>
		<author><name>Lilwhitemouse</name></author>
	</entry>
	<entry>
		<id>https://rimworldwiki.com/index.php?title=Modding_Tutorials/Custom_Comp_Classes&amp;diff=62031</id>
		<title>Modding Tutorials/Custom Comp Classes</title>
		<link rel="alternate" type="text/html" href="https://rimworldwiki.com/index.php?title=Modding_Tutorials/Custom_Comp_Classes&amp;diff=62031"/>
		<updated>2019-01-06T03:34:41Z</updated>

		<summary type="html">&lt;p&gt;Lilwhitemouse: /* Accessing your Comps */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Creating a custom comp class is a convenient way to add new functionality to RimWorld.&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
* You need to have [[Modding Tutorials/Setting up a solution|set up your editor and environment]]&lt;br /&gt;
* You need to know [[Modding Tutorials/Writing custom code|how to write custom code]]&lt;br /&gt;
* You should probably understand Defs at least somewhat.&lt;br /&gt;
&lt;br /&gt;
== def (xml) and C# structure ==&lt;br /&gt;
&lt;br /&gt;
=== Setup, Defs, and Classes ===&lt;br /&gt;
You will have some custom def and it will have something like this:&lt;br /&gt;
==== Defs (xml) ====&lt;br /&gt;
  &amp;lt;ThingDef ...&amp;gt;&lt;br /&gt;
    ...&lt;br /&gt;
    ...&lt;br /&gt;
    &amp;lt;comps&amp;gt;&lt;br /&gt;
      &amp;lt;&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt; Class=&amp;quot;MyNamespace.MyCompProperties&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;myCustomCompProperty&amp;gt;some value&amp;lt;/myCustomCompProperty&amp;gt;&lt;br /&gt;
        &amp;lt;mySecondCompProp&amp;gt;4&amp;lt;/mySecondCompProp&amp;gt;&lt;br /&gt;
      &amp;lt;/&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt;&amp;gt;&lt;br /&gt;
      &amp;lt;&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt;&amp;gt;&lt;br /&gt;
        ''&amp;lt;&amp;lt;nowiki&amp;gt;!--&amp;lt;/nowiki&amp;gt; this is kind of like &amp;lt;tag&amp;gt;MN.MyCustomTag&amp;lt;/tag&amp;gt;:--&amp;gt;''&lt;br /&gt;
        &amp;lt;compClass&amp;gt;MyNamespace.MyCustomThingComp&amp;lt;/compClass&amp;gt;&lt;br /&gt;
      &amp;lt;/&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt;&amp;gt;&lt;br /&gt;
    &amp;lt;/comps&amp;gt;&lt;br /&gt;
  &amp;lt;/ThingDef&amp;gt;&lt;br /&gt;
==== C# ====&lt;br /&gt;
  namespace MyNamespace ''// For example, LWM.ModName - by using your ''&lt;br /&gt;
                        ''//   handle/name/etc, you almost certainly guarantee uniqueness''&lt;br /&gt;
  {&lt;br /&gt;
  '''//////////// &amp;lt;&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt; Class=&amp;quot;MyNamespace.MyCompProperties&amp;quot;&amp;gt; ////////////'''&lt;br /&gt;
  public class MyCompProperties : CompProperties ''// Name this as you wish, of course''&lt;br /&gt;
  {&lt;br /&gt;
    public Properties() {&lt;br /&gt;
      this.compClass = typeof(MyNamespace.MyLinkedCompThing); ''// rename as appropriate''&lt;br /&gt;
    }&lt;br /&gt;
    public string myCustomCompProperty; ''// Name matches def, of course''&lt;br /&gt;
    public int mySecondCompProp = 1; ''// Can set default values''&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  ''// this ThingComp is used to actually access the comp property defined above''&lt;br /&gt;
  '''''// this is not &amp;quot;&amp;lt;compClass&amp;gt;MyNamespace.MyCustomThingComp&amp;lt;/compClass&amp;gt;&amp;quot;'''''&lt;br /&gt;
  public class MyLinkedCompThing : ThingComp&lt;br /&gt;
  {&lt;br /&gt;
    public string myCustomCompProperty&lt;br /&gt;
    {&lt;br /&gt;
      get&lt;br /&gt;
      {&lt;br /&gt;
        return ((MyCompProperties)this.props).myCustomCompProperty;&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    public int mySecondCompProperty ''// Have to get all the names right''&lt;br /&gt;
    { get  { return ((MyCompProperties)this.props).mySecondCompProperty; } } ''//etc''&lt;br /&gt;
  }&lt;br /&gt;
  '''//////////// &amp;lt;compClass&amp;gt;MyNamespace.MyCustomThingComp&amp;lt;/compClass&amp;gt; ////////////'''&lt;br /&gt;
  public class MyCustomThingComp : ThingComp&lt;br /&gt;
  {&lt;br /&gt;
    public override void CompTick()&lt;br /&gt;
    {&lt;br /&gt;
      // do stuff&lt;br /&gt;
    }&lt;br /&gt;
    public override void CompTickRare() //etc&lt;br /&gt;
    public override ... // Check out Verse/ThingComp.cs for more ideas&lt;br /&gt;
  }&lt;br /&gt;
  } // end MyNamespace&lt;br /&gt;
&lt;br /&gt;
=== Accessing your Comps ===&lt;br /&gt;
Just setting up your custom comps doesn't do you a lot of good if you can't access them!&lt;br /&gt;
&lt;br /&gt;
==== Accessing CompProperty directly ====&lt;br /&gt;
This is the &amp;quot;hard&amp;quot; way, but doable if you want:&lt;br /&gt;
&amp;lt;code lang=&amp;quot;C#&amp;quot;&amp;gt;&lt;br /&gt;
    int importantProperty = ((MyCompProperties)((ThingWithComps)myObject).GetComp&amp;lt;MyLinkedCompThing&amp;gt;().props).mySecondCompProp;&lt;br /&gt;
    //     The &amp;quot;(ThingWithComps) cast may or may not be needed&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Use the &amp;quot;get&amp;quot; method we created ====&lt;br /&gt;
&amp;lt;code lang=&amp;quot;C#&amp;quot;&amp;gt;&lt;br /&gt;
    // real world example:&lt;br /&gt;
    SlotGroup slotGroup = GetSlotGroupInEarlierCode();&lt;br /&gt;
    MyLinkedCompThing comp = ((ThingWithComps)slotGroup.parent).GetComp&amp;lt;MyLinkedCompThing&amp;gt;();&lt;br /&gt;
    if (comp != null) {&lt;br /&gt;
        string s = comp.myCustomCompProperty;&lt;br /&gt;
        int x = otherObject.GetComp&amp;lt;MyLinkedCompThing&amp;gt;().mySecondCompProp; // be sure it exists, etc&lt;br /&gt;
    } else { /* not a thing with my comp, etc */ }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Cautions, traps, etc ===&lt;br /&gt;
If you have the same comp in an abstract (XML) def and attempt to redefine it in a (XML) child def, it will get counted twice.  It's possible to get around this in the code, if you want to have default comps:&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;ThingDef Name=ParentWithDefault ... Abstract=true&amp;gt;&lt;br /&gt;
    ...&lt;br /&gt;
    &amp;lt;comps&amp;gt;&lt;br /&gt;
      &amp;lt;l&amp;lt;nowiki&amp;gt;i&amp;lt;/nowiki&amp;gt; Class=&amp;quot;MyCompPropertiesWithDefault&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;myValue&amp;gt;3&amp;lt;/myValue&amp;gt;&amp;lt;!--default!--&amp;gt;&lt;br /&gt;
      &amp;lt;/l&amp;lt;nowiki&amp;gt;i&amp;lt;/nowiki&amp;gt;&amp;gt;&lt;br /&gt;
    &amp;lt;/comps&amp;gt;&lt;br /&gt;
  &amp;lt;/ThingDef&amp;gt;&lt;br /&gt;
  &amp;lt;ThingDef ParentName=&amp;quot;ParentWihtDefault&amp;quot;&amp;gt;&lt;br /&gt;
    ...&lt;br /&gt;
    &amp;lt;comps&amp;gt;&lt;br /&gt;
      &amp;lt;l&amp;lt;nowiki&amp;gt;i&amp;lt;/nowiki&amp;gt; Class=&amp;quot;MyCompPropertiesWithDefault&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;myValue&amp;gt;5&amp;lt;/myValue&amp;gt;&amp;lt;!-- override default!--&amp;gt;&lt;br /&gt;
      &amp;lt;/&amp;lt;nowiki&amp;gt;l&amp;lt;/nowiki&amp;gt;i&amp;gt;&lt;br /&gt;
    &amp;lt;/comps&amp;gt;&lt;br /&gt;
  &amp;lt;/ThingDef&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  public class MyLinkedCompThing : ThingComp&lt;br /&gt;
  {&lt;br /&gt;
    public string myCustomCompProperty //etc&lt;br /&gt;
    &lt;br /&gt;
    public override void Initialize (CompProperties props) {&lt;br /&gt;
      base.Initialize(props);&lt;br /&gt;
      // Remove duplicate entries and ensure the last entry is the only one left&lt;br /&gt;
      //   This allows a default abstract def with the comp&lt;br /&gt;
      //   and child def to change the comp value:&lt;br /&gt;
      MyCompProprtiesWithDefault[] list = this.parent.GetComps&amp;lt;MyCompPropertiesWithDefault&amp;gt;().ToArray();&lt;br /&gt;
      // Remove everything but the last entry; harmless if only one entry:&lt;br /&gt;
      for (var i = 0; i &amp;lt; list.Length-1; i++)&lt;br /&gt;
      {&lt;br /&gt;
        this.parent.AllComps.Remove(list[i]);&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
  &lt;br /&gt;
  ///etc&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
[[Category:Modding tutorials]][[Category:Modding]][[Category:Defs]]&lt;/div&gt;</summary>
		<author><name>Lilwhitemouse</name></author>
	</entry>
	<entry>
		<id>https://rimworldwiki.com/index.php?title=Modding_Tutorials/Custom_Comp_Classes&amp;diff=62027</id>
		<title>Modding Tutorials/Custom Comp Classes</title>
		<link rel="alternate" type="text/html" href="https://rimworldwiki.com/index.php?title=Modding_Tutorials/Custom_Comp_Classes&amp;diff=62027"/>
		<updated>2019-01-05T22:23:51Z</updated>

		<summary type="html">&lt;p&gt;Lilwhitemouse: /* Cautions, traps, etc */ clearer&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Creating a custom comp class is a convenient way to add new functionality to RimWorld.&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
* You need to have [[Modding Tutorials/Setting up a solution|set up your editor and environment]]&lt;br /&gt;
* You need to know [[Modding Tutorials/Writing custom code|how to write custom code]]&lt;br /&gt;
* You should probably understand Defs at least somewhat.&lt;br /&gt;
&lt;br /&gt;
== def (xml) and C# structure ==&lt;br /&gt;
&lt;br /&gt;
=== Setup, Defs, and Classes ===&lt;br /&gt;
You will have some custom def and it will have something like this:&lt;br /&gt;
==== Defs (xml) ====&lt;br /&gt;
  &amp;lt;ThingDef ...&amp;gt;&lt;br /&gt;
    ...&lt;br /&gt;
    ...&lt;br /&gt;
    &amp;lt;comps&amp;gt;&lt;br /&gt;
      &amp;lt;&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt; Class=&amp;quot;MyNamespace.MyCompProperties&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;myCustomCompProperty&amp;gt;some value&amp;lt;/myCustomCompProperty&amp;gt;&lt;br /&gt;
        &amp;lt;mySecondCompProp&amp;gt;4&amp;lt;/mySecondCompProp&amp;gt;&lt;br /&gt;
      &amp;lt;/&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt;&amp;gt;&lt;br /&gt;
      &amp;lt;&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt;&amp;gt;&lt;br /&gt;
        ''&amp;lt;&amp;lt;nowiki&amp;gt;!--&amp;lt;/nowiki&amp;gt; this is kind of like &amp;lt;tag&amp;gt;MN.MyCustomTag&amp;lt;/tag&amp;gt;:--&amp;gt;''&lt;br /&gt;
        &amp;lt;compClass&amp;gt;MyNamespace.MyCustomThingComp&amp;lt;/compClass&amp;gt;&lt;br /&gt;
      &amp;lt;/&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt;&amp;gt;&lt;br /&gt;
    &amp;lt;/comps&amp;gt;&lt;br /&gt;
  &amp;lt;/ThingDef&amp;gt;&lt;br /&gt;
==== C# ====&lt;br /&gt;
  namespace MyNamespace ''// For example, LWM.ModName - by using your ''&lt;br /&gt;
                        ''//   handle/name/etc, you almost certainly guarantee uniqueness''&lt;br /&gt;
  {&lt;br /&gt;
  '''//////////// &amp;lt;&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt; Class=&amp;quot;MyNamespace.MyCompProperties&amp;quot;&amp;gt; ////////////'''&lt;br /&gt;
  public class MyCompProperties : CompProperties ''// Name this as you wish, of course''&lt;br /&gt;
  {&lt;br /&gt;
    public Properties() {&lt;br /&gt;
      this.compClass = typeof(MyNamespace.MyLinkedCompThing); ''// rename as appropriate''&lt;br /&gt;
    }&lt;br /&gt;
    public string myCustomCompProperty; ''// Name matches def, of course''&lt;br /&gt;
    public int mySecondCompProp = 1; ''// Can set default values''&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  ''// this ThingComp is used to actually access the comp property defined above''&lt;br /&gt;
  '''''// this is not &amp;quot;&amp;lt;compClass&amp;gt;MyNamespace.MyCustomThingComp&amp;lt;/compClass&amp;gt;&amp;quot;'''''&lt;br /&gt;
  public class MyLinkedCompThing : ThingComp&lt;br /&gt;
  {&lt;br /&gt;
    public string myCustomCompProperty&lt;br /&gt;
    {&lt;br /&gt;
      get&lt;br /&gt;
      {&lt;br /&gt;
        return ((MyCompProperties)this.props).myCustomCompProperty;&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    public int mySecondCompProperty ''// Have to get all the names right''&lt;br /&gt;
    { get  { return ((MyCompProperties)this.props).mySecondCompProperty; } } ''//etc''&lt;br /&gt;
  }&lt;br /&gt;
  '''//////////// &amp;lt;compClass&amp;gt;MyNamespace.MyCustomThingComp&amp;lt;/compClass&amp;gt; ////////////'''&lt;br /&gt;
  public class MyCustomThingComp : ThingComp&lt;br /&gt;
  {&lt;br /&gt;
    public override void CompTick()&lt;br /&gt;
    {&lt;br /&gt;
      // do stuff&lt;br /&gt;
    }&lt;br /&gt;
    public override void CompTickRare() //etc&lt;br /&gt;
    public override ... // Check out Verse/ThingComp.cs for more ideas&lt;br /&gt;
  }&lt;br /&gt;
  } // end MyNamespace&lt;br /&gt;
&lt;br /&gt;
=== Accessing your Comps ===&lt;br /&gt;
Just setting up your custom comps doesn't do you a lot of good if you can't access them!&lt;br /&gt;
&lt;br /&gt;
'''To do'''&lt;br /&gt;
&lt;br /&gt;
=== Cautions, traps, etc ===&lt;br /&gt;
If you have the same comp in an abstract (XML) def and attempt to redefine it in a (XML) child def, it will get counted twice.  It's possible to get around this in the code, if you want to have default comps:&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;ThingDef Name=ParentWithDefault ... Abstract=true&amp;gt;&lt;br /&gt;
    ...&lt;br /&gt;
    &amp;lt;comps&amp;gt;&lt;br /&gt;
      &amp;lt;l&amp;lt;nowiki&amp;gt;i&amp;lt;/nowiki&amp;gt; Class=&amp;quot;MyCompPropertiesWithDefault&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;myValue&amp;gt;3&amp;lt;/myValue&amp;gt;&amp;lt;!--default!--&amp;gt;&lt;br /&gt;
      &amp;lt;/l&amp;lt;nowiki&amp;gt;i&amp;lt;/nowiki&amp;gt;&amp;gt;&lt;br /&gt;
    &amp;lt;/comps&amp;gt;&lt;br /&gt;
  &amp;lt;/ThingDef&amp;gt;&lt;br /&gt;
  &amp;lt;ThingDef ParentName=&amp;quot;ParentWihtDefault&amp;quot;&amp;gt;&lt;br /&gt;
    ...&lt;br /&gt;
    &amp;lt;comps&amp;gt;&lt;br /&gt;
      &amp;lt;l&amp;lt;nowiki&amp;gt;i&amp;lt;/nowiki&amp;gt; Class=&amp;quot;MyCompPropertiesWithDefault&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;myValue&amp;gt;5&amp;lt;/myValue&amp;gt;&amp;lt;!-- override default!--&amp;gt;&lt;br /&gt;
      &amp;lt;/&amp;lt;nowiki&amp;gt;l&amp;lt;/nowiki&amp;gt;i&amp;gt;&lt;br /&gt;
    &amp;lt;/comps&amp;gt;&lt;br /&gt;
  &amp;lt;/ThingDef&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  public class MyLinkedCompThing : ThingComp&lt;br /&gt;
  {&lt;br /&gt;
    public string myCustomCompProperty //etc&lt;br /&gt;
    &lt;br /&gt;
    public override void Initialize (CompProperties props) {&lt;br /&gt;
      base.Initialize(props);&lt;br /&gt;
      // Remove duplicate entries and ensure the last entry is the only one left&lt;br /&gt;
      //   This allows a default abstract def with the comp&lt;br /&gt;
      //   and child def to change the comp value:&lt;br /&gt;
      MyCompProprtiesWithDefault[] list = this.parent.GetComps&amp;lt;MyCompPropertiesWithDefault&amp;gt;().ToArray();&lt;br /&gt;
      // Remove everything but the last entry; harmless if only one entry:&lt;br /&gt;
      for (var i = 0; i &amp;lt; list.Length-1; i++)&lt;br /&gt;
      {&lt;br /&gt;
        this.parent.AllComps.Remove(list[i]);&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
  &lt;br /&gt;
  ///etc&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
[[Category:Modding tutorials]][[Category:Modding]][[Category:Defs]]&lt;/div&gt;</summary>
		<author><name>Lilwhitemouse</name></author>
	</entry>
	<entry>
		<id>https://rimworldwiki.com/index.php?title=Modding_Tutorials/Custom_Comp_Classes&amp;diff=62026</id>
		<title>Modding Tutorials/Custom Comp Classes</title>
		<link rel="alternate" type="text/html" href="https://rimworldwiki.com/index.php?title=Modding_Tutorials/Custom_Comp_Classes&amp;diff=62026"/>
		<updated>2019-01-05T22:23:18Z</updated>

		<summary type="html">&lt;p&gt;Lilwhitemouse: fixed typo&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Creating a custom comp class is a convenient way to add new functionality to RimWorld.&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
* You need to have [[Modding Tutorials/Setting up a solution|set up your editor and environment]]&lt;br /&gt;
* You need to know [[Modding Tutorials/Writing custom code|how to write custom code]]&lt;br /&gt;
* You should probably understand Defs at least somewhat.&lt;br /&gt;
&lt;br /&gt;
== def (xml) and C# structure ==&lt;br /&gt;
&lt;br /&gt;
=== Setup, Defs, and Classes ===&lt;br /&gt;
You will have some custom def and it will have something like this:&lt;br /&gt;
==== Defs (xml) ====&lt;br /&gt;
  &amp;lt;ThingDef ...&amp;gt;&lt;br /&gt;
    ...&lt;br /&gt;
    ...&lt;br /&gt;
    &amp;lt;comps&amp;gt;&lt;br /&gt;
      &amp;lt;&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt; Class=&amp;quot;MyNamespace.MyCompProperties&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;myCustomCompProperty&amp;gt;some value&amp;lt;/myCustomCompProperty&amp;gt;&lt;br /&gt;
        &amp;lt;mySecondCompProp&amp;gt;4&amp;lt;/mySecondCompProp&amp;gt;&lt;br /&gt;
      &amp;lt;/&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt;&amp;gt;&lt;br /&gt;
      &amp;lt;&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt;&amp;gt;&lt;br /&gt;
        ''&amp;lt;&amp;lt;nowiki&amp;gt;!--&amp;lt;/nowiki&amp;gt; this is kind of like &amp;lt;tag&amp;gt;MN.MyCustomTag&amp;lt;/tag&amp;gt;:--&amp;gt;''&lt;br /&gt;
        &amp;lt;compClass&amp;gt;MyNamespace.MyCustomThingComp&amp;lt;/compClass&amp;gt;&lt;br /&gt;
      &amp;lt;/&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt;&amp;gt;&lt;br /&gt;
    &amp;lt;/comps&amp;gt;&lt;br /&gt;
  &amp;lt;/ThingDef&amp;gt;&lt;br /&gt;
==== C# ====&lt;br /&gt;
  namespace MyNamespace ''// For example, LWM.ModName - by using your ''&lt;br /&gt;
                        ''//   handle/name/etc, you almost certainly guarantee uniqueness''&lt;br /&gt;
  {&lt;br /&gt;
  '''//////////// &amp;lt;&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt; Class=&amp;quot;MyNamespace.MyCompProperties&amp;quot;&amp;gt; ////////////'''&lt;br /&gt;
  public class MyCompProperties : CompProperties ''// Name this as you wish, of course''&lt;br /&gt;
  {&lt;br /&gt;
    public Properties() {&lt;br /&gt;
      this.compClass = typeof(MyNamespace.MyLinkedCompThing); ''// rename as appropriate''&lt;br /&gt;
    }&lt;br /&gt;
    public string myCustomCompProperty; ''// Name matches def, of course''&lt;br /&gt;
    public int mySecondCompProp = 1; ''// Can set default values''&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  ''// this ThingComp is used to actually access the comp property defined above''&lt;br /&gt;
  '''''// this is not &amp;quot;&amp;lt;compClass&amp;gt;MyNamespace.MyCustomThingComp&amp;lt;/compClass&amp;gt;&amp;quot;'''''&lt;br /&gt;
  public class MyLinkedCompThing : ThingComp&lt;br /&gt;
  {&lt;br /&gt;
    public string myCustomCompProperty&lt;br /&gt;
    {&lt;br /&gt;
      get&lt;br /&gt;
      {&lt;br /&gt;
        return ((MyCompProperties)this.props).myCustomCompProperty;&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    public int mySecondCompProperty ''// Have to get all the names right''&lt;br /&gt;
    { get  { return ((MyCompProperties)this.props).mySecondCompProperty; } } ''//etc''&lt;br /&gt;
  }&lt;br /&gt;
  '''//////////// &amp;lt;compClass&amp;gt;MyNamespace.MyCustomThingComp&amp;lt;/compClass&amp;gt; ////////////'''&lt;br /&gt;
  public class MyCustomThingComp : ThingComp&lt;br /&gt;
  {&lt;br /&gt;
    public override void CompTick()&lt;br /&gt;
    {&lt;br /&gt;
      // do stuff&lt;br /&gt;
    }&lt;br /&gt;
    public override void CompTickRare() //etc&lt;br /&gt;
    public override ... // Check out Verse/ThingComp.cs for more ideas&lt;br /&gt;
  }&lt;br /&gt;
  } // end MyNamespace&lt;br /&gt;
&lt;br /&gt;
=== Accessing your Comps ===&lt;br /&gt;
Just setting up your custom comps doesn't do you a lot of good if you can't access them!&lt;br /&gt;
&lt;br /&gt;
'''To do'''&lt;br /&gt;
&lt;br /&gt;
=== Cautions, traps, etc ===&lt;br /&gt;
If you have the same comp in an abstract def and attempt to redefine it in a child def, it will get counted twice.  It's possible to get around this in the code, if you want to have default comps:&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;ThingDef Name=ParentWithDefault ... Abstract=true&amp;gt;&lt;br /&gt;
    ...&lt;br /&gt;
    &amp;lt;comps&amp;gt;&lt;br /&gt;
      &amp;lt;l&amp;lt;nowiki&amp;gt;i&amp;lt;/nowiki&amp;gt; Class=&amp;quot;MyCompPropertiesWithDefault&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;myValue&amp;gt;3&amp;lt;/myValue&amp;gt;&amp;lt;!--default!--&amp;gt;&lt;br /&gt;
      &amp;lt;/l&amp;lt;nowiki&amp;gt;i&amp;lt;/nowiki&amp;gt;&amp;gt;&lt;br /&gt;
    &amp;lt;/comps&amp;gt;&lt;br /&gt;
  &amp;lt;/ThingDef&amp;gt;&lt;br /&gt;
  &amp;lt;ThingDef ParentName=&amp;quot;ParentWihtDefault&amp;quot;&amp;gt;&lt;br /&gt;
    ...&lt;br /&gt;
    &amp;lt;comps&amp;gt;&lt;br /&gt;
      &amp;lt;l&amp;lt;nowiki&amp;gt;i&amp;lt;/nowiki&amp;gt; Class=&amp;quot;MyCompPropertiesWithDefault&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;myValue&amp;gt;5&amp;lt;/myValue&amp;gt;&amp;lt;!-- override default!--&amp;gt;&lt;br /&gt;
      &amp;lt;/&amp;lt;nowiki&amp;gt;l&amp;lt;/nowiki&amp;gt;i&amp;gt;&lt;br /&gt;
    &amp;lt;/comps&amp;gt;&lt;br /&gt;
  &amp;lt;/ThingDef&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  public class MyLinkedCompThing : ThingComp&lt;br /&gt;
  {&lt;br /&gt;
    public string myCustomCompProperty //etc&lt;br /&gt;
    &lt;br /&gt;
    public override void Initialize (CompProperties props) {&lt;br /&gt;
      base.Initialize(props);&lt;br /&gt;
      // Remove duplicate entries and ensure the last entry is the only one left&lt;br /&gt;
      //   This allows a default abstract def with the comp&lt;br /&gt;
      //   and child def to change the comp value:&lt;br /&gt;
      MyCompProprtiesWithDefault[] list = this.parent.GetComps&amp;lt;MyCompPropertiesWithDefault&amp;gt;().ToArray();&lt;br /&gt;
      // Remove everything but the last entry; harmless if only one entry:&lt;br /&gt;
      for (var i = 0; i &amp;lt; list.Length-1; i++)&lt;br /&gt;
      {&lt;br /&gt;
        this.parent.AllComps.Remove(list[i]);&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
  &lt;br /&gt;
  ///etc&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
[[Category:Modding tutorials]][[Category:Modding]][[Category:Defs]]&lt;/div&gt;</summary>
		<author><name>Lilwhitemouse</name></author>
	</entry>
	<entry>
		<id>https://rimworldwiki.com/index.php?title=Modding_Tutorials/Setting_up_a_solution&amp;diff=62021</id>
		<title>Modding Tutorials/Setting up a solution</title>
		<link rel="alternate" type="text/html" href="https://rimworldwiki.com/index.php?title=Modding_Tutorials/Setting_up_a_solution&amp;diff=62021"/>
		<updated>2019-01-04T02:27:21Z</updated>

		<summary type="html">&lt;p&gt;Lilwhitemouse: /* Option 2 (Automatic Method): */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{BackToTutorials}}&lt;br /&gt;
{{Credit|[[User:Alistaire|Alistaire]]}}&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this tutorial you will learn how to set up a solution, along with instructions on setting the output directory and files for more convenient building right into the Assemblies folder.&lt;br /&gt;
&lt;br /&gt;
=Important Note=&lt;br /&gt;
There is a [https://ludeon.com/forums/index.php?topic=39038.0 Rimworld Mod Development Cookiecutter] tool available that should be able to set up a lot of these files/etc for you!&lt;br /&gt;
&lt;br /&gt;
=Requirements=&lt;br /&gt;
&lt;br /&gt;
* The manual option in this tutorial requires you to have [[Modding_Tutorials/Mod_folder_structure#The Source and Assemblies folders|set up a Source and Assemblies folder]] (the Visual Studio automatic option sets this up for you).&lt;br /&gt;
* You will want to have an IDE installed: [[Modding Tutorials/Recommended software#IDE's|Recommended IDE's]].&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Setting up a solution=&lt;br /&gt;
Setting up can be different for different IDE's. Feel free to add '''''complete''''' instructions for your IDE of choice.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio Community 2017===&lt;br /&gt;
''NOTE: Visual Studio 2017 is a rather heavy application (2-3 GB for basic functionality) but has a bit more functionality. Only Install if your computer can handle it! The tutorial is similar for Visual Studio 2015.''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Option 1 (Manual Method):====&lt;br /&gt;
# Create a new class library project&lt;br /&gt;
## Once loaded, go to File -&amp;gt; New -&amp;gt; Project...&lt;br /&gt;
## Go to Templates -&amp;gt; Visual C# -&amp;gt; Class Library (Be sure to select the *.NET Framework* version, not *.NET Standard*) [[File:Capture.png|200px|thumb|right|Installing the .NET framework]]&lt;br /&gt;
## Enter your name and solution name in the lower pane.&lt;br /&gt;
## Choose a location, preferably:&amp;lt;br/&amp;gt;&amp;lt;pre&amp;gt;(RimWorldInstallFolder)/Mods/(YourModName)/Source&amp;lt;/pre&amp;gt;&lt;br /&gt;
## ''Optional'': Untick &amp;quot;Create directory for solution&amp;quot;&lt;br /&gt;
# In your project, set target framework and various other porperties&lt;br /&gt;
## In your Solution Explorer, right click your project -&amp;gt; Properties&lt;br /&gt;
## Once in your properties, select Application -&amp;gt; Set Target Framework to .NET Framework 3.5 (No client profile)&lt;br /&gt;
## ''Optional'': Change your Assembly and Namespace names to anything of your choice&lt;br /&gt;
## Go to Build -&amp;gt; Advanced... and set &amp;quot;Debugging information&amp;quot; to none&lt;br /&gt;
## Leave Advanced..., and set the Output Path to &amp;quot;..\..\Assemblies\&amp;quot; (The Assemblies folder in your mod folder)&lt;br /&gt;
# Add references to RimWorld code&lt;br /&gt;
## Expand your project. Then right click &amp;quot;References&amp;quot; -&amp;gt; Add Reference...&lt;br /&gt;
## Click Browse...&lt;br /&gt;
## Navigate towards &amp;lt;pre&amp;gt;RimWorld******/RimWorld******_Data/Managed&amp;lt;/pre&amp;gt; and select files: &amp;lt;br/&amp;gt;&amp;lt;pre&amp;gt;Assembly-CSharp.dll&amp;amp;#10;UnityEngine.dll&amp;lt;/pre&amp;gt;&lt;br /&gt;
## Click &amp;quot;Add&amp;quot;&lt;br /&gt;
## Right click on both Assembly-CSharp.dll and UnityEngine.dll and set Copy Local to False (Properties pane).&lt;br /&gt;
&lt;br /&gt;
====Option 2 (Automatic Method):====&lt;br /&gt;
'''Note: As of Jan 2019, the cookiecutter is set up for Windows development.  Linux/Mac people can still use it, but they will have a few errors to clean up.'''&lt;br /&gt;
# Open Visual Studio&lt;br /&gt;
# Once loaded, go to File -&amp;gt; New -&amp;gt; From Cookiecutter...&lt;br /&gt;
# Search for ''rimworld''&lt;br /&gt;
# Double-click ''cookiecutter-rimworld-mod-development''&lt;br /&gt;
# Change the Template Options:&lt;br /&gt;
## ''Create To'' =&amp;gt; ''Your/Rimworld/Mod/Directory''&lt;br /&gt;
## ''mod_name''&lt;br /&gt;
## ''namespace_name'' (don't change if unsure)&lt;br /&gt;
## ''author'' =&amp;gt; ''your steam username''&lt;br /&gt;
## ''target_version'' =&amp;gt; current RW version (can leave blank for most up-to-date)&lt;br /&gt;
## ''in_game_description'' (not required, can change later in About-Release.xml)&lt;br /&gt;
## ''url'' (can leave blank for link to your Steam Workshop profile)&lt;br /&gt;
# Click &amp;quot;Create and Open Folder&amp;quot;&lt;br /&gt;
&lt;br /&gt;
===Sharpdevelop===&lt;br /&gt;
'''Caution:''' Sharpdevelop (or #develop) does NOT CURRENTLY allow for C# 6.0+ syntax without plugins and does NOT ALLOW for C# 7.0+ syntax at all. For your average project this does not matter, however some existing projects are already built entirely upon C# 6.0+ syntax which can not be compiled anymore in Sharpdevelop. Visual Studio does not have these issues and should be your go-to for compiling large projects such as Combat Extended.&lt;br /&gt;
&lt;br /&gt;
# Create a new class library project in your [[Modding Tutorials/Recommended software#IDE.27s|IDE of choice]];&lt;br /&gt;
## Go to File -&amp;gt; New -&amp;gt; Solution;&lt;br /&gt;
## Go to C# or .NET -&amp;gt; Library or Class Library (NOT portable);&lt;br /&gt;
## Enter a project name (solution name automatically updated);&lt;br /&gt;
## Choose a location, preferably:&amp;lt;br/&amp;gt;&amp;lt;pre&amp;gt;(RimWorldInstallFolder)/Mods/(YourModName)/Source&amp;lt;/pre&amp;gt;&lt;br /&gt;
## ''Optional'': Untick &amp;quot;Create a directory for solution&amp;quot;/&amp;quot;Create a project within the solution directory&amp;quot;,&lt;br /&gt;
# In your project, add references to Assembly-CSharp.dll and UnityEngine.dll:&lt;br /&gt;
## In your IDE project file browser, right-click the &amp;quot;References&amp;quot; folder and &amp;quot;Add reference&amp;quot;;&lt;br /&gt;
## Choose the &amp;quot;.NET Assembly Browser&amp;quot; tab and &amp;quot;Browse...&amp;quot;;&lt;br /&gt;
## Navigate towards &amp;lt;pre&amp;gt;RimWorld******/RimWorld******_Data/Managed&amp;lt;/pre&amp;gt; and select files: &amp;lt;br/&amp;gt;&amp;lt;pre&amp;gt;Assembly-CSharp.dll&amp;amp;#10;UnityEngine.dll&amp;lt;/pre&amp;gt;&lt;br /&gt;
## Click &amp;quot;Open&amp;quot; then &amp;quot;OK&amp;quot;;&lt;br /&gt;
## In the References folder, right-click Assembly-CSharp -&amp;gt; Properties and change &amp;quot;Local copy&amp;quot; to False. Do the same for UnityEngine,&lt;br /&gt;
# In your project properties, change the target framework to .NET 3.5:&lt;br /&gt;
## In your IDE project file browser, right-click &amp;quot;(YourSolutionName)&amp;quot;;&lt;br /&gt;
## Choose Properties;&lt;br /&gt;
## Go to the &amp;quot;Compiling&amp;quot; tab, &amp;quot;Output&amp;quot;, &amp;quot;Target framework&amp;quot;, &amp;quot;Change&amp;quot; and choose &amp;quot;.NET Framework 3.5&amp;quot;,&lt;br /&gt;
# In your project properties, change the build events so only a single file is built:&lt;br /&gt;
## Go to the &amp;quot;Compiling&amp;quot; tab, &amp;quot;Output&amp;quot;, &amp;quot;Debug info&amp;quot; and choose &amp;quot;No debug information&amp;quot;;&lt;br /&gt;
## Right-click your .cs files -&amp;gt; Properties and change &amp;quot;Copy to output&amp;quot; (If you haven't resized the properties bar, this will be truncated to &amp;quot;Copy to out&amp;quot;) to Never,&lt;br /&gt;
# In your project properties, fix the output location to put the DLL in the Assemblies folder:&lt;br /&gt;
## Go to the &amp;quot;Compiling&amp;quot; tab, &amp;quot;Output&amp;quot;, &amp;quot;Output path&amp;quot; and change the output path to &amp;quot;..\..\Assemblies\&amp;quot;.&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Xamarin/MonoDevelop===&lt;br /&gt;
The setup is similar as the one above. A few special points to address:&lt;br /&gt;
# Mono 4.X isn't backward compatible so you may need to install an older 3.X version of Mono in order to compile against .NET3.5 dlls.&lt;br /&gt;
# Make sure you uncheck &amp;quot;Use MSBuild build engine (recommended for this project type)&amp;quot; under project &amp;gt; options &amp;gt; build &amp;gt; general   (You might find this by right-clicking on your project - not solution - name and selecting options)&lt;br /&gt;
# Changing the framework to 3.5 can be found (for Linux anyway) in the same place.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Rider (good for Mac)===&lt;br /&gt;
JetBrains Rider is a great cross-platform C# IDE, but it isn't cheap. It's $140 for the first year, including perpetual access to that version (access to future updates gets cheaper, but it's still over $100/year). However, the Early Access versions are a bit unstable but free. They also offer free student licenses.&lt;br /&gt;
&lt;br /&gt;
# Open Rider and click New Solution in the welcome dialog.&lt;br /&gt;
## Click Class Library under .NET on the left. The option may a second to show up.&lt;br /&gt;
## Under Solution Name (and Project Name), enter the name of your mod.&lt;br /&gt;
## Set the Solution Directory to [your mod folder]/Source.&lt;br /&gt;
## Optionally check &amp;quot;put solution and project in the same directory.&amp;quot; This is probably a good idea.&lt;br /&gt;
## Change Framework to .Net Framework 3.5.&lt;br /&gt;
## Click Create.&lt;br /&gt;
# In the left side bar, expand your solution, right click your project (mod name with &amp;quot;C#&amp;quot; icon) and click Properties.&lt;br /&gt;
## In the Properties window, select Configurations &amp;gt; Debug on the left and uncheck Debug Symbols.&lt;br /&gt;
## For both configurations, change the Output Path to ../../Assemblies.&lt;br /&gt;
## Click OK.&lt;br /&gt;
# Expand your project, right click References and click Add Reference.&lt;br /&gt;
## Click Add From.&lt;br /&gt;
## Browse to the folder with the RimWorld DLLs (Mac: /Users/[username]/Library/Application Support/Steam/steamapps/common/RimWorld/RimWorldMac.app/Contents/Resources/Data/Managed).&lt;br /&gt;
## Select both Assembly-CSharp.dll and UnityEngine.dll and click OK.&lt;br /&gt;
## Expand Assemblies under References. For both of the assemblies that you just added:&lt;br /&gt;
### Right click the assembly and click Properties.&lt;br /&gt;
### Uncheck &amp;quot;Copy Local&amp;quot; (you may need to scroll down) and click OK.&lt;br /&gt;
&lt;br /&gt;
You're done! Note that Rider has a built-in decompiler—to view the source of a RimWorld class or method, just right-click its name and click Go To &amp;gt; Definition.&lt;br /&gt;
&lt;br /&gt;
=See also=&lt;br /&gt;
* [[Modding Tutorials/Writing custom code|Writing custom code]] continues on setting up your solution.&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Modding tutorials]]&lt;/div&gt;</summary>
		<author><name>Lilwhitemouse</name></author>
	</entry>
	<entry>
		<id>https://rimworldwiki.com/index.php?title=Modding&amp;diff=62020</id>
		<title>Modding</title>
		<link rel="alternate" type="text/html" href="https://rimworldwiki.com/index.php?title=Modding&amp;diff=62020"/>
		<updated>2019-01-04T01:59:30Z</updated>

		<summary type="html">&lt;p&gt;Lilwhitemouse: /* What you can mod */ +how pawns htink&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;!--Top Nav Box--&amp;gt;&lt;br /&gt;
{| align=center&lt;br /&gt;
| {{Basics_Nav}}&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{See also|List of mods}}&lt;br /&gt;
'''Mods''' (short for modifications) are small packages that add to or otherwise affect gameplay in RimWorld. They include art packs (for reskinning the game), more weapons, more incidents, furniture, and game-balancing mods.&lt;br /&gt;
&lt;br /&gt;
This page is about making mods. For info about using mods, see [[Installing mods]].&lt;br /&gt;
&lt;br /&gt;
==Mod-making tutorials== &lt;br /&gt;
Mod-making tutorials are available at the [[Modding Tutorials]] page. If you can't find what you need, you should try looking in [[Modding/Random Bits of Information|Random Bits of Information]] to check if the information you're looking for has been found but just hasn't been organized into the correct article yet.&lt;br /&gt;
&lt;br /&gt;
===Mod-making Templates===&lt;br /&gt;
*[https://ludeon.com/forums/index.php?topic=39038.0 Mod Development Cookiecutter (automatically build your mod development environment)]&lt;br /&gt;
&lt;br /&gt;
==What you can mod==&lt;br /&gt;
You can mod defs, code, images, and sounds.&lt;br /&gt;
&lt;br /&gt;
* '''Defs''': XML files containing lists of definitions for use by the game. There are a lot of these. They define every thing, skills, storyteller, and many other types of data. Find them in YourModName/Defs. More about this later.&lt;br /&gt;
* '''Code''': You can add .NET assemblies and the game will load them. Place your DLLs in YourModName/Assemblies. More about this later.&lt;br /&gt;
* '''Images''': You can add images.&lt;br /&gt;
* '''Sounds''': You can add sound files.&lt;br /&gt;
* '''Jobs''':  A useful link here https://github.com/Mehni/ExampleJob/wiki - covers JobGivers WorkGivers and Toils&lt;br /&gt;
** Higher level, explanation on how pawns think:  https://github.com/roxxploxx/RimWorldModGuide/wiki/SHORTTUTORIAL%3A-How-Pawns-Think&lt;br /&gt;
&lt;br /&gt;
==The basics: Defs==&lt;br /&gt;
The most basic kind of RimWorld modding is done by editing '''defs'''.&lt;br /&gt;
&lt;br /&gt;
Definitions each define some piece of the game. Different kinds of definitions can define:&lt;br /&gt;
&lt;br /&gt;
* '''Sound'''&lt;br /&gt;
* '''Weapons'''&lt;br /&gt;
* '''Buildings'''&lt;br /&gt;
* '''Plants'''&lt;br /&gt;
* '''Animals'''&lt;br /&gt;
* '''More (To be determined)'''&lt;br /&gt;
&lt;br /&gt;
When the game runs, it collects all the definitions into pools. It then semi-randomly draws from these pools in various circumstances. It will randomly draw guns of a certain category to arm a new enemy mercenary. Or, it will randomly spawn an animal type on the edge of the map. Modding the game means adding your definitions to these pools and watching the game use them in this way.&lt;br /&gt;
&lt;br /&gt;
Definitions are organized into packages. Each package is saved as a single XML file.&lt;br /&gt;
&lt;br /&gt;
Groups of packages are organized into mods. A mod is a unit of interlinked functionality and content. It could be a pack of new weapons, a new animal, or a total conversion of the game. A mod will usually contain several packages of various types, as well as content like images and sounds.&lt;br /&gt;
&lt;br /&gt;
The base game is defined in a single mod called Core.&lt;br /&gt;
&lt;br /&gt;
Players can choose which mods to activate. In some cases, several mods can be active at once. You could use a medieval mod to replace the core mod, and add on a weapons pack created by someone else. The game will run with the medieval mod content, and also randomly spawn in weapons from the extra weapons pack.&lt;br /&gt;
&lt;br /&gt;
==Mod file structure==&lt;br /&gt;
For defining new game content, '''[[wikipedia:XML|XML]]''' files are used. Here is an example of the format, that applies to most of the definitions:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot; ?&amp;gt;&lt;br /&gt;
&amp;lt;SomeDefs&amp;gt;&lt;br /&gt;
   &amp;lt;SomeDef&amp;gt;&lt;br /&gt;
      &amp;lt;defName&amp;gt;MyNewDefinitionOfContent&amp;lt;/defName&amp;gt;&lt;br /&gt;
      &amp;lt;!-- more tags will appear depending on what are you defining --&amp;gt;&lt;br /&gt;
   &amp;lt;/SomeDef&amp;gt;&lt;br /&gt;
&amp;lt;/SomeDefs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Remember, that the word '''Some''' must be replaced by the name of whatever are you defining. For thing it's '''&amp;amp;lt;ThingDef&amp;amp;gt;'''.&lt;br /&gt;
&lt;br /&gt;
The RimWorld mods use the following directory structure:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
┌About &lt;br /&gt;
├─About.xml (Contains info about the mod)&lt;br /&gt;
├─Preview.png (Image that appears above the mod info in game. Max width 600px.)&lt;br /&gt;
│&lt;br /&gt;
├Assemblies (If your mod uses any DLL files put them here)&lt;br /&gt;
├─MyMod.dll&lt;br /&gt;
│&lt;br /&gt;
├Defs (Contains xml definitions of the mod)&lt;br /&gt;
├┬ThingDefs&lt;br /&gt;
│├─Things.xml&lt;br /&gt;
│└─Buildings.xml&lt;br /&gt;
│&lt;br /&gt;
├┬ResearchProjectDefs&lt;br /&gt;
│└─MyProjects.xml&lt;br /&gt;
│&lt;br /&gt;
│the folder name must be specific here. Look in Core mod to see what are other names supposed to be&lt;br /&gt;
│&lt;br /&gt;
├Sounds&lt;br /&gt;
│&lt;br /&gt;
├Source&lt;br /&gt;
├─MyMod.cs (Optionally, put the source code of your mod here)&lt;br /&gt;
│&lt;br /&gt;
├Patches&lt;br /&gt;
├─Patch.xml&lt;br /&gt;
│&lt;br /&gt;
├Languages&lt;br /&gt;
├┬English (Replace with the language name)&lt;br /&gt;
│├┬Keyed&lt;br /&gt;
││└─Keys.xml&lt;br /&gt;
│├┬Strings&lt;br /&gt;
││└┬Names&lt;br /&gt;
││  └─PawnNames.xml&lt;br /&gt;
│├┬DefInjected&lt;br /&gt;
││└┬ThingDef&lt;br /&gt;
││  └─Thing.xml&lt;br /&gt;
│├─LanguageInfo.xml&lt;br /&gt;
│└─LangIcon.png&lt;br /&gt;
│&lt;br /&gt;
├Textures (Put any image textures here, preferably in .png format.)&lt;br /&gt;
├┬Things&lt;br /&gt;
│├─MyMod_ImageA.png&lt;br /&gt;
│└─MyMod_ImageB.png&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Mod info===&lt;br /&gt;
This is found in &amp;lt;code&amp;gt;MODNAME/About&amp;lt;/code&amp;gt;&lt;br /&gt;
*The contents of About.xml are plain text. HTML Markup tags cause NullRef's.&lt;br /&gt;
*You can have an image for your mod. Restrict the image width to 600 pixels&lt;br /&gt;
&lt;br /&gt;
===Textures===&lt;br /&gt;
These are found in &amp;lt;code&amp;gt;MODNAME/Textures&amp;lt;/code&amp;gt;&lt;br /&gt;
*You can have any path you want from this point on.&lt;br /&gt;
*When referencing textures in your mod, using &amp;lt;graphicPath&amp;gt;, have the complete path relative to your mod, including the filename (but not the file extension). Example for the RoyalBed Testmod: &amp;lt;code&amp;gt;&amp;lt;graphicPath&amp;gt;Things/Building/RoyalBed&amp;lt;/graphicPath&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For textures that have multiple faces, like animals and furniture which can be rotated; You can use the Graphic_multi class. Immediately following your &amp;lt;graphicPath&amp;gt;&amp;lt;/graphicPath&amp;gt;. Your Path should point to the folder containing the different textures: Texturename_side, Texturename_front, and Texturename_back. &lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot; &amp;gt;&lt;br /&gt;
&amp;lt;graphicPath&amp;gt;Things/Buildings/RoyalCouch/RoyalCouch&amp;lt;/graphicPath&amp;gt;&lt;br /&gt;
&amp;lt;graphicClass&amp;gt;Graphic_multi&amp;lt;/graphicClass&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Inside your folder:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
┌Textures&lt;br /&gt;
└┬Things&lt;br /&gt;
 └┬Buildings&lt;br /&gt;
  └┬RoyalCouch&lt;br /&gt;
   ├╴RoyalCouch_side&lt;br /&gt;
   ├╴RoyalCouch_front&lt;br /&gt;
   └╴RoyalCouch_back&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Interactive &amp;quot;things&amp;quot;===&lt;br /&gt;
A thing is anything that exists in the game world. It includes resources, races (humanoid and animal), buildings, furniture, and many others.&lt;br /&gt;
&lt;br /&gt;
These are defined in &amp;lt;code&amp;gt;MODNAME/Defs/ThingDefs&amp;lt;/code&amp;gt;&lt;br /&gt;
If you make a new workbench, you'll need to define a recipe for it. This is a list, so you can have many new recipes listed.&lt;br /&gt;
&lt;br /&gt;
The recipes themselves are defined in: &amp;lt;code&amp;gt;MODNAME/Defs/RecipeDefs&amp;lt;/code&amp;gt;&lt;br /&gt;
In here you can define what ingredients/resources are required, what can be used, and what the default recipe is.&lt;br /&gt;
&lt;br /&gt;
Any new resources will need to be defined in: &amp;lt;code&amp;gt;MODNAME/Defs/ThingDefs&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Turrets===&lt;br /&gt;
These are defined in two files in: &amp;lt;code&amp;gt;MODNAME/Defs/ThingDefs/Buildings_Big.xml&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Weapons_Guns.xml&amp;lt;/code&amp;gt; (Remember, these can be named anything)&lt;br /&gt;
&lt;br /&gt;
Buildings_Big.xml defines the structure of the turret itself. For example:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot; &amp;gt;&lt;br /&gt;
&amp;lt;building&amp;gt;&lt;br /&gt;
	&amp;lt;turretGunDef&amp;gt;Gun_TurretImprovised&amp;lt;/turretGunDef&amp;gt;&lt;br /&gt;
	&amp;lt;burstCooldownTicks&amp;gt;300&amp;lt;/burstCooldownTicks&amp;gt;&lt;br /&gt;
&amp;lt;/building&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Weapons_Gun.xml defines the weapon the turret uses. Anything can be used as a weapon for turrets, including grenades.&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
These are defined in: &amp;lt;code&amp;gt;MODNAME/Defs/ThingDefs/Resources.xml&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Research projects===&lt;br /&gt;
These are found in: &amp;lt;code&amp;gt;MODNAME/Defs/ResearchProjectDefs&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can have research trees as well, where additional research projects get unlocked as you move through.&lt;br /&gt;
This is how to add prerequisites:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot; &amp;gt;&lt;br /&gt;
&amp;lt;prerequisites&amp;gt;&lt;br /&gt;
	&amp;lt;li&amp;gt;-this is the &amp;lt;defName&amp;gt; of the prerequisite-&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/prerequisites&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Because it's a list, you can have multiple prerequisites for a research project.&lt;br /&gt;
&lt;br /&gt;
==Advice==&lt;br /&gt;
*The tilde key (` or ~) brings up the development console, which will report any errors or warnings it encounters when a mod loads or during gameplay. This is the quickest way to see what, if any, errors exist in your mod. (You don't need to turn on development mode for this.)&lt;br /&gt;
*Use development mode (found in the options menu) to help debug your mod, spawn items related to your mod, or fire incidents at will. (Or just mess around, if you'd like.)&lt;br /&gt;
&lt;br /&gt;
==I want my mod to...:==&lt;br /&gt;
'''Or, how do I make my mod do ''this''?'''&lt;br /&gt;
&lt;br /&gt;
You can find links to tutorials on the [[Modding Tutorials]] page. There's also more tutorials about the basics there, so don't miss out on that.&lt;br /&gt;
&lt;br /&gt;
* Save/Load information.  See a very useful guide at [https://spdskatr.github.io/RWModdingResources/saving-guide this page]&lt;br /&gt;
* Add a new value to a def&lt;br /&gt;
** See [[Custom Comp Classes]]&lt;br /&gt;
** Also might be helpful: [https://ludeon.com/forums/index.php?topic=46351.0 Mod Extensions]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
*[https://github.com/roxxploxx/RimWorldModGuide/wiki A good guide to assist people trying to mod RimWorld]&lt;br /&gt;
*[https://ludeon.com/forums/index.php?topic=39038.0 Mod Development Cookiecutter (automatically build your mod development environment)]&lt;br /&gt;
*[http://ludeon.com/forums/index.php?topic=1681.0 Simple tutorial forum thread]&lt;br /&gt;
*[https://ludeon.com/forums/index.php?topic=2325.0 RimWorld core art source thread]&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
*You can have as many mods as you like, however too many mods may affect performance.&lt;br /&gt;
*If the game crashes due to a mod-related reason on startup, or mods conflict with each other, then the game will reset the mods.&lt;br /&gt;
*Mods for previous versions may be usable, however most of the time they are not compatible.&lt;br /&gt;
&lt;br /&gt;
[[Category:Modding]]&lt;/div&gt;</summary>
		<author><name>Lilwhitemouse</name></author>
	</entry>
	<entry>
		<id>https://rimworldwiki.com/index.php?title=Modding&amp;diff=61797</id>
		<title>Modding</title>
		<link rel="alternate" type="text/html" href="https://rimworldwiki.com/index.php?title=Modding&amp;diff=61797"/>
		<updated>2018-12-18T20:47:53Z</updated>

		<summary type="html">&lt;p&gt;Lilwhitemouse: /* I want my mod to...: */ add new value to a def&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;!--Top Nav Box--&amp;gt;&lt;br /&gt;
{| align=center&lt;br /&gt;
| {{Basics_Nav}}&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{See also|List of mods}}&lt;br /&gt;
'''Mods''' (short for modifications) are small packages that add to or otherwise affect gameplay in RimWorld. They include art packs (for reskinning the game), more weapons, more incidents, furniture, and game-balancing mods.&lt;br /&gt;
&lt;br /&gt;
This page is about making mods. For info about using mods, see [[Installing mods]].&lt;br /&gt;
&lt;br /&gt;
==Mod-making tutorials== &lt;br /&gt;
Mod-making tutorials are available at the [[Modding Tutorials]] page. If you can't find what you need, you should try looking in [[Modding/Random Bits of Information|Random Bits of Information]] to check if the information you're looking for has been found but just hasn't been organized into the correct article yet.&lt;br /&gt;
&lt;br /&gt;
===Mod-making Templates===&lt;br /&gt;
*[https://ludeon.com/forums/index.php?topic=39038.0 Mod Development Cookiecutter (automatically build your mod development environment)]&lt;br /&gt;
&lt;br /&gt;
==What you can mod==&lt;br /&gt;
You can mod defs, code, images, and sounds.&lt;br /&gt;
&lt;br /&gt;
* '''Defs''': XML files containing lists of definitions for use by the game. There are a lot of these. They define every thing, skills, storyteller, and many other types of data. Find them in YourModName/Defs. More about this later.&lt;br /&gt;
* '''Code''': You can add .NET assemblies and the game will load them. Place your DLLs in YourModName/Assemblies. More about this later.&lt;br /&gt;
* '''Images''': You can add images.&lt;br /&gt;
* '''Sounds''': You can add sound files.&lt;br /&gt;
* '''Jobs''':  A useful link here https://github.com/Mehni/ExampleJob/wiki - covers JobGivers WorkGivers and Toils&lt;br /&gt;
&lt;br /&gt;
==The basics: Defs==&lt;br /&gt;
The most basic kind of RimWorld modding is done by editing '''defs'''.&lt;br /&gt;
&lt;br /&gt;
Definitions each define some piece of the game. Different kinds of definitions can define:&lt;br /&gt;
&lt;br /&gt;
* '''Sound'''&lt;br /&gt;
* '''Weapons'''&lt;br /&gt;
* '''Buildings'''&lt;br /&gt;
* '''Plants'''&lt;br /&gt;
* '''Animals'''&lt;br /&gt;
* '''More (To be determined)'''&lt;br /&gt;
&lt;br /&gt;
When the game runs, it collects all the definitions into pools. It then semi-randomly draws from these pools in various circumstances. It will randomly draw guns of a certain category to arm a new enemy mercenary. Or, it will randomly spawn an animal type on the edge of the map. Modding the game means adding your definitions to these pools and watching the game use them in this way.&lt;br /&gt;
&lt;br /&gt;
Definitions are organized into packages. Each package is saved as a single XML file.&lt;br /&gt;
&lt;br /&gt;
Groups of packages are organized into mods. A mod is a unit of interlinked functionality and content. It could be a pack of new weapons, a new animal, or a total conversion of the game. A mod will usually contain several packages of various types, as well as content like images and sounds.&lt;br /&gt;
&lt;br /&gt;
The base game is defined in a single mod called Core.&lt;br /&gt;
&lt;br /&gt;
Players can choose which mods to activate. In some cases, several mods can be active at once. You could use a medieval mod to replace the core mod, and add on a weapons pack created by someone else. The game will run with the medieval mod content, and also randomly spawn in weapons from the extra weapons pack.&lt;br /&gt;
&lt;br /&gt;
==Mod file structure==&lt;br /&gt;
For defining new game content, '''[[wikipedia:XML|XML]]''' files are used. Here is an example of the format, that applies to most of the definitions:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot; ?&amp;gt;&lt;br /&gt;
&amp;lt;SomeDefs&amp;gt;&lt;br /&gt;
   &amp;lt;SomeDef&amp;gt;&lt;br /&gt;
      &amp;lt;defName&amp;gt;MyNewDefinitionOfContent&amp;lt;/defName&amp;gt;&lt;br /&gt;
      &amp;lt;!-- more tags will appear depending on what are you defining --&amp;gt;&lt;br /&gt;
   &amp;lt;/SomeDef&amp;gt;&lt;br /&gt;
&amp;lt;/SomeDefs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Remember, that the word '''Some''' must be replaced by the name of whatever are you defining. For thing it's '''&amp;amp;lt;ThingDef&amp;amp;gt;'''.&lt;br /&gt;
&lt;br /&gt;
The RimWorld mods use the following directory structure:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
┌About &lt;br /&gt;
├─About.xml (Contains info about the mod)&lt;br /&gt;
├─Preview.png (Image that appears above the mod info in game. Max width 600px.)&lt;br /&gt;
│&lt;br /&gt;
├Assemblies (If your mod uses any DLL files put them here)&lt;br /&gt;
├─MyMod.dll&lt;br /&gt;
│&lt;br /&gt;
├Defs (Contains xml definitions of the mod)&lt;br /&gt;
├┬ThingDefs&lt;br /&gt;
│├─Things.xml&lt;br /&gt;
│└─Buildings.xml&lt;br /&gt;
│&lt;br /&gt;
├┬ResearchProjectDefs&lt;br /&gt;
│└─MyProjects.xml&lt;br /&gt;
│&lt;br /&gt;
│the folder name must be specific here. Look in Core mod to see what are other names supposed to be&lt;br /&gt;
│&lt;br /&gt;
├Sounds&lt;br /&gt;
│&lt;br /&gt;
├Source&lt;br /&gt;
├─MyMod.cs (Optionally, put the source code of your mod here)&lt;br /&gt;
│&lt;br /&gt;
├Patches&lt;br /&gt;
├─Patch.xml&lt;br /&gt;
│&lt;br /&gt;
├Languages&lt;br /&gt;
├┬English (Replace with the language name)&lt;br /&gt;
│├┬Keyed&lt;br /&gt;
││└─Keys.xml&lt;br /&gt;
│├┬Strings&lt;br /&gt;
││└┬Names&lt;br /&gt;
││  └─PawnNames.xml&lt;br /&gt;
│├┬DefInjected&lt;br /&gt;
││└┬ThingDef&lt;br /&gt;
││  └─Thing.xml&lt;br /&gt;
│├─LanguageInfo.xml&lt;br /&gt;
│└─LangIcon.png&lt;br /&gt;
│&lt;br /&gt;
├Textures (Put any image textures here, preferably in .png format.)&lt;br /&gt;
├┬Things&lt;br /&gt;
│├─MyMod_ImageA.png&lt;br /&gt;
│└─MyMod_ImageB.png&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Mod info===&lt;br /&gt;
This is found in &amp;lt;code&amp;gt;MODNAME/About&amp;lt;/code&amp;gt;&lt;br /&gt;
*The contents of About.xml are plain text. HTML Markup tags cause NullRef's.&lt;br /&gt;
*You can have an image for your mod. Restrict the image width to 600 pixels&lt;br /&gt;
&lt;br /&gt;
===Textures===&lt;br /&gt;
These are found in &amp;lt;code&amp;gt;MODNAME/Textures&amp;lt;/code&amp;gt;&lt;br /&gt;
*You can have any path you want from this point on.&lt;br /&gt;
*When referencing textures in your mod, using &amp;lt;graphicPath&amp;gt;, have the complete path relative to your mod, including the filename (but not the file extension). Example for the RoyalBed Testmod: &amp;lt;code&amp;gt;&amp;lt;graphicPath&amp;gt;Things/Building/RoyalBed&amp;lt;/graphicPath&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For textures that have multiple faces, like animals and furniture which can be rotated; You can use the Graphic_multi class. Immediately following your &amp;lt;graphicPath&amp;gt;&amp;lt;/graphicPath&amp;gt;. Your Path should point to the folder containing the different textures: Texturename_side, Texturename_front, and Texturename_back. &lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot; &amp;gt;&lt;br /&gt;
&amp;lt;graphicPath&amp;gt;Things/Buildings/RoyalCouch/RoyalCouch&amp;lt;/graphicPath&amp;gt;&lt;br /&gt;
&amp;lt;graphicClass&amp;gt;Graphic_multi&amp;lt;/graphicClass&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Inside your folder:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
┌Textures&lt;br /&gt;
└┬Things&lt;br /&gt;
 └┬Buildings&lt;br /&gt;
  └┬RoyalCouch&lt;br /&gt;
   ├╴RoyalCouch_side&lt;br /&gt;
   ├╴RoyalCouch_front&lt;br /&gt;
   └╴RoyalCouch_back&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Interactive &amp;quot;things&amp;quot;===&lt;br /&gt;
A thing is anything that exists in the game world. It includes resources, races (humanoid and animal), buildings, furniture, and many others.&lt;br /&gt;
&lt;br /&gt;
These are defined in &amp;lt;code&amp;gt;MODNAME/Defs/ThingDefs&amp;lt;/code&amp;gt;&lt;br /&gt;
If you make a new workbench, you'll need to define a recipe for it. This is a list, so you can have many new recipes listed.&lt;br /&gt;
&lt;br /&gt;
The recipes themselves are defined in: &amp;lt;code&amp;gt;MODNAME/Defs/RecipeDefs&amp;lt;/code&amp;gt;&lt;br /&gt;
In here you can define what ingredients/resources are required, what can be used, and what the default recipe is.&lt;br /&gt;
&lt;br /&gt;
Any new resources will need to be defined in: &amp;lt;code&amp;gt;MODNAME/Defs/ThingDefs&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Turrets===&lt;br /&gt;
These are defined in two files in: &amp;lt;code&amp;gt;MODNAME/Defs/ThingDefs/Buildings_Big.xml&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Weapons_Guns.xml&amp;lt;/code&amp;gt; (Remember, these can be named anything)&lt;br /&gt;
&lt;br /&gt;
Buildings_Big.xml defines the structure of the turret itself. For example:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot; &amp;gt;&lt;br /&gt;
&amp;lt;building&amp;gt;&lt;br /&gt;
	&amp;lt;turretGunDef&amp;gt;Gun_TurretImprovised&amp;lt;/turretGunDef&amp;gt;&lt;br /&gt;
	&amp;lt;burstCooldownTicks&amp;gt;300&amp;lt;/burstCooldownTicks&amp;gt;&lt;br /&gt;
&amp;lt;/building&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Weapons_Gun.xml defines the weapon the turret uses. Anything can be used as a weapon for turrets, including grenades.&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
These are defined in: &amp;lt;code&amp;gt;MODNAME/Defs/ThingDefs/Resources.xml&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Research projects===&lt;br /&gt;
These are found in: &amp;lt;code&amp;gt;MODNAME/Defs/ResearchProjectDefs&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can have research trees as well, where additional research projects get unlocked as you move through.&lt;br /&gt;
This is how to add prerequisites:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot; &amp;gt;&lt;br /&gt;
&amp;lt;prerequisites&amp;gt;&lt;br /&gt;
	&amp;lt;li&amp;gt;-this is the &amp;lt;defName&amp;gt; of the prerequisite-&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/prerequisites&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Because it's a list, you can have multiple prerequisites for a research project.&lt;br /&gt;
&lt;br /&gt;
==Advice==&lt;br /&gt;
*The tilde key (` or ~) brings up the development console, which will report any errors or warnings it encounters when a mod loads or during gameplay. This is the quickest way to see what, if any, errors exist in your mod. (You don't need to turn on development mode for this.)&lt;br /&gt;
*Use development mode (found in the options menu) to help debug your mod, spawn items related to your mod, or fire incidents at will. (Or just mess around, if you'd like.)&lt;br /&gt;
&lt;br /&gt;
==I want my mod to...:==&lt;br /&gt;
'''Or, how do I make my mod do ''this''?'''&lt;br /&gt;
&lt;br /&gt;
You can find links to tutorials on the [[Modding Tutorials]] page. There's also more tutorials about the basics there, so don't miss out on that.&lt;br /&gt;
&lt;br /&gt;
* Save/Load information.  See a very useful guide at [https://spdskatr.github.io/RWModdingResources/saving-guide this page]&lt;br /&gt;
* Add a new value to a def&lt;br /&gt;
** See [[Custom Comp Classes]]&lt;br /&gt;
** Also might be helpful: [https://ludeon.com/forums/index.php?topic=46351.0 Mod Extensions]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
*[https://github.com/roxxploxx/RimWorldModGuide/wiki A good guide to assist people trying to mod RimWorld]&lt;br /&gt;
*[https://ludeon.com/forums/index.php?topic=39038.0 Mod Development Cookiecutter (automatically build your mod development environment)]&lt;br /&gt;
*[http://ludeon.com/forums/index.php?topic=1681.0 Simple tutorial forum thread]&lt;br /&gt;
*[https://ludeon.com/forums/index.php?topic=2325.0 RimWorld core art source thread]&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
*You can have as many mods as you like, however too many mods may affect performance.&lt;br /&gt;
*If the game crashes due to a mod-related reason on startup, or mods conflict with each other, then the game will reset the mods.&lt;br /&gt;
*Mods for previous versions may be usable, however most of the time they are not compatible.&lt;br /&gt;
&lt;br /&gt;
[[Category:Modding]]&lt;/div&gt;</summary>
		<author><name>Lilwhitemouse</name></author>
	</entry>
	<entry>
		<id>https://rimworldwiki.com/index.php?title=Modding&amp;diff=61632</id>
		<title>Modding</title>
		<link rel="alternate" type="text/html" href="https://rimworldwiki.com/index.php?title=Modding&amp;diff=61632"/>
		<updated>2018-12-15T17:53:42Z</updated>

		<summary type="html">&lt;p&gt;Lilwhitemouse: /* I want my mod to...: */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;!--Top Nav Box--&amp;gt;&lt;br /&gt;
{| align=center&lt;br /&gt;
| {{Basics_Nav}}&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{See also|List of mods}}&lt;br /&gt;
'''Mods''' (short for modifications) are small packages that add to or otherwise affect gameplay in RimWorld. They include art packs (for reskinning the game), more weapons, more incidents, furniture, and game-balancing mods.&lt;br /&gt;
&lt;br /&gt;
This page is about making mods. For info about using mods, see [[Installing mods]].&lt;br /&gt;
&lt;br /&gt;
==Mod-making tutorials== &lt;br /&gt;
Mod-making tutorials are available at the [[Modding Tutorials]] page. If you can't find what you need, you should try looking in [[Modding/Random Bits of Information|Random Bits of Information]] to check if the information you're looking for has been found but just hasn't been organized into the correct article yet.&lt;br /&gt;
&lt;br /&gt;
===Mod-making Templates===&lt;br /&gt;
*[https://ludeon.com/forums/index.php?topic=39038.0 Mod Development Cookiecutter (automatically build your mod development environment)]&lt;br /&gt;
&lt;br /&gt;
==What you can mod==&lt;br /&gt;
You can mod defs, code, images, and sounds.&lt;br /&gt;
&lt;br /&gt;
* '''Defs''': XML files containing lists of definitions for use by the game. There are a lot of these. They define every thing, skills, storyteller, and many other types of data. Find them in YourModName/Defs. More about this later.&lt;br /&gt;
* '''Code''': You can add .NET assemblies and the game will load them. Place your DLLs in YourModName/Assemblies. More about this later.&lt;br /&gt;
* '''Images''': You can add images.&lt;br /&gt;
* '''Sounds''': You can add sound files.&lt;br /&gt;
* '''Jobs''':  A useful link here https://github.com/Mehni/ExampleJob/wiki - covers JobGivers WorkGivers and Toils&lt;br /&gt;
&lt;br /&gt;
==The basics: Defs==&lt;br /&gt;
The most basic kind of RimWorld modding is done by editing '''defs'''.&lt;br /&gt;
&lt;br /&gt;
Definitions each define some piece of the game. Different kinds of definitions can define:&lt;br /&gt;
&lt;br /&gt;
* '''Sound'''&lt;br /&gt;
* '''Weapons'''&lt;br /&gt;
* '''Buildings'''&lt;br /&gt;
* '''Plants'''&lt;br /&gt;
* '''Animals'''&lt;br /&gt;
* '''More (To be determined)'''&lt;br /&gt;
&lt;br /&gt;
When the game runs, it collects all the definitions into pools. It then semi-randomly draws from these pools in various circumstances. It will randomly draw guns of a certain category to arm a new enemy mercenary. Or, it will randomly spawn an animal type on the edge of the map. Modding the game means adding your definitions to these pools and watching the game use them in this way.&lt;br /&gt;
&lt;br /&gt;
Definitions are organized into packages. Each package is saved as a single XML file.&lt;br /&gt;
&lt;br /&gt;
Groups of packages are organized into mods. A mod is a unit of interlinked functionality and content. It could be a pack of new weapons, a new animal, or a total conversion of the game. A mod will usually contain several packages of various types, as well as content like images and sounds.&lt;br /&gt;
&lt;br /&gt;
The base game is defined in a single mod called Core.&lt;br /&gt;
&lt;br /&gt;
Players can choose which mods to activate. In some cases, several mods can be active at once. You could use a medieval mod to replace the core mod, and add on a weapons pack created by someone else. The game will run with the medieval mod content, and also randomly spawn in weapons from the extra weapons pack.&lt;br /&gt;
&lt;br /&gt;
==Mod file structure==&lt;br /&gt;
For defining new game content, '''[[wikipedia:XML|XML]]''' files are used. Here is an example of the format, that applies to most of the definitions:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot; ?&amp;gt;&lt;br /&gt;
&amp;lt;SomeDefs&amp;gt;&lt;br /&gt;
   &amp;lt;SomeDef&amp;gt;&lt;br /&gt;
      &amp;lt;defName&amp;gt;MyNewDefinitionOfContent&amp;lt;/defName&amp;gt;&lt;br /&gt;
      &amp;lt;!-- more tags will appear depending on what are you defining --&amp;gt;&lt;br /&gt;
   &amp;lt;/SomeDef&amp;gt;&lt;br /&gt;
&amp;lt;/SomeDefs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Remember, that the word '''Some''' must be replaced by the name of whatever are you defining. For thing it's '''&amp;amp;lt;ThingDef&amp;amp;gt;'''.&lt;br /&gt;
&lt;br /&gt;
The RimWorld mods use the following directory structure:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
┌About &lt;br /&gt;
├─About.xml (Contains info about the mod)&lt;br /&gt;
├─Preview.png (Image that appears above the mod info in game. Max width 600px.)&lt;br /&gt;
│&lt;br /&gt;
├Assemblies (If your mod uses any DLL files put them here)&lt;br /&gt;
├─MyMod.dll&lt;br /&gt;
│&lt;br /&gt;
├Defs (Contains xml definitions of the mod)&lt;br /&gt;
├┬ThingDefs&lt;br /&gt;
│├─Things.xml&lt;br /&gt;
│└─Buildings.xml&lt;br /&gt;
│&lt;br /&gt;
├┬ResearchProjectDefs&lt;br /&gt;
│└─MyProjects.xml&lt;br /&gt;
│&lt;br /&gt;
│the folder name must be specific here. Look in Core mod to see what are other names supposed to be&lt;br /&gt;
│&lt;br /&gt;
├Sounds&lt;br /&gt;
│&lt;br /&gt;
├Source&lt;br /&gt;
├─MyMod.cs (Optionally, put the source code of your mod here)&lt;br /&gt;
│&lt;br /&gt;
├Patches&lt;br /&gt;
├─Patch.xml&lt;br /&gt;
│&lt;br /&gt;
├Languages&lt;br /&gt;
├┬English (Replace with the language name)&lt;br /&gt;
│├┬Keyed&lt;br /&gt;
││└─Keys.xml&lt;br /&gt;
│├┬Strings&lt;br /&gt;
││└┬Names&lt;br /&gt;
││  └─PawnNames.xml&lt;br /&gt;
│├┬DefInjected&lt;br /&gt;
││└┬ThingDef&lt;br /&gt;
││  └─Thing.xml&lt;br /&gt;
│├─LanguageInfo.xml&lt;br /&gt;
│└─LangIcon.png&lt;br /&gt;
│&lt;br /&gt;
├Textures (Put any image textures here, preferably in .png format.)&lt;br /&gt;
├┬Things&lt;br /&gt;
│├─MyMod_ImageA.png&lt;br /&gt;
│└─MyMod_ImageB.png&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Mod info===&lt;br /&gt;
This is found in &amp;lt;code&amp;gt;MODNAME/About&amp;lt;/code&amp;gt;&lt;br /&gt;
*The contents of About.xml are plain text. HTML Markup tags cause NullRef's.&lt;br /&gt;
*You can have an image for your mod. Restrict the image width to 600 pixels&lt;br /&gt;
&lt;br /&gt;
===Textures===&lt;br /&gt;
These are found in &amp;lt;code&amp;gt;MODNAME/Textures&amp;lt;/code&amp;gt;&lt;br /&gt;
*You can have any path you want from this point on.&lt;br /&gt;
*When referencing textures in your mod, using &amp;lt;graphicPath&amp;gt;, have the complete path relative to your mod, including the filename (but not the file extension). Example for the RoyalBed Testmod: &amp;lt;code&amp;gt;&amp;lt;graphicPath&amp;gt;Things/Building/RoyalBed&amp;lt;/graphicPath&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For textures that have multiple faces, like animals and furniture which can be rotated; You can use the Graphic_multi class. Immediately following your &amp;lt;graphicPath&amp;gt;&amp;lt;/graphicPath&amp;gt;. Your Path should point to the folder containing the different textures: Texturename_side, Texturename_front, and Texturename_back. &lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot; &amp;gt;&lt;br /&gt;
&amp;lt;graphicPath&amp;gt;Things/Buildings/RoyalCouch/RoyalCouch&amp;lt;/graphicPath&amp;gt;&lt;br /&gt;
&amp;lt;graphicClass&amp;gt;Graphic_multi&amp;lt;/graphicClass&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Inside your folder:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
┌Textures&lt;br /&gt;
└┬Things&lt;br /&gt;
 └┬Buildings&lt;br /&gt;
  └┬RoyalCouch&lt;br /&gt;
   ├╴RoyalCouch_side&lt;br /&gt;
   ├╴RoyalCouch_front&lt;br /&gt;
   └╴RoyalCouch_back&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Interactive &amp;quot;things&amp;quot;===&lt;br /&gt;
A thing is anything that exists in the game world. It includes resources, races (humanoid and animal), buildings, furniture, and many others.&lt;br /&gt;
&lt;br /&gt;
These are defined in &amp;lt;code&amp;gt;MODNAME/Defs/ThingDefs&amp;lt;/code&amp;gt;&lt;br /&gt;
If you make a new workbench, you'll need to define a recipe for it. This is a list, so you can have many new recipes listed.&lt;br /&gt;
&lt;br /&gt;
The recipes themselves are defined in: &amp;lt;code&amp;gt;MODNAME/Defs/RecipeDefs&amp;lt;/code&amp;gt;&lt;br /&gt;
In here you can define what ingredients/resources are required, what can be used, and what the default recipe is.&lt;br /&gt;
&lt;br /&gt;
Any new resources will need to be defined in: &amp;lt;code&amp;gt;MODNAME/Defs/ThingDefs&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Turrets===&lt;br /&gt;
These are defined in two files in: &amp;lt;code&amp;gt;MODNAME/Defs/ThingDefs/Buildings_Big.xml&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Weapons_Guns.xml&amp;lt;/code&amp;gt; (Remember, these can be named anything)&lt;br /&gt;
&lt;br /&gt;
Buildings_Big.xml defines the structure of the turret itself. For example:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot; &amp;gt;&lt;br /&gt;
&amp;lt;building&amp;gt;&lt;br /&gt;
	&amp;lt;turretGunDef&amp;gt;Gun_TurretImprovised&amp;lt;/turretGunDef&amp;gt;&lt;br /&gt;
	&amp;lt;burstCooldownTicks&amp;gt;300&amp;lt;/burstCooldownTicks&amp;gt;&lt;br /&gt;
&amp;lt;/building&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Weapons_Gun.xml defines the weapon the turret uses. Anything can be used as a weapon for turrets, including grenades.&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
These are defined in: &amp;lt;code&amp;gt;MODNAME/Defs/ThingDefs/Resources.xml&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Research projects===&lt;br /&gt;
These are found in: &amp;lt;code&amp;gt;MODNAME/Defs/ResearchProjectDefs&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can have research trees as well, where additional research projects get unlocked as you move through.&lt;br /&gt;
This is how to add prerequisites:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot; &amp;gt;&lt;br /&gt;
&amp;lt;prerequisites&amp;gt;&lt;br /&gt;
	&amp;lt;li&amp;gt;-this is the &amp;lt;defName&amp;gt; of the prerequisite-&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/prerequisites&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Because it's a list, you can have multiple prerequisites for a research project.&lt;br /&gt;
&lt;br /&gt;
==Advice==&lt;br /&gt;
*The tilde key (` or ~) brings up the development console, which will report any errors or warnings it encounters when a mod loads or during gameplay. This is the quickest way to see what, if any, errors exist in your mod. (You don't need to turn on development mode for this.)&lt;br /&gt;
*Use development mode (found in the options menu) to help debug your mod, spawn items related to your mod, or fire incidents at will. (Or just mess around, if you'd like.)&lt;br /&gt;
&lt;br /&gt;
==I want my mod to...:==&lt;br /&gt;
'''Or, how do I make my mod do ''this''?'''&lt;br /&gt;
&lt;br /&gt;
You can find links to tutorials on the [[Modding Tutorials]] page. There's also more tutorials about the basics there, so don't miss out on that.&lt;br /&gt;
&lt;br /&gt;
* Save/Load information.  See a very useful guide at [https://spdskatr.github.io/RWModdingResources/saving-guide this page]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
*[https://github.com/roxxploxx/RimWorldModGuide/wiki A good guide to assist people trying to mod RimWorld]&lt;br /&gt;
*[https://ludeon.com/forums/index.php?topic=39038.0 Mod Development Cookiecutter (automatically build your mod development environment)]&lt;br /&gt;
*[http://ludeon.com/forums/index.php?topic=1681.0 Simple tutorial forum thread]&lt;br /&gt;
*[https://ludeon.com/forums/index.php?topic=2325.0 RimWorld core art source thread]&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
*You can have as many mods as you like, however too many mods may affect performance.&lt;br /&gt;
*If the game crashes due to a mod-related reason on startup, or mods conflict with each other, then the game will reset the mods.&lt;br /&gt;
*Mods for previous versions may be usable, however most of the time they are not compatible.&lt;br /&gt;
&lt;br /&gt;
[[Category:Modding]]&lt;/div&gt;</summary>
		<author><name>Lilwhitemouse</name></author>
	</entry>
	<entry>
		<id>https://rimworldwiki.com/index.php?title=Modding&amp;diff=61631</id>
		<title>Modding</title>
		<link rel="alternate" type="text/html" href="https://rimworldwiki.com/index.php?title=Modding&amp;diff=61631"/>
		<updated>2018-12-15T17:53:03Z</updated>

		<summary type="html">&lt;p&gt;Lilwhitemouse: /* The other stuff: Code, Graphics, Sound */ Rewriting as collection of links to useful sections&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;!--Top Nav Box--&amp;gt;&lt;br /&gt;
{| align=center&lt;br /&gt;
| {{Basics_Nav}}&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{See also|List of mods}}&lt;br /&gt;
'''Mods''' (short for modifications) are small packages that add to or otherwise affect gameplay in RimWorld. They include art packs (for reskinning the game), more weapons, more incidents, furniture, and game-balancing mods.&lt;br /&gt;
&lt;br /&gt;
This page is about making mods. For info about using mods, see [[Installing mods]].&lt;br /&gt;
&lt;br /&gt;
==Mod-making tutorials== &lt;br /&gt;
Mod-making tutorials are available at the [[Modding Tutorials]] page. If you can't find what you need, you should try looking in [[Modding/Random Bits of Information|Random Bits of Information]] to check if the information you're looking for has been found but just hasn't been organized into the correct article yet.&lt;br /&gt;
&lt;br /&gt;
===Mod-making Templates===&lt;br /&gt;
*[https://ludeon.com/forums/index.php?topic=39038.0 Mod Development Cookiecutter (automatically build your mod development environment)]&lt;br /&gt;
&lt;br /&gt;
==What you can mod==&lt;br /&gt;
You can mod defs, code, images, and sounds.&lt;br /&gt;
&lt;br /&gt;
* '''Defs''': XML files containing lists of definitions for use by the game. There are a lot of these. They define every thing, skills, storyteller, and many other types of data. Find them in YourModName/Defs. More about this later.&lt;br /&gt;
* '''Code''': You can add .NET assemblies and the game will load them. Place your DLLs in YourModName/Assemblies. More about this later.&lt;br /&gt;
* '''Images''': You can add images.&lt;br /&gt;
* '''Sounds''': You can add sound files.&lt;br /&gt;
* '''Jobs''':  A useful link here https://github.com/Mehni/ExampleJob/wiki - covers JobGivers WorkGivers and Toils&lt;br /&gt;
&lt;br /&gt;
==The basics: Defs==&lt;br /&gt;
The most basic kind of RimWorld modding is done by editing '''defs'''.&lt;br /&gt;
&lt;br /&gt;
Definitions each define some piece of the game. Different kinds of definitions can define:&lt;br /&gt;
&lt;br /&gt;
* '''Sound'''&lt;br /&gt;
* '''Weapons'''&lt;br /&gt;
* '''Buildings'''&lt;br /&gt;
* '''Plants'''&lt;br /&gt;
* '''Animals'''&lt;br /&gt;
* '''More (To be determined)'''&lt;br /&gt;
&lt;br /&gt;
When the game runs, it collects all the definitions into pools. It then semi-randomly draws from these pools in various circumstances. It will randomly draw guns of a certain category to arm a new enemy mercenary. Or, it will randomly spawn an animal type on the edge of the map. Modding the game means adding your definitions to these pools and watching the game use them in this way.&lt;br /&gt;
&lt;br /&gt;
Definitions are organized into packages. Each package is saved as a single XML file.&lt;br /&gt;
&lt;br /&gt;
Groups of packages are organized into mods. A mod is a unit of interlinked functionality and content. It could be a pack of new weapons, a new animal, or a total conversion of the game. A mod will usually contain several packages of various types, as well as content like images and sounds.&lt;br /&gt;
&lt;br /&gt;
The base game is defined in a single mod called Core.&lt;br /&gt;
&lt;br /&gt;
Players can choose which mods to activate. In some cases, several mods can be active at once. You could use a medieval mod to replace the core mod, and add on a weapons pack created by someone else. The game will run with the medieval mod content, and also randomly spawn in weapons from the extra weapons pack.&lt;br /&gt;
&lt;br /&gt;
==Mod file structure==&lt;br /&gt;
For defining new game content, '''[[wikipedia:XML|XML]]''' files are used. Here is an example of the format, that applies to most of the definitions:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot; ?&amp;gt;&lt;br /&gt;
&amp;lt;SomeDefs&amp;gt;&lt;br /&gt;
   &amp;lt;SomeDef&amp;gt;&lt;br /&gt;
      &amp;lt;defName&amp;gt;MyNewDefinitionOfContent&amp;lt;/defName&amp;gt;&lt;br /&gt;
      &amp;lt;!-- more tags will appear depending on what are you defining --&amp;gt;&lt;br /&gt;
   &amp;lt;/SomeDef&amp;gt;&lt;br /&gt;
&amp;lt;/SomeDefs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Remember, that the word '''Some''' must be replaced by the name of whatever are you defining. For thing it's '''&amp;amp;lt;ThingDef&amp;amp;gt;'''.&lt;br /&gt;
&lt;br /&gt;
The RimWorld mods use the following directory structure:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
┌About &lt;br /&gt;
├─About.xml (Contains info about the mod)&lt;br /&gt;
├─Preview.png (Image that appears above the mod info in game. Max width 600px.)&lt;br /&gt;
│&lt;br /&gt;
├Assemblies (If your mod uses any DLL files put them here)&lt;br /&gt;
├─MyMod.dll&lt;br /&gt;
│&lt;br /&gt;
├Defs (Contains xml definitions of the mod)&lt;br /&gt;
├┬ThingDefs&lt;br /&gt;
│├─Things.xml&lt;br /&gt;
│└─Buildings.xml&lt;br /&gt;
│&lt;br /&gt;
├┬ResearchProjectDefs&lt;br /&gt;
│└─MyProjects.xml&lt;br /&gt;
│&lt;br /&gt;
│the folder name must be specific here. Look in Core mod to see what are other names supposed to be&lt;br /&gt;
│&lt;br /&gt;
├Sounds&lt;br /&gt;
│&lt;br /&gt;
├Source&lt;br /&gt;
├─MyMod.cs (Optionally, put the source code of your mod here)&lt;br /&gt;
│&lt;br /&gt;
├Patches&lt;br /&gt;
├─Patch.xml&lt;br /&gt;
│&lt;br /&gt;
├Languages&lt;br /&gt;
├┬English (Replace with the language name)&lt;br /&gt;
│├┬Keyed&lt;br /&gt;
││└─Keys.xml&lt;br /&gt;
│├┬Strings&lt;br /&gt;
││└┬Names&lt;br /&gt;
││  └─PawnNames.xml&lt;br /&gt;
│├┬DefInjected&lt;br /&gt;
││└┬ThingDef&lt;br /&gt;
││  └─Thing.xml&lt;br /&gt;
│├─LanguageInfo.xml&lt;br /&gt;
│└─LangIcon.png&lt;br /&gt;
│&lt;br /&gt;
├Textures (Put any image textures here, preferably in .png format.)&lt;br /&gt;
├┬Things&lt;br /&gt;
│├─MyMod_ImageA.png&lt;br /&gt;
│└─MyMod_ImageB.png&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Mod info===&lt;br /&gt;
This is found in &amp;lt;code&amp;gt;MODNAME/About&amp;lt;/code&amp;gt;&lt;br /&gt;
*The contents of About.xml are plain text. HTML Markup tags cause NullRef's.&lt;br /&gt;
*You can have an image for your mod. Restrict the image width to 600 pixels&lt;br /&gt;
&lt;br /&gt;
===Textures===&lt;br /&gt;
These are found in &amp;lt;code&amp;gt;MODNAME/Textures&amp;lt;/code&amp;gt;&lt;br /&gt;
*You can have any path you want from this point on.&lt;br /&gt;
*When referencing textures in your mod, using &amp;lt;graphicPath&amp;gt;, have the complete path relative to your mod, including the filename (but not the file extension). Example for the RoyalBed Testmod: &amp;lt;code&amp;gt;&amp;lt;graphicPath&amp;gt;Things/Building/RoyalBed&amp;lt;/graphicPath&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For textures that have multiple faces, like animals and furniture which can be rotated; You can use the Graphic_multi class. Immediately following your &amp;lt;graphicPath&amp;gt;&amp;lt;/graphicPath&amp;gt;. Your Path should point to the folder containing the different textures: Texturename_side, Texturename_front, and Texturename_back. &lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot; &amp;gt;&lt;br /&gt;
&amp;lt;graphicPath&amp;gt;Things/Buildings/RoyalCouch/RoyalCouch&amp;lt;/graphicPath&amp;gt;&lt;br /&gt;
&amp;lt;graphicClass&amp;gt;Graphic_multi&amp;lt;/graphicClass&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Inside your folder:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
┌Textures&lt;br /&gt;
└┬Things&lt;br /&gt;
 └┬Buildings&lt;br /&gt;
  └┬RoyalCouch&lt;br /&gt;
   ├╴RoyalCouch_side&lt;br /&gt;
   ├╴RoyalCouch_front&lt;br /&gt;
   └╴RoyalCouch_back&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Interactive &amp;quot;things&amp;quot;===&lt;br /&gt;
A thing is anything that exists in the game world. It includes resources, races (humanoid and animal), buildings, furniture, and many others.&lt;br /&gt;
&lt;br /&gt;
These are defined in &amp;lt;code&amp;gt;MODNAME/Defs/ThingDefs&amp;lt;/code&amp;gt;&lt;br /&gt;
If you make a new workbench, you'll need to define a recipe for it. This is a list, so you can have many new recipes listed.&lt;br /&gt;
&lt;br /&gt;
The recipes themselves are defined in: &amp;lt;code&amp;gt;MODNAME/Defs/RecipeDefs&amp;lt;/code&amp;gt;&lt;br /&gt;
In here you can define what ingredients/resources are required, what can be used, and what the default recipe is.&lt;br /&gt;
&lt;br /&gt;
Any new resources will need to be defined in: &amp;lt;code&amp;gt;MODNAME/Defs/ThingDefs&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Turrets===&lt;br /&gt;
These are defined in two files in: &amp;lt;code&amp;gt;MODNAME/Defs/ThingDefs/Buildings_Big.xml&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Weapons_Guns.xml&amp;lt;/code&amp;gt; (Remember, these can be named anything)&lt;br /&gt;
&lt;br /&gt;
Buildings_Big.xml defines the structure of the turret itself. For example:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot; &amp;gt;&lt;br /&gt;
&amp;lt;building&amp;gt;&lt;br /&gt;
	&amp;lt;turretGunDef&amp;gt;Gun_TurretImprovised&amp;lt;/turretGunDef&amp;gt;&lt;br /&gt;
	&amp;lt;burstCooldownTicks&amp;gt;300&amp;lt;/burstCooldownTicks&amp;gt;&lt;br /&gt;
&amp;lt;/building&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Weapons_Gun.xml defines the weapon the turret uses. Anything can be used as a weapon for turrets, including grenades.&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
These are defined in: &amp;lt;code&amp;gt;MODNAME/Defs/ThingDefs/Resources.xml&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Research projects===&lt;br /&gt;
These are found in: &amp;lt;code&amp;gt;MODNAME/Defs/ResearchProjectDefs&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can have research trees as well, where additional research projects get unlocked as you move through.&lt;br /&gt;
This is how to add prerequisites:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot; &amp;gt;&lt;br /&gt;
&amp;lt;prerequisites&amp;gt;&lt;br /&gt;
	&amp;lt;li&amp;gt;-this is the &amp;lt;defName&amp;gt; of the prerequisite-&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/prerequisites&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Because it's a list, you can have multiple prerequisites for a research project.&lt;br /&gt;
&lt;br /&gt;
==Advice==&lt;br /&gt;
*The tilde key (` or ~) brings up the development console, which will report any errors or warnings it encounters when a mod loads or during gameplay. This is the quickest way to see what, if any, errors exist in your mod. (You don't need to turn on development mode for this.)&lt;br /&gt;
*Use development mode (found in the options menu) to help debug your mod, spawn items related to your mod, or fire incidents at will. (Or just mess around, if you'd like.)&lt;br /&gt;
&lt;br /&gt;
==I want my mod to...:==&lt;br /&gt;
'''Or, how do I make my mod do this?'''&lt;br /&gt;
&lt;br /&gt;
You can find links to tutorials on the [[Modding Tutorials]] page. There's also more tutorials about the basics there, so don't miss out on that.&lt;br /&gt;
&lt;br /&gt;
* Save/Load information.  See a very useful guide at [https://spdskatr.github.io/RWModdingResources/saving-guide this page]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
*[https://github.com/roxxploxx/RimWorldModGuide/wiki A good guide to assist people trying to mod RimWorld]&lt;br /&gt;
*[https://ludeon.com/forums/index.php?topic=39038.0 Mod Development Cookiecutter (automatically build your mod development environment)]&lt;br /&gt;
*[http://ludeon.com/forums/index.php?topic=1681.0 Simple tutorial forum thread]&lt;br /&gt;
*[https://ludeon.com/forums/index.php?topic=2325.0 RimWorld core art source thread]&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
*You can have as many mods as you like, however too many mods may affect performance.&lt;br /&gt;
*If the game crashes due to a mod-related reason on startup, or mods conflict with each other, then the game will reset the mods.&lt;br /&gt;
*Mods for previous versions may be usable, however most of the time they are not compatible.&lt;br /&gt;
&lt;br /&gt;
[[Category:Modding]]&lt;/div&gt;</summary>
		<author><name>Lilwhitemouse</name></author>
	</entry>
	<entry>
		<id>https://rimworldwiki.com/index.php?title=Modding&amp;diff=61630</id>
		<title>Modding</title>
		<link rel="alternate" type="text/html" href="https://rimworldwiki.com/index.php?title=Modding&amp;diff=61630"/>
		<updated>2018-12-15T17:10:33Z</updated>

		<summary type="html">&lt;p&gt;Lilwhitemouse: /* What you can mod */ added link to useful jobs wiki&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;!--Top Nav Box--&amp;gt;&lt;br /&gt;
{| align=center&lt;br /&gt;
| {{Basics_Nav}}&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{See also|List of mods}}&lt;br /&gt;
'''Mods''' (short for modifications) are small packages that add to or otherwise affect gameplay in RimWorld. They include art packs (for reskinning the game), more weapons, more incidents, furniture, and game-balancing mods.&lt;br /&gt;
&lt;br /&gt;
This page is about making mods. For info about using mods, see [[Installing mods]].&lt;br /&gt;
&lt;br /&gt;
==Mod-making tutorials== &lt;br /&gt;
Mod-making tutorials are available at the [[Modding Tutorials]] page. If you can't find what you need, you should try looking in [[Modding/Random Bits of Information|Random Bits of Information]] to check if the information you're looking for has been found but just hasn't been organized into the correct article yet.&lt;br /&gt;
&lt;br /&gt;
===Mod-making Templates===&lt;br /&gt;
*[https://ludeon.com/forums/index.php?topic=39038.0 Mod Development Cookiecutter (automatically build your mod development environment)]&lt;br /&gt;
&lt;br /&gt;
==What you can mod==&lt;br /&gt;
You can mod defs, code, images, and sounds.&lt;br /&gt;
&lt;br /&gt;
* '''Defs''': XML files containing lists of definitions for use by the game. There are a lot of these. They define every thing, skills, storyteller, and many other types of data. Find them in YourModName/Defs. More about this later.&lt;br /&gt;
* '''Code''': You can add .NET assemblies and the game will load them. Place your DLLs in YourModName/Assemblies. More about this later.&lt;br /&gt;
* '''Images''': You can add images.&lt;br /&gt;
* '''Sounds''': You can add sound files.&lt;br /&gt;
* '''Jobs''':  A useful link here https://github.com/Mehni/ExampleJob/wiki - covers JobGivers WorkGivers and Toils&lt;br /&gt;
&lt;br /&gt;
==The basics: Defs==&lt;br /&gt;
The most basic kind of RimWorld modding is done by editing '''defs'''.&lt;br /&gt;
&lt;br /&gt;
Definitions each define some piece of the game. Different kinds of definitions can define:&lt;br /&gt;
&lt;br /&gt;
* '''Sound'''&lt;br /&gt;
* '''Weapons'''&lt;br /&gt;
* '''Buildings'''&lt;br /&gt;
* '''Plants'''&lt;br /&gt;
* '''Animals'''&lt;br /&gt;
* '''More (To be determined)'''&lt;br /&gt;
&lt;br /&gt;
When the game runs, it collects all the definitions into pools. It then semi-randomly draws from these pools in various circumstances. It will randomly draw guns of a certain category to arm a new enemy mercenary. Or, it will randomly spawn an animal type on the edge of the map. Modding the game means adding your definitions to these pools and watching the game use them in this way.&lt;br /&gt;
&lt;br /&gt;
Definitions are organized into packages. Each package is saved as a single XML file.&lt;br /&gt;
&lt;br /&gt;
Groups of packages are organized into mods. A mod is a unit of interlinked functionality and content. It could be a pack of new weapons, a new animal, or a total conversion of the game. A mod will usually contain several packages of various types, as well as content like images and sounds.&lt;br /&gt;
&lt;br /&gt;
The base game is defined in a single mod called Core.&lt;br /&gt;
&lt;br /&gt;
Players can choose which mods to activate. In some cases, several mods can be active at once. You could use a medieval mod to replace the core mod, and add on a weapons pack created by someone else. The game will run with the medieval mod content, and also randomly spawn in weapons from the extra weapons pack.&lt;br /&gt;
&lt;br /&gt;
==Mod file structure==&lt;br /&gt;
For defining new game content, '''[[wikipedia:XML|XML]]''' files are used. Here is an example of the format, that applies to most of the definitions:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot; ?&amp;gt;&lt;br /&gt;
&amp;lt;SomeDefs&amp;gt;&lt;br /&gt;
   &amp;lt;SomeDef&amp;gt;&lt;br /&gt;
      &amp;lt;defName&amp;gt;MyNewDefinitionOfContent&amp;lt;/defName&amp;gt;&lt;br /&gt;
      &amp;lt;!-- more tags will appear depending on what are you defining --&amp;gt;&lt;br /&gt;
   &amp;lt;/SomeDef&amp;gt;&lt;br /&gt;
&amp;lt;/SomeDefs&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Remember, that the word '''Some''' must be replaced by the name of whatever are you defining. For thing it's '''&amp;amp;lt;ThingDef&amp;amp;gt;'''.&lt;br /&gt;
&lt;br /&gt;
The RimWorld mods use the following directory structure:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
┌About &lt;br /&gt;
├─About.xml (Contains info about the mod)&lt;br /&gt;
├─Preview.png (Image that appears above the mod info in game. Max width 600px.)&lt;br /&gt;
│&lt;br /&gt;
├Assemblies (If your mod uses any DLL files put them here)&lt;br /&gt;
├─MyMod.dll&lt;br /&gt;
│&lt;br /&gt;
├Defs (Contains xml definitions of the mod)&lt;br /&gt;
├┬ThingDefs&lt;br /&gt;
│├─Things.xml&lt;br /&gt;
│└─Buildings.xml&lt;br /&gt;
│&lt;br /&gt;
├┬ResearchProjectDefs&lt;br /&gt;
│└─MyProjects.xml&lt;br /&gt;
│&lt;br /&gt;
│the folder name must be specific here. Look in Core mod to see what are other names supposed to be&lt;br /&gt;
│&lt;br /&gt;
├Sounds&lt;br /&gt;
│&lt;br /&gt;
├Source&lt;br /&gt;
├─MyMod.cs (Optionally, put the source code of your mod here)&lt;br /&gt;
│&lt;br /&gt;
├Patches&lt;br /&gt;
├─Patch.xml&lt;br /&gt;
│&lt;br /&gt;
├Languages&lt;br /&gt;
├┬English (Replace with the language name)&lt;br /&gt;
│├┬Keyed&lt;br /&gt;
││└─Keys.xml&lt;br /&gt;
│├┬Strings&lt;br /&gt;
││└┬Names&lt;br /&gt;
││  └─PawnNames.xml&lt;br /&gt;
│├┬DefInjected&lt;br /&gt;
││└┬ThingDef&lt;br /&gt;
││  └─Thing.xml&lt;br /&gt;
│├─LanguageInfo.xml&lt;br /&gt;
│└─LangIcon.png&lt;br /&gt;
│&lt;br /&gt;
├Textures (Put any image textures here, preferably in .png format.)&lt;br /&gt;
├┬Things&lt;br /&gt;
│├─MyMod_ImageA.png&lt;br /&gt;
│└─MyMod_ImageB.png&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Mod info===&lt;br /&gt;
This is found in &amp;lt;code&amp;gt;MODNAME/About&amp;lt;/code&amp;gt;&lt;br /&gt;
*The contents of About.xml are plain text. HTML Markup tags cause NullRef's.&lt;br /&gt;
*You can have an image for your mod. Restrict the image width to 600 pixels&lt;br /&gt;
&lt;br /&gt;
===Textures===&lt;br /&gt;
These are found in &amp;lt;code&amp;gt;MODNAME/Textures&amp;lt;/code&amp;gt;&lt;br /&gt;
*You can have any path you want from this point on.&lt;br /&gt;
*When referencing textures in your mod, using &amp;lt;graphicPath&amp;gt;, have the complete path relative to your mod, including the filename (but not the file extension). Example for the RoyalBed Testmod: &amp;lt;code&amp;gt;&amp;lt;graphicPath&amp;gt;Things/Building/RoyalBed&amp;lt;/graphicPath&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For textures that have multiple faces, like animals and furniture which can be rotated; You can use the Graphic_multi class. Immediately following your &amp;lt;graphicPath&amp;gt;&amp;lt;/graphicPath&amp;gt;. Your Path should point to the folder containing the different textures: Texturename_side, Texturename_front, and Texturename_back. &lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot; &amp;gt;&lt;br /&gt;
&amp;lt;graphicPath&amp;gt;Things/Buildings/RoyalCouch/RoyalCouch&amp;lt;/graphicPath&amp;gt;&lt;br /&gt;
&amp;lt;graphicClass&amp;gt;Graphic_multi&amp;lt;/graphicClass&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Inside your folder:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
┌Textures&lt;br /&gt;
└┬Things&lt;br /&gt;
 └┬Buildings&lt;br /&gt;
  └┬RoyalCouch&lt;br /&gt;
   ├╴RoyalCouch_side&lt;br /&gt;
   ├╴RoyalCouch_front&lt;br /&gt;
   └╴RoyalCouch_back&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Interactive &amp;quot;things&amp;quot;===&lt;br /&gt;
A thing is anything that exists in the game world. It includes resources, races (humanoid and animal), buildings, furniture, and many others.&lt;br /&gt;
&lt;br /&gt;
These are defined in &amp;lt;code&amp;gt;MODNAME/Defs/ThingDefs&amp;lt;/code&amp;gt;&lt;br /&gt;
If you make a new workbench, you'll need to define a recipe for it. This is a list, so you can have many new recipes listed.&lt;br /&gt;
&lt;br /&gt;
The recipes themselves are defined in: &amp;lt;code&amp;gt;MODNAME/Defs/RecipeDefs&amp;lt;/code&amp;gt;&lt;br /&gt;
In here you can define what ingredients/resources are required, what can be used, and what the default recipe is.&lt;br /&gt;
&lt;br /&gt;
Any new resources will need to be defined in: &amp;lt;code&amp;gt;MODNAME/Defs/ThingDefs&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Turrets===&lt;br /&gt;
These are defined in two files in: &amp;lt;code&amp;gt;MODNAME/Defs/ThingDefs/Buildings_Big.xml&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Weapons_Guns.xml&amp;lt;/code&amp;gt; (Remember, these can be named anything)&lt;br /&gt;
&lt;br /&gt;
Buildings_Big.xml defines the structure of the turret itself. For example:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot; &amp;gt;&lt;br /&gt;
&amp;lt;building&amp;gt;&lt;br /&gt;
	&amp;lt;turretGunDef&amp;gt;Gun_TurretImprovised&amp;lt;/turretGunDef&amp;gt;&lt;br /&gt;
	&amp;lt;burstCooldownTicks&amp;gt;300&amp;lt;/burstCooldownTicks&amp;gt;&lt;br /&gt;
&amp;lt;/building&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Weapons_Gun.xml defines the weapon the turret uses. Anything can be used as a weapon for turrets, including grenades.&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
These are defined in: &amp;lt;code&amp;gt;MODNAME/Defs/ThingDefs/Resources.xml&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Research projects===&lt;br /&gt;
These are found in: &amp;lt;code&amp;gt;MODNAME/Defs/ResearchProjectDefs&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can have research trees as well, where additional research projects get unlocked as you move through.&lt;br /&gt;
This is how to add prerequisites:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot; &amp;gt;&lt;br /&gt;
&amp;lt;prerequisites&amp;gt;&lt;br /&gt;
	&amp;lt;li&amp;gt;-this is the &amp;lt;defName&amp;gt; of the prerequisite-&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/prerequisites&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Because it's a list, you can have multiple prerequisites for a research project.&lt;br /&gt;
&lt;br /&gt;
==Advice==&lt;br /&gt;
*The tilde key (` or ~) brings up the development console, which will report any errors or warnings it encounters when a mod loads or during gameplay. This is the quickest way to see what, if any, errors exist in your mod. (You don't need to turn on development mode for this.)&lt;br /&gt;
*Use development mode (found in the options menu) to help debug your mod, spawn items related to your mod, or fire incidents at will. (Or just mess around, if you'd like.)&lt;br /&gt;
&lt;br /&gt;
==The other stuff: Code, Graphics, Sound==&lt;br /&gt;
&lt;br /&gt;
You can find links to tutorials on the [[Modding Tutorials]] page. There's also more tutorials about the basics there, so don't miss out on that.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
*[https://github.com/roxxploxx/RimWorldModGuide/wiki A good guide to assist people trying to mod RimWorld]&lt;br /&gt;
*[https://ludeon.com/forums/index.php?topic=39038.0 Mod Development Cookiecutter (automatically build your mod development environment)]&lt;br /&gt;
*[http://ludeon.com/forums/index.php?topic=1681.0 Simple tutorial forum thread]&lt;br /&gt;
*[https://ludeon.com/forums/index.php?topic=2325.0 RimWorld core art source thread]&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
*You can have as many mods as you like, however too many mods may affect performance.&lt;br /&gt;
*If the game crashes due to a mod-related reason on startup, or mods conflict with each other, then the game will reset the mods.&lt;br /&gt;
*Mods for previous versions may be usable, however most of the time they are not compatible.&lt;br /&gt;
&lt;br /&gt;
[[Category:Modding]]&lt;/div&gt;</summary>
		<author><name>Lilwhitemouse</name></author>
	</entry>
	<entry>
		<id>https://rimworldwiki.com/index.php?title=Modding_Tutorials/Custom_Comp_Classes&amp;diff=61628</id>
		<title>Modding Tutorials/Custom Comp Classes</title>
		<link rel="alternate" type="text/html" href="https://rimworldwiki.com/index.php?title=Modding_Tutorials/Custom_Comp_Classes&amp;diff=61628"/>
		<updated>2018-12-15T16:33:31Z</updated>

		<summary type="html">&lt;p&gt;Lilwhitemouse: /* Cautions, traps, etc */ better example&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Creating a custom comp class is a convenient way to add new functionality to RimWorld.&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
* You need to have [[Modding Tutorials/Setting up a solution|set up your editor and environment]]&lt;br /&gt;
* You need to know [[Modding Tutorials/Writing custom code|how to write custom code]]&lt;br /&gt;
* You should probably understand Defs at least somewhat.&lt;br /&gt;
&lt;br /&gt;
== def (xml) and C# structure ==&lt;br /&gt;
&lt;br /&gt;
=== Setup, Defs, and Classes ===&lt;br /&gt;
You will have some custom def and it will have something like this:&lt;br /&gt;
==== Defs (xml) ====&lt;br /&gt;
  &amp;lt;ThingDef ...&amp;gt;&lt;br /&gt;
    ...&lt;br /&gt;
    ...&lt;br /&gt;
    &amp;lt;comps&amp;gt;&lt;br /&gt;
      &amp;lt;&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt; Class=&amp;quot;MyNamespace.MyCompProperties&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;myCustomCompProperty&amp;gt;some value&amp;lt;/myCustomCompProperty&amp;gt;&lt;br /&gt;
        &amp;lt;mySecondCompProp&amp;gt;4&amp;lt;/mySecondCompProp&amp;gt;&lt;br /&gt;
      &amp;lt;/&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt;&amp;gt;&lt;br /&gt;
      &amp;lt;&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt;&amp;gt;&lt;br /&gt;
        ''&amp;lt;&amp;lt;nowiki&amp;gt;!--&amp;lt;/nowiki&amp;gt; this is kind of like &amp;lt;tag&amp;gt;MN.MyCustomTag&amp;lt;/tag&amp;gt;:--&amp;gt;''&lt;br /&gt;
        &amp;lt;compClass&amp;gt;MyNamespace.MyCustomThingComp&amp;lt;/compClass&amp;gt;&lt;br /&gt;
      &amp;lt;/&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt;&amp;gt;&lt;br /&gt;
    &amp;lt;/comps&amp;gt;&lt;br /&gt;
  &amp;lt;/ThingDef&amp;gt;&lt;br /&gt;
==== C# ====&lt;br /&gt;
  namespace MyNamespace ''// For example, LWM.ModName - by using your ''&lt;br /&gt;
                        ''//   handle/name/etc, you almost certainly guarantee uniqueness''&lt;br /&gt;
  {&lt;br /&gt;
  '''//////////// &amp;lt;&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki Class=&amp;quot;MyNamespace.MyCompProperties&amp;quot;&amp;gt; ////////////'''&lt;br /&gt;
  public class MyCompProperties : CompProperties ''// Name this as you wish, of course''&lt;br /&gt;
  {&lt;br /&gt;
    public Properties() {&lt;br /&gt;
      this.compClass = typeof(MyNamespace.MyLinkedCompThing); ''// rename as appropriate''&lt;br /&gt;
    }&lt;br /&gt;
    public string myCustomCompProperty; ''// Name matches def, of course''&lt;br /&gt;
    public int mySecondCompProp = 1; ''// Can set default values''&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  ''// this ThingComp is used to actually access the comp property defined above''&lt;br /&gt;
  '''''// this is not &amp;quot;&amp;lt;compClass&amp;gt;MyNamespace.MyCustomThingComp&amp;lt;/compClass&amp;gt;&amp;quot;'''''&lt;br /&gt;
  public class MyLinkedCompThing : ThingComp&lt;br /&gt;
  {&lt;br /&gt;
    public string myCustomCompProperty&lt;br /&gt;
    {&lt;br /&gt;
      get&lt;br /&gt;
      {&lt;br /&gt;
        return ((MyCompProperties)this.props).myCustomCompProperty;&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    public int mySecondCompProperty ''// Have to get all the names right''&lt;br /&gt;
    { get  { return ((MyCompProperties)this.props).mySecondCompProperty; } } ''//etc''&lt;br /&gt;
  }&lt;br /&gt;
  '''//////////// &amp;lt;compClass&amp;gt;MyNamespace.MyCustomThingComp&amp;lt;/compClass&amp;gt; ////////////'''&lt;br /&gt;
  public class MyCustomThingComp : ThingComp&lt;br /&gt;
  {&lt;br /&gt;
    public override void CompTick()&lt;br /&gt;
    {&lt;br /&gt;
      // do stuff&lt;br /&gt;
    }&lt;br /&gt;
    public override void CompTickRare() //etc&lt;br /&gt;
    public override ... // Check out Verse/ThingComp.cs for more ideas&lt;br /&gt;
  }&lt;br /&gt;
  } // end MyNamespace&lt;br /&gt;
&lt;br /&gt;
=== Accessing your Comps ===&lt;br /&gt;
Just setting up your custom comps doesn't do you a lot of good if you can't access them!&lt;br /&gt;
&lt;br /&gt;
'''To do'''&lt;br /&gt;
&lt;br /&gt;
=== Cautions, traps, etc ===&lt;br /&gt;
If you have the same comp in an abstract def and attempt to redefine it in a child def, it will get counted twice.  It's possible to get around this in the code, if you want to have default comps:&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;ThingDef Name=ParentWithDefault ... Abstract=true&amp;gt;&lt;br /&gt;
    ...&lt;br /&gt;
    &amp;lt;comps&amp;gt;&lt;br /&gt;
      &amp;lt;l&amp;lt;nowiki&amp;gt;i&amp;lt;/nowiki&amp;gt; Class=&amp;quot;MyCompPropertiesWithDefault&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;myValue&amp;gt;3&amp;lt;/myValue&amp;gt;&amp;lt;!--default!--&amp;gt;&lt;br /&gt;
      &amp;lt;/l&amp;lt;nowiki&amp;gt;i&amp;lt;/nowiki&amp;gt;&amp;gt;&lt;br /&gt;
    &amp;lt;/comps&amp;gt;&lt;br /&gt;
  &amp;lt;/ThingDef&amp;gt;&lt;br /&gt;
  &amp;lt;ThingDef ParentName=&amp;quot;ParentWihtDefault&amp;quot;&amp;gt;&lt;br /&gt;
    ...&lt;br /&gt;
    &amp;lt;comps&amp;gt;&lt;br /&gt;
      &amp;lt;l&amp;lt;nowiki&amp;gt;i&amp;lt;/nowiki&amp;gt; Class=&amp;quot;MyCompPropertiesWithDefault&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;myValue&amp;gt;5&amp;lt;/myValue&amp;gt;&amp;lt;!-- override default!--&amp;gt;&lt;br /&gt;
      &amp;lt;/&amp;lt;nowiki&amp;gt;l&amp;lt;/nowiki&amp;gt;i&amp;gt;&lt;br /&gt;
    &amp;lt;/comps&amp;gt;&lt;br /&gt;
  &amp;lt;/ThingDef&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  public class MyLinkedCompThing : ThingComp&lt;br /&gt;
  {&lt;br /&gt;
    public string myCustomCompProperty //etc&lt;br /&gt;
    &lt;br /&gt;
    public override void Initialize (CompProperties props) {&lt;br /&gt;
      base.Initialize(props);&lt;br /&gt;
      // Remove duplicate entries and ensure the last entry is the only one left&lt;br /&gt;
      //   This allows a default abstract def with the comp&lt;br /&gt;
      //   and child def to change the comp value:&lt;br /&gt;
      MyCompProprtiesWithDefault[] list = this.parent.GetComps&amp;lt;MyCompPropertiesWithDefault&amp;gt;().ToArray();&lt;br /&gt;
      // Remove everything but the last entry; harmless if only one entry:&lt;br /&gt;
      for (var i = 0; i &amp;lt; list.Length-1; i++)&lt;br /&gt;
      {&lt;br /&gt;
        this.parent.AllComps.Remove(list[i]);&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
  &lt;br /&gt;
  ///etc&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
[[Category:Modding tutorials]][[Category:Modding]][[Category:Defs]]&lt;/div&gt;</summary>
		<author><name>Lilwhitemouse</name></author>
	</entry>
	<entry>
		<id>https://rimworldwiki.com/index.php?title=Modding_Tutorials/Setting_up_a_solution&amp;diff=61456</id>
		<title>Modding Tutorials/Setting up a solution</title>
		<link rel="alternate" type="text/html" href="https://rimworldwiki.com/index.php?title=Modding_Tutorials/Setting_up_a_solution&amp;diff=61456"/>
		<updated>2018-12-01T18:59:08Z</updated>

		<summary type="html">&lt;p&gt;Lilwhitemouse: link to cookiecutter&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{BackToTutorials}}&lt;br /&gt;
{{Credit|[[User:Alistaire|Alistaire]]}}&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this tutorial you will learn how to set up a solution, along with instructions on setting the output directory and files for more convenient building right into the Assemblies folder.&lt;br /&gt;
&lt;br /&gt;
=Important Note=&lt;br /&gt;
There is a [https://ludeon.com/forums/index.php?topic=39038.0 Rimworld Mod Development Cookiecutter] tool available that should be able to set up a lot of these files/etc for you!&lt;br /&gt;
&lt;br /&gt;
=Requirements=&lt;br /&gt;
&lt;br /&gt;
* The manual option in this tutorial requires you to have [[Modding_Tutorials/Mod_folder_structure#The Source and Assemblies folders|set up a Source and Assemblies folder]] (the Visual Studio automatic option sets this up for you).&lt;br /&gt;
* You will want to have an IDE installed: [[Modding Tutorials/Recommended software#IDE's|Recommended IDE's]].&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Setting up a solution=&lt;br /&gt;
Setting up can be different for different IDE's. Feel free to add '''''complete''''' instructions for your IDE of choice.&lt;br /&gt;
&lt;br /&gt;
===Visual Studio Community 2017===&lt;br /&gt;
''NOTE: Visual Studio 2017 is a rather heavy application (2-3 GB for basic functionality) but has a bit more functionality. Only Install if your computer can handle it! The tutorial is similar for Visual Studio 2015.''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Option 1 (Manual Method):====&lt;br /&gt;
# Create a new class library project&lt;br /&gt;
## Once loaded, go to File -&amp;gt; New -&amp;gt; Project...&lt;br /&gt;
## Go to Templates -&amp;gt; Visual C# -&amp;gt; Class Library (Be sure to select the *.NET Framework* version, not *.NET Standard*) [[File:Capture.png|200px|thumb|right|Installing the .NET framework]]&lt;br /&gt;
## Enter your name and solution name in the lower pane.&lt;br /&gt;
## Choose a location, preferably:&amp;lt;br/&amp;gt;&amp;lt;pre&amp;gt;(RimWorldInstallFolder)/Mods/(YourModName)/Source&amp;lt;/pre&amp;gt;&lt;br /&gt;
## ''Optional'': Untick &amp;quot;Create directory for solution&amp;quot;&lt;br /&gt;
# In your project, set target framework and various other porperties&lt;br /&gt;
## In your Solution Explorer, right click your project -&amp;gt; Properties&lt;br /&gt;
## Once in your properties, select Application -&amp;gt; Set Target Framework to .NET Framework 3.5 (No client profile)&lt;br /&gt;
## ''Optional'': Change your Assembly and Namespace names to anything of your choice&lt;br /&gt;
## Go to Build -&amp;gt; Advanced... and set &amp;quot;Debugging information&amp;quot; to none&lt;br /&gt;
## Leave Advanced..., and set the Output Path to &amp;quot;..\..\Assemblies\&amp;quot; (The Assemblies folder in your mod folder)&lt;br /&gt;
# Add references to RimWorld code&lt;br /&gt;
## Expand your project. Then right click &amp;quot;References&amp;quot; -&amp;gt; Add Reference...&lt;br /&gt;
## Click Browse...&lt;br /&gt;
## Navigate towards &amp;lt;pre&amp;gt;RimWorld******/RimWorld******_Data/Managed&amp;lt;/pre&amp;gt; and select files: &amp;lt;br/&amp;gt;&amp;lt;pre&amp;gt;Assembly-CSharp.dll&amp;amp;#10;UnityEngine.dll&amp;lt;/pre&amp;gt;&lt;br /&gt;
## Click &amp;quot;Add&amp;quot;&lt;br /&gt;
## Right click on both Assembly-CSharp.dll and UnityEngine.dll and set Copy Local to False (Properties pane).&lt;br /&gt;
&lt;br /&gt;
====Option 2 (Automatic Method):====&lt;br /&gt;
# Open Visual Studio&lt;br /&gt;
# Once loaded, go to File -&amp;gt; New -&amp;gt; From Cookiecutter...&lt;br /&gt;
# Search for ''rimworld''&lt;br /&gt;
# Double-click ''cookiecutter-rimworld-mod-development''&lt;br /&gt;
# Change the Template Options:&lt;br /&gt;
## ''Create To'' =&amp;gt; ''Your/Rimworld/Mod/Directory''&lt;br /&gt;
## ''mod_name''&lt;br /&gt;
## ''namespace_name'' (don't change if unsure)&lt;br /&gt;
## ''author'' =&amp;gt; ''your steam username''&lt;br /&gt;
## ''target_version'' =&amp;gt; current RW version (can leave blank for most up-to-date)&lt;br /&gt;
## ''in_game_description'' (not required, can change later in About-Release.xml)&lt;br /&gt;
## ''url'' (can leave blank for link to your Steam Workshop profile)&lt;br /&gt;
# Click &amp;quot;Create and Open Folder&amp;quot;&lt;br /&gt;
&lt;br /&gt;
===Sharpdevelop===&lt;br /&gt;
'''Caution:''' Sharpdevelop (or #develop) does NOT CURRENTLY allow for C# 6.0+ syntax without plugins and does NOT ALLOW for C# 7.0+ syntax at all. For your average project this does not matter, however some existing projects are already built entirely upon C# 6.0+ syntax which can not be compiled anymore in Sharpdevelop. Visual Studio does not have these issues and should be your go-to for compiling large projects such as Combat Extended.&lt;br /&gt;
&lt;br /&gt;
# Create a new class library project in your [[Modding Tutorials/Recommended software#IDE.27s|IDE of choice]];&lt;br /&gt;
## Go to File -&amp;gt; New -&amp;gt; Solution;&lt;br /&gt;
## Go to C# or .NET -&amp;gt; Library or Class Library (NOT portable);&lt;br /&gt;
## Enter a project name (solution name automatically updated);&lt;br /&gt;
## Choose a location, preferably:&amp;lt;br/&amp;gt;&amp;lt;pre&amp;gt;(RimWorldInstallFolder)/Mods/(YourModName)/Source&amp;lt;/pre&amp;gt;&lt;br /&gt;
## ''Optional'': Untick &amp;quot;Create a directory for solution&amp;quot;/&amp;quot;Create a project within the solution directory&amp;quot;,&lt;br /&gt;
# In your project, add references to Assembly-CSharp.dll and UnityEngine.dll:&lt;br /&gt;
## In your IDE project file browser, right-click the &amp;quot;References&amp;quot; folder and &amp;quot;Add reference&amp;quot;;&lt;br /&gt;
## Choose the &amp;quot;.NET Assembly Browser&amp;quot; tab and &amp;quot;Browse...&amp;quot;;&lt;br /&gt;
## Navigate towards &amp;lt;pre&amp;gt;RimWorld******/RimWorld******_Data/Managed&amp;lt;/pre&amp;gt; and select files: &amp;lt;br/&amp;gt;&amp;lt;pre&amp;gt;Assembly-CSharp.dll&amp;amp;#10;UnityEngine.dll&amp;lt;/pre&amp;gt;&lt;br /&gt;
## Click &amp;quot;Open&amp;quot; then &amp;quot;OK&amp;quot;;&lt;br /&gt;
## In the References folder, right-click Assembly-CSharp -&amp;gt; Properties and change &amp;quot;Local copy&amp;quot; to False. Do the same for UnityEngine,&lt;br /&gt;
# In your project properties, change the target framework to .NET 3.5:&lt;br /&gt;
## In your IDE project file browser, right-click &amp;quot;(YourSolutionName)&amp;quot;;&lt;br /&gt;
## Choose Properties;&lt;br /&gt;
## Go to the &amp;quot;Compiling&amp;quot; tab, &amp;quot;Output&amp;quot;, &amp;quot;Target framework&amp;quot;, &amp;quot;Change&amp;quot; and choose &amp;quot;.NET Framework 3.5&amp;quot;,&lt;br /&gt;
# In your project properties, change the build events so only a single file is built:&lt;br /&gt;
## Go to the &amp;quot;Compiling&amp;quot; tab, &amp;quot;Output&amp;quot;, &amp;quot;Debug info&amp;quot; and choose &amp;quot;No debug information&amp;quot;;&lt;br /&gt;
## Right-click your .cs files -&amp;gt; Properties and change &amp;quot;Copy to output&amp;quot; (If you haven't resized the properties bar, this will be truncated to &amp;quot;Copy to out&amp;quot;) to Never,&lt;br /&gt;
# In your project properties, fix the output location to put the DLL in the Assemblies folder:&lt;br /&gt;
## Go to the &amp;quot;Compiling&amp;quot; tab, &amp;quot;Output&amp;quot;, &amp;quot;Output path&amp;quot; and change the output path to &amp;quot;..\..\Assemblies\&amp;quot;.&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Xamarin/MonoDevelop===&lt;br /&gt;
The setup is similar as the one above. A few special points to address:&lt;br /&gt;
# Mono 4.X isn't backward compatible so you may need to install an older 3.X version of Mono in order to compile against .NET3.5 dlls.&lt;br /&gt;
# Make sure you uncheck &amp;quot;Use MSBuild build engine (recommended for this project type)&amp;quot; under project &amp;gt; options &amp;gt; build &amp;gt; general   (You might find this by right-clicking on your project - not solution - name and selecting options)&lt;br /&gt;
# Changing the framework to 3.5 can be found (for Linux anyway) in the same place.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Rider (good for Mac)===&lt;br /&gt;
JetBrains Rider is a great cross-platform C# IDE, but it isn't cheap. It's $140 for the first year, including perpetual access to that version (access to future updates gets cheaper, but it's still over $100/year). However, the Early Access versions are a bit unstable but free. They also offer free student licenses.&lt;br /&gt;
&lt;br /&gt;
# Open Rider and click New Solution in the welcome dialog.&lt;br /&gt;
## Click Class Library under .NET on the left. The option may a second to show up.&lt;br /&gt;
## Under Solution Name (and Project Name), enter the name of your mod.&lt;br /&gt;
## Set the Solution Directory to [your mod folder]/Source.&lt;br /&gt;
## Optionally check &amp;quot;put solution and project in the same directory.&amp;quot; This is probably a good idea.&lt;br /&gt;
## Change Framework to .Net Framework 3.5.&lt;br /&gt;
## Click Create.&lt;br /&gt;
# In the left side bar, expand your solution, right click your project (mod name with &amp;quot;C#&amp;quot; icon) and click Properties.&lt;br /&gt;
## In the Properties window, select Configurations &amp;gt; Debug on the left and uncheck Debug Symbols.&lt;br /&gt;
## For both configurations, change the Output Path to ../../Assemblies.&lt;br /&gt;
## Click OK.&lt;br /&gt;
# Expand your project, right click References and click Add Reference.&lt;br /&gt;
## Click Add From.&lt;br /&gt;
## Browse to the folder with the RimWorld DLLs (Mac: /Users/[username]/Library/Application Support/Steam/steamapps/common/RimWorld/RimWorldMac.app/Contents/Resources/Data/Managed).&lt;br /&gt;
## Select both Assembly-CSharp.dll and UnityEngine.dll and click OK.&lt;br /&gt;
## Expand Assemblies under References. For both of the assemblies that you just added:&lt;br /&gt;
### Right click the assembly and click Properties.&lt;br /&gt;
### Uncheck &amp;quot;Copy Local&amp;quot; (you may need to scroll down) and click OK.&lt;br /&gt;
&lt;br /&gt;
You're done! Note that Rider has a built-in decompiler—to view the source of a RimWorld class or method, just right-click its name and click Go To &amp;gt; Definition.&lt;br /&gt;
&lt;br /&gt;
=See also=&lt;br /&gt;
* [[Modding Tutorials/Writing custom code|Writing custom code]] continues on setting up your solution.&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Modding tutorials]]&lt;/div&gt;</summary>
		<author><name>Lilwhitemouse</name></author>
	</entry>
	<entry>
		<id>https://rimworldwiki.com/index.php?title=Modding_Tutorials/Recommended_software&amp;diff=61440</id>
		<title>Modding Tutorials/Recommended software</title>
		<link rel="alternate" type="text/html" href="https://rimworldwiki.com/index.php?title=Modding_Tutorials/Recommended_software&amp;diff=61440"/>
		<updated>2018-11-30T05:39:56Z</updated>

		<summary type="html">&lt;p&gt;Lilwhitemouse: /* IDE's */ Linux!&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{BackToTutorials}}&lt;br /&gt;
{{Credit|[[User:Alistaire|Alistaire]]}}&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=What you'll learn=&lt;br /&gt;
&lt;br /&gt;
This tutorial lists a few programs you could use to edit XML and C# code.&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=XML Code Editors=&lt;br /&gt;
&lt;br /&gt;
===Basic Editors===&lt;br /&gt;
&lt;br /&gt;
Just about any text editor can write XML code, but as a modder you will want to at the very least see when you forgot closing brackets, a closing tag and other syntax errors.&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notepad doesn't do this, so if you're even somewhat serious about modding, the following software will help you immensely:&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Software !! OS !! Description&lt;br /&gt;
|-&lt;br /&gt;
| [NotepadQQ] || Linux || Notepadqq is a Notepad++-like editor for the Linux desktop so has the exact same UI and functions as Notepad++&lt;br /&gt;
|-&lt;br /&gt;
| [http://notepad-plus-plus.org/download/ Notepad++] || Windows || Has well implemented auto-completion and a very customizable user interface. Can be used to write both XML and C# code, although C# software usually has its own text editor&lt;br /&gt;
|-&lt;br /&gt;
| [http://www.sublimetext.com/ Sublime Text] || Linux/Windows/Mac || Natively supports many programming languages and markup languages, and its functionality can be extended by users with plugins - A brief overview of its functionality can be found [http://webdesign.tutsplus.com/tutorials/useful-shortcuts-for-a-faster-workflow-in-sublime-text-3--cms-22185 here] and a full course [http://code.tutsplus.com/courses/perfect-workflow-in-sublime-text-2 here]&lt;br /&gt;
|-&lt;br /&gt;
| [http://www.pnotepad.org/download/ Programmer's Notepad] || Windows || More lightweight with a less cluttered interface than Notepad++, also capable of editing both XML and C# code&lt;br /&gt;
|-&lt;br /&gt;
| [http://xmlnotepad.codeplex.com/releases/ XML Notepad] || Windows || XML-oriented editor with a lot of features you will most likely never use in Rimworld modding&lt;br /&gt;
|-&lt;br /&gt;
| [http://www.geany.org/ Geany] || Linux/Windows/Mac || Extremely lightweight text editor with syntax highlighting and some other basic features oriented towards XML and code editing.&lt;br /&gt;
|}&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Advanced Editors===&lt;br /&gt;
&lt;br /&gt;
There's many editors out there specifically made for XML code. Because Rimworld uses XML in a very simple way, advanced code editors are rarely needed. In case you're ever in need of one, however, the following ones might help:&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Software !! OS !! Description&lt;br /&gt;
|-&lt;br /&gt;
| [http://sourceforge.net/projects/xpontus/files/ XPontus] || Windows || Has a tree view and is capable of checking XML for errors, fixing tabs and creating schema's detailing every tag's data types&lt;br /&gt;
|-&lt;br /&gt;
| [http://xmlgrid.net/ XMLGrid] || - || Capable of validating XML and turning it into Excel Spreadsheets, XSD Charts and an online table detailing each tag of a certain type and its contents&lt;br /&gt;
|-&lt;br /&gt;
| [http://codebeautify.org/xmlviewer Codebeautify's xmlviewer] || - || Can display as a tree view, automatically format/indent your code and can validate and show errors too. Also have a function share code (like [http://codebeautify.org/xmlviewer/b39586 that])&lt;br /&gt;
|}&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=IDE's=&lt;br /&gt;
&lt;br /&gt;
C# code is best edited in an IDE (Integrated Development Environment) to make the process of editing code, managing a solution's content and compiling its projects both easier and faster. Any IDE for C# will probably work just fine, so here's a list of suggested editors:&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Software !! OS !! Description&lt;br /&gt;
|-&lt;br /&gt;
| [http://www.visualstudio.com/ Visual Studio] || Windows || Very extensive IDE with paid, trial and free versions. Any of these versions will probably work, so you might as well take [https://www.visualstudio.com/products/visual-studio-community-vs Visual Studio Community 2015] which is free for individuals and small teams&lt;br /&gt;
|-&lt;br /&gt;
| [http://www.icsharpcode.net/OpenSource/SD/Download/ SharpDevelop] || Windows || Free IDE specifically made for C#&lt;br /&gt;
|-&lt;br /&gt;
| [http://www.monodevelop.com/download/ MonoDevelop] || Linux/Windows/Mac || Free, cross-platform IDE with customizable user interface. Has support for C# as well as some other languages you won't need for Rimworld&lt;br /&gt;
|-&lt;br /&gt;
| [http://www.xamarin.com/platform Xamarin] || Mac || It's free but you need to register to download it. Probably your best option on a mac.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
'''For Linux users:''' See also [https://ludeon.com/forums/index.php?topic=46775.0 this thread] about working with C# on ArchLinux - it may be useful.&lt;br /&gt;
&lt;br /&gt;
Whichever IDE you choose, make sure it's capable of compiling for .NET Framework 3.5. If you for whatever reason don't have this framework installed, you can download it [https://www.microsoft.com/en-us/download/details.aspx?id=21 here].&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Additional C# Software=&lt;br /&gt;
&lt;br /&gt;
Besides your IDE it's strongly recommended to install the following software for decompiling:&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Software !! OS !! Description&lt;br /&gt;
|-&lt;br /&gt;
| [https://github.com/0xd4d/dnSpy dnSpy] || Windows || Software which is capable of [[Modding Tutorials/Decompiling source code|decompiling source code]], which is very useful in Rimworld modding (some authors have had better luck with dnSpy than ILSpy?)&lt;br /&gt;
|-&lt;br /&gt;
| [http://ilspy.net/ ILSpy] || Windows || Software which is capable of [[Modding Tutorials/Decompiling source code|decompiling source code]], which is very useful in Rimworld modding&lt;br /&gt;
|-&lt;br /&gt;
| [http://www.monodevelop.com/download/ MonoDevelop] || Linux/Windows/Mac || The Linux version of the software has an integrated decompiler for .DLLs&lt;br /&gt;
|}&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Graphics Software=&lt;br /&gt;
&lt;br /&gt;
For making textures you will need graphics software. Any image editing program should work, and if you have an alternative to the following links that's probably okay:&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Software !! OS !! Description&lt;br /&gt;
|-&lt;br /&gt;
| [http://www.photofiltre-studio.com/download-en.htm Photofiltre Studio] || Windows || Functional software with very little user interface clutter for its applications. Doesn't support pen tablet, and has a 100% free (non-trial) version called [http://photofiltre.free.fr/download_en.htm Photofiltre]&lt;br /&gt;
|-&lt;br /&gt;
| [http://inkscape.org/en/download/ Inkscape] || Linux/Windows/Mac || Free vector graphic program with a steeper learning curve due to the vector based image editing. Vector graphics can look better than bitmap graphics in Rimworld&lt;br /&gt;
|-&lt;br /&gt;
| [http://www.photoshop.com/products Photoshop] || Windows/Mac || Paid software with a trial version. Rimworld's original graphics are made in Photoshop (they're .PSD files)&lt;br /&gt;
|-&lt;br /&gt;
| [http://www.gimp.org/ Gimp] || Linux/Windows/Mac || A free, open-source alternative to Photoshop that's been around since 1998. Gimp has a large user community, with great list of [http://www.gimp.org/tutorials/ tutorials] on the official sites&lt;br /&gt;
|-&lt;br /&gt;
| [https://krita.org/en/homepage/ Krita] || Linux/Windows/Mac || A free digital painting software. Better suited than GIMP for painting and should feel like home pretty quick for Photoshop users.&lt;br /&gt;
|}&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Audio Software=&lt;br /&gt;
&lt;br /&gt;
Recording your own audio for mods might be too much to ask, but editing audio is always possible. This can be done with the following software or your own alternative:&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Software !! OS !! Description&lt;br /&gt;
|-&lt;br /&gt;
| [http://sourceforge.net/projects/audacity/ Audacity] || Linux/Windows/Mac || Audio editing software with many tutorials online, lots of useful functionality and a relatively readable interface&lt;br /&gt;
|}&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Next up=&lt;br /&gt;
&lt;br /&gt;
# [[Modding Tutorials/XML file structure|XML File Structure]] starts you off with the XML side of modding.&lt;br /&gt;
# [[Modding_Tutorials/Setting up a solution|Setting up]] starts you off with the C# side of modding. Knowledge of the XML part can and will be very useful.&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Modding tutorials]]&lt;/div&gt;</summary>
		<author><name>Lilwhitemouse</name></author>
	</entry>
	<entry>
		<id>https://rimworldwiki.com/index.php?title=Modding_Tutorials/Recommended_software&amp;diff=61439</id>
		<title>Modding Tutorials/Recommended software</title>
		<link rel="alternate" type="text/html" href="https://rimworldwiki.com/index.php?title=Modding_Tutorials/Recommended_software&amp;diff=61439"/>
		<updated>2018-11-30T05:38:42Z</updated>

		<summary type="html">&lt;p&gt;Lilwhitemouse: /* Additional C# Software */ typo&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{BackToTutorials}}&lt;br /&gt;
{{Credit|[[User:Alistaire|Alistaire]]}}&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=What you'll learn=&lt;br /&gt;
&lt;br /&gt;
This tutorial lists a few programs you could use to edit XML and C# code.&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=XML Code Editors=&lt;br /&gt;
&lt;br /&gt;
===Basic Editors===&lt;br /&gt;
&lt;br /&gt;
Just about any text editor can write XML code, but as a modder you will want to at the very least see when you forgot closing brackets, a closing tag and other syntax errors.&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notepad doesn't do this, so if you're even somewhat serious about modding, the following software will help you immensely:&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Software !! OS !! Description&lt;br /&gt;
|-&lt;br /&gt;
| [NotepadQQ] || Linux || Notepadqq is a Notepad++-like editor for the Linux desktop so has the exact same UI and functions as Notepad++&lt;br /&gt;
|-&lt;br /&gt;
| [http://notepad-plus-plus.org/download/ Notepad++] || Windows || Has well implemented auto-completion and a very customizable user interface. Can be used to write both XML and C# code, although C# software usually has its own text editor&lt;br /&gt;
|-&lt;br /&gt;
| [http://www.sublimetext.com/ Sublime Text] || Linux/Windows/Mac || Natively supports many programming languages and markup languages, and its functionality can be extended by users with plugins - A brief overview of its functionality can be found [http://webdesign.tutsplus.com/tutorials/useful-shortcuts-for-a-faster-workflow-in-sublime-text-3--cms-22185 here] and a full course [http://code.tutsplus.com/courses/perfect-workflow-in-sublime-text-2 here]&lt;br /&gt;
|-&lt;br /&gt;
| [http://www.pnotepad.org/download/ Programmer's Notepad] || Windows || More lightweight with a less cluttered interface than Notepad++, also capable of editing both XML and C# code&lt;br /&gt;
|-&lt;br /&gt;
| [http://xmlnotepad.codeplex.com/releases/ XML Notepad] || Windows || XML-oriented editor with a lot of features you will most likely never use in Rimworld modding&lt;br /&gt;
|-&lt;br /&gt;
| [http://www.geany.org/ Geany] || Linux/Windows/Mac || Extremely lightweight text editor with syntax highlighting and some other basic features oriented towards XML and code editing.&lt;br /&gt;
|}&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Advanced Editors===&lt;br /&gt;
&lt;br /&gt;
There's many editors out there specifically made for XML code. Because Rimworld uses XML in a very simple way, advanced code editors are rarely needed. In case you're ever in need of one, however, the following ones might help:&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Software !! OS !! Description&lt;br /&gt;
|-&lt;br /&gt;
| [http://sourceforge.net/projects/xpontus/files/ XPontus] || Windows || Has a tree view and is capable of checking XML for errors, fixing tabs and creating schema's detailing every tag's data types&lt;br /&gt;
|-&lt;br /&gt;
| [http://xmlgrid.net/ XMLGrid] || - || Capable of validating XML and turning it into Excel Spreadsheets, XSD Charts and an online table detailing each tag of a certain type and its contents&lt;br /&gt;
|-&lt;br /&gt;
| [http://codebeautify.org/xmlviewer Codebeautify's xmlviewer] || - || Can display as a tree view, automatically format/indent your code and can validate and show errors too. Also have a function share code (like [http://codebeautify.org/xmlviewer/b39586 that])&lt;br /&gt;
|}&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=IDE's=&lt;br /&gt;
&lt;br /&gt;
C# code is best edited in an IDE (Integrated Development Environment) to make the process of editing code, managing a solution's content and compiling its projects both easier and faster. Any IDE for C# will probably work just fine, so here's a list of suggested editors:&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Software !! OS !! Description&lt;br /&gt;
|-&lt;br /&gt;
| [http://www.visualstudio.com/ Visual Studio] || Windows || Very extensive IDE with paid, trial and free versions. Any of these versions will probably work, so you might as well take [https://www.visualstudio.com/products/visual-studio-community-vs Visual Studio Community 2015] which is free for individuals and small teams&lt;br /&gt;
|-&lt;br /&gt;
| [http://www.icsharpcode.net/OpenSource/SD/Download/ SharpDevelop] || Windows || Free IDE specifically made for C#&lt;br /&gt;
|-&lt;br /&gt;
| [http://www.monodevelop.com/download/ MonoDevelop] || Linux/Windows/Mac || Free, cross-platform IDE with customizable user interface. Has support for C# as well as some other languages you won't need for Rimworld&lt;br /&gt;
|-&lt;br /&gt;
| [http://www.xamarin.com/platform Xamarin] || Mac || It's free but you need to register to download it. Probably your best option on a mac.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Whichever IDE you choose, make sure it's capable of compiling for .NET Framework 3.5. If you for whatever reason don't have this framework installed, you can download it [https://www.microsoft.com/en-us/download/details.aspx?id=21 here].&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Additional C# Software=&lt;br /&gt;
&lt;br /&gt;
Besides your IDE it's strongly recommended to install the following software for decompiling:&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Software !! OS !! Description&lt;br /&gt;
|-&lt;br /&gt;
| [https://github.com/0xd4d/dnSpy dnSpy] || Windows || Software which is capable of [[Modding Tutorials/Decompiling source code|decompiling source code]], which is very useful in Rimworld modding (some authors have had better luck with dnSpy than ILSpy?)&lt;br /&gt;
|-&lt;br /&gt;
| [http://ilspy.net/ ILSpy] || Windows || Software which is capable of [[Modding Tutorials/Decompiling source code|decompiling source code]], which is very useful in Rimworld modding&lt;br /&gt;
|-&lt;br /&gt;
| [http://www.monodevelop.com/download/ MonoDevelop] || Linux/Windows/Mac || The Linux version of the software has an integrated decompiler for .DLLs&lt;br /&gt;
|}&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Graphics Software=&lt;br /&gt;
&lt;br /&gt;
For making textures you will need graphics software. Any image editing program should work, and if you have an alternative to the following links that's probably okay:&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Software !! OS !! Description&lt;br /&gt;
|-&lt;br /&gt;
| [http://www.photofiltre-studio.com/download-en.htm Photofiltre Studio] || Windows || Functional software with very little user interface clutter for its applications. Doesn't support pen tablet, and has a 100% free (non-trial) version called [http://photofiltre.free.fr/download_en.htm Photofiltre]&lt;br /&gt;
|-&lt;br /&gt;
| [http://inkscape.org/en/download/ Inkscape] || Linux/Windows/Mac || Free vector graphic program with a steeper learning curve due to the vector based image editing. Vector graphics can look better than bitmap graphics in Rimworld&lt;br /&gt;
|-&lt;br /&gt;
| [http://www.photoshop.com/products Photoshop] || Windows/Mac || Paid software with a trial version. Rimworld's original graphics are made in Photoshop (they're .PSD files)&lt;br /&gt;
|-&lt;br /&gt;
| [http://www.gimp.org/ Gimp] || Linux/Windows/Mac || A free, open-source alternative to Photoshop that's been around since 1998. Gimp has a large user community, with great list of [http://www.gimp.org/tutorials/ tutorials] on the official sites&lt;br /&gt;
|-&lt;br /&gt;
| [https://krita.org/en/homepage/ Krita] || Linux/Windows/Mac || A free digital painting software. Better suited than GIMP for painting and should feel like home pretty quick for Photoshop users.&lt;br /&gt;
|}&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Audio Software=&lt;br /&gt;
&lt;br /&gt;
Recording your own audio for mods might be too much to ask, but editing audio is always possible. This can be done with the following software or your own alternative:&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Software !! OS !! Description&lt;br /&gt;
|-&lt;br /&gt;
| [http://sourceforge.net/projects/audacity/ Audacity] || Linux/Windows/Mac || Audio editing software with many tutorials online, lots of useful functionality and a relatively readable interface&lt;br /&gt;
|}&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Next up=&lt;br /&gt;
&lt;br /&gt;
# [[Modding Tutorials/XML file structure|XML File Structure]] starts you off with the XML side of modding.&lt;br /&gt;
# [[Modding_Tutorials/Setting up a solution|Setting up]] starts you off with the C# side of modding. Knowledge of the XML part can and will be very useful.&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Modding tutorials]]&lt;/div&gt;</summary>
		<author><name>Lilwhitemouse</name></author>
	</entry>
	<entry>
		<id>https://rimworldwiki.com/index.php?title=Modding_Tutorials/Recommended_software&amp;diff=61438</id>
		<title>Modding Tutorials/Recommended software</title>
		<link rel="alternate" type="text/html" href="https://rimworldwiki.com/index.php?title=Modding_Tutorials/Recommended_software&amp;diff=61438"/>
		<updated>2018-11-30T05:38:25Z</updated>

		<summary type="html">&lt;p&gt;Lilwhitemouse: /* Additional C# Software */ dnSpy&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{BackToTutorials}}&lt;br /&gt;
{{Credit|[[User:Alistaire|Alistaire]]}}&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=What you'll learn=&lt;br /&gt;
&lt;br /&gt;
This tutorial lists a few programs you could use to edit XML and C# code.&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=XML Code Editors=&lt;br /&gt;
&lt;br /&gt;
===Basic Editors===&lt;br /&gt;
&lt;br /&gt;
Just about any text editor can write XML code, but as a modder you will want to at the very least see when you forgot closing brackets, a closing tag and other syntax errors.&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notepad doesn't do this, so if you're even somewhat serious about modding, the following software will help you immensely:&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Software !! OS !! Description&lt;br /&gt;
|-&lt;br /&gt;
| [NotepadQQ] || Linux || Notepadqq is a Notepad++-like editor for the Linux desktop so has the exact same UI and functions as Notepad++&lt;br /&gt;
|-&lt;br /&gt;
| [http://notepad-plus-plus.org/download/ Notepad++] || Windows || Has well implemented auto-completion and a very customizable user interface. Can be used to write both XML and C# code, although C# software usually has its own text editor&lt;br /&gt;
|-&lt;br /&gt;
| [http://www.sublimetext.com/ Sublime Text] || Linux/Windows/Mac || Natively supports many programming languages and markup languages, and its functionality can be extended by users with plugins - A brief overview of its functionality can be found [http://webdesign.tutsplus.com/tutorials/useful-shortcuts-for-a-faster-workflow-in-sublime-text-3--cms-22185 here] and a full course [http://code.tutsplus.com/courses/perfect-workflow-in-sublime-text-2 here]&lt;br /&gt;
|-&lt;br /&gt;
| [http://www.pnotepad.org/download/ Programmer's Notepad] || Windows || More lightweight with a less cluttered interface than Notepad++, also capable of editing both XML and C# code&lt;br /&gt;
|-&lt;br /&gt;
| [http://xmlnotepad.codeplex.com/releases/ XML Notepad] || Windows || XML-oriented editor with a lot of features you will most likely never use in Rimworld modding&lt;br /&gt;
|-&lt;br /&gt;
| [http://www.geany.org/ Geany] || Linux/Windows/Mac || Extremely lightweight text editor with syntax highlighting and some other basic features oriented towards XML and code editing.&lt;br /&gt;
|}&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Advanced Editors===&lt;br /&gt;
&lt;br /&gt;
There's many editors out there specifically made for XML code. Because Rimworld uses XML in a very simple way, advanced code editors are rarely needed. In case you're ever in need of one, however, the following ones might help:&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Software !! OS !! Description&lt;br /&gt;
|-&lt;br /&gt;
| [http://sourceforge.net/projects/xpontus/files/ XPontus] || Windows || Has a tree view and is capable of checking XML for errors, fixing tabs and creating schema's detailing every tag's data types&lt;br /&gt;
|-&lt;br /&gt;
| [http://xmlgrid.net/ XMLGrid] || - || Capable of validating XML and turning it into Excel Spreadsheets, XSD Charts and an online table detailing each tag of a certain type and its contents&lt;br /&gt;
|-&lt;br /&gt;
| [http://codebeautify.org/xmlviewer Codebeautify's xmlviewer] || - || Can display as a tree view, automatically format/indent your code and can validate and show errors too. Also have a function share code (like [http://codebeautify.org/xmlviewer/b39586 that])&lt;br /&gt;
|}&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=IDE's=&lt;br /&gt;
&lt;br /&gt;
C# code is best edited in an IDE (Integrated Development Environment) to make the process of editing code, managing a solution's content and compiling its projects both easier and faster. Any IDE for C# will probably work just fine, so here's a list of suggested editors:&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Software !! OS !! Description&lt;br /&gt;
|-&lt;br /&gt;
| [http://www.visualstudio.com/ Visual Studio] || Windows || Very extensive IDE with paid, trial and free versions. Any of these versions will probably work, so you might as well take [https://www.visualstudio.com/products/visual-studio-community-vs Visual Studio Community 2015] which is free for individuals and small teams&lt;br /&gt;
|-&lt;br /&gt;
| [http://www.icsharpcode.net/OpenSource/SD/Download/ SharpDevelop] || Windows || Free IDE specifically made for C#&lt;br /&gt;
|-&lt;br /&gt;
| [http://www.monodevelop.com/download/ MonoDevelop] || Linux/Windows/Mac || Free, cross-platform IDE with customizable user interface. Has support for C# as well as some other languages you won't need for Rimworld&lt;br /&gt;
|-&lt;br /&gt;
| [http://www.xamarin.com/platform Xamarin] || Mac || It's free but you need to register to download it. Probably your best option on a mac.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Whichever IDE you choose, make sure it's capable of compiling for .NET Framework 3.5. If you for whatever reason don't have this framework installed, you can download it [https://www.microsoft.com/en-us/download/details.aspx?id=21 here].&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Additional C# Software=&lt;br /&gt;
&lt;br /&gt;
Besides your IDE it's strongly recommended to install the following software for decompiling:&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Software !! OS !! Description&lt;br /&gt;
|-&lt;br /&gt;
| [https://github.com/0xd4d/dnSpy] || Windows || Software which is capable of [[Modding Tutorials/Decompiling source code|decompiling source code]], which is very useful in Rimworld modding (some authors have had better luck with dnSpy than ILSpy?)&lt;br /&gt;
|-&lt;br /&gt;
| [http://ilspy.net/ ILSpy] || Windows || Software which is capable of [[Modding Tutorials/Decompiling source code|decompiling source code]], which is very useful in Rimworld modding&lt;br /&gt;
|-&lt;br /&gt;
| [http://www.monodevelop.com/download/ MonoDevelop] || Linux/Windows/Mac || The Linux version of the software has an integrated decompiler for .DLLs&lt;br /&gt;
|}&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Graphics Software=&lt;br /&gt;
&lt;br /&gt;
For making textures you will need graphics software. Any image editing program should work, and if you have an alternative to the following links that's probably okay:&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Software !! OS !! Description&lt;br /&gt;
|-&lt;br /&gt;
| [http://www.photofiltre-studio.com/download-en.htm Photofiltre Studio] || Windows || Functional software with very little user interface clutter for its applications. Doesn't support pen tablet, and has a 100% free (non-trial) version called [http://photofiltre.free.fr/download_en.htm Photofiltre]&lt;br /&gt;
|-&lt;br /&gt;
| [http://inkscape.org/en/download/ Inkscape] || Linux/Windows/Mac || Free vector graphic program with a steeper learning curve due to the vector based image editing. Vector graphics can look better than bitmap graphics in Rimworld&lt;br /&gt;
|-&lt;br /&gt;
| [http://www.photoshop.com/products Photoshop] || Windows/Mac || Paid software with a trial version. Rimworld's original graphics are made in Photoshop (they're .PSD files)&lt;br /&gt;
|-&lt;br /&gt;
| [http://www.gimp.org/ Gimp] || Linux/Windows/Mac || A free, open-source alternative to Photoshop that's been around since 1998. Gimp has a large user community, with great list of [http://www.gimp.org/tutorials/ tutorials] on the official sites&lt;br /&gt;
|-&lt;br /&gt;
| [https://krita.org/en/homepage/ Krita] || Linux/Windows/Mac || A free digital painting software. Better suited than GIMP for painting and should feel like home pretty quick for Photoshop users.&lt;br /&gt;
|}&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Audio Software=&lt;br /&gt;
&lt;br /&gt;
Recording your own audio for mods might be too much to ask, but editing audio is always possible. This can be done with the following software or your own alternative:&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Software !! OS !! Description&lt;br /&gt;
|-&lt;br /&gt;
| [http://sourceforge.net/projects/audacity/ Audacity] || Linux/Windows/Mac || Audio editing software with many tutorials online, lots of useful functionality and a relatively readable interface&lt;br /&gt;
|}&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Next up=&lt;br /&gt;
&lt;br /&gt;
# [[Modding Tutorials/XML file structure|XML File Structure]] starts you off with the XML side of modding.&lt;br /&gt;
# [[Modding_Tutorials/Setting up a solution|Setting up]] starts you off with the C# side of modding. Knowledge of the XML part can and will be very useful.&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Modding tutorials]]&lt;/div&gt;</summary>
		<author><name>Lilwhitemouse</name></author>
	</entry>
	<entry>
		<id>https://rimworldwiki.com/index.php?title=Bed&amp;diff=61437</id>
		<title>Bed</title>
		<link rel="alternate" type="text/html" href="https://rimworldwiki.com/index.php?title=Bed&amp;diff=61437"/>
		<updated>2018-11-30T04:22:07Z</updated>

		<summary type="html">&lt;p&gt;Lilwhitemouse: Colonists can sleep in dumb places&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{infobox main|furniture|&lt;br /&gt;
|name = Bed&lt;br /&gt;
|image = Bed.png|Bed&lt;br /&gt;
|description =  A cozy mattress and sheets on a frame for resting.&lt;br /&gt;
|type  = Furniture&lt;br /&gt;
|placeable = Yes&lt;br /&gt;
|size = 1|2&lt;br /&gt;
|hp = 140&lt;br /&gt;
|beauty = 1&lt;br /&gt;
|material amount  = 45&lt;br /&gt;
|flammability = 1&lt;br /&gt;
|work to build = 800&lt;br /&gt;
|comfort = 0.75&lt;br /&gt;
|rest effectiveness = 1&lt;br /&gt;
|immunity gain speed factor = 1.07&lt;br /&gt;
|surgery success chance factor = 1&lt;br /&gt;
|mass base = 50&lt;br /&gt;
|cover = 0.4&lt;br /&gt;
}}&lt;br /&gt;
{{#set:&lt;br /&gt;
 facility = dresser&lt;br /&gt;
|facility = end table&lt;br /&gt;
}}&lt;br /&gt;
{{Info|A bed is used by [[colonists]] for sleeping to recover their [[rest]]. It can be made out of any material but its [[Rest Effectiveness]] is 100% only when made of [[wood]] or metal. [[Quality]] can further influence the rest effectiveness and [[comfort]].&lt;br /&gt;
&lt;br /&gt;
While resting in a bed, colonists heal by an additional 3 HP per day.&lt;br /&gt;
&lt;br /&gt;
Beds can be walked over, although at a slower rate.&lt;br /&gt;
&lt;br /&gt;
A newly constructed bed is shown as 'unowned'. A colonist without an assigned bed will claim an unowned bed which will then show their name. A bed's ownership can be set or overridden by clicking the 'Set owner' button. Manually setting bed ownership is often unnecessary except when the player finds it desirable to control where a colonist sleeps, such as near their work area. If there are beds in terrible sleeping places (outside, cold, whatever), colonists have a strong ability to choose them.  Also, sometimes married colonists will not choose double beds on their own, and will end up sleeping alone.&lt;br /&gt;
&lt;br /&gt;
There is a version for two colonists called the [[double bed]], and a deluxe version known as the [[royal bed]].}}&lt;br /&gt;
&lt;br /&gt;
===Prisoner bed===&lt;br /&gt;
A bed may be assigned for [[prisoner]] use by clicking 'Set for prisoners'. The bed must be in an enclosed room. Once a bed is set for prisoners the entire room is set as a prisoner room and all other beds within are changed to prisoner beds. A prisoner bed is clearly indicated by its gold color. The game will not allow a non-colonist to be captured or arrested without an available prisoner bed. A bed may be switched back for colonist use by clicking 'Set for colonists' and all beds in the same room will also revert to the green colonist bed. However, if any prisoner bed has an owner the player will be required to confirm the action and the prisoners will be unable to use the beds.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Medical bed===&lt;br /&gt;
A bed may be designated as a medical bed by clicking 'Set as medical'. This is not to be confused with a [[hospital bed]], which is unlocked with [[research]]. Colonists can be assigned to this bed to Rest Until Healed, however it cannot be assigned an owner and will lose any ownership it had.  A medical colonist bed is indicated by its blue color. A medical prisoner bed is indicated by its dark brown color. Newly captured prisoners are usually [[injury|injured]], therefore their captors will prioritise medical prisoner beds over regular prisoner beds. Clicking 'Set as non medical' reverts a medical bed to its original type.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Stats ===&lt;br /&gt;
&lt;br /&gt;
Beds can be made out of the following materials:&lt;br /&gt;
&lt;br /&gt;
[[Rest Effectiveness Base::1| ]] [[Flammability Base::1| ]] [[Comfort Base::0.75| ]] [[Immunity Gain Speed Factor::1.07| ]] [[Work To Make Base::800| ]]&lt;br /&gt;
&lt;br /&gt;
{| {{STDT| sortable c_08 text-center}}&lt;br /&gt;
! Material&lt;br /&gt;
!data-sort-type=&amp;quot;number&amp;quot;| [[Beauty]]&lt;br /&gt;
!data-sort-type=&amp;quot;number&amp;quot;| Flammability&lt;br /&gt;
!data-sort-type=&amp;quot;number&amp;quot;| Market value&lt;br /&gt;
!data-sort-type=&amp;quot;number&amp;quot;| Max health&lt;br /&gt;
!data-sort-type=&amp;quot;number&amp;quot;| Work to make&lt;br /&gt;
!data-sort-type=&amp;quot;number&amp;quot;| Rest effectiveness&lt;br /&gt;
|-&lt;br /&gt;
|Silver || 42 || 20% || 505.00 || 105 || 12 || 100%&lt;br /&gt;
|-&lt;br /&gt;
|Gold || 155 || 20% || 7505.00 || 90 || 13 || 100%&lt;br /&gt;
|-&lt;br /&gt;
|Steel || 8 || 20% || 55.22 || 150 || 10 || 100%&lt;br /&gt;
|-&lt;br /&gt;
|Plasteel || 10 || 10% || 685.00 || 420 || 19 || 100%&lt;br /&gt;
|-&lt;br /&gt;
|Wood || 12 || 100% || 38.65 || 75 || 7 || 100%&lt;br /&gt;
|-&lt;br /&gt;
|Uranium || 3 || 0% || 2510.00 || 375 || 18 || 100%&lt;br /&gt;
|-&lt;br /&gt;
|Sandstone || 11 || 0% || 76.66 || 360 || 54 || 90%&lt;br /&gt;
|-&lt;br /&gt;
|Granite || 12 || 0% || 81.66 || 405 || 54 || 90%&lt;br /&gt;
|-&lt;br /&gt;
|Limestone || 12 || 0% || 76.66 || 380 || 54 || 90%&lt;br /&gt;
|-&lt;br /&gt;
|Slate || 11 || 0% || 76.66 || 345 || 54 || 90%&lt;br /&gt;
|-&lt;br /&gt;
|Marble || 14 || 0% || 76.66 || 330 || 54 || 90%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Rest effectiveness varies by quality and material. Stone materials only offer 90% of the rest effectiveness of a bed made from non-stone materials at the same quality level.&lt;br /&gt;
&lt;br /&gt;
{| {{STDT| sortable c_08 text-center}}&lt;br /&gt;
! Material&lt;br /&gt;
!data-sort-type=&amp;quot;number&amp;quot;| Awful&lt;br /&gt;
!data-sort-type=&amp;quot;number&amp;quot;| Poor&lt;br /&gt;
!data-sort-type=&amp;quot;number&amp;quot;| Normal&lt;br /&gt;
!data-sort-type=&amp;quot;number&amp;quot;| Good&lt;br /&gt;
!data-sort-type=&amp;quot;number&amp;quot;| Excellent&lt;br /&gt;
!data-sort-type=&amp;quot;number&amp;quot;| Masterwork&lt;br /&gt;
!data-sort-type=&amp;quot;number&amp;quot;| Legendary&lt;br /&gt;
|-&lt;br /&gt;
|Non-stone materials|| 86% || 92% || 100% || 108% || 114% || 125% || 160%&lt;br /&gt;
|-&lt;br /&gt;
|Stone materials|| 77% ||  83% || 90% || 97% || 103% || 113% || 144%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{see also|Hospital bed}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;noinclude&amp;gt;&lt;br /&gt;
{{nav|furniture|wide}}&lt;br /&gt;
&amp;lt;/noinclude&amp;gt;&lt;br /&gt;
[[Category:Furniture]]&lt;br /&gt;
[[Category:Environment]]&lt;/div&gt;</summary>
		<author><name>Lilwhitemouse</name></author>
	</entry>
	<entry>
		<id>https://rimworldwiki.com/index.php?title=Modding_Tutorials/Custom_Comp_Classes&amp;diff=61435</id>
		<title>Modding Tutorials/Custom Comp Classes</title>
		<link rel="alternate" type="text/html" href="https://rimworldwiki.com/index.php?title=Modding_Tutorials/Custom_Comp_Classes&amp;diff=61435"/>
		<updated>2018-11-29T19:46:17Z</updated>

		<summary type="html">&lt;p&gt;Lilwhitemouse: /* C# */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Creating a custom comp class is a convenient way to add new functionality to RimWorld.&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
* You need to have [[Modding Tutorials/Setting up a solution|set up your editor and environment]]&lt;br /&gt;
* You need to know [[Modding Tutorials/Writing custom code|how to write custom code]]&lt;br /&gt;
* You should probably understand Defs at least somewhat.&lt;br /&gt;
&lt;br /&gt;
== def (xml) and C# structure ==&lt;br /&gt;
&lt;br /&gt;
=== Setup, Defs, and Classes ===&lt;br /&gt;
You will have some custom def and it will have something like this:&lt;br /&gt;
==== Defs (xml) ====&lt;br /&gt;
  &amp;lt;ThingDef ...&amp;gt;&lt;br /&gt;
    ...&lt;br /&gt;
    ...&lt;br /&gt;
    &amp;lt;comps&amp;gt;&lt;br /&gt;
      &amp;lt;&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt; Class=&amp;quot;MyNamespace.MyCompProperties&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;myCustomCompProperty&amp;gt;some value&amp;lt;/myCustomCompProperty&amp;gt;&lt;br /&gt;
        &amp;lt;mySecondCompProp&amp;gt;4&amp;lt;/mySecondCompProp&amp;gt;&lt;br /&gt;
      &amp;lt;/&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt;&amp;gt;&lt;br /&gt;
      &amp;lt;&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt;&amp;gt;&lt;br /&gt;
        ''&amp;lt;&amp;lt;nowiki&amp;gt;!--&amp;lt;/nowiki&amp;gt; this is kind of like &amp;lt;tag&amp;gt;MN.MyCustomTag&amp;lt;/tag&amp;gt;:--&amp;gt;''&lt;br /&gt;
        &amp;lt;compClass&amp;gt;MyNamespace.MyCustomThingComp&amp;lt;/compClass&amp;gt;&lt;br /&gt;
      &amp;lt;/&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt;&amp;gt;&lt;br /&gt;
    &amp;lt;/comps&amp;gt;&lt;br /&gt;
  &amp;lt;/ThingDef&amp;gt;&lt;br /&gt;
==== C# ====&lt;br /&gt;
  namespace MyNamespace ''// For example, LWM.ModName - by using your ''&lt;br /&gt;
                        ''//   handle/name/etc, you almost certainly guarantee uniqueness''&lt;br /&gt;
  {&lt;br /&gt;
  '''//////////// &amp;lt;&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki Class=&amp;quot;MyNamespace.MyCompProperties&amp;quot;&amp;gt; ////////////'''&lt;br /&gt;
  public class MyCompProperties : CompProperties ''// Name this as you wish, of course''&lt;br /&gt;
  {&lt;br /&gt;
    public Properties() {&lt;br /&gt;
      this.compClass = typeof(MyNamespace.MyLinkedCompThing); ''// rename as appropriate''&lt;br /&gt;
    }&lt;br /&gt;
    public string myCustomCompProperty; ''// Name matches def, of course''&lt;br /&gt;
    public int mySecondCompProp = 1; ''// Can set default values''&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  ''// this ThingComp is used to actually access the comp property defined above''&lt;br /&gt;
  '''''// this is not &amp;quot;&amp;lt;compClass&amp;gt;MyNamespace.MyCustomThingComp&amp;lt;/compClass&amp;gt;&amp;quot;'''''&lt;br /&gt;
  public class MyLinkedCompThing : ThingComp&lt;br /&gt;
  {&lt;br /&gt;
    public string myCustomCompProperty&lt;br /&gt;
    {&lt;br /&gt;
      get&lt;br /&gt;
      {&lt;br /&gt;
        return ((MyCompProperties)this.props).myCustomCompProperty;&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    public int mySecondCompProperty ''// Have to get all the names right''&lt;br /&gt;
    { get  { return ((MyCompProperties)this.props).mySecondCompProperty; } } ''//etc''&lt;br /&gt;
  }&lt;br /&gt;
  '''//////////// &amp;lt;compClass&amp;gt;MyNamespace.MyCustomThingComp&amp;lt;/compClass&amp;gt; ////////////'''&lt;br /&gt;
  public class MyCustomThingComp : ThingComp&lt;br /&gt;
  {&lt;br /&gt;
    public override void CompTick()&lt;br /&gt;
    {&lt;br /&gt;
      // do stuff&lt;br /&gt;
    }&lt;br /&gt;
    public override void CompTickRare() //etc&lt;br /&gt;
    public override ... // Check out Verse/ThingComp.cs for more ideas&lt;br /&gt;
  }&lt;br /&gt;
  } // end MyNamespace&lt;br /&gt;
&lt;br /&gt;
=== Accessing your Comps ===&lt;br /&gt;
Just setting up your custom comps doesn't do you a lot of good if you can't access them!&lt;br /&gt;
&lt;br /&gt;
'''To do'''&lt;br /&gt;
&lt;br /&gt;
=== Cautions, traps, etc ===&lt;br /&gt;
If you have the same comp in an abstract def and attempt to redefine it in a child def, it will get counted twice.  It's possible to get around this in the code, if you want to have default comps:&lt;br /&gt;
&lt;br /&gt;
  public class MyLinkedCompThing : ThingComp&lt;br /&gt;
  {&lt;br /&gt;
    public string myCustomCompProperty //etc&lt;br /&gt;
    &lt;br /&gt;
    public override void Initialize (CompProperties props) {&lt;br /&gt;
      base.Initialize(props);&lt;br /&gt;
      // Remove duplicate entries and ensure the last entry is the only one left&lt;br /&gt;
      //   This allows a default abstract def with the comp&lt;br /&gt;
      //   and child def to change the comp value:&lt;br /&gt;
      CompDeepStorage[] list = this.parent.GetComps&amp;lt;CompDeepStorage&amp;gt;().ToArray();&lt;br /&gt;
      // Remove everything but the last entry; harmless if only one entry:&lt;br /&gt;
      for (var i = 0; i &amp;lt; list.Length-1; i++)&lt;br /&gt;
      {&lt;br /&gt;
        this.parent.AllComps.Remove(list[i]);&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
  &lt;br /&gt;
  ///etc&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
[[Category:Modding tutorials]][[Category:Modding]][[Category:Defs]]&lt;/div&gt;</summary>
		<author><name>Lilwhitemouse</name></author>
	</entry>
	<entry>
		<id>https://rimworldwiki.com/index.php?title=Modding_Tutorials/Custom_Comp_Classes&amp;diff=61434</id>
		<title>Modding Tutorials/Custom Comp Classes</title>
		<link rel="alternate" type="text/html" href="https://rimworldwiki.com/index.php?title=Modding_Tutorials/Custom_Comp_Classes&amp;diff=61434"/>
		<updated>2018-11-29T19:37:43Z</updated>

		<summary type="html">&lt;p&gt;Lilwhitemouse: duplicate comps can cause problems :p&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Creating a custom comp class is a convenient way to add new functionality to RimWorld.&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
* You need to have [[Modding Tutorials/Setting up a solution|set up your editor and environment]]&lt;br /&gt;
* You need to know [[Modding Tutorials/Writing custom code|how to write custom code]]&lt;br /&gt;
* You should probably understand Defs at least somewhat.&lt;br /&gt;
&lt;br /&gt;
== def (xml) and C# structure ==&lt;br /&gt;
&lt;br /&gt;
=== Setup, Defs, and Classes ===&lt;br /&gt;
You will have some custom def and it will have something like this:&lt;br /&gt;
==== Defs (xml) ====&lt;br /&gt;
  &amp;lt;ThingDef ...&amp;gt;&lt;br /&gt;
    ...&lt;br /&gt;
    ...&lt;br /&gt;
    &amp;lt;comps&amp;gt;&lt;br /&gt;
      &amp;lt;&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt; Class=&amp;quot;MyNamespace.MyCompProperties&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;myCustomCompProperty&amp;gt;some value&amp;lt;/myCustomCompProperty&amp;gt;&lt;br /&gt;
        &amp;lt;mySecondCompProp&amp;gt;4&amp;lt;/mySecondCompProp&amp;gt;&lt;br /&gt;
      &amp;lt;/&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt;&amp;gt;&lt;br /&gt;
      &amp;lt;&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt;&amp;gt;&lt;br /&gt;
        ''&amp;lt;&amp;lt;nowiki&amp;gt;!--&amp;lt;/nowiki&amp;gt; this is kind of like &amp;lt;tag&amp;gt;MN.MyCustomTag&amp;lt;/tag&amp;gt;:--&amp;gt;''&lt;br /&gt;
        &amp;lt;compClass&amp;gt;MyNamespace.MyCustomThingComp&amp;lt;/compClass&amp;gt;&lt;br /&gt;
      &amp;lt;/&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt;&amp;gt;&lt;br /&gt;
    &amp;lt;/comps&amp;gt;&lt;br /&gt;
  &amp;lt;/ThingDef&amp;gt;&lt;br /&gt;
==== C# ====&lt;br /&gt;
  namespace MyNamespace ''// For example, LWM.ModName - by using your &lt;br /&gt;
                          //   handle/name/etc, you almost certainly guarantee uniqueness''&lt;br /&gt;
  {&lt;br /&gt;
  '''//////////// &amp;lt;&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki Class=&amp;quot;MyNamespace.MyCompProperties&amp;quot;&amp;gt; ////////////'''&lt;br /&gt;
  public class MyCompProperties : CompProperties ''// Name this as you wish, of course''&lt;br /&gt;
  {&lt;br /&gt;
    public Properties() {&lt;br /&gt;
      this.compClass = typeof(MyNamespace.MyLinkedCompThing); ''// rename as appropriate''&lt;br /&gt;
    }&lt;br /&gt;
    public string myCustomCompProperty; ''// Name matches def, of course''&lt;br /&gt;
    public int mySecondCompProp = 1; ''// Can set default values''&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  ''// this ThingComp is used to actually access the comp property defined above''&lt;br /&gt;
  '''''// this is not &amp;quot;&amp;lt;compClass&amp;gt;MyNamespace.MyCustomThingComp&amp;lt;/compClass&amp;gt;&amp;quot;'''''&lt;br /&gt;
  public class MyLinkedCompThing : ThingComp&lt;br /&gt;
  {&lt;br /&gt;
    public string myCustomCompProperty&lt;br /&gt;
    {&lt;br /&gt;
      get&lt;br /&gt;
      {&lt;br /&gt;
        return ((MyCompProperties)this.props).myCustomCompProperty;&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    public int mySecondCompProperty ''// Have to get all the names right''&lt;br /&gt;
    { get  { return ((MyCompProperties)this.props).mySecondCompProperty; } } ''//etc''&lt;br /&gt;
  }&lt;br /&gt;
  '''//////////// &amp;lt;compClass&amp;gt;MyNamespace.MyCustomThingComp&amp;lt;/compClass&amp;gt; ////////////'''&lt;br /&gt;
  public class MyCustomThingComp : ThingComp&lt;br /&gt;
  {&lt;br /&gt;
    public override void CompTick()&lt;br /&gt;
    {&lt;br /&gt;
      // do stuff&lt;br /&gt;
    }&lt;br /&gt;
    public override void CompTickRare() //etc&lt;br /&gt;
    public override ... // Check out Verse/ThingComp.cs for more ideas&lt;br /&gt;
  }&lt;br /&gt;
  } // end MyNamespace&lt;br /&gt;
&lt;br /&gt;
=== Accessing your Comps ===&lt;br /&gt;
Just setting up your custom comps doesn't do you a lot of good if you can't access them!&lt;br /&gt;
&lt;br /&gt;
'''To do'''&lt;br /&gt;
&lt;br /&gt;
=== Cautions, traps, etc ===&lt;br /&gt;
If you have the same comp in an abstract def and attempt to redefine it in a child def, it will get counted twice.  It's possible to get around this in the code, if you want to have default comps:&lt;br /&gt;
&lt;br /&gt;
  public class MyLinkedCompThing : ThingComp&lt;br /&gt;
  {&lt;br /&gt;
    public string myCustomCompProperty //etc&lt;br /&gt;
    &lt;br /&gt;
    public override void Initialize (CompProperties props) {&lt;br /&gt;
      base.Initialize(props);&lt;br /&gt;
      // Remove duplicate entries and ensure the last entry is the only one left&lt;br /&gt;
      //   This allows a default abstract def with the comp&lt;br /&gt;
      //   and child def to change the comp value:&lt;br /&gt;
      CompDeepStorage[] list = this.parent.GetComps&amp;lt;CompDeepStorage&amp;gt;().ToArray();&lt;br /&gt;
      // Remove everything but the last entry; harmless if only one entry:&lt;br /&gt;
      for (var i = 0; i &amp;lt; list.Length-1; i++)&lt;br /&gt;
      {&lt;br /&gt;
        this.parent.AllComps.Remove(list[i]);&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
  &lt;br /&gt;
  ///etc&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
[[Category:Modding tutorials]][[Category:Modding]][[Category:Defs]]&lt;/div&gt;</summary>
		<author><name>Lilwhitemouse</name></author>
	</entry>
	<entry>
		<id>https://rimworldwiki.com/index.php?title=Modding_Tutorials/Custom_Comp_Classes&amp;diff=61433</id>
		<title>Modding Tutorials/Custom Comp Classes</title>
		<link rel="alternate" type="text/html" href="https://rimworldwiki.com/index.php?title=Modding_Tutorials/Custom_Comp_Classes&amp;diff=61433"/>
		<updated>2018-11-29T17:06:29Z</updated>

		<summary type="html">&lt;p&gt;Lilwhitemouse: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Creating a custom comp class is a convenient way to add new functionality to RimWorld.&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
* You need to have [[Modding Tutorials/Setting up a solution|set up your editor and environment]]&lt;br /&gt;
* You need to know [[Modding Tutorials/Writing custom code|how to write custom code]]&lt;br /&gt;
* You should probably understand Defs at least somewhat.&lt;br /&gt;
&lt;br /&gt;
== def (xml) and C# structure ==&lt;br /&gt;
&lt;br /&gt;
=== Setup, Defs, and Classes ===&lt;br /&gt;
You will have some custom def and it will have something like this:&lt;br /&gt;
==== Defs (xml) ====&lt;br /&gt;
  &amp;lt;ThingDef ...&amp;gt;&lt;br /&gt;
    ...&lt;br /&gt;
    ...&lt;br /&gt;
    &amp;lt;comps&amp;gt;&lt;br /&gt;
      &amp;lt;&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt; Class=&amp;quot;MyNamespace.MyCompProperties&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;myCustomCompProperty&amp;gt;some value&amp;lt;/myCustomCompProperty&amp;gt;&lt;br /&gt;
        &amp;lt;mySecondCompProp&amp;gt;4&amp;lt;/mySecondCompProp&amp;gt;&lt;br /&gt;
      &amp;lt;/&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt;&amp;gt;&lt;br /&gt;
      &amp;lt;&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt;&amp;gt;&lt;br /&gt;
        ''&amp;lt;&amp;lt;nowiki&amp;gt;!--&amp;lt;/nowiki&amp;gt; this is kind of like &amp;lt;tag&amp;gt;MN.MyCustomTag&amp;lt;/tag&amp;gt;:--&amp;gt;''&lt;br /&gt;
        &amp;lt;compClass&amp;gt;MyNamespace.MyCustomThingComp&amp;lt;/compClass&amp;gt;&lt;br /&gt;
      &amp;lt;/&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt;&amp;gt;&lt;br /&gt;
    &amp;lt;/comps&amp;gt;&lt;br /&gt;
  &amp;lt;/ThingDef&amp;gt;&lt;br /&gt;
==== C# ====&lt;br /&gt;
  namespace MyNamespace ''// For example, LWM.ModName - by using your &lt;br /&gt;
                          //   handle/name/etc, you almost certainly guarantee uniqueness''&lt;br /&gt;
  {&lt;br /&gt;
  '''//////////// &amp;lt;&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki Class=&amp;quot;MyNamespace.MyCompProperties&amp;quot;&amp;gt; ////////////'''&lt;br /&gt;
  public class MyCompProperties : CompProperties ''// Name this as you wish, of course''&lt;br /&gt;
  {&lt;br /&gt;
    public Properties() {&lt;br /&gt;
      this.compClass = typeof(MyNamespace.MyLinkedCompThing); ''// rename as appropriate''&lt;br /&gt;
    }&lt;br /&gt;
    public string myCustomCompProperty; ''// Name matches def, of course''&lt;br /&gt;
    public int mySecondCompProp = 1; ''// Can set default values''&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  ''// this ThingComp is used to actually access the comp property defined above''&lt;br /&gt;
  '''''// this is not &amp;quot;&amp;lt;compClass&amp;gt;MyNamespace.MyCustomThingComp&amp;lt;/compClass&amp;gt;&amp;quot;'''''&lt;br /&gt;
  public class MyLinkedCompThing : ThingComp&lt;br /&gt;
  {&lt;br /&gt;
    public string myCustomCompProperty&lt;br /&gt;
    {&lt;br /&gt;
      get&lt;br /&gt;
      {&lt;br /&gt;
        return ((MyCompProperties)this.props).myCustomCompProperty;&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    public int mySecondCompProperty ''// Have to get all the names right''&lt;br /&gt;
    { get  { return ((MyCompProperties)this.props).mySecondCompProperty; } } ''//etc''&lt;br /&gt;
  }&lt;br /&gt;
  '''//////////// &amp;lt;compClass&amp;gt;MyNamespace.MyCustomThingComp&amp;lt;/compClass&amp;gt; ////////////'''&lt;br /&gt;
  public class MyCustomThingComp : ThingComp&lt;br /&gt;
  {&lt;br /&gt;
    public override void CompTick()&lt;br /&gt;
    {&lt;br /&gt;
      // do stuff&lt;br /&gt;
    }&lt;br /&gt;
    public override void CompTickRare() //etc&lt;br /&gt;
    public override ... // Check out Verse/ThingComp.cs for more ideas&lt;br /&gt;
  }&lt;br /&gt;
  } // end MyNamespace&lt;br /&gt;
&lt;br /&gt;
=== Accessing your Comps ===&lt;br /&gt;
Just setting up your custom comps doesn't do you a lot of good if you can't access them!&lt;br /&gt;
&lt;br /&gt;
'''To do'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Modding tutorials]][[Category:Modding]][[Category:Defs]]&lt;/div&gt;</summary>
		<author><name>Lilwhitemouse</name></author>
	</entry>
	<entry>
		<id>https://rimworldwiki.com/index.php?title=Modding_Tutorials/Custom_Comp_Classes&amp;diff=61432</id>
		<title>Modding Tutorials/Custom Comp Classes</title>
		<link rel="alternate" type="text/html" href="https://rimworldwiki.com/index.php?title=Modding_Tutorials/Custom_Comp_Classes&amp;diff=61432"/>
		<updated>2018-11-29T17:01:34Z</updated>

		<summary type="html">&lt;p&gt;Lilwhitemouse: look at thingcomp&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Creating a custom comp class is a convenient way to add new functionality to RimWorld.&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
* You need to have [[Modding Tutorials/Setting up a solution|set up your editor and environment]]&lt;br /&gt;
* You need to know [[Modding Tutorials/Writing custom code|how to write custom code]]&lt;br /&gt;
* You should probably understand Defs at least somewhat.&lt;br /&gt;
&lt;br /&gt;
== def (xml) and C# structure ==&lt;br /&gt;
&lt;br /&gt;
=== Basic outline ===&lt;br /&gt;
You will have some custom def and it will have something like this:&lt;br /&gt;
==== Defs (xml) ====&lt;br /&gt;
  &amp;lt;ThingDef ...&amp;gt;&lt;br /&gt;
    ...&lt;br /&gt;
    ...&lt;br /&gt;
    &amp;lt;comps&amp;gt;&lt;br /&gt;
      &amp;lt;&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt; Class=&amp;quot;MyNamespace.MyCompProperties&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;myCustomCompProperty&amp;gt;some value&amp;lt;/myCustomCompProperty&amp;gt;&lt;br /&gt;
        &amp;lt;mySecondCompProp&amp;gt;4&amp;lt;/mySecondCompProp&amp;gt;&lt;br /&gt;
      &amp;lt;/&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt;&amp;gt;&lt;br /&gt;
      &amp;lt;&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt;&amp;gt;&lt;br /&gt;
        ''&amp;lt;&amp;lt;nowiki&amp;gt;!--&amp;lt;/nowiki&amp;gt; this is kind of like &amp;lt;tag&amp;gt;MN.MyCustomTag&amp;lt;/tag&amp;gt;:--&amp;gt;''&lt;br /&gt;
        &amp;lt;compClass&amp;gt;MyNamespace.MyCustomThingComp&amp;lt;/compClass&amp;gt;&lt;br /&gt;
      &amp;lt;/&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt;&amp;gt;&lt;br /&gt;
    &amp;lt;/comps&amp;gt;&lt;br /&gt;
  &amp;lt;/ThingDef&amp;gt;&lt;br /&gt;
==== C# ====&lt;br /&gt;
  namespace MyNamespace ''// For example, LWM.ModName - by using your &lt;br /&gt;
                          //   handle/name/etc, you almost certainly guarantee uniqueness''&lt;br /&gt;
  {&lt;br /&gt;
  '''//////////// &amp;lt;&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki Class=&amp;quot;MyNamespace.MyCompProperties&amp;quot;&amp;gt; ////////////'''&lt;br /&gt;
  public class MyCompProperties : CompProperties ''// Name this as you wish, of course''&lt;br /&gt;
  {&lt;br /&gt;
    public Properties() {&lt;br /&gt;
      this.compClass = typeof(MyNamespace.MyLinkedCompThing); ''// rename as appropriate''&lt;br /&gt;
    }&lt;br /&gt;
    public string myCustomCompProperty; ''// Name matches def, of course''&lt;br /&gt;
    public int mySecondCompProp = 1; ''// Can set default values''&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  ''// this ThingComp is used to actually access the comp property defined above''&lt;br /&gt;
  '''''// this is not &amp;quot;&amp;lt;compClass&amp;gt;MyNamespace.MyCustomThingComp&amp;lt;/compClass&amp;gt;&amp;quot;'''''&lt;br /&gt;
  public class MyLinkedCompThing : ThingComp&lt;br /&gt;
  {&lt;br /&gt;
    public string myCustomCompProperty&lt;br /&gt;
    {&lt;br /&gt;
      get&lt;br /&gt;
      {&lt;br /&gt;
        return ((MyCompProperties)this.props).myCustomCompProperty;&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    public int mySecondCompProperty ''// Have to get all the names right''&lt;br /&gt;
    { get  { return ((MyCompProperties)this.props).mySecondCompProperty; } } ''//etc''&lt;br /&gt;
  }&lt;br /&gt;
  '''//////////// &amp;lt;compClass&amp;gt;MyNamespace.MyCustomThingComp&amp;lt;/compClass&amp;gt; ////////////'''&lt;br /&gt;
  public class MyCustomThingComp : ThingComp&lt;br /&gt;
  {&lt;br /&gt;
    public override void CompTick()&lt;br /&gt;
    {&lt;br /&gt;
      // do stuff&lt;br /&gt;
    }&lt;br /&gt;
    public override void CompTickRare() //etc&lt;br /&gt;
    public override ... // Check out Verse/ThingComp.cs for more ideas&lt;br /&gt;
  }&lt;br /&gt;
  } // end MyNamespace&lt;br /&gt;
[[Category:Modding tutorials]][[Category:Modding]][[Category:Defs]]&lt;/div&gt;</summary>
		<author><name>Lilwhitemouse</name></author>
	</entry>
	<entry>
		<id>https://rimworldwiki.com/index.php?title=Modding_Tutorials/Custom_Comp_Classes&amp;diff=61431</id>
		<title>Modding Tutorials/Custom Comp Classes</title>
		<link rel="alternate" type="text/html" href="https://rimworldwiki.com/index.php?title=Modding_Tutorials/Custom_Comp_Classes&amp;diff=61431"/>
		<updated>2018-11-29T16:57:38Z</updated>

		<summary type="html">&lt;p&gt;Lilwhitemouse: more C#&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Creating a custom comp class is a convenient way to add new functionality to RimWorld.&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
* You need to have [[Modding Tutorials/Setting up a solution|set up your editor and environment]]&lt;br /&gt;
* You need to know [[Modding Tutorials/Writing custom code|how to write custom code]]&lt;br /&gt;
* You should probably understand Defs at least somewhat.&lt;br /&gt;
&lt;br /&gt;
== def (xml) and C# structure ==&lt;br /&gt;
&lt;br /&gt;
=== Basic outline ===&lt;br /&gt;
You will have some custom def and it will have something like this:&lt;br /&gt;
==== Defs (xml) ====&lt;br /&gt;
  &amp;lt;ThingDef ...&amp;gt;&lt;br /&gt;
    ...&lt;br /&gt;
    ...&lt;br /&gt;
    &amp;lt;comps&amp;gt;&lt;br /&gt;
      &amp;lt;&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt; Class=&amp;quot;MyNamespace.MyCompProperties&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;myCustomCompProperty&amp;gt;some value&amp;lt;/myCustomCompProperty&amp;gt;&lt;br /&gt;
        &amp;lt;mySecondCompProp&amp;gt;4&amp;lt;/mySecondCompProp&amp;gt;&lt;br /&gt;
      &amp;lt;/&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt;&amp;gt;&lt;br /&gt;
      &amp;lt;&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt;&amp;gt;&lt;br /&gt;
        ''&amp;lt;&amp;lt;nowiki&amp;gt;!--&amp;lt;/nowiki&amp;gt; this is kind of like &amp;lt;tag&amp;gt;MN.MyCustomTag&amp;lt;/tag&amp;gt;:--&amp;gt;''&lt;br /&gt;
        &amp;lt;compClass&amp;gt;MyNamespace.MyCustomThingComp&amp;lt;/compClass&amp;gt;&lt;br /&gt;
      &amp;lt;/&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt;&amp;gt;&lt;br /&gt;
    &amp;lt;/comps&amp;gt;&lt;br /&gt;
  &amp;lt;/ThingDef&amp;gt;&lt;br /&gt;
==== C# ====&lt;br /&gt;
  namespace MyNamespace ''// For example, LWM.ModName - by using your &lt;br /&gt;
                          //   handle/name/etc, you almost certainly guarantee uniqueness''&lt;br /&gt;
  {&lt;br /&gt;
  '''//////////// &amp;lt;&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki Class=&amp;quot;MyNamespace.MyCompProperties&amp;quot;&amp;gt; ////////////'''&lt;br /&gt;
  public class MyCompProperties : CompProperties ''// Name this as you wish, of course''&lt;br /&gt;
  {&lt;br /&gt;
    public Properties() {&lt;br /&gt;
      this.compClass = typeof(MyNamespace.MyLinkedCompThing); ''// rename as appropriate''&lt;br /&gt;
    }&lt;br /&gt;
    public string myCustomCompProperty; ''// Name matches def, of course''&lt;br /&gt;
    public int mySecondCompProp = 1; ''// Can set default values''&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  ''// this ThingComp is used to actually access the comp property defined above''&lt;br /&gt;
  '''''// this is not &amp;quot;&amp;lt;compClass&amp;gt;MyNamespace.MyCustomThingComp&amp;lt;/compClass&amp;gt;&amp;quot;'''''&lt;br /&gt;
  public class MyLinkedCompThing : ThingComp&lt;br /&gt;
  {&lt;br /&gt;
    public string myCustomCompProperty&lt;br /&gt;
    {&lt;br /&gt;
      get&lt;br /&gt;
      {&lt;br /&gt;
        return ((MyCompProperties)this.props).myCustomCompProperty;&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    public int mySecondCompProperty ''// Have to get all the names right''&lt;br /&gt;
    { get  { return ((MyCompProperties)this.props).mySecondCompProperty; } } ''//etc''&lt;br /&gt;
  }&lt;br /&gt;
  '''//////////// &amp;lt;compClass&amp;gt;MyNamespace.MyCustomThingComp&amp;lt;/compClass&amp;gt; ////////////'''&lt;br /&gt;
  public class MyCustomThingComp : ThingComp&lt;br /&gt;
  {&lt;br /&gt;
    public override void CompTick()&lt;br /&gt;
    {&lt;br /&gt;
      // do stuff&lt;br /&gt;
    }&lt;br /&gt;
    public override void CompTickRare() //...&lt;br /&gt;
    public override ... // etc&lt;br /&gt;
  }&lt;br /&gt;
  } // end MyNamespace&lt;br /&gt;
[[Category:Modding tutorials]][[Category:Modding]][[Category:Defs]]&lt;/div&gt;</summary>
		<author><name>Lilwhitemouse</name></author>
	</entry>
	<entry>
		<id>https://rimworldwiki.com/index.php?title=Modding_Tutorials/Custom_Comp_Classes&amp;diff=61430</id>
		<title>Modding Tutorials/Custom Comp Classes</title>
		<link rel="alternate" type="text/html" href="https://rimworldwiki.com/index.php?title=Modding_Tutorials/Custom_Comp_Classes&amp;diff=61430"/>
		<updated>2018-11-29T16:45:40Z</updated>

		<summary type="html">&lt;p&gt;Lilwhitemouse: C#&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Creating a custom comp class is a convenient way to add new functionality to RimWorld.&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
* You need to have [[Modding Tutorials/Setting up a solution|set up your editor and environment]]&lt;br /&gt;
* You need to know [[Modding Tutorials/Writing custom code|how to write custom code]]&lt;br /&gt;
* You should probably understand Defs at least somewhat.&lt;br /&gt;
&lt;br /&gt;
== def (xml) and C# structure ==&lt;br /&gt;
&lt;br /&gt;
=== Basic outline ===&lt;br /&gt;
You will have some custom def and it will have something like this:&lt;br /&gt;
==== Defs (xml) ====&lt;br /&gt;
  &amp;lt;ThingDef ...&amp;gt;&lt;br /&gt;
    ...&lt;br /&gt;
    ...&lt;br /&gt;
    &amp;lt;comps&amp;gt;&lt;br /&gt;
      &amp;lt;&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt; Class=&amp;quot;MyNamespace.MyCompProperties&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;myCustomCompProperty&amp;gt;some value&amp;lt;/myCustomCompProperty&amp;gt;&lt;br /&gt;
        &amp;lt;mySecondCompProp&amp;gt;4&amp;lt;/mySecondCompProp&amp;gt;&lt;br /&gt;
      &amp;lt;/&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt;&amp;gt;&lt;br /&gt;
      &amp;lt;&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt;&amp;gt;&lt;br /&gt;
        ''&amp;lt;&amp;lt;nowiki&amp;gt;!--&amp;lt;/nowiki&amp;gt; this is kind of like &amp;lt;tag&amp;gt;MN.MyCustomTag&amp;lt;/tag&amp;gt;:--&amp;gt;''&lt;br /&gt;
        &amp;lt;compClass&amp;gt;MyNamespace.MyCustomThingComp&amp;lt;/compClass&amp;gt;&lt;br /&gt;
      &amp;lt;/&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt;&amp;gt;&lt;br /&gt;
    &amp;lt;/comps&amp;gt;&lt;br /&gt;
  &amp;lt;/ThingDef&amp;gt;&lt;br /&gt;
==== C# ====&lt;br /&gt;
  namespace MyNamespace ''// For example, LWM.ModName - by using your &lt;br /&gt;
                          //   handle/name/etc, you almost certainly guarantee uniqueness''&lt;br /&gt;
  &lt;br /&gt;
  public class MyCompProperties : CompProperties ''// Name this as you wish, of course''&lt;br /&gt;
  {&lt;br /&gt;
    public Properties() {&lt;br /&gt;
      this.compClass = typeof(MyNamespace.MyLinkedCompThing); ''// rename as appropriate''&lt;br /&gt;
    }&lt;br /&gt;
    public string myCustomCompProperty; ''// Name matches def, of course''&lt;br /&gt;
    public int mySecondCompProp = 1; ''// Can set default values''&lt;br /&gt;
  }&lt;br /&gt;
  &lt;br /&gt;
  ''// this ThingComp is used to actually access the comp property defined above''&lt;br /&gt;
  '''''// this is not &amp;quot;&amp;lt;compClass&amp;gt;MyNamespace.MyCustomThingComp&amp;lt;/compClass&amp;gt;&amp;quot;'''''&lt;br /&gt;
  public class MyLinkedCompThing : ThingComp&lt;br /&gt;
  {&lt;br /&gt;
    public string myCustomCompProperty&lt;br /&gt;
    {&lt;br /&gt;
      get&lt;br /&gt;
      {&lt;br /&gt;
        return ((MyCompProperties)this.props).myCustomCompProperty;&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    public int mySecondCompProperty ''// Have to get all the names right''&lt;br /&gt;
    { get  { return ((MyCompProperties)this.props).mySecondCompProperty; } } ''//etc''&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
[[Category:Modding tutorials]][[Category:Modding]][[Category:Defs]]&lt;/div&gt;</summary>
		<author><name>Lilwhitemouse</name></author>
	</entry>
	<entry>
		<id>https://rimworldwiki.com/index.php?title=Modding_Tutorials/Custom_Comp_Classes&amp;diff=61429</id>
		<title>Modding Tutorials/Custom Comp Classes</title>
		<link rel="alternate" type="text/html" href="https://rimworldwiki.com/index.php?title=Modding_Tutorials/Custom_Comp_Classes&amp;diff=61429"/>
		<updated>2018-11-29T16:17:24Z</updated>

		<summary type="html">&lt;p&gt;Lilwhitemouse: Fixed formatting :p&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Creating a custom comp class is a convenient way to add new functionality to RimWorld.&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
* You need to have [[Modding Tutorials/Setting up a solution|set up your editor and environment]]&lt;br /&gt;
* You need to know [[Modding Tutorials/Writing custom code|how to write custom code]]&lt;br /&gt;
* You should probably understand Defs at least somewhat.&lt;br /&gt;
&lt;br /&gt;
== def (xml) and C# structure ==&lt;br /&gt;
&lt;br /&gt;
=== Basic outline ===&lt;br /&gt;
You will have some custom def and it will have something like this:&lt;br /&gt;
  &amp;lt;ThingDef ...&amp;gt;&lt;br /&gt;
    ...&lt;br /&gt;
    ...&lt;br /&gt;
    &amp;lt;comps&amp;gt;&lt;br /&gt;
      &amp;lt;&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt; Class=&amp;quot;MyNamespace.MyCompProperties&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;myCustomCompProperty&amp;gt;some value&amp;lt;/myCustomCompProperty&amp;gt;&lt;br /&gt;
        &amp;lt;mySecondCompProp&amp;gt;4&amp;lt;/mySecondCompProp&amp;gt;&lt;br /&gt;
      &amp;lt;/&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt;&amp;gt;&lt;br /&gt;
      &amp;lt;&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt;&amp;gt;&lt;br /&gt;
        ''&amp;lt;&amp;lt;nowiki&amp;gt;!--&amp;lt;/nowiki&amp;gt; this is kind of like &amp;lt;tag&amp;gt;MN.MyCustomTag&amp;lt;/tag&amp;gt;:--&amp;gt;''&lt;br /&gt;
        &amp;lt;compClass&amp;gt;MyNamespace.MyCustomThingComp&amp;lt;/compClass&amp;gt;&lt;br /&gt;
      &amp;lt;/&amp;lt;nowiki&amp;gt;li&amp;lt;/nowiki&amp;gt;&amp;gt;&lt;br /&gt;
    &amp;lt;/comps&amp;gt;&lt;br /&gt;
  &amp;lt;/ThingDef&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Modding tutorials]][[Category:Modding]][[Category:Defs]]&lt;/div&gt;</summary>
		<author><name>Lilwhitemouse</name></author>
	</entry>
</feed>