2015-10-09 16:29:57 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2016-01-10 03:06:50 +00:00
|
|
|
* Copyright (C) 2015-2016 - Andre Leiradella
|
2015-10-09 16:29:57 +00:00
|
|
|
*
|
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
|
|
|
#include <formats/jsonsax.h>
|
2016-03-20 15:29:14 +00:00
|
|
|
#include <streams/file_stream.h>
|
2015-11-03 02:54:26 +00:00
|
|
|
#include <rhash.h>
|
2015-10-28 06:47:57 +00:00
|
|
|
#include <rthreads/async_job.h>
|
2016-05-10 17:03:53 +00:00
|
|
|
#include <libretro.h>
|
2015-10-09 16:29:57 +00:00
|
|
|
|
|
|
|
#include "cheevos.h"
|
2016-05-11 08:06:15 +00:00
|
|
|
#include "command.h"
|
2015-10-09 16:29:57 +00:00
|
|
|
#include "dynamic.h"
|
2015-12-07 12:32:03 +00:00
|
|
|
#include "libretro.h"
|
2016-05-13 01:03:18 +00:00
|
|
|
#include "system.h"
|
2016-05-09 15:47:45 +00:00
|
|
|
#include "network/net_http_special.h"
|
2015-10-30 12:31:56 +00:00
|
|
|
#include "configuration.h"
|
2016-05-10 06:53:14 +00:00
|
|
|
#include "performance_counters.h"
|
2016-03-14 10:51:54 +00:00
|
|
|
#include "msg_hash.h"
|
2015-12-06 17:40:32 +00:00
|
|
|
#include "runloop.h"
|
2016-05-08 03:29:10 +00:00
|
|
|
#include "core.h"
|
2015-12-06 16:55:27 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_MENU
|
|
|
|
#include "menu/menu_driver.h"
|
2015-12-07 13:53:33 +00:00
|
|
|
#include "menu/menu_entries.h"
|
2015-12-06 16:55:27 +00:00
|
|
|
#endif
|
|
|
|
|
2015-11-23 11:03:38 +00:00
|
|
|
#include "verbosity.h"
|
2015-10-30 12:31:56 +00:00
|
|
|
|
2016-05-09 23:44:59 +00:00
|
|
|
/* Define this macro to deactivate awarded cheevos. */
|
|
|
|
#define CHEEVOS_DEACTIVATE
|
|
|
|
|
|
|
|
/* Define this macro to log URLs (will log the user token). */
|
|
|
|
#undef CHEEVOS_LOG_URLS
|
|
|
|
|
2016-05-13 01:03:18 +00:00
|
|
|
/* Define this macro to dump all cheevos' addresses. */
|
|
|
|
#undef CHEEVOS_DUMP_ADDRS
|
|
|
|
|
2016-02-13 04:47:41 +00:00
|
|
|
#define JSON_KEY_GAMEID 0xb4960eecU
|
|
|
|
#define JSON_KEY_ACHIEVEMENTS 0x69749ae1U
|
|
|
|
#define JSON_KEY_ID 0x005973f2U
|
|
|
|
#define JSON_KEY_MEMADDR 0x1e76b53fU
|
|
|
|
#define JSON_KEY_TITLE 0x0e2a9a07U
|
|
|
|
#define JSON_KEY_DESCRIPTION 0xe61a1f69U
|
|
|
|
#define JSON_KEY_POINTS 0xca8fce22U
|
|
|
|
#define JSON_KEY_AUTHOR 0xa804edb8U
|
|
|
|
#define JSON_KEY_MODIFIED 0xdcea4fe6U
|
|
|
|
#define JSON_KEY_CREATED 0x3a84721dU
|
|
|
|
#define JSON_KEY_BADGENAME 0x887685d9U
|
2016-05-09 23:44:59 +00:00
|
|
|
#define JSON_KEY_CONSOLE_ID 0x071656e5U
|
2016-02-13 04:47:41 +00:00
|
|
|
#define JSON_KEY_TOKEN 0x0e2dbd26U
|
|
|
|
#define JSON_KEY_FLAGS 0x0d2e96b2U
|
|
|
|
|
2016-05-09 23:44:59 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
CHEEVOS_CONSOLE_GAMEBOY = 4,
|
2016-05-13 01:03:18 +00:00
|
|
|
CHEEVOS_CONSOLE_GAMEBOY_ADVANCED = 5,
|
2016-05-09 23:44:59 +00:00
|
|
|
CHEEVOS_CONSOLE_GAMEBOY_COLOR = 6,
|
|
|
|
};
|
|
|
|
|
2015-10-09 16:29:57 +00:00
|
|
|
enum
|
|
|
|
{
|
2015-11-03 02:54:26 +00:00
|
|
|
CHEEVOS_VAR_SIZE_BIT_0,
|
2015-10-27 17:50:41 +00:00
|
|
|
CHEEVOS_VAR_SIZE_BIT_1,
|
|
|
|
CHEEVOS_VAR_SIZE_BIT_2,
|
|
|
|
CHEEVOS_VAR_SIZE_BIT_3,
|
|
|
|
CHEEVOS_VAR_SIZE_BIT_4,
|
|
|
|
CHEEVOS_VAR_SIZE_BIT_5,
|
|
|
|
CHEEVOS_VAR_SIZE_BIT_6,
|
|
|
|
CHEEVOS_VAR_SIZE_BIT_7,
|
|
|
|
CHEEVOS_VAR_SIZE_NIBBLE_LOWER,
|
|
|
|
CHEEVOS_VAR_SIZE_NIBBLE_UPPER,
|
|
|
|
/* Byte, */
|
|
|
|
CHEEVOS_VAR_SIZE_EIGHT_BITS, /* =Byte, */
|
|
|
|
CHEEVOS_VAR_SIZE_SIXTEEN_BITS,
|
|
|
|
CHEEVOS_VAR_SIZE_THIRTYTWO_BITS,
|
|
|
|
|
|
|
|
CHEEVOS_VAR_SIZE_LAST
|
2015-10-10 14:06:59 +00:00
|
|
|
}; /* cheevos_var_t.size */
|
2015-10-09 16:29:57 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2016-02-03 15:09:11 +00:00
|
|
|
/* compare to the value of a live address in RAM */
|
|
|
|
CHEEVOS_VAR_TYPE_ADDRESS,
|
|
|
|
|
|
|
|
/* a number. assume 32 bit */
|
|
|
|
CHEEVOS_VAR_TYPE_VALUE_COMP,
|
|
|
|
|
|
|
|
/* the value last known at this address. */
|
|
|
|
CHEEVOS_VAR_TYPE_DELTA_MEM,
|
|
|
|
|
|
|
|
/* a custom user-set variable */
|
|
|
|
CHEEVOS_VAR_TYPE_DYNAMIC_VAR,
|
2015-10-09 16:29:57 +00:00
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
CHEEVOS_VAR_TYPE_LAST
|
2015-10-10 14:06:59 +00:00
|
|
|
}; /* cheevos_var_t.type */
|
2015-10-09 16:29:57 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2015-11-03 02:54:26 +00:00
|
|
|
CHEEVOS_COND_OP_EQUALS,
|
2015-10-27 17:50:41 +00:00
|
|
|
CHEEVOS_COND_OP_LESS_THAN,
|
|
|
|
CHEEVOS_COND_OP_LESS_THAN_OR_EQUAL,
|
|
|
|
CHEEVOS_COND_OP_GREATER_THAN,
|
|
|
|
CHEEVOS_COND_OP_GREATER_THAN_OR_EQUAL,
|
|
|
|
CHEEVOS_COND_OP_NOT_EQUAL_TO,
|
|
|
|
|
|
|
|
CHEEVOS_COND_OP_LAST
|
2015-10-09 18:42:39 +00:00
|
|
|
}; /* cheevos_cond_t.op */
|
2015-10-09 16:29:57 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2015-11-03 02:54:26 +00:00
|
|
|
CHEEVOS_COND_TYPE_STANDARD,
|
2015-10-27 17:50:41 +00:00
|
|
|
CHEEVOS_COND_TYPE_PAUSE_IF,
|
|
|
|
CHEEVOS_COND_TYPE_RESET_IF,
|
2015-10-16 23:57:11 +00:00
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
CHEEVOS_COND_TYPE_LAST
|
2015-10-09 18:42:39 +00:00
|
|
|
}; /* cheevos_cond_t.type */
|
2015-10-09 16:29:57 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2015-10-27 17:50:41 +00:00
|
|
|
CHEEVOS_DIRTY_TITLE = 1 << 0,
|
|
|
|
CHEEVOS_DIRTY_DESC = 1 << 1,
|
|
|
|
CHEEVOS_DIRTY_POINTS = 1 << 2,
|
|
|
|
CHEEVOS_DIRTY_AUTHOR = 1 << 3,
|
|
|
|
CHEEVOS_DIRTY_ID = 1 << 4,
|
|
|
|
CHEEVOS_DIRTY_BADGE = 1 << 5,
|
|
|
|
CHEEVOS_DIRTY_CONDITIONS = 1 << 6,
|
|
|
|
CHEEVOS_DIRTY_VOTES = 1 << 7,
|
|
|
|
CHEEVOS_DIRTY_DESCRIPTION = 1 << 8,
|
|
|
|
|
|
|
|
CHEEVOS_DIRTY_ALL = (1 << 9) - 1
|
2015-10-09 16:29:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2015-10-27 17:50:41 +00:00
|
|
|
unsigned size;
|
|
|
|
unsigned type;
|
2016-05-13 01:03:18 +00:00
|
|
|
int bank_id;
|
2015-10-27 17:50:41 +00:00
|
|
|
unsigned value;
|
|
|
|
unsigned previous;
|
|
|
|
} cheevos_var_t;
|
2015-10-09 16:29:57 +00:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2015-10-27 17:50:41 +00:00
|
|
|
unsigned type;
|
|
|
|
unsigned req_hits;
|
|
|
|
unsigned curr_hits;
|
2015-10-09 16:29:57 +00:00
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
cheevos_var_t source;
|
|
|
|
unsigned op;
|
|
|
|
cheevos_var_t target;
|
|
|
|
} cheevos_cond_t;
|
2015-10-09 16:29:57 +00:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2015-10-27 17:50:41 +00:00
|
|
|
cheevos_cond_t *conds;
|
|
|
|
unsigned count;
|
2015-10-09 16:29:57 +00:00
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
const char* expression;
|
|
|
|
} cheevos_condset_t;
|
2015-10-09 16:29:57 +00:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2015-10-27 17:50:41 +00:00
|
|
|
unsigned id;
|
|
|
|
const char *title;
|
|
|
|
const char *description;
|
|
|
|
const char *author;
|
|
|
|
const char *badge;
|
|
|
|
unsigned points;
|
|
|
|
unsigned dirty;
|
|
|
|
int active;
|
|
|
|
int modified;
|
|
|
|
|
|
|
|
cheevos_condset_t *condsets;
|
|
|
|
unsigned count;
|
|
|
|
} cheevo_t;
|
2015-10-09 16:29:57 +00:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2015-10-27 17:50:41 +00:00
|
|
|
cheevo_t *cheevos;
|
|
|
|
unsigned count;
|
|
|
|
} cheevoset_t;
|
2015-10-09 16:29:57 +00:00
|
|
|
|
2015-12-07 12:30:03 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
int is_element;
|
|
|
|
} cheevos_deactivate_t;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
unsigned key_hash;
|
|
|
|
int is_key;
|
|
|
|
const char *value;
|
|
|
|
size_t length;
|
|
|
|
} cheevos_getvalueud_t;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
int in_cheevos;
|
|
|
|
uint32_t field_hash;
|
|
|
|
unsigned core_count;
|
|
|
|
unsigned unofficial_count;
|
|
|
|
} cheevos_countud_t;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
const char *string;
|
|
|
|
size_t length;
|
|
|
|
} cheevos_field_t;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
int in_cheevos;
|
2016-05-13 01:03:18 +00:00
|
|
|
int is_console_id;
|
2015-12-07 12:30:03 +00:00
|
|
|
unsigned core_count;
|
|
|
|
unsigned unofficial_count;
|
|
|
|
|
|
|
|
cheevos_field_t *field;
|
|
|
|
cheevos_field_t id, memaddr, title, desc, points, author;
|
|
|
|
cheevos_field_t modified, created, badge, flags;
|
|
|
|
} cheevos_readud_t;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
unsigned (*finder)(const struct retro_game_info *, retro_time_t);
|
|
|
|
const char *name;
|
|
|
|
const uint32_t *ext_hashes;
|
|
|
|
} cheevos_finder_t;
|
|
|
|
|
2016-05-09 23:44:59 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2016-05-13 01:03:18 +00:00
|
|
|
int loaded;
|
|
|
|
int console_id;
|
|
|
|
bool core_supports;
|
2016-05-09 23:44:59 +00:00
|
|
|
|
|
|
|
cheevoset_t core;
|
|
|
|
cheevoset_t unofficial;
|
|
|
|
|
|
|
|
char token[32];
|
2016-05-13 01:03:18 +00:00
|
|
|
|
|
|
|
retro_ctx_memory_info_t meminfo[4];
|
2016-05-09 23:44:59 +00:00
|
|
|
} cheevos_locals_t;
|
2015-12-07 12:30:03 +00:00
|
|
|
|
2016-01-29 13:39:38 +00:00
|
|
|
static cheevos_locals_t cheevos_locals =
|
2015-10-27 17:50:41 +00:00
|
|
|
{
|
2016-05-09 23:44:59 +00:00
|
|
|
0,
|
2015-10-27 17:50:41 +00:00
|
|
|
0,
|
2016-05-13 01:03:18 +00:00
|
|
|
true,
|
2015-10-27 17:50:41 +00:00
|
|
|
{NULL, 0},
|
|
|
|
{NULL, 0},
|
|
|
|
{0},
|
|
|
|
};
|
2015-10-09 16:29:57 +00:00
|
|
|
|
2016-05-07 22:15:04 +00:00
|
|
|
static int cheats_are_enabled = 0;
|
|
|
|
static int cheats_were_enabled = 0;
|
|
|
|
|
2015-12-06 17:37:57 +00:00
|
|
|
/* forward declaration */
|
|
|
|
|
|
|
|
int rarch_main_async_job_add(async_task_t task, void *payload);
|
|
|
|
|
2015-10-09 16:29:57 +00:00
|
|
|
/*****************************************************************************
|
2015-10-16 23:57:11 +00:00
|
|
|
Supporting functions.
|
|
|
|
*****************************************************************************/
|
2015-10-09 16:29:57 +00:00
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
static uint32_t cheevos_djb2(const char* str, size_t length)
|
|
|
|
{
|
|
|
|
const unsigned char *aux = (const unsigned char*)str;
|
|
|
|
const unsigned char *end = aux + length;
|
|
|
|
uint32_t hash = 5381;
|
|
|
|
|
|
|
|
while (aux < end)
|
|
|
|
hash = (hash << 5) + hash + *aux++;
|
|
|
|
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
2016-02-03 15:09:11 +00:00
|
|
|
static int cheevos_http_get(const char **result, size_t *size,
|
|
|
|
const char *url, retro_time_t *timeout)
|
2015-10-27 23:54:51 +00:00
|
|
|
{
|
2016-02-13 04:47:41 +00:00
|
|
|
const char *msg = NULL;
|
|
|
|
int ret = net_http_get(result, size, url, timeout);
|
2015-10-27 23:54:51 +00:00
|
|
|
|
|
|
|
switch (ret)
|
|
|
|
{
|
|
|
|
case NET_HTTP_GET_OK:
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
case NET_HTTP_GET_MALFORMED_URL:
|
|
|
|
msg = "malformed url";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NET_HTTP_GET_CONNECT_ERROR:
|
|
|
|
msg = "connect error";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NET_HTTP_GET_TIMEOUT:
|
|
|
|
msg = "timeout";
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
msg = "?";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-05-09 23:44:59 +00:00
|
|
|
RARCH_ERR("CHEEVOS error getting %s: %s\n", url, msg);
|
2015-10-27 23:54:51 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-02-03 15:09:11 +00:00
|
|
|
static int cheevos_getvalue__json_key(void *userdata,
|
|
|
|
const char *name, size_t length)
|
2015-10-27 17:50:41 +00:00
|
|
|
{
|
2015-11-08 14:41:57 +00:00
|
|
|
cheevos_getvalueud_t* ud = (cheevos_getvalueud_t*)userdata;
|
2015-10-27 17:50:41 +00:00
|
|
|
|
|
|
|
ud->is_key = cheevos_djb2(name, length) == ud->key_hash;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-02-03 15:09:11 +00:00
|
|
|
static int cheevos_getvalue__json_string(void *userdata,
|
|
|
|
const char *string, size_t length)
|
2015-10-27 17:50:41 +00:00
|
|
|
{
|
2015-11-08 14:41:57 +00:00
|
|
|
cheevos_getvalueud_t* ud = (cheevos_getvalueud_t*)userdata;
|
2015-10-27 17:50:41 +00:00
|
|
|
|
|
|
|
if (ud->is_key)
|
|
|
|
{
|
|
|
|
ud->value = string;
|
|
|
|
ud->length = length;
|
|
|
|
ud->is_key = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-11-08 14:41:57 +00:00
|
|
|
static int cheevos_getvalue__json_boolean(void *userdata, int istrue)
|
2015-10-27 17:50:41 +00:00
|
|
|
{
|
2015-11-08 14:41:57 +00:00
|
|
|
cheevos_getvalueud_t* ud = (cheevos_getvalueud_t*)userdata;
|
2015-10-27 17:50:41 +00:00
|
|
|
|
|
|
|
if ( ud->is_key )
|
|
|
|
{
|
|
|
|
ud->value = istrue ? "true" : "false";
|
|
|
|
ud->length = istrue ? 4 : 5;
|
|
|
|
ud->is_key = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-11-08 14:41:57 +00:00
|
|
|
static int cheevos_getvalue__json_null(void *userdata)
|
2015-10-09 16:29:57 +00:00
|
|
|
{
|
2015-11-08 14:41:57 +00:00
|
|
|
cheevos_getvalueud_t* ud = (cheevos_getvalueud_t*)userdata;
|
2015-10-09 16:29:57 +00:00
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
if ( ud->is_key )
|
|
|
|
{
|
|
|
|
ud->value = "null";
|
|
|
|
ud->length = 4;
|
|
|
|
ud->is_key = 0;
|
|
|
|
}
|
2015-10-09 16:29:57 +00:00
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-02-03 15:09:11 +00:00
|
|
|
static int cheevos_get_value(const char *json, unsigned key_hash,
|
|
|
|
char *value, size_t length)
|
2015-10-27 17:50:41 +00:00
|
|
|
{
|
|
|
|
static const jsonsax_handlers_t handlers =
|
|
|
|
{
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2015-11-08 14:41:57 +00:00
|
|
|
cheevos_getvalue__json_key,
|
2015-10-27 17:50:41 +00:00
|
|
|
NULL,
|
2015-11-08 14:41:57 +00:00
|
|
|
cheevos_getvalue__json_string,
|
|
|
|
cheevos_getvalue__json_string, /* number */
|
|
|
|
cheevos_getvalue__json_boolean,
|
|
|
|
cheevos_getvalue__json_null
|
2015-10-27 17:50:41 +00:00
|
|
|
};
|
|
|
|
|
2015-11-08 14:41:57 +00:00
|
|
|
cheevos_getvalueud_t ud;
|
2015-10-27 17:50:41 +00:00
|
|
|
|
|
|
|
ud.key_hash = key_hash;
|
2016-02-13 04:47:41 +00:00
|
|
|
ud.is_key = 0;
|
|
|
|
ud.value = NULL;
|
|
|
|
ud.length = 0;
|
|
|
|
*value = 0;
|
2015-10-27 17:50:41 +00:00
|
|
|
|
2016-02-13 04:47:41 +00:00
|
|
|
if ((jsonsax_parse(json, &handlers, (void*)&ud) == JSONSAX_OK)
|
|
|
|
&& ud.value && ud.length < length)
|
2015-10-27 17:50:41 +00:00
|
|
|
{
|
|
|
|
strncpy(value, ud.value, length);
|
|
|
|
value[ud.length] = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
2015-10-09 16:29:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
2015-10-16 23:57:11 +00:00
|
|
|
Count number of achievements in a JSON file.
|
|
|
|
*****************************************************************************/
|
2015-10-09 16:29:57 +00:00
|
|
|
|
2015-11-08 14:41:57 +00:00
|
|
|
static int cheevos_count__json_end_array(void *userdata)
|
2015-10-09 16:29:57 +00:00
|
|
|
{
|
2015-10-16 23:57:11 +00:00
|
|
|
cheevos_countud_t* ud = (cheevos_countud_t*)userdata;
|
|
|
|
ud->in_cheevos = 0;
|
|
|
|
return 0;
|
2015-10-09 16:29:57 +00:00
|
|
|
}
|
|
|
|
|
2016-02-03 15:09:11 +00:00
|
|
|
static int cheevos_count__json_key(void *userdata,
|
|
|
|
const char *name, size_t length)
|
2015-10-09 16:29:57 +00:00
|
|
|
{
|
2015-10-27 17:50:41 +00:00
|
|
|
cheevos_countud_t* ud = (cheevos_countud_t*)userdata;
|
2015-11-08 17:09:04 +00:00
|
|
|
ud->field_hash = cheevos_djb2(name, length);
|
2015-10-09 16:29:57 +00:00
|
|
|
|
2016-02-13 04:47:41 +00:00
|
|
|
if (ud->field_hash == JSON_KEY_ACHIEVEMENTS)
|
2015-10-27 17:50:41 +00:00
|
|
|
ud->in_cheevos = 1;
|
2015-10-09 16:29:57 +00:00
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
return 0;
|
2015-10-09 16:29:57 +00:00
|
|
|
}
|
|
|
|
|
2016-02-03 15:09:11 +00:00
|
|
|
static int cheevos_count__json_number(void *userdata,
|
|
|
|
const char *number, size_t length)
|
2015-10-09 16:29:57 +00:00
|
|
|
{
|
2015-10-27 17:50:41 +00:00
|
|
|
long flags;
|
2015-11-08 17:09:04 +00:00
|
|
|
cheevos_countud_t* ud = (cheevos_countud_t*)userdata;
|
2015-10-16 23:57:11 +00:00
|
|
|
|
2016-02-13 04:47:41 +00:00
|
|
|
if (ud->in_cheevos && ud->field_hash == JSON_KEY_FLAGS)
|
2015-10-27 17:50:41 +00:00
|
|
|
{
|
|
|
|
flags = strtol(number, NULL, 10);
|
2015-10-16 23:57:11 +00:00
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
if (flags == 3) /* core achievements */
|
|
|
|
ud->core_count++;
|
|
|
|
else if (flags == 5) /* unofficial achievements */
|
|
|
|
ud->unofficial_count++;
|
|
|
|
}
|
2015-10-16 23:57:11 +00:00
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
return 0;
|
2015-10-09 16:29:57 +00:00
|
|
|
}
|
|
|
|
|
2016-02-03 15:09:11 +00:00
|
|
|
static int cheevos_count_cheevos(const char *json,
|
|
|
|
unsigned *core_count, unsigned *unofficial_count)
|
2015-10-27 17:50:41 +00:00
|
|
|
{
|
|
|
|
static const jsonsax_handlers_t handlers =
|
|
|
|
{
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2015-11-08 14:41:57 +00:00
|
|
|
cheevos_count__json_end_array,
|
|
|
|
cheevos_count__json_key,
|
2015-10-27 17:50:41 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2015-11-08 14:41:57 +00:00
|
|
|
cheevos_count__json_number,
|
2015-10-27 17:50:41 +00:00
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
int res;
|
|
|
|
cheevos_countud_t ud;
|
2016-02-13 04:47:41 +00:00
|
|
|
ud.in_cheevos = 0;
|
|
|
|
ud.core_count = 0;
|
2015-10-27 17:50:41 +00:00
|
|
|
ud.unofficial_count = 0;
|
|
|
|
|
2016-02-13 04:47:41 +00:00
|
|
|
res = jsonsax_parse(json, &handlers, (void*)&ud);
|
2015-10-27 17:50:41 +00:00
|
|
|
|
2016-02-13 04:47:41 +00:00
|
|
|
*core_count = ud.core_count;
|
|
|
|
*unofficial_count = ud.unofficial_count;
|
2015-10-27 17:50:41 +00:00
|
|
|
|
|
|
|
return res;
|
2015-10-09 16:29:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
2015-10-16 23:57:11 +00:00
|
|
|
Parse the MemAddr field.
|
|
|
|
*****************************************************************************/
|
2015-10-09 16:29:57 +00:00
|
|
|
|
2015-11-08 14:41:57 +00:00
|
|
|
static unsigned cheevos_prefix_to_comp_size(char prefix)
|
2015-10-09 16:29:57 +00:00
|
|
|
{
|
2015-10-27 17:50:41 +00:00
|
|
|
/* Careful not to use ABCDEF here, this denotes part of an actual variable! */
|
|
|
|
|
|
|
|
switch( toupper( prefix ) )
|
|
|
|
{
|
2016-02-03 15:09:11 +00:00
|
|
|
case 'M':
|
|
|
|
return CHEEVOS_VAR_SIZE_BIT_0;
|
|
|
|
case 'N':
|
|
|
|
return CHEEVOS_VAR_SIZE_BIT_1;
|
|
|
|
case 'O':
|
|
|
|
return CHEEVOS_VAR_SIZE_BIT_2;
|
|
|
|
case 'P':
|
|
|
|
return CHEEVOS_VAR_SIZE_BIT_3;
|
|
|
|
case 'Q':
|
|
|
|
return CHEEVOS_VAR_SIZE_BIT_4;
|
|
|
|
case 'R':
|
|
|
|
return CHEEVOS_VAR_SIZE_BIT_5;
|
|
|
|
case 'S':
|
|
|
|
return CHEEVOS_VAR_SIZE_BIT_6;
|
|
|
|
case 'T':
|
|
|
|
return CHEEVOS_VAR_SIZE_BIT_7;
|
|
|
|
case 'L':
|
|
|
|
return CHEEVOS_VAR_SIZE_NIBBLE_LOWER;
|
|
|
|
case 'U':
|
|
|
|
return CHEEVOS_VAR_SIZE_NIBBLE_UPPER;
|
|
|
|
case 'H':
|
|
|
|
return CHEEVOS_VAR_SIZE_EIGHT_BITS;
|
|
|
|
case 'X':
|
|
|
|
return CHEEVOS_VAR_SIZE_THIRTYTWO_BITS;
|
2015-10-27 17:50:41 +00:00
|
|
|
default:
|
2016-02-03 15:09:11 +00:00
|
|
|
case ' ':
|
|
|
|
break;
|
2015-10-27 17:50:41 +00:00
|
|
|
}
|
2016-02-03 15:09:11 +00:00
|
|
|
|
|
|
|
return CHEEVOS_VAR_SIZE_SIXTEEN_BITS;
|
2015-10-09 16:29:57 +00:00
|
|
|
}
|
|
|
|
|
2015-11-08 14:41:57 +00:00
|
|
|
static unsigned cheevos_read_hits(const char **memaddr)
|
2015-10-27 17:50:41 +00:00
|
|
|
{
|
2016-02-13 04:47:41 +00:00
|
|
|
char *end = NULL;
|
|
|
|
const char *str = *memaddr;
|
2015-10-27 17:50:41 +00:00
|
|
|
unsigned num_hits = 0;
|
|
|
|
|
|
|
|
if (*str == '(' || *str == '.')
|
|
|
|
{
|
|
|
|
num_hits = strtol(str + 1, &end, 10);
|
|
|
|
str = end + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*memaddr = str;
|
|
|
|
return num_hits;
|
2015-10-09 16:29:57 +00:00
|
|
|
}
|
|
|
|
|
2015-11-08 14:41:57 +00:00
|
|
|
static unsigned cheevos_parse_operator(const char **memaddr)
|
2015-10-27 17:50:41 +00:00
|
|
|
{
|
|
|
|
unsigned char op;
|
2015-11-08 17:09:04 +00:00
|
|
|
const char *str = *memaddr;
|
2015-10-27 17:50:41 +00:00
|
|
|
|
|
|
|
if (*str == '=' && str[1] == '=')
|
|
|
|
{
|
|
|
|
op = CHEEVOS_COND_OP_EQUALS;
|
|
|
|
str += 2;
|
|
|
|
}
|
|
|
|
else if (*str == '=')
|
|
|
|
{
|
|
|
|
op = CHEEVOS_COND_OP_EQUALS;
|
|
|
|
str++;
|
|
|
|
}
|
|
|
|
else if (*str == '!' && str[1] == '=')
|
|
|
|
{
|
|
|
|
op = CHEEVOS_COND_OP_NOT_EQUAL_TO;
|
|
|
|
str += 2;
|
|
|
|
}
|
|
|
|
else if (*str == '<' && str[1] == '=')
|
|
|
|
{
|
|
|
|
op = CHEEVOS_COND_OP_LESS_THAN_OR_EQUAL;
|
|
|
|
str += 2;
|
|
|
|
}
|
|
|
|
else if (*str == '<')
|
|
|
|
{
|
|
|
|
op = CHEEVOS_COND_OP_LESS_THAN;
|
2015-10-16 23:57:11 +00:00
|
|
|
str++;
|
2015-10-27 17:50:41 +00:00
|
|
|
}
|
|
|
|
else if (*str == '>' && str[1] == '=')
|
|
|
|
{
|
|
|
|
op = CHEEVOS_COND_OP_GREATER_THAN_OR_EQUAL;
|
|
|
|
str += 2;
|
|
|
|
}
|
|
|
|
else if (*str == '>')
|
|
|
|
{
|
|
|
|
op = CHEEVOS_COND_OP_GREATER_THAN;
|
2015-10-16 23:57:11 +00:00
|
|
|
str++;
|
2015-10-27 17:50:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-05-09 23:44:59 +00:00
|
|
|
RARCH_ERR("CHEEVOS Unknown operator %c\n", *str);
|
2015-10-27 17:50:41 +00:00
|
|
|
op = CHEEVOS_COND_OP_EQUALS;
|
|
|
|
}
|
|
|
|
|
|
|
|
*memaddr = str;
|
|
|
|
return op;
|
|
|
|
}
|
2015-10-15 14:04:26 +00:00
|
|
|
|
2015-11-08 14:41:57 +00:00
|
|
|
static void cheevos_parse_var(cheevos_var_t *var, const char **memaddr)
|
2015-10-27 17:50:41 +00:00
|
|
|
{
|
2016-02-13 04:47:41 +00:00
|
|
|
char *end = NULL;
|
2015-10-27 17:50:41 +00:00
|
|
|
const char *str = *memaddr;
|
2016-02-13 04:47:41 +00:00
|
|
|
unsigned base = 16;
|
2015-10-27 17:50:41 +00:00
|
|
|
|
|
|
|
if (toupper(*str) == 'D' && str[1] == '0' && toupper(str[2]) == 'X')
|
|
|
|
{
|
|
|
|
/* d0x + 4 hex digits */
|
|
|
|
str += 3;
|
|
|
|
var->type = CHEEVOS_VAR_TYPE_DELTA_MEM;
|
|
|
|
}
|
|
|
|
else if (*str == '0' && toupper(str[1]) == 'X')
|
|
|
|
{
|
|
|
|
/* 0x + 4 hex digits */
|
|
|
|
str += 2;
|
|
|
|
var->type = CHEEVOS_VAR_TYPE_ADDRESS;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var->type = CHEEVOS_VAR_TYPE_VALUE_COMP;
|
|
|
|
|
|
|
|
if (toupper(*str) == 'H')
|
|
|
|
str++;
|
|
|
|
else
|
|
|
|
base = 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (var->type != CHEEVOS_VAR_TYPE_VALUE_COMP)
|
|
|
|
{
|
2015-11-08 14:41:57 +00:00
|
|
|
var->size = cheevos_prefix_to_comp_size(*str);
|
2015-10-27 17:50:41 +00:00
|
|
|
|
|
|
|
if (var->size != CHEEVOS_VAR_SIZE_SIXTEEN_BITS)
|
|
|
|
str++;
|
|
|
|
}
|
|
|
|
|
|
|
|
var->value = strtol(str, &end, base);
|
|
|
|
*memaddr = end;
|
2016-05-13 01:03:18 +00:00
|
|
|
|
|
|
|
if ( var->type == CHEEVOS_VAR_TYPE_ADDRESS
|
|
|
|
|| var->type == CHEEVOS_VAR_TYPE_DELTA_MEM)
|
|
|
|
{
|
|
|
|
rarch_system_info_t *system;
|
|
|
|
runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &system);
|
|
|
|
|
|
|
|
var->bank_id = -1;
|
|
|
|
|
|
|
|
if (system->mmaps.num_descriptors != 0)
|
|
|
|
{
|
|
|
|
const struct retro_memory_descriptor *desc;
|
|
|
|
const struct retro_memory_descriptor *end;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
if (cheevos_locals.console_id == CHEEVOS_CONSOLE_GAMEBOY_ADVANCED)
|
|
|
|
{
|
|
|
|
/* Patch the address to correctly map it to the mmaps */
|
|
|
|
if (var->value < 0x8000)
|
|
|
|
{
|
|
|
|
/* Internal RAM */
|
|
|
|
var->value += 0x3000000;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Work RAM */
|
|
|
|
var->value += 0x2000000 - 0x8000;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
desc = system->mmaps.descriptors;
|
|
|
|
end = desc + system->mmaps.num_descriptors;
|
|
|
|
|
|
|
|
for (; desc < end; desc++)
|
|
|
|
{
|
|
|
|
if (var->value >= desc->start && var->value < (desc->start + desc->len))
|
|
|
|
{
|
|
|
|
var->bank_id = desc - system->mmaps.descriptors;
|
|
|
|
var->value = var->value - desc->start + desc->offset;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof(cheevos_locals.meminfo) / sizeof(cheevos_locals.meminfo[0]); i++)
|
|
|
|
{
|
|
|
|
if (var->value < cheevos_locals.meminfo[i].size)
|
|
|
|
{
|
|
|
|
var->bank_id = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
var->value -= cheevos_locals.meminfo[i].size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef CHEEVOS_DUMP_ADDRS
|
|
|
|
RARCH_LOG("CHEEVOS var %03d:%08X\n", var->bank_id + 1, var->value);
|
|
|
|
#endif
|
|
|
|
}
|
2015-10-09 16:29:57 +00:00
|
|
|
}
|
|
|
|
|
2015-11-08 14:41:57 +00:00
|
|
|
static void cheevos_parse_cond(cheevos_cond_t *cond, const char **memaddr)
|
2015-10-27 17:50:41 +00:00
|
|
|
{
|
|
|
|
const char* str = *memaddr;
|
|
|
|
|
|
|
|
if (*str == 'R' && str[1] == ':')
|
|
|
|
{
|
|
|
|
cond->type = CHEEVOS_COND_TYPE_RESET_IF;
|
|
|
|
str += 2;
|
|
|
|
}
|
|
|
|
else if (*str == 'P' && str[1] == ':')
|
|
|
|
{
|
|
|
|
cond->type = CHEEVOS_COND_TYPE_PAUSE_IF;
|
|
|
|
str += 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
cond->type = CHEEVOS_COND_TYPE_STANDARD;
|
|
|
|
|
2015-11-08 14:41:57 +00:00
|
|
|
cheevos_parse_var(&cond->source, &str);
|
|
|
|
cond->op = cheevos_parse_operator(&str);
|
|
|
|
cheevos_parse_var(&cond->target, &str);
|
2015-10-27 17:50:41 +00:00
|
|
|
cond->curr_hits = 0;
|
2015-11-08 14:41:57 +00:00
|
|
|
cond->req_hits = cheevos_read_hits(&str);
|
2015-10-27 17:50:41 +00:00
|
|
|
|
|
|
|
*memaddr = str;
|
2015-10-09 16:29:57 +00:00
|
|
|
}
|
|
|
|
|
2015-11-08 14:41:57 +00:00
|
|
|
static unsigned cheevos_count_cond_sets(const char *memaddr)
|
2015-10-09 16:29:57 +00:00
|
|
|
{
|
2015-10-27 17:50:41 +00:00
|
|
|
cheevos_cond_t cond;
|
2015-11-08 17:09:04 +00:00
|
|
|
unsigned count = 0;
|
2015-10-16 23:57:11 +00:00
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
do
|
2015-10-09 16:29:57 +00:00
|
|
|
{
|
2016-02-03 15:09:11 +00:00
|
|
|
while ( *memaddr == ' '
|
|
|
|
|| *memaddr == '_'
|
|
|
|
|| *memaddr == '|'
|
|
|
|
|| *memaddr == 'S')
|
2015-10-27 17:50:41 +00:00
|
|
|
memaddr++; /* Skip any chars up til the start of the achievement condition */
|
2015-10-09 16:29:57 +00:00
|
|
|
|
2015-11-08 14:41:57 +00:00
|
|
|
cheevos_parse_cond(&cond, &memaddr);
|
2015-10-27 17:50:41 +00:00
|
|
|
}
|
2016-02-03 15:09:11 +00:00
|
|
|
while ( *memaddr == '_'
|
|
|
|
|| *memaddr == 'R'
|
|
|
|
|| *memaddr == 'P'); /* AND, ResetIf, PauseIf */
|
2015-10-09 16:29:57 +00:00
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
while (*memaddr == 'S'); /* Repeat for all subconditions if they exist */
|
2015-10-09 16:29:57 +00:00
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
return count;
|
2015-10-09 16:29:57 +00:00
|
|
|
}
|
|
|
|
|
2015-11-08 14:41:57 +00:00
|
|
|
static unsigned cheevos_count_conds_in_set(const char *memaddr, unsigned set)
|
2015-10-09 16:29:57 +00:00
|
|
|
{
|
2015-11-08 17:09:04 +00:00
|
|
|
cheevos_cond_t cond;
|
2015-10-27 17:50:41 +00:00
|
|
|
unsigned index = 0;
|
|
|
|
unsigned count = 0;
|
2015-10-16 23:57:11 +00:00
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
do
|
2015-10-09 16:29:57 +00:00
|
|
|
{
|
2015-10-27 17:50:41 +00:00
|
|
|
while (*memaddr == ' ' || *memaddr == '_' || *memaddr == '|' || *memaddr == 'S')
|
|
|
|
memaddr++; /* Skip any chars up til the start of the achievement condition */
|
2015-10-09 16:29:57 +00:00
|
|
|
|
2015-11-08 14:41:57 +00:00
|
|
|
cheevos_parse_cond(&cond, &memaddr);
|
2015-10-09 16:29:57 +00:00
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
if (index == set)
|
|
|
|
count++;
|
2015-10-16 23:57:11 +00:00
|
|
|
}
|
2015-10-27 17:50:41 +00:00
|
|
|
while (*memaddr == '_' || *memaddr == 'R' || *memaddr == 'P'); /* AND, ResetIf, PauseIf */
|
|
|
|
}
|
|
|
|
while (*memaddr == 'S'); /* Repeat for all subconditions if they exist */
|
2015-10-09 16:29:57 +00:00
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
return count;
|
2015-10-09 16:29:57 +00:00
|
|
|
}
|
|
|
|
|
2015-11-08 14:41:57 +00:00
|
|
|
static void cheevos_parse_memaddr(cheevos_cond_t *cond, const char *memaddr)
|
2015-10-09 16:29:57 +00:00
|
|
|
{
|
2015-10-27 17:50:41 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
do
|
2015-10-09 16:29:57 +00:00
|
|
|
{
|
2015-10-27 17:50:41 +00:00
|
|
|
while (*memaddr == ' ' || *memaddr == '_' || *memaddr == '|' || *memaddr == 'S')
|
|
|
|
memaddr++; /* Skip any chars up til the start of the achievement condition */
|
2015-10-09 16:29:57 +00:00
|
|
|
|
2015-11-08 14:41:57 +00:00
|
|
|
cheevos_parse_cond(cond++, &memaddr);
|
2015-10-27 17:50:41 +00:00
|
|
|
}
|
|
|
|
while (*memaddr == '_' || *memaddr == 'R' || *memaddr == 'P'); /* AND, ResetIf, PauseIf */
|
|
|
|
}
|
|
|
|
while (*memaddr == 'S'); /* Repeat for all subconditions if they exist */
|
2015-10-09 16:29:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
2015-10-16 23:57:11 +00:00
|
|
|
Load achievements from a JSON string.
|
|
|
|
*****************************************************************************/
|
2015-10-09 16:29:57 +00:00
|
|
|
|
2015-11-08 14:41:57 +00:00
|
|
|
static INLINE const char *cheevos_dupstr(const cheevos_field_t *field)
|
2015-10-09 16:29:57 +00:00
|
|
|
{
|
2015-10-27 17:50:41 +00:00
|
|
|
char *string = (char*)malloc(field->length + 1);
|
2015-10-09 16:29:57 +00:00
|
|
|
|
2015-11-08 17:09:04 +00:00
|
|
|
if (!string)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
memcpy ((void*)string, (void*)field->string, field->length);
|
|
|
|
string[field->length] = 0;
|
2015-10-09 16:29:57 +00:00
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
return string;
|
2015-10-09 16:29:57 +00:00
|
|
|
}
|
|
|
|
|
2015-11-08 14:41:57 +00:00
|
|
|
static int cheevos_new_cheevo(cheevos_readud_t *ud)
|
2015-10-27 17:50:41 +00:00
|
|
|
{
|
|
|
|
const cheevos_condset_t *end;
|
|
|
|
unsigned set;
|
|
|
|
cheevos_condset_t *condset;
|
|
|
|
cheevo_t *cheevo;
|
2015-11-08 17:09:04 +00:00
|
|
|
int flags = strtol(ud->flags.string, NULL, 10);
|
2015-10-27 17:50:41 +00:00
|
|
|
|
|
|
|
if (flags == 3)
|
|
|
|
cheevo = cheevos_locals.core.cheevos + ud->core_count++;
|
|
|
|
else
|
|
|
|
cheevo = cheevos_locals.unofficial.cheevos + ud->unofficial_count++;
|
|
|
|
|
2015-11-08 17:09:04 +00:00
|
|
|
cheevo->id = strtol(ud->id.string, NULL, 10);
|
|
|
|
cheevo->title = cheevos_dupstr(&ud->title);
|
2015-11-08 14:41:57 +00:00
|
|
|
cheevo->description = cheevos_dupstr(&ud->desc);
|
2015-11-08 17:09:04 +00:00
|
|
|
cheevo->author = cheevos_dupstr(&ud->author);
|
|
|
|
cheevo->badge = cheevos_dupstr(&ud->badge);
|
|
|
|
cheevo->points = strtol(ud->points.string, NULL, 10);
|
|
|
|
cheevo->dirty = 0;
|
|
|
|
cheevo->active = 1; /* flags == 3; */
|
|
|
|
cheevo->modified = 0;
|
2015-10-27 17:50:41 +00:00
|
|
|
|
|
|
|
if (!cheevo->title || !cheevo->description || !cheevo->author || !cheevo->badge)
|
|
|
|
{
|
|
|
|
free((void*)cheevo->title);
|
|
|
|
free((void*)cheevo->description);
|
|
|
|
free((void*)cheevo->author);
|
|
|
|
free((void*)cheevo->badge);
|
2015-10-11 15:55:29 +00:00
|
|
|
return -1;
|
2015-10-27 17:50:41 +00:00
|
|
|
}
|
2015-10-11 15:55:29 +00:00
|
|
|
|
2015-11-08 14:41:57 +00:00
|
|
|
cheevo->count = cheevos_count_cond_sets(ud->memaddr.string);
|
2015-10-09 16:29:57 +00:00
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
if (cheevo->count)
|
|
|
|
{
|
2016-02-03 15:09:11 +00:00
|
|
|
cheevo->condsets = (cheevos_condset_t*)
|
|
|
|
malloc(cheevo->count * sizeof(cheevos_condset_t));
|
2015-10-09 16:29:57 +00:00
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
if (!cheevo->condsets)
|
|
|
|
return -1;
|
2015-10-15 14:04:26 +00:00
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
memset((void*)cheevo->condsets, 0, cheevo->count * sizeof(cheevos_condset_t));
|
|
|
|
end = cheevo->condsets + cheevo->count;
|
|
|
|
set = 0;
|
2015-10-15 14:04:26 +00:00
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
for (condset = cheevo->condsets; condset < end; condset++)
|
2015-10-16 23:57:11 +00:00
|
|
|
{
|
2016-02-13 04:47:41 +00:00
|
|
|
condset->count =
|
|
|
|
cheevos_count_conds_in_set(ud->memaddr.string, set++);
|
2015-10-27 17:50:41 +00:00
|
|
|
|
|
|
|
if (condset->count)
|
|
|
|
{
|
2016-02-03 15:09:11 +00:00
|
|
|
condset->conds = (cheevos_cond_t*)
|
|
|
|
malloc(condset->count * sizeof(cheevos_cond_t));
|
2015-10-27 17:50:41 +00:00
|
|
|
|
|
|
|
if (!condset->conds)
|
|
|
|
return -1;
|
|
|
|
|
2016-02-03 15:09:11 +00:00
|
|
|
memset((void*)condset->conds, 0,
|
|
|
|
condset->count * sizeof(cheevos_cond_t));
|
|
|
|
|
2015-11-08 14:41:57 +00:00
|
|
|
condset->expression = cheevos_dupstr(&ud->memaddr);
|
|
|
|
cheevos_parse_memaddr(condset->conds, ud->memaddr.string);
|
2015-10-27 17:50:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
condset->conds = NULL;
|
2015-10-09 16:29:57 +00:00
|
|
|
}
|
2015-10-27 17:50:41 +00:00
|
|
|
}
|
2015-10-09 16:29:57 +00:00
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
return 0;
|
2015-10-09 16:29:57 +00:00
|
|
|
}
|
|
|
|
|
2016-02-03 15:09:11 +00:00
|
|
|
static int cheevos_read__json_key( void *userdata,
|
|
|
|
const char *name, size_t length)
|
2015-10-27 17:50:41 +00:00
|
|
|
{
|
|
|
|
cheevos_readud_t *ud = (cheevos_readud_t*)userdata;
|
2015-11-08 17:09:04 +00:00
|
|
|
uint32_t hash = cheevos_djb2(name, length);
|
2015-10-16 23:57:11 +00:00
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
ud->field = NULL;
|
|
|
|
|
2016-02-13 04:47:41 +00:00
|
|
|
if (hash == JSON_KEY_ACHIEVEMENTS)
|
2015-10-27 17:50:41 +00:00
|
|
|
ud->in_cheevos = 1;
|
2016-05-09 23:44:59 +00:00
|
|
|
else if (hash == JSON_KEY_CONSOLE_ID)
|
2016-05-13 01:03:18 +00:00
|
|
|
ud->is_console_id = 1;
|
2015-10-27 17:50:41 +00:00
|
|
|
else if (ud->in_cheevos)
|
|
|
|
{
|
|
|
|
switch ( hash )
|
|
|
|
{
|
2016-02-13 04:47:41 +00:00
|
|
|
case JSON_KEY_ID:
|
|
|
|
ud->field = &ud->id;
|
|
|
|
break;
|
|
|
|
case JSON_KEY_MEMADDR:
|
|
|
|
ud->field = &ud->memaddr;
|
|
|
|
break;
|
|
|
|
case JSON_KEY_TITLE:
|
|
|
|
ud->field = &ud->title;
|
|
|
|
break;
|
|
|
|
case JSON_KEY_DESCRIPTION:
|
|
|
|
ud->field = &ud->desc;
|
|
|
|
break;
|
|
|
|
case JSON_KEY_POINTS:
|
|
|
|
ud->field = &ud->points;
|
|
|
|
break;
|
|
|
|
case JSON_KEY_AUTHOR:
|
|
|
|
ud->field = &ud->author;
|
|
|
|
break;
|
|
|
|
case JSON_KEY_MODIFIED:
|
|
|
|
ud->field = &ud->modified;
|
|
|
|
break;
|
|
|
|
case JSON_KEY_CREATED:
|
|
|
|
ud->field = &ud->created;
|
|
|
|
break;
|
|
|
|
case JSON_KEY_BADGENAME:
|
|
|
|
ud->field = &ud->badge;
|
|
|
|
break;
|
|
|
|
case JSON_KEY_FLAGS:
|
|
|
|
ud->field = &ud->flags;
|
|
|
|
break;
|
2015-10-27 17:50:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2015-10-09 16:29:57 +00:00
|
|
|
}
|
|
|
|
|
2016-02-03 15:09:11 +00:00
|
|
|
static int cheevos_read__json_string(void *userdata,
|
|
|
|
const char *string, size_t length)
|
2015-10-09 16:29:57 +00:00
|
|
|
{
|
2015-10-27 17:50:41 +00:00
|
|
|
cheevos_readud_t *ud = (cheevos_readud_t*)userdata;
|
2015-10-09 16:29:57 +00:00
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
if (ud->field)
|
|
|
|
{
|
|
|
|
ud->field->string = string;
|
|
|
|
ud->field->length = length;
|
|
|
|
}
|
2015-10-09 16:29:57 +00:00
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
return 0;
|
2015-10-09 16:29:57 +00:00
|
|
|
}
|
|
|
|
|
2016-02-03 15:09:11 +00:00
|
|
|
static int cheevos_read__json_number(void *userdata,
|
|
|
|
const char *number, size_t length)
|
2015-10-09 16:29:57 +00:00
|
|
|
{
|
2015-10-27 17:50:41 +00:00
|
|
|
cheevos_readud_t *ud = (cheevos_readud_t*)userdata;
|
2015-10-09 16:29:57 +00:00
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
if (ud->field)
|
|
|
|
{
|
|
|
|
ud->field->string = number;
|
|
|
|
ud->field->length = length;
|
|
|
|
}
|
2016-05-13 01:03:18 +00:00
|
|
|
else if (ud->is_console_id)
|
|
|
|
{
|
|
|
|
cheevos_locals.console_id = strtol(number, NULL, 10);
|
|
|
|
ud->is_console_id = 0;
|
|
|
|
}
|
2016-05-09 23:44:59 +00:00
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
return 0;
|
2015-10-09 16:29:57 +00:00
|
|
|
}
|
|
|
|
|
2015-11-08 14:41:57 +00:00
|
|
|
static int cheevos_read__json_end_object(void *userdata)
|
2015-10-09 16:29:57 +00:00
|
|
|
{
|
2015-10-27 17:50:41 +00:00
|
|
|
cheevos_readud_t *ud = (cheevos_readud_t*)userdata;
|
2015-10-09 16:29:57 +00:00
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
if (ud->in_cheevos)
|
2015-11-08 14:41:57 +00:00
|
|
|
return cheevos_new_cheevo(ud);
|
2015-10-09 16:29:57 +00:00
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
return 0;
|
2015-10-09 16:29:57 +00:00
|
|
|
}
|
|
|
|
|
2015-11-08 14:41:57 +00:00
|
|
|
static int cheevos_read__json_end_array(void *userdata)
|
2015-10-09 16:29:57 +00:00
|
|
|
{
|
2015-10-27 17:50:41 +00:00
|
|
|
cheevos_readud_t *ud = (cheevos_readud_t*)userdata;
|
|
|
|
ud->in_cheevos = 0;
|
|
|
|
return 0;
|
2015-10-09 16:29:57 +00:00
|
|
|
}
|
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
static int cheevos_parse(const char *json)
|
|
|
|
{
|
|
|
|
static const jsonsax_handlers_t handlers =
|
|
|
|
{
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2015-11-08 14:41:57 +00:00
|
|
|
cheevos_read__json_end_object,
|
2015-10-27 17:50:41 +00:00
|
|
|
NULL,
|
2015-11-08 14:41:57 +00:00
|
|
|
cheevos_read__json_end_array,
|
|
|
|
cheevos_read__json_key,
|
2015-10-27 17:50:41 +00:00
|
|
|
NULL,
|
2015-11-08 14:41:57 +00:00
|
|
|
cheevos_read__json_string,
|
|
|
|
cheevos_read__json_number,
|
2015-10-27 17:50:41 +00:00
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
unsigned core_count, unofficial_count;
|
|
|
|
cheevos_readud_t ud;
|
2015-11-08 17:09:04 +00:00
|
|
|
settings_t *settings = config_get_ptr();
|
2015-10-27 17:50:41 +00:00
|
|
|
|
|
|
|
/* Just return OK if cheevos are disabled. */
|
2015-11-08 17:09:04 +00:00
|
|
|
if (!settings->cheevos.enable)
|
2015-10-27 17:50:41 +00:00
|
|
|
return 0;
|
2015-10-16 23:57:11 +00:00
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
/* Count the number of achievements in the JSON file. */
|
2015-10-09 16:29:57 +00:00
|
|
|
|
2015-11-08 14:41:57 +00:00
|
|
|
if (cheevos_count_cheevos(json, &core_count, &unofficial_count) != JSONSAX_OK)
|
2015-10-27 17:50:41 +00:00
|
|
|
return -1;
|
2015-10-09 16:29:57 +00:00
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
/* Allocate the achievements. */
|
2015-10-16 23:57:11 +00:00
|
|
|
|
2016-02-03 15:09:11 +00:00
|
|
|
cheevos_locals.core.cheevos = (cheevo_t*)
|
|
|
|
malloc(core_count * sizeof(cheevo_t));
|
2015-10-27 17:50:41 +00:00
|
|
|
cheevos_locals.core.count = core_count;
|
2015-10-16 23:57:11 +00:00
|
|
|
|
2016-02-03 15:09:11 +00:00
|
|
|
cheevos_locals.unofficial.cheevos = (cheevo_t*)
|
|
|
|
malloc(unofficial_count * sizeof(cheevo_t));
|
2015-10-27 17:50:41 +00:00
|
|
|
cheevos_locals.unofficial.count = unofficial_count;
|
2015-10-16 23:57:11 +00:00
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
if (!cheevos_locals.core.cheevos || !cheevos_locals.unofficial.cheevos)
|
|
|
|
{
|
|
|
|
free((void*)cheevos_locals.core.cheevos);
|
|
|
|
free((void*)cheevos_locals.unofficial.cheevos);
|
|
|
|
cheevos_locals.core.count = cheevos_locals.unofficial.count = 0;
|
2015-10-16 23:57:11 +00:00
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2015-10-16 23:57:11 +00:00
|
|
|
|
2016-02-03 15:09:11 +00:00
|
|
|
memset((void*)cheevos_locals.core.cheevos,
|
|
|
|
0, core_count * sizeof(cheevo_t));
|
|
|
|
memset((void*)cheevos_locals.unofficial.cheevos,
|
|
|
|
0, unofficial_count * sizeof(cheevo_t));
|
2015-10-16 23:57:11 +00:00
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
/* Load the achievements. */
|
2016-02-13 05:24:49 +00:00
|
|
|
ud.in_cheevos = 0;
|
2016-05-13 01:03:18 +00:00
|
|
|
ud.is_console_id = 0;
|
2016-02-13 05:24:49 +00:00
|
|
|
ud.field = NULL;
|
|
|
|
ud.core_count = 0;
|
2015-10-27 17:50:41 +00:00
|
|
|
ud.unofficial_count = 0;
|
2015-10-16 23:57:11 +00:00
|
|
|
|
2015-11-19 13:05:08 +00:00
|
|
|
if (jsonsax_parse(json, &handlers, (void*)&ud) != JSONSAX_OK)
|
2015-10-27 17:50:41 +00:00
|
|
|
{
|
2016-05-07 22:15:04 +00:00
|
|
|
cheevos_unload();
|
2015-10-27 17:50:41 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-11-09 00:53:17 +00:00
|
|
|
return 0;
|
2015-10-16 16:07:57 +00:00
|
|
|
}
|
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
Test all the achievements (call once per frame).
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2016-05-13 01:03:18 +00:00
|
|
|
static const uint8_t *cheevos_get_memory(const cheevos_var_t *var)
|
2015-10-27 17:50:41 +00:00
|
|
|
{
|
2016-05-13 01:03:18 +00:00
|
|
|
if (var->bank_id >= 0)
|
2015-10-27 17:50:41 +00:00
|
|
|
{
|
2016-05-13 01:03:18 +00:00
|
|
|
rarch_system_info_t *system;
|
|
|
|
runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &system);
|
|
|
|
|
|
|
|
if (system->mmaps.num_descriptors != 0)
|
|
|
|
{
|
|
|
|
return (uint8_t *)system->mmaps.descriptors[var->bank_id].ptr + var->value;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return (uint8_t *)cheevos_locals.meminfo[var->bank_id].data + var->value;
|
|
|
|
}
|
2015-10-27 17:50:41 +00:00
|
|
|
}
|
2016-05-13 01:03:18 +00:00
|
|
|
|
2015-11-03 16:28:18 +00:00
|
|
|
return NULL;
|
2015-10-09 16:29:57 +00:00
|
|
|
}
|
|
|
|
|
2015-11-08 14:41:57 +00:00
|
|
|
static unsigned cheevos_get_var_value(cheevos_var_t *var)
|
2015-10-09 16:29:57 +00:00
|
|
|
{
|
2016-02-13 05:24:49 +00:00
|
|
|
unsigned previous = var->previous;
|
|
|
|
unsigned live_val = 0;
|
|
|
|
const uint8_t *memory = NULL;
|
2015-10-27 17:50:41 +00:00
|
|
|
|
|
|
|
if (var->type == CHEEVOS_VAR_TYPE_VALUE_COMP)
|
|
|
|
return var->value;
|
|
|
|
|
2016-02-03 15:09:11 +00:00
|
|
|
if ( var->type == CHEEVOS_VAR_TYPE_ADDRESS
|
|
|
|
|| var->type == CHEEVOS_VAR_TYPE_DELTA_MEM)
|
2015-10-27 17:50:41 +00:00
|
|
|
{
|
|
|
|
/* TODO Check with Scott if the bank id is needed */
|
2016-05-13 01:03:18 +00:00
|
|
|
memory = cheevos_get_memory(var);
|
2015-11-03 16:28:18 +00:00
|
|
|
|
|
|
|
if (memory)
|
2015-10-27 17:50:41 +00:00
|
|
|
{
|
2015-11-03 16:28:18 +00:00
|
|
|
live_val = memory[0];
|
|
|
|
|
2016-02-13 04:47:41 +00:00
|
|
|
if (var->size >= CHEEVOS_VAR_SIZE_BIT_0
|
|
|
|
&& var->size <= CHEEVOS_VAR_SIZE_BIT_7)
|
|
|
|
live_val = (live_val &
|
|
|
|
(1 << (var->size - CHEEVOS_VAR_SIZE_BIT_0))) != 0;
|
|
|
|
else
|
2015-11-03 16:28:18 +00:00
|
|
|
{
|
2016-02-13 04:47:41 +00:00
|
|
|
switch (var->size)
|
|
|
|
{
|
|
|
|
case CHEEVOS_VAR_SIZE_NIBBLE_LOWER:
|
|
|
|
live_val &= 0x0f;
|
|
|
|
break;
|
|
|
|
case CHEEVOS_VAR_SIZE_NIBBLE_UPPER:
|
|
|
|
live_val = (live_val >> 4) & 0x0f;
|
|
|
|
break;
|
|
|
|
case CHEEVOS_VAR_SIZE_EIGHT_BITS:
|
|
|
|
break;
|
|
|
|
case CHEEVOS_VAR_SIZE_SIXTEEN_BITS:
|
|
|
|
live_val |= memory[1] << 8;
|
|
|
|
break;
|
|
|
|
case CHEEVOS_VAR_SIZE_THIRTYTWO_BITS:
|
|
|
|
live_val |= memory[1] << 8;
|
|
|
|
live_val |= memory[2] << 16;
|
|
|
|
live_val |= memory[3] << 24;
|
|
|
|
break;
|
|
|
|
}
|
2015-11-03 16:28:18 +00:00
|
|
|
}
|
2015-10-27 17:50:41 +00:00
|
|
|
}
|
2015-11-03 16:28:18 +00:00
|
|
|
else
|
|
|
|
live_val = 0;
|
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
if (var->type == CHEEVOS_VAR_TYPE_DELTA_MEM)
|
|
|
|
{
|
|
|
|
var->previous = live_val;
|
|
|
|
return previous;
|
|
|
|
}
|
2015-10-09 16:29:57 +00:00
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
return live_val;
|
|
|
|
}
|
2015-10-09 16:29:57 +00:00
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
/* We shouldn't get here... */
|
|
|
|
return 0;
|
|
|
|
}
|
2015-10-09 16:29:57 +00:00
|
|
|
|
2015-11-08 14:41:57 +00:00
|
|
|
static int cheevos_test_condition(cheevos_cond_t *cond)
|
2015-10-27 17:50:41 +00:00
|
|
|
{
|
2015-11-08 14:41:57 +00:00
|
|
|
unsigned sval = cheevos_get_var_value(&cond->source);
|
|
|
|
unsigned tval = cheevos_get_var_value(&cond->target);
|
2015-10-27 17:50:41 +00:00
|
|
|
|
|
|
|
switch (cond->op)
|
|
|
|
{
|
|
|
|
case CHEEVOS_COND_OP_EQUALS:
|
|
|
|
return sval == tval;
|
|
|
|
|
|
|
|
case CHEEVOS_COND_OP_LESS_THAN:
|
|
|
|
return sval < tval;
|
2015-10-09 16:29:57 +00:00
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
case CHEEVOS_COND_OP_LESS_THAN_OR_EQUAL:
|
|
|
|
return sval <= tval;
|
2015-10-09 16:29:57 +00:00
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
case CHEEVOS_COND_OP_GREATER_THAN:
|
|
|
|
return sval > tval;
|
2015-10-09 16:29:57 +00:00
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
case CHEEVOS_COND_OP_GREATER_THAN_OR_EQUAL:
|
|
|
|
return sval >= tval;
|
|
|
|
|
|
|
|
case CHEEVOS_COND_OP_NOT_EQUAL_TO:
|
|
|
|
return sval != tval;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return 1;
|
|
|
|
}
|
2015-10-09 16:29:57 +00:00
|
|
|
}
|
|
|
|
|
2016-02-03 15:09:11 +00:00
|
|
|
static int cheevos_test_cond_set(const cheevos_condset_t *condset,
|
|
|
|
int *dirty_conds, int *reset_conds, int match_any)
|
2015-10-27 17:50:41 +00:00
|
|
|
{
|
2016-02-13 05:24:49 +00:00
|
|
|
int cond_valid = 0;
|
|
|
|
int set_valid = 1;
|
2015-10-27 17:50:41 +00:00
|
|
|
const cheevos_cond_t *end = condset->conds + condset->count;
|
2016-02-13 05:24:49 +00:00
|
|
|
cheevos_cond_t *cond = NULL;
|
2015-10-27 17:50:41 +00:00
|
|
|
|
2016-02-03 15:09:11 +00:00
|
|
|
/* Now, read all Pause conditions, and if any are true,
|
|
|
|
* do not process further (retain old state). */
|
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
for (cond = condset->conds; cond < end; cond++)
|
|
|
|
{
|
|
|
|
if (cond->type == CHEEVOS_COND_TYPE_PAUSE_IF)
|
2015-10-09 16:29:57 +00:00
|
|
|
{
|
2015-10-27 17:50:41 +00:00
|
|
|
/* Reset by default, set to 1 if hit! */
|
|
|
|
cond->curr_hits = 0;
|
2015-10-09 16:29:57 +00:00
|
|
|
|
2015-11-08 14:41:57 +00:00
|
|
|
if (cheevos_test_condition(cond))
|
2015-10-27 17:50:41 +00:00
|
|
|
{
|
|
|
|
cond->curr_hits = 1;
|
|
|
|
*dirty_conds = 1;
|
|
|
|
|
2016-02-03 15:09:11 +00:00
|
|
|
/* Early out: this achievement is paused,
|
|
|
|
* do not process any further! */
|
2015-10-27 17:50:41 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2015-10-16 23:57:11 +00:00
|
|
|
}
|
2015-10-27 17:50:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Read all standard conditions, and process as normal: */
|
|
|
|
for (cond = condset->conds; cond < end; cond++)
|
|
|
|
{
|
2016-02-03 15:09:11 +00:00
|
|
|
if ( cond->type == CHEEVOS_COND_TYPE_PAUSE_IF
|
|
|
|
|| cond->type == CHEEVOS_COND_TYPE_RESET_IF)
|
2015-10-27 17:50:41 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (cond->req_hits != 0 && cond->curr_hits >= cond->req_hits)
|
|
|
|
continue;
|
|
|
|
|
2015-11-08 14:41:57 +00:00
|
|
|
cond_valid = cheevos_test_condition(cond);
|
2015-10-27 17:50:41 +00:00
|
|
|
|
|
|
|
if (cond_valid)
|
2015-10-16 23:57:11 +00:00
|
|
|
{
|
2015-10-27 17:50:41 +00:00
|
|
|
cond->curr_hits++;
|
|
|
|
*dirty_conds = 1;
|
|
|
|
|
|
|
|
/* Process this logic, if this condition is true: */
|
|
|
|
if (cond->req_hits == 0)
|
|
|
|
; /* Not a hit-based requirement: ignore any additional logic! */
|
|
|
|
else if (cond->curr_hits < cond->req_hits)
|
|
|
|
cond_valid = 0; /* Not entirely valid yet! */
|
|
|
|
|
|
|
|
if (match_any)
|
|
|
|
break;
|
2015-10-09 16:29:57 +00:00
|
|
|
}
|
2015-10-15 14:04:26 +00:00
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
/* Sequential or non-sequential? */
|
|
|
|
set_valid &= cond_valid;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now, ONLY read reset conditions! */
|
|
|
|
for (cond = condset->conds; cond < end; cond++)
|
|
|
|
{
|
|
|
|
if (cond->type == CHEEVOS_COND_TYPE_RESET_IF)
|
2015-10-16 23:57:11 +00:00
|
|
|
{
|
2015-11-08 14:41:57 +00:00
|
|
|
cond_valid = cheevos_test_condition(cond);
|
2015-10-27 17:50:41 +00:00
|
|
|
|
|
|
|
if (cond_valid)
|
|
|
|
{
|
|
|
|
*reset_conds = 1; /* Resets all hits found so far */
|
|
|
|
set_valid = 0; /* Cannot be valid if we've hit a reset condition. */
|
|
|
|
break; /* No point processing any further reset conditions. */
|
|
|
|
}
|
2015-10-16 23:57:11 +00:00
|
|
|
}
|
2015-10-27 17:50:41 +00:00
|
|
|
}
|
2015-10-09 16:29:57 +00:00
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
return set_valid;
|
|
|
|
}
|
2015-10-09 16:29:57 +00:00
|
|
|
|
2015-11-08 14:41:57 +00:00
|
|
|
static int cheevos_reset_cond_set(cheevos_condset_t *condset, int deltas)
|
2015-10-27 17:50:41 +00:00
|
|
|
{
|
2016-02-13 05:24:49 +00:00
|
|
|
int dirty = 0;
|
2015-10-27 17:50:41 +00:00
|
|
|
const cheevos_cond_t *end = condset->conds + condset->count;
|
2016-02-13 05:24:49 +00:00
|
|
|
cheevos_cond_t *cond = NULL;
|
2015-10-09 16:29:57 +00:00
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
if (deltas)
|
|
|
|
{
|
|
|
|
for (cond = condset->conds; cond < end; cond++)
|
2015-10-09 16:29:57 +00:00
|
|
|
{
|
2015-10-27 17:50:41 +00:00
|
|
|
dirty |= cond->curr_hits != 0;
|
|
|
|
cond->curr_hits = 0;
|
|
|
|
|
|
|
|
cond->source.previous = cond->source.value;
|
|
|
|
cond->target.previous = cond->target.value;
|
2015-10-09 16:29:57 +00:00
|
|
|
}
|
2015-10-27 17:50:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (cond = condset->conds; cond < end; cond++)
|
|
|
|
{
|
|
|
|
dirty |= cond->curr_hits != 0;
|
|
|
|
cond->curr_hits = 0;
|
|
|
|
}
|
|
|
|
}
|
2015-10-09 16:29:57 +00:00
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
return dirty;
|
2015-10-09 16:29:57 +00:00
|
|
|
}
|
|
|
|
|
2015-11-08 14:41:57 +00:00
|
|
|
static int cheevos_test_cheevo(cheevo_t *cheevo)
|
2015-10-27 17:50:41 +00:00
|
|
|
{
|
|
|
|
int dirty;
|
2016-02-13 05:24:49 +00:00
|
|
|
int dirty_conds = 0;
|
|
|
|
int reset_conds = 0;
|
|
|
|
int ret_val = 0;
|
|
|
|
int ret_val_sub_cond = cheevo->count == 1;
|
|
|
|
cheevos_condset_t *condset = cheevo->condsets;
|
|
|
|
const cheevos_condset_t *end = condset + cheevo->count;
|
2015-10-27 17:50:41 +00:00
|
|
|
|
|
|
|
if (condset < end)
|
|
|
|
{
|
2015-11-08 14:41:57 +00:00
|
|
|
ret_val = cheevos_test_cond_set(condset, &dirty_conds, &reset_conds, 0);
|
2015-10-27 17:50:41 +00:00
|
|
|
condset++;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (condset < end)
|
|
|
|
{
|
2015-11-08 14:41:57 +00:00
|
|
|
int res = cheevos_test_cond_set(condset, &dirty_conds, &reset_conds, 0);
|
2015-10-27 17:50:41 +00:00
|
|
|
ret_val_sub_cond |= res;
|
|
|
|
condset++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dirty_conds)
|
|
|
|
cheevo->dirty |= CHEEVOS_DIRTY_CONDITIONS;
|
|
|
|
|
|
|
|
if (reset_conds)
|
|
|
|
{
|
|
|
|
dirty = 0;
|
|
|
|
|
|
|
|
for (condset = cheevo->condsets; condset < end; condset++)
|
2015-11-08 14:41:57 +00:00
|
|
|
dirty |= cheevos_reset_cond_set(condset, 0);
|
2015-10-27 17:50:41 +00:00
|
|
|
|
|
|
|
if (dirty)
|
|
|
|
cheevo->dirty |= CHEEVOS_DIRTY_CONDITIONS;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret_val && ret_val_sub_cond;
|
2015-10-09 16:29:57 +00:00
|
|
|
}
|
|
|
|
|
2015-11-08 19:40:25 +00:00
|
|
|
static void cheevos_url_encode(const char *str, char *encoded, size_t len)
|
|
|
|
{
|
|
|
|
while (*str)
|
|
|
|
{
|
2016-02-13 05:24:49 +00:00
|
|
|
if ( isalnum(*str) || *str == '-'
|
|
|
|
|| *str == '_' || *str == '.'
|
|
|
|
|| *str == '~')
|
2015-11-08 19:40:25 +00:00
|
|
|
{
|
|
|
|
if (len >= 2)
|
|
|
|
{
|
|
|
|
*encoded++ = *str++;
|
|
|
|
len--;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (len >= 4)
|
|
|
|
{
|
|
|
|
sprintf(encoded, "%%%02x", (uint8_t)*str);
|
|
|
|
encoded += 3;
|
|
|
|
str++;
|
|
|
|
len -= 3;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*encoded = 0;
|
|
|
|
}
|
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
static int cheevos_login(retro_time_t *timeout)
|
|
|
|
{
|
2015-10-30 21:31:21 +00:00
|
|
|
const char *username;
|
|
|
|
const char *password;
|
2015-11-08 19:40:25 +00:00
|
|
|
char urle_user[64];
|
|
|
|
char urle_pwd[64];
|
2015-10-27 17:50:41 +00:00
|
|
|
char request[256];
|
|
|
|
const char *json;
|
|
|
|
int res;
|
2015-11-08 17:03:56 +00:00
|
|
|
settings_t *settings = config_get_ptr();
|
2015-10-09 16:29:57 +00:00
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
if (cheevos_locals.token[0])
|
|
|
|
return 0;
|
2015-10-30 21:31:21 +00:00
|
|
|
|
2015-11-08 17:03:56 +00:00
|
|
|
username = settings->cheevos.username;
|
|
|
|
password = settings->cheevos.password;
|
2015-10-30 21:31:21 +00:00
|
|
|
|
|
|
|
if (!username || !*username || !password || !*password)
|
|
|
|
{
|
2015-12-07 14:32:14 +00:00
|
|
|
runloop_msg_queue_push("Missing Retro Achievements account information", 0, 5 * 60, false);
|
|
|
|
runloop_msg_queue_push("Please fill in your account information in Settings", 0, 5 * 60, false);
|
2016-05-09 23:44:59 +00:00
|
|
|
RARCH_ERR("CHEEVOS username and/or password not informed\n");
|
2015-10-30 21:31:21 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2015-11-08 19:40:25 +00:00
|
|
|
|
|
|
|
cheevos_url_encode(username, urle_user, sizeof(urle_user));
|
|
|
|
cheevos_url_encode(password, urle_pwd, sizeof(urle_pwd));
|
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
snprintf(
|
|
|
|
request, sizeof(request),
|
|
|
|
"http://retroachievements.org/dorequest.php?r=login&u=%s&p=%s",
|
2015-11-08 19:40:25 +00:00
|
|
|
urle_user, urle_pwd
|
2015-10-27 17:50:41 +00:00
|
|
|
);
|
2015-11-08 19:40:25 +00:00
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
request[sizeof(request) - 1] = 0;
|
|
|
|
|
2016-05-09 23:44:59 +00:00
|
|
|
#ifdef CHEEVOS_LOG_URLS
|
|
|
|
RARCH_LOG("CHEEVOS url to login: %s\n", request);
|
|
|
|
#endif
|
|
|
|
|
2015-11-08 14:41:57 +00:00
|
|
|
if (!cheevos_http_get(&json, NULL, request, timeout))
|
2015-10-27 17:50:41 +00:00
|
|
|
{
|
2016-02-13 04:47:41 +00:00
|
|
|
res = cheevos_get_value(json, JSON_KEY_TOKEN,
|
|
|
|
cheevos_locals.token, sizeof(cheevos_locals.token));
|
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
free((void*)json);
|
|
|
|
|
|
|
|
if (!res)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-13 05:24:49 +00:00
|
|
|
runloop_msg_queue_push("Retro Achievements login error",
|
|
|
|
0, 5 * 60, false);
|
|
|
|
runloop_msg_queue_push(
|
|
|
|
"Please make sure your account information is correct",
|
|
|
|
0, 5 * 60, false);
|
2016-05-09 23:44:59 +00:00
|
|
|
RARCH_ERR("CHEEVOS error getting user token.\n");
|
2015-10-27 17:50:41 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-11-08 14:41:57 +00:00
|
|
|
static void cheevos_unlocker(void *payload)
|
2015-10-27 17:50:41 +00:00
|
|
|
{
|
|
|
|
char request[256];
|
|
|
|
const char *result;
|
2015-11-09 00:53:17 +00:00
|
|
|
settings_t *settings = config_get_ptr();
|
|
|
|
unsigned cheevo_id = (unsigned)(uintptr_t)payload;
|
2015-10-27 17:50:41 +00:00
|
|
|
|
|
|
|
if (!cheevos_login(NULL))
|
|
|
|
{
|
|
|
|
snprintf(
|
|
|
|
request, sizeof(request),
|
|
|
|
"http://retroachievements.org/dorequest.php?r=awardachievement&u=%s&t=%s&a=%u&h=%d",
|
2016-03-14 10:51:54 +00:00
|
|
|
settings->cheevos.username, cheevos_locals.token, cheevo_id, settings->cheevos.hardcore_mode_enable
|
2015-10-27 17:50:41 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
request[sizeof(request) - 1] = 0;
|
2016-05-09 23:44:59 +00:00
|
|
|
|
|
|
|
#ifdef CHEEVOS_LOG_URLS
|
2016-05-13 01:03:18 +00:00
|
|
|
RARCH_LOG("CHEEVOS url to award the cheevo: %s\n", request);
|
2016-05-09 23:44:59 +00:00
|
|
|
#endif
|
|
|
|
|
2015-11-08 14:41:57 +00:00
|
|
|
if (!cheevos_http_get(&result, NULL, request, NULL))
|
2015-10-27 17:50:41 +00:00
|
|
|
{
|
2015-11-05 00:41:12 +00:00
|
|
|
RARCH_LOG("CHEEVOS awarded achievement %u: %s\n", cheevo_id, result);
|
2015-10-27 17:50:41 +00:00
|
|
|
free((void*)result);
|
|
|
|
}
|
|
|
|
else
|
2015-11-08 03:34:44 +00:00
|
|
|
{
|
2016-05-09 23:44:59 +00:00
|
|
|
RARCH_ERR("CHEEVOS error awarding achievement %u, will retry...\n", cheevo_id);
|
|
|
|
/* re-schedule */
|
2015-12-06 17:37:57 +00:00
|
|
|
rarch_main_async_job_add(cheevos_unlocker, (void*)(uintptr_t)cheevo_id);
|
2015-11-08 03:34:44 +00:00
|
|
|
}
|
2015-10-27 17:50:41 +00:00
|
|
|
}
|
2015-10-09 16:29:57 +00:00
|
|
|
}
|
|
|
|
|
2015-11-08 14:41:57 +00:00
|
|
|
static void cheevos_test_cheevo_set(const cheevoset_t *set)
|
2015-10-09 16:29:57 +00:00
|
|
|
{
|
2015-12-06 17:39:48 +00:00
|
|
|
cheevo_t *cheevo = NULL;
|
2015-10-27 17:50:41 +00:00
|
|
|
const cheevo_t *end = set->cheevos + set->count;
|
|
|
|
|
|
|
|
for (cheevo = set->cheevos; cheevo < end; cheevo++)
|
|
|
|
{
|
2015-11-08 14:41:57 +00:00
|
|
|
if (cheevo->active && cheevos_test_cheevo(cheevo))
|
2015-10-27 17:50:41 +00:00
|
|
|
{
|
2016-05-09 23:44:59 +00:00
|
|
|
RARCH_LOG("CHEEVOS awarding cheevo %s (%s)\n", cheevo->title, cheevo->description);
|
2015-10-16 23:57:11 +00:00
|
|
|
|
2015-12-07 14:32:14 +00:00
|
|
|
runloop_msg_queue_push(cheevo->title, 0, 3 * 60, false);
|
|
|
|
runloop_msg_queue_push(cheevo->description, 0, 5 * 60, false);
|
2015-10-16 23:57:11 +00:00
|
|
|
|
2016-02-03 15:09:11 +00:00
|
|
|
rarch_main_async_job_add(cheevos_unlocker,
|
|
|
|
(void*)(uintptr_t)cheevo->id);
|
2015-10-16 23:57:11 +00:00
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
cheevo->active = 0;
|
|
|
|
}
|
|
|
|
}
|
2015-10-09 16:29:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
2015-10-16 23:57:11 +00:00
|
|
|
Free the loaded achievements.
|
|
|
|
*****************************************************************************/
|
2015-10-09 16:29:57 +00:00
|
|
|
|
2015-11-08 14:41:57 +00:00
|
|
|
static void cheevos_free_condset(const cheevos_condset_t *set)
|
2015-10-09 16:29:57 +00:00
|
|
|
{
|
2015-10-27 17:50:41 +00:00
|
|
|
free((void*)set->conds);
|
2015-10-09 16:29:57 +00:00
|
|
|
}
|
|
|
|
|
2015-11-08 14:41:57 +00:00
|
|
|
static void cheevos_free_cheevo(const cheevo_t *cheevo)
|
2015-10-09 16:29:57 +00:00
|
|
|
{
|
2015-10-27 17:50:41 +00:00
|
|
|
free((void*)cheevo->title);
|
|
|
|
free((void*)cheevo->description);
|
|
|
|
free((void*)cheevo->author);
|
|
|
|
free((void*)cheevo->badge);
|
2015-11-08 14:41:57 +00:00
|
|
|
cheevos_free_condset(cheevo->condsets);
|
2015-10-09 16:29:57 +00:00
|
|
|
}
|
|
|
|
|
2015-11-08 14:41:57 +00:00
|
|
|
static void cheevos_free_cheevo_set(const cheevoset_t *set)
|
2015-10-09 16:29:57 +00:00
|
|
|
{
|
2015-10-27 17:50:41 +00:00
|
|
|
const cheevo_t *cheevo = set->cheevos;
|
|
|
|
const cheevo_t *end = cheevo + set->count;
|
2015-10-09 16:29:57 +00:00
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
while (cheevo < end)
|
2015-11-08 14:41:57 +00:00
|
|
|
cheevos_free_cheevo(cheevo++);
|
2015-10-09 16:29:57 +00:00
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
free((void*)set->cheevos);
|
2015-10-09 16:29:57 +00:00
|
|
|
}
|
|
|
|
|
2015-10-14 03:12:01 +00:00
|
|
|
/*****************************************************************************
|
2015-10-16 23:57:11 +00:00
|
|
|
Load achievements from retroachievements.org.
|
|
|
|
*****************************************************************************/
|
2015-10-14 03:12:01 +00:00
|
|
|
|
2016-02-03 15:09:11 +00:00
|
|
|
static int cheevos_get_by_game_id(const char **json,
|
|
|
|
unsigned game_id, retro_time_t *timeout)
|
2015-10-14 03:12:01 +00:00
|
|
|
{
|
2015-10-27 17:50:41 +00:00
|
|
|
char request[256];
|
2016-02-13 05:24:49 +00:00
|
|
|
settings_t *settings = config_get_ptr();
|
2015-10-14 03:12:01 +00:00
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
/* Just return OK if cheevos are disabled. */
|
2015-11-08 17:03:56 +00:00
|
|
|
if (!settings->cheevos.enable)
|
2015-10-27 17:50:41 +00:00
|
|
|
return 0;
|
2015-10-14 03:12:01 +00:00
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
if (!cheevos_login(timeout))
|
|
|
|
{
|
|
|
|
snprintf(
|
|
|
|
request, sizeof(request),
|
|
|
|
"http://retroachievements.org/dorequest.php?r=patch&u=%s&g=%u&f=3&l=1&t=%s",
|
2015-11-08 17:03:56 +00:00
|
|
|
settings->cheevos.username, game_id, cheevos_locals.token
|
2015-10-27 17:50:41 +00:00
|
|
|
);
|
2015-10-14 03:12:01 +00:00
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
request[sizeof(request) - 1] = 0;
|
2016-05-09 23:44:59 +00:00
|
|
|
|
|
|
|
#ifdef CHEEVOS_LOG_URLS
|
|
|
|
RARCH_LOG("CHEEVOS url to get the list of cheevos: %s\n", request);
|
|
|
|
#endif
|
2015-10-27 17:50:41 +00:00
|
|
|
|
2015-11-08 14:41:57 +00:00
|
|
|
if (!cheevos_http_get(json, NULL, request, timeout))
|
2015-10-27 17:50:41 +00:00
|
|
|
{
|
|
|
|
RARCH_LOG("CHEEVOS got achievements for game id %u\n", game_id);
|
|
|
|
return 0;
|
|
|
|
}
|
2015-10-14 03:12:01 +00:00
|
|
|
|
2016-05-09 23:44:59 +00:00
|
|
|
RARCH_ERR("CHEEVOS error getting achievements for game id %u\n", game_id);
|
2015-10-27 17:50:41 +00:00
|
|
|
}
|
2015-10-14 03:12:01 +00:00
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
return -1;
|
2015-10-14 03:12:01 +00:00
|
|
|
}
|
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
static unsigned cheevos_get_game_id(unsigned char *hash, retro_time_t *timeout)
|
2015-10-14 03:12:01 +00:00
|
|
|
{
|
2015-10-27 17:50:41 +00:00
|
|
|
char request[256];
|
|
|
|
const char* json;
|
|
|
|
char game_id[16];
|
|
|
|
int res;
|
2015-10-30 21:31:21 +00:00
|
|
|
|
|
|
|
RARCH_LOG(
|
|
|
|
"CHEEVOS getting game id for hash %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\n",
|
|
|
|
hash[ 0], hash[ 1], hash[ 2], hash[ 3],
|
|
|
|
hash[ 4], hash[ 5], hash[ 6], hash[ 7],
|
|
|
|
hash[ 8], hash[ 9], hash[10], hash[11],
|
|
|
|
hash[12], hash[13], hash[14], hash[15]
|
|
|
|
);
|
2015-10-27 17:50:41 +00:00
|
|
|
|
|
|
|
snprintf(
|
|
|
|
request, sizeof(request),
|
2015-11-05 00:41:12 +00:00
|
|
|
"http://retroachievements.org/dorequest.php?r=gameid&m=%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
|
2015-10-27 17:50:41 +00:00
|
|
|
hash[ 0], hash[ 1], hash[ 2], hash[ 3],
|
|
|
|
hash[ 4], hash[ 5], hash[ 6], hash[ 7],
|
|
|
|
hash[ 8], hash[ 9], hash[10], hash[11],
|
|
|
|
hash[12], hash[13], hash[14], hash[15]
|
|
|
|
);
|
|
|
|
|
|
|
|
request[sizeof(request) - 1] = 0;
|
2016-05-09 23:44:59 +00:00
|
|
|
|
|
|
|
#ifdef CHEEVOS_LOG_URLS
|
|
|
|
RARCH_LOG("CHEEVOS url to get the game's id: %s\n", request);
|
|
|
|
#endif
|
2015-10-27 17:50:41 +00:00
|
|
|
|
2015-11-08 14:41:57 +00:00
|
|
|
if (!cheevos_http_get(&json, NULL, request, timeout))
|
2015-10-27 17:50:41 +00:00
|
|
|
{
|
2016-02-13 04:47:41 +00:00
|
|
|
res = cheevos_get_value(json, JSON_KEY_GAMEID,
|
|
|
|
game_id, sizeof(game_id));
|
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
free((void*)json);
|
|
|
|
|
|
|
|
if (!res)
|
|
|
|
{
|
|
|
|
RARCH_LOG("CHEEVOS got game id %s\n", game_id);
|
|
|
|
return strtoul(game_id, NULL, 10);
|
|
|
|
}
|
|
|
|
}
|
2015-10-14 03:12:01 +00:00
|
|
|
|
2016-05-09 23:44:59 +00:00
|
|
|
RARCH_ERR("CHEEVOS error getting game_id\n");
|
2015-10-27 17:50:41 +00:00
|
|
|
return 0;
|
2015-10-14 03:12:01 +00:00
|
|
|
}
|
|
|
|
|
2015-11-08 14:41:57 +00:00
|
|
|
static void cheevos_playing(void *payload)
|
2015-10-14 03:12:01 +00:00
|
|
|
{
|
2015-10-27 17:50:41 +00:00
|
|
|
char request[256];
|
|
|
|
const char* json;
|
2015-11-09 00:53:17 +00:00
|
|
|
unsigned game_id = (unsigned)(uintptr_t)payload;
|
|
|
|
settings_t *settings = config_get_ptr();
|
2015-10-27 17:50:41 +00:00
|
|
|
|
2015-11-05 00:41:12 +00:00
|
|
|
if (!cheevos_login(NULL))
|
2015-10-27 17:50:41 +00:00
|
|
|
{
|
|
|
|
snprintf(
|
|
|
|
request, sizeof(request),
|
|
|
|
"http://retroachievements.org/dorequest.php?r=postactivity&u=%s&t=%s&a=3&m=%u",
|
2015-11-08 17:03:56 +00:00
|
|
|
settings->cheevos.username, cheevos_locals.token, game_id
|
2015-10-27 17:50:41 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
request[sizeof(request) - 1] = 0;
|
2016-05-09 23:44:59 +00:00
|
|
|
|
|
|
|
#ifdef CHEEVOS_LOG_URLS
|
|
|
|
RARCH_LOG("CHEEVOS url to post the 'playing' activity: %s\n", request);
|
|
|
|
#endif
|
2015-10-27 17:50:41 +00:00
|
|
|
|
2015-11-08 14:41:57 +00:00
|
|
|
if (!cheevos_http_get(&json, NULL, request, NULL))
|
2015-10-27 17:50:41 +00:00
|
|
|
{
|
|
|
|
free((void*)json);
|
|
|
|
RARCH_LOG("CHEEVOS posted playing game %u activity\n", game_id);
|
2015-11-05 00:41:12 +00:00
|
|
|
return;
|
2015-10-27 17:50:41 +00:00
|
|
|
}
|
|
|
|
else
|
2015-11-08 03:34:44 +00:00
|
|
|
{
|
2016-05-09 23:44:59 +00:00
|
|
|
RARCH_ERR("CHEEVOS error posting playing game %u activity, will retry\n", game_id);
|
|
|
|
/* re-schedule */
|
2015-12-06 17:37:57 +00:00
|
|
|
rarch_main_async_job_add(cheevos_playing, (void*)(uintptr_t)game_id);
|
2015-11-08 03:34:44 +00:00
|
|
|
}
|
2015-10-27 17:50:41 +00:00
|
|
|
}
|
|
|
|
}
|
2015-10-14 03:12:01 +00:00
|
|
|
|
2016-05-09 23:44:59 +00:00
|
|
|
#ifdef CHEEVOS_DEACTIVATE
|
2015-11-08 14:41:57 +00:00
|
|
|
static int cheevos_deactivate__json_index(void *userdata, unsigned int index)
|
2015-10-27 17:50:41 +00:00
|
|
|
{
|
|
|
|
cheevos_deactivate_t *ud = (cheevos_deactivate_t*)userdata;
|
|
|
|
ud->is_element = 1;
|
|
|
|
return 0;
|
2015-10-14 03:12:01 +00:00
|
|
|
}
|
|
|
|
|
2016-02-03 15:09:11 +00:00
|
|
|
static int cheevos_deactivate__json_number(void *userdata,
|
|
|
|
const char *number, size_t length)
|
2015-10-27 17:50:41 +00:00
|
|
|
{
|
|
|
|
long id;
|
|
|
|
int found;
|
2016-02-03 15:09:11 +00:00
|
|
|
cheevo_t* cheevo = NULL;
|
|
|
|
const cheevo_t* end = NULL;
|
|
|
|
cheevos_deactivate_t *ud = (cheevos_deactivate_t*)userdata;
|
2015-10-27 17:50:41 +00:00
|
|
|
|
|
|
|
if (ud->is_element)
|
|
|
|
{
|
|
|
|
ud->is_element = 0;
|
2016-02-03 15:09:11 +00:00
|
|
|
id = strtol(number, NULL, 10);
|
|
|
|
found = 0;
|
|
|
|
cheevo = cheevos_locals.core.cheevos;
|
|
|
|
end = cheevo + cheevos_locals.core.count;
|
|
|
|
|
|
|
|
for (; cheevo < end; cheevo++)
|
2015-10-27 17:50:41 +00:00
|
|
|
{
|
|
|
|
if (cheevo->id == id)
|
|
|
|
{
|
|
|
|
cheevo->active = 0;
|
|
|
|
found = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
{
|
2016-02-03 15:09:11 +00:00
|
|
|
cheevo = cheevos_locals.unofficial.cheevos;
|
|
|
|
end = cheevo + cheevos_locals.unofficial.count;
|
|
|
|
|
|
|
|
for (; cheevo < end; cheevo++)
|
2015-10-27 17:50:41 +00:00
|
|
|
{
|
2016-05-09 23:44:59 +00:00
|
|
|
if (cheevo->id == id)
|
|
|
|
{
|
|
|
|
cheevo->active = 0;
|
|
|
|
break;
|
|
|
|
}
|
2015-10-27 17:50:41 +00:00
|
|
|
}
|
|
|
|
}
|
2016-05-09 23:44:59 +00:00
|
|
|
if (found)
|
|
|
|
RARCH_LOG("CHEEVOS deactivated unlocked cheevo %s\n", cheevo->title);
|
|
|
|
else
|
|
|
|
RARCH_ERR("CHEEVOS unknown cheevo to deactivate: %u\n", id);
|
2015-10-27 17:50:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2015-10-14 03:12:01 +00:00
|
|
|
}
|
2016-05-09 23:44:59 +00:00
|
|
|
#endif
|
2015-10-14 03:12:01 +00:00
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
static int cheevos_deactivate_unlocks(unsigned game_id, retro_time_t *timeout)
|
2015-10-14 03:12:01 +00:00
|
|
|
{
|
2015-10-27 17:50:41 +00:00
|
|
|
/* Only call this function after the cheevos have been loaded. */
|
|
|
|
|
2016-05-09 23:44:59 +00:00
|
|
|
#ifdef CHEEVOS_DEACTIVATE
|
2015-10-27 17:50:41 +00:00
|
|
|
static const jsonsax_handlers_t handlers =
|
|
|
|
{
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2015-11-08 14:41:57 +00:00
|
|
|
cheevos_deactivate__json_index,
|
2015-10-27 17:50:41 +00:00
|
|
|
NULL,
|
2015-11-08 14:41:57 +00:00
|
|
|
cheevos_deactivate__json_number,
|
2015-10-27 17:50:41 +00:00
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2016-02-13 05:24:49 +00:00
|
|
|
int res;
|
2015-10-27 17:50:41 +00:00
|
|
|
char request[256];
|
|
|
|
cheevos_deactivate_t ud;
|
2016-02-13 05:24:49 +00:00
|
|
|
const char* json = NULL;
|
2015-11-08 17:03:56 +00:00
|
|
|
settings_t *settings = config_get_ptr();
|
2015-10-27 17:50:41 +00:00
|
|
|
|
|
|
|
if (!cheevos_login(timeout))
|
|
|
|
{
|
|
|
|
snprintf(
|
|
|
|
request, sizeof(request),
|
|
|
|
"http://retroachievements.org/dorequest.php?r=unlocks&u=%s&t=%s&g=%u&h=0",
|
2015-11-08 17:03:56 +00:00
|
|
|
settings->cheevos.username, cheevos_locals.token, game_id
|
2015-10-27 17:50:41 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
request[sizeof(request) - 1] = 0;
|
2016-05-09 23:44:59 +00:00
|
|
|
|
|
|
|
#ifdef CHEEVOS_LOG_URLS
|
|
|
|
RARCH_LOG("CHEEVOS url to get the list of unlocked cheevos: %s\n", request);
|
|
|
|
#endif
|
2015-10-27 17:50:41 +00:00
|
|
|
|
2015-11-08 14:41:57 +00:00
|
|
|
if (!cheevos_http_get(&json, NULL, request, timeout))
|
2015-10-16 23:57:11 +00:00
|
|
|
{
|
2015-10-27 17:50:41 +00:00
|
|
|
ud.is_element = 0;
|
|
|
|
res = jsonsax_parse(json, &handlers, (void*)&ud);
|
|
|
|
free((void*)json);
|
|
|
|
|
|
|
|
if (res == JSONSAX_OK)
|
|
|
|
{
|
|
|
|
RARCH_LOG("CHEEVOS deactivated unlocked achievements\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2015-10-16 23:57:11 +00:00
|
|
|
}
|
2015-10-27 17:50:41 +00:00
|
|
|
}
|
|
|
|
|
2016-05-09 23:44:59 +00:00
|
|
|
RARCH_ERR("CHEEVOS error deactivating unlocked achievements\n");
|
2015-10-27 17:50:41 +00:00
|
|
|
return -1;
|
2016-05-09 23:44:59 +00:00
|
|
|
#else
|
|
|
|
RARCH_LOG("CHEEVOS cheevo deactivation is disabled\n");
|
|
|
|
return 0;
|
|
|
|
#endif
|
2015-10-14 03:12:01 +00:00
|
|
|
}
|
|
|
|
|
2015-11-03 02:54:26 +00:00
|
|
|
#define CHEEVOS_SIX_MB (6 * 1024 * 1024)
|
2015-10-27 17:50:41 +00:00
|
|
|
#define CHEEVOS_EIGHT_MB (8 * 1024 * 1024)
|
|
|
|
|
2015-11-08 14:41:57 +00:00
|
|
|
static INLINE unsigned cheevos_next_power_of_2(unsigned n)
|
2015-11-03 17:33:49 +00:00
|
|
|
{
|
|
|
|
n--;
|
|
|
|
|
|
|
|
n |= n >> 1;
|
|
|
|
n |= n >> 2;
|
|
|
|
n |= n >> 4;
|
|
|
|
n |= n >> 8;
|
|
|
|
n |= n >> 16;
|
|
|
|
|
|
|
|
return n + 1;
|
|
|
|
}
|
|
|
|
|
2016-02-03 15:09:11 +00:00
|
|
|
static size_t cheevos_eval_md5(
|
|
|
|
const struct retro_game_info *info,
|
|
|
|
MD5_CTX *ctx)
|
2015-10-27 17:50:41 +00:00
|
|
|
{
|
2015-11-02 16:17:34 +00:00
|
|
|
MD5_Init(ctx);
|
|
|
|
|
|
|
|
if (info->data)
|
|
|
|
{
|
|
|
|
MD5_Update(ctx, info->data, info->size);
|
|
|
|
return info->size;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-03-24 03:23:17 +00:00
|
|
|
RFILE *file = filestream_open(info->path, RFILE_MODE_READ, 0);
|
2015-11-02 16:17:34 +00:00
|
|
|
size_t size = 0;
|
|
|
|
|
|
|
|
if (!file)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
uint8_t buffer[4096];
|
2016-03-24 03:23:17 +00:00
|
|
|
ssize_t num_read = filestream_read(file,
|
2016-02-03 15:09:11 +00:00
|
|
|
(void*)buffer, sizeof(buffer));
|
2015-11-02 16:17:34 +00:00
|
|
|
|
|
|
|
if (num_read <= 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
MD5_Update(ctx, (void*)buffer, num_read);
|
|
|
|
size += num_read;
|
|
|
|
}
|
|
|
|
|
2016-03-24 03:23:17 +00:00
|
|
|
filestream_close(file);
|
2015-11-02 16:17:34 +00:00
|
|
|
return size;
|
|
|
|
}
|
|
|
|
}
|
2015-10-14 03:12:01 +00:00
|
|
|
|
2015-11-02 16:17:34 +00:00
|
|
|
static void cheevos_fill_md5(size_t size, size_t total, MD5_CTX *ctx)
|
|
|
|
{
|
|
|
|
char buffer[4096];
|
2016-02-13 05:24:49 +00:00
|
|
|
ssize_t fill = total - size;
|
2015-11-02 16:17:34 +00:00
|
|
|
|
|
|
|
memset((void*)buffer, 0, sizeof(buffer));
|
2015-10-14 03:12:01 +00:00
|
|
|
|
2015-11-04 03:05:46 +00:00
|
|
|
while (fill > 0)
|
2015-10-27 17:50:41 +00:00
|
|
|
{
|
2015-11-02 16:17:34 +00:00
|
|
|
ssize_t len = sizeof(buffer);
|
2015-10-14 23:52:25 +00:00
|
|
|
|
2015-11-02 16:17:34 +00:00
|
|
|
if (len > fill)
|
|
|
|
len = fill;
|
2015-10-27 17:50:41 +00:00
|
|
|
|
2015-11-02 16:17:34 +00:00
|
|
|
MD5_Update(ctx, (void*)buffer, len);
|
|
|
|
fill -= len;
|
|
|
|
}
|
|
|
|
}
|
2015-10-14 03:12:01 +00:00
|
|
|
|
2016-02-03 15:09:11 +00:00
|
|
|
static unsigned cheevos_find_game_id_generic(
|
|
|
|
const struct retro_game_info *info,
|
|
|
|
retro_time_t timeout)
|
2015-11-02 16:17:34 +00:00
|
|
|
{
|
|
|
|
MD5_CTX ctx;
|
|
|
|
uint8_t hash[16];
|
|
|
|
retro_time_t to;
|
|
|
|
size_t size;
|
|
|
|
|
|
|
|
size = cheevos_eval_md5(info, &ctx);
|
|
|
|
MD5_Final(hash, &ctx);
|
|
|
|
|
|
|
|
if (!size)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
to = timeout;
|
|
|
|
return cheevos_get_game_id(hash, &to);
|
|
|
|
}
|
2015-10-15 14:04:26 +00:00
|
|
|
|
2016-02-03 15:09:11 +00:00
|
|
|
static unsigned cheevos_find_game_id_snes(
|
|
|
|
const struct retro_game_info *info,
|
|
|
|
retro_time_t timeout)
|
2015-11-02 16:17:34 +00:00
|
|
|
{
|
|
|
|
MD5_CTX ctx;
|
|
|
|
uint8_t hash[16];
|
|
|
|
retro_time_t to;
|
|
|
|
size_t size;
|
|
|
|
|
|
|
|
size = cheevos_eval_md5(info, &ctx);
|
|
|
|
|
|
|
|
if (!size)
|
|
|
|
{
|
|
|
|
MD5_Final(hash, &ctx);
|
|
|
|
return 0;
|
2015-10-27 17:50:41 +00:00
|
|
|
}
|
2015-11-02 16:17:34 +00:00
|
|
|
|
|
|
|
cheevos_fill_md5(size, CHEEVOS_EIGHT_MB, &ctx);
|
|
|
|
MD5_Final(hash, &ctx);
|
|
|
|
|
|
|
|
to = timeout;
|
|
|
|
return cheevos_get_game_id(hash, &to);
|
|
|
|
}
|
2015-10-14 03:12:01 +00:00
|
|
|
|
2016-02-03 15:09:11 +00:00
|
|
|
static unsigned cheevos_find_game_id_genesis(
|
|
|
|
const struct retro_game_info *info, retro_time_t timeout)
|
2015-11-03 02:54:26 +00:00
|
|
|
{
|
|
|
|
MD5_CTX ctx;
|
|
|
|
uint8_t hash[16];
|
|
|
|
retro_time_t to;
|
|
|
|
size_t size;
|
|
|
|
|
|
|
|
size = cheevos_eval_md5(info, &ctx);
|
|
|
|
|
|
|
|
if (!size)
|
|
|
|
{
|
|
|
|
MD5_Final(hash, &ctx);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
cheevos_fill_md5(size, CHEEVOS_SIX_MB, &ctx);
|
|
|
|
MD5_Final(hash, &ctx);
|
|
|
|
|
|
|
|
to = timeout;
|
|
|
|
return cheevos_get_game_id(hash, &to);
|
|
|
|
}
|
|
|
|
|
2016-02-03 15:09:11 +00:00
|
|
|
static unsigned cheevos_find_game_id_nes(
|
|
|
|
const struct retro_game_info *info,
|
|
|
|
retro_time_t timeout)
|
2015-11-03 02:54:26 +00:00
|
|
|
{
|
2015-11-03 12:06:03 +00:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
uint8_t id[4]; /* NES^Z */
|
|
|
|
uint8_t rom_size;
|
|
|
|
uint8_t vrom_size;
|
|
|
|
uint8_t rom_type;
|
|
|
|
uint8_t rom_type2;
|
|
|
|
uint8_t reserve[8];
|
|
|
|
} header;
|
|
|
|
|
|
|
|
size_t rom_size;
|
|
|
|
MD5_CTX ctx;
|
|
|
|
uint8_t hash[16];
|
|
|
|
retro_time_t to;
|
|
|
|
|
|
|
|
if (info->data)
|
|
|
|
{
|
|
|
|
if (info->size < sizeof(header))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
memcpy((void*)&header, info->data, sizeof(header));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-03-24 03:23:17 +00:00
|
|
|
RFILE *file = filestream_open(info->path, RFILE_MODE_READ, 0);
|
2015-11-03 12:06:03 +00:00
|
|
|
ssize_t num_read;
|
|
|
|
|
|
|
|
if (!file)
|
|
|
|
return 0;
|
|
|
|
|
2016-03-24 03:23:17 +00:00
|
|
|
num_read = filestream_read(file, (void*)&header, sizeof(header));
|
|
|
|
filestream_close(file);
|
2015-11-03 12:06:03 +00:00
|
|
|
|
2015-11-10 01:46:44 +00:00
|
|
|
if (num_read < (ssize_t)sizeof(header))
|
2015-11-03 12:06:03 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-02-03 15:09:53 +00:00
|
|
|
if ( header.id[0] != 'N'
|
|
|
|
|| header.id[1] != 'E'
|
|
|
|
|| header.id[2] != 'S'
|
|
|
|
|| header.id[3] != 0x1a)
|
2015-11-03 12:06:03 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (header.rom_size)
|
2016-03-11 20:26:07 +00:00
|
|
|
rom_size = cheevos_next_power_of_2(header.rom_size);
|
2015-11-03 12:06:03 +00:00
|
|
|
else
|
2016-03-11 20:26:07 +00:00
|
|
|
rom_size = 256;
|
2015-11-03 12:06:03 +00:00
|
|
|
|
|
|
|
if (info->data)
|
|
|
|
{
|
|
|
|
if (rom_size + sizeof(header) > info->size)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
MD5_Init(&ctx);
|
2016-02-03 15:09:11 +00:00
|
|
|
MD5_Update(&ctx,
|
|
|
|
(void*)((char*)info->data + sizeof(header)), rom_size);
|
2015-11-03 12:06:03 +00:00
|
|
|
MD5_Final(hash, &ctx);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-03-20 04:24:05 +00:00
|
|
|
unsigned bytes;
|
|
|
|
ssize_t num_read;
|
|
|
|
int i, mapper_no;
|
|
|
|
int not_power2[] =
|
|
|
|
{
|
|
|
|
53, 198, 228
|
|
|
|
};
|
2016-03-24 03:09:25 +00:00
|
|
|
bool round = true;
|
2016-03-24 03:23:17 +00:00
|
|
|
RFILE *file = filestream_open(info->path, RFILE_MODE_READ, 0);
|
2016-03-11 20:26:07 +00:00
|
|
|
uint8_t * data = (uint8_t *) malloc(rom_size << 14);
|
2015-11-03 12:06:03 +00:00
|
|
|
|
2016-03-11 20:26:07 +00:00
|
|
|
if (!file || !data)
|
2015-11-03 12:06:03 +00:00
|
|
|
return 0;
|
2016-03-11 20:26:07 +00:00
|
|
|
|
|
|
|
/* from fceu core - need it for a correctly md5 sum */
|
|
|
|
memset(data, 0xFF, rom_size << 14);
|
|
|
|
|
|
|
|
/* from fceu core - compute size using the cart mapper */
|
2016-03-20 04:24:05 +00:00
|
|
|
mapper_no = (header.rom_type >> 4);
|
|
|
|
mapper_no |= (header.rom_type2 & 0xF0);
|
2015-11-03 12:06:03 +00:00
|
|
|
|
2016-03-11 20:26:07 +00:00
|
|
|
|
2016-03-20 04:24:05 +00:00
|
|
|
for (i = 0; i != sizeof(not_power2) / sizeof(not_power2[0]); ++i)
|
|
|
|
{
|
|
|
|
/* 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. */
|
|
|
|
if (not_power2[i] == mapper_no) {
|
2016-03-11 20:26:07 +00:00
|
|
|
round = false;
|
2015-11-03 12:06:03 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-11 20:26:07 +00:00
|
|
|
MD5_Init(&ctx);
|
2016-03-24 03:23:17 +00:00
|
|
|
filestream_seek(file, sizeof(header), SEEK_SET);
|
2016-03-11 20:26:07 +00:00
|
|
|
/* from fceu core - check if Trainer included in ROM data */
|
|
|
|
if (header.rom_type & 4)
|
2016-03-24 03:23:17 +00:00
|
|
|
filestream_seek(file, sizeof(header), SEEK_CUR);
|
2016-03-11 20:26:07 +00:00
|
|
|
|
2016-03-20 04:24:05 +00:00
|
|
|
bytes = (round) ? rom_size : header.rom_size;
|
2016-03-24 03:23:17 +00:00
|
|
|
num_read = filestream_read(file, (void*) data, 0x4000 * bytes );
|
|
|
|
filestream_close(file);
|
2016-03-11 20:26:07 +00:00
|
|
|
|
|
|
|
if (num_read <= 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
MD5_Update(&ctx, (void*) data, rom_size << 14);
|
|
|
|
MD5_Final(hash, &ctx);
|
2015-11-03 12:06:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
to = timeout;
|
|
|
|
return cheevos_get_game_id(hash, &to);
|
2015-11-03 02:54:26 +00:00
|
|
|
}
|
|
|
|
|
2016-05-07 22:15:04 +00:00
|
|
|
bool cheevos_load(const void *data)
|
2015-11-02 16:17:34 +00:00
|
|
|
{
|
2015-11-05 00:41:12 +00:00
|
|
|
static const uint32_t genesis_exts[] =
|
|
|
|
{
|
|
|
|
0x0b888feeU, /* mdx */
|
|
|
|
0x005978b6U, /* md */
|
|
|
|
0x0b88aa89U, /* smd */
|
|
|
|
0x0b88767fU, /* gen */
|
|
|
|
0x0b8861beU, /* bin */
|
|
|
|
0x0b886782U, /* cue */
|
|
|
|
0x0b8880d0U, /* iso */
|
|
|
|
0x0b88aa98U, /* sms */
|
|
|
|
0x005977f3U, /* gg */
|
|
|
|
0x0059797fU, /* sg */
|
|
|
|
0
|
2015-11-02 16:17:34 +00:00
|
|
|
};
|
|
|
|
|
2015-11-05 00:41:12 +00:00
|
|
|
static const uint32_t snes_exts[] =
|
|
|
|
{
|
|
|
|
0x0b88aa88U, /* smc */
|
|
|
|
0x0b8872bbU, /* fig */
|
|
|
|
0x0b88a9a1U, /* sfc */
|
|
|
|
0x0b887623U, /* gd3 */
|
|
|
|
0x0b887627U, /* gd7 */
|
|
|
|
0x0b886bf3U, /* dx2 */
|
|
|
|
0x0b886312U, /* bsx */
|
|
|
|
0x0b88abd2U, /* swc */
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
static cheevos_finder_t finders[] =
|
2015-11-03 17:33:49 +00:00
|
|
|
{
|
2015-11-05 00:41:12 +00:00
|
|
|
{cheevos_find_game_id_snes, "SNES (8Mb padding)", snes_exts},
|
|
|
|
{cheevos_find_game_id_genesis, "Genesis (6Mb padding)", genesis_exts},
|
|
|
|
{cheevos_find_game_id_nes, "NES (discards VROM)", NULL},
|
|
|
|
{cheevos_find_game_id_generic, "Generic (plain content)", NULL},
|
2015-11-03 17:33:49 +00:00
|
|
|
};
|
|
|
|
|
2015-11-05 00:41:12 +00:00
|
|
|
struct retro_system_info sysinfo;
|
2015-11-10 01:46:44 +00:00
|
|
|
unsigned i;
|
2016-02-13 04:47:41 +00:00
|
|
|
const char *json = NULL;
|
2015-11-09 00:53:17 +00:00
|
|
|
retro_time_t timeout = 5000000;
|
|
|
|
unsigned game_id = 0;
|
|
|
|
settings_t *settings = config_get_ptr();
|
2015-12-07 12:32:03 +00:00
|
|
|
const struct retro_game_info *info = (const struct retro_game_info*)data;
|
2015-11-02 16:17:34 +00:00
|
|
|
|
2015-11-03 16:28:18 +00:00
|
|
|
cheevos_locals.loaded = 0;
|
|
|
|
|
2016-05-13 01:03:18 +00:00
|
|
|
/* Just return OK if cheevos are disabled, the core doesn't support cheevos, or info is NULL. */
|
|
|
|
if (!settings->cheevos.enable || !cheevos_locals.core_supports || !info)
|
2016-02-13 05:06:51 +00:00
|
|
|
return true;
|
2015-11-03 16:28:18 +00:00
|
|
|
|
2016-05-13 01:03:18 +00:00
|
|
|
cheevos_locals.meminfo[0].id = RETRO_MEMORY_SYSTEM_RAM;
|
|
|
|
core_get_memory(&cheevos_locals.meminfo[0]);
|
2016-01-28 02:06:25 +00:00
|
|
|
|
2016-05-13 01:03:18 +00:00
|
|
|
cheevos_locals.meminfo[1].id = RETRO_MEMORY_SAVE_RAM;
|
|
|
|
core_get_memory(&cheevos_locals.meminfo[1]);
|
2016-01-28 02:06:25 +00:00
|
|
|
|
2016-05-13 01:03:18 +00:00
|
|
|
cheevos_locals.meminfo[2].id = RETRO_MEMORY_VIDEO_RAM;
|
|
|
|
core_get_memory(&cheevos_locals.meminfo[2]);
|
2016-01-28 02:06:25 +00:00
|
|
|
|
2016-05-13 01:03:18 +00:00
|
|
|
cheevos_locals.meminfo[3].id = RETRO_MEMORY_RTC;
|
|
|
|
core_get_memory(&cheevos_locals.meminfo[3]);
|
2015-11-03 16:28:18 +00:00
|
|
|
|
2015-11-05 00:41:12 +00:00
|
|
|
/* The the supported extensions as a hint to what method we should use. */
|
|
|
|
|
2016-05-07 23:33:57 +00:00
|
|
|
core_get_system_info(&sysinfo);
|
2015-11-02 16:17:34 +00:00
|
|
|
|
2015-11-06 01:14:50 +00:00
|
|
|
for (i = 0; i < sizeof(finders) / sizeof(finders[0]); i++)
|
2015-10-27 17:50:41 +00:00
|
|
|
{
|
2015-11-06 01:14:50 +00:00
|
|
|
if (finders[i].ext_hashes)
|
2015-10-27 17:50:41 +00:00
|
|
|
{
|
2015-11-06 01:14:50 +00:00
|
|
|
const char *ext = sysinfo.valid_extensions;
|
|
|
|
|
|
|
|
while (ext)
|
2015-10-27 17:50:41 +00:00
|
|
|
{
|
2015-11-06 01:14:50 +00:00
|
|
|
int j;
|
2016-02-13 05:24:49 +00:00
|
|
|
unsigned hash;
|
|
|
|
const char *end = strchr(ext, '|');
|
2015-11-06 01:14:50 +00:00
|
|
|
|
|
|
|
if (end)
|
|
|
|
{
|
|
|
|
hash = cheevos_djb2(ext, end - ext);
|
2015-11-06 15:34:34 +00:00
|
|
|
ext = end + 1;
|
2015-11-06 01:14:50 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hash = cheevos_djb2(ext, strlen(ext));
|
|
|
|
ext = NULL;
|
|
|
|
}
|
|
|
|
|
2015-11-05 00:41:12 +00:00
|
|
|
for (j = 0; finders[i].ext_hashes[j]; j++)
|
|
|
|
{
|
|
|
|
if (finders[i].ext_hashes[j] == hash)
|
|
|
|
{
|
|
|
|
RARCH_LOG("CHEEVOS testing %s\n", finders[i].name);
|
|
|
|
|
|
|
|
game_id = finders[i].finder(info, 5000000);
|
|
|
|
|
|
|
|
if (game_id)
|
|
|
|
goto found;
|
|
|
|
|
2015-11-06 01:14:50 +00:00
|
|
|
ext = NULL; /* force next finder */
|
2015-11-05 00:41:12 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-11-06 01:14:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof(finders) / sizeof(finders[0]); i++)
|
|
|
|
{
|
2016-02-13 04:47:41 +00:00
|
|
|
if (finders[i].ext_hashes)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
RARCH_LOG("CHEEVOS testing %s\n", finders[i].name);
|
|
|
|
|
|
|
|
game_id = finders[i].finder(info, 5000000);
|
|
|
|
|
|
|
|
if (game_id)
|
|
|
|
goto found;
|
2015-11-05 00:41:12 +00:00
|
|
|
}
|
|
|
|
|
2016-02-03 15:09:11 +00:00
|
|
|
runloop_msg_queue_push("This game doesn't feature achievements",
|
|
|
|
0, 5 * 60, false);
|
2016-05-09 23:44:59 +00:00
|
|
|
RARCH_LOG("CHEEVOS this game doesn't feature achievements\n");
|
2016-02-13 05:06:51 +00:00
|
|
|
return false;
|
2015-11-05 00:41:12 +00:00
|
|
|
|
|
|
|
found:
|
|
|
|
|
|
|
|
if (!cheevos_get_by_game_id(&json, game_id, &timeout))
|
|
|
|
{
|
|
|
|
if (!cheevos_parse(json))
|
|
|
|
{
|
|
|
|
cheevos_deactivate_unlocks(game_id, &timeout);
|
2015-10-27 17:50:41 +00:00
|
|
|
free((void*)json);
|
2015-11-05 00:41:12 +00:00
|
|
|
cheevos_locals.loaded = 1;
|
|
|
|
|
2015-12-06 17:37:57 +00:00
|
|
|
rarch_main_async_job_add(cheevos_playing, (void*)(uintptr_t)game_id);
|
2016-02-13 05:06:51 +00:00
|
|
|
return true;
|
2015-10-27 17:50:41 +00:00
|
|
|
}
|
2015-10-30 21:31:21 +00:00
|
|
|
|
2015-11-05 00:41:12 +00:00
|
|
|
free((void*)json);
|
2015-10-27 17:50:41 +00:00
|
|
|
}
|
|
|
|
|
2015-12-07 14:32:14 +00:00
|
|
|
runloop_msg_queue_push("Error loading achievements", 0, 5 * 60, false);
|
2016-05-09 23:44:59 +00:00
|
|
|
RARCH_ERR("CHEEVOS error loading achievements\n", 0, 5 * 60, false);
|
2016-02-13 05:06:51 +00:00
|
|
|
return false;
|
2015-10-14 03:12:01 +00:00
|
|
|
}
|
2015-11-08 15:19:54 +00:00
|
|
|
|
2016-05-07 22:15:04 +00:00
|
|
|
void cheevos_populate_menu(void *data)
|
2015-11-08 15:19:54 +00:00
|
|
|
{
|
2016-05-07 22:15:04 +00:00
|
|
|
#ifdef HAVE_MENU
|
2015-11-08 17:03:56 +00:00
|
|
|
unsigned i;
|
2015-12-07 13:53:33 +00:00
|
|
|
const cheevo_t *end = NULL;
|
|
|
|
cheevo_t *cheevo = NULL;
|
|
|
|
settings_t *settings = config_get_ptr();
|
|
|
|
menu_displaylist_info_t *info = (menu_displaylist_info_t*)data;
|
2015-11-08 15:19:54 +00:00
|
|
|
|
2016-04-11 03:49:39 +00:00
|
|
|
menu_entries_add(info->list, "Unlocked Achievements:",
|
2016-02-03 15:09:11 +00:00
|
|
|
"", MENU_SETTINGS_CHEEVOS_NONE, 0, 0);
|
2016-04-11 03:49:39 +00:00
|
|
|
menu_entries_add(info->list, "", "", MENU_SETTINGS_CHEEVOS_NONE, 0, 0);
|
2015-11-08 17:03:56 +00:00
|
|
|
|
|
|
|
cheevo = cheevos_locals.core.cheevos;
|
|
|
|
end = cheevos_locals.core.cheevos + cheevos_locals.core.count;
|
2015-11-08 15:19:54 +00:00
|
|
|
|
2015-11-08 17:03:56 +00:00
|
|
|
for (i = 0; cheevo < end; i++, cheevo++)
|
2015-11-08 15:19:54 +00:00
|
|
|
{
|
2015-11-08 15:51:14 +00:00
|
|
|
if (!cheevo->active)
|
2016-04-11 03:49:39 +00:00
|
|
|
menu_entries_add(info->list, cheevo->title,
|
2016-02-03 15:09:11 +00:00
|
|
|
cheevo->description, MENU_SETTINGS_CHEEVOS_START + i, 0, 0);
|
2015-11-08 15:19:54 +00:00
|
|
|
}
|
|
|
|
|
2015-11-08 17:03:56 +00:00
|
|
|
if (settings->cheevos.test_unofficial)
|
2015-11-08 15:19:54 +00:00
|
|
|
{
|
2015-11-08 17:03:56 +00:00
|
|
|
cheevo = cheevos_locals.unofficial.cheevos;
|
2016-02-03 15:09:11 +00:00
|
|
|
end = cheevos_locals.unofficial.cheevos
|
|
|
|
+ cheevos_locals.unofficial.count;
|
2015-11-08 17:03:56 +00:00
|
|
|
|
2015-11-08 18:42:23 +00:00
|
|
|
for (i = cheevos_locals.core.count; cheevo < end; i++, cheevo++)
|
2015-11-08 15:19:54 +00:00
|
|
|
{
|
2015-11-08 15:51:14 +00:00
|
|
|
if (!cheevo->active)
|
2016-04-11 03:49:39 +00:00
|
|
|
menu_entries_add(info->list, cheevo->title,
|
2016-02-03 15:09:11 +00:00
|
|
|
cheevo->description, MENU_SETTINGS_CHEEVOS_START + i, 0, 0);
|
2015-11-08 15:19:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-11 03:49:39 +00:00
|
|
|
menu_entries_add(info->list, "", "", MENU_SETTINGS_CHEEVOS_NONE, 0, 0);
|
|
|
|
menu_entries_add(info->list, "Locked Achievements:", "",
|
2016-02-13 04:47:41 +00:00
|
|
|
MENU_SETTINGS_CHEEVOS_NONE, 0, 0);
|
2016-04-11 03:49:39 +00:00
|
|
|
menu_entries_add(info->list, "", "", MENU_SETTINGS_CHEEVOS_NONE, 0, 0);
|
2015-11-08 17:03:56 +00:00
|
|
|
|
|
|
|
cheevo = cheevos_locals.core.cheevos;
|
2015-11-08 17:05:58 +00:00
|
|
|
end = cheevos_locals.core.cheevos + cheevos_locals.core.count;
|
2015-11-08 17:03:56 +00:00
|
|
|
|
|
|
|
for (i = 0; cheevo < end; i++, cheevo++)
|
2015-11-08 15:19:54 +00:00
|
|
|
{
|
2015-11-08 17:33:16 +00:00
|
|
|
if (cheevo->active)
|
2016-04-11 03:49:39 +00:00
|
|
|
menu_entries_add(info->list, cheevo->title,
|
2016-02-03 15:09:11 +00:00
|
|
|
cheevo->description, MENU_SETTINGS_CHEEVOS_START + i, 0, 0);
|
2015-11-08 15:19:54 +00:00
|
|
|
}
|
|
|
|
|
2015-11-08 17:03:56 +00:00
|
|
|
if (settings->cheevos.test_unofficial)
|
2015-11-08 15:19:54 +00:00
|
|
|
{
|
2015-11-08 17:03:56 +00:00
|
|
|
cheevo = cheevos_locals.unofficial.cheevos;
|
2016-02-03 15:09:11 +00:00
|
|
|
end = cheevos_locals.unofficial.cheevos
|
|
|
|
+ cheevos_locals.unofficial.count;
|
2015-11-08 17:03:56 +00:00
|
|
|
|
2015-11-08 18:42:23 +00:00
|
|
|
for (i = cheevos_locals.core.count; cheevo < end; i++, cheevo++)
|
2015-11-08 15:19:54 +00:00
|
|
|
{
|
2015-11-08 17:42:44 +00:00
|
|
|
if (cheevo->active)
|
2016-04-11 03:49:39 +00:00
|
|
|
menu_entries_add(info->list, cheevo->title,
|
2016-02-03 15:09:11 +00:00
|
|
|
cheevo->description, MENU_SETTINGS_CHEEVOS_START + i, 0, 0);
|
2015-11-08 15:19:54 +00:00
|
|
|
}
|
|
|
|
}
|
2015-12-06 16:55:27 +00:00
|
|
|
#endif
|
2016-05-07 22:15:04 +00:00
|
|
|
}
|
2015-11-08 18:42:23 +00:00
|
|
|
|
2016-05-07 22:15:04 +00:00
|
|
|
bool cheevos_get_description(cheevos_ctx_desc_t *desc)
|
2016-02-13 05:06:51 +00:00
|
|
|
{
|
2016-05-07 22:15:04 +00:00
|
|
|
cheevo_t *cheevos = cheevos_locals.core.cheevos;
|
2016-02-13 05:09:37 +00:00
|
|
|
|
2016-05-07 22:15:04 +00:00
|
|
|
if (desc->idx >= cheevos_locals.core.count)
|
2016-02-13 05:06:51 +00:00
|
|
|
{
|
2016-05-07 22:15:04 +00:00
|
|
|
cheevos = cheevos_locals.unofficial.cheevos;
|
|
|
|
desc->idx -= cheevos_locals.unofficial.count;
|
|
|
|
}
|
2016-02-13 05:30:39 +00:00
|
|
|
|
2016-05-07 22:15:04 +00:00
|
|
|
strncpy(desc->s, cheevos[desc->idx].description, desc->len);
|
|
|
|
desc->s[desc->len - 1] = 0;
|
2016-02-13 05:30:39 +00:00
|
|
|
|
2016-05-07 22:15:04 +00:00
|
|
|
return true;
|
|
|
|
}
|
2016-03-14 10:51:54 +00:00
|
|
|
|
2016-05-07 22:15:04 +00:00
|
|
|
bool cheevos_apply_cheats(bool *data_bool)
|
|
|
|
{
|
|
|
|
cheats_are_enabled = *data_bool;
|
|
|
|
cheats_were_enabled |= cheats_are_enabled;
|
2016-02-13 05:11:17 +00:00
|
|
|
|
2016-05-07 22:15:04 +00:00
|
|
|
return true;
|
|
|
|
}
|
2016-02-13 05:11:17 +00:00
|
|
|
|
2016-05-07 22:15:04 +00:00
|
|
|
bool cheevos_unload(void)
|
|
|
|
{
|
|
|
|
if (!cheevos_locals.loaded)
|
|
|
|
return false;
|
2016-03-14 11:53:56 +00:00
|
|
|
|
2016-05-07 22:15:04 +00:00
|
|
|
cheevos_free_cheevo_set(&cheevos_locals.core);
|
|
|
|
cheevos_free_cheevo_set(&cheevos_locals.unofficial);
|
2016-02-13 05:09:37 +00:00
|
|
|
|
2016-05-07 22:15:04 +00:00
|
|
|
cheevos_locals.loaded = 0;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2016-02-13 05:09:37 +00:00
|
|
|
|
2016-05-07 22:15:04 +00:00
|
|
|
bool cheevos_toggle_hardcore_mode(void)
|
|
|
|
{
|
|
|
|
settings_t *settings = config_get_ptr();
|
|
|
|
/* reset and deinit rewind to avoid cheat the score */
|
|
|
|
if (settings->cheevos.hardcore_mode_enable)
|
|
|
|
{
|
|
|
|
/* send reset core cmd to avoid any user savestate previusly loaded */
|
2016-05-09 18:51:53 +00:00
|
|
|
command_event(CMD_EVENT_RESET, NULL);
|
2016-05-07 22:15:04 +00:00
|
|
|
if (settings->rewind_enable)
|
2016-05-09 18:51:53 +00:00
|
|
|
command_event(CMD_EVENT_REWIND_DEINIT, NULL);
|
2016-02-13 05:09:37 +00:00
|
|
|
|
2016-05-07 22:15:04 +00:00
|
|
|
RARCH_LOG("%s\n", msg_hash_to_str(MSG_CHEEVOS_HARDCORE_MODE_ENABLE));
|
|
|
|
runloop_msg_queue_push(msg_hash_to_str(MSG_CHEEVOS_HARDCORE_MODE_ENABLE), 0, 3 * 60, true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (settings->rewind_enable)
|
2016-05-09 18:51:53 +00:00
|
|
|
command_event(CMD_EVENT_REWIND_INIT, NULL);
|
2016-05-07 22:15:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cheevos_test(void)
|
|
|
|
{
|
|
|
|
settings_t *settings = config_get_ptr();
|
|
|
|
if (!cheevos_locals.loaded)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!cheats_are_enabled && !cheats_were_enabled)
|
|
|
|
{
|
|
|
|
if (!settings->cheevos.enable)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
cheevos_test_cheevo_set(&cheevos_locals.core);
|
|
|
|
|
|
|
|
if (settings->cheevos.test_unofficial)
|
|
|
|
cheevos_test_cheevo_set(&cheevos_locals.unofficial);
|
2016-02-13 05:06:51 +00:00
|
|
|
}
|
2016-05-07 22:15:04 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cheevos_set_cheats(void)
|
|
|
|
{
|
|
|
|
cheats_were_enabled = cheats_are_enabled;
|
|
|
|
|
2016-02-13 05:06:51 +00:00
|
|
|
return true;
|
|
|
|
}
|
2016-05-13 01:03:18 +00:00
|
|
|
|
|
|
|
void cheevos_set_support_cheevos(bool state)
|
|
|
|
{
|
|
|
|
cheevos_locals.core_supports = state;
|
|
|
|
}
|