Skip to content

Commit

Permalink
support raintegration
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamiras committed Feb 4, 2024
1 parent fb63c79 commit cf722a5
Show file tree
Hide file tree
Showing 7 changed files with 211 additions and 47 deletions.
122 changes: 122 additions & 0 deletions cheevos/cheevos.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <net/net_http.h>
#include <libretro.h>
#include <lrc_hash.h>
#include <gfx/common/win32_common.h>

#ifdef HAVE_CONFIG_H
#include "../config.h"
Expand Down Expand Up @@ -70,9 +71,11 @@
#include "../runtime_file.h"
#include "../core.h"
#include "../core_option_manager.h"
#include "../version.h"

#include "../tasks/tasks_internal.h"

#include "../deps/rcheevos/include/rc_client_raintegration.h"
#include "../deps/rcheevos/include/rc_runtime.h"
#include "../deps/rcheevos/include/rc_runtime_types.h"
#include "../deps/rcheevos/include/rc_hash.h"
Expand Down Expand Up @@ -3103,6 +3106,104 @@ bool rcheevos_load_aborted(void)

#endif /* HAVE_RC_CLIENT */

#ifdef RC_CLIENT_SUPPORTS_RAINTEGRATION

static void rc_client_raintegration_hardcore_changed(rc_client_t* client)
{
const bool hardcore_enabled = rc_client_get_hardcore_enabled(client);
if (hardcore_enabled)
{
if (rcheevos_locals.hardcore_allowed)
{
rcheevos_validate_config_settings();
if (rcheevos_locals.hardcore_allowed)
{
cheat_manager_apply_cheats();
if (rcheevos_locals.hardcore_allowed)
rcheevos_enforce_hardcore_settings();
}
}

if (!rcheevos_locals.hardcore_allowed)
{
/* local setting prevented hardcore enablement - message should
* have been displayed */
rc_client_set_hardcore_enabled(client, false);
return;
}
}

{
settings_t* settings = config_get_ptr();
settings->bools.cheevos_hardcore_mode_enable = hardcore_enabled;

bool rewind_enable = settings->bools.rewind_enable;
if (rewind_enable)
{
const enum event_command cmd = hardcore_enabled ?
CMD_EVENT_REWIND_DEINIT : CMD_EVENT_REWIND_INIT;

#ifdef HAVE_THREADS
if (!task_is_on_main_thread())
{
/* have to "schedule" this.
* CMD_EVENT_REWIND_DEINIT should
* only be called on the main thread */
rcheevos_locals.queued_command = cmd;
}
else
#endif
command_event(cmd, NULL);
}
}
}

static void rcheevos_raintegration_event_handler(const rc_client_raintegration_event_t* event, rc_client_t* client)
{
switch (event->type)
{
case RC_CLIENT_RAINTEGRATION_EVENT_MENUITEM_CHECKED_CHANGED:
rc_client_raintegration_update_menu_item(client, event->menu_item);
break;
case RC_CLIENT_RAINTEGRATION_EVENT_PAUSE:
command_event(CMD_EVENT_PAUSE, NULL); /* pause the game */
break;
case RC_CLIENT_RAINTEGRATION_EVENT_HARDCORE_CHANGED:
rc_client_raintegration_hardcore_changed(client);
break;
default:
#ifndef NDEBUG
CHEEVOS_LOG(RCHEEVOS_TAG "Unsupported raintegration event %u\n", event->type);
#endif
break;
}
}

static void rcheevos_load_raintegration_callback(int result,
const char* error_message, rc_client_t* client, void* userdata)
{
struct retro_game_info* info = (struct retro_game_info*)userdata;

rc_client_raintegration_set_event_handler(client, rcheevos_raintegration_event_handler);

rcheevos_load(info);

if (info->path)
free((void*)info->path);
if (info->data)
free((void*)info->data);
free(info);

/* the raintegration initialization process may start before the window is created.
* ensure the handle is correct */
rc_client_raintegration_update_main_window_handle(rcheevos_locals.client, win32_get_window());

/* initialization has finished, the menu can be populated now */
rcheevos_rebuild_integration_menu();
}

#endif

bool rcheevos_load(const void *data)
{
const struct retro_game_info *info = (const struct retro_game_info*)data;
Expand Down Expand Up @@ -3183,6 +3284,27 @@ bool rcheevos_load(const void *data)
}

rcheevos_client_download_placeholder_badge();

#ifdef RC_CLIENT_SUPPORTS_RAINTEGRATION
{
struct retro_game_info* info_copy = (struct retro_game_info*)
calloc(1, sizeof(*info));
info_copy->path = (info->path) ? strdup(info->path) : NULL;
if (info->data)
{
info_copy->data = malloc(info->size);
memcpy((void*)info_copy->data, info->data, info->size);
info_copy->size = info->size;
}

// TODO: use local path
rc_client_begin_load_raintegration(rcheevos_locals.client,
L"E:\\Source\\RetroAchievements\\RAIntegration\\bin\\x64\\Debug",
(HWND)video_driver_window_get(), "RetroArch", PACKAGE_VERSION,
rcheevos_load_raintegration_callback, info_copy);
return true;
}
#endif
}

