duckstation

duckstation, but archived from the revision just before upstream changed it to a proprietary software project, this version is the libre one
git clone https://git.neptards.moe/u3shit/duckstation.git
Log | Files | Refs | README | LICENSE

rc_api_runtime.h (11212B)


      1 #ifndef RC_API_RUNTIME_H
      2 #define RC_API_RUNTIME_H
      3 
      4 #include "rc_api_request.h"
      5 
      6 #include <stdint.h>
      7 #include <time.h>
      8 
      9 RC_BEGIN_C_DECLS
     10 
     11 /* --- Fetch Image --- */
     12 
     13 /**
     14  * API parameters for a fetch image request.
     15  * NOTE: fetch image server response is the raw image data. There is no rc_api_process_fetch_image_response function.
     16  */
     17 typedef struct rc_api_fetch_image_request_t {
     18   /* The name of the image to fetch */
     19   const char* image_name;
     20   /* The type of image to fetch */
     21   uint32_t image_type;
     22 }
     23 rc_api_fetch_image_request_t;
     24 
     25 #define RC_IMAGE_TYPE_GAME 1
     26 #define RC_IMAGE_TYPE_ACHIEVEMENT 2
     27 #define RC_IMAGE_TYPE_ACHIEVEMENT_LOCKED 3
     28 #define RC_IMAGE_TYPE_USER 4
     29 
     30 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);
     31 
     32 /* --- Resolve Hash --- */
     33 
     34 /**
     35  * API parameters for a resolve hash request.
     36  */
     37 typedef struct rc_api_resolve_hash_request_t {
     38   /* Unused - hash lookup does not require credentials */
     39   const char* username;
     40   /* Unused - hash lookup does not require credentials */
     41   const char* api_token;
     42   /* The generated hash of the game to be identified */
     43   const char* game_hash;
     44 }
     45 rc_api_resolve_hash_request_t;
     46 
     47 /**
     48  * Response data for a resolve hash request.
     49  */
     50 typedef struct rc_api_resolve_hash_response_t {
     51   /* The unique identifier of the game, 0 if no match was found */
     52   uint32_t game_id;
     53 
     54   /* Common server-provided response information */
     55   rc_api_response_t response;
     56 }
     57 rc_api_resolve_hash_response_t;
     58 
     59 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);
     60 RC_EXPORT int RC_CCONV rc_api_process_resolve_hash_response(rc_api_resolve_hash_response_t* response, const char* server_response);
     61 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);
     62 RC_EXPORT void RC_CCONV rc_api_destroy_resolve_hash_response(rc_api_resolve_hash_response_t* response);
     63 
     64 /* --- Fetch Game Data --- */
     65 
     66 /**
     67  * API parameters for a fetch game data request.
     68  */
     69 typedef struct rc_api_fetch_game_data_request_t {
     70   /* The username of the player */
     71   const char* username;
     72   /* The API token from the login request */
     73   const char* api_token;
     74   /* The unique identifier of the game */
     75   uint32_t game_id;
     76 }
     77 rc_api_fetch_game_data_request_t;
     78 
     79 /* A leaderboard definition */
     80 typedef struct rc_api_leaderboard_definition_t {
     81   /* The unique identifier of the leaderboard */
     82   uint32_t id;
     83   /* The format to pass to rc_format_value to format the leaderboard value */
     84   int format;
     85   /* The title of the leaderboard */
     86   const char* title;
     87   /* The description of the leaderboard */
     88   const char* description;
     89   /* The definition of the leaderboard to be passed to rc_runtime_activate_lboard */
     90   const char* definition;
     91   /* Non-zero if lower values are better for this leaderboard */
     92   uint8_t lower_is_better;
     93   /* Non-zero if the leaderboard should not be displayed in a list of leaderboards */
     94   uint8_t hidden;
     95 }
     96 rc_api_leaderboard_definition_t;
     97 
     98 /* An achievement definition */
     99 typedef struct rc_api_achievement_definition_t {
    100   /* The unique identifier of the achievement */
    101   uint32_t id;
    102   /* The number of points the achievement is worth */
    103   uint32_t points;
    104   /* The achievement category (core, unofficial) */
    105   uint32_t category;
    106   /* The title of the achievement */
    107   const char* title;
    108   /* The dscription of the achievement */
    109   const char* description;
    110   /* The definition of the achievement to be passed to rc_runtime_activate_achievement */
    111   const char* definition;
    112   /* The author of the achievment */
    113   const char* author;
    114   /* The image name for the achievement badge */
    115   const char* badge_name;
    116   /* When the achievement was first uploaded to the server */
    117   time_t created;
    118   /* When the achievement was last modified on the server */
    119   time_t updated;
    120   /* The achievement type (win/progression/missable) */
    121   uint32_t type;
    122   /* The approximate rarity of the achievement (X% of users have earned the achievement) */
    123   float rarity;
    124   /* The approximate rarity of the achievement in hardcore (X% of users have earned the achievement in hardcore) */
    125   float rarity_hardcore;
    126 }
    127 rc_api_achievement_definition_t;
    128 
    129 #define RC_ACHIEVEMENT_CATEGORY_CORE 3
    130 #define RC_ACHIEVEMENT_CATEGORY_UNOFFICIAL 5
    131 
    132 #define RC_ACHIEVEMENT_TYPE_STANDARD 0
    133 #define RC_ACHIEVEMENT_TYPE_MISSABLE 1
    134 #define RC_ACHIEVEMENT_TYPE_PROGRESSION 2
    135 #define RC_ACHIEVEMENT_TYPE_WIN 3
    136 
    137 /**
    138  * Response data for a fetch game data request.
    139  */
    140 typedef struct rc_api_fetch_game_data_response_t {
    141   /* The unique identifier of the game */
    142   uint32_t id;
    143   /* The console associated to the game */
    144   uint32_t console_id;
    145   /* The title of the game */
    146   const char* title;
    147   /* The image name for the game badge */
    148   const char* image_name;
    149   /* The rich presence script for the game to be passed to rc_runtime_activate_richpresence */
    150   const char* rich_presence_script;
    151 
    152   /* An array of achievements for the game */
    153   rc_api_achievement_definition_t* achievements;
    154   /* The number of items in the achievements array */
    155   uint32_t num_achievements;
    156 
    157   /* An array of leaderboards for the game */
    158   rc_api_leaderboard_definition_t* leaderboards;
    159   /* The number of items in the leaderboards array */
    160   uint32_t num_leaderboards;
    161 
    162   /* Common server-provided response information */
    163   rc_api_response_t response;
    164 }
    165 rc_api_fetch_game_data_response_t;
    166 
    167 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);
    168 RC_EXPORT int RC_CCONV rc_api_process_fetch_game_data_response(rc_api_fetch_game_data_response_t* response, const char* server_response);
    169 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);
    170 RC_EXPORT void RC_CCONV rc_api_destroy_fetch_game_data_response(rc_api_fetch_game_data_response_t* response);
    171 
    172 /* --- Ping --- */
    173 
    174 /**
    175  * API parameters for a ping request.
    176  */
    177 typedef struct rc_api_ping_request_t {
    178   /* The username of the player */
    179   const char* username;
    180   /* The API token from the login request */
    181   const char* api_token;
    182   /* The unique identifier of the game */
    183   uint32_t game_id;
    184   /* (optional) The current rich presence evaluation for the user */
    185   const char* rich_presence;
    186   /* (recommended) The hash associated to the game being played */
    187   const char* game_hash;
    188   /* Non-zero if hardcore is currently enabled (ignored if game_hash is null) */
    189   uint32_t hardcore;
    190 }
    191 rc_api_ping_request_t;
    192 
    193 /**
    194  * Response data for a ping request.
    195  */
    196 typedef struct rc_api_ping_response_t {
    197   /* Common server-provided response information */
    198   rc_api_response_t response;
    199 }
    200 rc_api_ping_response_t;
    201 
    202 RC_EXPORT int RC_CCONV rc_api_init_ping_request(rc_api_request_t* request, const rc_api_ping_request_t* api_params);
    203 RC_EXPORT int RC_CCONV rc_api_process_ping_response(rc_api_ping_response_t* response, const char* server_response);
    204 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);
    205 RC_EXPORT void RC_CCONV rc_api_destroy_ping_response(rc_api_ping_response_t* response);
    206 
    207 /* --- Award Achievement --- */
    208 
    209 /**
    210  * API parameters for an award achievement request.
    211  */
    212 typedef struct rc_api_award_achievement_request_t {
    213   /* The username of the player */
    214   const char* username;
    215   /* The API token from the login request */
    216   const char* api_token;
    217   /* The unique identifier of the achievement */
    218   uint32_t achievement_id;
    219   /* Non-zero if the achievement was earned in hardcore */
    220   uint32_t hardcore;
    221   /* The hash associated to the game being played */
    222   const char* game_hash;
    223 }
    224 rc_api_award_achievement_request_t;
    225 
    226 /**
    227  * Response data for an award achievement request.
    228  */
    229 typedef struct rc_api_award_achievement_response_t {
    230   /* The unique identifier of the achievement that was awarded */
    231   uint32_t awarded_achievement_id;
    232   /* The updated player score */
    233   uint32_t new_player_score;
    234   /* The updated player softcore score */
    235   uint32_t new_player_score_softcore;
    236   /* The number of achievements the user has not yet unlocked for this game
    237    * (in hardcore/non-hardcore per hardcore flag in request) */
    238   uint32_t achievements_remaining;
    239 
    240   /* Common server-provided response information */
    241   rc_api_response_t response;
    242 }
    243 rc_api_award_achievement_response_t;
    244 
    245 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);
    246 RC_EXPORT int RC_CCONV rc_api_process_award_achievement_response(rc_api_award_achievement_response_t* response, const char* server_response);
    247 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);
    248 RC_EXPORT void RC_CCONV rc_api_destroy_award_achievement_response(rc_api_award_achievement_response_t* response);
    249 
    250 /* --- Submit Leaderboard Entry --- */
    251 
    252 /**
    253  * API parameters for a submit lboard entry request.
    254  */
    255 typedef struct rc_api_submit_lboard_entry_request_t {
    256   /* The username of the player */
    257   const char* username;
    258   /* The API token from the login request */
    259   const char* api_token;
    260   /* The unique identifier of the leaderboard */
    261   uint32_t leaderboard_id;
    262   /* The value being submitted */
    263   int32_t score;
    264   /* The hash associated to the game being played */
    265   const char* game_hash;
    266 }
    267 rc_api_submit_lboard_entry_request_t;
    268 
    269 /* A leaderboard entry */
    270 typedef struct rc_api_lboard_entry_t {
    271   /* The user associated to the entry */
    272   const char* username;
    273   /* The rank of the entry */
    274   uint32_t rank;
    275   /* The value of the entry */
    276   int32_t score;
    277 }
    278 rc_api_lboard_entry_t;
    279 
    280 /**
    281  * Response data for a submit lboard entry request.
    282  */
    283 typedef struct rc_api_submit_lboard_entry_response_t {
    284   /* The value that was submitted */
    285   int32_t submitted_score;
    286   /* The player's best submitted value */
    287   int32_t best_score;
    288   /* The player's new rank within the leaderboard */
    289   uint32_t new_rank;
    290   /* The total number of entries in the leaderboard */
    291   uint32_t num_entries;
    292 
    293   /* An array of the top entries for the leaderboard */
    294   rc_api_lboard_entry_t* top_entries;
    295   /* The number of items in the top_entries array */
    296   uint32_t num_top_entries;
    297 
    298   /* Common server-provided response information */
    299   rc_api_response_t response;
    300 }
    301 rc_api_submit_lboard_entry_response_t;
    302 
    303 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);
    304 RC_EXPORT int RC_CCONV rc_api_process_submit_lboard_entry_response(rc_api_submit_lboard_entry_response_t* response, const char* server_response);
    305 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);
    306 RC_EXPORT void RC_CCONV rc_api_destroy_submit_lboard_entry_response(rc_api_submit_lboard_entry_response_t* response);
    307 
    308 RC_END_C_DECLS
    309 
    310 #endif /* RC_API_RUNTIME_H */