commonlibsse_ng\re\b/
BSInputDeviceManager.rs

1use crate::re::BSFixedString::BSFixedString;
2use crate::re::BSIInputDevice::BSIInputDevice;
3use crate::re::BSTEvent::BSTEventSource;
4use crate::re::InputDevices::INPUT_DEVICE;
5use crate::re::InputEvent::InputEvent;
6
7#[repr(C)]
8#[derive(Debug)]
9pub struct BSInputDeviceManager {
10    pub __base: BSTEventSource<*mut InputEvent>, // 0x000
11    // pub __base1: BSTSingletonSDM<BSInputDeviceManager>, // Empty base optimization -> 0 size
12    //
13    #[allow(unused)]
14    pad59: u8, // 0x059
15    #[allow(unused)]
16    pad5A: u16, // 0x05A
17    #[allow(unused)]
18    pad5C: u32, // 0x05C
19
20    pub devices: [*mut BSIInputDevice; 4], // 0x060
21}
22const _: () = assert!(core::mem::size_of::<BSInputDeviceManager>() == 0x80);
23
24impl BSInputDeviceManager {
25    /// Gets the singleton instance of `ControlMap`.
26    #[commonlibsse_ng_derive_internal::relocate(
27        cast_as = "*mut *mut BSInputDeviceManager",
28        default = "None",
29        deref_once,
30        id(se = 516574, ae = 402776)
31    )]
32    pub fn get_singleton() -> Option<&'static BSInputDeviceManager> {
33        |deref_type: DerefType| unsafe { deref_type.as_ref() }
34    }
35
36    /// Gets the mutable singleton instance of `BSInputDeviceManager`.
37    #[commonlibsse_ng_derive_internal::relocate(
38        cast_as = "*mut *mut BSInputDeviceManager",
39        default = "None",
40        deref_once,
41        id(se = 516574, ae = 402776)
42    )]
43    pub fn get_singleton_mut() -> Option<&'static mut BSInputDeviceManager> {
44        |deref_type: DerefType| unsafe { deref_type.as_mut() }
45    }
46
47    // TODO: `&mut self` permission need really?(currently propagate vtable definition)
48    #[inline]
49    pub fn get_button_name_from_id(
50        &mut self,
51        device: INPUT_DEVICE,
52        id: u32,
53    ) -> Option<BSFixedString> {
54        let device = unsafe { self.devices.get_mut(device.0 as usize)?.as_mut() }?;
55
56        let mut output = BSFixedString::new(c"");
57        unsafe { (device.vtable.as_ref()?.GetKeyMapping)(device, id, &mut output) };
58        Some(output)
59    }
60}