Explorar o código

Do not crash if Scholar is not a rewardable object

Ivan Savenko %!s(int64=2) %!d(string=hai) anos
pai
achega
9ff00d75dc
Modificáronse 1 ficheiros con 43 adicións e 36 borrados
  1. 43 36
      lib/mapping/MapFormatH3M.cpp

+ 43 - 36
lib/mapping/MapFormatH3M.cpp

@@ -1206,45 +1206,52 @@ CGObjectInstance * CMapLoaderH3M::readScholar(const int3 & position, std::shared
 	auto bonusType = static_cast<ScholarBonusType>(bonusTypeRaw);
 	auto bonusID = reader->readUInt8();
 
-	switch (bonusType)
+	if (rewardable)
 	{
-		case ScholarBonusType::PRIM_SKILL:
-		{
-			JsonNode variable;
-			JsonNode dice;
-			variable.String() = NPrimarySkill::names[bonusID];
-			variable.setMeta(ModScope::scopeGame());
-			dice.Integer() = 80;
-			rewardable->configuration.presetVariable("primarySkill", "gainedStat", variable);
-			rewardable->configuration.presetVariable("dice", "0", dice);
-			break;
-		}
-		case ScholarBonusType::SECONDARY_SKILL:
-		{
-			JsonNode variable;
-			JsonNode dice;
-			variable.String() = VLC->skills()->getByIndex(bonusID)->getJsonKey();
-			variable.setMeta(ModScope::scopeGame());
-			dice.Integer() = 50;
-			rewardable->configuration.presetVariable("secondarySkill", "gainedSkill", variable);
-			rewardable->configuration.presetVariable("dice", "0", dice);
-			break;
-		}
-		case ScholarBonusType::SPELL:
+		switch (bonusType)
 		{
-			JsonNode variable;
-			JsonNode dice;
-			variable.String() = VLC->spells()->getByIndex(bonusID)->getJsonKey();
-			variable.setMeta(ModScope::scopeGame());
-			dice.Integer() = 20;
-			rewardable->configuration.presetVariable("spell", "gainedSpell", variable);
-			rewardable->configuration.presetVariable("dice", "0", dice);
-			break;
+			case ScholarBonusType::PRIM_SKILL:
+			{
+				JsonNode variable;
+				JsonNode dice;
+				variable.String() = NPrimarySkill::names[bonusID];
+				variable.setMeta(ModScope::scopeGame());
+				dice.Integer() = 80;
+				rewardable->configuration.presetVariable("primarySkill", "gainedStat", variable);
+				rewardable->configuration.presetVariable("dice", "0", dice);
+				break;
+			}
+			case ScholarBonusType::SECONDARY_SKILL:
+			{
+				JsonNode variable;
+				JsonNode dice;
+				variable.String() = VLC->skills()->getByIndex(bonusID)->getJsonKey();
+				variable.setMeta(ModScope::scopeGame());
+				dice.Integer() = 50;
+				rewardable->configuration.presetVariable("secondarySkill", "gainedSkill", variable);
+				rewardable->configuration.presetVariable("dice", "0", dice);
+				break;
+			}
+			case ScholarBonusType::SPELL:
+			{
+				JsonNode variable;
+				JsonNode dice;
+				variable.String() = VLC->spells()->getByIndex(bonusID)->getJsonKey();
+				variable.setMeta(ModScope::scopeGame());
+				dice.Integer() = 20;
+				rewardable->configuration.presetVariable("spell", "gainedSpell", variable);
+				rewardable->configuration.presetVariable("dice", "0", dice);
+				break;
+			}
+			case ScholarBonusType::RANDOM:
+				break;// No-op
+			default:
+				logGlobal->warn("Map '%s': Invalid Scholar settings! Ignoring...", mapName);
 		}
-		case ScholarBonusType::RANDOM:
-			break;// No-op
-		default:
-			logGlobal->warn("Map '%s': Invalid Scholar settings! Ignoring...", mapName);
+	}
+	else
+	{
+		logGlobal->warn("Failed to set reward parameters for a Scholar! Object is not rewardable!");
 	}
 
 	reader->skipZero(6);