idkkkkkkkkkkkkkkk

This commit is contained in:
Janis 2023-05-23 00:29:19 +02:00
parent 1e059a3b92
commit b1bf442a27
2 changed files with 60 additions and 33 deletions

View file

@ -34,12 +34,13 @@ pub mod sdk {
actor_static_class, actor_static_class,
any_type::{self, AnyField, AnyObject, AnyProperty, AnyStruct}, any_type::{self, AnyField, AnyObject, AnyProperty, AnyStruct},
traits::{ traits::{
AsUObject, StaticClass, UArrayPropertyTrait, UBytePropertyTrait, AsUObject, StaticClass, UArrayPropertyTrait, UBoolPropertyTrait,
UEnumPropertyTrait, UEnumTrait, UFunctionTrait, UObjectNonConst, UBytePropertyTrait, UEnumPropertyTrait, UEnumTrait, UFunctionTrait,
UObjectPropertyBaseTrait, UObjectTrait, UPropertyTrait, UStructNonConst, UObjectNonConst, UObjectPropertyBaseTrait, UObjectTrait, UPropertyTrait,
UStructPropertyTrait, UStructTrait, 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(_) => { AnyProperty::Interface(_) => {
return Err(anyhow::anyhow!("skipping interfaces for now")) return Err(anyhow::anyhow!("skipping interfaces for now"))
} }
@ -748,7 +749,7 @@ pub mod sdk {
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
pub enum PrimitiveType { pub enum PrimitiveType {
Bool, Bool(UBoolProperty),
U8, U8,
U16, U16,
U32, U32,

View file

@ -12,7 +12,7 @@ use crate::{
Sdk, Type, Types, Sdk, Type, Types,
}, },
v2_types::{ v2_types::{
traits::{AsUObject, UObjectNonConst, UStructNonConst}, traits::{AsUObject, UBoolPropertyTrait, UObjectNonConst, UStructNonConst},
UObject, UObject,
}, },
}; };
@ -87,7 +87,7 @@ impl RustType for Type {
w, w,
"{}", "{}",
match ty { match ty {
PrimitiveType::Bool => "bool", PrimitiveType::Bool(_) => "bool",
PrimitiveType::U8 => "u8", PrimitiveType::U8 => "u8",
PrimitiveType::U16 => "u16", PrimitiveType::U16 => "u16",
PrimitiveType::U32 => "u32", PrimitiveType::U32 => "u32",
@ -292,32 +292,58 @@ pub fn generate_class_impl<W: Write>(class: &Class, sdk: &Sdk, w: &mut W) -> any
let name = class.rust_name(); let name = class.rust_name();
// FIELDS
writeln!(w, "pub trait {}Fields: AsPtr {{", name)?; writeln!(w, "pub trait {}Fields: AsPtr {{", name)?;
for field in fields { for field in fields {
write!(w, "fn {}(&self) -> &", field.name)?; // need to handle bools in a special way because they might be bitfields
field.ty.rust_type(sdk, w)?;
writeln!(
w,
" {{unsafe {{ &*self.as_ptr().offset({}).cast() }} }}",
field.offset
)?;
write!(w, "fn {}_mut(&mut self) -> &mut ", field.name)?; match field.ty {
field.ty.rust_type(sdk, w)?; Type::Primitive(PrimitiveType::Bool(prop)) if *prop.byte_mask() != 0xff => {
writeln!( write!(w, "fn {}(&self) -> bool", field.name)?;
w, writeln!(
" {{unsafe {{ &mut *self.as_mut_ptr().offset({}).cast() }} }}", w,
field.offset " {{unsafe {{ *self.as_ptr().offset({}) & (1u8 << {}u8) != 0 }} }}",
)?; field.offset,
prop.field_mask().trailing_zeros(),
)?;
write!(w, "fn set_{0}(&mut self, {0}: ", field.name)?; write!(w, "fn set_{0}(&mut self, {0}: bool", field.name)?;
field.ty.rust_type(sdk, w)?; write!(w, ") -> ()")?;
write!(w, ") -> ()")?; writeln!(
writeln!( w,
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); }} }} }}",
" {{*unsafe {{ &mut *self.as_mut_ptr().offset({}).cast() }} = {}; }}", field.offset,
field.offset, field.name field.name,
)?; prop.field_mask().trailing_zeros(),
)?;
}
_ => {
write!(w, "fn {}(&self) -> &", field.name)?;
field.ty.rust_type(sdk, w)?;
writeln!(
w,
" {{unsafe {{ &*self.as_ptr().offset({}).cast() }} }}",
field.offset
)?;
write!(w, "fn set_{0}(&mut self, {0}: ", field.name)?;
field.ty.rust_type(sdk, w)?;
write!(w, ") -> ()")?;
writeln!(
w,
" {{*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, "}}")?;
writeln!(w, "impl {name}Fields for {name} {{}}")?; 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(); static OBJECT: OnceCell<Option<UObject>> = OnceCell::new();
OBJECT.get_or_init(|| {{ OBJECT.get_or_init(|| {{
match find_object("{name}") {{ match find_object(obfstr::obfstr!("{name}")) {{
Some(class) => {{Some(class)}}, Some(class) => {{Some(class)}},
None => {{ None => {{
log::error!("static object {name} not found!"); log::error!("{{}}", obfstr::obfstr!("static object {name} not found!"));
None None
}} }}
}} }}