Merge pull request #3037 from leiradel/cheevos

added all console ids; added fixup for pce; fixed mmap matching
This commit is contained in:
Andrés 2016-05-26 22:14:31 -05:00
commit bf04b798fe
7 changed files with 110 additions and 116 deletions

141
cheevos.c
View File

@ -19,7 +19,6 @@
#include <formats/jsonsax.h> #include <formats/jsonsax.h>
#include <streams/file_stream.h> #include <streams/file_stream.h>
#include <rhash.h> #include <rhash.h>
#include <rthreads/async_job.h>
#include <libretro.h> #include <libretro.h>
#include "cheevos.h" #include "cheevos.h"
@ -28,6 +27,7 @@
#include "libretro.h" #include "libretro.h"
#include "system.h" #include "system.h"
#include "network/net_http_special.h" #include "network/net_http_special.h"
#include "tasks/tasks_internal.h"
#include "configuration.h" #include "configuration.h"
#include "performance_counters.h" #include "performance_counters.h"
#include "msg_hash.h" #include "msg_hash.h"
@ -41,8 +41,8 @@
#include "verbosity.h" #include "verbosity.h"
/* Define this macro to deactivate awarded cheevos. */ /* Define this macro to prevent cheevos from being deactivated. */
#define CHEEVOS_DEACTIVATE #undef CHEEVOS_DONT_DEACTIVATE
/* Define this macro to log URLs (will log the user token). */ /* Define this macro to log URLs (will log the user token). */
#undef CHEEVOS_LOG_URLS #undef CHEEVOS_LOG_URLS
@ -50,6 +50,9 @@
/* Define this macro to dump all cheevos' addresses. */ /* Define this macro to dump all cheevos' addresses. */
#undef CHEEVOS_DUMP_ADDRS #undef CHEEVOS_DUMP_ADDRS
/* Define this macro to remove HTTP timeouts. */
#undef CHEEVOS_NO_TIMEOUT
#define JSON_KEY_GAMEID 0xb4960eecU #define JSON_KEY_GAMEID 0xb4960eecU
#define JSON_KEY_ACHIEVEMENTS 0x69749ae1U #define JSON_KEY_ACHIEVEMENTS 0x69749ae1U
#define JSON_KEY_ID 0x005973f2U #define JSON_KEY_ID 0x005973f2U
@ -67,9 +70,17 @@
enum enum
{ {
CHEEVOS_CONSOLE_MEGA_DRIVE = 1,
CHEEVOS_CONSOLE_NINTENDO_64 = 2,
CHEEVOS_CONSOLE_SUPER_NINTENDO = 3,
CHEEVOS_CONSOLE_GAMEBOY = 4, CHEEVOS_CONSOLE_GAMEBOY = 4,
CHEEVOS_CONSOLE_GAMEBOY_ADVANCED = 5, CHEEVOS_CONSOLE_GAMEBOY_ADVANCE = 5,
CHEEVOS_CONSOLE_GAMEBOY_COLOR = 6, CHEEVOS_CONSOLE_GAMEBOY_COLOR = 6,
CHEEVOS_CONSOLE_NINTENDO = 7,
CHEEVOS_CONSOLE_PC_ENGINE = 8,
CHEEVOS_CONSOLE_SEGA_CD = 9,
CHEEVOS_CONSOLE_SEGA_32X = 10,
CHEEVOS_CONSOLE_MASTER_SYSTEM = 11,
}; };
enum enum
@ -268,10 +279,6 @@ static cheevos_locals_t cheevos_locals =
static int cheats_are_enabled = 0; static int cheats_are_enabled = 0;
static int cheats_were_enabled = 0; static int cheats_were_enabled = 0;
/* forward declaration */
int retroarch_async_job_add(async_task_t task, void *payload);
/***************************************************************************** /*****************************************************************************
Supporting functions. Supporting functions.
*****************************************************************************/ *****************************************************************************/
@ -292,7 +299,12 @@ static int cheevos_http_get(const char **result, size_t *size,
const char *url, retro_time_t *timeout) const char *url, retro_time_t *timeout)
{ {
const char *msg = NULL; const char *msg = NULL;
#ifdef CHEEVOS_NO_TIMEOUT
int ret = net_http_get(result, size, url, NULL);
#else
int ret = net_http_get(result, size, url, timeout); int ret = net_http_get(result, size, url, timeout);
#endif
switch (ret) switch (ret)
{ {
@ -645,8 +657,7 @@ static void cheevos_parse_var(cheevos_var_t *var, const char **memaddr)
const struct retro_memory_descriptor *desc; const struct retro_memory_descriptor *desc;
const struct retro_memory_descriptor *end; const struct retro_memory_descriptor *end;
#if 0 if (cheevos_locals.console_id == CHEEVOS_CONSOLE_GAMEBOY_ADVANCE)
if (cheevos_locals.console_id == CHEEVOS_CONSOLE_GAMEBOY_ADVANCED)
{ {
/* Patch the address to correctly map it to the mmaps */ /* Patch the address to correctly map it to the mmaps */
if (var->value < 0x8000) if (var->value < 0x8000)
@ -660,14 +671,17 @@ static void cheevos_parse_var(cheevos_var_t *var, const char **memaddr)
var->value += 0x2000000 - 0x8000; var->value += 0x2000000 - 0x8000;
} }
} }
#endif else if (cheevos_locals.console_id == CHEEVOS_CONSOLE_PC_ENGINE)
{
var->value += 0x1f0000;
}
desc = system->mmaps.descriptors; desc = system->mmaps.descriptors;
end = desc + system->mmaps.num_descriptors; end = desc + system->mmaps.num_descriptors;
for (; desc < end; desc++) for (; desc < end; desc++)
{ {
if (var->value >= desc->start && var->value < (desc->start + desc->len)) if ((var->value & desc->select) == desc->start)
{ {
var->bank_id = desc - system->mmaps.descriptors; var->bank_id = desc - system->mmaps.descriptors;
var->value = var->value - desc->start + desc->offset; var->value = var->value - desc->start + desc->offset;
@ -1414,38 +1428,39 @@ static int cheevos_login(retro_time_t *timeout)
return -1; return -1;
} }
static void cheevos_unlocker(void *payload) static void cheevos_make_unlock_url(const cheevo_t *cheevo, char* url, size_t url_size)
{ {
char request[256];
const char *result;
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
unsigned cheevo_id = (unsigned)(uintptr_t)payload;
if (!cheevos_login(NULL))
{
snprintf( snprintf(
request, sizeof(request), url, url_size,
"http://retroachievements.org/dorequest.php?r=awardachievement&u=%s&t=%s&a=%u&h=%d", "http://retroachievements.org/dorequest.php?r=awardachievement&u=%s&t=%s&a=%u&h=%d",
settings->cheevos.username, cheevos_locals.token, cheevo_id, settings->cheevos.hardcore_mode_enable settings->cheevos.username, cheevos_locals.token, cheevo->id, settings->cheevos.hardcore_mode_enable
); );
request[sizeof(request) - 1] = 0; url[url_size - 1] = 0;
#ifdef CHEEVOS_LOG_URLS #ifdef CHEEVOS_LOG_URLS
RARCH_LOG("CHEEVOS url to award the cheevo: %s\n", request); RARCH_LOG("CHEEVOS url to award the cheevo: %s\n", url);
#endif #endif
}
if (!cheevos_http_get(&result, NULL, request, NULL)) static void cheevos_unlocked(void *task_data, void *user_data, const char *error)
{
cheevo_t *cheevo = (cheevo_t *)user_data;
if (error == NULL)
{ {
RARCH_LOG("CHEEVOS awarded achievement %u: %s\n", cheevo_id, result); RARCH_LOG("CHEEVOS awarded achievement %u\n", cheevo->id);
free((void*)result);
} }
else else
{ {
RARCH_ERR("CHEEVOS error awarding achievement %u, will retry...\n", cheevo_id); char url[256];
/* re-schedule */
retroarch_async_job_add(cheevos_unlocker, (void*)(uintptr_t)cheevo_id); RARCH_ERR("CHEEVOS error awarding achievement %u, retrying\n", cheevo->id);
}
cheevos_make_unlock_url(cheevo, url, sizeof(url));
rarch_task_push_http_transfer(url, true, NULL, cheevos_unlocked, cheevo);
} }
} }
@ -1458,15 +1473,18 @@ static void cheevos_test_cheevo_set(const cheevoset_t *set)
{ {
if (cheevo->active && cheevos_test_cheevo(cheevo)) if (cheevo->active && cheevos_test_cheevo(cheevo))
{ {
RARCH_LOG("CHEEVOS awarding cheevo %s (%s)\n", cheevo->title, cheevo->description); settings_t *settings = config_get_ptr();
char url[256];
cheevo->active = 0;
RARCH_LOG("CHEEVOS awarding cheevo %u: %s (%s)\n", cheevo->id, cheevo->title, cheevo->description);
runloop_msg_queue_push(cheevo->title, 0, 3 * 60, false); runloop_msg_queue_push(cheevo->title, 0, 3 * 60, false);
runloop_msg_queue_push(cheevo->description, 0, 5 * 60, false); runloop_msg_queue_push(cheevo->description, 0, 5 * 60, false);
retroarch_async_job_add(cheevos_unlocker, cheevos_make_unlock_url(cheevo, url, sizeof(url));
(void*)(uintptr_t)cheevo->id); rarch_task_push_http_transfer(url, true, NULL, cheevos_unlocked, cheevo);
cheevo->active = 0;
} }
} }
} }
@ -1588,43 +1606,43 @@ static unsigned cheevos_get_game_id(unsigned char *hash, retro_time_t *timeout)
return 0; return 0;
} }
static void cheevos_playing(void *payload) static void cheevos_make_playing_url(unsigned game_id, char* url, size_t url_size)
{ {
char request[256];
const char* json;
unsigned game_id = (unsigned)(uintptr_t)payload;
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
if (!cheevos_login(NULL))
{
snprintf( snprintf(
request, sizeof(request), url, url_size,
"http://retroachievements.org/dorequest.php?r=postactivity&u=%s&t=%s&a=3&m=%u", "http://retroachievements.org/dorequest.php?r=postactivity&u=%s&t=%s&a=3&m=%u",
settings->cheevos.username, cheevos_locals.token, game_id settings->cheevos.username, cheevos_locals.token, game_id
); );
request[sizeof(request) - 1] = 0; url[url_size - 1] = 0;
#ifdef CHEEVOS_LOG_URLS #ifdef CHEEVOS_LOG_URLS
RARCH_LOG("CHEEVOS url to post the 'playing' activity: %s\n", request); RARCH_LOG("CHEEVOS url to post the 'playing' activity: %s\n", url);
#endif #endif
}
if (!cheevos_http_get(&json, NULL, request, NULL)) static void cheevos_playing(void *task_data, void *user_data, const char *error)
{
unsigned game_id = (unsigned)(uintptr_t)user_data;
if (error == NULL)
{ {
free((void*)json);
RARCH_LOG("CHEEVOS posted playing game %u activity\n", game_id); RARCH_LOG("CHEEVOS posted playing game %u activity\n", game_id);
return;
} }
else else
{ {
char url[256];
RARCH_ERR("CHEEVOS error posting playing game %u activity, will retry\n", game_id); RARCH_ERR("CHEEVOS error posting playing game %u activity, will retry\n", game_id);
/* re-schedule */
retroarch_async_job_add(cheevos_playing, (void*)(uintptr_t)game_id); cheevos_make_playing_url(game_id, url, sizeof(url));
} rarch_task_push_http_transfer(url, true, NULL, cheevos_playing, (void*)(uintptr_t)game_id);
} }
} }
#ifdef CHEEVOS_DEACTIVATE #ifndef CHEEVOS_DONT_DEACTIVATE
static int cheevos_deactivate__json_index(void *userdata, unsigned int index) static int cheevos_deactivate__json_index(void *userdata, unsigned int index)
{ {
cheevos_deactivate_t *ud = (cheevos_deactivate_t*)userdata; cheevos_deactivate_t *ud = (cheevos_deactivate_t*)userdata;
@ -1687,7 +1705,7 @@ static int cheevos_deactivate_unlocks(unsigned game_id, retro_time_t *timeout)
{ {
/* Only call this function after the cheevos have been loaded. */ /* Only call this function after the cheevos have been loaded. */
#ifdef CHEEVOS_DEACTIVATE #ifndef CHEEVOS_DONT_DEACTIVATE
static const jsonsax_handlers_t handlers = static const jsonsax_handlers_t handlers =
{ {
NULL, NULL,
@ -1956,21 +1974,12 @@ static unsigned cheevos_find_game_id_nes(
53, 198, 228 53, 198, 228
}; };
bool round = true; bool round = true;
RFILE *file = NULL; RFILE *file = filestream_open(info->path, RFILE_MODE_READ, 0);
uint8_t * data = (uint8_t *) malloc(rom_size << 14); uint8_t * data = (uint8_t *) malloc(rom_size << 14);
if (!data) if (!file || !data)
return 0; return 0;
file = filestream_open(info->path, RFILE_MODE_READ, 0);
if (!file)
{
free(data);
filestream_close(file);
return 0;
}
/* from fceu core - need it for a correctly md5 sum */ /* from fceu core - need it for a correctly md5 sum */
memset(data, 0xFF, rom_size << 14); memset(data, 0xFF, rom_size << 14);
@ -1978,6 +1987,7 @@ static unsigned cheevos_find_game_id_nes(
mapper_no = (header.rom_type >> 4); mapper_no = (header.rom_type >> 4);
mapper_no |= (header.rom_type2 & 0xF0); mapper_no |= (header.rom_type2 & 0xF0);
for (i = 0; i != sizeof(not_power2) / sizeof(not_power2[0]); ++i) 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 /* for games not to the power of 2, so we just read enough
@ -1985,8 +1995,7 @@ static unsigned cheevos_find_game_id_nes(
* since PRGCartMapping wants ROM_size to be 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 * so instead if not to power of 2, we just use head.ROM_size when
* we use FCEU_read. */ * we use FCEU_read. */
if (not_power2[i] == mapper_no) if (not_power2[i] == mapper_no) {
{
round = false; round = false;
break; break;
} }
@ -2060,6 +2069,7 @@ bool cheevos_load(const void *data)
const char *json = NULL; const char *json = NULL;
retro_time_t timeout = 5000000; retro_time_t timeout = 5000000;
unsigned game_id = 0; unsigned game_id = 0;
char url[256];
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
const struct retro_game_info *info = (const struct retro_game_info*)data; const struct retro_game_info *info = (const struct retro_game_info*)data;
@ -2155,7 +2165,8 @@ bool cheevos_load(const void *data)
free((void*)json); free((void*)json);
cheevos_locals.loaded = 1; cheevos_locals.loaded = 1;
retroarch_async_job_add(cheevos_playing, (void*)(uintptr_t)game_id); cheevos_make_playing_url(game_id, url, sizeof(url));
rarch_task_push_http_transfer(url, true, NULL, cheevos_playing, (void*)(uintptr_t)game_id);
return true; return true;
} }

View File

@ -135,6 +135,9 @@ struct retro_task
* to signal the task *must* end. */ * to signal the task *must* end. */
bool cancelled; bool cancelled;
/* if true no OSD messages will be displayed. */
bool mute;
/* created by the handler, destroyed by the user */ /* created by the handler, destroyed by the user */
void *task_data; void *task_data;

View File

@ -1515,7 +1515,7 @@ static int action_ok_download_generic(const char *path,
transf->type_hash = menu_hash_calculate(type_msg); transf->type_hash = menu_hash_calculate(type_msg);
strlcpy(transf->path, path, sizeof(transf->path)); strlcpy(transf->path, path, sizeof(transf->path));
rarch_task_push_http_transfer(s3, type_msg, cb_generic_download, transf); rarch_task_push_http_transfer(s3, false, type_msg, cb_generic_download, transf);
#endif #endif
return 0; return 0;
} }
@ -1777,7 +1777,7 @@ static int generic_action_ok_network(const char *path,
#endif #endif
} }
rarch_task_push_http_transfer(url_path, url_label, callback, NULL); rarch_task_push_http_transfer(url_path, false, url_label, callback, NULL);
return generic_action_ok_displaylist_push(path, return generic_action_ok_displaylist_push(path,
label, type, idx, entry_idx, type_id2); label, type, idx, entry_idx, type_id2);

View File

@ -26,9 +26,6 @@
#include <boolean.h> #include <boolean.h>
#include <string/stdstring.h> #include <string/stdstring.h>
#include <lists/string_list.h> #include <lists/string_list.h>
#ifdef HAVE_THREADS
#include <rthreads/async_job.h>
#endif
#ifdef _WIN32 #ifdef _WIN32
#ifdef _XBOX #ifdef _XBOX
@ -115,10 +112,6 @@ static char current_savefile_dir[PATH_MAX_LENGTH];
static char error_string[PATH_MAX_LENGTH]; static char error_string[PATH_MAX_LENGTH];
static jmp_buf error_sjlj_context; static jmp_buf error_sjlj_context;
#ifdef HAVE_THREADS
static async_job_t *async_jobs;
#endif
#define _PSUPP(var, name, desc) printf(" %s:\n\t\t%s: %s\n", name, desc, _##var##_supp ? "yes" : "no") #define _PSUPP(var, name, desc) printf(" %s:\n\t\t%s: %s\n", name, desc, _##var##_supp ? "yes" : "no")
static void retroarch_print_features(void) static void retroarch_print_features(void)
@ -178,13 +171,6 @@ static void retroarch_print_features(void)
} }
#undef _PSUPP #undef _PSUPP
#ifdef HAVE_THREADS
int retroarch_async_job_add(async_task_t task, void *payload)
{
return async_job_add(async_jobs, task, payload);
}
#endif
static void retroarch_print_version(void) static void retroarch_print_version(void)
{ {
char str[PATH_MAX_LENGTH] = {0}; char str[PATH_MAX_LENGTH] = {0};
@ -1462,10 +1448,6 @@ bool rarch_ctl(enum rarch_ctl_state state, void *data)
command_event(CMD_EVENT_SAVEFILES_DEINIT, NULL); command_event(CMD_EVENT_SAVEFILES_DEINIT, NULL);
rarch_ctl(RARCH_CTL_UNSET_INITED, NULL); rarch_ctl(RARCH_CTL_UNSET_INITED, NULL);
#ifdef HAVE_THREADS
async_job_free(async_jobs);
async_jobs = NULL;
#endif
break; break;
case RARCH_CTL_INIT: case RARCH_CTL_INIT:
rarch_ctl(RARCH_CTL_DEINIT, NULL); rarch_ctl(RARCH_CTL_DEINIT, NULL);
@ -1476,9 +1458,6 @@ bool rarch_ctl(enum rarch_ctl_state state, void *data)
settings->input.libretro_device[i] = RETRO_DEVICE_JOYPAD; settings->input.libretro_device[i] = RETRO_DEVICE_JOYPAD;
} }
runloop_ctl(RUNLOOP_CTL_MSG_QUEUE_INIT, NULL); runloop_ctl(RUNLOOP_CTL_MSG_QUEUE_INIT, NULL);
#ifdef HAVE_THREADS
async_jobs = async_job_new();
#endif
break; break;
case RARCH_CTL_SET_PATHS_REDIRECT: case RARCH_CTL_SET_PATHS_REDIRECT:
if(settings->sort_savestates_enable || settings->sort_savefiles_enable) if(settings->sort_savestates_enable || settings->sort_savefiles_enable)

