nexus\api/
v6.rs

1//! Addon API version 6.
2
3use super::{
4    alert::RawAlertNotify,
5    data_link::{RawDataGetResource, RawDataShareResource},
6    event::{
7        RawEventRaise, RawEventRaiseNotification, RawEventRaiseNotificationTargeted,
8        RawEventRaiseTargeted, RawEventSubscribe,
9    },
10    font::{
11        RawFontAddFromFile, RawFontAddFromMemory, RawFontAddFromResource, RawFontGet,
12        RawFontRelease, RawFontResize,
13    },
14    gamebind::{
15        RawGamebindInvokeAsync, RawGamebindIsBound, RawGamebindPress, RawGamebindPressAsync,
16        RawGamebindRelease, RawGamebindReleaseAsync,
17    },
18    gui::{
19        ImguiFree, ImguiMalloc, RawGuiAddRender, RawGuiDeregisterCloseOnEscape,
20        RawGuiRegisterCloseOnEscape, RawGuiRemRender,
21    },
22    hook::{RawHookCreate, RawHookDisable, RawHookEnable, RawHookRemove},
23    keybind::{
24        RawKeybindDeregister, RawKeybindInvoke, RawKeybindRegisterWithString,
25        RawKeybindRegisterWithStruct,
26    },
27    localization::{RawLocalizationSet, RawLocalizationTranslate, RawLocalizationTranslateTo},
28    log::RawLog,
29    paths::{RawGetAddonDir, RawGetCommonDir, RawGetGameDir},
30    quick_access::{
31        RawQuickAccessAddContextMenu2, RawQuickAccessAddShortcut, RawQuickAccessGeneric,
32    },
33    texture::{
34        RawTextureGet, RawTextureGetOrCreateFromFile, RawTextureGetOrCreateFromMemory,
35        RawTextureGetOrCreateFromResource, RawTextureGetOrCreateFromUrl, RawTextureLoadFromFile,
36        RawTextureLoadFromMemory, RawTextureLoadFromResource, RawTextureLoadFromUrl,
37    },
38    updater::RawRequestUpdate,
39    wnd_proc::{RawWndProcAddRem, RawWndProcSendToGame},
40};
41use windows::Win32::Graphics::{Direct3D11::ID3D11Device, Dxgi::IDXGISwapChain};
42
43/// Nexus addon API (version 6).
44#[derive(Debug, Clone)]
45#[repr(C)]
46pub struct AddonApi {
47    /// DirectX swap chain.
48    pub swap_chain: IDXGISwapChain,
49
50    /// ImGui context.
51    pub imgui_context: *mut imgui::sys::ImGuiContext,
52
53    /// ImGui malloc function.
54    pub imgui_malloc: Option<ImguiMalloc>,
55
56    /// ImGui free function.
57    pub imgui_free: Option<ImguiFree>,
58
59    /// Rendering API.
60    pub renderer: RendererApi,
61
62    /// Downloads the addon available at remote without checking its version.
63    pub request_update: RawRequestUpdate,
64
65    /// Logs a message to the log window and log file.
66    ///
67    /// Supports custom coloring for addon window messages, for example `<c=#FF0000>this text is red</c>`.
68    pub log: RawLog,
69
70    /// Ui API.
71    pub ui: UiApi,
72
73    /// Paths API.
74    pub path: PathApi,
75
76    /// MinHook API.
77    pub min_hook: MinHookApi,
78
79    /// Event API.
80    pub event: EventApi,
81
82    /// [WNDPROC](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nc-winuser-wndproc) API.
83    pub wnd_proc: WndProcApi,
84
85    /// Input keybinds API.
86    pub input_binds: InputBindsApi,
87
88    /// Game keybinds API.
89    pub game_bind: GameBindApi,
90
91    /// Data Link API.
92    pub data_link: DataLinkApi,
93
94    /// Texture Api.
95    pub texture: TextureApi,
96
97    /// Quick Access API.
98    pub quick_access: QuickAccessApi,
99
100    /// Localization API.
101    pub localization: LocalizationApi,
102
103    /// Font API.
104    pub font: FontApi,
105}
106
107unsafe impl Sync for AddonApi {}
108
109unsafe impl Send for AddonApi {}
110
111impl AddonApi {
112    /// Nexus Addon API version.
113    pub const VERSION: i32 = 6;
114
115    /// Retrieves the DirectX 11 device associated with the swap chain.
116    #[inline]
117    pub fn get_d3d11_device(&self) -> Option<ID3D11Device> {
118        unsafe { self.swap_chain.GetDevice() }.ok()
119    }
120}
121
122#[derive(Debug, Clone)]
123#[repr(C)]
124pub struct RendererApi {
125    /// Registers a new render callback.
126    pub register: RawGuiAddRender,
127
128    /// Removes a registered render callback.
129    pub deregister: RawGuiRemRender,
130}
131
132#[derive(Debug, Clone)]
133#[repr(C)]
134pub struct UiApi {
135    /// Sends a text alert to the user visible for a short amount of time.
136    pub send_alert: RawAlertNotify,
137
138    /// Registers a window name to get its bool toggled when escape is pressed.
139    pub register_close_on_escape: RawGuiRegisterCloseOnEscape,
140
141    /// Deregisters a window name to listen to on escape.
142    pub deregister_close_on_escape: RawGuiDeregisterCloseOnEscape,
143}
144
145#[derive(Debug, Clone)]
146#[repr(C)]
147pub struct PathApi {
148    /// Returns the path to the game directory.
149    ///
150    /// For example `"C:\Program Files\Guild Wars 2\"`.
151    pub get_game_dir: RawGetGameDir,
152
153    /// Returns a path to `"\addons\{name}"`.
154    ///
155    /// Passing `null` or `""` returns `"\addons"` without trailing slash.
156    pub get_addon_dir: RawGetAddonDir,
157
158    /// Returns the path to the common addon folder.
159    ///
160    /// Alias for `get_addon_dir("common")`.
161    pub get_common_dir: RawGetCommonDir,
162}
163
164#[derive(Debug, Clone)]
165#[repr(C)]
166pub struct MinHookApi {
167    /// MinHook create.
168    pub create: RawHookCreate,
169
170    /// MinHook remove.
171    pub remove: RawHookRemove,
172
173    /// MinHook enable.
174    pub enable: RawHookEnable,
175
176    /// MinHook disable.
177    pub disable: RawHookDisable,
178}
179
180#[derive(Debug, Clone)]
181#[repr(C)]
182pub struct EventApi {
183    /// Raises an event to all subscribing addons.
184    pub raise: RawEventRaise,
185
186    /// Raises an event without payload to all subscribing addons.
187    ///
188    /// Alias for `event_raise("EV_FOO", null)`.
189    pub raise_notification: RawEventRaiseNotification,
190
191    /// Raises an event for a specific subscribing addon.
192    pub raise_targeted: RawEventRaiseTargeted,
193
194    /// Raises an event without payload for a specific subscribing addon.
195    ///
196    /// Alias for `event_raise_targeted("EV_FOO", null)`.
197    pub raise_notification_targeted: RawEventRaiseNotificationTargeted,
198
199    /// Registers a new event callback.
200    pub subscribe: RawEventSubscribe,
201
202    /// Removes a registered event callback.
203    pub unsubscribe: RawEventSubscribe,
204}
205
206#[derive(Debug, Clone)]
207#[repr(C)]
208pub struct WndProcApi {
209    /// Registers a new [WNDPROC](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nc-winuser-wndproc) callback.
210    pub register: RawWndProcAddRem,
211
212    /// Removes a registered [WNDPROC](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nc-winuser-wndproc) callback.
213    pub deregister: RawWndProcAddRem,
214
215    /// Sends a [WNDPROC](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nc-winuser-wndproc) directly to the game, bypassing other hooks.
216    pub send_to_game_only: RawWndProcSendToGame,
217}
218
219#[derive(Debug, Clone)]
220#[repr(C)]
221pub struct InputBindsApi {
222    /// Trigger a keybind programmatically.
223    pub invoke: RawKeybindInvoke,
224
225    /// Registers a new keybind handler for a given named keybind.
226    ///
227    /// Keybind is a string like `"ALT+SHIFT+T`.
228    pub register_with_string: RawKeybindRegisterWithString,
229
230    /// Registers a new keybind handler for a given named keybind.
231    ///
232    /// Keybind is a [`Keybind`](crate::keybind::Keybind) struct.
233    pub register_with_struct: RawKeybindRegisterWithStruct,
234
235    /// Removes a registered keybind.
236    pub deregister: RawKeybindDeregister,
237}
238
239#[derive(Debug, Clone)]
240#[repr(C)]
241pub struct GameBindApi {
242    /// Presses the keys of a given bind.
243    pub press_async: RawGamebindPressAsync,
244
245    /// Releases the keypress of a given bind.
246    pub release_async: RawGamebindReleaseAsync,
247
248    /// Sends the keys of a given bind and then releases them after a given duration.
249    pub invoke_async: RawGamebindInvokeAsync,
250
251    /// TPresses the keys of a given bind.
252    pub press: RawGamebindPress,
253
254    /// Releases the keypress of a given bind.
255    pub release: RawGamebindRelease,
256
257    /// Returns if a given game bind is set.
258    pub is_bound: RawGamebindIsBound,
259}
260
261#[derive(Debug, Clone)]
262#[repr(C)]
263pub struct DataLinkApi {
264    /// Returns a pointer to the requested resource of `null` if it does not exist.
265    pub get: RawDataGetResource,
266
267    /// Allocates a shared resource of the given size and returns a pointer to it for writing.
268    pub share: RawDataShareResource,
269}
270
271#[derive(Debug, Clone)]
272#[repr(C)]
273pub struct TextureApi {
274    /// Returns a pointer to the [`Texture`](crate::texture::Texture) or `null` if it does not exist.
275    pub get: RawTextureGet,
276
277    /// Returns a pointer to the [`Texture`](crate::texture::Texture) or creates it from the file if it does not exist.
278    pub get_or_create_from_file: RawTextureGetOrCreateFromFile,
279
280    /// Returns a pointer to the [`Texture`](crate::texture::Texture) or creates it from the resource if it does not exist.
281    pub get_or_create_from_resource: RawTextureGetOrCreateFromResource,
282
283    /// Returns a pointer to the [`Texture`](crate::texture::Texture) or creates it from the URL if it does not exist.
284    pub get_or_create_from_url: RawTextureGetOrCreateFromUrl,
285
286    /// Returns a pointer to the [`Texture`](crate::texture::Texture) or creates it from the memory if it does not exist.
287    pub get_or_create_from_memory: RawTextureGetOrCreateFromMemory,
288
289    /// Creates a texture from the file and passes it to the callback when finished.
290    pub load_from_file: RawTextureLoadFromFile,
291
292    /// Creates a texture from the resource and passes it to the callback when finished.
293    pub load_from_resource: RawTextureLoadFromResource,
294
295    /// Creates a texture from the URL and passes it to the callback when finished.
296    pub load_from_url: RawTextureLoadFromUrl,
297
298    /// Creates a texture from the memory and passes it to the callback when finished.
299    pub load_from_memory: RawTextureLoadFromMemory,
300}
301
302#[derive(Debug, Clone)]
303#[repr(C)]
304pub struct QuickAccessApi {
305    /// Adds a new icon to the quick access with the given texture identifiers.
306    /// When clicked the given keybind identifier will be invoked.
307    pub add: RawQuickAccessAddShortcut,
308
309    /// Removes a shortcut with the given identifier from quick access.
310    pub remove: RawQuickAccessGeneric,
311
312    /// Sends a notification icon to the given shortcut.
313    pub notify: RawQuickAccessGeneric,
314
315    /// Adds a new ImGui callback fired when right-clicking the shortcut icon.
316    pub add_context_menu: RawQuickAccessAddContextMenu2,
317
318    /// Removes a registered context menu from the quick access item with the given identifier.
319    pub remove_context_menu: RawQuickAccessGeneric,
320}
321
322#[derive(Debug, Clone)]
323#[repr(C)]
324pub struct LocalizationApi {
325    /// Translates the identifier into the current active language.
326    /// Returns the same identifier if unavailable.
327    pub translate: RawLocalizationTranslate,
328
329    /// Translates the identifier into the given language.
330    /// Returns the same identifier if unavailable.
331    pub translate_to: RawLocalizationTranslateTo,
332
333    /// Set a translated string at runtime.
334    pub set: RawLocalizationSet,
335}
336
337#[derive(Debug, Clone)]
338#[repr(C)]
339pub struct FontApi {
340    /// Requests a font to be sent to the given callback/receiver.
341    pub get: RawFontGet,
342
343    /// Releases a callback/receiver from a specific font.
344    pub release: RawFontRelease,
345
346    /// Adds a font from disk and sends updates to the callback.
347    pub add_from_file: RawFontAddFromFile,
348
349    /// Adds a font from an embedded resource and sends updates to the callback.
350    pub add_from_resource: RawFontAddFromResource,
351
352    /// Adds a font from memory and sends updates to the callback.
353    pub add_from_memory: RawFontAddFromMemory,
354
355    /// Resizes a font and sends updates to the registered callbacks.
356    pub resize: RawFontResize,
357}