1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-06 09:09:40 +02:00

Merge pull request #3110 from IvanSavenko/mod_compat_fix

Mod compatibility fixes
This commit is contained in:
Ivan Savenko
2023-10-29 14:30:04 +02:00
committed by GitHub
2 changed files with 17 additions and 5 deletions

View File

@@ -193,13 +193,16 @@ TObjectTypeHandler CObjectClassesHandler::loadSubObjectFromJson(const std::strin
assert(identifier.find(':') == std::string::npos); assert(identifier.find(':') == std::string::npos);
assert(!scope.empty()); assert(!scope.empty());
if(!handlerConstructors.count(obj->handlerName)) std::string handler = obj->handlerName;
if(!handlerConstructors.count(handler))
{ {
logGlobal->error("Handler with name %s was not found!", obj->handlerName); logMod->error("Handler with name %s was not found!", handler);
return nullptr; // workaround for potential crash - if handler does not exists, continue with generic handler that is used for objects without any custom logc
handler = "generic";
assert(handlerConstructors.count(handler) != 0);
} }
auto createdObject = handlerConstructors.at(obj->handlerName)(); auto createdObject = handlerConstructors.at(handler)();
createdObject->modScope = scope; createdObject->modScope = scope;
createdObject->typeName = obj->identifier;; createdObject->typeName = obj->identifier;;

View File

@@ -104,7 +104,16 @@ bool ContentTypeHandler::loadMod(const std::string & modName, bool validate)
JsonNode & data = entry.second; JsonNode & data = entry.second;
if (data.meta != modName) if (data.meta != modName)
logMod->warn("Mod %s is attempting to inject object %s into mod %s! This may not be supported in future versions!", data.meta, name, modName); {
// in this scenario, entire object record comes from another mod
// normally, this is used to "patch" object from another mod (which is legal)
// however in this case there is no object to patch. This might happen in such cases:
// - another mod attempts to add object into this mod (technically can be supported, but might lead to weird edge cases)
// - another mod attempts to edit object from this mod that no longer exist - DANGER since such patch likely has very incomplete data
// so emit warning and skip such case
logMod->warn("Mod %s attempts to edit object %s from mod %s but no such object exist!", data.meta, name, modName);
continue;
}
if (vstd::contains(data.Struct(), "index") && !data["index"].isNull()) if (vstd::contains(data.Struct(), "index") && !data["index"].isNull())
{ {