From 18dff33dae386834096256abb05feb1e16a75448 Mon Sep 17 00:00:00 2001 From: Justin Pridgen Date: Mon, 25 Nov 2024 22:04:53 -0500 Subject: [PATCH] Damn... --- CMakeLists.txt | 2 +- changelog.md | 4 ++++ mod.json | 2 +- src/DemonsInBetween.cpp | 21 +++++++++++++++------ src/DemonsInBetween.hpp | 10 ++++++++-- src/classes/DIBInfoPopup.cpp | 6 +++++- src/classes/DIBSearchPopup.cpp | 6 +++++- src/classes/DIBSearchPopup.hpp | 1 + src/hooks/LevelBrowserLayer.cpp | 3 ++- src/hooks/LevelCell.cpp | 7 +++++++ src/hooks/LevelInfoLayer.cpp | 3 ++- src/hooks/LevelSelectLayer.cpp | 6 +++--- 12 files changed, 54 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 803c4a8..5e24177 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64") set(CMAKE_CXX_VISIBILITY_PRESET hidden) -project(DemonsInBetween VERSION 1.4.4) +project(DemonsInBetween VERSION 1.4.5) add_library(${PROJECT_NAME} SHARED src/classes/DIBInfoPopup.cpp diff --git a/changelog.md b/changelog.md index 8f743e2..5254e37 100644 --- a/changelog.md +++ b/changelog.md @@ -1,4 +1,8 @@ # Demons In Between Changelog +## v1.4.5 (2024-11-24) +- Fixed some crashes related to exiting menus too quickly +- Fixed difficulties disappearing on failed requests + ## v1.4.4 (2024-11-24) - Fixed constant reloading of the demon difficulties diff --git a/mod.json b/mod.json index 3dae0dd..fd70f7a 100644 --- a/mod.json +++ b/mod.json @@ -5,7 +5,7 @@ "win": "2.2074", "mac": "2.2074" }, - "version": "v1.4.4", + "version": "v1.4.5", "id": "hiimjustin000.demons_in_between", "name": "Demons In Between", "developer": "hiimjustin000", diff --git a/src/DemonsInBetween.cpp b/src/DemonsInBetween.cpp index f7d8ab5..2ba809f 100644 --- a/src/DemonsInBetween.cpp +++ b/src/DemonsInBetween.cpp @@ -46,25 +46,29 @@ GJFeatureState DemonsInBetween::stateForLevel(GJGameLevel* level) { return state; } -void DemonsInBetween::loadDemonForLevel(EventListener&& listenerRef, int levelID, bool main, std::function const& callback) { +void DemonsInBetween::loadDemonForLevel( + EventListener&& listenerRef, int levelID, bool main, + std::function const& callback, std::function const& preCallback +) { if (LEVELS_LOADED.contains(levelID)) return; auto&& listener = std::move(listenerRef); - listener.bind([callback, levelID, main](web::WebTask::Event* e) { + listener.bind([callback, levelID, main, preCallback](web::WebTask::Event* e) { if (auto res = e->getValue()) { LEVELS_LOADED.insert(levelID); if (!res->ok()) return; auto json = res->json().unwrapOr(matjson::Value()); - if (json["Rating"].isNull()) return; + if (!json.contains("Rating") || json["Rating"].isNull()) return; auto rating = round(json["Rating"].asDouble().unwrapOr(0.0) * 100) / 100; auto difficulty = DemonsInBetween::DIFFICULTY_INDICES[(int)round(rating)]; - auto enjoyment = !json["Enjoyment"].isNull() ? round(json["Enjoyment"].asDouble().unwrapOr(-999.0) * 100) / 100 : -999.0; + auto enjoyment = !json.contains("Enjoyment") || json["Enjoyment"].isNull() ? round(json["Enjoyment"].asDouble().unwrapOr(-999.0) * 100) / 100 : -999.0; auto& gddl = main ? GDDL_MAIN : GDDL; gddl.push_back({ levelID, rating, enjoyment, difficulty }); + preCallback(); queueInMainThread([callback, levelID, main] { callback(demonForLevel(levelID, main)); }); } }); @@ -72,7 +76,10 @@ void DemonsInBetween::loadDemonForLevel(EventListener&& listenerRe listener.setFilter(web::WebRequest().get(fmt::format("https://gdladder.com/api/level/{}", levelID))); } -void DemonsInBetween::searchObjectForPage(EventListener&& listenerRef, int page, bool refresh, std::function const& callback) { +void DemonsInBetween::searchObjectForPage( + EventListener&& listenerRef, int page, bool refresh, + std::function const& callback, std::function const& preCallback +) { auto glm = GameLevelManager::get(); auto searchCache = static_cast(glm->getUserObject("search-cache"_spr)); if (!searchCache) { @@ -84,6 +91,7 @@ void DemonsInBetween::searchObjectForPage(EventListener&& listener if (!refresh && searchCache->objectForKey(searchKey)) { SEARCH_SIZE = SEARCH_SIZES[DIFFICULTY]; MAX_PAGE = (SEARCH_SIZE - 1) / 10; + preCallback(); callback(static_cast(searchCache->objectForKey(searchKey))); return; } @@ -91,7 +99,7 @@ void DemonsInBetween::searchObjectForPage(EventListener&& listener auto tierBound = TIER_BOUNDS[DIFFICULTY]; auto&& listener = std::move(listenerRef); - listener.bind([callback, page](web::WebTask::Event* e) { + listener.bind([callback, page, preCallback](web::WebTask::Event* e) { if (auto res = e->getValue()) { if (!res->ok()) return; @@ -107,6 +115,7 @@ void DemonsInBetween::searchObjectForPage(EventListener&& listener } } + preCallback(); queueInMainThread([callback, levels, page] { auto searchObject = GJSearchObject::create(SearchType::MapPackOnClick, string::join(levels, ",")); if (auto searchCache = static_cast(GameLevelManager::get()->getUserObject("search-cache"_spr))) diff --git a/src/DemonsInBetween.hpp b/src/DemonsInBetween.hpp index 6211721..b1f95fe 100644 --- a/src/DemonsInBetween.hpp +++ b/src/DemonsInBetween.hpp @@ -44,6 +44,12 @@ class DemonsInBetween { static cocos2d::CCSprite* spriteForDifficulty(GJDifficultySprite*, int, GJDifficultyName, GJFeatureState); static int difficultyForDemonDifficulty(int); static GJFeatureState stateForLevel(GJGameLevel*); - static void loadDemonForLevel(geode::EventListener&&, int, bool, std::function const&); - static void searchObjectForPage(geode::EventListener&&, int, bool, std::function const&); + static void loadDemonForLevel( + geode::EventListener&&, int, bool, + std::function const&, std::function const& + ); + static void searchObjectForPage( + geode::EventListener&&, int, bool, + std::function const&, std::function const& + ); }; diff --git a/src/classes/DIBInfoPopup.cpp b/src/classes/DIBInfoPopup.cpp index 17fbf49..6cc5393 100644 --- a/src/classes/DIBInfoPopup.cpp +++ b/src/classes/DIBInfoPopup.cpp @@ -67,7 +67,11 @@ bool DIBInfoPopup::setup() { CACHED_DEMONS.push_back(demon); } - queueInMainThread([this] { setupDemonInfo(); }); + retain(); + queueInMainThread([this] { + setupDemonInfo(); + release(); + }); } }); diff --git a/src/classes/DIBSearchPopup.cpp b/src/classes/DIBSearchPopup.cpp index 6361bf2..479dfe8 100644 --- a/src/classes/DIBSearchPopup.cpp +++ b/src/classes/DIBSearchPopup.cpp @@ -92,11 +92,15 @@ bool DIBSearchPopup::setup() { for (int i = 1; i < 21; i++) { table->addButton(CCMenuItemExt::createSpriteExtraWithFrameName(fmt::format("DIB_{:02d}_btn2_001.png"_spr, i).c_str(), 1.0f, [this, i](auto) { + if (m_isBusy) return; + m_isBusy = true; DemonsInBetween::DIFFICULTY = i; DemonsInBetween::SEARCHING = true; DemonsInBetween::searchObjectForPage(std::move(m_listener), 0, false, [this](GJSearchObject* obj) { CCDirector::get()->pushScene(CCTransitionFade::create(0.5f, LevelBrowserLayer::scene(obj))); - }); + m_isBusy = false; + release(); + }, [this] { retain(); }); })); } diff --git a/src/classes/DIBSearchPopup.hpp b/src/classes/DIBSearchPopup.hpp index ed0e667..ca6b50b 100644 --- a/src/classes/DIBSearchPopup.hpp +++ b/src/classes/DIBSearchPopup.hpp @@ -25,6 +25,7 @@ class TableNode : public cocos2d::CCNode { class DIBSearchPopup : public geode::Popup<> { protected: geode::EventListener m_listener; + bool m_isBusy; bool setup() override; public: diff --git a/src/hooks/LevelBrowserLayer.cpp b/src/hooks/LevelBrowserLayer.cpp index 6147cbb..0d56b8f 100644 --- a/src/hooks/LevelBrowserLayer.cpp +++ b/src/hooks/LevelBrowserLayer.cpp @@ -62,7 +62,8 @@ class $modify(DIBLevelBrowserLayer, LevelBrowserLayer) { DemonsInBetween::searchObjectForPage(std::move(f->m_listener), f->m_currentPage, refresh, [this](GJSearchObject* obj) { m_fields->m_loadingPage = false; loadPage(obj); - }); + release(); + }, [this] { retain(); }); } void updatePageButtons() { diff --git a/src/hooks/LevelCell.cpp b/src/hooks/LevelCell.cpp index 4fd2690..375ca5c 100644 --- a/src/hooks/LevelCell.cpp +++ b/src/hooks/LevelCell.cpp @@ -43,6 +43,13 @@ class $modify(DIBLevelCell, LevelCell) { DemonsInBetween::loadDemonForLevel(std::move(m_fields->m_listener), levelID, false, [this, difficultyContainer, difficultySprite](LadderDemon& demon) { createUI(demon, difficultyContainer, difficultySprite); + release(); + difficultyContainer->release(); + difficultySprite->release(); + }, [this, difficultyContainer, difficultySprite] { + retain(); + difficultyContainer->retain(); + difficultySprite->retain(); }); } diff --git a/src/hooks/LevelInfoLayer.cpp b/src/hooks/LevelInfoLayer.cpp index 1649d25..5964363 100644 --- a/src/hooks/LevelInfoLayer.cpp +++ b/src/hooks/LevelInfoLayer.cpp @@ -40,7 +40,8 @@ class $modify(DIBLevelInfoLayer, LevelInfoLayer) { DemonsInBetween::loadDemonForLevel(std::move(m_fields->m_listener), levelID, false, [this, createDemon](LadderDemon& demon) { createUI(demon, createDemon); - }); + release(); + }, [this] { retain(); }); return true; } diff --git a/src/hooks/LevelSelectLayer.cpp b/src/hooks/LevelSelectLayer.cpp index fc8a3ed..d0d102d 100644 --- a/src/hooks/LevelSelectLayer.cpp +++ b/src/hooks/LevelSelectLayer.cpp @@ -17,15 +17,15 @@ class $modify(DIBLevelSelectLayer, LevelSelectLayer) { auto ladderDemon1 = DemonsInBetween::demonForLevel(14, true); if (ladderDemon1.id == 0 || ladderDemon1.difficulty == 0) - DemonsInBetween::loadDemonForLevel(std::move(f->m_listener1), 1, true, [this](LadderDemon& demon) { demon.id = 14; }); + DemonsInBetween::loadDemonForLevel(std::move(f->m_listener1), 1, true, [this](LadderDemon& demon) { demon.id = 14; }, [this] {}); auto ladderDemon2 = DemonsInBetween::demonForLevel(18, true); if (ladderDemon2.id == 0 || ladderDemon2.difficulty == 0) - DemonsInBetween::loadDemonForLevel(std::move(f->m_listener2), 2, true, [this](LadderDemon& demon) { demon.id = 18; }); + DemonsInBetween::loadDemonForLevel(std::move(f->m_listener2), 2, true, [this](LadderDemon& demon) { demon.id = 18; }, [this] {}); auto ladderDemon3 = DemonsInBetween::demonForLevel(20, true); if (ladderDemon3.id == 0 || ladderDemon3.difficulty == 0) - DemonsInBetween::loadDemonForLevel(std::move(f->m_listener3), 3, true, [this](LadderDemon& demon) { demon.id = 20; }); + DemonsInBetween::loadDemonForLevel(std::move(f->m_listener3), 3, true, [this](LadderDemon& demon) { demon.id = 20; }, [this] {}); return true; }