From 5c457251d41fae481b5054167482cdd5adff7703 Mon Sep 17 00:00:00 2001 From: altalk23 <45172705+altalk23@users.noreply.github.com> Date: Sun, 4 Feb 2024 12:41:18 +0300 Subject: [PATCH] some problems rework --- loader/src/hooks/MenuLayer.cpp | 4 +++ loader/src/internal/crashlog.cpp | 6 +++- loader/src/loader/LoaderImpl.cpp | 36 +++++++++++-------- loader/src/loader/LoaderImpl.hpp | 2 ++ loader/src/loader/ModImpl.cpp | 13 +++++++ loader/src/loader/ModImpl.hpp | 5 +++ loader/src/ui/internal/list/ModListCell.cpp | 10 +----- .../ui/internal/list/ProblemsListPopup.cpp | 4 +-- 8 files changed, 54 insertions(+), 26 deletions(-) diff --git a/loader/src/hooks/MenuLayer.cpp b/loader/src/hooks/MenuLayer.cpp index db1da216..f18e0e7c 100644 --- a/loader/src/hooks/MenuLayer.cpp +++ b/loader/src/hooks/MenuLayer.cpp @@ -65,6 +65,10 @@ struct CustomMenuLayer : Modify { m_fields->m_menuDisabled = Loader::get()->getLaunchFlag("disable-custom-menu"); + std::stringstream ss; + crashlog::printMods(ss); + log::debug("Test {}", ss.str()); + // add geode button if (!m_fields->m_menuDisabled) { m_fields->m_geodeButton = CircleButtonSprite::createWithSpriteFrameName( diff --git a/loader/src/internal/crashlog.cpp b/loader/src/internal/crashlog.cpp index d3ecbd9b..ced31b1f 100644 --- a/loader/src/internal/crashlog.cpp +++ b/loader/src/internal/crashlog.cpp @@ -41,7 +41,11 @@ void crashlog::printMods(std::stringstream& stream) { using namespace std::string_view_literals; for (auto& mod : mods) { stream << fmt::format("{} | [{}] {}\n", - mod->isEnabled() ? "x"sv : mod->shouldLoad() ? "~"sv : ModImpl::getImpl(mod)->isCurrentlyLoading() ? "o"sv : " "sv, + mod->isEnabled() ? "x"sv : + ModImpl::getImpl(mod)->hasProblems() ? "!"sv : // thank you for this bug report + mod->shouldLoad() ? "~"sv : + ModImpl::getImpl(mod)->isCurrentlyLoading() ? "o"sv : + " "sv, mod->getVersion().toString(), mod->getID() ); } diff --git a/loader/src/loader/LoaderImpl.cpp b/loader/src/loader/LoaderImpl.cpp index 44c2f119..14ec63f7 100644 --- a/loader/src/loader/LoaderImpl.cpp +++ b/loader/src/loader/LoaderImpl.cpp @@ -246,6 +246,14 @@ void Loader::Impl::updateModResources(Mod* mod) { log::popNest(); } +void Loader::Impl::addProblem(LoadProblem const& problem) { + if (std::holds_alternative(problem.cause)) { + auto mod = std::get(problem.cause); + ModImpl::getImpl(mod)->m_problems.push_back(problem); + } + m_problems.push_back(problem); +} + // Dependencies and refreshing void Loader::Impl::queueMods(std::vector& modQueue) { @@ -262,7 +270,7 @@ void Loader::Impl::queueMods(std::vector& modQueue) { auto res = ModMetadata::createFromGeodeFile(entry.path()); if (!res) { - m_problems.push_back({ + this->addProblem({ LoadProblem::Type::InvalidFile, entry.path(), res.unwrapErr() @@ -280,7 +288,7 @@ void Loader::Impl::queueMods(std::vector& modQueue) { if (std::find_if(modQueue.begin(), modQueue.end(), [&](auto& item) { return modMetadata.getID() == item.getID(); }) != modQueue.end()) { - m_problems.push_back({ + this->addProblem({ LoadProblem::Type::Duplicate, modMetadata, "A mod with the same ID is already present." @@ -317,7 +325,7 @@ void Loader::Impl::populateModList(std::vector& modQueue) { auto res = mod->m_impl->setup(); if (!res) { - m_problems.push_back({ + this->addProblem({ LoadProblem::Type::SetupFailed, mod, res.unwrapErr() @@ -406,7 +414,7 @@ void Loader::Impl::loadModGraph(Mod* node, bool early) { log::debug("Load"); auto res = node->m_impl->loadBinary(); if (!res) { - m_problems.push_back({ + this->addProblem({ LoadProblem::Type::LoadFailed, node, res.unwrapErr() @@ -427,7 +435,7 @@ void Loader::Impl::loadModGraph(Mod* node, bool early) { { // version checking auto res = node->getMetadata().checkGameVersion(); if (!res) { - m_problems.push_back({ + this->addProblem({ LoadProblem::Type::UnsupportedVersion, node, res.unwrapErr() @@ -439,7 +447,7 @@ void Loader::Impl::loadModGraph(Mod* node, bool early) { } if (!this->isModVersionSupported(node->getMetadata().getGeodeVersion())) { - m_problems.push_back({ + this->addProblem({ LoadProblem::Type::UnsupportedGeodeVersion, node, fmt::format( @@ -458,7 +466,7 @@ void Loader::Impl::loadModGraph(Mod* node, bool early) { if (early) { auto res = unzipFunction(); if (!res) { - m_problems.push_back({ + this->addProblem({ LoadProblem::Type::UnzipFailed, node, res.unwrapErr() @@ -480,7 +488,7 @@ void Loader::Impl::loadModGraph(Mod* node, bool early) { auto prevNest = log::saveNest(); log::loadNest(nest); if (!res) { - m_problems.push_back({ + this->addProblem({ LoadProblem::Type::UnzipFailed, node, res.unwrapErr() @@ -512,7 +520,7 @@ void Loader::Impl::findProblems() { continue; switch(dep.importance) { case ModMetadata::Dependency::Importance::Suggested: - m_problems.push_back({ + this->addProblem({ LoadProblem::Type::Suggestion, mod, fmt::format("{} {}", dep.id, dep.version.toString()) @@ -520,7 +528,7 @@ void Loader::Impl::findProblems() { log::info("{} suggests {} {}", id, dep.id, dep.version); break; case ModMetadata::Dependency::Importance::Recommended: - m_problems.push_back({ + this->addProblem({ LoadProblem::Type::Recommendation, mod, fmt::format("{} {}", dep.id, dep.version.toString()) @@ -528,7 +536,7 @@ void Loader::Impl::findProblems() { log::warn("{} recommends {} {}", id, dep.id, dep.version); break; case ModMetadata::Dependency::Importance::Required: - m_problems.push_back({ + this->addProblem({ LoadProblem::Type::MissingDependency, mod, fmt::format("{} {}", dep.id, dep.version.toString()) @@ -543,7 +551,7 @@ void Loader::Impl::findProblems() { continue; switch(dep.importance) { case ModMetadata::Incompatibility::Importance::Conflicting: - m_problems.push_back({ + this->addProblem({ LoadProblem::Type::Conflict, mod, fmt::format("{} {}", dep.id, dep.version.toString()) @@ -551,7 +559,7 @@ void Loader::Impl::findProblems() { log::warn("{} conflicts with {} {}", id, dep.id, dep.version); break; case ModMetadata::Incompatibility::Importance::Breaking: - m_problems.push_back({ + this->addProblem({ LoadProblem::Type::PresentIncompatibility, mod, fmt::format("{} {}", dep.id, dep.version.toString()) @@ -571,7 +579,7 @@ void Loader::Impl::findProblems() { std::holds_alternative(item.cause) && std::get(item.cause) == myEpicMod; })) { - m_problems.push_back({ + this->addProblem({ LoadProblem::Type::Unknown, mod, "" diff --git a/loader/src/loader/LoaderImpl.hpp b/loader/src/loader/LoaderImpl.hpp index d55361f0..10992b8e 100644 --- a/loader/src/loader/LoaderImpl.hpp +++ b/loader/src/loader/LoaderImpl.hpp @@ -133,6 +133,8 @@ namespace geode { Result<> setupInternalMod(); bool userTriedToLoadDLLs() const; + + void addProblem(LoadProblem const& problem); }; class LoaderImpl : public Loader::Impl { diff --git a/loader/src/loader/ModImpl.cpp b/loader/src/loader/ModImpl.cpp index e38f0738..d1cd46e8 100644 --- a/loader/src/loader/ModImpl.cpp +++ b/loader/src/loader/ModImpl.cpp @@ -746,6 +746,19 @@ bool Mod::Impl::isCurrentlyLoading() const { return m_isCurrentlyLoading; } +bool Mod::Impl::hasProblems() const { + for (auto const& item : m_problems) { + if (item.type <= LoadProblem::Type::Recommendation) + continue; + return true; + } + return false; +} + +std::vector Mod::Impl::getProblems() const { + return m_problems; +} + static Result getModImplInfo() { std::string error; auto res = matjson::parse(LOADER_MOD_JSON, error); diff --git a/loader/src/loader/ModImpl.hpp b/loader/src/loader/ModImpl.hpp index 5600465f..216632f2 100644 --- a/loader/src/loader/ModImpl.hpp +++ b/loader/src/loader/ModImpl.hpp @@ -68,6 +68,8 @@ namespace geode { ModRequestedAction m_requestedAction = ModRequestedAction::None; + std::vector m_problems; + Impl(Mod* self, ModMetadata const& metadata); ~Impl(); @@ -150,6 +152,9 @@ namespace geode { bool isLoggingEnabled() const; void setLoggingEnabled(bool enabled); + std::vector getProblems() const; + + bool hasProblems() const; bool shouldLoad() const; bool isCurrentlyLoading() const; }; diff --git a/loader/src/ui/internal/list/ModListCell.cpp b/loader/src/ui/internal/list/ModListCell.cpp index f3e817a9..088f7f33 100644 --- a/loader/src/ui/internal/list/ModListCell.cpp +++ b/loader/src/ui/internal/list/ModListCell.cpp @@ -274,15 +274,7 @@ void ModCell::updateState() { m_enableToggle->m_onButton->setOpacity(!toggleable ? 100 : 255); m_enableToggle->m_onButton->setColor(!toggleable ? cc3x(155) : cc3x(255)); } - bool hasProblems = false; - for (auto const& item : Loader::get()->getProblems()) { - if (!std::holds_alternative(item.cause) || - std::get(item.cause) != m_mod || - item.type <= LoadProblem::Type::Recommendation) - continue; - hasProblems = true; - break; - } + bool hasProblems = ModImpl::getImpl(m_mod)->hasProblems(); m_unresolvedExMark->setVisible(hasProblems); this->updateCellLayout(); diff --git a/loader/src/ui/internal/list/ProblemsListPopup.cpp b/loader/src/ui/internal/list/ProblemsListPopup.cpp index 9140c115..d3db822e 100644 --- a/loader/src/ui/internal/list/ProblemsListPopup.cpp +++ b/loader/src/ui/internal/list/ProblemsListPopup.cpp @@ -1,6 +1,6 @@ #include "ProblemsListPopup.hpp" #include "ProblemsListCell.hpp" - +#include "../../../loader/ModImpl.hpp" #include #include @@ -39,7 +39,7 @@ CCArray* ProblemsListPopup::createCells(Mod* scrollTo, float& scrollValue) { std::vector middle; std::vector bottom; - for (auto const& problem : Loader::get()->getProblems()) { + for (auto const& problem : scrollTo ? ModImpl::getImpl(scrollTo)->getProblems() : Loader::get()->getProblems()) { switch (problem.type) { case geode::LoadProblem::Type::Suggestion: bottom.push_back(ProblemsListCell::create(problem, this, this->getCellSize()));