1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-01 00:45:26 +02:00

Fixed mod dependencies check on save loading to prevent crashes:

- mods that don't affect game objects can be ignored when loading save
- gameplay-affecting mods that were present in save must be active
- gameplay-affecting mods that were not in save must not be active
This commit is contained in:
Ivan Savenko
2023-08-14 23:37:16 +03:00
parent 5dc735494c
commit ef0cd0ba6e
2 changed files with 82 additions and 6 deletions

View File

@ -649,6 +649,48 @@ void CModInfo::updateChecksum(ui32 newChecksum)
}
}
bool CModInfo::checkModGameplayAffecting() const
{
if (modGameplayAffecting.has_value())
return *modGameplayAffecting;
static const std::vector<std::string> keysToTest = {
"heroClasses",
"artifacts",
"creatures",
"factions",
"objects",
"heroes",
"spells",
"skills",
"templates",
"scripts",
"battlefields",
"terrains",
"rivers",
"roads",
"obstacles"
};
ResourceID modFileResource(CModInfo::getModFile(identifier));
if(CResourceHandler::get("initial")->existsResource(modFileResource))
{
const JsonNode modConfig(modFileResource);
for (auto const & key : keysToTest)
{
if (!modConfig[key].isNull())
{
modGameplayAffecting = true;
return *modGameplayAffecting;
}
}
}
modGameplayAffecting = false;
return *modGameplayAffecting;
}
void CModInfo::loadLocalData(const JsonNode & data)
{
bool validated = false;