nexus\api/
v4.rs

1//! Addon API version 4.
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,
13    },
14    gui::{ImguiFree, ImguiMalloc, RawGuiAddRender, RawGuiRemRender},
15    hook::{RawHookCreate, RawHookDisable, RawHookEnable, RawHookRemove},
16    keybind::{RawKeybindDeregister, RawKeybindRegisterWithString, RawKeybindRegisterWithStruct},
17    localization::{RawLocalizationTranslate, RawLocalizationTranslateTo},
18    log::RawLog,
19    paths::{RawGetAddonDir, RawGetCommonDir, RawGetGameDir},
20    quick_access::{
21        RawQuickAccessAddContextMenu, RawQuickAccessAddShortcut, RawQuickAccessGeneric,
22    },
23    texture::{
24        RawTextureGet, RawTextureGetOrCreateFromFile, RawTextureGetOrCreateFromMemory,
25        RawTextureGetOrCreateFromResource, RawTextureGetOrCreateFromUrl, RawTextureLoadFromFile,
26        RawTextureLoadFromMemory, RawTextureLoadFromResource, RawTextureLoadFromUrl,
27    },
28    updater::RawRequestUpdate,
29    wnd_proc::{RawWndProcAddRem, RawWndProcSendToGame},
30};
31use windows::Win32::Graphics::{Direct3D11::ID3D11Device, Dxgi::IDXGISwapChain};
32
33/// Nexus addon API (version 4).
34#[derive(Debug, Clone)]
35#[repr(C)]
36pub struct AddonApi {
37    /// DirectX swap chain.
38    pub swap_chain: IDXGISwapChain,
39
40    /// ImGui context.
41    pub imgui_context: *mut imgui::sys::ImGuiContext,
42
43    /// ImGui malloc function.
44    pub imgui_malloc: Option<ImguiMalloc>,
45
46    /// ImGui free function.
47    pub imgui_free: Option<ImguiFree>,
48
49    /// Registers a new render callback.
50    pub register_render: RawGuiAddRender,
51
52    /// Removes a registered render callback.
53    pub deregister_render: RawGuiRemRender,
54
55    /// Downloads the addon available at remote without checking its version.
56    pub request_update: RawRequestUpdate,
57
58    /// Returns the path to the game directory.
59    ///
60    /// For example `"C:\Program Files\Guild Wars 2\"`.
61    pub get_game_dir: RawGetGameDir,
62
63    /// Returns a path to `"\addons\{name}"`.
64    ///
65    /// Passing `null` or `""` returns `"\addons"` without trailing slash.
66    pub get_addon_dir: RawGetAddonDir,
67
68    /// Returns the path to the common addon folder.
69    ///
70    /// Alias for `get_addon_dir("common")`.
71    pub get_common_dir: RawGetCommonDir,
72
73    /// MinHook create.
74    pub hook_create: RawHookCreate,
75
76    /// MinHook remove.
77    pub hook_remove: RawHookRemove,
78
79    /// MinHook enable.
80    pub hook_enable: RawHookEnable,
81
82    /// MinHook disable.
83    pub hook_disable: RawHookDisable,
84
85    /// Logs a message to the log window and log file.
86    ///
87    /// Supports custom coloring for addon window messages, for example `<c=#FF0000>this text is red</c>`.
88    pub log: RawLog,
89
90    /// Sends a text alert to the user visible for a short amount of time.
91    pub alert_notify: RawAlertNotify,
92
93    /// Raises an event to all subscribing addons.
94    pub event_raise: RawEventRaise,
95
96    /// Raises an event without payload to all subscribing addons.
97    ///
98    /// Alias for `event_raise("EV_FOO", null)`.
99    pub event_raise_notification: RawEventRaiseNotification,
100
101    /// Raises an event for a specific subscribing addon.
102    pub event_raise_targeted: RawEventRaiseTargeted,
103
104    /// Raises an event without payload for a specific subscribing addon.
105    ///
106    /// Alias for `event_raise_targeted("EV_FOO", null)`.
107    pub event_raise_notification_targeted: RawEventRaiseNotificationTargeted,
108
109    /// Registers a new event callback.
110    pub event_subscribe: RawEventSubscribe,
111
112    /// Removes a registered event callback.
113    pub event_unsubscribe: RawEventSubscribe,
114
115    /// Registers a new [WNDPROC](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nc-winuser-wndproc) callback.
116    pub register_wnd_proc: RawWndProcAddRem,
117
118    /// Removes a registered [WNDPROC](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nc-winuser-wndproc) callback.
119    pub deregister_wnd_proc: RawWndProcAddRem,
120
121    /// Sends a [WNDPROC](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nc-winuser-wndproc) directly to the game, bypassing other hooks.
122    pub send_wnd_proc_to_game_only: RawWndProcSendToGame,
123
124    /// Registers a new keybind handler for a given named keybind.
125    ///
126    /// Keybind is a string like `"ALT+SHIFT+T`.
127    pub keybind_register_with_string: RawKeybindRegisterWithString,
128
129    /// Registers a new keybind handler for a given named keybind.
130    ///
131    /// Keybind is a [`Keybind`](crate::keybind::Keybind) struct.
132    pub keybind_register_with_struct: RawKeybindRegisterWithStruct,
133
134    /// Removes a registered keybind.
135    pub keybind_deregister: RawKeybindDeregister,
136
137    /// Returns a pointer to the requested resource of `null` if it does not exist.
138    pub get_resource: RawDataGetResource,
139
140    /// Allocates a shared resource of the given size and returns a pointer to it for writing.
141    pub share_resource: RawDataShareResource,
142
143    /// Returns a pointer to the [`Texture`](crate::texture::Texture) or `null` if it does not exist.
144    pub get_texture: RawTextureGet,
145
146    /// Returns a pointer to the [`Texture`](crate::texture::Texture) or creates it from the file if it does not exist.
147    pub get_texture_or_create_from_file: RawTextureGetOrCreateFromFile,
148
149    /// Returns a pointer to the [`Texture`](crate::texture::Texture) or creates it from the resource if it does not exist.
150    pub get_texture_or_create_from_resource: RawTextureGetOrCreateFromResource,
151
152    /// Returns a pointer to the [`Texture`](crate::texture::Texture) or creates it from the URL if it does not exist.
153    pub get_texture_or_create_from_url: RawTextureGetOrCreateFromUrl,
154
155    /// Returns a pointer to the [`Texture`](crate::texture::Texture) or creates it from the memory if it does not exist.
156    pub get_texture_or_create_from_memory: RawTextureGetOrCreateFromMemory,
157
158    /// Creates a texture from the file and passes it to the callback when finished.
159    pub load_texture_from_file: RawTextureLoadFromFile,
160
161    /// Creates a texture from the resource and passes it to the callback when finished.
162    pub load_texture_from_resource: RawTextureLoadFromResource,
163
164    /// Creates a texture from the URL and passes it to the callback when finished.
165    pub load_texture_from_url: RawTextureLoadFromUrl,
166
167    /// Creates a texture from the memory and passes it to the callback when finished.
168    pub load_texture_from_memory: RawTextureLoadFromMemory,
169
170    /// Adds a new shortcut icon to the quick access with the given texture identifiers.
171    /// When clicked the given keybind identifier will be called.
172    pub add_shortcut: RawQuickAccessAddShortcut,
173
174    /// Removes a shortcut with the given identifier from quick access.
175    pub remove_shortcut: RawQuickAccessGeneric,
176
177    /// Sends a notification icon to the given shortcut.
178    pub notify_shortcut: RawQuickAccessGeneric,
179
180    /// Adds a new ImGui callback fired when right-clicking the Nexus icon.
181    pub add_simple_shortcut: RawQuickAccessAddContextMenu,
182
183    /// Removes a registered simple shortcut callback.
184    pub remove_simple_shortcut: RawQuickAccessGeneric,
185
186    /// Translates the identifier into the current active language.
187    /// Returns the same identifier if unavailable.
188    pub translate: RawLocalizationTranslate,
189
190    /// Translates the identifier into the given language.
191    /// Returns the same identifier if unavailable.
192    pub translate_to: RawLocalizationTranslateTo,
193
194    /// Requests a font to be sent to the given callback/receiver.
195    pub get_font: RawFontGet,
196
197    /// Releases a callback/receiver from a specific font.
198    pub release_font: RawFontRelease,
199
200    /// Adds a font from disk and sends updates to the callback.
201    pub add_font_from_file: RawFontAddFromFile,
202
203    /// Adds a font from an embedded resource and sends updates to the callback.
204    pub add_font_from_resource: RawFontAddFromResource,
205
206    /// Adds a font from memory and sends updates to the callback.
207    pub add_font_from_memory: RawFontAddFromMemory,
208}
209
210unsafe impl Sync for AddonApi {}
211
212unsafe impl Send for AddonApi {}
213
214impl AddonApi {
215    /// Nexus Addon API version.
216    pub const VERSION: i32 = 4;
217
218    /// Retrieves the DirectX 11 device associated with the swap chain.
219    #[inline]
220    pub fn get_d3d11_device(&self) -> Option<ID3D11Device> {
221        unsafe { self.swap_chain.GetDevice() }.ok()
222    }
223}