mirror of
https://github.com/vcmi/vcmi.git
synced 2025-02-03 13:01:33 +02:00
Ignore illegal 'index' entries in mods
This commit is contained in:
parent
ef5686634d
commit
3b66701ffe
@ -177,8 +177,10 @@ void CObjectClassesHandler::loadSubObject(const std::string & scope, const std::
|
|||||||
auto object = loadSubObjectFromJson(scope, identifier, entry, obj, index);
|
auto object = loadSubObjectFromJson(scope, identifier, entry, obj, index);
|
||||||
|
|
||||||
assert(object);
|
assert(object);
|
||||||
assert(obj->objects[index] == nullptr); // ensure that this id was not loaded before
|
if (obj->objects.at(index) != nullptr)
|
||||||
obj->objects[index] = object;
|
throw std::runtime_error("Attempt to load already loaded object:" + identifier);
|
||||||
|
|
||||||
|
obj->objects.at(index) = object;
|
||||||
|
|
||||||
registerObject(scope, obj->getJsonKey(), object->getSubTypeName(), object->subtype);
|
registerObject(scope, obj->getJsonKey(), object->getSubTypeName(), object->subtype);
|
||||||
for(const auto & compatID : entry["compatibilityIdentifiers"].Vector())
|
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;
|
const std::string & subMeta = subData.second["index"].meta;
|
||||||
|
|
||||||
if ( subMeta != "core")
|
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();
|
size_t subIndex = subData.second["index"].Integer();
|
||||||
loadSubObject(subData.second.meta, subData.first, subData.second, obj.get(), subIndex);
|
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
|
else
|
||||||
loadSubObject(subData.second.meta, subData.first, subData.second, obj.get());
|
loadSubObject(subData.second.meta, subData.first, subData.second, obj.get());
|
||||||
|
@ -115,11 +115,13 @@ bool ContentTypeHandler::loadMod(const std::string & modName, bool validate)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vstd::contains(data.Struct(), "index") && !data["index"].isNull())
|
bool hasIndex = 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);
|
|
||||||
|
|
||||||
|
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
|
// try to add H3 object data
|
||||||
size_t index = static_cast<size_t>(data["index"].Float());
|
size_t index = static_cast<size_t>(data["index"].Float());
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user