duckstation/dep/rcheevos/include/rc_api_runtime.h

311 lines
11 KiB
C
Raw Normal View History

2022-07-18 12:46:12 +00:00
#ifndef RC_API_RUNTIME_H
#define RC_API_RUNTIME_H
#include "rc_api_request.h"
2023-11-06 09:41:10 +00:00
#include <stdint.h>
2022-07-18 12:46:12 +00:00
#include <time.h>
2024-01-13 04:24:04 +00:00
RC_BEGIN_C_DECLS
2022-07-18 12:46:12 +00:00
/* --- Fetch Image --- */
/**
* API parameters for a fetch image request.
* NOTE: fetch image server response is the raw image data. There is no rc_api_process_fetch_image_response function.
*/
typedef struct rc_api_fetch_image_request_t {
/* The name of the image to fetch */
const char* image_name;
/* The type of image to fetch */
2023-11-06 09:41:10 +00:00
uint32_t image_type;
2022-07-18 12:46:12 +00:00
}
rc_api_fetch_image_request_t;
#define RC_IMAGE_TYPE_GAME 1
#define RC_IMAGE_TYPE_ACHIEVEMENT 2
#define RC_IMAGE_TYPE_ACHIEVEMENT_LOCKED 3
#define RC_IMAGE_TYPE_USER 4
2024-01-13 04:24:04 +00:00
RC_EXPORT int RC_CCONV rc_api_init_fetch_image_request(rc_api_request_t* request, const rc_api_fetch_image_request_t* api_params);
2022-07-18 12:46:12 +00:00
/* --- Resolve Hash --- */
/**
* API parameters for a resolve hash request.
*/
typedef struct rc_api_resolve_hash_request_t {
/* Unused - hash lookup does not require credentials */
const char* username;
/* Unused - hash lookup does not require credentials */
const char* api_token;
/* The generated hash of the game to be identified */
const char* game_hash;
}
rc_api_resolve_hash_request_t;
/**
* Response data for a resolve hash request.
*/
typedef struct rc_api_resolve_hash_response_t {
/* The unique identifier of the game, 0 if no match was found */
2023-11-06 09:41:10 +00:00
uint32_t game_id;
2022-07-18 12:46:12 +00:00
/* Common server-provided response information */
rc_api_response_t response;
}
rc_api_resolve_hash_response_t;
2024-01-13 04:24:04 +00:00
RC_EXPORT int RC_CCONV rc_api_init_resolve_hash_request(rc_api_request_t* request, const rc_api_resolve_hash_request_t* api_params);
RC_EXPORT int RC_CCONV rc_api_process_resolve_hash_response(rc_api_resolve_hash_response_t* response, const char* server_response);
RC_EXPORT int RC_CCONV rc_api_process_resolve_hash_server_response(rc_api_resolve_hash_response_t* response, const rc_api_server_response_t* server_response);
RC_EXPORT void RC_CCONV rc_api_destroy_resolve_hash_response(rc_api_resolve_hash_response_t* response);
2022-07-18 12:46:12 +00:00
/* --- Fetch Game Data --- */
/**
* API parameters for a fetch game data request.
*/
typedef struct rc_api_fetch_game_data_request_t {
/* The username of the player */
const char* username;
/* The API token from the login request */
const char* api_token;
/* The unique identifier of the game */
2023-11-06 09:41:10 +00:00
uint32_t game_id;
2022-07-18 12:46:12 +00:00
}
rc_api_fetch_game_data_request_t;
/* A leaderboard definition */
typedef struct rc_api_leaderboard_definition_t {
/* The unique identifier of the leaderboard */
2023-11-06 09:41:10 +00:00
uint32_t id;
2022-07-18 12:46:12 +00:00
/* The format to pass to rc_format_value to format the leaderboard value */
int format;
/* The title of the leaderboard */
const char* title;
/* The description of the leaderboard */
const char* description;
/* The definition of the leaderboard to be passed to rc_runtime_activate_lboard */
const char* definition;
/* Non-zero if lower values are better for this leaderboard */
2023-11-06 09:41:10 +00:00
uint8_t lower_is_better;
2022-07-18 12:46:12 +00:00
/* Non-zero if the leaderboard should not be displayed in a list of leaderboards */
2023-11-06 09:41:10 +00:00
uint8_t hidden;
2022-07-18 12:46:12 +00:00
}
rc_api_leaderboard_definition_t;
/* An achievement definition */
typedef struct rc_api_achievement_definition_t {
/* The unique identifier of the achievement */
2023-11-06 09:41:10 +00:00
uint32_t id;
2022-07-18 12:46:12 +00:00
/* The number of points the achievement is worth */
2023-11-06 09:41:10 +00:00
uint32_t points;
2022-07-18 12:46:12 +00:00
/* The achievement category (core, unofficial) */
2023-11-06 09:41:10 +00:00
uint32_t category;
2022-07-18 12:46:12 +00:00
/* The title of the achievement */
const char* title;
/* The dscription of the achievement */
const char* description;
/* The definition of the achievement to be passed to rc_runtime_activate_achievement */
const char* definition;
/* The author of the achievment */
const char* author;
/* The image name for the achievement badge */
const char* badge_name;
/* When the achievement was first uploaded to the server */
time_t created;
/* When the achievement was last modified on the server */
time_t updated;
2024-01-13 04:24:04 +00:00
/* The achievement type (win/progression/missable) */
uint32_t type;
/* The approximate rarity of the achievement (X% of users have earned the achievement) */
float rarity;
/* The approximate rarity of the achievement in hardcore (X% of users have earned the achievement in hardcore) */
float rarity_hardcore;
2022-07-18 12:46:12 +00:00
}
rc_api_achievement_definition_t;
#define RC_ACHIEVEMENT_CATEGORY_CORE 3
#define RC_ACHIEVEMENT_CATEGORY_UNOFFICIAL 5
2024-01-13 04:24:04 +00:00
#define RC_ACHIEVEMENT_TYPE_STANDARD 0
#define RC_ACHIEVEMENT_TYPE_MISSABLE 1
#define RC_ACHIEVEMENT_TYPE_PROGRESSION 2
#define RC_ACHIEVEMENT_TYPE_WIN 3
2022-07-18 12:46:12 +00:00
/**
* Response data for a fetch game data request.
*/
typedef struct rc_api_fetch_game_data_response_t {
/* The unique identifier of the game */
2023-11-06 09:41:10 +00:00
uint32_t id;
2022-07-18 12:46:12 +00:00
/* The console associated to the game */
2023-11-06 09:41:10 +00:00
uint32_t console_id;
2022-07-18 12:46:12 +00:00
/* The title of the game */
const char* title;
/* The image name for the game badge */
const char* image_name;
/* The rich presence script for the game to be passed to rc_runtime_activate_richpresence */
const char* rich_presence_script;
/* An array of achievements for the game */
rc_api_achievement_definition_t* achievements;
/* The number of items in the achievements array */
2023-11-06 09:41:10 +00:00
uint32_t num_achievements;
2022-07-18 12:46:12 +00:00
/* An array of leaderboards for the game */
rc_api_leaderboard_definition_t* leaderboards;
/* The number of items in the leaderboards array */
2023-11-06 09:41:10 +00:00
uint32_t num_leaderboards;
2022-07-18 12:46:12 +00:00
/* Common server-provided response information */
rc_api_response_t response;
}
rc_api_fetch_game_data_response_t;
2024-01-13 04:24:04 +00:00
RC_EXPORT int RC_CCONV rc_api_init_fetch_game_data_request(rc_api_request_t* request, const rc_api_fetch_game_data_request_t* api_params);
RC_EXPORT int RC_CCONV rc_api_process_fetch_game_data_response(rc_api_fetch_game_data_response_t* response, const char* server_response);
RC_EXPORT int RC_CCONV rc_api_process_fetch_game_data_server_response(rc_api_fetch_game_data_response_t* response, const rc_api_server_response_t* server_response);
RC_EXPORT void RC_CCONV rc_api_destroy_fetch_game_data_response(rc_api_fetch_game_data_response_t* response);
2022-07-18 12:46:12 +00:00
/* --- Ping --- */
/**
* API parameters for a ping request.
*/
typedef struct rc_api_ping_request_t {
/* The username of the player */
const char* username;
/* The API token from the login request */
const char* api_token;
/* The unique identifier of the game */
2023-11-06 09:41:10 +00:00
uint32_t game_id;
2022-07-18 12:46:12 +00:00
/* (optional) The current rich presence evaluation for the user */
const char* rich_presence;
2024-01-13 04:24:04 +00:00
/* (recommended) The hash associated to the game being played */
const char* game_hash;
/* Non-zero if hardcore is currently enabled (ignored if game_hash is null) */
uint32_t hardcore;
2022-07-18 12:46:12 +00:00
}
rc_api_ping_request_t;
/**
* Response data for a ping request.
*/
typedef struct rc_api_ping_response_t {
/* Common server-provided response information */
rc_api_response_t response;
}
rc_api_ping_response_t;
2024-01-13 04:24:04 +00:00
RC_EXPORT int RC_CCONV rc_api_init_ping_request(rc_api_request_t* request, const rc_api_ping_request_t* api_params);
RC_EXPORT int RC_CCONV rc_api_process_ping_response(rc_api_ping_response_t* response, const char* server_response);
RC_EXPORT int RC_CCONV rc_api_process_ping_server_response(rc_api_ping_response_t* response, const rc_api_server_response_t* server_response);
RC_EXPORT void RC_CCONV rc_api_destroy_ping_response(rc_api_ping_response_t* response);
2022-07-18 12:46:12 +00:00
/* --- Award Achievement --- */
/**
* API parameters for an award achievement request.
*/
typedef struct rc_api_award_achievement_request_t {
/* The username of the player */
const char* username;
/* The API token from the login request */
const char* api_token;
/* The unique identifier of the achievement */
2023-11-06 09:41:10 +00:00
uint32_t achievement_id;
2022-07-18 12:46:12 +00:00
/* Non-zero if the achievement was earned in hardcore */
2023-11-06 09:41:10 +00:00
uint32_t hardcore;
2022-07-18 12:46:12 +00:00
/* The hash associated to the game being played */
const char* game_hash;
}
rc_api_award_achievement_request_t;
/**
* Response data for an award achievement request.
*/
typedef struct rc_api_award_achievement_response_t {
/* The unique identifier of the achievement that was awarded */
2023-11-06 09:41:10 +00:00
uint32_t awarded_achievement_id;
2022-07-18 12:46:12 +00:00
/* The updated player score */
2023-11-06 09:41:10 +00:00
uint32_t new_player_score;
/* The updated player softcore score */
2023-11-06 09:41:10 +00:00
uint32_t new_player_score_softcore;
2022-07-18 12:46:12 +00:00
/* The number of achievements the user has not yet unlocked for this game
* (in hardcore/non-hardcore per hardcore flag in request) */
2023-11-06 09:41:10 +00:00
uint32_t achievements_remaining;
2022-07-18 12:46:12 +00:00
/* Common server-provided response information */
rc_api_response_t response;
}
rc_api_award_achievement_response_t;
2024-01-13 04:24:04 +00:00
RC_EXPORT int RC_CCONV rc_api_init_award_achievement_request(rc_api_request_t* request, const rc_api_award_achievement_request_t* api_params);
RC_EXPORT int RC_CCONV rc_api_process_award_achievement_response(rc_api_award_achievement_response_t* response, const char* server_response);
RC_EXPORT int RC_CCONV rc_api_process_award_achievement_server_response(rc_api_award_achievement_response_t* response, const rc_api_server_response_t* server_response);
RC_EXPORT void RC_CCONV rc_api_destroy_award_achievement_response(rc_api_award_achievement_response_t* response);
2022-07-18 12:46:12 +00:00
/* --- Submit Leaderboard Entry --- */
/**
* API parameters for a submit lboard entry request.
*/
typedef struct rc_api_submit_lboard_entry_request_t {
/* The username of the player */
const char* username;
/* The API token from the login request */
const char* api_token;
/* The unique identifier of the leaderboard */
2023-11-06 09:41:10 +00:00
uint32_t leaderboard_id;
2022-07-18 12:46:12 +00:00
/* The value being submitted */
2023-11-06 09:41:10 +00:00
int32_t score;
2022-07-18 12:46:12 +00:00
/* The hash associated to the game being played */
const char* game_hash;
}
rc_api_submit_lboard_entry_request_t;
/* A leaderboard entry */
typedef struct rc_api_lboard_entry_t {
/* The user associated to the entry */
const char* username;
/* The rank of the entry */
2023-11-06 09:41:10 +00:00
uint32_t rank;
2022-07-18 12:46:12 +00:00
/* The value of the entry */
2023-11-06 09:41:10 +00:00
int32_t score;
2022-07-18 12:46:12 +00:00
}
rc_api_lboard_entry_t;
/**
* Response data for a submit lboard entry request.
*/
typedef struct rc_api_submit_lboard_entry_response_t {
/* The value that was submitted */
2023-11-06 09:41:10 +00:00
int32_t submitted_score;
2022-07-18 12:46:12 +00:00
/* The player's best submitted value */
2023-11-06 09:41:10 +00:00
int32_t best_score;
2022-07-18 12:46:12 +00:00
/* The player's new rank within the leaderboard */
2023-11-06 09:41:10 +00:00
uint32_t new_rank;
2022-07-18 12:46:12 +00:00
/* The total number of entries in the leaderboard */
2023-11-06 09:41:10 +00:00
uint32_t num_entries;
2022-07-18 12:46:12 +00:00
/* An array of the top entries for the leaderboard */
rc_api_lboard_entry_t* top_entries;
/* The number of items in the top_entries array */
2023-11-06 09:41:10 +00:00
uint32_t num_top_entries;
2022-07-18 12:46:12 +00:00
/* Common server-provided response information */
rc_api_response_t response;
}
rc_api_submit_lboard_entry_response_t;
2024-01-13 04:24:04 +00:00
RC_EXPORT int RC_CCONV rc_api_init_submit_lboard_entry_request(rc_api_request_t* request, const rc_api_submit_lboard_entry_request_t* api_params);
RC_EXPORT int RC_CCONV rc_api_process_submit_lboard_entry_response(rc_api_submit_lboard_entry_response_t* response, const char* server_response);
RC_EXPORT int RC_CCONV rc_api_process_submit_lboard_entry_server_response(rc_api_submit_lboard_entry_response_t* response, const rc_api_server_response_t* server_response);
RC_EXPORT void RC_CCONV rc_api_destroy_submit_lboard_entry_response(rc_api_submit_lboard_entry_response_t* response);
2022-07-18 12:46:12 +00:00
2024-01-13 04:24:04 +00:00
RC_END_C_DECLS
2022-07-18 12:46:12 +00:00
#endif /* RC_API_RUNTIME_H */