diff --git a/desmume/src/NDSSystem.cpp b/desmume/src/NDSSystem.cpp index e3f8a5f02..a752c08f1 100644 --- a/desmume/src/NDSSystem.cpp +++ b/desmume/src/NDSSystem.cpp @@ -766,7 +766,7 @@ int NDS_LoadROM( const char *filename, else if ( !strcasecmp(extROM, ".gba") && !strcasecmp(extROM2, ".ds")) type = ROM_DSGBA; else - return -1; + type = ROM_NDS; file = reader->Init(filename); if (!file) @@ -819,9 +819,15 @@ int NDS_LoadROM( const char *filename, //decrypt if necessary.. //but this is untested and suspected to fail on big endian, so lets not support this on big endian #ifndef WORDS_BIGENDIAN - DecryptSecureArea(data,size); + bool okRom = DecryptSecureArea(data,size); + + if(!okRom) { + printf("Specified file is not a valid rom\n"); + return -1; + } #endif + MMU_unsetRom(); NDS_SetROM(data, mask); NDS_Reset(); diff --git a/desmume/src/gfx3d.cpp b/desmume/src/gfx3d.cpp index fb76ce814..ff54b483a 100644 --- a/desmume/src/gfx3d.cpp +++ b/desmume/src/gfx3d.cpp @@ -1412,8 +1412,9 @@ static bool gfx3d_ysort_compare(int num1, int num2) const POLY &poly1 = polylist->list[num1]; const POLY &poly2 = polylist->list[num2]; - if (poly1.maxy > poly2.maxy) return true; - if (poly1.maxy < poly2.maxy) return false; + //this may be verified by checking the game create menus in harvest moon island of happiness + if (poly1.maxy > poly2.maxy) return false; + if (poly1.maxy < poly2.maxy) return true; if (poly1.miny < poly2.miny) return true; if (poly1.miny > poly2.miny) return false; return false; //equal should always return false "strict weak ordering" diff --git a/desmume/src/utils/decrypt/decrypt.cpp b/desmume/src/utils/decrypt/decrypt.cpp index dc648c970..9a0de58e1 100644 --- a/desmume/src/utils/decrypt/decrypt.cpp +++ b/desmume/src/utils/decrypt/decrypt.cpp @@ -449,7 +449,7 @@ static void decrypt_arm9(u32 cardheader_gamecode, unsigned char *data) } -void DecryptSecureArea(u8 *romdata, long romlen) +bool DecryptSecureArea(u8 *romdata, long romlen) { //this looks like it will only work on little endian hosts Header* header = (Header*)romdata; @@ -465,6 +465,9 @@ void DecryptSecureArea(u8 *romdata, long romlen) unsigned int sbox_offsets = 0x2800; #endif + if(romType == ROMTYPE_INVALID) + return false; + // check if ROM is already encrypted if (romType == ROMTYPE_NDSDUMPED) { @@ -498,4 +501,6 @@ void DecryptSecureArea(u8 *romdata, long romlen) { printf("File doesn't appear to have a secure area.\n"); } + + return true; } diff --git a/desmume/src/utils/decrypt/decrypt.h b/desmume/src/utils/decrypt/decrypt.h index 503da906f..d279d560d 100644 --- a/desmume/src/utils/decrypt/decrypt.h +++ b/desmume/src/utils/decrypt/decrypt.h @@ -21,6 +21,6 @@ #ifndef _DECRYPT_H_ #define _DECRYPT_H_ -void DecryptSecureArea(u8 *romdata, long romlen); +bool DecryptSecureArea(u8 *romdata, long romlen); #endif diff --git a/desmume/src/utils/decrypt/header.cpp b/desmume/src/utils/decrypt/header.cpp index 007fde447..7b8559108 100644 --- a/desmume/src/utils/decrypt/header.cpp +++ b/desmume/src/utils/decrypt/header.cpp @@ -69,6 +69,10 @@ int DetectRomType(const Header& header, char* romdata) { unsigned int * data = (unsigned int*)(romdata + 0x4000); + + //this is attempting to check for an utterly invalid nds header + if(header.unitcode != 0) return ROMTYPE_INVALID; + if (header.arm9_rom_offset < 0x4000) return ROMTYPE_HOMEBREW; if (data[0] == 0x00000000 && data[1] == 0x00000000) return ROMTYPE_MULTIBOOT; if (data[0] == 0xE7FFDEFF && data[1] == 0xE7FFDEFF) return ROMTYPE_NDSDUMPED; diff --git a/desmume/src/utils/decrypt/header.h b/desmume/src/utils/decrypt/header.h index df42908cb..a8eb9c380 100644 --- a/desmume/src/utils/decrypt/header.h +++ b/desmume/src/utils/decrypt/header.h @@ -129,5 +129,6 @@ unsigned short CalcSecureAreaCRC(bool encrypt); #define ROMTYPE_NDSDUMPED 2 // decrypted secure area #define ROMTYPE_ENCRSECURE 3 #define ROMTYPE_MASKROM 4 // unknown layout +#define ROMTYPE_INVALID 5 // rejected; can't be a supported rom #endif