ソースを参照

Ignore illegal 'index' entries in mods

Ivan Savenko 1 年間 前
コミット
3b66701ffe

+ 14 - 6
lib/mapObjectConstructors/CObjectClassesHandler.cpp

@@ -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());

+ 6 - 4
lib/modding/ContentTypeHandler.cpp

@@ -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());