[1.1.2567 (+ Royalty)] QuestNode_Equal compares incorrectly

Started by Alistaire, March 10, 2020, 09:55:28 AM

Previous topic - Next topic


Using mods which add new children of Def, the following issue occurs:

  • QuestScriptDef TradeRequest is tested for
  • QuestNode_TradeRequest_Initiate returns $requestedThing which is a child of ThingDef, such as CombatExtended.AmmoDef or any other child of ThingDef
  • QuestNode_Equal tests whether $requestedThing is Leather_Human
  • QuestNodeEqualUtility.Equal(this.value1.GetValue(slate), this.value2.GetValue(slate), this.compareAs.GetValue(slate)), the value of slate.GetValue() is CombatExtended.AmmoDef
  • ConvertHelper.CanConvert returns true because CombatExtended.AmmoDef is a child of ThingDef (IsAssignableFrom)
  • ConvertHelper.Convert is called, which because CombatExtended.AmmoDef is assignable from Def, checks through the DefDatabase of CombatExtended.AmmoDef!
  • Attempt to GetNamed<CombatExtended.AmmoDef>("Leather_Human")
  • Error, because the AmmoDef DefDatabase does not contain a definition for Leather_Human

This error prevents mods from extending ThingDef, just because of a comparison to human leather for no good reason.

There should be a fallback which checks whether the Def children EXACTLY match rather than if they are assignable from eachother, at least in this case. Specifically, the DefDatabase does NOT allow calling one ThingDef and converting it to another Type : ThingDef, so this equality comparison shouldn't be able to do so (e.g it shouldn't check whether the types are assignable from eachother, but whether they ARE eachother).

Since this is an interpretation of the issues; exact stacktrace attached to post (stacktrace.png).