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