1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-22 22:13:35 +02:00
vcmi/lib/modding/ModVerificationInfo.cpp

117 lines
2.9 KiB
C++
Raw Normal View History

/*
* 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 "CModHandler.h"
#include "ModDescription.h"
2024-04-16 15:30:22 +02:00
#include "ModIncompatibility.h"
#include "../json/JsonNode.h"
2024-04-16 15:30:22 +02:00
#include "../VCMI_Lib.h"
2024-04-19 11:46:50 +02:00
VCMI_LIB_NAMESPACE_BEGIN
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;
if (!mod.second.parent.empty())
modWriter["parent"].String() = mod.second.parent;
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).affectsGameplay())
2024-04-16 15:30:22 +02:00
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;
}
const auto & localVersion = VLC->modh->getModInfo(remoteModId).getVersion();
modAffectsGameplay |= VLC->modh->getModInfo(remoteModId).affectsGameplay();
2024-04-16 15:30:22 +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)
continue;
2024-04-16 15:30:22 +02:00
if (!vstd::contains(VLC->modh->getActiveMods(), remoteModId))
{
result[remoteModId] = ModVerificationStatus::DISABLED;
continue;
}
if(remoteModInfo.version != localVersion)
2024-04-16 15:30:22 +02:00
{
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