Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
stenzek
GitHub Repository: stenzek/duckstation
Path: blob/master/dep/rcheevos/include/rc_api_runtime.h
4246 views
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
RC_EXPORT int RC_CCONV rc_api_init_fetch_image_request_hosted(rc_api_request_t* request, const rc_api_fetch_image_request_t* api_params, const rc_api_host_t* host);
32
33
/* --- Resolve Hash --- */
34
35
/**
36
* API parameters for a resolve hash request.
37
*/
38
typedef struct rc_api_resolve_hash_request_t {
39
/* Unused - hash lookup does not require credentials */
40
const char* username;
41
/* Unused - hash lookup does not require credentials */
42
const char* api_token;
43
/* The generated hash of the game to be identified */
44
const char* game_hash;
45
}
46
rc_api_resolve_hash_request_t;
47
48
/**
49
* Response data for a resolve hash request.
50
*/
51
typedef struct rc_api_resolve_hash_response_t {
52
/* The unique identifier of the game, 0 if no match was found */
53
uint32_t game_id;
54
55
/* Common server-provided response information */
56
rc_api_response_t response;
57
}
58
rc_api_resolve_hash_response_t;
59
60
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);
61
RC_EXPORT int RC_CCONV rc_api_init_resolve_hash_request_hosted(rc_api_request_t* request, const rc_api_resolve_hash_request_t* api_params, const rc_api_host_t* host);
62
/* [deprecated] use rc_api_process_resolve_hash_server_response instead */
63
RC_EXPORT int RC_CCONV rc_api_process_resolve_hash_response(rc_api_resolve_hash_response_t* response, const char* server_response);
64
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);
65
RC_EXPORT void RC_CCONV rc_api_destroy_resolve_hash_response(rc_api_resolve_hash_response_t* response);
66
67
/* --- Fetch Game Data --- */
68
69
/**
70
* API parameters for a fetch game data request.
71
*/
72
typedef struct rc_api_fetch_game_data_request_t {
73
/* The username of the player */
74
const char* username;
75
/* The API token from the login request */
76
const char* api_token;
77
/* The unique identifier of the game */
78
uint32_t game_id;
79
/* The generated hash of the game to be identified (ignored if game_id is not 0) */
80
const char* game_hash;
81
}
82
rc_api_fetch_game_data_request_t;
83
84
/* A leaderboard definition */
85
typedef struct rc_api_leaderboard_definition_t {
86
/* The unique identifier of the leaderboard */
87
uint32_t id;
88
/* The format to pass to rc_format_value to format the leaderboard value */
89
int format;
90
/* The title of the leaderboard */
91
const char* title;
92
/* The description of the leaderboard */
93
const char* description;
94
/* The definition of the leaderboard to be passed to rc_runtime_activate_lboard */
95
const char* definition;
96
/* Non-zero if lower values are better for this leaderboard */
97
uint8_t lower_is_better;
98
/* Non-zero if the leaderboard should not be displayed in a list of leaderboards */
99
uint8_t hidden;
100
}
101
rc_api_leaderboard_definition_t;
102
103
/* An achievement definition */
104
typedef struct rc_api_achievement_definition_t {
105
/* The unique identifier of the achievement */
106
uint32_t id;
107
/* The number of points the achievement is worth */
108
uint32_t points;
109
/* The achievement category (core, unofficial) */
110
uint32_t category;
111
/* The title of the achievement */
112
const char* title;
113
/* The description of the achievement */
114
const char* description;
115
/* The definition of the achievement to be passed to rc_runtime_activate_achievement */
116
const char* definition;
117
/* The author of the achievment */
118
const char* author;
119
/* The image name for the achievement badge */
120
const char* badge_name;
121
/* When the achievement was first uploaded to the server */
122
time_t created;
123
/* When the achievement was last modified on the server */
124
time_t updated;
125
/* The achievement type (win/progression/missable) */
126
uint32_t type;
127
/* The approximate rarity of the achievement (X% of users have earned the achievement) */
128
float rarity;
129
/* The approximate rarity of the achievement in hardcore (X% of users have earned the achievement in hardcore) */
130
float rarity_hardcore;
131
/* The URL for the achievement badge */
132
const char* badge_url;
133
/* The URL for the locked achievement badge */
134
const char* badge_locked_url;
135
}
136
rc_api_achievement_definition_t;
137
138
/* A game subset definition */
139
typedef struct rc_api_subset_definition_t {
140
/* The unique identifier of the subset */
141
uint32_t id;
142
/* The title of the subset */
143
const char* title;
144
/* The image name for the subset badge */
145
const char* image_name;
146
/* The URL for the subset badge */
147
const char* image_url;
148
149
/* An array of achievements for the game */
150
rc_api_achievement_definition_t* achievements;
151
/* The number of items in the achievements array */
152
uint32_t num_achievements;
153
154
/* An array of leaderboards for the game */
155
rc_api_leaderboard_definition_t* leaderboards;
156
/* The number of items in the leaderboards array */
157
uint32_t num_leaderboards;
158
}
159
rc_api_subset_definition_t;
160
161
#define RC_ACHIEVEMENT_CATEGORY_CORE 3
162
#define RC_ACHIEVEMENT_CATEGORY_UNOFFICIAL 5
163
164
#define RC_ACHIEVEMENT_TYPE_STANDARD 0
165
#define RC_ACHIEVEMENT_TYPE_MISSABLE 1
166
#define RC_ACHIEVEMENT_TYPE_PROGRESSION 2
167
#define RC_ACHIEVEMENT_TYPE_WIN 3
168
169
/**
170
* Response data for a fetch game data request.
171
*/
172
typedef struct rc_api_fetch_game_data_response_t {
173
/* The unique identifier of the game */
174
uint32_t id;
175
/* The console associated to the game */
176
uint32_t console_id;
177
/* The title of the game */
178
const char* title;
179
/* The image name for the game badge */
180
const char* image_name;
181
/* The URL for the game badge */
182
const char* image_url;
183
/* The rich presence script for the game to be passed to rc_runtime_activate_richpresence */
184
const char* rich_presence_script;
185
186
/* An array of achievements for the game */
187
rc_api_achievement_definition_t* achievements;
188
/* The number of items in the achievements array */
189
uint32_t num_achievements;
190
191
/* An array of leaderboards for the game */
192
rc_api_leaderboard_definition_t* leaderboards;
193
/* The number of items in the leaderboards array */
194
uint32_t num_leaderboards;
195
196
/* An array of subsets for the game */
197
rc_api_subset_definition_t* subsets;
198
/* The number of items in the subsets array */
199
uint32_t num_subsets;
200
201
/* Common server-provided response information */
202
rc_api_response_t response;
203
}
204
rc_api_fetch_game_data_response_t;
205
206
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);
207
RC_EXPORT int RC_CCONV rc_api_init_fetch_game_data_request_hosted(rc_api_request_t* request, const rc_api_fetch_game_data_request_t* api_params, const rc_api_host_t* host);
208
/* [deprecated] use rc_api_process_fetch_game_data_server_response instead */
209
RC_EXPORT int RC_CCONV rc_api_process_fetch_game_data_response(rc_api_fetch_game_data_response_t* response, const char* server_response);
210
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);
211
RC_EXPORT void RC_CCONV rc_api_destroy_fetch_game_data_response(rc_api_fetch_game_data_response_t* response);
212
213
/* --- Ping --- */
214
215
/**
216
* API parameters for a ping request.
217
*/
218
typedef struct rc_api_ping_request_t {
219
/* The username of the player */
220
const char* username;
221
/* The API token from the login request */
222
const char* api_token;
223
/* The unique identifier of the game */
224
uint32_t game_id;
225
/* (optional) The current rich presence evaluation for the user */
226
const char* rich_presence;
227
/* (recommended) The hash associated to the game being played */
228
const char* game_hash;
229
/* Non-zero if hardcore is currently enabled (ignored if game_hash is null) */
230
uint32_t hardcore;
231
}
232
rc_api_ping_request_t;
233
234
/**
235
* Response data for a ping request.
236
*/
237
typedef struct rc_api_ping_response_t {
238
/* Common server-provided response information */
239
rc_api_response_t response;
240
}
241
rc_api_ping_response_t;
242
243
RC_EXPORT int RC_CCONV rc_api_init_ping_request(rc_api_request_t* request, const rc_api_ping_request_t* api_params);
244
RC_EXPORT int RC_CCONV rc_api_init_ping_request_hosted(rc_api_request_t* request, const rc_api_ping_request_t* api_params, const rc_api_host_t* host);
245
/* [deprecated] use rc_api_process_ping_server_response instead */
246
RC_EXPORT int RC_CCONV rc_api_process_ping_response(rc_api_ping_response_t* response, const char* server_response);
247
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);
248
RC_EXPORT void RC_CCONV rc_api_destroy_ping_response(rc_api_ping_response_t* response);
249
250
/* --- Award Achievement --- */
251
252
/**
253
* API parameters for an award achievement request.
254
*/
255
typedef struct rc_api_award_achievement_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 achievement */
261
uint32_t achievement_id;
262
/* Non-zero if the achievement was earned in hardcore */
263
uint32_t hardcore;
264
/* The hash associated to the game being played */
265
const char* game_hash;
266
/* The number of seconds since the achievement was unlocked */
267
uint32_t seconds_since_unlock;
268
}
269
rc_api_award_achievement_request_t;
270
271
/**
272
* Response data for an award achievement request.
273
*/
274
typedef struct rc_api_award_achievement_response_t {
275
/* The unique identifier of the achievement that was awarded */
276
uint32_t awarded_achievement_id;
277
/* The updated player score */
278
uint32_t new_player_score;
279
/* The updated player softcore score */
280
uint32_t new_player_score_softcore;
281
/* The number of achievements the user has not yet unlocked for this game
282
* (in hardcore/non-hardcore per hardcore flag in request) */
283
uint32_t achievements_remaining;
284
285
/* Common server-provided response information */
286
rc_api_response_t response;
287
}
288
rc_api_award_achievement_response_t;
289
290
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);
291
RC_EXPORT int RC_CCONV rc_api_init_award_achievement_request_hosted(rc_api_request_t* request, const rc_api_award_achievement_request_t* api_params, const rc_api_host_t* host);
292
/* [deprecated] use rc_api_process_award_achievement_server_response instead */
293
RC_EXPORT int RC_CCONV rc_api_process_award_achievement_response(rc_api_award_achievement_response_t* response, const char* server_response);
294
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);
295
RC_EXPORT void RC_CCONV rc_api_destroy_award_achievement_response(rc_api_award_achievement_response_t* response);
296
297
/* --- Submit Leaderboard Entry --- */
298
299
/**
300
* API parameters for a submit lboard entry request.
301
*/
302
typedef struct rc_api_submit_lboard_entry_request_t {
303
/* The username of the player */
304
const char* username;
305
/* The API token from the login request */
306
const char* api_token;
307
/* The unique identifier of the leaderboard */
308
uint32_t leaderboard_id;
309
/* The value being submitted */
310
int32_t score;
311
/* The hash associated to the game being played */
312
const char* game_hash;
313
/* The number of seconds since the leaderboard attempt was completed */
314
uint32_t seconds_since_completion;
315
}
316
rc_api_submit_lboard_entry_request_t;
317
318
/* A leaderboard entry */
319
typedef struct rc_api_lboard_entry_t {
320
/* The user associated to the entry */
321
const char* username;
322
/* The rank of the entry */
323
uint32_t rank;
324
/* The value of the entry */
325
int32_t score;
326
}
327
rc_api_lboard_entry_t;
328
329
/**
330
* Response data for a submit lboard entry request.
331
*/
332
typedef struct rc_api_submit_lboard_entry_response_t {
333
/* The value that was submitted */
334
int32_t submitted_score;
335
/* The player's best submitted value */
336
int32_t best_score;
337
/* The player's new rank within the leaderboard */
338
uint32_t new_rank;
339
/* The total number of entries in the leaderboard */
340
uint32_t num_entries;
341
342
/* An array of the top entries for the leaderboard */
343
rc_api_lboard_entry_t* top_entries;
344
/* The number of items in the top_entries array */
345
uint32_t num_top_entries;
346
347
/* Common server-provided response information */
348
rc_api_response_t response;
349
}
350
rc_api_submit_lboard_entry_response_t;
351
352
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);
353
RC_EXPORT int RC_CCONV rc_api_init_submit_lboard_entry_request_hosted(rc_api_request_t* request, const rc_api_submit_lboard_entry_request_t* api_params, const rc_api_host_t* host);
354
/* [deprecated] use rc_api_process_submit_lboard_entry_server_response instead */
355
RC_EXPORT int RC_CCONV rc_api_process_submit_lboard_entry_response(rc_api_submit_lboard_entry_response_t* response, const char* server_response);
356
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);
357
RC_EXPORT void RC_CCONV rc_api_destroy_submit_lboard_entry_response(rc_api_submit_lboard_entry_response_t* response);
358
359
RC_END_C_DECLS
360
361
#endif /* RC_API_RUNTIME_H */
362
363