View File

@ -232,7 +232,7 @@ static bool rarch_task_http_retriever(retro_task_t *task, void *data)
return true; return true;
} }
void *rarch_task_push_http_transfer(const char *url, const char *type, void *rarch_task_push_http_transfer(const char *url, bool mute, const char *type,
retro_task_callback_t cb, void *user_data) retro_task_callback_t cb, void *user_data)
{ {
char tmp[PATH_MAX_LENGTH]; char tmp[PATH_MAX_LENGTH];
@ -280,6 +280,7 @@ void *rarch_task_push_http_transfer(const char *url, const char *type,
t->handler = rarch_task_http_transfer_handler; t->handler = rarch_task_http_transfer_handler;
t->state = http; t->state = http;
t->mute = mute;
t->callback = cb; t->callback = cb;
t->user_data = user_data; t->user_data = user_data;
t->progress = -1; t->progress = -1;

View File

@ -37,7 +37,7 @@ static void task_queue_msg_push(unsigned prio, unsigned duration,
void task_queue_push_progress(retro_task_t *task) void task_queue_push_progress(retro_task_t *task)
{ {
if (task->title) if (task->title && !task->mute)
{ {
if (task->finished) if (task->finished)
{ {

View File

@ -69,7 +69,7 @@ typedef struct nbio_handle
} nbio_handle_t; } nbio_handle_t;
#ifdef HAVE_NETWORKING #ifdef HAVE_NETWORKING
void *rarch_task_push_http_transfer(const char *url, const char *type, void *rarch_task_push_http_transfer(const char *url, bool mute, const char *type,
retro_task_callback_t cb, void *userdata); retro_task_callback_t cb, void *userdata);
task_retriever_info_t *http_task_get_transfer_list(void); task_retriever_info_t *http_task_get_transfer_list(void);