diff --git a/cube/swiss/source/devices/dvd/deviceHandler-DVD.c b/cube/swiss/source/devices/dvd/deviceHandler-DVD.c index 1d64c6fc..be1842ad 100644 --- a/cube/swiss/source/devices/dvd/deviceHandler-DVD.c +++ b/cube/swiss/source/devices/dvd/deviceHandler-DVD.c @@ -395,6 +395,10 @@ s32 deviceHandler_DVD_readFile(file_handle* file, void* buffer, u32 length){ } s32 deviceHandler_DVD_setupFile(file_handle* file, file_handle* file2, ExecutableFile* filesToPatch, int numToPatch) { + int i; + file_frag *fragList = NULL; + u32 numFrags = 0; + // Multi-Game disc audio streaming setup if((dvdDiscTypeInt == COBRA_MULTIGAME_DISC)||(dvdDiscTypeInt == GCOSD5_MULTIGAME_DISC)||(dvdDiscTypeInt == GCOSD9_MULTIGAME_DISC)) { if(swissSettings.audioStreaming && !isXenoGC) { @@ -423,10 +427,6 @@ s32 deviceHandler_DVD_setupFile(file_handle* file, file_handle* file2, Executabl } // Check if there are any fragments in our patch location for this game if(devices[DEVICE_PATCHES] != NULL) { - int i; - file_frag *fragList = NULL; - u32 numFrags = 0; - print_gecko("Save Patch device found\r\n"); // Look for patch files, if we find some, open them and add them as fragments diff --git a/cube/swiss/source/devices/fat/deviceHandler-FAT.c b/cube/swiss/source/devices/fat/deviceHandler-FAT.c index 13f026e1..0bb52467 100644 --- a/cube/swiss/source/devices/fat/deviceHandler-FAT.c +++ b/cube/swiss/source/devices/fat/deviceHandler-FAT.c @@ -210,6 +210,9 @@ s32 deviceHandler_FAT_setupFile(file_handle* file, file_handle* file2, Executabl file_frag *fragList = NULL; u32 numFrags = 0; + if(numToPatch < 0) { + return 0; + } // Look for patch files, if we find some, open them and add them as fragments file_handle patchFile; for(i = 0; i < numToPatch; i++) { diff --git a/cube/swiss/source/devices/fsp/deviceHandler-FSP.c b/cube/swiss/source/devices/fsp/deviceHandler-FSP.c index 60cdb24e..ee81ad68 100644 --- a/cube/swiss/source/devices/fsp/deviceHandler-FSP.c +++ b/cube/swiss/source/devices/fsp/deviceHandler-FSP.c @@ -127,6 +127,9 @@ s32 deviceHandler_FSP_setupFile(file_handle* file, file_handle* file2, Executabl file_frag *fragList = NULL; u32 numFrags = 0; + if(numToPatch < 0) { + return 0; + } // Check if there are any fragments in our patch location for this game if(devices[DEVICE_PATCHES] != NULL) { print_gecko("Save Patch device found\r\n"); diff --git a/cube/swiss/source/devices/gcloader/deviceHandler-gcloader.c b/cube/swiss/source/devices/gcloader/deviceHandler-gcloader.c index 03b605bf..617691c2 100644 --- a/cube/swiss/source/devices/gcloader/deviceHandler-gcloader.c +++ b/cube/swiss/source/devices/gcloader/deviceHandler-gcloader.c @@ -109,6 +109,10 @@ static s32 setupFile(file_handle* file, file_handle* file2, ExecutableFile* file } s32 deviceHandler_GCLoader_setupFile(file_handle* file, file_handle* file2, ExecutableFile* filesToPatch, int numToPatch) { + int i; + file_frag *fragList = NULL; + u32 numFrags = 0; + if(!setupFile(file, file2, filesToPatch, numToPatch)) { return 0; } @@ -117,10 +121,6 @@ s32 deviceHandler_GCLoader_setupFile(file_handle* file, file_handle* file2, Exec } // Check if there are any fragments in our patch location for this game if(devices[DEVICE_PATCHES] != NULL) { - int i; - file_frag *fragList = NULL; - u32 numFrags = 0; - print_gecko("Save Patch device found\r\n"); // Look for patch files, if we find some, open them and add them as fragments diff --git a/cube/swiss/source/devices/usbgecko/deviceHandler-usbgecko.c b/cube/swiss/source/devices/usbgecko/deviceHandler-usbgecko.c index 172dc8fc..f6b60bf2 100644 --- a/cube/swiss/source/devices/usbgecko/deviceHandler-usbgecko.c +++ b/cube/swiss/source/devices/usbgecko/deviceHandler-usbgecko.c @@ -95,6 +95,9 @@ s32 deviceHandler_USBGecko_setupFile(file_handle* file, file_handle* file2, Exec file_frag *fragList = NULL; u32 numFrags = 0; + if(numToPatch < 0) { + return 0; + } // Check if there are any fragments in our patch location for this game if(devices[DEVICE_PATCHES] != NULL) { print_gecko("Save Patch device found\r\n"); diff --git a/cube/swiss/source/devices/wode/deviceHandler-WODE.c b/cube/swiss/source/devices/wode/deviceHandler-WODE.c index fa54e8fc..a120652d 100644 --- a/cube/swiss/source/devices/wode/deviceHandler-WODE.c +++ b/cube/swiss/source/devices/wode/deviceHandler-WODE.c @@ -115,6 +115,10 @@ s32 deviceHandler_WODE_readFile(file_handle* file, void* buffer, u32 length) { } s32 deviceHandler_WODE_setupFile(file_handle* file, file_handle* file2, ExecutableFile* filesToPatch, int numToPatch) { + int i; + file_frag *fragList = NULL; + u32 numFrags = 0; + if(numToPatch < 0 || !devices[DEVICE_CUR]->emulated()) { if(file->status == STATUS_NOT_MAPPED) { ISOInfo_t* isoInfo = (ISOInfo_t*)&file->other; @@ -129,10 +133,6 @@ s32 deviceHandler_WODE_setupFile(file_handle* file, file_handle* file2, Executab // Check if there are any fragments in our patch location for this game if(devices[DEVICE_PATCHES] != NULL) { - int i; - file_frag *fragList = NULL; - u32 numFrags = 0; - print_gecko("Save Patch device found\r\n"); // Look for patch files, if we find some, open them and add them as fragments diff --git a/cube/swiss/source/swiss.c b/cube/swiss/source/swiss.c index d37ffd1d..d2727482 100644 --- a/cube/swiss/source/swiss.c +++ b/cube/swiss/source/swiss.c @@ -1268,11 +1268,8 @@ void load_app(ExecutableFile *fileToPatch) void boot_dol(file_handle* file, int argc, char *argv[]) { - void *dol_buffer; - void *ptr; - - dol_buffer = memalign(32, file->size); - if(!dol_buffer) { + void *buffer = memalign(32, file->size); + if(!buffer) { uiDrawObj_t *msgBox = DrawMessageBox(D_FAIL,"DOL is too big. Press A."); DrawPublish(msgBox); wait_press_A(); @@ -1281,7 +1278,7 @@ void boot_dol(file_handle* file, int argc, char *argv[]) } int i=0; - ptr = dol_buffer; + void *ptr = buffer; uiDrawObj_t* progBar = DrawProgressBar(false, 0, "Loading DOL"); DrawPublish(progBar); for(i = 0; i < file->size; i+= 131072) { @@ -1291,7 +1288,7 @@ void boot_dol(file_handle* file, int argc, char *argv[]) int size = i+131072 > file->size ? file->size-i : 131072; if(devices[DEVICE_CUR]->readFile(file,ptr,size)!=size) { DrawDispose(progBar); - free(dol_buffer); + free(buffer); devices[DEVICE_CUR]->closeFile(file); uiDrawObj_t *msgBox = DrawMessageBox(D_FAIL,"Failed to read DOL. Press A."); DrawPublish(msgBox); @@ -1302,10 +1299,10 @@ void boot_dol(file_handle* file, int argc, char *argv[]) ptr+=size; } - XXH64_hash_t hash = XXH3_64bits(dol_buffer, file->size); + XXH64_hash_t hash = XXH3_64bits(buffer, file->size); if(!valid_dol_xxh3(file, hash)) { DrawDispose(progBar); - free(dol_buffer); + free(buffer); devices[DEVICE_CUR]->closeFile(file); uiDrawObj_t *msgBox = DrawMessageBox(D_FAIL,"DOL is corrupted. Press A."); DrawPublish(msgBox); @@ -1324,16 +1321,16 @@ void boot_dol(file_handle* file, int argc, char *argv[]) DrawDispose(msgBox); } } - - // Build a command line to pass to the DOL - char *argz = getExternalPath(file->name); - size_t argz_len = strlen(argz) + 1; char fileName[PATHNAME_MAX]; memset(fileName, 0, PATHNAME_MAX); strncpy(fileName, file->name, strrchr(file->name, '.') - file->name); print_gecko("DOL file name without extension [%s]\r\n", fileName); + // Build a command line to pass to the DOL + char *argz = getExternalPath(file->name); + size_t argz_len = strlen(argz) + 1; + // .cli argument file file_handle *cliArgFile = calloc(1, sizeof(file_handle)); snprintf(cliArgFile->name, PATHNAME_MAX, "%s.cli", fileName); @@ -1391,21 +1388,31 @@ void boot_dol(file_handle* file, int argc, char *argv[]) argz_add(&argz, &argz_len, argv[i]); } + // .iso disc image file + file_handle *imageFile = calloc(1, sizeof(file_handle)); + snprintf(imageFile->name, PATHNAME_MAX, "%s.iso", fileName); + + if(devices[DEVICE_CUR]->location == LOC_DVD_CONNECTOR) { + devices[DEVICE_CUR]->setupFile(imageFile, NULL, NULL, -1); + } + // Boot - if(!memcmp(dol_buffer, ELFMAG, SELFMAG)) { - ELFtoARAM(dol_buffer, argz, argz_len); + if(!memcmp(buffer, ELFMAG, SELFMAG)) { + ELFtoARAM(buffer, argz, argz_len); } else if(endsWith(file->name, "/SDLOADER.BIN")) { - BINtoARAM(dol_buffer, file->size, 0x81700000, 0x81700000); + BINtoARAM(buffer, file->size, 0x81700000, 0x81700000); } - else if(branchResolve(dol_buffer, PATCH_BIN, 0)) { - BINtoARAM(dol_buffer, file->size, 0x80003100, 0x80003100); + else if(branchResolve(buffer, PATCH_BIN, 0)) { + BINtoARAM(buffer, file->size, 0x80003100, 0x80003100); } else { - DOLtoARAM(dol_buffer, argz, argz_len); + DOLtoARAM(buffer, argz, argz_len); } - free(dol_buffer); + devices[DEVICE_CUR]->closeFile(imageFile); + free(imageFile); + free(buffer); } /* Manage file - The user will be asked what they want to do with the currently selected file - copy/move/delete*/