rc_client_set_hardcore_enabled(rcheevos_locals.client, settings->bools.cheevos_hardcore_mode_enable);
Expand Down
30 changes: 30 additions & 0 deletions cheevos/cheevos_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,36 @@ uintptr_t rcheevos_get_badge_texture(const char* badge, bool locked, bool downlo
return tex;
}

#ifdef RC_CLIENT_SUPPORTS_RAINTEGRATION

void rcheevos_update_hwnd(HWND hWnd)
{
rc_client_raintegration_update_main_window_handle(rcheevos_locals.client, hWnd);
}

void rcheevos_append_integration_menu(HMENU hMenu)
{
rc_client_raintegration_rebuild_submenu(rcheevos_locals.client, hMenu);
}

void rcheevos_rebuild_integration_menu()
{
if (rcheevos_locals.client->state.raintegration &&
rcheevos_locals.client->state.raintegration->hPopupMenu)
{
HWND hWnd = (HWND)video_driver_window_get();
rc_client_raintegration_rebuild_submenu(rcheevos_locals.client, GetMenu(hWnd));
//DrawMenuBar(hWnd);
}
}

bool rcheevos_activate_integration_menu_item(uint32_t nMenuItemId)
{
return rc_client_raintegration_activate_menu_item(rcheevos_locals.client, nMenuItemId);
}

#endif /* RC_CLIENT_SUPPORTS_RAINTEGRATION */

#else /* !HAVE_RC_CLIENT */

enum rcheevos_menuitem_bucket
Expand Down
7 changes: 7 additions & 0 deletions cheevos/cheevos_menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ bool rcheevos_menu_get_sublabel(unsigned menu_offset, char* buffer, size_t buffe
uintptr_t rcheevos_menu_get_badge_texture(unsigned menu_offset);
void rcheevos_menu_reset_badges(void);

#ifdef RC_CLIENT_SUPPORTS_RAINTEGRATION
void rcheevos_update_hwnd(HWND hWnd);
void rcheevos_rebuild_integration_menu();
void rcheevos_append_integration_menu(HMENU hMenu);
bool rcheevos_activate_integration_menu_item(uint32_t nMenuItemId);
#endif

RETRO_END_DECLS

#endif /* HAVE_MENU */
Expand Down
32 changes: 14 additions & 18 deletions deps/rcheevos/include/rc_api_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
#include <stdint.h>
#include <time.h>

#ifdef __cplusplus
extern "C" {
#endif
RC_BEGIN_C_DECLS

/* --- Fetch Achievement Info --- */

Expand Down Expand Up @@ -63,10 +61,10 @@ typedef struct rc_api_fetch_achievement_info_response_t {
}
rc_api_fetch_achievement_info_response_t;

int rc_api_init_fetch_achievement_info_request(rc_api_request_t* request, const rc_api_fetch_achievement_info_request_t* api_params);
int rc_api_process_fetch_achievement_info_response(rc_api_fetch_achievement_info_response_t* response, const char* server_response);
int rc_api_process_fetch_achievement_info_server_response(rc_api_fetch_achievement_info_response_t* response, const rc_api_server_response_t* server_response);
void rc_api_destroy_fetch_achievement_info_response(rc_api_fetch_achievement_info_response_t* response);
RC_EXPORT int RC_CCONV rc_api_init_fetch_achievement_info_request(rc_api_request_t* request, const rc_api_fetch_achievement_info_request_t* api_params);
RC_EXPORT int RC_CCONV rc_api_process_fetch_achievement_info_response(rc_api_fetch_achievement_info_response_t* response, const char* server_response);
RC_EXPORT int RC_CCONV rc_api_process_fetch_achievement_info_server_response(rc_api_fetch_achievement_info_response_t* response, const rc_api_server_response_t* server_response);
RC_EXPORT void RC_CCONV rc_api_destroy_fetch_achievement_info_response(rc_api_fetch_achievement_info_response_t* response);

/* --- Fetch Leaderboard Info --- */

Expand Down Expand Up @@ -135,10 +133,10 @@ typedef struct rc_api_fetch_leaderboard_info_response_t {
}
rc_api_fetch_leaderboard_info_response_t;

int rc_api_init_fetch_leaderboard_info_request(rc_api_request_t* request, const rc_api_fetch_leaderboard_info_request_t* api_params);
int rc_api_process_fetch_leaderboard_info_response(rc_api_fetch_leaderboard_info_response_t* response, const char* server_response);
int rc_api_process_fetch_leaderboard_info_server_response(rc_api_fetch_leaderboard_info_response_t* response, const rc_api_server_response_t* server_response);
void rc_api_destroy_fetch_leaderboard_info_response(rc_api_fetch_leaderboard_info_response_t* response);
RC_EXPORT int RC_CCONV rc_api_init_fetch_leaderboard_info_request(rc_api_request_t* request, const rc_api_fetch_leaderboard_info_request_t* api_params);
RC_EXPORT int RC_CCONV rc_api_process_fetch_leaderboard_info_response(rc_api_fetch_leaderboard_info_response_t* response, const char* server_response);
RC_EXPORT int RC_CCONV rc_api_process_fetch_leaderboard_info_server_response(rc_api_fetch_leaderboard_info_response_t* response, const rc_api_server_response_t* server_response);
RC_EXPORT void RC_CCONV rc_api_destroy_fetch_leaderboard_info_response(rc_api_fetch_leaderboard_info_response_t* response);

/* --- Fetch Games List --- */

Expand Down Expand Up @@ -174,13 +172,11 @@ typedef struct rc_api_fetch_games_list_response_t {
}
rc_api_fetch_games_list_response_t;

int rc_api_init_fetch_games_list_request(rc_api_request_t* request, const rc_api_fetch_games_list_request_t* api_params);
int rc_api_process_fetch_games_list_response(rc_api_fetch_games_list_response_t* response, const char* server_response);
int rc_api_process_fetch_games_list_server_response(rc_api_fetch_games_list_response_t* response, const rc_api_server_response_t* server_response);
void rc_api_destroy_fetch_games_list_response(rc_api_fetch_games_list_response_t* response);
RC_EXPORT int RC_CCONV rc_api_init_fetch_games_list_request(rc_api_request_t* request, const rc_api_fetch_games_list_request_t* api_params);
RC_EXPORT int RC_CCONV rc_api_process_fetch_games_list_response(rc_api_fetch_games_list_response_t* response, const char* server_response);
RC_EXPORT int RC_CCONV rc_api_process_fetch_games_list_server_response(rc_api_fetch_games_list_response_t* response, const rc_api_server_response_t* server_response);
RC_EXPORT void RC_CCONV rc_api_destroy_fetch_games_list_response(rc_api_fetch_games_list_response_t* response);

#ifdef __cplusplus
}
#endif
RC_END_C_DECLS

#endif /* RC_API_INFO_H */
29 changes: 0 additions & 29 deletions deps/rcheevos/src/rcheevos/rc_version.h

This file was deleted.

30 changes: 30 additions & 0 deletions gfx/common/win32_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@
#include "../../menu/menu_driver.h"
#endif

#ifdef HAVE_CHEEVOS
#include "../../cheevos/cheevos_menu.h"
#endif

#include <encodings/utf.h>

/* Assume W-functions do not work below Win2K and Xbox platforms */
Expand Down Expand Up @@ -851,6 +855,13 @@ static LRESULT win32_menu_loop(HWND owner, WPARAM wparam)
configuration_set_int(
settings, settings->ints.state_slot, idx);
}
#ifdef HAVE_CHEEVOS
#ifdef RC_CLIENT_SUPPORTS_RAINTEGRATION
else if (rcheevos_activate_integration_menu_item(mode))
{
}
#endif
#endif
break;
}

