Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions arm9/source/dsrom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
#include "unknown_nds_banner_bin.h"

namespace {
constexpr long ndzBannerOffset = 0x10;
constexpr long ndzGameCodeOffset = 0x2410;
constexpr long ndzHeaderCrcOffset = 0x2418;

const u16* iconBackground() {
static u16 background[32 * 32];
static int cachedSource = -1;
Expand Down Expand Up @@ -49,6 +53,7 @@ DSRomInfo& DSRomInfo::operator=(const DSRomInfo& src) {
_isDSiWare = src._isDSiWare;
_isModernHomebrew = src._isModernHomebrew;
_isGbaRom = src._isGbaRom;
_isNdz = src._isNdz;
_fileName = src._fileName;
_romVersion = src._romVersion;
_extIcon = src._extIcon;
Expand All @@ -60,6 +65,7 @@ bool DSRomInfo::loadDSRomInfo(const std::string& filename, bool loadBanner) {
_isHomebrew = EFalse;
_isDSiWare = EFalse;
_isModernHomebrew = EFalse;
_isNdz = false;
FILE* f = fopen(filename.c_str(), "rb");
if (NULL == f) // 锟斤拷锟侥硷拷失锟斤拷
{
Expand All @@ -76,6 +82,27 @@ bool DSRomInfo::loadDSRomInfo(const std::string& filename, bool loadBanner) {
return false;
}

if (0 == memcmp(&header, "NDZ1", 4)) {
_isNdz = true;
_isDSRom = ETrue;
fseek(f, ndzGameCodeOffset, SEEK_SET);
fread(_saveInfo.gameCode, 1, sizeof(_saveInfo.gameCode), f);
fseek(f, ndzHeaderCrcOffset, SEEK_SET);
fread(&_saveInfo.gameCRC, 1, sizeof(_saveInfo.gameCRC), f);
saveManager().updateSaveInfoByInfo(_saveInfo);

tNDSBanner banner;
fseek(f, ndzBannerOffset, SEEK_SET);
if (sizeof(tNDSBanner) == fread(&banner, 1, sizeof(banner), f) &&
swiCRC16(0xffff, banner.icon, 0x840 - 32) == banner.crc) {
memcpy(&_banner, &banner, sizeof(_banner));
} else {
loadBannerIcon(_banner, "nds_banner.bin", nds_banner_bin);
}
fclose(f);
return true;
}

if (header.unitCode == 0x03) {
_isDSiWare = ETrue;
}
Expand Down Expand Up @@ -357,6 +384,11 @@ bool DSRomInfo::isGbaRom(void) {
return (_isGbaRom == ETrue) ? true : false;
}

bool DSRomInfo::isNdz(void) {
load();
return _isNdz;
}

void DSRomInfo::setExtIcon(const std::string& aValue) {
_extIcon = fileIcons().Icon(aValue);
};
Expand Down
4 changes: 3 additions & 1 deletion arm9/source/dsrom.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class DSRomInfo {
TBool _isHomebrew;
TBool _isModernHomebrew;
TBool _isGbaRom;
bool _isNdz;
std::string _fileName;
s32 _extIcon;
u8 _romVersion;
Expand All @@ -37,7 +38,7 @@ class DSRomInfo {

public:
DSRomInfo()
: _isDSRom(EFalse), _isDSiWare(EFalse), _isHomebrew(EFalse), _isModernHomebrew(EFalse), _isGbaRom(EFalse), _extIcon(-1), _romVersion(0) {
: _isDSRom(EFalse), _isDSiWare(EFalse), _isHomebrew(EFalse), _isModernHomebrew(EFalse), _isGbaRom(EFalse), _isNdz(false), _extIcon(-1), _romVersion(0) {
// memcpy(&_banner,unknown_banner_bin,unknown_banner_bin_size);
memset(&_banner, 0, sizeof(_banner));
memset(&_saveInfo, 0, sizeof(_saveInfo));
Expand All @@ -56,6 +57,7 @@ class DSRomInfo {
bool isHomebrew(void);
bool isModernHomebrew(void);
bool isGbaRom(void);
bool isNdz(void);
DSRomInfo& operator=(const DSRomInfo& src);
void MayBeDSRom(const std::string& filename) {
_isDSRom = EMayBe;
Expand Down
2 changes: 1 addition & 1 deletion arm9/source/romlauncher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ TLaunchResult launchRom(const std::string& aFullPath, DSRomInfo& aRomInfo, bool

u8 loader = aRomInfo.saveInfo().getLoader();
// loader = 0: pico, 1: nds-bootstrap, 2: global
if(((gs().pico && loader == 2) || loader == 0) && aFullPath[0] != 's'){ //roms can only be launched from the sd with nds-bootstrap
if(aRomInfo.isNdz() || (((gs().pico && loader == 2) || loader == 0) && aFullPath[0] != 's')){ //roms can only be launched from the sd with nds-bootstrap
launcher = new DSpicoLauncher();
}
else {
Expand Down
Loading