don't disable achievement when AddAddress generates an out-of-range address

This commit is contained in:
Jamiras 2019-12-26 09:53:05 -07:00
parent 7c8d831497
commit 410e94aa89
2 changed files with 47 additions and 18 deletions

View File

@ -665,6 +665,20 @@ static unsigned rcheevos_peek(unsigned address, unsigned num_bytes, void* ud)
return value;
}
static int rcheevos_has_indirect_memref(const rc_memref_value_t* memrefs)
{
const rc_memref_value_t* memref = memrefs;
while (memref != NULL)
{
if (memref->memref.is_indirect)
return 1;
memref = memref->next;
}
return 0;
}
static void rcheevos_test_cheevo_set(bool official)
{
settings_t *settings = config_get_ptr();
@ -700,6 +714,16 @@ static void rcheevos_test_cheevo_set(bool official)
{
/* if the we're still waiting for the trigger to stabilize, check to see if an error occurred */
if (rcheevos_locals.invalid_peek_address)
{
/* reset the flag for the next achievement */
rcheevos_locals.invalid_peek_address = false;
if (rcheevos_has_indirect_memref(cheevo->trigger->memrefs))
{
/* ignore bad addresses possibly generated by AddAddress */
CHEEVOS_LOG(RCHEEVOS_TAG "Ignoring invalid address in achievement with AddAddress: %s\n", cheevo->info->title);
}
else
{
/* could not map one or more addresses - disable the achievement */
CHEEVOS_ERR(RCHEEVOS_TAG "Achievement disabled (invalid address): %s\n", cheevo->info->title);
@ -709,10 +733,9 @@ static void rcheevos_test_cheevo_set(bool official)
CHEEVOS_FREE(cheevo->trigger);
cheevo->trigger = NULL;
/* reset the flag for the next achievement */
rcheevos_locals.invalid_peek_address = false;
continue;
}
}
/* no error, reset any hit counts for the next check */
rc_reset_trigger(cheevo->trigger);
@ -849,15 +872,18 @@ static void rcheevos_test_leaderboards(void)
}
if (rcheevos_locals.invalid_peek_address)
{
/* reset the flag for the next leaderboard */
rcheevos_locals.invalid_peek_address = false;
if (!rcheevos_has_indirect_memref(lboard->lboard->memrefs))
{
/* disable the leaderboard */
CHEEVOS_FREE(lboard->lboard);
lboard->lboard = NULL;
CHEEVOS_LOG(RCHEEVOS_TAG "Leaderboard disabled (invalid address): %s\n", lboard->info->title);
/* reset the flag for the next leaderboard */
rcheevos_locals.invalid_peek_address = false;
}
}
}
}

View File

@ -236,6 +236,7 @@ const uint8_t* rcheevos_patch_address(unsigned address, int console)
else
{
unsigned i;
unsigned addr = address;
for (i = 0; i < 4; i++)
{
@ -259,9 +260,10 @@ const uint8_t* rcheevos_patch_address(unsigned address, int console)
core_get_memory(&meminfo);
if (address < meminfo.size)
if (addr < meminfo.size)
{
pointer = meminfo.data;
address = addr;
break;
}
@ -270,14 +272,15 @@ const uint8_t* rcheevos_patch_address(unsigned address, int console)
* it's size is not always set correctly in the core.
*/
if (i == 0 && console == RC_CONSOLE_NINTENDO)
address -= 0x6000;
addr -= 0x6000;
else
address -= meminfo.size;
addr -= meminfo.size;
}
}
if (pointer == NULL)
{
CHEEVOS_LOG(RCHEEVOS_TAG "address %X not supported\n", address);
return NULL;
}