--- trunk/loader/source/main.c
+++ trunk/loader/source/main.c
@@ -63,14 +63,70 @@
0x48, 0x03, 0x49, 0x04, 0x47, 0x78, 0x46, 0xC0, 0xE6, 0x00, 0x08, 0x70, 0xE1, 0x2F, 0xFF, 0x1E,
0x10, 0x10, 0x00, 0x00,
};
+
static const unsigned char FSAccessPattern[] =
{
0x9B, 0x05, 0x40, 0x03, 0x99, 0x05, 0x42, 0x8B,
};
+
static const unsigned char FSAccessPatch[] =
{
0x9B, 0x05, 0x40, 0x03, 0x1C, 0x0B, 0x42, 0x8B,
};
+
+typedef struct _PR
+{
+ u8 state;
+ u8 chs_st[3];
+ u8 type;
+ u8 chs_e[3];
+ u32 lba;
+ u32 bc;
+} __attribute__((__packed__)) _pr;
+
+typedef struct _MBR
+{
+ u8 ca[446];
+ _pr part[4];
+ u16 sig;
+} __attribute__((__packed__)) _mbr;
+
+FILE mountAll()
+{bool KernelFound = false;
+FILE *f = NULL;
+int retry = 0;
+
+while(retry < 10)
+{if(__io_usbstorage.startup() && __io_usbstorage.isInserted())
+break;
+retry++;
+usleep(150000);
+}
+
+if(retry < 10)
+{_mbr mbr;
+char buffer[4096];
+
+__io_usbstorage.readSectors(0, 1, &mbr);
+
+if(mbr.part[1].type != 0)
+{__io_usbstorage.readSectors(le32(mbr.part[1].lba), 1, buffer);
+
+if((*((u16*)(buffer + 0x1FE)) == 0x55AA) || (*((u16*)(buffer + 0x1FE)) == 0x55AB))
+{if(memcmp(buffer + 0x36, "FAT", 3) == 0 || memcmp(buffer + 0x52, "FAT", 3) == 0)
+{fatMount("usb", &__io_usbstorage, le32(mbr.part[1].lba), 8, 64);
+f = fopen("usb:/nincfg.bin", "rb+");
+}
+}
+}
+}
+
+if(__io_wiisd.startup() || !__io_wiisd.isInserted())
+if(fatMount("sd", &__io_wiisd, 0, 8, 64))
+f = fopen("sd:/nincfg.bin", "rb+");
+
+return f;
+}
s32 __IOS_LoadStartupIOS(void)
{
@@ -146,7 +202,7 @@
}
}
-fatInitDefault();
+cfg = mountAll();
if( IsWiiU() )
{
@@ -156,7 +212,10 @@
}
// Simple code to autoupdate the meta.xml in Nintendont's folder
- FILE *meta = fopen("meta.xml", "w");
+ FILE *meta = fopen("sd:/apps/nintendont/meta.xml", "w");
+ if(meta == NULL)
+ meta = fopen("usb:/apps/nintendont/meta.xml", "w");
+// to do: this would be most effective based on argv[0]
if(meta != NULL)
{
fprintf(meta, "%s\r\n<app version=\"1\">\r\n\t<name>%s</name>\r\n", META_XML, META_NAME);
@@ -170,7 +229,6 @@
u32 ConfigReset = 0;
-cfg = fopen("/nincfg.bin", "rb+");
if (cfg == NULL)
{
ConfigReset = 1;