Ludeon Forums

Ludeon Forums

  • December 15, 2019, 05:57:53 PM
  • Welcome, Guest
Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: How to only activate code when another mod is active?(SOLVED)  (Read 200 times)

Kuratheris

  • Muffalo
  • *
  • Posts: 8
  • Refugee
    • View Profile
How to only activate code when another mod is active?(SOLVED)
« on: December 02, 2019, 05:20:46 PM »

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.

Code: [Select]
  <TerrainDef ParentName="WDRoughStoneTileBase">
    <defName>WDRoughAndesiteTile</defName>
    <label>rough andesite tile</label>
    <color>(112,118,118)</color>
    <costList>
      <BlocksAndesite>2</BlocksAndesite>
    </costList>
  </TerrainDef>
« Last Edit: December 10, 2019, 02:04:40 AM by Kuratheris »
Logged

LWM

  • Colonist
  • ***
  • Posts: 491
  • Little White Mouse
    • View Profile
Logged

Kuratheris

  • Muffalo
  • *
  • Posts: 8
  • Refugee
    • View Profile
Re: How to only activate code when another mod is active?
« Reply #2 on: December 04, 2019, 03:47:54 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.
Logged

hauvega

  • Colonist
  • ***
  • Posts: 140
  • Refugee
    • View Profile
Re: How to only activate code when another mod is active?
« Reply #3 on: December 04, 2019, 04:30:02 PM »

Is that the only def being added?
Logged

 BoJack is calling.                           Horses in Spaceeee!

Work on mod
Break mod
Fix Mod
Break mod again

Kuratheris

  • Muffalo
  • *
  • Posts: 8
  • Refugee
    • View Profile
Re: How to only activate code when another mod is active?
« Reply #4 on: December 04, 2019, 05:34:56 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).
Logged

LWM

  • Colonist
  • ***
  • Posts: 491
  • Little White Mouse
    • View Profile
Re: How to only activate code when another mod is active?
« Reply #5 on: December 04, 2019, 05:55:23 PM »

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

hauvega

  • Colonist
  • ***
  • Posts: 140
  • Refugee
    • View Profile
Re: How to only activate code when another mod is active?
« Reply #6 on: December 04, 2019, 06:23:46 PM »

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>
Logged

 BoJack is calling.                           Horses in Spaceeee!

Work on mod
Break mod
Fix Mod
Break mod again

Kuratheris

  • Muffalo
  • *
  • Posts: 8
  • Refugee
    • View Profile
Re: How to only activate code when another mod is active?
« Reply #7 on: December 07, 2019, 05:55:14 PM »

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

Code: [Select]
<?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:
Code: [Select]
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()
Logged

hauvega

  • Colonist
  • ***
  • Posts: 140
  • Refugee
    • View Profile
Re: How to only activate code when another mod is active?
« Reply #8 on: December 07, 2019, 06:04:05 PM »

Remove the <Defs> tag inside the value.
Logged

 BoJack is calling.                           Horses in Spaceeee!

Work on mod
Break mod
Fix Mod
Break mod again

Kuratheris

  • Muffalo
  • *
  • Posts: 8
  • Refugee
    • View Profile
Re: How to only activate code when another mod is active?
« Reply #9 on: December 07, 2019, 10:20:08 PM »

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

hauvega

  • Colonist
  • ***
  • Posts: 140
  • Refugee
    • View Profile
Re: How to only activate code when another mod is active?
« Reply #10 on: December 08, 2019, 01:59:44 AM »

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>
Logged

 BoJack is calling.                           Horses in Spaceeee!

Work on mod
Break mod
Fix Mod
Break mod again