From da71ed8e3b3d70e86f1cd49ad895312ef1e38f4b Mon Sep 17 00:00:00 2001 From: Jamiras Date: Wed, 24 Feb 2021 15:47:22 -0700 Subject: [PATCH] only validate memrefs once --- cheevos/cheevos.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/cheevos/cheevos.c b/cheevos/cheevos.c index 0d5b51f5f3..a06309da7b 100644 --- a/cheevos/cheevos.c +++ b/cheevos/cheevos.c @@ -503,9 +503,6 @@ static unsigned rcheevos_peek(unsigned address, unsigned num_bytes, void* ud) } } - if (address < rcheevos_locals.memory.total_size) - rcheevos_invalidate_address(address); - return 0; } @@ -706,6 +703,22 @@ static void rcheevos_async_task_callback( } } +static void rcheevos_validate_memrefs(rcheevos_locals_t* locals) +{ + rc_memref_value_t* memref = locals->runtime.memrefs; + while (memref) + { + if (!memref->memref.is_indirect) + { + uint8_t* data = rcheevos_memory_find(&rcheevos_locals.memory, memref->memref.address); + if (!data) + rcheevos_invalidate_address(memref->memref.address); + } + + memref = memref->next; + } +} + static void rcheevos_activate_achievements(rcheevos_locals_t *locals, rcheevos_racheevo_t* cheevo, unsigned count, unsigned flags) { @@ -878,6 +891,10 @@ static int rcheevos_parse(rcheevos_locals_t *locals, const char* json) rcheevos_async_schedule(request, CHEEVOS_PING_FREQUENCY / 4); } + /* validate the memrefs */ + if (rcheevos_locals.memory.count != 0) + rcheevos_validate_memrefs(&rcheevos_locals); + return 0; error: @@ -1861,6 +1878,8 @@ void rcheevos_test(void) rcheevos_pause_hardcore(); return; } + + rcheevos_validate_memrefs(&rcheevos_locals); } rc_runtime_do_frame(&rcheevos_locals.runtime, &rcheevos_runtime_event_handler, rcheevos_peek, NULL, 0);