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

Ignore illegal 'index' entries in mods

This commit is contained in:
Ivan Savenko 2024-01-04 23:52:01 +02:00
parent ef5686634d
commit 3b66701ffe
2 changed files with 20 additions and 10 deletions

View File

@ -177,8 +177,10 @@ void CObjectClassesHandler::loadSubObject(const std::string & scope, const std::
auto object = loadSubObjectFromJson(scope, identifier, entry, obj, index);
assert(object);
assert(obj->objects[index] == nullptr); // ensure that this id was not loaded before
obj->objects[index] = object;
if (obj->objects.at(index) != nullptr)
throw std::runtime_error("Attempt to load already loaded object:" + identifier);
obj->objects.at(index) = object;
registerObject(scope, obj->getJsonKey(), object->getSubTypeName(), object->subtype);
for(const auto & compatID : entry["compatibilityIdentifiers"].Vector())
@ -259,10 +261,16 @@ std::unique_ptr<ObjectClass> CObjectClassesHandler::loadFromJson(const std::stri
{
const std::string & subMeta = subData.second["index"].meta;
if ( subMeta != "core")
logMod->warn("Object %s:%s.%s - attempt to load object with preset index! This option is reserved for built-in mod", subMeta, name, subData.first );
size_t subIndex = subData.second["index"].Integer();
loadSubObject(subData.second.meta, subData.first, subData.second, obj.get(), subIndex);
if ( subMeta == "core")
{
size_t subIndex = subData.second["index"].Integer();
loadSubObject(subData.second.meta, subData.first, subData.second, obj.get(), subIndex);
}
else
{
logMod->error("Object %s:%s.%s - attempt to load object with preset index! This option is reserved for built-in mod", subMeta, name, subData.first );
loadSubObject(subData.second.meta, subData.first, subData.second, obj.get());
}
}
else
loadSubObject(subData.second.meta, subData.first, subData.second, obj.get());

View File

@ -115,11 +115,13 @@ bool ContentTypeHandler::loadMod(const std::string & modName, bool validate)
continue;
}
if (vstd::contains(data.Struct(), "index") && !data["index"].isNull())
{
if (modName != "core")
logMod->warn("Mod %s is attempting to load original data! This should be reserved for built-in mod.", modName);
bool hasIndex = vstd::contains(data.Struct(), "index") && !data["index"].isNull();
if (hasIndex && modName != "core")
logMod->error("Mod %s is attempting to load original data! This option is reserved for built-in mod.", modName);
if (hasIndex && modName == "core")
{
// try to add H3 object data
size_t index = static_cast<size_t>(data["index"].Float());