浏览代码

Fixed several scenarios which could lead to json with incorrectly set
mod origin info, leading to non-resolving identifiers

Ivan Savenko 2 年之前
父节点
当前提交
36ae26bc37
共有 4 个文件被更改,包括 13 次插入12 次删除
  1. 1 1
      lib/CArtHandler.cpp
  2. 1 0
      lib/CCreatureHandler.cpp
  3. 10 11
      lib/mapObjects/CObjectClassesHandler.cpp
  4. 1 0
      lib/mapObjects/CommonConstructors.cpp

+ 1 - 1
lib/CArtHandler.cpp

@@ -373,8 +373,8 @@ CArtifact * CArtHandler::loadFromJson(const std::string & scope, const JsonNode
 		if(!art->advMapDef.empty())
 		if(!art->advMapDef.empty())
 		{
 		{
 			JsonNode templ;
 			JsonNode templ;
-			templ.setMeta(scope);
 			templ["animation"].String() = art->advMapDef;
 			templ["animation"].String() = art->advMapDef;
+			templ.setMeta(scope);
 
 
 			// add new template.
 			// add new template.
 			// Necessary for objects added via mods that don't have any templates in H3
 			// Necessary for objects added via mods that don't have any templates in H3

+ 1 - 0
lib/CCreatureHandler.cpp

@@ -633,6 +633,7 @@ CCreature * CCreatureHandler::loadFromJson(const std::string & scope, const Json
 		{
 		{
 			JsonNode templ;
 			JsonNode templ;
 			templ["animation"].String() = cre->advMapDef;
 			templ["animation"].String() = cre->advMapDef;
+			templ.setMeta(scope);
 			VLC->objtypeh->getHandlerFor(Obj::MONSTER, cre->idNumber.num)->addTemplate(templ);
 			VLC->objtypeh->getHandlerFor(Obj::MONSTER, cre->idNumber.num)->addTemplate(templ);
 		}
 		}
 
 

+ 10 - 11
lib/mapObjects/CObjectClassesHandler.cpp

@@ -26,14 +26,6 @@
 
 
 VCMI_LIB_NAMESPACE_BEGIN
 VCMI_LIB_NAMESPACE_BEGIN
 
 
-// FIXME: move into inheritNode?
-static void inheritNodeWithMeta(JsonNode & descendant, const JsonNode & base)
-{
-	std::string oldMeta = descendant.meta;
-	JsonUtils::inherit(descendant, base);
-	descendant.setMeta(oldMeta);
-}
-
 CObjectClassesHandler::CObjectClassesHandler()
 CObjectClassesHandler::CObjectClassesHandler()
 {
 {
 #define SET_HANDLER_CLASS(STRING, CLASSNAME) handlerConstructors[STRING] = std::make_shared<CLASSNAME>;
 #define SET_HANDLER_CLASS(STRING, CLASSNAME) handlerConstructors[STRING] = std::make_shared<CLASSNAME>;
@@ -291,8 +283,9 @@ void CObjectClassesHandler::loadSubObject(const std::string & identifier, JsonNo
 		assert(objects.at(ID)->subObjects.count(subID.get()) == 0);
 		assert(objects.at(ID)->subObjects.count(subID.get()) == 0);
 		assert(config["index"].isNull());
 		assert(config["index"].isNull());
 		config["index"].Float() = subID.get();
 		config["index"].Float() = subID.get();
+		config["index"].setMeta(config.meta);
 	}
 	}
-	inheritNodeWithMeta(config, objects.at(ID)->base);
+	JsonUtils::inherit(config, objects.at(ID)->base);
 	loadObjectEntry(identifier, config, objects[ID], isSubObject);
 	loadObjectEntry(identifier, config, objects[ID], isSubObject);
 }
 }
 
 
@@ -367,10 +360,16 @@ void CObjectClassesHandler::beforeValidate(JsonNode & object)
 {
 {
 	for (auto & entry : object["types"].Struct())
 	for (auto & entry : object["types"].Struct())
 	{
 	{
-		inheritNodeWithMeta(entry.second, object["base"]);
+		JsonNode base = object["base"];
+		base.setMeta(entry.second.meta);
+
+		JsonUtils::inherit(entry.second, base);
 		for (auto & templ : entry.second["templates"].Struct())
 		for (auto & templ : entry.second["templates"].Struct())
 		{
 		{
-			inheritNodeWithMeta(templ.second, entry.second["base"]);
+			JsonNode subBase = entry.second["base"];
+			subBase.setMeta(entry.second.meta);
+
+			JsonUtils::inherit(templ.second, subBase);
 		}
 		}
 	}
 	}
 }
 }

+ 1 - 0
lib/mapObjects/CommonConstructors.cpp

@@ -44,6 +44,7 @@ void CTownInstanceConstructor::initTypeData(const JsonNode & input)
 	});
 	});
 
 
 	filtersJson = input["filters"];
 	filtersJson = input["filters"];
+	filtersJson.setMeta(input["faction"].meta);
 }
 }
 
 
 void CTownInstanceConstructor::afterLoadFinalization()
 void CTownInstanceConstructor::afterLoadFinalization()