void PatchAspectRatio(void *addr, u32 len, u8 aspect) { if(aspect > 1) return; wifi_printf("patchcode_PatchAspectRatio: aspect value = %d\n", aspect); static const u32 aspect_searchpattern1[5] = { 0x9421FFF0, 0x7C0802A6, 0x38800001, 0x90010014, 0x38610008 }; static const u32 aspect_searchpattern2[15] = { 0x2C030000, 0x40820010, 0x38000000, 0x98010008, 0x48000018, 0x88010008, 0x28000001, 0x4182000C, 0x38000000, 0x98010008, 0x80010014, 0x88610008, 0x7C0803A6, 0x38210010, 0x4E800020 }; u8 *addr_start = (u8 *) addr; u8 *addr_end = addr_start + len - sizeof(aspect_searchpattern1) - 4 - sizeof(aspect_searchpattern2); while(addr_start < addr_end) { if( (memcmp(addr_start, aspect_searchpattern1, sizeof(aspect_searchpattern1)) == 0) && (memcmp(addr_start + 4 + sizeof(aspect_searchpattern1), aspect_searchpattern2, sizeof(aspect_searchpattern2)) == 0)) { *((u32 *)(addr_start+0x44)) = (0x38600000 | aspect); wifi_printf("patchcode_PatchAspectRatio: aspect patch found at %08X\n", addr_start); break; } addr_start += 4; } }
u32 Apploader_Run(u8 vidMode, GXRModeObj *vmode, bool vipatch, bool countryString, u8 patchVidModes, int aspectRatio) { void *dst = NULL; int len = 0; int offset = 0; u32 appldr_len; s32 ret; app_entry appldr_entry; app_init appldr_init; app_main appldr_main; app_final appldr_final; ret = WDVD_Read(&apploader_hdr, 0x20, APPLDR_OFFSET); wifi_printf("apploader_Apploader_Run: WDVD_Read() return value = %d\n", ret); if(ret < 0) return 0; appldr_len = apploader_hdr.size + apploader_hdr.trailersize; wifi_printf("apploader_Apploader_Run: appldr_len value = %08X\n", appldr_len); ret = WDVD_Read(appldr, appldr_len, APPLDR_CODE); wifi_printf("apploader_Apploader_Run: WDVD_Read() return value = %d\n", ret); if(ret < 0) return 0; DCFlushRange(appldr, appldr_len); ICInvalidateRange(appldr, appldr_len); appldr_entry = apploader_hdr.entry; appldr_entry(&appldr_init, &appldr_main, &appldr_final); appldr_init(gprintf); while(appldr_main(&dst, &len, &offset)) { WDVD_Read(dst, len, offset); wifi_printf("apploader_Apploader_Run: dst = %08X len = %08X offset = %08X\n", (u32)dst, (u32)len, (u32)offset); maindolpatches(dst, len, vidMode, vmode, vipatch, countryString, patchVidModes, aspectRatio); DCFlushRange(dst, len); ICInvalidateRange(dst, len); prog(10); } return (u32)appldr_final(); }
extern "C" void xprintf(const char *str, ...) { if(Options.sdgecko) sdprintf(str); if(Options.wifigecko) wifi_printf(str); if(!Options.wifigecko && !Options.sdgecko) gprintf(str); }
s32 WDVD_Init(void) { /* Open "/dev/di" */ if(di_fd < 0) { di_fd = IOS_Open(di_fs, 0); wifi_printf("wdvd_WDVD_Init: di_fd value = %d\n", di_fd); if (di_fd < 0) return di_fd; } return 0; }
void ocarina_set_codes(void *list, u8 *listend, u8 *cheats, u32 cheatSize) { codelist = list; codelistend = listend; code_buf = cheats; code_size = cheatSize; wifi_printf("fst_ocarina_set_codes: code_size value = %08X\n", code_size); if(code_size <= 0) { code_buf = NULL; code_size = 0; return; } if (code_size > (u32)codelistend - (u32)codelist) { wifi_printf("fst_ocarina_set_codes: codes are too long\n"); code_buf = NULL; code_size = 0; return; } }
void vidolpatcher(void *addr, u32 len) { void *addr_start = addr; void *addr_end = addr+len; while(addr_start < addr_end) { if(memcmp(addr_start, vipatchcode, sizeof(vipatchcode))==0) { vipatch((u32)addr_start, len); wifi_printf("patchcode_vidolpatcher: vidolpatcher found at %08X\n", addr_start); } addr_start += 4; } }
int ocarina_do_code() { if(codelist) memset(codelist, 0, (u32)codelistend - (u32)codelist); wifi_printf("fst_ocarina_do_code: code_size value = %08X\n", code_size); if(code_size > 0 && code_buf) { memcpy(codelist, code_buf, code_size); DCFlushRange(codelist, (u32)codelistend - (u32)codelist); } return 1; }
void langpatcher(void *addr, u32 len) { void *addr_start = addr; void *addr_end = addr+len; while(addr_start < addr_end) { if(memcmp(addr_start, langpatch, sizeof(langpatch))==0) if(configbytes[0] != 0xCD) { langvipatch((u32)addr_start, len, configbytes[0]); wifi_printf("patchcode_langpatcher: langpatcher found at %08X\n", addr_start); } addr_start += 4; } }
bool dogamehooks(void *addr, u32 len, bool channel) { /* 0 No Hook 1 VBI 2 KPAD read 3 Joypad Hook 4 GXDraw Hook 5 GXFlush Hook 6 OSSleepThread Hook 7 AXNextFrame Hook */ void *addr_start = addr; void *addr_end = addr+len; while(addr_start < addr_end) { switch(hooktype) { case 0x00: hookpatched = true; break; case 0x01: if(memcmp(addr_start, viwiihooks, sizeof(viwiihooks))==0) { patchhook((u32)addr_start, len); wifi_printf("patchcode_dogamehooks: viwiihooks at = %08X\n", addr_start); hookpatched = true; } break; case 0x02: if(memcmp(addr_start, kpadhooks, sizeof(kpadhooks))==0) { patchhook((u32)addr_start, len); wifi_printf("patchcode_dogamehooks: kpadhooks at = %08X\n", addr_start); hookpatched = true; } if(memcmp(addr_start, kpadoldhooks, sizeof(kpadoldhooks))==0) { patchhook((u32)addr_start, len); wifi_printf("patchcode_dogamehooks: kpadoldhooks at = %08X\n", addr_start); hookpatched = true; } break; case 0x03: if(memcmp(addr_start, joypadhooks, sizeof(joypadhooks))==0) { patchhook((u32)addr_start, len); wifi_printf("patchcode_dogamehooks: joypadhooks at = %08X\n", addr_start); hookpatched = true; } break; case 0x04: if(memcmp(addr_start, gxdrawhooks, sizeof(gxdrawhooks))==0) { patchhook((u32)addr_start, len); wifi_printf("patchcode_dogamehooks: gxdrawhooks at = %08X\n", addr_start); hookpatched = true; } break; case 0x05: if(memcmp(addr_start, gxflushhooks, sizeof(gxflushhooks))==0) { patchhook((u32)addr_start, len); wifi_printf("patchcode_dogamehooks: gxflushhooks at = %08X\n", addr_start); hookpatched = true; } break; case 0x06: if(memcmp(addr_start, ossleepthreadhooks, sizeof(ossleepthreadhooks))==0) { patchhook((u32)addr_start, len); wifi_printf("patchcode_dogamehooks: ossleepthreadhooks at = %08X\n", addr_start); hookpatched = true; } break; case 0x07: if(memcmp(addr_start, axnextframehooks, sizeof(axnextframehooks))==0) { patchhook((u32)addr_start, len); wifi_printf("patchcode_dogamehooks: axnextframehooks at = %08X\n", addr_start); hookpatched = true; } break; } if (hooktype != 0) { if(channel && memcmp(addr_start, multidolchanhooks, sizeof(multidolchanhooks))==0) { *(((u32*)addr_start)+1) = 0x7FE802A6; DCFlushRange(((u32*)addr_start)+1, 4); multidolhook((u32)addr_start+sizeof(multidolchanhooks)-4); wifi_printf("patchcode_dogamehooks: multidolchanhooks at = %08X\n", addr_start); } else if(!channel && memcmp(addr_start, multidolhooks, sizeof(multidolhooks))==0) { multidolhook((u32)addr_start+sizeof(multidolhooks)-4); wifi_printf("patchcode_dogamehooks: multidoldolhooks at = %08X\n", addr_start); } } addr_start += 4; } return hookpatched; }
void PatchCountryStrings(void *Address, int Size) { u8 SearchPattern[4] = {0x00, 0x00, 0x00, 0x00}; u8 PatchData[4] = {0x00, 0x00, 0x00, 0x00}; u8 *Addr = (u8*)Address; int wiiregion = CONF_GetRegion(); wifi_printf("patchcode_PatchCountryStrings: wiiregion value = %d\n", wiiregion); switch(wiiregion) { case CONF_REGION_JP: SearchPattern[0] = 0x00; SearchPattern[1] = 'J'; SearchPattern[2] = 'P'; break; case CONF_REGION_EU: SearchPattern[0] = 0x02; SearchPattern[1] = 'E'; SearchPattern[2] = 'U'; break; case CONF_REGION_KR: SearchPattern[0] = 0x04; SearchPattern[1] = 'K'; SearchPattern[2] = 'R'; break; case CONF_REGION_CN: SearchPattern[0] = 0x05; SearchPattern[1] = 'C'; SearchPattern[2] = 'N'; break; case CONF_REGION_US: default: SearchPattern[0] = 0x01; SearchPattern[1] = 'U'; SearchPattern[2] = 'S'; } const char DiscRegion = ((u8*)Disc_ID)[3]; wifi_printf("PatchCountryStrings: DiscRegion value = %c\n", DiscRegion); switch(DiscRegion) { case 'J': PatchData[1] = 'J'; PatchData[2] = 'P'; break; case 'D': case 'F': case 'P': case 'X': case 'Y': PatchData[1] = 'E'; PatchData[2] = 'U'; break; case 'E': default: PatchData[1] = 'U'; PatchData[2] = 'S'; } while (Size >= 4) { if(Addr[0] == SearchPattern[0] && Addr[1] == SearchPattern[1] && Addr[2] == SearchPattern[2] && Addr[3] == SearchPattern[3]) { Addr += 1; *Addr = PatchData[1]; Addr += 1; *Addr = PatchData[2]; Addr += 1; Addr += 1; Size -= 4; } else { Addr += 4; Size -= 4; } } }
void patchmenu(void *addr, u32 len, int patchnum) { void *addr_start = addr; void *addr_end = addr+len; wifi_printf("patchcode_patchmenu: patchnum value = %d\n", patchnum); while(addr_start < addr_end) { switch (patchnum) { case 0: if(memcmp(addr_start, recoveryhooks, sizeof(recoveryhooks))==0){ patchhook3((u32)addr_start, len); menuhook = 1; wifi_printf("patchcode_patchmenu: found recoveryhooks = %08X\n", (u32)addr_start); } break; case 1: if(memcmp(addr_start, viwiihooks, sizeof(viwiihooks))==0){ patchhook2((u32)addr_start, len); menuhook = 1; wifi_printf("patchcode_patchmenu: found viwiihooks = %08X\n", (u32)addr_start); } break; case 2: // jap region free if(memcmp(addr_start, regionfreehooks, sizeof(regionfreehooks))==0){ regionfreejap((u32)addr_start, len); wifi_printf("patchcode_patchmenu: found regionfreejap = %08X\n", (u32)addr_start); } // usa region free if(memcmp(addr_start, regionfreehooks, sizeof(regionfreehooks))==0){ regionfreeusa((u32)addr_start, len); wifi_printf("patchcode_patchmenu: found regionfreeusa = %08X\n", (u32)addr_start); } // pal region free if(memcmp(addr_start, regionfreehooks, sizeof(regionfreehooks))==0){ regionfreepal((u32)addr_start, len); wifi_printf("patchcode_patchmenu: found regionfreepal = %08X\n", (u32)addr_start); } // skip disc update if(memcmp(addr_start, updatecheckhook, sizeof(updatecheckhook))==0){ patchupdatecheck((u32)addr_start, len); wifi_printf("patchcode_patchmenu: found updatecheckhook = %08X\n", (u32)addr_start); } break; // button skip case 3: if(memcmp(addr_start, healthcheckhook, sizeof(healthcheckhook))==0){ removehealthcheck((u32)addr_start, len); wifi_printf("patchcode_patchmenu: found healthcheckhook = %08X\n", (u32)addr_start); } break; // no copy flags case 4: // Remove the actual flag so can copy back if(memcmp(addr_start, nocopyflag5, sizeof(nocopyflag5))==0){ copyflagcheck5((u32)addr_start, len); wifi_printf("patchcode_patchmenu: found nocopyflag5 = %08X\n", (u32)addr_start); } if(memcmp(addr_start, nocopyflag1, sizeof(nocopyflag1))==0){ copyflagcheck1((u32)addr_start, len); wifi_printf("patchcode_patchmenu: found nocopyflag1 = %08X\n", (u32)addr_start); } if(memcmp(addr_start, nocopyflag2, sizeof(nocopyflag2))==0){ copyflagcheck2((u32)addr_start, len); wifi_printf("patchcode_patchmenu: found nocopyflag2 = %08X\n", (u32)addr_start); } if(memcmp(addr_start, nocopyflag3, sizeof(nocopyflag2))==0){ copyflagcheck3((u32)addr_start, len); wifi_printf("patchcode_patchmenu: found nocopyflag3 = %08X\n", (u32)addr_start); } if(memcmp(addr_start, nocopyflag4, sizeof(nocopyflag4))==0){ copyflagcheck4((u32)addr_start, len); wifi_printf("patchcode_patchmenu: found nocopyflag4 = %08X\n", (u32)addr_start); } if(memcmp(addr_start, nocopyflag6, sizeof(nocopyflag6))==0){ copyflagcheck6((u32)addr_start, len); wifi_printf("patchcode_patchmenu: found nocopyflag6 = %08X\n", (u32)addr_start); } if(memcmp(addr_start, nocopyflag7, sizeof(nocopyflag7))==0){ copyflagcheck7((u32)addr_start, len); wifi_printf("patchcode_patchmenu: found nocopyflag7 = %08X\n", (u32)addr_start); } if(memcmp(addr_start, nocopyflag8, sizeof(nocopyflag8))==0){ copyflagcheck8((u32)addr_start, len); wifi_printf("patchcode_patchmenu: found nocopyflag8 = %08X\n", (u32)addr_start); } break; // move disc channel case 5: if(memcmp(addr_start, movedvdpatch, sizeof(movedvdpatch))==0){ movedvdhooks((u32)addr_start, len); wifi_printf("patchcode_patchmenu: found movvedvdhooks = %08X\n", (u32)addr_start); } break; } addr_start += 4; } }
void load_handler() { if(debuggerselect == 0x01) { wifi_printf("fst_load_handler: debugger selected\n"); memcpy((void*)0x80001800, codehandler, codehandler_size); if(code_size > 0 && code_buf) { wifi_printf("fst_load_handler: codes found\n"); memcpy((void*)0x80001CDE, &codelist, 2); memcpy((void*)0x80001CE2, ((u8*) &codelist) + 2, 2); memcpy((void*)0x80001F5A, &codelist, 2); memcpy((void*)0x80001F5E, ((u8*) &codelist) + 2, 2); } else wifi_printf("fst_load_handler: no codes found\n"); DCFlushRange((void*)0x80001800, codehandler_size); ICInvalidateRange((void*)0x80001800, codehandler_size); } else { wifi_printf("fst_load_handler: no debugger selected\n"); memcpy((void*)0x80001800, codehandleronly, codehandleronly_size); if(code_size > 0 && code_buf) { wifi_printf("fst_load_handler: codes found\n"); memcpy((void*)0x80001906, &codelist, 2); memcpy((void*)0x8000190A, ((u8*) &codelist) + 2, 2); } else wifi_printf("fst_load_handler: no codes found\n"); DCFlushRange((void*)0x80001800, codehandleronly_size); ICInvalidateRange((void*)0x80001800, codehandleronly_size); } // Load multidol handler memcpy((void*)0x80001000, multidol, multidol_size); DCFlushRange((void*)0x80001000, multidol_size); ICInvalidateRange((void*)0x80001000, multidol_size); switch(hooktype) { case 0x01: memcpy((void*)0x8000119C,viwiihooks,12); memcpy((void*)0x80001198,viwiihooks+3,4); break; case 0x02: memcpy((void*)0x8000119C,kpadhooks,12); memcpy((void*)0x80001198,kpadhooks+3,4); break; case 0x03: memcpy((void*)0x8000119C,joypadhooks,12); memcpy((void*)0x80001198,joypadhooks+3,4); break; case 0x04: memcpy((void*)0x8000119C,gxdrawhooks,12); memcpy((void*)0x80001198,gxdrawhooks+3,4); break; case 0x05: memcpy((void*)0x8000119C,gxflushhooks,12); memcpy((void*)0x80001198,gxflushhooks+3,4); break; case 0x06: memcpy((void*)0x8000119C,ossleepthreadhooks,12); memcpy((void*)0x80001198,ossleepthreadhooks+3,4); break; case 0x07: memcpy((void*)0x8000119C,axnextframehooks,12); memcpy((void*)0x80001198,axnextframehooks+3,4); break; } DCFlushRange((void*)0x80001198,16); }