* Fixed Ocarina download from Geckocodes issue2253 (Thanks Gave92)

* Added a check for downloaded Ocarina content (Thanks Airline38)
* Removed Error #002 setting (Always set to Anti)
This commit is contained in:
Cyan 2014-05-05 18:35:19 +00:00
parent e1b58a73ce
commit 9a78c7a1a9
12 changed files with 46 additions and 135 deletions

View File

@ -2,8 +2,8 @@
<app version="1"> <app version="1">
<name> USB Loader GX</name> <name> USB Loader GX</name>
<coder>USB Loader GX Team</coder> <coder>USB Loader GX Team</coder>
<version>3.0 r1224</version> <version>3.0 r1225</version>
<release_date>20140504153530</release_date> <release_date>20140505182616</release_date>
<!-- // remove this line to enable arguments <!-- // remove this line to enable arguments
<arguments> <arguments>
<arg>--ios=250</arg> <arg>--ios=250</arg>

View File

@ -25,6 +25,7 @@ static s32 send_message(s32 server, char *msg)
if ((bytes_transferred = net_write(server, msg, remaining > NET_BUFFER_SIZE ? NET_BUFFER_SIZE : remaining)) > 0) if ((bytes_transferred = net_write(server, msg, remaining > NET_BUFFER_SIZE ? NET_BUFFER_SIZE : remaining)) > 0)
{ {
remaining -= bytes_transferred; remaining -= bytes_transferred;
msg += bytes_transferred;
usleep(20 * 1000); usleep(20 * 1000);
} }
else if (bytes_transferred < 0) else if (bytes_transferred < 0)
@ -46,7 +47,7 @@ static s32 send_message(s32 server, char *msg)
* @param u32 the port to connect to on the server * @param u32 the port to connect to on the server
* @return s32 The connection to the server (negative number if connection could not be established) * @return s32 The connection to the server (negative number if connection could not be established)
*/ */
static s32 server_connect(u32 ipaddress, u32 socket_port) static s32 server_connect(u32 ipaddress, u16 socket_port)
{ {
//Initialize socket //Initialize socket
s32 connection = net_socket(AF_INET, SOCK_STREAM, IPPROTO_IP); s32 connection = net_socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
@ -55,7 +56,7 @@ static s32 server_connect(u32 ipaddress, u32 socket_port)
struct sockaddr_in connect_addr; struct sockaddr_in connect_addr;
memset(&connect_addr, 0, sizeof(connect_addr)); memset(&connect_addr, 0, sizeof(connect_addr));
connect_addr.sin_family = AF_INET; connect_addr.sin_family = AF_INET;
connect_addr.sin_port = socket_port; connect_addr.sin_port = htons(socket_port);
connect_addr.sin_addr.s_addr = ipaddress; connect_addr.sin_addr.s_addr = ipaddress;
sprintf(incommingIP, "%s", inet_ntoa(connect_addr.sin_addr)); sprintf(incommingIP, "%s", inet_ntoa(connect_addr.sin_addr));
@ -199,11 +200,18 @@ struct block downloadfile(const char *url)
return emptyblock; return emptyblock;
} }
// Remove Referer from the request header for incompatible websites (ex. Cloudflare proxy)
char referer[domainlength + 12];
snprintf(referer, sizeof(referer), "Referer: %s\r\n", domain);
if(strstr(url, "geckocodes"))
{
strcpy(referer, "");
}
//Form a nice request header to send to the webserver //Form a nice request header to send to the webserver
char* headerformat = "GET %s HTTP/1.0\r\nHost: %s\r\nReferer: %s\r\n%sUser-Agent: USBLoaderGX r%s\r\n\r\n"; char* headerformat = "GET %s HTTP/1.0\r\nHost: %s\r\n%sUser-Agent: USBLoaderGX r%s\r\n\r\n";
char header[strlen(headerformat) + strlen(path) + strlen(domain)*2 + 100]; char header[strlen(headerformat) + strlen(path) + strlen(domain) + strlen(referer) + 100];
sprintf(header, headerformat, path, domain, domain, GetRev()); sprintf(header, headerformat, path, domain, referer, GetRev());
//gprintf("\nHTTP Request:\n"); //gprintf("\nHTTP Request:\n");
//gprintf("%s\n",header); //gprintf("%s\n",header);
@ -245,10 +253,10 @@ struct block downloadfile(const char *url)
//gprintf("HTTP response code: %d\n", code); //gprintf("HTTP response code: %d\n", code);
if (code == 302) // 302 FOUND (redirected link) if (code == 302) // 302 FOUND (redirected link)
{ {
char *ptr = strstr((char*)response.data, "ocation: "); // location or Location char *ptr = strcasestr((char*)response.data, "Location: ");
if(ptr) if(ptr)
{ {
ptr += strlen("ocation: "); ptr += strlen("Location: ");
strncpy(newURL, ptr, sizeof(newURL)); strncpy(newURL, ptr, sizeof(newURL));
*(strchr(newURL, '\r'))=0; *(strchr(newURL, '\r'))=0;

View File

@ -50,7 +50,7 @@ void ClearDOLList()
} }
void gamepatches(u8 videoSelected, u8 videoPatchDol, u8 aspectForce, u8 languageChoice, u8 patchcountrystring, void gamepatches(u8 videoSelected, u8 videoPatchDol, u8 aspectForce, u8 languageChoice, u8 patchcountrystring,
u8 vipatch, u8 sneekVideoPatch, u8 hooktype, u8 fix002, u64 returnTo) u8 vipatch, u8 sneekVideoPatch, u8 hooktype, u64 returnTo)
{ {
int i; int i;
@ -82,8 +82,7 @@ void gamepatches(u8 videoSelected, u8 videoPatchDol, u8 aspectForce, u8 language
do_wip_code(dst, len); do_wip_code(dst, len);
if (fix002 == 2) Anti_002_fix(dst, len);
Anti_002_fix(dst, len);
if(returnTo) if(returnTo)
PatchReturnTo(dst, len, (u32) returnTo); PatchReturnTo(dst, len, (u32) returnTo);
@ -96,8 +95,7 @@ void gamepatches(u8 videoSelected, u8 videoPatchDol, u8 aspectForce, u8 language
} }
/* ERROR 002 fix (thanks to WiiPower for sharing this)*/ /* ERROR 002 fix (thanks to WiiPower for sharing this)*/
if (fix002 != 0) *(u32 *)0x80003140 = *(u32 *)0x80003188;
*(u32 *)0x80003140 = *(u32 *)0x80003188;
DCFlushRange((void*) 0x80000000, 0x3f00); DCFlushRange((void*) 0x80000000, 0x3f00);

View File

@ -10,7 +10,7 @@ extern "C" {
void RegisterDOL(u8 *dst, int len); void RegisterDOL(u8 *dst, int len);
void ClearDOLList(); void ClearDOLList();
void gamepatches(u8 videoSelected, u8 videoPatchDol, u8 aspectForce, u8 languageChoice, u8 patchcountrystring, void gamepatches(u8 videoSelected, u8 videoPatchDol, u8 aspectForce, u8 languageChoice, u8 patchcountrystring,
u8 vipatch, u8 sneekVideoPatch, u8 hooktype, u8 fix002, u64 returnTo); u8 vipatch, u8 sneekVideoPatch, u8 hooktype, u64 returnTo);
bool Anti_002_fix(u8 * Address, int Size); bool Anti_002_fix(u8 * Address, int Size);
bool NSMBPatch(); bool NSMBPatch();
bool PoPPatch(); bool PoPPatch();

View File

@ -1371,13 +1371,6 @@ bool NetworkInitPrompt()
return success; return success;
} }
/*
static size_t writedata(void *ptr, size_t size, size_t nmemb, void *stream)
{
int written = fwrite(ptr, size, nmemb, (FILE *)stream);
return written;
}
*/
int CodeDownload(const char *id) int CodeDownload(const char *id)
{ {
if (!CreateSubfolder(Settings.TxtCheatcodespath)) if (!CreateSubfolder(Settings.TxtCheatcodespath))
@ -1472,62 +1465,7 @@ int CodeDownload(const char *id)
char codeurl[250]; char codeurl[250];
snprintf(codeurl, sizeof(codeurl), "http://geckocodes.org/txt.php?txt=%s", id); snprintf(codeurl, sizeof(codeurl), "http://geckocodes.org/txt.php?txt=%s", id);
//snprintf(codeurl, sizeof(codeurl), "http://geckocodes.org/codes/G/%s.txt", id); //snprintf(codeurl, sizeof(codeurl), "http://geckocodes.org/codes/G/%s.txt", id);
/* //// preparation for lib cURL - Thanks airline38
CURL *curl_handle;
// Forge cURL header - needed for cloudflare proxy
char useragent[20];
snprintf(useragent, sizeof(useragent), "USBLoaderGX r%s", GetRev());
curl_handle = curl_easy_init();
curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, useragent);
curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl_handle, CURLOPT_URL, codeurl);
curl_easy_setopt(curl_handle, CURLOPT_HTTPGET, 1); // needed?
FILE * pfile = fopen(txtpath, "wb");
if(pfile)
{
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, writedata);
curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)pfile);
curl_easy_perform(curl_handle);
fclose(pfile);
// verify downloaded content
pfile = fopen(txtpath, "rb");
char target[4];
fseek(pfile,0,SEEK_SET);
fread(target, sizeof(char), 4, pfile);
fclose(pfile);
//printf("target=%s game id=%s\n",target,id);
if (strncmp(target,id,4)== 0 )
{
snprintf(txtpath, sizeof(txtpath), "%s%s", txtpath, tr(" has been Saved. The text has not been verified. Some of the code may not work right with each other. If you experience trouble, open the text in a real text editor for more information." ));
WindowPrompt(0, txtpath, tr( "OK" ));
curl_easy_cleanup(curl_handle);
curl_global_cleanup();
ret = 0;
}
else
{
RemoveFile(txtpath);
snprintf(codeurl, sizeof(codeurl), "%s%s", codeurl, tr( " is not on the server." ));
WindowPrompt(tr( "Error" ), codeurl, tr( "OK" ));
}
}
else
{
snprintf(codeurl, sizeof(codeurl), "%s%s", codeurl, tr(" could not be downloaded."));
WindowPrompt(tr( "Error" ), codeurl, tr( "OK" ));
}
curl_easy_cleanup(curl_handle);
curl_global_cleanup();
/////
*/
struct block file = downloadfile(codeurl); struct block file = downloadfile(codeurl);
if (file.data != NULL) if (file.data != NULL)
@ -1557,9 +1495,29 @@ int CodeDownload(const char *id)
{ {
fwrite(file.data, 1, file.size, pfile); fwrite(file.data, 1, file.size, pfile);
fclose(pfile); fclose(pfile);
snprintf(txtpath, sizeof(txtpath), "%s%s", txtpath, tr(" has been Saved. The text has not been verified. Some of the code may not work right with each other. If you experience trouble, open the text in a real text editor for more information." ));
WindowPrompt(0, txtpath, tr( "OK" )); // verify downloaded content - thanks airline38
ret = 0; pfile = fopen(txtpath, "rb");
if(pfile)
{
char target[4];
fseek(pfile,0,SEEK_SET);
fread(target, sizeof(char), 4, pfile);
fclose(pfile);
//printf("target=%s game id=%s\n",target,id);
if (strncmp(target,id,4)== 0 )
{
snprintf(txtpath, sizeof(txtpath), "%s%s", txtpath, tr(" has been Saved. The text has not been verified. Some of the code may not work right with each other. If you experience trouble, open the text in a real text editor for more information." ));
WindowPrompt(0, txtpath, tr( "OK" ));
ret = 0;
}
else
{
RemoveFile(txtpath);
snprintf(codeurl, sizeof(codeurl), "%s%s", codeurl, tr( " is not on the server." ));
WindowPrompt(tr( "Error" ), codeurl, tr( "OK" ));
}
}
} }
else else
WindowPrompt(tr("Error"), tr("Could not write file."), tr( "OK" )); WindowPrompt(tr("Error"), tr("Could not write file."), tr( "OK" ));

View File

@ -194,7 +194,6 @@ bool CGameSettings::Save()
fprintf(f, "vipatch:%d; ", GameList[i].vipatch); fprintf(f, "vipatch:%d; ", GameList[i].vipatch);
fprintf(f, "ios:%d; ", GameList[i].ios); fprintf(f, "ios:%d; ", GameList[i].ios);
fprintf(f, "parentalcontrol:%d; ", GameList[i].parentalcontrol); fprintf(f, "parentalcontrol:%d; ", GameList[i].parentalcontrol);
fprintf(f, "errorfix002:%d; ", GameList[i].errorfix002);
fprintf(f, "iosreloadblock:%d; ", GameList[i].iosreloadblock); fprintf(f, "iosreloadblock:%d; ", GameList[i].iosreloadblock);
fprintf(f, "patchcountrystrings:%d; ", GameList[i].patchcountrystrings); fprintf(f, "patchcountrystrings:%d; ", GameList[i].patchcountrystrings);
fprintf(f, "loadalternatedol:%d; ", GameList[i].loadalternatedol); fprintf(f, "loadalternatedol:%d; ", GameList[i].loadalternatedol);
@ -275,11 +274,6 @@ bool CGameSettings::SetSetting(GameCFG & game, const char *name, const char *val
game.parentalcontrol = atoi(value); game.parentalcontrol = atoi(value);
return true; return true;
} }
else if(strcmp(name, "errorfix002") == 0)
{
game.errorfix002 = atoi(value);
return true;
}
else if(strcmp(name, "iosreloadblock") == 0) else if(strcmp(name, "iosreloadblock") == 0)
{ {
game.iosreloadblock = atoi(value); game.iosreloadblock = atoi(value);
@ -544,7 +538,6 @@ void CGameSettings::SetDefault(GameCFG &game)
game.vipatch = INHERIT; game.vipatch = INHERIT;
game.ios = INHERIT; game.ios = INHERIT;
game.parentalcontrol = PARENTAL_LVL_EVERYONE; game.parentalcontrol = PARENTAL_LVL_EVERYONE;
game.errorfix002 = INHERIT;
game.patchcountrystrings = INHERIT; game.patchcountrystrings = INHERIT;
game.loadalternatedol = ALT_DOL_DEFAULT; game.loadalternatedol = ALT_DOL_DEFAULT;
game.alternatedolstart = 0; game.alternatedolstart = 0;

View File

@ -18,7 +18,6 @@ typedef struct _GameCFG
short vipatch; short vipatch;
short ios; short ios;
short parentalcontrol; short parentalcontrol;
short errorfix002;
short iosreloadblock; short iosreloadblock;
short loadalternatedol; short loadalternatedol;
u32 alternatedolstart; u32 alternatedolstart;
@ -62,7 +61,6 @@ typedef struct _GameCFG
this->vipatch = game.vipatch; this->vipatch = game.vipatch;
this->ios = game.ios; this->ios = game.ios;
this->parentalcontrol = game.parentalcontrol; this->parentalcontrol = game.parentalcontrol;
this->errorfix002 = game.errorfix002;
this->iosreloadblock = game.iosreloadblock; this->iosreloadblock = game.iosreloadblock;
this->loadalternatedol = game.loadalternatedol; this->loadalternatedol = game.loadalternatedol;
this->alternatedolstart = game.alternatedolstart; this->alternatedolstart = game.alternatedolstart;

View File

@ -109,7 +109,6 @@ void CSettings::SetDefault()
LoaderIOS = BUILD_IOS; LoaderIOS = BUILD_IOS;
cios = BUILD_IOS; cios = BUILD_IOS;
gridRows = 3; gridRows = 3;
error002 = 2;
partition = 0; partition = 0;
discart = DISCARTS_ORIGINALS_CUSTOMS; discart = DISCARTS_ORIGINALS_CUSTOMS;
coversfull = COVERSFULL_HQ; coversfull = COVERSFULL_HQ;
@ -331,7 +330,6 @@ bool CSettings::Save()
fprintf(file, "patchcountrystrings = %d\n", patchcountrystrings); fprintf(file, "patchcountrystrings = %d\n", patchcountrystrings);
fprintf(file, "screensaver = %d\n", screensaver); fprintf(file, "screensaver = %d\n", screensaver);
fprintf(file, "musicloopmode = %d\n", musicloopmode); fprintf(file, "musicloopmode = %d\n", musicloopmode);
fprintf(file, "error002 = %d\n", error002);
fprintf(file, "autonetwork = %d\n", autonetwork); fprintf(file, "autonetwork = %d\n", autonetwork);
fprintf(file, "discart = %d\n", discart); fprintf(file, "discart = %d\n", discart);
fprintf(file, "coversfull = %d\n", coversfull); fprintf(file, "coversfull = %d\n", coversfull);
@ -669,11 +667,6 @@ bool CSettings::SetSetting(char *name, char *value)
coversfull = atoi(value); coversfull = atoi(value);
return true; return true;
} }
else if (strcmp(name, "error002") == 0)
{
error002 = atoi(value);
return true;
}
else if (strcmp(name, "autonetwork") == 0) else if (strcmp(name, "autonetwork") == 0)
{ {
autonetwork = atoi(value); autonetwork = atoi(value);

View File

@ -117,7 +117,6 @@ class CSettings
short partition; short partition;
short musicloopmode; short musicloopmode;
short godmode; short godmode;
short error002;
short titlesOverride; // db_titles short titlesOverride; // db_titles
short gridRows; short gridRows;
short autonetwork; short autonetwork;

View File

@ -84,13 +84,6 @@ static const char * LanguageText[] =
trNOOP( "Console Default" ), trNOOP( "Console Default" ),
}; };
static const char * Error002Text[] =
{
trNOOP( "No" ),
trNOOP( "Yes" ),
trNOOP( "Anti" )
};
static const char * ParentalText[] = static const char * ParentalText[] =
{ {
trNOOP( "0 (Everyone)" ), trNOOP( "0 (Everyone)" ),
@ -293,12 +286,6 @@ void GameLoadSM::SetOptionValues()
else else
Options->SetValue(Idx++, "%i", GameConfig.ios); Options->SetValue(Idx++, "%i", GameConfig.ios);
//! Settings: Error 002 fix
if(GameConfig.errorfix002 == INHERIT)
Options->SetValue(Idx++, tr("Use global"));
else
Options->SetValue(Idx++, "%s", tr(Error002Text[GameConfig.errorfix002]));
//! Settings: Return To //! Settings: Return To
if(GameConfig.returnTo) if(GameConfig.returnTo)
{ {
@ -488,12 +475,6 @@ int GameLoadSM::GetMenuInternal()
} }
} }
//! Settings: Error 002 fix
else if (ret == ++Idx)
{
if (++GameConfig.errorfix002 >= 3) GameConfig.errorfix002 = INHERIT;
}
//! Settings: Return To //! Settings: Return To
else if (ret == ++Idx) else if (ret == ++Idx)
{ {

View File

@ -87,13 +87,6 @@ static const char * LanguageText[] =
trNOOP( "Console Default" ) trNOOP( "Console Default" )
}; };
static const char * Error002Text[] =
{
trNOOP( "No" ),
trNOOP( "Yes" ),
trNOOP( "Anti" )
};
static const char * NandEmuText[] = static const char * NandEmuText[] =
{ {
trNOOP( "OFF" ), trNOOP( "OFF" ),
@ -298,9 +291,6 @@ void LoaderSettings::SetOptionValues()
//! Settings: Quick Boot //! Settings: Quick Boot
Options->SetValue(Idx++, "%s", tr( OnOffText[Settings.quickboot] )); Options->SetValue(Idx++, "%s", tr( OnOffText[Settings.quickboot] ));
//! Settings: Error 002 fix
Options->SetValue(Idx++, "%s", tr( Error002Text[Settings.error002] ));
//! Settings: Block IOS Reload //! Settings: Block IOS Reload
Options->SetValue(Idx++, "%s", tr( OnOffText[Settings.BlockIOSReload] )); Options->SetValue(Idx++, "%s", tr( OnOffText[Settings.BlockIOSReload] ));
@ -523,12 +513,6 @@ int LoaderSettings::GetMenuInternal()
if (++Settings.quickboot >= MAX_ON_OFF) Settings.quickboot = 0; if (++Settings.quickboot >= MAX_ON_OFF) Settings.quickboot = 0;
} }
//! Settings: Error 002 fix
else if (ret == ++Idx )
{
if (++Settings.error002 >= 3) Settings.error002 = 0;
}
//! Settings: Block IOS Reload //! Settings: Block IOS Reload
else if (ret == ++Idx ) else if (ret == ++Idx )
{ {

View File

@ -270,7 +270,6 @@ int GameBooter::BootGame(struct discHdr *gameHdr)
u8 viChoice = game_cfg->vipatch == INHERIT ? Settings.videopatch : game_cfg->vipatch; u8 viChoice = game_cfg->vipatch == INHERIT ? Settings.videopatch : game_cfg->vipatch;
u8 sneekChoice = game_cfg->sneekVideoPatch == INHERIT ? Settings.sneekVideoPatch : game_cfg->sneekVideoPatch; u8 sneekChoice = game_cfg->sneekVideoPatch == INHERIT ? Settings.sneekVideoPatch : game_cfg->sneekVideoPatch;
u8 iosChoice = game_cfg->ios == INHERIT ? Settings.cios : game_cfg->ios; u8 iosChoice = game_cfg->ios == INHERIT ? Settings.cios : game_cfg->ios;
u8 fix002 = game_cfg->errorfix002 == INHERIT ? Settings.error002 : game_cfg->errorfix002;
u8 countrystrings = game_cfg->patchcountrystrings == INHERIT ? Settings.patchcountrystrings : game_cfg->patchcountrystrings; u8 countrystrings = game_cfg->patchcountrystrings == INHERIT ? Settings.patchcountrystrings : game_cfg->patchcountrystrings;
u8 alternatedol = game_cfg->loadalternatedol; u8 alternatedol = game_cfg->loadalternatedol;
u32 alternatedoloffset = game_cfg->alternatedolstart; u32 alternatedoloffset = game_cfg->alternatedolstart;
@ -405,7 +404,7 @@ int GameBooter::BootGame(struct discHdr *gameHdr)
//! Do all the game patches //! Do all the game patches
gprintf("Applying game patches...\n"); gprintf("Applying game patches...\n");
gamepatches(videoChoice, videoPatchDolChoice, aspectChoice, languageChoice, countrystrings, viChoice, sneekChoice, Hooktype, fix002, returnToChoice); gamepatches(videoChoice, videoPatchDolChoice, aspectChoice, languageChoice, countrystrings, viChoice, sneekChoice, Hooktype, returnToChoice);
//! Load Code handler if needed //! Load Code handler if needed
load_handler(Hooktype, WiirdDebugger, Settings.WiirdDebuggerPause); load_handler(Hooktype, WiirdDebugger, Settings.WiirdDebuggerPause);