Properly map to "sd" deviceList path, even if it says "nand"

Hiya passes the appname as nand:/, but the nand device is set as being external storage, so is actually mapped to the sd, account for that
This commit is contained in:
Edoardo Lolletti 2024-04-27 12:42:32 +02:00
parent 9c01c0c464
commit 101269a3a8

View File

@ -4,19 +4,49 @@
#define DEVICE_LIST_SENTINEL *(vu32*)0x02300020 #define DEVICE_LIST_SENTINEL *(vu32*)0x02300020
#define DEVICE_LIST_ADDR (vu8*)0x02300024 #define DEVICE_LIST_ADDR (vu8*)0x02300024
size_t getDeviceNameLenFromAppName(const char (appname)[0x40])
{
for(int i = 0; i < 0x40; ++i)
{
if(appname[i] == ':')
{
return i;
}
}
return 0;
}
DeviceList* getDeviceList(void) DeviceList* getDeviceList(void)
{ {
static bool gotDeviceList = false; static bool gotDeviceList = false;
if(!gotDeviceList) { if(!gotDeviceList) {
while(!DEVICE_LIST_SENTINEL); while(!DEVICE_LIST_SENTINEL);
DeviceList* list = (DeviceList*)DEVICE_LIST_ADDR; DeviceList* list = (DeviceList*)DEVICE_LIST_ADDR;
bool isSd = strncmp(list->appname, "sdmc", 4) == 0;
if(!isSd && strncmp(list->appname, "nand", 4) != 0) size_t deviceNameLen = getDeviceNameLenFromAppName(list->appname);
if(deviceNameLen == 0)
{
return 0; return 0;
}
bool isSd = false;
for(int i = 0; i < 11; ++i)
{
Device* device = &list->devices[i];
if(device->deviceName[deviceNameLen] == '\0' && strncmp(device->deviceName, list->appname, deviceNameLen) == 0)
{
isSd = device->phisicalDrive == 0;
break;
}
}
if(isSd) if(isSd)
{ {
//transform sdmc:/ to sd:/ //transform the root path to sd:/ (can be sdmc:/, nand:/, nand2:/, etc)
memmove(list->appname + 2, list->appname + 4, sizeof(list->appname) - 4); memmove(list->appname + (deviceNameLen - 2), list->appname + deviceNameLen, sizeof(list->appname) - deviceNameLen);
list->appname[0] = 's';
list->appname[1] = 'd';
list->appname[sizeof(list->appname) - 1] = '\0'; list->appname[sizeof(list->appname) - 1] = '\0';
list->appname[sizeof(list->appname) - 2] = '\0'; list->appname[sizeof(list->appname) - 2] = '\0';
} }