Help with Patching

Started by cory3573, November 17, 2021, 03:11:42 PM

Previous topic - Next topic

cory3573

I am attempting to Patch the Orbital weapons and the Low Shield Pack to be refuellable using the bits of another mod (Buyable Quest Rewards) I have installed.

I've tried various different patching methods but I can't seem to target the "CompProperties_Reloadable" li or even the comps of each item.
The section I'm modifying is
    <comps>
      <li Class="CompProperties_Reloadable">
        <maxCharges>1</maxCharges>
        <destroyOnEmpty>true</destroyOnEmpty>
        <hotKey>Misc4</hotKey>
        <chargeNoun>charge</chargeNoun>
        <displayGizmoWhileUndrafted>false</displayGizmoWhileUndrafted>
      </li>
    </comps>

I want to remove the destroyOnEmpty (I was trying to remove the entire comps node at this point) and add in refuel parameters with these(might need to be li[0]?)
<Operation Class="PatchOperationRemove"> <!-- Recharging Tornado Generator -->
<xpath>*/ThingDef[defname="OrbitalTargeterBombardment"]/comps</xpath>
</Operation>
<Operation Class="PatchOperationAdd"> <!-- Recharging Tornado Generator -->
<xpath>*/ThingDef[defname="TornadoGenerator"]/comps/li[1]</xpath>
<value>
<ammoDef>Chemfuel</ammoDef>
<ammoCountPerCharge>50</ammoCountPerCharge>
<baseReloadTicks>60</baseReloadTicks>
<soundReload>Standard_Reload</soundReload>
</value>
</Operation>

I also tried replacing the entire list and comps nodes but I get an error every time
[Buyable Quest Rewards] Patch operation Verse.PatchOperationRemove(*/ThingDef[defname="OrbitalTargeterBombardment"]/comps) failed
file: I:\SteamLibrary\steamapps\workshop\content\294100\1634468067\1.2\Patches\BuyablePatchesv1.2.xml
Verse.Log:Error(String, Boolean)
Verse.PatchOperation:Complete(String)
Verse.LoadedModManager:ClearCachedPatches()
Verse.LoadedModManager:LoadAllActiveMods()
Verse.PlayDataLoader:DoPlayLoad()
Verse.PlayDataLoader:LoadAllPlayData(Boolean)
Verse.<>c:<Start>b__6_1()
Verse.LongEventHandler:RunEventFromAnotherThread(Action)
Verse.<>c:<UpdateCurrentAsynchronousEvent>b__27_0()
System.Threading.ThreadHelper:ThreadStart_Context(Object)
System.Threading.ExecutionContext:RunInternal(ExecutionContext, ContextCallback, Object, Boolean)
System.Threading.ExecutionContext:Run(ExecutionContext, ContextCallback, Object, Boolean)
System.Threading.ExecutionContext:Run(ExecutionContext, ContextCallback, Object)
System.Threading.ThreadHelper:ThreadStart()
[Buyable Quest Rewards] Patch operation Verse.PatchOperationAdd(*/ThingDef[defname="TornadoGenerator"]/comps/li[1]) failed
file: I:\SteamLibrary\steamapps\workshop\content\294100\1634468067\1.2\Patches\BuyablePatchesv1.2.xml
Verse.Log:Error(String, Boolean)
Verse.PatchOperation:Complete(String)
Verse.LoadedModManager:ClearCachedPatches()
Verse.LoadedModManager:LoadAllActiveMods()
Verse.PlayDataLoader:DoPlayLoad()
Verse.PlayDataLoader:LoadAllPlayData(Boolean)
Verse.<>c:<Start>b__6_1()
Verse.LongEventHandler:RunEventFromAnotherThread(Action)
Verse.<>c:<UpdateCurrentAsynchronousEvent>b__27_0()
System.Threading.ThreadHelper:ThreadStart_Context(Object)
System.Threading.ExecutionContext:RunInternal(ExecutionContext, ContextCallback, Object, Boolean)
System.Threading.ExecutionContext:Run(ExecutionContext, ContextCallback, Object, Boolean)
System.Threading.ExecutionContext:Run(ExecutionContext, ContextCallback, Object)
System.Threading.ThreadHelper:ThreadStart()

Not sure what I'm doing wrong but my next plan is making a separate mod folder and trying to mod the files directly but that's just mod conflict central.

cory3573

I figured it out myself after a few hours, moved all of my various changes into a new mod of my own and went through rimworlds complaints. Ended up figuring out the problem as long as I load my newly made mod last. Seems it was an issue with context, make sure you spell and position everything PERFECTLY
Ended with this code for the comps replacement
<li Class="PatchOperationRemove"><xpath>/Defs/ThingDef[defName="OrbitalTargeterBombardment"]/comps/li[@Class="CompProperties_Reloadable"]/destroyOnEmpty</xpath></li>
<li Class="PatchOperationAdd"><xpath>/Defs/ThingDef[defName="OrbitalTargeterBombardment"]/comps/li[@Class="CompProperties_Reloadable"]</xpath>
<value>
<ammoDef>Uranium</ammoDef>
<ammoCountPerCharge>20</ammoCountPerCharge>
<baseReloadTicks>60</baseReloadTicks>
<soundReload>Standard_Reload</soundReload>
</value>
</li>