From 6521d8dbb3b250fed003146ccfae9f698ff8003b Mon Sep 17 00:00:00 2001 From: dankmeme01 <42031238+dankmeme01@users.noreply.github.com> Date: Sat, 30 Nov 2024 02:22:21 +0100 Subject: [PATCH] improve tp detection --- changelog.md | 4 ++- mod.json | 2 +- src/hooks/menu_layer.cpp | 54 +++++++++++++++++++++++++++++++++++----- 3 files changed, 52 insertions(+), 8 deletions(-) diff --git a/changelog.md b/changelog.md index bdedaddef..2d49a2950 100644 --- a/changelog.md +++ b/changelog.md @@ -1,6 +1,8 @@ ## v1.7.2 -* Fix crash when viewing changelog popup +* Make some corrections to the texture pack detection algorithm +* Fix rare crash when viewing changelog popup +* Fix rare crash caused by a race condition ## v1.7.1 diff --git a/mod.json b/mod.json index 8e2dbf05f..206f9e241 100644 --- a/mod.json +++ b/mod.json @@ -3,7 +3,7 @@ "name": "Globed", "developer": "dankmeme", "geode": "4.0.1", - "version": "v1.7.1", + "version": "v1.7.2", "gd": { "win": "2.2074", "android": "2.2074", diff --git a/src/hooks/menu_layer.cpp b/src/hooks/menu_layer.cpp index 78bb2a3fe..375d1b2c2 100644 --- a/src/hooks/menu_layer.cpp +++ b/src/hooks/menu_layer.cpp @@ -159,31 +159,60 @@ void HookedMenuLayer::maybeUpdateButton(float) { void HookedMenuLayer::onGlobedButton(CCObject*) { if (softDisabled) { + geode::createQuickPopup( "Globed Error", "Outdated resources were detected. The mod has been disabled to prevent crashes.\n\nIf you have any texture packs, or mods that change textures, please try disabling them.", "Dismiss", "More info", [](auto, bool moreInfo) { - if (!moreInfo) return; - bool texturePack = [] { - // auto hasLdr = Loader::get()->isModLoaded("geode.texture-loader"); - // if (!hasLdr) return false; + // Debug data format: + // gs1:0 - all is good + // gs1:-1 - globedsheet1.png not found + // gs1:-2 - globedsheet1.plist not found + // gs1:1 - tp detected, png and plist are in different folders + // gs1:2 - tp detected, png or plist in wrong folder + // dmv4:1 - darkmode v4 detected + std::string debugData; + if (!moreInfo) return; + + bool texturePack = [&] { // check if filename of a globedsheet1.png is overriden auto p = CCFileUtils::get()->fullPathForFilename("globedsheet1.png"_spr, false); + auto plist = CCFileUtils::get()->fullPathForFilename("globedsheet1.plist"_spr, false); + if (p.empty()) { log::error("Failed to find globedsheet1.png"); + debugData += "gs1:-1;"; return false; } + if (plist.empty()) { + log::error("Failed to find globedsheet1.plist"); + debugData += "gs1:-2;"; + return false; + } + + if (std::filesystem::path(std::string(p)).parent_path() != std::filesystem::path(std::string(plist)).parent_path()) { + log::debug("Mismatch, globedsheet1.plist and globedsheet1.png are in different places ({} and {})", p, plist); + debugData += "gs1:1;"; + return true; + } + if (std::filesystem::path(std::string(p)).parent_path() != Mod::get()->getResourcesDir()) { log::debug("Mismatch, globedsheet1 expected in {}, found at {}", Mod::get()->getResourcesDir(), p); + debugData += "gs1:2;"; return true; } + debugData += "gs1:0;"; return false; }(); + bool darkmode = Loader::get()->isModLoaded("bitz.darkmode_v4"); + if (darkmode) { + debugData += "dmv4:1;"; + } // TODO: for android, check if the dankmeme.globed2 folder is in the apk @@ -191,6 +220,10 @@ void HookedMenuLayer::onGlobedButton(CCObject*) { std::error_code ec{}; bool impostorFolder = std::filesystem::exists(impostorFolderLoc) && ec == std::error_code{}; + debugData += fmt::format("impf:{};", impostorFolder ? "1" : "0"); + + log::debug("complete tp debug data: {}", debugData); + if (impostorFolder) { geode::createQuickPopup( "Note", @@ -221,15 +254,24 @@ void HookedMenuLayer::onGlobedButton(CCObject*) { } ); } else if (texturePack || darkmode) { + std::string enabledtxt; + if (texturePack) { + enabledtxt += "Globed texture pack detected: yes\n"; + } + + if (darkmode) { + enabledtxt += "DarkMode v4 enabled: yes\n"; + } + FLAlertLayer::create( "Note", - fmt::format("Globed texture pack detected: {}\nDarkMode v4 enabled: {}\n\nPlease try to disable these and see if the issue is resolved after restarting.", texturePack ? "yes" : "no", darkmode ? "yes" : "no"), + fmt::format("{}\nPlease try to disable these and see if the issue is resolved after restarting.\n\nDebug data: {}", enabledtxt, debugData), "Ok" )->show(); } else { geode::createQuickPopup( "Error", - "Failed to determine the root cause of the issue. Please create a bug report on our GitHub page.", + fmt::format("Failed to determine the root cause of the issue. Please create a bug report on our GitHub page, including this information:\n\nDebug data: {}", debugData), "Dismiss", "Open page", [](auto, bool open) {