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_runtime.h (6338B)


      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 lua_State lua_State;
     18 
     19 typedef struct rc_trigger_t rc_trigger_t;
     20 typedef struct rc_lboard_t rc_lboard_t;
     21 typedef struct rc_richpresence_t rc_richpresence_t;
     22 typedef struct rc_memref_t rc_memref_t;
     23 typedef struct rc_value_t rc_value_t;
     24 
     25 #endif
     26 
     27 /*****************************************************************************\
     28 | Callbacks                                                                   |
     29 \*****************************************************************************/
     30 
     31 /**
     32  * Callback used to read num_bytes bytes from memory starting at address. If
     33  * num_bytes is greater than 1, the value is read in little-endian from
     34  * memory.
     35  */
     36 typedef uint32_t(RC_CCONV *rc_runtime_peek_t)(uint32_t address, uint32_t num_bytes, void* ud);
     37 
     38 /*****************************************************************************\
     39 | Runtime                                                                     |
     40 \*****************************************************************************/
     41 
     42 typedef struct rc_runtime_trigger_t {
     43   uint32_t id;
     44   rc_trigger_t* trigger;
     45   void* buffer;
     46   rc_memref_t* invalid_memref;
     47   uint8_t md5[16];
     48   int32_t serialized_size;
     49   uint8_t owns_memrefs;
     50 }
     51 rc_runtime_trigger_t;
     52 
     53 typedef struct rc_runtime_lboard_t {
     54   uint32_t id;
     55   int32_t value;
     56   rc_lboard_t* lboard;
     57   void* buffer;
     58   rc_memref_t* invalid_memref;
     59   uint8_t md5[16];
     60   uint32_t serialized_size;
     61   uint8_t owns_memrefs;
     62 }
     63 rc_runtime_lboard_t;
     64 
     65 typedef struct rc_runtime_richpresence_t {
     66   rc_richpresence_t* richpresence;
     67   void* buffer;
     68   struct rc_runtime_richpresence_t* previous;
     69   uint8_t md5[16];
     70   uint8_t owns_memrefs;
     71 }
     72 rc_runtime_richpresence_t;
     73 
     74 typedef struct rc_runtime_t {
     75   rc_runtime_trigger_t* triggers;
     76   uint32_t trigger_count;
     77   uint32_t trigger_capacity;
     78 
     79   rc_runtime_lboard_t* lboards;
     80   uint32_t lboard_count;
     81   uint32_t lboard_capacity;
     82 
     83   rc_runtime_richpresence_t* richpresence;
     84 
     85   rc_memref_t* memrefs;
     86   rc_memref_t** next_memref;
     87 
     88   rc_value_t* variables;
     89   rc_value_t** next_variable;
     90 
     91   uint8_t owns_self;
     92 }
     93 rc_runtime_t;
     94 
     95 RC_EXPORT rc_runtime_t* RC_CCONV rc_runtime_alloc(void);
     96 RC_EXPORT void RC_CCONV rc_runtime_init(rc_runtime_t* runtime);
     97 RC_EXPORT void RC_CCONV rc_runtime_destroy(rc_runtime_t* runtime);
     98 
     99 RC_EXPORT int RC_CCONV rc_runtime_activate_achievement(rc_runtime_t* runtime, uint32_t id, const char* memaddr, lua_State* L, int funcs_idx);
    100 RC_EXPORT void RC_CCONV rc_runtime_deactivate_achievement(rc_runtime_t* runtime, uint32_t id);
    101 RC_EXPORT rc_trigger_t* RC_CCONV rc_runtime_get_achievement(const rc_runtime_t* runtime, uint32_t id);
    102 RC_EXPORT int RC_CCONV rc_runtime_get_achievement_measured(const rc_runtime_t* runtime, uint32_t id, unsigned* measured_value, unsigned* measured_target);
    103 RC_EXPORT int RC_CCONV rc_runtime_format_achievement_measured(const rc_runtime_t* runtime, uint32_t id, char *buffer, size_t buffer_size);
    104 
    105 RC_EXPORT int RC_CCONV rc_runtime_activate_lboard(rc_runtime_t* runtime, uint32_t id, const char* memaddr, lua_State* L, int funcs_idx);
    106 RC_EXPORT void RC_CCONV rc_runtime_deactivate_lboard(rc_runtime_t* runtime, uint32_t id);
    107 RC_EXPORT rc_lboard_t* RC_CCONV rc_runtime_get_lboard(const rc_runtime_t* runtime, uint32_t id);
    108 RC_EXPORT int RC_CCONV rc_runtime_format_lboard_value(char* buffer, int size, int32_t value, int format);
    109 
    110 
    111 RC_EXPORT int RC_CCONV rc_runtime_activate_richpresence(rc_runtime_t* runtime, const char* script, lua_State* L, int funcs_idx);
    112 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, lua_State* L);
    113 RC_EXPORT int RC_CCONV rc_runtime_get_richpresence_strings(const rc_runtime_t* runtime, const char** buffer, size_t buffersize, size_t* count);
    114 
    115 enum {
    116   RC_RUNTIME_EVENT_ACHIEVEMENT_ACTIVATED, /* from WAITING, PAUSED, or PRIMED to ACTIVE */
    117   RC_RUNTIME_EVENT_ACHIEVEMENT_PAUSED,
    118   RC_RUNTIME_EVENT_ACHIEVEMENT_RESET,
    119   RC_RUNTIME_EVENT_ACHIEVEMENT_TRIGGERED,
    120   RC_RUNTIME_EVENT_ACHIEVEMENT_PRIMED,
    121   RC_RUNTIME_EVENT_LBOARD_STARTED,
    122   RC_RUNTIME_EVENT_LBOARD_CANCELED,
    123   RC_RUNTIME_EVENT_LBOARD_UPDATED,
    124   RC_RUNTIME_EVENT_LBOARD_TRIGGERED,
    125   RC_RUNTIME_EVENT_ACHIEVEMENT_DISABLED,
    126   RC_RUNTIME_EVENT_LBOARD_DISABLED,
    127   RC_RUNTIME_EVENT_ACHIEVEMENT_UNPRIMED,
    128   RC_RUNTIME_EVENT_ACHIEVEMENT_PROGRESS_UPDATED
    129 };
    130 
    131 typedef struct rc_runtime_event_t {
    132   uint32_t id;
    133   int32_t value;
    134   uint8_t type;
    135 }
    136 rc_runtime_event_t;
    137 
    138 typedef void (RC_CCONV *rc_runtime_event_handler_t)(const rc_runtime_event_t* runtime_event);
    139 
    140 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, lua_State* L);
    141 RC_EXPORT void RC_CCONV rc_runtime_reset(rc_runtime_t* runtime);
    142 
    143 typedef int (RC_CCONV *rc_runtime_validate_address_t)(uint32_t address);
    144 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);
    145 RC_EXPORT void RC_CCONV rc_runtime_invalidate_address(rc_runtime_t* runtime, uint32_t address);
    146 
    147 RC_EXPORT uint32_t RC_CCONV rc_runtime_progress_size(const rc_runtime_t* runtime, lua_State* L);
    148 
    149 /* [deprecated] use rc_runtime_serialize_progress_sized instead */
    150 RC_EXPORT int RC_CCONV rc_runtime_serialize_progress(void* buffer, const rc_runtime_t* runtime, lua_State* L);
    151 RC_EXPORT int RC_CCONV rc_runtime_serialize_progress_sized(uint8_t* buffer, uint32_t buffer_size, const rc_runtime_t* runtime, lua_State* L);
    152 
    153 /* [deprecated] use rc_runtime_deserialize_progress_sized instead */
    154 RC_EXPORT int RC_CCONV rc_runtime_deserialize_progress(rc_runtime_t* runtime, const uint8_t* serialized, lua_State* L);
    155 RC_EXPORT int RC_CCONV rc_runtime_deserialize_progress_sized(rc_runtime_t* runtime, const uint8_t* serialized, uint32_t serialized_size, lua_State* L);
    156 
    157 RC_END_C_DECLS
    158 
    159 #endif /* RC_RUNTIME_H */