From dc45fbada6e4bbda882ad0896b23f1b363f25422 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Zumer?= Date: Tue, 18 Dec 2018 17:24:13 -0500 Subject: [PATCH 1/4] Include VROM in cheevos NES hash --- cheevos/cheevos.c | 36 ++++-------------------------------- 1 file changed, 4 insertions(+), 32 deletions(-) diff --git a/cheevos/cheevos.c b/cheevos/cheevos.c index 18535b4232..59be4db214 100644 --- a/cheevos/cheevos.c +++ b/cheevos/cheevos.c @@ -2615,7 +2615,7 @@ static int cheevos_iterate(coro_t *coro) {SNES_MD5, "SNES (8Mb padding)", snes_exts}, {GENESIS_MD5, "Genesis (6Mb padding)", genesis_exts}, {LYNX_MD5, "Atari Lynx (only first 512 bytes)", lynx_exts}, - {NES_MD5, "NES (discards VROM)", NULL}, + {NES_MD5, "NES (discards header)", NULL}, {GENERIC_MD5, "Generic (plain content)", NULL}, {FILENAME_MD5, "Generic (filename)", NULL} }; @@ -2987,12 +2987,8 @@ found: *************************************************************************/ CORO_SUB(NES_MD5) - /* Note about the references to the FCEU emulator below. There is no - * core-specific code in this function, it's rather Retro Achievements - * specific code that must be followed to the letter so we compute - * the correct ROM hash. Retro Achievements does indeed use some - * FCEU related method to compute the hash, since its NES emulator - * is based on it. */ + /* Checks for the existence of a headered NES file. + Unheadered files fall back to GENERIC_MD5. */ if (coro->len < sizeof(coro->header)) { @@ -3012,37 +3008,13 @@ found: CORO_RET(); } - { - size_t romsize = 256; - /* from FCEU core - compute size using the cart mapper */ - int mapper = (coro->header.rom_type >> 4) | (coro->header.rom_type2 & 0xF0); - - if (coro->header.rom_size) - romsize = next_pow2(coro->header.rom_size); - - /* for games not to the power of 2, so we just read enough - * PRG rom from it, but we have to keep ROM_size to the power of 2 - * since PRGCartMapping wants ROM_size to be to the power of 2 - * so instead if not to power of 2, we just use head.ROM_size when - * we use FCEU_read. */ - coro->round = mapper != 53 && mapper != 198 && mapper != 228; - coro->bytes = coro->round ? romsize : coro->header.rom_size; - } - /* from FCEU core - check if Trainer included in ROM data */ MD5_Init(&coro->md5); coro->offset = sizeof(coro->header) + (coro->header.rom_type & 4 ? sizeof(coro->header) : 0); - coro->count = 0x4000 * coro->bytes; + coro->count = coro->len - coro->offset; CORO_GOSUB(EVAL_MD5); - if (coro->count < 0x4000 * coro->bytes) - { - coro->offset = 0xff; - coro->count = 0x4000 * coro->bytes - coro->count; - CORO_GOSUB(FILL_MD5); - } - MD5_Final(coro->hash, &coro->md5); CORO_GOTO(GET_GAMEID); From 2a9f6d9d408ad56f229fdc155ddb5f011541c14a Mon Sep 17 00:00:00 2001 From: meleu Date: Mon, 24 Dec 2018 16:00:16 -0200 Subject: [PATCH 2/4] SNES hashing, just ignore header if it has one --- cheevos/cheevos.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/cheevos/cheevos.c b/cheevos/cheevos.c index 59be4db214..aa5a4b3d1d 100644 --- a/cheevos/cheevos.c +++ b/cheevos/cheevos.c @@ -2612,7 +2612,7 @@ static int cheevos_iterate(coro_t *coro) static cheevos_finder_t finders[] = { - {SNES_MD5, "SNES (8Mb padding)", snes_exts}, + {SNES_MD5, "SNES (discards header)", snes_exts}, {GENESIS_MD5, "Genesis (6Mb padding)", genesis_exts}, {LYNX_MD5, "Atari Lynx (only first 512 bytes)", lynx_exts}, {NES_MD5, "NES (discards header)", NULL}, @@ -2902,7 +2902,12 @@ found: MD5_Init(&coro->md5); - coro->offset = 0; + /* if the file contains header, ignore it */ + if (coro->len - ((coro->len / 0x2000) * 0x2000) == 512) + coro->offset = 512; + else + coro->offset = 0; + coro->count = 0; CORO_GOSUB(EVAL_MD5); @@ -2914,17 +2919,6 @@ found: CORO_RET(); } - if (coro->count < size_in_megabytes(8)) - { - /* - * Inputs: CHEEVOS_VAR_MD5, CHEEVOS_VAR_OFFSET, CHEEVOS_VAR_COUNT - * Outputs: CHEEVOS_VAR_MD5 - */ - coro->offset = 0; - coro->count = size_in_megabytes(8) - coro->count; - CORO_GOSUB(FILL_MD5); - } - MD5_Final(coro->hash, &coro->md5); CORO_GOTO(GET_GAMEID); From 0ebf5a2563fafa279237f113bf51d8313082e3f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Zumer?= Date: Wed, 2 Jan 2019 09:55:48 -0500 Subject: [PATCH 3/4] Fall back to GENERIC_MD5 for headerless SNES --- cheevos/cheevos.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/cheevos/cheevos.c b/cheevos/cheevos.c index aa5a4b3d1d..f0bc96c5f0 100644 --- a/cheevos/cheevos.c +++ b/cheevos/cheevos.c @@ -2902,24 +2902,23 @@ found: MD5_Init(&coro->md5); - /* if the file contains header, ignore it */ - if (coro->len - ((coro->len / 0x2000) * 0x2000) == 512) - coro->offset = 512; - else - coro->offset = 0; + /* Checks for the existence of a headered SNES file. + Unheadered files fall back to GENERIC_MD5. */ + + const int SNES_HEADER_LEN = 0x200; + + if (coro->len % 0x2000 != SNES_HEADER_LEN || coro->len <= SNES_HEADER_LEN) + { + coro->gameid = 0; + CORO_RET(); + } + coro->offset = 512; coro->count = 0; CORO_GOSUB(EVAL_MD5); - - if (coro->count == 0) - { - MD5_Final(coro->hash, &coro->md5); - coro->gameid = 0; - CORO_RET(); - } - MD5_Final(coro->hash, &coro->md5); + CORO_GOTO(GET_GAMEID); /************************************************************************** From 5cef12160a1dcf4cbd2b3e5593e7d94c6a1418ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Zumer?= Date: Wed, 2 Jan 2019 18:58:47 -0500 Subject: [PATCH 4/4] Ignore trainer data for NES hashing --- cheevos/cheevos.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/cheevos/cheevos.c b/cheevos/cheevos.c index f0bc96c5f0..db5b1e8128 100644 --- a/cheevos/cheevos.c +++ b/cheevos/cheevos.c @@ -2081,7 +2081,7 @@ void cheevos_populate_menu(void *data) cheevo_t *cheevo = cheevos_locals.core.cheevos; end = cheevo + cheevos_locals.core.count; - if(settings->bools.cheevos_enable && settings->bools.cheevos_hardcore_mode_enable + if(settings->bools.cheevos_enable && settings->bools.cheevos_hardcore_mode_enable && cheevos_loaded) { if (!cheevos_hardcore_paused) @@ -2904,10 +2904,10 @@ found: /* Checks for the existence of a headered SNES file. Unheadered files fall back to GENERIC_MD5. */ - + const int SNES_HEADER_LEN = 0x200; - - if (coro->len % 0x2000 != SNES_HEADER_LEN || coro->len <= SNES_HEADER_LEN) + + if (coro->len < 0x2000 || coro->len % 0x2000 != SNES_HEADER_LEN) { coro->gameid = 0; CORO_RET(); @@ -2918,7 +2918,7 @@ found: CORO_GOSUB(EVAL_MD5); MD5_Final(coro->hash, &coro->md5); - + CORO_GOTO(GET_GAMEID); /************************************************************************** @@ -3001,10 +3001,8 @@ found: CORO_RET(); } - /* from FCEU core - check if Trainer included in ROM data */ MD5_Init(&coro->md5); - coro->offset = sizeof(coro->header) + (coro->header.rom_type & 4 - ? sizeof(coro->header) : 0); + coro->offset = sizeof(coro->header); coro->count = coro->len - coro->offset; CORO_GOSUB(EVAL_MD5);