Skip to content

Commit

Permalink
- Enable mounting a disc image alongside an executable.
Browse files Browse the repository at this point in the history
  • Loading branch information
Extrems committed Jan 18, 2025
1 parent 322f290 commit 71b6bc5
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 32 deletions.
8 changes: 4 additions & 4 deletions cube/swiss/source/devices/dvd/deviceHandler-DVD.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions cube/swiss/source/devices/fat/deviceHandler-FAT.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
3 changes: 3 additions & 0 deletions cube/swiss/source/devices/fsp/deviceHandler-FSP.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
8 changes: 4 additions & 4 deletions cube/swiss/source/devices/gcloader/deviceHandler-gcloader.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions cube/swiss/source/devices/usbgecko/deviceHandler-usbgecko.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
8 changes: 4 additions & 4 deletions cube/swiss/source/devices/wode/deviceHandler-WODE.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
47 changes: 27 additions & 20 deletions cube/swiss/source/swiss.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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) {
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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*/
Expand Down

0 comments on commit 71b6bc5

Please sign in to comment.