From 36973bfb921bed16449ff8c493d99dcae4dcd521 Mon Sep 17 00:00:00 2001 From: cottonvibes Date: Wed, 12 May 2010 09:33:45 +0000 Subject: [PATCH] - Get pcsx2 to display "game name (region) [serial] [crc]" in the console title-bar based on info found in game database. - Some work on the database_loader class... now loads all game data into memory, and you can switch the game who's data is being read by calling setGame(). - Made the database_loader class a global "GameDB" so that it can be referred to throughout pcsx2 code... git-svn-id: http://pcsx2.googlecode.com/svn/trunk@2983 96395faa-99c1-11dd-bbfe-3dabce05a288 --- pcsx2/CDVD/CDVD.cpp | 6 ++- pcsx2/DataBase_Loader.h | 116 +++++++++++++++++++++++++++++++--------- pcsx2/R5900.cpp | 13 +++-- 3 files changed, 103 insertions(+), 32 deletions(-) diff --git a/pcsx2/CDVD/CDVD.cpp b/pcsx2/CDVD/CDVD.cpp index 9567e669b9..07df8258da 100644 --- a/pcsx2/CDVD/CDVD.cpp +++ b/pcsx2/CDVD/CDVD.cpp @@ -29,6 +29,7 @@ #include "ps2/BiosTools.h" #include "DataBase_Loader.h" +DataBase_Loader GameDB("DataBase.dbf", "Serial"); wxString DiscID; static cdvdStruct cdvd; @@ -346,8 +347,9 @@ static __forceinline void _reloadElfInfo(wxString elfpath) elfptr.Delete(); - DataBase_Loader dbLoader("DataBase.dbf", "Serial", DiscID.ToUTF8().data()); - Console.WriteLn("Game = %s (%s)", dbLoader.getString("Name").c_str(), dbLoader.getString("Region").c_str()); + // Set the Game DataBase to the correct game based on Game Serial Code... + GameDB.setGame(DiscID.ToUTF8().data()); + Console.WriteLn("Game = %s (%s)", GameDB.getString("Name").c_str(), GameDB.getString("Region").c_str()); } void cdvdReloadElfInfo() diff --git a/pcsx2/DataBase_Loader.h b/pcsx2/DataBase_Loader.h index 36b0225979..cfe1b4a77b 100644 --- a/pcsx2/DataBase_Loader.h +++ b/pcsx2/DataBase_Loader.h @@ -13,6 +13,7 @@ * If not, see . */ +#pragma once #include "File_Reader.h" struct key_pair { @@ -22,6 +23,14 @@ struct key_pair { : key(_key) , value(_value) {} }; +class Game_Data { +public: + string id; // Serial Identification Code + deque kList; // List of all (key, value) pairs for game data + Game_Data(string _id) + : id(_id) {} +}; + // DataBase_Loader: // Give the starting Key and Value you're looking for, // and it will extract the necessary data from the database. @@ -50,6 +59,8 @@ private: void extract(string& line, key_pair& keyPair) { stringstream ss(line); string t; + keyPair.key = ""; + keyPair.value = ""; ss >> keyPair.key; if (!line.length() || isComment(keyPair.key)) { doError(line, keyPair); @@ -78,60 +89,113 @@ private: } } public: - deque kList; - DataBase_Loader(string file, string key, string value) { + deque gList; + Game_Data* curGame; + + DataBase_Loader(string file, string key, string value = "") { + curGame = NULL; if (!fileExists(file)) { Console.Error("DataBase_Loader: DataBase Not Found! [%s]", file.c_str()); } File_Reader reader(file); key_pair keyPair("", ""); - string s0, s1; + string s0; try { for(;;) { - keyPair.key = ""; - keyPair.value = ""; - s0 = reader.getLine(); - extract(s0, keyPair); - if ((keyPair.key.compare(key) == 0) - && (keyPair.value.compare(value) == 0)) break; - } - Console.WriteLn("DataBase_Loader: Found Game! [%s]", value.c_str()); - kList.push_back(keyPair); - for (;;) { - s0 = reader.getLine(); - extract(s0, keyPair); - if (keyPair.key.compare("") == 0) continue; - if (keyPair.key.compare(key) == 0) break; - kList.push_back(keyPair); + for(;;) { // Find first game + s0 = reader.getLine(); + extract(s0, keyPair); + if (keyPair.key.compare(key) == 0) break; + } + Game_Data* game = new Game_Data(keyPair.value); + game->kList.push_back(keyPair); + for (;;) { // Fill game data, find new game, repeat... + s0 = reader.getLine(); + extract(s0, keyPair); + if (keyPair.key.compare("") == 0) continue; + if (keyPair.key.compare(key) == 0) { + gList.push_back(game); + game = new Game_Data(keyPair.value); + } + game->kList.push_back(keyPair); + } } } - catch(...) {} - if (!kList.size()) Console.Warning("DataBase_Loader: Game Not Found! [%s]", value.c_str()); + catch(int& i) { i = 0; } + if (!value.compare("")) return; + if (setGame(value)) Console.WriteLn("DataBase_Loader: Found Game! [%s]", value.c_str()); + else Console.Warning("DataBase_Loader: Game Not Found! [%s]", value.c_str()); } - ~DataBase_Loader() {} + + ~DataBase_Loader() { + deque::iterator it = gList.begin(); + for ( ; it != gList.end(); ++it) { + delete it[0]; + } + } + + // Sets the current game to the one matching the serial id given + // Returns true if game found, false if not found... + bool setGame(string id) { + deque::iterator it = gList.begin(); + for ( ; it != gList.end(); ++it) { + if (!it[0]->id.compare(id)) { + curGame = it[0]; + return true; + } + } + return false; + } + + // Gets a string representation of the 'value' for the given key string getString(string key) { - deque::iterator it = kList.begin(); - for ( ; it != kList.end(); ++it) { - if (!it[0].key.compare(key)) { - return it[0].value; + if (curGame) { + deque::iterator it = curGame->kList.begin(); + for ( ; it != curGame->kList.end(); ++it) { + if (!it[0].key.compare(key)) { + return it[0].value; + } } } - return string("???"); + else Console.Error("DataBase_Loader: Game not set!"); + return string(""); } + + // Gets a wxString representation of the 'value' for the given key + wxString getStringWX(string key) { + string s = getString(key); + return wxString(fromAscii(s.c_str())); + } + + // Gets a double representation of the 'value' for the given key double getDouble(string key) { string v = getString(key); return atof(v.c_str()); } + + // Gets a float representation of the 'value' for the given key float getFloat(string key) { string v = getString(key); return (float)atof(v.c_str()); } + + // Gets an integer representation of the 'value' for the given key int getInt(string key) { string v = getString(key); return strtoul(v.c_str(), NULL, 0); } + + // Gets a u8 representation of the 'value' for the given key u8 getU8(string key) { string v = getString(key); return (u8)atoi(v.c_str()); } + + // Gets a bool representation of the 'value' for the given key + u8 getBool(string key) { + string v = getString(key); + return !!atoi(v.c_str()); + } }; + +extern DataBase_Loader GameDB; diff --git a/pcsx2/R5900.cpp b/pcsx2/R5900.cpp index f633fbff09..b061dfd8e8 100644 --- a/pcsx2/R5900.cpp +++ b/pcsx2/R5900.cpp @@ -30,6 +30,7 @@ #include "Elfheader.h" #include "CDVD/CDVD.h" #include "Patch.h" +#include "DataBase_Loader.h" using namespace R5900; // for R5900 disasm tools @@ -576,12 +577,16 @@ __forceinline void CPU_INT( u32 n, s32 ecycle) void __fastcall eeGameStarting() { if (!g_GameStarted && ElfCRC) { - wxString filename( wxsFormat( L"%8.8x", ElfCRC ) ); + wxString gameCRC( wxsFormat( L"%8.8x", ElfCRC ) ); + wxString gameName = GameDB.getStringWX("Name"); + gameName += L" (" + GameDB.getStringWX("Region") + L")"; + gameName += L" [" + DiscID + L"]"; + gameName += L" [" + gameCRC + L"]"; - // if patches found the following status msg will be overwritten - Console.SetTitle(L"Game running [CRC=" + filename +L"]"); + // if patches found the following title will be overwritten + Console.SetTitle(gameName); - if (EmuConfig.EnablePatches) InitPatch(filename); + if (EmuConfig.EnablePatches) InitPatch(gameCRC); GetMTGS().SendGameCRC(ElfCRC); g_GameStarted = true;