Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
stenzek
GitHub Repository: stenzek/duckstation
Path: blob/master/dep/rcheevos/include/rc_runtime.h
4246 views
1
#ifndef RC_RUNTIME_H
2
#define RC_RUNTIME_H
3
4
#include "rc_error.h"
5
6
#include <stddef.h>
7
#include <stdint.h>
8
9
RC_BEGIN_C_DECLS
10
11
/*****************************************************************************\
12
| Forward Declarations (defined in rc_runtime_types.h) |
13
\*****************************************************************************/
14
15
#ifndef RC_RUNTIME_TYPES_H /* prevents pedantic redefinition error */
16
17
typedef struct rc_trigger_t rc_trigger_t;
18
typedef struct rc_lboard_t rc_lboard_t;
19
typedef struct rc_richpresence_t rc_richpresence_t;
20
typedef struct rc_memref_t rc_memref_t;
21
typedef struct rc_value_t rc_value_t;
22
23
#endif
24
25
/*****************************************************************************\
26
| Callbacks |
27
\*****************************************************************************/
28
29
/**
30
* Callback used to read num_bytes bytes from memory starting at address. If
31
* num_bytes is greater than 1, the value is read in little-endian from
32
* memory.
33
*/
34
typedef uint32_t(RC_CCONV *rc_runtime_peek_t)(uint32_t address, uint32_t num_bytes, void* ud);
35
36
/*****************************************************************************\
37
| Runtime |
38
\*****************************************************************************/
39
40
typedef struct rc_runtime_trigger_t {
41
uint32_t id;
42
rc_trigger_t* trigger;
43
void* buffer;
44
rc_memref_t* invalid_memref;
45
uint8_t md5[16];
46
int32_t serialized_size;
47
}
48
rc_runtime_trigger_t;
49
50
typedef struct rc_runtime_lboard_t {
51
uint32_t id;
52
int32_t value;
53
rc_lboard_t* lboard;
54
void* buffer;
55
rc_memref_t* invalid_memref;
56
uint8_t md5[16];
57
uint32_t serialized_size;
58
}
59
rc_runtime_lboard_t;
60
61
typedef struct rc_runtime_richpresence_t {
62
rc_richpresence_t* richpresence;
63
void* buffer;
64
uint8_t md5[16];
65
}
66
rc_runtime_richpresence_t;
67
68
typedef struct rc_runtime_t {
69
rc_runtime_trigger_t* triggers;
70
uint32_t trigger_count;
71
uint32_t trigger_capacity;
72
73
rc_runtime_lboard_t* lboards;
74
uint32_t lboard_count;
75
uint32_t lboard_capacity;
76
77
rc_runtime_richpresence_t* richpresence;
78
79
struct rc_memrefs_t* memrefs;
80
81
uint8_t owns_self;
82
}
83
rc_runtime_t;
84
85
RC_EXPORT rc_runtime_t* RC_CCONV rc_runtime_alloc(void);
86
RC_EXPORT void RC_CCONV rc_runtime_init(rc_runtime_t* runtime);
87
RC_EXPORT void RC_CCONV rc_runtime_destroy(rc_runtime_t* runtime);
88
89
RC_EXPORT int RC_CCONV rc_runtime_activate_achievement(rc_runtime_t* runtime, uint32_t id, const char* memaddr, void* unused_L, int unused_funcs_idx);
90
RC_EXPORT void RC_CCONV rc_runtime_deactivate_achievement(rc_runtime_t* runtime, uint32_t id);
91
RC_EXPORT rc_trigger_t* RC_CCONV rc_runtime_get_achievement(const rc_runtime_t* runtime, uint32_t id);
92
RC_EXPORT int RC_CCONV rc_runtime_get_achievement_measured(const rc_runtime_t* runtime, uint32_t id, unsigned* measured_value, unsigned* measured_target);
93
RC_EXPORT int RC_CCONV rc_runtime_format_achievement_measured(const rc_runtime_t* runtime, uint32_t id, char *buffer, size_t buffer_size);
94
95
RC_EXPORT int RC_CCONV rc_runtime_activate_lboard(rc_runtime_t* runtime, uint32_t id, const char* memaddr, void* unused_L, int unused_funcs_idx);
96
RC_EXPORT void RC_CCONV rc_runtime_deactivate_lboard(rc_runtime_t* runtime, uint32_t id);
97
RC_EXPORT rc_lboard_t* RC_CCONV rc_runtime_get_lboard(const rc_runtime_t* runtime, uint32_t id);
98
RC_EXPORT int RC_CCONV rc_runtime_format_lboard_value(char* buffer, int size, int32_t value, int format);
99
100
101
RC_EXPORT int RC_CCONV rc_runtime_activate_richpresence(rc_runtime_t* runtime, const char* script, void* unused_L, int unused_funcs_idx);
102
RC_EXPORT int RC_CCONV rc_runtime_get_richpresence(const rc_runtime_t* runtime, char* buffer, size_t buffersize, rc_runtime_peek_t peek, void* peek_ud, void* unused_L);
103
RC_EXPORT int RC_CCONV rc_runtime_get_richpresence_strings(const rc_runtime_t* runtime, const char** buffer, size_t buffersize, size_t* count);
104
105
enum {
106
RC_RUNTIME_EVENT_ACHIEVEMENT_ACTIVATED, /* from WAITING, PAUSED, or PRIMED to ACTIVE */
107
RC_RUNTIME_EVENT_ACHIEVEMENT_PAUSED,
108
RC_RUNTIME_EVENT_ACHIEVEMENT_RESET,
109
RC_RUNTIME_EVENT_ACHIEVEMENT_TRIGGERED,
110
RC_RUNTIME_EVENT_ACHIEVEMENT_PRIMED,
111
RC_RUNTIME_EVENT_LBOARD_STARTED,
112
RC_RUNTIME_EVENT_LBOARD_CANCELED,
113
RC_RUNTIME_EVENT_LBOARD_UPDATED,
114
RC_RUNTIME_EVENT_LBOARD_TRIGGERED,
115
RC_RUNTIME_EVENT_ACHIEVEMENT_DISABLED,
116
RC_RUNTIME_EVENT_LBOARD_DISABLED,
117
RC_RUNTIME_EVENT_ACHIEVEMENT_UNPRIMED,
118
RC_RUNTIME_EVENT_ACHIEVEMENT_PROGRESS_UPDATED
119
};
120
121
typedef struct rc_runtime_event_t {
122
uint32_t id;
123
int32_t value;
124
uint8_t type;
125
}
126
rc_runtime_event_t;
127
128
typedef void (RC_CCONV *rc_runtime_event_handler_t)(const rc_runtime_event_t* runtime_event);
129
130
RC_EXPORT void RC_CCONV rc_runtime_do_frame(rc_runtime_t* runtime, rc_runtime_event_handler_t event_handler, rc_runtime_peek_t peek, void* ud, void* unused_L);
131
RC_EXPORT void RC_CCONV rc_runtime_reset(rc_runtime_t* runtime);
132
133
typedef int (RC_CCONV *rc_runtime_validate_address_t)(uint32_t address);
134
RC_EXPORT void RC_CCONV rc_runtime_validate_addresses(rc_runtime_t* runtime, rc_runtime_event_handler_t event_handler, rc_runtime_validate_address_t validate_handler);
135
RC_EXPORT void RC_CCONV rc_runtime_invalidate_address(rc_runtime_t* runtime, uint32_t address);
136
137
RC_EXPORT uint32_t RC_CCONV rc_runtime_progress_size(const rc_runtime_t* runtime, void* unused_L);
138
139
/* [deprecated] use rc_runtime_serialize_progress_sized instead */
140
RC_EXPORT int RC_CCONV rc_runtime_serialize_progress(void* buffer, const rc_runtime_t* runtime, void* unused_L);
141
RC_EXPORT int RC_CCONV rc_runtime_serialize_progress_sized(uint8_t* buffer, uint32_t buffer_size, const rc_runtime_t* runtime, void* unused_L);
142
143
/* [deprecated] use rc_runtime_deserialize_progress_sized instead */
144
RC_EXPORT int RC_CCONV rc_runtime_deserialize_progress(rc_runtime_t* runtime, const uint8_t* serialized, void* unused_L);
145
RC_EXPORT int RC_CCONV rc_runtime_deserialize_progress_sized(rc_runtime_t* runtime, const uint8_t* serialized, uint32_t serialized_size, void* unused_L);
146
147
RC_END_C_DECLS
148
149
#endif /* RC_RUNTIME_H */
150
151