How to only activate code when another mod is active?(SOLVED)

Started by Kuratheris, December 02, 2019, 05:20:46 PM

Previous topic - Next topic

Kuratheris

I'm trying to create a simple compatibility patch for my mod so it will only add/activate the code below(and more just like it) when the mod I'm making compatibility for is activated. I have zero idea how to make a patch, and don't know enough for the wiki to help at all.

  <TerrainDef ParentName="WDRoughStoneTileBase">
    <defName>WDRoughAndesiteTile</defName>
    <label>rough andesite tile</label>
    <color>(112,118,118)</color>
    <costList>
      <BlocksAndesite>2</BlocksAndesite>
    </costList>
  </TerrainDef>


Kuratheris

Quote from: LWM on December 02, 2019, 11:00:20 PM
Here are some concrete examples:

https://github.com/lilwhitemouse/RimWorld-LWM.DeepStorage/tree/master/_Mod/LWM.DeepStorage/Patches

This still doesn't help me. Like, I assume I use PatchOperationFindMod, then PatchOperationSequence, success always, then the mod in the right place, then I assume PatchOperationAdd, then what? I don't know exactly what I would put in the xpath, nor anything of what I would put after that.

hauvega


Work on mod
Break mod
Fix Mod
Break mod again

Kuratheris

Quote from: hauvega on December 04, 2019, 04:30:02 PM
Is that the only def being added?

Yes, plus more in the same .xml that are pretty much the same but 6 different ParentNames, and a bunch of different defName, label, color, and cost. Just knowing what I put for those 8 lines will probably tell me what to do with the rest(if I even need to).

LWM

So you're trying to add 8 different complete defs if one particular mod is added?

hauvega

Adding refs is not hard.  I use sequence only if I am doing more than one type of patch type that does different things.
<Operation Class="PatchOperationFindMod">
      <mods>                     
         <li>target mod</li>               
      </mods>
         <match Class="PatchOperationAdd">
.                             <xpath>/Defs</xpath>
                         <value>
                                            (put added defs here)
                                        </value>
                               </match>
                </Operation>
</Patch>

Work on mod
Break mod
Fix Mod
Break mod again

Kuratheris

Okay I have this so far, what am I doing wrong?

<?xml version="1.0" encoding="utf-8" ?>
  <Operation Class="PatchOperationFindMod">
<mods>
<li>[WD] Expanded Floors 1.0</li>
</mods>
  <match Class="PatchOperationAdd">
    <xpath>/Defs</xpath>
    <value>

<Defs>
  <TerrainDef ParentName="WDRoughStoneTileBase">
    <defName>WDRoughAndesiteTile</defName>
    <label>rough andesite tile</label>
    <color>(112,118,118)</color>
    <costList>
      <BlocksAndesite>2</BlocksAndesite>
    </costList>
  </TerrainDef>
</Defs>

    </value>
</match>
  </Operation>
</Patch>


Error text:
D:\Steam\steamapps\common\RimWorld\Mods\Kura's Extra Minerals\Defs\TerrainDefs/Terrain_Floors_StoneTile_Expanded_Floors.xml: unknown parse failure
Verse.Log:Error(String, Boolean)
Verse.LoadedModManager:CombineIntoUnifiedXML(List`1, Dictionary`2)
Verse.LoadedModManager:LoadAllActiveMods()
Verse.PlayDataLoader:DoPlayLoad()
Verse.PlayDataLoader:LoadAllPlayData(Boolean)
Verse.Root:<Start>m__1()
Verse.LongEventHandler:RunEventFromAnotherThread(Action)
Verse.LongEventHandler:<UpdateCurrentAsynchronousEvent>m__1()

hauvega


Work on mod
Break mod
Fix Mod
Break mod again

Kuratheris

It still gives me the same error, and still doesn't get rid of the code in-game WITHOUT the other mod on.

hauvega

Forgot the opening "<Patch>" tag
     <?xml version="1.0" encoding="utf-8" ?>
      <Patch>
                     <Operation Class="PatchOperationFindMod">
   <mods>
      <li>[WD] Expanded Floors 1.0</li>
   </mods>
  <match Class="PatchOperationAdd">
    <xpath>/Defs</xpath>
    <value>
  <TerrainDef ParentName="WDRoughStoneTileBase">
    <defName>WDRoughAndesiteTile</defName>
    <label>rough andesite tile</label>
    <color>(112,118,118)</color>
    <costList>
      <BlocksAndesite>2</BlocksAndesite>
    </costList>
  </TerrainDef>
    </value>
   </match>
  </Operation>
</Patch>

Work on mod
Break mod
Fix Mod
Break mod again