This commit is contained in:
twinaphex 2020-06-07 21:18:07 +02:00
parent d15942f6c8
commit 2baa3be2da
2 changed files with 137 additions and 149 deletions

View File

@ -104,6 +104,13 @@
/* Keep consistent with SERVER_PING_FREQUENCY from RAIntegration. */ /* Keep consistent with SERVER_PING_FREQUENCY from RAIntegration. */
#define CHEEVOS_PING_FREQUENCY 2 * 60 * 1000000 #define CHEEVOS_PING_FREQUENCY 2 * 60 * 1000000
enum rcheevos_async_io_type
{
CHEEVOS_ASYNC_RICHPRESENCE,
CHEEVOS_ASYNC_AWARD_ACHIEVEMENT,
CHEEVOS_ASYNC_SUBMIT_LBOARD
};
typedef struct typedef struct
{ {
rc_trigger_t* trigger; rc_trigger_t* trigger;
@ -128,13 +135,6 @@ typedef struct
retro_time_t last_update; retro_time_t last_update;
} rcheevos_richpresence_t; } rcheevos_richpresence_t;
enum rcheevos_async_io_type
{
CHEEVOS_ASYNC_RICHPRESENCE,
CHEEVOS_ASYNC_AWARD_ACHIEVEMENT,
CHEEVOS_ASYNC_SUBMIT_LBOARD
};
typedef struct rcheevos_async_io_request typedef struct rcheevos_async_io_request
{ {
int id; int id;
@ -204,6 +204,7 @@ static rcheevos_locals_t rcheevos_locals =
"N/A",/* hash */ "N/A",/* hash */
}; };
/* TODO/FIXME - public global variables */
bool rcheevos_loaded = false; bool rcheevos_loaded = false;
bool rcheevos_hardcore_active = false; bool rcheevos_hardcore_active = false;
bool rcheevos_hardcore_paused = false; bool rcheevos_hardcore_paused = false;
@ -225,12 +226,10 @@ Supporting functions.
*****************************************************************************/ *****************************************************************************/
#ifndef CHEEVOS_VERBOSE #ifndef CHEEVOS_VERBOSE
void rcheevos_log(const char *fmt, ...) void rcheevos_log(const char *fmt, ...)
{ {
(void)fmt; (void)fmt;
} }
#endif #endif
static void rcheevos_get_user_agent(char* buffer) static void rcheevos_get_user_agent(char* buffer)
@ -278,11 +277,9 @@ static void rcheevos_get_user_agent(char* buffer)
++scan; ++scan;
} }
else else
{
*ptr++ = *scan++; *ptr++ = *scan++;
} }
} }
}
if (system->library_version) if (system->library_version)
{ {
@ -297,12 +294,10 @@ static void rcheevos_get_user_agent(char* buffer)
++scan; ++scan;
} }
else else
{
*ptr++ = *scan++; *ptr++ = *scan++;
} }
} }
} }
}
*ptr = '\0'; *ptr = '\0';
} }
@ -395,10 +390,84 @@ static void rcheevos_log_post_url(const char* api, const char* url, const char*
#endif #endif
} }
static retro_time_t rcheevos_async_send_rich_presence(rcheevos_async_io_request* request); static unsigned rcheevos_peek(unsigned address, unsigned num_bytes, void* ud)
{
const uint8_t* data = rcheevos_fixup_find(&rcheevos_locals.fixups,
address, rcheevos_locals.patchdata.console_id);
unsigned value = 0;
if (data)
{
switch (num_bytes)
{
case 4:
value |= data[2] << 16 | data[3] << 24;
case 2:
value |= data[1] << 8;
case 1:
value |= data[0];
}
}
else
rcheevos_locals.invalid_peek_address = true;
return value;
}
static void rcheevos_async_award_achievement(rcheevos_async_io_request* request); static void rcheevos_async_award_achievement(rcheevos_async_io_request* request);
static void rcheevos_async_submit_lboard(rcheevos_async_io_request* request); static void rcheevos_async_submit_lboard(rcheevos_async_io_request* request);
static retro_time_t rcheevos_async_send_rich_presence(rcheevos_async_io_request* request)
{
settings_t *settings = config_get_ptr();
const char *cheevos_username = settings->arrays.cheevos_username;
bool cheevos_richpresence_enable = settings->bools.cheevos_richpresence_enable;
if (cheevos_richpresence_enable && rcheevos_locals.richpresence.richpresence)
{
rc_evaluate_richpresence(rcheevos_locals.richpresence.richpresence,
rcheevos_locals.richpresence.evaluation,
sizeof(rcheevos_locals.richpresence.evaluation), rcheevos_peek, NULL, NULL);
}
{
char url[256], post_data[1024];
int ret = rc_url_ping(url, sizeof(url), post_data, sizeof(post_data),
cheevos_username, rcheevos_locals.token, rcheevos_locals.patchdata.game_id,
rcheevos_locals.richpresence.evaluation);
if (ret < 0)
{
CHEEVOS_ERR(RCHEEVOS_TAG "buffer too small to create URL\n");
}
else
{
rcheevos_log_post_url("rc_url_ping", url, post_data);
rcheevos_get_user_agent(request->user_agent);
task_push_http_post_transfer_with_user_agent(url, post_data, true, "POST", request->user_agent, NULL, NULL);
}
}
#ifdef HAVE_DISCORD
if (rcheevos_locals.richpresence.evaluation[0])
{
if (settings->bools.discord_enable
&& discord_is_ready())
discord_update(DISCORD_PRESENCE_RETROACHIEVEMENTS, false);
}
#endif
/* Update rich presence every two minutes */
if (settings->bools.cheevos_richpresence_enable)
return cpu_features_get_time_usec() + CHEEVOS_PING_FREQUENCY;
/* Send ping every four minutes */
return cpu_features_get_time_usec() + CHEEVOS_PING_FREQUENCY * 2;
}
static void rcheevos_async_task_handler(retro_task_t* task) static void rcheevos_async_task_handler(retro_task_t* task)
{ {
rcheevos_async_io_request* request = (rcheevos_async_io_request*)task->user_data; rcheevos_async_io_request* request = (rcheevos_async_io_request*)task->user_data;
@ -406,14 +475,13 @@ static void rcheevos_async_task_handler(retro_task_t* task)
switch (request->type) switch (request->type)
{ {
case CHEEVOS_ASYNC_RICHPRESENCE: case CHEEVOS_ASYNC_RICHPRESENCE:
if (request->id == (int)rcheevos_locals.patchdata.game_id)
{
/* update the task to fire again in two minutes */ /* update the task to fire again in two minutes */
if (request->id == (int)rcheevos_locals.patchdata.game_id)
task->when = rcheevos_async_send_rich_presence(request); task->when = rcheevos_async_send_rich_presence(request);
}
else else
{ {
/* game changed; stop the recurring task - a new one will be scheduled for the next game */ /* game changed; stop the recurring task - a new one will
* be scheduled for the next game */
task_set_finished(task, 1); task_set_finished(task, 1);
free(request); free(request);
} }
@ -814,29 +882,6 @@ static void rcheevos_award(rcheevos_cheevo_t* cheevo, int mode)
} }
} }
static unsigned rcheevos_peek(unsigned address, unsigned num_bytes, void* ud)
{
const uint8_t* data = rcheevos_fixup_find(&rcheevos_locals.fixups,
address, rcheevos_locals.patchdata.console_id);
unsigned value = 0;
if (data)
{
switch (num_bytes)
{
case 4: value |= data[2] << 16 | data[3] << 24;
case 2: value |= data[1] << 8;
case 1: value |= data[0];
}
}
else
{
rcheevos_locals.invalid_peek_address = true;
}
return value;
}
static int rcheevos_has_indirect_memref(const rc_memref_value_t* memrefs) static int rcheevos_has_indirect_memref(const rc_memref_value_t* memrefs)
{ {
const rc_memref_value_t* memref = memrefs; const rc_memref_value_t* memref = memrefs;
@ -1043,55 +1088,6 @@ const char* rcheevos_get_richpresence(void)
return rcheevos_locals.richpresence.evaluation; return rcheevos_locals.richpresence.evaluation;
} }
static retro_time_t rcheevos_async_send_rich_presence(rcheevos_async_io_request* request)
{
settings_t *settings = config_get_ptr();
const char *cheevos_username = settings->arrays.cheevos_username;
bool cheevos_richpresence_enable = settings->bools.cheevos_richpresence_enable;
if (cheevos_richpresence_enable && rcheevos_locals.richpresence.richpresence)
{
rc_evaluate_richpresence(rcheevos_locals.richpresence.richpresence,
rcheevos_locals.richpresence.evaluation,
sizeof(rcheevos_locals.richpresence.evaluation), rcheevos_peek, NULL, NULL);
}
{
char url[256], post_data[1024];
int ret = rc_url_ping(url, sizeof(url), post_data, sizeof(post_data),
cheevos_username, rcheevos_locals.token, rcheevos_locals.patchdata.game_id,
rcheevos_locals.richpresence.evaluation);
if (ret < 0)
{
CHEEVOS_ERR(RCHEEVOS_TAG "buffer too small to create URL\n");
}
else
{
rcheevos_log_post_url("rc_url_ping", url, post_data);
rcheevos_get_user_agent(request->user_agent);
task_push_http_post_transfer_with_user_agent(url, post_data, true, "POST", request->user_agent, NULL, NULL);
}
}
#ifdef HAVE_DISCORD
if (rcheevos_locals.richpresence.evaluation[0])
{
if (settings->bools.discord_enable
&& discord_is_ready())
discord_update(DISCORD_PRESENCE_RETROACHIEVEMENTS, false);
}
#endif
/* Update rich presence every two minutes */
if (settings->bools.cheevos_richpresence_enable)
return cpu_features_get_time_usec() + CHEEVOS_PING_FREQUENCY;
/* Send ping every four minutes */
return cpu_features_get_time_usec() + CHEEVOS_PING_FREQUENCY * 2;
}
void rcheevos_reset_game(void) void rcheevos_reset_game(void)
{ {
unsigned i; unsigned i;
@ -1159,12 +1155,9 @@ void rcheevos_get_achievement_state(unsigned index, char *buffer, size_t buffer_
enum_idx = MENU_ENUM_LABEL_VALUE_CHEEVOS_UNLOCKED_ENTRY_HARDCORE; enum_idx = MENU_ENUM_LABEL_VALUE_CHEEVOS_UNLOCKED_ENTRY_HARDCORE;
else if (!hardcore && !(cheevo->active & RCHEEVOS_ACTIVE_SOFTCORE)) else if (!hardcore && !(cheevo->active & RCHEEVOS_ACTIVE_SOFTCORE))
enum_idx = MENU_ENUM_LABEL_VALUE_CHEEVOS_UNLOCKED_ENTRY; enum_idx = MENU_ENUM_LABEL_VALUE_CHEEVOS_UNLOCKED_ENTRY;
else else /* Use either "Locked" for core or "Unofficial" for unofficial as set above */
{
/* use either "Locked" for core or "Unofficial" for unofficial as set above */
check_measured = true; check_measured = true;
} }
}
strlcpy(buffer, msg_hash_to_str(enum_idx), buffer_size); strlcpy(buffer, msg_hash_to_str(enum_idx), buffer_size);
@ -1183,7 +1176,8 @@ void rcheevos_get_achievement_state(unsigned index, char *buffer, size_t buffer_
} }
} }
static void rcheevos_append_menu_achievement(menu_displaylist_info_t* info, size_t idx, rcheevos_cheevo_t* cheevo) static void rcheevos_append_menu_achievement(
menu_displaylist_info_t* info, size_t idx, rcheevos_cheevo_t* cheevo)
{ {
bool badge_grayscale; bool badge_grayscale;
@ -1196,16 +1190,11 @@ static void rcheevos_append_menu_achievement(menu_displaylist_info_t* info, size
/* unsupported */ /* unsupported */
badge_grayscale = true; badge_grayscale = true;
} }
else if (!(cheevo->active & RCHEEVOS_ACTIVE_HARDCORE) || !(cheevo->active & RCHEEVOS_ACTIVE_SOFTCORE)) else if (!(cheevo->active & RCHEEVOS_ACTIVE_HARDCORE) ||
{ !(cheevo->active & RCHEEVOS_ACTIVE_SOFTCORE))
/* unlocked */ badge_grayscale = false; /* unlocked */
badge_grayscale = false;
}
else else
{ badge_grayscale = true; /* locked */
/* locked */
badge_grayscale = true;
}
cheevos_set_menu_badge(idx, cheevo->info->badge, badge_grayscale); cheevos_set_menu_badge(idx, cheevo->info->badge, badge_grayscale);
} }
@ -1243,18 +1232,14 @@ void rcheevos_populate_menu(void* data)
cheevo = rcheevos_locals.core; cheevo = rcheevos_locals.core;
for (count = rcheevos_locals.patchdata.core_count; count > 0; count--) for (count = rcheevos_locals.patchdata.core_count; count > 0; count--)
{
rcheevos_append_menu_achievement(info, i++, cheevo++); rcheevos_append_menu_achievement(info, i++, cheevo++);
}
if (cheevos_test_unofficial) if (cheevos_test_unofficial)
{ {
cheevo = rcheevos_locals.unofficial; cheevo = rcheevos_locals.unofficial;
for (count = rcheevos_locals.patchdata.unofficial_count; count > 0; count--) for (count = rcheevos_locals.patchdata.unofficial_count; count > 0; count--)
{
rcheevos_append_menu_achievement(info, i++, cheevo++); rcheevos_append_menu_achievement(info, i++, cheevo++);
} }
}
if (i == 0) if (i == 0)
{ {
@ -1299,7 +1284,7 @@ bool rcheevos_get_description(rcheevos_ctx_desc_t* desc)
return true; return true;
} }
void rcheevos_pause_hardcore() void rcheevos_pause_hardcore(void)
{ {
rcheevos_hardcore_paused = true; rcheevos_hardcore_paused = true;
} }
@ -1325,8 +1310,7 @@ bool rcheevos_unload(void)
CHEEVOS_LOCK(rcheevos_locals.task_lock); CHEEVOS_LOCK(rcheevos_locals.task_lock);
running = rcheevos_locals.task != NULL; running = rcheevos_locals.task != NULL;
CHEEVOS_UNLOCK(rcheevos_locals.task_lock); CHEEVOS_UNLOCK(rcheevos_locals.task_lock);
} }while (running);
while (running);
#endif #endif
} }
@ -1396,7 +1380,8 @@ bool rcheevos_toggle_hardcore_mode(void)
command_event(CMD_EVENT_REWIND_DEINIT, NULL); command_event(CMD_EVENT_REWIND_DEINIT, NULL);
CHEEVOS_LOG("%s\n", msg); CHEEVOS_LOG("%s\n", msg);
runloop_msg_queue_push(msg, 0, 3 * 60, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); runloop_msg_queue_push(msg, 0, 3 * 60, true, NULL,
MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
} }
else else
{ {
@ -1447,7 +1432,7 @@ const char* rcheevos_get_hash(void)
static void rcheevos_unlock_cb(unsigned id, void* userdata) static void rcheevos_unlock_cb(unsigned id, void* userdata)
{ {
int i = 0; int i;
unsigned j = 0, count = 0; unsigned j = 0, count = 0;
rcheevos_cheevo_t* cheevo = NULL; rcheevos_cheevo_t* cheevo = NULL;
@ -1622,10 +1607,7 @@ static int rcheevos_prepare_hash_psx(rcheevos_coro_t* coro)
} }
} }
else else
{ exe_name = "PSX.EXE"; /* no SYSTEM.CNF, check for a PSX.EXE */
/* no SYSTEM.CNF, check for a PSX.EXE */
exe_name = "PSX.EXE";
}
if (!exe_name || !cdfs_open_file(&coro->cdfp, coro->track, exe_name)) if (!exe_name || !cdfs_open_file(&coro->cdfp, coro->track, exe_name))
{ {
@ -1671,7 +1653,7 @@ static int rcheevos_prepare_hash_psx(rcheevos_coro_t* coro)
cdfs_read_file(&coro->cdfp, (uint8_t*)coro->data + coro->len, to_read); cdfs_read_file(&coro->cdfp, (uint8_t*)coro->data + coro->len, to_read);
coro->len += to_read; coro->len += to_read;
}; }
success = 1; success = 1;
} }
@ -1700,8 +1682,14 @@ static int rcheevos_prepare_hash_nintendo_ds(rcheevos_coro_t* coro)
unsigned int hash_size, arm9_size, arm9_addr, arm7_size, arm7_addr, icon_addr; unsigned int hash_size, arm9_size, arm9_addr, arm7_size, arm7_addr, icon_addr;
int offset = 0; int offset = 0;
if (header[0] == 0x2E && header[1] == 0x00 && header[2] == 0x00 && header[3] == 0xEA && if ( header[0] == 0x2E &&
header[0xB0] == 0x44 && header[0xB1] == 0x46 && header[0xB2] == 0x96 && header[0xB3] == 0x00) header[1] == 0x00 &&
header[2] == 0x00 &&
header[3] == 0xEA &&
header[0xB0] == 0x44 &&
header[0xB1] == 0x46 &&
header[0xB2] == 0x96 &&
header[0xB3] == 0x00)
{ {
/* SuperCard header detected, ignore it */ /* SuperCard header detected, ignore it */
offset = 512; offset = 512;
@ -2043,11 +2031,10 @@ found:
if (!number_of_unsupported) if (!number_of_unsupported)
{ {
if (coro->settings->bools.cheevos_start_active) { if (coro->settings->bools.cheevos_start_active)
snprintf(msg, sizeof(msg), snprintf(msg, sizeof(msg),
"All %d achievements activated for this session.", "All %d achievements activated for this session.",
rcheevos_locals.patchdata.core_count); rcheevos_locals.patchdata.core_count);
}
else else
{ {
snprintf(msg, sizeof(msg), snprintf(msg, sizeof(msg),
@ -2057,13 +2044,13 @@ found:
} }
else else
{ {
if (coro->settings->bools.cheevos_start_active) { if (coro->settings->bools.cheevos_start_active)
snprintf(msg, sizeof(msg), snprintf(msg, sizeof(msg),
"All %d achievements activated for this session (%d unsupported).", "All %d achievements activated for this session (%d unsupported).",
rcheevos_locals.patchdata.core_count, rcheevos_locals.patchdata.core_count,
number_of_unsupported); number_of_unsupported);
} else
else{ {
snprintf(msg, sizeof(msg), snprintf(msg, sizeof(msg),
"You have %d of %d achievements unlocked (%d unsupported).", "You have %d of %d achievements unlocked (%d unsupported).",
number_of_unlocked - number_of_unsupported, number_of_unlocked - number_of_unsupported,

View File

@ -6476,7 +6476,8 @@ bool menu_shader_manager_set_preset(struct video_shader *shader,
* Used when a preset is directly loaded. * Used when a preset is directly loaded.
* No point in updating when the Preset was * No point in updating when the Preset was
* created from the menu itself. */ * created from the menu itself. */
if (!(conf = video_shader_read_preset(preset_path))) if ( !shader ||
!(conf = video_shader_read_preset(preset_path)))
{ {
ret = false; ret = false;
goto end; goto end;