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