From b372cc84e91d8acdd3901cc24572e49de61b5893 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Tue, 25 Feb 2025 15:26:16 +0000 Subject: [PATCH] Avoid crash if object has same name as on provided in compatiblity identifiers field --- .../CObjectClassesHandler.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/mapObjectConstructors/CObjectClassesHandler.cpp b/lib/mapObjectConstructors/CObjectClassesHandler.cpp index 422c8e2cf..92c35cfae 100644 --- a/lib/mapObjectConstructors/CObjectClassesHandler.cpp +++ b/lib/mapObjectConstructors/CObjectClassesHandler.cpp @@ -177,7 +177,12 @@ void CObjectClassesHandler::loadSubObject(const std::string & scope, const std:: registerObject(scope, baseObject->getJsonKey(), subObject->getSubTypeName(), subObject->subtype); for(const auto & compatID : entry["compatibilityIdentifiers"].Vector()) - registerObject(scope, baseObject->getJsonKey(), compatID.String(), subObject->subtype); + { + if (identifier != compatID.String()) + registerObject(scope, baseObject->getJsonKey(), compatID.String(), subObject->subtype); + else + logMod->warn("Mod '%s' map object '%s': compatibility identifier has same name as object itself!"); + } } void CObjectClassesHandler::loadSubObject(const std::string & scope, const std::string & identifier, const JsonNode & entry, ObjectClass * baseObject, size_t index) @@ -192,7 +197,12 @@ void CObjectClassesHandler::loadSubObject(const std::string & scope, const std:: registerObject(scope, baseObject->getJsonKey(), subObject->getSubTypeName(), subObject->subtype); for(const auto & compatID : entry["compatibilityIdentifiers"].Vector()) - registerObject(scope, baseObject->getJsonKey(), compatID.String(), subObject->subtype); + { + if (identifier != compatID.String()) + registerObject(scope, baseObject->getJsonKey(), compatID.String(), subObject->subtype); + else + logMod->warn("Mod '%s' map object '%s': compatibility identifier has same name as object itself!"); + } } TObjectTypeHandler CObjectClassesHandler::loadSubObjectFromJson(const std::string & scope, const std::string & identifier, const JsonNode & entry, ObjectClass * baseObject, size_t index)