1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-27 22:49:25 +02:00

Fix possible crashes on attempt to parse bonus

This commit is contained in:
Ivan Savenko
2025-06-15 23:54:43 +03:00
parent f9b4a36a5f
commit 464865f20d
2 changed files with 14 additions and 12 deletions

View File

@@ -903,9 +903,6 @@ void CCreatureHandler::loadCreatureJson(CCreature * creature, const JsonNode & c
{
creature->animDefName = AnimationPath::fromJson(config["graphics"]["animation"]);
//FIXME: MOD COMPATIBILITY
if (config["abilities"].getType() == JsonNode::JsonType::DATA_STRUCT)
{
for(const auto & ability : config["abilities"].Struct())
{
if (!ability.second.isNull())
@@ -917,7 +914,6 @@ void CCreatureHandler::loadCreatureJson(CCreature * creature, const JsonNode & c
creature->addNewBonus(b);
}
}
}
LIBRARY->identifiers()->requestIdentifier("faction", config["faction"], [=](si32 faction)
{

View File

@@ -404,7 +404,7 @@ static TUpdaterPtr parseUpdater(const JsonNode & updaterJson)
if(updaterJson["type"].String() == "GROWS_WITH_LEVEL")
{
// MOD COMPATIBILITY - parameters is deprecated in 1.7
const JsonVector param = updaterJson["parameters"].Vector();
const JsonNode & param = updaterJson["parameters"];
int valPer20 = updaterJson["valPer20"].isNull() ? param[0].Integer() : updaterJson["valPer20"].Integer();
int stepSize = updaterJson["stepSize"].isNull() ? param[1].Integer() : updaterJson["stepSize"].Integer();
@@ -648,6 +648,12 @@ bool JsonUtils::parseBonus(const JsonNode &ability, Bonus *b, const TextIdentifi
const JsonNode & subtypeNode = ability["subtype"];
const JsonNode & addinfoNode = ability["addInfo"];
if (ability["type"].isNull())
{
logMod->error("Failed to parse bonus. Description: '%s'. Config: '%s'", descriptionID.get(), ability.toCompactString());
return false;
}
LIBRARY->identifiers()->requestIdentifier("bonus", ability["type"], [b, subtypeNode, addinfoNode](si32 bonusID)
{
b->type = static_cast<BonusType>(bonusID);