use NDSHeader struct, and expand it with the DSi shit

This commit is contained in:
Arisotura 2021-08-26 18:59:07 +02:00
parent 7395d6a6c0
commit 36672a4089
4 changed files with 131 additions and 43 deletions

View File

@ -733,7 +733,7 @@ bool TitleExists(u32 category, u32 titleid)
return (res == FR_OK);
}
void GetTitleInfo(u32 category, u32 titleid, u32& version, u8* header, u8* banner)
void GetTitleInfo(u32 category, u32 titleid, u32& version, NDSHeader* header, NDSBanner* banner)
{
version = GetTitleVersion(category, titleid);
if (version == 0xFFFFFFFF)
@ -749,11 +749,11 @@ void GetTitleInfo(u32 category, u32 titleid, u32& version, u8* header, u8* banne
return;
u32 nread;
f_read(&file, header, 0x1000, &nread);
f_read(&file, header, sizeof(NDSHeader), &nread);
if (banner)
{
u32 banneraddr = *(u32*)&header[0x68];
u32 banneraddr = header->BannerOffset;
if (!banneraddr)
{
memset(banner, 0, 0x2400);
@ -761,7 +761,7 @@ void GetTitleInfo(u32 category, u32 titleid, u32& version, u8* header, u8* banne
else
{
f_lseek(&file, banneraddr);
f_read(&file, banner, 0x2400, &nread);
f_read(&file, banner, sizeof(NDSBanner), &nread);
}
}
@ -991,16 +991,16 @@ void DeleteTitle(u32 category, u32 titleid)
u32 GetTitleDataMask(u32 category, u32 titleid)
{
u32 version;
u8 header[0x1000];
NDSHeader header;
GetTitleInfo(category, titleid, version, header, nullptr);
GetTitleInfo(category, titleid, version, &header, nullptr);
if (version == 0xFFFFFFFF)
return 0;
u32 ret = 0;
if (*(u32*)&header[0x238] != 0) ret |= (1 << TitleData_PublicSav);
if (*(u32*)&header[0x23C] != 0) ret |= (1 << TitleData_PrivateSav);
if (header[0x1BF] & 0x04) ret |= (1 << TitleData_BannerSav);
if (header.DSiPublicSavSize != 0) ret |= (1 << TitleData_PublicSav);
if (header.DSiPrivateSavSize != 0) ret |= (1 << TitleData_PrivateSav);
if (header.AppFlags & 0x04) ret |= (1 << TitleData_BannerSav);
return ret;
}

View File

@ -20,6 +20,7 @@
#define DSI_NAND_H
#include "types.h"
#include "NDS_Header.h"
#include <vector>
#include <string>
@ -42,7 +43,7 @@ void PatchTSC();
void ListTitles(u32 category, std::vector<u32>& titlelist);
bool TitleExists(u32 category, u32 titleid);
void GetTitleInfo(u32 category, u32 titleid, u32& version, u8* header, u8* banner);
void GetTitleInfo(u32 category, u32 titleid, u32& version, NDSHeader* header, NDSBanner* banner);
bool ImportTitle(const char* appfile, u8* tmd, bool readonly);
void DeleteTitle(u32 category, u32 titleid);

View File

@ -30,7 +30,8 @@ struct NDSHeader
u8 UnitCode;
u8 EncryptionSeedSelect;
u8 CardSize;
u8 Reserved1[8];
u8 Reserved1[7];
u8 DSiCryptoFlags;
u8 NDSRegion;
u8 ROMVersion;
u8 Autostart;
@ -44,7 +45,7 @@ struct NDSHeader
u32 ARM7EntryAddress;
u32 ARM7RAMAddress;
u32 ARM7Size;
u32 FNTOffset;
u32 FNTSize;
u32 FATOffset;
@ -54,40 +55,133 @@ struct NDSHeader
u32 ARM9OverlaySize;
u32 ARM7OverlayOffset;
u32 ARM7OverlaySize;
u32 NormalCommandSettings;
u32 Key1CommandSettings;
u32 BannerOffset;
u16 SecureAreaCRC16;
u16 SecureAreaDelay;
// GBATEK lists the following two with a question mark
u32 ARM9AutoLoadListAddress;
u32 ARM7AutoLoadListAddress;
u64 SecureAreaDisable;
u32 ROMSize;
u32 ROMSize; // excluding DSi area
u32 HeaderSize;
u32 Unknown1;
u8 Reserved2[52];
// GBATEK lists the following two with a question mark
u32 DSiARM9ParamTableOffset;
u32 DSiARM7ParamTableOffset;
// expressed in 0x80000-byte units
u16 NDSRegionEnd;
u16 DSiRegionStart;
// specific to NAND games
u16 NANDROMEnd;
u16 NANDRWStart;
u8 Reserved2[40];
u8 NintendoLogo[156];
u16 NintendoLogoCRC16;
u16 HeaderCRC16;
u32 DebugROMOffset;
u32 DebugSize;
u32 DebugRAMAddress;
u32 Reserved4;
u8 Reserved5[144];
u8 Reserved5[16];
u32 DSiMBKSlots[5]; // global MBK1..MBK5 settings
u32 DSiARM9MBKAreas[3]; // local MBK6..MBK8 settings for ARM9
u32 DSiARM7MBKAreas[3]; // local MBK6..MBK8 settings for ARM7
u8 DSiMBKWriteProtect[3]; // global MBK9 setting
u8 DSiWRAMCntSetting; // global WRAMCNT setting
u32 DSiRegionMask;
u32 DSiPermissions;
u8 Reserved6[3];
u8 AppFlags; // flags at 1BF
u32 DSiARM9iROMOffset;
u32 Reserved7;
u32 DSiARM9iRAMAddress;
u32 DSiARM9iSize;
u32 DSiARM7iROMOffset;
u32 DSiSDMMCDeviceList;
u32 DSiARM7iRAMAddress;
u32 DSiARM7iSize;
u32 DSiDigestNTROffset;
u32 DSiDigestNTRSize;
u32 DSiDigestTWLOffset;
u32 DSiDigestTWLSize;
u32 DSiDigestSecHashtblOffset;
u32 DSiDigestSecHashtblSize;
u32 DSiDigestBlkHashtblOffset;
u32 DSiDigestBlkHashtblSize;
u32 DSiDigestSecSize; // sector size in bytes
u32 DSiDigestBlkSecCount; // sectors per block
u32 DSiBannerSize;
// ???
u8 DSiShared0Size;
u8 DSiShared1Size;
u8 DSiEULARatings;
u8 DSiUseRatings;
u32 DSiTotalROMSize;
u8 DSiShared2Size;
u8 DSiShared3Size;
u8 DSiShared4Size;
u8 DSiShared5Size;
// ???
u32 DSiARM9iParamTableOffset;
u32 DSiARM7iParamTableOffset;
u32 DSiModcrypt1Offset;
u32 DSiModcrypt1Size;
u32 DSiModcrypt2Offset;
u32 DSiModcrypt2Size;
u32 DSiTitleIDLow;
u32 DSiTitleIDHigh;
u32 DSiPublicSavSize;
u32 DSiPrivateSavSize;
u8 Reserved8[176];
u8 DSiAgeRatingFlags[16];
// 0x300 - hashes (SHA1-HMAC)
u8 DSiARM9Hash[20];
u8 DSiARM7Hash[20];
u8 DSiDigestMasterHash[20];
u8 BannerHash[20];
u8 DSiARM9iHash[20];
u8 DSiARM7iHash[20];
u8 HeaderBinariesHash[20]; // 0x160-byte header + ARM9/ARM7 binaries
u8 ARM9OverlayHash[20]; // ARM9 overlay and NitroFAT
u8 DSiARM9NoSecureHash[20]; // ARM9 binary without secure area
u8 Reserved9[2636];
// reserved and unchecked region at 0xE00
u8 Reserved10[384];
u8 HeaderSignature[128]; // RSA-SHA1 across 0x000..0xDFF
};
static_assert(sizeof(NDSHeader) == 512, "NDSHeader is not 512 bytes!");
static_assert(sizeof(NDSHeader) == 4096, "NDSHeader is not 4096 bytes!");
struct NDSBanner
{

View File

@ -106,29 +106,22 @@ TitleManagerDialog::~TitleManagerDialog()
void TitleManagerDialog::createTitleItem(u32 category, u32 titleid)
{
u32 version;
u8 header[0x1000];
u8 banner[0x2400];
NDSHeader header;
NDSBanner banner;
DSi_NAND::GetTitleInfo(category, titleid, version, header, banner);
DSi_NAND::GetTitleInfo(category, titleid, version, &header, &banner);
u8 icongfx[512];
u16 iconpal[16];
memcpy(icongfx, &banner[0x20], 512);
memcpy(iconpal, &banner[0x220], 16*2);
u32 icondata[32*32];
Frontend::ROMIcon(icongfx, iconpal, icondata);
Frontend::ROMIcon(banner.Icon, banner.Palette, icondata);
QImage iconimg((const uchar*)icondata, 32, 32, QImage::Format_ARGB32);
QIcon icon(QPixmap::fromImage(iconimg.copy()));
// TODO: make it possible to select other languages?
u16 titleraw[129];
memcpy(titleraw, &banner[0x340], 128*sizeof(u16));
titleraw[128] = '\0';
QString title = QString::fromUtf16(titleraw);
QString title = QString::fromUtf16(banner.EnglishTitle, 128);
title.replace("\n", " · ");
char gamecode[5];
*(u32*)&gamecode[0] = *(u32*)&header[0xC];
*(u32*)&gamecode[0] = *(u32*)&header.GameCode[0];
gamecode[4] = '\0';
char extra[128];
sprintf(extra, "\n(title ID: %s · %08x/%08x · version %08x)", gamecode, category, titleid, version);
@ -136,9 +129,9 @@ void TitleManagerDialog::createTitleItem(u32 category, u32 titleid)
QListWidgetItem* item = new QListWidgetItem(title + QString(extra));
item->setIcon(icon);
item->setData(Qt::UserRole, QVariant((qulonglong)(((u64)category<<32) | (u64)titleid)));
item->setData(Qt::UserRole+1, QVariant(*(u32*)&header[0x238])); // public.sav size
item->setData(Qt::UserRole+2, QVariant(*(u32*)&header[0x23C])); // private.sav size
item->setData(Qt::UserRole+3, QVariant((u32)((header[0x1BF] & 0x04) ? 0x4000 : 0))); // banner.sav size
item->setData(Qt::UserRole+1, QVariant(header.DSiPublicSavSize)); // public.sav size
item->setData(Qt::UserRole+2, QVariant(header.DSiPrivateSavSize)); // private.sav size
item->setData(Qt::UserRole+3, QVariant((u32)((header.AppFlags & 0x04) ? 0x4000 : 0))); // banner.sav size
ui->lstTitleList->addItem(item);
}