diff options
| author | Mehmet Samet Duman <yongdohyun@projecttick.org> | 2026-04-02 18:45:07 +0300 |
|---|---|---|
| committer | Mehmet Samet Duman <yongdohyun@projecttick.org> | 2026-04-02 18:45:07 +0300 |
| commit | 31b9a8949ed0a288143e23bf739f2eb64fdc63be (patch) | |
| tree | 8a984fa143c38fccad461a77792d6864f3e82cd3 /meshmc/launcher/modplatform/flame | |
| parent | 934382c8a1ce738589dee9ee0f14e1cec812770e (diff) | |
| parent | fad6a1066616b69d7f5fef01178efdf014c59537 (diff) | |
| download | Project-Tick-31b9a8949ed0a288143e23bf739f2eb64fdc63be.tar.gz Project-Tick-31b9a8949ed0a288143e23bf739f2eb64fdc63be.zip | |
Add 'meshmc/' from commit 'fad6a1066616b69d7f5fef01178efdf014c59537'
git-subtree-dir: meshmc
git-subtree-mainline: 934382c8a1ce738589dee9ee0f14e1cec812770e
git-subtree-split: fad6a1066616b69d7f5fef01178efdf014c59537
Diffstat (limited to 'meshmc/launcher/modplatform/flame')
| -rw-r--r-- | meshmc/launcher/modplatform/flame/FileResolvingTask.cpp | 82 | ||||
| -rw-r--r-- | meshmc/launcher/modplatform/flame/FileResolvingTask.h | 56 | ||||
| -rw-r--r-- | meshmc/launcher/modplatform/flame/FlamePackIndex.cpp | 151 | ||||
| -rw-r--r-- | meshmc/launcher/modplatform/flame/FlamePackIndex.h | 63 | ||||
| -rw-r--r-- | meshmc/launcher/modplatform/flame/PackManifest.cpp | 155 | ||||
| -rw-r--r-- | meshmc/launcher/modplatform/flame/PackManifest.h | 79 |
6 files changed, 586 insertions, 0 deletions
diff --git a/meshmc/launcher/modplatform/flame/FileResolvingTask.cpp b/meshmc/launcher/modplatform/flame/FileResolvingTask.cpp new file mode 100644 index 0000000000..884d3831f0 --- /dev/null +++ b/meshmc/launcher/modplatform/flame/FileResolvingTask.cpp @@ -0,0 +1,82 @@ +/* SPDX-FileCopyrightText: 2026 Project Tick + * SPDX-FileContributor: Project Tick + * SPDX-License-Identifier: GPL-3.0-or-later + * + * MeshMC - A Custom Launcher for Minecraft + * Copyright (C) 2026 Project Tick + * + * This program 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 3 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#include "FileResolvingTask.h" +#include "Json.h" + +Flame::FileResolvingTask::FileResolvingTask( + shared_qobject_ptr<QNetworkAccessManager> network, + Flame::Manifest& toProcess) + : m_network(network), m_toProcess(toProcess) +{ +} + +void Flame::FileResolvingTask::executeTask() +{ + setStatus(tr("Resolving mod IDs...")); + setProgress(0, m_toProcess.files.size()); + m_dljob = new NetJob("Mod id resolver", m_network); + results.resize(m_toProcess.files.size()); + int index = 0; + for (auto& file : m_toProcess.files) { + auto projectIdStr = QString::number(file.projectId); + auto fileIdStr = QString::number(file.fileId); + QString metaurl = + QString("https://api.curseforge.com/v1/mods/%1/files/%2") + .arg(projectIdStr, fileIdStr); + auto dl = Net::Download::makeByteArray(QUrl(metaurl), &results[index]); + m_dljob->addNetAction(dl); + index++; + } + connect(m_dljob.get(), &NetJob::finished, this, + &Flame::FileResolvingTask::netJobFinished); + m_dljob->start(); +} + +void Flame::FileResolvingTask::netJobFinished() +{ + int index = 0; + int unresolved = 0; + for (auto& bytes : results) { + auto& out = m_toProcess.files[index]; + try { + if (!out.parseFromBytes(bytes)) { + unresolved++; + qWarning() << "Resolving of" << out.projectId << out.fileId + << "failed: mod may have restricted downloads"; + } + } catch (const JSONValidationError& e) { + unresolved++; + qCritical() << "Resolving of" << out.projectId << out.fileId + << "failed because of a parsing error:"; + qCritical() << e.cause(); + qCritical() << "JSON:"; + qCritical() << bytes; + } + index++; + } + if (unresolved > 0) { + qWarning() << unresolved + << "mod(s) could not be resolved (restricted downloads). " + "They will be skipped."; + } + emitSucceeded(); +} diff --git a/meshmc/launcher/modplatform/flame/FileResolvingTask.h b/meshmc/launcher/modplatform/flame/FileResolvingTask.h new file mode 100644 index 0000000000..a59df3d3a4 --- /dev/null +++ b/meshmc/launcher/modplatform/flame/FileResolvingTask.h @@ -0,0 +1,56 @@ +/* SPDX-FileCopyrightText: 2026 Project Tick + * SPDX-FileContributor: Project Tick + * SPDX-License-Identifier: GPL-3.0-or-later + * + * MeshMC - A Custom Launcher for Minecraft + * Copyright (C) 2026 Project Tick + * + * This program 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 3 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#pragma once + +#include "tasks/Task.h" +#include "net/NetJob.h" +#include "PackManifest.h" + +namespace Flame +{ + class FileResolvingTask : public Task + { + Q_OBJECT + public: + explicit FileResolvingTask( + shared_qobject_ptr<QNetworkAccessManager> network, + Flame::Manifest& toProcess); + virtual ~FileResolvingTask() {}; + + const Flame::Manifest& getResults() const + { + return m_toProcess; + } + + protected: + virtual void executeTask() override; + + protected slots: + void netJobFinished(); + + private: /* data */ + shared_qobject_ptr<QNetworkAccessManager> m_network; + Flame::Manifest m_toProcess; + QVector<QByteArray> results; + NetJob::Ptr m_dljob; + }; +} // namespace Flame diff --git a/meshmc/launcher/modplatform/flame/FlamePackIndex.cpp b/meshmc/launcher/modplatform/flame/FlamePackIndex.cpp new file mode 100644 index 0000000000..6808d84f91 --- /dev/null +++ b/meshmc/launcher/modplatform/flame/FlamePackIndex.cpp @@ -0,0 +1,151 @@ +/* SPDX-FileCopyrightText: 2026 Project Tick + * SPDX-FileContributor: Project Tick + * SPDX-License-Identifier: GPL-3.0-or-later + * + * MeshMC - A Custom Launcher for Minecraft + * Copyright (C) 2026 Project Tick + * + * This program 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 3 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#include "FlamePackIndex.h" + +#include "Json.h" + +void Flame::loadIndexedPack(Flame::IndexedPack& pack, QJsonObject& obj) +{ + pack.addonId = Json::requireInteger(obj, "id"); + pack.name = Json::requireString(obj, "name"); + pack.description = Json::ensureString(obj, "summary", ""); + + // API v1: links.websiteUrl, API v2: websiteUrl at root + if (obj.contains("links") && obj.value("links").isObject()) { + pack.websiteUrl = + Json::ensureString(obj.value("links").toObject(), "websiteUrl", ""); + } else { + pack.websiteUrl = Json::ensureString(obj, "websiteUrl", ""); + } + + // API v1: logo is a single object, API v2: attachments is an array + bool thumbnailFound = false; + if (obj.contains("logo") && obj.value("logo").isObject()) { + auto logoObj = obj.value("logo").toObject(); + pack.logoName = Json::ensureString(logoObj, "title", pack.name); + pack.logoUrl = Json::ensureString(logoObj, "thumbnailUrl", ""); + thumbnailFound = !pack.logoUrl.isEmpty(); + } + if (!thumbnailFound && obj.contains("attachments")) { + auto attachments = Json::requireArray(obj, "attachments"); + for (auto attachmentRaw : attachments) { + auto attachmentObj = Json::requireObject(attachmentRaw); + bool isDefault = attachmentObj.value("isDefault").toBool(false); + if (isDefault) { + thumbnailFound = true; + pack.logoName = Json::requireString(attachmentObj, "title"); + pack.logoUrl = + Json::requireString(attachmentObj, "thumbnailUrl"); + break; + } + } + } + if (!thumbnailFound) { + pack.logoName = pack.name; + pack.logoUrl = ""; + } + + auto authors = Json::requireArray(obj, "authors"); + for (auto authorIter : authors) { + auto author = Json::requireObject(authorIter); + Flame::ModpackAuthor packAuthor; + packAuthor.name = Json::requireString(author, "name"); + packAuthor.url = Json::ensureString(author, "url", ""); + pack.authors.append(packAuthor); + } + + // API v1: mainFileId, API v2: defaultFileId + int defaultFileId = 0; + if (obj.contains("mainFileId")) { + defaultFileId = Json::requireInteger(obj, "mainFileId"); + } else { + defaultFileId = Json::requireInteger(obj, "defaultFileId"); + } + + bool found = false; + // check if there are some files before adding the pack + auto files = Json::ensureArray(obj, "latestFiles"); + for (auto fileIter : files) { + auto file = Json::requireObject(fileIter); + int id = Json::requireInteger(file, "id"); + + // NOTE: for now, ignore everything that's not the default... + if (id != defaultFileId) { + continue; + } + + // API v1: gameVersions, API v2: gameVersion + QJsonArray versionArray; + if (file.contains("gameVersions")) { + versionArray = Json::requireArray(file, "gameVersions"); + } else { + versionArray = Json::requireArray(file, "gameVersion"); + } + if (versionArray.size() < 1) { + continue; + } + + found = true; + break; + } + if (!found) { + throw JSONValidationError( + QString("Pack with no good file, skipping: %1").arg(pack.name)); + } +} + +void Flame::loadIndexedPackVersions(Flame::IndexedPack& pack, QJsonArray& arr) +{ + QVector<Flame::IndexedVersion> unsortedVersions; + for (auto versionIter : arr) { + auto version = Json::requireObject(versionIter); + Flame::IndexedVersion file; + + file.addonId = pack.addonId; + file.fileId = Json::requireInteger(version, "id"); + QJsonArray versionArray; + if (version.contains("gameVersions")) { + versionArray = Json::requireArray(version, "gameVersions"); + } else { + versionArray = Json::requireArray(version, "gameVersion"); + } + if (versionArray.size() < 1) { + continue; + } + + // pick the latest version supported + file.mcVersion = versionArray[0].toString(); + file.version = Json::requireString(version, "displayName"); + file.downloadUrl = Json::ensureString(version, "downloadUrl", ""); + file.fileName = Json::ensureString(version, "fileName", ""); + unsortedVersions.append(file); + } + + auto orderSortPredicate = [](const IndexedVersion& a, + const IndexedVersion& b) -> bool { + return a.fileId > b.fileId; + }; + std::sort(unsortedVersions.begin(), unsortedVersions.end(), + orderSortPredicate); + pack.versions = unsortedVersions; + pack.versionsLoaded = true; +} diff --git a/meshmc/launcher/modplatform/flame/FlamePackIndex.h b/meshmc/launcher/modplatform/flame/FlamePackIndex.h new file mode 100644 index 0000000000..ab3ec77ec1 --- /dev/null +++ b/meshmc/launcher/modplatform/flame/FlamePackIndex.h @@ -0,0 +1,63 @@ +/* SPDX-FileCopyrightText: 2026 Project Tick + * SPDX-FileContributor: Project Tick + * SPDX-License-Identifier: GPL-3.0-or-later + * + * MeshMC - A Custom Launcher for Minecraft + * Copyright (C) 2026 Project Tick + * + * This program 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 3 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#pragma once + +#include <QList> +#include <QMetaType> +#include <QString> +#include <QVector> + +namespace Flame +{ + + struct ModpackAuthor { + QString name; + QString url; + }; + + struct IndexedVersion { + int addonId; + int fileId; + QString version; + QString mcVersion; + QString downloadUrl; + QString fileName; + }; + + struct IndexedPack { + int addonId; + QString name; + QString description; + QList<ModpackAuthor> authors; + QString logoName; + QString logoUrl; + QString websiteUrl; + + bool versionsLoaded = false; + QVector<IndexedVersion> versions; + }; + + void loadIndexedPack(IndexedPack& m, QJsonObject& obj); + void loadIndexedPackVersions(IndexedPack& m, QJsonArray& arr); +} // namespace Flame + +Q_DECLARE_METATYPE(Flame::IndexedPack) diff --git a/meshmc/launcher/modplatform/flame/PackManifest.cpp b/meshmc/launcher/modplatform/flame/PackManifest.cpp new file mode 100644 index 0000000000..020370b29f --- /dev/null +++ b/meshmc/launcher/modplatform/flame/PackManifest.cpp @@ -0,0 +1,155 @@ +/* SPDX-FileCopyrightText: 2026 Project Tick + * SPDX-FileContributor: Project Tick + * SPDX-License-Identifier: GPL-3.0-or-later + * + * MeshMC - A Custom Launcher for Minecraft + * Copyright (C) 2026 Project Tick + * + * This program 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 3 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#include "PackManifest.h" +#include "Json.h" + +static void loadFileV1(Flame::File& f, QJsonObject& file) +{ + f.projectId = Json::requireInteger(file, "projectID"); + f.fileId = Json::requireInteger(file, "fileID"); + f.required = Json::ensureBoolean(file, QString("required"), true); +} + +static void loadModloaderV1(Flame::Modloader& m, QJsonObject& modLoader) +{ + m.id = Json::requireString(modLoader, "id"); + m.primary = Json::ensureBoolean(modLoader, QString("primary"), false); +} + +static void loadMinecraftV1(Flame::Minecraft& m, QJsonObject& minecraft) +{ + m.version = Json::requireString(minecraft, "version"); + // extra libraries... apparently only used for a custom Minecraft launcher + // in the 1.2.5 FTB retro pack intended use is likely hardcoded in the + // 'Flame' client, the manifest says nothing + m.libraries = + Json::ensureString(minecraft, QString("libraries"), QString()); + auto arr = Json::ensureArray(minecraft, "modLoaders", QJsonArray()); + for (QJsonValueRef item : arr) { + auto obj = Json::requireObject(item); + Flame::Modloader loader; + loadModloaderV1(loader, obj); + m.modLoaders.append(loader); + } +} + +static void loadManifestV1(Flame::Manifest& m, QJsonObject& manifest) +{ + auto mc = Json::requireObject(manifest, "minecraft"); + loadMinecraftV1(m.minecraft, mc); + m.name = Json::ensureString(manifest, QString("name"), "Unnamed"); + m.version = Json::ensureString(manifest, QString("version"), QString()); + m.author = + Json::ensureString(manifest, QString("author"), "Anonymous Coward"); + auto arr = Json::ensureArray(manifest, "files", QJsonArray()); + for (QJsonValueRef item : arr) { + auto obj = Json::requireObject(item); + Flame::File file; + loadFileV1(file, obj); + m.files.append(file); + } + m.overrides = Json::ensureString(manifest, "overrides", "overrides"); +} + +void Flame::loadManifest(Flame::Manifest& m, const QString& filepath) +{ + auto doc = Json::requireDocument(filepath); + auto obj = Json::requireObject(doc); + m.manifestType = Json::requireString(obj, "manifestType"); + if (m.manifestType != "minecraftModpack") { + throw JSONValidationError("Not a modpack manifest!"); + } + m.manifestVersion = Json::requireInteger(obj, "manifestVersion"); + if (m.manifestVersion != 1) { + throw JSONValidationError( + QString("Unknown manifest version (%1)").arg(m.manifestVersion)); + } + loadManifestV1(m, obj); +} + +bool Flame::File::parseFromBytes(const QByteArray& bytes) +{ + auto doc = Json::requireDocument(bytes); + auto obj = Json::requireObject(doc); + // result code signifies true failure. + if (obj.contains("code")) { + qCritical() << "Resolving of" << projectId << fileId + << "failed because of a negative result:"; + qCritical() << bytes; + return false; + } + // CurseForge API v1 wraps the file object in "data" + if (obj.contains("data")) { + obj = Json::requireObject(obj, "data"); + } + // Support both old cursemeta (FileNameOnDisk) and CurseForge API v1 + // (fileName) field names + fileName = Json::ensureString(obj, "fileName", QString()); + if (fileName.isEmpty()) { + fileName = Json::requireString(obj, "FileNameOnDisk"); + } + QString rawUrl = Json::ensureString(obj, "downloadUrl", QString()); + if (rawUrl.isEmpty()) { + rawUrl = Json::ensureString(obj, "DownloadURL", QString()); + } + if (rawUrl.isEmpty()) { + // Mod has disabled third-party downloads — will be handled via browser + // download + qWarning() << "Mod" << projectId << fileId << "(" << fileName + << ") has no download URL (restricted)." + << "Will require browser download."; + resolved = false; + return true; + } + url = QUrl(rawUrl, QUrl::TolerantMode); + if (!url.isValid()) { + throw JSONValidationError(QString("Invalid URL: %1").arg(rawUrl)); + } + // This is a piece of a Flame project JSON pulled out into the file metadata + // (here) for convenience It is also optional + QJsonObject projObj = Json::ensureObject(obj, "_Project", {}); + if (!projObj.isEmpty()) { + QString strType = + Json::ensureString(projObj, "PackageType", "mod").toLower(); + if (strType == "singlefile") { + type = File::Type::SingleFile; + } else if (strType == "ctoc") { + type = File::Type::Ctoc; + } else if (strType == "cmod2") { + type = File::Type::Cmod2; + } else if (strType == "mod") { + type = File::Type::Mod; + } else if (strType == "folder") { + type = File::Type::Folder; + } else if (strType == "modpack") { + type = File::Type::Modpack; + } else { + qCritical() << "Resolving of" << projectId << fileId + << "failed because of unknown file type:" << strType; + type = File::Type::Unknown; + return false; + } + targetFolder = Json::ensureString(projObj, "Path", "mods"); + } + resolved = true; + return true; +} diff --git a/meshmc/launcher/modplatform/flame/PackManifest.h b/meshmc/launcher/modplatform/flame/PackManifest.h new file mode 100644 index 0000000000..79ffb9585a --- /dev/null +++ b/meshmc/launcher/modplatform/flame/PackManifest.h @@ -0,0 +1,79 @@ +/* SPDX-FileCopyrightText: 2026 Project Tick + * SPDX-FileContributor: Project Tick + * SPDX-License-Identifier: GPL-3.0-or-later + * + * MeshMC - A Custom Launcher for Minecraft + * Copyright (C) 2026 Project Tick + * + * This program 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 3 of the License, or + * (at your option) any later version. + * + * This program 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 this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#pragma once + +#include <QString> +#include <QVector> +#include <QUrl> + +namespace Flame +{ + struct File { + // NOTE: throws JSONValidationError + bool parseFromBytes(const QByteArray& bytes); + + int projectId = 0; + int fileId = 0; + // NOTE: the opposite to 'optional'. This is at the time of writing + // unused. + bool required = true; + + // our + bool resolved = false; + QString fileName; + QUrl url; + QString targetFolder = QLatin1String("mods"); + enum class Type { + Unknown, + Folder, + Ctoc, + SingleFile, + Cmod2, + Modpack, + Mod + } type = Type::Mod; + }; + + struct Modloader { + QString id; + bool primary = false; + }; + + struct Minecraft { + QString version; + QString libraries; + QVector<Flame::Modloader> modLoaders; + }; + + struct Manifest { + QString manifestType; + int manifestVersion = 0; + Flame::Minecraft minecraft; + QString name; + QString version; + QString author; + QVector<Flame::File> files; + QString overrides; + }; + + void loadManifest(Flame::Manifest& m, const QString& filepath); +} // namespace Flame |
