Exemplo n.º 1
0
void WDMMenu::CheckGameFiles(const struct discHdr * header)
{
	wbfs_disc_t *disc = WBFS_OpenDisc((u8 *) header->id);
	if (!disc)
	{
		WindowPrompt(tr( "ERROR:" ), tr( "Could not open Disc" ), tr( "OK" ));
		return;
	}

	wiidisc_t *wdisc = wd_open_disc((int(*)(void *, u32, u32, void *)) wbfs_disc_read, disc);
	if (!wdisc)
	{
		WindowPrompt(tr( "ERROR:" ), tr( "Could not open Disc" ), tr( "OK" ));
		return;
	}

	FST_ENTRY * fstbuffer = (FST_ENTRY *) wd_extract_file(wdisc, ONLY_GAME_PARTITION, (char*) "FST");
	if (!fstbuffer)
	{
		WindowPrompt(tr( "ERROR:" ), tr( "Not enough free memory." ), tr( "OK" ));
		return;
	}

	wd_close_disc(wdisc);
	WBFS_CloseDisc(disc);

	int position = 0;
	vector<pair<int, string> > FilesNotInWDM;

	for(int i = 0; i < wdmFile->size(); ++i)
	{
		if(stringcompare(wdmFile->GetDolName(i), "main") == true)
		{
			DOLOffsetList.push_back(pair<int, int>(0, wdmFile->GetParameter(i)));
			Options->SetName(position, "%i.", position+1);
			Options->SetValue(position, wdmFile->GetReplaceName(i));
			position++;
		}
	}

	for (u32 i = 1; i < fstbuffer[0].filelen; i++)
	{
		//don't add files that aren't .dol to the list
		const char * filename = fstfiles(fstbuffer, i);
		const char * fileext = NULL;

		if(filename)
			fileext = strrchr(filename, '.');

		if (fileext && strcasecmp(fileext, ".dol") == 0)
		{
			char NameCpy[strlen(filename)+1];
			strcpy(NameCpy, filename);
			char *extension = strrchr(NameCpy, '.');
			if(extension) *extension = 0;

			int j;
			for(j = 0; j < wdmFile->size(); ++j)
			{
				if(stringcompare(wdmFile->GetDolName(j), NameCpy) == true)
				{
					DOLOffsetList.push_back(pair<int, int>(i, wdmFile->GetParameter(j)));
					Options->SetName(position, "%i.", position+1);
					Options->SetValue(position, wdmFile->GetReplaceName(j));
					position++;
					break;
				}
			}

			if(j == wdmFile->size())
				FilesNotInWDM.push_back(pair<int, string>(i, filename));
		}
	}

	for(u32 i = 0; i < FilesNotInWDM.size(); ++i)
	{
		DOLOffsetList.push_back(pair<int, int>(FilesNotInWDM[i].first, 1));
		Options->SetName(position, "%i.", position+1);
		Options->SetValue(position, FilesNotInWDM[i].second.c_str());
		position++;
	}

	free(fstbuffer);
}
Exemplo n.º 2
0
static void test_open_disc ( int argc, char ** argv )
{
    putchar('\n');
    int i, dump_level = 0;
    bool print_mm = false, print_ptab = false;
    wd_pfst_t pfst = 0;

    for ( i = 1; i < argc; i++ )
    {
	if (!strcmp(argv[i],"-l") )	dump_level++;
	if (!strcmp(argv[i],"-ll"))	dump_level += 2;
	if (!strcmp(argv[i],"-lll"))	dump_level += 3;
	if (!strcmp(argv[i],"-m"))	print_mm = true;
	if (!strcmp(argv[i],"-p"))	print_ptab = true;
	if (!strcmp(argv[i],"-f"))	pfst |= WD_PFST__ALL;
	if (!strcmp(argv[i],"-u"))	pfst |= WD_PFST_UNUSED|WD_PFST_HEADER;
	if (!strcmp(argv[i],"-o"))	pfst |= WD_PFST_OFFSET|WD_PFST_HEADER;
	if (!strcmp(argv[i],"-h"))	pfst |= WD_PFST_SIZE_HEX|WD_PFST_HEADER;
	if (!strcmp(argv[i],"-d"))	pfst |= WD_PFST_SIZE_DEC|WD_PFST_HEADER;
	if (!strcmp(argv[i],"-L"))	logging++;

	if ( *argv[i] == '-' )
	    continue;

	SuperFile_t sf;
	InitializeSF(&sf);
	if (!OpenSF(&sf,argv[i],false,false))
	{
	    printf("*** %s\n",sf.f.fname);
	    enumError err;
	    wd_disc_t * disc = wd_open_disc(WrapperReadDirectSF,&sf,sf.file_size,
						sf.f.fname,opt_force,&err);
	    if (disc)
	    {
		putchar('\n');
		wd_print_disc(stdout,3,disc,dump_level);

		if (print_mm)
		{
		    MemMap_t mm;
		    InitializeMemMap(&mm);
		    InsertDiscMemMap(&mm,disc);
		    printf("\nMemory map:\n\n");
		    PrintMemMap(&mm,stdout,3,0);
		    ResetMemMap(&mm);
		}

		if (print_ptab)
		{
		    printf("\nPartition tables:\n\n");
		    char buf[WII_MAX_PTAB_SIZE];
		    ReadSF(&sf,WII_PTAB_REF_OFF,buf,WII_MAX_PTAB_SIZE);
		    u64 * ptr = (u64*)(buf + WII_MAX_PTAB_SIZE) - 1;
		    while ( ptr > (u64*)buf && !*ptr )
			ptr--;
		    ptr++;
		    HexDump16(stdout,3,WII_PTAB_REF_OFF,buf,(ccp)ptr-buf);

		    putchar('\n');
		    wd_patch_ptab(disc,buf,true);
		    ptr = (u64*)(buf + WII_MAX_PTAB_SIZE) - 1;
		    while ( ptr > (u64*)buf && !*ptr )
			ptr--;
		    ptr++;
		    HexDump16(stdout,3,WII_PTAB_REF_OFF,buf,(ccp)ptr-buf);
		}

		if (pfst)
		{
		    printf("\nFile list:\n\n");
		    wd_print_fst(stdout,3,disc,WD_IPM_AUTO,pfst,0,0);
		}

		wd_close_disc(disc);
		putchar('\n');
	    }
	    else
		printf("\t==> FAILED, err=%x=%d!\n\n",err,err);
	    CloseSF(&sf,0);
	}
    }
}
Exemplo n.º 3
0
/********************************************************************************
 *Disk Browser
 *********************************************************************************/
