diff --git a/desmume/src/NDSSystem.cpp b/desmume/src/NDSSystem.cpp index 9c2aca979..35be85a84 100644 --- a/desmume/src/NDSSystem.cpp +++ b/desmume/src/NDSSystem.cpp @@ -724,7 +724,7 @@ void GameInfo::populate() static std::vector buffer; static std::vector v; -static void loadrom(std::vector* buf, std::string fname) { +static void loadrom(std::string fname) { FILE* inf = fopen(fname.c_str(),"rb"); if(!inf) return; @@ -741,40 +741,33 @@ static void loadrom(std::vector* buf, std::string fname) { int NDS_LoadROM(const char *filename, const char *logicalFilename) { - int type; + int type = ROM_NDS; u32 mask; char buf[MAX_PATH]; if (filename == NULL) return -1; - path.init(filename); + path.init(logicalFilename); if ( path.isdsgba(path.path)) { type = ROM_DSGBA; - loadrom(&buffer, path.path); - gameInfo.romsize = buffer.size(); + loadrom(path.path); } else if ( !strcasecmp(path.extension().c_str(), "nds")) { - loadrom(NULL, path.path); //n.b. this does nothing if the file can't be found (i.e. if it was an extracted tempfile)... + loadrom(path.path); //n.b. this does nothing if the file can't be found (i.e. if it was an extracted tempfile)... //...but since the data was extracted to gameInfo then it is ok type = ROM_NDS; } //ds.gba in archives, it's already been loaded into memory at this point else if (path.isdsgba(std::string(logicalFilename))) { - - std::vector v(gameInfo.romdata, gameInfo.romdata + gameInfo.romsize); - v.erase(v.begin(),v.begin()+DSGBA_LOADER_SIZE); - buffer.assign( v.begin(), v.end() ); - gameInfo.romdata = &buffer[0]; - gameInfo.romsize = buffer.size(); + type = ROM_DSGBA; } if(type == ROM_DSGBA) { - buffer.erase(buffer.begin(),buffer.begin()+DSGBA_LOADER_SIZE); - gameInfo.romdata = &buffer[0]; - gameInfo.romsize = buffer.size(); + std::vector v(gameInfo.romdata + DSGBA_LOADER_SIZE, gameInfo.romdata + gameInfo.romsize); + gameInfo.loadData(&v[0],gameInfo.romsize - DSGBA_LOADER_SIZE); } //check that size is at least the size of the header diff --git a/desmume/src/NDSSystem.h b/desmume/src/NDSSystem.h index d1f6799e3..e12417067 100644 --- a/desmume/src/NDSSystem.h +++ b/desmume/src/NDSSystem.h @@ -254,6 +254,12 @@ struct GameInfo : romdata(NULL) {} + void loadData(char* buf, int size) + { + resize(size); + memcpy(romdata,buf,size); + } + void resize(int size) { if(romdata != NULL) delete[] romdata; romdata = new char[size];