use crate::api;
use std::os::raw::c_void;
use std::slice;
#[repr(C)]
#[derive(Debug, Clone)]
pub struct Il2cppString {
pub klass: *mut c_void,
pub monitor: *mut c_void,
pub length: i32,
pub chars: [u16; 1],
}
impl Il2cppString {
pub fn to_string(&self) -> Option<String> {
let len = self.length as usize;
unsafe {
let slice = slice::from_raw_parts(self.chars.as_ptr(), len);
String::from_utf16(slice).ok()
}
}
pub fn new(s: &str) -> *mut Il2cppString {
let c_str = std::ffi::CString::new(s).unwrap();
unsafe { api::string_new(c_str.as_ptr()) as *mut Il2cppString }
}
}