2021-03-23 13:46:59 +01:00
|
|
|
/* Copyright (C) 2021 Wildfire Games.
|
2014-08-25 18:02:40 +02:00
|
|
|
* This file is part of 0 A.D.
|
|
|
|
*
|
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "precompiled.h"
|
|
|
|
|
|
|
|
#include "ps/Mod.h"
|
|
|
|
|
2021-05-16 15:50:05 +02:00
|
|
|
#include "i18n/L10n.h"
|
2017-12-05 18:17:21 +01:00
|
|
|
#include "lib/file/file_system.h"
|
|
|
|
#include "lib/file/vfs/vfs.h"
|
|
|
|
#include "lib/utf8.h"
|
|
|
|
#include "ps/Filesystem.h"
|
|
|
|
#include "ps/GameSetup/GameSetup.h"
|
|
|
|
#include "ps/GameSetup/Paths.h"
|
2021-05-16 15:50:05 +02:00
|
|
|
#include "ps/Profiler2.h"
|
2020-01-02 19:07:40 +01:00
|
|
|
#include "ps/Pyrogenesis.h"
|
2021-05-25 08:12:45 +02:00
|
|
|
#include "scriptinterface/JSON.h"
|
2021-05-13 19:23:52 +02:00
|
|
|
#include "scriptinterface/Object.h"
|
2021-05-25 08:12:45 +02:00
|
|
|
#include "scriptinterface/ScriptExceptions.h"
|
2018-04-27 18:48:44 +02:00
|
|
|
#include "scriptinterface/ScriptInterface.h"
|
2017-12-05 18:17:21 +01:00
|
|
|
|
2021-05-09 15:53:25 +02:00
|
|
|
#include <algorithm>
|
|
|
|
#include <boost/algorithm/string/split.hpp>
|
|
|
|
#include <boost/algorithm/string/classification.hpp>
|
2021-05-16 15:50:05 +02:00
|
|
|
#include <fstream>
|
|
|
|
#include <sstream>
|
2021-05-09 15:53:25 +02:00
|
|
|
#include <unordered_map>
|
|
|
|
|
2021-05-20 10:32:11 +02:00
|
|
|
namespace
|
2021-05-16 15:50:05 +02:00
|
|
|
{
|
2021-05-20 10:32:11 +02:00
|
|
|
/**
|
|
|
|
* Global instance of Mod, always exists.
|
|
|
|
*/
|
|
|
|
Mod g_ModInstance;
|
2018-05-24 20:08:56 +02:00
|
|
|
|
2021-05-25 08:12:45 +02:00
|
|
|
bool LoadModJSON(const PIVFS& vfs, OsPath modsPath, OsPath mod, std::string& text)
|
2021-05-16 15:50:05 +02:00
|
|
|
{
|
|
|
|
// Attempt to open mod.json first.
|
|
|
|
std::ifstream modjson;
|
|
|
|
modjson.open((modsPath / mod / L"mod.json").string8());
|
|
|
|
|
|
|
|
if (!modjson.is_open())
|
|
|
|
{
|
|
|
|
modjson.close();
|
|
|
|
|
|
|
|
// Fallback: open the archive and read mod.json there.
|
|
|
|
// This can take in the hundreds of milliseconds with large mods.
|
|
|
|
vfs->Clear();
|
|
|
|
if (vfs->Mount(L"", modsPath / mod / "", VFS_MOUNT_MUST_EXIST, VFS_MIN_PRIORITY) < 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
CVFSFile modinfo;
|
|
|
|
if (modinfo.Load(vfs, L"mod.json", false) != PSRETURN_OK)
|
|
|
|
return false;
|
|
|
|
|
2021-05-25 08:12:45 +02:00
|
|
|
text = modinfo.GetAsString();
|
2021-05-16 15:50:05 +02:00
|
|
|
|
|
|
|
// Attempt to write the mod.json file so we'll take the fast path next time.
|
|
|
|
std::ofstream out_mod_json((modsPath / mod / L"mod.json").string8());
|
|
|
|
if (out_mod_json.good())
|
|
|
|
{
|
2021-05-25 08:12:45 +02:00
|
|
|
out_mod_json << text;
|
2021-05-16 15:50:05 +02:00
|
|
|
out_mod_json.close();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Print a warning - we'll keep trying, which could have adverse effects.
|
|
|
|
if (L10n::IsInitialised())
|
|
|
|
LOGWARNING(g_L10n.Translate("Could not write external mod.json for zipped mod '%s'. The mod should be reinstalled."), mod.string8());
|
|
|
|
else
|
|
|
|
LOGWARNING("Could not write external mod.json for zipped mod '%s'. The mod should be reinstalled.", mod.string8());
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::stringstream buffer;
|
|
|
|
buffer << modjson.rdbuf();
|
2021-05-25 08:12:45 +02:00
|
|
|
text = buffer.str();
|
|
|
|
return true;
|
2021-05-16 15:50:05 +02:00
|
|
|
}
|
|
|
|
}
|
2021-05-25 08:12:45 +02:00
|
|
|
|
|
|
|
bool ParseModJSON(const ScriptRequest& rq, const PIVFS& vfs, OsPath modsPath, OsPath mod, Mod::ModData& data)
|
|
|
|
{
|
|
|
|
std::string text;
|
|
|
|
if (!LoadModJSON(vfs, modsPath, mod, text))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
JS::RootedValue json(rq.cx);
|
|
|
|
if (!Script::ParseJSON(rq, text, &json))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
data.m_Pathname = utf8_from_wstring(mod.string());
|
|
|
|
data.m_Text = text;
|
|
|
|
|
|
|
|
if (!Script::GetProperty(rq, json, "version", data.m_Version))
|
|
|
|
return false;
|
|
|
|
if (!Script::GetProperty(rq, json, "name", data.m_Name))
|
|
|
|
return false;
|
|
|
|
if (!Script::GetProperty(rq, json, "dependencies", data.m_Dependencies))
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-05-20 10:32:11 +02:00
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
Mod& Mod::Instance()
|
|
|
|
{
|
|
|
|
return g_ModInstance;
|
|
|
|
}
|
2017-12-05 18:17:21 +01:00
|
|
|
|
2021-05-25 08:12:45 +02:00
|
|
|
void Mod::UpdateAvailableMods(const ScriptInterface& scriptInterface)
|
2017-12-05 18:17:21 +01:00
|
|
|
{
|
2021-05-25 08:12:45 +02:00
|
|
|
PROFILE2("UpdateAvailableMods");
|
2017-12-05 18:17:21 +01:00
|
|
|
|
2021-05-16 15:50:05 +02:00
|
|
|
const Paths paths(g_CmdLineArgs);
|
2017-12-05 18:17:21 +01:00
|
|
|
|
|
|
|
// loop over all possible paths
|
|
|
|
OsPath modPath = paths.RData()/"mods";
|
|
|
|
OsPath modUserPath = paths.UserData()/"mods";
|
|
|
|
|
|
|
|
DirectoryNames modDirs;
|
|
|
|
DirectoryNames modDirsUser;
|
|
|
|
|
|
|
|
GetDirectoryEntries(modPath, NULL, &modDirs);
|
|
|
|
// Sort modDirs so that we can do a fast lookup below
|
|
|
|
std::sort(modDirs.begin(), modDirs.end());
|
|
|
|
|
2017-12-10 18:33:03 +01:00
|
|
|
PIVFS vfs = CreateVfs();
|
2017-12-05 18:17:21 +01:00
|
|
|
|
2021-05-16 15:50:05 +02:00
|
|
|
ScriptRequest rq(scriptInterface);
|
2017-12-05 18:17:21 +01:00
|
|
|
for (DirectoryNames::iterator iter = modDirs.begin(); iter != modDirs.end(); ++iter)
|
|
|
|
{
|
2021-05-25 08:12:45 +02:00
|
|
|
ModData data;
|
|
|
|
if (!ParseModJSON(rq, vfs, modPath, *iter, data))
|
2017-12-05 18:17:21 +01:00
|
|
|
continue;
|
2021-05-16 15:50:05 +02:00
|
|
|
// Valid mod data, add it to our structure
|
2021-05-25 08:12:45 +02:00
|
|
|
m_AvailableMods.emplace_back(std::move(data));
|
2017-12-05 18:17:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
GetDirectoryEntries(modUserPath, NULL, &modDirsUser);
|
|
|
|
|
|
|
|
for (DirectoryNames::iterator iter = modDirsUser.begin(); iter != modDirsUser.end(); ++iter)
|
|
|
|
{
|
2021-05-16 15:50:05 +02:00
|
|
|
// Ignore mods in the user folder if we have already found them in modDirs.
|
|
|
|
if (std::binary_search(modDirs.begin(), modDirs.end(), *iter))
|
2017-12-05 18:17:21 +01:00
|
|
|
continue;
|
|
|
|
|
2021-05-25 08:12:45 +02:00
|
|
|
ModData data;
|
|
|
|
if (!ParseModJSON(rq, vfs, modUserPath, *iter, data))
|
2017-12-05 18:17:21 +01:00
|
|
|
continue;
|
2021-05-16 15:50:05 +02:00
|
|
|
// Valid mod data, add it to our structure
|
2021-05-25 08:12:45 +02:00
|
|
|
m_AvailableMods.emplace_back(std::move(data));
|
2017-12-05 18:17:21 +01:00
|
|
|
}
|
|
|
|
}
|
2018-02-17 17:53:14 +01:00
|
|
|
|
2021-05-20 10:32:11 +02:00
|
|
|
const std::vector<CStr>& Mod::GetEnabledMods() const
|
2021-05-09 15:53:25 +02:00
|
|
|
{
|
2021-05-22 11:50:30 +02:00
|
|
|
return m_EnabledMods;
|
2021-05-09 15:53:25 +02:00
|
|
|
}
|
|
|
|
|
2021-05-20 10:32:11 +02:00
|
|
|
const std::vector<CStr>& Mod::GetIncompatibleMods() const
|
2021-05-09 15:53:25 +02:00
|
|
|
{
|
2021-05-20 10:32:11 +02:00
|
|
|
return m_IncompatibleMods;
|
2021-05-09 15:53:25 +02:00
|
|
|
}
|
|
|
|
|
2021-05-20 16:36:42 +02:00
|
|
|
bool Mod::EnableMods(const ScriptInterface& scriptInterface, const std::vector<CStr>& mods, const bool addPublic)
|
2021-05-09 15:53:25 +02:00
|
|
|
{
|
2021-05-20 16:36:42 +02:00
|
|
|
m_IncompatibleMods.clear();
|
2021-05-22 11:50:30 +02:00
|
|
|
m_EnabledMods.clear();
|
2021-05-09 15:53:25 +02:00
|
|
|
|
2021-05-20 16:36:42 +02:00
|
|
|
std::unordered_map<CStr, int> counts;
|
|
|
|
for (const CStr& mod : mods)
|
|
|
|
{
|
|
|
|
// Ignore duplicates.
|
|
|
|
if (counts.try_emplace(mod, 0).first->second++ > 0)
|
|
|
|
continue;
|
2021-05-22 11:50:30 +02:00
|
|
|
m_EnabledMods.emplace_back(mod);
|
2021-05-20 16:36:42 +02:00
|
|
|
}
|
2021-05-09 15:53:25 +02:00
|
|
|
|
2021-05-20 16:36:42 +02:00
|
|
|
if (addPublic && counts["public"] == 0)
|
2021-05-22 11:50:30 +02:00
|
|
|
m_EnabledMods.insert(m_EnabledMods.begin(), "public");
|
2021-05-09 15:53:25 +02:00
|
|
|
|
2021-05-20 16:36:42 +02:00
|
|
|
if (counts["mod"] == 0)
|
2021-05-22 11:50:30 +02:00
|
|
|
m_EnabledMods.insert(m_EnabledMods.begin(), "mod");
|
2021-05-09 15:53:25 +02:00
|
|
|
|
2021-05-25 08:12:45 +02:00
|
|
|
UpdateAvailableMods(scriptInterface);
|
|
|
|
|
|
|
|
m_IncompatibleMods = CheckForIncompatibleMods(m_EnabledMods);
|
2021-05-09 15:53:25 +02:00
|
|
|
|
2021-05-20 16:36:42 +02:00
|
|
|
for (const CStr& mod : m_IncompatibleMods)
|
2021-05-22 11:50:30 +02:00
|
|
|
m_EnabledMods.erase(std::find(m_EnabledMods.begin(), m_EnabledMods.end(), mod));
|
2021-05-09 15:53:25 +02:00
|
|
|
|
2021-05-20 16:36:42 +02:00
|
|
|
return m_IncompatibleMods.empty();
|
2021-05-09 15:53:25 +02:00
|
|
|
}
|
|
|
|
|
2021-05-25 08:12:45 +02:00
|
|
|
std::vector<CStr> Mod::CheckForIncompatibleMods(const std::vector<CStr>& mods) const
|
2021-05-09 15:53:25 +02:00
|
|
|
{
|
2021-05-20 16:36:42 +02:00
|
|
|
std::vector<CStr> incompatibleMods;
|
2021-05-09 15:53:25 +02:00
|
|
|
std::unordered_map<CStr, std::vector<CStr>> modDependencies;
|
|
|
|
std::unordered_map<CStr, CStr> modNameVersions;
|
|
|
|
for (const CStr& mod : mods)
|
|
|
|
{
|
|
|
|
if (mod == "mod")
|
|
|
|
continue;
|
|
|
|
|
2021-05-25 08:12:45 +02:00
|
|
|
std::vector<ModData>::const_iterator it = std::find_if(m_AvailableMods.begin(), m_AvailableMods.end(),
|
|
|
|
[&mod](const ModData& modData) { return modData.m_Pathname == mod; });
|
2021-05-09 15:53:25 +02:00
|
|
|
|
2021-05-25 08:12:45 +02:00
|
|
|
if (it == m_AvailableMods.end())
|
2021-05-09 15:53:25 +02:00
|
|
|
{
|
2021-05-20 16:36:42 +02:00
|
|
|
incompatibleMods.push_back(mod);
|
2021-05-09 15:53:25 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-05-25 08:12:45 +02:00
|
|
|
modNameVersions.emplace(it->m_Name, it->m_Version);
|
|
|
|
modDependencies.emplace(it->m_Name, it->m_Dependencies);
|
2021-05-09 15:53:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const std::vector<CStr> toCheck = { "<=", ">=", "=", "<", ">" };
|
|
|
|
for (const CStr& mod : mods)
|
|
|
|
{
|
|
|
|
if (mod == "mod")
|
|
|
|
continue;
|
|
|
|
|
|
|
|
const std::unordered_map<CStr, std::vector<CStr>>::iterator res = modDependencies.find(mod);
|
|
|
|
if (res == modDependencies.end())
|
|
|
|
continue;
|
|
|
|
const std::vector<CStr> deps = res->second;
|
|
|
|
if (deps.empty())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (const CStr& dep : deps)
|
|
|
|
{
|
|
|
|
if (dep.empty())
|
|
|
|
continue;
|
|
|
|
// 0ad<=0.0.24
|
|
|
|
for (const CStr& op : toCheck)
|
|
|
|
{
|
|
|
|
const int pos = dep.Find(op.c_str());
|
|
|
|
if (pos == -1)
|
|
|
|
continue;
|
|
|
|
//0ad
|
|
|
|
const CStr modToCheck = dep.substr(0, pos);
|
|
|
|
//0.0.24
|
|
|
|
const CStr versionToCheck = dep.substr(pos + op.size());
|
|
|
|
const std::unordered_map<CStr, CStr>::iterator it = modNameVersions.find(modToCheck);
|
|
|
|
if (it == modNameVersions.end())
|
|
|
|
{
|
2021-05-20 16:36:42 +02:00
|
|
|
incompatibleMods.push_back(mod);
|
2021-05-09 15:53:25 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// 0.0.25(0ad) , <=, 0.0.24(required version)
|
|
|
|
if (!CompareVersionStrings(it->second, op, versionToCheck))
|
|
|
|
{
|
2021-05-20 16:36:42 +02:00
|
|
|
incompatibleMods.push_back(mod);
|
2021-05-09 15:53:25 +02:00
|
|
|
continue;
|
|
|
|
}
|
2021-05-09 19:05:02 +02:00
|
|
|
break;
|
2021-05-09 15:53:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-05-20 16:36:42 +02:00
|
|
|
return incompatibleMods;
|
2021-05-09 15:53:25 +02:00
|
|
|
}
|
|
|
|
|
2021-05-20 10:32:11 +02:00
|
|
|
bool Mod::CompareVersionStrings(const CStr& version, const CStr& op, const CStr& required) const
|
2021-05-09 15:53:25 +02:00
|
|
|
{
|
|
|
|
std::vector<CStr> versionSplit;
|
|
|
|
std::vector<CStr> requiredSplit;
|
|
|
|
static const std::string toIgnore = "-,_";
|
|
|
|
boost::split(versionSplit, version, boost::is_any_of(toIgnore), boost::token_compress_on);
|
|
|
|
boost::split(requiredSplit, required, boost::is_any_of(toIgnore), boost::token_compress_on);
|
|
|
|
boost::split(versionSplit, versionSplit[0], boost::is_any_of("."), boost::token_compress_on);
|
|
|
|
boost::split(requiredSplit, requiredSplit[0], boost::is_any_of("."), boost::token_compress_on);
|
|
|
|
|
|
|
|
const bool eq = op.Find("=") != -1;
|
|
|
|
const bool lt = op.Find("<") != -1;
|
|
|
|
const bool gt = op.Find(">") != -1;
|
|
|
|
|
|
|
|
const size_t min = std::min(versionSplit.size(), requiredSplit.size());
|
|
|
|
|
|
|
|
for (size_t i = 0; i < min; ++i)
|
|
|
|
{
|
|
|
|
const int diff = versionSplit[i].ToInt() - requiredSplit[i].ToInt();
|
2021-05-09 19:05:02 +02:00
|
|
|
if ((gt && diff > 0) || (lt && diff < 0))
|
2021-05-09 15:53:25 +02:00
|
|
|
return true;
|
|
|
|
|
2021-05-09 19:05:02 +02:00
|
|
|
if ((gt && diff < 0) || (lt && diff > 0) || (eq && diff))
|
2021-05-09 15:53:25 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const size_t versionSize = versionSplit.size();
|
|
|
|
const size_t requiredSize = requiredSplit.size();
|
|
|
|
if (versionSize == requiredSize)
|
|
|
|
return eq;
|
|
|
|
return versionSize < requiredSize ? lt : gt;
|
|
|
|
}
|
|
|
|
|
2021-05-25 08:12:45 +02:00
|
|
|
JS::Value Mod::GetLoadedModsWithVersions(const ScriptInterface& scriptInterface) const
|
2018-02-17 17:53:14 +01:00
|
|
|
{
|
2021-05-25 08:12:45 +02:00
|
|
|
std::vector<std::vector<CStr>> loadedMods;
|
2021-05-22 11:50:30 +02:00
|
|
|
for (const CStr& mod : m_EnabledMods)
|
2018-02-17 17:53:14 +01:00
|
|
|
{
|
2021-05-25 08:12:45 +02:00
|
|
|
std::vector<ModData>::const_iterator it = std::find_if(m_AvailableMods.begin(), m_AvailableMods.end(),
|
|
|
|
[&mod](const ModData& modData) { return modData.m_Pathname == mod; });
|
2018-05-24 20:08:56 +02:00
|
|
|
|
2021-05-25 08:12:45 +02:00
|
|
|
// This ought be impossible, but let's handle it anyways since it's not a reason to crash.
|
|
|
|
if (it == m_AvailableMods.end())
|
|
|
|
{
|
|
|
|
LOGERROR("Unavailable mod '%s' was enabled.", mod);
|
|
|
|
continue;
|
|
|
|
}
|
2018-05-24 20:08:56 +02:00
|
|
|
|
2021-05-25 08:12:45 +02:00
|
|
|
loadedMods.emplace_back(std::vector<CStr>{ it->m_Name, it->m_Version });
|
2018-02-17 17:53:14 +01:00
|
|
|
}
|
Improve JS Exception handling.
- Check for pending exceptions after function calls and script
executions.
- Call LOGERROR instead of JS_ReportError when there is a conversion
error in FromJSVal, since that can only be called from C++ (where JS
errors don't really make sense). Instead, C++ callers of FromJSVal
should handle the failure and, themselves, either report an error or
simply do something else.
- Wrap JS_ReportError since that makes updating it later easier.
This isn't a systematical fix since ToJSVal also ought return a boolean
for failures, and we probably should trigger errors instead of warnings
on 'implicit' conversions, rather a preparation diff.
Part of the SM52 migration, stage: SM45 compatible (actually SM52
incompatible, too).
Based on a patch by: Itms
Comments by: Vladislavbelov, Stan`
Refs #742, #4893
Differential Revision: https://code.wildfiregames.com/D3093
This was SVN commit r24187.
2020-11-15 19:29:17 +01:00
|
|
|
ScriptRequest rq(scriptInterface);
|
2020-11-13 14:18:22 +01:00
|
|
|
JS::RootedValue returnValue(rq.cx);
|
2021-05-25 08:12:45 +02:00
|
|
|
Script::ToJSVal(rq, &returnValue, loadedMods);
|
2018-05-24 20:08:56 +02:00
|
|
|
return returnValue;
|
2018-02-17 17:53:14 +01:00
|
|
|
}
|
2018-02-17 18:36:43 +01:00
|
|
|
|
2021-05-20 10:32:11 +02:00
|
|
|
JS::Value Mod::GetEngineInfo(const ScriptInterface& scriptInterface) const
|
2018-02-17 18:36:43 +01:00
|
|
|
{
|
Improve JS Exception handling.
- Check for pending exceptions after function calls and script
executions.
- Call LOGERROR instead of JS_ReportError when there is a conversion
error in FromJSVal, since that can only be called from C++ (where JS
errors don't really make sense). Instead, C++ callers of FromJSVal
should handle the failure and, themselves, either report an error or
simply do something else.
- Wrap JS_ReportError since that makes updating it later easier.
This isn't a systematical fix since ToJSVal also ought return a boolean
for failures, and we probably should trigger errors instead of warnings
on 'implicit' conversions, rather a preparation diff.
Part of the SM52 migration, stage: SM45 compatible (actually SM52
incompatible, too).
Based on a patch by: Itms
Comments by: Vladislavbelov, Stan`
Refs #742, #4893
Differential Revision: https://code.wildfiregames.com/D3093
This was SVN commit r24187.
2020-11-15 19:29:17 +01:00
|
|
|
ScriptRequest rq(scriptInterface);
|
2018-02-17 18:36:43 +01:00
|
|
|
|
2021-05-16 15:50:05 +02:00
|
|
|
JS::RootedValue mods(rq.cx, GetLoadedModsWithVersions(scriptInterface));
|
2020-11-13 14:18:22 +01:00
|
|
|
JS::RootedValue metainfo(rq.cx);
|
2019-07-22 21:35:14 +02:00
|
|
|
|
2021-05-13 19:23:52 +02:00
|
|
|
Script::CreateObject(
|
2020-11-13 14:18:22 +01:00
|
|
|
rq,
|
2019-07-22 21:35:14 +02:00
|
|
|
&metainfo,
|
2019-09-13 02:56:51 +02:00
|
|
|
"engine_version", engine_version,
|
2019-07-22 21:35:14 +02:00
|
|
|
"mods", mods);
|
2018-02-17 18:36:43 +01:00
|
|
|
|
2021-05-13 19:23:52 +02:00
|
|
|
Script::FreezeObject(rq, metainfo, true);
|
2018-02-17 18:36:43 +01:00
|
|
|
|
|
|
|
return metainfo;
|
|
|
|
}
|
2021-05-25 08:12:45 +02:00
|
|
|
|
|
|
|
JS::Value Mod::GetAvailableMods(const ScriptRequest& rq) const
|
|
|
|
{
|
|
|
|
JS::RootedValue ret(rq.cx, Script::CreateObject(rq));
|
|
|
|
for (const ModData& data : m_AvailableMods)
|
|
|
|
{
|
|
|
|
JS::RootedValue json(rq.cx);
|
|
|
|
if (!Script::ParseJSON(rq, data.m_Text, &json))
|
|
|
|
{
|
|
|
|
ScriptException::Raise(rq, "Error parsing mod.json of '%s'", data.m_Pathname.c_str());
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
Script::SetProperty(rq, ret, data.m_Pathname.c_str(), json);
|
|
|
|
}
|
|
|
|
return ret.get();
|
|
|
|
}
|