2009-10-01 01:10:58 +02:00
|
|
|
/*
|
|
|
|
* 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 <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <gccore.h>
|
|
|
|
#include <malloc.h>
|
|
|
|
#include <sys/unistd.h>
|
|
|
|
#include <sdcard/wiisd_io.h>
|
|
|
|
#include <ogc/ipc.h>
|
|
|
|
|
|
|
|
#include "settings/cfg.h"
|
|
|
|
#include "fst.h"
|
|
|
|
#include "dvd_broadway.h"
|
|
|
|
#include "wpad.h"
|
|
|
|
#include "fatmounter.h"
|
2009-12-04 16:05:20 +01:00
|
|
|
#include "sys.h"
|
2009-12-11 00:05:32 +01:00
|
|
|
#include "../gecko.h"
|
2009-12-04 16:05:20 +01:00
|
|
|
#include "mload/mload.h"
|
|
|
|
#include "mload/dip_plugin.h"
|
2009-12-15 07:04:14 +01:00
|
|
|
#include "patches/wip.h"
|
2009-10-01 01:10:58 +02:00
|
|
|
|
|
|
|
extern struct SSettings Settings;
|
|
|
|
|
2009-11-15 20:52:58 +01:00
|
|
|
// Pre-allocate the buffer size for ocarina codes
|
|
|
|
u8 filebuff[MAX_GCT_SIZE];
|
|
|
|
|
2010-02-09 11:59:55 +01:00
|
|
|
u32 do_sd_code(char *filename)
|
|
|
|
{
|
|
|
|
gprintf("\ndo_sd_code(%s)",filename);
|
|
|
|
printf("\ndo_sd_code(%s)",filename);
|
2009-12-11 00:05:32 +01:00
|
|
|
|
2010-02-09 11:59:55 +01:00
|
|
|
FILE *fp;
|
|
|
|
//u8 *filebuff;
|
|
|
|
u32 filesize;
|
|
|
|
u32 ret;
|
|
|
|
char filepath[150];
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2009-12-11 00:05:32 +01:00
|
|
|
//SDCard_Init();
|
2010-02-09 11:59:55 +01:00
|
|
|
//USBDevice_Init();
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-02-09 11:59:55 +01:00
|
|
|
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;
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-02-09 11:59:55 +01:00
|
|
|
fp = fopen(filepath, "rb");
|
|
|
|
if (!fp) {
|
2009-10-01 01:10:58 +02:00
|
|
|
USBDevice_deInit();
|
|
|
|
SDCard_deInit();
|
2010-02-09 11:59:55 +01:00
|
|
|
gprintf("\n\tcan't open %s",filepath);
|
|
|
|
printf("\n\tcan't open %s",filepath);
|
|
|
|
sleep(10);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
fseek(fp, 0, SEEK_END);
|
|
|
|
filesize = ftell(fp);
|
|
|
|
if(filesize <= 16 || filesize>MAX_GCT_SIZE){
|
|
|
|
fclose(fp);
|
|
|
|
sleep(2);
|
2009-10-01 01:10:58 +02:00
|
|
|
USBDevice_deInit();
|
|
|
|
SDCard_deInit();
|
2010-02-09 11:59:55 +01:00
|
|
|
gprintf("\n\tError. size = %d",filesize);
|
|
|
|
printf("\n\tError. size = %d",filesize);
|
|
|
|
sleep(10);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
fseek(fp, 0, SEEK_SET);
|
|
|
|
|
|
|
|
|
|
|
|
ret = fread(&filebuff, 1, filesize, fp);
|
|
|
|
if(ret != filesize){
|
|
|
|
fclose(fp);
|
2009-10-01 01:10:58 +02:00
|
|
|
USBDevice_deInit();
|
|
|
|
SDCard_deInit();
|
2010-02-09 11:59:55 +01:00
|
|
|
gprintf("\n\tError. ret != size");
|
|
|
|
printf("\n\tError. ret != size");
|
|
|
|
sleep(10);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
fclose(fp);
|
|
|
|
//USBDevice_deInit();
|
2009-12-11 00:05:32 +01:00
|
|
|
//SDCard_deInit();
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2009-11-15 20:52:58 +01:00
|
|
|
memcpy((void*)0x800027E8, &filebuff,filesize);
|
2009-10-01 01:10:58 +02:00
|
|
|
*(vu8*)0x80001807 = 0x01;
|
2010-02-09 11:59:55 +01:00
|
|
|
//gprintf("\n\tDe-init SD & USB");
|
|
|
|
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-02-09 11:59:55 +01:00
|
|
|
|
|
|
|
gprintf("\n\tDone");
|
|
|
|
printf("...Done");
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-02-09 11:59:55 +01:00
|
|
|
return 1;
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
2010-02-09 11:59:55 +01:00
|
|
|
u32 do_bca_code(u8 *gameid)
|
|
|
|
{
|
|
|
|
if (IOS_GetVersion() == 222 || IOS_GetVersion() == 223)
|
|
|
|
{
|
|
|
|
FILE *fp;
|
|
|
|
u32 filesize;
|
|
|
|
char filepath[150];
|
|
|
|
memset(filepath, 0, 150);
|
|
|
|
u8 bcaCode[64] ATTRIBUTE_ALIGN(32);
|
|
|
|
|
|
|
|
sprintf(filepath, "%s%6s", Settings.BcaCodepath, gameid);
|
|
|
|
filepath[strlen(Settings.BcaCodepath)+6] = '.';
|
|
|
|
filepath[strlen(Settings.BcaCodepath)+7] = 'b';
|
|
|
|
filepath[strlen(Settings.BcaCodepath)+8] = 'c';
|
|
|
|
filepath[strlen(Settings.BcaCodepath)+9] = 'a';
|
|
|
|
|
|
|
|
fp = fopen(filepath, "rb");
|
|
|
|
if (!fp) {
|
|
|
|
memset(filepath, 0, 150);
|
|
|
|
sprintf(filepath, "%s%3s", Settings.BcaCodepath, gameid + 1);
|
|
|
|
filepath[strlen(Settings.BcaCodepath)+3] = '.';
|
|
|
|
filepath[strlen(Settings.BcaCodepath)+4] = 'b';
|
|
|
|
filepath[strlen(Settings.BcaCodepath)+5] = 'c';
|
|
|
|
filepath[strlen(Settings.BcaCodepath)+6] = 'a';
|
|
|
|
fp = fopen(filepath, "rb");
|
|
|
|
|
|
|
|
if (!fp) {
|
|
|
|
// Set default bcaCode
|
|
|
|
memset(bcaCode, 0, 64);
|
|
|
|
bcaCode[0x33] = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fp) {
|
|
|
|
u32 ret = 0;
|
|
|
|
|
|
|
|
fseek(fp, 0, SEEK_END);
|
|
|
|
filesize = ftell(fp);
|
|
|
|
|
|
|
|
if (filesize == 64) {
|
|
|
|
fseek(fp, 0, SEEK_SET);
|
|
|
|
ret = fread(bcaCode, 1, 64, fp);
|
|
|
|
}
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
if (ret != 64) {
|
|
|
|
// Set default bcaCode
|
|
|
|
memset(bcaCode, 0, 64);
|
|
|
|
bcaCode[0x33] = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mload_seek(*((u32 *) (dip_plugin+15*4)), SEEK_SET); // offset 15 (bca_data area)
|
|
|
|
mload_write(bcaCode, 64);
|
|
|
|
mload_close();
|
|
|
|
}
|
|
|
|
return 0;
|
2009-12-04 16:05:20 +01:00
|
|
|
}
|