nexus/
addon.rs

1//! Addon information.
2
3use crate::api::AddonApi;
4use bitflags::bitflags;
5use std::ffi::c_char;
6
7/// Addon definition.
8#[derive(Debug, Clone)]
9#[repr(C)]
10pub struct AddonDefinition {
11    /// Raidcore addon id or random unique negative integer, if not on Raidcore.
12    pub signature: i32,
13
14    /// Determines which [`AddonApi`] struct revision the Loader will pass.
15    pub api_version: i32,
16
17    /// Name of the addon.
18    pub name: *const c_char,
19
20    /// Version of the addon.
21    pub version: AddonVersion,
22
23    /// Author of the addon.
24    pub author: *const c_char,
25
26    /// Short addon description.
27    pub description: *const c_char,
28
29    /// Load function of the addon.
30    pub load: RawAddonLoad,
31
32    /// Unload function of the addon.
33    ///
34    /// Not required if [`AddonFlags::DisableHotloading`] is set.
35    pub unload: Option<RawAddonUnload>,
36
37    /// Information about the addon
38    pub flags: AddonFlags,
39
40    /// What platform is the the addon hosted on.
41    pub provider: UpdateProvider,
42
43    /// Link to the update resource.
44    pub update_link: *const c_char,
45}
46
47unsafe impl Send for AddonDefinition {}
48
49unsafe impl Sync for AddonDefinition {}
50
51pub type AddonLoad = fn();
52
53pub type AddonUnload = fn();
54
55pub type RawAddonLoad = unsafe extern "C-unwind" fn(api: *const AddonApi);
56
57pub type RawAddonUnload = unsafe extern "C-unwind" fn();
58
59/// Addon version.
60#[derive(Debug, Clone)]
61#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
62#[repr(C)]
63pub struct AddonVersion {
64    pub major: i16,
65    pub minor: i16,
66    pub build: i16,
67    pub revision: i16,
68}
69
70bitflags! {
71    /// Addon flags.
72    #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
73    #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
74    pub struct AddonFlags: u32 {
75        const None = 0;
76
77        /// Hooking functions or doing anything else that is volatile and game build dependant.
78        const IsVolatile = 1;
79
80        /// Prevents unloading at runtime. Will require a restart if updated, etc.
81        const DisableHotloading = 2;
82
83        /// Prevents loading the addon later than the initial character select.
84        const OnlyLoadDuringGameLaunchSequence = 4;
85    }
86}
87
88/// Addon update provider.
89// TODO: rust enum encapsulating provider & link?
90#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
91#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
92#[cfg_attr(
93    feature = "strum",
94    derive(
95        strum::AsRefStr,
96        strum::Display,
97        strum::EnumCount,
98        strum::EnumIter,
99        strum::IntoStaticStr,
100        strum::VariantArray,
101        strum::VariantNames
102    )
103)]
104#[repr(C)]
105pub enum UpdateProvider {
106    /// Does not support auto updating.
107    None = 0,
108
109    /// Raidcore via API.
110    Raidcore = 1,
111
112    /// GitHub releases.
113    GitHub = 2,
114
115    /// Direct file link.
116    Direct = 3,
117
118    /// Manual updating.
119    ///
120    /// Addon has to check versions itself and request updates manually.
121    Manual = 4,
122}