idkkkkkkkkkkkkkkk
This commit is contained in:
parent
1e059a3b92
commit
b1bf442a27
15
src/lib.rs
15
src/lib.rs
|
@ -34,12 +34,13 @@ pub mod sdk {
|
|||
actor_static_class,
|
||||
any_type::{self, AnyField, AnyObject, AnyProperty, AnyStruct},
|
||||
traits::{
|
||||
AsUObject, StaticClass, UArrayPropertyTrait, UBytePropertyTrait,
|
||||
UEnumPropertyTrait, UEnumTrait, UFunctionTrait, UObjectNonConst,
|
||||
UObjectPropertyBaseTrait, UObjectTrait, UPropertyTrait, UStructNonConst,
|
||||
UStructPropertyTrait, UStructTrait,
|
||||
AsUObject, StaticClass, UArrayPropertyTrait, UBoolPropertyTrait,
|
||||
UBytePropertyTrait, UEnumPropertyTrait, UEnumTrait, UFunctionTrait,
|
||||
UObjectNonConst, UObjectPropertyBaseTrait, UObjectTrait, UPropertyTrait,
|
||||
UStructNonConst, UStructPropertyTrait, UStructTrait,
|
||||
},
|
||||
EFunctionFlags, EPropertyFlags, UClass, UEnum, UFunction, UObject, UStruct,
|
||||
EFunctionFlags, EPropertyFlags, UBoolProperty, UClass, UEnum, UFunction, UObject,
|
||||
UStruct,
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -237,7 +238,7 @@ pub mod sdk {
|
|||
}
|
||||
}
|
||||
}
|
||||
AnyProperty::Bool(_) => Type::Primitive(PrimitiveType::Bool),
|
||||
AnyProperty::Bool(prop) => Type::Primitive(PrimitiveType::Bool(prop)),
|
||||
AnyProperty::Interface(_) => {
|
||||
return Err(anyhow::anyhow!("skipping interfaces for now"))
|
||||
}
|
||||
|
@ -748,7 +749,7 @@ pub mod sdk {
|
|||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum PrimitiveType {
|
||||
Bool,
|
||||
Bool(UBoolProperty),
|
||||
U8,
|
||||
U16,
|
||||
U32,
|
||||
|
|
|
@ -12,7 +12,7 @@ use crate::{
|
|||
Sdk, Type, Types,
|
||||
},
|
||||
v2_types::{
|
||||
traits::{AsUObject, UObjectNonConst, UStructNonConst},
|
||||
traits::{AsUObject, UBoolPropertyTrait, UObjectNonConst, UStructNonConst},
|
||||
UObject,
|
||||
},
|
||||
};
|
||||
|
@ -87,7 +87,7 @@ impl RustType for Type {
|
|||
w,
|
||||
"{}",
|
||||
match ty {
|
||||
PrimitiveType::Bool => "bool",
|
||||
PrimitiveType::Bool(_) => "bool",
|
||||
PrimitiveType::U8 => "u8",
|
||||
PrimitiveType::U16 => "u16",
|
||||
PrimitiveType::U32 => "u32",
|
||||
|
@ -292,8 +292,32 @@ pub fn generate_class_impl<W: Write>(class: &Class, sdk: &Sdk, w: &mut W) -> any
|
|||
|
||||
let name = class.rust_name();
|
||||
|
||||
// FIELDS
|
||||
writeln!(w, "pub trait {}Fields: AsPtr {{", name)?;
|
||||
for field in fields {
|
||||
// need to handle bools in a special way because they might be bitfields
|
||||
|
||||
match field.ty {
|
||||
Type::Primitive(PrimitiveType::Bool(prop)) if *prop.byte_mask() != 0xff => {
|
||||
write!(w, "fn {}(&self) -> bool", field.name)?;
|
||||
writeln!(
|
||||
w,
|
||||
" {{unsafe {{ *self.as_ptr().offset({}) & (1u8 << {}u8) != 0 }} }}",
|
||||
field.offset,
|
||||
prop.field_mask().trailing_zeros(),
|
||||
)?;
|
||||
|
||||
write!(w, "fn set_{0}(&mut self, {0}: bool", field.name)?;
|
||||
write!(w, ") -> ()")?;
|
||||
writeln!(
|
||||
w,
|
||||
" {{unsafe {{ if {1} {{ *self.as_mut_ptr().offset({0}) |= ({1} as u8) << {2}u8; }} else {{ *self.as_mut_ptr().offset({0}) &= !(({1} as u8) << {2}u8); }} }} }}",
|
||||
field.offset,
|
||||
field.name,
|
||||
prop.field_mask().trailing_zeros(),
|
||||
)?;
|
||||
}
|
||||
_ => {
|
||||
write!(w, "fn {}(&self) -> &", field.name)?;
|
||||
field.ty.rust_type(sdk, w)?;
|
||||
writeln!(
|
||||
|
@ -302,14 +326,6 @@ pub fn generate_class_impl<W: Write>(class: &Class, sdk: &Sdk, w: &mut W) -> any
|
|||
field.offset
|
||||
)?;
|
||||
|
||||
write!(w, "fn {}_mut(&mut self) -> &mut ", field.name)?;
|
||||
field.ty.rust_type(sdk, w)?;
|
||||
writeln!(
|
||||
w,
|
||||
" {{unsafe {{ &mut *self.as_mut_ptr().offset({}).cast() }} }}",
|
||||
field.offset
|
||||
)?;
|
||||
|
||||
write!(w, "fn set_{0}(&mut self, {0}: ", field.name)?;
|
||||
field.ty.rust_type(sdk, w)?;
|
||||
write!(w, ") -> ()")?;
|
||||
|
@ -318,6 +334,16 @@ pub fn generate_class_impl<W: Write>(class: &Class, sdk: &Sdk, w: &mut W) -> any
|
|||
" {{*unsafe {{ &mut *self.as_mut_ptr().offset({}).cast() }} = {}; }}",
|
||||
field.offset, field.name
|
||||
)?;
|
||||
|
||||
write!(w, "fn {}_mut(&mut self) -> &mut ", field.name)?;
|
||||
field.ty.rust_type(sdk, w)?;
|
||||
writeln!(
|
||||
w,
|
||||
" {{unsafe {{ &mut *self.as_mut_ptr().offset({}).cast() }} }}",
|
||||
field.offset
|
||||
)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
writeln!(w, "}}")?;
|
||||
writeln!(w, "impl {name}Fields for {name} {{}}")?;
|
||||
|
@ -365,10 +391,10 @@ fn generate_find_object<W: Write>(name: &str, w: &mut W) -> anyhow::Result<()> {
|
|||
{{
|
||||
static OBJECT: OnceCell<Option<UObject>> = OnceCell::new();
|
||||
OBJECT.get_or_init(|| {{
|
||||
match find_object("{name}") {{
|
||||
match find_object(obfstr::obfstr!("{name}")) {{
|
||||
Some(class) => {{Some(class)}},
|
||||
None => {{
|
||||
log::error!("static object {name} not found!");
|
||||
log::error!("{{}}", obfstr::obfstr!("static object {name} not found!"));
|
||||
None
|
||||
}}
|
||||
}}
|
||||
|
|
Loading…
Reference in a new issue