arcdps\extras/exports.rs
1//! Unofficial Extras exports.
2//!
3//! Calling an export before Unofficial Extras calls `extras_init` will cause a panic.
4
5use crate::extras::{globals::ExtrasGlobals, Control, Key, Keybind};
6
7/// Retrieves the Unofficial Extras version as string.
8#[inline]
9pub fn version() -> Option<&'static str> {
10 ExtrasGlobals::get().version
11}
12
13/// Checks whether the `get_key` export was found.
14#[inline]
15pub fn has_get_key() -> bool {
16 ExtrasGlobals::get().get_key.is_some()
17}
18
19/// Retrieves the [`Key`] for a given game [`Control`] from Unofficial Extras.
20/// `secondary` determines whether the primary or secondary bind.
21///
22/// Returns an empty/default [`Key`] if the key is not set
23/// **or** if the functionality is disabled cause of missing patterns.
24///
25/// # Examples
26/// ```no_run
27/// use arcdps::extras::{keybinds::Control, exports::get_key};
28///
29/// let primary = get_key(Control::Skills_EliteSkill, false);
30/// let secondary = get_key(Control::Skills_EliteSkill, true);
31/// ```
32#[inline]
33pub fn get_key(control: Control, secondary: bool) -> Key {
34 unsafe { raw::get_key(control, secondary as u32) }.into()
35}
36
37/// Checks whether the `get_keybind` export was found.
38#[inline]
39pub fn has_get_keybind() -> bool {
40 ExtrasGlobals::get().get_keybind.is_some()
41}
42
43/// Retrieves the [`Keybind`] for a given game [`Control`] from Unofficial Extras.
44///
45/// Returns an empty/default [`Key`] if the key is not set
46/// **or** if the functionality is disabled cause of missing patterns.
47///
48/// # Examples
49/// ```no_run
50/// use arcdps::extras::{keybinds::Control, exports::get_keybind};
51///
52/// let keybind = get_keybind(Control::Skills_EliteSkill);
53/// let primary = keybind.primary;
54/// let secondary = keybind.secondary;
55/// ```
56#[inline]
57pub fn get_keybind(control: Control) -> Keybind {
58 unsafe { raw::get_keybind(control) }.into()
59}
60
61/// Raw Unofficial Extras exports.
62pub mod raw {
63 use crate::extras::{
64 globals::ExtrasGlobals,
65 keybinds::{RawKey, RawKeybind},
66 Control,
67 };
68 use windows::Win32::Foundation::HMODULE;
69
70 /// Returns the handle to the Unofficial Extras dll.
71 pub unsafe fn handle() -> HMODULE {
72 ExtrasGlobals::get().handle
73 }
74
75 /// Signature of the [`get_key`] export.
76 pub type ExportGetKey = unsafe extern "C" fn(control: Control, key_index: u32) -> RawKey;
77
78 /// Retrieves the [`RawKey`] for a given game [`Control`] from Unofficial Extras.
79 /// `key_index` can be `0` or `1` for primary/secondary keybind respectively.
80 #[inline]
81 pub unsafe fn get_key(control: Control, key_index: u32) -> RawKey {
82 ExtrasGlobals::get()
83 .get_key
84 .expect("failed to find extras export get_key")(control, key_index)
85 }
86
87 /// Signature of the [`get_keybind`] export.
88 pub type ExportGetKeybind = unsafe extern "C" fn(control: Control) -> RawKeybind;
89
90 /// Retrieves the [`RawKeybind`] for a given game [`Control`] from Unofficial Extras.
91 #[inline]
92 pub unsafe fn get_keybind(control: Control) -> RawKeybind {
93 ExtrasGlobals::get()
94 .get_keybind
95 .expect("failed to find extras export get_key")(control)
96 }
97}