s32 WDVD_OpenDataPartition() { //gprintf( "%s %i\n", __FILE__, __LINE__ ); u64 dataPartitionOffset; // u32 status = 0; //gprintf( "%s %i\n", __FILE__, __LINE__ ); s32 ret = WDVD_FindPartition( &dataPartitionOffset ); if( ret < 0 ) { gprintf("WDVD_FindPartition(): %d\n", ret ); return ret; } //gprintf( "%s %i\n", __FILE__, __LINE__ ); ret = WDVD_OpenPartition( dataPartitionOffset ); if( ret < 0 ) { gprintf("WDVD_OpenPartition( %016llx ): %d\n", dataPartitionOffset, ret ); return ret; } // partitionOpen = true; //gprintf("opened partition @ %016llx\n", dataPartitionOffset ); return 0; }
s32 Disc_OpenPartitionO(u32 mode, u8 *id, u64 *offset) { if (Disc_Open() < 0) return -2; if (__Disc_FindPartition(offset) < 0) return -3; if (WDVD_OpenPartition(*offset, 0, 0, 0, Tmd_Buffer) < 0) return -4; return 0; }
s32 Disc_BootPartition(LoaderConfig loaderConfig , u64 offset) { entry_point p_entry; s32 ret; /* Open specified partition */ ret = WDVD_OpenPartition(offset); if (ret < 0) return ret; /* Run apploader */ ret = Apploader_Run(loaderConfig, &p_entry); if (ret < 0) return ret; /* Setup low memory */ __Disc_SetLowMem(); /* Set an appropiate video mode */ __Disc_SetVMode(); /* Set time */ __Disc_SetTime(); /* OCARINA STUFF - FISHEARS*/ if (loaderConfig.ocarinaSelection) //(ocarinaChoice) { if (loaderConfig.verboseLog) printf("Doing sd codes\n"); memset(gameid, 0, 8); memcpy(gameid, (char*)0x80000000, 6); do_sd_code(loaderConfig.verboseLog, gameid); } /* Close subsystems */ Subsystem_Close(); /* Shutdown IOS subsystems */ SYS_ResetSystem(SYS_SHUTDOWN, 0, 0); /* Jump to entry point */ p_entry(); /* Epic failure */ while (1); return 0; }
s32 dump_openingbnr(u8 *discID, const char * dest) { // Mount the disc Disc_SetUSB(discID); Disc_Open(); u64 offset; s32 ret; ret = __Disc_FindPartition(&offset); if (ret < 0) return ret; ret = WDVD_OpenPartition(offset); if (ret < 0) { return ret; } // Read where to find the fst.bin u32 *buffer = memalign(32, 0x20); if (buffer == NULL) { //Out of memory return -1; } ret = WDVD_Read(buffer, 0x20, 0x420); if (ret < 0) return ret; // Read fst.bin void *fstbuffer = memalign(32, buffer[2]*4); FST_ENTRY *fst = (FST_ENTRY *)fstbuffer; if (fst == NULL) { //Out of memory free(buffer); return -1; } ret = WDVD_Read(fstbuffer, buffer[2]*4, buffer[1]*4); if (ret < 0) return ret; free(buffer); // Search the fst.bin u32 count = fst[0].filelen; int i; u32 index = 0; for (i=1;i<count;i++) { if (strstr(fstfiles(fst, i), "opening.bnr") != NULL) { index = i; } } if (index == 0) { //opening.bnr not found free(fstbuffer); return -1; } // Load the .bnr u8 *banner = memalign(32, fst[index].filelen); if (banner == NULL) { //Out of memory free(fstbuffer); return -1; } ret = WDVD_Read((void *)banner, fst[index].filelen, fst[index].fileoffset * 4); if (ret < 0) return ret; FILE *fp = NULL; fp = fopen(dest, "wb"); fwrite(banner, 1, fst[index].filelen, fp); fclose(fp); free(fstbuffer); free(banner); return 1; }
s32 Disc_BootPartition(u64 offset, u8 vidMode, bool vipatch, bool countryString, u8 patchVidMode, int aspectRatio) { entry_point p_entry; IOSReloadBlock(IOS_GetVersion()); s32 ret = WDVD_OpenPartition(offset, 0, 0, 0, Tmd_Buffer); if (ret < 0) return ret; /* Select an appropriate video mode */ __Disc_SelectVMode(vidMode, 0); /* Setup low memory */; __Disc_SetLowMem(); /* Run apploader */ ret = Apploader_Run(&p_entry, vidMode, vmode, vipatch, countryString, patchVidMode, aspectRatio); free_wip(); if (ret < 0) return ret; if (hooktype != 0) ocarina_do_code(); gprintf("\n\nEntry Point is: %0x8\n", p_entry); // gprintf("Lowmem:\n\n"); // ghexdump((void*)0x80000000, 0x3f00); /* Set time */ __Disc_SetTime(); /* Set an appropriate video mode */ __Disc_SetVMode(); u8 temp_data[4]; // fix for PeppaPig memcpy((char *) &temp_data, (void*)0x800000F4,4); usleep(100 * 1000); /* Shutdown IOS subsystems */ SYS_ResetSystem(SYS_SHUTDOWN, 0, 0); /* Originally from tueidj - taken from NeoGamma (thx) */ *(vu32*)0xCC003024 = 1; // fix for PeppaPig memcpy((void*)0x800000F4,(char *) &temp_data, 4); appentrypoint = (u32) p_entry; gprintf("Jumping to entrypoint\n"); if (hooktype != 0) //2x "nop\n" removed From Mod { __asm__( "lis %r3, appentrypoint@h\n" "ori %r3, %r3, appentrypoint@l\n" "lwz %r3, 0(%r3)\n" "mtlr %r3\n" "lis %r3, 0x8000\n" "ori %r3, %r3, 0x18A8\n" "nop\n" "mtctr %r3\n" "bctr\n" ); } else { __asm__( "lis %r3, appentrypoint@h\n" "ori %r3, %r3, appentrypoint@l\n" "lwz %r3, 0(%r3)\n" "mtlr %r3\n" "blr\n" ); } return 0; }
s32 dump_banner(const u8* discid,const char * dest) { // Mount the disc //Disc_SetWBFS(1, (u8*)discid); Disc_SetUSB(discid); Disc_Open(); u64 offset; s32 ret; ret = __Disc_FindPartition(&offset); if (ret < 0) return ret; ret = WDVD_OpenPartition(offset, NULL); if (ret < 0) { //printf("ERROR: OpenPartition(0x%llx) %d\n", offset, ret); return ret; } // Read where to find the fst.bin u32 *buffer = memalign(32, 0x20); if (buffer == NULL) { //Out of memory return -1; } ret = WDVD_Read(buffer, 0x20, 0x420); if (ret < 0) return ret; // Read fst.bin void *fstbuffer = memalign(32, buffer[2]*4); FST_ENTRY *fst = (FST_ENTRY *)fstbuffer; if (fst == NULL) { //Out of memory free(buffer); return -1; } ret = WDVD_Read(fstbuffer, buffer[2]*4, buffer[1]*4); if (ret < 0) return ret; free(buffer); // Search the fst.bin u32 count = fst[0].filelen; int i; u32 index = 0; for (i=1;i<count;i++) { if (strstr(fstfiles(fst, i), "opening.bnr") != NULL) { index = i; } } if (index == 0) { //opening.bnr not found free(fstbuffer); return -1; } // Load the .bnr u8 *banner = memalign(32, fst[index].filelen); if (banner == NULL) { //Out of memory free(fstbuffer); return -1; } ret = WDVD_Read((void *)banner, fst[index].filelen, fst[index].fileoffset * 4); if (ret < 0) return ret; WDVD_Reset(); WDVD_ClosePartition(); //fatInitDefault(); //SDCard_Init(); WDVD_SetUSBMode(NULL, 0); FILE *fp = fopen(dest, "wb"); if(fp) { fwrite(banner, 1, fst[index].filelen, fp); fclose(fp); } free(fstbuffer); free(banner); return 1; }
s32 Disc_BootPartition(u64 offset, u8 videoselected, u8 cheat, u8 vipatch, u8 patchcountrystring, u32 rtrn) { entry_point p_entry; s32 ret; /* Open specified partition */ ret = WDVD_OpenPartition(offset, tmd_buffer); if (ret < 0) return ret; char gameid[8]; memset(gameid, 0, 8); memcpy(gameid, (char*)Disc_ID, 6); //kill the SD SDCard_deInit(); /* Disconnect Wiimote */ WPAD_Flush(0); WPAD_Disconnect(0); WPAD_Shutdown(); // Load Disc IOS u32 disc_ios = tmd_buffer[0x18B]; if (disc_ios != IOS_GetVersion()) { WDVD_ClosePartition(); WDVD_Close(); ret = IOS_ReloadIOS(disc_ios); if (ret < 0) { gprintf("Disc IOS %u could not be loaded! (ret = %d)", disc_ios, ret); return ret; } Disc_Init(); Disc_Open(); WDVD_OpenPartition(offset, tmd_buffer); } /* Setup low memory */ __Disc_SetLowMem(); /* Run apploader */ ret = Apploader_Run(&p_entry, cheat, videoselected, vipatch, patchcountrystring, rtrn); if (ret < 0) return ret; bool cheatloaded = false; if (cheat == 1) { /* OCARINA STUFF - FISHEARS*/ cheatloaded = ocarina_do_code() == 1; cheatloaded = true; } /* Set an appropiate video mode */ __Disc_SetVMode(videoselected); /* Set time */ __Disc_SetTime(); // Anti-green screen fix VIDEO_SetBlack(TRUE); VIDEO_Flush(); VIDEO_WaitVSync(); gprintf("\n\nUSB Loader GX is done.\n\n"); /* Shutdown IOS subsystems */ // fix for PeppaPig (from NeoGamma) extern void __exception_closeall(); IRQ_Disable(); __IOS_ShutdownSubsystems(); __exception_closeall(); appentrypoint = (u32) p_entry; if (cheat == 1 && cheatloaded) { __asm__( "lis %r3, appentrypoint@h\n" "ori %r3, %r3, appentrypoint@l\n" "lwz %r3, 0(%r3)\n" "mtlr %r3\n" "lis %r3, 0x8000\n" "ori %r3, %r3, 0x18A8\n" "mtctr %r3\n" "bctr\n" ); } else { __asm__( "lis %r3, appentrypoint@h\n" "ori %r3, %r3, appentrypoint@l\n" "lwz %r3, 0(%r3)\n" "mtlr %r3\n" "blr\n" ); } return 0; }
s32 Disc_OpenPartitionSimple(u64 offset) { return WDVD_OpenPartition(offset, 0, 0, 0, Tmd_Buffer); }
s32 Disc_BootPartition(u64 offset, u8 vidMode, const u8 *cheat, u32 cheatSize, bool vipatch, bool countryString, u8 patchVidMode) { entry_point p_entry; gprintf("Open partition at offset: 0x%08x\n", offset); s32 ret = WDVD_OpenPartition(offset, 0, 0, 0, Tmd_Buffer); if (ret < 0) { gprintf("Open partition failed: %d\n", ret); return ret; } /* Disconnect Wiimote */ WPAD_Flush(0); WPAD_Disconnect(0); WPAD_Shutdown(); /* Reload IOS into the correct IOS */ u8 ios = Tmd_Buffer[0x18B]; gprintf("Game requires ios %d\n", ios); if (ios != IOS_GetVersion()) { WDVD_ClosePartition(); WDVD_Close(); gprintf("Reloading IOS..."); ret = IOS_ReloadIOS(ios); if (ret < 0) { gprintf("failed: %d\n", ret); } else { gprintf("done\n"); } if (Disc_Init() < 0) { return -4; } if (Disc_Open() < 0) { return -6; } if (WDVD_OpenPartition(offset, 0, 0, 0, Tmd_Buffer) < 0) { return -8; } } gprintf("Setting low memory\n"); /* Setup low memory */; __Disc_SetLowMem(); gprintf("Select video mode\n"); /* Select an appropriate video mode */ __Disc_SelectVMode(vidMode); gprintf("Running apploader\n"); /* Run apploader */ ret = Apploader_Run(&p_entry, cheat != 0, vidMode, vmode, vipatch, countryString, patchVidMode); if (ret < 0) { gprintf("Failed to run apploader\n"); return ret; } gprintf("Set video mode\n"); /* Set an appropriate video mode */ __Disc_SetVMode(); if (cheat != 0 && hooktype != 0) { ocarina_do_code(); } gprintf("Set time\n"); /* Set time */ __Disc_SetTime(); gprintf("Reset video..."); /* This prevent a green screen (or a flash of green before loading the game) */ VIDEO_SetBlack(TRUE); gprintf("flushing..."); VIDEO_Flush(); gprintf("wait for sync..."); VIDEO_WaitVSync(); gprintf("wait for sync..."); VIDEO_WaitVSync(); gprintf("\n"); u8 temp_data[4]; gprintf("Shutting down wii systems\n"); // fix for PeppaPig memcpy((char *) &temp_data, (void*)0x800000F4,4); /* Shutdown IOS subsystems */ SYS_ResetSystem(SYS_SHUTDOWN, 0, 0); // fix for PeppaPig memcpy((void*)0x800000F4,(char *) &temp_data, 4); appentrypoint = (u32) p_entry; gprintf("Current IOS: %d\n", IOS_GetVersion()); gprintf("Starting game\n"); if (cheat != 0) { __asm__( "lis %r3, appentrypoint@h\n" "ori %r3, %r3, appentrypoint@l\n" "lwz %r3, 0(%r3)\n" "mtlr %r3\n" "lis %r3, 0x8000\n" "ori %r3, %r3, 0x18A8\n" "mtctr %r3\n" "bctr\n" ); } else { __asm__( "lis %r3, appentrypoint@h\n" "ori %r3, %r3, appentrypoint@l\n" "lwz %r3, 0(%r3)\n" "mtlr %r3\n" "blr\n" ); } return 0; }