renamed field getters, unsafe cast

- renamed field getter functions to just the field, and field_mut for &mut
getters
- made casting `unsafe` to make sure it explicitly is checked each time
- fixed injected types being NonNull<T>
This commit is contained in:
Janis 2023-04-22 02:13:14 +02:00
parent ab27f8ba82
commit 0987e57963
2 changed files with 13 additions and 7 deletions

View file

@ -255,6 +255,12 @@ pub mod par_iter {
} }
} }
pub trait FindObject<Object> {
fn find_object<S>(&self, object_name: S) -> Option<Object>
where
S: Into<String>;
}
pub trait FindClass { pub trait FindClass {
fn find_class<S>(&self, class_name: S) -> Option<v2_types::UClass> fn find_class<S>(&self, class_name: S) -> Option<v2_types::UClass>
where where

View file

@ -268,7 +268,7 @@ pub fn generate_class_impl<W: Write>(class: &Class, sdk: &Sdk, w: &mut W) -> any
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 get_{}(&self) -> &", field.name)?; write!(w, "fn {}(&self) -> &", field.name)?;
field.ty.rust_type(sdk, w)?; field.ty.rust_type(sdk, w)?;
writeln!( writeln!(
w, w,
@ -276,7 +276,7 @@ pub fn generate_class_impl<W: Write>(class: &Class, sdk: &Sdk, w: &mut W) -> any
field.offset field.offset
)?; )?;
write!(w, "fn get_{}_mut(&mut self) -> &mut ", field.name)?; write!(w, "fn {}_mut(&mut self) -> &mut ", field.name)?;
field.ty.rust_type(sdk, w)?; field.ty.rust_type(sdk, w)?;
writeln!( writeln!(
w, w,
@ -346,7 +346,7 @@ fn generate_find_object<W: Write>(name: &str, w: &mut W) -> anyhow::Result<()> {
None None
}} }}
}} }}
}}).map(|object| object.cast()) }}).map(|object| unsafe {{ object.cast() }})
}} }}
"# "#
)?; )?;
@ -406,7 +406,7 @@ pub fn generate_method<W: Write>(
} }
} }
writeln!(w, "let flags = *func.get_function_flags();")?; writeln!(w, "let flags = *func.function_flags();")?;
writeln!(w, "process_event(self.as_uobject(), func, &mut params);")?; writeln!(w, "process_event(self.as_uobject(), func, &mut params);")?;
writeln!(w, "func.set_function_flags(flags);")?; writeln!(w, "func.set_function_flags(flags);")?;
@ -554,7 +554,7 @@ pub(crate) fn inject_coreuobject_types(sdk: &mut Sdk) {
offset: 16, offset: 16,
size: 8, size: 8,
name: "class".to_string(), name: "class".to_string(),
ty: Type::Primitive(PrimitiveType::Custom("Option<NonNull<UClass>>")), ty: Type::Primitive(PrimitiveType::Custom("Option<UClass>")),
}, },
ClassField { ClassField {
offset: 24, offset: 24,
@ -566,7 +566,7 @@ pub(crate) fn inject_coreuobject_types(sdk: &mut Sdk) {
offset: 32, offset: 32,
size: 8, size: 8,
name: "outer".to_string(), name: "outer".to_string(),
ty: Type::Primitive(PrimitiveType::Custom("Option<NonNull<UObject>>")), ty: Type::Primitive(PrimitiveType::Custom("Option<UObject>")),
}, },
], ],
methods: vec![], methods: vec![],
@ -583,7 +583,7 @@ pub(crate) fn inject_coreuobject_types(sdk: &mut Sdk) {
offset: 40, offset: 40,
size: 8, size: 8,
name: "next".to_string(), name: "next".to_string(),
ty: Type::Primitive(PrimitiveType::Custom("Option<NonNull<UField>>")), ty: Type::Primitive(PrimitiveType::Custom("Option<UField>")),
}], }],
methods: vec![], methods: vec![],
}; };