diff --git a/sdk-builder/src/main.rs b/sdk-builder/src/main.rs index 5f6b0b4..a3dc775 100644 --- a/sdk-builder/src/main.rs +++ b/sdk-builder/src/main.rs @@ -309,32 +309,32 @@ pub mod rust { } Type::WeakPtr(inner) => { format!( - "::crate::engine::TWeakObjectPtr<{}>", + "crate::engine::TWeakObjectPtr<{}>", self.get_type_path(inner) .context("type name was not cached.")? ) } Type::SoftPtr(inner) => { format!( - "::crate::engine::TSoftObjectPtr<{}>", + "crate::engine::TSoftObjectPtr<{}>", self.get_type_path(inner) .context("type name was not cached.")? ) } Type::LazyPtr(inner) => { format!( - "::crate::engine::TLazyObjectPtr<{}>", + "crate::engine::TLazyObjectPtr<{}>", self.get_type_path(inner) .context("type name was not cached.")? ) } Type::AssetPtr(inner) => format!( - "::crate::engine::TAssetPtr<{}>", + "crate::engine::TAssetPtr<{}>", self.get_type_path(inner) .context("type name was not cached.")? ), Type::Array(inner) => { - format!("::crate::engine::TArray<{}>", self.type_name(&inner)?) + format!("crate::engine::TArray<{}>", self.type_name(&inner)?) } Type::Primitive(prim) => { format!("{prim}") @@ -342,9 +342,9 @@ pub mod rust { Type::RawArray { ty, len } => { format!("[{}; {}]", self.type_name(&ty)?, len) } - Type::Name => "::crate::engine::FName".to_string(), - Type::String => "::crate::engine::FString".to_string(), - Type::Text => "::crate::engine::FText".to_string(), + Type::Name => "crate::engine::FName".to_string(), + Type::String => "crate::engine::FString".to_string(), + Type::Text => "crate::engine::FText".to_string(), Type::Enum { enum_type, .. } => self .get_type_path(enum_type) .context("type name was not cached.")?, @@ -403,17 +403,17 @@ pub mod rust { let static_class_impl: TokenStream = Self::generate_find_object(name); let impls = quote! { - impl AsUObject for #name { - fn as_uobject(&self) -> UObject { - UObject(self.0) + impl crate::engine::AsUObject for #name { + fn as_uobject(&self) -> crate::engine::UObject { + crate::engine::UObject(self.0) } - fn from_uobject(obj: &UObject) -> Self { + fn from_uobject(obj: &crate::engine::UObject) -> Self { Self(obj.0) } } - impl AsPtr for #name { + impl crate::engine::AsPtr for #name { fn as_ptr(&self) -> *const u8 { unsafe { self.0.as_ref().get() as _ } } @@ -423,9 +423,10 @@ pub mod rust { } } - impl StaticClass for #name { - fn get_static_class() -> Option { - let class: Option = #static_class_impl; + impl crate::engine::StaticClass for #name { + fn get_static_class() -> ::core::option::Option { + let class: ::core::option::Option = + #static_class_impl; class } } @@ -462,7 +463,7 @@ pub mod rust { } } - impl AsPtr for #name { + impl crate::engine::AsPtr for #name { fn as_ptr(&self) -> *const u8 { self.0.get().cast() } @@ -693,6 +694,8 @@ pub mod rust { }); // FIXME: handle super struct fields aswell, ARK doesnt seem to have those anyways. + // export getting fields into a seperate function, this function will be fallible then. + // it is a lot of work for nothing currently. quote! { pub fn new(#(#fields_defs),*) -> Self { @@ -762,6 +765,23 @@ pub mod rust { } } + fn iter_super_types(&self, class: &Class) -> impl Iterator { + let super_traits = core::iter::from_fn({ + let mut sup = class.super_class; + move || { + if let Some(key) = sup { + let next = self.sdk.get_object(&key); + sup = next.and_then(|next| next.super_class()); + next + } else { + None + } + } + }); + + super_traits + } + fn generate_class(&self, class: &Class) -> anyhow::Result { let name = &self .get_type_name(&class.obj_ref) @@ -788,29 +808,26 @@ pub mod rust { impl #method_trait for #name {} }; - let mut sup = class.super_class; - let super_traits = core::iter::from_fn(|| { - if let Some(key) = sup { - let next = self.sdk.get_object(&key); - sup = next.and_then(|next| next.super_class()); - next - } else { - None - } - }) - // SAFETY: we already got this type by its obj_ref, so it must be there. - .map(|ty| self.get_type_path(&ty.obj_ref()).unwrap()) - .map(|super_name| { - let fields = format_ident!("{super_name}Fields"); - let methods = format_ident!("{super_name}Methods"); + let super_traits = self + .iter_super_types(class) + // SAFETY: we already got this type by its obj_ref, so it must be there. + .map(|ty| { + ( + self.get_type_package_path(&ty.obj_ref()).unwrap(), + self.get_type_name(&ty.obj_ref()).unwrap(), + ) + }) + .map(|(super_path, super_name)| { + let fields = format_ident!("{super_name}Fields"); + let methods = format_ident!("{super_name}Methods"); - quote! { - impl #fields for #name {} - impl #methods for #name {} - } - }); + quote! { + impl #super_path::#fields for #name {} + impl #super_path::#methods for #name {} + } + }); - quote! { + let tokens = quote! { #[repr(transparent)] #[derive(Debug)] #typedef