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