From e8956ae02ed780cd2e7e390c646eb12fa656d582 Mon Sep 17 00:00:00 2001 From: Edoardo Lolletti Date: Thu, 25 Apr 2024 15:37:31 +0200 Subject: [PATCH] Fix unlaunch being wrongly detected as installed --- arm9/src/main.c | 7 ++++++- arm9/src/unlaunch.c | 14 ++++++++++++++ arm9/src/unlaunch.h | 2 ++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/arm9/src/main.c b/arm9/src/main.c index 6a99a10..8f730a5 100644 --- a/arm9/src/main.c +++ b/arm9/src/main.c @@ -203,6 +203,7 @@ int main(int argc, char **argv) const char* hnaaTmdPath = "nand:/title/00030017/484e4141/content/title.tmd"; { FILE* file = fopen("nand:/sys/HWINFO_S.dat", "rb"); + bool mainTmdIsPatched = false; if (file) { fseek(file, 0xA0, SEEK_SET); @@ -224,6 +225,10 @@ int main(int argc, char **argv) //if size isn't 520 then the tmd either is not present (size 0), or is already invalid, thus no need to patch retailLauncherTmdPresentAndToBePatched = false; } + else + { + mainTmdIsPatched = isLauncherTmdPatched(retailLauncherTmdPath); + } // HWINFO_S may not always exist (PRE_IMPORT). Fill in defaults if that happens. } @@ -231,7 +236,7 @@ int main(int argc, char **argv) // These can normally be identified by having the region set to ALL (0x41) retailConsole = (region != 0x41 && region != 0xFF); - if (!unlaunchFound) + if (!unlaunchFound && (mainTmdIsPatched || !retailConsole)) { unsigned long long tmdSize = getFileSizePath(hnaaTmdPath); if (tmdSize > 520) diff --git a/arm9/src/unlaunch.c b/arm9/src/unlaunch.c index cb20f27..da665fb 100644 --- a/arm9/src/unlaunch.c +++ b/arm9/src/unlaunch.c @@ -8,6 +8,20 @@ static char unlaunchInstallerBuffer[0x30000]; static const char* hnaaTmdPath = "nand:/title/00030017/484e4141/content/title.tmd"; +bool isLauncherTmdPatched(const char* path) +{ + FILE* launcherTmd = fopen(path, "rb"); + if(!launcherTmd) + { + return false; + } + fseek(launcherTmd, 0x190, SEEK_SET); + char c; + fread(&c, 1, 1, launcherTmd); + fclose(launcherTmd); + return c == 0x47; +} + static bool restoreMainTmd(const char* path) { FILE* launcherTmd = fopen(path, "r+b"); diff --git a/arm9/src/unlaunch.h b/arm9/src/unlaunch.h index 4c74d6b..bbc5cee 100644 --- a/arm9/src/unlaunch.h +++ b/arm9/src/unlaunch.h @@ -5,4 +5,6 @@ bool uninstallUnlaunch(bool notProto, const char* retailLauncherTmdPath); bool installUnlaunch(bool retailConsole, const char* retailLauncherTmdPath); +bool isLauncherTmdPatched(const char* path); + #endif \ No newline at end of file