void printd(const char *text, ...) { static int geckoinit = 0; if (!geckoinit) { if (usb_isgeckoalive (EXI_CHANNEL_1)) geckoinit = 1; else geckoinit = -1; } if (geckoinit <= 0) return; char buff[1024]; va_list args; va_start(args, text); vsprintf(buff, text, args); va_end(args); strcat (buff, "\n"); usb_sendbuffer( EXI_CHANNEL_1, buff, strlen(buff) ); usb_flush(EXI_CHANNEL_1); }
s32 DebugStart (bool gecko, char *fn) { filelog = 0; started = 0; sprintf (dbgfile, fn); geckolog = usb_isgeckoalive (EXI_CHANNEL_1); // check if the file exist FILE * f = NULL; f = fopen(dbgfile, "rb"); if (f) { filelog = 1; fclose (f); } memset (cache, 0, sizeof(cache)); if (filelog || geckolog) started = 1; return started; }
void debug(const char *text, ...) { static int gecko = 0; if (gecko == 0) { if (usb_isgeckoalive (EXI_CHANNEL_1)) gecko = 2; else gecko = 1; } va_list args; va_start(args, text); vsprintf(debugbuff, text, args); va_end(args); if (gecko == 2) { usb_sendbuffer( EXI_CHANNEL_1, debugbuff, strlen(debugbuff) ); usb_flush(EXI_CHANNEL_1); } if (debug2ConsoleEnabled) { printf(debugbuff); sleep (1); } else { if (strlen(points) < 80) strcat (points, "."); Console_SetPosition (14,0); PrintCenter (points, 80); } /* printf(debugbuff); if (strstr (debugbuff, "ERR:")) sleep (5); */ if (logbuff == NULL) // allocate space for { logbuff = calloc (LBSIZE,1); lbsize = 0; } else { int blen; blen = strlen(debugbuff); if (lbsize + blen < LBSIZE) { strcat (logbuff, debugbuff); lbsize += blen; } } }
static void * GeckoThread(void *arg) { stopNetworkThread = 0; errors = 0; LWP_SetThreadPriority(geckothread, 8); printopt("gecko thread running, ready !"); if (usb_isgeckoalive (EXI_CHANNEL_1)) { wiiload.gecko = 1; while (!stopGeckoThread) { if (!GeckoLoad ()) usb_flush (EXI_CHANNEL_1); usleep (100); } } else while (!stopGeckoThread) { usleep (250000); } printopt("exiting gecko thread..."); stopGeckoThread = 2; return 0; }
static int usbopen(struct dbginterface *device) { if(!usb_isgeckoalive(device->fhndl)) { return -1; } return 0; }
void USBGeckoOutput() { LWP_MutexInit(&gecko_mutex, false); gecko = usb_isgeckoalive(1); devoptab_list[STD_OUT] = &gecko_out; devoptab_list[STD_ERR] = &gecko_out; }
void InitGecko() { if (usb_isgeckoalive(EXI_CHANNEL_1)) { usb_flush(EXI_CHANNEL_1); geckoinit = true; } }
bool InitGecko() { u32 geckoattached = usb_isgeckoalive(EXI_CHANNEL_1); if (geckoattached) { usb_flush(EXI_CHANNEL_1); return true; } else return false; }
void CheckForGecko( void ) { GeckoFound = usb_isgeckoalive( EXI_CHANNEL_1 ); if(GeckoFound) { usb_flush(EXI_CHANNEL_1); gprintf("gecko found\n"); } return; }
void Output::WiiSetConsole() { LWP_MutexInit(&usbgecko_mutex, false); usbgecko = usb_isgeckoalive(1); if (usbgecko) { devoptab_list[STD_OUT] = &dotab_geckoout; devoptab_list[STD_ERR] = &dotab_geckoout; } else { devoptab_list[STD_OUT] = &dotab_stdnull; devoptab_list[STD_ERR] = &dotab_stdnull; } }
void CON_EnableGecko(int channel,int safe) { if(channel && (channel>1 || !usb_isgeckoalive(channel))) channel = -1; __gecko_status = channel; __gecko_safe = safe; if(__gecko_status!=-1) { devoptab_list[STD_OUT] = &dotab_stdout; devoptab_list[STD_ERR] = &dotab_stdout; } }
void log_console_init(GXRModeObj *vmode, u16 logsize) { u16 i; LWP_MutexInit(&console_mutex, false); #ifndef WIILIB CON_InitEx(vmode, 20, 30, vmode->fbWidth - 40, vmode->xfbHeight - 60); //CON_InitEx(vmode, 10, 10 , (vmode->fbWidth / 2)-80, vmode->xfbHeight - 40); #endif rcb = VIDEO_SetPostRetraceCallback(NULL); VIDEO_SetPostRetraceCallback(rcb); /* VIDEO_ClearFrameBuffer(vmode, xfb[0], COLOR_BLACK); VIDEO_ClearFrameBuffer(vmode, xfb[1], COLOR_BLACK); VIDEO_SetNextFramebuffer(xfb[whichfb]); VIDEO_SetBlack(FALSE); VIDEO_Flush(); VIDEO_WaitVSync(); if (vmode->viTVMode & VI_NON_INTERLACE) VIDEO_WaitVSync(); */ gecko = usb_isgeckoalive(1); if (log_size && log) { for (i = 0; i < log_size; ++i) if (log[i]) free(log[i]); free(log); } log_size = logsize; log_next = 0; if (log_size) { log = (char **) malloc(log_size * sizeof(char *)); for (i = 0; i < log_size; ++i) log[i] = NULL; } log_active = log_size > 0; dot_video = devoptab_list[STD_OUT]; video_active = true; devoptab_list[STD_OUT] = &dot_out; devoptab_list[STD_ERR] = &dot_out; }
struct dbginterface* usb_init(s32 channel) { usb_device.fhndl = channel; if(usb_isgeckoalive(channel)) usb_flush(channel); usb_device.open = usbopen; usb_device.close = usbclose; usb_device.wait = usbwait; usb_device.read = usbread; usb_device.write = usbwrite; return &usb_device; }
s32 DebugStart (bool gecko, const char *dbgfile) { #ifdef USBGECKO started = 0; geckolog = usb_isgeckoalive (EXI_CHANNEL_1); // Open or create dbgfile fdebug = fopen(dbgfile, "wb"); // File will be cleared if it already exists. if (fdebug || geckolog) started = 1; return started; #endif return 0; }
void CON_EnableGecko(int channel,int safe) { if(channel && (channel>1 || !usb_isgeckoalive(channel))) channel = -1; __gecko_status = channel; __gecko_safe = safe; if(__gecko_status!=-1) { devoptab_list[STD_OUT] = &dotab_stdout; devoptab_list[STD_ERR] = &dotab_stdout; // line buffered output for threaded apps when only using the usbgecko if(!curr_con) { setvbuf(stdout, NULL, _IOLBF, 0); setvbuf(stderr, NULL, _IOLBF, 0); } } }
// Checks if devices are available, prints name of device being detected for slow init devices void populateDeviceAvailability() { DrawFrameStart(); DrawMessageBox(D_INFO, "Detecting devices ...\nThis can be skipped by holding B next time"); DrawFrameFinish(); if(PAD_ButtonsHeld(0) & PAD_BUTTON_B) { deviceHandler_setAllDevicesAvailable(); return; } const DISC_INTERFACE* carda = &__io_gcsda; const DISC_INTERFACE* cardb = &__io_gcsdb; // DVD deviceHandler_setDeviceAvailable(DVD_DISC, swissSettings.hasDVDDrive); // SD Gecko DrawFrameStart(); DrawMessageBox(D_INFO, "Detecting devices [SD] ...\nThis can be skipped by holding B next time"); DrawFrameFinish(); deviceHandler_setDeviceAvailable(SD_CARD, carda->isInserted() || cardb->isInserted()); // IDE-EXI DrawFrameStart(); DrawMessageBox(D_INFO, "Detecting devices [IDE-EXI] ...\nThis can be skipped by holding B next time"); DrawFrameFinish(); deviceHandler_setDeviceAvailable(IDEEXI, ide_exi_inserted(0) || ide_exi_inserted(1)); // Qoob deviceHandler_setDeviceAvailable(QOOB_FLASH, 0); // Hidden by default, add auto detect at some point // WODE deviceHandler_setDeviceAvailable(WODE, 0); // Hidden by default, add auto detect at some point // Memory card DrawFrameStart(); DrawMessageBox(D_INFO, "Detecting devices [Memory Card] ...\nThis can be skipped by holding B next time"); DrawFrameFinish(); deviceHandler_setDeviceAvailable(MEMCARD, (initialize_card(0)==CARD_ERROR_READY) || (initialize_card(1)==CARD_ERROR_READY)); // WKF/WASP DrawFrameStart(); DrawMessageBox(D_INFO, "Detecting devices [WKF/WASP] ...\nThis can be skipped by holding B next time"); DrawFrameFinish(); deviceHandler_setDeviceAvailable(WKF, swissSettings.hasDVDDrive && (__wkfSpiReadId() != 0 && __wkfSpiReadId() != 0xFFFFFFFF)); // USB Gecko deviceHandler_setDeviceAvailable(USBGECKO, usb_isgeckoalive(1)); // BBA/SAMBA deviceHandler_setDeviceAvailable(SAMBA, exi_bba_exists()); // System, always there deviceHandler_setDeviceAvailable(SYS, 1); }
void InitDebug() { if (CFG.debug_gecko & (1|4)) { if (usb_isgeckoalive(EXI_CHANNEL_1)) { usb_flush(EXI_CHANNEL_1); if (!gecko_enabled) { gecko_enabled = 1; gecko_prints("\n\n====================\n\n"); } } } if (CFG.debug_gecko & 2) { CON_EnableGecko(EXI_CHANNEL_1, 0); } debug_inited = 1; if (strlen(dbg_log_buf)) { gecko_printf(">>>\n%s\n<<<\n", dbg_log_buf); } }
int deviceHandler_USBGecko_init(file_handle* file) { DrawFrameStart(); DrawMessageBox(D_INFO,"Looking for USBGecko in Slot B"); DrawFrameFinish(); if(usb_isgeckoalive(1)) { int retries = 1000; DrawFrameStart(); DrawMessageBox(D_INFO,"Waiting for PC ..."); DrawFrameFinish(); usb_flush(1); usbgecko_lock_file(0); // Wait for the PC and retry 1000 times while(!usbgecko_pc_ready() && retries) { VIDEO_WaitVSync(); retries--; } if(!retries) { DrawFrameStart(); DrawMessageBox(D_INFO,"Couldn't find PC!"); DrawFrameFinish(); sleep(5); return 0; // Didn't find the PC } else { DrawFrameStart(); DrawMessageBox(D_INFO,"Found PC !!"); DrawFrameFinish(); return 1; } } else { return 0; } }
/**************************************************************************** * Main ****************************************************************************/ int main () { // Setup defaults (if no config is found) memset(&swissSettings, 0 , sizeof(SwissSettings)); void *fb; fb = Initialise(); if(!fb) { return -1; } // Sane defaults refreshSRAM(); swissSettings.debugUSB = 1; swissSettings.gameVMode = 0; // Auto video mode swissSettings.exiSpeed = 1; // 32MHz swissSettings.uiVMode = 0; // Auto UI mode swissSettings.enableFileManagement = 0; config_copy_swiss_settings(&swissSettings); needsDeviceChange = 1; needsRefresh = 1; //debugging stuff if(swissSettings.debugUSB) { if(usb_isgeckoalive(1)) { usb_flush(1); } print_gecko("Arena Size: %iKb\r\n",(SYS_GetArena1Hi()-SYS_GetArena1Lo())/1024); print_gecko("DVD Drive Present? %s\r\n",swissSettings.hasDVDDrive?"Yes":"No"); print_gecko("GIT Commit: %s\r\n", GITREVISION); print_gecko("GIT Revision: %s\r\n", GITVERSION); } // Detect devices populateDeviceAvailability(); curDevice = -1; // Are we working with a Wiikey Fusion? if(__wkfSpiReadId() != 0 && __wkfSpiReadId() != 0xFFFFFFFF) { print_gecko("Detected Wiikey Fusion with SPI Flash ID: %08X\r\n",__wkfSpiReadId()); // Set real device back curDevice = WKF; // SlotB hack trySlotB(); } else { deviceHandler_setStatEnabled(0); // Try to init SD cards here and load config deviceHandler_initial = &initial_SD0; deviceHandler_init = deviceHandler_FAT_init; deviceHandler_deinit = deviceHandler_FAT_deinit; if(deviceHandler_init(deviceHandler_initial)) { print_gecko("Detected SDGecko in Slot A\r\n"); load_auto_dol(); curDevice = SD_CARD; } else { deviceHandler_deinit(deviceHandler_initial); deviceHandler_initial = &initial_SD1; if(deviceHandler_init(deviceHandler_initial)) { print_gecko("Detected SDGecko in Slot B\r\n"); load_auto_dol(); curDevice = SD_CARD; } } deviceHandler_setStatEnabled(1); } // If no device has been selected yet to browse .. if(curDevice < 0) { print_gecko("No default boot device detected, trying DVD!\r\n"); // Do we have a DVD drive with a ready medium we can perhaps browse then? u8 driveReallyExists[8]; drive_version(&driveReallyExists[0]); if(*(u32*)&driveReallyExists[0]) { dvd_read_id(); if(!dvd_get_error()) { print_gecko("DVD Medium is up, using it as default device\r\n"); curDevice = DVD_DISC; // If we have a GameCube (single image) bootable disc, show the banner screen here dvdDiscTypeInt = gettype_disc(); if(dvdDiscTypeInt == GAMECUBE_DISC) { select_device(1); // Setup curFile and load it memset(&curFile, 0, sizeof(file_handle)); strcpy(&curFile.name[0], "game.gcm"); curFile.size = DISC_SIZE; curFile.fileAttrib = IS_FILE; populate_meta(&curFile); load_file(); curDevice = -1; deviceHandler_initial = NULL; } } } } if(curDevice) { needsDeviceChange = 0; select_device(1); // to setup deviceHandler_ ptrs load_config(forceSlot); } // Start up the BBA if it exists init_network_thread(); init_httpd_thread(); // DVD Motor off if(swissSettings.stopMotor && swissSettings.hasDVDDrive) { dvd_motor_off(); } // Swiss video mode force GXRModeObj *forcedMode = getModeFromSwissSetting(swissSettings.uiVMode); if((forcedMode != NULL) && (forcedMode != vmode)) { initialise_video(forcedMode); vmode = forcedMode; } while(1) { main_loop(); } return 0; }
//--------------------------------------------------------------------------------- int main(int argc, char **argv) { //--------------------------------------------------------------------------------- s32 ret; u8 gamestatus = 0x03; u8 versionnumber = 0x80; u32 geckoidcheck; u8 oldconfigbytes[2]; ret = sd_init(); if(!ret){ sd_found = 0; } else { sd_found = 1; } if (*((u32 *) 0x80001804) == 0x53545542 && *((u32 *) 0x80001808) == 0x48415858) loaderhbc = 1; *(u32*)0xCD00643C = 0x00000000; // 32Mhz on Bus gecko_attached = usb_isgeckoalive(EXI_CHANNEL_1); if(gecko_attached){ gecko_channel = 1; if (EXI_GetID(gecko_channel, 0x80, &geckoidcheck) == 1) { if (geckoidcheck != 0) { gecko_attached = FALSE; goto slota; } } else { gecko_attached = FALSE; goto slota; } usb_flushnew(gecko_channel); goto slotb; } slota: gecko_attached = usb_isgeckoalive(EXI_CHANNEL_0); if(gecko_attached){ gecko_channel = 0; if (EXI_GetID(gecko_channel, 0x80, &geckoidcheck) == 1) { if (geckoidcheck != 0) { gecko_attached = FALSE; goto slotb; } } else { gecko_attached = FALSE; goto slotb; } usb_flushnew(gecko_channel); } slotb: sd_load_config(); tempgameconf = (char *) sdbuffer; autobootcheck = 1; memset(gameidbuffer, 0, 8); app_loadgameconfig(gameidbuffer); autobootcheck = 0; loadStartupIOS(); iosversion = IOS_GetVersion(); if(config_not_loaded == 0){ menu_load_config(); config_not_loaded = 1; } if (autoboothbc || !loaderhbc) { if (autoboot == 1) { rebooter_thread(); menu_number = 12; rebooter_thread_state = 0; } } else autoboot = 0; WPAD_Init(); PAD_Init(); VIDEO_Init(); AUDIO_Init (NULL); SYS_SetPowerCallback (power_cb); SYS_SetResetCallback (reset_cb); if (CONF_GetProgressiveScan() > 0 && VIDEO_HaveComponentCable()) { progmode = 1; } if (CONF_GetAspectRatio()) { widescreen = 1; } gfx_init(); gfx_load_gfx(); gfx_load_gfx1(); if (autoboot == 0 || autobootwait > 1) gfx_fade_logo(); VIDEO_WaitVSync(); if(!gecko_attached){ gecko_channel = 2; } gfx_int_stars(); while(1) { if(gecko_attached){ usb_recvbuffer(gecko_channel,&gecko_command,1); switch(gecko_command) { //case 0x04: // gecko_readmem(); //break; case 0x14: // Load DOL load_geckoexe(0); break; case 0x24: // Load DOL load_geckoexe(1); break; case 0x42: // Debugger on, pause start off config_bytes[7] = 0x01; config_bytes[5] = 0x00; usb_recvbuffer_safe(gecko_channel,&oldconfigbytes,2); // Get config config_bytes[0] = oldconfigbytes[0]; switch (oldconfigbytes[1]) { case 0x00: config_bytes[1] = 0x00; break; case 0x01: config_bytes[1] = 0x01; break; case 0x02: config_bytes[1] = 0x00; break; case 0x03: config_bytes[1] = 0x01; break; case 0x04: config_bytes[1] = 0x03; break; case 0x05: config_bytes[1] = 0x03; break; case 0x06: config_bytes[1] = 0x02; break; case 0x07: config_bytes[1] = 0x02; break; } menu_number = 8; apploader_thread(); gecko_command = 0; break; case 0x43: // Debugger on, pause start on config_bytes[7] = 0x01; config_bytes[5] = 0x01; usb_recvbuffer_safe(gecko_channel,&oldconfigbytes,2); // Get config config_bytes[0] = oldconfigbytes[0]; switch (oldconfigbytes[1]) { case 0x00: config_bytes[1] = 0x00; break; case 0x01: config_bytes[1] = 0x01; break; case 0x02: config_bytes[1] = 0x00; break; case 0x03: config_bytes[1] = 0x01; break; case 0x04: config_bytes[1] = 0x03; break; case 0x05: config_bytes[1] = 0x03; break; case 0x06: config_bytes[1] = 0x02; break; case 0x07: config_bytes[1] = 0x02; break; } menu_number = 8; apploader_thread(); gecko_command = 0; break; case 0x50: usb_sendbuffer_safe(gecko_channel,&gamestatus,1); break; case 0x99: usb_sendbuffer_safe(gecko_channel,&versionnumber,1); break; } } if(error_sd || confirm_sd || error_video){ sleep(1); error_sd = 0; confirm_sd = 0; error_video = 0; } if(loadedpng && !alphapng){ // if custom backdrop draw bubbles after image gfx_draw_image(0, 0, 640, 480, tex_logo1, 0, 1, 1,0xff); gfx_draw_stars(); } else{ gfx_draw_stars(); // else if own back drop do in this order due to border clip gfx_draw_image(0, 0, 640, 480, tex_logo1, 0, 1, 1,0xff); }; menu_draw(); gfx_render_direct(); } return 0; }
//--------------------------------------------------------------------------------- int main(int argc, char **argv) { //--------------------------------------------------------------------------------- s32 retval; // Initialise the video system VIDEO_Init(); // This function initialises the attached controllers WPAD_Init(); // Obtain the preferred video mode from the system // This will correspond to the settings in the Wii menu rmode = VIDEO_GetPreferredMode(NULL); // Allocate memory for the display in the uncached region xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); // Initialise the console, required for printf console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ); // Set up the video registers with the chosen mode VIDEO_Configure(rmode); // Tell the video hardware where our display memory is VIDEO_SetNextFramebuffer(xfb); // Make the display visible VIDEO_SetBlack(FALSE); // Flush the video register changes to the hardware VIDEO_Flush(); // Wait for Video setup to complete VIDEO_WaitVSync(); if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); if(usb_isgeckoalive(1))CON_EnableGecko(1, 1); log_buffer = (char*)malloc(0x4000); memset(log_buffer, 0, 0x4000); printf("Initializing WC24...\n"); retval = WC24_Init(); if(retval<0) { printf("WC24_Init returned %d\n", retval); return retval; } curtitleid = WC24_GetTitleID(); printf("\n\n"); printf("Getting NANDBOOTINFO argv...\n"); argv = WII_GetNANDBootInfoArgv(&argc, &launchcode); #ifdef WIILOADAPPDEBUG #ifdef WIILOADTEST_BOOTDISC argc = 1; launchcode = 2; #endif #ifdef WIILOADTEST_BOOTHB launchcode = 1; argc = 2; argv[1] = WIILOADTEST_BOOTHB; #endif #endif ResetWakeup_Timestamp(); #ifndef WIILOADAPPDEBUG retval = ProcessWC24(launchcode & BIT(25));//Don't do any WC24 stuff with HBC wiiload, only with the actual installed wc24boottitle. #endif launchcode &= ~(BIT(25)); ProcessArgs(argc, argv, 0); printf("Shutting down WC24...\n"); WC24_Shutdown(); FlushLog(); return 0; }
void info_draw_page(int page_num) { doBackdrop(); DrawEmptyBox(20,60, vmode->fbWidth-20, 420, COLOR_BLACK); syssram* sram = __SYS_LockSram(); __SYS_UnlockSram(0); // System Info (Page 1/3) if(!page_num) { WriteFont(30, 65, "System Info (1/3):"); // Model if(is_gamecube()) { if(*(u32*)&driveVersion[0] == 0x20010831) { sprintf(topStr, "Panasonic Q SL-GC10-S"); } else if(IPLInfo[0x55]=='M') { // MPAL 1.1 (Brazil) sprintf(topStr, "Nintendo GameCube DOL-002 (BRA)"); } else if((!IPLInfo[0x55]) // NTSC 1.0 || (IPLInfo[0x55] == 'P' && IPLInfo[0x65]=='0') // PAL 1.0 || (IPLInfo[0x55] != 'P' && IPLInfo[0x65]=='1')) { // NTSC 1.1 sprintf(topStr, "Nintendo GameCube DOL-001"); } else if((IPLInfo[0x55] == 'P' && IPLInfo[0x65]=='0') // PAL 1.1 || IPLInfo[0x65]=='2') { // NTSC 1.2 sprintf(topStr, "Nintendo GameCube DOL-101"); } } else { sprintf(topStr, "Nintendo Wii"); } WriteFontStyled(640/2, 110, topStr, 1.0f, true, defaultColor); // IPL version string if(is_gamecube()) { if(!IPLInfo[0x55]) { sprintf(topStr, "NTSC Revision 1.0"); } else { sprintf(topStr, "%s", &IPLInfo[0x55]); } } else { sprintf(topStr, "Wii IPL"); } WriteFontStyled(640/2, 140, topStr, 1.0f, true, defaultColor); if(swissSettings.hasDVDDrive) { if((!__wkfSpiReadId() || (__wkfSpiReadId() == 0xFFFFFFFF))) { sprintf(topStr, "DVD Drive %02X %02X%02X/%02X (%02X)",driveVersion[2],driveVersion[0],driveVersion[1],driveVersion[3],driveVersion[4]); } else { sprintf(topStr, "WKF Serial %s",wkfGetSerial()); } } else sprintf(topStr, "No DVD Drive present"); WriteFontStyled(640/2, 170, topStr, 1.0f, true, defaultColor); sprintf(topStr, "%s",videoStr); WriteFontStyled(640/2, 200, topStr, 1.0f, true, defaultColor); sprintf(topStr,"%s / %s",getSramLang(sram->lang), sram->flags&4 ? "Stereo":"Mono"); WriteFontStyled(640/2, 230, topStr, 1.0f, true, defaultColor); sprintf(topStr,"PVR %08X ECID %08X:%08X:%08X",mfpvr(),mfspr(0x39C),mfspr(0x39D),mfspr(0x39E)); WriteFontStyled(640/2, 260, topStr, 0.75f, true, defaultColor); } else if(page_num == 1) { WriteFont(30, 65, "Device Info (2/3):"); sprintf(topStr,"BBA: %s", bba_exists ? "Installed":"Not Present"); WriteFont(30, 110, topStr); if(exi_bba_exists()) { sprintf(topStr,"IP: %s", net_initialized ? bba_ip:"Not Available"); } else { sprintf(topStr,"IP: Not Available"); } WriteFont(270, 110, topStr); sprintf(topStr,"Component Cable Plugged in: %s",VIDEO_HaveComponentCable()?"Yes":"No"); WriteFont(30, 140, topStr); if(usb_isgeckoalive(0)||usb_isgeckoalive(1)) { sprintf(topStr,"USB Gecko: Installed in %s",usb_isgeckoalive(0)?"Slot A":"Slot B"); } else { sprintf(topStr,"USB Gecko: Not Present"); } WriteFont(30, 170, topStr); if (!deviceHandler_initial) { sprintf(topStr, "Current Device: No Device Selected"); } else if(deviceHandler_initial == &initial_SD0 || deviceHandler_initial == &initial_SD1) { int slot = (deviceHandler_initial->name[2] == 'b'); sprintf(topStr, "Current Device: %s Card in %s @ %s",!SDHCCard?"SDHC":"SD",!slot?"Slot A":"Slot B",!swissSettings.exiSpeed?"16Mhz":"32Mhz"); } else if(deviceHandler_initial == &initial_DVD) { sprintf(topStr, "Current Device: %s DVD Disc",dvdDiscTypeStr); } else if(deviceHandler_initial == &initial_IDE0 || deviceHandler_initial == &initial_IDE1) { int slot = (deviceHandler_initial->name[3] == 'b'); sprintf(topStr, "Current Device: %d GB HDD in %s",ataDriveInfo.sizeInGigaBytes,!slot?"Slot A":"Slot B"); } else if(deviceHandler_initial == &initial_Qoob) { sprintf(topStr, "Current Device: Qoob IPL Replacement"); } else if(deviceHandler_initial == &initial_WODE) { sprintf(topStr, "Current Device: Wode Jukebox"); } else if(deviceHandler_initial == &initial_CARDA || deviceHandler_initial == &initial_CARDB) { sprintf(topStr, "Current Device: Memory Card in %s",!deviceHandler_initial->fileBase?"Slot A":"Slot B"); } else if(deviceHandler_initial == &initial_USBGecko) { sprintf(topStr, "Current Device: USB Gecko"); } else if(deviceHandler_initial == &initial_WKF) { sprintf(topStr, "Current Device: Wiikey Fusion"); } else if(deviceHandler_initial == &initial_SYS) { sprintf(topStr, "Current Device: System"); } WriteFont(30, 200, topStr); } else if(page_num == 2) { WriteFont(30, 65, "Credits (3/3):"); WriteFontStyled(640/2, 115, "Swiss ver 0.4", 1.0f, true, defaultColor); WriteFontStyled(640/2, 140, "by emu_kidid 2015", 0.75f, true, defaultColor); sprintf(txtbuffer, "Commit %s Revision %s SD Gecko Slot B Cheats Mod", GITREVISION, GITVERSION); WriteFontStyled(640/2, 165, txtbuffer, 0.75f, true, defaultColor); WriteFontStyled(640/2, 210, "Thanks to", 0.75f, true, defaultColor); WriteFontStyled(640/2, 228, "Testers & libOGC/dkPPC authors", 0.75f, true, defaultColor); WriteFontStyled(640/2, 246, "sepp256 for GX / FIX94 for Audio Streaming", 0.75f, true, defaultColor); WriteFontStyled(640/2, 264, "Extrems for video patches / Megalomaniac for builds", 0.75f, true, defaultColor); WriteFontStyled(640/2, 282, "Fishaman P for cheats support with all devices", 0.75f, true, defaultColor); WriteFontStyled(640/2, 318, "Web/Support http://www.gc-forever.com/", 0.75f, true, defaultColor); WriteFontStyled(640/2, 336, "Source at https://github.com/emukidid/swiss-gc", 0.75f, true, defaultColor); WriteFontStyled(640/2, 354, "Visit us at #gc-forever on EFNet", 0.75f, true, defaultColor); } if(page_num != 2) { WriteFont(520, 390, "->"); } if(page_num != 0) { WriteFont(100, 390, "<-"); } WriteFontStyled(640/2, 400, "Press A to return", 1.0f, true, defaultColor); DrawFrameFinish(); }
void CheckForGecko( void ) { if( !IsWiiU() ) GeckoFound = usb_isgeckoalive( 1 ); }
int patch_gcm(file_handle *file, ExecutableFile *filesToPatch, int numToPatch, int multiDol) { int i, num_patched = 0; // If the current device isn't SD Gecko, init SD Gecko Slot A or B to write patches. if(deviceHandler_initial != &initial_SD0 && deviceHandler_initial != &initial_SD1) { deviceHandler_setStatEnabled(0); if(deviceHandler_FAT_init(&initial_SD0)) { savePatchDevice = 0; } else if(deviceHandler_FAT_init(&initial_SD1)) { savePatchDevice = 1; } deviceHandler_setStatEnabled(1); } // Already using SD Gecko if(deviceHandler_initial == &initial_SD0) savePatchDevice = 0; else if(deviceHandler_initial == &initial_SD1) savePatchDevice = 1; if(savePatchDevice == -1) { DrawFrameStart(); DrawMessageBox(D_FAIL, "No writable device present\nA SD Gecko must be inserted in\n order to utilise patches for this game."); DrawFrameFinish(); sleep(5); return 0; } char patchFileName[256]; char patchDirName[256]; char patchBaseDirName[256]; char gameID[8]; memset(&gameID, 0, 8); memset(&patchDirName, 0, 256); memset(&patchBaseDirName, 0, 256); strncpy((char*)&gameID, (char*)&GCMDisk, 4); sprintf(&patchDirName[0],"%s:/swiss_patches/%s",(savePatchDevice ? "sdb":"sda"), &gameID[0]); sprintf(&patchBaseDirName[0],"%s:/swiss_patches",(savePatchDevice ? "sdb":"sda")); print_gecko("Patch dir will be: %s if required\r\n", patchDirName); *(u32*)VAR_EXECD_OFFSET = 0xFFFFFFFF; // Go through all the possible files we think need patching.. for(i = 0; i < numToPatch; i++) { u32 patched = 0, crc32 = 0; sprintf(txtbuffer, "Patching File %i/%i",i+1,numToPatch); DrawFrameStart(); DrawProgressBar((int)(((float)(i+1)/(float)numToPatch)*100), txtbuffer); DrawFrameFinish(); // Round up to 32 bytes if(filesToPatch[i].size % 0x20) { filesToPatch[i].size += (0x20-(filesToPatch[i].size%0x20)); } if(filesToPatch[i].size > 8*1024*1024) { print_gecko("Skipping %s %iKB too large\r\n", filesToPatch[i].name, filesToPatch[i].size/1024); continue; } print_gecko("Checking %s %iKb\r\n", filesToPatch[i].name, filesToPatch[i].size/1024); if(strstr(filesToPatch[i].name, "execD.")) { *(u32*)VAR_EXECD_OFFSET = filesToPatch[i].offset; } if(strstr(filesToPatch[i].name, "iwanagaD.dol") || strstr(filesToPatch[i].name, "switcherD.dol")) { continue; // skip unused PSO files } int sizeToRead = filesToPatch[i].size; u8 *buffer = (u8*)memalign(32, sizeToRead); deviceHandler_seekFile(file,filesToPatch[i].offset, DEVICE_HANDLER_SEEK_SET); if(deviceHandler_readFile(file,buffer,sizeToRead)!= sizeToRead) { DrawFrameStart(); DrawMessageBox(D_FAIL, "Failed to read!"); DrawFrameFinish(); sleep(5); return 0; } if(curDevice != DVD_DISC) { u32 ret = Patch_DVDLowLevelRead(buffer, sizeToRead, filesToPatch[i].type); if(READ_PATCHED_ALL != ret) { DrawFrameStart(); DrawMessageBox(D_FAIL, "Failed to find necessary functions for patching!"); DrawFrameFinish(); sleep(5); } else patched += 1; } if(swissSettings.debugUSB && usb_isgeckoalive(1) && !swissSettings.wiirdDebug) { patched += Patch_Fwrite(buffer, sizeToRead); } if(swissSettings.wiirdDebug || getEnabledCheatsSize() > 0) { Patch_CheatsHook(buffer, sizeToRead, filesToPatch[i].type); } if(curDevice == DVD_DISC && is_gamecube()) { patched += Patch_DVDLowLevelReadForDVD(buffer, sizeToRead, filesToPatch[i].type); patched += Patch_DVDReset(buffer, sizeToRead); } patched += Patch_VidMode(buffer, sizeToRead, filesToPatch[i].type); patched += Patch_FontEnc(buffer, sizeToRead); if(swissSettings.forceWidescreen) Patch_WideAspect(buffer, sizeToRead, filesToPatch[i].type); if(swissSettings.forceAnisotropy) Patch_TexFilt(buffer, sizeToRead, filesToPatch[i].type); if(patched) { // File handle for a patch we might need to write FILE *patchFile = 0; memset(patchFileName, 0, 256); // Make a base patches dir if we don't have one already if(mkdir(&patchBaseDirName[0], 0777) != 0) { if(errno != EEXIST) { return -2; } } if(mkdir(&patchDirName[0], 0777) != 0) { if(errno != EEXIST) { return -2; } } sprintf(patchFileName, "%s/%i",patchDirName, num_patched); // Work out the crc32 crc32 = Crc32_ComputeBuf( 0, buffer, (u32) sizeToRead); // See if this file already exists, if it does, match crc patchFile = fopen( patchFileName, "rb" ); if(patchFile) { //print_gecko("Old Patch exists\r\n"); u32 oldCrc32 = 0; fseek(patchFile, 0L, SEEK_END); u32 file_size = ftell(patchFile); fseek(patchFile, file_size-4, SEEK_SET); fread(&oldCrc32, 1, 4, patchFile); if(oldCrc32 == crc32) { num_patched++; fclose(patchFile); free(buffer); print_gecko("CRC matched, no need to patch again\r\n"); continue; } else { remove(patchFileName); fclose(patchFile); print_gecko("CRC mismatch, writing patch again\r\n"); } } // Otherwise, write a file out for this game with the patched buffer inside. print_gecko("Writing patch file: %s %i bytes (disc offset %08X)\r\n", patchFileName, sizeToRead, filesToPatch[i].offset); patchFile = fopen(patchFileName, "wb"); fwrite(buffer, 1, sizeToRead, patchFile); u32 magic = SWISS_MAGIC; fwrite(&filesToPatch[i].offset, 1, 4, patchFile); fwrite(&filesToPatch[i].size, 1, 4, patchFile); fwrite(&magic, 1, 4, patchFile); fwrite(&crc32, 1, 4, patchFile); fclose(patchFile); num_patched++; } free(buffer); } return num_patched; }
/**************************************************************************** * Main ****************************************************************************/ int main () { // Setup defaults (if no config is found) memset(&swissSettings, 0 , sizeof(SwissSettings)); // Register all devices supported (order matters for boot devices) int i = 0; for(i = 0; i < MAX_DEVICES; i++) allDevices[i] = NULL; i = 0; allDevices[i++] = &__device_wkf; allDevices[i++] = &__device_wode; allDevices[i++] = &__device_sd_a; allDevices[i++] = &__device_sd_b; allDevices[i++] = &__device_card_a; allDevices[i++] = &__device_card_b; allDevices[i++] = &__device_dvd; allDevices[i++] = &__device_ide_a; allDevices[i++] = &__device_ide_b; allDevices[i++] = &__device_qoob; allDevices[i++] = &__device_smb; allDevices[i++] = &__device_sys; allDevices[i++] = &__device_usbgecko; allDevices[i++] = &__device_ftp; allDevices[i++] = &__device_fsp; allDevices[i++] = NULL; // Set current devices devices[DEVICE_CUR] = NULL; devices[DEVICE_DEST] = NULL; devices[DEVICE_TEMP] = NULL; devices[DEVICE_CONFIG] = NULL; devices[DEVICE_PATCHES] = NULL; Initialise(); // Sane defaults refreshSRAM(&swissSettings); swissSettings.debugUSB = 0; swissSettings.gameVMode = 0; // Auto video mode swissSettings.exiSpeed = 1; // 32MHz swissSettings.uiVMode = 0; // Auto UI mode swissSettings.aveCompat = 1; swissSettings.enableFileManagement = 0; needsDeviceChange = 1; needsRefresh = 1; //debugging stuff if(swissSettings.debugUSB) { if(usb_isgeckoalive(1)) { usb_flush(1); } print_gecko("Arena Size: %iKb\r\n",(SYS_GetArena1Hi()-SYS_GetArena1Lo())/1024); print_gecko("DVD Drive Present? %s\r\n",swissSettings.hasDVDDrive?"Yes":"No"); print_gecko("GIT Commit: %s\r\n", GITREVISION); print_gecko("GIT Revision: %s\r\n", GITVERSION); } // Go through all devices with FEAT_BOOT_DEVICE feature and set it as current if one is available for(i = 0; i < MAX_DEVICES; i++) { if(allDevices[i] != NULL && (allDevices[i]->features & FEAT_BOOT_DEVICE)) { print_gecko("Testing device %s\r\n", allDevices[i]->deviceName); if(allDevices[i]->test()) { deviceHandler_setDeviceAvailable(allDevices[i], true); devices[DEVICE_CUR] = allDevices[i]; break; } } } if(devices[DEVICE_CUR] != NULL) { print_gecko("Detected %s\r\n", devices[DEVICE_CUR]->deviceName); if(devices[DEVICE_CUR]->init(devices[DEVICE_CUR]->initial)) { if(devices[DEVICE_CUR]->features & FEAT_AUTOLOAD_DOL) { load_auto_dol(); } memcpy(&curFile, devices[DEVICE_CUR]->initial, sizeof(file_handle)); needsDeviceChange = 0; } } // Scan here since some devices would already be initialised (faster) populateDeviceAvailability(); // If there's no default config device, set it to the first writable device available if(swissSettings.configDeviceId == DEVICE_ID_UNK) { for(int i = 0; i < MAX_DEVICES; i++) { if(allDevices[i] != NULL && (allDevices[i]->features & FEAT_WRITE) && deviceHandler_getDeviceAvailable(allDevices[i])) { swissSettings.configDeviceId = allDevices[i]->deviceUniqueId; print_gecko("No default config device found, using [%s]\r\n", allDevices[i]->deviceName); syssramex* sramex = __SYS_LockSramEx(); sramex->__padding0 = swissSettings.configDeviceId; __SYS_UnlockSramEx(1); while(!__SYS_SyncSram()); break; } } } // Try to open up the config .ini in case it hasn't been opened already if(config_init()) { // TODO notification area this print_gecko("Loaded %i entries from the config file\r\n",config_get_count()); } if(swissSettings.initNetworkAtStart) { // Start up the BBA if it exists uiDrawObj_t *msgBox = DrawPublish(DrawProgressBar(true, 0, "Initialising Network")); init_network(); init_httpd_thread(); DrawDispose(msgBox); } // DVD Motor off setting; Always stop the drive if we only started it to read the ID out if((swissSettings.stopMotor && swissSettings.hasDVDDrive) || (swissSettings.hasDVDDrive == 2)) { dvd_motor_off(); } // Swiss video mode force GXRModeObj *forcedMode = getVideoModeFromSwissSetting(swissSettings.uiVMode); if((forcedMode != NULL) && (forcedMode != getVideoMode())) { setVideoMode(forcedMode); } while(1) { menu_loop(); } return 0; }