Expand Down Expand Up @@ -1833,6 +1844,13 @@ bool win32_window_create(void *data, unsigned style,
window_opacity) / 100, LWA_ALPHA);
}
#endif

#ifdef HAVE_CHEEVOS
#ifdef RC_CLIENT_SUPPORTS_RAINTEGRATION
rcheevos_update_hwnd(main_window.hwnd);
#endif
#endif

return true;
}
#endif
Expand Down Expand Up @@ -2430,6 +2448,12 @@ void win32_set_window(unsigned *width, unsigned *height,
{
RECT *rect = (RECT*)rect_data;

#ifdef HAVE_CHEEVOS
#ifdef RC_CLIENT_SUPPORTS_RAINTEGRATION
rcheevos_update_hwnd(main_window.hwnd);
#endif
#endif

if (!fullscreen || windowed_full)
{
settings_t *settings = config_get_ptr();
Expand All @@ -2450,6 +2474,12 @@ void win32_set_window(unsigned *width, unsigned *height,
win32_localize_menu(menuItem);
SetMenu(main_window.hwnd, menuItem);

#ifdef HAVE_CHEEVOS
#ifdef RC_CLIENT_SUPPORTS_RAINTEGRATION
rcheevos_append_integration_menu(menuItem);
#endif
#endif

SendMessage(main_window.hwnd, WM_NCCALCSIZE, FALSE, (LPARAM)&rc_temp);
g_win32_resize_height = *height += rc_temp.top + rect->top;
SetWindowPos(main_window.hwnd, NULL, 0, 0, *width, *height, SWP_NOMOVE);
Expand Down
8 changes: 8 additions & 0 deletions griffin/griffin.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ ACHIEVEMENTS
#define RC_NO_THREADS 1
#endif

#if defined(_WIN32)
#define RC_CLIENT_SUPPORTS_RAINTEGRATION
#endif

#include "../libretro-common/formats/cdfs/cdfs.c"
#include "../network/net_http_special.c"

Expand Down Expand Up @@ -227,6 +231,10 @@ ACHIEVEMENTS
#include "../deps/rcheevos/src/rhash/cdreader.c"
#include "../deps/rcheevos/src/rhash/hash.c"

#ifdef RC_CLIENT_SUPPORTS_RAINTEGRATION
#include "../deps/rcheevos/src/rc_client_raintegration.c"
#endif

#endif

/*============================================================
Expand Down

0 comments on commit cf722a5

Please sign in to comment.