arcdps/
callbacks.rs

1//! Callback types.
2
3use crate::{
4    evtc::{Agent, Event},
5    imgui,
6    util::abi,
7};
8use std::os::raw::c_char;
9use windows::Win32::Foundation::{HWND, LPARAM, WPARAM};
10
11/// Exported struct for ArcDPS plugins.
12#[repr(C)]
13pub struct ArcDpsExport {
14    /// Size of exports table.
15    pub size: usize,
16
17    /// Unique plugin signature.
18    ///
19    /// Pick a random number that is not used by other modules.
20    pub sig: u32,
21
22    /// ImGui version number.
23    ///
24    /// Set to `18000` if you do not use ImGui (as of 2021-02-02).
25    pub imgui_version: u32,
26
27    /// Plugin name string.
28    pub out_name: *const c_char,
29
30    /// Plugin build (version) string.
31    pub out_build: *const c_char,
32
33    /// WndProc callback.
34    ///
35    /// Return is assigned to uMsg (return zero to not be processed by ArcDPS or game).
36    pub wnd_nofilter: Option<RawWndProcCallback>,
37
38    /// Combat callback.
39    ///
40    /// May be called asynchronously, use `id` to keep track of order.
41    /// First event id will be `2`.
42    /// Return is ignored.
43    pub combat: Option<RawCombatCallback>,
44
45    /// ImGui callback.
46    pub imgui: Option<RawImguiCallback>,
47
48    /// Options callback.
49    ///
50    /// For a plugin options tab.
51    pub options_end: Option<RawOptionsCallback>,
52
53    /// Local combat callback.
54    ///
55    /// Like `combat` (area) but from chat log.
56    pub combat_local: Option<RawCombatCallback>,
57
58    /// Filtered WndProc callback.
59    ///
60    /// Like `wnd_nofilter` but input fitlered using modifiers.
61    pub wnd_filter: Option<RawWndProcCallback>,
62
63    /// Options windows callback.
64    ///
65    /// Called once per window option checkbox in settings, with null at the end.
66    /// Non-zero return disables ArcDPS drawing that checkbox.
67    pub options_windows: Option<RawOptionsWindowsCallback>,
68}
69
70unsafe impl Sync for ArcDpsExport {}
71
72pub type InitFunc = fn() -> Result<(), String>;
73
74pub type ReleaseFunc = fn();
75
76pub type UpdateUrlFunc = fn() -> Option<String>;
77
78pub type WndProcCallback = fn(key: usize, key_down: bool, prev_key_down: bool) -> bool;
79
80pub type CombatCallback = fn(
81    event: Option<&Event>,
82    src: Option<&Agent>,
83    dst: Option<&Agent>,
84    skill_name: Option<&'static str>,
85    id: u64,
86    revision: u64,
87);
88
89pub type ImguiCallback = fn(ui: &imgui::Ui, not_character_select_or_loading: bool);
90
91pub type OptionsCallback = fn(ui: &imgui::Ui);
92
93pub type OptionsWindowsCallback = fn(ui: &imgui::Ui, window_name: Option<&str>) -> bool;
94
95abi! {
96    pub type RawWndProcCallback =
97        unsafe extern fn(h_wnd: HWND, u_msg: u32, w_param: WPARAM, l_param: LPARAM) -> u32;
98
99    pub type RawCombatCallback = unsafe extern fn(
100        event: *const Event,
101        src: *const Agent,
102        dst: *const Agent,
103        skill_name: *const c_char,
104        id: u64,
105        revision: u64,
106    );
107
108    pub type RawImguiCallback = unsafe extern fn(not_character_select_or_loading: u32);
109
110    pub type RawOptionsCallback = unsafe extern fn();
111
112    pub type RawOptionsWindowsCallback = unsafe extern fn(window_name: *const c_char) -> bool;
113}