2012-02-20 09:26:50 +01:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2012
|
2012-02-24 22:08:24 +01:00
|
|
|
* by OverjoY and FIX94 for Wiiflow
|
2012-02-20 09:26:50 +01:00
|
|
|
*
|
|
|
|
* This software is provided 'as-is', without any express or implied
|
|
|
|
* warranty. In no event will the authors be held liable for any
|
|
|
|
* damages arising from the use of this software.
|
|
|
|
*
|
|
|
|
* Permission is granted to anyone to use this software for any
|
|
|
|
* purpose, including commercial applications, and to alter it and
|
|
|
|
* redistribute it freely, subject to the following restrictions:
|
|
|
|
*
|
|
|
|
* 1. The origin of this software must not be misrepresented; you
|
|
|
|
* must not claim that you wrote the original software. If you use
|
|
|
|
* this software in a product, an acknowledgment in the product
|
|
|
|
* documentation would be appreciated but is not required.
|
|
|
|
*
|
|
|
|
* 2. Altered source versions must be plainly marked as such, and
|
|
|
|
* must not be misrepresented as being the original software.
|
|
|
|
*
|
|
|
|
* 3. This notice may not be removed or altered from any source
|
|
|
|
* distribution.
|
|
|
|
*
|
2012-07-06 02:36:45 +02:00
|
|
|
* gc_disc_dump.cpp
|
2012-02-20 09:26:50 +01:00
|
|
|
*
|
|
|
|
***************************************************************************/
|
2012-02-17 03:35:42 +01:00
|
|
|
#include <stdio.h>
|
2012-02-29 01:19:50 +01:00
|
|
|
#include <unistd.h>
|
2012-02-17 03:35:42 +01:00
|
|
|
#include <ogcsys.h>
|
2012-02-20 09:26:50 +01:00
|
|
|
#include <sys/statvfs.h>
|
2012-02-17 03:35:42 +01:00
|
|
|
|
2012-07-06 02:36:45 +02:00
|
|
|
#include "gc_disc_dump.hpp"
|
2012-02-17 03:35:42 +01:00
|
|
|
#include "disc.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "wdvd.h"
|
2012-08-05 15:48:15 +02:00
|
|
|
#include "devicemounter/DeviceHandler.hpp"
|
|
|
|
#include "fileOps/fileOps.h"
|
2012-12-08 17:17:35 +01:00
|
|
|
#include "gecko/gecko.hpp"
|
2013-12-21 18:02:36 +01:00
|
|
|
#include "hw/Gekko.h"
|
2012-08-05 15:48:15 +02:00
|
|
|
#include "gui/text.hpp"
|
|
|
|
#include "memory/mem2.hpp"
|
2013-06-26 23:35:38 +02:00
|
|
|
#include "menu/menu.hpp"
|
2018-11-12 21:38:37 +01:00
|
|
|
|
2012-02-28 19:44:41 +01:00
|
|
|
using namespace std;
|
|
|
|
|
2012-08-19 11:45:57 +02:00
|
|
|
static u8 *FSTable ATTRIBUTE_ALIGN(32);
|
2012-02-20 09:26:50 +01:00
|
|
|
|
2012-03-09 19:15:07 +01:00
|
|
|
void GCDump::__AnalizeMultiDisc()
|
|
|
|
{
|
2012-08-19 11:45:57 +02:00
|
|
|
u8 *Buffer = (u8 *)MEM2_memalign(32, ALIGN32(0x10));
|
2012-05-13 19:25:26 +02:00
|
|
|
if(Buffer == NULL)
|
|
|
|
return;
|
|
|
|
|
2012-03-09 19:15:07 +01:00
|
|
|
MultiGameCnt = 0;
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
__DiscReadRaw(Buffer, 0x40+(MultiGameCnt*4), 4);
|
|
|
|
u64 MultiGameOffset = *(vu32*)(Buffer) << 2;
|
|
|
|
if(!MultiGameOffset)
|
2012-08-19 11:45:57 +02:00
|
|
|
break;
|
2012-03-09 19:15:07 +01:00
|
|
|
|
|
|
|
if(MultiGameDump == MultiGameCnt)
|
|
|
|
NextOffset = MultiGameOffset;
|
|
|
|
MultiGameCnt++;
|
|
|
|
}
|
2012-08-19 11:45:57 +02:00
|
|
|
MEM2_free(Buffer);
|
2012-03-09 19:15:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
s32 GCDump::__DiscReadRaw(void *outbuf, u64 offset, u32 length)
|
2012-07-27 19:26:49 +02:00
|
|
|
{
|
2012-08-19 11:45:57 +02:00
|
|
|
length = ALIGN32(length);
|
|
|
|
wiiLightOn();
|
2012-02-20 09:26:50 +01:00
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
gc_error = 0;
|
|
|
|
s32 ret = WDVD_UnencryptedRead(outbuf, length, offset);
|
2012-07-27 19:26:49 +02:00
|
|
|
if(ret != 0)
|
2012-02-20 09:26:50 +01:00
|
|
|
{
|
2012-08-19 11:45:57 +02:00
|
|
|
WDVD_LowRequestError(&gc_error);
|
2012-02-20 09:26:50 +01:00
|
|
|
if(gc_error == 0x30200 || gc_error == 0x30201 || gc_error == 0x31100)
|
|
|
|
{
|
2012-03-09 03:47:41 +01:00
|
|
|
if(gc_retry >= gc_nbrretry && waitonerror)
|
|
|
|
{
|
|
|
|
__WaitForDisc(Disc, 10);
|
|
|
|
gc_retry = 0;
|
|
|
|
waitonerror = false;
|
|
|
|
if(FSTTotal > FSTSize)
|
2013-06-26 23:35:38 +02:00
|
|
|
mainMenu.GC_Messenger(4, Disc+1, minfo);
|
2012-03-09 03:47:41 +01:00
|
|
|
else
|
2013-06-26 23:35:38 +02:00
|
|
|
mainMenu.GC_Messenger(3, 0, minfo);
|
2012-03-09 03:47:41 +01:00
|
|
|
}
|
2012-02-20 09:26:50 +01:00
|
|
|
if(gc_retry >= gc_nbrretry)
|
|
|
|
{
|
2012-07-27 19:26:49 +02:00
|
|
|
wiiLightOff();
|
2012-02-20 09:26:50 +01:00
|
|
|
if(!skiponerror)
|
|
|
|
return gc_error;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gc_retry = 0;
|
|
|
|
gc_skipped++;
|
|
|
|
gprintf("Read error (%x) at offset: 0x%08x. Skipping %d bytes\n", gc_error, offset, length);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gc_retry++;
|
|
|
|
}
|
2012-03-09 03:47:41 +01:00
|
|
|
else if(gc_error == 0x1023a00)
|
|
|
|
{
|
|
|
|
__WaitForDisc(Disc, 11);
|
|
|
|
if(FSTTotal > FSTSize)
|
2013-06-26 23:35:38 +02:00
|
|
|
mainMenu.GC_Messenger(4, Disc+1, minfo);
|
2012-03-09 03:47:41 +01:00
|
|
|
else
|
2013-06-26 23:35:38 +02:00
|
|
|
mainMenu.GC_Messenger(3, 0, minfo);
|
2012-03-09 03:47:41 +01:00
|
|
|
}
|
2012-02-20 09:26:50 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
gprintf("Read error(%x) at offset: 0x%08x.\n", gc_error, offset);
|
2012-07-27 19:26:49 +02:00
|
|
|
wiiLightOff();
|
2012-02-20 09:26:50 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-07-27 19:26:49 +02:00
|
|
|
wiiLightOff();
|
2012-02-20 09:26:50 +01:00
|
|
|
gc_retry = 0;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
2012-07-27 19:26:49 +02:00
|
|
|
wiiLightOff();
|
2013-06-30 20:40:49 +02:00
|
|
|
return -1;
|
2012-02-20 09:26:50 +01:00
|
|
|
}
|
|
|
|
|
2012-03-09 19:15:07 +01:00
|
|
|
s32 GCDump::__DiscWrite(char * path, u64 offset, u32 length, u8 *ReadBuffer)
|
2012-02-17 03:35:42 +01:00
|
|
|
{
|
2012-02-20 09:26:50 +01:00
|
|
|
gprintf("__DiscWrite(%s, 0x%08x, %x)\n", path, offset, length);
|
|
|
|
u32 wrote = 0;
|
2012-02-28 16:06:01 +01:00
|
|
|
FILE *f = fopen(path, "wb");
|
|
|
|
|
2012-03-09 03:47:41 +01:00
|
|
|
wrote = __DiscWriteFile(f, offset, length, ReadBuffer);
|
2012-02-20 09:26:50 +01:00
|
|
|
|
2012-05-13 17:13:33 +02:00
|
|
|
fclose(f);
|
2012-02-20 09:26:50 +01:00
|
|
|
return wrote;
|
2012-02-17 03:35:42 +01:00
|
|
|
}
|
|
|
|
|
2012-03-09 19:15:07 +01:00
|
|
|
s32 GCDump::__DiscWriteFile(FILE *f, u64 offset, u32 length, u8 *ReadBuffer)
|
2012-02-20 09:26:50 +01:00
|
|
|
{
|
|
|
|
u32 toread = 0;
|
|
|
|
u32 wrote = 0;
|
2012-02-25 19:27:11 +01:00
|
|
|
|
2012-02-20 09:26:50 +01:00
|
|
|
while(length)
|
|
|
|
{
|
2012-03-07 03:05:57 +01:00
|
|
|
toread = min(length, gc_readsize);
|
2016-12-01 01:05:39 +01:00
|
|
|
mainMenu.update_pThread(toread);
|
2012-08-19 11:45:57 +02:00
|
|
|
s32 ret = __DiscReadRaw(ReadBuffer, offset, toread);
|
2012-02-24 22:08:24 +01:00
|
|
|
if (ret == 1)
|
2012-02-20 09:26:50 +01:00
|
|
|
memset(ReadBuffer, 0, gc_readsize);
|
2012-02-24 22:08:24 +01:00
|
|
|
else if (ret > 1)
|
|
|
|
return 0;
|
2012-02-26 16:03:54 +01:00
|
|
|
fwrite(ReadBuffer, 1, toread, f);
|
|
|
|
wrote += toread;
|
|
|
|
offset += toread;
|
|
|
|
length -= toread;
|
2012-03-07 03:05:57 +01:00
|
|
|
gc_done += toread;
|
2012-02-20 09:26:50 +01:00
|
|
|
}
|
|
|
|
return wrote;
|
|
|
|
}
|
|
|
|
|
2012-03-09 03:47:41 +01:00
|
|
|
bool GCDump::__WaitForDisc(u8 dsc, u32 msg)
|
2012-03-07 03:05:57 +01:00
|
|
|
{
|
2012-08-19 11:45:57 +02:00
|
|
|
u8 *ReadBuffer = (u8 *)MEM2_memalign(32, ALIGN32(0x440));
|
2012-05-13 19:25:26 +02:00
|
|
|
if(ReadBuffer == NULL)
|
|
|
|
return false;
|
|
|
|
|
2012-03-07 03:05:57 +01:00
|
|
|
u32 cover = 0;
|
2012-08-19 11:45:57 +02:00
|
|
|
bool done = false;
|
2012-03-07 03:05:57 +01:00
|
|
|
while(!done)
|
2012-07-27 19:26:49 +02:00
|
|
|
{
|
2013-06-26 23:35:38 +02:00
|
|
|
mainMenu.GC_Messenger(msg, dsc+1, minfo);
|
2012-03-07 03:05:57 +01:00
|
|
|
while(1)
|
|
|
|
{
|
2012-08-19 11:45:57 +02:00
|
|
|
wiiLightOn();
|
2012-07-27 19:26:49 +02:00
|
|
|
usleep(1000000);
|
|
|
|
wiiLightOff();
|
|
|
|
usleep(1000000);
|
2012-03-07 03:05:57 +01:00
|
|
|
WDVD_GetCoverStatus(&cover);
|
|
|
|
if(!(cover & 0x2))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(1)
|
|
|
|
{
|
2012-08-19 11:45:57 +02:00
|
|
|
wiiLightOn();
|
2012-07-27 19:26:49 +02:00
|
|
|
usleep(1000000);
|
|
|
|
wiiLightOff();
|
|
|
|
usleep(1000000);
|
2012-03-07 03:05:57 +01:00
|
|
|
if(Disc_Wait() < 0)
|
|
|
|
continue;
|
|
|
|
|
2012-08-26 14:05:04 +02:00
|
|
|
if(Disc_Open(false) < 0)
|
2012-03-07 03:05:57 +01:00
|
|
|
{
|
2012-08-19 11:45:57 +02:00
|
|
|
MEM2_free(ReadBuffer);
|
2012-03-07 03:05:57 +01:00
|
|
|
return false;
|
|
|
|
}
|
2012-05-13 19:25:26 +02:00
|
|
|
|
2012-03-07 03:05:57 +01:00
|
|
|
if(Disc_IsGC() == 0)
|
|
|
|
{
|
2012-03-17 23:32:53 +01:00
|
|
|
s32 ret = __DiscReadRaw(ReadBuffer, NextOffset, 0x440);
|
2012-03-07 03:05:57 +01:00
|
|
|
if(ret > 0)
|
|
|
|
{
|
2012-08-19 11:45:57 +02:00
|
|
|
MEM2_free(ReadBuffer);
|
2012-03-07 03:05:57 +01:00
|
|
|
return false;
|
|
|
|
}
|
2012-05-13 19:25:26 +02:00
|
|
|
|
2012-03-07 03:05:57 +01:00
|
|
|
ID2 = *(vu32*)(ReadBuffer);
|
|
|
|
Disc2 = *(vu8*)(ReadBuffer+0x06);
|
2012-05-13 19:25:26 +02:00
|
|
|
|
2012-03-07 03:05:57 +01:00
|
|
|
if(ID == ID2 && Disc2 == dsc)
|
2012-08-19 11:45:57 +02:00
|
|
|
{
|
2012-03-07 03:05:57 +01:00
|
|
|
done = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if(ID == ID2 && Disc2 != dsc)
|
|
|
|
{
|
2013-06-26 23:35:38 +02:00
|
|
|
mainMenu.GC_Messenger( 7, Disc2+1, NULL);
|
2012-03-07 03:05:57 +01:00
|
|
|
usleep( 5000000 );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if(ID != ID2)
|
|
|
|
{
|
2013-06-26 23:35:38 +02:00
|
|
|
mainMenu.GC_Messenger( 8, 0, NULL);
|
2012-03-07 03:05:57 +01:00
|
|
|
usleep( 5000000 );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(Disc_IsWii() == 0)
|
|
|
|
{
|
2013-06-26 23:35:38 +02:00
|
|
|
mainMenu.GC_Messenger( 5, 0, NULL);
|
2012-03-07 03:05:57 +01:00
|
|
|
usleep( 5000000 );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-26 23:35:38 +02:00
|
|
|
mainMenu.GC_Messenger( 6, 0, NULL);
|
2012-03-07 03:05:57 +01:00
|
|
|
usleep( 5000000 );
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-08-19 11:45:57 +02:00
|
|
|
MEM2_free(ReadBuffer);
|
2012-03-07 03:05:57 +01:00
|
|
|
return done;
|
|
|
|
}
|
|
|
|
|
2012-07-22 20:02:56 +02:00
|
|
|
bool GCDump::__CheckMDHack(u32 ID)
|
|
|
|
{
|
|
|
|
/********************************************************************/
|
|
|
|
/**** Because some lazy gamedevs don't set a proper max FST size ****/
|
|
|
|
/*** on their first disc some games need a hardcoded hack. Please ***/
|
|
|
|
/****** report unsupported games so we can add an entry for it ******/
|
|
|
|
/********************************************************************/
|
|
|
|
switch(ID >> 8)
|
|
|
|
{
|
|
|
|
case 0x475153: /*** Tales of Symphonia ***/
|
2012-08-31 21:25:49 +02:00
|
|
|
case 0x474b42: /*** Baten Kaitos: Eternal Wings and the Lost Ocean ***/
|
|
|
|
case 0x473341: /*** The Lord of the Rings: The Third Age ***/
|
|
|
|
case 0x473554: /*** Tiger Woods PGA Tour 2005 ***/
|
2013-06-26 23:35:38 +02:00
|
|
|
case 0x473442: /*** Resident Evil 4 ***/
|
2012-07-22 20:02:56 +02:00
|
|
|
return true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-03-09 03:47:41 +01:00
|
|
|
s32 GCDump::DumpGame()
|
2012-08-19 11:45:57 +02:00
|
|
|
{
|
|
|
|
u8 *ReadBuffer = (u8 *)MEM2_memalign(32, ALIGN32(gc_readsize));
|
2012-05-13 19:25:26 +02:00
|
|
|
if(ReadBuffer == NULL)
|
|
|
|
return 0x31100;
|
2012-02-17 03:35:42 +01:00
|
|
|
|
2012-03-07 03:05:57 +01:00
|
|
|
gc_done = 0;
|
2012-03-09 19:15:07 +01:00
|
|
|
gamedone = false;
|
|
|
|
multigamedisc = false;
|
|
|
|
MultiGameDump = 0;
|
|
|
|
MultiGameCnt = 0;
|
|
|
|
NextOffset = 0;
|
|
|
|
Disc = 0;
|
2012-02-29 19:11:35 +01:00
|
|
|
|
2012-11-18 14:40:26 +01:00
|
|
|
char *FSTNameOff = NULL;
|
2012-02-26 16:03:54 +01:00
|
|
|
|
2018-05-29 11:59:57 +02:00
|
|
|
char folder[MAX_FAT_PATH + 76];
|
|
|
|
memset(folder, 0, sizeof(folder));
|
|
|
|
char gamepath[MAX_FAT_PATH + 90];
|
|
|
|
memset(gamepath, 0, sizeof(gamepath));
|
2013-06-26 23:35:38 +02:00
|
|
|
char basedir[MAX_FAT_PATH];
|
2018-05-29 11:59:57 +02:00
|
|
|
memset(basedir, 0, sizeof(basedir));
|
2016-04-03 02:31:02 +02:00
|
|
|
strncpy(basedir, fmt(gc_gamesDir, gamepartition), MAX_FAT_PATH);
|
2012-02-29 19:11:35 +01:00
|
|
|
|
2012-03-09 19:15:07 +01:00
|
|
|
while(!gamedone)
|
2012-02-29 01:19:50 +01:00
|
|
|
{
|
|
|
|
u8 *FSTBuffer;
|
|
|
|
u32 wrote = 0;
|
2012-11-18 14:40:26 +01:00
|
|
|
memset(&gc_hdr, 0, sizeof(gc_hdr));
|
|
|
|
s32 ret = Disc_ReadGCHeader(&gc_hdr);
|
|
|
|
if(memcmp(gc_hdr.id, "GCOPDV", 6) == 0)
|
2012-03-09 19:15:07 +01:00
|
|
|
{
|
|
|
|
multigamedisc = true;
|
|
|
|
__AnalizeMultiDisc();
|
2012-03-17 23:32:53 +01:00
|
|
|
__DiscReadRaw(ReadBuffer, NextOffset, sizeof(gc_discHdr));
|
2012-12-27 21:22:40 +01:00
|
|
|
memcpy(gc_hdr.title, ReadBuffer + 0x20, 64);
|
2012-11-18 14:40:26 +01:00
|
|
|
memcpy(gc_hdr.id, ReadBuffer, 6);
|
2012-03-09 19:15:07 +01:00
|
|
|
}
|
2012-11-18 14:40:26 +01:00
|
|
|
Asciify2(gc_hdr.title);
|
2012-03-07 22:03:27 +01:00
|
|
|
|
2013-06-26 23:35:38 +02:00
|
|
|
snprintf(folder, sizeof(folder), basedir);
|
2013-07-07 03:50:26 +02:00
|
|
|
fsop_MakeFolder(folder);
|
|
|
|
|
2013-06-26 23:35:38 +02:00
|
|
|
memset(folder, 0, sizeof(folder));
|
|
|
|
snprintf(folder, sizeof(folder), "%s/%s [%.06s]", basedir, gc_hdr.title, gc_hdr.id);
|
2013-07-07 03:50:26 +02:00
|
|
|
if(!fsop_FolderExist(folder))
|
2013-06-26 23:35:38 +02:00
|
|
|
fsop_MakeFolder(folder);
|
|
|
|
else if(!Disc)
|
|
|
|
{
|
|
|
|
gprintf("Skipping game: %s (Already installed)(%d)\n", gc_hdr.title, Gamesize[MultiGameDump]);
|
|
|
|
break;
|
2012-03-09 19:15:07 +01:00
|
|
|
}
|
2012-02-26 16:03:54 +01:00
|
|
|
|
2012-03-17 23:32:53 +01:00
|
|
|
ret = __DiscReadRaw(ReadBuffer, NextOffset, 0x440);
|
2012-02-29 01:19:50 +01:00
|
|
|
if(ret > 0)
|
|
|
|
{
|
2012-08-19 11:45:57 +02:00
|
|
|
MEM2_free(ReadBuffer);
|
2012-02-29 01:19:50 +01:00
|
|
|
return 0x31100;
|
|
|
|
}
|
2012-02-26 16:03:54 +01:00
|
|
|
|
2012-02-29 01:19:50 +01:00
|
|
|
ID = *(vu32*)(ReadBuffer);
|
2012-03-09 03:47:41 +01:00
|
|
|
Disc = *(vu8*)(ReadBuffer+0x06);
|
2012-02-29 01:19:50 +01:00
|
|
|
ApploaderSize = *(vu32*)(ReadBuffer+0x400);
|
|
|
|
DOLOffset = *(vu32*)(ReadBuffer+0x420);
|
|
|
|
FSTOffset = *(vu32*)(ReadBuffer+0x424);
|
|
|
|
FSTSize = *(vu32*)(ReadBuffer+0x428);
|
|
|
|
FSTTotal = *(vu32*)(ReadBuffer+0x42c);
|
|
|
|
GamePartOffset = *(vu32*)(ReadBuffer+0x434);
|
|
|
|
DataSize = *(vu32*)(ReadBuffer+0x438);
|
2012-02-26 16:03:54 +01:00
|
|
|
|
2012-02-29 01:19:50 +01:00
|
|
|
DOLSize = FSTOffset - DOLOffset;
|
2012-03-04 14:22:36 +01:00
|
|
|
DiscSize = DataSize + GamePartOffset;
|
2012-02-17 03:35:42 +01:00
|
|
|
|
2012-08-19 11:45:57 +02:00
|
|
|
FSTBuffer = (u8 *)MEM2_memalign(32, ALIGN32(FSTSize));
|
2012-05-13 19:25:26 +02:00
|
|
|
if(FSTBuffer == NULL)
|
|
|
|
return 0x31100;
|
2012-02-26 16:03:54 +01:00
|
|
|
|
2012-08-19 11:45:57 +02:00
|
|
|
ret = __DiscReadRaw(FSTBuffer, FSTOffset+NextOffset, FSTSize);
|
2012-02-26 16:03:54 +01:00
|
|
|
|
2012-02-29 01:19:50 +01:00
|
|
|
if(ret > 0)
|
|
|
|
{
|
2012-08-19 11:45:57 +02:00
|
|
|
MEM2_free(FSTBuffer);
|
|
|
|
MEM2_free(ReadBuffer);
|
2012-02-29 01:19:50 +01:00
|
|
|
return 0x31100;
|
|
|
|
}
|
2012-02-28 19:44:41 +01:00
|
|
|
|
2012-02-29 01:19:50 +01:00
|
|
|
FSTable = (u8*)FSTBuffer;
|
2012-02-20 09:26:50 +01:00
|
|
|
|
2012-02-29 01:19:50 +01:00
|
|
|
FSTEnt = *(u32*)(FSTable+0x08);
|
2012-02-26 16:03:54 +01:00
|
|
|
|
2012-02-29 01:19:50 +01:00
|
|
|
FSTNameOff = (char*)(FSTable + FSTEnt * 0x0C);
|
|
|
|
FST *fst = (FST *)(FSTable);
|
2012-02-29 19:11:35 +01:00
|
|
|
|
2012-11-18 14:40:26 +01:00
|
|
|
snprintf(minfo, sizeof(minfo), "[%.06s] %s", gc_hdr.id, gc_hdr.title);
|
2012-02-29 19:11:35 +01:00
|
|
|
|
2012-02-29 01:19:50 +01:00
|
|
|
if(FSTTotal > FSTSize)
|
2013-06-26 23:35:38 +02:00
|
|
|
mainMenu.GC_Messenger(4, Disc+1, minfo);
|
2012-02-29 01:19:50 +01:00
|
|
|
else
|
2013-06-26 23:35:38 +02:00
|
|
|
mainMenu.GC_Messenger(3, 0, minfo);
|
2012-02-26 16:03:54 +01:00
|
|
|
|
2012-11-18 14:40:26 +01:00
|
|
|
gprintf("Dumping: %s %s\n", gc_hdr.title, compressed ? "compressed" : "full");
|
2012-02-26 16:03:54 +01:00
|
|
|
|
2012-02-29 01:19:50 +01:00
|
|
|
gprintf("Apploader size : %d\n", ApploaderSize);
|
|
|
|
gprintf("DOL offset : 0x%08x\n", DOLOffset);
|
|
|
|
gprintf("DOL size : %d\n", DOLSize);
|
|
|
|
gprintf("FST offset : 0x%08x\n", FSTOffset);
|
|
|
|
gprintf("FST size : %d\n", FSTSize);
|
|
|
|
gprintf("Num FST entries: %d\n", FSTEnt);
|
|
|
|
gprintf("Data Offset : 0x%08x\n", FSTOffset+FSTSize);
|
|
|
|
gprintf("Disc size : %d\n", DiscSize);
|
2012-02-26 16:03:54 +01:00
|
|
|
|
2012-07-22 20:02:56 +02:00
|
|
|
if(writeexfiles && !Disc)
|
2012-02-29 01:19:50 +01:00
|
|
|
{
|
2012-03-07 22:03:27 +01:00
|
|
|
memset(folder, 0, sizeof(folder));
|
2013-06-26 23:35:38 +02:00
|
|
|
snprintf(folder, sizeof(folder), "%s/%s [%.06s]/sys", basedir, gc_hdr.title, gc_hdr.id);
|
2013-07-07 03:50:26 +02:00
|
|
|
fsop_MakeFolder(folder);
|
2012-02-28 16:06:01 +01:00
|
|
|
|
2012-02-29 01:19:50 +01:00
|
|
|
gprintf("Writing %s/boot.bin\n", folder);
|
|
|
|
snprintf(gamepath, sizeof(gamepath), "%s/boot.bin", folder);
|
2012-03-17 23:32:53 +01:00
|
|
|
gc_done += __DiscWrite(gamepath, NextOffset, 0x440, ReadBuffer);
|
2012-02-20 09:26:50 +01:00
|
|
|
|
2012-02-29 01:19:50 +01:00
|
|
|
gprintf("Writing %s/bi2.bin\n", folder);
|
2012-03-04 14:22:36 +01:00
|
|
|
snprintf(gamepath, sizeof(gamepath), "%s/bi2.bin", folder);
|
2012-03-09 19:15:07 +01:00
|
|
|
gc_done += __DiscWrite(gamepath, 0x440+NextOffset, 0x2000, ReadBuffer);
|
2012-03-04 14:22:36 +01:00
|
|
|
|
2012-02-29 01:19:50 +01:00
|
|
|
gprintf("Writing %s/apploader.img\n", folder);
|
2012-03-04 14:22:36 +01:00
|
|
|
snprintf(gamepath, sizeof(gamepath), "%s/apploader.img", folder);
|
2012-03-09 19:15:07 +01:00
|
|
|
gc_done += __DiscWrite(gamepath, 0x2440+NextOffset, ApploaderSize, ReadBuffer);
|
2012-02-29 01:19:50 +01:00
|
|
|
}
|
2012-02-26 16:03:54 +01:00
|
|
|
|
2013-06-26 23:35:38 +02:00
|
|
|
snprintf(gamepath, sizeof(gamepath), "%s/%s [%.06s]/game.iso", basedir, gc_hdr.title, gc_hdr.id);
|
2012-08-19 16:06:09 +02:00
|
|
|
if(Disc)
|
2012-07-22 20:02:56 +02:00
|
|
|
{
|
2012-08-19 16:06:09 +02:00
|
|
|
char *ptz = strstr(gamepath, "game.iso");
|
2012-08-19 12:07:51 +02:00
|
|
|
if(ptz != NULL)
|
2018-05-29 11:59:57 +02:00
|
|
|
memcpy(ptz, "gam1.iso", 8);
|
2012-07-22 20:02:56 +02:00
|
|
|
}
|
2012-02-29 01:19:50 +01:00
|
|
|
gprintf("Writing %s\n", gamepath);
|
|
|
|
if(compressed)
|
|
|
|
{
|
|
|
|
u32 align;
|
|
|
|
u32 correction;
|
2012-03-03 22:52:07 +01:00
|
|
|
u32 toread;
|
2012-02-28 16:06:01 +01:00
|
|
|
|
2013-06-30 20:40:49 +02:00
|
|
|
FILE *f = fopen(gamepath, "wb");
|
2012-02-24 22:08:24 +01:00
|
|
|
|
2012-03-17 23:32:53 +01:00
|
|
|
ret = __DiscWriteFile(f, NextOffset, (FSTOffset + FSTSize), ReadBuffer);
|
2012-02-29 01:19:50 +01:00
|
|
|
wrote += (FSTOffset + FSTSize);
|
2012-03-07 03:05:57 +01:00
|
|
|
gc_done += wrote;
|
2012-02-20 09:26:50 +01:00
|
|
|
|
2012-02-29 01:19:50 +01:00
|
|
|
u32 i;
|
2012-02-26 16:03:54 +01:00
|
|
|
|
2012-02-29 01:19:50 +01:00
|
|
|
for( i=1; i < FSTEnt; ++i )
|
2012-02-26 16:03:54 +01:00
|
|
|
{
|
2012-08-19 11:45:57 +02:00
|
|
|
if(fst[i].Type)
|
2012-02-29 01:19:50 +01:00
|
|
|
continue;
|
2012-03-03 22:52:07 +01:00
|
|
|
else
|
2012-02-29 01:19:50 +01:00
|
|
|
{
|
|
|
|
for(align = 0x8000; align > 2; align/=2)
|
2012-02-26 16:03:54 +01:00
|
|
|
{
|
2012-02-29 01:19:50 +01:00
|
|
|
if((fst[i].FileOffset & (align-1)) == 0 || force_32k_align)
|
|
|
|
{
|
2012-03-07 03:05:57 +01:00
|
|
|
correction = 0;
|
2012-02-29 01:19:50 +01:00
|
|
|
while(((wrote+correction) & (align-1)) != 0)
|
|
|
|
correction++;
|
|
|
|
wrote += correction;
|
2012-03-03 22:52:07 +01:00
|
|
|
while(correction)
|
|
|
|
{
|
2012-03-07 03:05:57 +01:00
|
|
|
toread=min(correction, gc_readsize);
|
|
|
|
memset(ReadBuffer, 0, toread);
|
|
|
|
fwrite(ReadBuffer, 1, toread, f);
|
2012-03-03 22:52:07 +01:00
|
|
|
correction -= toread;
|
2012-03-07 03:05:57 +01:00
|
|
|
gc_done += toread;
|
2012-03-03 22:52:07 +01:00
|
|
|
}
|
2012-02-29 01:19:50 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-03-09 19:15:07 +01:00
|
|
|
ret = __DiscWriteFile(f, fst[i].FileOffset+NextOffset, fst[i].FileLength, ReadBuffer);
|
2012-02-29 01:19:50 +01:00
|
|
|
gprintf("Writing: %d/%d: %s from 0x%08x to 0x%08x(%i)\n", i, FSTEnt, FSTNameOff + fst[i].NameOffset, fst[i].FileOffset, wrote, align);
|
|
|
|
if( ret >= 0 )
|
|
|
|
{
|
|
|
|
fst[i].FileOffset = wrote;
|
|
|
|
wrote += ret;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-08-19 11:45:57 +02:00
|
|
|
MEM2_free(ReadBuffer);
|
|
|
|
MEM2_free(FSTBuffer);
|
2012-05-13 17:13:33 +02:00
|
|
|
fclose(f);
|
2012-02-29 01:19:50 +01:00
|
|
|
return gc_error;
|
2012-02-26 16:03:54 +01:00
|
|
|
}
|
|
|
|
}
|
2012-02-29 01:19:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
gprintf("Updating FST\n");
|
|
|
|
fseek(f, FSTOffset, SEEK_SET);
|
|
|
|
fwrite(fst, 1, FSTSize, f);
|
2012-05-13 17:13:33 +02:00
|
|
|
fclose(f);
|
2012-02-29 01:19:50 +01:00
|
|
|
|
|
|
|
gprintf("Done!! Disc old size: %d, disc new size: %d, saved: %d\n", DiscSize, wrote, DiscSize - wrote);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-17 23:32:53 +01:00
|
|
|
ret = __DiscWrite(gamepath, NextOffset, DiscSize, ReadBuffer);
|
2012-02-29 01:19:50 +01:00
|
|
|
if( ret < 0 )
|
|
|
|
{
|
2012-08-19 11:45:57 +02:00
|
|
|
MEM2_free(ReadBuffer);
|
|
|
|
MEM2_free(FSTBuffer);
|
2012-02-29 01:19:50 +01:00
|
|
|
return gc_error;
|
2012-08-19 11:45:57 +02:00
|
|
|
}
|
2012-02-29 01:19:50 +01:00
|
|
|
gprintf("Done!! Disc size: %d\n", DiscSize);
|
|
|
|
}
|
2012-08-19 11:45:57 +02:00
|
|
|
MEM2_free(FSTBuffer);
|
2012-05-13 19:25:26 +02:00
|
|
|
|
2012-07-22 20:02:56 +02:00
|
|
|
if((FSTTotal > FSTSize || __CheckMDHack(ID)) && !multigamedisc)
|
2012-03-09 19:15:07 +01:00
|
|
|
{
|
|
|
|
if(Disc)
|
|
|
|
{
|
|
|
|
gamedone = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
__WaitForDisc(1, 9);
|
|
|
|
Disc++;
|
|
|
|
}
|
|
|
|
}
|
2012-03-17 23:32:53 +01:00
|
|
|
else if(multigamedisc)
|
2012-03-09 19:15:07 +01:00
|
|
|
{
|
|
|
|
if(MultiGameDump+1 == MultiGameCnt)
|
|
|
|
{
|
|
|
|
gamedone = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
MultiGameDump++;
|
|
|
|
}
|
|
|
|
}
|
2012-03-17 23:32:53 +01:00
|
|
|
else
|
|
|
|
gamedone = true;
|
2012-02-20 09:26:50 +01:00
|
|
|
}
|
2012-08-19 11:45:57 +02:00
|
|
|
MEM2_free(ReadBuffer);
|
2012-02-20 09:26:50 +01:00
|
|
|
|
2012-08-19 11:45:57 +02:00
|
|
|
return gc_skipped;
|
2012-02-20 09:26:50 +01:00
|
|
|
}
|
|
|
|
|
2012-03-09 03:47:41 +01:00
|
|
|
s32 GCDump::CheckSpace(u32 *needed, bool comp)
|
2012-02-20 09:26:50 +01:00
|
|
|
{
|
2012-08-19 11:45:57 +02:00
|
|
|
u8 *ReadBuffer = (u8 *)MEM2_memalign(32, ALIGN32(0x440));
|
2012-05-13 19:25:26 +02:00
|
|
|
if(ReadBuffer == NULL)
|
|
|
|
return 1;
|
|
|
|
|
2012-03-17 23:32:53 +01:00
|
|
|
u32 size = 0;
|
2012-03-09 19:15:07 +01:00
|
|
|
bool scnddisc = false;
|
|
|
|
gamedone = false;
|
|
|
|
multigamedisc = false;
|
|
|
|
MultiGameDump = 0;
|
|
|
|
MultiGameCnt = 0;
|
|
|
|
NextOffset = 0;
|
|
|
|
Disc = 0;
|
|
|
|
|
|
|
|
while(!gamedone)
|
2012-03-17 23:32:53 +01:00
|
|
|
{
|
2012-03-09 19:15:07 +01:00
|
|
|
u32 multisize = 0;
|
2012-11-18 14:40:26 +01:00
|
|
|
memset(&gc_hdr, 0, sizeof(gc_hdr));
|
|
|
|
Disc_ReadGCHeader(&gc_hdr);
|
|
|
|
if(memcmp(gc_hdr.id, "GCOPDV", 6) == 0)
|
2012-03-09 19:15:07 +01:00
|
|
|
{
|
|
|
|
multigamedisc = true;
|
|
|
|
__AnalizeMultiDisc();
|
2012-03-17 23:32:53 +01:00
|
|
|
__DiscReadRaw(ReadBuffer, NextOffset, sizeof(gc_discHdr));
|
2012-12-27 21:22:40 +01:00
|
|
|
memcpy(gc_hdr.title, ReadBuffer + 0x20, 64);
|
|
|
|
memcpy(gc_hdr.id, ReadBuffer, 6);
|
2012-03-09 19:15:07 +01:00
|
|
|
}
|
2012-11-18 14:40:26 +01:00
|
|
|
Asciify2(gc_hdr.title);
|
2012-08-19 11:45:57 +02:00
|
|
|
|
2012-03-17 23:32:53 +01:00
|
|
|
s32 ret = __DiscReadRaw(ReadBuffer, NextOffset, 0x440);
|
2012-02-20 09:26:50 +01:00
|
|
|
if(ret > 0)
|
|
|
|
{
|
2012-08-19 11:45:57 +02:00
|
|
|
MEM2_free(ReadBuffer);
|
2012-02-20 09:26:50 +01:00
|
|
|
return 1;
|
|
|
|
}
|
2012-03-01 20:36:17 +01:00
|
|
|
|
2012-02-29 01:19:50 +01:00
|
|
|
ID = *(vu32*)(ReadBuffer);
|
|
|
|
ID2 = 0;
|
|
|
|
Disc = *(vu8*)(ReadBuffer+0x06);
|
|
|
|
Disc2 = 0;
|
|
|
|
ApploaderSize = *(vu32*)(ReadBuffer+0x400);
|
|
|
|
FSTOffset = *(vu32*)(ReadBuffer+0x424);
|
|
|
|
FSTSize = *(vu32*)(ReadBuffer+0x428);
|
|
|
|
FSTTotal = *(vu32*)(ReadBuffer+0x42c);
|
|
|
|
GamePartOffset = *(vu32*)(ReadBuffer+0x434);
|
|
|
|
DataSize = *(vu32*)(ReadBuffer+0x438);
|
|
|
|
DiscSize = DataSize + GamePartOffset;
|
2012-03-01 20:36:17 +01:00
|
|
|
|
2012-11-18 14:40:26 +01:00
|
|
|
snprintf(minfo, sizeof(minfo), "[%.06s] %s", gc_hdr.id, gc_hdr.title);
|
2012-03-01 20:36:17 +01:00
|
|
|
|
2013-06-26 23:35:38 +02:00
|
|
|
mainMenu.GC_Messenger(2, 0, minfo);
|
2012-03-01 20:36:17 +01:00
|
|
|
|
2012-02-29 01:19:50 +01:00
|
|
|
if(writeexfiles)
|
2012-02-20 09:26:50 +01:00
|
|
|
{
|
2012-03-09 19:15:07 +01:00
|
|
|
multisize += 0xa440;
|
|
|
|
multisize += ApploaderSize;
|
2012-02-29 01:19:50 +01:00
|
|
|
}
|
2012-03-01 20:36:17 +01:00
|
|
|
|
2012-02-29 01:19:50 +01:00
|
|
|
if(!comp)
|
|
|
|
{
|
2012-08-19 11:45:57 +02:00
|
|
|
multisize += DiscSize;
|
2012-02-29 01:19:50 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-08-19 11:45:57 +02:00
|
|
|
u8 *FSTBuffer = (u8*)MEM2_memalign(32, ALIGN32(FSTSize));
|
2012-05-13 19:25:26 +02:00
|
|
|
if(FSTBuffer == NULL)
|
|
|
|
return 1;
|
2012-02-29 01:19:50 +01:00
|
|
|
|
2012-08-19 11:45:57 +02:00
|
|
|
ret = __DiscReadRaw(FSTBuffer, FSTOffset+NextOffset, FSTSize);
|
2012-02-29 01:19:50 +01:00
|
|
|
if(ret > 0)
|
2012-02-20 09:26:50 +01:00
|
|
|
{
|
2012-08-19 11:45:57 +02:00
|
|
|
MEM2_free(FSTBuffer);
|
2012-02-29 01:19:50 +01:00
|
|
|
return 1;
|
2012-02-20 09:26:50 +01:00
|
|
|
}
|
2012-03-01 20:36:17 +01:00
|
|
|
|
2012-02-29 01:19:50 +01:00
|
|
|
FSTable = (u8*)FSTBuffer;
|
|
|
|
u32 FSTEnt = *(u32*)(FSTable+0x08);
|
|
|
|
FST *fst = (FST *)(FSTable);
|
2012-03-01 20:36:17 +01:00
|
|
|
|
2012-03-09 19:15:07 +01:00
|
|
|
multisize += (FSTOffset + FSTSize);
|
2012-03-01 20:36:17 +01:00
|
|
|
|
2012-02-29 01:19:50 +01:00
|
|
|
u32 i;
|
2012-03-01 20:36:17 +01:00
|
|
|
u32 correction;
|
2012-08-19 11:45:57 +02:00
|
|
|
for(i = 1; i < FSTEnt; ++i)
|
2012-02-29 01:19:50 +01:00
|
|
|
{
|
2012-08-19 11:45:57 +02:00
|
|
|
if(fst[i].Type)
|
2012-02-29 01:19:50 +01:00
|
|
|
continue;
|
2012-03-01 20:36:17 +01:00
|
|
|
else
|
|
|
|
{
|
2012-08-19 11:45:57 +02:00
|
|
|
for(u32 align = 0x8000; align > 2; align /= 2)
|
2012-03-01 20:36:17 +01:00
|
|
|
{
|
2012-08-19 11:45:57 +02:00
|
|
|
if((fst[i].FileOffset & (align - 1)) == 0 || force_32k_align)
|
2012-03-01 20:36:17 +01:00
|
|
|
{
|
2012-03-09 03:47:41 +01:00
|
|
|
correction = 0;
|
2012-03-17 23:32:53 +01:00
|
|
|
while(((multisize+correction) & (align-1)) != 0)
|
2012-03-01 20:36:17 +01:00
|
|
|
correction++;
|
2012-03-09 19:15:07 +01:00
|
|
|
multisize += correction;
|
2012-03-01 20:36:17 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-03-09 19:15:07 +01:00
|
|
|
multisize += fst[i].FileLength;
|
2012-02-29 01:19:50 +01:00
|
|
|
}
|
|
|
|
}
|
2012-08-19 11:45:57 +02:00
|
|
|
MEM2_free(FSTBuffer);
|
2012-02-20 09:26:50 +01:00
|
|
|
}
|
2012-03-09 19:15:07 +01:00
|
|
|
size += multisize;
|
|
|
|
Gamesize[MultiGameDump] = multisize;
|
2012-03-01 20:36:17 +01:00
|
|
|
|
2012-07-22 20:02:56 +02:00
|
|
|
if((FSTTotal > FSTSize || __CheckMDHack(ID)) && !multigamedisc)
|
2012-02-29 01:19:50 +01:00
|
|
|
{
|
2012-03-17 23:32:53 +01:00
|
|
|
if(Disc == 0 && !scnddisc)
|
2012-03-09 03:47:41 +01:00
|
|
|
__WaitForDisc(1, 1);
|
2012-03-09 19:15:07 +01:00
|
|
|
else if(Disc == 0x01 && !scnddisc)
|
2012-03-09 03:47:41 +01:00
|
|
|
__WaitForDisc(0, 1);
|
2012-03-17 23:32:53 +01:00
|
|
|
|
2012-03-09 19:15:07 +01:00
|
|
|
if(scnddisc)
|
2012-02-29 01:19:50 +01:00
|
|
|
{
|
|
|
|
if(Disc == 0x01)
|
2012-03-17 23:32:53 +01:00
|
|
|
__WaitForDisc(0, 1);
|
2012-02-29 01:19:50 +01:00
|
|
|
|
2012-03-09 19:15:07 +01:00
|
|
|
gamedone = true;
|
2012-02-29 01:19:50 +01:00
|
|
|
break;
|
|
|
|
}
|
2012-03-09 19:15:07 +01:00
|
|
|
scnddisc = true;
|
2012-02-29 01:19:50 +01:00
|
|
|
}
|
2012-03-17 23:32:53 +01:00
|
|
|
else if(multigamedisc)
|
2012-03-09 19:15:07 +01:00
|
|
|
{
|
|
|
|
if(MultiGameDump+1 == MultiGameCnt)
|
|
|
|
{
|
|
|
|
gamedone = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
MultiGameDump++;
|
|
|
|
}
|
2012-03-17 23:32:53 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
gamedone = true;
|
2012-02-20 09:26:50 +01:00
|
|
|
}
|
2012-08-19 11:45:57 +02:00
|
|
|
MEM2_free(ReadBuffer);
|
2013-08-14 21:11:38 +02:00
|
|
|
mainMenu.m_thrdTotal = size;
|
2012-03-09 03:47:41 +01:00
|
|
|
DiscSizeCalculated = size/0x400;
|
|
|
|
*needed = (size/0x8000) >> 2;
|
|
|
|
gprintf("Free space needed: %d Mb (%d blocks)\n", size/0x100000, (size/0x8000) >> 2);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 GCDump::GetFreeSpace(char *path, u32 Value)
|
|
|
|
{
|
|
|
|
struct statvfs stats;
|
|
|
|
memset(&stats, 0, sizeof(stats));
|
|
|
|
statvfs(path , &stats);
|
|
|
|
|
|
|
|
u64 free = (u64)stats.f_frsize * (u64)stats.f_bfree;
|
|
|
|
|
|
|
|
switch(Value)
|
|
|
|
{
|
|
|
|
case KB:
|
|
|
|
return free/0x400;
|
|
|
|
case BL:
|
2012-12-27 21:22:40 +01:00
|
|
|
return (free/0x8000) >> 2;
|
2012-03-09 03:47:41 +01:00
|
|
|
case MB:
|
|
|
|
return free/0x100000;
|
|
|
|
case GB:
|
2012-12-27 21:22:40 +01:00
|
|
|
return free/0x40000000;
|
2012-03-09 03:47:41 +01:00
|
|
|
}
|
2012-02-20 09:26:50 +01:00
|
|
|
return 0;
|
2012-03-07 03:05:57 +01:00
|
|
|
}
|
|
|
|
|