2012-07-06 02:36:45 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Copyright (C) 2012 FIX94
|
|
|
|
*
|
|
|
|
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
****************************************************************************/
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2012-08-05 15:48:15 +02:00
|
|
|
#include "gc.hpp"
|
2012-07-06 02:36:45 +02:00
|
|
|
#include "gcdisc.hpp"
|
2013-09-21 16:03:45 +02:00
|
|
|
#include "fileOps/fileOps.h"
|
2012-07-06 02:36:45 +02:00
|
|
|
#include "loader/gc_disc_dump.hpp"
|
2012-12-08 17:17:35 +01:00
|
|
|
#include "gecko/gecko.hpp"
|
2012-08-05 15:48:15 +02:00
|
|
|
#include "memory/mem2.hpp"
|
2013-09-21 16:03:45 +02:00
|
|
|
#include "gui/fmt.h"
|
2012-07-06 02:36:45 +02:00
|
|
|
|
2013-09-21 16:03:45 +02:00
|
|
|
GC_Disc GC_Disc_Reader;
|
2012-07-06 02:36:45 +02:00
|
|
|
|
2013-01-21 00:30:28 +01:00
|
|
|
void GC_Disc::init(const char *path)
|
2012-07-06 02:36:45 +02:00
|
|
|
{
|
2013-09-21 16:03:45 +02:00
|
|
|
strncpy(GamePath, path, MAX_FAT_PATH);
|
2012-07-06 02:36:45 +02:00
|
|
|
opening_bnr = NULL;
|
2012-07-27 00:09:20 +02:00
|
|
|
FSTable = NULL;
|
|
|
|
|
|
|
|
FILE *f = NULL;
|
2013-09-21 16:03:45 +02:00
|
|
|
u32 FSTSize = 0;
|
|
|
|
if(strstr(GamePath, "boot.bin") != NULL)
|
2012-07-06 02:36:45 +02:00
|
|
|
{
|
|
|
|
GameType = TYPE_FST;
|
2013-09-21 16:03:45 +02:00
|
|
|
if(strchr(GamePath, '/') != NULL) //boot.bin
|
|
|
|
*strrchr(GamePath, '/') = '\0';
|
|
|
|
if(strchr(GamePath, '/') != NULL) //sys
|
|
|
|
*strrchr(GamePath, '/') = '\0';
|
2013-09-24 17:21:31 +02:00
|
|
|
char *FstPath = fmt_malloc("%s/sys/fst.bin", GamePath);
|
|
|
|
if(FstPath != NULL)
|
|
|
|
{
|
|
|
|
fsop_GetFileSizeBytes(FstPath, &FSTSize);
|
|
|
|
f = fopen(FstPath, "rb");
|
|
|
|
MEM2_free(FstPath);
|
|
|
|
}
|
2012-07-06 02:36:45 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-09-22 00:03:41 +02:00
|
|
|
if(strstr(GamePath, ".ciso") != NULL)
|
|
|
|
return;
|
2012-07-06 02:36:45 +02:00
|
|
|
GameType = TYPE_ISO;
|
|
|
|
f = fopen(GamePath, "rb");
|
2012-07-27 00:09:20 +02:00
|
|
|
if(f == NULL)
|
|
|
|
return;
|
2013-09-21 16:03:45 +02:00
|
|
|
u8 *ReadBuffer = (u8*)MEM2_alloc(0x440);
|
2012-07-27 00:09:20 +02:00
|
|
|
if(ReadBuffer == NULL)
|
|
|
|
return;
|
2012-07-06 02:36:45 +02:00
|
|
|
fread(ReadBuffer, 1, 0x440, f);
|
2013-09-21 16:03:45 +02:00
|
|
|
u32 FSTOffset = *(u32*)(ReadBuffer + 0x424);
|
|
|
|
FSTSize = *(u32*)(ReadBuffer + 0x428);
|
|
|
|
MEM2_free(ReadBuffer);
|
2012-07-06 02:36:45 +02:00
|
|
|
fseek(f, FSTOffset, SEEK_SET);
|
2013-09-21 16:03:45 +02:00
|
|
|
}
|
|
|
|
if(f != NULL)
|
|
|
|
{
|
2012-07-06 02:36:45 +02:00
|
|
|
Read_FST(f, FSTSize);
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GC_Disc::clear()
|
|
|
|
{
|
2013-09-21 16:03:45 +02:00
|
|
|
if(opening_bnr != NULL)
|
2012-07-06 02:36:45 +02:00
|
|
|
{
|
2013-09-21 16:03:45 +02:00
|
|
|
MEM2_free(opening_bnr);
|
2012-07-06 02:36:45 +02:00
|
|
|
opening_bnr = NULL;
|
|
|
|
}
|
2013-09-21 16:03:45 +02:00
|
|
|
if(FSTable != NULL)
|
2012-07-06 02:36:45 +02:00
|
|
|
{
|
2013-09-21 16:03:45 +02:00
|
|
|
MEM2_free(FSTable);
|
2012-07-06 02:36:45 +02:00
|
|
|
FSTable = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GC_Disc::Read_FST(FILE *f, u32 FST_size)
|
|
|
|
{
|
2013-09-21 16:03:45 +02:00
|
|
|
if(f == NULL)
|
|
|
|
return;
|
|
|
|
FSTable = (u8*)MEM2_alloc(FST_size);
|
2012-07-27 00:09:20 +02:00
|
|
|
if(FSTable == NULL)
|
|
|
|
return;
|
2012-07-06 02:36:45 +02:00
|
|
|
fread(FSTable, 1, FST_size, f);
|
|
|
|
|
2013-09-21 16:03:45 +02:00
|
|
|
FSTEnt = *(u32*)(FSTable + 0x08);
|
2012-07-06 02:36:45 +02:00
|
|
|
FSTNameOff = (char*)(FSTable + FSTEnt * 0x0C);
|
|
|
|
}
|
|
|
|
|
|
|
|
u8 *GC_Disc::GetGameCubeBanner()
|
|
|
|
{
|
2013-09-21 16:03:45 +02:00
|
|
|
if(FSTable == NULL || GamePath == NULL)
|
2012-07-27 00:09:20 +02:00
|
|
|
return NULL;
|
2013-09-21 16:03:45 +02:00
|
|
|
|
|
|
|
FILE *bnr_fp = NULL;
|
|
|
|
u32 BnrSize = 0;
|
|
|
|
|
|
|
|
FST *fst = (FST*)FSTable;
|
2012-07-06 02:36:45 +02:00
|
|
|
for(u32 i = 1; i < FSTEnt; ++i)
|
|
|
|
{
|
|
|
|
if(fst[i].Type) //Folder
|
|
|
|
continue;
|
2013-09-21 16:03:45 +02:00
|
|
|
else if(strcmp(FSTNameOff + fst[i].NameOffset, "opening.bnr") == 0)
|
2012-07-06 02:36:45 +02:00
|
|
|
{
|
|
|
|
if(GameType == TYPE_FST)
|
2013-09-21 16:03:45 +02:00
|
|
|
bnr_fp = fopen(fmt("%s/root/opening.bnr", GamePath), "rb");
|
2012-07-06 02:36:45 +02:00
|
|
|
else
|
|
|
|
{
|
2013-09-21 16:03:45 +02:00
|
|
|
bnr_fp = fopen(GamePath, "rb");
|
|
|
|
if(bnr_fp != NULL)
|
|
|
|
fseek(bnr_fp, fst[i].FileOffset, SEEK_SET);
|
2012-07-06 02:36:45 +02:00
|
|
|
}
|
2013-09-21 16:03:45 +02:00
|
|
|
BnrSize = fst[i].FileLength;
|
|
|
|
break;
|
2012-07-06 02:36:45 +02:00
|
|
|
}
|
|
|
|
}
|
2013-09-21 16:03:45 +02:00
|
|
|
|
|
|
|
if(bnr_fp != NULL)
|
|
|
|
{
|
|
|
|
opening_bnr = (u8*)MEM2_alloc(BnrSize);
|
|
|
|
if(opening_bnr != NULL && fread(opening_bnr, 1, BnrSize, bnr_fp) != BnrSize)
|
|
|
|
MEM2_free(opening_bnr);
|
|
|
|
fclose(bnr_fp);
|
|
|
|
}
|
2012-07-06 02:36:45 +02:00
|
|
|
return opening_bnr;
|
|
|
|
}
|