diff --git a/source/cheats/cheatmenu.cpp b/source/cheats/cheatmenu.cpp index 3c24548b..389eeaad 100644 --- a/source/cheats/cheatmenu.cpp +++ b/source/cheats/cheatmenu.cpp @@ -27,7 +27,6 @@ int CheatMenu(const char * gameID) { bool exit = false; int ret = 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]; @@ -35,25 +34,24 @@ int CheatMenu(const char * gameID) { GuiImageData btnOutline(imgPath, button_dialogue_box_png); snprintf(imgPath, sizeof(imgPath), "%ssettings_background.png", CFG.theme_path); GuiImageData settingsbg(imgPath, settings_background_png); - + GuiImage settingsbackground(&settingsbg); + GuiTrigger trigA; trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); GuiTrigger trigB; trigB.SetButtonOnlyTrigger(-1, WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B, PAD_BUTTON_B); - GuiImage settingsbackground(&settingsbg); - GuiText backBtnTxt(tr("Back") , 22, (GXColor) {THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); backBtnTxt.SetMaxWidth(btnOutline.GetWidth()-30); GuiImage backBtnImg(&btnOutline); - GuiButton backBtn(&backBtnImg,&backBtnImg, 2, 3, -140, 400, &trigA, &btnSoundOver, &btnClick,1); + GuiButton backBtn(&backBtnImg,&backBtnImg, 2, 3, -140, 400, &trigA, NULL, &btnClick,1); backBtn.SetLabel(&backBtnTxt); backBtn.SetTrigger(&trigB); GuiText createBtnTxt(tr("Create") , 22, (GXColor) {THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); createBtnTxt.SetMaxWidth(btnOutline.GetWidth()-30); GuiImage createBtnImg(&btnOutline); - GuiButton createBtn(&createBtnImg,&createBtnImg, 2, 3, 160, 400, &trigA, &btnSoundOver, &btnClick,1); + GuiButton createBtn(&createBtnImg,&createBtnImg, 2, 3, 160, 400, &trigA, NULL, &btnClick,1); createBtn.SetLabel(&createBtnTxt); char txtfilename[55]; @@ -63,8 +61,6 @@ int CheatMenu(const char * gameID) { int check = c.openTxtfile(txtfilename); int download =0; - //char tmp[10]; - switch (check) { case -1: @@ -72,9 +68,7 @@ int CheatMenu(const char * gameID) { break; case 0: download = WindowPrompt(tr("Error"),tr("No Cheatfile found"),tr("OK"),tr("Download Now")); - //snprintf(tmp, sizeof(tmp), "%i",download); - //WindowPrompt(0,tmp,tr("OK"),tr("Download Now")); if (download==0) download = CodeDownload(gameID); break; @@ -133,7 +127,6 @@ int CheatMenu(const char * gameID) { x++; } } - string chtpath = Settings.Cheatcodespath; string gctfname = chtpath + c.getGameID() + ".gct"; c.createGCT(selectednrs,x,gctfname.c_str()); @@ -141,7 +134,6 @@ int CheatMenu(const char * gameID) { exit = true; break; } else WindowPrompt(tr("Error"),tr("Could not create GCT file"),tr("OK")); - } if (backBtn.GetState() == STATE_CLICKED) { @@ -154,7 +146,6 @@ int CheatMenu(const char * gameID) { mainWindow->SetState(STATE_DEFAULT); mainWindow->Remove(&w); ResumeGui(); - break; } diff --git a/source/cheats/gct.cpp b/source/cheats/gct.cpp index e2186fda..7ac29f14 100644 --- a/source/cheats/gct.cpp +++ b/source/cheats/gct.cpp @@ -1,293 +1,218 @@ -#include -#include -#include "gct.h" - -#define OUTOFRANGE "Error:Range" - -GCTCheats::GCTCheats(void) { - iCntCheats = 0; -} - -GCTCheats::~GCTCheats(void) { -} - -int GCTCheats::getCnt() { - return iCntCheats; -} - -string GCTCheats::getGameName(void) { - return sGameTitle; -} - -string GCTCheats::getGameID(void) { - return sGameID; -} - -string GCTCheats::getCheat(int nr) { - if (nr <= (iCntCheats-1)) { - return sCheats[nr]; - } else { - return OUTOFRANGE;//"Error: CheatNr out of range"; - } -} - -string GCTCheats::getCheatName(int nr) { - if (nr <= (iCntCheats-1)) { - return sCheatName[nr]; - } else { - return "Error: CheatNr out of range"; - } -} - -string GCTCheats::getCheatComment(int nr) { - if (nr <= (iCntCheats-1)) { - return sCheatComment[nr]; - } else { - return "Error: CheatNr out of range"; - } -} - -int GCTCheats::createGCT(int nr,const char * filename) { - ofstream filestr; - filestr.open(filename); - - if (filestr.fail()) - return 0; - - //Reversed Header and Footer - char header[] = { 0x00, 0xd0, 0xc0, 0xde, 0x00, 0xd0, 0xc0, 0xde}; - char footer[] = { 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - - string buf = getCheat(nr); - filestr.write(header,sizeof(header)); - - int x = 0; - long int li; - int len = buf.size(); - - while (x < len) { - string temp = buf.substr(x,2); - li = strtol(temp.c_str(),NULL,16); - temp = li; - filestr.write(temp.c_str(),1); - x +=2; - } - filestr.write(footer,sizeof(footer)); - - filestr.close(); - return 1; -} - -int GCTCheats::createGCT(const char * chtbuffer,const char * filename) { - ofstream filestr; - filestr.open(filename); - - if (filestr.fail()) - return 0; - - //Reversed Header and Footer - char header[] = { 0x00, 0xd0, 0xc0, 0xde, 0x00, 0xd0, 0xc0, 0xde}; - char footer[] = { 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - - string buf = chtbuffer; - filestr.write(header,sizeof(header)); - - int x = 0; - long int li; - int len = buf.size(); - - while (x < len) { - string temp = buf.substr(x,2); - li = strtol(temp.c_str(),NULL,16); - temp = li; - filestr.write(temp.c_str(),1); - x +=2; - } - - filestr.write(footer,sizeof(footer)); - - filestr.close(); - - return 1; -} - -int GCTCheats::createGCT(int nr[],int cnt,const char * filename) { - - ofstream filestr; - filestr.open(filename); - - if (filestr.fail()) - return 0; - - //Reversed Header and Footer - char header[] = { 0x00, 0xd0, 0xc0, 0xde, 0x00, 0xd0, 0xc0, 0xde}; - char footer[] = { 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - - filestr.write(header,sizeof(header)); - - int c = 0; - while (c != cnt) { - int actnr = nr[c]; - string buf = getCheat(actnr); - long int li; - int len = buf.size(); - int x = 0; - - while (x < len) { - string temp = buf.substr(x,2); - li = strtol(temp.c_str(),NULL,16); - temp = li; - filestr.write(temp.c_str(),1); - x +=2; - } - c++; - } - - filestr.write(footer,sizeof(footer)); - filestr.close(); - return 1; -} - -int GCTCheats::openTxtfile(const char * filename) { - ifstream filestr; - int i = 0; - string str; - filestr.open(filename); - - if (filestr.fail()) - return 0; - - filestr.seekg(0,ios_base::end); - int size = filestr.tellg(); - if (size <= 0) return -1; - filestr.seekg(0,ios_base::beg); - - getline(filestr,sGameID); - getline(filestr,sGameTitle); - filestr.ignore(); - - while (!filestr.eof()) { - getline(filestr,sCheatName[i]); - string cheatdata; - bool emptyline = false; - bool isComment = false; - - do { - getline(filestr,str,'\n'); - //cheatdata.append(str); - - if (str == "") { - emptyline = true; - break; - } - - if (str.size() <= 16 || str.size() > 17 ) { - isComment = true; - printf ("%i",str.size()); - } - - if (!isComment) { - cheatdata.append(str); - size_t found=cheatdata.find(' '); - cheatdata.replace(found,1,""); - } else { - sCheatComment[i] = str; - } - - if (filestr.eof()) break; - } while (!emptyline); - - sCheats[i] = cheatdata; - i++; - } - iCntCheats = i; - filestr.close(); - return 1; -} - - -/*int GCTCheats::openTxtfile(const char * filename) -{ - ifstream filestr; - int i = 0; - string str; - filestr.open(filename); - - if (filestr.fail()) - return 0; - - filestr.seekg(0,ios_base::end); - int size = filestr.tellg(); - if (size <= 0) return -1; - filestr.seekg(0,ios_base::beg); - - getline(filestr,sGameID); - getline(filestr,sGameTitle); - filestr.ignore(); - - while(!filestr.eof()) - { - getline(filestr,sCheatName[i]); - string cheatdata; - bool emptyline = false; - - do - { - getline(filestr,str,'\n'); - cheatdata.append(str); - - if (str == "") - { - emptyline = true; - break; - } - - size_t found=cheatdata.find(' '); - cheatdata.replace(found,1,""); - - if (filestr.eof()) break; - } while(!emptyline); - - sCheats[i] = cheatdata; - i++; -} -iCntCheats = i; -filestr.close(); -return 1; -}*/ - -struct GCTCheats::chtentries GCTCheats::getCheatList(void) { - - struct GCTCheats::chtentries cheatlist; - int i = 0; - cheatlist.sGameID = sGameID; - cheatlist.sGameTitle = sGameTitle; - - while (i < iCntCheats) { - cheatlist.sCheatName[i] = sCheatName[i]; - cheatlist.sCheats[i] = sCheats[i]; - i++; - } - return cheatlist; -} - -struct GCTCheats::chtentries GCTCheats::getCheatList(const char * filename) { - openTxtfile(filename); - struct GCTCheats::chtentries cheatlist; - int i = 0; - cheatlist.sGameID = sGameID; - cheatlist.sGameTitle = sGameTitle; - cheatlist.iCntCheats = iCntCheats; - - while (i < iCntCheats) { - cheatlist.sCheatName[i] = sCheatName[i]; - cheatlist.sCheats[i] = sCheats[i]; - i++; - } - return cheatlist; -} - -int GCTCheats::download_txtcheat(int id) { -//ToDo - return 1; -} +/* + * gct.h + * Class to handle Ocarina TXT Cheatfiles + * nIxx + */ + +#include +#include +#include "gct.h" + +#define ERRORRANGE "Error: CheatNr out of range" + +GCTCheats::GCTCheats(void) { + iCntCheats = 0; +} + +GCTCheats::~GCTCheats(void) { + + string sGameID =""; + string sGameTitle = ""; + /*string sCheatName[MAXCHEATS]; + string sCheats[MAXCHEATS]; + string sCheatComment[MAXCHEATS];*/ +} + +int GCTCheats::getCnt() { + return iCntCheats; +} + +string GCTCheats::getGameName(void) { + return sGameTitle; +} + +string GCTCheats::getGameID(void) { + return sGameID; +} + +string GCTCheats::getCheat(int nr) { + if (nr <= (iCntCheats-1)) { + return sCheats[nr]; + } else { + return ERRORRANGE; + } +} + +string GCTCheats::getCheatName(int nr) { + if (nr <= (iCntCheats-1)) { + return sCheatName[nr]; + } else { + return ERRORRANGE; + } +} + +string GCTCheats::getCheatComment(int nr) { + if (nr <= (iCntCheats-1)) { + return sCheatComment[nr]; + } else { + return ERRORRANGE; + } +} + +int GCTCheats::createGCT(int nr,const char * filename) { + ofstream filestr; + filestr.open(filename); + + if (filestr.fail()) + return 0; + + //Header and Footer + char header[] = { 0x00, 0xd0, 0xc0, 0xde, 0x00, 0xd0, 0xc0, 0xde}; + char footer[] = { 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + + string buf = getCheat(nr); + filestr.write(header,sizeof(header)); + + int x = 0; + long int li; + int len = buf.size(); + + while (x < len) { + string temp = buf.substr(x,2); + li = strtol(temp.c_str(),NULL,16); + temp = li; + filestr.write(temp.c_str(),1); + x +=2; + } + filestr.write(footer,sizeof(footer)); + + filestr.close(); + return 1; +} + +int GCTCheats::createGCT(const char * chtbuffer,const char * filename) { + ofstream filestr; + filestr.open(filename); + + if (filestr.fail()) + return 0; + + //Header and Footer + char header[] = { 0x00, 0xd0, 0xc0, 0xde, 0x00, 0xd0, 0xc0, 0xde}; + char footer[] = { 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + + string buf = chtbuffer; + filestr.write(header,sizeof(header)); + + int x = 0; + long int li; + int len = buf.size(); + + while (x < len) { + string temp = buf.substr(x,2); + li = strtol(temp.c_str(),NULL,16); + temp = li; + filestr.write(temp.c_str(),1); + x +=2; + } + + filestr.write(footer,sizeof(footer)); + + filestr.close(); + + return 1; +} + +int GCTCheats::createGCT(int nr[],int cnt,const char * filename) { + + ofstream filestr; + filestr.open(filename); + + if (filestr.fail()) + return 0; + + //Header and Footer + char header[] = { 0x00, 0xd0, 0xc0, 0xde, 0x00, 0xd0, 0xc0, 0xde}; + char footer[] = { 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + + filestr.write(header,sizeof(header)); + + int c = 0; + while (c != cnt) { + int actnr = nr[c]; + string buf = getCheat(actnr); + long int li; + int len = buf.size(); + int x = 0; + + while (x < len) { + string temp = buf.substr(x,2); + li = strtol(temp.c_str(),NULL,16); + temp = li; + filestr.write(temp.c_str(),1); + x +=2; + } + c++; + } + + filestr.write(footer,sizeof(footer)); + filestr.close(); + return 1; +} + +int GCTCheats::openTxtfile(const char * filename) { + ifstream filestr; + int i = 0; + string str; + filestr.open(filename); + + if (filestr.fail()) + return 0; + + filestr.seekg(0,ios_base::end); + int size = filestr.tellg(); + if (size <= 0) return -1; + filestr.seekg(0,ios_base::beg); + + getline(filestr,sGameID); + getline(filestr,sGameTitle); + filestr.ignore(); + + while (!filestr.eof()) { + getline(filestr,sCheatName[i]); + string cheatdata; + bool emptyline = false; + bool isComment = false; + + do { + getline(filestr,str,'\n'); + //cheatdata.append(str); + + if (str == "") { + emptyline = true; + break; + } + + if (str.size() <= 16 || str.size() > 17 ) { + isComment = true; + printf ("%i",str.size()); + } + + if (!isComment) { + cheatdata.append(str); + size_t found=cheatdata.find(' '); + cheatdata.replace(found,1,""); + } else { + sCheatComment[i] = str; + } + + if (filestr.eof()) break; + } while (!emptyline); + + sCheats[i] = cheatdata; + i++; + } + iCntCheats = i; + filestr.close(); + return 1; +} diff --git a/source/cheats/gct.h b/source/cheats/gct.h index 6b2b2087..1e1055f1 100644 --- a/source/cheats/gct.h +++ b/source/cheats/gct.h @@ -1,103 +1,71 @@ -/* - * gct.h - * Class to handle Ocarina TXT Cheatfiles - * WIP: Actually itīs needed to call fatInitDefault() or the file will not be found - * and no Comments supported for now - */ - -#ifndef _GCT_H -#define _GCT_H - -#include - -#define MAXCHEATS 40 - -using namespace std; - -struct chtentrie { - string sGameID; - string sGameTitle; - string sCheatName[MAXCHEATS]; - string sCheats[MAXCHEATS]; - string sCheatComment[MAXCHEATS]; - int iCntCheats; -}; - -//!Handles Ocarina TXT Cheatfiles -class GCTCheats { -private: - chtentrie ccc; - string sGameID; - string sGameTitle; - string sCheatName[MAXCHEATS]; - string sCheats[MAXCHEATS]; - string sCheatComment[MAXCHEATS]; - int iCntCheats; - -public: - - struct chtentries { - string sGameID; - string sGameTitle; - string sCheatName[MAXCHEATS]; - string sCheats[MAXCHEATS]; - int iCntCheats; - }; - - //!Constructor - GCTCheats(void); - //!Destructor - ~GCTCheats(void); - //!Open txt file with cheats - //!\param filename name of TXT file - //!\return error code - int openTxtfile(const char * filename); - //!Creates GCT file for one cheat - //!\param nr selected Cheat Numbers - //!\param filename name of GCT file - //!\return error code - int createGCT(int nr,const char * filename); - //!Creates GCT file from a buffer - //!\param chtbuffer buffer that holds the cheat data - //!\param filename name of GCT file - //!\return error code - int createGCT(const char * chtbuffer,const char * filename); - //!Creates GCT file - //!\param nr[] array of selected Cheat Numbers - //!\param cnt size of array - //!\param filename name of GCT file - //!\return error code - int createGCT(int nr[],int cnt,const char * filename); - //!Gets Count cheats - //!\return Count cheats - int getCnt(); - //!Gets Game Name - //!\return Game Name - string getGameName(void); - //!Gets GameID - //!\return GameID - string getGameID(void); - //!Gets cheat data - //!\return cheat data - string getCheat(int nr); - //!Gets Cheat Name - //!\return Cheat Name - string getCheatName(int nr); - //!Gets Cheat Comment - //!\return Cheat Comment - string getCheatComment(int nr); - //!Gets Cheat List - //!\return struct chtentrie - //struct chtentrie getCheatList2(void); - //!Gets Cheat List - //!\return struct chtentries - struct chtentries getCheatList(void); - //!Gets Cheat List from file - //!\param filename name of TXT file - //!\return struct chtentries - struct chtentries getCheatList(const char * filename); - - int download_txtcheat(int id); -}; - -#endif /* _GCT_H */ +/* + * gct.h + * Class to handle Ocarina TXT Cheatfiles + * + */ + +#ifndef _GCT_H +#define _GCT_H + +#include + +#define MAXCHEATS 40 + +using namespace std; + +//!Handles Ocarina TXT Cheatfiles +class GCTCheats { +private: + string sGameID; + string sGameTitle; + string sCheatName[MAXCHEATS]; + string sCheats[MAXCHEATS]; + string sCheatComment[MAXCHEATS]; + int iCntCheats; + +public: + //!Constructor + GCTCheats(void); + //!Destructor + ~GCTCheats(void); + //!Open txt file with cheats + //!\param filename name of TXT file + //!\return error code + int openTxtfile(const char * filename); + //!Creates GCT file for one cheat + //!\param nr selected Cheat Numbers + //!\param filename name of GCT file + //!\return error code + int createGCT(int nr,const char * filename); + //!Creates GCT file from a buffer + //!\param chtbuffer buffer that holds the cheat data + //!\param filename name of GCT file + //!\return error code + int createGCT(const char * chtbuffer,const char * filename); + //!Creates GCT file + //!\param nr[] array of selected Cheat Numbers + //!\param cnt size of array + //!\param filename name of GCT file + //!\return error code + int createGCT(int nr[],int cnt,const char * filename); + //!Gets Count cheats + //!\return Count cheats + int getCnt(); + //!Gets Game Name + //!\return Game Name + string getGameName(void); + //!Gets GameID + //!\return GameID + string getGameID(void); + //!Gets cheat data + //!\return cheat data + string getCheat(int nr); + //!Gets Cheat Name + //!\return Cheat Name + string getCheatName(int nr); + //!Gets Cheat Comment + //!\return Cheat Comment + string getCheatComment(int nr); +}; + +#endif /* _GCT_H */ diff --git a/source/homebrewboot/BootHomebrew.c b/source/homebrewboot/BootHomebrew.c index ff6fcbb3..81f20be0 100644 --- a/source/homebrewboot/BootHomebrew.c +++ b/source/homebrewboot/BootHomebrew.c @@ -1,144 +1,144 @@ -#include -#include -#include -#include -#include -#include -#include -#include - -#include "fatmounter.h" -#include "dolloader.h" -#include "elfloader.h" - -void *innetbuffer = NULL; - -int AllocHomebrewMemory(u32 filesize) { - - innetbuffer = malloc(filesize); - - if (!innetbuffer) - return -1; - - return 1; - -} - -void FreeHomebrewBuffer() { - free(innetbuffer); - innetbuffer = NULL; -} - -void CopyHomebrewMemory(u32 read, u8 *temp, u32 len) { - - memcpy(((u8 *) innetbuffer)+read, temp, len); - -} - -int BootHomebrew(char * path) { - void *buffer = NULL; - u32 filesize = 0; - entrypoint entry; - u32 cpu_isr; - - FILE * file = fopen(path, "rb"); - if (!file) SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); - - fseek (file, 0, SEEK_END); - filesize = ftell(file); - rewind(file); - - buffer = malloc(filesize); - - if (fread (buffer, 1, filesize, file) != filesize) { - fclose (file); - free(buffer); - SDCard_deInit(); - USBDevice_deInit(); - SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); - } - fclose (file); - - struct __argv args; - bzero(&args, sizeof(args)); - args.argvMagic = ARGV_MAGIC; - args.length = strlen(path) + 2; - args.commandLine = (char*)malloc(args.length); - if (!args.commandLine) SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); - strcpy(args.commandLine, path); - args.commandLine[args.length - 1] = '\0'; - args.argc = 1; - args.argv = &args.commandLine; - args.endARGV = args.argv + 1; - - int ret = valid_elf_image(buffer); - if (ret == 1) - entry = (entrypoint) load_elf_image(buffer); - else - entry = (entrypoint) load_dol(buffer, &args); - - free(buffer); - - if (!entry) { - SDCard_deInit(); - USBDevice_deInit(); - SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); - } - - SDCard_deInit(); - USBDevice_deInit(); - - WPAD_Flush(0); - WPAD_Disconnect(0); - WPAD_Shutdown(); - - SYS_ResetSystem(SYS_SHUTDOWN, 0, 0); - _CPU_ISR_Disable (cpu_isr); - __exception_closeall(); - entry(); - _CPU_ISR_Restore (cpu_isr); - - return 0; -} - -int BootHomebrewFromMem() { - entrypoint entry; - u32 cpu_isr; - - if (!innetbuffer) { - SDCard_deInit(); - USBDevice_deInit(); - SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); - } - - struct __argv args; - - int ret = valid_elf_image(innetbuffer); - if (ret == 1) - entry = (entrypoint) load_elf_image(innetbuffer); - else - entry = (entrypoint) load_dol(innetbuffer, &args); - - free(innetbuffer); - - if (!entry) { - SDCard_deInit(); - USBDevice_deInit(); - SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); - } - - SDCard_deInit(); - USBDevice_deInit(); - - WPAD_Flush(0); - WPAD_Disconnect(0); - WPAD_Shutdown(); - - SYS_ResetSystem(SYS_SHUTDOWN, 0, 0); - _CPU_ISR_Disable (cpu_isr); - __exception_closeall(); - entry(); - _CPU_ISR_Restore (cpu_isr); - - return 0; -} +#include +#include +#include +#include +#include +#include +#include +#include + +#include "fatmounter.h" +#include "dolloader.h" +#include "elfloader.h" + +void *innetbuffer = NULL; + +int AllocHomebrewMemory(u32 filesize) { + + innetbuffer = malloc(filesize); + + if (!innetbuffer) + return -1; + + return 1; + +} + +void FreeHomebrewBuffer() { + free(innetbuffer); + innetbuffer = NULL; +} + +void CopyHomebrewMemory(u32 read, u8 *temp, u32 len) { + + memcpy(((u8 *) innetbuffer)+read, temp, len); + +} + +int BootHomebrew(char * path) { + void *buffer = NULL; + u32 filesize = 0; + entrypoint entry; + u32 cpu_isr; + + FILE * file = fopen(path, "rb"); + if (!file) SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); + + fseek (file, 0, SEEK_END); + filesize = ftell(file); + rewind(file); + + buffer = malloc(filesize); + + if (fread (buffer, 1, filesize, file) != filesize) { + fclose (file); + free(buffer); + SDCard_deInit(); + USBDevice_deInit(); + SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); + } + fclose (file); + + struct __argv args; + bzero(&args, sizeof(args)); + args.argvMagic = ARGV_MAGIC; + args.length = strlen(path) + 2; + args.commandLine = (char*)malloc(args.length); + if (!args.commandLine) SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); + strcpy(args.commandLine, path); + args.commandLine[args.length - 1] = '\0'; + args.argc = 1; + args.argv = &args.commandLine; + args.endARGV = args.argv + 1; + + int ret = valid_elf_image(buffer); + if (ret == 1) + entry = (entrypoint) load_elf_image(buffer); + else + entry = (entrypoint) load_dol(buffer, &args); + + free(buffer); + + if (!entry) { + SDCard_deInit(); + USBDevice_deInit(); + SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); + } + + SDCard_deInit(); + USBDevice_deInit(); + + WPAD_Flush(0); + WPAD_Disconnect(0); + WPAD_Shutdown(); + + SYS_ResetSystem(SYS_SHUTDOWN, 0, 0); + _CPU_ISR_Disable (cpu_isr); + __exception_closeall(); + entry(); + _CPU_ISR_Restore (cpu_isr); + + return 0; +} + +int BootHomebrewFromMem() { + entrypoint entry; + u32 cpu_isr; + + if (!innetbuffer) { + SDCard_deInit(); + USBDevice_deInit(); + SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); + } + + struct __argv args; + + int ret = valid_elf_image(innetbuffer); + if (ret == 1) + entry = (entrypoint) load_elf_image(innetbuffer); + else + entry = (entrypoint) load_dol(innetbuffer, &args); + + free(innetbuffer); + + if (!entry) { + SDCard_deInit(); + USBDevice_deInit(); + SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); + } + + SDCard_deInit(); + USBDevice_deInit(); + + WPAD_Flush(0); + WPAD_Disconnect(0); + WPAD_Shutdown(); + + SYS_ResetSystem(SYS_SHUTDOWN, 0, 0); + _CPU_ISR_Disable (cpu_isr); + __exception_closeall(); + entry(); + _CPU_ISR_Restore (cpu_isr); + + return 0; +} diff --git a/source/homebrewboot/HomebrewBrowse.cpp b/source/homebrewboot/HomebrewBrowse.cpp index ef7b13b0..d31cb593 100644 --- a/source/homebrewboot/HomebrewBrowse.cpp +++ b/source/homebrewboot/HomebrewBrowse.cpp @@ -322,7 +322,6 @@ int MenuHomebrewBrowse() { GuiWindow w(screenwidth, screenheight); - /*** XML Variables ***/ HomebrewXML XMLInfo[4]; diff --git a/source/network/URL_List.cpp b/source/network/URL_List.cpp index 76ffec8e..0f9cf83b 100644 --- a/source/network/URL_List.cpp +++ b/source/network/URL_List.cpp @@ -1,132 +1,132 @@ -/**************************************************************************** - * URL List Class - * for USB Loader GX - * by dimok - ***************************************************************************/ -#include -#include -#include -#include - -#include "URL_List.h" - - -URL_List::URL_List(const char * url) { - Links = NULL; - urlcount = 0; - - if (!IsNetworkInit()) { - urlcount = -1; - return; - } - - struct block file = downloadfile(url); - - if (!file.data || !file.size) { - urlcount = -2; - return; - } - - u32 cnt = 0; - char temp[1024]; - - Links = (Link_Info *) malloc(sizeof(Link_Info)); - if (!Links) { - free(file.data); - urlcount = -3; - return; - } - - memset(&Links[urlcount], 0, sizeof(Link_Info)); - - while (cnt < file.size) { - - if (file.data[cnt] == '"' && file.data[cnt-1] == '=' && file.data[cnt-2] == 'f' - && file.data[cnt-3] == 'e' && file.data[cnt-4] == 'r' && file.data[cnt-5] == 'h') { - - u32 cnt2 = 0; - cnt++; - while (file.data[cnt] != '"' && cnt2 < 1024) { - temp[cnt2] = file.data[cnt]; - cnt2++; - cnt++; - } - temp[cnt2] = '\0'; - - Links = (Link_Info *) realloc(Links, (urlcount+1)*sizeof(Link_Info)); - - if (!Links) { - for (int i = 0; i == urlcount; i++) { - delete Links[i].URL; - Links[i].URL = NULL; - } - free(Links); - Links = NULL; - free(file.data); - urlcount = -4; - break; - } - - memset(&(Links[urlcount]), 0, sizeof(Link_Info)); - - Links[urlcount].URL = new char[cnt2+1]; - - if (!Links[urlcount].URL) { - for (int i = 0; i == urlcount; i++) { - delete Links[i].URL; - Links[i].URL = NULL; - } - free(Links); - Links = NULL; - free(file.data); - urlcount = -5; - break; - } - - snprintf(Links[urlcount].URL, cnt2+1, "%s", temp); - - if (strncmp(Links[urlcount].URL, "http://", strlen("http://")) != 0) - Links[urlcount].direct = false; - else - Links[urlcount].direct = true; - - urlcount++; - } - cnt++; - } - - free(file.data); -} - -URL_List::~URL_List() { - for (int i = 0; i == urlcount; i++) { - delete Links[i].URL; - Links[i].URL = NULL; - } - - if (Links != NULL) { - free(Links); - Links = NULL; - } -} - -char * URL_List::GetURL(int ind) { - if (ind > urlcount || ind < 0 || !Links || urlcount <= 0) - return NULL; - else - return Links[ind].URL; -} - -int URL_List::GetURLCount() { - return urlcount; -} - -static int ListCompare(const void *a, const void *b) { - Link_Info *ab = (Link_Info*) a; - Link_Info *bb = (Link_Info*) b; - - return stricmp((char *) ab->URL, (char *) bb->URL); -} -void URL_List::SortList() { - qsort(Links, urlcount, sizeof(Link_Info), ListCompare); -} +/**************************************************************************** + * URL List Class + * for USB Loader GX + * by dimok + ***************************************************************************/ +#include +#include +#include +#include + +#include "URL_List.h" + + +URL_List::URL_List(const char * url) { + Links = NULL; + urlcount = 0; + + if (!IsNetworkInit()) { + urlcount = -1; + return; + } + + struct block file = downloadfile(url); + + if (!file.data || !file.size) { + urlcount = -2; + return; + } + + u32 cnt = 0; + char temp[1024]; + + Links = (Link_Info *) malloc(sizeof(Link_Info)); + if (!Links) { + free(file.data); + urlcount = -3; + return; + } + + memset(&Links[urlcount], 0, sizeof(Link_Info)); + + while (cnt < file.size) { + + if (file.data[cnt] == '"' && file.data[cnt-1] == '=' && file.data[cnt-2] == 'f' + && file.data[cnt-3] == 'e' && file.data[cnt-4] == 'r' && file.data[cnt-5] == 'h') { + + u32 cnt2 = 0; + cnt++; + while (file.data[cnt] != '"' && cnt2 < 1024) { + temp[cnt2] = file.data[cnt]; + cnt2++; + cnt++; + } + temp[cnt2] = '\0'; + + Links = (Link_Info *) realloc(Links, (urlcount+1)*sizeof(Link_Info)); + + if (!Links) { + for (int i = 0; i == urlcount; i++) { + delete Links[i].URL; + Links[i].URL = NULL; + } + free(Links); + Links = NULL; + free(file.data); + urlcount = -4; + break; + } + + memset(&(Links[urlcount]), 0, sizeof(Link_Info)); + + Links[urlcount].URL = new char[cnt2+1]; + + if (!Links[urlcount].URL) { + for (int i = 0; i == urlcount; i++) { + delete Links[i].URL; + Links[i].URL = NULL; + } + free(Links); + Links = NULL; + free(file.data); + urlcount = -5; + break; + } + + snprintf(Links[urlcount].URL, cnt2+1, "%s", temp); + + if (strncmp(Links[urlcount].URL, "http://", strlen("http://")) != 0) + Links[urlcount].direct = false; + else + Links[urlcount].direct = true; + + urlcount++; + } + cnt++; + } + + free(file.data); +} + +URL_List::~URL_List() { + for (int i = 0; i == urlcount; i++) { + delete Links[i].URL; + Links[i].URL = NULL; + } + + if (Links != NULL) { + free(Links); + Links = NULL; + } +} + +char * URL_List::GetURL(int ind) { + if (ind > urlcount || ind < 0 || !Links || urlcount <= 0) + return NULL; + else + return Links[ind].URL; +} + +int URL_List::GetURLCount() { + return urlcount; +} + +static int ListCompare(const void *a, const void *b) { + Link_Info *ab = (Link_Info*) a; + Link_Info *bb = (Link_Info*) b; + + return stricmp((char *) ab->URL, (char *) bb->URL); +} +void URL_List::SortList() { + qsort(Links, urlcount, sizeof(Link_Info), ListCompare); +} diff --git a/source/patches/dvd_broadway.c b/source/patches/dvd_broadway.c index ee7d2aa9..d919de43 100644 --- a/source/patches/dvd_broadway.c +++ b/source/patches/dvd_broadway.c @@ -1,583 +1,583 @@ -/* - * Copyright (C) 2008 Nuke (wiinuke@gmail.com) - * - * this file is part of GeckoOS for USB Gecko - * http://www.usbgecko.com - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "dvd_broadway.h" - -#define DI_CMDCTX_CNT 4 - -#define DVD_DISKIDSIZE 0x20 -#define DVD_DRVINFSIZE 0x20 - -#define IOCTL_DI_INQUIRY 0x12 -#define IOCTL_DI_READID 0x70 -#define IOCTL_DI_READ 0x71 -#define IOCTL_DI_WAITCVRCLOSE 0x79 -#define IOCTL_DI_COVER 0x7A -#define IOCTL_DI_RESETNOTIFY 0x7E -#define IOCTL_DI_RESET 0x8A -#define IOCTL_DI_OPENPART 0x8B -#define IOCTL_DI_CLOSEPART 0x8C -#define IOCTL_DI_UNENCREAD 0x8D -#define IOCTL_DI_ENABLE_DVD 0x8E -#define IOCTL_DI_SEEK 0xAB -#define IOCTL_DI_READ_DVDVIDEO 0xD0 -#define IOCTL_DI_STOPLASER 0xD2 -#define IOCTL_DI_OFFSET 0xD9 -#define IOCTL_DI_REQERROR 0xE0 -#define IOCTL_DI_STOPMOTOR 0xE3 -#define IOCTL_DI_SETOFFBASE 0xF0 -#define IOCTL_DI_GETOFFBASE 0xF1 -#define IOCTL_DI_SETCRYPTMODE 0xF2 -#define IOCTL_DI_GETCRYPTMODE 0xF3 -#define IOCTL_DI_SETDVDROMMODE 0xF4 -#define IOCTL_DI_GETDVDROMMODE 0xF5 - -#define _SHIFTL(v, s, w) \ - ((u32) (((u32)(v) & ((0x01 << (w)) - 1)) << (s))) -#define _SHIFTR(v, s, w) \ - ((u32)(((u32)(v) >> (s)) & ((0x01 << (w)) - 1))) - -struct dicommand { - u32 diReg[8]; -}; - -struct dicontext { - lwp_node node; - dvdcallbacklow cb; - struct dicommand *cmd; -}; - -static s32 __dvd_fd = -1; -static u32 __dvd_spinupval = 1; -static lwp_queue __di_contextq; -static u32 __dvd_readlength = 0; -static u32 __dvd_cbinprogress = 0; -static u32 __dvd_reqinprogress = 0; -static u32 __dvd_lowinitcalled = 0; -static struct dicommand *__di_commands = NULL; -static struct dicontext __di_contexts[DI_CMDCTX_CNT]; -static u32 __di_regbuffer[0x08] ATTRIBUTE_ALIGN(32); -static u32 __di_regvalcache[0x08] ATTRIBUTE_ALIGN(32); -static u32 __di_lastticketerror[0x08] ATTRIBUTE_ALIGN(32); -static ioctlv __di_iovector[0x08] ATTRIBUTE_ALIGN(32); -static char __di_fs[] ATTRIBUTE_ALIGN(32) = "/dev/di"; - -extern u32 __IPC_ClntInit(); - -static __inline__ lwp_node* __lwp_queue_head(lwp_queue *queue) { - return (lwp_node*)queue; -} - -static __inline__ lwp_node* __lwp_queue_tail(lwp_queue *queue) { - return (lwp_node*)&queue->perm_null; -} - - -static __inline__ void __lwp_queue_init_empty(lwp_queue *queue) { - queue->first = __lwp_queue_tail(queue); - queue->perm_null = NULL; - queue->last = __lwp_queue_head(queue); -} - -static struct dicontext* __dvd_getcontext(dvdcallbacklow cb) { - struct dicontext *ctx; - - ctx = (struct dicontext*)__lwp_queue_get(&__di_contextq); - if (ctx!=NULL) ctx->cb = cb; - - return ctx; -} - -static s32 __dvd_iostransactionCB(s32 result,void *usrdata) { - struct dicontext *ctx = (struct dicontext*)usrdata; - - __dvd_reqinprogress = 0; - - if (ctx->cb!=NULL) { - __dvd_cbinprogress = 1; - if (result!=0) __dvd_readlength = 0; - ctx->cb(result); - __dvd_cbinprogress = 0; - } - __lwp_queue_append(&__di_contextq,&ctx->node); - - return 0; -} - -static s32 __dvd_ioscoverregisterCB(s32 result,void *usrdata) { - struct dicontext *ctx = (struct dicontext*)usrdata; - - __dvd_reqinprogress = 0; - __di_regvalcache[1] = __di_regbuffer[0]; - - if (ctx->cb!=NULL) { - __dvd_cbinprogress = 1; - ctx->cb(result); - __dvd_cbinprogress = 0; - } - __lwp_queue_append(&__di_contextq,&ctx->node); - - return 0; -} - -static s32 __dvd_ioscovercloseCB(s32 result,void *usrdata) { - struct dicontext *ctx = (struct dicontext*)usrdata; - - __dvd_reqinprogress = 0; - - if (ctx->cb!=NULL) { - __dvd_cbinprogress = 1; - ctx->cb(result); - __dvd_cbinprogress = 0; - } - __lwp_queue_append(&__di_contextq,&ctx->node); - - return 0; -} - -s32 bwDVD_LowInit() { - s32 i,ret = 0; - u32 ipclo,ipchi; - lwp_queue inactives; - struct dicontext *ctx; - - if (__dvd_lowinitcalled==0) { - ret = __IPC_ClntInit(); - if (ret<0) return ret; - - ipclo = (((u32)IPC_GetBufferLo()+0x1f)&~0x1f); - ipchi = (u32)IPC_GetBufferHi(); - if (ipchi>=(ipclo+(sizeof(struct dicommand)*DI_CMDCTX_CNT))) { - __di_commands = (struct dicommand*)ipclo; - IPC_SetBufferLo((void*)(ipclo+(sizeof(struct dicommand)*DI_CMDCTX_CNT))); - - memset(__di_commands,0,(sizeof(struct dicommand)*DI_CMDCTX_CNT)); - - i = 0; - __lwp_queue_init_empty(&__di_contextq); - __lwp_queue_initialize(&inactives,__di_contexts,DI_CMDCTX_CNT,sizeof(struct dicontext)); - while ((ctx=(struct dicontext*)__lwp_queue_get(&inactives))!=NULL) { - ctx->cmd = &__di_commands[i]; - ctx->cb = NULL; - __lwp_queue_append(&__di_contextq,&ctx->node); - - i++; - } - } - - ret = IOS_Open(__di_fs,0); - if (ret<0) return ret; - - __dvd_fd = ret; -// __dvd_lowinitcalled = 1; - - // printf("DVD_LowInit(%d)\n",ret); - } - return 0; -} - -s32 bwDVD_LowInquiry(dvddrvinfo *info,dvdcallbacklow cb) { - s32 ret; - struct dicontext *ctx; - struct dicommand *cmd; - - __dvd_reqinprogress = 1; - - ctx = __dvd_getcontext(cb); - if (ctx==NULL) return IPC_ENOMEM; - - cmd = ctx->cmd; - cmd->diReg[0] = (IOCTL_DI_INQUIRY<<24); - ret = IOS_IoctlAsync(__dvd_fd,IOCTL_DI_INQUIRY,cmd->diReg,sizeof(struct dicommand),info,DVD_DRVINFSIZE,__dvd_iostransactionCB,ctx); - - return ret; -} - -s32 bwDVD_LowReadID(dvddiskid *diskID,dvdcallbacklow cb) { - s32 ret = 0; - struct dicontext *ctx; - struct dicommand *cmd; - -// printf("DVD_LowReadID()\n"); - - __dvd_reqinprogress = 1; - - ctx = __dvd_getcontext(cb); - if (ctx==NULL) return IPC_ENOMEM; - - cmd = ctx->cmd; - cmd->diReg[0] = (IOCTL_DI_READID<<24); - ret = IOS_IoctlAsync(__dvd_fd,IOCTL_DI_READID,cmd->diReg,sizeof(struct dicommand),diskID,DVD_DISKIDSIZE,__dvd_iostransactionCB,ctx); - -// printf("DVD_LowReadID(%d)\n",ret); - return ret; -} - - -s32 bwDVD_LowRead(void *buf,u32 len,u32 offset,dvdcallbacklow cb) { - s32 ret; - struct dicontext *ctx; - struct dicommand *cmd; - - if (buf==NULL || ((u32)buf%32)!=0) return -1; - - __dvd_reqinprogress = 1; - __dvd_readlength = len; - - ctx = __dvd_getcontext(cb); - if (ctx==NULL) return IPC_ENOMEM; - - cmd = ctx->cmd; - cmd->diReg[0] = (IOCTL_DI_READ<<24); - cmd->diReg[1] = len; - cmd->diReg[2] = offset; - ret = IOS_IoctlAsync(__dvd_fd,IOCTL_DI_READ,cmd->diReg,sizeof(struct dicommand),buf,len,__dvd_iostransactionCB,ctx); - - return ret; -} - -// never got this function working, probably removed from wii -s32 bwDVD_LowReadVideo(void *buf,u32 len,u32 offset,dvdcallbacklow cb) { - s32 ret; - struct dicontext *ctx; - struct dicommand *cmd; - - __dvd_reqinprogress = 1; - __dvd_readlength = len; - - ctx = __dvd_getcontext(cb); - if (ctx==NULL) return IPC_ENOMEM; - - cmd = ctx->cmd; - cmd->diReg[0] = (IOCTL_DI_READ_DVDVIDEO<<24); - cmd->diReg[1] = len; - cmd->diReg[2] = offset; - ret = IOS_IoctlAsync(__dvd_fd,IOCTL_DI_READ_DVDVIDEO,cmd->diReg,sizeof(struct dicommand),buf,len,__dvd_iostransactionCB,ctx); - - return ret; -} - - - -s32 bwDVD_LowStopLaser(dvdcallbacklow cb) { - s32 ret; - struct dicontext *ctx; - struct dicommand *cmd; - - __dvd_reqinprogress = 1; - - ctx = __dvd_getcontext(cb); - if (ctx==NULL) return IPC_ENOMEM; - - cmd = ctx->cmd; - cmd->diReg[0] = (IOCTL_DI_STOPLASER<<24); - ret = IOS_IoctlAsync(__dvd_fd,IOCTL_DI_STOPLASER,cmd->diReg,sizeof(struct dicommand),__di_regvalcache,0x20,__dvd_iostransactionCB,ctx); - - return ret; -} - -// never got this function working, probably removed from wii -s32 bwDVD_EnableVideo(dvdcallbacklow cb) { - s32 ret; - struct dicontext *ctx; - struct dicommand *cmd; - - __dvd_reqinprogress = 1; - - ctx = __dvd_getcontext(cb); - if (ctx==NULL) return IPC_ENOMEM; - - cmd = ctx->cmd; - cmd->diReg[0] = (IOCTL_DI_ENABLE_DVD<<24); - ret = IOS_IoctlAsync(__dvd_fd,IOCTL_DI_ENABLE_DVD,cmd->diReg,sizeof(struct dicommand),__di_regvalcache,0x20,__dvd_iostransactionCB,ctx); - - return ret; -} - -s32 bwDVD_LowSeek(u32 offset,dvdcallbacklow cb) { - s32 ret; - struct dicontext *ctx; - struct dicommand *cmd; - - __dvd_reqinprogress = 1; - - ctx = __dvd_getcontext(cb); - if (ctx==NULL) return IPC_ENOMEM; - - cmd = ctx->cmd; - cmd->diReg[0] = (IOCTL_DI_SEEK<<24); - cmd->diReg[1] = offset; - ret = IOS_IoctlAsync(__dvd_fd,IOCTL_DI_SEEK,cmd->diReg,sizeof(struct dicommand),NULL,0,__dvd_iostransactionCB,ctx); - - return ret; -} - -s32 bwDVD_LowOffset(u64 offset,dvdcallbacklow cb) { - s32 ret; - u32 *off = (u32*)(void*)(&offset); - struct dicontext *ctx; - struct dicommand *cmd; - - __dvd_reqinprogress = 1; - - ctx = __dvd_getcontext(cb); - if (ctx==NULL) return IPC_ENOMEM; - - cmd = ctx->cmd; - cmd->diReg[0] = (IOCTL_DI_OFFSET<<24); - cmd->diReg[1] = 0; - if (off[0]) cmd->diReg[1] = 1; - cmd->diReg[2] = off[1]; - ret = IOS_IoctlAsync(__dvd_fd,IOCTL_DI_OFFSET,cmd->diReg,sizeof(struct dicommand),__di_regvalcache,0x20,__dvd_iostransactionCB,ctx); - - return ret; -} - -s32 bwDVD_LowPrepareCoverRegister(dvdcallbacklow cb) { - s32 ret; - struct dicontext *ctx; - struct dicommand *cmd; - - __dvd_reqinprogress = 1; - - ctx = __dvd_getcontext(cb); - if (ctx==NULL) return IPC_ENOMEM; - - cmd = ctx->cmd; - cmd->diReg[0] = (IOCTL_DI_COVER<<24); - ret = IOS_IoctlAsync(__dvd_fd,IOCTL_DI_COVER,cmd->diReg,sizeof(struct dicommand),__di_regbuffer,0x20,__dvd_ioscoverregisterCB,ctx); - - return ret; -} - -s32 bwDVD_LowOpenPartition(u32 offset,void *eticket,u32 certin_len,void *certificate_in,void *certificate_out,dvdcallbacklow cb) { - s32 ret; - struct dicontext *ctx; - struct dicommand *cmd; - - if (eticket!=NULL && ((u32)eticket%32)!=0) return -1; - if (certificate_in!=NULL && ((u32)certificate_in%32)!=0) return -1; - if (certificate_out!=NULL && ((u32)certificate_out%32)!=0) return -1; - - __dvd_reqinprogress = 1; - - ctx = __dvd_getcontext(cb); - if (ctx==NULL) return IPC_ENOMEM; - - cmd = ctx->cmd; - cmd->diReg[0] = (IOCTL_DI_OPENPART<<24); - cmd->diReg[1] = offset; - - __di_iovector[0].data = cmd; - __di_iovector[0].len = sizeof(struct dicommand); - - __di_iovector[1].data = eticket; - if (eticket==NULL) __di_iovector[1].len = 0; - else __di_iovector[1].len = 676; - - __di_iovector[2].data = certificate_in; - if (certificate_in==NULL) __di_iovector[2].len = 0; - else __di_iovector[2].len = certin_len; - - __di_iovector[3].data = certificate_out; - __di_iovector[3].len = 18916; - __di_iovector[4].data = __di_lastticketerror; - __di_iovector[4].len = 0x20; - ret = IOS_IoctlvAsync(__dvd_fd,IOCTL_DI_OPENPART,3,2,__di_iovector,__dvd_iostransactionCB,ctx); - - return ret; -} - -s32 bwDVD_LowClosePartition(dvdcallbacklow cb) { - s32 ret; - struct dicontext *ctx; - struct dicommand *cmd; - - __dvd_reqinprogress = 1; - - ctx = __dvd_getcontext(cb); - if (ctx==NULL) return IPC_ENOMEM; - - cmd = ctx->cmd; - cmd->diReg[0] = (IOCTL_DI_CLOSEPART<<24); - ret = IOS_IoctlAsync(__dvd_fd,IOCTL_DI_CLOSEPART,cmd->diReg,sizeof(struct dicommand),NULL,0,__dvd_iostransactionCB,ctx); - - return ret; -} - -s32 bwDVD_LowUnencryptedRead(void *buf,u32 len,u32 offset,dvdcallbacklow cb) { - s32 ret; - struct dicontext *ctx; - struct dicommand *cmd; - - __dvd_reqinprogress = 1; - __dvd_readlength = len; - - ctx = __dvd_getcontext(cb); - if (ctx==NULL) return IPC_ENOMEM; - - cmd = ctx->cmd; - cmd->diReg[0] = (IOCTL_DI_UNENCREAD<<24); - cmd->diReg[1] = len; - cmd->diReg[2] = offset; - ret = IOS_IoctlAsync(__dvd_fd,IOCTL_DI_UNENCREAD,cmd->diReg,sizeof(struct dicommand),buf,len,__dvd_iostransactionCB,ctx); - - return ret; -} - -s32 bwDVD_LowWaitCoverClose(dvdcallbacklow cb) { - s32 ret; - struct dicontext *ctx; - struct dicommand *cmd; - - __dvd_reqinprogress = 1; - - ctx = __dvd_getcontext(cb); - if (ctx==NULL) return IPC_ENOMEM; - - cmd = ctx->cmd; - cmd->diReg[0] = (IOCTL_DI_WAITCVRCLOSE<<24); - ret = IOS_IoctlAsync(__dvd_fd,IOCTL_DI_WAITCVRCLOSE,cmd->diReg,sizeof(struct dicommand),NULL,0,__dvd_ioscovercloseCB,ctx); - - return ret; -} - -s32 bwDVD_LowResetNotify() { - s32 ret; - struct dicontext *ctx; - struct dicommand *cmd; - - if (__dvd_cbinprogress==1) return -1; - - ctx = __dvd_getcontext(NULL); - if (ctx==NULL) return IPC_ENOMEM; - - cmd = ctx->cmd; - cmd->diReg[0] = (IOCTL_DI_RESETNOTIFY<<24); - ret = IOS_Ioctl(__dvd_fd,IOCTL_DI_RESETNOTIFY,cmd->diReg,sizeof(struct dicommand),NULL,0); - - return ret; -} - -s32 bwDVD_LowReset(dvdcallbacklow cb) { - s32 ret; - struct dicontext *ctx; - struct dicommand *cmd; - -// printf("DVD_LowReset()\n"); - __dvd_reqinprogress = 1; - - ctx = __dvd_getcontext(cb); - if (ctx==NULL) return IPC_ENOMEM; - - cmd = ctx->cmd; - cmd->diReg[0] = (IOCTL_DI_RESET<<24); - cmd->diReg[1] = __dvd_spinupval; - ret = IOS_IoctlAsync(__dvd_fd,IOCTL_DI_RESET,cmd->diReg,sizeof(struct dicommand),NULL,0,__dvd_iostransactionCB,ctx); - -// printf("DVD_LowReset(%d)\n",ret); - return ret; -} - -s32 bwDVD_LowStopMotor(u8 stop1,u8 stop2,dvdcallbacklow cb) { - s32 ret; - struct dicontext *ctx; - struct dicommand *cmd; - - __dvd_reqinprogress = 1; - - ctx = __dvd_getcontext(cb); - if (ctx==NULL) return IPC_ENOMEM; - - cmd = ctx->cmd; - cmd->diReg[0] = (IOCTL_DI_STOPMOTOR<<24); - cmd->diReg[1] = (stop1<<24); - cmd->diReg[2] = (stop2<<24); - ret = IOS_IoctlAsync(__dvd_fd,IOCTL_DI_STOPMOTOR,cmd->diReg,sizeof(struct dicommand),__di_regvalcache,0x20,__dvd_iostransactionCB,ctx); - - return ret; - -} - -s32 bwDVD_LowRequestError(dvdcallbacklow cb) { - s32 ret; - struct dicontext *ctx; - struct dicommand *cmd; - - __dvd_reqinprogress = 1; - - ctx = __dvd_getcontext(cb); - if (ctx==NULL) return IPC_ENOMEM; - - cmd = ctx->cmd; - cmd->diReg[0] = (IOCTL_DI_REQERROR<<24); - ret = IOS_IoctlAsync(__dvd_fd,IOCTL_DI_REQERROR,cmd->diReg,sizeof(struct dicommand),__di_regvalcache,0x20,__dvd_iostransactionCB,ctx); - - return ret; -} - - -s32 bwDVD_SetDecryption(s32 mode, dvdcallbacklow cb) { - s32 ret; - struct dicontext *ctx; - struct dicommand *cmd; - - __dvd_reqinprogress = 1; - - ctx = __dvd_getcontext(cb); - if (ctx==NULL) return IPC_ENOMEM; - - cmd = ctx->cmd; - cmd->diReg[0] = (IOCTL_DI_SETCRYPTMODE<<24); - cmd->diReg[1] = mode; - ret = IOS_IoctlAsync(__dvd_fd,IOCTL_DI_SETCRYPTMODE,cmd->diReg,sizeof(struct dicommand),__di_regvalcache,0x20,__dvd_iostransactionCB,ctx); - - return ret; - -} - -s32 bwDVD_SetOffset(u32 offset, dvdcallbacklow cb) { - s32 ret; - struct dicontext *ctx; - struct dicommand *cmd; - - __dvd_reqinprogress = 1; - - ctx = __dvd_getcontext(cb); - if (ctx==NULL) return IPC_ENOMEM; - - cmd = ctx->cmd; - cmd->diReg[0] = (IOCTL_DI_SETOFFBASE<<24); - cmd->diReg[1] = offset; - ret = IOS_IoctlAsync(__dvd_fd,IOCTL_DI_SETOFFBASE,cmd->diReg,sizeof(struct dicommand),__di_regvalcache,0x20,__dvd_iostransactionCB,ctx); - - return ret; - -} +/* + * Copyright (C) 2008 Nuke (wiinuke@gmail.com) + * + * this file is part of GeckoOS for USB Gecko + * http://www.usbgecko.com + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "dvd_broadway.h" + +#define DI_CMDCTX_CNT 4 + +#define DVD_DISKIDSIZE 0x20 +#define DVD_DRVINFSIZE 0x20 + +#define IOCTL_DI_INQUIRY 0x12 +#define IOCTL_DI_READID 0x70 +#define IOCTL_DI_READ 0x71 +#define IOCTL_DI_WAITCVRCLOSE 0x79 +#define IOCTL_DI_COVER 0x7A +#define IOCTL_DI_RESETNOTIFY 0x7E +#define IOCTL_DI_RESET 0x8A +#define IOCTL_DI_OPENPART 0x8B +#define IOCTL_DI_CLOSEPART 0x8C +#define IOCTL_DI_UNENCREAD 0x8D +#define IOCTL_DI_ENABLE_DVD 0x8E +#define IOCTL_DI_SEEK 0xAB +#define IOCTL_DI_READ_DVDVIDEO 0xD0 +#define IOCTL_DI_STOPLASER 0xD2 +#define IOCTL_DI_OFFSET 0xD9 +#define IOCTL_DI_REQERROR 0xE0 +#define IOCTL_DI_STOPMOTOR 0xE3 +#define IOCTL_DI_SETOFFBASE 0xF0 +#define IOCTL_DI_GETOFFBASE 0xF1 +#define IOCTL_DI_SETCRYPTMODE 0xF2 +#define IOCTL_DI_GETCRYPTMODE 0xF3 +#define IOCTL_DI_SETDVDROMMODE 0xF4 +#define IOCTL_DI_GETDVDROMMODE 0xF5 + +#define _SHIFTL(v, s, w) \ + ((u32) (((u32)(v) & ((0x01 << (w)) - 1)) << (s))) +#define _SHIFTR(v, s, w) \ + ((u32)(((u32)(v) >> (s)) & ((0x01 << (w)) - 1))) + +struct dicommand { + u32 diReg[8]; +}; + +struct dicontext { + lwp_node node; + dvdcallbacklow cb; + struct dicommand *cmd; +}; + +static s32 __dvd_fd = -1; +static u32 __dvd_spinupval = 1; +static lwp_queue __di_contextq; +static u32 __dvd_readlength = 0; +static u32 __dvd_cbinprogress = 0; +static u32 __dvd_reqinprogress = 0; +static u32 __dvd_lowinitcalled = 0; +static struct dicommand *__di_commands = NULL; +static struct dicontext __di_contexts[DI_CMDCTX_CNT]; +static u32 __di_regbuffer[0x08] ATTRIBUTE_ALIGN(32); +static u32 __di_regvalcache[0x08] ATTRIBUTE_ALIGN(32); +static u32 __di_lastticketerror[0x08] ATTRIBUTE_ALIGN(32); +static ioctlv __di_iovector[0x08] ATTRIBUTE_ALIGN(32); +static char __di_fs[] ATTRIBUTE_ALIGN(32) = "/dev/di"; + +extern u32 __IPC_ClntInit(); + +static __inline__ lwp_node* __lwp_queue_head(lwp_queue *queue) { + return (lwp_node*)queue; +} + +static __inline__ lwp_node* __lwp_queue_tail(lwp_queue *queue) { + return (lwp_node*)&queue->perm_null; +} + + +static __inline__ void __lwp_queue_init_empty(lwp_queue *queue) { + queue->first = __lwp_queue_tail(queue); + queue->perm_null = NULL; + queue->last = __lwp_queue_head(queue); +} + +static struct dicontext* __dvd_getcontext(dvdcallbacklow cb) { + struct dicontext *ctx; + + ctx = (struct dicontext*)__lwp_queue_get(&__di_contextq); + if (ctx!=NULL) ctx->cb = cb; + + return ctx; +} + +static s32 __dvd_iostransactionCB(s32 result,void *usrdata) { + struct dicontext *ctx = (struct dicontext*)usrdata; + + __dvd_reqinprogress = 0; + + if (ctx->cb!=NULL) { + __dvd_cbinprogress = 1; + if (result!=0) __dvd_readlength = 0; + ctx->cb(result); + __dvd_cbinprogress = 0; + } + __lwp_queue_append(&__di_contextq,&ctx->node); + + return 0; +} + +static s32 __dvd_ioscoverregisterCB(s32 result,void *usrdata) { + struct dicontext *ctx = (struct dicontext*)usrdata; + + __dvd_reqinprogress = 0; + __di_regvalcache[1] = __di_regbuffer[0]; + + if (ctx->cb!=NULL) { + __dvd_cbinprogress = 1; + ctx->cb(result); + __dvd_cbinprogress = 0; + } + __lwp_queue_append(&__di_contextq,&ctx->node); + + return 0; +} + +static s32 __dvd_ioscovercloseCB(s32 result,void *usrdata) { + struct dicontext *ctx = (struct dicontext*)usrdata; + + __dvd_reqinprogress = 0; + + if (ctx->cb!=NULL) { + __dvd_cbinprogress = 1; + ctx->cb(result); + __dvd_cbinprogress = 0; + } + __lwp_queue_append(&__di_contextq,&ctx->node); + + return 0; +} + +s32 bwDVD_LowInit() { + s32 i,ret = 0; + u32 ipclo,ipchi; + lwp_queue inactives; + struct dicontext *ctx; + + if (__dvd_lowinitcalled==0) { + ret = __IPC_ClntInit(); + if (ret<0) return ret; + + ipclo = (((u32)IPC_GetBufferLo()+0x1f)&~0x1f); + ipchi = (u32)IPC_GetBufferHi(); + if (ipchi>=(ipclo+(sizeof(struct dicommand)*DI_CMDCTX_CNT))) { + __di_commands = (struct dicommand*)ipclo; + IPC_SetBufferLo((void*)(ipclo+(sizeof(struct dicommand)*DI_CMDCTX_CNT))); + + memset(__di_commands,0,(sizeof(struct dicommand)*DI_CMDCTX_CNT)); + + i = 0; + __lwp_queue_init_empty(&__di_contextq); + __lwp_queue_initialize(&inactives,__di_contexts,DI_CMDCTX_CNT,sizeof(struct dicontext)); + while ((ctx=(struct dicontext*)__lwp_queue_get(&inactives))!=NULL) { + ctx->cmd = &__di_commands[i]; + ctx->cb = NULL; + __lwp_queue_append(&__di_contextq,&ctx->node); + + i++; + } + } + + ret = IOS_Open(__di_fs,0); + if (ret<0) return ret; + + __dvd_fd = ret; +// __dvd_lowinitcalled = 1; + + // printf("DVD_LowInit(%d)\n",ret); + } + return 0; +} + +s32 bwDVD_LowInquiry(dvddrvinfo *info,dvdcallbacklow cb) { + s32 ret; + struct dicontext *ctx; + struct dicommand *cmd; + + __dvd_reqinprogress = 1; + + ctx = __dvd_getcontext(cb); + if (ctx==NULL) return IPC_ENOMEM; + + cmd = ctx->cmd; + cmd->diReg[0] = (IOCTL_DI_INQUIRY<<24); + ret = IOS_IoctlAsync(__dvd_fd,IOCTL_DI_INQUIRY,cmd->diReg,sizeof(struct dicommand),info,DVD_DRVINFSIZE,__dvd_iostransactionCB,ctx); + + return ret; +} + +s32 bwDVD_LowReadID(dvddiskid *diskID,dvdcallbacklow cb) { + s32 ret = 0; + struct dicontext *ctx; + struct dicommand *cmd; + +// printf("DVD_LowReadID()\n"); + + __dvd_reqinprogress = 1; + + ctx = __dvd_getcontext(cb); + if (ctx==NULL) return IPC_ENOMEM; + + cmd = ctx->cmd; + cmd->diReg[0] = (IOCTL_DI_READID<<24); + ret = IOS_IoctlAsync(__dvd_fd,IOCTL_DI_READID,cmd->diReg,sizeof(struct dicommand),diskID,DVD_DISKIDSIZE,__dvd_iostransactionCB,ctx); + +// printf("DVD_LowReadID(%d)\n",ret); + return ret; +} + + +s32 bwDVD_LowRead(void *buf,u32 len,u32 offset,dvdcallbacklow cb) { + s32 ret; + struct dicontext *ctx; + struct dicommand *cmd; + + if (buf==NULL || ((u32)buf%32)!=0) return -1; + + __dvd_reqinprogress = 1; + __dvd_readlength = len; + + ctx = __dvd_getcontext(cb); + if (ctx==NULL) return IPC_ENOMEM; + + cmd = ctx->cmd; + cmd->diReg[0] = (IOCTL_DI_READ<<24); + cmd->diReg[1] = len; + cmd->diReg[2] = offset; + ret = IOS_IoctlAsync(__dvd_fd,IOCTL_DI_READ,cmd->diReg,sizeof(struct dicommand),buf,len,__dvd_iostransactionCB,ctx); + + return ret; +} + +// never got this function working, probably removed from wii +s32 bwDVD_LowReadVideo(void *buf,u32 len,u32 offset,dvdcallbacklow cb) { + s32 ret; + struct dicontext *ctx; + struct dicommand *cmd; + + __dvd_reqinprogress = 1; + __dvd_readlength = len; + + ctx = __dvd_getcontext(cb); + if (ctx==NULL) return IPC_ENOMEM; + + cmd = ctx->cmd; + cmd->diReg[0] = (IOCTL_DI_READ_DVDVIDEO<<24); + cmd->diReg[1] = len; + cmd->diReg[2] = offset; + ret = IOS_IoctlAsync(__dvd_fd,IOCTL_DI_READ_DVDVIDEO,cmd->diReg,sizeof(struct dicommand),buf,len,__dvd_iostransactionCB,ctx); + + return ret; +} + + + +s32 bwDVD_LowStopLaser(dvdcallbacklow cb) { + s32 ret; + struct dicontext *ctx; + struct dicommand *cmd; + + __dvd_reqinprogress = 1; + + ctx = __dvd_getcontext(cb); + if (ctx==NULL) return IPC_ENOMEM; + + cmd = ctx->cmd; + cmd->diReg[0] = (IOCTL_DI_STOPLASER<<24); + ret = IOS_IoctlAsync(__dvd_fd,IOCTL_DI_STOPLASER,cmd->diReg,sizeof(struct dicommand),__di_regvalcache,0x20,__dvd_iostransactionCB,ctx); + + return ret; +} + +// never got this function working, probably removed from wii +s32 bwDVD_EnableVideo(dvdcallbacklow cb) { + s32 ret; + struct dicontext *ctx; + struct dicommand *cmd; + + __dvd_reqinprogress = 1; + + ctx = __dvd_getcontext(cb); + if (ctx==NULL) return IPC_ENOMEM; + + cmd = ctx->cmd; + cmd->diReg[0] = (IOCTL_DI_ENABLE_DVD<<24); + ret = IOS_IoctlAsync(__dvd_fd,IOCTL_DI_ENABLE_DVD,cmd->diReg,sizeof(struct dicommand),__di_regvalcache,0x20,__dvd_iostransactionCB,ctx); + + return ret; +} + +s32 bwDVD_LowSeek(u32 offset,dvdcallbacklow cb) { + s32 ret; + struct dicontext *ctx; + struct dicommand *cmd; + + __dvd_reqinprogress = 1; + + ctx = __dvd_getcontext(cb); + if (ctx==NULL) return IPC_ENOMEM; + + cmd = ctx->cmd; + cmd->diReg[0] = (IOCTL_DI_SEEK<<24); + cmd->diReg[1] = offset; + ret = IOS_IoctlAsync(__dvd_fd,IOCTL_DI_SEEK,cmd->diReg,sizeof(struct dicommand),NULL,0,__dvd_iostransactionCB,ctx); + + return ret; +} + +s32 bwDVD_LowOffset(u64 offset,dvdcallbacklow cb) { + s32 ret; + u32 *off = (u32*)(void*)(&offset); + struct dicontext *ctx; + struct dicommand *cmd; + + __dvd_reqinprogress = 1; + + ctx = __dvd_getcontext(cb); + if (ctx==NULL) return IPC_ENOMEM; + + cmd = ctx->cmd; + cmd->diReg[0] = (IOCTL_DI_OFFSET<<24); + cmd->diReg[1] = 0; + if (off[0]) cmd->diReg[1] = 1; + cmd->diReg[2] = off[1]; + ret = IOS_IoctlAsync(__dvd_fd,IOCTL_DI_OFFSET,cmd->diReg,sizeof(struct dicommand),__di_regvalcache,0x20,__dvd_iostransactionCB,ctx); + + return ret; +} + +s32 bwDVD_LowPrepareCoverRegister(dvdcallbacklow cb) { + s32 ret; + struct dicontext *ctx; + struct dicommand *cmd; + + __dvd_reqinprogress = 1; + + ctx = __dvd_getcontext(cb); + if (ctx==NULL) return IPC_ENOMEM; + + cmd = ctx->cmd; + cmd->diReg[0] = (IOCTL_DI_COVER<<24); + ret = IOS_IoctlAsync(__dvd_fd,IOCTL_DI_COVER,cmd->diReg,sizeof(struct dicommand),__di_regbuffer,0x20,__dvd_ioscoverregisterCB,ctx); + + return ret; +} + +s32 bwDVD_LowOpenPartition(u32 offset,void *eticket,u32 certin_len,void *certificate_in,void *certificate_out,dvdcallbacklow cb) { + s32 ret; + struct dicontext *ctx; + struct dicommand *cmd; + + if (eticket!=NULL && ((u32)eticket%32)!=0) return -1; + if (certificate_in!=NULL && ((u32)certificate_in%32)!=0) return -1; + if (certificate_out!=NULL && ((u32)certificate_out%32)!=0) return -1; + + __dvd_reqinprogress = 1; + + ctx = __dvd_getcontext(cb); + if (ctx==NULL) return IPC_ENOMEM; + + cmd = ctx->cmd; + cmd->diReg[0] = (IOCTL_DI_OPENPART<<24); + cmd->diReg[1] = offset; + + __di_iovector[0].data = cmd; + __di_iovector[0].len = sizeof(struct dicommand); + + __di_iovector[1].data = eticket; + if (eticket==NULL) __di_iovector[1].len = 0; + else __di_iovector[1].len = 676; + + __di_iovector[2].data = certificate_in; + if (certificate_in==NULL) __di_iovector[2].len = 0; + else __di_iovector[2].len = certin_len; + + __di_iovector[3].data = certificate_out; + __di_iovector[3].len = 18916; + __di_iovector[4].data = __di_lastticketerror; + __di_iovector[4].len = 0x20; + ret = IOS_IoctlvAsync(__dvd_fd,IOCTL_DI_OPENPART,3,2,__di_iovector,__dvd_iostransactionCB,ctx); + + return ret; +} + +s32 bwDVD_LowClosePartition(dvdcallbacklow cb) { + s32 ret; + struct dicontext *ctx; + struct dicommand *cmd; + + __dvd_reqinprogress = 1; + + ctx = __dvd_getcontext(cb); + if (ctx==NULL) return IPC_ENOMEM; + + cmd = ctx->cmd; + cmd->diReg[0] = (IOCTL_DI_CLOSEPART<<24); + ret = IOS_IoctlAsync(__dvd_fd,IOCTL_DI_CLOSEPART,cmd->diReg,sizeof(struct dicommand),NULL,0,__dvd_iostransactionCB,ctx); + + return ret; +} + +s32 bwDVD_LowUnencryptedRead(void *buf,u32 len,u32 offset,dvdcallbacklow cb) { + s32 ret; + struct dicontext *ctx; + struct dicommand *cmd; + + __dvd_reqinprogress = 1; + __dvd_readlength = len; + + ctx = __dvd_getcontext(cb); + if (ctx==NULL) return IPC_ENOMEM; + + cmd = ctx->cmd; + cmd->diReg[0] = (IOCTL_DI_UNENCREAD<<24); + cmd->diReg[1] = len; + cmd->diReg[2] = offset; + ret = IOS_IoctlAsync(__dvd_fd,IOCTL_DI_UNENCREAD,cmd->diReg,sizeof(struct dicommand),buf,len,__dvd_iostransactionCB,ctx); + + return ret; +} + +s32 bwDVD_LowWaitCoverClose(dvdcallbacklow cb) { + s32 ret; + struct dicontext *ctx; + struct dicommand *cmd; + + __dvd_reqinprogress = 1; + + ctx = __dvd_getcontext(cb); + if (ctx==NULL) return IPC_ENOMEM; + + cmd = ctx->cmd; + cmd->diReg[0] = (IOCTL_DI_WAITCVRCLOSE<<24); + ret = IOS_IoctlAsync(__dvd_fd,IOCTL_DI_WAITCVRCLOSE,cmd->diReg,sizeof(struct dicommand),NULL,0,__dvd_ioscovercloseCB,ctx); + + return ret; +} + +s32 bwDVD_LowResetNotify() { + s32 ret; + struct dicontext *ctx; + struct dicommand *cmd; + + if (__dvd_cbinprogress==1) return -1; + + ctx = __dvd_getcontext(NULL); + if (ctx==NULL) return IPC_ENOMEM; + + cmd = ctx->cmd; + cmd->diReg[0] = (IOCTL_DI_RESETNOTIFY<<24); + ret = IOS_Ioctl(__dvd_fd,IOCTL_DI_RESETNOTIFY,cmd->diReg,sizeof(struct dicommand),NULL,0); + + return ret; +} + +s32 bwDVD_LowReset(dvdcallbacklow cb) { + s32 ret; + struct dicontext *ctx; + struct dicommand *cmd; + +// printf("DVD_LowReset()\n"); + __dvd_reqinprogress = 1; + + ctx = __dvd_getcontext(cb); + if (ctx==NULL) return IPC_ENOMEM; + + cmd = ctx->cmd; + cmd->diReg[0] = (IOCTL_DI_RESET<<24); + cmd->diReg[1] = __dvd_spinupval; + ret = IOS_IoctlAsync(__dvd_fd,IOCTL_DI_RESET,cmd->diReg,sizeof(struct dicommand),NULL,0,__dvd_iostransactionCB,ctx); + +// printf("DVD_LowReset(%d)\n",ret); + return ret; +} + +s32 bwDVD_LowStopMotor(u8 stop1,u8 stop2,dvdcallbacklow cb) { + s32 ret; + struct dicontext *ctx; + struct dicommand *cmd; + + __dvd_reqinprogress = 1; + + ctx = __dvd_getcontext(cb); + if (ctx==NULL) return IPC_ENOMEM; + + cmd = ctx->cmd; + cmd->diReg[0] = (IOCTL_DI_STOPMOTOR<<24); + cmd->diReg[1] = (stop1<<24); + cmd->diReg[2] = (stop2<<24); + ret = IOS_IoctlAsync(__dvd_fd,IOCTL_DI_STOPMOTOR,cmd->diReg,sizeof(struct dicommand),__di_regvalcache,0x20,__dvd_iostransactionCB,ctx); + + return ret; + +} + +s32 bwDVD_LowRequestError(dvdcallbacklow cb) { + s32 ret; + struct dicontext *ctx; + struct dicommand *cmd; + + __dvd_reqinprogress = 1; + + ctx = __dvd_getcontext(cb); + if (ctx==NULL) return IPC_ENOMEM; + + cmd = ctx->cmd; + cmd->diReg[0] = (IOCTL_DI_REQERROR<<24); + ret = IOS_IoctlAsync(__dvd_fd,IOCTL_DI_REQERROR,cmd->diReg,sizeof(struct dicommand),__di_regvalcache,0x20,__dvd_iostransactionCB,ctx); + + return ret; +} + + +s32 bwDVD_SetDecryption(s32 mode, dvdcallbacklow cb) { + s32 ret; + struct dicontext *ctx; + struct dicommand *cmd; + + __dvd_reqinprogress = 1; + + ctx = __dvd_getcontext(cb); + if (ctx==NULL) return IPC_ENOMEM; + + cmd = ctx->cmd; + cmd->diReg[0] = (IOCTL_DI_SETCRYPTMODE<<24); + cmd->diReg[1] = mode; + ret = IOS_IoctlAsync(__dvd_fd,IOCTL_DI_SETCRYPTMODE,cmd->diReg,sizeof(struct dicommand),__di_regvalcache,0x20,__dvd_iostransactionCB,ctx); + + return ret; + +} + +s32 bwDVD_SetOffset(u32 offset, dvdcallbacklow cb) { + s32 ret; + struct dicontext *ctx; + struct dicommand *cmd; + + __dvd_reqinprogress = 1; + + ctx = __dvd_getcontext(cb); + if (ctx==NULL) return IPC_ENOMEM; + + cmd = ctx->cmd; + cmd->diReg[0] = (IOCTL_DI_SETOFFBASE<<24); + cmd->diReg[1] = offset; + ret = IOS_IoctlAsync(__dvd_fd,IOCTL_DI_SETOFFBASE,cmd->diReg,sizeof(struct dicommand),__di_regvalcache,0x20,__dvd_iostransactionCB,ctx); + + return ret; + +} diff --git a/source/patches/fst.c b/source/patches/fst.c index cfea0d0f..211414c4 100644 --- a/source/patches/fst.c +++ b/source/patches/fst.c @@ -1,98 +1,98 @@ -/* - * Copyright (C) 2008 Nuke (wiinuke@gmail.com) - * - * this file is part of GeckoOS for USB Gecko - * http://www.usbgecko.com - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "settings/cfg.h" -#include "fst.h" -#include "dvd_broadway.h" -#include "wpad.h" -#include "fatmounter.h" - -extern struct SSettings Settings; - -u32 do_sd_code(char *filename) { - FILE *fp; - u8 *filebuff; - u32 filesize; - u32 ret; - char filepath[150]; - - SDCard_Init(); - USBDevice_Init(); - - sprintf(filepath, "%s%s", Settings.Cheatcodespath, filename); - filepath[strlen(Settings.Cheatcodespath)+6] = 0x2E; - filepath[strlen(Settings.Cheatcodespath)+7] = 0x67; - filepath[strlen(Settings.Cheatcodespath)+8] = 0x63; - filepath[strlen(Settings.Cheatcodespath)+9] = 0x74; - filepath[strlen(Settings.Cheatcodespath)+10] = 0; - - fp = fopen(filepath, "rb"); - if (!fp) { - USBDevice_deInit(); - SDCard_deInit(); - return 0; - } - - fseek(fp, 0, SEEK_END); - filesize = ftell(fp); - fseek(fp, 0, SEEK_SET); - - filebuff = (u8*) malloc (filesize); - if (filebuff == 0) { - fclose(fp); - sleep(2); - USBDevice_deInit(); - SDCard_deInit(); - return 0; - } - - ret = fread(filebuff, 1, filesize, fp); - if (ret != filesize) { - free(filebuff); - fclose(fp); - USBDevice_deInit(); - SDCard_deInit(); - return 0; - } - - memcpy((void*)0x800027E8,filebuff,filesize); - *(vu8*)0x80001807 = 0x01; - - free(filebuff); - fclose(fp); - - USBDevice_deInit(); - SDCard_deInit(); - - return 1; -} - - +/* + * Copyright (C) 2008 Nuke (wiinuke@gmail.com) + * + * this file is part of GeckoOS for USB Gecko + * http://www.usbgecko.com + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "settings/cfg.h" +#include "fst.h" +#include "dvd_broadway.h" +#include "wpad.h" +#include "fatmounter.h" + +extern struct SSettings Settings; + +u32 do_sd_code(char *filename) { + FILE *fp; + u8 *filebuff; + u32 filesize; + u32 ret; + char filepath[150]; + + SDCard_Init(); + USBDevice_Init(); + + sprintf(filepath, "%s%s", Settings.Cheatcodespath, filename); + filepath[strlen(Settings.Cheatcodespath)+6] = 0x2E; + filepath[strlen(Settings.Cheatcodespath)+7] = 0x67; + filepath[strlen(Settings.Cheatcodespath)+8] = 0x63; + filepath[strlen(Settings.Cheatcodespath)+9] = 0x74; + filepath[strlen(Settings.Cheatcodespath)+10] = 0; + + fp = fopen(filepath, "rb"); + if (!fp) { + USBDevice_deInit(); + SDCard_deInit(); + return 0; + } + + fseek(fp, 0, SEEK_END); + filesize = ftell(fp); + fseek(fp, 0, SEEK_SET); + + filebuff = (u8*) malloc (filesize); + if (filebuff == 0) { + fclose(fp); + sleep(2); + USBDevice_deInit(); + SDCard_deInit(); + return 0; + } + + ret = fread(filebuff, 1, filesize, fp); + if (ret != filesize) { + free(filebuff); + fclose(fp); + USBDevice_deInit(); + SDCard_deInit(); + return 0; + } + + memcpy((void*)0x800027E8,filebuff,filesize); + *(vu8*)0x80001807 = 0x01; + + free(filebuff); + fclose(fp); + + USBDevice_deInit(); + SDCard_deInit(); + + return 1; +} + + diff --git a/source/usbloader/alternatedol.c b/source/usbloader/alternatedol.c index d593a3fa..490d31e8 100644 --- a/source/usbloader/alternatedol.c +++ b/source/usbloader/alternatedol.c @@ -1,225 +1,224 @@ -#include -#include -#include -#include -#include - -#include "fatmounter.h" -#include "apploader.h" -#include "wdvd.h" -#include "fstfile.h" - -/** Alternate dolloader made by WiiPower modified by dimok **/ - -bool Load_Dol(void **buffer, int* dollen, char * filepath) { - int ret; - FILE* file; - void* dol_buffer; - - char fullpath[200]; - char gameidbuffer6[7]; - memset(gameidbuffer6, 0, 7); - memcpy(gameidbuffer6, (char*)0x80000000, 6); - snprintf(fullpath, 200, "%s%s.dol", filepath, gameidbuffer6); - - SDCard_Init(); - USBDevice_Init(); - - file = fopen(fullpath, "rb"); - - if (file == NULL) { - fclose(file); - SDCard_deInit(); - USBDevice_deInit(); - return false; - } - - int filesize; - fseek(file, 0, SEEK_END); - filesize = ftell(file); - fseek(file, 0, SEEK_SET); - - dol_buffer = malloc(filesize); - if (dol_buffer == NULL) { - fclose(file); - SDCard_deInit(); - USBDevice_deInit(); - return false; - } - ret = fread( dol_buffer, 1, filesize, file); - if (ret != filesize) { - free(dol_buffer); - fclose(file); - SDCard_deInit(); - USBDevice_deInit(); - return false; - } - fclose(file); - - SDCard_deInit(); - USBDevice_deInit(); - *buffer = dol_buffer; - *dollen = filesize; - return true; -} - -bool Remove_001_Protection(void *Address, int Size) { - u8 SearchPattern[16] = { 0x40, 0x82, 0x00, 0x0C, 0x38, 0x60, 0x00, 0x01, 0x48, 0x00, 0x02, 0x44, 0x38, 0x61, 0x00, 0x18 }; - u8 PatchData[16] = { 0x40, 0x82, 0x00, 0x04, 0x38, 0x60, 0x00, 0x01, 0x48, 0x00, 0x02, 0x44, 0x38, 0x61, 0x00, 0x18 }; - - void *Addr = Address; - void *Addr_end = Address+Size; - - while (Addr <= Addr_end-sizeof(SearchPattern)) { - if (memcmp(Addr, SearchPattern, sizeof(SearchPattern))==0) { - memcpy(Addr,PatchData,sizeof(PatchData)); - return true; - } - Addr += 4; - } - return false; -} - -typedef struct _dolheader { - u32 text_pos[7]; - u32 data_pos[11]; - u32 text_start[7]; - u32 data_start[11]; - u32 text_size[7]; - u32 data_size[11]; - u32 bss_start; - u32 bss_size; - u32 entry_point; -} dolheader; - -static dolheader *dolfile; - - -u32 load_dol_image(void *dolstart) { - - u32 i; - - if (dolstart) { - dolfile = (dolheader *) dolstart; - for (i = 0; i < 7; i++) { - if ((!dolfile->text_size[i]) || (dolfile->text_start[i] < 0x100)) continue; - VIDEO_WaitVSync(); - ICInvalidateRange ((void *) dolfile->text_start[i],dolfile->text_size[i]); - memmove ((void *) dolfile->text_start[i],dolstart+dolfile->text_pos[i],dolfile->text_size[i]); - } - - for (i = 0; i < 11; i++) { - if ((!dolfile->data_size[i]) || (dolfile->data_start[i] < 0x100)) continue; - VIDEO_WaitVSync(); - memmove ((void *) dolfile->data_start[i],dolstart+dolfile->data_pos[i],dolfile->data_size[i]); - DCFlushRangeNoSync ((void *) dolfile->data_start[i],dolfile->data_size[i]); - } - /* - memset ((void *) dolfile->bss_start, 0, dolfile->bss_size); - DCFlushRange((void *) dolfile->bss_start, dolfile->bss_size); - */ - return dolfile->entry_point; - } - return 0; -} - -static int i; -static int phase; - -u32 load_dol_start(void *dolstart) { - if (dolstart) { - dolfile = (dolheader *)dolstart; - return dolfile->entry_point; - } else { - return 0; - } - - memset((void *)dolfile->bss_start, 0, dolfile->bss_size); - DCFlushRange((void *)dolfile->bss_start, dolfile->bss_size); - - phase = 0; - i = 0; -} - -bool load_dol_image_modified(void **offset, u32 *pos, u32 *len) { - if (phase == 0) { - if (i == 7) { - phase = 1; - i = 0; - } else { - if ((!dolfile->text_size[i]) || (dolfile->text_start[i] < 0x100)) { - *offset = 0; - *pos = 0; - *len = 0; - } else { - *offset = (void *)dolfile->text_start[i]; - *pos = dolfile->text_pos[i]; - *len = dolfile->text_size[i]; - } - i++; - return true; - } - } - - if (phase == 1) { - if (i == 11) { - phase = 2; - return false; - } - - if ((!dolfile->data_size[i]) || (dolfile->data_start[i] < 0x100)) { - *offset = 0; - *pos = 0; - *len = 0; - } else { - *offset = (void *)dolfile->data_start[i]; - *pos = dolfile->data_pos[i]; - *len = dolfile->data_size[i]; - } - i++; - return true; - } - return false; -} - -u32 Load_Dol_from_disc(u32 doloffset, u8 videoSelected, u8 patchcountrystring, u8 vipatch) { - int ret; - void *dol_header; - u32 entrypoint; - - dol_header = memalign(32, sizeof(dolheader)); - if (dol_header == NULL) { - return -1; - } - - ret = WDVD_Read(dol_header, sizeof(dolheader), (doloffset<<2)); - - entrypoint = load_dol_start(dol_header); - - if (entrypoint == 0) { - free(dol_header); - return -1; - } - - void *offset; - u32 pos; - u32 len; - - while (load_dol_image_modified(&offset, &pos, &len)) { - if (len != 0) { - ret = WDVD_Read(offset, len, (doloffset<<2) + pos); - - DCFlushRange(offset, len); - - gamepatches(offset, len, videoSelected, patchcountrystring, vipatch); - - DCFlushRange(offset, len); - - Remove_001_Protection(offset, len); - } - } - - free(dol_header); - - return entrypoint; -} +#include +#include +#include +#include +#include + +#include "fatmounter.h" +#include "apploader.h" +#include "wdvd.h" +#include "fstfile.h" + +/** Alternate dolloader made by WiiPower modified by dimok **/ +bool Load_Dol(void **buffer, int* dollen, char * filepath) { + int ret; + FILE* file; + void* dol_buffer; + + char fullpath[200]; + char gameidbuffer6[7]; + memset(gameidbuffer6, 0, 7); + memcpy(gameidbuffer6, (char*)0x80000000, 6); + snprintf(fullpath, 200, "%s%s.dol", filepath, gameidbuffer6); + + SDCard_Init(); + USBDevice_Init(); + + file = fopen(fullpath, "rb"); + + if (file == NULL) { + fclose(file); + SDCard_deInit(); + USBDevice_deInit(); + return false; + } + + int filesize; + fseek(file, 0, SEEK_END); + filesize = ftell(file); + fseek(file, 0, SEEK_SET); + + dol_buffer = malloc(filesize); + if (dol_buffer == NULL) { + fclose(file); + SDCard_deInit(); + USBDevice_deInit(); + return false; + } + ret = fread( dol_buffer, 1, filesize, file); + if (ret != filesize) { + free(dol_buffer); + fclose(file); + SDCard_deInit(); + USBDevice_deInit(); + return false; + } + fclose(file); + + SDCard_deInit(); + USBDevice_deInit(); + *buffer = dol_buffer; + *dollen = filesize; + return true; +} + +bool Remove_001_Protection(void *Address, int Size) { + u8 SearchPattern[16] = { 0x40, 0x82, 0x00, 0x0C, 0x38, 0x60, 0x00, 0x01, 0x48, 0x00, 0x02, 0x44, 0x38, 0x61, 0x00, 0x18 }; + u8 PatchData[16] = { 0x40, 0x82, 0x00, 0x04, 0x38, 0x60, 0x00, 0x01, 0x48, 0x00, 0x02, 0x44, 0x38, 0x61, 0x00, 0x18 }; + + void *Addr = Address; + void *Addr_end = Address+Size; + + while (Addr <= Addr_end-sizeof(SearchPattern)) { + if (memcmp(Addr, SearchPattern, sizeof(SearchPattern))==0) { + memcpy(Addr,PatchData,sizeof(PatchData)); + return true; + } + Addr += 4; + } + return false; +} + +typedef struct _dolheader { + u32 text_pos[7]; + u32 data_pos[11]; + u32 text_start[7]; + u32 data_start[11]; + u32 text_size[7]; + u32 data_size[11]; + u32 bss_start; + u32 bss_size; + u32 entry_point; +} dolheader; + +static dolheader *dolfile; + + +u32 load_dol_image(void *dolstart) { + + u32 i; + + if (dolstart) { + dolfile = (dolheader *) dolstart; + for (i = 0; i < 7; i++) { + if ((!dolfile->text_size[i]) || (dolfile->text_start[i] < 0x100)) continue; + VIDEO_WaitVSync(); + ICInvalidateRange ((void *) dolfile->text_start[i],dolfile->text_size[i]); + memmove ((void *) dolfile->text_start[i],dolstart+dolfile->text_pos[i],dolfile->text_size[i]); + } + + for (i = 0; i < 11; i++) { + if ((!dolfile->data_size[i]) || (dolfile->data_start[i] < 0x100)) continue; + VIDEO_WaitVSync(); + memmove ((void *) dolfile->data_start[i],dolstart+dolfile->data_pos[i],dolfile->data_size[i]); + DCFlushRangeNoSync ((void *) dolfile->data_start[i],dolfile->data_size[i]); + } + /* + memset ((void *) dolfile->bss_start, 0, dolfile->bss_size); + DCFlushRange((void *) dolfile->bss_start, dolfile->bss_size); + */ + return dolfile->entry_point; + } + return 0; +} + +static int i; +static int phase; + +u32 load_dol_start(void *dolstart) { + if (dolstart) { + dolfile = (dolheader *)dolstart; + return dolfile->entry_point; + } else { + return 0; + } + + memset((void *)dolfile->bss_start, 0, dolfile->bss_size); + DCFlushRange((void *)dolfile->bss_start, dolfile->bss_size); + + phase = 0; + i = 0; +} + +bool load_dol_image_modified(void **offset, u32 *pos, u32 *len) { + if (phase == 0) { + if (i == 7) { + phase = 1; + i = 0; + } else { + if ((!dolfile->text_size[i]) || (dolfile->text_start[i] < 0x100)) { + *offset = 0; + *pos = 0; + *len = 0; + } else { + *offset = (void *)dolfile->text_start[i]; + *pos = dolfile->text_pos[i]; + *len = dolfile->text_size[i]; + } + i++; + return true; + } + } + + if (phase == 1) { + if (i == 11) { + phase = 2; + return false; + } + + if ((!dolfile->data_size[i]) || (dolfile->data_start[i] < 0x100)) { + *offset = 0; + *pos = 0; + *len = 0; + } else { + *offset = (void *)dolfile->data_start[i]; + *pos = dolfile->data_pos[i]; + *len = dolfile->data_size[i]; + } + i++; + return true; + } + return false; +} + +u32 Load_Dol_from_disc(u32 doloffset, u8 videoSelected, u8 patchcountrystring, u8 vipatch) { + int ret; + void *dol_header; + u32 entrypoint; + + dol_header = memalign(32, sizeof(dolheader)); + if (dol_header == NULL) { + return -1; + } + + ret = WDVD_Read(dol_header, sizeof(dolheader), (doloffset<<2)); + + entrypoint = load_dol_start(dol_header); + + if (entrypoint == 0) { + free(dol_header); + return -1; + } + + void *offset; + u32 pos; + u32 len; + + while (load_dol_image_modified(&offset, &pos, &len)) { + if (len != 0) { + ret = WDVD_Read(offset, len, (doloffset<<2) + pos); + + DCFlushRange(offset, len); + + gamepatches(offset, len, videoSelected, patchcountrystring, vipatch); + + DCFlushRange(offset, len); + + Remove_001_Protection(offset, len); + } + } + + free(dol_header); + + return entrypoint; +} diff --git a/source/usbloader/apploader.c b/source/usbloader/apploader.c index 0f250461..4a87764f 100644 --- a/source/usbloader/apploader.c +++ b/source/usbloader/apploader.c @@ -1,28 +1,28 @@ -#include -#include -#include - -#include "patches/patchcode.h" +#include +#include +#include + +#include "patches/patchcode.h" #include "patches/kenobiwii.h" /*FISHEARS*/ -#include "apploader.h" -#include "wdvd.h" -#include "wpad.h" -#include "disc.h" -#include "alternatedol.h" -#include "fstfile.h" -#include "settings/cfg.h" - -/*KENOBI! - FISHEARS*/ -extern const unsigned char kenobiwii[]; -extern const int kenobiwii_size; -/*KENOBI! - FISHEARS*/ - -/* Apploader function pointers */ -typedef int (*app_main)(void **dst, int *size, int *offset); -typedef void (*app_init)(void (*report)(const char *fmt, ...)); -typedef void *(*app_final)(); -typedef void (*app_entry)(void (**init)(void (*report)(const char *fmt, ...)), int (**main)(), void *(**final)()); - +#include "apploader.h" +#include "wdvd.h" +#include "wpad.h" +#include "disc.h" +#include "alternatedol.h" +#include "fstfile.h" +#include "settings/cfg.h" + +/*KENOBI! - FISHEARS*/ +extern const unsigned char kenobiwii[]; +extern const int kenobiwii_size; +/*KENOBI! - FISHEARS*/ + +/* Apploader function pointers */ +typedef int (*app_main)(void **dst, int *size, int *offset); +typedef void (*app_init)(void (*report)(const char *fmt, ...)); +typedef void *(*app_final)(); +typedef void (*app_entry)(void (**init)(void (*report)(const char *fmt, ...)), int (**main)(), void *(**final)()); + /* Apploader pointers */ static u8 *appldr = (u8 *)0x81200000; @@ -46,330 +46,330 @@ bool compare_videomodes(GXRModeObj* mode1, GXRModeObj* mode2) { mode1->sample_pattern[1][0] != mode2->sample_pattern[1][0] || mode1->sample_pattern[2][0] != mode2->sample_pattern[2][0] || mode1->sample_pattern[3][0] != mode2->sample_pattern[3][0] || mode1->sample_pattern[4][0] != mode2->sample_pattern[4][0] || mode1->sample_pattern[5][0] != mode2->sample_pattern[5][0] || mode1->sample_pattern[6][0] != mode2->sample_pattern[6][0] || - mode1->sample_pattern[7][0] != mode2->sample_pattern[7][0] || mode1->sample_pattern[8][0] != mode2->sample_pattern[8][0] || - mode1->sample_pattern[9][0] != mode2->sample_pattern[9][0] || mode1->sample_pattern[10][0] != mode2->sample_pattern[10][0] || - mode1->sample_pattern[11][0] != mode2->sample_pattern[11][0] || mode1->sample_pattern[0][1] != mode2->sample_pattern[0][1] || - mode1->sample_pattern[1][1] != mode2->sample_pattern[1][1] || mode1->sample_pattern[2][1] != mode2->sample_pattern[2][1] || - mode1->sample_pattern[3][1] != mode2->sample_pattern[3][1] || mode1->sample_pattern[4][1] != mode2->sample_pattern[4][1] || - mode1->sample_pattern[5][1] != mode2->sample_pattern[5][1] || mode1->sample_pattern[6][1] != mode2->sample_pattern[6][1] || - mode1->sample_pattern[7][1] != mode2->sample_pattern[7][1] || mode1->sample_pattern[8][1] != mode2->sample_pattern[8][1] || - mode1->sample_pattern[9][1] != mode2->sample_pattern[9][1] || mode1->sample_pattern[10][1] != mode2->sample_pattern[10][1] || - mode1->sample_pattern[11][1] != mode2->sample_pattern[11][1] || mode1->vfilter[0] != mode2->vfilter[0] || - mode1->vfilter[1] != mode2->vfilter[1] || mode1->vfilter[2] != mode2->vfilter[2] || mode1->vfilter[3] != mode2->vfilter[3] || mode1->vfilter[4] != mode2->vfilter[4] || - mode1->vfilter[5] != mode2->vfilter[5] || mode1->vfilter[6] != mode2->vfilter[6] ) { - return false; - } else { - return true; - } -} - - -void patch_videomode(GXRModeObj* mode1, GXRModeObj* mode2) { - mode1->viTVMode = mode2->viTVMode; - mode1->fbWidth = mode2->fbWidth; - mode1->efbHeight = mode2->efbHeight; - mode1->xfbHeight = mode2->xfbHeight; - mode1->viXOrigin = mode2->viXOrigin; - mode1->viYOrigin = mode2->viYOrigin; - mode1->viWidth = mode2->viWidth; - mode1->viHeight = mode2->viHeight; - mode1->xfbMode = mode2->xfbMode; - mode1->field_rendering = mode2->field_rendering; - mode1->aa = mode2->aa; - mode1->sample_pattern[0][0] = mode2->sample_pattern[0][0]; - mode1->sample_pattern[1][0] = mode2->sample_pattern[1][0]; - mode1->sample_pattern[2][0] = mode2->sample_pattern[2][0]; - mode1->sample_pattern[3][0] = mode2->sample_pattern[3][0]; - mode1->sample_pattern[4][0] = mode2->sample_pattern[4][0]; - mode1->sample_pattern[5][0] = mode2->sample_pattern[5][0]; - mode1->sample_pattern[6][0] = mode2->sample_pattern[6][0]; - mode1->sample_pattern[7][0] = mode2->sample_pattern[7][0]; - mode1->sample_pattern[8][0] = mode2->sample_pattern[8][0]; - mode1->sample_pattern[9][0] = mode2->sample_pattern[9][0]; - mode1->sample_pattern[10][0] = mode2->sample_pattern[10][0]; - mode1->sample_pattern[11][0] = mode2->sample_pattern[11][0]; - mode1->sample_pattern[0][1] = mode2->sample_pattern[0][1]; - mode1->sample_pattern[1][1] = mode2->sample_pattern[1][1]; - mode1->sample_pattern[2][1] = mode2->sample_pattern[2][1]; - mode1->sample_pattern[3][1] = mode2->sample_pattern[3][1]; - mode1->sample_pattern[4][1] = mode2->sample_pattern[4][1]; - mode1->sample_pattern[5][1] = mode2->sample_pattern[5][1]; - mode1->sample_pattern[6][1] = mode2->sample_pattern[6][1]; - mode1->sample_pattern[7][1] = mode2->sample_pattern[7][1]; - mode1->sample_pattern[8][1] = mode2->sample_pattern[8][1]; - mode1->sample_pattern[9][1] = mode2->sample_pattern[9][1]; - mode1->sample_pattern[10][1] = mode2->sample_pattern[10][1]; - mode1->sample_pattern[11][1] = mode2->sample_pattern[11][1]; - mode1->vfilter[0] = mode2->vfilter[0]; - mode1->vfilter[1] = mode2->vfilter[1]; - mode1->vfilter[2] = mode2->vfilter[2]; - mode1->vfilter[3] = mode2->vfilter[3]; - mode1->vfilter[4] = mode2->vfilter[4]; - mode1->vfilter[5] = mode2->vfilter[5]; - mode1->vfilter[6] = mode2->vfilter[6]; -} - -GXRModeObj* vmodes[] = { - &TVNtsc240Ds, - &TVNtsc240DsAa, - &TVNtsc240Int, - &TVNtsc240IntAa, - &TVNtsc480IntDf, - &TVNtsc480IntAa, - &TVNtsc480Prog, - &TVMpal480IntDf, - &TVPal264Ds, - &TVPal264DsAa, - &TVPal264Int, - &TVPal264IntAa, - &TVPal524IntAa, - &TVPal528Int, - &TVPal528IntDf, - &TVPal574IntDfScale, - &TVEurgb60Hz240Ds, - &TVEurgb60Hz240DsAa, - &TVEurgb60Hz240Int, - &TVEurgb60Hz240IntAa, - &TVEurgb60Hz480Int, - &TVEurgb60Hz480IntDf, - &TVEurgb60Hz480IntAa, - &TVEurgb60Hz480Prog, - &TVEurgb60Hz480ProgSoft, - &TVEurgb60Hz480ProgAa -}; - -GXRModeObj* PAL2NTSC[]={ - &TVMpal480IntDf, &TVNtsc480IntDf, - &TVPal264Ds, &TVNtsc240Ds, - &TVPal264DsAa, &TVNtsc240DsAa, - &TVPal264Int, &TVNtsc240Int, - &TVPal264IntAa, &TVNtsc240IntAa, - &TVPal524IntAa, &TVNtsc480IntAa, - &TVPal528Int, &TVNtsc480IntAa, - &TVPal528IntDf, &TVNtsc480IntDf, - &TVPal574IntDfScale, &TVNtsc480IntDf, - &TVEurgb60Hz240Ds, &TVNtsc240Ds, - &TVEurgb60Hz240DsAa, &TVNtsc240DsAa, - &TVEurgb60Hz240Int, &TVNtsc240Int, - &TVEurgb60Hz240IntAa, &TVNtsc240IntAa, - &TVEurgb60Hz480Int, &TVNtsc480IntAa, - &TVEurgb60Hz480IntDf, &TVNtsc480IntDf, - &TVEurgb60Hz480IntAa, &TVNtsc480IntAa, - &TVEurgb60Hz480Prog, &TVNtsc480Prog, - &TVEurgb60Hz480ProgSoft,&TVNtsc480Prog, - &TVEurgb60Hz480ProgAa, &TVNtsc480Prog, - 0,0 -}; - -GXRModeObj* NTSC2PAL[]={ - &TVNtsc240Ds, &TVPal264Ds, - &TVNtsc240DsAa, &TVPal264DsAa, - &TVNtsc240Int, &TVPal264Int, - &TVNtsc240IntAa, &TVPal264IntAa, - &TVNtsc480IntDf, &TVPal528IntDf, - &TVNtsc480IntAa, &TVPal524IntAa, - &TVNtsc480Prog, &TVPal528IntDf, - 0,0 -}; - -GXRModeObj* NTSC2PAL60[]={ - &TVNtsc240Ds, &TVEurgb60Hz240Ds, - &TVNtsc240DsAa, &TVEurgb60Hz240DsAa, - &TVNtsc240Int, &TVEurgb60Hz240Int, - &TVNtsc240IntAa, &TVEurgb60Hz240IntAa, - &TVNtsc480IntDf, &TVEurgb60Hz480IntDf, - &TVNtsc480IntAa, &TVEurgb60Hz480IntAa, - &TVNtsc480Prog, &TVEurgb60Hz480Prog, - 0,0 -}; -bool Search_and_patch_Video_Modes(void *Address, u32 Size, GXRModeObj* Table[]) { - u8 *Addr = (u8 *)Address; - bool found = 0; - u32 i; - - while (Size >= sizeof(GXRModeObj)) { - - - - for (i = 0; Table[i]; i+=2) { - - - if (compare_videomodes(Table[i], (GXRModeObj*)Addr)) - - { - found = 1; - patch_videomode((GXRModeObj*)Addr, Table[i+1]); - Addr += (sizeof(GXRModeObj)-4); - Size -= (sizeof(GXRModeObj)-4); - break; - } - } - - Addr += 4; - Size -= 4; - } - - - return found; -} - -/** Anti 002 fix for IOS 249 rev < 12 thanks to WiiPower **/ -void Anti_002_fix(void *Address, int Size) { - u8 SearchPattern[12] = { 0x2C, 0x00, 0x00, 0x00, 0x48, 0x00, 0x02, 0x14, 0x3C, 0x60, 0x80, 0x00 }; - u8 PatchData[12] = { 0x2C, 0x00, 0x00, 0x00, 0x40, 0x82, 0x02, 0x14, 0x3C, 0x60, 0x80, 0x00 }; - - void *Addr = Address; - void *Addr_end = Address+Size; - - while (Addr <= Addr_end-sizeof(SearchPattern)) { - if (memcmp(Addr, SearchPattern, sizeof(SearchPattern))==0) { - memcpy(Addr,PatchData,sizeof(PatchData)); - } - Addr += 4; - } -} - -void gamepatches(void * dst, int len, u8 videoSelected, u8 patchcountrystring, u8 vipatch) { - GXRModeObj** table = NULL; - if (videoSelected == 5) // patch - - { - switch (CONF_GetVideo()) { - case CONF_VIDEO_PAL: - if (CONF_GetEuRGB60() > 0) { - table = NTSC2PAL60; - } else { - table = NTSC2PAL; - } - break; - - case CONF_VIDEO_MPAL: - - - - table = NTSC2PAL; - break; - - - default: - table = PAL2NTSC; - break; - } - Search_and_patch_Video_Modes(dst, len, table); - } - - /*GAME HOOK - FISHEARS*/ - dogamehooks(dst,len); - - if (vipatch) - vidolpatcher(dst,len); - - - /*LANGUAGE PATCH - FISHEARS*/ - langpatcher(dst,len); - - /*Thanks to WiiPower*/ - if (patchcountrystring == 1) - PatchCountryStrings(dst, len); - - //if(Settings.anti002fix == on) - if (fix002 == 2) - Anti_002_fix(dst, len); - -} - -s32 Apploader_Run(entry_point *entry, u8 cheat, u8 videoSelected, u8 vipatch, u8 patchcountrystring, u8 error002fix, u8 alternatedol, u32 alternatedoloffset) { - app_entry appldr_entry; - app_init appldr_init; - app_main appldr_main; - app_final appldr_final; - - u32 appldr_len; - s32 ret; - - /* Read apploader header */ - ret = WDVD_Read(buffer, 0x20, APPLDR_OFFSET); - if (ret < 0) - return ret; - - /* Calculate apploader length */ - appldr_len = buffer[5] + buffer[6]; - - /* Read apploader code */ - ret = WDVD_Read(appldr, appldr_len, APPLDR_OFFSET + 0x20); - if (ret < 0) - return ret; - - /* Set apploader entry function */ - appldr_entry = (app_entry)buffer[4]; - - /* Call apploader entry */ - appldr_entry(&appldr_init, &appldr_main, &appldr_final); - - /* Initialize apploader */ - appldr_init(__noprint); - - if (error002fix!=0) { - /* ERROR 002 fix (thanks to WiiPower for sharing this)*/ - *(u32 *)0x80003140 = *(u32 *)0x80003188; - } - - if (cheat) { - /*HOOKS STUFF - FISHEARS*/ - memset((void*)0x80001800,0,kenobiwii_size); - memcpy((void*)0x80001800,kenobiwii,kenobiwii_size); - DCFlushRange((void*)0x80001800,kenobiwii_size); - hooktype = 1; - memcpy((void*)0x80001800, (char*)0x80000000, 6); // For WiiRD - /*HOOKS STUFF - FISHEARS*/ - } - - for (;;) { - void *dst = NULL; - int len = 0, offset = 0; - - /* Run apploader main function */ - ret = appldr_main(&dst, &len, &offset); - if (!ret) - break; - - /* Read data from DVD */ - WDVD_Read(dst, len, (u64)(offset << 2)); - - gamepatches(dst, len, videoSelected, patchcountrystring, vipatch); - - DCFlushRange(dst, len); - } - - *entry = appldr_final(); - - /** Load alternate dol if set **/ - if (alternatedol == 1) { - void *dolbuffer; - int dollen; - - bool dolloaded = Load_Dol(&dolbuffer, &dollen, Settings.dolpath); - if (dolloaded) { - Remove_001_Protection(dolbuffer, dollen); - - DCFlushRange(dolbuffer, dollen); - - gamepatches(dolbuffer, dollen, videoSelected, patchcountrystring, vipatch); - - DCFlushRange(dolbuffer, dollen); - - /* Set entry point from apploader */ - *entry = (entry_point) load_dol_image(dolbuffer); - } - } else if (alternatedol == 2) { - - FST_ENTRY *fst = (FST_ENTRY *)*(u32 *)0x80000038; - - *entry = (entry_point) Load_Dol_from_disc(fst[alternatedoloffset].fileoffset, videoSelected, patchcountrystring, vipatch); - - if (*entry == 0) - SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); - } - - return 0; -} + mode1->sample_pattern[7][0] != mode2->sample_pattern[7][0] || mode1->sample_pattern[8][0] != mode2->sample_pattern[8][0] || + mode1->sample_pattern[9][0] != mode2->sample_pattern[9][0] || mode1->sample_pattern[10][0] != mode2->sample_pattern[10][0] || + mode1->sample_pattern[11][0] != mode2->sample_pattern[11][0] || mode1->sample_pattern[0][1] != mode2->sample_pattern[0][1] || + mode1->sample_pattern[1][1] != mode2->sample_pattern[1][1] || mode1->sample_pattern[2][1] != mode2->sample_pattern[2][1] || + mode1->sample_pattern[3][1] != mode2->sample_pattern[3][1] || mode1->sample_pattern[4][1] != mode2->sample_pattern[4][1] || + mode1->sample_pattern[5][1] != mode2->sample_pattern[5][1] || mode1->sample_pattern[6][1] != mode2->sample_pattern[6][1] || + mode1->sample_pattern[7][1] != mode2->sample_pattern[7][1] || mode1->sample_pattern[8][1] != mode2->sample_pattern[8][1] || + mode1->sample_pattern[9][1] != mode2->sample_pattern[9][1] || mode1->sample_pattern[10][1] != mode2->sample_pattern[10][1] || + mode1->sample_pattern[11][1] != mode2->sample_pattern[11][1] || mode1->vfilter[0] != mode2->vfilter[0] || + mode1->vfilter[1] != mode2->vfilter[1] || mode1->vfilter[2] != mode2->vfilter[2] || mode1->vfilter[3] != mode2->vfilter[3] || mode1->vfilter[4] != mode2->vfilter[4] || + mode1->vfilter[5] != mode2->vfilter[5] || mode1->vfilter[6] != mode2->vfilter[6] ) { + return false; + } else { + return true; + } +} + + +void patch_videomode(GXRModeObj* mode1, GXRModeObj* mode2) { + mode1->viTVMode = mode2->viTVMode; + mode1->fbWidth = mode2->fbWidth; + mode1->efbHeight = mode2->efbHeight; + mode1->xfbHeight = mode2->xfbHeight; + mode1->viXOrigin = mode2->viXOrigin; + mode1->viYOrigin = mode2->viYOrigin; + mode1->viWidth = mode2->viWidth; + mode1->viHeight = mode2->viHeight; + mode1->xfbMode = mode2->xfbMode; + mode1->field_rendering = mode2->field_rendering; + mode1->aa = mode2->aa; + mode1->sample_pattern[0][0] = mode2->sample_pattern[0][0]; + mode1->sample_pattern[1][0] = mode2->sample_pattern[1][0]; + mode1->sample_pattern[2][0] = mode2->sample_pattern[2][0]; + mode1->sample_pattern[3][0] = mode2->sample_pattern[3][0]; + mode1->sample_pattern[4][0] = mode2->sample_pattern[4][0]; + mode1->sample_pattern[5][0] = mode2->sample_pattern[5][0]; + mode1->sample_pattern[6][0] = mode2->sample_pattern[6][0]; + mode1->sample_pattern[7][0] = mode2->sample_pattern[7][0]; + mode1->sample_pattern[8][0] = mode2->sample_pattern[8][0]; + mode1->sample_pattern[9][0] = mode2->sample_pattern[9][0]; + mode1->sample_pattern[10][0] = mode2->sample_pattern[10][0]; + mode1->sample_pattern[11][0] = mode2->sample_pattern[11][0]; + mode1->sample_pattern[0][1] = mode2->sample_pattern[0][1]; + mode1->sample_pattern[1][1] = mode2->sample_pattern[1][1]; + mode1->sample_pattern[2][1] = mode2->sample_pattern[2][1]; + mode1->sample_pattern[3][1] = mode2->sample_pattern[3][1]; + mode1->sample_pattern[4][1] = mode2->sample_pattern[4][1]; + mode1->sample_pattern[5][1] = mode2->sample_pattern[5][1]; + mode1->sample_pattern[6][1] = mode2->sample_pattern[6][1]; + mode1->sample_pattern[7][1] = mode2->sample_pattern[7][1]; + mode1->sample_pattern[8][1] = mode2->sample_pattern[8][1]; + mode1->sample_pattern[9][1] = mode2->sample_pattern[9][1]; + mode1->sample_pattern[10][1] = mode2->sample_pattern[10][1]; + mode1->sample_pattern[11][1] = mode2->sample_pattern[11][1]; + mode1->vfilter[0] = mode2->vfilter[0]; + mode1->vfilter[1] = mode2->vfilter[1]; + mode1->vfilter[2] = mode2->vfilter[2]; + mode1->vfilter[3] = mode2->vfilter[3]; + mode1->vfilter[4] = mode2->vfilter[4]; + mode1->vfilter[5] = mode2->vfilter[5]; + mode1->vfilter[6] = mode2->vfilter[6]; +} + +GXRModeObj* vmodes[] = { + &TVNtsc240Ds, + &TVNtsc240DsAa, + &TVNtsc240Int, + &TVNtsc240IntAa, + &TVNtsc480IntDf, + &TVNtsc480IntAa, + &TVNtsc480Prog, + &TVMpal480IntDf, + &TVPal264Ds, + &TVPal264DsAa, + &TVPal264Int, + &TVPal264IntAa, + &TVPal524IntAa, + &TVPal528Int, + &TVPal528IntDf, + &TVPal574IntDfScale, + &TVEurgb60Hz240Ds, + &TVEurgb60Hz240DsAa, + &TVEurgb60Hz240Int, + &TVEurgb60Hz240IntAa, + &TVEurgb60Hz480Int, + &TVEurgb60Hz480IntDf, + &TVEurgb60Hz480IntAa, + &TVEurgb60Hz480Prog, + &TVEurgb60Hz480ProgSoft, + &TVEurgb60Hz480ProgAa +}; + +GXRModeObj* PAL2NTSC[]={ + &TVMpal480IntDf, &TVNtsc480IntDf, + &TVPal264Ds, &TVNtsc240Ds, + &TVPal264DsAa, &TVNtsc240DsAa, + &TVPal264Int, &TVNtsc240Int, + &TVPal264IntAa, &TVNtsc240IntAa, + &TVPal524IntAa, &TVNtsc480IntAa, + &TVPal528Int, &TVNtsc480IntAa, + &TVPal528IntDf, &TVNtsc480IntDf, + &TVPal574IntDfScale, &TVNtsc480IntDf, + &TVEurgb60Hz240Ds, &TVNtsc240Ds, + &TVEurgb60Hz240DsAa, &TVNtsc240DsAa, + &TVEurgb60Hz240Int, &TVNtsc240Int, + &TVEurgb60Hz240IntAa, &TVNtsc240IntAa, + &TVEurgb60Hz480Int, &TVNtsc480IntAa, + &TVEurgb60Hz480IntDf, &TVNtsc480IntDf, + &TVEurgb60Hz480IntAa, &TVNtsc480IntAa, + &TVEurgb60Hz480Prog, &TVNtsc480Prog, + &TVEurgb60Hz480ProgSoft,&TVNtsc480Prog, + &TVEurgb60Hz480ProgAa, &TVNtsc480Prog, + 0,0 +}; + +GXRModeObj* NTSC2PAL[]={ + &TVNtsc240Ds, &TVPal264Ds, + &TVNtsc240DsAa, &TVPal264DsAa, + &TVNtsc240Int, &TVPal264Int, + &TVNtsc240IntAa, &TVPal264IntAa, + &TVNtsc480IntDf, &TVPal528IntDf, + &TVNtsc480IntAa, &TVPal524IntAa, + &TVNtsc480Prog, &TVPal528IntDf, + 0,0 +}; + +GXRModeObj* NTSC2PAL60[]={ + &TVNtsc240Ds, &TVEurgb60Hz240Ds, + &TVNtsc240DsAa, &TVEurgb60Hz240DsAa, + &TVNtsc240Int, &TVEurgb60Hz240Int, + &TVNtsc240IntAa, &TVEurgb60Hz240IntAa, + &TVNtsc480IntDf, &TVEurgb60Hz480IntDf, + &TVNtsc480IntAa, &TVEurgb60Hz480IntAa, + &TVNtsc480Prog, &TVEurgb60Hz480Prog, + 0,0 +}; +bool Search_and_patch_Video_Modes(void *Address, u32 Size, GXRModeObj* Table[]) { + u8 *Addr = (u8 *)Address; + bool found = 0; + u32 i; + + while (Size >= sizeof(GXRModeObj)) { + + + + for (i = 0; Table[i]; i+=2) { + + + if (compare_videomodes(Table[i], (GXRModeObj*)Addr)) + + { + found = 1; + patch_videomode((GXRModeObj*)Addr, Table[i+1]); + Addr += (sizeof(GXRModeObj)-4); + Size -= (sizeof(GXRModeObj)-4); + break; + } + } + + Addr += 4; + Size -= 4; + } + + + return found; +} + +/** Anti 002 fix for IOS 249 rev < 12 thanks to WiiPower **/ +void Anti_002_fix(void *Address, int Size) { + u8 SearchPattern[12] = { 0x2C, 0x00, 0x00, 0x00, 0x48, 0x00, 0x02, 0x14, 0x3C, 0x60, 0x80, 0x00 }; + u8 PatchData[12] = { 0x2C, 0x00, 0x00, 0x00, 0x40, 0x82, 0x02, 0x14, 0x3C, 0x60, 0x80, 0x00 }; + + void *Addr = Address; + void *Addr_end = Address+Size; + + while (Addr <= Addr_end-sizeof(SearchPattern)) { + if (memcmp(Addr, SearchPattern, sizeof(SearchPattern))==0) { + memcpy(Addr,PatchData,sizeof(PatchData)); + } + Addr += 4; + } +} + +void gamepatches(void * dst, int len, u8 videoSelected, u8 patchcountrystring, u8 vipatch) { + GXRModeObj** table = NULL; + if (videoSelected == 5) // patch + + { + switch (CONF_GetVideo()) { + case CONF_VIDEO_PAL: + if (CONF_GetEuRGB60() > 0) { + table = NTSC2PAL60; + } else { + table = NTSC2PAL; + } + break; + + case CONF_VIDEO_MPAL: + + + + table = NTSC2PAL; + break; + + + default: + table = PAL2NTSC; + break; + } + Search_and_patch_Video_Modes(dst, len, table); + } + + /*GAME HOOK - FISHEARS*/ + dogamehooks(dst,len); + + if (vipatch) + vidolpatcher(dst,len); + + + /*LANGUAGE PATCH - FISHEARS*/ + langpatcher(dst,len); + + /*Thanks to WiiPower*/ + if (patchcountrystring == 1) + PatchCountryStrings(dst, len); + + //if(Settings.anti002fix == on) + if (fix002 == 2) + Anti_002_fix(dst, len); + +} + +s32 Apploader_Run(entry_point *entry, u8 cheat, u8 videoSelected, u8 vipatch, u8 patchcountrystring, u8 error002fix, u8 alternatedol, u32 alternatedoloffset) { + app_entry appldr_entry; + app_init appldr_init; + app_main appldr_main; + app_final appldr_final; + + u32 appldr_len; + s32 ret; + + /* Read apploader header */ + ret = WDVD_Read(buffer, 0x20, APPLDR_OFFSET); + if (ret < 0) + return ret; + + /* Calculate apploader length */ + appldr_len = buffer[5] + buffer[6]; + + /* Read apploader code */ + ret = WDVD_Read(appldr, appldr_len, APPLDR_OFFSET + 0x20); + if (ret < 0) + return ret; + + /* Set apploader entry function */ + appldr_entry = (app_entry)buffer[4]; + + /* Call apploader entry */ + appldr_entry(&appldr_init, &appldr_main, &appldr_final); + + /* Initialize apploader */ + appldr_init(__noprint); + + if (error002fix!=0) { + /* ERROR 002 fix (thanks to WiiPower for sharing this)*/ + *(u32 *)0x80003140 = *(u32 *)0x80003188; + } + + if (cheat) { + /*HOOKS STUFF - FISHEARS*/ + memset((void*)0x80001800,0,kenobiwii_size); + memcpy((void*)0x80001800,kenobiwii,kenobiwii_size); + DCFlushRange((void*)0x80001800,kenobiwii_size); + hooktype = 1; + memcpy((void*)0x80001800, (char*)0x80000000, 6); // For WiiRD + /*HOOKS STUFF - FISHEARS*/ + } + + for (;;) { + void *dst = NULL; + int len = 0, offset = 0; + + /* Run apploader main function */ + ret = appldr_main(&dst, &len, &offset); + if (!ret) + break; + + /* Read data from DVD */ + WDVD_Read(dst, len, (u64)(offset << 2)); + + gamepatches(dst, len, videoSelected, patchcountrystring, vipatch); + + DCFlushRange(dst, len); + } + + *entry = appldr_final(); + + /** Load alternate dol if set **/ + if (alternatedol == 1) { + void *dolbuffer; + int dollen; + + bool dolloaded = Load_Dol(&dolbuffer, &dollen, Settings.dolpath); + if (dolloaded) { + Remove_001_Protection(dolbuffer, dollen); + + DCFlushRange(dolbuffer, dollen); + + gamepatches(dolbuffer, dollen, videoSelected, patchcountrystring, vipatch); + + DCFlushRange(dolbuffer, dollen); + + /* Set entry point from apploader */ + *entry = (entry_point) load_dol_image(dolbuffer); + } + } else if (alternatedol == 2) { + + FST_ENTRY *fst = (FST_ENTRY *)*(u32 *)0x80000038; + + *entry = (entry_point) Load_Dol_from_disc(fst[alternatedoloffset].fileoffset, videoSelected, patchcountrystring, vipatch); + + if (*entry == 0) + SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); + } + + return 0; +}