arcdps\extras/version.rs
1use std::ops::RangeInclusive;
2
3/// Helper for version checks.
4#[derive(Debug, Clone)]
5pub struct ExtrasVersion {
6 /// Version of the API.
7 ///
8 /// Gets incremented whenever a function signature or behavior changes in a breaking way.
9 pub api_version: u32,
10
11 /// Highest known version of the [`ExtrasSubscriberInfo`] struct.
12 ///
13 /// Also determines the size of the subscriber info buffer in the init call.
14 /// The buffer is only guaranteed to have enough space for known [`ExtrasSubscriberInfo`] versions.
15 pub max_info_version: u32,
16}
17
18impl ExtrasVersion {
19 /// Supported Unofficial Extras API version.
20 pub const API: u32 = 2;
21
22 /// Range of supported [`ExtrasSubscriberInfo`] versions.
23 pub const SUB_INFO_RANGE: RangeInclusive<u32> = 1..=3;
24
25 /// Minimum supported [`ExtrasSubscriberInfo`] version.
26 pub const MIN_SUB_INFO: u32 = *Self::SUB_INFO_RANGE.start();
27
28 /// Maximum supported [`ExtrasSubscriberInfo`] version.
29 pub const MAX_SUB_INFO: u32 = *Self::SUB_INFO_RANGE.end();
30
31 /// Minimum [`ExtrasSubscriberInfo`] version for message callback.
32 pub const MESSAGE_CALLBACK: u32 = 2;
33
34 /// Minimum [`ExtrasSubscriberInfo`] version for message callback 2.
35 pub const MESSAGE_CALLBACK2: u32 = 3;
36
37 /// Creates new version information.
38 #[inline]
39 pub const fn new(api_version: u32, max_info_version: u32) -> Self {
40 Self {
41 api_version,
42 max_info_version,
43 }
44 }
45
46 /// Checks compatibility with the Unofficial Extras addon.
47 #[inline]
48 pub const fn is_compatible(&self) -> bool {
49 self.api_version == Self::API && self.max_info_version >= Self::MIN_SUB_INFO
50 }
51
52 /// Checks for compatibility and returns the highest supported [`ExtrasSubscriberInfo`] version supported by Unofficial Extras & the bindings.
53 #[inline]
54 pub fn get_version_to_use(&self) -> Option<u32> {
55 self.is_compatible()
56 .then(|| self.max_info_version.min(Self::MAX_SUB_INFO))
57 }
58
59 /// Whether the Unofficial Extras addon supports squad chat message callback.
60 #[inline]
61 pub const fn supports_squad_chat_message(&self) -> bool {
62 self.max_info_version >= Self::MESSAGE_CALLBACK
63 }
64
65 /// Whether the Unofficial Extras addon supports chat message callback 2.
66 #[inline]
67 pub const fn supports_chat_message2(&self) -> bool {
68 self.max_info_version >= Self::MESSAGE_CALLBACK2
69 }
70}