- Region detection for the system is now using setting.txt

- Without Konami you can't install a vWii menu
- Removed unused code
This commit is contained in:
0verjoY 2023-03-06 15:32:03 +01:00
parent be66aa76cf
commit 4c79610cbf
5 changed files with 117 additions and 257 deletions

View File

@ -39,14 +39,11 @@ static u8 gDirLevel = 0;
static char gDirList [MAX_DIR_LEVELS][MAX_FILE_PATH_LEN]; static char gDirList [MAX_DIR_LEVELS][MAX_FILE_PATH_LEN];
static s32 gSeleted[MAX_DIR_LEVELS]; static s32 gSeleted[MAX_DIR_LEVELS];
static s32 gStart[MAX_DIR_LEVELS]; static s32 gStart[MAX_DIR_LEVELS];
static char gMenuRegion = '\0';
static u16 gMenuVersion = 0;
static u8 gSelected = 0; static u8 gSelected = 0;
static bool gNeedPriiloaderOption = false; static bool gNeedPriiloaderOption = false;
/* Macros */ /* Macros */
//#define NB_FAT_DEVICES (sizeof(fdevList) / sizeof(fatDevice))
#define NB_NAND_DEVICES (sizeof(ndevList) / sizeof(nandDevice)) #define NB_NAND_DEVICES (sizeof(ndevList) / sizeof(nandDevice))
// Local prototypes: wiiNinja // Local prototypes: wiiNinja
@ -71,7 +68,6 @@ int __Menu_IsGreater(const void *p1, const void *p2)
return (n1 > n2) ? 1 : -1; return (n1 > n2) ? 1 : -1;
} }
int __Menu_EntryCmp(const void *p1, const void *p2) int __Menu_EntryCmp(const void *p1, const void *p2)
{ {
fatFile *f1 = (fatFile *)p1; fatFile *f1 = (fatFile *)p1;
@ -323,7 +319,10 @@ void Menu_FatDevice(void)
int codePosition = 0; int codePosition = 0;
extern bool skipRegionSafetyCheck; extern bool skipRegionSafetyCheck;
GetSysMenuRegion(&gMenuVersion, &gMenuRegion); char region = '\0';
u16 version = 0;
GetSysMenuRegion(&version, &region);
bool havePriiloader = IsPriiloaderInstalled(); bool havePriiloader = IsPriiloaderInstalled();
u32 ios = *((u32*)0x80003140); u32 ios = *((u32*)0x80003140);
@ -336,12 +335,15 @@ void Menu_FatDevice(void)
Con_Clear(); Con_Clear();
bool deviceOk = (FatGetDeviceCount() > 0); bool deviceOk = (FatGetDeviceCount() > 0);
printf("\tIOS %d v%d, System menu: %s%c %s\n\n", ((ios >> 16) & 0xFF), (ios & 0xFFFF), if (VersionIsOriginal(version))
GetSysMenuVersionString(gMenuVersion), gMenuRegion > 0 ? gMenuRegion : ' ', GetSysMenuRegionString(gMenuRegion)); printf("\tIOS %d v%d, System menu: %s%c %s\n\n", ((ios >> 16) & 0xFF), (ios & 0xFFFF), GetSysMenuVersionString(version), region, GetSysMenuRegionString(region));
else
printf("\tIOS %d v%d, System menu: Unknown %s\n\n", ((ios >> 16) & 0xFF), (ios & 0xFFFF), GetSysMenuRegionString(region));
printf("\tAHB access: %s\n", AHBPROT_DISABLED ? "Yes" : "No"); printf("\tAHB access: %s\n", AHBPROT_DISABLED ? "Yes" : "No");
printf("\tPriiloader: %s\n\n", havePriiloader ? "Installed" : "Not installed"); printf("\tPriiloader: %s\n\n", havePriiloader ? "Installed" : "Not installed");
if (!deviceOk) if (!deviceOk)
{ {
printf("\t[+] No source devices found\n\n"); printf("\t[+] No source devices found\n\n");
@ -360,7 +362,7 @@ void Menu_FatDevice(void)
if (skipRegionSafetyCheck) if (skipRegionSafetyCheck)
{ {
printf("[+] WARNING: SM Region checks disabled!\n\n"); printf("[+] WARNING: SM region and version checks disabled!\n\n");
printf("\t Press 2 button to reset.\n"); printf("\t Press 2 button to reset.\n");
} }
@ -415,7 +417,7 @@ void Menu_FatDevice(void)
if (codePosition == sizeof(konamiCode) / sizeof(konamiCode[0])) if (codePosition == sizeof(konamiCode) / sizeof(konamiCode[0]))
{ {
skipRegionSafetyCheck = true; skipRegionSafetyCheck = true;
printf("[+] Disabled SM region checks\n"); printf("[+] Disabled SM region and version checks\n");
sleep(3); sleep(3);
} }

View File

@ -7,53 +7,10 @@
#include "nand.h" #include "nand.h"
#include "fileops.h" #include "fileops.h"
#define BLOCK 2048
/* Buffer */ /* Buffer */
static u32 inbuf[8] ATTRIBUTE_ALIGN(32); static u32 inbuf[8] ATTRIBUTE_ALIGN(32);
static bool gNandInitialized = false; static bool gNandInitialized = false;
#if 0
static void NANDFATify(char* ptr, const char* str)
{
char ctr;
while ((ctr = *(str++)) != '\0')
{
const char* esc;
switch (ctr)
{
case '"':
esc = "&qt;";
break;
case '*':
esc = "&st;";
break;
case ':':
esc = "&cl;";
break;
case '<':
esc = "&lt;";
break;
case '>':
esc = "&gt;";
break;
case '?':
esc = "&qm;";
break;
case '|':
esc = "&vb;";
break;
default:
*(ptr++) = ctr;
continue;
}
strcpy(ptr, esc);
ptr += 4;
}
*ptr = '\0';
}
#endif
s32 Nand_Mount(nandDevice *dev) s32 Nand_Mount(nandDevice *dev)
{ {
@ -291,178 +248,3 @@ s32 NANDDeleteFile(const char* path)
NANDInitialize(); NANDInitialize();
return ISFS_Delete(path); return ISFS_Delete(path);
} }
#if 0
s32 NANDGetNameList(const char* src, NameList** entries, s32* count)
{
*count = 0;
u32 numEntries = 0;
char currentEntry[ISFS_MAXPATH];
char entryPath[ISFS_MAXPATH + 1];
s32 ret = ISFS_ReadDir(src, NULL, &numEntries);
if (ret < 0)
return ret;
char* names = (char*)memalign(0x40, ISFS_MAXPATH * numEntries);
if (!names)
return ISFS_ENOMEM;
ret = ISFS_ReadDir(src, names, &numEntries);
if (ret < 0)
{
free(names);
return ret;
}
*count = numEntries;
free(*entries);
*entries = (NameList*)memalign(0x20, sizeof(NameList) * numEntries);
if (!*entries)
{
free(names);
return ISFS_ENOMEM;
}
s32 i, j, k;
u32 dummy;
for (i = 0, k = 0; i < numEntries; i++)
{
for (j = 0; names[k] != 0; j++, k++)
currentEntry[j] = names[k];
currentEntry[j] = 0;
k++;
strcpy((*entries)[i].name, currentEntry);
if (src[strlen(src) - 1] == '/')
snprintf(entryPath, sizeof(entryPath), "%s%s", src, currentEntry);
else
snprintf(entryPath, sizeof(entryPath), "%s/%s", src, currentEntry);
ret = ISFS_ReadDir(entryPath, NULL, &dummy);
(*entries)[i].type = ret < 0 ? 0 : 1;
}
free(names);
return 0;
}
s32 NANDDumpFile(const char* src, const char* dst)
{
printf("Dump file: %s\n", src);
s32 fd = ISFS_Open(src, ISFS_OPEN_READ);
if (fd < 0)
return fd;
fstats* status = (fstats*)memalign(32, sizeof(fstats));
if (status == NULL)
return ISFS_ENOMEM;
s32 ret = ISFS_GetFileStats(fd, status);
if (ret < 0)
{
ISFS_Close(fd);
free(status);
return ret;
}
FSOPDeleteFile(dst);
FILE* file = fopen(dst, "wb");
if (!file)
{
ISFS_Close(fd);
free(status);
return ISFS_EINVAL;
}
u8* buffer = (u8*)memalign(32, BLOCK);
if (!buffer)
{
ISFS_Close(fd);
free(status);
return ISFS_ENOMEM;
}
u32 toRead = status->file_length;
while (toRead > 0)
{
u32 size = toRead < BLOCK ? toRead : BLOCK;
ret = ISFS_Read(fd, buffer, size);
if (ret < 0)
{
ISFS_Close(fd);
fclose(file);
free(status);
free(buffer);
return ret;
}
ret = fwrite(buffer, 1, size, file);
if (ret < 0)
{
ISFS_Close(fd);
fclose(file);
free(status);
free(buffer);
return ret;
}
toRead -= size;
}
fclose(file);
ISFS_Close(fd);
free(status);
free(buffer);
return ISFS_OK;
}
s32 NANDDumpFolder(const char* src, const char* dst)
{
NameList* names = NULL;
s32 count = 0;
s32 i;
char nSrc[ISFS_MAXPATH + 1];
char nDst[1024];
char tDst[1024];
NANDGetNameList(src, &names, &count);
FSOPMakeFolder(dst);
for (i = 0; i < count; i++)
{
if (src[strlen(src) - 1] == '/')
snprintf(nSrc, sizeof(nSrc), "%s%s", src, names[i].name);
else
snprintf(nSrc, sizeof(nSrc), "%s/%s", src, names[i].name);
if (!names[i].type)
{
NANDFATify(tDst, nSrc);
snprintf(nDst, sizeof(nDst), "%s%s", dst, tDst);
NANDDumpFile(nSrc, nDst);
}
else
{
NANDFATify(tDst, nSrc);
snprintf(nDst, sizeof(nDst), "%s%s", dst, tDst);
FSOPMakeFolder(nDst);
NANDDumpFolder(nSrc, dst);
}
}
free(names);
return 0;
}
#endif

View File

@ -34,10 +34,4 @@ s32 NANDBackUpFile(const char* src, const char* dst, u32* size);
s32 NANDGetFileSize(const char* path, u32* size); s32 NANDGetFileSize(const char* path, u32* size);
s32 NANDDeleteFile(const char* path); s32 NANDDeleteFile(const char* path);
#if 0
s32 NANDGetNameList(const char* src, NameList** entries, s32* count);
s32 NANDDumpFile(const char* src, const char* dst);
s32 NANDDumpFolder(const char* src, const char* dst);
#endif
#endif #endif

View File

@ -31,7 +31,7 @@ const char RegionLookupTable[16] =
const u16 VersionList[] = const u16 VersionList[] =
{ {
// J E P K // J U E K
64, 33, 66, // 1.0 64, 33, 66, // 1.0
128, 97, 130, // 2.0 128, 97, 130, // 2.0
@ -49,6 +49,8 @@ const u16 VersionList[] =
512, 513, 514, 518, // 4.3 512, 513, 514, 518, // 4.3
}; };
u32 VersionListSize = sizeof(VersionList) / sizeof(VersionList[0]);
const char* VersionLookupTable[7][17] = const char* VersionLookupTable[7][17] =
{ {
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
@ -75,6 +77,18 @@ u64 be64(const u8 *p)
return ((u64)be32(p) << 32) | be32(p + 4); return ((u64)be32(p) << 32) | be32(p + 4);
} }
static inline void DecEncTxtBuffer(char* buffer)
{
u32 key = 0x73B5DBFA;
s32 i;
for (i = 0; i < 0x100; i++)
{
buffer[i] ^= key & 0xFF;
key = (key << 1) | (key >> 31);
}
}
u64 get_title_ios(u64 title) { u64 get_title_ios(u64 title) {
s32 ret, fd; s32 ret, fd;
static char filepath[256] ATTRIBUTE_ALIGN(32); static char filepath[256] ATTRIBUTE_ALIGN(32);
@ -145,6 +159,53 @@ u64 get_title_ios(u64 title) {
return 0; return 0;
} }
static bool GetRegionFromTXT(char* region)
{
u32 size = 0;
*region = 0;
char* buffer = (char*)NANDLoadFile("/title/00000001/00000002/data/setting.txt", &size);
if (!buffer)
return false;
DecEncTxtBuffer(buffer);
char* current = strstr(buffer, "AREA");
if(current)
{
char* start = strchr(current, '=');
char* end = strchr(current, '\r');
if (start && end)
{
start++;
if (!strncmp(start, "JPN", 3))
*region = 'J';
else if (!strncmp(start, "USA", 3))
*region = 'U';
else if (!strncmp(start, "EUR", 3))
*region = 'E';
else if (!strncmp(start, "KOR", 3))
*region = 'K';
if (*region != 0)
{
free(buffer);
return true;
}
}
}
else
{
printf("Error! GetRegionFromTXT: Item AREA not found!\n");
}
free(buffer);
return false;
}
s32 GetSysMenuRegion(u16* version, char* region) s32 GetSysMenuRegion(u16* version, char* region)
{ {
u16 v = 0; u16 v = 0;
@ -156,12 +217,29 @@ s32 GetSysMenuRegion(u16* version, char* region)
if (version) if (version)
*version = v; *version = v;
if (region) if(!GetRegionFromTXT(region))
*region = RegionLookupTable[(v & 0x0F)]; {
printf("\nCouldn't find the region of this system\n");
sleep(5);
return -1;
}
return 0; return 0;
} }
bool VersionIsOriginal(u16 version)
{
s32 i;
for (i = 0; i < VersionListSize; i++)
{
if (VersionList[i] == version)
return true;
}
return false;
}
const char* GetSysMenuRegionString(const char region) const char* GetSysMenuRegionString(const char region)
{ {
switch (region) switch (region)
@ -621,41 +699,47 @@ s32 Wad_Install(FILE *fp)
if (tid == TITLE_ID(1, 2)) if (tid == TITLE_ID(1, 2))
{ {
char region = 0;
u16 version = 0;
if (skipRegionSafetyCheck || gForcedInstall) if (skipRegionSafetyCheck || gForcedInstall)
goto skipChecks; goto skipChecks;
char region = 0;
u16 version = 0;
GetSysMenuRegion(&version, &region); GetSysMenuRegion(&version, &region);
if(region == 0)
if (tmd_data->vwii_title)
{ {
printf("\n Unkown SM region\n Please check the site for updates\n"); printf("\n I won't install a vWii SM by default.\n\n");
printf("\n If you're really sure what you're doing, next time\n");
printf(" select your device using Konami...\n\n");
ret = -999; ret = -999;
goto err; goto err;
} }
int i, ret = -1; if(region == 0)
for(i = 0; i < sizeof(VersionList); i++)
{ {
if(VersionList[i] == tmd_data->title_version) printf("\n Unkown System menu region\n Please check the site for updates\n");
{
ret = 1;
break;
}
}
if(ret != 1)
{
printf("\n Unknown SM region\n Please check the site for updates\n");
ret = -999; ret = -999;
goto err; goto err;
} }
if (!VersionIsOriginal(tmd_data->title_version))
{
printf("\n I won't install an unkown SM versions by default.\n\n");
printf("\n Are you installing a tweaked system menu?\n");
printf("\n If you're really sure what you're doing, next time\n");
printf(" select your device using Konami...\n\n");
ret = -999;
goto err;
}
if(region != RegionLookupTable[(tmd_data->title_version & 0x0F)]) if(region != RegionLookupTable[(tmd_data->title_version & 0x0F)])
{ {
printf("\n I won't install the wrong regions SM by default.\n\n"); printf("\n I won't install the wrong regions SM by default.\n\n");
printf("\n Are you region changing?\n"); printf("\n Are you region changing?\n");
printf("\n If you're really sure what you're doing, next time\n"); printf("\n If you're really sure what you're doing, next time\n");
printf(" select your device using Konami...\n\n"); printf(" select your device using Konami...\n\n");
@ -679,8 +763,6 @@ skipChecks:
printf("\n Priiloader is installed next to the system menu.\n\n"); printf("\n Priiloader is installed next to the system menu.\n\n");
printf(" It is recommended to retain Priiloader as it can\n"); printf(" It is recommended to retain Priiloader as it can\n");
printf(" protect your console from being bricked.\n\n"); printf(" protect your console from being bricked.\n\n");
printf(" Press A to retain Priiloader or B to remove."); printf(" Press A to retain Priiloader or B to remove.");
u32 buttons = WaitButtons(); u32 buttons = WaitButtons();
@ -700,7 +782,6 @@ skipChecks:
Con_ClearLine(); Con_ClearLine();
printf("\r Couldn't backup Priiloader.\n"); printf("\r Couldn't backup Priiloader.\n");
fflush(stdout); fflush(stdout);
printf("\n Press A to continue or B to skip"); printf("\n Press A to continue or B to skip");
u32 buttons = WaitButtons(); u32 buttons = WaitButtons();

View File

@ -5,6 +5,7 @@
s32 Wad_Install(FILE* fp); s32 Wad_Install(FILE* fp);
s32 Wad_Uninstall(FILE* fp); s32 Wad_Uninstall(FILE* fp);
s32 GetSysMenuRegion(u16* version, char* region); s32 GetSysMenuRegion(u16* version, char* region);
bool VersionIsOriginal(u16 version);
const char* GetSysMenuRegionString(const char region); const char* GetSysMenuRegionString(const char region);
const char* GetSysMenuVersionString(u16 version); const char* GetSysMenuVersionString(u16 version);
bool IsPriiloaderInstalled(); bool IsPriiloaderInstalled();