From 4e6a7f04246049a13090617ab9d0efe5ada6280f Mon Sep 17 00:00:00 2001 From: rogerman Date: Mon, 24 Jul 2023 13:46:05 -0700 Subject: [PATCH] Cheat System: Fix a couple bugs with CheatDBFile::LoadGameList() when reading the entire database's game list. - Fix a bug where loading all database game entries from an encrypted database would result in reading gobbledygook. - Fix a bug where calling CheatDBFile::LoadGameList() for all database game entries would always return 0 entries rather than the actual number of found entries. --- desmume/src/cheatSystem.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/desmume/src/cheatSystem.cpp b/desmume/src/cheatSystem.cpp index 25072ab8e..55f4b82c2 100755 --- a/desmume/src/cheatSystem.cpp +++ b/desmume/src/cheatSystem.cpp @@ -2352,6 +2352,12 @@ u32 CheatDBFile::LoadGameList(const char *gameCode, const u32 gameDatabaseCRC, C if ((pos >> 9) > t) { t++; + if ( (t << 9) > this->_size) + { + break; + } + + fseek(this->_fp, t << 9, SEEK_SET); fread(fatBuffer, 1, 512, this->_fp); CheatDBFile::R4Decrypt(fatBuffer, 512, t); } @@ -2421,6 +2427,7 @@ u32 CheatDBFile::LoadGameList(const char *gameCode, const u32 gameDatabaseCRC, C else { outList.push_back( this->_ReadGame(encryptOffset, fatEntryCurrent, dataSize, gameEntryBuffer) ); + entryCount++; } } while (fatEntryNext.addr > 0);