RA Leaderboards: BCD and Ignore Unused Fields

- Support for binary-coded-decimal submits (b0x1234)
- Ignore unused fields from older leaderboards (PRO, FOR, TTL, DES)
This commit is contained in:
celerizer 2017-11-19 14:16:49 -06:00 committed by GitHub
parent 3519e4e16a
commit 7be0dd9b18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 127 additions and 48 deletions

View File

@ -534,6 +534,8 @@ static void cheevos_add_var(const cheevos_var_t* var, char** memaddr,
{
if (var->type == CHEEVOS_VAR_TYPE_DELTA_MEM)
cheevos_add_char(memaddr, left, 'd');
else if (var->is_bcd)
cheevos_add_char(memaddr, left, 'b');
cheevos_add_string(memaddr, left, "0x");
cheevos_add_var_size(memaddr, left, var);
@ -915,6 +917,7 @@ static int cheevos_parse_condition(cheevos_condition_t *condition, const char* m
{
while (--condset >= condition->condsets)
{
if ((void*)condset->conds)
free((void*)condset->conds);
}
@ -937,9 +940,19 @@ static void cheevos_free_condition(cheevos_condition_t* condition)
if (condition->condsets)
{
for (i = 0; i < condition->count; i++)
free((void*)condition->condsets[i].conds);
{
if (condition->condsets[i].conds)
{
free(condition->condsets[i].conds);
condition->condsets[i].conds = NULL;
}
}
free((void*)condition->condsets);
if (condition->condsets)
{
free(condition->condsets);
condition->condsets = NULL;
}
}
}
@ -955,8 +968,12 @@ static int cheevos_parse_expression(cheevos_expr_t *expr, const char* mem)
expr->count = 1;
expr->compare_count = 1;
for (aux = mem; *aux != '"'; aux++)
for (aux = mem;; aux++)
{
if(*aux == '"' || *aux == ':')
break;
expr->count += *aux == '_';
}
expr->terms = (cheevos_term_t*)calloc(expr->count, sizeof(cheevos_term_t));
@ -996,7 +1013,11 @@ static int cheevos_parse_expression(cheevos_expr_t *expr, const char* mem)
/* invalid character in expression */
else
{
free((void*)expr->terms);
if (expr->terms)
{
free(expr->terms);
expr->terms = NULL;
}
return -1;
}
}
@ -1053,8 +1074,6 @@ static int cheevos_parse_mem(cheevos_leaderboard_t *lb, const char* mem)
if (cheevos_parse_expression(&lb->value, mem + 4))
goto error;
}
else
goto error;
for (mem += 4;; mem++)
{
@ -1072,7 +1091,11 @@ error:
cheevos_free_condition(&lb->start);
cheevos_free_condition(&lb->cancel);
cheevos_free_condition(&lb->submit);
if (lb->value.terms)
{
free((void*)lb->value.terms);
lb->value.terms = NULL;
}
return -1;
}
@ -1130,10 +1153,26 @@ static int cheevos_new_cheevo(cheevos_readud_t *ud)
return 0;
error:
if (cheevo->title)
{
free((void*)cheevo->title);
cheevo->title = NULL;
}
if (cheevo->description)
{
free((void*)cheevo->description);
cheevo->description = NULL;
}
if (cheevo->author)
{
free((void*)cheevo->author);
cheevo->author = NULL;
}
if (cheevo->badge)
{
free((void*)cheevo->badge);
cheevo->badge = NULL;
}
return -1;
}
@ -1228,7 +1267,9 @@ static int cheevos_new_lboard(cheevos_readud_t *ud)
return 0;
error:
if ((void*)lboard->title)
free((void*)lboard->title);
if ((void*)lboard->description)
free((void*)lboard->description);
return -1;
}
@ -1405,8 +1446,11 @@ static int cheevos_parse(const char *json)
if ( !cheevos_locals.core.cheevos || !cheevos_locals.unofficial.cheevos
|| !cheevos_locals.leaderboards)
{
if ((void*)cheevos_locals.core.cheevos)
free((void*)cheevos_locals.core.cheevos);
if ((void*)cheevos_locals.unofficial.cheevos)
free((void*)cheevos_locals.unofficial.cheevos);
if ((void*)cheevos_locals.leaderboards)
free((void*)cheevos_locals.leaderboards);
cheevos_locals.core.count = cheevos_locals.unofficial.count =
cheevos_locals.lboard_count = 0;
@ -1964,14 +2008,19 @@ Free the loaded achievements.
static void cheevos_free_condset(const cheevos_condset_t *set)
{
if (set->conds)
free((void*)set->conds);
}
static void cheevos_free_cheevo(const cheevo_t *cheevo)
{
if (cheevo->title)
free((void*)cheevo->title);
if (cheevo->description)
free((void*)cheevo->description);
if (cheevo->author)
free((void*)cheevo->author);
if (cheevo->badge)
free((void*)cheevo->badge);
cheevos_free_condset(cheevo->condition.condsets);
}
@ -1984,6 +2033,7 @@ static void cheevos_free_cheevo_set(const cheevoset_t *set)
while (cheevo < end)
cheevos_free_cheevo(cheevo++);
if (set->cheevos)
free((void*)set->cheevos);
}
@ -2605,7 +2655,7 @@ static int cheevos_iterate(coro_t* coro)
/* Load the content into memory, or copy it over to our own buffer */
if (!CHEEVOS_VAR_DATA)
{
CHEEVOS_VAR_STREAM = filestream_open(CHEEVOS_VAR_PATH, RFILE_MODE_READ, 0);
CHEEVOS_VAR_STREAM = filestream_open(CHEEVOS_VAR_PATH, RFILE_MODE_READ, -1);
if (!CHEEVOS_VAR_STREAM)
CORO_STOP();
@ -2757,10 +2807,12 @@ static int cheevos_iterate(coro_t* coro)
#endif
if (cheevos_parse(CHEEVOS_VAR_JSON))
{
if ((void*)CHEEVOS_VAR_JSON)
free((void*)CHEEVOS_VAR_JSON);
CORO_STOP();
}
if ((void*)CHEEVOS_VAR_JSON)
free((void*)CHEEVOS_VAR_JSON);
cheevos_loaded = true;
@ -3052,11 +3104,13 @@ static int cheevos_iterate(coro_t* coro)
if (cheevos_get_value(CHEEVOS_VAR_JSON, CHEEVOS_JSON_KEY_GAMEID, gameid, sizeof(gameid)))
{
if ((void*)CHEEVOS_VAR_JSON)
free((void*)CHEEVOS_VAR_JSON);
RARCH_ERR("[CHEEVOS]: error getting game_id.\n");
CORO_RET();
}
if ((void*)CHEEVOS_VAR_JSON)
free((void*)CHEEVOS_VAR_JSON);
RARCH_LOG("[CHEEVOS]: got game id %s.\n", gameid);
CHEEVOS_VAR_GAMEID = strtol(gameid, NULL, 10);
@ -3139,6 +3193,7 @@ static int cheevos_iterate(coro_t* coro)
if (CHEEVOS_VAR_JSON)
{
int res = cheevos_get_value(CHEEVOS_VAR_JSON, CHEEVOS_JSON_KEY_TOKEN, cheevos_locals.token, sizeof(cheevos_locals.token));
if ((void*)CHEEVOS_VAR_JSON)
free((void*)CHEEVOS_VAR_JSON);
if (!res)
@ -3282,6 +3337,7 @@ static int cheevos_iterate(coro_t* coro)
else
RARCH_ERR("[CHEEVOS]: error deactivating unlocked achievements in softcore mode.\n");
if ((void*)CHEEVOS_VAR_JSON)
free((void*)CHEEVOS_VAR_JSON);
}
else
@ -3310,6 +3366,7 @@ static int cheevos_iterate(coro_t* coro)
else
RARCH_ERR("[CHEEVOS]: error deactivating unlocked achievements in hardcore mode.\n");
if ((void*)CHEEVOS_VAR_JSON)
free((void*)CHEEVOS_VAR_JSON);
}
else
@ -3343,6 +3400,7 @@ static int cheevos_iterate(coro_t* coro)
if (CHEEVOS_VAR_JSON)
{
RARCH_LOG("[CHEEVOS]: posted playing activity.\n");
if ((void*)CHEEVOS_VAR_JSON)
free((void*)CHEEVOS_VAR_JSON);
}
else
@ -3358,10 +3416,15 @@ static void cheevos_task_handler(retro_task_t *task)
{
coro_t *coro = (coro_t*)task->state;
if (!coro)
return;
if (!cheevos_iterate(coro))
{
task_set_finished(task, true);
if (CHEEVOS_VAR_DATA)
free(CHEEVOS_VAR_DATA);
if ((void*)CHEEVOS_VAR_PATH)
free((void*)CHEEVOS_VAR_PATH);
free((void*)coro);
}
@ -3370,8 +3433,8 @@ static void cheevos_task_handler(retro_task_t *task)
bool cheevos_load(const void *data)
{
retro_task_t *task;
coro_t *coro;
const struct retro_game_info *info;
const struct retro_game_info *info = NULL;
coro_t *coro = NULL;
cheevos_loaded = 0;
@ -3387,6 +3450,7 @@ bool cheevos_load(const void *data)
if (!task)
{
if ((void*)coro)
free((void*)coro);
return false;
}
@ -3406,7 +3470,9 @@ bool cheevos_load(const void *data)
if (!CHEEVOS_VAR_DATA)
{
if ((void*)task)
free((void*)task);
if ((void*)coro)
free((void*)coro);
return false;
}

View File

@ -119,12 +119,21 @@ void cheevos_var_parse(cheevos_var_t* var, const char** memaddr)
const char *str = *memaddr;
unsigned base = 16;
var->is_bcd = false;
if (toupper((unsigned char)*str) == 'D' && str[1] == '0' && toupper((unsigned char)str[2]) == 'X')
{
/* d0x + 4 hex digits */
str += 3;
var->type = CHEEVOS_VAR_TYPE_DELTA_MEM;
}
else if (toupper((unsigned char)*str) == 'B' && str[1] == '0' && toupper((unsigned char)str[2]) == 'X')
{
/* b0x (binary-coded decimal) */
str += 3;
var->is_bcd = true;
var->type = CHEEVOS_VAR_TYPE_ADDRESS;
}
else if (*str == '0' && toupper((unsigned char)str[1]) == 'X')
{
/* 0x + 4 hex digits */
@ -406,5 +415,8 @@ unsigned cheevos_var_get_value(cheevos_var_t* var)
break;
}
if(var->is_bcd)
return (((value >> 4) & 0xf) * 10) + (value & 0xf);
else
return value;
}

View File

@ -62,6 +62,7 @@ typedef struct
cheevos_var_size_t size;
cheevos_var_type_t type;
int bank_id;
bool is_bcd;
unsigned value;
unsigned previous;
} cheevos_var_t;