int applyAllCheats() { int i = 0, j = 0; for(i = 0; i < _cheats.num_cheats; i++) { CheatEntry *cheat = &_cheats.cheat[i]; cheat->enabled = 1; if(getEnabledCheatsSize() > kenobi_get_maxsize()) cheat->enabled = 0; j++; } return j; }
// Installs the GeckoOS (kenobiGC) cheats engine and sets up variables/copies cheats void kenobi_install_engine() { int isDebug = swissSettings.wiirdDebug; // If high memory is in use, we'll use low, otherwise high. u8 *ptr = isDebug ? kenobigc_dbg_bin : kenobigc_bin; u32 size = isDebug ? kenobigc_dbg_bin_size : kenobigc_bin_size; print_gecko("Copying kenobi%s to %08X\r\n", (isDebug?"_dbg":""),(u32)CHEATS_ENGINE); memcpy(CHEATS_ENGINE, ptr, size); memcpy(CHEATS_GAMEID, (void*)0x80000000, CHEATS_GAMEID_LEN); if(!isDebug) { CHEATS_ENABLE_CHEATS = CHEATS_TRUE; } CHEATS_START_PAUSED = isDebug ? CHEATS_TRUE : CHEATS_FALSE; memset(CHEATS_LOCATION(size), 0, kenobi_get_maxsize()); print_gecko("Copying %i bytes of cheats to %08X\r\n", getEnabledCheatsSize(),(u32)CHEATS_LOCATION(size)); u32 *cheatsLocation = (u32*)CHEATS_LOCATION(size); cheatsLocation[0] = 0x00D0C0DE; cheatsLocation[1] = 0x00D0C0DE; cheatsLocation+=2; int i = 0, j = 0; for(i = 0; i < _cheats.num_cheats; i++) { CheatEntry *cheat = &_cheats.cheat[i]; if(cheat->enabled) { for(j = 0; j < cheat->num_codes; j++) { // Copy & fix cheats that want to jump to the old cheat engine location 0x800018A8 -> CHEATS_ENGINE+0xA8 cheatsLocation[0] = cheat->codes[j][0]; cheatsLocation[1] = cheat->codes[j][1] == 0x800018A8 ? (u32)(CHEATS_ENGINE+0xA8) : cheat->codes[j][1]; cheatsLocation+=2; } } } cheatsLocation[0] = 0xFF000000; DCFlushRange((void*)CHEATS_ENGINE, WIIRD_ENGINE_SPACE); ICInvalidateRange((void*)CHEATS_ENGINE, WIIRD_ENGINE_SPACE); }
void DrawCheatsSelector(char *fileName) { CheatEntries* cheats = getCheats(); int cheat_selection = 0; int cheats_per_page = 6; while ((PAD_ButtonsHeld(0) & PAD_BUTTON_A)){ VIDEO_WaitVSync (); } while(1) { doBackdrop(); DrawEmptyBox(20,60, vmode->fbWidth-20, 460, COLOR_BLACK); sprintf(txtbuffer, "%s Cheats:", fileName); WriteFontStyled(25, 62, txtbuffer, GetTextScaleToFitInWidth(txtbuffer, vmode->fbWidth-50), false, defaultColor); int j = 0; int current_view_start = MIN(MAX(0,cheat_selection-cheats_per_page/2),MAX(0,cheats->num_cheats-cheats_per_page)); int current_view_end = MIN(cheats->num_cheats, MAX(cheat_selection+cheats_per_page/2,cheats_per_page)); int scrollBarHeight = 90+(cheats_per_page*20); int scrollBarTabHeight = (int)((float)scrollBarHeight/(float)cheats->num_cheats); DrawVertScrollBar(vmode->fbWidth-45, 120, 25, scrollBarHeight, (float)((float)cheat_selection/(float)(cheats->num_cheats-1)),scrollBarTabHeight); for(j = 0; current_view_start<current_view_end; ++current_view_start,++j) { drawCheatForCheatsSelector(&cheats->cheat[current_view_start], 25, 120+j*35, current_view_start==cheat_selection); } // Write about how many cheats are enabled DrawTransparentBox( 35, 350, vmode->fbWidth-35, 410); WriteFontStyled(33, 345, "Space taken by cheats:", 0.8f, false, defaultColor); GXColor noColor = (GXColor) {0,0,0,0}; //blank GXColor borderColor = (GXColor) {200,200,200,GUI_MSGBOX_ALPHA}; //silver GXColor progressBarColor = (GXColor) {255,128,0,GUI_MSGBOX_ALPHA}; //orange float multiplier = (float)getEnabledCheatsSize() / (float)kenobi_get_maxsize(); DrawSimpleBox( 33, 370, vmode->fbWidth-66, 20, 0, noColor, borderColor); DrawSimpleBox( 33, 370, (int)((vmode->fbWidth-66)*multiplier), 20, 0, progressBarColor, noColor); sprintf(txtbuffer, "WiiRD Debug %s", swissSettings.wiirdDebug ? "Enabled":"Disabled"); WriteFontStyled(33, 395, txtbuffer, 0.8f, false, defaultColor); WriteFontStyled(640/2, 440, "(A) Toggle Cheat - (X) WiiRD Debug - (B) Return", 0.9f, true, defaultColor); DrawFrameFinish(); while (!(PAD_ButtonsHeld(0) & (PAD_BUTTON_UP|PAD_BUTTON_DOWN|PAD_BUTTON_B|PAD_BUTTON_A|PAD_BUTTON_X))) { VIDEO_WaitVSync (); } u16 btns = PAD_ButtonsHeld(0); if(btns & (PAD_BUTTON_UP|PAD_BUTTON_DOWN)) { cheat_selection = btns & PAD_BUTTON_UP ? ((--cheat_selection < 0) ? cheats->num_cheats-1 : cheat_selection) :((cheat_selection + 1) % cheats->num_cheats); } if(btns & PAD_BUTTON_A) { cheats->cheat[cheat_selection].enabled ^= 1; if(getEnabledCheatsSize() > kenobi_get_maxsize()) // No room cheats->cheat[cheat_selection].enabled = 0; } if(btns & PAD_BUTTON_X) { swissSettings.wiirdDebug ^=1; } if(btns & PAD_BUTTON_B) { break; } while (PAD_ButtonsHeld(0) & (PAD_BUTTON_UP|PAD_BUTTON_DOWN|PAD_BUTTON_B|PAD_BUTTON_A|PAD_BUTTON_X)) { VIDEO_WaitVSync (); } } }