arcdps\exports/raw.rs
1//! Raw ArcDPS exports.
2
3use crate::{evtc::Event, globals::arc::ArcGlobals, imgui::sys::ImVec4};
4use std::ffi::{c_char, c_void};
5use windows::Win32::Foundation::HMODULE;
6
7/// Returns the handle to the ArcDPS dll.
8pub unsafe fn handle() -> HMODULE {
9 ArcGlobals::get().handle
10}
11
12/// Signature of the `e0` export. See [`e0_config_path`] for details.
13pub type Export0 = unsafe extern "C" fn() -> *const u16;
14
15/// Retrieves path to ArcDPS ini config file as wide char string.
16#[inline]
17pub unsafe fn e0_config_path() -> *const u16 {
18 ArcGlobals::get().e0.expect("failed to find arc export e0")()
19}
20
21/// Signature of the `e3` export. See [`e3_log_file`] for details.
22pub type Export3 = unsafe extern "C" fn(string: *const c_char);
23
24/// Logs a string to `arcdps.log` file.
25#[inline]
26pub unsafe fn e3_log_file(string: *const c_char) {
27 ArcGlobals::get().e3.expect("failed to find arc export e3")(string)
28}
29
30/// Signature of the `e5` export. See [`e5_colors`] for details.
31pub type Export5 = unsafe extern "C" fn(out: *mut [*mut ImVec4; 5]);
32
33/// Writes color array pointers to buffer.
34#[inline]
35pub unsafe fn e5_colors(buffer: *mut [*mut ImVec4; 5]) {
36 ArcGlobals::get().e5.expect("failed to find arc export e5")(buffer)
37}
38
39/// Signature of the `e6` export. See [`e6_ui_settings`] for details.
40pub type Export6 = unsafe extern "C" fn() -> u64;
41
42/// Retrieves bit mask of current ArcDPS UI settings.
43#[inline]
44pub unsafe fn e6_ui_settings() -> u64 {
45 ArcGlobals::get().e6.expect("failed to find arc export e6")()
46}
47
48/// Signature of the `e7` export. See [`e7_modifiers`] for details.
49pub type Export7 = unsafe extern "C" fn() -> u64;
50
51/// Retrieves modifier keys as virtual key codes.
52#[inline]
53pub unsafe fn e7_modifiers() -> u64 {
54 ArcGlobals::get().e7.expect("failed to find arc export e7")()
55}
56
57/// Signature of the `e8` export. See [`e8_log_window`] for details.
58pub type Export8 = unsafe extern "C" fn(string: *const c_char);
59
60/// Logs a string to the ArcDPS logger window.
61///
62/// Colors are HTML-like: `<c=#aaaaaa>colored text</c>`.
63#[inline]
64pub unsafe fn e8_log_window(string: *const c_char) {
65 ArcGlobals::get().e8.expect("failed to find arc export e8")(string)
66}
67
68/// Signature of the `e9` export. See [`e9_add_event`] for details.
69pub type Export9 = unsafe extern "C" fn(event: *const Event, sig: u32);
70
71/// Adds an [`Event`] to ArcDPS' event processing.
72///
73/// `is_statechange` will be set to [`StateChange::Extension`](crate::evtc::StateChange::Extension), pad61-64 will be set to `sig`.
74/// Event will end up processed like ArcDPS events and logged to EVTC.
75#[inline]
76pub unsafe fn e9_add_event(event: *const Event, sig: u32) {
77 ArcGlobals::get().e9.expect("failed to find arc export e9")(event, sig)
78}
79
80/// Signature of the `e10` export. See [`e10_add_event_combat`] for details.
81pub type Export10 = unsafe extern "C" fn(event: *const Event, sig: u32);
82
83/// Adds an [`Event`] to ArcDPS' event processing.
84///
85/// `is_statechange` will be set to [`StateChange::ExtensionCombat`](crate::evtc::StateChange::ExtensionCombat), pad61-64 will be set to `sig`.
86/// Event will end up processed like ArcDPS events and logged to EVTC.
87///
88/// Contrary to [`e9_add_event`], the `skill_id` is treated as skill id and will be added to the EVTC skill table.
89#[inline]
90pub unsafe fn e10_add_event_combat(event: *const Event, sig: u32) {
91 ArcGlobals::get()
92 .e10
93 .expect("failed to find arc export e10")(event, sig)
94}
95
96/// Signature of the `addextension2` export. See [`add_extension`] for details.
97pub type ExportAddExtension = unsafe extern "C" fn(handle: HMODULE) -> u32;
98
99/// Requests to load an extension (plugin/addon).
100///
101/// ArcDPS will `LoadLibrary` the `handle` to increment the reference count, call `get_init_addr` and call its returned function.
102/// Returns `0` on success or non-zero on error. See [`AddExtensionResult`](super::AddExtensionResult) for details.
103///
104/// This uses version 2 (`addextension2`) of the extension API.
105#[inline]
106pub unsafe fn add_extension(handle: HMODULE) -> u32 {
107 ArcGlobals::get()
108 .add_extension
109 .expect("failed to find arc export addextension2")(handle)
110}
111
112/// Signature of the `freeextension2` export. See [`free_extension`] for details.
113pub type ExportFreeExtension = unsafe extern "C" fn(sig: u32) -> HMODULE;
114
115/// Requests to free a loaded extension (plugin/addon).
116///
117/// ArcDPS will call `get_release_addr` and its returned function.
118/// Upon returning from [`free_extension`] there will be no more pending callbacks.
119/// However, the caller must ensure no callbacks are executing before freeing.
120/// Returns `0` if extension was not found or [`HMODULE`] handle of the module otherwise.
121///
122/// This uses version 2 (`freeextension2`) of the extension API.
123#[inline]
124pub unsafe fn free_extension(sig: u32) -> HMODULE {
125 ArcGlobals::get()
126 .free_extension
127 .expect("failed to find arc export freeextension2")(sig)
128}
129
130/// Signature of the `listextension` export. See [`list_extension`] for details.
131pub type ExportListExtension = unsafe extern "C" fn(callback_fn: *const c_void);
132
133/// Retrieves a list of extensions via callback.
134///
135/// `callback_fn` is a callback of type `void callback_fn(arcdps_exports* exp)`.
136/// Callback is called once for each extension current loaded.
137#[inline]
138pub unsafe fn list_extension(callback_fn: *const c_void) {
139 // TODO: is this sync?
140 // TODO: bindings should check for uninitialized
141 ArcGlobals::get()
142 .list_extension
143 .expect("failed to find arc export listextension")(callback_fn)
144}