use crate::ffi;
use core::ffi::CStr;
use core::mem::MaybeUninit;
pub struct OwnedWte(ffi::wte_handle);
impl OwnedWte {
pub unsafe fn from_handle(handle: ffi::wte_handle) -> Self {
Self(handle)
}
pub unsafe fn load_from_rom<C: AsRef<CStr>>(path: C, malloc_flags: u32) -> Self {
let mut handle = MaybeUninit::uninit();
ffi::LoadWteFromRom(handle.as_mut_ptr(), path.as_ref().as_ptr(), malloc_flags);
Self(handle.assume_init())
}
pub unsafe fn load_from_dir(pack_file_id: u16, file_index: u16, malloc_flags: u32) -> Self {
let mut handle = MaybeUninit::uninit();
ffi::LoadWteFromFileDirectory(handle.as_mut_ptr(), pack_file_id, file_index, malloc_flags);
Self(handle.assume_init())
}
}
impl Drop for OwnedWte {
fn drop(&mut self) {
unsafe {
ffi::UnloadWte(&mut self.0);
}
}
}