commonlibsse_ng\re\n/
NiObject.rs

1use crate::re::NiRTTI::NiRTTI;
2use crate::re::NiRefObject::NiRefObject;
3use crate::re::NiRefObject::NiRefObjectVtbl;
4use crate::re::NiSmartPointer::NiPointer;
5use crate::re::offsets_ni_rtti::NiRTTI_NiObject;
6use crate::re::offsets_rtti::RTTI_NiObject;
7use crate::re::offsets_vtable::VTABLE_NiObject;
8use crate::re::{
9    BSDynamicTriShape, BSFadeNode, BSGeometry, BSLines, BSMultiBoundNode, BSSegmentedTriShape,
10    BSSubIndexTriShape, BSTriShape, NiCloningProcess, NiControllerManager, NiGeometry, NiNode,
11    NiObjectGroup, NiParticles, NiStream, NiSwitchNode, NiTriBasedGeom, NiTriShape, NiTriStrips,
12    bhkAttachmentCollisionObject, bhkBlendCollisionObject, bhkLimitedHingeConstraint,
13    bhkNiCollisionObject, bhkRigidBody,
14};
15use crate::rel::ResolvableAddress as _;
16use crate::rel::id::{DataBaseError, VariantID};
17use crate::rel::relocation::Relocation;
18use core::ffi::CStr;
19use core::ptr::NonNull;
20
21#[repr(C)]
22#[derive(Debug)]
23pub struct NiObject {
24    pub __base: NiRefObject,
25}
26const _: () = assert!(core::mem::size_of::<NiObject>() == 0x10);
27
28impl NiObject {
29    pub const RTTI: VariantID = RTTI_NiObject;
30    pub const NI_RTTI: VariantID = NiRTTI_NiObject;
31    pub const VTABLE: [VariantID; 1] = VTABLE_NiObject;
32
33    /// # Errors
34    pub fn get_rtti(&self) -> Result<NonNull<NiRTTI>, DataBaseError> {
35        let rel = Relocation::new(Self::NI_RTTI.address()?);
36        Ok(rel.cast::<NiRTTI>())
37    }
38
39    /// # Safety
40    pub unsafe fn is_equal(&self, other: *mut Self) -> bool {
41        if other.is_null() {};
42
43        let name = match self.get_rtti() {
44            Ok(rtti) => unsafe { rtti.as_ref().get_name() },
45            Err(_) => return false,
46        };
47        let rtti = match unsafe { other.as_ref() } {
48            Some(rtti) => rtti,
49            None => return false,
50        };
51
52        let rtti = match rtti.get_rtti() {
53            Ok(rtti) => rtti,
54            Err(_) => return false,
55        };
56        let other_name = unsafe { rtti.as_ref().get_name() };
57        let self_name = unsafe { CStr::from_ptr(name) };
58        let other_name = unsafe { CStr::from_ptr(other_name) };
59        self_name == other_name
60    }
61
62    #[commonlibsse_ng_derive_internal::relocate_fn(se_id = 68838, ae_id = 70190)]
63    pub unsafe fn process_clone(&self, cloning: &NiCloningProcess) {}
64
65    #[commonlibsse_ng_derive_internal::relocate_fn(se_id = 68839, ae_id = 70191)]
66    pub unsafe fn create_deep_copy(&self, cloning: &NiPointer<NiObject>) {}
67}
68
69impl crate::re::NiSmartPointer::RefCountable for NiObject {
70    #[inline]
71    fn inc_ref_count(&self) {
72        self.__base.inc_ref_count();
73    }
74
75    #[inline]
76    fn dec_ref_count(&mut self) {
77        self.__base.dec_ref_count();
78    }
79}
80
81/// # Virtual member functions info
82/// - fn count: 37
83/// - offset: 37 * 8 = 288(0x128)
84#[repr(C)]
85pub struct NiObjectVtbl {
86    //                                                                                                  | Method count |
87    /// - overrides
88    ///  - destructor
89    pub __base: NiRefObjectVtbl,
90
91    // additional methods
92    pub GetRtti: unsafe extern "C" fn(this: *const NiObject) -> *const NiRTTI, // 0x02
93    pub AsNode: unsafe extern "C" fn(this: *mut NiObject) -> *mut NiNode,      // 0x03
94    pub AsSwitchNode: unsafe extern "C" fn(this: *mut NiObject) -> *mut NiSwitchNode, // 0x04
95    pub AsFadeNode: unsafe extern "C" fn(this: *mut NiObject) -> *mut BSFadeNode, // 0x05
96    pub AsMultiBoundNode: unsafe extern "C" fn(this: *mut NiObject) -> *mut BSMultiBoundNode, // 0x06
97    pub AsGeometry: unsafe extern "C" fn(this: *mut NiObject) -> *mut BSGeometry, // 0x07
98    pub AsTriStrips: unsafe extern "C" fn(this: *mut NiObject) -> *mut NiTriStrips, // 0x08
99    pub AsTriShape: unsafe extern "C" fn(this: *mut NiObject) -> *mut BSTriShape, // 0x09
100    pub AsSegmentedTriShape: unsafe extern "C" fn(this: *mut NiObject) -> *mut BSSegmentedTriShape, // 0x0A
101    pub AsSubIndexTriShape: unsafe extern "C" fn(this: *mut NiObject) -> *mut BSSubIndexTriShape, // 0x0B
102    pub AsDynamicTriShape: unsafe extern "C" fn(this: *mut NiObject) -> *mut BSDynamicTriShape, // 0x0C
103    pub AsNiGeometry: unsafe extern "C" fn(this: *mut NiObject) -> *mut NiGeometry, // 0x0D
104    pub AsNiTriBasedGeom: unsafe extern "C" fn(this: *mut NiObject) -> *mut NiTriBasedGeom, // 0x0E
105    pub AsNiTriShape: unsafe extern "C" fn(this: *mut NiObject) -> *mut NiTriShape, // 0x0F
106    pub AsParticlesGeom: unsafe extern "C" fn(this: *mut NiObject) -> *mut NiParticles, // 0x10
107    pub AsLinesGeom: unsafe extern "C" fn(this: *mut NiObject) -> *mut BSLines,     // 0x11
108    pub AsBhkNiCollisionObject:
109        unsafe extern "C" fn(this: *mut NiObject) -> *mut bhkNiCollisionObject, // 0x12
110    pub AsBhkBlendCollisionObject:
111        unsafe extern "C" fn(this: *mut NiObject) -> *mut bhkBlendCollisionObject, // 0x13
112    pub AsBhkAttachmentCollisionObject:
113        unsafe extern "C" fn(this: *mut NiObject) -> *mut bhkAttachmentCollisionObject, // 0x14
114    pub AsBhkRigidBody: unsafe extern "C" fn(this: *mut NiObject) -> *mut bhkRigidBody, // 0x15
115    pub AsBhkLimitedHingeConstraint:
116        unsafe extern "C" fn(this: *mut NiObject) -> *mut bhkLimitedHingeConstraint, // 0x16
117    pub CreateClone:
118        unsafe extern "C" fn(this: *mut NiObject, cloning: *mut NiCloningProcess) -> *mut NiObject, // 0x17
119    pub LoadBinary: unsafe extern "C" fn(this: *mut NiObject, stream: *mut NiStream), // 0x18
120    pub LinkObject: unsafe extern "C" fn(this: *mut NiObject, stream: *mut NiStream), // 0x19
121    pub RegisterStreamables:
122        unsafe extern "C" fn(this: *mut NiObject, stream: *mut NiStream) -> bool, // 0x1A
123    pub SaveBinary: unsafe extern "C" fn(this: *mut NiObject, stream: *mut NiStream), // 0x1B
124    pub IsEqual: unsafe extern "C" fn(this: *mut NiObject, other: *mut NiObject) -> bool, // 0x1C
125    pub ProcessClone: unsafe extern "C" fn(this: *mut NiObject, cloning: *mut NiCloningProcess), // 0x1D
126    pub PostLinkObject: unsafe extern "C" fn(this: *mut NiObject, stream: *mut NiStream), // 0x1E
127    pub StreamCanSkip: unsafe extern "C" fn(this: *mut NiObject) -> bool,                 // 0x1F
128    pub GetStreamableRtti: unsafe extern "C" fn(this: *const NiObject) -> *const NiRTTI,  // 0x20
129    pub GetBlockAllocationSize: unsafe extern "C" fn(this: *const NiObject) -> u32,       // 0x21
130    pub GetGroup: unsafe extern "C" fn(this: *const NiObject) -> *mut NiObjectGroup,      // 0x22
131    pub SetGroup: unsafe extern "C" fn(this: *mut NiObject, group: *mut NiObjectGroup),   // 0x23
132
133    pub AsNiControllerManager:
134        unsafe extern "C" fn(this: *mut NiObject) -> *mut NiControllerManager, // 0x24
135}
136const _: () = {
137    const FN_COUNT: usize = 37 * core::mem::size_of::<usize>();
138    assert!(core::mem::size_of::<NiObjectVtbl>() == FN_COUNT);
139};