From 41297b6d8e8b90790ff449a5a073357d02174c18 Mon Sep 17 00:00:00 2001 From: mtabachenko Date: Mon, 21 Dec 2009 14:06:04 +0000 Subject: [PATCH] core: - the type of ROM serial code is changed (now NTR-****-***) --- desmume/src/NDSSystem.cpp | 52 +++++++++++++++++++++------ desmume/src/NDSSystem.h | 2 ++ desmume/src/cheatSystem.cpp | 10 ++++-- desmume/src/common.cpp | 18 ++++++++++ desmume/src/common.h | 1 + desmume/src/windows/console.cpp | 30 ++++++++-------- tools/cheatsConverter/src/convert.cpp | 36 +++++++++++++++++-- 7 files changed, 119 insertions(+), 30 deletions(-) diff --git a/desmume/src/NDSSystem.cpp b/desmume/src/NDSSystem.cpp index 1629cb1d2..4b0a01eec 100644 --- a/desmume/src/NDSSystem.cpp +++ b/desmume/src/NDSSystem.cpp @@ -266,10 +266,28 @@ static u32 ones32(u32 x) void GameInfo::populate() { + const char *regions[] = { "JPFSEDIRKH", + "JPN", + "EUR", + "FRA", + "ESP", + "USA", + "NOE", + "ITA", + "RUS", + "KOR", + "HOL", + + }; + NDS_header * _header = NDS_getROMHeader(); header = *_header; delete _header; + memset(ROMserial, 0, sizeof(ROMserial)); + memset(ROMname, 0, sizeof(ROMname)); + memset(ROMfullName, 0, sizeof(ROMfullName)); + if ( // ??? in all Homebrews game title have is 2E0000EA //( @@ -290,16 +308,28 @@ void GameInfo::populate() header.makerCode == 0x0 ) { - memset(ROMserial, 0, sizeof(ROMserial)); strcpy(ROMserial, "Homebrew"); } else { - memset(ROMserial, '_', sizeof(ROMserial)); - memcpy(ROMserial, header.gameTile, strlen(header.gameTile) < 12 ? strlen(header.gameTile) : 12); - memcpy(ROMserial+12+1, header.gameCode, 4); - memcpy(ROMserial+12+1+4, &header.makerCode, 2); - memset(ROMserial+19, '\0', 1); + strcpy(ROMserial,"NTR- -"); + memcpy(ROMserial+4, header.gameCode, 4); + + u32 region = (u32)(std::max(strchr(regions[0],header.gameCode[3]) - regions[0] + 1, 0)); + if (region != 0) + strcat(ROMserial, regions[region]); + else + strcat(ROMserial, "Unknown"); + memcpy(ROMname, header.gameTile, 12); + trim(ROMname); + + u8 num = (T1ReadByte((u8*)romdata, header.IconOff) == 1)?6:7; + for (int i = 0; i < num; i++) + { + wcstombs(ROMfullName[i], (wchar_t *)(romdata+header.IconOff+0x240+(i*0x100)), 0x100); + trim(ROMfullName[i]); + } + } } #ifdef WIN32 @@ -408,8 +438,9 @@ int NDS_LoadROM(const char *filename, const char *logicalFilename) gameInfo.populate(); gameInfo.crc = crc32(0,(u8*)gameInfo.romdata,gameInfo.romsize); - INFO("\nROM crc: %08X\n\n", gameInfo.crc); - INFO("\nROM serial: %s\n", gameInfo.ROMserial); + INFO("\nROM crc: %08X\n", gameInfo.crc); + INFO("ROM serial: %s\n", gameInfo.ROMserial); + INFO("ROM internal name: %s\n\n", gameInfo.ROMname); return 1; } @@ -528,8 +559,9 @@ int NDS_LoadROM(const char *filename, const char *logicalFilename) gameInfo.populate(); gameInfo.crc = crc32(0,data,size); - INFO("\nROM crc: %08X\n\n", gameInfo.crc); - INFO("\nROM serial: %s\n", gameInfo.ROMserial); + INFO("\nROM crc: %08X\n", gameInfo.crc); + INFO("ROM serial: %s\n", gameInfo.ROMserial); + INFO("ROM internal name: %s\n\n", gameInfo.ROMname); return ret; } diff --git a/desmume/src/NDSSystem.h b/desmume/src/NDSSystem.h index 7b830f414..6698d93fa 100644 --- a/desmume/src/NDSSystem.h +++ b/desmume/src/NDSSystem.h @@ -284,6 +284,8 @@ struct GameInfo u32 crc; NDS_header header; char ROMserial[20]; + char ROMname[20]; + char ROMfullName[7][0x100]; void populate(); char* romdata; int romsize; diff --git a/desmume/src/cheatSystem.cpp b/desmume/src/cheatSystem.cpp index 409306651..c14d34cd9 100644 --- a/desmume/src/cheatSystem.cpp +++ b/desmume/src/cheatSystem.cpp @@ -543,8 +543,12 @@ BOOL CHEATS::save() if (flist) { fprintf(flist, "; DeSmuME cheats file. VERSION %i.%03i\n", CHEAT_VERSION_MAJOR, CHEAT_VERSION_MINOR); - fprintf(flist, "Name=%s\n", gameInfo.ROMserial); - fputs("; lists list\n", flist); + strcpy(buf, gameInfo.ROMfullName[0]); + trim(buf); + removeSpecialChars(buf); + fprintf(flist, "Name=%s\n", buf); + fprintf(flist, "Serial=%s\n", gameInfo.ROMserial); + fputs("\n; lists list\n", flist); for (int i = 0; i < num; i++) { if (list[i].num == 0) continue; @@ -610,7 +614,7 @@ BOOL CHEATS::load() line++; // only for debug memset(buf, 0, sizeof(buf)); fgets(buf, sizeof(buf), flist); - strcpy(buf, trim(buf)); + trim(buf); if ((strlen(buf) == 0) || (buf[0] == ';')) continue; memset(&tmp_cht, 0, sizeof(tmp_cht)); diff --git a/desmume/src/common.cpp b/desmume/src/common.cpp index 300c6d7cc..b35cbec65 100644 --- a/desmume/src/common.cpp +++ b/desmume/src/common.cpp @@ -61,3 +61,21 @@ char *trim(char *s) ptr[1] = '\0'; return s; } + +char *removeSpecialChars(char *s) +{ + char *buf = s; + if (!s) return NULL; + if (!*s) return s; + + for (int i = 0; i < strlen(s); i++) + { + if (isspace(s[i]) && (s[i] != 0x20)) + *buf = 0x20; + else + *buf = s[i]; + buf++; + } + *buf = 0; + return s; +} \ No newline at end of file diff --git a/desmume/src/common.h b/desmume/src/common.h index b968f4a01..0753b7fad 100644 --- a/desmume/src/common.h +++ b/desmume/src/common.h @@ -57,6 +57,7 @@ extern u8 logo_data[156]; extern u8 reverseBitsInByte(u8 x); extern char *trim(char *s); +extern char *removeSpecialChars(char *s); #endif diff --git a/desmume/src/windows/console.cpp b/desmume/src/windows/console.cpp index ebc59f4ab..6d2b0fc95 100644 --- a/desmume/src/windows/console.cpp +++ b/desmume/src/windows/console.cpp @@ -1,6 +1,4 @@ -/* Copyright (C) 2006 yopyop - Copyright (C) 2008 CrazyMax (mtabachenko) - Copyright (C) 2009 DeSmuME team +/* Copyright 2008-2009 DeSmuME team This file is part of DeSmuME @@ -16,7 +14,7 @@ You should have received a copy of the GNU General Public License along with DeSmuME; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "../common.h" @@ -34,10 +32,10 @@ void printlog(const char *fmt, ...); void OpenConsole() { - COORD csize; - CONSOLE_SCREEN_BUFFER_INFO csbiInfo; - SMALL_RECT srect; - char buf[256]; + COORD csize = {0}; + CONSOLE_SCREEN_BUFFER_INFO csbiInfo = {0}; + SMALL_RECT srect = {0}; + char buf[256] = {0}; //dont do anything if we're already attached if (hConsole) return; @@ -61,40 +59,42 @@ void OpenConsole() //if we failed to attach, then alloc a new console if(!attached) { - AllocConsole(); + if (!AllocConsole()) return; } hConsole = GetStdHandle(STD_OUTPUT_HANDLE); + if (hConsole == INVALID_HANDLE_VALUE) return; //redirect stdio long lStdHandle = (long)hConsole; int hConHandle = _open_osfhandle(lStdHandle, _O_TEXT); if(hConHandle == -1) return; //this fails from a visual studio command prompt +#if 1 FILE *fp = _fdopen( hConHandle, "w" ); +#else + FILE *fp = fopen( "c:\\desmume.log", "w" ); +#endif *stdout = *fp; //and stderr *stderr = *fp; - memset(buf,0,256); sprintf(buf,"%s OUTPUT", EMU_DESMUME_NAME_AND_VERSION()); SetConsoleTitle(TEXT(buf)); csize.X = 60; csize.Y = 800; - SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), csize); - GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbiInfo); + SetConsoleScreenBufferSize(hConsole, csize); + GetConsoleScreenBufferInfo(hConsole, &csbiInfo); srect = csbiInfo.srWindow; srect.Right = srect.Left + 99; srect.Bottom = srect.Top + 64; - SetConsoleWindowInfo(GetStdHandle(STD_OUTPUT_HANDLE), TRUE, &srect); + SetConsoleWindowInfo(hConsole, TRUE, &srect); SetConsoleCP(GetACP()); SetConsoleOutputCP(GetACP()); if(attached) printlog("\n"); printlog("%s\n",EMU_DESMUME_NAME_AND_VERSION()); printlog("- compiled: %s %s\n\n",__DATE__,__TIME__); - - } void CloseConsole() { diff --git a/tools/cheatsConverter/src/convert.cpp b/tools/cheatsConverter/src/convert.cpp index 901ce6108..8866592fd 100644 --- a/tools/cheatsConverter/src/convert.cpp +++ b/tools/cheatsConverter/src/convert.cpp @@ -23,12 +23,41 @@ #include #include #include +#include #include "convert.h" CHEATS_LIST list[MAX_CHEAT_LIST] = {0}; u32 num = 0; char ROMserial[50] = {0}; +static void convertSerial() +{ + const char *regions[] = { "JPFSEDIRKH", + "JPN", + "EUR", + "FRA", + "ESP", + "USA", + "NOE", + "ITA", + "RUS", + "KOR", + "HOL", + + }; + char buf[5] = {0}; + + if (!ROMserial[0]) return; + + memcpy(buf, &ROMserial[strlen(ROMserial)-6], 4); + sprintf(ROMserial, "NTR-%s-", buf); + u32 region = (u32)(std::max(strchr(regions[0], buf[3]) - regions[0] + 1, 0)); + if (region != 0) + strcat(ROMserial, regions[region]); + else + memset(ROMserial, 0, sizeof(ROMserial)); +} + static void cheatsClear() { memset(list, 0, sizeof(list)); @@ -47,8 +76,9 @@ bool save(char *filename) if (flist) { fprintf(flist, "; DeSmuME cheat file. VERSION %i.%03i\n", CHEAT_VERSION_MAJOR, CHEAT_VERSION_MINOR); - fprintf(flist, "Name=%s\n", ROMserial); - fputs("; lists list\n", flist); + fprintf(flist, "Name=\n"); + fprintf(flist, "Serial=%s\n", ROMserial); + fputs("\n; lists list\n", flist); for (unsigned int i = 0; i < num; i++) { if (list[i].num == 0) continue; @@ -199,6 +229,8 @@ bool load_1_3(char *fname) //INFO("Loaded %i cheats\n", last); num = last; + + convertSerial(); return true; } return false;