2024-04-14 14:45:13 +02:00
|
|
|
/*
|
|
|
|
* ModVerificationInfo.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include "StdInc.h"
|
|
|
|
#include "ModVerificationInfo.h"
|
|
|
|
|
2024-04-16 15:30:22 +02:00
|
|
|
#include "CModInfo.h"
|
|
|
|
#include "CModHandler.h"
|
|
|
|
#include "ModIncompatibility.h"
|
|
|
|
|
2024-04-14 14:45:13 +02:00
|
|
|
#include "../json/JsonNode.h"
|
2024-04-16 15:30:22 +02:00
|
|
|
#include "../VCMI_Lib.h"
|
2024-04-14 14:45:13 +02:00
|
|
|
|
2024-04-19 11:46:50 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2024-04-14 14:45:13 +02:00
|
|
|
JsonNode ModVerificationInfo::jsonSerializeList(const ModCompatibilityInfo & input)
|
|
|
|
{
|
|
|
|
JsonNode output;
|
|
|
|
|
|
|
|
for(const auto & mod : input)
|
|
|
|
{
|
|
|
|
JsonNode modWriter;
|
|
|
|
modWriter["modId"].String() = mod.first;
|
|
|
|
modWriter["name"].String() = mod.second.name;
|
2024-04-15 12:34:16 +02:00
|
|
|
if (!mod.second.parent.empty())
|
|
|
|
modWriter["parent"].String() = mod.second.parent;
|
2024-04-14 14:45:13 +02:00
|
|
|
modWriter["version"].String() = mod.second.version.toString();
|
|
|
|
output.Vector().push_back(modWriter);
|
|
|
|
}
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
ModCompatibilityInfo ModVerificationInfo::jsonDeserializeList(const JsonNode & input)
|
|
|
|
{
|
|
|
|
ModCompatibilityInfo output;
|
|
|
|
|
|
|
|
for(const auto & mod : input.Vector())
|
|
|
|
{
|
|
|
|
ModVerificationInfo info;
|
|
|
|
info.version = CModVersion::fromString(mod["version"].String());
|
|
|
|
info.name = mod["name"].String();
|
|
|
|
info.parent = mod["parent"].String();
|
|
|
|
info.checksum = 0;
|
|
|
|
info.impactsGameplay = true;
|
|
|
|
|
|
|
|
if(!mod["modId"].isNull())
|
|
|
|
output[mod["modId"].String()] = info;
|
|
|
|
else
|
|
|
|
output[mod["name"].String()] = info;
|
|
|
|
}
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
2024-04-16 15:30:22 +02:00
|
|
|
|
|
|
|
ModListVerificationStatus ModVerificationInfo::verifyListAgainstLocalMods(const ModCompatibilityInfo & modList)
|
|
|
|
{
|
|
|
|
ModListVerificationStatus result;
|
|
|
|
|
|
|
|
for(const auto & m : VLC->modh->getActiveMods())
|
|
|
|
{
|
|
|
|
if(modList.count(m))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if(VLC->modh->getModInfo(m).checkModGameplayAffecting())
|
|
|
|
result[m] = ModVerificationStatus::EXCESSIVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(const auto & infoPair : modList)
|
|
|
|
{
|
|
|
|
auto & remoteModId = infoPair.first;
|
|
|
|
auto & remoteModInfo = infoPair.second;
|
|
|
|
|
|
|
|
bool modAffectsGameplay = remoteModInfo.impactsGameplay;
|
|
|
|
//parent mod affects gameplay if child affects too
|
|
|
|
for(const auto & subInfoPair : modList)
|
|
|
|
modAffectsGameplay |= (subInfoPair.second.impactsGameplay && subInfoPair.second.parent == remoteModId);
|
|
|
|
|
|
|
|
if(!vstd::contains(VLC->modh->getAllMods(), remoteModId))
|
|
|
|
{
|
|
|
|
result[remoteModId] = ModVerificationStatus::NOT_INSTALLED;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto & localModInfo = VLC->modh->getModInfo(remoteModId).getVerificationInfo();
|
|
|
|
modAffectsGameplay |= VLC->modh->getModInfo(remoteModId).checkModGameplayAffecting();
|
|
|
|
|
2024-04-28 19:54:33 +02:00
|
|
|
// skip it. Such mods should only be present in old saves or if mod changed and no longer affects gameplay
|
2024-04-19 11:46:50 +02:00
|
|
|
if (!modAffectsGameplay)
|
2024-04-28 19:54:33 +02:00
|
|
|
continue;
|
2024-04-16 15:30:22 +02:00
|
|
|
|
|
|
|
if (!vstd::contains(VLC->modh->getActiveMods(), remoteModId))
|
|
|
|
{
|
|
|
|
result[remoteModId] = ModVerificationStatus::DISABLED;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(remoteModInfo.version != localModInfo.version)
|
|
|
|
{
|
|
|
|
result[remoteModId] = ModVerificationStatus::VERSION_MISMATCH;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
result[remoteModId] = ModVerificationStatus::FULL_MATCH;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2024-04-19 11:46:50 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|