this kinda works
Some checks failed
CI / Rust checks (push) Failing after 1m17s
Security / Audit (push) Failing after 7m24s

This commit is contained in:
2024-10-20 19:44:04 +02:00
parent c50bb6c344
commit 54f84ed7af
7 changed files with 387 additions and 22 deletions

View File

@@ -32,6 +32,7 @@ fn main() {
.allowlist_function("SimConnect_Open")
.allowlist_function("SimConnect_RemoveClientEvent")
.allowlist_function("SimConnect_RequestDataOnSimObject")
.allowlist_function("SimConnect_SetDataOnSimObject")
.allowlist_function("SimConnect_RequestFacilitiesList")
.allowlist_function("SimConnect_SetNotificationGroupPriority")
.allowlist_function("SimConnect_SubscribeToFacilities")

View File

@@ -109,4 +109,47 @@ impl SimConnect {
)
})
}
pub fn set_data_on_sim_object<T>(&self, obj: &mut T) -> Result<(), SimConnectError> {
let type_name: String = std::any::type_name::<T>().into();
let request_id = self
.registered_objects
.get(&type_name)
.ok_or_else(|| SimConnectError::ObjectNotRegistered(type_name.clone()))?;
success!(unsafe {
bindings::SimConnect_SetDataOnSimObject(
self.handle.as_ptr(),
request_id.id,
bindings::SIMCONNECT_OBJECT_ID_USER,
Condition::None.into(),
0,
size_of::<T>().try_into().unwrap(),
obj as *mut _ as *mut std::ffi::c_void,
)
})
}
pub fn set_data_on_sim_object_with_id<T>(
&self,
request_id: u32,
obj: &mut T,
) -> Result<(), SimConnectError> {
// Strings require to be something specific, so until we can figure out how to
// convert the strings "on-the-fly"
// we'll use the packed variant of the struct, but it'll need a custom request_id
success!(unsafe {
bindings::SimConnect_SetDataOnSimObject(
self.handle.as_ptr(),
request_id,
bindings::SIMCONNECT_OBJECT_ID_USER,
Condition::None.into(),
0,
size_of::<T>().try_into().unwrap(),
obj as *mut _ as *mut std::ffi::c_void,
)
})
}
}