Merge pull request #3859 from leiradel/master

Fixed NES ROM identification for cores whee needs_fullpath == false
This commit is contained in:
Twinaphex 2016-10-26 02:17:14 +02:00 committed by GitHub
commit 30d292b60d

View File

@ -44,16 +44,16 @@
#include "verbosity.h"
/* Define this macro to prevent cheevos from being deactivated. */
#undef CHEEVOS_DONT_DEACTIVATE
#define CHEEVOS_DONT_DEACTIVATE
/* Define this macro to log URLs (will log the user token). */
#undef CHEEVOS_LOG_URLS
#define CHEEVOS_LOG_URLS
/* Define this macro to dump all cheevos' addresses. */
#undef CHEEVOS_DUMP_ADDRS
/* Define this macro to remove HTTP timeouts. */
#undef CHEEVOS_NO_TIMEOUT
#define CHEEVOS_NO_TIMEOUT
#define JSON_KEY_GAMEID 0xb4960eecU
#define JSON_KEY_ACHIEVEMENTS 0x69749ae1U
@ -1934,6 +1934,11 @@ static unsigned cheevos_find_game_id_nes(
const struct retro_game_info *info,
retro_time_t timeout)
{
static int not_power2[] =
{
53, 198, 228
};
struct
{
uint8_t id[4]; /* NES^Z */
@ -1949,6 +1954,12 @@ static unsigned cheevos_find_game_id_nes(
uint8_t hash[16];
retro_time_t to;
unsigned bytes;
ssize_t num_read;
int i, mapper_no;
bool round = true;
uint8_t *data;
if (info->data)
{
if (info->size < sizeof(header))
@ -1982,41 +1993,11 @@ static unsigned cheevos_find_game_id_nes(
else
rom_size = 256;
if (info->data)
{
if (rom_size + sizeof(header) > info->size)
data = (uint8_t *) malloc(rom_size << 14);
if (!data)
return 0;
MD5_Init(&ctx);
MD5_Update(&ctx,
(void*)((char*)info->data + sizeof(header)), rom_size);
MD5_Final(hash, &ctx);
}
else
{
unsigned bytes;
ssize_t num_read;
int i, mapper_no;
int not_power2[] =
{
53, 198, 228
};
bool round = true;
RFILE *file = filestream_open(info->path, RFILE_MODE_READ, 0);
uint8_t * data = (uint8_t *) malloc(rom_size << 14);
if (!file || !data)
{
if (file)
filestream_close(file);
if (data)
free(data);
return 0;
}
/* TODO/FIXME - any way we can move this per-core stuff
* somewhere else? Bound to become really messy in here over time */
/* from FCEU core - need it for a correctly md5 sum */
memset(data, 0xFF, rom_size << 14);
@ -2038,17 +2019,41 @@ static unsigned cheevos_find_game_id_nes(
}
}
bytes = (round) ? rom_size : header.rom_size;
MD5_Init(&ctx);
if (info->data)
{
size_t offset = sizeof(header);
size_t count;
/* from FCEU core - check if Trainer included in ROM data */
if (header.rom_type & 4)
offset += sizeof(header);
count = info->size - offset;
if (count > 0x4000 * bytes)
count = 0x4000 * bytes;
memcpy(data, (void*)(uint8_t*)info->data + offset, count);
}
else
{
RFILE *file = filestream_open(info->path, RFILE_MODE_READ, 0);
if (!file)
{
free(data);
return 0;
}
filestream_seek(file, sizeof(header), SEEK_SET);
/* TODO/FIXME - any way we can move this per-core stuff
* somewhere else? Bound to become really messy in here over time */
/* from FCEU core - check if Trainer included in ROM data */
if (header.rom_type & 4)
filestream_seek(file, sizeof(header), SEEK_CUR);
bytes = (round) ? rom_size : header.rom_size;
num_read = filestream_read(file, (void*)data, 0x4000 * bytes );
filestream_close(file);
@ -2057,11 +2062,11 @@ static unsigned cheevos_find_game_id_nes(
free(data);
return 0;
}
}
MD5_Update(&ctx, (void*) data, rom_size << 14);
MD5_Final(hash, &ctx);
free(data);
}
to = timeout;
return cheevos_get_game_id(hash, &to);
@ -2220,7 +2225,7 @@ found:
}
runloop_msg_queue_push("Error loading achievements.", 0, 5 * 60, false);
RARCH_ERR("CHEEVOS error loading achievements.\n", 0, 5 * 60, false);
RARCH_ERR("CHEEVOS error loading achievements.\n");
return false;
}