int DiscBrowse(const char * GameID, char * alternatedname, int alternatedname_size)
{
	gprintf("\nDiscBrowser() started");
	bool exit = false;
	int ret = -1, choice;

	HaltGui();

	gprintf("WBFS_OpenDisc\n");
	wbfs_disc_t *disc = WBFS_OpenDisc((u8 *) GameID);
	if (!disc)
	{
		ResumeGui();
		WindowPrompt(tr( "ERROR:" ), tr( "Could not open Disc" ), tr( "OK" ));
		return ret;
	}
	gprintf("wd_open_disc\n");
	wiidisc_t *wdisc = wd_open_disc((int(*)(void *, u32, u32, void *)) wbfs_disc_read, disc);
	if (!wdisc)
	{
		ResumeGui();
		WindowPrompt(tr( "ERROR:" ), tr( "Could not open Disc" ), tr( "OK" ));
		return ret;
	}

	gprintf("wd_get_fst\n");
	FST_ENTRY * fstbuffer = (FST_ENTRY *) wd_extract_file(wdisc, ONLY_GAME_PARTITION, (char *) "FST");
	if (!fstbuffer)
	{
		ResumeGui();
		WindowPrompt(tr( "ERROR:" ), tr( "Not enough free memory." ), tr( "OK" ));
		return -1;
	}

	gprintf("wd_close_disc\n");
	wd_close_disc(wdisc);
	gprintf("WBFS_CloseDisc\n");
	WBFS_CloseDisc(disc);

	gprintf("options\n");
	OptionList options;

	for (u32 i = 0, position = 0; i < fstbuffer[0].filelen; i++)
	{
		//don't add files that aren't .dol to the list
		const char * filename = fstfiles(fstbuffer, i);
		const char * fileext = NULL;

		if(filename)
			fileext = strrchr(filename, '.');

		if (fileext && strcasecmp(fileext, ".dol") == 0)
		{
			options.SetName(position, "%s %03i", tr("Offset"), i);
			options.SetValue(position, filename);
			position++;
		}
	}

	free(fstbuffer);

	gprintf("\n%i alt dols found", options.GetLength()+1);
	if (options.GetLength() <= 0)
	{
		WindowPrompt(tr( "ERROR" ), tr( "No DOL file found on disc." ), tr( "OK" ));
		return ret;
	}

	GuiImageData btnOutline(Resources::GetFile("button_dialogue_box.png"), Resources::GetFileSize("button_dialogue_box.png"));
	GuiImageData settingsbg(Resources::GetFile("settings_background.png"), Resources::GetFileSize("settings_background.png"));

	GuiTrigger trigA;
	trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
	GuiTrigger trigHome;
	trigHome.SetButtonOnlyTrigger(-1, WPAD_BUTTON_HOME | WPAD_CLASSIC_BUTTON_HOME, 0);
	GuiTrigger trigB;
	trigB.SetButtonOnlyTrigger(-1, WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B, PAD_BUTTON_B);

	GuiText titleTxt(GameTitles.GetTitle(GameID), 28, ( GXColor ) {0, 0, 0, 255});
	titleTxt.SetAlignment(ALIGN_CENTER, ALIGN_TOP);
	titleTxt.SetPosition(12, 40);
	titleTxt.SetMaxWidth(356, SCROLL_HORIZONTAL);

	GuiImage settingsbackground(&settingsbg);
	GuiButton settingsbackgroundbtn(settingsbackground.GetWidth(), settingsbackground.GetHeight());
	settingsbackgroundbtn.SetAlignment(ALIGN_LEFT, ALIGN_TOP);
	settingsbackgroundbtn.SetPosition(0, 0);
	settingsbackgroundbtn.SetImage(&settingsbackground);

	GuiText cancelBtnTxt(tr( "Back" ), 22, thColor("r=0 g=0 b=0 a=255 - prompt windows button text color"));
	cancelBtnTxt.SetMaxWidth(btnOutline.GetWidth() - 30);
	GuiImage cancelBtnImg(&btnOutline);
	if (Settings.wsprompt == ON)
	{
		cancelBtnTxt.SetWidescreen(Settings.widescreen);
		cancelBtnImg.SetWidescreen(Settings.widescreen);
	}
	GuiButton cancelBtn(&cancelBtnImg, &cancelBtnImg, 2, 3, 180, 400, &trigA, btnSoundOver, btnSoundClick2, 1);
	cancelBtn.SetScale(0.9);
	cancelBtn.SetLabel(&cancelBtnTxt);
	cancelBtn.SetTrigger(&trigB);

	GuiOptionBrowser optionBrowser3(396, 280, &options, "bg_options_settings.png");
	optionBrowser3.SetPosition(0, 90);
	optionBrowser3.SetAlignment(ALIGN_CENTER, ALIGN_TOP);

	HaltGui();
	GuiWindow w(screenwidth, screenheight);
	w.Append(&settingsbackgroundbtn);
	w.Append(&titleTxt);
	w.Append(&cancelBtn);
	w.Append(&optionBrowser3);

	mainWindow->Append(&w);

	ResumeGui();
	while (!exit)
	{
		usleep(100);

		if (shutdown)
			Sys_Shutdown();
		if (reset)
			Sys_Reboot();

		ret = optionBrowser3.GetClickedOption();

		if (ret >= 0)
		{
			choice = WindowPrompt(options.GetValue(ret), tr( "Load this DOL as alternate DOL?" ), tr( "OK" ), tr( "Cancel" ));
			if (choice)
			{
				snprintf(alternatedname, alternatedname_size, options.GetValue(ret));
				const char * offset = options.GetName(ret);
				if(offset)
					ret = atoi(offset+strlen("Offset ")); //doloffset
				else
					ret = -1; // weird problem
				exit = true;
			}
		}

		if (cancelBtn.GetState() == STATE_CLICKED)
		{
			exit = true;
		}
	}

	HaltGui();
	mainWindow->Remove(&w);
	ResumeGui();

	return ret;
}