Skip to content

Patching

NachoToast edited this page Mar 24, 2025 · 5 revisions

You can leverage XML patches to define how other modded things interact with gases.

For example, the following patch makes the hazmat mask from Vanilla Armour Expanded nullify the effects of knockout gas:

<?xml version="1.0" encoding="utf-8"?>
<Patch>
    <!-- Find the mod. -->
    <Operation Class="PatchOperationFindMod">
        <mods>
            <li>Vanilla Armour Expanded</li>
        </mods>
        <!-- If found, do these actions: -->
        <match Class="PatchOperationSequence">
            <operations>
                <!-- Check if it has the <immunityWhen> node. -->
                <li Class="PatchOperationConditional">
                    <xpath>Defs/SCGF.GasDef[defName="KnockoutGas"]/immunityWhen</xpath>
                    <!-- If it doesn't, add it. -->
                    <nomatch Class="PatchOperationAdd">
                        <xpath>Defs/SCGF.GasDef[defName="KnockoutGas"]</xpath>
                        <value>
                            <immunityWhen />
                        </value>
                    </nomatch>
                </li>
                <!-- Then add a value to it's <immunityWhen> node. -->
                <li Class="PatchOperationAdd">
                    <xpath>Defs/SCGF.GasDef[defName="KnockoutGas"]/immunityWhen</xpath>
                    <value>
                        <!-- Which considers a pawn immune if they're wearing the hazmat mask. -->
                        <li Class="SCGF.Filters.ApparelSets">
                            <sets>
                                <li>
                                    <li>VAE_Headgear_HAZMATMask</li>
                                </li>
                            </sets>
                        </li>
                    </value>
                </li>
            </operations>
        </match>
    </Operation>
</Patch>

Fine-tuned patching like this isn't recommended, since it means you'll have to do it for every single gas you think the hazmat mask should stop. This is where protective apparel defs come into play. Instead of patching for a specific mod, patch the ProtectiveApparelDef itself:

<!-- Taken from 1.5/Patches/ProtectiveApparel/Vanilla Armour Expanded.xml -->
<?xml version="1.0" encoding="utf-8"?>
<Patch>
    <Operation Class="PatchOperationFindMod">
        <mods>
            <li>Vanilla Armour Expanded</li>
        </mods>
        <match Class="PatchOperationSequence">
            <operations>
                <li Class="PatchOperationAdd">
                    <xpath>Defs/SCGF.ProtectiveApparelDef[defName="Head"]/apparel</xpath>
                    <value>
                        <li>VAE_Headgear_HAZMATMask</li>
                    </value>
                </li>
                <!-- Other operations omitted for brevity. -->
            </operations>
        </match>
    </Operation>

</Patch>

Now any gas that uses a SCGF.Filter.ProtectiveApparel filter in it's <immunityWhen> node and specifies Mouth, Face, or Head in the <type> list will not affect pawns wearing the hazmat mask! If you are making patches like these, please consider contributing them to the framework so other gas mods can benefit from them as well. You can see a list of existing patches here.

Clone this wiki locally