Skip to main content

rusteal_ffi/
handles.rs

1use std::ffi::c_void;
2
3macro_rules! define_ptr_handle {
4    ($(#[$meta:meta])* $name:ident) => {
5        $(#[$meta])*
6        #[repr(transparent)]
7        #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
8        pub struct $name(pub *mut c_void);
9
10        impl $name {
11            pub fn is_null(&self) -> bool {
12                self.0.is_null()
13            }
14
15            pub fn null() -> Self {
16                Self(std::ptr::null_mut())
17            }
18
19            pub fn from_addr(addr: u64) -> Self {
20                Self(addr as usize as *mut c_void)
21            }
22
23            pub fn to_addr(&self) -> u64 {
24                self.0 as usize as u64
25            }
26        }
27    };
28}
29
30define_ptr_handle! {
31    UObjectHandle
32}
33
34define_ptr_handle! {
35    UClassHandle
36}
37
38define_ptr_handle! {
39    FPropertyHandle
40}
41
42define_ptr_handle! {
43    UFunctionHandle
44}
45
46define_ptr_handle! {
47    UStructHandle
48}
49
50#[repr(transparent)]
51#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Default)]
52pub struct FNameHandle(pub u64);
53
54#[repr(C)]
55#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
56pub struct FWeakObjectHandle {
57    pub object_index: i32,
58    pub object_serial_number: i32,
59}
60
61impl Default for FWeakObjectHandle {
62    fn default() -> Self {
63        FWeakObjectHandle {
64            object_index: -1,
65            object_serial_number: 0,
66        }
67    }
68}
69
70unsafe impl Send for UObjectHandle {}
71unsafe impl Sync for UObjectHandle {}
72unsafe impl Send for UClassHandle {}
73unsafe impl Sync for UClassHandle {}
74unsafe impl Send for FPropertyHandle {}
75unsafe impl Sync for FPropertyHandle {}
76unsafe impl Send for UFunctionHandle {}
77unsafe impl Sync for UFunctionHandle {}
78unsafe impl Send for UStructHandle {}
79unsafe impl Sync for UStructHandle {}
80unsafe impl Send for FWeakObjectHandle {}
81unsafe impl Sync for FWeakObjectHandle {}