Skip to content

Commit

Permalink
improve tp detection
Browse files Browse the repository at this point in the history
  • Loading branch information
dankmeme01 committed Nov 30, 2024
1 parent 2827b0d commit 6521d8d
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 8 deletions.
4 changes: 3 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
54 changes: 48 additions & 6 deletions src/hooks/menu_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,38 +159,71 @@ void HookedMenuLayer::maybeUpdateButton(float) {

void HookedMenuLayer::onGlobedButton(CCObject*) {
if (softDisabled) {

geode::createQuickPopup(
"Globed Error",
"<cy>Outdated resources</c> were detected. The mod has been <cr>disabled</c> to prevent crashes.\n\nIf you have any <cg>texture packs</c>, or mods that change textures, please try <cy>disabling</c> 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

auto impostorFolderLoc = dirs::getGameDir() / "Resources" / "dankmeme.globed2";
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",
Expand Down Expand Up @@ -221,15 +254,24 @@ void HookedMenuLayer::onGlobedButton(CCObject*) {
}
);
} else if (texturePack || darkmode) {
std::string enabledtxt;
if (texturePack) {
enabledtxt += "Globed texture pack detected: <cg>yes</c>\n";
}

if (darkmode) {
enabledtxt += "DarkMode v4 enabled: <cg>yes</c>\n";
}

FLAlertLayer::create(
"Note",
fmt::format("Globed texture pack detected: {}</c>\nDarkMode v4 enabled: {}</c>\n\nPlease try to <cr>disable</c> these and see if the issue is resolved after restarting.", texturePack ? "<cg>yes" : "<cr>no", darkmode ? "<cg>yes" : "<cr>no"),
fmt::format("{}\nPlease try to <cr>disable</c> these and see if the issue is resolved after restarting.\n\nDebug data: <cy>{}</c>", enabledtxt, debugData),
"Ok"
)->show();
} else {
geode::createQuickPopup(
"Error",
"Failed to determine the root cause of the issue. Please create a <cy>bug report</c> on our GitHub page.",
fmt::format("Failed to determine the root cause of the issue. Please create a <cy>bug report</c> on our GitHub page, including this information:\n\nDebug data: <cy>{}</c>", debugData),
"Dismiss",
"Open page",
[](auto, bool open) {
Expand Down

0 comments on commit 6521d8d

Please sign in to comment.