From 101269a3a8a5a8b68ebf085f514fc8324dd0a596 Mon Sep 17 00:00:00 2001 From: Edoardo Lolletti Date: Sat, 27 Apr 2024 12:42:32 +0200 Subject: [PATCH] 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 --- arm9/src/deviceList.c | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/arm9/src/deviceList.c b/arm9/src/deviceList.c index 83c7351..584c0bc 100644 --- a/arm9/src/deviceList.c +++ b/arm9/src/deviceList.c @@ -4,19 +4,49 @@ #define DEVICE_LIST_SENTINEL *(vu32*)0x02300020 #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) { static bool gotDeviceList = false; if(!gotDeviceList) { while(!DEVICE_LIST_SENTINEL); 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; + } + 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) { - //transform sdmc:/ to sd:/ - memmove(list->appname + 2, list->appname + 4, sizeof(list->appname) - 4); + //transform the root path to sd:/ (can be sdmc:/, nand:/, nand2:/, etc) + 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) - 2] = '\0'; }