From 6fa3487d2ee7de74689586b2794f4582d409015e Mon Sep 17 00:00:00 2001 From: Extrems Date: Thu, 26 Dec 2019 21:42:55 -0500 Subject: [PATCH] - Find second disc through the metadata cache. --- cube/swiss/source/devices/deviceHandler.h | 3 +- cube/swiss/source/devices/filemeta.c | 25 +++++++++++++++ cube/swiss/source/devices/filemeta.h | 1 + cube/swiss/source/swiss.c | 38 +---------------------- 4 files changed, 29 insertions(+), 38 deletions(-) diff --git a/cube/swiss/source/devices/deviceHandler.h b/cube/swiss/source/devices/deviceHandler.h index 974ead96..3557efb6 100644 --- a/cube/swiss/source/devices/deviceHandler.h +++ b/cube/swiss/source/devices/deviceHandler.h @@ -18,11 +18,12 @@ #define PATHNAME_MAX 1024 typedef struct { + void *tplLocation; int fileTypeTexId; int regionTexId; + dvddiskid diskId; u8 *banner; int bannerSize; - void *tplLocation; GXTexObj bannerTexObj; char description[128]; } file_meta; diff --git a/cube/swiss/source/devices/filemeta.c b/cube/swiss/source/devices/filemeta.c index 6e0f063f..3cf85262 100644 --- a/cube/swiss/source/devices/filemeta.c +++ b/cube/swiss/source/devices/filemeta.c @@ -106,6 +106,7 @@ void populate_meta(file_handle *f) { DiskHeader *header = memalign(32, sizeof(DiskHeader)); devices[DEVICE_CUR]->seekFile(f, 0, DEVICE_HANDLER_SEEK_SET); devices[DEVICE_CUR]->readFile(f, header, sizeof(DiskHeader)); + memcpy(&f->meta->diskId, header, sizeof(dvddiskid)); if(header->DVDMagicWord == DVD_MAGIC) { //print_gecko("FILE identifed as valid GCM\r\n"); @@ -172,3 +173,27 @@ void populate_meta(file_handle *f) { } } +file_handle* meta_find_disk2(file_handle* f) { + file_handle* dirEntries = getCurrentDirEntries(); + if(f->meta) { + int i; + for(i = 0; i < getCurrentDirEntryCount(); i++) { + if(dirEntries[i].meta) { + if(strncmp(dirEntries[i].meta->diskId.gamename, f->meta->diskId.gamename, 4)) { + continue; + } + if(strncmp(dirEntries[i].meta->diskId.company, f->meta->diskId.company, 2)) { + continue; + } + if(dirEntries[i].meta->diskId.disknum == f->meta->diskId.disknum) { + continue; + } + if(dirEntries[i].meta->diskId.gamever != f->meta->diskId.gamever) { + continue; + } + return &dirEntries[i]; + } + } + } + return NULL; +} diff --git a/cube/swiss/source/devices/filemeta.h b/cube/swiss/source/devices/filemeta.h index 2bb81d66..cf55539f 100644 --- a/cube/swiss/source/devices/filemeta.h +++ b/cube/swiss/source/devices/filemeta.h @@ -15,6 +15,7 @@ void meta_create_direct_texture(file_meta* meta); void populate_meta(file_handle *f); +file_handle* meta_find_disk2(file_handle *f); void meta_free(void* ptr); #endif diff --git a/cube/swiss/source/swiss.c b/cube/swiss/source/swiss.c index ce4e8bb4..42b7f685 100644 --- a/cube/swiss/source/swiss.c +++ b/cube/swiss/source/swiss.c @@ -1420,38 +1420,7 @@ void load_game() { } if(devices[DEVICE_CUR] != &__device_wode) { - file_handle *secondDisc = NULL; - - // If we're booting from SD card or IDE hdd - if(devices[DEVICE_CUR]->features & FEAT_REPLACES_DVD_FUNCS) { - // look to see if it's a two disc game - // set things up properly to allow disc swapping - // the files must be setup as so: game-disc1.xxx game-disc2.xxx - secondDisc = calloc(1,sizeof(file_handle)); - memcpy(secondDisc->name,&curFile.name,PATHNAME_MAX); - secondDisc->fp = 0; - secondDisc->ffsFp = NULL; - - // you're trying to load a disc1 of something - if(curFile.name[strlen(curFile.name)-5] == '1') { - secondDisc->name[strlen(secondDisc->name)-5] = '2'; - } else if(curFile.name[strlen(curFile.name)-5] == '2' && strcasecmp(getRelativeName(curFile.name), "disc2.iso")) { - secondDisc->name[strlen(curFile.name)-5] = '1'; - } else if(!strcasecmp(getRelativeName(curFile.name), "game.iso")) { - memset(secondDisc->name, 0, PATHNAME_MAX); - strncpy(secondDisc->name, curFile.name, strlen(curFile.name)-strlen(getRelativeName(curFile.name))); - strcat(secondDisc->name, "disc2.iso\0"); // Nintendont style - } else if(!strcasecmp(getRelativeName(curFile.name), "disc2.iso")) { - memset(secondDisc->name, 0, PATHNAME_MAX); - strncpy(secondDisc->name, curFile.name, strlen(curFile.name)-strlen(getRelativeName(curFile.name))); - strcat(secondDisc->name, "game.iso\0"); // Nintendont style - } - else { - free(secondDisc); - secondDisc = NULL; - } - } - + file_handle *secondDisc = meta_find_disk2(&curFile); *(vu32*)VAR_SECOND_DISC = secondDisc ? 1:0; *(vu32*)VAR_CURRENT_DISC = 0; *(vu32*)VAR_IGR_DOL_SIZE = 0; @@ -1464,11 +1433,6 @@ void load_game() { config_unload_current(); return; } - - - if(secondDisc) { - free(secondDisc); - } } load_app(filesToPatch, numToPatch);