Patching ThingDef after CE - Patching Operation Failed

Started by Mat1az, January 24, 2019, 02:31:05 PM

Previous topic - Next topic

Mat1az

Hello, guys.

I'm trying to change some parameters in Gun_Revolver def after its been patched by Combat Extended patcher, and game throw me "PatchOperationReplace failed" error.

My code:

<?xml version="1.0" encoding="utf-8" ?>
<Patch>
 
  <!-- ========== Revolver ========== -->
 
<Operation Class="PatchOperationReplace">
<xpath>*/ThingDef[defName = "Gun_Revolver"]/Properties</xpath>
<value>
<defaultProjectile>Bullet_357Magnum_FMJ</defaultProjectile>
</value>
</Operation>

<Operation Class="PatchOperationReplace">
  <xpath>*/ThingDef[defName = "Gun_Revolver"]/AmmoUser</xpath>
<value>
<ammoSet>AmmoSet_357Magnum</ammoSet>
</value>
</Operation>
</Patch>


Error log:

[CE Rebalance] Patch operation Verse.PatchOperationReplace(*/ThingDef[defName = "Gun_Revolver"]/Properties) failed
file: D:\Games\Steam\steamapps\common\RimWorld\Mods\RebalanceCE\Patches\CombatExtended\Core\ThingDefs_Misc\Weapons_guns.xml
Verse.Log:Error(String, Boolean)
Verse.PatchOperation:Complete(String)
Verse.LoadedModManager:ClearCachedPatches()
Verse.LoadedModManager:LoadAllActiveMods()
Verse.PlayDataLoader:DoPlayLoad()
Verse.PlayDataLoader:LoadAllPlayData(Boolean)
Verse.Root:<Start>m__1()
Verse.LongEventHandler:RunEventFromAnotherThread(Action)
Verse.LongEventHandler:<UpdateCurrentAsynchronousEvent>m__1()


Can't understand, that is wrong with it. Any help please?

WereCat88

i think the xpath is wrong, it should be

<xpath>Defs/ThingDef[defName = "Gun_Revolver"]/Properties</xpath>
I am The Primal Mammelon

Mehni

Looks like you extrapolated from PatchOperationMakeGunCECompatible, or whatever it's called?

That PatchOperation takes some... liberties. What you see there absolutely does not reflect what the XML for a CE compatible gun ends up looking like.

https://github.com/NoImageAvailable/CombatExtendedGuns/blob/master/Defs/ThingDefs/Weapons_CE_Guns.xml

That's what the XML for a CE-compatible gun ends up looking like. Extrapolating from there, I end up with something like
/Defs/ThingDef[defName = "Gun_Revolver"]/verbs/li[@Class = "CombatExtended.VerbPropertiesCE"]/defaultProjectile

That's probably not entirely correct, but should provide you enough of a handhold to get closer.

Mat1az

Quote from: Mehni on January 28, 2019, 03:42:32 AM
That's what the XML for a CE-compatible gun ends up looking like. Extrapolating from there, I end up with something like
/Defs/ThingDef[defName = "Gun_Revolver"]/verbs/li[@Class = "CombatExtended.VerbPropertiesCE"]/defaultProjectile

That's probably not entirely correct, but should provide you enough of a handhold to get closer.

Thanks a lot, it's worked. The valid code for my task is


<?xml version="1.0" encoding="utf-8" ?>
<Patch>

<Operation Class="PatchOperationReplace">
<xpath>/Defs/ThingDef[defName = "Gun_Revolver"]/verbs/li[@Class = "CombatExtended.VerbPropertiesCE"]/defaultProjectile</xpath>
<value>
<defaultProjectile>Bullet_357Magnum_FMJ</defaultProjectile>
</value>
</Operation>

<Operation Class="PatchOperationReplace">
<xpath>/Defs/ThingDef[defName = "Gun_Revolver"]//li[@Class = "CombatExtended.CompProperties_AmmoUser"]/ammoSet</xpath>
<value>
<ammoSet>AmmoSet_357Magnum</ammoSet>
</value>
</Operation>

</Patch>