GC Ex Dumper:

* Fixed progress bar for games that come with 2 discs
* Dumper now uses a much smaller buffer when "skip on error" mode is on
* Added __WaitForDisc function to cleanup a lot of code
* Cleaned up some more
This commit is contained in:
overjoy.psm 2012-03-07 02:05:57 +00:00
parent 9472bd3d59
commit 5ff5952db3
5 changed files with 148 additions and 313 deletions

View File

@ -92,26 +92,26 @@ s32 GCDump::__DiscReadRaw(void *outbuf, u32 offset, u32 length)
return -1;
}
s32 GCDump::__DiscWrite(char * path, u32 offset, u32 length, u32 already_done, u8 *ReadBuffer, progress_callback_t spinner, void *spinner_data)
s32 GCDump::__DiscWrite(char * path, u32 offset, u32 length, u8 *ReadBuffer, progress_callback_t spinner, void *spinner_data)
{
gprintf("__DiscWrite(%s, 0x%08x, %x)\n", path, offset, length);
u32 wrote = 0;
FILE *f = fopen(path, "wb");
wrote = __DiscWriteFile(f, offset, length, already_done, ReadBuffer, spinner, spinner_data);
wrote = __DiscWriteFile(f, offset, length, ReadBuffer, spinner, spinner_data);
SAFE_CLOSE(f);
return wrote;
}
s32 GCDump::__DiscWriteFile(FILE *f, u32 offset, u32 length, u32 already_done, u8 *ReadBuffer, progress_callback_t spinner, void *spinner_data)
s32 GCDump::__DiscWriteFile(FILE *f, u32 offset, u32 length, u8 *ReadBuffer, progress_callback_t spinner, void *spinner_data)
{
u32 toread = 0;
u32 wrote = 0;
while(length)
{
toread = min(length,gc_readsize);
toread = min(length, gc_readsize);
s32 ret = __DiscReadRaw(ReadBuffer, offset, (toread+31)&(~31));
if (ret == 1)
memset(ReadBuffer, 0, gc_readsize);
@ -121,12 +121,91 @@ s32 GCDump::__DiscWriteFile(FILE *f, u32 offset, u32 length, u32 already_done, u
wrote += toread;
offset += toread;
length -= toread;
gc_done += toread;
if(spinner)
spinner(already_done+wrote, DiscSizeCalculated, spinner_data);
spinner(gc_done/1024, DiscSizeCalculated, spinner_data);
}
return wrote;
}
bool GCDump::__WaitForDisc(u8 dsc, char *minfo, u32 msg, message_callback_t message, void *message_data)
{
u8 *ReadBuffer = (u8 *)MEM2_alloc(0x440);
u32 cover = 0;
bool done = false;
*(u32*)0xCD0000C0 |= 0x20;
while(!done)
{
message( msg, dsc+1, minfo, message_data);
while(1)
{
WDVD_GetCoverStatus(&cover);
if(!(cover & 0x2))
break;
}
while(1)
{
if(Disc_Wait() < 0)
continue;
if(Disc_Open() < 0)
{
MEM2_free(ReadBuffer);
return false;
}
if(Disc_IsGC() == 0)
{
s32 ret = __DiscReadRaw(ReadBuffer, 0, 0x440);
if(ret > 0)
{
MEM2_free(ReadBuffer);
return false;
}
ID2 = *(vu32*)(ReadBuffer);
Disc2 = *(vu8*)(ReadBuffer+0x06);
if(ID == ID2 && Disc2 == dsc)
{
*(u32*)0xCD0000C0 &= ~0x20;
done = true;
break;
}
else if(ID == ID2 && Disc2 != dsc)
{
message( 7, dsc+1, NULL, message_data);
usleep( 5000000 );
break;
}
else if(ID != ID2)
{
message( 8, 0, NULL, message_data);
usleep( 5000000 );
break;
}
}
else if(Disc_IsWii() == 0)
{
message( 5, 0, NULL, message_data);
usleep( 5000000 );
break;
}
else
{
message( 6, 0, NULL, message_data);
usleep( 5000000 );
break;
}
}
}
MEM2_free(ReadBuffer);
return done;
}
s32 GCDump::DumpGame(progress_callback_t spinner, message_callback_t message, void *spinner_data)
{
static gc_discHdr gcheader ATTRIBUTE_ALIGN(32);
@ -134,6 +213,7 @@ s32 GCDump::DumpGame(progress_callback_t spinner, message_callback_t message, vo
u8 *ReadBuffer = (u8 *)MEM2_alloc(gc_readsize);
u32 j;
gc_done = 0;
char *FSTNameOff = (char *)NULL;
@ -145,15 +225,14 @@ s32 GCDump::DumpGame(progress_callback_t spinner, message_callback_t message, vo
for( j=0; j<2; ++j)
{
bool done = false;
u8 *FSTBuffer;
u32 wrote = 0;
s32 ret = Disc_ReadGCHeader(&gcheader);
Asciify2(gcheader.title);
if(strncmp(gamepartition, "sd",2) != 0)
snprintf(folder, sizeof(folder), dmlgamedir, gamepartition);
if(strncmp(gamepartition, "sd", 2) != 0)
snprintf(folder, sizeof(folder), dmlgamedir, gamepartition); //WTF??
else
snprintf(folder, sizeof(folder), DML_DIR, gamepartition);
if(!fsop_DirExist(folder))
@ -225,15 +304,15 @@ s32 GCDump::DumpGame(progress_callback_t spinner, message_callback_t message, vo
gprintf("Writing %s/boot.bin\n", folder);
snprintf(gamepath, sizeof(gamepath), "%s/boot.bin", folder);
__DiscWrite(gamepath, 0, 0x440, wrote, ReadBuffer, spinner, spinner_data);
gc_done += __DiscWrite(gamepath, 0, 0x440, ReadBuffer, spinner, spinner_data);
gprintf("Writing %s/bi2.bin\n", folder);
snprintf(gamepath, sizeof(gamepath), "%s/bi2.bin", folder);
__DiscWrite(gamepath, 0x440, 0x2000, wrote, ReadBuffer, spinner, spinner_data);
gc_done += __DiscWrite(gamepath, 0x440, 0x2000, ReadBuffer, spinner, spinner_data);
gprintf("Writing %s/apploader.img\n", folder);
snprintf(gamepath, sizeof(gamepath), "%s/apploader.img", folder);
__DiscWrite(gamepath, 0x2440, ApploaderSize, wrote, ReadBuffer, spinner, spinner_data);
gc_done += __DiscWrite(gamepath, 0x2440, ApploaderSize, ReadBuffer, spinner, spinner_data);
}
snprintf(gamepath, sizeof(gamepath), "%s:/games/%s [%.06s]%s/game.iso", gamepartition, gcheader.title, (char *)gcheader.id, j ? "2" : "");
@ -248,8 +327,9 @@ s32 GCDump::DumpGame(progress_callback_t spinner, message_callback_t message, vo
FILE *f;
f = fopen(gamepath, "wb");
ret = __DiscWriteFile(f, 0, (FSTOffset + FSTSize), wrote, ReadBuffer, spinner, spinner_data);
ret = __DiscWriteFile(f, 0, (FSTOffset + FSTSize), ReadBuffer, spinner, spinner_data);
wrote += (FSTOffset + FSTSize);
gc_done += wrote;
u32 i;
@ -265,24 +345,23 @@ s32 GCDump::DumpGame(progress_callback_t spinner, message_callback_t message, vo
{
if((fst[i].FileOffset & (align-1)) == 0 || force_32k_align)
{
correction = 0x00;
correction = 0;
while(((wrote+correction) & (align-1)) != 0)
correction++;
wrote += correction;
//fseek(f,correction,SEEK_END);
while(correction)
{
toread=min(correction,gc_readsize);
memset(ReadBuffer,0,toread);
fwrite(ReadBuffer,1,toread,f);
toread=min(correction, gc_readsize);
memset(ReadBuffer, 0, toread);
fwrite(ReadBuffer, 1, toread, f);
correction -= toread;
if(spinner)
spinner(wrote+toread, DiscSizeCalculated, spinner_data);
gc_done += toread;
}
break;
}
}
ret = __DiscWriteFile(f, fst[i].FileOffset, fst[i].FileLength, wrote, ReadBuffer, spinner, spinner_data);
ret = __DiscWriteFile(f, fst[i].FileOffset, fst[i].FileLength, ReadBuffer, spinner, spinner_data);
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 )
{
@ -308,87 +387,22 @@ s32 GCDump::DumpGame(progress_callback_t spinner, message_callback_t message, vo
}
else
{
ret = __DiscWrite(gamepath, 0, DiscSize, wrote, ReadBuffer, spinner, spinner_data);
ret = __DiscWrite(gamepath, 0, DiscSize, ReadBuffer, spinner, spinner_data);
if( ret < 0 )
{
MEM2_free(ReadBuffer);
MEM2_free(FSTBuffer);
return gc_error;
}
}
gprintf("Done!! Disc size: %d\n", DiscSize);
}
MEM2_free(FSTBuffer);
if(FSTTotal > FSTSize && !j)
{
*(u32*)0xCD0000C0 |= 0x20;
u32 cover = 0;
message( 9, 0, minfo, spinner_data);
while(!done)
{
while(1)
{
WDVD_GetCoverStatus(&cover);
if(!(cover & 0x2))
break;
}
while(1)
{
if(Disc_Wait() < 0)
continue;
if(Disc_Open() < 0)
return 1;
if(Disc_IsGC() == 0)
{
s32 ret = __DiscReadRaw(ReadBuffer, 0, 0x440);
if(ret > 0)
return 1;
ID2 = *(vu32*)(ReadBuffer);
Disc = *(vu8*)(ReadBuffer+0x06);
if(ID == ID2 && Disc == 0x01)
{
done = true;
*(u32*)0xCD0000C0 &= ~0x20;
break;
}
else if(ID == ID2 && Disc == 0x00)
{
message( 7, 1, NULL, spinner_data);
usleep( 5000000 );
break;
}
else if(ID != ID2)
{
message( 8, 0, NULL, spinner_data);
usleep( 5000000 );
break;
}
}
else if(Disc_IsWii() == 0)
{
message( 5, 0, NULL, spinner_data);
usleep( 5000000 );
break;
}
else
{
message( 6, 0, NULL, spinner_data);
usleep( 5000000 );
break;
}
}
}
}
__WaitForDisc(1, minfo, 9, message, spinner_data);
else
{
break;
}
}
MEM2_free(ReadBuffer);
@ -427,8 +441,6 @@ s32 GCDump::CheckSpace(u32 *needed, bool comp, message_callback_t message, void
DataSize = *(vu32*)(ReadBuffer+0x438);
DiscSize = DataSize + GamePartOffset;
bool done = false;
Disc_ReadGCHeader(&gcheader);
Asciify2(gcheader.title);
@ -494,214 +506,16 @@ s32 GCDump::CheckSpace(u32 *needed, bool comp, message_callback_t message, void
if(FSTTotal > FSTSize)
{
u32 cover = 0;
if(Disc == 0x00 && j == 0)
{
while(!done)
{
message( 1, 2, minfo, message_data);
while(1)
{
WDVD_GetCoverStatus(&cover);
if(!(cover & 0x2))
break;
}
while(1)
{
if(Disc_Wait() < 0)
continue;
if(Disc_Open() < 0)
{
MEM2_free(ReadBuffer);
return 1;
}
if(Disc_IsGC() == 0)
{
s32 ret = __DiscReadRaw(ReadBuffer, 0, 0x440);
if(ret > 0)
{
MEM2_free(ReadBuffer);
return 1;
}
ID2 = *(vu32*)(ReadBuffer);
Disc2 = *(vu8*)(ReadBuffer+0x06);
if(ID == ID2 && Disc2 == 0x01)
{
done = true;
break;
}
else if(ID == ID2 && Disc2 == 0x00)
{
message( 7, 1, NULL, message_data);
usleep( 5000000 );
break;
}
else if(ID != ID2)
{
message( 8, 0, NULL, message_data);
usleep( 5000000 );
break;
}
}
else if(Disc_IsWii() == 0)
{
message( 5, 0, NULL, message_data);
usleep( 5000000 );
break;
}
else
{
message( 6, 0, NULL, message_data);
usleep( 5000000 );
break;
}
}
}
}
if(Disc == 0 && j == 0)
__WaitForDisc(1, minfo, 1, message, message_data);
else if(Disc == 0x01 && j == 0)
{
while(!done)
{
message( 1, 1, minfo, message_data);
while(1)
{
WDVD_GetCoverStatus(&cover);
if(!(cover & 0x2))
break;
}
while(1)
{
if(Disc_Wait() < 0)
continue;
if(Disc_Open() < 0)
{
MEM2_free(ReadBuffer);
return 1;
}
if(Disc_IsGC() == 0)
{
s32 ret = __DiscReadRaw(ReadBuffer, 0, 0x440);
if(ret > 0)
{
MEM2_free(ReadBuffer);
return 1;
}
ID2 = *(vu32*)(ReadBuffer);
Disc2 = *(vu8*)(ReadBuffer+0x06);
if(ID == ID2 && Disc2 == 0x00)
{
done = true;
break;
}
else if(ID == ID2 && Disc2 == 0x01)
{
message( 7, 2, NULL, message_data);
usleep( 5000000 );
break;
}
else if(ID != ID2)
{
message( 8, 0, NULL, message_data);
usleep( 5000000 );
break;
}
}
else if(Disc_IsWii() == 0)
{
message( 5, 0, NULL, message_data);
usleep( 5000000 );
break;
}
else
{
message( 6, 0, NULL, message_data);
usleep( 5000000 );
break;
}
}
}
}
__WaitForDisc(0, minfo, 1, message, message_data);
if(j == 1)
{
if(Disc == 0x01)
{
while(!done)
{
message( 1, 1, minfo, message_data);
while(1)
{
WDVD_GetCoverStatus(&cover);
if(!(cover & 0x2))
break;
}
__WaitForDisc(0, minfo, 1, message, message_data);
while(1)
{
if(Disc_Wait() < 0)
continue;
if(Disc_Open() < 0)
{
MEM2_free(ReadBuffer);
return 1;
}
if(Disc_IsGC() == 0)
{
s32 ret = __DiscReadRaw(ReadBuffer, 0, 0x440);
if(ret > 0)
{
MEM2_free(ReadBuffer);
return 1;
}
ID2 = *(vu32*)(ReadBuffer);
Disc2 = *(vu8*)(ReadBuffer+0x06);
if(ID == ID2 && Disc2 == 0x00)
{
done = true;
break;
}
else if(ID == ID2 && Disc2 == 0x01)
{
message( 7, 2, NULL, message_data);
usleep( 5000000 );
break;
}
else if(ID != ID2)
{
message( 8, 0, NULL, message_data);
usleep( 5000000 );
break;
}
}
else if(Disc_IsWii() == 0)
{
message( 5, 0, NULL, message_data);
usleep( 5000000 );
break;
}
else
{
message( 6, 0, NULL, message_data);
usleep( 5000000 );
break;
}
}
}
}
break;
}
}
@ -709,8 +523,9 @@ s32 GCDump::CheckSpace(u32 *needed, bool comp, message_callback_t message, void
break;
}
MEM2_free(ReadBuffer);
DiscSizeCalculated = size;
DiscSizeCalculated = (size/1024);
*needed = size/0x8000;
gprintf("Free space needed: %d Mb (%x blocks)\n", (size/1024)/1024, size/0x8000);
return 0;
}
}

View File

@ -61,7 +61,8 @@ private:
u32 gc_error;
u32 gc_retry;
u32 gc_skipped;
u32 gc_readsize;
u32 gc_readsize;
u32 gc_done;
u32 ID;
u32 ID2;
u32 ApploaderSize;
@ -102,7 +103,8 @@ private:
};
} FST;
s32 __DiscReadRaw(void *outbuf, u32 offset, u32 length);
s32 __DiscWrite(char * path, u32 offset, u32 length, u32 already_done, u8 *ReadBuffer, progress_callback_t spinner, void *spinner_data);
s32 __DiscWriteFile(FILE *f, u32 offset, u32 length, u32 already_done, u8 *ReadBuffer, progress_callback_t spinner, void *spinner_data);
s32 __DiscWrite(char * path, u32 offset, u32 length, u8 *ReadBuffer, progress_callback_t spinner, void *spinner_data);
s32 __DiscWriteFile(FILE *f, u32 offset, u32 length, u8 *ReadBuffer, progress_callback_t spinner, void *spinner_data);
bool __WaitForDisc(u8 dsc, char *minfo, u32 msg, message_callback_t message, void *message_data);
};
#endif

View File

@ -944,6 +944,7 @@ private:
static int _gameInstaller(void *obj);
static int _GCgameInstaller(void *obj);
static int _GCcopyGame(void *obj);
float m_progress;
wstringEx _optBoolToString(int b);
void _stopSounds(void);

View File

@ -62,12 +62,12 @@ static void slotLight(bool state)
void CMenu::_addDiscProgress(int status, int total, void *user_data)
{
CMenu &m = *(CMenu *)user_data;
float progress = total == 0 ? 0.f : (float)status / (float)total;
m.m_progress = total == 0 ? 0.f : (float)status / (float)total;
// Don't synchronize too often
if (progress - m.m_thrdProgress >= 0.01f)
if(m.m_progress - m.m_thrdProgress >= 0.01f)
{
LWP_MutexLock(m.m_mutex);
m._setThrdMsg(L"", progress);
m._setThrdMsg(L"", m.m_progress);
LWP_MutexUnlock(m.m_mutex);
}
}
@ -77,23 +77,23 @@ void CMenu::_Messenger(int message, int info, char *cinfo, void *user_data)
CMenu &m = *(CMenu *)user_data;
LWP_MutexLock(m.m_mutex);
if(message == 1)
m._setThrdMsg(wfmt(m._fmt("wbfsop14", L"Calculating space needed for %s...\n Please insert disc %d to continue"), cinfo, info), 0.f);
m._setThrdMsg(wfmt(m._fmt("wbfsop23", L"Calculating space needed for %s...\n Please insert disc %d to continue"), cinfo, info), m.m_progress);
if(message == 2)
m._setThrdMsg(wfmt(m._fmt("wbfsop15", L"Calculating space needed for %s"), cinfo), 0.f);
m._setThrdMsg(wfmt(m._fmt("wbfsop15", L"Calculating space needed for %s"), cinfo), m.m_progress);
if(message == 3)
m._setThrdMsg(wfmt(m._fmt("wbfsop16", L"Installing %s"), cinfo), 0.f);
m._setThrdMsg(wfmt(m._fmt("wbfsop16", L"Installing %s"), cinfo), m.m_progress);
if(message == 4)
m._setThrdMsg(wfmt(m._fmt("wbfsop17", L"Installing %s disc %d/2"), cinfo, info), 0.f);
m._setThrdMsg(wfmt(m._fmt("wbfsop17", L"Installing %s disc %d/2"), cinfo, info), m.m_progress);
if(message == 5)
m._setThrdMsg(m._t("wbfsop18", L"Don't try to trick me with a Wii disc!!"), 0.f);
m._setThrdMsg(m._t("wbfsop18", L"Don't try to trick me with a Wii disc!!"), m.m_progress);
if(message == 6)
m._setThrdMsg(m._t("wbfsop19", L"This is not a GC disc!!"), 0.f);
m._setThrdMsg(m._t("wbfsop19", L"This is not a GC disc!!"), m.m_progress);
if(message == 7)
m._setThrdMsg(wfmt(m._fmt("wbfsop20", L"You inserted disc %d again!!"), info), 0.f);
m._setThrdMsg(wfmt(m._fmt("wbfsop20", L"You inserted disc %d again!!"), info), m.m_progress);
if(message == 8)
m._setThrdMsg(m._t("wbfsop21", L"This is a disc of another game!!"), 0.f);
m._setThrdMsg(m._t("wbfsop21", L"This is a disc of another game!!"), m.m_progress);
if(message == 9)
m._setThrdMsg(wfmt(m._fmt("wbfsop22", L"Installing %s...\n Please insert disc 2 to continue"), cinfo), 1.f);
m._setThrdMsg(wfmt(m._fmt("wbfsop22", L"Installing %s...\n Please insert disc 2 to continue"), cinfo), m.m_progress);
LWP_MutexUnlock(m.m_mutex);
}
@ -150,10 +150,14 @@ int CMenu::_GCgameInstaller(void *obj)
bool alig = m.m_cfg.getBool("DML", "force_32k_align_files", false);
u32 nretry = m.m_cfg.getUInt("DML", "num_retries", 5);
u32 rsize = 1048576; //1MB
if(skip)
rsize = 8192; // Use small chunks when skip on error is enabled
m_gcdump.Init(skip, comp, wexf, alig, nretry, rsize,DeviceName[currentPartition],m.m_DMLgameDir.c_str());
int ret;
int ret;
m.m_progress = 0.f;
if (!DeviceHandler::Instance()->IsInserted(currentPartition))
{

View File

@ -206,10 +206,23 @@ vmpall=Alles
vmpmore=Meer
vmpnone=Geen
vmpnormal=Normaal
wbfsadddlg=Plaats het te kopiëren spel in de disk sleuf, klik daarna op Start.
wbfsadddlg=Plaats het te kopiëren spel in de disc sleuf, klik daarna op Start.
wbfsop1=Installeer Spel
wbfsop10=Niet genoeg ruimte: %i blokken benodigd, %i beschikbaar
wbfsop11=Kopieër Spel
wbfsop12=DVD Lees Fout(%d)
wbfsop13=Spel geïnstalleerd, maar bevat %d leesfouten
wbfsop14=Spel gekopieërd, klik op terug om spel te starten
wbfsop15=Benodigde ruimte aan het berekenen voor %s
wbfsop16=Bezig met installeren van %s
wbfsop17=Bezig met installeren van %s disc %d/2
wbfsop18=Dit is een Wii disc!
wbfsop19=Dit is geen Gamecube disc!
wbfsop2=Verwijder Spel
wbfsop20=Je hebt disc %d terug in de disc sleuf gedaan!
wbfsop21=Dit is een disc van een ander spel!
wbfsop22=Bezig met installeren van %s...\nDoe disc 2 in de disc sleuf om door the gaan
wbfsop23=Benodigde ruimte aan het berekenen voor %s...\nDoe disc %d in de disc sleuf om door the gaan
wbfsop4=Terug
wbfsop5=Start
wbfsop6=Bezig met installeren van [%s] %s...
@ -218,7 +231,7 @@ wbfsop8=Spel geïnstalleerd
wbfsop9=Er is een fout opgetreden
wbfsoperr1=Disc_Wait mislukt
wbfsoperr2=Disc_Open muslukt
wbfsoperr3=Dit is geen Wii disc!
wbfsoperr3=Dit is geen Wii of Gamecube disc!
wbfsoperr4=Dit spel is al geïnstalleerd
wbfsprogress=%i%%
wbfsremdlg=Om het spel: "%s" permanent te verwijderen, klik op Start.