CModHandler.cpp 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249
  1. /*
  2. * CModHandler.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "CModHandler.h"
  12. #include "mapObjects/CObjectClassesHandler.h"
  13. #include "rmg/CRmgTemplateStorage.h"
  14. #include "filesystem/FileStream.h"
  15. #include "filesystem/AdapterLoaders.h"
  16. #include "filesystem/CFilesystemLoader.h"
  17. #include "filesystem/Filesystem.h"
  18. #include "CCreatureHandler.h"
  19. #include "CArtHandler.h"
  20. #include "CTownHandler.h"
  21. #include "CHeroHandler.h"
  22. #include "mapObjects/CObjectHandler.h"
  23. #include "StringConstants.h"
  24. #include "CStopWatch.h"
  25. #include "IHandlerBase.h"
  26. #include "spells/CSpellHandler.h"
  27. #include "CSkillHandler.h"
  28. #include "CGeneralTextHandler.h"
  29. #include "Languages.h"
  30. #include "ScriptHandler.h"
  31. #include "RoadHandler.h"
  32. #include "GameSettings.h"
  33. #include "RiverHandler.h"
  34. #include "TerrainHandler.h"
  35. #include "BattleFieldHandler.h"
  36. #include "ObstacleHandler.h"
  37. #include <vstd/StringUtils.h>
  38. VCMI_LIB_NAMESPACE_BEGIN
  39. CIdentifierStorage::CIdentifierStorage():
  40. state(LOADING)
  41. {
  42. }
  43. void CIdentifierStorage::checkIdentifier(std::string & ID)
  44. {
  45. if (boost::algorithm::ends_with(ID, "."))
  46. logMod->warn("BIG WARNING: identifier %s seems to be broken!", ID);
  47. else
  48. {
  49. size_t pos = 0;
  50. do
  51. {
  52. if (std::tolower(ID[pos]) != ID[pos] ) //Not in camelCase
  53. {
  54. logMod->warn("Warning: identifier %s is not in camelCase!", ID);
  55. ID[pos] = std::tolower(ID[pos]);// Try to fix the ID
  56. }
  57. pos = ID.find('.', pos);
  58. }
  59. while(pos++ != std::string::npos);
  60. }
  61. }
  62. CIdentifierStorage::ObjectCallback::ObjectCallback(std::string localScope,
  63. std::string remoteScope,
  64. std::string type,
  65. std::string name,
  66. std::function<void(si32)> callback,
  67. bool optional):
  68. localScope(std::move(localScope)),
  69. remoteScope(std::move(remoteScope)),
  70. type(std::move(type)),
  71. name(std::move(name)),
  72. callback(std::move(callback)),
  73. optional(optional)
  74. {}
  75. void CIdentifierStorage::requestIdentifier(ObjectCallback callback)
  76. {
  77. checkIdentifier(callback.type);
  78. checkIdentifier(callback.name);
  79. assert(!callback.localScope.empty());
  80. if (state != FINISHED) // enqueue request if loading is still in progress
  81. scheduledRequests.push_back(callback);
  82. else // execute immediately for "late" requests
  83. resolveIdentifier(callback);
  84. }
  85. void CIdentifierStorage::requestIdentifier(const std::string & scope, const std::string & type, const std::string & name, const std::function<void(si32)> & callback)
  86. {
  87. auto pair = vstd::splitStringToPair(name, ':'); // remoteScope:name
  88. requestIdentifier(ObjectCallback(scope, pair.first, type, pair.second, callback, false));
  89. }
  90. void CIdentifierStorage::requestIdentifier(const std::string & scope, const std::string & fullName, const std::function<void(si32)> & callback)
  91. {
  92. auto scopeAndFullName = vstd::splitStringToPair(fullName, ':');
  93. auto typeAndName = vstd::splitStringToPair(scopeAndFullName.second, '.');
  94. requestIdentifier(ObjectCallback(scope, scopeAndFullName.first, typeAndName.first, typeAndName.second, callback, false));
  95. }
  96. void CIdentifierStorage::requestIdentifier(const std::string & type, const JsonNode & name, const std::function<void(si32)> & callback)
  97. {
  98. auto pair = vstd::splitStringToPair(name.String(), ':'); // remoteScope:name
  99. requestIdentifier(ObjectCallback(name.meta, pair.first, type, pair.second, callback, false));
  100. }
  101. void CIdentifierStorage::requestIdentifier(const JsonNode & name, const std::function<void(si32)> & callback)
  102. {
  103. auto pair = vstd::splitStringToPair(name.String(), ':'); // remoteScope:<type.name>
  104. auto pair2 = vstd::splitStringToPair(pair.second, '.'); // type.name
  105. requestIdentifier(ObjectCallback(name.meta, pair.first, pair2.first, pair2.second, callback, false));
  106. }
  107. void CIdentifierStorage::tryRequestIdentifier(const std::string & scope, const std::string & type, const std::string & name, const std::function<void(si32)> & callback)
  108. {
  109. auto pair = vstd::splitStringToPair(name, ':'); // remoteScope:name
  110. requestIdentifier(ObjectCallback(scope, pair.first, type, pair.second, callback, true));
  111. }
  112. void CIdentifierStorage::tryRequestIdentifier(const std::string & type, const JsonNode & name, const std::function<void(si32)> & callback)
  113. {
  114. auto pair = vstd::splitStringToPair(name.String(), ':'); // remoteScope:name
  115. requestIdentifier(ObjectCallback(name.meta, pair.first, type, pair.second, callback, true));
  116. }
  117. boost::optional<si32> CIdentifierStorage::getIdentifier(const std::string & scope, const std::string & type, const std::string & name, bool silent)
  118. {
  119. auto pair = vstd::splitStringToPair(name, ':'); // remoteScope:name
  120. auto idList = getPossibleIdentifiers(ObjectCallback(scope, pair.first, type, pair.second, std::function<void(si32)>(), silent));
  121. if (idList.size() == 1)
  122. return idList.front().id;
  123. if (!silent)
  124. logMod->error("Failed to resolve identifier %s of type %s from mod %s", name , type ,scope);
  125. return boost::optional<si32>();
  126. }
  127. boost::optional<si32> CIdentifierStorage::getIdentifier(const std::string & type, const JsonNode & name, bool silent)
  128. {
  129. auto pair = vstd::splitStringToPair(name.String(), ':'); // remoteScope:name
  130. auto idList = getPossibleIdentifiers(ObjectCallback(name.meta, pair.first, type, pair.second, std::function<void(si32)>(), silent));
  131. if (idList.size() == 1)
  132. return idList.front().id;
  133. if (!silent)
  134. logMod->error("Failed to resolve identifier %s of type %s from mod %s", name.String(), type, name.meta);
  135. return boost::optional<si32>();
  136. }
  137. boost::optional<si32> CIdentifierStorage::getIdentifier(const JsonNode & name, bool silent)
  138. {
  139. auto pair = vstd::splitStringToPair(name.String(), ':'); // remoteScope:<type.name>
  140. auto pair2 = vstd::splitStringToPair(pair.second, '.'); // type.name
  141. auto idList = getPossibleIdentifiers(ObjectCallback(name.meta, pair.first, pair2.first, pair2.second, std::function<void(si32)>(), silent));
  142. if (idList.size() == 1)
  143. return idList.front().id;
  144. if (!silent)
  145. logMod->error("Failed to resolve identifier %s of type %s from mod %s", name.String(), pair2.first, name.meta);
  146. return boost::optional<si32>();
  147. }
  148. boost::optional<si32> CIdentifierStorage::getIdentifier(const std::string & scope, const std::string & fullName, bool silent)
  149. {
  150. auto pair = vstd::splitStringToPair(fullName, ':'); // remoteScope:<type.name>
  151. auto pair2 = vstd::splitStringToPair(pair.second, '.'); // type.name
  152. auto idList = getPossibleIdentifiers(ObjectCallback(scope, pair.first, pair2.first, pair2.second, std::function<void(si32)>(), silent));
  153. if (idList.size() == 1)
  154. return idList.front().id;
  155. if (!silent)
  156. logMod->error("Failed to resolve identifier %s of type %s from mod %s", fullName, pair2.first, scope);
  157. return boost::optional<si32>();
  158. }
  159. void CIdentifierStorage::registerObject(const std::string & scope, const std::string & type, const std::string & name, si32 identifier)
  160. {
  161. ObjectData data;
  162. data.scope = scope;
  163. data.id = identifier;
  164. std::string fullID = type + '.' + name;
  165. checkIdentifier(fullID);
  166. std::pair<const std::string, ObjectData> mapping = std::make_pair(fullID, data);
  167. if(!vstd::containsMapping(registeredObjects, mapping))
  168. {
  169. logMod->trace("registered %s as %s:%s", fullID, scope, identifier);
  170. registeredObjects.insert(mapping);
  171. }
  172. }
  173. std::vector<CIdentifierStorage::ObjectData> CIdentifierStorage::getPossibleIdentifiers(const ObjectCallback & request)
  174. {
  175. std::set<std::string> allowedScopes;
  176. bool isValidScope = true;
  177. // called have not specified destination mod explicitly
  178. if (request.remoteScope.empty())
  179. {
  180. // special scope that should have access to all in-game objects
  181. if (request.localScope == CModHandler::scopeGame())
  182. {
  183. for(const auto & modName : VLC->modh->getActiveMods())
  184. allowedScopes.insert(modName);
  185. }
  186. // normally ID's from all required mods, own mod and virtual built-in mod are allowed
  187. else if(request.localScope != CModHandler::scopeBuiltin() && !request.localScope.empty())
  188. {
  189. allowedScopes = VLC->modh->getModDependencies(request.localScope, isValidScope);
  190. if(!isValidScope)
  191. return std::vector<ObjectData>();
  192. allowedScopes.insert(request.localScope);
  193. }
  194. // all mods can access built-in mod
  195. allowedScopes.insert(CModHandler::scopeBuiltin());
  196. }
  197. else
  198. {
  199. //if destination mod was specified explicitly, restrict lookup to this mod
  200. if(request.remoteScope == CModHandler::scopeBuiltin() )
  201. {
  202. //built-in mod is an implicit dependency for all mods, allow access into it
  203. allowedScopes.insert(request.remoteScope);
  204. }
  205. else if ( request.localScope == CModHandler::scopeGame() )
  206. {
  207. // allow access, this is special scope that should have access to all in-game objects
  208. allowedScopes.insert(request.remoteScope);
  209. }
  210. else if(request.remoteScope == request.localScope )
  211. {
  212. // allow self-access
  213. allowedScopes.insert(request.remoteScope);
  214. }
  215. else
  216. {
  217. // allow access only if mod is in our dependencies
  218. auto myDeps = VLC->modh->getModDependencies(request.localScope, isValidScope);
  219. if(!isValidScope)
  220. return std::vector<ObjectData>();
  221. if(myDeps.count(request.remoteScope))
  222. allowedScopes.insert(request.remoteScope);
  223. }
  224. }
  225. std::string fullID = request.type + '.' + request.name;
  226. auto entries = registeredObjects.equal_range(fullID);
  227. if (entries.first != entries.second)
  228. {
  229. std::vector<ObjectData> locatedIDs;
  230. for (auto it = entries.first; it != entries.second; it++)
  231. {
  232. if (vstd::contains(allowedScopes, it->second.scope))
  233. {
  234. locatedIDs.push_back(it->second);
  235. }
  236. }
  237. return locatedIDs;
  238. }
  239. return std::vector<ObjectData>();
  240. }
  241. bool CIdentifierStorage::resolveIdentifier(const ObjectCallback & request)
  242. {
  243. auto identifiers = getPossibleIdentifiers(request);
  244. if (identifiers.size() == 1) // normally resolved ID
  245. {
  246. request.callback(identifiers.front().id);
  247. return true;
  248. }
  249. if (request.optional && identifiers.empty()) // failed to resolve optinal ID
  250. {
  251. return true;
  252. }
  253. // error found. Try to generate some debug info
  254. if(identifiers.empty())
  255. logMod->error("Unknown identifier!");
  256. else
  257. logMod->error("Ambiguous identifier request!");
  258. logMod->error("Request for %s.%s from mod %s", request.type, request.name, request.localScope);
  259. for(const auto & id : identifiers)
  260. {
  261. logMod->error("\tID is available in mod %s", id.scope);
  262. }
  263. return false;
  264. }
  265. void CIdentifierStorage::finalize()
  266. {
  267. state = FINALIZING;
  268. bool errorsFound = false;
  269. while ( !scheduledRequests.empty() )
  270. {
  271. // Use local copy since new requests may appear during resolving, invalidating any iterators
  272. auto request = scheduledRequests.back();
  273. scheduledRequests.pop_back();
  274. if (!resolveIdentifier(request))
  275. errorsFound = true;
  276. }
  277. if (errorsFound)
  278. {
  279. for(const auto & object : registeredObjects)
  280. {
  281. logMod->trace("%s : %s -> %d", object.second.scope, object.first, object.second.id);
  282. }
  283. logMod->error("All known identifiers were dumped into log file");
  284. }
  285. assert(errorsFound == false);
  286. state = FINISHED;
  287. }
  288. ContentTypeHandler::ContentTypeHandler(IHandlerBase * handler, const std::string & objectName):
  289. handler(handler),
  290. objectName(objectName),
  291. originalData(handler->loadLegacyData())
  292. {
  293. for(auto & node : originalData)
  294. {
  295. node.setMeta(CModHandler::scopeBuiltin());
  296. }
  297. }
  298. bool ContentTypeHandler::preloadModData(const std::string & modName, const std::vector<std::string> & fileList, bool validate)
  299. {
  300. bool result = false;
  301. JsonNode data = JsonUtils::assembleFromFiles(fileList, result);
  302. data.setMeta(modName);
  303. ModInfo & modInfo = modData[modName];
  304. for(auto entry : data.Struct())
  305. {
  306. size_t colon = entry.first.find(':');
  307. if (colon == std::string::npos)
  308. {
  309. // normal object, local to this mod
  310. modInfo.modData[entry.first].swap(entry.second);
  311. }
  312. else
  313. {
  314. std::string remoteName = entry.first.substr(0, colon);
  315. std::string objectName = entry.first.substr(colon + 1);
  316. // patching this mod? Send warning and continue - this situation can be handled normally
  317. if (remoteName == modName)
  318. logMod->warn("Redundant namespace definition for %s", objectName);
  319. logMod->trace("Patching object %s (%s) from %s", objectName, remoteName, modName);
  320. JsonNode & remoteConf = modData[remoteName].patches[objectName];
  321. JsonUtils::merge(remoteConf, entry.second);
  322. }
  323. }
  324. return result;
  325. }
  326. bool ContentTypeHandler::loadMod(const std::string & modName, bool validate)
  327. {
  328. ModInfo & modInfo = modData[modName];
  329. bool result = true;
  330. auto performValidate = [&,this](JsonNode & data, const std::string & name){
  331. handler->beforeValidate(data);
  332. if (validate)
  333. result &= JsonUtils::validate(data, "vcmi:" + objectName, name);
  334. };
  335. // apply patches
  336. if (!modInfo.patches.isNull())
  337. JsonUtils::merge(modInfo.modData, modInfo.patches);
  338. for(auto & entry : modInfo.modData.Struct())
  339. {
  340. const std::string & name = entry.first;
  341. JsonNode & data = entry.second;
  342. if (vstd::contains(data.Struct(), "index") && !data["index"].isNull())
  343. {
  344. if (modName != "core")
  345. logMod->warn("Mod %s is attempting to load original data! This should be reserved for built-in mod.", modName);
  346. // try to add H3 object data
  347. size_t index = static_cast<size_t>(data["index"].Float());
  348. if(originalData.size() > index)
  349. {
  350. logMod->trace("found original data in loadMod(%s) at index %d", name, index);
  351. JsonUtils::merge(originalData[index], data);
  352. std::swap(originalData[index], data);
  353. originalData[index].clear(); // do not use same data twice (same ID)
  354. }
  355. else
  356. {
  357. logMod->trace("no original data in loadMod(%s) at index %d", name, index);
  358. }
  359. performValidate(data, name);
  360. handler->loadObject(modName, name, data, index);
  361. }
  362. else
  363. {
  364. // normal new object
  365. logMod->trace("no index in loadMod(%s)", name);
  366. performValidate(data,name);
  367. handler->loadObject(modName, name, data);
  368. }
  369. }
  370. return result;
  371. }
  372. void ContentTypeHandler::loadCustom()
  373. {
  374. handler->loadCustom();
  375. }
  376. void ContentTypeHandler::afterLoadFinalization()
  377. {
  378. handler->afterLoadFinalization();
  379. }
  380. void CContentHandler::init()
  381. {
  382. handlers.insert(std::make_pair("heroClasses", ContentTypeHandler(&VLC->heroh->classes, "heroClass")));
  383. handlers.insert(std::make_pair("artifacts", ContentTypeHandler(VLC->arth, "artifact")));
  384. handlers.insert(std::make_pair("creatures", ContentTypeHandler(VLC->creh, "creature")));
  385. handlers.insert(std::make_pair("factions", ContentTypeHandler(VLC->townh, "faction")));
  386. handlers.insert(std::make_pair("objects", ContentTypeHandler(VLC->objtypeh, "object")));
  387. handlers.insert(std::make_pair("heroes", ContentTypeHandler(VLC->heroh, "hero")));
  388. handlers.insert(std::make_pair("spells", ContentTypeHandler(VLC->spellh, "spell")));
  389. handlers.insert(std::make_pair("skills", ContentTypeHandler(VLC->skillh, "skill")));
  390. handlers.insert(std::make_pair("templates", ContentTypeHandler(VLC->tplh, "template")));
  391. #if SCRIPTING_ENABLED
  392. handlers.insert(std::make_pair("scripts", ContentTypeHandler(VLC->scriptHandler, "script")));
  393. #endif
  394. handlers.insert(std::make_pair("battlefields", ContentTypeHandler(VLC->battlefieldsHandler, "battlefield")));
  395. handlers.insert(std::make_pair("terrains", ContentTypeHandler(VLC->terrainTypeHandler, "terrain")));
  396. handlers.insert(std::make_pair("rivers", ContentTypeHandler(VLC->riverTypeHandler, "river")));
  397. handlers.insert(std::make_pair("roads", ContentTypeHandler(VLC->roadTypeHandler, "road")));
  398. handlers.insert(std::make_pair("obstacles", ContentTypeHandler(VLC->obstacleHandler, "obstacle")));
  399. //TODO: any other types of moddables?
  400. }
  401. bool CContentHandler::preloadModData(const std::string & modName, JsonNode modConfig, bool validate)
  402. {
  403. bool result = true;
  404. for(auto & handler : handlers)
  405. {
  406. result &= handler.second.preloadModData(modName, modConfig[handler.first].convertTo<std::vector<std::string> >(), validate);
  407. }
  408. return result;
  409. }
  410. bool CContentHandler::loadMod(const std::string & modName, bool validate)
  411. {
  412. bool result = true;
  413. for(auto & handler : handlers)
  414. {
  415. result &= handler.second.loadMod(modName, validate);
  416. }
  417. return result;
  418. }
  419. void CContentHandler::loadCustom()
  420. {
  421. for(auto & handler : handlers)
  422. {
  423. handler.second.loadCustom();
  424. }
  425. }
  426. void CContentHandler::afterLoadFinalization()
  427. {
  428. for(auto & handler : handlers)
  429. {
  430. handler.second.afterLoadFinalization();
  431. }
  432. }
  433. void CContentHandler::preloadData(CModInfo & mod)
  434. {
  435. bool validate = (mod.validation != CModInfo::PASSED);
  436. // print message in format [<8-symbols checksum>] <modname>
  437. logMod->info("\t\t[%08x]%s", mod.checksum, mod.name);
  438. if (validate && mod.identifier != CModHandler::scopeBuiltin())
  439. {
  440. if (!JsonUtils::validate(mod.config, "vcmi:mod", mod.identifier))
  441. mod.validation = CModInfo::FAILED;
  442. }
  443. if (!preloadModData(mod.identifier, mod.config, validate))
  444. mod.validation = CModInfo::FAILED;
  445. }
  446. void CContentHandler::load(CModInfo & mod)
  447. {
  448. bool validate = (mod.validation != CModInfo::PASSED);
  449. if (!loadMod(mod.identifier, validate))
  450. mod.validation = CModInfo::FAILED;
  451. if (validate)
  452. {
  453. if (mod.validation != CModInfo::FAILED)
  454. logMod->info("\t\t[DONE] %s", mod.name);
  455. else
  456. logMod->error("\t\t[FAIL] %s", mod.name);
  457. }
  458. else
  459. logMod->info("\t\t[SKIP] %s", mod.name);
  460. }
  461. const ContentTypeHandler & CContentHandler::operator[](const std::string & name) const
  462. {
  463. return handlers.at(name);
  464. }
  465. static JsonNode loadModSettings(const std::string & path)
  466. {
  467. if (CResourceHandler::get("local")->existsResource(ResourceID(path)))
  468. {
  469. return JsonNode(ResourceID(path, EResType::TEXT));
  470. }
  471. // Probably new install. Create initial configuration
  472. CResourceHandler::get("local")->createResource(path);
  473. return JsonNode();
  474. }
  475. JsonNode addMeta(JsonNode config, const std::string & meta)
  476. {
  477. config.setMeta(meta);
  478. return config;
  479. }
  480. CModInfo::Version CModInfo::Version::GameVersion()
  481. {
  482. return Version(VCMI_VERSION_MAJOR, VCMI_VERSION_MINOR, VCMI_VERSION_PATCH);
  483. }
  484. CModInfo::Version CModInfo::Version::fromString(std::string from)
  485. {
  486. int major = 0;
  487. int minor = 0;
  488. int patch = 0;
  489. try
  490. {
  491. auto pointPos = from.find('.');
  492. major = std::stoi(from.substr(0, pointPos));
  493. if(pointPos != std::string::npos)
  494. {
  495. from = from.substr(pointPos + 1);
  496. pointPos = from.find('.');
  497. minor = std::stoi(from.substr(0, pointPos));
  498. if(pointPos != std::string::npos)
  499. patch = std::stoi(from.substr(pointPos + 1));
  500. }
  501. }
  502. catch(const std::invalid_argument &)
  503. {
  504. return Version();
  505. }
  506. return Version(major, minor, patch);
  507. }
  508. std::string CModInfo::Version::toString() const
  509. {
  510. return std::to_string(major) + '.' + std::to_string(minor) + '.' + std::to_string(patch);
  511. }
  512. bool CModInfo::Version::compatible(const Version & other, bool checkMinor, bool checkPatch) const
  513. {
  514. return (major == other.major &&
  515. (!checkMinor || minor >= other.minor) &&
  516. (!checkPatch || minor > other.minor || (minor == other.minor && patch >= other.patch)));
  517. }
  518. bool CModInfo::Version::isNull() const
  519. {
  520. return major == 0 && minor == 0 && patch == 0;
  521. }
  522. CModInfo::CModInfo():
  523. checksum(0),
  524. explicitlyEnabled(false),
  525. implicitlyEnabled(true),
  526. validation(PENDING)
  527. {
  528. }
  529. CModInfo::CModInfo(const std::string & identifier, const JsonNode & local, const JsonNode & config):
  530. identifier(identifier),
  531. name(config["name"].String()),
  532. description(config["description"].String()),
  533. dependencies(config["depends"].convertTo<std::set<std::string>>()),
  534. conflicts(config["conflicts"].convertTo<std::set<std::string>>()),
  535. checksum(0),
  536. explicitlyEnabled(false),
  537. implicitlyEnabled(true),
  538. validation(PENDING),
  539. config(addMeta(config, identifier))
  540. {
  541. version = Version::fromString(config["version"].String());
  542. if(!config["compatibility"].isNull())
  543. {
  544. vcmiCompatibleMin = Version::fromString(config["compatibility"]["min"].String());
  545. vcmiCompatibleMax = Version::fromString(config["compatibility"]["max"].String());
  546. }
  547. if (!config["language"].isNull())
  548. baseLanguage = config["language"].String();
  549. else
  550. baseLanguage = "english";
  551. loadLocalData(local);
  552. }
  553. JsonNode CModInfo::saveLocalData() const
  554. {
  555. std::ostringstream stream;
  556. stream << std::noshowbase << std::hex << std::setw(8) << std::setfill('0') << checksum;
  557. JsonNode conf;
  558. conf["active"].Bool() = explicitlyEnabled;
  559. conf["validated"].Bool() = validation != FAILED;
  560. conf["checksum"].String() = stream.str();
  561. return conf;
  562. }
  563. std::string CModInfo::getModDir(const std::string & name)
  564. {
  565. return "MODS/" + boost::algorithm::replace_all_copy(name, ".", "/MODS/");
  566. }
  567. std::string CModInfo::getModFile(const std::string & name)
  568. {
  569. return getModDir(name) + "/mod.json";
  570. }
  571. void CModInfo::updateChecksum(ui32 newChecksum)
  572. {
  573. // comment-out next line to force validation of all mods ignoring checksum
  574. if (newChecksum != checksum)
  575. {
  576. checksum = newChecksum;
  577. validation = PENDING;
  578. }
  579. }
  580. void CModInfo::loadLocalData(const JsonNode & data)
  581. {
  582. bool validated = false;
  583. implicitlyEnabled = true;
  584. explicitlyEnabled = true;
  585. checksum = 0;
  586. if (data.getType() == JsonNode::JsonType::DATA_BOOL)
  587. {
  588. explicitlyEnabled = data.Bool();
  589. }
  590. if (data.getType() == JsonNode::JsonType::DATA_STRUCT)
  591. {
  592. explicitlyEnabled = data["active"].Bool();
  593. validated = data["validated"].Bool();
  594. checksum = strtol(data["checksum"].String().c_str(), nullptr, 16);
  595. }
  596. //check compatibility
  597. implicitlyEnabled &= (vcmiCompatibleMin.isNull() || Version::GameVersion().compatible(vcmiCompatibleMin));
  598. implicitlyEnabled &= (vcmiCompatibleMax.isNull() || vcmiCompatibleMax.compatible(Version::GameVersion()));
  599. if(!implicitlyEnabled)
  600. logGlobal->warn("Mod %s is incompatible with current version of VCMI and cannot be enabled", name);
  601. if (boost::iequals(config["modType"].String(), "translation")) // compatibility code - mods use "Translation" type at the moment
  602. {
  603. if (baseLanguage != VLC->generaltexth->getPreferredLanguage())
  604. {
  605. logGlobal->warn("Translation mod %s was not loaded: language mismatch!", name);
  606. implicitlyEnabled = false;
  607. }
  608. }
  609. if (isEnabled())
  610. validation = validated ? PASSED : PENDING;
  611. else
  612. validation = validated ? PASSED : FAILED;
  613. }
  614. bool CModInfo::isEnabled() const
  615. {
  616. return implicitlyEnabled && explicitlyEnabled;
  617. }
  618. void CModInfo::setEnabled(bool on)
  619. {
  620. explicitlyEnabled = on;
  621. }
  622. CModHandler::CModHandler() : content(std::make_shared<CContentHandler>())
  623. {
  624. for (int i = 0; i < GameConstants::RESOURCE_QUANTITY; ++i)
  625. {
  626. identifiers.registerObject(CModHandler::scopeBuiltin(), "resource", GameConstants::RESOURCE_NAMES[i], i);
  627. }
  628. for(int i=0; i<GameConstants::PRIMARY_SKILLS; ++i)
  629. {
  630. identifiers.registerObject(CModHandler::scopeBuiltin(), "primSkill", PrimarySkill::names[i], i);
  631. identifiers.registerObject(CModHandler::scopeBuiltin(), "primarySkill", PrimarySkill::names[i], i);
  632. }
  633. }
  634. // currentList is passed by value to get current list of depending mods
  635. bool CModHandler::hasCircularDependency(const TModID & modID, std::set<TModID> currentList) const
  636. {
  637. const CModInfo & mod = allMods.at(modID);
  638. // Mod already present? We found a loop
  639. if (vstd::contains(currentList, modID))
  640. {
  641. logMod->error("Error: Circular dependency detected! Printing dependency list:");
  642. logMod->error("\t%s -> ", mod.name);
  643. return true;
  644. }
  645. currentList.insert(modID);
  646. // recursively check every dependency of this mod
  647. for(const TModID & dependency : mod.dependencies)
  648. {
  649. if (hasCircularDependency(dependency, currentList))
  650. {
  651. logMod->error("\t%s ->\n", mod.name); // conflict detected, print dependency list
  652. return true;
  653. }
  654. }
  655. return false;
  656. }
  657. // Returned vector affects the resource loaders call order (see CFilesystemList::load).
  658. // The loaders call order matters when dependent mod overrides resources in its dependencies.
  659. std::vector <TModID> CModHandler::validateAndSortDependencies(std::vector <TModID> modsToResolve) const
  660. {
  661. // Topological sort algorithm.
  662. // TODO: Investigate possible ways to improve performance.
  663. boost::range::sort(modsToResolve); // Sort mods per name
  664. std::vector <TModID> sortedValidMods; // Vector keeps order of elements (LIFO)
  665. sortedValidMods.reserve(modsToResolve.size()); // push_back calls won't cause memory reallocation
  666. std::set <TModID> resolvedModIDs; // Use a set for validation for performance reason, but set does not keep order of elements
  667. // Mod is resolved if it has not dependencies or all its dependencies are already resolved
  668. auto isResolved = [&](const CModInfo & mod) -> CModInfo::EValidationStatus
  669. {
  670. if(mod.dependencies.size() > resolvedModIDs.size())
  671. return CModInfo::PENDING;
  672. for(const TModID & dependency : mod.dependencies)
  673. {
  674. if(!vstd::contains(resolvedModIDs, dependency))
  675. return CModInfo::PENDING;
  676. }
  677. return CModInfo::PASSED;
  678. };
  679. while(true)
  680. {
  681. std::set <TModID> resolvedOnCurrentTreeLevel;
  682. for(auto it = modsToResolve.begin(); it != modsToResolve.end();) // One iteration - one level of mods tree
  683. {
  684. if(isResolved(allMods.at(*it)) == CModInfo::PASSED)
  685. {
  686. resolvedOnCurrentTreeLevel.insert(*it); // Not to the resolvedModIDs, so current node childs will be resolved on the next iteration
  687. sortedValidMods.push_back(*it);
  688. it = modsToResolve.erase(it);
  689. continue;
  690. }
  691. it++;
  692. }
  693. if(!resolvedOnCurrentTreeLevel.empty())
  694. {
  695. resolvedModIDs.insert(resolvedOnCurrentTreeLevel.begin(), resolvedOnCurrentTreeLevel.end());
  696. continue;
  697. }
  698. // If there're no valid mods on the current mods tree level, no more mod can be resolved, should be end.
  699. break;
  700. }
  701. // Left mods have unresolved dependencies, output all to log.
  702. for(const auto & brokenModID : modsToResolve)
  703. {
  704. const CModInfo & brokenMod = allMods.at(brokenModID);
  705. for(const TModID & dependency : brokenMod.dependencies)
  706. {
  707. if(!vstd::contains(resolvedModIDs, dependency))
  708. logMod->error("Mod '%s' will not work: it depends on mod '%s', which is not installed.", brokenMod.name, dependency);
  709. }
  710. }
  711. return sortedValidMods;
  712. }
  713. std::vector<std::string> CModHandler::getModList(const std::string & path) const
  714. {
  715. std::string modDir = boost::to_upper_copy(path + "MODS/");
  716. size_t depth = boost::range::count(modDir, '/');
  717. auto list = CResourceHandler::get("initial")->getFilteredFiles([&](const ResourceID & id) -> bool
  718. {
  719. if (id.getType() != EResType::DIRECTORY)
  720. return false;
  721. if (!boost::algorithm::starts_with(id.getName(), modDir))
  722. return false;
  723. if (boost::range::count(id.getName(), '/') != depth )
  724. return false;
  725. return true;
  726. });
  727. //storage for found mods
  728. std::vector<std::string> foundMods;
  729. for(const auto & entry : list)
  730. {
  731. std::string name = entry.getName();
  732. name.erase(0, modDir.size()); //Remove path prefix
  733. if (!name.empty())
  734. foundMods.push_back(name);
  735. }
  736. return foundMods;
  737. }
  738. bool CModHandler::isScopeReserved(const TModID & scope)
  739. {
  740. //following scopes are reserved - either in use by mod system or by filesystem
  741. static const std::array<TModID, 9> reservedScopes = {
  742. "core", "map", "game", "root", "saves", "config", "local", "initial", "mapEditor"
  743. };
  744. return std::find(reservedScopes.begin(), reservedScopes.end(), scope) != reservedScopes.end();
  745. }
  746. const TModID & CModHandler::scopeBuiltin()
  747. {
  748. static const TModID scope = "core";
  749. return scope;
  750. }
  751. const TModID & CModHandler::scopeGame()
  752. {
  753. static const TModID scope = "game";
  754. return scope;
  755. }
  756. const TModID & CModHandler::scopeMap()
  757. {
  758. //TODO: implement accessing map dependencies for both H3 and VCMI maps
  759. // for now, allow access to any identifiers
  760. static const TModID scope = "game";
  761. return scope;
  762. }
  763. void CModHandler::loadMods(const std::string & path, const std::string & parent, const JsonNode & modSettings, bool enableMods)
  764. {
  765. for(const std::string & modName : getModList(path))
  766. loadOneMod(modName, parent, modSettings, enableMods);
  767. }
  768. void CModHandler::loadOneMod(std::string modName, const std::string & parent, const JsonNode & modSettings, bool enableMods)
  769. {
  770. boost::to_lower(modName);
  771. std::string modFullName = parent.empty() ? modName : parent + '.' + modName;
  772. if ( isScopeReserved(modFullName))
  773. {
  774. logMod->error("Can not load mod %s - this name is reserved for internal use!", modFullName);
  775. return;
  776. }
  777. if(CResourceHandler::get("initial")->existsResource(ResourceID(CModInfo::getModFile(modFullName))))
  778. {
  779. CModInfo mod(modFullName, modSettings[modName], JsonNode(ResourceID(CModInfo::getModFile(modFullName))));
  780. if (!parent.empty()) // this is submod, add parent to dependencies
  781. mod.dependencies.insert(parent);
  782. allMods[modFullName] = mod;
  783. if (mod.isEnabled() && enableMods)
  784. activeMods.push_back(modFullName);
  785. loadMods(CModInfo::getModDir(modFullName) + '/', modFullName, modSettings[modName]["mods"], enableMods && mod.isEnabled());
  786. }
  787. }
  788. void CModHandler::loadMods(bool onlyEssential)
  789. {
  790. JsonNode modConfig;
  791. if(onlyEssential)
  792. {
  793. loadOneMod("vcmi", "", modConfig, true);//only vcmi and submods
  794. }
  795. else
  796. {
  797. modConfig = loadModSettings("config/modSettings.json");
  798. loadMods("", "", modConfig["activeMods"], true);
  799. }
  800. coreMod = CModInfo(CModHandler::scopeBuiltin(), modConfig[CModHandler::scopeBuiltin()], JsonNode(ResourceID("config/gameConfig.json")));
  801. coreMod.name = "Original game files";
  802. }
  803. std::vector<std::string> CModHandler::getAllMods()
  804. {
  805. std::vector<std::string> modlist;
  806. modlist.reserve(allMods.size());
  807. for (auto & entry : allMods)
  808. modlist.push_back(entry.first);
  809. return modlist;
  810. }
  811. std::vector<std::string> CModHandler::getActiveMods()
  812. {
  813. return activeMods;
  814. }
  815. static JsonNode genDefaultFS()
  816. {
  817. // default FS config for mods: directory "Content" that acts as H3 root directory
  818. JsonNode defaultFS;
  819. defaultFS[""].Vector().resize(2);
  820. defaultFS[""].Vector()[0]["type"].String() = "zip";
  821. defaultFS[""].Vector()[0]["path"].String() = "/Content.zip";
  822. defaultFS[""].Vector()[1]["type"].String() = "dir";
  823. defaultFS[""].Vector()[1]["path"].String() = "/Content";
  824. return defaultFS;
  825. }
  826. static ISimpleResourceLoader * genModFilesystem(const std::string & modName, const JsonNode & conf)
  827. {
  828. static const JsonNode defaultFS = genDefaultFS();
  829. if (!conf["filesystem"].isNull())
  830. return CResourceHandler::createFileSystem(CModInfo::getModDir(modName), conf["filesystem"]);
  831. else
  832. return CResourceHandler::createFileSystem(CModInfo::getModDir(modName), defaultFS);
  833. }
  834. static ui32 calculateModChecksum(const std::string & modName, ISimpleResourceLoader * filesystem)
  835. {
  836. boost::crc_32_type modChecksum;
  837. // first - add current VCMI version into checksum to force re-validation on VCMI updates
  838. modChecksum.process_bytes(reinterpret_cast<const void*>(GameConstants::VCMI_VERSION.data()), GameConstants::VCMI_VERSION.size());
  839. // second - add mod.json into checksum because filesystem does not contains this file
  840. // FIXME: remove workaround for core mod
  841. if (modName != CModHandler::scopeBuiltin())
  842. {
  843. ResourceID modConfFile(CModInfo::getModFile(modName), EResType::TEXT);
  844. ui32 configChecksum = CResourceHandler::get("initial")->load(modConfFile)->calculateCRC32();
  845. modChecksum.process_bytes(reinterpret_cast<const void *>(&configChecksum), sizeof(configChecksum));
  846. }
  847. // third - add all detected text files from this mod into checksum
  848. auto files = filesystem->getFilteredFiles([](const ResourceID & resID)
  849. {
  850. return resID.getType() == EResType::TEXT &&
  851. ( boost::starts_with(resID.getName(), "DATA") ||
  852. boost::starts_with(resID.getName(), "CONFIG"));
  853. });
  854. for (const ResourceID & file : files)
  855. {
  856. ui32 fileChecksum = filesystem->load(file)->calculateCRC32();
  857. modChecksum.process_bytes(reinterpret_cast<const void *>(&fileChecksum), sizeof(fileChecksum));
  858. }
  859. return modChecksum.checksum();
  860. }
  861. void CModHandler::loadModFilesystems()
  862. {
  863. CGeneralTextHandler::detectInstallParameters();
  864. activeMods = validateAndSortDependencies(activeMods);
  865. coreMod.updateChecksum(calculateModChecksum(CModHandler::scopeBuiltin(), CResourceHandler::get(CModHandler::scopeBuiltin())));
  866. for(std::string & modName : activeMods)
  867. {
  868. CModInfo & mod = allMods[modName];
  869. CResourceHandler::addFilesystem("data", modName, genModFilesystem(modName, mod.config));
  870. }
  871. }
  872. TModID CModHandler::findResourceOrigin(const ResourceID & name)
  873. {
  874. for(const auto & modID : boost::adaptors::reverse(activeMods))
  875. {
  876. if(CResourceHandler::get(modID)->existsResource(name))
  877. return modID;
  878. }
  879. if(CResourceHandler::get("core")->existsResource(name))
  880. return "core";
  881. if(CResourceHandler::get("mapEditor")->existsResource(name))
  882. return "core"; // Workaround for loading maps via map editor
  883. assert(0);
  884. return "";
  885. }
  886. std::string CModHandler::getModLanguage(const TModID& modId) const
  887. {
  888. if ( modId == "core")
  889. return VLC->generaltexth->getInstalledLanguage();
  890. return allMods.at(modId).baseLanguage;
  891. }
  892. std::set<TModID> CModHandler::getModDependencies(const TModID & modId, bool & isModFound) const
  893. {
  894. auto it = allMods.find(modId);
  895. isModFound = (it != allMods.end());
  896. if(isModFound)
  897. return it->second.dependencies;
  898. logMod->error("Mod not found: '%s'", modId);
  899. return {};
  900. }
  901. void CModHandler::initializeConfig()
  902. {
  903. VLC->settingsHandler->load(coreMod.config["settings"]);
  904. for(const TModID & modName : activeMods)
  905. {
  906. const auto & mod = allMods[modName];
  907. VLC->settingsHandler->load(mod.config["settings"]);
  908. }
  909. }
  910. bool CModHandler::validateTranslations(TModID modName) const
  911. {
  912. bool result = true;
  913. const auto & mod = allMods.at(modName);
  914. {
  915. auto fileList = mod.config["translations"].convertTo<std::vector<std::string> >();
  916. JsonNode json = JsonUtils::assembleFromFiles(fileList);
  917. result |= VLC->generaltexth->validateTranslation(mod.baseLanguage, modName, json);
  918. }
  919. for(const auto & language : Languages::getLanguageList())
  920. {
  921. if (!language.hasTranslation)
  922. continue;
  923. if (mod.config[language.identifier].isNull())
  924. continue;
  925. if (mod.config[language.identifier]["skipValidation"].Bool())
  926. continue;
  927. auto fileList = mod.config[language.identifier]["translations"].convertTo<std::vector<std::string> >();
  928. JsonNode json = JsonUtils::assembleFromFiles(fileList);
  929. result |= VLC->generaltexth->validateTranslation(language.identifier, modName, json);
  930. }
  931. return result;
  932. }
  933. void CModHandler::loadTranslation(const TModID & modName)
  934. {
  935. const auto & mod = allMods[modName];
  936. std::string preferredLanguage = VLC->generaltexth->getPreferredLanguage();
  937. std::string modBaseLanguage = allMods[modName].baseLanguage;
  938. auto baseTranslationList = mod.config["translations"].convertTo<std::vector<std::string> >();
  939. auto extraTranslationList = mod.config[preferredLanguage]["translations"].convertTo<std::vector<std::string> >();
  940. JsonNode baseTranslation = JsonUtils::assembleFromFiles(baseTranslationList);
  941. JsonNode extraTranslation = JsonUtils::assembleFromFiles(extraTranslationList);
  942. VLC->generaltexth->loadTranslationOverrides(modBaseLanguage, modName, baseTranslation);
  943. VLC->generaltexth->loadTranslationOverrides(preferredLanguage, modName, extraTranslation);
  944. }
  945. void CModHandler::load()
  946. {
  947. CStopWatch totalTime;
  948. CStopWatch timer;
  949. logMod->info("\tInitializing content handler: %d ms", timer.getDiff());
  950. content->init();
  951. for(const TModID & modName : activeMods)
  952. {
  953. logMod->trace("Generating checksum for %s", modName);
  954. allMods[modName].updateChecksum(calculateModChecksum(modName, CResourceHandler::get(modName)));
  955. }
  956. // first - load virtual builtin mod that contains all data
  957. // TODO? move all data into real mods? RoE, AB, SoD, WoG
  958. content->preloadData(coreMod);
  959. for(const TModID & modName : activeMods)
  960. content->preloadData(allMods[modName]);
  961. logMod->info("\tParsing mod data: %d ms", timer.getDiff());
  962. content->load(coreMod);
  963. for(const TModID & modName : activeMods)
  964. content->load(allMods[modName]);
  965. #if SCRIPTING_ENABLED
  966. VLC->scriptHandler->performRegistration(VLC);//todo: this should be done before any other handlers load
  967. #endif
  968. content->loadCustom();
  969. for(const TModID & modName : activeMods)
  970. loadTranslation(modName);
  971. for(const TModID & modName : activeMods)
  972. if (!validateTranslations(modName))
  973. allMods[modName].validation = CModInfo::FAILED;
  974. logMod->info("\tLoading mod data: %d ms", timer.getDiff());
  975. VLC->creh->loadCrExpBon();
  976. VLC->creh->buildBonusTreeForTiers(); //do that after all new creatures are loaded
  977. identifiers.finalize();
  978. logMod->info("\tResolving identifiers: %d ms", timer.getDiff());
  979. content->afterLoadFinalization();
  980. logMod->info("\tHandlers post-load finalization: %d ms ", timer.getDiff());
  981. logMod->info("\tAll game content loaded in %d ms", totalTime.getDiff());
  982. }
  983. void CModHandler::afterLoad(bool onlyEssential)
  984. {
  985. JsonNode modSettings;
  986. for (auto & modEntry : allMods)
  987. {
  988. std::string pointer = "/" + boost::algorithm::replace_all_copy(modEntry.first, ".", "/mods/");
  989. modSettings["activeMods"].resolvePointer(pointer) = modEntry.second.saveLocalData();
  990. }
  991. modSettings[CModHandler::scopeBuiltin()] = coreMod.saveLocalData();
  992. if(!onlyEssential)
  993. {
  994. FileStream file(*CResourceHandler::get()->getResourceName(ResourceID("config/modSettings.json")), std::ofstream::out | std::ofstream::trunc);
  995. file << modSettings.toJson();
  996. }
  997. }
  998. std::string CModHandler::normalizeIdentifier(const std::string & scope, const std::string & remoteScope, const std::string & identifier)
  999. {
  1000. auto p = vstd::splitStringToPair(identifier, ':');
  1001. if(p.first.empty())
  1002. p.first = scope;
  1003. if(p.first == remoteScope)
  1004. p.first.clear();
  1005. return p.first.empty() ? p.second : p.first + ":" + p.second;
  1006. }
  1007. void CModHandler::parseIdentifier(const std::string & fullIdentifier, std::string & scope, std::string & type, std::string & identifier)
  1008. {
  1009. auto p = vstd::splitStringToPair(fullIdentifier, ':');
  1010. scope = p.first;
  1011. auto p2 = vstd::splitStringToPair(p.second, '.');
  1012. if(!p2.first.empty())
  1013. {
  1014. type = p2.first;
  1015. identifier = p2.second;
  1016. }
  1017. else
  1018. {
  1019. type = p.second;
  1020. identifier.clear();
  1021. }
  1022. }
  1023. std::string CModHandler::makeFullIdentifier(const std::string & scope, const std::string & type, const std::string & identifier)
  1024. {
  1025. if(type.empty())
  1026. logGlobal->error("Full identifier (%s %s) requires type name", scope, identifier);
  1027. std::string actualScope = scope;
  1028. std::string actualName = identifier;
  1029. //ignore scope if identifier is scoped
  1030. auto scopeAndName = vstd::splitStringToPair(identifier, ':');
  1031. if(!scopeAndName.first.empty())
  1032. {
  1033. actualScope = scopeAndName.first;
  1034. actualName = scopeAndName.second;
  1035. }
  1036. if(actualScope.empty())
  1037. {
  1038. return actualName.empty() ? type : type + "." + actualName;
  1039. }
  1040. else
  1041. {
  1042. return actualName.empty() ? actualScope+ ":" + type : actualScope + ":" + type + "." + actualName;
  1043. }
  1044. }
  1045. VCMI_LIB_NAMESPACE_END