From 21af4012638271aaeb8039bf862027d67d851af3 Mon Sep 17 00:00:00 2001 From: zeromus Date: Tue, 19 Jan 2021 22:46:00 -0500 Subject: [PATCH] make cheat database lookup based on crc instead of game ID, which locates the wrong file half the time when the cheat DB contains two entries with the same game ID (but differing crc). Left the serial check ADDITIONALLY as a backup in case of a crc collision --- desmume/src/cheatSystem.cpp | 3 ++- desmume/src/frontend/windows/cheatsWin.cpp | 4 +--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/desmume/src/cheatSystem.cpp b/desmume/src/cheatSystem.cpp index 14531c4cd..a5860f545 100644 --- a/desmume/src/cheatSystem.cpp +++ b/desmume/src/cheatSystem.cpp @@ -1553,7 +1553,8 @@ bool CHEATSEXPORT::search() } //printf("serial: %s, offset %08X\n", fat.serial, fat.addr); - if (memcmp(gameInfo.header.gameCode, &fat.serial[0], 4) == 0) + if (gameInfo.crcForCheatsDb == fat.CRC + && !memcmp(gameInfo.header.gameCode, &fat.serial[0], 4)) { dataSize = fat_tmp.addr?(fat_tmp.addr - fat.addr):0; if (encrypted) diff --git a/desmume/src/frontend/windows/cheatsWin.cpp b/desmume/src/frontend/windows/cheatsWin.cpp index 45f8f07d9..25a8d16bc 100644 --- a/desmume/src/frontend/windows/cheatsWin.cpp +++ b/desmume/src/frontend/windows/cheatsWin.cpp @@ -1564,8 +1564,6 @@ INT_PTR CALLBACK CheatsExportProc(HWND dialog, UINT msg,WPARAM wparam,LPARAM lpa lvi.pszText= tmp[i].description; SendMessage(exportListView, LVM_INSERTITEM, 0, (LPARAM)&lvi); } - if (gameInfo.crc && (gameInfo.crcForCheatsDb != cheatsExport->CRC)) - msgbox->warn("Checksums not matching"); SendMessage(exportListView, WM_SETREDRAW, (WPARAM)TRUE,0); ListView_SetItemState(exportListView,0, LVIS_SELECTED|LVIS_FOCUSED, LVIS_SELECTED|LVIS_FOCUSED); @@ -1646,7 +1644,7 @@ bool CheatsExportDialog(HWND hwnd) sprintf(buf2, "File \"%s\" is not R4 cheats database.\nWrong file format!", buf); else if (cheatsExport->getErrorCode() == 3) - sprintf(buf2, "Serial \"%s\" not found in database.", gameInfo.ROMserial); + sprintf(buf2, "CRC %8X not found in database.", gameInfo.crcForCheatsDb); else if (cheatsExport->getErrorCode() == 4) sprintf(buf2, "Error export from database");