mirror of
https://github.com/wiidev/usbloadergx.git
synced 2024-11-05 02:55:07 +01:00
928020b32f
*Added Browser for AlternateDOL from disc feature NOTE: Right now the browser isn't working right and crashing from time to time so you i would not recommend to use it yet. It's also showing all files on the disc for test purpose. I'll try to fix it later right now i don't have time for it. *Changed some minor codes and moved cheats to its own folder
217 lines
6.1 KiB
C++
217 lines
6.1 KiB
C++
/****************************************************************************
|
|
* DiscBrowser
|
|
* USB Loader GX 2009
|
|
*
|
|
* DiscBrowser.h
|
|
***************************************************************************/
|
|
#include "language/gettext.h"
|
|
#include "libwiigui/gui.h"
|
|
#include "libwiigui/gui_customoptionbrowser.h"
|
|
#include "prompts/PromptWindows.h"
|
|
#include "filelist.h"
|
|
#include "menu.h"
|
|
#include "usbloader/disc.h"
|
|
#include "usbloader/fstfile.h"
|
|
#include "usbloader/wdvd.h"
|
|
#include "main.h"
|
|
#include "sys.h"
|
|
#include "settings/cfg.h"
|
|
|
|
/*** Extern functions ***/
|
|
extern void ResumeGui();
|
|
extern void HaltGui();
|
|
|
|
/*** Extern variables ***/
|
|
extern GuiWindow * mainWindow;
|
|
extern u8 shutdown;
|
|
extern u8 reset;
|
|
|
|
/********************************************************************************
|
|
*Game specific settings
|
|
*********************************************************************************/
|
|
int DiscBrowse(struct discHdr * header)
|
|
{
|
|
bool exit = false;
|
|
int ret, choice;
|
|
u64 offset;
|
|
|
|
ret = Disc_SetUSB(header->id);
|
|
if(ret < 0) {
|
|
WindowPrompt(tr("ERROR:"), tr("Could not set USB."), tr("OK"));
|
|
return ret;
|
|
}
|
|
|
|
ret = Disc_Open();
|
|
if(ret < 0) {
|
|
WindowPrompt(tr("ERROR:"), tr("Could not open disc."), tr("OK"));
|
|
return ret;
|
|
}
|
|
|
|
ret = __Disc_FindPartition(&offset);
|
|
if (ret < 0) {
|
|
WindowPrompt(tr("ERROR:"), tr("Could not find a WBFS partition."), tr("OK"));
|
|
return ret;
|
|
}
|
|
|
|
ret = WDVD_OpenPartition(offset);
|
|
if (ret < 0) {
|
|
WindowPrompt(tr("ERROR:"), tr("Could not open WBFS partition"), tr("OK"));
|
|
return ret;
|
|
}
|
|
|
|
int *buffer = (int*)memalign(32, 0x20);
|
|
|
|
if (buffer == NULL)
|
|
{
|
|
WindowPrompt(tr("ERROR:"), tr("Not enough free memory."), tr("OK"));
|
|
return -1;
|
|
}
|
|
|
|
ret = WDVD_Read(buffer, 0x20, 0x420);
|
|
if (ret < 0) {
|
|
WindowPrompt(tr("ERROR:"), tr("Could not read the disc."), tr("OK"));
|
|
return ret;
|
|
}
|
|
void *fstbuffer = memalign(32, buffer[2]*4);
|
|
FST_ENTRY *fst = (FST_ENTRY *)fstbuffer;
|
|
|
|
if (fst == NULL)
|
|
{
|
|
WindowPrompt(tr("ERROR:"), tr("Not enough free memory."), tr("OK"));
|
|
free(buffer);
|
|
return -1;
|
|
}
|
|
|
|
ret = WDVD_Read(fstbuffer, buffer[2]*4, buffer[1]*4);
|
|
|
|
if (ret < 0) {
|
|
WindowPrompt(tr("ERROR:"), tr("Could not read the disc."), tr("OK"));
|
|
free(buffer);
|
|
free(fstbuffer);
|
|
return ret;
|
|
}
|
|
|
|
free(buffer);
|
|
|
|
WDVD_Reset();
|
|
//Disc_SetUSB(NULL);
|
|
WDVD_ClosePartition();
|
|
|
|
u32 discfilecount = fst[0].filelen;
|
|
u32 dolfilecount = 0;
|
|
//int offsetselect[20];
|
|
|
|
customOptionList options3(discfilecount);
|
|
|
|
for (u32 i = 0; i < discfilecount; i++) {
|
|
options3.SetName(i, "%i", i);
|
|
options3.SetValue(i, fstfiles(fst, i));
|
|
dolfilecount++;
|
|
}
|
|
|
|
if(dolfilecount <= 0) {
|
|
WindowPrompt(tr("ERROR"), tr("No dol file found on disc."), tr("OK"));
|
|
free(fstbuffer);
|
|
return -1;
|
|
}
|
|
|
|
GuiSound btnSoundOver(button_over_pcm, button_over_pcm_size, SOUND_PCM, Settings.sfxvolume);
|
|
GuiSound btnClick(button_click2_pcm, button_click2_pcm_size, SOUND_PCM, Settings.sfxvolume);
|
|
|
|
char imgPath[100];
|
|
|
|
snprintf(imgPath, sizeof(imgPath), "%sbutton_dialogue_box.png", CFG.theme_path);
|
|
GuiImageData btnOutline(imgPath, button_dialogue_box_png);
|
|
snprintf(imgPath, sizeof(imgPath), "%sgamesettings_background.png", CFG.theme_path);
|
|
GuiImageData settingsbg(imgPath, 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(get_title(header), 28, (GXColor){0, 0, 0, 255});
|
|
titleTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
|
titleTxt.SetPosition(12,40);
|
|
titleTxt.SetMaxWidth(356, GuiText::SCROLL);
|
|
|
|
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, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255});
|
|
cancelBtnTxt.SetMaxWidth(btnOutline.GetWidth()-30);
|
|
GuiImage cancelBtnImg(&btnOutline);
|
|
if (Settings.wsprompt == yes){
|
|
cancelBtnTxt.SetWidescreen(CFG.widescreen);
|
|
cancelBtnImg.SetWidescreen(CFG.widescreen);
|
|
}
|
|
GuiButton cancelBtn(&cancelBtnImg,&cancelBtnImg, 2, 3, 180, 400, &trigA, &btnSoundOver, &btnClick,1);
|
|
cancelBtn.SetScale(0.9);
|
|
cancelBtn.SetLabel(&cancelBtnTxt);
|
|
cancelBtn.SetTrigger(&trigB);
|
|
|
|
u8 scrollbaron = 0;
|
|
if(dolfilecount > 9)
|
|
scrollbaron = 1;
|
|
|
|
GuiCustomOptionBrowser optionBrowser3(396, 280, &options3, CFG.theme_path, "bg_options_gamesettings.png", bg_options_settings_png, scrollbaron, 200);
|
|
optionBrowser3.SetPosition(0, 90);
|
|
optionBrowser3.SetAlignment(ALIGN_CENTRE, 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)
|
|
{
|
|
VIDEO_WaitVSync();
|
|
|
|
if(shutdown == 1)
|
|
Sys_Shutdown();
|
|
if(reset == 1)
|
|
Sys_Reboot();
|
|
|
|
ret = optionBrowser3.GetClickedOption();
|
|
|
|
if(ret > 0) {
|
|
char temp[100];
|
|
strncpy(temp, fstfiles(fst, ret), sizeof(temp));
|
|
choice = WindowPrompt(temp, tr("Load this dol as alternate dol?"), tr("OK"), tr("Cancel"));
|
|
if(choice) {
|
|
//ret = offsetselect[ret];
|
|
snprintf(alternatedname, sizeof(alternatedname), "%s", temp);
|
|
exit = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (cancelBtn.GetState() == STATE_CLICKED)
|
|
{
|
|
exit = true;
|
|
ret = -1;
|
|
break;
|
|
}
|
|
}
|
|
|
|
HaltGui();
|
|
mainWindow->Remove(&w);
|
|
ResumeGui();
|
|
|
|
//free not needed list buffer anymore
|
|
free(fstbuffer);
|
|
|
|
return ret;
|
|
}
|