usbloadergx/source/banner/banner.c

125 lines
2.4 KiB
C
Raw Normal View History

/****************************************************************************
* USB Loader GX Team
* banner.c
*
* Dump opening.bnr thanks to Wiipower
***************************************************************************/
#include <gctypes.h>
#include <gccore.h>
#include <ogcsys.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <malloc.h>
#include "libfat/fat.h"
#include "fatmounter.h"
#include "usbloader/wdvd.h"
#include "usbloader/disc.h"
#include "banner.h"
#include "patches/fst.h"
#include "usbloader/fstfile.h"
2010-09-24 02:48:03 +02:00
s32 dump_banner(const u8* discid, const char * dest)
{
// Mount the disc
//Disc_SetWBFS(1, (u8*)discid);
2010-09-24 02:48:03 +02:00
Disc_SetUSB(discid);
Disc_Open();
u64 offset;
s32 ret;
2010-09-24 02:48:03 +02:00
ret = __Disc_FindPartition(&offset);
if (ret < 0) return ret;
2010-09-24 02:48:03 +02:00
ret = WDVD_OpenPartition(offset);
2010-09-24 02:48:03 +02:00
if (ret < 0)
{
//printf("ERROR: OpenPartition(0x%llx) %d\n", offset, ret);
return ret;
}
// Read where to find the fst.bin
2010-09-24 02:48:03 +02:00
u32 *buffer = memalign(32, 0x20);
2010-09-24 02:48:03 +02:00
if (buffer == NULL)
{
//Out of memory
return -1;
}
2010-09-24 02:48:03 +02:00
ret = WDVD_Read(buffer, 0x20, 0x420);
if (ret < 0) return ret;
// Read fst.bin
2010-09-24 02:48:03 +02:00
void *fstbuffer = memalign(32, buffer[2] * 4);
FST_ENTRY *fst = (FST_ENTRY *) fstbuffer;
2010-09-24 02:48:03 +02:00
if (fst == NULL)
{
//Out of memory
2010-09-24 02:48:03 +02:00
free(buffer);
return -1;
}
2010-09-24 02:48:03 +02:00
ret = WDVD_Read(fstbuffer, buffer[2] * 4, buffer[1] * 4);
if (ret < 0) return ret;
2010-09-24 02:48:03 +02:00
free(buffer);
// Search the fst.bin
u32 count = fst[0].filelen;
int i;
u32 index = 0;
2010-09-24 02:48:03 +02:00
for (i = 1; i < count; i++)
{
2010-09-24 02:48:03 +02:00
if (strstr(fstfiles(fst, i), "opening.bnr") != NULL)
{
index = i;
}
}
2010-09-24 02:48:03 +02:00
if (index == 0)
{
//opening.bnr not found
2010-09-24 02:48:03 +02:00
free(fstbuffer);
return -1;
}
// Load the .bnr
2010-09-24 02:48:03 +02:00
u8 *banner = memalign(32, fst[index].filelen);
2010-09-24 02:48:03 +02:00
if (banner == NULL)
{
//Out of memory
2010-09-24 02:48:03 +02:00
free(fstbuffer);
return -1;
}
2010-09-24 02:48:03 +02:00
ret = WDVD_Read((void *) banner, fst[index].filelen, fst[index].fileoffset * 4);
if (ret < 0) return ret;
WDVD_Reset();
WDVD_ClosePartition();
//fatInitDefault();
//SDCard_Init();
2010-09-24 02:48:03 +02:00
WDVD_SetUSBMode(NULL, 0);
FILE *fp = fopen(dest, "wb");
if (fp)
{
2010-09-24 02:48:03 +02:00
fwrite(banner, 1, fst[index].filelen, fp);
fclose(fp);
}
2010-09-24 02:48:03 +02:00
free(fstbuffer);
free(banner);
return 1;
}