From d95c2f3e3c4cbbfd5cc022cfef057561c4031c03 Mon Sep 17 00:00:00 2001 From: HJfod <60038575+HJfod@users.noreply.github.com> Date: Mon, 12 Dec 2022 13:46:00 +0200 Subject: [PATCH] loader stuff - remove InternalLoader info alerts - make sure mods that need early load are early loaded --- loader/include/Geode/loader/Mod.hpp | 5 ++++- loader/src/hooks/LoadingLayer.cpp | 2 ++ loader/src/internal/InternalLoader.cpp | 16 ---------------- loader/src/internal/InternalLoader.hpp | 11 ----------- loader/src/ui/internal/info/ModInfoPopup.cpp | 9 +++++---- loader/src/ui/internal/list/ModListCell.cpp | 2 +- 6 files changed, 12 insertions(+), 33 deletions(-) diff --git a/loader/include/Geode/loader/Mod.hpp b/loader/include/Geode/loader/Mod.hpp index ae917d42..fcb613b3 100644 --- a/loader/include/Geode/loader/Mod.hpp +++ b/loader/include/Geode/loader/Mod.hpp @@ -207,10 +207,13 @@ namespace geode { * closed, the value is automatically saved under the key * @param key Key of the saved value * @param value Value + * @returns The old value */ template - void setSavedValue(std::string const& key, T const& value) { + T setSavedValue(std::string const& key, T const& value) { + auto old = this->getSavedValue(key); m_saved[key] = value; + return old; } /** diff --git a/loader/src/hooks/LoadingLayer.cpp b/loader/src/hooks/LoadingLayer.cpp index 32864c74..b1a973a3 100644 --- a/loader/src/hooks/LoadingLayer.cpp +++ b/loader/src/hooks/LoadingLayer.cpp @@ -13,6 +13,8 @@ struct CustomLoadingLayer : Modify { CustomLoadingLayer() : m_updatingResources(false) {} bool init(bool fromReload) { + Loader::get()->waitForModsToBeLoaded(); + if (!LoadingLayer::init(fromReload)) return false; auto winSize = CCDirector::sharedDirector()->getWinSize(); diff --git a/loader/src/internal/InternalLoader.cpp b/loader/src/internal/InternalLoader.cpp index 8af2ddaf..004688fe 100644 --- a/loader/src/internal/InternalLoader.cpp +++ b/loader/src/internal/InternalLoader.cpp @@ -115,22 +115,6 @@ bool InternalLoader::platformConsoleOpen() const { return m_platformConsoleOpen; } -bool InternalLoader::shownInfoAlert(std::string const& key) { - if (m_shownInfoAlerts.count(key)) { - return true; - } - m_shownInfoAlerts.insert(key); - return false; -} - -void InternalLoader::saveInfoAlerts(nlohmann::json& json) { - json["alerts"] = m_shownInfoAlerts; -} - -void InternalLoader::loadInfoAlerts(nlohmann::json& json) { - m_shownInfoAlerts = json["alerts"].get>(); -} - void InternalLoader::downloadLoaderResources() { auto version = this->getVersion().toString(); auto tempResourcesZip = dirs::getTempDir() / "new.zip"; diff --git a/loader/src/internal/InternalLoader.hpp b/loader/src/internal/InternalLoader.hpp index 043da556..05cf8f01 100644 --- a/loader/src/internal/InternalLoader.hpp +++ b/loader/src/internal/InternalLoader.hpp @@ -39,14 +39,10 @@ protected: std::vector> m_gdThreadQueue; mutable std::mutex m_gdThreadMutex; bool m_platformConsoleOpen = false; - std::unordered_set m_shownInfoAlerts; std::vector> m_internalHooks; bool m_readyToHook; - void saveInfoAlerts(nlohmann::json& json); - void loadInfoAlerts(nlohmann::json& json); - void downloadLoaderResources(); bool loadHooks(); @@ -64,13 +60,6 @@ public: static nlohmann::json processRawIPC(void* rawHandle, std::string const& buffer); - /** - * Check if a one-time event has been shown to the user, - * and set it to true if not. Will return the previous - * state of the event before setting it to true - */ - bool shownInfoAlert(std::string const& key); - void queueInGDThread(ScheduledFunction func); void executeGDThreadQueue(); diff --git a/loader/src/ui/internal/info/ModInfoPopup.cpp b/loader/src/ui/internal/info/ModInfoPopup.cpp index 0aee639a..047d5609 100644 --- a/loader/src/ui/internal/info/ModInfoPopup.cpp +++ b/loader/src/ui/internal/info/ModInfoPopup.cpp @@ -447,14 +447,15 @@ void LocalModInfoPopup::onUninstall(CCObject*) { } void LocalModInfoPopup::onEnableMod(CCObject* sender) { - if (!InternalLoader::get()->shownInfoAlert("mod-disable-vs-unload")) { + if (!Mod::get()->setSavedValue("shown-disable-vs-unload-info", true)) { FLAlertLayer::create( "Notice", - "You may still see some effects of the mod left, and you may " + "Disabling a mod removes its hooks & patches and " + "calls its user-defined disable function if one exists. You may " + "still see some effects of the mod left however, and you may " "need to restart the game to have it fully unloaded.", "OK" - ) - ->show(); + )->show(); if (m_layer) m_layer->updateAllStates(nullptr); return; } diff --git a/loader/src/ui/internal/list/ModListCell.cpp b/loader/src/ui/internal/list/ModListCell.cpp index 15cfef74..838a022a 100644 --- a/loader/src/ui/internal/list/ModListCell.cpp +++ b/loader/src/ui/internal/list/ModListCell.cpp @@ -146,7 +146,7 @@ ModCell* ModCell::create( } void ModCell::onEnable(CCObject* sender) { - if (!InternalLoader::get()->shownInfoAlert("mod-disable-vs-unload")) { + if (!Mod::get()->setSavedValue("shown-disable-vs-unload-info", true)) { FLAlertLayer::create( "Notice", "Disabling a mod removes its hooks & patches and "