From e2d503456f668d0a3f58f66c96b0421754f744a8 Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Thu, 12 Feb 2026 16:43:11 +0000 Subject: [PATCH] Detect resources incompatible with the MC version Signed-off-by: TheKodeToad --- launcher/minecraft/mod/ModFolderModel.cpp | 6 ++++-- launcher/minecraft/mod/Resource.cpp | 20 +++++++++++++++++++ launcher/minecraft/mod/Resource.h | 11 ++++++++++ .../minecraft/mod/ResourceFolderModel.cpp | 11 +++++++++- .../mod/tasks/ResourceFolderLoadTask.h | 4 +++- 5 files changed, 48 insertions(+), 4 deletions(-) diff --git a/launcher/minecraft/mod/ModFolderModel.cpp b/launcher/minecraft/mod/ModFolderModel.cpp index 8b849dc43..e7bb13128 100644 --- a/launcher/minecraft/mod/ModFolderModel.cpp +++ b/launcher/minecraft/mod/ModFolderModel.cpp @@ -258,9 +258,11 @@ void ModFolderModel::onParseSucceeded(int ticket, QString mod_id) auto resource = find(mod_id); auto result = cast_task->result(); - if (result && resource) - static_cast(resource.get())->finishResolvingWithDetails(std::move(result->details)); + if (result && resource) { + auto* mod = static_cast(resource.get()); + mod->finishResolvingWithDetails(std::move(result->details)); + } emit dataChanged(index(row, RequiresColumn), index(row, RequiredByColumn)); } diff --git a/launcher/minecraft/mod/Resource.cpp b/launcher/minecraft/mod/Resource.cpp index 8f67d5d94..64bf14b6c 100644 --- a/launcher/minecraft/mod/Resource.cpp +++ b/launcher/minecraft/mod/Resource.cpp @@ -7,6 +7,8 @@ #include "FileSystem.h" #include "StringUtils.h" +#include "minecraft/MinecraftInstance.h" +#include "minecraft/PackProfile.h" Resource::Resource(QObject* parent) : QObject(parent) {} @@ -111,6 +113,24 @@ void Resource::setMetadata(std::shared_ptr&& metadata) m_metadata = metadata; } +void Resource::determineCompat(const BaseInstance* inst) { + if (m_metadata == nullptr) { + m_isCompatible = true; + return; + } + + auto mcInst = dynamic_cast(inst); + if (mcInst == nullptr) { + m_isCompatible = true; + return; + } + + auto profile = mcInst->getPackProfile(); + QString mcVersion = profile->getComponentVersion("net.minecraft"); + + m_isCompatible = m_metadata->mcVersions.contains(mcVersion); +} + int Resource::compare(const Resource& other, SortType type) const { switch (type) { diff --git a/launcher/minecraft/mod/Resource.h b/launcher/minecraft/mod/Resource.h index 3eda4c013..7121a8a6b 100644 --- a/launcher/minecraft/mod/Resource.h +++ b/launcher/minecraft/mod/Resource.h @@ -43,6 +43,8 @@ #include "MetadataHandler.h" #include "QObjectPtr.h" +class BaseInstance; + enum class ResourceType { UNKNOWN, //!< Indicates an unspecified resource type. ZIPFILE, //!< The resource is a zip file containing the resource's class files. @@ -119,6 +121,13 @@ class Resource : public QObject { void setMetadata(std::shared_ptr&& metadata); void setMetadata(const Metadata::ModStruct& metadata) { setMetadata(std::make_shared(metadata)); } + /** + * Returns whether the resource is compatible with the instance. + * This is initially true, and may be updated when calling determineCompat with an instance. + */ + bool isCompatible() const { return m_isCompatible; } + void determineCompat(const BaseInstance* inst); + /** Compares two Resources, for sorting purposes, considering a ascending order, returning: * > 0: 'this' comes after 'other' * = 0: 'this' is equal to 'other' @@ -188,6 +197,8 @@ class Resource : public QObject { /* Whether the resource is enabled (e.g. shows up in the game) or not. */ bool m_enabled = true; + bool m_isCompatible = true; + /* Used to keep trach of pending / concluded actions on the resource. */ bool m_is_resolving = false; bool m_is_resolved = false; diff --git a/launcher/minecraft/mod/ResourceFolderModel.cpp b/launcher/minecraft/mod/ResourceFolderModel.cpp index 9b7193a4c..532eb8d66 100644 --- a/launcher/minecraft/mod/ResourceFolderModel.cpp +++ b/launcher/minecraft/mod/ResourceFolderModel.cpp @@ -810,7 +810,13 @@ void ResourceFolderModel::applyUpdates(QSet& current_set, QSet auto const& current_resource = m_resources.at(row); if (new_resource->dateTimeChanged() == current_resource->dateTimeChanged()) { - // no significant change, ignore... + // no significant change + bool oldCompat = current_resource->isCompatible(); + current_resource->determineCompat(m_instance); + + if (current_resource->isCompatible() != oldCompat) { + emit dataChanged(index(row, 0), index(row, columnCount({}) - 1)); + } continue; } @@ -825,6 +831,8 @@ void ResourceFolderModel::applyUpdates(QSet& current_set, QSet } m_resources[row].reset(new_resource); + new_resource->determineCompat(m_instance); + resolveResource(m_resources.at(row)); emit dataChanged(index(row, 0), index(row, columnCount(QModelIndex()) - 1)); } @@ -872,6 +880,7 @@ void ResourceFolderModel::applyUpdates(QSet& current_set, QSet for (auto& added : added_set) { auto res = new_resources[added]; + res->determineCompat(m_instance); m_resources.append(res); resolveResource(m_resources.last()); } diff --git a/launcher/minecraft/mod/tasks/ResourceFolderLoadTask.h b/launcher/minecraft/mod/tasks/ResourceFolderLoadTask.h index 7c872c13d..7f69a1841 100644 --- a/launcher/minecraft/mod/tasks/ResourceFolderLoadTask.h +++ b/launcher/minecraft/mod/tasks/ResourceFolderLoadTask.h @@ -41,9 +41,11 @@ #include #include #include -#include "minecraft/mod/Mod.h" +#include "minecraft/mod/Resource.h" #include "tasks/Task.h" +class BaseInstance; + class ResourceFolderLoadTask : public Task { Q_OBJECT public: