Exemple #1
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;
}
Exemple #2
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;
}
Exemple #3
0
void Menu_Boot()
{
	struct discHdr *header;
	bool gc = false;

	header = &gameList[gameSelected];
	
	s32 ret;
	struct Game_CFG_2 *game_cfg = NULL;

	/* Clear console */
	if (!CFG.direct_launch) {
		Con_Clear();
	}
	FgColor(CFG.color_header);
	printf_x(gt("Start this game?"));
	printf("\n\n");
	DefaultColor();
	
	game_cfg = CFG_find_game(header->id);

	// Get game size
	gc = header->magic == GC_MAGIC;
	bool do_skip = !CFG.confirm_start;
/*
	SoundInfo snd;
	u8 banner_title[84];
	memset(banner_title, 0, 84);
	memset(&snd, 0, sizeof(snd));
	WBFS_Banner(header->id, &snd, banner_title, !do_skip, CFG_read_active_game_setting(header->id).write_playlog);
*/
	if (do_skip) {
		goto skip_confirm;
	}

	printf("\n");

	/* Show game info */
	printf_("%s\n", get_title(header));
	printf_("(%.6s)\n\n", header->id);

	__Menu_ShowGameInfo(true, header->id); /* load game info from XML */
	printf("\n");

	//Does DL warning apply to launching discs too? Not sure
	printf_h(gt("Press %s button to continue."), (button_names[CFG.button_confirm.num]));
	printf("\n");
	printf_h(gt("Press %s button to go back."), (button_names[CFG.button_cancel.num]));
	if (!gc) {
		printf("\n");
		printf_h(gt("Press %s button for options."), (button_names[CFG.button_other.num]));
	}
	printf("\n\n");
	__console_flush(0);

	// play banner sound
/*
	if (snd.dsp_data) {
		SND_PauseVoice(0, 1); // pause mp3
		int fmt = (snd.channels == 2) ? VOICE_STEREO_16BIT : VOICE_MONO_16BIT;
		SND_SetVoice(1, fmt, snd.rate, 0,
			snd.dsp_data, snd.size,
			255,255, //volume,volume,
			NULL); //DataTransferCallback
	}
*/
	/* Wait for user answer */
	u32 buttons;
	for (;;) {
		buttons = Wpad_WaitButtons();
		if (buttons & CFG.button_confirm.mask) break;
		if (buttons & CFG.button_cancel.mask) break;
		if (!gc && (buttons & CFG.button_other.mask)) break;
		if (buttons & CFG.button_exit.mask) break;
	}
/*
	// stop banner sound, resume mp3
	if (snd.dsp_data) {
		SND_StopVoice(1);
		SAFE_FREE(snd.dsp_data);
		if (buttons & CFG.button_confirm.mask) {
			SND_ChangeVolumeVoice(0, 0, 0);
		}
		SND_PauseVoice(0, 0);
	}
*/
	if (buttons & CFG.button_cancel.mask) goto close;
	if (buttons & CFG.button_exit.mask) {
		Handle_Home(0);
		return;
	}
	if (!gc && (buttons & CFG.button_other.mask)) {
		Menu_Boot_Options(header);
		return;
	}
	// A button: continue to boot

	skip_confirm:

	if (game_cfg) {
		CFG.game = game_cfg->curr;
	}

	if (CFG.game.write_playlog && set_playrec(header->id, (u8 *) header->title) < 0) { // banner_title) < 0) {
		printf_(gt("Error storing playlog file.\nStart from the Wii Menu to fix."));
		printf("\n");
		printf_h(gt("Press %s button to exit."), (button_names[CFG.button_exit.num]));
		printf("\n");
		if (!Menu_Confirm(0)) return;
	}

	WBFS_OpenDisc(header->id, header->game_idx);

	printf("\n");
	printf_x(gt("Booting Wii game, please wait..."));
	printf("\n\n");
	
	// load stuff before ios reloads & services close
	ocarina_load_code(header->id);
	load_wip_patches(header->id);

	// Close the wode stuff
	WBFS_Close();
	use_dvdx = 0;
	
	Disc_Init();
	ret = Disc_Wait();
	if (ret < 0) {
		printf("Cannot mount newly selected image: %d\n", ret);
	}
	Disc_Open();

	// stop services (music, gui)
	Services_Close();

	setPlayStat(header->id); //I'd rather do this after the check, but now you unmount fat before that ;)
	
	Fat_UnmountAll();

	if (gc) {
		WII_Initialize();
		ret = WII_LaunchTitle(0x0000000100000100ULL);
	} else {
		switch(CFG.game.language)
				{
						// 0 = CFG_LANG_CONSOLE
						case 0: configbytes[0] = 0xCD; break; 
						case 1: configbytes[0] = 0x00; break; 
						case 2: configbytes[0] = 0x01; break; 
						case 3: configbytes[0] = 0x02; break; 
						case 4: configbytes[0] = 0x03; break; 
						case 5: configbytes[0] = 0x04; break; 
						case 6: configbytes[0] = 0x05; break; 
						case 7: configbytes[0] = 0x06; break; 
						case 8: configbytes[0] = 0x07; break; 
						case 9: configbytes[0] = 0x08; break; 
						case 10: configbytes[0] = 0x09; break;
				}

		/* Boot Wii disc */
		ret = Disc_WiiBoot();
	}
	printf_(gt("Returned! (ret = %d)"), ret);
	printf("\n");

	printf("\n");
	printf_(gt("Press any button to exit..."));
	printf("\n");

	/* Wait for button */
	Wpad_WaitButtonsCommon();
	exit(0);
close:
	WDVD_StopMotor();
	header = &gameList[gameSelected];
	Gui_DrawCover(header->id);
	
	// Reopen the wode
	WBFS_Init();
	
	return;
}
Exemple #4
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;
}
Exemple #5
0
//---------------------------------------------------------------------------------
int main(int argc, char **argv) 
	{
	VIDEO_Init();
	VIDEO_SetBlack(true);  // Disable video output during initialisation

	net_wc24cleanup();
	
	if (fatMountSimple("sd", &__io_wiisd))
		DebugStart (true, "sd://ploader.log");
	else
		DebugStart (true, NULL);

	configbytes[0] = 0xCD;
	//configbytes[0] = 0;

	Debug ("---------------------------------------------------------------------------");
	Debug ("                             di "VER" by stfour");
	Debug ("                       (part of postLoader project)");
	Debug ("---------------------------------------------------------------------------");
	
	struct discHdr *header;
	header = (struct discHdr *)memalign(32, sizeof(struct discHdr));

	s32 rr = Disc_Init();
	Debug("Disc_Init() returned: %d", rr);
	
	rr = Disc_Open();
	Debug("Disc_Open() returned: %d", rr);

	// Check disc 
	rr = Disc_IsGC();
	Debug("Disc_IsGC() returned: %d", rr);
	
	if (rr == 0)
		{
		rr = WDVD_ReadDiskId ((void*)0x80000000);
		Debug("WDVD_ReadDiskId() returned: %d", rr);
		
		rr = WDVD_EnableAudio(*(u8*)0x80000008);
		Debug("WDVD_EnableAudio() returned: %d", rr);
		
		*(volatile unsigned int *)0xCC003024 |= 7;

		int retval = ES_GetTicketViews(BC, &view, 1);

		if (retval != 0)
			{
			Debug("ES_GetTicketViews fail %d", retval);
			exit (0);
			}
			
		retval = ES_LaunchTitle(BC, &view);
		exit (0);
		}
		
	// Check disc 
	rr = Disc_IsWii();
	Debug("Disc_IsWii() returned: %d", rr);

	if (rr == 0)
		{
		// Read header 
		rr = Disc_ReadHeader(header);
		Debug("Disc_ReadHeader() returned: %d", rr);

		Disc_WiiBoot (0, FALSE, TRUE, 0);
		}
	
	exit (0);
	}
Exemple #6
0
void Menu_Boot(void)
{
	struct discHdr *header = NULL;

	s32 ret;

	/* No game list */
	if (!gameCnt)
		return;

	/* Selected game */
	header = &gameList[gameSelected];

	/* Clear console */
	Con_Clear();

	printf("[+] Are you sure you want to boot this\n");
	printf("    game?\n\n");

	/* Show game info */
	__Menu_PrintInfo(header);

	printf("    Press A button to continue.\n");
	printf("    Press B button to go back.\n\n");

	/* Wait for user answer */
	for (;;) {
		u32 buttons = Wpad_WaitButtons();

		/* A button */
		if (buttons & WPAD_BUTTON_A)
			break;

		/* B button */
		if (buttons & WPAD_BUTTON_B)
			return;
	}

	printf("\n");
	printf("[+] Booting Wii game, please wait...\n");

	/* Set WBFS mode */
	Disc_SetWBFS(wbfsDev, header->id);

	/* Open disc */
	ret = Disc_Open();
	if (ret < 0) {
		printf("    ERROR: Could not open game! (ret = %d)\n", ret);
		goto out;
	}

	/* Boot Wii disc */
	Disc_WiiBoot();

	printf("    Returned! (ret = %d)\n", ret);

out:
	printf("\n");
	printf("    Press any button to continue...\n");

	/* Wait for button */
	Wpad_WaitButtons();
}
Exemple #7
0
void Menu_Install(void)
{
	static struct discHdr header ATTRIBUTE_ALIGN(32);

	s32 ret;

	/* Clear console */
	Con_Clear();

	printf("[+] Are you sure you want to install a\n");
	printf("    new Wii game?\n\n");

	printf("    Press A button to continue.\n");
	printf("    Press B button to go back.\n\n\n");

	/* Wait for user answer */
	for (;;) {
		u32 buttons = Wpad_WaitButtons();

		/* A button */
		if (buttons & WPAD_BUTTON_A)
			break;

		/* B button */
		if (buttons & WPAD_BUTTON_B)
			return;
	}

	/* Disable WBFS mode */
	Disc_SetWBFS(0, NULL);

	printf("[+] Insert the game DVD disc...");
	fflush(stdout);

	/* Wait for disc */
	ret = Disc_Wait();
	if (ret < 0) {
		printf("\n    ERROR! (ret = %d)\n", ret);
		goto out;
	} else
		printf(" OK!\n");

	printf("[+] Opening DVD disc...");
	fflush(stdout);

	/* Open disc */
	ret = Disc_Open();
	if (ret < 0) {
		printf("\n    ERROR! (ret = %d)\n", ret);
		goto out;
	} else
		printf(" OK!\n\n");

	/* Check disc */
	ret = Disc_IsWii();
	if (ret < 0) {
		printf("[+] ERROR: Not a Wii disc!!\n");
		goto out;
	}

	/* Read header */
	Disc_ReadHeader(&header);

	/* Check if game is already installed */
	ret = WBFS_CheckGame(header.id);
	if (ret) {
		printf("[+] ERROR: Game already installed!!\n");
		goto out;
	}

	printf("[+] Installing game, please wait...\n\n");

	printf("    %s\n",           header.title);
	printf("    (%c%c%c%c)\n\n", header.id[0], header.id[1], header.id[2], header.id[3]);

	/* Install game */
	ret = WBFS_AddGame();
	if (ret < 0) {
		printf("[+] Installation ERROR! (ret = %d)\n", ret);
		goto out;
	}

	/* Reload entries */
	__Menu_GetEntries();

out:
	printf("\n");
	printf("    Press any button to continue...\n");

	/* Wait for any button */
	Wpad_WaitButtons();
}
Exemple #8
0
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;
}
Exemple #9
0
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;
}