2012-08-10 16:07:53 +03:00
|
|
|
#include "StdInc.h"
|
|
|
|
#include "CModHandler.h"
|
2012-09-20 21:41:16 +03:00
|
|
|
#include "CDefObjInfoHandler.h"
|
2012-08-11 12:06:23 +03:00
|
|
|
#include "JsonNode.h"
|
2013-07-28 17:49:50 +03:00
|
|
|
#include "filesystem/Filesystem.h"
|
2013-12-29 14:27:38 +03:00
|
|
|
#include "filesystem/AdapterLoaders.h"
|
|
|
|
#include "filesystem/CFilesystemLoader.h"
|
2012-12-03 19:00:17 +03:00
|
|
|
|
2012-12-15 11:47:02 +03:00
|
|
|
#include "CCreatureHandler.h"
|
|
|
|
#include "CArtHandler.h"
|
|
|
|
#include "CTownHandler.h"
|
|
|
|
#include "CHeroHandler.h"
|
2012-12-19 19:35:58 +03:00
|
|
|
#include "CObjectHandler.h"
|
2012-12-26 12:46:09 +03:00
|
|
|
#include "StringConstants.h"
|
2013-04-21 15:49:26 +03:00
|
|
|
#include "CStopWatch.h"
|
|
|
|
#include "IHandlerBase.h"
|
2014-03-07 16:21:09 +03:00
|
|
|
#include "CSpellHandler.h"
|
2012-12-15 11:47:02 +03:00
|
|
|
|
2012-08-10 16:07:53 +03:00
|
|
|
/*
|
2013-03-06 21:49:56 +03:00
|
|
|
* CModHandler.cpp, part of VCMI engine
|
2012-08-10 16:07:53 +03:00
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-12-22 19:47:12 +03:00
|
|
|
void CIdentifierStorage::checkIdentifier(std::string & ID)
|
|
|
|
{
|
|
|
|
if (boost::algorithm::ends_with(ID, "."))
|
2013-04-09 17:31:36 +03:00
|
|
|
logGlobal->warnStream() << "BIG WARNING: identifier " << ID << " seems to be broken!";
|
2012-12-22 19:47:12 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
size_t pos = 0;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (std::tolower(ID[pos]) != ID[pos] ) //Not in camelCase
|
|
|
|
{
|
2013-04-09 17:31:36 +03:00
|
|
|
logGlobal->warnStream() << "Warning: identifier " << ID << " is not in camelCase!";
|
2012-12-22 19:47:12 +03:00
|
|
|
ID[pos] = std::tolower(ID[pos]);// Try to fix the ID
|
|
|
|
}
|
|
|
|
pos = ID.find('.', pos);
|
|
|
|
}
|
|
|
|
while(pos++ != std::string::npos);
|
|
|
|
}
|
|
|
|
}
|
2012-08-10 16:07:53 +03:00
|
|
|
|
2013-04-25 17:03:35 +03:00
|
|
|
CIdentifierStorage::ObjectCallback::ObjectCallback(std::string localScope, std::string remoteScope, std::string type,
|
2013-12-02 14:58:02 +03:00
|
|
|
std::string name, const std::function<void(si32)> & callback, bool optional):
|
2013-04-25 17:03:35 +03:00
|
|
|
localScope(localScope),
|
|
|
|
remoteScope(remoteScope),
|
|
|
|
type(type),
|
|
|
|
name(name),
|
2013-12-02 14:58:02 +03:00
|
|
|
callback(callback),
|
|
|
|
optional(optional)
|
2013-04-25 17:03:35 +03:00
|
|
|
{}
|
|
|
|
|
|
|
|
static std::pair<std::string, std::string> splitString(std::string input, char separator)
|
2012-12-03 19:00:17 +03:00
|
|
|
{
|
2013-04-25 17:03:35 +03:00
|
|
|
std::pair<std::string, std::string> ret;
|
|
|
|
size_t splitPos = input.find(separator);
|
2012-12-22 19:47:12 +03:00
|
|
|
|
2013-04-25 17:03:35 +03:00
|
|
|
if (splitPos == std::string::npos)
|
|
|
|
{
|
|
|
|
ret.first.clear();
|
|
|
|
ret.second = input;
|
|
|
|
}
|
2012-12-03 19:00:17 +03:00
|
|
|
else
|
2013-02-25 12:48:26 +03:00
|
|
|
{
|
2013-04-25 17:03:35 +03:00
|
|
|
ret.first = input.substr(0, splitPos);
|
|
|
|
ret.second = input.substr(splitPos + 1);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CIdentifierStorage::requestIdentifier(ObjectCallback callback)
|
|
|
|
{
|
|
|
|
checkIdentifier(callback.type);
|
|
|
|
checkIdentifier(callback.name);
|
2013-02-25 12:48:26 +03:00
|
|
|
|
2013-04-25 17:03:35 +03:00
|
|
|
assert(!callback.localScope.empty());
|
2013-04-21 15:49:26 +03:00
|
|
|
|
2013-04-25 17:03:35 +03:00
|
|
|
scheduledRequests.push_back(callback);
|
|
|
|
}
|
|
|
|
|
2013-06-26 14:18:27 +03:00
|
|
|
void CIdentifierStorage::requestIdentifier(std::string scope, std::string type, std::string name, const std::function<void(si32)> & callback)
|
2013-04-25 17:03:35 +03:00
|
|
|
{
|
|
|
|
auto pair = splitString(name, ':'); // remoteScope:name
|
|
|
|
|
2013-12-02 14:58:02 +03:00
|
|
|
requestIdentifier(ObjectCallback(scope, pair.first, type, pair.second, callback, false));
|
2013-04-25 17:03:35 +03:00
|
|
|
}
|
|
|
|
|
2013-06-26 14:18:27 +03:00
|
|
|
void CIdentifierStorage::requestIdentifier(std::string type, const JsonNode & name, const std::function<void(si32)> & callback)
|
2013-04-25 17:03:35 +03:00
|
|
|
{
|
|
|
|
auto pair = splitString(name.String(), ':'); // remoteScope:name
|
|
|
|
|
2013-12-02 14:58:02 +03:00
|
|
|
requestIdentifier(ObjectCallback(name.meta, pair.first, type, pair.second, callback, false));
|
2013-04-25 17:03:35 +03:00
|
|
|
}
|
|
|
|
|
2013-06-26 14:18:27 +03:00
|
|
|
void CIdentifierStorage::requestIdentifier(const JsonNode & name, const std::function<void(si32)> & callback)
|
2013-04-25 17:03:35 +03:00
|
|
|
{
|
|
|
|
auto pair = splitString(name.String(), ':'); // remoteScope:<type.name>
|
|
|
|
auto pair2 = splitString(pair.second, '.'); // type.name
|
|
|
|
|
2013-12-02 14:58:02 +03:00
|
|
|
requestIdentifier(ObjectCallback(name.meta, pair.first, pair2.first, pair2.second, callback, false));
|
|
|
|
}
|
|
|
|
|
|
|
|
void CIdentifierStorage::tryRequestIdentifier(std::string scope, std::string type, std::string name, const std::function<void(si32)> & callback)
|
|
|
|
{
|
|
|
|
auto pair = splitString(name, ':'); // remoteScope:name
|
|
|
|
|
|
|
|
requestIdentifier(ObjectCallback(scope, pair.first, type, pair.second, callback, true));
|
|
|
|
}
|
|
|
|
|
|
|
|
void CIdentifierStorage::tryRequestIdentifier(std::string type, const JsonNode & name, const std::function<void(si32)> & callback)
|
|
|
|
{
|
|
|
|
auto pair = splitString(name.String(), ':'); // remoteScope:name
|
|
|
|
|
|
|
|
requestIdentifier(ObjectCallback(name.meta, pair.first, type, pair.second, callback, true));
|
|
|
|
}
|
|
|
|
|
|
|
|
boost::optional<si32> CIdentifierStorage::getIdentifier(std::string type, const JsonNode & name, bool silent)
|
|
|
|
{
|
|
|
|
auto pair = splitString(name.String(), ':'); // remoteScope:name
|
2013-12-31 02:09:58 +03:00
|
|
|
auto idList = getPossibleIdentifiers(ObjectCallback(name.meta, pair.first, type, pair.second, std::function<void(si32)>(), silent));
|
2013-12-02 14:58:02 +03:00
|
|
|
|
|
|
|
if (idList.size() == 1)
|
|
|
|
return idList.front().id;
|
|
|
|
if (!silent)
|
|
|
|
logGlobal->errorStream() << "Failed to resolve identifier " << name.String() << " from mod " << type;
|
|
|
|
|
|
|
|
return boost::optional<si32>();
|
2012-12-03 19:00:17 +03:00
|
|
|
}
|
|
|
|
|
2013-12-31 02:09:58 +03:00
|
|
|
boost::optional<si32> CIdentifierStorage::getIdentifier(const JsonNode & name, bool silent)
|
|
|
|
{
|
|
|
|
auto pair = splitString(name.String(), ':'); // remoteScope:<type.name>
|
|
|
|
auto pair2 = splitString(pair.second, '.'); // type.name
|
|
|
|
auto idList = getPossibleIdentifiers(ObjectCallback(name.meta, pair.first, pair2.first, pair2.second, std::function<void(si32)>(), silent));
|
|
|
|
|
|
|
|
if (idList.size() == 1)
|
|
|
|
return idList.front().id;
|
|
|
|
if (!silent)
|
2014-02-02 14:05:05 +03:00
|
|
|
logGlobal->errorStream() << "Failed to resolve identifier " << name.String() << " from mod " << name.meta;
|
2013-12-31 02:09:58 +03:00
|
|
|
|
|
|
|
return boost::optional<si32>();
|
|
|
|
}
|
|
|
|
|
2013-04-21 15:49:26 +03:00
|
|
|
void CIdentifierStorage::registerObject(std::string scope, std::string type, std::string name, si32 identifier)
|
2012-12-03 19:00:17 +03:00
|
|
|
{
|
2013-04-25 17:03:35 +03:00
|
|
|
ObjectData data;
|
|
|
|
data.scope = scope;
|
|
|
|
data.id = identifier;
|
|
|
|
|
2013-04-21 15:49:26 +03:00
|
|
|
std::string fullID = type + '.' + name;
|
|
|
|
checkIdentifier(fullID);
|
2012-12-22 19:47:12 +03:00
|
|
|
|
2013-04-25 17:03:35 +03:00
|
|
|
registeredObjects.insert(std::make_pair(fullID, data));
|
|
|
|
}
|
|
|
|
|
2013-12-31 02:09:58 +03:00
|
|
|
std::vector<CIdentifierStorage::ObjectData> CIdentifierStorage::getPossibleIdentifiers(const ObjectCallback & request)
|
2013-04-25 17:03:35 +03:00
|
|
|
{
|
|
|
|
std::set<std::string> allowedScopes;
|
|
|
|
|
|
|
|
if (request.remoteScope.empty())
|
|
|
|
{
|
|
|
|
// normally ID's from all required mods, own mod and virtual "core" mod are allowed
|
2013-12-31 02:09:58 +03:00
|
|
|
if (request.localScope != "core" && request.localScope != "")
|
2013-04-25 17:03:35 +03:00
|
|
|
allowedScopes = VLC->modh->getModData(request.localScope).dependencies;
|
|
|
|
|
|
|
|
allowedScopes.insert(request.localScope);
|
|
|
|
allowedScopes.insert("core");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-05-22 01:11:44 +03:00
|
|
|
//...unless destination mod was specified explicitly
|
|
|
|
auto myDeps = VLC->modh->getModData(request.localScope).dependencies;
|
|
|
|
if (request.remoteScope == "core" || // allow only available to all core mod
|
|
|
|
myDeps.count(request.remoteScope)) // or dependencies
|
|
|
|
allowedScopes.insert(request.remoteScope);
|
2013-04-25 17:03:35 +03:00
|
|
|
}
|
2012-12-03 19:00:17 +03:00
|
|
|
|
2013-04-25 17:03:35 +03:00
|
|
|
std::string fullID = request.type + '.' + request.name;
|
2012-12-03 19:00:17 +03:00
|
|
|
|
2013-04-25 17:03:35 +03:00
|
|
|
auto entries = registeredObjects.equal_range(fullID);
|
|
|
|
if (entries.first != entries.second)
|
2012-12-03 19:00:17 +03:00
|
|
|
{
|
2013-12-02 14:58:02 +03:00
|
|
|
std::vector<ObjectData> locatedIDs;
|
2013-09-21 21:29:26 +03:00
|
|
|
|
2013-04-25 17:03:35 +03:00
|
|
|
for (auto it = entries.first; it != entries.second; it++)
|
|
|
|
{
|
|
|
|
if (vstd::contains(allowedScopes, it->second.scope))
|
|
|
|
{
|
2013-12-02 14:58:02 +03:00
|
|
|
locatedIDs.push_back(it->second);
|
2013-04-25 17:03:35 +03:00
|
|
|
}
|
|
|
|
}
|
2013-12-02 14:58:02 +03:00
|
|
|
return locatedIDs;
|
|
|
|
}
|
|
|
|
return std::vector<ObjectData>();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CIdentifierStorage::resolveIdentifier(const ObjectCallback & request)
|
|
|
|
{
|
2013-12-31 02:09:58 +03:00
|
|
|
auto identifiers = getPossibleIdentifiers(request);
|
2013-12-02 14:58:02 +03:00
|
|
|
if (identifiers.size() == 1) // normally resolved ID
|
|
|
|
{
|
|
|
|
request.callback(identifiers.front().id);
|
|
|
|
return true;
|
|
|
|
}
|
2013-04-25 17:03:35 +03:00
|
|
|
|
2013-12-02 14:58:02 +03:00
|
|
|
if (request.optional && identifiers.empty()) // failed to resolve optinal ID
|
|
|
|
return true;
|
2013-09-21 21:29:26 +03:00
|
|
|
|
2013-12-02 14:58:02 +03:00
|
|
|
// error found. Try to generate some debug info
|
|
|
|
if (identifiers.size() == 0)
|
|
|
|
logGlobal->errorStream() << "Unknown identifier!";
|
|
|
|
else
|
|
|
|
logGlobal->errorStream() << "Ambiguous identifier request!";
|
2013-09-21 21:29:26 +03:00
|
|
|
|
2013-12-02 14:58:02 +03:00
|
|
|
logGlobal->errorStream() << "Request for " << request.type << "." << request.name << " from mod " << request.localScope;
|
2013-09-21 21:29:26 +03:00
|
|
|
|
2013-12-02 14:58:02 +03:00
|
|
|
for (auto id : identifiers)
|
|
|
|
{
|
|
|
|
logGlobal->errorStream() << "\tID is available in mod " << id.scope;
|
2013-04-25 17:03:35 +03:00
|
|
|
}
|
|
|
|
return false;
|
2012-12-03 19:00:17 +03:00
|
|
|
}
|
|
|
|
|
2013-04-21 15:49:26 +03:00
|
|
|
void CIdentifierStorage::finalize()
|
2012-12-03 19:00:17 +03:00
|
|
|
{
|
2013-04-25 17:03:35 +03:00
|
|
|
bool errorsFound = false;
|
|
|
|
|
2013-06-29 16:05:48 +03:00
|
|
|
for(const ObjectCallback & request : scheduledRequests)
|
2013-04-21 15:49:26 +03:00
|
|
|
{
|
2013-04-25 17:03:35 +03:00
|
|
|
errorsFound |= !resolveIdentifier(request);
|
2013-04-21 15:49:26 +03:00
|
|
|
}
|
|
|
|
|
2013-04-25 17:03:35 +03:00
|
|
|
if (errorsFound)
|
2012-12-03 19:00:17 +03:00
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
for(auto object : registeredObjects)
|
2013-03-09 16:16:35 +03:00
|
|
|
{
|
2013-04-25 17:03:35 +03:00
|
|
|
logGlobal->traceStream() << object.first << " -> " << object.second.id;
|
2013-03-09 16:16:35 +03:00
|
|
|
}
|
2013-04-25 17:03:35 +03:00
|
|
|
logGlobal->errorStream() << "All known identifiers were dumped into log file";
|
2012-12-03 19:00:17 +03:00
|
|
|
}
|
2013-04-25 17:03:35 +03:00
|
|
|
assert(errorsFound == false);
|
2012-12-03 19:00:17 +03:00
|
|
|
}
|
|
|
|
|
2013-04-26 00:50:55 +03:00
|
|
|
CContentHandler::ContentTypeHandler::ContentTypeHandler(IHandlerBase * handler, std::string objectName):
|
2013-04-21 15:49:26 +03:00
|
|
|
handler(handler),
|
|
|
|
objectName(objectName),
|
2013-04-26 00:50:55 +03:00
|
|
|
originalData(handler->loadLegacyData(VLC->modh->settings.data["textData"][objectName].Float()))
|
2013-04-21 15:49:26 +03:00
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
for(auto & node : originalData)
|
2013-04-25 17:03:35 +03:00
|
|
|
{
|
|
|
|
node.setMeta("core");
|
|
|
|
}
|
2013-04-21 15:49:26 +03:00
|
|
|
}
|
|
|
|
|
2013-11-09 22:10:16 +03:00
|
|
|
bool CContentHandler::ContentTypeHandler::preloadModData(std::string modName, std::vector<std::string> fileList, bool validate)
|
2013-04-21 15:49:26 +03:00
|
|
|
{
|
2013-11-08 23:36:26 +03:00
|
|
|
bool result;
|
|
|
|
JsonNode data = JsonUtils::assembleFromFiles(fileList, result);
|
2013-04-25 17:03:35 +03:00
|
|
|
data.setMeta(modName);
|
2013-04-21 15:49:26 +03:00
|
|
|
|
|
|
|
ModInfo & modInfo = modData[modName];
|
|
|
|
|
2013-06-29 16:05:48 +03:00
|
|
|
for(auto entry : data.Struct())
|
2013-04-21 15:49:26 +03:00
|
|
|
{
|
|
|
|
size_t colon = entry.first.find(':');
|
|
|
|
|
|
|
|
if (colon == std::string::npos)
|
|
|
|
{
|
|
|
|
// normal object, local to this mod
|
|
|
|
modInfo.modData[entry.first].swap(entry.second);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::string remoteName = entry.first.substr(0, colon);
|
|
|
|
std::string objectName = entry.first.substr(colon + 1);
|
|
|
|
|
|
|
|
// patching this mod? Send warning and continue - this situation can be handled normally
|
|
|
|
if (remoteName == modName)
|
|
|
|
logGlobal->warnStream() << "Redundant namespace definition for " << objectName;
|
|
|
|
|
|
|
|
JsonNode & remoteConf = modData[remoteName].patches[objectName];
|
|
|
|
|
|
|
|
JsonUtils::merge(remoteConf, entry.second);
|
|
|
|
}
|
|
|
|
}
|
2013-11-08 23:36:26 +03:00
|
|
|
return result;
|
2013-04-21 15:49:26 +03:00
|
|
|
}
|
|
|
|
|
2013-11-09 22:10:16 +03:00
|
|
|
bool CContentHandler::ContentTypeHandler::loadMod(std::string modName, bool validate)
|
2013-04-21 15:49:26 +03:00
|
|
|
{
|
|
|
|
ModInfo & modInfo = modData[modName];
|
2013-11-08 23:36:26 +03:00
|
|
|
bool result = true;
|
2013-04-21 15:49:26 +03:00
|
|
|
|
|
|
|
// apply patches
|
|
|
|
if (!modInfo.patches.isNull())
|
|
|
|
JsonUtils::merge(modInfo.modData, modInfo.patches);
|
|
|
|
|
2013-11-14 16:21:09 +03:00
|
|
|
for(auto & entry : modInfo.modData.Struct())
|
2013-04-21 15:49:26 +03:00
|
|
|
{
|
|
|
|
const std::string & name = entry.first;
|
|
|
|
JsonNode & data = entry.second;
|
|
|
|
|
|
|
|
if (vstd::contains(data.Struct(), "index") && !data["index"].isNull())
|
|
|
|
{
|
|
|
|
// try to add H3 object data
|
|
|
|
size_t index = data["index"].Float();
|
|
|
|
|
|
|
|
if (originalData.size() > index)
|
|
|
|
{
|
|
|
|
JsonUtils::merge(originalData[index], data);
|
2013-11-09 22:10:16 +03:00
|
|
|
if (validate)
|
|
|
|
result &= JsonUtils::validate(originalData[index], "vcmi:" + objectName, name);
|
2013-04-21 15:49:26 +03:00
|
|
|
handler->loadObject(modName, name, originalData[index], index);
|
|
|
|
|
|
|
|
originalData[index].clear(); // do not use same data twice (same ID)
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2013-11-06 16:42:58 +03:00
|
|
|
// normal new object or one with index bigger that data size
|
2013-11-09 22:10:16 +03:00
|
|
|
if (validate)
|
|
|
|
result &= JsonUtils::validate(data, "vcmi:" + objectName, name);
|
2013-04-21 15:49:26 +03:00
|
|
|
handler->loadObject(modName, name, data);
|
|
|
|
}
|
2013-11-08 23:36:26 +03:00
|
|
|
return result;
|
2013-04-21 15:49:26 +03:00
|
|
|
}
|
|
|
|
|
2013-07-21 17:19:29 +03:00
|
|
|
void CContentHandler::ContentTypeHandler::afterLoadFinalization()
|
|
|
|
{
|
|
|
|
handler->afterLoadFinalization();
|
|
|
|
}
|
|
|
|
|
2013-04-21 15:49:26 +03:00
|
|
|
CContentHandler::CContentHandler()
|
|
|
|
{
|
2014-03-07 16:21:09 +03:00
|
|
|
handlers.insert(std::make_pair("heroClasses", ContentTypeHandler(&VLC->heroh->classes, "heroClass")));
|
2013-04-26 00:50:55 +03:00
|
|
|
handlers.insert(std::make_pair("artifacts", ContentTypeHandler(VLC->arth, "artifact")));
|
|
|
|
handlers.insert(std::make_pair("creatures", ContentTypeHandler(VLC->creh, "creature")));
|
|
|
|
handlers.insert(std::make_pair("factions", ContentTypeHandler(VLC->townh, "faction")));
|
|
|
|
handlers.insert(std::make_pair("heroes", ContentTypeHandler(VLC->heroh, "hero")));
|
2014-03-07 16:21:09 +03:00
|
|
|
handlers.insert(std::make_pair("spells", ContentTypeHandler(VLC->spellh, "spell")));
|
2013-04-21 15:49:26 +03:00
|
|
|
|
2014-03-07 16:21:09 +03:00
|
|
|
//TODO: bonuses, something else?
|
2013-04-21 15:49:26 +03:00
|
|
|
}
|
|
|
|
|
2013-11-09 22:10:16 +03:00
|
|
|
bool CContentHandler::preloadModData(std::string modName, JsonNode modConfig, bool validate)
|
2013-04-21 15:49:26 +03:00
|
|
|
{
|
2013-11-08 23:36:26 +03:00
|
|
|
bool result = true;
|
2013-06-29 16:05:48 +03:00
|
|
|
for(auto & handler : handlers)
|
2013-04-21 15:49:26 +03:00
|
|
|
{
|
2013-11-09 22:10:16 +03:00
|
|
|
result &= handler.second.preloadModData(modName, modConfig[handler.first].convertTo<std::vector<std::string> >(), validate);
|
2013-04-21 15:49:26 +03:00
|
|
|
}
|
2013-11-08 23:36:26 +03:00
|
|
|
return result;
|
2013-04-21 15:49:26 +03:00
|
|
|
}
|
|
|
|
|
2013-11-09 22:10:16 +03:00
|
|
|
bool CContentHandler::loadMod(std::string modName, bool validate)
|
2013-04-21 15:49:26 +03:00
|
|
|
{
|
2013-11-08 23:36:26 +03:00
|
|
|
bool result = true;
|
2013-06-29 16:05:48 +03:00
|
|
|
for(auto & handler : handlers)
|
2013-04-21 15:49:26 +03:00
|
|
|
{
|
2013-11-09 22:10:16 +03:00
|
|
|
result &= handler.second.loadMod(modName, validate);
|
2013-04-21 15:49:26 +03:00
|
|
|
}
|
2013-11-08 23:36:26 +03:00
|
|
|
return result;
|
2013-04-21 15:49:26 +03:00
|
|
|
}
|
|
|
|
|
2013-07-21 17:19:29 +03:00
|
|
|
void CContentHandler::afterLoadFinalization()
|
|
|
|
{
|
|
|
|
for(auto & handler : handlers)
|
|
|
|
{
|
|
|
|
handler.second.afterLoadFinalization();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-11 23:11:51 +03:00
|
|
|
void CContentHandler::preloadData(CModInfo & mod)
|
|
|
|
{
|
|
|
|
bool validate = (mod.validation != CModInfo::PASSED);
|
|
|
|
|
|
|
|
// print message in format [<8-symbols checksum>] <modname>
|
|
|
|
logGlobal->infoStream() << "\t\t[" << std::noshowbase << std::hex << std::setw(8) << std::setfill('0')
|
|
|
|
<< mod.checksum << "] " << mod.name;
|
|
|
|
|
|
|
|
if (validate && mod.identifier != "core")
|
|
|
|
{
|
|
|
|
if (!JsonUtils::validate(mod.config, "vcmi:mod", mod.identifier))
|
|
|
|
mod.validation = CModInfo::FAILED;
|
|
|
|
}
|
|
|
|
if (!preloadModData(mod.identifier, mod.config, validate))
|
|
|
|
mod.validation = CModInfo::FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CContentHandler::load(CModInfo & mod)
|
|
|
|
{
|
|
|
|
bool validate = (mod.validation != CModInfo::PASSED);
|
|
|
|
|
|
|
|
if (!loadMod(mod.identifier, validate))
|
|
|
|
mod.validation = CModInfo::FAILED;
|
|
|
|
|
|
|
|
if (validate)
|
|
|
|
{
|
|
|
|
if (mod.validation != CModInfo::FAILED)
|
|
|
|
logGlobal->infoStream() << "\t\t[DONE] " << mod.name;
|
|
|
|
else
|
|
|
|
logGlobal->errorStream() << "\t\t[FAIL] " << mod.name;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
logGlobal->infoStream() << "\t\t[SKIP] " << mod.name;
|
|
|
|
}
|
|
|
|
|
2012-08-10 16:07:53 +03:00
|
|
|
CModHandler::CModHandler()
|
|
|
|
{
|
2012-12-26 12:46:09 +03:00
|
|
|
for (int i = 0; i < GameConstants::RESOURCE_QUANTITY; ++i)
|
|
|
|
{
|
2013-04-21 15:49:26 +03:00
|
|
|
identifiers.registerObject("core", "resource", GameConstants::RESOURCE_NAMES[i], i);
|
2012-12-26 12:46:09 +03:00
|
|
|
}
|
|
|
|
|
2013-02-25 12:48:26 +03:00
|
|
|
for(int i=0; i<GameConstants::PRIMARY_SKILLS; ++i)
|
2013-04-21 15:49:26 +03:00
|
|
|
identifiers.registerObject("core", "primSkill", PrimarySkill::names[i], i);
|
2013-02-25 12:48:26 +03:00
|
|
|
|
2012-08-10 16:07:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CModHandler::loadConfigFromFile (std::string name)
|
2012-08-11 12:06:23 +03:00
|
|
|
{
|
2013-04-26 00:50:55 +03:00
|
|
|
settings.data = JsonUtils::assembleFromFiles("config/" + name);
|
|
|
|
const JsonNode & hardcodedFeatures = settings.data["hardcodedFeatures"];
|
2012-08-11 12:06:23 +03:00
|
|
|
|
|
|
|
settings.CREEP_SIZE = hardcodedFeatures["CREEP_SIZE"].Float();
|
|
|
|
settings.WEEKLY_GROWTH = hardcodedFeatures["WEEKLY_GROWTH_PERCENT"].Float();
|
|
|
|
settings.NEUTRAL_STACK_EXP = hardcodedFeatures["NEUTRAL_STACK_EXP_DAILY"].Float();
|
2012-09-05 15:49:23 +03:00
|
|
|
settings.MAX_BUILDING_PER_TURN = hardcodedFeatures["MAX_BUILDING_PER_TURN"].Float();
|
2012-08-11 12:06:23 +03:00
|
|
|
settings.DWELLINGS_ACCUMULATE_CREATURES = hardcodedFeatures["DWELLINGS_ACCUMULATE_CREATURES"].Bool();
|
|
|
|
settings.ALL_CREATURES_GET_DOUBLE_MONTHS = hardcodedFeatures["ALL_CREATURES_GET_DOUBLE_MONTHS"].Bool();
|
2012-08-24 12:37:52 +03:00
|
|
|
|
2013-04-26 00:50:55 +03:00
|
|
|
const JsonNode & gameModules = settings.data["modules"];
|
2012-08-24 12:37:52 +03:00
|
|
|
modules.STACK_EXP = gameModules["STACK_EXPERIENCE"].Bool();
|
|
|
|
modules.STACK_ARTIFACT = gameModules["STACK_ARTIFACTS"].Bool();
|
|
|
|
modules.COMMANDERS = gameModules["COMMANDERS"].Bool();
|
|
|
|
modules.MITHRIL = gameModules["MITHRIL"].Bool();
|
2012-08-11 12:06:23 +03:00
|
|
|
}
|
2012-09-21 00:28:18 +03:00
|
|
|
|
2013-01-10 21:53:49 +03:00
|
|
|
// currentList is passed by value to get current list of depending mods
|
|
|
|
bool CModHandler::hasCircularDependency(TModID modID, std::set <TModID> currentList) const
|
|
|
|
{
|
|
|
|
const CModInfo & mod = allMods.at(modID);
|
|
|
|
|
|
|
|
// Mod already present? We found a loop
|
|
|
|
if (vstd::contains(currentList, modID))
|
|
|
|
{
|
2013-04-09 17:31:36 +03:00
|
|
|
logGlobal->errorStream() << "Error: Circular dependency detected! Printing dependency list:";
|
|
|
|
logGlobal->errorStream() << "\t" << mod.name << " -> ";
|
2013-01-10 21:53:49 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
currentList.insert(modID);
|
|
|
|
|
|
|
|
// recursively check every dependency of this mod
|
2013-06-29 16:05:48 +03:00
|
|
|
for(const TModID & dependency : mod.dependencies)
|
2013-01-10 21:53:49 +03:00
|
|
|
{
|
|
|
|
if (hasCircularDependency(dependency, currentList))
|
|
|
|
{
|
2013-04-09 17:31:36 +03:00
|
|
|
logGlobal->errorStream() << "\t" << mod.name << " ->\n"; // conflict detected, print dependency list
|
2013-01-10 21:53:49 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CModHandler::checkDependencies(const std::vector <TModID> & input) const
|
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
for(const TModID & id : input)
|
2013-01-10 21:53:49 +03:00
|
|
|
{
|
|
|
|
const CModInfo & mod = allMods.at(id);
|
|
|
|
|
2013-06-29 16:05:48 +03:00
|
|
|
for(const TModID & dep : mod.dependencies)
|
2013-01-10 21:53:49 +03:00
|
|
|
{
|
|
|
|
if (!vstd::contains(input, dep))
|
|
|
|
{
|
2013-04-09 17:31:36 +03:00
|
|
|
logGlobal->errorStream() << "Error: Mod " << mod.name << " requires missing " << dep << "!";
|
2013-01-10 21:53:49 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-29 16:05:48 +03:00
|
|
|
for(const TModID & conflicting : mod.conflicts)
|
2013-01-10 21:53:49 +03:00
|
|
|
{
|
|
|
|
if (vstd::contains(input, conflicting))
|
|
|
|
{
|
2013-04-09 17:31:36 +03:00
|
|
|
logGlobal->errorStream() << "Error: Mod " << mod.name << " conflicts with " << allMods.at(conflicting).name << "!";
|
2013-01-10 21:53:49 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hasCircularDependency(id))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector <TModID> CModHandler::resolveDependencies(std::vector <TModID> input) const
|
|
|
|
{
|
2013-04-21 15:49:26 +03:00
|
|
|
// Topological sort algorithm
|
|
|
|
// May not be the fastest one but VCMI does not needs any speed here
|
|
|
|
// Unless user have dozens of mods with complex dependencies this code should be fine
|
|
|
|
|
|
|
|
// first - sort input to have input strictly based on name (and not on hashmap or anything else)
|
|
|
|
boost::range::sort(input);
|
2013-01-10 21:53:49 +03:00
|
|
|
|
|
|
|
std::vector <TModID> output;
|
|
|
|
output.reserve(input.size());
|
|
|
|
|
|
|
|
std::set <TModID> resolvedMods;
|
|
|
|
|
|
|
|
// Check if all mod dependencies are resolved (moved to resolvedMods)
|
|
|
|
auto isResolved = [&](const CModInfo mod) -> bool
|
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
for(const TModID & dependency : mod.dependencies)
|
2013-01-10 21:53:49 +03:00
|
|
|
{
|
|
|
|
if (!vstd::contains(resolvedMods, dependency))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
while (!input.empty())
|
|
|
|
{
|
2013-04-21 15:49:26 +03:00
|
|
|
std::set <TModID> toResolve; // list of mods resolved on this iteration
|
|
|
|
|
2013-01-10 21:53:49 +03:00
|
|
|
for (auto it = input.begin(); it != input.end();)
|
|
|
|
{
|
|
|
|
if (isResolved(allMods.at(*it)))
|
|
|
|
{
|
2013-04-21 15:49:26 +03:00
|
|
|
toResolve.insert(*it);
|
2013-01-10 21:53:49 +03:00
|
|
|
output.push_back(*it);
|
|
|
|
it = input.erase(it);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
it++;
|
|
|
|
}
|
2013-04-21 15:49:26 +03:00
|
|
|
resolvedMods.insert(toResolve.begin(), toResolve.end());
|
2013-01-10 21:53:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
2013-11-09 22:10:16 +03:00
|
|
|
static JsonNode loadModSettings(std::string path)
|
2012-08-11 12:06:23 +03:00
|
|
|
{
|
2013-11-09 22:10:16 +03:00
|
|
|
if (CResourceHandler::get()->existsResource(ResourceID(path)))
|
|
|
|
{
|
2014-01-09 23:15:32 +03:00
|
|
|
return JsonNode(ResourceID(path, EResType::TEXT));
|
2013-11-09 22:10:16 +03:00
|
|
|
}
|
2013-11-03 15:07:23 +03:00
|
|
|
// Probably new install. Create initial configuration
|
2013-11-09 22:10:16 +03:00
|
|
|
CResourceHandler::get()->createResource(path);
|
|
|
|
return JsonNode();
|
|
|
|
}
|
2013-04-03 00:39:32 +03:00
|
|
|
|
2013-12-13 11:53:44 +03:00
|
|
|
JsonNode addMeta(JsonNode config, std::string meta)
|
|
|
|
{
|
|
|
|
config.setMeta(meta);
|
|
|
|
return std::move(config);
|
|
|
|
}
|
|
|
|
|
2013-11-11 23:11:51 +03:00
|
|
|
CModInfo::CModInfo(std::string identifier,const JsonNode & local, const JsonNode & config):
|
|
|
|
identifier(identifier),
|
|
|
|
name(config["name"].String()),
|
|
|
|
description(config["description"].String()),
|
|
|
|
dependencies(config["depends"].convertTo<std::set<std::string> >()),
|
|
|
|
conflicts(config["conflicts"].convertTo<std::set<std::string> >()),
|
|
|
|
validation(PENDING),
|
2013-12-13 11:53:44 +03:00
|
|
|
config(addMeta(config, identifier))
|
2013-11-11 23:11:51 +03:00
|
|
|
{
|
|
|
|
loadLocalData(local);
|
|
|
|
}
|
|
|
|
|
|
|
|
JsonNode CModInfo::saveLocalData()
|
2013-11-09 22:10:16 +03:00
|
|
|
{
|
2013-11-11 23:11:51 +03:00
|
|
|
std::ostringstream stream;
|
|
|
|
stream << std::noshowbase << std::hex << std::setw(8) << std::setfill('0') << checksum;
|
|
|
|
|
|
|
|
JsonNode conf;
|
|
|
|
conf["active"].Bool() = enabled;
|
|
|
|
conf["validated"].Bool() = validation != FAILED;
|
|
|
|
conf["checksum"].String() = stream.str();
|
|
|
|
return conf;
|
2013-11-09 22:10:16 +03:00
|
|
|
}
|
2013-11-03 15:07:23 +03:00
|
|
|
|
2013-11-11 23:11:51 +03:00
|
|
|
void CModInfo::updateChecksum(ui32 newChecksum)
|
2013-11-09 22:10:16 +03:00
|
|
|
{
|
2013-12-13 11:53:44 +03:00
|
|
|
// comment-out next line to force validation of all mods ignoring checksum
|
2013-11-11 23:11:51 +03:00
|
|
|
if (newChecksum != checksum)
|
2013-11-09 22:10:16 +03:00
|
|
|
{
|
2013-11-11 23:11:51 +03:00
|
|
|
checksum = newChecksum;
|
|
|
|
validation = PENDING;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CModInfo::loadLocalData(const JsonNode & data)
|
|
|
|
{
|
|
|
|
bool validated = false;
|
2014-01-09 23:15:32 +03:00
|
|
|
enabled = true;
|
|
|
|
checksum = 0;
|
|
|
|
if (data.getType() == JsonNode::DATA_BOOL)
|
2013-11-11 23:11:51 +03:00
|
|
|
{
|
2014-01-09 23:15:32 +03:00
|
|
|
enabled = data.Bool();
|
2013-11-09 22:10:16 +03:00
|
|
|
}
|
2014-01-30 17:51:15 +03:00
|
|
|
if (data.getType() == JsonNode::DATA_STRUCT)
|
2013-11-09 22:10:16 +03:00
|
|
|
{
|
2013-11-11 23:11:51 +03:00
|
|
|
enabled = data["active"].Bool();
|
|
|
|
validated = data["validated"].Bool();
|
|
|
|
checksum = strtol(data["checksum"].String().c_str(), nullptr, 16);
|
2013-11-09 22:10:16 +03:00
|
|
|
}
|
2013-11-11 23:11:51 +03:00
|
|
|
|
|
|
|
if (enabled)
|
|
|
|
validation = validated ? PASSED : PENDING;
|
|
|
|
else
|
|
|
|
validation = validated ? PASSED : FAILED;
|
2013-11-09 22:10:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CModHandler::initializeMods(std::vector<std::string> availableMods)
|
|
|
|
{
|
|
|
|
const JsonNode modConfig = loadModSettings("config/modSettings.json");
|
2013-01-10 21:53:49 +03:00
|
|
|
const JsonNode & modList = modConfig["activeMods"];
|
|
|
|
|
|
|
|
std::vector <TModID> detectedMods;
|
|
|
|
|
2013-06-29 16:05:48 +03:00
|
|
|
for(std::string name : availableMods)
|
2012-12-12 14:13:57 +03:00
|
|
|
{
|
2013-01-10 21:53:49 +03:00
|
|
|
boost::to_lower(name);
|
2012-12-12 14:13:57 +03:00
|
|
|
std::string modFileName = "mods/" + name + "/mod.json";
|
2012-08-11 12:06:23 +03:00
|
|
|
|
2012-12-12 14:13:57 +03:00
|
|
|
if (CResourceHandler::get()->existsResource(ResourceID(modFileName)))
|
|
|
|
{
|
2013-11-11 23:11:51 +03:00
|
|
|
CModInfo mod(name, modList[name], JsonNode(ResourceID(modFileName)));
|
2013-11-09 22:10:16 +03:00
|
|
|
|
2013-11-11 23:11:51 +03:00
|
|
|
allMods[name] = mod;
|
2013-11-09 22:10:16 +03:00
|
|
|
if (mod.enabled)
|
|
|
|
detectedMods.push_back(name);
|
2012-12-12 14:13:57 +03:00
|
|
|
}
|
|
|
|
else
|
2013-04-09 17:31:36 +03:00
|
|
|
logGlobal->warnStream() << "\t\t Directory " << name << " does not contains VCMI mod";
|
2012-12-12 14:13:57 +03:00
|
|
|
}
|
2013-11-11 23:11:51 +03:00
|
|
|
coreMod = CModInfo("core", modConfig["core"], JsonNode(ResourceID("config/gameConfig.json")));
|
|
|
|
coreMod.name = "Original game files";
|
2012-08-11 12:06:23 +03:00
|
|
|
|
2013-01-10 21:53:49 +03:00
|
|
|
if (!checkDependencies(detectedMods))
|
2012-12-12 14:13:57 +03:00
|
|
|
{
|
2013-04-09 17:31:36 +03:00
|
|
|
logGlobal->errorStream() << "Critical error: failed to load mods! Exiting...";
|
2013-01-10 21:53:49 +03:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
activeMods = resolveDependencies(detectedMods);
|
2013-11-08 23:36:26 +03:00
|
|
|
loadModFilesystems();
|
|
|
|
}
|
|
|
|
|
|
|
|
static JsonNode genDefaultFS()
|
|
|
|
{
|
|
|
|
// default FS config for mods: directory "Content" that acts as H3 root directory
|
|
|
|
JsonNode defaultFS;
|
|
|
|
defaultFS[""].Vector().resize(2);
|
|
|
|
defaultFS[""].Vector()[0]["type"].String() = "zip";
|
|
|
|
defaultFS[""].Vector()[0]["path"].String() = "/Content.zip";
|
|
|
|
defaultFS[""].Vector()[1]["type"].String() = "dir";
|
|
|
|
defaultFS[""].Vector()[1]["path"].String() = "/Content";
|
|
|
|
return defaultFS;
|
2012-08-11 12:06:23 +03:00
|
|
|
}
|
2012-08-30 17:57:24 +03:00
|
|
|
|
2013-11-08 23:36:26 +03:00
|
|
|
static ISimpleResourceLoader * genModFilesystem(const std::string & modName, const JsonNode & conf)
|
2012-11-13 14:52:23 +03:00
|
|
|
{
|
2013-11-08 23:36:26 +03:00
|
|
|
static const JsonNode defaultFS = genDefaultFS();
|
|
|
|
|
|
|
|
if (!conf["filesystem"].isNull())
|
|
|
|
return CResourceHandler::createFileSystem("mods/" + modName, conf["filesystem"]);
|
|
|
|
else
|
|
|
|
return CResourceHandler::createFileSystem("mods/" + modName, defaultFS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ui32 calculateModChecksum(const std::string modName, ISimpleResourceLoader * filesystem)
|
|
|
|
{
|
|
|
|
boost::crc_32_type modChecksum;
|
|
|
|
// first - add current VCMI version into checksum to force re-validation on VCMI updates
|
|
|
|
modChecksum.process_bytes(reinterpret_cast<const void*>(GameConstants::VCMI_VERSION.data()), GameConstants::VCMI_VERSION.size());
|
|
|
|
|
|
|
|
// second - add mod.json into checksum because filesystem does not contains this file
|
2013-11-11 23:11:51 +03:00
|
|
|
// FIXME: remove workaround for core mod
|
|
|
|
if (modName != "core")
|
|
|
|
{
|
|
|
|
ResourceID modConfFile("mods/" + modName + "/mod", EResType::TEXT);
|
|
|
|
ui32 configChecksum = CResourceHandler::getInitial()->load(modConfFile)->calculateCRC32();
|
|
|
|
modChecksum.process_bytes(reinterpret_cast<const void *>(&configChecksum), sizeof(configChecksum));
|
|
|
|
}
|
|
|
|
// third - add all detected text files from this mod into checksum
|
2013-11-08 23:36:26 +03:00
|
|
|
auto files = filesystem->getFilteredFiles([](const ResourceID & resID)
|
|
|
|
{
|
2013-11-11 23:11:51 +03:00
|
|
|
return resID.getType() == EResType::TEXT &&
|
|
|
|
( boost::starts_with(resID.getName(), "DATA") ||
|
|
|
|
boost::starts_with(resID.getName(), "CONFIG"));
|
2013-11-08 23:36:26 +03:00
|
|
|
});
|
|
|
|
|
2013-11-11 23:11:51 +03:00
|
|
|
// these two files may change between two runs of vcmi and must be handled separately
|
|
|
|
files.erase(ResourceID("CONFIG/SETTINGS", EResType::TEXT));
|
|
|
|
files.erase(ResourceID("CONFIG/MODSETTINGS", EResType::TEXT));
|
|
|
|
|
2013-11-08 23:36:26 +03:00
|
|
|
for (const ResourceID & file : files)
|
|
|
|
{
|
|
|
|
ui32 fileChecksum = filesystem->load(file)->calculateCRC32();
|
|
|
|
modChecksum.process_bytes(reinterpret_cast<const void *>(&fileChecksum), sizeof(fileChecksum));
|
|
|
|
}
|
|
|
|
return modChecksum.checksum();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CModHandler::loadModFilesystems()
|
|
|
|
{
|
2013-12-11 20:12:39 +03:00
|
|
|
coreMod.updateChecksum(calculateModChecksum("core", CResourceHandler::get("core")));
|
2013-11-11 23:11:51 +03:00
|
|
|
|
2013-11-08 23:36:26 +03:00
|
|
|
for(std::string & modName : activeMods)
|
|
|
|
{
|
2013-11-11 23:11:51 +03:00
|
|
|
CModInfo & mod = allMods[modName];
|
2013-12-11 20:12:39 +03:00
|
|
|
CResourceHandler::addFilesystem(modName, genModFilesystem(modName, mod.config));
|
2013-11-08 23:36:26 +03:00
|
|
|
}
|
2012-11-13 14:52:23 +03:00
|
|
|
}
|
2012-09-20 21:41:16 +03:00
|
|
|
|
2013-04-25 17:03:35 +03:00
|
|
|
CModInfo & CModHandler::getModData(TModID modId)
|
|
|
|
{
|
|
|
|
CModInfo & mod = allMods.at(modId);
|
|
|
|
assert(vstd::contains(activeMods, modId)); // not really necessary but won't hurt
|
|
|
|
return mod;
|
|
|
|
}
|
2013-11-09 22:10:16 +03:00
|
|
|
|
|
|
|
void CModHandler::initializeConfig()
|
2012-11-13 14:52:23 +03:00
|
|
|
{
|
2013-04-26 00:50:55 +03:00
|
|
|
loadConfigFromFile("defaultMods.json");
|
2013-04-28 18:06:14 +03:00
|
|
|
}
|
2013-04-26 00:50:55 +03:00
|
|
|
|
2013-11-09 22:10:16 +03:00
|
|
|
void CModHandler::load()
|
2013-04-28 18:06:14 +03:00
|
|
|
{
|
2013-11-09 22:10:16 +03:00
|
|
|
CStopWatch totalTime, timer;
|
|
|
|
|
2013-04-21 15:49:26 +03:00
|
|
|
CContentHandler content;
|
2013-05-30 15:14:39 +03:00
|
|
|
logGlobal->infoStream() << "\tInitializing content handler: " << timer.getDiff() << " ms";
|
2013-04-21 15:49:26 +03:00
|
|
|
|
2013-12-11 20:12:39 +03:00
|
|
|
for(const TModID & modName : activeMods)
|
|
|
|
{
|
|
|
|
logGlobal->traceStream() << "Generating checksum for " << modName;
|
|
|
|
allMods[modName].updateChecksum(calculateModChecksum(modName, CResourceHandler::get(modName)));
|
|
|
|
}
|
|
|
|
|
2013-04-25 17:03:35 +03:00
|
|
|
// first - load virtual "core" mod that contains all data
|
2013-04-21 15:49:26 +03:00
|
|
|
// TODO? move all data into real mods? RoE, AB, SoD, WoG
|
2013-11-11 23:11:51 +03:00
|
|
|
content.preloadData(coreMod);
|
2013-06-29 16:05:48 +03:00
|
|
|
for(const TModID & modName : activeMods)
|
2013-11-11 23:11:51 +03:00
|
|
|
content.preloadData(allMods[modName]);
|
2013-04-21 15:49:26 +03:00
|
|
|
logGlobal->infoStream() << "\tParsing mod data: " << timer.getDiff() << " ms";
|
|
|
|
|
2013-11-11 23:11:51 +03:00
|
|
|
content.load(coreMod);
|
2013-06-29 16:05:48 +03:00
|
|
|
for(const TModID & modName : activeMods)
|
2013-11-11 23:11:51 +03:00
|
|
|
content.load(allMods[modName]);
|
2013-11-09 22:10:16 +03:00
|
|
|
|
2013-04-21 15:49:26 +03:00
|
|
|
logGlobal->infoStream() << "\tLoading mod data: " << timer.getDiff() << "ms";
|
|
|
|
|
|
|
|
VLC->creh->loadCrExpBon();
|
2012-11-13 14:52:23 +03:00
|
|
|
VLC->creh->buildBonusTreeForTiers(); //do that after all new creatures are loaded
|
2013-11-09 22:10:16 +03:00
|
|
|
|
2012-12-03 19:00:17 +03:00
|
|
|
identifiers.finalize();
|
2013-04-25 17:03:35 +03:00
|
|
|
logGlobal->infoStream() << "\tResolving identifiers: " << timer.getDiff() << " ms";
|
2013-07-21 17:19:29 +03:00
|
|
|
|
|
|
|
content.afterLoadFinalization();
|
|
|
|
logGlobal->infoStream() << "\tHandlers post-load finalization: " << timer.getDiff() << " ms";
|
2013-04-21 15:49:26 +03:00
|
|
|
logGlobal->infoStream() << "\tAll game content loaded in " << totalTime.getDiff() << " ms";
|
2012-11-13 14:52:23 +03:00
|
|
|
}
|
2012-08-30 17:57:24 +03:00
|
|
|
|
2013-11-09 22:10:16 +03:00
|
|
|
void CModHandler::afterLoad()
|
|
|
|
{
|
|
|
|
JsonNode modSettings;
|
|
|
|
for (auto & modEntry : allMods)
|
2013-11-11 23:11:51 +03:00
|
|
|
modSettings["activeMods"][modEntry.first] = modEntry.second.saveLocalData();
|
|
|
|
modSettings["core"] = coreMod.saveLocalData();
|
2013-11-09 22:10:16 +03:00
|
|
|
|
|
|
|
std::ofstream file(*CResourceHandler::get()->getResourceName(ResourceID("config/modSettings.json")), std::ofstream::trunc);
|
|
|
|
file << modSettings;
|
2012-08-10 16:07:53 +03:00
|
|
|
}
|