Merge pull request #7769 from rzumer/patch-2

Update NES and SNES hashing methods
This commit is contained in:
Twinaphex 2019-01-10 15:14:08 +01:00 committed by GitHub
commit cdcadf6237
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)
@ -2612,10 +2612,10 @@ 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 VROM)", NULL},
{NES_MD5, "NES (discards header)", NULL},
{GENERIC_MD5, "Generic (plain content)", NULL},
{FILENAME_MD5, "Generic (filename)", NULL}
};
@ -2900,30 +2900,23 @@ found:
MD5_Init(&coro->md5);
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 || coro->len % 0x2000 != 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();
}
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);
/**************************************************************************
@ -2985,12 +2978,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))
{
@ -3010,37 +2999,11 @@ 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->offset = sizeof(coro->header);
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);