Skip to content

Commit

Permalink
- Find second disc through the metadata cache.
Browse files Browse the repository at this point in the history
  • Loading branch information
Extrems committed Dec 27, 2019
1 parent 111fd96 commit 6fa3487
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 38 deletions.
3 changes: 2 additions & 1 deletion cube/swiss/source/devices/deviceHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
25 changes: 25 additions & 0 deletions cube/swiss/source/devices/filemeta.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions cube/swiss/source/devices/filemeta.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

38 changes: 1 addition & 37 deletions cube/swiss/source/swiss.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -1464,11 +1433,6 @@ void load_game() {
config_unload_current();
return;
}


if(secondDisc) {
free(secondDisc);
}
}

load_app(filesToPatch, numToPatch);
Expand Down

0 comments on commit 6fa3487

Please sign in to comment.