diff --git a/unreal_asset/src/asset.rs b/unreal_asset/src/asset.rs index 6e628f6c..85056040 100644 --- a/unreal_asset/src/asset.rs +++ b/unreal_asset/src/asset.rs @@ -6,6 +6,9 @@ use std::mem::size_of; use byteorder::{ReadBytesExt, WriteBytesExt, BE, LE}; +use unreal_asset_base::flags::EObjectFlags; +use unreal_asset_base::passthrough_archive_reader; +use unreal_asset_base::types::PackageIndexTrait; use unreal_asset_base::{ cast, containers::{Chain, IndexedMap, NameMap, SharedResource}, @@ -16,10 +19,7 @@ use unreal_asset_base::{ error::Error, flags::EPackageFlags, object_version::{ObjectVersion, ObjectVersionUE5}, - reader::{ - ArchiveReader, ArchiveTrait, ArchiveType, ArchiveWriter, PassthroughArchiveReader, - RawReader, RawWriter, - }, + reader::{ArchiveReader, ArchiveTrait, ArchiveType, ArchiveWriter, RawReader, RawWriter}, types::{fname::FNameContainer, FName, GenerationInfo, PackageIndex}, unversioned::Usmap, FNameContainer, Guid, Import, @@ -41,6 +41,281 @@ pub struct ParentClassInfo { pub parent_class_export_name: FName, } +/// UAsset export map entry +#[derive(Default, Debug, Clone, PartialEq, Eq, Hash)] +pub struct UAssetExportMapEntry { + /// Class index + pub class_index: PackageIndex, + /// Super index + pub super_index: PackageIndex, + /// Template index + pub template_index: PackageIndex, + /// Outer index + pub outer_index: PackageIndex, + /// Object name + pub object_name: FName, + /// Object flags + pub object_flags: EObjectFlags, + /// Serialized size + pub serial_size: i64, + /// Serialized offset + pub serial_offset: i64, + /// Is forced export + pub forced_export: bool, + /// Is not for client + pub not_for_client: bool, + /// Is not for server + pub not_for_server: bool, + /// Package guid + pub package_guid: Guid, + /// Is inherited instance + pub is_inherited_instance: bool, + /// Package flags + pub package_flags: u32, + /// Is not always loaded for editor game + pub not_always_loaded_for_editor_game: bool, + /// Is an asset + pub is_asset: bool, + /// Generate public hash + pub generate_public_hash: bool, + /// Public export hash. Interpreted as a global import PackageObjectIndex in UE4 assets + pub public_export_hash: u64, + /// First dependency serialized offset + pub first_export_dependency_offset: i32, + + /// Dependencies that should be serialized before this export is serialized + pub serialization_before_serialization_dependencies: Vec<PackageIndex>, + /// Dependencies that should be created before this export is serialized + pub create_before_serialization_dependencies: Vec<PackageIndex>, + /// Dependencies that should be serialized before this export is created + pub serialization_before_create_dependencies: Vec<PackageIndex>, + /// Dependencies that should be created before this export is created + pub create_before_create_dependencies: Vec<PackageIndex>, +} + +impl UAssetExportMapEntry { + /// Read `UAssetExportMapEntry` from an archive + pub fn read<R: ArchiveReader<PackageIndex>>(archive: &mut R) -> Result<Self, Error> { + let mut entry = UAssetExportMapEntry { + class_index: PackageIndex::new(archive.read_i32::<LE>()?), + super_index: PackageIndex::new(archive.read_i32::<LE>()?), + ..Default::default() + }; + + if archive.get_object_version() >= ObjectVersion::VER_UE4_TemplateIndex_IN_COOKED_EXPORTS { + entry.template_index = PackageIndex::new(archive.read_i32::<LE>()?); + } + + entry.outer_index = PackageIndex::new(archive.read_i32::<LE>()?); + entry.object_name = archive.read_fname()?; + entry.object_flags = EObjectFlags::from_bits(archive.read_u32::<LE>()?) + .ok_or_else(|| Error::invalid_file("Invalid property flags".to_string()))?; + + if archive.get_object_version() < ObjectVersion::VER_UE4_64BIT_EXPORTMAP_SERIALSIZES { + entry.serial_size = archive.read_i32::<LE>()? as i64; + entry.serial_offset = archive.read_i32::<LE>()? as i64; + } else { + entry.serial_size = archive.read_i64::<LE>()?; + entry.serial_offset = archive.read_i64::<LE>()?; + } + + entry.forced_export = archive.read_i32::<LE>()? == 1; + entry.not_for_client = archive.read_i32::<LE>()? == 1; + entry.not_for_server = archive.read_i32::<LE>()? == 1; + + if archive.get_object_version_ue5() < ObjectVersionUE5::REMOVE_OBJECT_EXPORT_PACKAGE_GUID { + entry.package_guid = archive.read_guid()?; + } + + if archive.get_object_version_ue5() >= ObjectVersionUE5::TRACK_OBJECT_EXPORT_IS_INHERITED { + entry.is_inherited_instance = archive.read_i32::<LE>()? == 1; + } + + entry.package_flags = archive.read_u32::<LE>()?; + + if archive.get_object_version() >= ObjectVersion::VER_UE4_LOAD_FOR_EDITOR_GAME { + entry.not_always_loaded_for_editor_game = archive.read_i32::<LE>()? == 1; + } + + if archive.get_object_version() >= ObjectVersion::VER_UE4_COOKED_ASSETS_IN_EDITOR_SUPPORT { + entry.is_asset = archive.read_i32::<LE>()? == 1; + } + + if archive.get_object_version_ue5() >= ObjectVersionUE5::OPTIONAL_RESOURCES { + entry.generate_public_hash = archive.read_i32::<LE>()? == 1; + } + + if archive.get_object_version() + >= ObjectVersion::VER_UE4_PRELOAD_DEPENDENCIES_IN_COOKED_EXPORTS + { + entry.first_export_dependency_offset = archive.read_i32::<LE>()?; + entry.serialization_before_serialization_dependencies = + Vec::with_capacity(archive.read_i32::<LE>()? as usize); + entry.create_before_serialization_dependencies = + Vec::with_capacity(archive.read_i32::<LE>()? as usize); + entry.serialization_before_create_dependencies = + Vec::with_capacity(archive.read_i32::<LE>()? as usize); + entry.create_before_create_dependencies = + Vec::with_capacity(archive.read_i32::<LE>()? as usize); + } + + Ok(entry) + } + + /// Write `UAssetExportMapEntry` to an archive + pub fn write<W: ArchiveWriter<PackageIndex>>( + &self, + archive: &mut W, + serial_size: i64, + serial_offset: i64, + first_export_dependency_offset: i32, + ) -> Result<(), Error> { + archive.write_i32::<LE>(self.class_index.index)?; + archive.write_i32::<LE>(self.super_index.index)?; + + if archive.get_object_version() >= ObjectVersion::VER_UE4_TemplateIndex_IN_COOKED_EXPORTS { + archive.write_i32::<LE>(self.template_index.index)?; + } + + archive.write_i32::<LE>(self.outer_index.index)?; + archive.write_fname(&self.object_name)?; + archive.write_u32::<LE>(self.object_flags.bits())?; + + if archive.get_object_version() < ObjectVersion::VER_UE4_64BIT_EXPORTMAP_SERIALSIZES { + archive.write_i32::<LE>(serial_size as i32)?; + archive.write_i32::<LE>(serial_offset as i32)?; + } else { + archive.write_i64::<LE>(serial_size)?; + archive.write_i64::<LE>(serial_offset)?; + } + + archive.write_i32::<LE>(match self.forced_export { + true => 1, + false => 0, + })?; + archive.write_i32::<LE>(match self.not_for_client { + true => 1, + false => 0, + })?; + archive.write_i32::<LE>(match self.not_for_server { + true => 1, + false => 0, + })?; + + if archive.get_object_version_ue5() < ObjectVersionUE5::REMOVE_OBJECT_EXPORT_PACKAGE_GUID { + archive.write_guid(&self.package_guid)?; + } + + if archive.get_object_version_ue5() >= ObjectVersionUE5::TRACK_OBJECT_EXPORT_IS_INHERITED { + archive.write_i32::<LE>(match self.is_inherited_instance { + true => 1, + false => 0, + })?; + } + + archive.write_u32::<LE>(self.package_flags)?; + + if archive.get_object_version() >= ObjectVersion::VER_UE4_LOAD_FOR_EDITOR_GAME { + archive.write_i32::<LE>(match self.not_always_loaded_for_editor_game { + true => 1, + false => 0, + })?; + } + + if archive.get_object_version() >= ObjectVersion::VER_UE4_COOKED_ASSETS_IN_EDITOR_SUPPORT { + archive.write_i32::<LE>(match self.is_asset { + true => 1, + false => 0, + })?; + } + + if archive.get_object_version_ue5() >= ObjectVersionUE5::OPTIONAL_RESOURCES { + archive.write_i32::<LE>(match self.generate_public_hash { + true => 1, + false => 0, + })?; + } + + if archive.get_object_version() + >= ObjectVersion::VER_UE4_PRELOAD_DEPENDENCIES_IN_COOKED_EXPORTS + { + archive.write_i32::<LE>(first_export_dependency_offset)?; + archive.write_i32::<LE>( + self.serialization_before_serialization_dependencies.len() as i32 + )?; + archive.write_i32::<LE>(self.create_before_serialization_dependencies.len() as i32)?; + archive.write_i32::<LE>(self.serialization_before_create_dependencies.len() as i32)?; + archive.write_i32::<LE>(self.create_before_create_dependencies.len() as i32)?; + } + Ok(()) + } + + /// Convert `UAssetExportMapEntry` to [`BaseExport`] + pub fn to_base_export(self) -> BaseExport<PackageIndex> { + BaseExport { + class_index: self.class_index, + super_index: self.super_index, + template_index: self.template_index, + outer_index: self.outer_index, + object_name: self.object_name, + object_flags: self.object_flags, + serial_size: self.serial_size, + serial_offset: self.serial_offset, + forced_export: self.forced_export, + not_for_client: self.not_for_client, + not_for_server: self.not_for_server, + package_guid: self.package_guid, + is_inherited_instance: self.is_inherited_instance, + package_flags: self.package_flags, + not_always_loaded_for_editor_game: self.not_always_loaded_for_editor_game, + is_asset: self.is_asset, + generate_public_hash: self.generate_public_hash, + public_export_hash: self.public_export_hash, + first_export_dependency_offset: self.first_export_dependency_offset, + serialization_before_serialization_dependencies: self + .serialization_before_serialization_dependencies, + create_before_serialization_dependencies: self.create_before_serialization_dependencies, + serialization_before_create_dependencies: self.serialization_before_create_dependencies, + create_before_create_dependencies: self.create_before_create_dependencies, + } + } + + /// Convert [`BaseExport`] to `UAssetExportMapEntry` + pub fn from_base_export(b: &BaseExport<PackageIndex>) -> Self { + UAssetExportMapEntry { + class_index: b.class_index, + super_index: b.super_index, + template_index: b.template_index, + outer_index: b.outer_index, + object_name: b.object_name.clone(), + object_flags: b.object_flags, + serial_size: b.serial_size, + serial_offset: b.serial_offset, + forced_export: b.forced_export, + not_for_client: b.not_for_client, + not_for_server: b.not_for_server, + package_guid: b.package_guid, + is_inherited_instance: b.is_inherited_instance, + package_flags: b.package_flags, + not_always_loaded_for_editor_game: b.not_always_loaded_for_editor_game, + is_asset: b.is_asset, + generate_public_hash: b.generate_public_hash, + public_export_hash: b.public_export_hash, + first_export_dependency_offset: b.first_export_dependency_offset, + serialization_before_serialization_dependencies: b + .serialization_before_serialization_dependencies + .clone(), + create_before_serialization_dependencies: b + .create_before_serialization_dependencies + .clone(), + serialization_before_create_dependencies: b + .serialization_before_create_dependencies + .clone(), + create_before_create_dependencies: b.create_before_create_dependencies.clone(), + } + } +} + /// Asset header struct AssetHeader { /// Name map offset @@ -73,12 +348,12 @@ struct AssetHeader { pub struct Asset<C: Read + Seek> { /// Raw reader #[container_ignore] - pub raw_reader: RawReader<C>, + pub raw_reader: RawReader<PackageIndex, C>, // parsed data /// Asset info pub info: String, /// Asset data - pub asset_data: AssetData, + pub asset_data: AssetData<PackageIndex>, /// Legacy file version pub legacy_file_version: i32, @@ -124,12 +399,8 @@ pub struct Asset<C: Read + Seek> { gatherable_text_data_count: i32, /// Gatherable text data offset gatherable_text_data_offset: i32, - /// Export count - export_count: i32, /// Exports offset export_offset: i32, - /// Import count - import_count: i32, /// Imports offset import_offset: i32, /// Depends offset @@ -222,9 +493,7 @@ impl<'a, C: Read + Seek> Asset<C> { soft_object_paths_offset: 0, gatherable_text_data_count: 0, gatherable_text_data_offset: 0, - export_count: 0, export_offset: 0, - import_count: 0, import_offset: 0, depends_offset: 0, soft_package_reference_count: 0, @@ -285,9 +554,9 @@ impl<'a, C: Read + Seek> Asset<C> { // read unreal version let file_version = self.read_i32::<LE>()?.try_into()?; - self.asset_data.unversioned = file_version == ObjectVersion::UNKNOWN; + self.asset_data.summary.unversioned = file_version == ObjectVersion::UNKNOWN; - if self.asset_data.unversioned { + if self.asset_data.summary.unversioned { if self.asset_data.object_version == ObjectVersion::UNKNOWN { return Err(Error::invalid_file("Cannot begin serialization of an unversioned asset before an engine version is manually specified".to_string())); } @@ -313,13 +582,13 @@ impl<'a, C: Read + Seek> Asset<C> { } // read file license version - self.asset_data.file_license_version = self.read_i32::<LE>()?; + self.asset_data.summary.file_licensee_version = self.read_i32::<LE>()?; // read custom versions container if self.legacy_file_version <= -2 { // TODO: support for enum-based custom versions - let old_container = self.asset_data.custom_versions.clone(); - self.asset_data.custom_versions = self.read_custom_version_container( + let old_container = self.asset_data.summary.custom_versions.clone(); + self.asset_data.summary.custom_versions = self.read_custom_version_container( self.get_custom_version_serialization_format(), Some(&old_container), )?; @@ -334,7 +603,7 @@ impl<'a, C: Read + Seek> Asset<C> { .ok_or_else(|| Error::no_data("folder_name is None".to_string()))?; // read package flags - self.asset_data.package_flags = EPackageFlags::from_bits(self.read_u32::<LE>()?) + self.asset_data.summary.package_flags = EPackageFlags::from_bits(self.read_u32::<LE>()?) .ok_or_else(|| Error::invalid_file("Invalid package flags".to_string()))?; // read name count and offset @@ -353,9 +622,9 @@ impl<'a, C: Read + Seek> Asset<C> { } // read count and offset for exports, imports, depends, soft package references, searchable names, thumbnail table - self.export_count = self.read_i32::<LE>()?; + self.asset_data.summary.export_count = self.read_i32::<LE>()?; self.export_offset = self.read_i32::<LE>()?; - self.import_count = self.read_i32::<LE>()?; + self.asset_data.summary.import_count = self.read_i32::<LE>()?; self.import_offset = self.read_i32::<LE>()?; self.depends_offset = self.read_i32::<LE>()?; if self.asset_data.object_version >= ObjectVersion::VER_UE4_ADD_STRING_ASSET_REFERENCES_MAP @@ -507,7 +776,6 @@ impl<'a, C: Read + Seek> Asset<C> { /// Add an `Import` pub fn add_import(&mut self, import: Import) -> PackageIndex { let index = -(self.imports.len() as i32) - 1; - let import = import; self.imports.push(import); PackageIndex::new(index) } @@ -552,13 +820,30 @@ impl<'a, C: Read + Seek> Asset<C> { None } + /// Get an import by [`PackageIndex`] + pub fn get_import(&self, index: PackageIndex) -> Option<Import> { + if !index.is_import() { + return None; + } + + let index = -index.index - 1; + if index < 0 || index > self.imports.len() as i32 { + return None; + } + + Some(self.imports[index as usize].clone()) + } + /// Get an export - pub fn get_export(&'a self, index: PackageIndex) -> Option<&'a Export> { + pub fn get_export(&'a self, index: PackageIndex) -> Option<&'a Export<PackageIndex>> { self.asset_data.get_export(index) } /// Get a mutable export reference - pub fn get_export_mut(&'a mut self, index: PackageIndex) -> Option<&'a mut Export> { + pub fn get_export_mut( + &'a mut self, + index: PackageIndex, + ) -> Option<&'a mut Export<PackageIndex>> { self.asset_data.get_export_mut(index) } @@ -590,7 +875,7 @@ impl<'a, C: Read + Seek> Asset<C> { if self.import_offset > 0 { self.seek(SeekFrom::Start(self.import_offset as u64))?; - for _i in 0..self.import_count { + for _i in 0..self.asset_data.summary.import_count { let class_package = self.read_fname()?; let class_name = self.read_fname()?; let outer_index = PackageIndex::new(self.read_i32::<LE>()?); @@ -612,11 +897,11 @@ impl<'a, C: Read + Seek> Asset<C> { } } + let mut export_map = Vec::with_capacity(self.asset_data.summary.export_count as usize); if self.export_offset > 0 { self.seek(SeekFrom::Start(self.export_offset as u64))?; - for _i in 0..self.export_count { - let export = BaseExport::read_export_map_entry(self)?; - self.asset_data.exports.push(export.into()); + for _i in 0..self.asset_data.summary.export_count { + export_map.push(UAssetExportMapEntry::read(self)?); } } @@ -626,14 +911,14 @@ impl<'a, C: Read + Seek> Asset<C> { if self.depends_offset > 0 || depends_offset_zero_version_range.contains(&self.get_object_version()) { - let mut depends_map = Vec::with_capacity(self.export_count as usize); + let mut depends_map = Vec::with_capacity(self.asset_data.summary.export_count as usize); // 4.14-4.15 the depends offset wasnt updated so always serialized as 0 if self.depends_offset > 0 { self.seek(SeekFrom::Start(self.depends_offset as u64))?; } - for _i in 0..self.export_count as usize { + for _i in 0..self.asset_data.summary.export_count as usize { let size = self.read_i32::<LE>()?; let mut data: Vec<i32> = Vec::new(); for _j in 0..size { @@ -666,13 +951,11 @@ impl<'a, C: Read + Seek> Asset<C> { } if self.asset_data.use_event_driven_loader { - for export in &mut self.asset_data.exports { - let unk_export = export.get_base_export_mut(); - + for entry in &mut export_map { self.raw_reader .seek(SeekFrom::Start(self.preload_dependency_offset as u64))?; self.raw_reader.seek(SeekFrom::Current( - unk_export.first_export_dependency_offset as i64 * size_of::<i32>() as i64, + entry.first_export_dependency_offset as i64 * size_of::<i32>() as i64, ))?; let mut read_deps = |list: &mut Vec<PackageIndex>| -> Result<(), Error> { @@ -681,29 +964,41 @@ impl<'a, C: Read + Seek> Asset<C> { } Ok(()) }; - read_deps(&mut unk_export.serialization_before_serialization_dependencies)?; - read_deps(&mut unk_export.create_before_serialization_dependencies)?; - read_deps(&mut unk_export.serialization_before_create_dependencies)?; - read_deps(&mut unk_export.create_before_create_dependencies)?; + read_deps(&mut entry.serialization_before_serialization_dependencies)?; + read_deps(&mut entry.create_before_serialization_dependencies)?; + read_deps(&mut entry.serialization_before_create_dependencies)?; + read_deps(&mut entry.create_before_create_dependencies)?; } self.seek(SeekFrom::Start(self.preload_dependency_offset as u64))?; } - if self.header_offset > 0 && !self.asset_data.exports.is_empty() { - let mut new_exports = Vec::with_capacity(self.asset_data.exports.len()); - for i in 0..self.asset_data.exports.len() { - let export = self.read_export(i)?; - new_exports.push(export); - } + if self.header_offset > 0 && !export_map.is_empty() { + let map_len = export_map.len(); + self.asset_data.exports.reserve(map_len); - self.asset_data.exports = new_exports; + let serial_offsets = export_map + .iter() + .map(|e| e.serial_offset as u64) + .collect::<Vec<_>>(); + + for (i, entry) in export_map.into_iter().enumerate() { + let base_export = entry.to_base_export(); + + let next_starting = match i < (map_len - 1) { + true => serial_offsets[i + 1], + false => self.data_length()? - 4, + }; + + let export = self.read_export(base_export, next_starting)?; + self.asset_data.exports.push(export); + } } Ok(()) } /// Write asset header - fn write_header<Writer: ArchiveWriter>( + fn write_header<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, cursor: &mut Writer, asset_header: &AssetHeader, @@ -712,31 +1007,31 @@ impl<'a, C: Read + Seek> Asset<C> { cursor.write_i32::<LE>(self.legacy_file_version)?; if self.legacy_file_version != 4 { - match self.asset_data.unversioned { + match self.asset_data.summary.unversioned { true => cursor.write_i32::<LE>(0)?, false => cursor.write_i32::<LE>(864)?, }; } - match self.asset_data.unversioned { + match self.asset_data.summary.unversioned { true => cursor.write_i32::<LE>(0)?, false => cursor.write_i32::<LE>(self.asset_data.object_version as i32)?, }; if self.legacy_file_version <= -8 { - match self.asset_data.unversioned { + match self.asset_data.summary.unversioned { true => cursor.write_i32::<LE>(0)?, false => cursor.write_i32::<LE>(self.get_object_version_ue5() as i32)?, }; } - cursor.write_i32::<LE>(self.asset_data.file_license_version)?; + cursor.write_i32::<LE>(self.asset_data.summary.file_licensee_version)?; if self.legacy_file_version <= -2 { - match self.asset_data.unversioned { + match self.asset_data.summary.unversioned { true => cursor.write_i32::<LE>(0)?, false => { - cursor.write_i32::<LE>(self.asset_data.custom_versions.len() as i32)?; - for custom_version in &self.asset_data.custom_versions { + cursor.write_i32::<LE>(self.asset_data.summary.custom_versions.len() as i32)?; + for custom_version in &self.asset_data.summary.custom_versions { cursor.write_guid(&custom_version.guid)?; cursor.write_i32::<LE>(custom_version.version)?; } @@ -746,7 +1041,7 @@ impl<'a, C: Read + Seek> Asset<C> { cursor.write_i32::<LE>(asset_header.header_offset)?; cursor.write_fstring(Some(&self.folder_name))?; - cursor.write_u32::<LE>(self.asset_data.package_flags.bits())?; + cursor.write_u32::<LE>(self.asset_data.summary.package_flags.bits())?; cursor.write_i32::<LE>(self.name_map.get_ref().get_name_map_index_list().len() as i32)?; cursor.write_i32::<LE>(asset_header.name_offset)?; @@ -857,7 +1152,10 @@ impl<'a, C: Read + Seek> Asset<C> { let mut current_name_map = self.name_map.clone(); self.traverse_fnames(&mut |mut name| { let content = name.get_owned_content(); - let FName::Backed { index, name_map, .. } = &mut name else { + let FName::Backed { + index, name_map, .. + } = &mut name + else { return; }; @@ -960,8 +1258,8 @@ impl<'a, C: Read + Seek> Asset<C> { }; for export in &self.asset_data.exports { - let unk: &BaseExport = export.get_base_export(); - unk.write_export_map_entry( + let unk: &BaseExport<PackageIndex> = export.get_base_export(); + UAssetExportMapEntry::from_base_export(unk).write( &mut serializer, unk.serial_size, unk.serial_offset, @@ -1092,7 +1390,9 @@ impl<'a, C: Read + Seek> Asset<C> { true => bulk_serializer.position() + final_cursor_pos, false => bulk_serializer.position(), }); + export.write(bulk_serializer)?; + if let Some(normal_export) = export.get_normal_export() { bulk_serializer.write_all(&normal_export.extras)?; } @@ -1115,7 +1415,8 @@ impl<'a, C: Read + Seek> Asset<C> { true => category_starts[i + 1] as i64, false => bulk_data_start_offset, }; - unk.write_export_map_entry( + + UAssetExportMapEntry::from_base_export(unk).write( &mut serializer, next_loc - category_starts[i] as i64, category_starts[i] as i64, @@ -1124,6 +1425,7 @@ impl<'a, C: Read + Seek> Asset<C> { false => -1, }, )?; + first_export_dependency_offset += (unk.serialization_before_serialization_dependencies.len() + unk.create_before_serialization_dependencies.len() @@ -1155,12 +1457,12 @@ impl<'a, C: Read + Seek> Asset<C> { } } -impl<C: Read + Seek> AssetTrait for Asset<C> { - fn get_asset_data(&self) -> &AssetData { +impl<C: Read + Seek> AssetTrait<PackageIndex> for Asset<C> { + fn get_asset_data(&self) -> &AssetData<PackageIndex> { &self.asset_data } - fn get_asset_data_mut(&mut self) -> &mut AssetData { + fn get_asset_data_mut(&mut self) -> &mut AssetData<PackageIndex> { &mut self.asset_data } @@ -1187,7 +1489,7 @@ impl<C: Read + Seek> AssetTrait for Asset<C> { } } -impl<C: Read + Seek> ArchiveTrait for Asset<C> { +impl<C: Read + Seek> ArchiveTrait<PackageIndex> for Asset<C> { fn get_archive_type(&self) -> ArchiveType { ArchiveType::UAsset } @@ -1253,26 +1555,17 @@ impl<C: Read + Seek> ArchiveTrait for Asset<C> { .map(|e| e.object_name) } - fn get_import(&self, index: PackageIndex) -> Option<Import> { - if !index.is_import() { - return None; - } - - let index = -index.index - 1; - if index < 0 || index > self.imports.len() as i32 { - return None; - } + fn get_object_name(&self, index: PackageIndex) -> Option<FName> { + self.get_object_name_packageindex(index) + } - Some(self.imports[index as usize].clone()) + fn get_object_name_packageindex(&self, index: PackageIndex) -> Option<FName> { + self.get_import(index).map(|e| e.object_name) } } -impl<C: Read + Seek> PassthroughArchiveReader for Asset<C> { - type Passthrough = RawReader<C>; - - fn get_passthrough(&mut self) -> &mut Self::Passthrough { - &mut self.raw_reader - } +impl<C: Read + Seek> ArchiveReader<PackageIndex> for Asset<C> { + passthrough_archive_reader!(raw_reader); } impl<C: Read + Seek> Read for Asset<C> { @@ -1307,7 +1600,7 @@ impl<C: Read + Seek> Debug for Asset<C> { .field("engine_version_recorded", &self.engine_version_recorded) .field("engine_version_compatible", &self.engine_version_compatible) .field("chunk_ids", &self.chunk_ids) - .field("package_flags", &self.asset_data.package_flags) + .field("asset_data", &self.asset_data) .field("package_source", &self.package_source) .field("folder_name", &self.folder_name) // map struct type override @@ -1323,9 +1616,7 @@ impl<C: Read + Seek> Debug for Asset<C> { "gatherable_text_data_offset", &self.gatherable_text_data_offset, ) - .field("export_count", &self.export_count) .field("export_offset", &self.export_offset) - .field("import_count", &self.import_count) .field("import_offset", &self.import_offset) .field("depends_offset", &self.depends_offset) .field( diff --git a/unreal_asset/src/asset_archive_writer.rs b/unreal_asset/src/asset_archive_writer.rs index 69ad46bb..f332d1f4 100644 --- a/unreal_asset/src/asset_archive_writer.rs +++ b/unreal_asset/src/asset_archive_writer.rs @@ -9,34 +9,35 @@ use unreal_asset_base::{ engine_version::EngineVersion, flags::EPackageFlags, object_version::{ObjectVersion, ObjectVersionUE5}, - reader::{ArchiveTrait, ArchiveType, ArchiveWriter, PassthroughArchiveWriter}, - types::{FName, PackageIndex}, + passthrough_archive_writer, + reader::{ArchiveTrait, ArchiveType, ArchiveWriter}, + types::{FName, PackageIndex, PackageIndexTrait}, unversioned::Usmap, - Import, + Error, Import, }; use unreal_asset_exports::Export; use crate::asset_data::AssetData; -/// Archive that can be used to write an asset -pub struct AssetArchiveWriter<'parent_writer, 'asset, ParentWriter: ArchiveWriter> { +/// Archive that can be used to write UAsset data +pub struct AssetArchiveWriter<'parent_writer, 'asset, ParentWriter: ArchiveWriter<PackageIndex>> { /// Parent writer for this writer writer: &'parent_writer mut ParentWriter, /// Asset data - asset_data: &'asset AssetData, + asset_data: &'asset AssetData<PackageIndex>, /// Asset imports imports: &'asset [Import], /// Asset name map name_map: SharedResource<NameMap>, } -impl<'parent_writer, 'asset, ParentWriter: ArchiveWriter> +impl<'parent_writer, 'asset, ParentWriter: ArchiveWriter<PackageIndex>> AssetArchiveWriter<'parent_writer, 'asset, ParentWriter> { /// Create a new `AssetArchiveWriter` instance pub fn new( parent_writer: &'parent_writer mut ParentWriter, - asset_data: &'asset AssetData, + asset_data: &'asset AssetData<PackageIndex>, imports: &'asset [Import], name_map: SharedResource<NameMap>, ) -> Self { @@ -47,9 +48,23 @@ impl<'parent_writer, 'asset, ParentWriter: ArchiveWriter> name_map, } } + + /// Get an [`Import`] from this `AssetArchiveWriter` + pub fn get_import(&self, index: PackageIndex) -> Option<Import> { + if !index.is_import() { + return None; + } + + let index = -index.index - 1; + if index < 0 || index > self.imports.len() as i32 { + return None; + } + + Some(self.imports[index as usize].clone()) + } } -impl<'parent_writer, 'asset, ParentWriter: ArchiveWriter> ArchiveTrait +impl<'parent_writer, 'asset, ParentWriter: ArchiveWriter<PackageIndex>> ArchiveTrait<PackageIndex> for AssetArchiveWriter<'parent_writer, 'asset, ParentWriter> { #[inline(always)] @@ -66,6 +81,7 @@ impl<'parent_writer, 'asset, ParentWriter: ArchiveWriter> ArchiveTrait fn has_unversioned_properties(&self) -> bool { self.asset_data + .summary .package_flags .contains(EPackageFlags::PKG_UNVERSIONED_PROPERTIES) } @@ -124,32 +140,22 @@ impl<'parent_writer, 'asset, ParentWriter: ArchiveWriter> ArchiveTrait .map(|e| e.object_name) } - fn get_import(&self, index: PackageIndex) -> Option<Import> { - if !index.is_import() { - return None; - } - - let index = -index.index - 1; - if index < 0 || index > self.imports.len() as i32 { - return None; - } + fn get_object_name(&self, index: PackageIndex) -> Option<FName> { + self.get_object_name_packageindex(index) + } - Some(self.imports[index as usize].clone()) + fn get_object_name_packageindex(&self, index: PackageIndex) -> Option<FName> { + self.get_import(index).map(|e| e.object_name) } } -impl<'parent_writer, 'asset, ParentWriter: ArchiveWriter> PassthroughArchiveWriter +impl<'parent_writer, 'asset, ParentWriter: ArchiveWriter<PackageIndex>> ArchiveWriter<PackageIndex> for AssetArchiveWriter<'parent_writer, 'asset, ParentWriter> { - type Passthrough = ParentWriter; - - #[inline(always)] - fn get_passthrough(&mut self) -> &mut Self::Passthrough { - self.writer - } + passthrough_archive_writer!(writer); } -impl<'parent_writer, 'asset, ParentWriter: ArchiveWriter> Write +impl<'parent_writer, 'asset, ParentWriter: ArchiveWriter<PackageIndex>> Write for AssetArchiveWriter<'parent_writer, 'asset, ParentWriter> { fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> { @@ -161,7 +167,7 @@ impl<'parent_writer, 'asset, ParentWriter: ArchiveWriter> Write } } -impl<'parent_writer, 'asset, ParentWriter: ArchiveWriter> Seek +impl<'parent_writer, 'asset, ParentWriter: ArchiveWriter<PackageIndex>> Seek for AssetArchiveWriter<'parent_writer, 'asset, ParentWriter> { fn seek(&mut self, pos: std::io::SeekFrom) -> std::io::Result<u64> { diff --git a/unreal_asset/src/asset_data.rs b/unreal_asset/src/asset_data.rs index 80303209..f51517d2 100644 --- a/unreal_asset/src/asset_data.rs +++ b/unreal_asset/src/asset_data.rs @@ -12,7 +12,7 @@ use unreal_asset_base::{ flags::EPackageFlags, object_version::{ObjectVersion, ObjectVersionUE5}, reader::ArchiveReader, - types::{FName, PackageIndex}, + types::{FName, PackageIndex, PackageIndexTrait}, unversioned::Usmap, FNameContainer, }; @@ -26,19 +26,16 @@ use unreal_asset_exports::{ }; use unreal_asset_properties::world_tile_property::FWorldTileInfo; +use crate::package_file_summary::PackageFileSummary; + /// Unreal asset data, this is relevant for all assets #[derive(FNameContainer, Debug, Clone, PartialEq, Eq)] -pub struct AssetData { +pub struct AssetData<Index: PackageIndexTrait> { /// Does asset use the event driven loader pub use_event_driven_loader: bool, - /// Is asset unversioned - pub unversioned: bool, - /// Asset flags + /// Package file summary #[container_ignore] - pub package_flags: EPackageFlags, - - /// File licensee version, used by some games for their own engine versioning. - pub file_license_version: i32, + pub summary: PackageFileSummary, /// Object version #[container_ignore] @@ -50,16 +47,12 @@ pub struct AssetData { #[container_ignore] pub object_version_ue5: ObjectVersionUE5, - /// Custom versions - #[container_ignore] - pub custom_versions: Vec<CustomVersion>, - /// .usmap mappings #[container_ignore] pub mappings: Option<Usmap>, /// Object exports - pub exports: Vec<Export>, + pub exports: Vec<Export<Index>>, /// World tile information used by WorldComposition /// Degines propertiesn ecessary for tile positioning in the world @@ -86,17 +79,17 @@ pub struct AssetData { /// /// This is needed because export reading may want to modify [`AssetData`] which upsets the borrow checker #[derive(Debug, Clone)] -pub struct ReadExport { - export: Export, +pub struct ReadExport<Index: PackageIndexTrait> { + export: Export<Index>, new_map_key_overrides: IndexedMap<String, String>, new_map_value_overrides: IndexedMap<String, String>, new_array_overrides: IndexedMap<String, String>, } -impl ReadExport { +impl<Index: PackageIndexTrait> ReadExport<Index> { /// Create a new `ReadExport` instance pub fn new( - export: Export, + export: Export<Index>, new_map_key_overrides: IndexedMap<String, String>, new_map_value_overrides: IndexedMap<String, String>, new_array_overrides: IndexedMap<String, String>, @@ -110,7 +103,7 @@ impl ReadExport { } /// Reduce `ReadExport` to an [`Export`] - pub fn reduce(self, asset_data: &mut AssetData) -> Export { + pub fn reduce(self, asset_data: &mut AssetData<Index>) -> Export<Index> { asset_data.map_key_override.extend( self.new_map_key_overrides .into_iter() @@ -128,9 +121,9 @@ impl ReadExport { } } -impl AssetData { +impl<Index: PackageIndexTrait> AssetData<Index> { /// Creates a new `AssetData` instance - pub fn new() -> AssetData { + pub fn new() -> AssetData<Index> { AssetData::default() } @@ -145,7 +138,8 @@ impl AssetData { self.engine_version = engine_version; self.object_version = object_version; self.object_version_ue5 = object_version_ue5; - self.custom_versions = CustomVersion::get_default_custom_version_container(engine_version); + self.summary.custom_versions = + CustomVersion::get_default_custom_version_container(engine_version); } /// Get a custom version from this AssetData @@ -164,7 +158,8 @@ impl AssetData { where T: CustomVersionTrait + Into<i32>, { - self.custom_versions + self.summary + .custom_versions .iter() .find(|e| { e.friendly_name @@ -182,7 +177,7 @@ impl AssetData { } /// Get an export - pub fn get_export(&self, index: PackageIndex) -> Option<&Export> { + pub fn get_export(&self, index: PackageIndex) -> Option<&Export<Index>> { if !index.is_export() { return None; } @@ -197,7 +192,7 @@ impl AssetData { } /// Get a mutable export reference - pub fn get_export_mut(&mut self, index: PackageIndex) -> Option<&mut Export> { + pub fn get_export_mut(&mut self, index: PackageIndex) -> Option<&mut Export<Index>> { if !index.is_export() { return None; } @@ -212,7 +207,7 @@ impl AssetData { } /// Searches for an returns this asset's ClassExport, if one exists - pub fn get_class_export(&self) -> Option<&ClassExport> { + pub fn get_class_export(&self) -> Option<&ClassExport<Index>> { self.exports .iter() .find_map(|e| cast!(Export, ClassExport, e)) @@ -220,22 +215,23 @@ impl AssetData { /// Get if the asset has unversioned properties pub fn has_unversioned_properties(&self) -> bool { - self.package_flags + self.summary + .package_flags .contains(EPackageFlags::PKG_UNVERSIONED_PROPERTIES) } } -impl Default for AssetData { +impl<Index: PackageIndexTrait> Default for AssetData<Index> { fn default() -> Self { Self { use_event_driven_loader: false, - unversioned: true, - package_flags: EPackageFlags::PKG_NONE, - file_license_version: 0, + summary: PackageFileSummary { + unversioned: true, + ..Default::default() + }, engine_version: EngineVersion::UNKNOWN, object_version: ObjectVersion::UNKNOWN, object_version_ue5: ObjectVersionUE5::UNKNOWN, - custom_versions: Vec::new(), mappings: None, exports: Vec::new(), world_tile_info: None, @@ -290,11 +286,11 @@ impl Default for AssetData { } /// Unreal asset trait, must be implemented for all assets -pub trait AssetTrait { +pub trait AssetTrait<Index: PackageIndexTrait> { /// Gets a reference to the asset data - fn get_asset_data(&self) -> &AssetData; + fn get_asset_data(&self) -> &AssetData<Index>; /// Gets a mutable reference to the asset data - fn get_asset_data_mut(&mut self) -> &mut AssetData; + fn get_asset_data_mut(&mut self) -> &mut AssetData<Index>; /// Gets the name map fn get_name_map(&self) -> SharedResource<NameMap>; @@ -314,7 +310,9 @@ pub trait AssetTrait { } /// Export reader trait, used to read exports from an asset, implemented for all assets that implemented [`ArchiveReader`]+[`AssetTrait`] -pub trait ExportReaderTrait: ArchiveReader + AssetTrait + Sized { +pub trait ExportReaderTrait<Index: PackageIndexTrait>: + ArchiveReader<Index> + AssetTrait<Index> + Sized +{ /// Read an export from this asset /// /// This function doesn't automatically create a raw export if an error occurs @@ -327,18 +325,9 @@ pub trait ExportReaderTrait: ArchiveReader + AssetTrait + Sized { /// * `i` - export index fn read_export_no_raw( &mut self, - base_export: BaseExport, - i: usize, - ) -> Result<ReadExport, Error> { - let asset_data = self.get_asset_data(); - let next_starting = match i < (asset_data.exports.len() - 1) { - true => match &asset_data.exports[i + 1] { - Export::BaseExport(next_export) => next_export.serial_offset as u64, - _ => self.data_length()? - 4, - }, - false => self.data_length()? - 4, - }; - + base_export: BaseExport<Index>, + next_starting: u64, + ) -> Result<ReadExport<Index>, Error> { self.seek(SeekFrom::Start(base_export.serial_offset as u64))?; //todo: manual skips @@ -350,8 +339,8 @@ pub trait ExportReaderTrait: ArchiveReader + AssetTrait + Sized { let mut new_map_value_overrides = IndexedMap::new(); let new_array_overrides = IndexedMap::new(); - let mut export: Export = export_class_type.get_content(|class| { - Ok::<Export, Error>(match class { + let mut export: Export<Index> = export_class_type.get_content(|class| { + Ok::<Export<Index>, Error>(match class { "Level" => LevelExport::from_base(&base_export, self)?.into(), "World" => WorldExport::from_base(&base_export, self)?.into(), "UserDefinedStruct" => { @@ -374,8 +363,10 @@ pub trait ExportReaderTrait: ArchiveReader + AssetTrait + Sized { FProperty::FStructProperty(struct_property) => { match struct_property.struct_value.is_import() { true => self - .get_import(struct_property.struct_value) - .map(|e| e.object_name.get_owned_content()), + .get_object_name_packageindex( + struct_property.struct_value, + ) + .map(|e| e.get_owned_content()), false => None, } } @@ -390,8 +381,10 @@ pub trait ExportReaderTrait: ArchiveReader + AssetTrait + Sized { FProperty::FStructProperty(struct_property) => { match struct_property.struct_value.is_import() { true => self - .get_import(struct_property.struct_value) - .map(|e| e.object_name.get_owned_content()), + .get_object_name_packageindex( + struct_property.struct_value, + ) + .map(|e| e.get_owned_content()), false => None, } } @@ -421,7 +414,8 @@ pub trait ExportReaderTrait: ArchiveReader + AssetTrait + Sized { // todo: warning? self.seek(SeekFrom::Start(base_export.serial_offset as u64))?; - let export: Export = RawExport::from_base(base_export, self)?.into(); + + let export: Export<Index> = RawExport::from_base(base_export, self)?.into(); return Ok(ReadExport::new( export, new_map_key_overrides, @@ -451,16 +445,14 @@ pub trait ExportReaderTrait: ArchiveReader + AssetTrait + Sized { /// # Arguments /// /// * `i` - export index - fn read_export(&mut self, i: usize) -> Result<Export, Error> { - let asset_data = self.get_asset_data(); - let base_export = - cast!(Export, BaseExport, asset_data.exports[i].clone()).ok_or_else(|| { - Error::invalid_file("Couldn't cast to BaseExport when reading exports".to_string()) - })?; - + fn read_export( + &mut self, + base_export: BaseExport<Index>, + next_starting: u64, + ) -> Result<Export<Index>, Error> { let serial_offset = base_export.serial_offset as u64; - match self.read_export_no_raw(base_export.clone(), i) { + match self.read_export_no_raw(base_export.clone(), next_starting) { Ok(e) => { let asset_data_mut = self.get_asset_data_mut(); let reduced = e.reduce(asset_data_mut); @@ -476,4 +468,7 @@ pub trait ExportReaderTrait: ArchiveReader + AssetTrait + Sized { } } -impl<R: ArchiveReader + AssetTrait + Sized> ExportReaderTrait for R {} +impl<Index: PackageIndexTrait, R: ArchiveReader<Index> + AssetTrait<Index> + Sized> + ExportReaderTrait<Index> for R +{ +} diff --git a/unreal_asset/src/fengineversion.rs b/unreal_asset/src/fengineversion.rs index 0944895f..3ef92108 100644 --- a/unreal_asset/src/fengineversion.rs +++ b/unreal_asset/src/fengineversion.rs @@ -6,6 +6,7 @@ use byteorder::{ReadBytesExt, WriteBytesExt, LE}; use unreal_asset_base::{ reader::{ArchiveReader, ArchiveWriter}, + types::PackageIndexTrait, Error, }; @@ -35,7 +36,9 @@ impl FEngineVersion { } } - pub(crate) fn read<Reader: ArchiveReader>(cursor: &mut Reader) -> Result<Self, Error> { + pub(crate) fn read<Reader: ArchiveReader<impl PackageIndexTrait>>( + cursor: &mut Reader, + ) -> Result<Self, Error> { let major = cursor.read_u16::<LE>()?; let minor = cursor.read_u16::<LE>()?; let patch = cursor.read_u16::<LE>()?; @@ -45,7 +48,10 @@ impl FEngineVersion { Ok(Self::new(major, minor, patch, build, branch)) } - pub(crate) fn write<Writer: ArchiveWriter>(&self, cursor: &mut Writer) -> Result<(), Error> { + pub(crate) fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + cursor: &mut Writer, + ) -> Result<(), Error> { cursor.write_u16::<LE>(self.major)?; cursor.write_u16::<LE>(self.minor)?; cursor.write_u16::<LE>(self.patch)?; diff --git a/unreal_asset/src/lib.rs b/unreal_asset/src/lib.rs index 4382489f..72945b5e 100644 --- a/unreal_asset/src/lib.rs +++ b/unreal_asset/src/lib.rs @@ -86,6 +86,7 @@ pub mod asset; pub mod asset_archive_writer; pub mod asset_data; pub mod fengineversion; +pub mod package_file_summary; pub use asset::Asset; diff --git a/unreal_asset/src/package_file_summary.rs b/unreal_asset/src/package_file_summary.rs new file mode 100644 index 00000000..cf127a20 --- /dev/null +++ b/unreal_asset/src/package_file_summary.rs @@ -0,0 +1,42 @@ +//! Package(asset) file summary + +use unreal_asset_base::{ + custom_version::{CustomVersion, CustomVersionTrait}, + flags::EPackageFlags, +}; + +/// Package file summary +#[derive(Default, Debug, Clone, PartialEq, Eq, Hash)] +pub struct PackageFileSummary { + /// Package flags + pub package_flags: EPackageFlags, + /// Export count + pub export_count: i32, + /// Import count + pub import_count: i32, + /// File licensee version + pub file_licensee_version: i32, + /// Custom versions + pub custom_versions: Vec<CustomVersion>, + /// Is unversioned + pub unversioned: bool, +} + +impl PackageFileSummary { + /// Get custom version from + pub fn get_custom_version<T>(&self) -> CustomVersion + where + T: CustomVersionTrait + Into<i32>, + { + self.custom_versions + .iter() + .find(|e| { + e.friendly_name + .as_ref() + .map(|name| name == T::FRIENDLY_NAME) + .unwrap_or(false) + }) + .cloned() + .unwrap_or_else(|| CustomVersion::new(T::GUID, 0)) + } +} diff --git a/unreal_asset/tests/ac7.rs b/unreal_asset/tests/ac7.rs index 8b25780b..c43422ef 100644 --- a/unreal_asset/tests/ac7.rs +++ b/unreal_asset/tests/ac7.rs @@ -14,18 +14,11 @@ macro_rules! assets_folder { }; } -const TEST_ASSETS: [(&str, &[u8], &[u8]); 2] = [ - ( - "ex02_IGC_03_Subtitle", - include_bytes!(concat!(assets_folder!(), "ex02_IGC_03_Subtitle.uasset")), - include_bytes!(concat!(assets_folder!(), "ex02_IGC_03_Subtitle.uexp")), - ), - ( - "plwp_6aam_a0", - include_bytes!(concat!(assets_folder!(), "plwp_6aam_a0.uasset")), - include_bytes!(concat!(assets_folder!(), "plwp_6aam_a0.uexp")), - ), -]; +const TEST_ASSETS: [(&str, &[u8], &[u8]); 1] = [( + "ex02_IGC_03_Subtitle", + include_bytes!(concat!(assets_folder!(), "ex02_IGC_03_Subtitle.uasset")), + include_bytes!(concat!(assets_folder!(), "ex02_IGC_03_Subtitle.uexp")), +)]; #[test] fn ac7() -> Result<(), Error> { diff --git a/unreal_asset/tests/cdo_modification.rs b/unreal_asset/tests/cdo_modification.rs index 4a38ae83..dafc4ceb 100644 --- a/unreal_asset/tests/cdo_modification.rs +++ b/unreal_asset/tests/cdo_modification.rs @@ -37,7 +37,7 @@ fn cdo_modification() -> Result<(), Error> { let new_name = asset.get_name_map().get_mut().add_fname("PickupActor"); - let cdo_export: &mut NormalExport = asset + let cdo_export: &mut NormalExport<_> = asset .asset_data .exports .iter_mut() diff --git a/unreal_asset/tests/custom_serialization_structs_in_map.rs b/unreal_asset/tests/custom_serialization_structs_in_map.rs index 8c66d991..d6c1ff25 100644 --- a/unreal_asset/tests/custom_serialization_structs_in_map.rs +++ b/unreal_asset/tests/custom_serialization_structs_in_map.rs @@ -39,7 +39,7 @@ fn custom_serialization_structs_in_map() -> Result<(), Error> { let export_two = asset .get_export(PackageIndex::new(2)) .ok_or_else(|| Error::no_data("Export two doesn't exist".to_string()))?; - let export_two: &NormalExport = export_two + let export_two: &NormalExport<_> = export_two .get_normal_export() .ok_or_else(|| Error::invalid_file("Export two is not NormalExport".to_string()))?; diff --git a/unreal_asset/tests/data_tables.rs b/unreal_asset/tests/data_tables.rs index c036922c..8a49332f 100644 --- a/unreal_asset/tests/data_tables.rs +++ b/unreal_asset/tests/data_tables.rs @@ -34,7 +34,7 @@ fn data_tables() -> Result<(), Error> { shared::verify_binary_equality(TEST_ASSET, None, &mut asset)?; assert!(shared::verify_all_exports_parsed(&asset)); - let data_table_export: &mut DataTableExport = + let data_table_export: &mut DataTableExport<_> = cast!(Export, DataTableExport, &mut asset.asset_data.exports[0]) .expect("First export is not a DataTableExport"); @@ -71,7 +71,7 @@ fn data_tables() -> Result<(), Error> { assert!(shared::verify_all_exports_parsed(&parsed_back)); assert!(parsed_back.asset_data.exports.len() == 1); - let data_table_export: &DataTableExport = + let data_table_export: &DataTableExport<_> = cast!(Export, DataTableExport, &parsed_back.asset_data.exports[0]) .expect("First export is not a DataTableExport after serializing and deserializing"); diff --git a/unreal_asset/unreal_asset_base/src/custom_version.rs b/unreal_asset/unreal_asset_base/src/custom_version.rs index 80cb2f70..f5b36867 100644 --- a/unreal_asset/unreal_asset_base/src/custom_version.rs +++ b/unreal_asset/unreal_asset_base/src/custom_version.rs @@ -9,6 +9,7 @@ use num_enum::{IntoPrimitive, TryFromPrimitive}; use crate::engine_version::EngineVersion; use crate::reader::{ArchiveReader, ArchiveWriter}; +use crate::types::PackageIndexTrait; use crate::Error; use crate::Guid; @@ -94,7 +95,9 @@ impl CustomVersion { } /// Read a custom version from an asset - pub fn read<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn read<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let guid = asset.read_guid()?; let version = asset.read_i32::<LE>()?; @@ -108,7 +111,10 @@ impl CustomVersion { } /// Write a custom version to an asset - pub fn write<Writer: ArchiveWriter>(&self, writer: &mut Writer) -> Result<(), Error> { + pub fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + writer: &mut Writer, + ) -> Result<(), Error> { writer.write_guid(&self.guid)?; writer.write_i32::<LE>(self.version)?; Ok(()) @@ -1330,7 +1336,9 @@ const ASSET_REGISTRY_VERSION_GUID: Guid = impl FAssetRegistryVersionType { /// Read an asset registry version from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let guid = asset.read_guid()?; if guid == ASSET_REGISTRY_VERSION_GUID { @@ -1341,7 +1349,10 @@ impl FAssetRegistryVersionType { } /// Write an asset registry version to an asset - pub fn write<Writer: ArchiveWriter>(&self, writer: &mut Writer) -> Result<(), Error> { + pub fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + writer: &mut Writer, + ) -> Result<(), Error> { writer.write_guid(&ASSET_REGISTRY_VERSION_GUID)?; writer.write_i32::<LE>((*self).into())?; Ok(()) diff --git a/unreal_asset/unreal_asset_base/src/enums.rs b/unreal_asset/unreal_asset_base/src/enums.rs index 12edab33..c95a2a18 100644 --- a/unreal_asset/unreal_asset_base/src/enums.rs +++ b/unreal_asset/unreal_asset_base/src/enums.rs @@ -70,3 +70,41 @@ pub enum ECustomVersionSerializationFormat { #[default] Optimized, } + +/// Zen package version +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, TryFromPrimitive, IntoPrimitive)] +#[repr(u32)] +pub enum EZenPackageVersion { + /// Initial + Initial, + /// Data resource table + DataResourceTable, + /// Imported package names + ImportedPackageNames, + + /// Latest + Latest, + /// Latest plus one + LatestPlusOne, +} + +/// IoStore container header version +#[derive( + Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, TryFromPrimitive, IntoPrimitive, +)] +#[repr(u32)] +pub enum EIoContainerHeaderVersion { + /// Initial + Initial, + /// Localized packages + LocalizedPackages, + /// Optional segment packages + OptionalSegmentPackages, + /// No export info + NoExportInfo, + + /// Latest + Latest, + /// Latest plus one + LatestPlusOne, +} diff --git a/unreal_asset/unreal_asset_base/src/flags.rs b/unreal_asset/unreal_asset_base/src/flags.rs index 6b4f1278..4a8f8a88 100644 --- a/unreal_asset/unreal_asset_base/src/flags.rs +++ b/unreal_asset/unreal_asset_base/src/flags.rs @@ -480,6 +480,12 @@ impl Default for EObjectFlags { } } +impl Default for EPackageFlags { + fn default() -> Self { + Self::PKG_NONE + } +} + impl Default for EPropertyFlags { fn default() -> Self { Self::CPF_NONE diff --git a/unreal_asset/unreal_asset_base/src/reader/archive_reader.rs b/unreal_asset/unreal_asset_base/src/reader/archive_reader.rs index 27d21eba..14ba2a0c 100644 --- a/unreal_asset/unreal_asset_base/src/reader/archive_reader.rs +++ b/unreal_asset/unreal_asset_base/src/reader/archive_reader.rs @@ -12,11 +12,11 @@ use crate::enums::ECustomVersionSerializationFormat; use crate::error::{Error, FNameError}; use crate::object_version::ObjectVersion; use crate::reader::ArchiveTrait; -use crate::types::{FName, SerializedNameHeader}; +use crate::types::{FName, PackageIndexTrait, SerializedNameHeader}; use crate::Guid; /// A trait that allows reading from an archive in an asset-specific way -pub trait ArchiveReader: ArchiveTrait + Read { +pub trait ArchiveReader<Index: PackageIndexTrait>: ArchiveTrait<Index> + Read { /// Read a `Guid` property fn read_property_guid(&mut self) -> Result<Option<Guid>, Error> { if self.get_object_version() >= ObjectVersion::VER_UE4_PROPERTY_GUID_IN_PROPERTY_TAG { @@ -188,7 +188,7 @@ pub trait ArchiveReader: ArchiveTrait + Read { /// use unreal_asset::reader::asset_reader::ArchiveReader; /// use byteorder::LE; /// - /// let reader: ArchiveReader = ...; + /// let reader: ArchiveReader<impl PackageIndexTrait> = ...; /// let ints = reader.read_array_with_length(12, |e| e.read_i32::<LE>()?)?; /// ``` fn read_array_with_length<T>( @@ -227,40 +227,32 @@ pub trait ArchiveReader: ArchiveTrait + Read { fn read_bool(&mut self) -> io::Result<bool>; } -/// A trait that allows for quick implementation of [`ArchiveReader`] as a passthrough trait for the underlying archive -pub trait PassthroughArchiveReader: ArchiveTrait + Read { - /// Passthrough archive reader type - type Passthrough: ArchiveReader; - /// Get the passthrough archive reader - fn get_passthrough(&mut self) -> &mut Self::Passthrough; -} - -impl<Reader, Passthrough> ArchiveReader for Passthrough -where - Reader: ArchiveReader, - Passthrough: PassthroughArchiveReader<Passthrough = Reader>, -{ - #[inline(always)] - fn read_fstring(&mut self) -> Result<Option<String>, Error> { - self.get_passthrough().read_fstring() - } +/// A macro that allows for quick implementation of [`ArchiveReader`] as a passthrough for the underlying archive +#[macro_export] +macro_rules! passthrough_archive_reader { + ($passthrough:ident) => { + #[inline(always)] + fn read_fstring(&mut self) -> Result<Option<String>, Error> { + self.$passthrough.read_fstring() + } - #[inline(always)] - fn read_fstring_name_header( - &mut self, - serialized_name_header: SerializedNameHeader, - ) -> Result<Option<String>, Error> { - self.get_passthrough() - .read_fstring_name_header(serialized_name_header) - } + #[inline(always)] + fn read_fstring_name_header( + &mut self, + serialized_name_header: $crate::types::SerializedNameHeader, + ) -> Result<Option<String>, Error> { + self.$passthrough + .read_fstring_name_header(serialized_name_header) + } - #[inline(always)] - fn read_guid(&mut self) -> io::Result<Guid> { - self.get_passthrough().read_guid() - } + #[inline(always)] + fn read_guid(&mut self) -> std::io::Result<unreal_helpers::Guid> { + self.$passthrough.read_guid() + } - #[inline(always)] - fn read_bool(&mut self) -> io::Result<bool> { - self.get_passthrough().read_bool() - } + #[inline(always)] + fn read_bool(&mut self) -> std::io::Result<bool> { + self.$passthrough.read_bool() + } + }; } diff --git a/unreal_asset/unreal_asset_base/src/reader/archive_trait.rs b/unreal_asset/unreal_asset_base/src/reader/archive_trait.rs index 05bc2b14..8c172501 100644 --- a/unreal_asset/unreal_asset_base/src/reader/archive_trait.rs +++ b/unreal_asset/unreal_asset_base/src/reader/archive_trait.rs @@ -7,9 +7,9 @@ use crate::containers::{IndexedMap, NameMap, SharedResource}; use crate::custom_version::{CustomVersion, CustomVersionTrait}; use crate::engine_version::EngineVersion; use crate::object_version::{ObjectVersion, ObjectVersionUE5}; -use crate::types::{FName, PackageIndex}; +use crate::types::{FName, PackageIndex, PackageIndexTrait}; use crate::unversioned::Usmap; -use crate::Import; + /// An enum to help identify current archive type #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] @@ -36,7 +36,7 @@ impl Display for ArchiveType { } /// A trait that allows accessing data about the archive that is currently being read -pub trait ArchiveTrait: Seek { +pub trait ArchiveTrait<Index: PackageIndexTrait>: Seek { /// Get archive type fn get_archive_type(&self) -> ArchiveType; @@ -122,13 +122,15 @@ pub trait ArchiveTrait: Seek { /// Get parent class export name fn get_parent_class_export_name(&self) -> Option<FName>; - /// Get an import by a `PackageIndex` - fn get_import(&self, index: PackageIndex) -> Option<Import>; - /// Get export class type by a `PackageIndex` - fn get_export_class_type(&self, index: PackageIndex) -> Option<FName> { + /// Get object name by an `Index` + fn get_object_name(&self, index: Index) -> Option<FName>; + /// Get object name by a `PackageIndex` + fn get_object_name_packageindex(&self, index: PackageIndex) -> Option<FName>; + /// Get export class type by an `Index` + fn get_export_class_type(&self, index: Index) -> Option<FName> { match index.is_import() { - true => self.get_import(index).map(|e| e.object_name), - false => Some(FName::new_dummy(index.index.to_string(), 0)), + true => self.get_object_name(index), + false => Some(FName::new_dummy(index.to_string(), 0)), } } } diff --git a/unreal_asset/unreal_asset_base/src/reader/archive_writer.rs b/unreal_asset/unreal_asset_base/src/reader/archive_writer.rs index d977b804..9e8f996b 100644 --- a/unreal_asset/unreal_asset_base/src/reader/archive_writer.rs +++ b/unreal_asset/unreal_asset_base/src/reader/archive_writer.rs @@ -7,11 +7,11 @@ use byteorder::{WriteBytesExt, LE}; use crate::error::{Error, FNameError}; use crate::object_version::ObjectVersion; use crate::reader::ArchiveTrait; -use crate::types::FName; +use crate::types::{FName, PackageIndexTrait}; use crate::Guid; /// A trait that allows for writing to an archive in an asset-specific way -pub trait ArchiveWriter: ArchiveTrait + Write { +pub trait ArchiveWriter<Index: PackageIndexTrait>: ArchiveTrait<Index> + Write { /// Write a `Guid` property fn write_property_guid(&mut self, guid: Option<&Guid>) -> Result<(), Error> { if self.get_object_version() >= ObjectVersion::VER_UE4_PROPERTY_GUID_IN_PROPERTY_TAG { @@ -50,31 +50,23 @@ pub trait ArchiveWriter: ArchiveTrait + Write { fn write_bool(&mut self, value: bool) -> io::Result<()>; } -/// A trait that allows for quick implementation of [`ArchiveWriter`] as a passthrough trait for the underlying archive -pub trait PassthroughArchiveWriter: ArchiveTrait + Write { - /// Passthrough archive writer type - type Passthrough: ArchiveWriter; - /// Get the passthrough archive writer - fn get_passthrough(&mut self) -> &mut Self::Passthrough; -} - -impl<Writer, Passthrough> ArchiveWriter for Passthrough -where - Writer: ArchiveWriter, - Passthrough: PassthroughArchiveWriter<Passthrough = Writer>, -{ - #[inline(always)] - fn write_fstring(&mut self, value: Option<&str>) -> Result<usize, Error> { - self.get_passthrough().write_fstring(value) - } +/// A macro that allows for quick implementation of [`ArchiveWriter`] as a passthrough for the underlying archive +#[macro_export] +macro_rules! passthrough_archive_writer { + ($passthrough:ident) => { + #[inline(always)] + fn write_fstring(&mut self, value: Option<&str>) -> Result<usize, Error> { + self.$passthrough.write_fstring(value) + } - #[inline(always)] - fn write_guid(&mut self, guid: &Guid) -> io::Result<()> { - self.get_passthrough().write_guid(guid) - } + #[inline(always)] + fn write_guid(&mut self, guid: &unreal_helpers::Guid) -> std::io::Result<()> { + self.$passthrough.write_guid(guid) + } - #[inline(always)] - fn write_bool(&mut self, value: bool) -> io::Result<()> { - self.get_passthrough().write_bool(value) - } + #[inline(always)] + fn write_bool(&mut self, value: bool) -> std::io::Result<()> { + self.$passthrough.write_bool(value) + } + }; } diff --git a/unreal_asset/unreal_asset_base/src/reader/mod.rs b/unreal_asset/unreal_asset_base/src/reader/mod.rs index a254fa5b..93486ce7 100644 --- a/unreal_asset/unreal_asset_base/src/reader/mod.rs +++ b/unreal_asset/unreal_asset_base/src/reader/mod.rs @@ -2,7 +2,6 @@ pub mod archive_reader; pub use archive_reader::ArchiveReader; -pub use archive_reader::PassthroughArchiveReader; pub mod archive_trait; pub use archive_trait::ArchiveTrait; @@ -10,7 +9,6 @@ pub use archive_trait::ArchiveType; pub mod archive_writer; pub use archive_writer::ArchiveWriter; -pub use archive_writer::PassthroughArchiveWriter; pub mod raw_reader; pub use raw_reader::RawReader; diff --git a/unreal_asset/unreal_asset_base/src/reader/raw_reader.rs b/unreal_asset/unreal_asset_base/src/reader/raw_reader.rs index a1018a26..ad16193a 100644 --- a/unreal_asset/unreal_asset_base/src/reader/raw_reader.rs +++ b/unreal_asset/unreal_asset_base/src/reader/raw_reader.rs @@ -1,6 +1,7 @@ //! Binary archive reader use std::io::{self, Read, Seek}; +use std::marker::PhantomData; use unreal_helpers::{read_ext::read_fstring_len, Guid, UnrealReadExt}; @@ -12,13 +13,13 @@ use crate::reader::{ archive_trait::{ArchiveTrait, ArchiveType}, ArchiveReader, }; -use crate::types::{FName, PackageIndex, SerializedNameHeader}; +use crate::types::{FName, PackageIndex, PackageIndexTrait, SerializedNameHeader}; use crate::unversioned::Usmap; use crate::Error; -use crate::Import; + /// A binary reader -pub struct RawReader<C: Read + Seek> { +pub struct RawReader<Index: PackageIndexTrait, C: Read + Seek> { /// Reader cursor cursor: Chain<C>, /// Object version @@ -31,9 +32,12 @@ pub struct RawReader<C: Read + Seek> { pub name_map: SharedResource<NameMap>, /// Empty map empty_map: IndexedMap<String, String>, + + /// Marker + _marker: PhantomData<Index>, } -impl<C: Read + Seek> RawReader<C> { +impl<Index: PackageIndexTrait, C: Read + Seek> RawReader<Index, C> { /// Create a new instance of `RawReader` with the specified object versions and a name map pub fn new( cursor: Chain<C>, @@ -49,11 +53,12 @@ impl<C: Read + Seek> RawReader<C> { use_event_driven_loader, name_map, empty_map: IndexedMap::new(), + _marker: PhantomData, } } } -impl<C: Read + Seek> ArchiveTrait for RawReader<C> { +impl<Index: PackageIndexTrait, C: Read + Seek> ArchiveTrait<Index> for RawReader<Index, C> { #[inline(always)] fn get_archive_type(&self) -> ArchiveType { ArchiveType::Raw @@ -114,12 +119,16 @@ impl<C: Read + Seek> ArchiveTrait for RawReader<C> { None } - fn get_import(&self, _: PackageIndex) -> Option<Import> { + fn get_object_name(&self, _: Index) -> Option<FName> { + None + } + + fn get_object_name_packageindex(&self, _: PackageIndex) -> Option<FName> { None } } -impl<C: Read + Seek> ArchiveReader for RawReader<C> { +impl<Index: PackageIndexTrait, C: Read + Seek> ArchiveReader<Index> for RawReader<Index, C> { fn read_fstring(&mut self) -> Result<Option<String>, Error> { Ok(self.cursor.read_fstring()?) } @@ -148,14 +157,14 @@ impl<C: Read + Seek> ArchiveReader for RawReader<C> { } } -impl<C: Read + Seek> Read for RawReader<C> { +impl<Index: PackageIndexTrait, C: Read + Seek> Read for RawReader<Index, C> { #[inline(always)] fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { self.cursor.read(buf) } } -impl<C: Read + Seek> Seek for RawReader<C> { +impl<Index: PackageIndexTrait, C: Read + Seek> Seek for RawReader<Index, C> { #[inline(always)] fn seek(&mut self, pos: io::SeekFrom) -> io::Result<u64> { self.cursor.seek(pos) diff --git a/unreal_asset/unreal_asset_base/src/reader/raw_writer.rs b/unreal_asset/unreal_asset_base/src/reader/raw_writer.rs index 6ae8a8aa..400247ee 100644 --- a/unreal_asset/unreal_asset_base/src/reader/raw_writer.rs +++ b/unreal_asset/unreal_asset_base/src/reader/raw_writer.rs @@ -1,6 +1,7 @@ //! Binary archive writer use std::io::{self, Seek, Write}; +use std::marker::PhantomData; use unreal_helpers::{Guid, UnrealWriteExt}; @@ -12,13 +13,13 @@ use crate::reader::{ archive_trait::{ArchiveTrait, ArchiveType}, ArchiveWriter, }; -use crate::types::{FName, PackageIndex}; +use crate::types::{FName, PackageIndex, PackageIndexTrait}; use crate::unversioned::Usmap; use crate::Error; -use crate::Import; + /// A binary writer -pub struct RawWriter<'cursor, W: Write + Seek> { +pub struct RawWriter<'cursor, Index: PackageIndexTrait, W: Write + Seek> { /// Writer cursor cursor: &'cursor mut W, /// Object version @@ -31,9 +32,11 @@ pub struct RawWriter<'cursor, W: Write + Seek> { name_map: SharedResource<NameMap>, /// Empty map empty_map: IndexedMap<String, String>, + /// Marker + _marker: PhantomData<Index>, } -impl<'cursor, W: Write + Seek> RawWriter<'cursor, W> { +impl<'cursor, Index: PackageIndexTrait, W: Write + Seek> RawWriter<'cursor, Index, W> { /// Create a new instance of `RawWriter` with the specified object versions pub fn new( cursor: &'cursor mut W, @@ -49,11 +52,14 @@ impl<'cursor, W: Write + Seek> RawWriter<'cursor, W> { use_event_driven_loader, name_map, empty_map: IndexedMap::new(), + _marker: PhantomData, } } } -impl<'cursor, W: Write + Seek> ArchiveTrait for RawWriter<'cursor, W> { +impl<'cursor, Index: PackageIndexTrait, W: Write + Seek> ArchiveTrait<Index> + for RawWriter<'cursor, Index, W> +{ #[inline(always)] fn get_archive_type(&self) -> ArchiveType { ArchiveType::Raw @@ -114,12 +120,18 @@ impl<'cursor, W: Write + Seek> ArchiveTrait for RawWriter<'cursor, W> { None } - fn get_import(&self, _: PackageIndex) -> Option<Import> { + fn get_object_name(&self, _: Index) -> Option<FName> { + None + } + + fn get_object_name_packageindex(&self, _: PackageIndex) -> Option<FName> { None } } -impl<'cursor, W: Write + Seek> ArchiveWriter for RawWriter<'cursor, W> { +impl<'cursor, Index: PackageIndexTrait, W: Write + Seek> ArchiveWriter<Index> + for RawWriter<'cursor, Index, W> +{ fn write_fstring(&mut self, value: Option<&str>) -> Result<usize, Error> { Ok(self.cursor.write_fstring(value)?) } @@ -133,7 +145,7 @@ impl<'cursor, W: Write + Seek> ArchiveWriter for RawWriter<'cursor, W> { } } -impl<'cursor, W: Write + Seek> Write for RawWriter<'cursor, W> { +impl<'cursor, Index: PackageIndexTrait, W: Write + Seek> Write for RawWriter<'cursor, Index, W> { fn write(&mut self, buf: &[u8]) -> io::Result<usize> { self.cursor.write(buf) } @@ -143,7 +155,7 @@ impl<'cursor, W: Write + Seek> Write for RawWriter<'cursor, W> { } } -impl<'cursor, W: Write + Seek> Seek for RawWriter<'cursor, W> { +impl<'cursor, Index: PackageIndexTrait, W: Write + Seek> Seek for RawWriter<'cursor, Index, W> { fn seek(&mut self, pos: io::SeekFrom) -> io::Result<u64> { self.cursor.seek(pos) } diff --git a/unreal_asset/unreal_asset_base/src/types/mod.rs b/unreal_asset/unreal_asset_base/src/types/mod.rs index cafc4419..cf32e700 100644 --- a/unreal_asset/unreal_asset_base/src/types/mod.rs +++ b/unreal_asset/unreal_asset_base/src/types/mod.rs @@ -25,7 +25,7 @@ pub struct SerializedNameHeader { impl SerializedNameHeader { /// Read a `SerializedNameHeader` from an archive - pub fn read<Reader: ArchiveReader + ?Sized>( + pub fn read<Reader: ArchiveReader<impl PackageIndexTrait> + ?Sized>( reader: &mut Reader, ) -> Result<SerializedNameHeader, Error> { let (first_byte, second_byte) = (reader.read_u8()?, reader.read_u8()?); @@ -37,7 +37,10 @@ impl SerializedNameHeader { } /// Write a `SerializedNameHeader` to an archive - pub fn write<Writer: ArchiveWriter>(&self, writer: &mut Writer) -> Result<(), Error> { + pub fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + writer: &mut Writer, + ) -> Result<(), Error> { let is_wide = match self.is_wide { true => 1u8, false => 0u8, @@ -52,6 +55,15 @@ impl SerializedNameHeader { } } +/// PackageIndexTrait is used to group PackageIndex and PackageObjectIndex together +/// This is useful for exports to share code between UAsset/IoStore implementations +pub trait PackageIndexTrait: std::fmt::Debug + Copy + Clone + PartialEq + Eq + ToString { + /// Check if this index is an import + fn is_import(&self) -> bool; + /// Check if this index is an export + fn is_export(&self) -> bool; +} + /// PackageIndex is one of the most important structs in UE4 /// /// It is basically a reference into an import/export table @@ -73,16 +85,6 @@ impl PackageIndex { PackageIndex { index } } - /// Check if this index is an import - pub fn is_import(&self) -> bool { - self.index < 0 - } - - /// Check if this index is an export - pub fn is_export(&self) -> bool { - self.index > 0 - } - /// Create a `PackageIndex` from an import index pub fn from_import(import_index: i32) -> Result<Self, Error> { match import_index < 0 { @@ -104,6 +106,22 @@ impl PackageIndex { } } +impl PackageIndexTrait for PackageIndex { + fn is_import(&self) -> bool { + self.index < 0 + } + + fn is_export(&self) -> bool { + self.index > 0 + } +} + +impl ToString for PackageIndex { + fn to_string(&self) -> String { + self.index.to_string() + } +} + /// Create a Guid from 4 u32 values // #[rustfmt::skip] // pub const fn new_guid(a: u32, b: u32, c: u32, d: u32) -> Guid { diff --git a/unreal_asset/unreal_asset_base/src/types/movie.rs b/unreal_asset/unreal_asset_base/src/types/movie.rs index 2555dd1a..ffdb1196 100644 --- a/unreal_asset/unreal_asset_base/src/types/movie.rs +++ b/unreal_asset/unreal_asset_base/src/types/movie.rs @@ -8,6 +8,8 @@ use crate::{ reader::{ArchiveReader, ArchiveWriter}, }; +use super::PackageIndexTrait; + /// Frame number #[derive(Debug, Copy, Clone, Default, PartialEq, Eq, Hash)] pub struct FrameNumber { @@ -76,7 +78,9 @@ pub struct FFrameNumberRangeBound { impl FFrameNumberRangeBound { /// Read a `FFrameNumberRangeBound` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let ty: ERangeBoundTypes = ERangeBoundTypes::try_from(asset.read_i8()?)?; let value = FrameNumber::new(asset.read_i32::<LE>()?); @@ -84,7 +88,10 @@ impl FFrameNumberRangeBound { } /// Write a `FFrameNumberRangeBound` to an asset - pub fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { + pub fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<(), Error> { asset.write_i8(self.ty as i8)?; asset.write_i32::<LE>(self.value.value)?; Ok(()) @@ -102,7 +109,9 @@ pub struct FFrameNumberRange { impl FFrameNumberRange { /// Read a `FFrameNumberRange` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let lower_bound = FFrameNumberRangeBound::new(asset)?; let upper_bound = FFrameNumberRangeBound::new(asset)?; @@ -113,7 +122,10 @@ impl FFrameNumberRange { } /// Write a `FFrameNumberRange` to an asset - pub fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { + pub fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<(), Error> { self.lower_bound.write(asset)?; self.upper_bound.write(asset)?; Ok(()) diff --git a/unreal_asset/unreal_asset_base/src/unversioned/header.rs b/unreal_asset/unreal_asset_base/src/unversioned/header.rs index 3c171f67..d2348866 100644 --- a/unreal_asset/unreal_asset_base/src/unversioned/header.rs +++ b/unreal_asset/unreal_asset_base/src/unversioned/header.rs @@ -4,6 +4,7 @@ use bitvec::prelude::*; use byteorder::{ReadBytesExt, WriteBytesExt, LE}; use crate::reader::{ArchiveReader, ArchiveWriter}; +use crate::types::PackageIndexTrait; use crate::Error; /// Unversioned header fragment @@ -51,12 +52,17 @@ impl UnversionedHeaderFragment { } /// Read an `UnversionedHeaderFragment` from an asset - pub fn read<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn read<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok(UnversionedHeaderFragment::from(asset.read_u16::<LE>()?)) } /// Write an `UnversionedHeaderFragment` to an asset - pub fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { + pub fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<(), Error> { let has_zero_mask = match self.has_zeros { true => UnversionedHeaderFragment::HAS_ZEROS_MASK, false => 0, @@ -97,7 +103,7 @@ pub struct UnversionedHeader { impl UnversionedHeader { /// Loads zero mask data from an asset - fn load_zero_mask_data<Reader: ArchiveReader>( + fn load_zero_mask_data<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, num_bits: u16, ) -> Result<BitVec<u8, Lsb0>, Error> { @@ -120,7 +126,9 @@ impl UnversionedHeader { } /// Read `UnversionedHeader` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Option<Self>, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Option<Self>, Error> { if !asset.has_unversioned_properties() { return Ok(None); } @@ -173,7 +181,10 @@ impl UnversionedHeader { } /// Write `UnversionedHeader` to an asset - pub fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { + pub fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<(), Error> { if !asset.has_unversioned_properties() { return Ok(()); } diff --git a/unreal_asset/unreal_asset_base/src/unversioned/mod.rs b/unreal_asset/unreal_asset_base/src/unversioned/mod.rs index 1cbc923b..f0cbd490 100644 --- a/unreal_asset/unreal_asset_base/src/unversioned/mod.rs +++ b/unreal_asset/unreal_asset_base/src/unversioned/mod.rs @@ -13,7 +13,7 @@ use crate::error::{Error, UsmapError}; use crate::object_version::{ObjectVersion, ObjectVersionUE5}; use crate::reader::{ArchiveReader, ArchiveTrait, RawReader}; -use crate::types::FName; +use crate::types::{FName, PackageIndex}; pub mod ancestry; pub mod header; @@ -92,7 +92,7 @@ pub struct UsmapSchema { impl UsmapSchema { /// Read a `UsmapSchema` from an archive - pub fn read<R: ArchiveReader>( + pub fn read<R: ArchiveReader<PackageIndex>>( reader: &mut UsmapReader<'_, '_, R>, ) -> Result<UsmapSchema, Error> { let name = reader.read_name()?; @@ -237,7 +237,7 @@ impl Usmap { /// Parse usmap file pub fn parse_data<C: Read + Seek>(&mut self, cursor: C) -> Result<(), Error> { - let mut reader = RawReader::new( + let mut reader = RawReader::<PackageIndex, C>::new( Chain::new(cursor, None), ObjectVersion::UNKNOWN, ObjectVersionUE5::UNKNOWN, @@ -262,7 +262,7 @@ impl Usmap { if has_versioning { self.object_version = ObjectVersion::try_from(reader.read_i32::<LE>()?)?; self.object_version_ue5 = ObjectVersionUE5::try_from(reader.read_i32::<LE>()?)?; - self.custom_versions = reader.read_array(|e| CustomVersion::read(e))?; + self.custom_versions = reader.read_array(CustomVersion::read)?; self.net_cl = reader.read_u32::<LE>()?; } diff --git a/unreal_asset/unreal_asset_base/src/unversioned/properties/array_property.rs b/unreal_asset/unreal_asset_base/src/unversioned/properties/array_property.rs index 274f9b03..b3ed8c95 100644 --- a/unreal_asset/unreal_asset_base/src/unversioned/properties/array_property.rs +++ b/unreal_asset/unreal_asset_base/src/unversioned/properties/array_property.rs @@ -5,6 +5,7 @@ use std::mem::size_of; use byteorder::WriteBytesExt; use crate::reader::{ArchiveReader, ArchiveWriter}; +use crate::types::{PackageIndex}; use crate::unversioned::{usmap_reader::UsmapReader, usmap_writer::UsmapWriter}; use crate::Error; @@ -19,7 +20,9 @@ pub struct UsmapArrayPropertyData { impl UsmapArrayPropertyData { /// Read a `UsmapArrayPropertyData` from an asset - pub fn new<R: ArchiveReader>(asset: &mut UsmapReader<'_, '_, R>) -> Result<Self, Error> { + pub fn new<R: ArchiveReader<PackageIndex>>( + asset: &mut UsmapReader<'_, '_, R>, + ) -> Result<Self, Error> { let inner_type = UsmapPropertyData::new(asset)?; Ok(UsmapArrayPropertyData { @@ -29,7 +32,10 @@ impl UsmapArrayPropertyData { } impl UsmapPropertyDataTrait for UsmapArrayPropertyData { - fn write<W: ArchiveWriter>(&self, asset: &mut UsmapWriter<'_, '_, W>) -> Result<usize, Error> { + fn write<W: ArchiveWriter<PackageIndex>>( + &self, + asset: &mut UsmapWriter<'_, '_, W>, + ) -> Result<usize, Error> { asset.write_u8(EPropertyType::ArrayProperty as u8)?; let size = self.inner_type.write(asset)?; Ok(size + size_of::<u8>()) diff --git a/unreal_asset/unreal_asset_base/src/unversioned/properties/enum_property.rs b/unreal_asset/unreal_asset_base/src/unversioned/properties/enum_property.rs index 6d668fa2..2fb739ec 100644 --- a/unreal_asset/unreal_asset_base/src/unversioned/properties/enum_property.rs +++ b/unreal_asset/unreal_asset_base/src/unversioned/properties/enum_property.rs @@ -5,6 +5,7 @@ use std::mem::size_of; use byteorder::WriteBytesExt; use crate::reader::{ArchiveReader, ArchiveWriter}; +use crate::types::{PackageIndex}; use crate::unversioned::{usmap_reader::UsmapReader, usmap_writer::UsmapWriter}; use crate::Error; @@ -21,7 +22,9 @@ pub struct UsmapEnumPropertyData { impl UsmapEnumPropertyData { /// Read a `UsmapEnumPropertyData` from an asset - pub fn new<R: ArchiveReader>(asset: &mut UsmapReader<'_, '_, R>) -> Result<Self, Error> { + pub fn new<R: ArchiveReader<PackageIndex>>( + asset: &mut UsmapReader<'_, '_, R>, + ) -> Result<Self, Error> { let inner_property = UsmapPropertyData::new(asset)?; let name = asset.read_name()?; @@ -33,7 +36,10 @@ impl UsmapEnumPropertyData { } impl UsmapPropertyDataTrait for UsmapEnumPropertyData { - fn write<W: ArchiveWriter>(&self, asset: &mut UsmapWriter<'_, '_, W>) -> Result<usize, Error> { + fn write<W: ArchiveWriter<PackageIndex>>( + &self, + asset: &mut UsmapWriter<'_, '_, W>, + ) -> Result<usize, Error> { asset.write_u8(EPropertyType::EnumProperty as u8)?; let size = self.inner_property.write(asset)?; asset.write_name(&self.name)?; diff --git a/unreal_asset/unreal_asset_base/src/unversioned/properties/map_property.rs b/unreal_asset/unreal_asset_base/src/unversioned/properties/map_property.rs index 0062c5f0..a6fde320 100644 --- a/unreal_asset/unreal_asset_base/src/unversioned/properties/map_property.rs +++ b/unreal_asset/unreal_asset_base/src/unversioned/properties/map_property.rs @@ -5,6 +5,7 @@ use std::mem::size_of; use byteorder::WriteBytesExt; use crate::reader::{ArchiveReader, ArchiveWriter}; +use crate::types::{PackageIndex}; use crate::unversioned::{usmap_reader::UsmapReader, usmap_writer::UsmapWriter}; use crate::Error; @@ -21,7 +22,9 @@ pub struct UsmapMapPropertyData { impl UsmapMapPropertyData { /// Read a `UsmapMapPropertyData` from an asset - pub fn new<R: ArchiveReader>(asset: &mut UsmapReader<'_, '_, R>) -> Result<Self, Error> { + pub fn new<R: ArchiveReader<PackageIndex>>( + asset: &mut UsmapReader<'_, '_, R>, + ) -> Result<Self, Error> { let inner_type = UsmapPropertyData::new(asset)?; let value_type = UsmapPropertyData::new(asset)?; @@ -33,7 +36,10 @@ impl UsmapMapPropertyData { } impl UsmapPropertyDataTrait for UsmapMapPropertyData { - fn write<W: ArchiveWriter>(&self, asset: &mut UsmapWriter<'_, '_, W>) -> Result<usize, Error> { + fn write<W: ArchiveWriter<PackageIndex>>( + &self, + asset: &mut UsmapWriter<'_, '_, W>, + ) -> Result<usize, Error> { asset.write_u8(EPropertyType::MapProperty as u8)?; let mut size = self.inner_type.write(asset)?; size += self.value_type.write(asset)?; diff --git a/unreal_asset/unreal_asset_base/src/unversioned/properties/mod.rs b/unreal_asset/unreal_asset_base/src/unversioned/properties/mod.rs index d3aeee1a..627e1404 100644 --- a/unreal_asset/unreal_asset_base/src/unversioned/properties/mod.rs +++ b/unreal_asset/unreal_asset_base/src/unversioned/properties/mod.rs @@ -8,6 +8,7 @@ use enum_dispatch::enum_dispatch; use num_enum::{IntoPrimitive, TryFromPrimitive}; use crate::reader::{ArchiveReader, ArchiveWriter}; +use crate::types::{PackageIndex}; use crate::unversioned::{usmap_reader::UsmapReader, usmap_writer::UsmapWriter}; use crate::Error; @@ -131,7 +132,10 @@ pub trait UsmapPropertyDataTrait: Debug + Hash + Clone + PartialEq + Eq { /// Get `UsmapPropertyData` property type fn get_property_type(&self) -> EPropertyType; /// Write `UsmapPropertyData` to an asset - fn write<W: ArchiveWriter>(&self, writer: &mut UsmapWriter<'_, '_, W>) -> Result<usize, Error>; + fn write<W: ArchiveWriter<PackageIndex>>( + &self, + writer: &mut UsmapWriter<'_, '_, W>, + ) -> Result<usize, Error>; } /// UsmapPropertyData @@ -155,7 +159,9 @@ pub enum UsmapPropertyData { impl UsmapPropertyData { /// Read an `UsmapPropertyData` from an asset - pub fn new<R: ArchiveReader>(asset: &mut UsmapReader<'_, '_, R>) -> Result<Self, Error> { + pub fn new<R: ArchiveReader<PackageIndex>>( + asset: &mut UsmapReader<'_, '_, R>, + ) -> Result<Self, Error> { let prop_type: EPropertyType = EPropertyType::try_from(asset.read_u8()?)?; let res: UsmapPropertyData = match prop_type { @@ -191,7 +197,9 @@ pub struct UsmapProperty { impl UsmapProperty { /// Read an `UsmapProperty` from an asset - pub fn new<R: ArchiveReader>(asset: &mut UsmapReader<'_, '_, R>) -> Result<Self, Error> { + pub fn new<R: ArchiveReader<PackageIndex>>( + asset: &mut UsmapReader<'_, '_, R>, + ) -> Result<Self, Error> { let schema_index = asset.read_u16::<LE>()?; let array_size = asset.read_u8()?; let name = asset.read_name()?; diff --git a/unreal_asset/unreal_asset_base/src/unversioned/properties/set_property.rs b/unreal_asset/unreal_asset_base/src/unversioned/properties/set_property.rs index bf0d2e12..20dea1bc 100644 --- a/unreal_asset/unreal_asset_base/src/unversioned/properties/set_property.rs +++ b/unreal_asset/unreal_asset_base/src/unversioned/properties/set_property.rs @@ -5,6 +5,7 @@ use std::mem::size_of; use byteorder::WriteBytesExt; use crate::reader::{ArchiveReader, ArchiveWriter}; +use crate::types::{PackageIndex}; use crate::unversioned::{usmap_reader::UsmapReader, usmap_writer::UsmapWriter}; use crate::Error; @@ -19,7 +20,9 @@ pub struct UsmapSetPropertyData { impl UsmapSetPropertyData { /// Read a `UsmapSetPropertyData` from an asset - pub fn new<R: ArchiveReader>(asset: &mut UsmapReader<'_, '_, R>) -> Result<Self, Error> { + pub fn new<R: ArchiveReader<PackageIndex>>( + asset: &mut UsmapReader<'_, '_, R>, + ) -> Result<Self, Error> { let inner_type = UsmapPropertyData::new(asset)?; Ok(UsmapSetPropertyData { @@ -29,7 +32,10 @@ impl UsmapSetPropertyData { } impl UsmapPropertyDataTrait for UsmapSetPropertyData { - fn write<W: ArchiveWriter>(&self, asset: &mut UsmapWriter<'_, '_, W>) -> Result<usize, Error> { + fn write<W: ArchiveWriter<PackageIndex>>( + &self, + asset: &mut UsmapWriter<'_, '_, W>, + ) -> Result<usize, Error> { asset.write_u8(EPropertyType::SetProperty as u8)?; let size = self.inner_type.write(asset)?; Ok(size + size_of::<u8>()) diff --git a/unreal_asset/unreal_asset_base/src/unversioned/properties/shallow_property.rs b/unreal_asset/unreal_asset_base/src/unversioned/properties/shallow_property.rs index 95bd87f7..d7d14558 100644 --- a/unreal_asset/unreal_asset_base/src/unversioned/properties/shallow_property.rs +++ b/unreal_asset/unreal_asset_base/src/unversioned/properties/shallow_property.rs @@ -2,9 +2,10 @@ use byteorder::WriteBytesExt; -use crate::reader::ArchiveWriter; +use crate::types::PackageIndex; use crate::unversioned::usmap_writer::UsmapWriter; use crate::Error; +use crate::{reader::ArchiveWriter}; use super::{EPropertyType, UsmapPropertyDataTrait}; @@ -16,7 +17,10 @@ pub struct UsmapShallowPropertyData { } impl UsmapPropertyDataTrait for UsmapShallowPropertyData { - fn write<W: ArchiveWriter>(&self, asset: &mut UsmapWriter<'_, '_, W>) -> Result<usize, Error> { + fn write<W: ArchiveWriter<PackageIndex>>( + &self, + asset: &mut UsmapWriter<'_, '_, W>, + ) -> Result<usize, Error> { asset.write_u8(self.property_type as u8)?; Ok(0) } diff --git a/unreal_asset/unreal_asset_base/src/unversioned/properties/struct_property.rs b/unreal_asset/unreal_asset_base/src/unversioned/properties/struct_property.rs index 1d6754d4..f0c2bbde 100644 --- a/unreal_asset/unreal_asset_base/src/unversioned/properties/struct_property.rs +++ b/unreal_asset/unreal_asset_base/src/unversioned/properties/struct_property.rs @@ -5,6 +5,7 @@ use std::mem::size_of; use byteorder::WriteBytesExt; use crate::reader::{ArchiveReader, ArchiveWriter}; +use crate::types::{PackageIndex}; use crate::unversioned::{usmap_reader::UsmapReader, usmap_writer::UsmapWriter}; use crate::Error; @@ -19,7 +20,9 @@ pub struct UsmapStructPropertyData { impl UsmapStructPropertyData { /// Read a `UsmapStructPropertyData` from an asset - pub fn new<R: ArchiveReader>(asset: &mut UsmapReader<'_, '_, R>) -> Result<Self, Error> { + pub fn new<R: ArchiveReader<PackageIndex>>( + asset: &mut UsmapReader<'_, '_, R>, + ) -> Result<Self, Error> { let struct_type = asset.read_name()?; Ok(UsmapStructPropertyData { struct_type }) @@ -27,7 +30,10 @@ impl UsmapStructPropertyData { } impl UsmapPropertyDataTrait for UsmapStructPropertyData { - fn write<W: ArchiveWriter>(&self, asset: &mut UsmapWriter<'_, '_, W>) -> Result<usize, Error> { + fn write<W: ArchiveWriter<PackageIndex>>( + &self, + asset: &mut UsmapWriter<'_, '_, W>, + ) -> Result<usize, Error> { asset.write_u8(EPropertyType::StructProperty as u8)?; asset.write_name(&self.struct_type)?; Ok(size_of::<i32>() * 2) diff --git a/unreal_asset/unreal_asset_base/src/unversioned/usmap_reader.rs b/unreal_asset/unreal_asset_base/src/unversioned/usmap_reader.rs index 1613565a..4f830442 100644 --- a/unreal_asset/unreal_asset_base/src/unversioned/usmap_reader.rs +++ b/unreal_asset/unreal_asset_base/src/unversioned/usmap_reader.rs @@ -11,18 +11,18 @@ use crate::{ engine_version::EngineVersion, error::{Error, UsmapError}, object_version::{ObjectVersion, ObjectVersionUE5}, + passthrough_archive_reader, reader::{ - archive_reader::{ArchiveReader, PassthroughArchiveReader}, + archive_reader::ArchiveReader, archive_trait::{ArchiveTrait, ArchiveType}, }, types::{FName, PackageIndex}, - Import, }; use super::Usmap; /// Usmap file reader -pub struct UsmapReader<'parent_reader, 'asset, R: ArchiveReader> { +pub struct UsmapReader<'parent_reader, 'asset, R: ArchiveReader<PackageIndex>> { /// Parent reader parent_reader: &'parent_reader mut R, /// Name map @@ -31,7 +31,9 @@ pub struct UsmapReader<'parent_reader, 'asset, R: ArchiveReader> { custom_versions: &'asset [CustomVersion], } -impl<'parent_reader, 'asset, R: ArchiveReader> UsmapReader<'parent_reader, 'asset, R> { +impl<'parent_reader, 'asset, R: ArchiveReader<PackageIndex>> + UsmapReader<'parent_reader, 'asset, R> +{ /// Create a new `UsmapReader` instance pub fn new( parent_reader: &'parent_reader mut R, @@ -57,7 +59,7 @@ impl<'parent_reader, 'asset, R: ArchiveReader> UsmapReader<'parent_reader, 'asse } } -impl<'parent_reader, 'asset, R: ArchiveReader> ArchiveTrait +impl<'parent_reader, 'asset, R: ArchiveReader<PackageIndex>> ArchiveTrait<PackageIndex> for UsmapReader<'parent_reader, 'asset, R> { fn get_archive_type(&self) -> ArchiveType { @@ -123,28 +125,32 @@ impl<'parent_reader, 'asset, R: ArchiveReader> ArchiveTrait self.parent_reader.get_parent_class_export_name() } - fn get_import(&self, index: PackageIndex) -> Option<Import> { - self.parent_reader.get_import(index) + fn get_object_name(&self, index: PackageIndex) -> Option<FName> { + self.parent_reader.get_object_name(index) + } + + fn get_object_name_packageindex(&self, index: PackageIndex) -> Option<FName> { + self.parent_reader.get_object_name_packageindex(index) } } -impl<'parent_reader, 'asset, R: ArchiveReader> PassthroughArchiveReader +impl<'parent_reader, 'asset, R: ArchiveReader<PackageIndex>> ArchiveReader<PackageIndex> for UsmapReader<'parent_reader, 'asset, R> { - type Passthrough = R; - - fn get_passthrough(&mut self) -> &mut Self::Passthrough { - self.parent_reader - } + passthrough_archive_reader!(parent_reader); } -impl<'parent_reader, 'asset, R: ArchiveReader> Read for UsmapReader<'parent_reader, 'asset, R> { +impl<'parent_reader, 'asset, R: ArchiveReader<PackageIndex>> Read + for UsmapReader<'parent_reader, 'asset, R> +{ fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> { self.parent_reader.read(buf) } } -impl<'parent_reader, 'asset, R: ArchiveReader> Seek for UsmapReader<'parent_reader, 'asset, R> { +impl<'parent_reader, 'asset, R: ArchiveReader<PackageIndex>> Seek + for UsmapReader<'parent_reader, 'asset, R> +{ fn seek(&mut self, pos: std::io::SeekFrom) -> std::io::Result<u64> { self.parent_reader.seek(pos) } diff --git a/unreal_asset/unreal_asset_base/src/unversioned/usmap_writer.rs b/unreal_asset/unreal_asset_base/src/unversioned/usmap_writer.rs index 54a0d546..71ae4ee6 100644 --- a/unreal_asset/unreal_asset_base/src/unversioned/usmap_writer.rs +++ b/unreal_asset/unreal_asset_base/src/unversioned/usmap_writer.rs @@ -8,18 +8,18 @@ use crate::{ engine_version::EngineVersion, error::Error, object_version::{ObjectVersion, ObjectVersionUE5}, + passthrough_archive_writer, reader::{ archive_trait::{ArchiveTrait, ArchiveType}, - archive_writer::{ArchiveWriter, PassthroughArchiveWriter}, + archive_writer::ArchiveWriter, }, types::{FName, PackageIndex}, - Import, }; use super::Usmap; /// Usmap file writer -pub struct UsmapWriter<'parent_writer, 'asset, W: ArchiveWriter> { +pub struct UsmapWriter<'parent_writer, 'asset, W: ArchiveWriter<PackageIndex>> { /// Parent writer parent_writer: &'parent_writer mut W, /// Name map @@ -28,14 +28,16 @@ pub struct UsmapWriter<'parent_writer, 'asset, W: ArchiveWriter> { custom_versions: &'asset [CustomVersion], } -impl<'parent_writer, 'asset, W: ArchiveWriter> UsmapWriter<'parent_writer, 'asset, W> { +impl<'parent_writer, 'asset, W: ArchiveWriter<PackageIndex>> + UsmapWriter<'parent_writer, 'asset, W> +{ /// Write a name to this archive pub fn write_name(&mut self, _: &str) -> Result<usize, Error> { todo!() } } -impl<'parent_writer, 'asset, W: ArchiveWriter> ArchiveTrait +impl<'parent_writer, 'asset, W: ArchiveWriter<PackageIndex>> ArchiveTrait<PackageIndex> for UsmapWriter<'parent_writer, 'asset, W> { fn get_archive_type(&self) -> ArchiveType { @@ -101,22 +103,24 @@ impl<'parent_writer, 'asset, W: ArchiveWriter> ArchiveTrait self.parent_writer.get_parent_class_export_name() } - fn get_import(&self, index: PackageIndex) -> Option<Import> { - self.parent_writer.get_import(index) + fn get_object_name(&self, index: PackageIndex) -> Option<FName> { + self.parent_writer.get_object_name(index) + } + + fn get_object_name_packageindex(&self, index: PackageIndex) -> Option<FName> { + self.parent_writer.get_object_name_packageindex(index) } } -impl<'parent_writer, 'asset, W: ArchiveWriter> PassthroughArchiveWriter +impl<'parent_writer, 'asset, W: ArchiveWriter<PackageIndex>> ArchiveWriter<PackageIndex> for UsmapWriter<'parent_writer, 'asset, W> { - type Passthrough = W; - - fn get_passthrough(&mut self) -> &mut Self::Passthrough { - self.parent_writer - } + passthrough_archive_writer!(parent_writer); } -impl<'parent_writer, 'asset, W: ArchiveWriter> Write for UsmapWriter<'parent_writer, 'asset, W> { +impl<'parent_writer, 'asset, W: ArchiveWriter<PackageIndex>> Write + for UsmapWriter<'parent_writer, 'asset, W> +{ fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> { self.parent_writer.write(buf) } @@ -126,7 +130,9 @@ impl<'parent_writer, 'asset, W: ArchiveWriter> Write for UsmapWriter<'parent_wri } } -impl<'parent_writer, 'asset, W: ArchiveWriter> Seek for UsmapWriter<'parent_writer, 'asset, W> { +impl<'parent_writer, 'asset, W: ArchiveWriter<PackageIndex>> Seek + for UsmapWriter<'parent_writer, 'asset, W> +{ fn seek(&mut self, pos: std::io::SeekFrom) -> std::io::Result<u64> { self.parent_writer.seek(pos) } diff --git a/unreal_asset/unreal_asset_exports/src/base_export.rs b/unreal_asset/unreal_asset_exports/src/base_export.rs index 9ec7f465..b6365f0b 100644 --- a/unreal_asset/unreal_asset_exports/src/base_export.rs +++ b/unreal_asset/unreal_asset_exports/src/base_export.rs @@ -1,15 +1,14 @@ //! Base uasset export -use std::io::Cursor; -use byteorder::{ReadBytesExt, WriteBytesExt, LE}; + + use num_enum::{IntoPrimitive, TryFromPrimitive}; use unreal_asset_base::{ flags::EObjectFlags, - object_version::{ObjectVersion, ObjectVersionUE5}, - reader::{ArchiveReader, ArchiveTrait, ArchiveType, ArchiveWriter, RawWriter}, - types::{FName, PackageIndex}, + reader::{ArchiveTrait, ArchiveWriter}, + types::{FName, PackageIndex, PackageIndexTrait}, Error, FNameContainer, Guid, }; @@ -28,28 +27,20 @@ pub enum EExportFilterFlags { } /// Minimal information about an export -#[derive(FNameContainer, Debug, Clone, Default, PartialEq, Eq, Hash)] -pub struct BaseExport { +#[derive(FNameContainer, Debug, Default, Clone, PartialEq, Eq, Hash)] +pub struct BaseExport<Index: PackageIndexTrait> { /// Class index #[container_ignore] - pub class_index: PackageIndex, - /// Zen class index - + pub class_index: Index, /// Super index #[container_ignore] - pub super_index: PackageIndex, - /// Zen super index - + pub super_index: Index, /// Template index #[container_ignore] - pub template_index: PackageIndex, - /// Zen template index - + pub template_index: Index, /// Outer index #[container_ignore] - pub outer_index: PackageIndex, - /// Zen outer index - + pub outer_index: Index, /// Object name pub object_name: FName, /// Object flags @@ -98,263 +89,41 @@ pub struct BaseExport { pub create_before_create_dependencies: Vec<PackageIndex>, } -impl BaseExport { +impl<Index: PackageIndexTrait> BaseExport<Index> { /// Gets class type for first ancestry parent - pub fn get_class_type_for_ancestry<Asset: ArchiveTrait>(&self, asset: &Asset) -> FName { + pub fn get_class_type_for_ancestry<Asset: ArchiveTrait<Index>>(&self, asset: &Asset) -> FName { match self.class_index.is_import() { - true => asset.get_import(self.class_index).map(|e| e.object_name), + true => asset.get_object_name(self.class_index), false => asset.get_parent_class_export_name(), } .unwrap_or_default() } - - /// Read `BaseExport` from an archive - pub fn read_export_map_entry<Archive: ArchiveReader>( - reader: &mut Archive, - ) -> Result<Self, Error> { - match reader.get_archive_type() { - ArchiveType::UAsset => Self::read_export_map_entry_uasset(reader), - _ => Err(Error::archive_type_mismatch( - &[ArchiveType::UAsset, ArchiveType::Zen], - reader.get_archive_type(), - )), - } - } - - /// UAsset specific export map entry reading implementation - fn read_export_map_entry_uasset<Archive: ArchiveReader>( - reader: &mut Archive, - ) -> Result<Self, Error> { - let mut export = BaseExport { - class_index: PackageIndex::new(reader.read_i32::<LE>()?), - super_index: PackageIndex::new(reader.read_i32::<LE>()?), - ..Default::default() - }; - - if reader.get_object_version() >= ObjectVersion::VER_UE4_TemplateIndex_IN_COOKED_EXPORTS { - export.template_index = PackageIndex::new(reader.read_i32::<LE>()?); - } - - export.outer_index = PackageIndex::new(reader.read_i32::<LE>()?); - export.object_name = reader.read_fname()?; - export.object_flags = EObjectFlags::from_bits(reader.read_u32::<LE>()?) - .ok_or_else(|| Error::invalid_file("Invalid property flags".to_string()))?; - - if reader.get_object_version() < ObjectVersion::VER_UE4_64BIT_EXPORTMAP_SERIALSIZES { - export.serial_size = reader.read_i32::<LE>()? as i64; - export.serial_offset = reader.read_i32::<LE>()? as i64; - } else { - export.serial_size = reader.read_i64::<LE>()?; - export.serial_offset = reader.read_i64::<LE>()?; - } - - export.forced_export = reader.read_i32::<LE>()? == 1; - export.not_for_client = reader.read_i32::<LE>()? == 1; - export.not_for_server = reader.read_i32::<LE>()? == 1; - - if reader.get_object_version_ue5() < ObjectVersionUE5::REMOVE_OBJECT_EXPORT_PACKAGE_GUID { - export.package_guid = reader.read_guid()?; - } - - if reader.get_object_version_ue5() >= ObjectVersionUE5::TRACK_OBJECT_EXPORT_IS_INHERITED { - export.is_inherited_instance = reader.read_i32::<LE>()? == 1; - } - - export.package_flags = reader.read_u32::<LE>()?; - - if reader.get_object_version() >= ObjectVersion::VER_UE4_LOAD_FOR_EDITOR_GAME { - export.not_always_loaded_for_editor_game = reader.read_i32::<LE>()? == 1; - } - - if reader.get_object_version() >= ObjectVersion::VER_UE4_COOKED_ASSETS_IN_EDITOR_SUPPORT { - export.is_asset = reader.read_i32::<LE>()? == 1; - } - - if reader.get_object_version_ue5() >= ObjectVersionUE5::OPTIONAL_RESOURCES { - export.generate_public_hash = reader.read_i32::<LE>()? == 1; - } - - if reader.get_object_version() - >= ObjectVersion::VER_UE4_PRELOAD_DEPENDENCIES_IN_COOKED_EXPORTS - { - export.first_export_dependency_offset = reader.read_i32::<LE>()?; - export.serialization_before_serialization_dependencies = - Vec::with_capacity(reader.read_i32::<LE>()? as usize); - export.create_before_serialization_dependencies = - Vec::with_capacity(reader.read_i32::<LE>()? as usize); - export.serialization_before_create_dependencies = - Vec::with_capacity(reader.read_i32::<LE>()? as usize); - export.create_before_create_dependencies = - Vec::with_capacity(reader.read_i32::<LE>()? as usize); - } - - Ok(export) - } - - /// Write `BaseExport` export map entry to an archive - pub fn write_export_map_entry<Archive: ArchiveWriter>( - &self, - writer: &mut Archive, - serial_size: i64, - serial_offset: i64, - first_export_dependency_offset: i32, - ) -> Result<(), Error> { - match writer.get_archive_type() { - ArchiveType::UAsset => self.write_export_map_entry_uasset( - writer, - serial_size, - serial_offset, - first_export_dependency_offset, - ), - _ => Err(Error::archive_type_mismatch( - &[ArchiveType::UAsset, ArchiveType::Zen], - writer.get_archive_type(), - )), - } - } - - /// UAsset specific export map entry writing implementation - fn write_export_map_entry_uasset<Archive: ArchiveWriter>( - &self, - writer: &mut Archive, - serial_size: i64, - serial_offset: i64, - first_export_dependency_offset: i32, - ) -> Result<(), Error> { - writer.write_i32::<LE>(self.class_index.index)?; - writer.write_i32::<LE>(self.super_index.index)?; - - if writer.get_object_version() >= ObjectVersion::VER_UE4_TemplateIndex_IN_COOKED_EXPORTS { - writer.write_i32::<LE>(self.template_index.index)?; - } - - writer.write_i32::<LE>(self.outer_index.index)?; - writer.write_fname(&self.object_name)?; - writer.write_u32::<LE>(self.object_flags.bits())?; - - if writer.get_object_version() < ObjectVersion::VER_UE4_64BIT_EXPORTMAP_SERIALSIZES { - writer.write_i32::<LE>(serial_size as i32)?; - writer.write_i32::<LE>(serial_offset as i32)?; - } else { - writer.write_i64::<LE>(serial_size)?; - writer.write_i64::<LE>(serial_offset)?; - } - - writer.write_i32::<LE>(match self.forced_export { - true => 1, - false => 0, - })?; - writer.write_i32::<LE>(match self.not_for_client { - true => 1, - false => 0, - })?; - writer.write_i32::<LE>(match self.not_for_server { - true => 1, - false => 0, - })?; - - if writer.get_object_version_ue5() < ObjectVersionUE5::REMOVE_OBJECT_EXPORT_PACKAGE_GUID { - writer.write_guid(&self.package_guid)?; - } - - if writer.get_object_version_ue5() >= ObjectVersionUE5::TRACK_OBJECT_EXPORT_IS_INHERITED { - writer.write_i32::<LE>(match self.is_inherited_instance { - true => 1, - false => 0, - })?; - } - - writer.write_u32::<LE>(self.package_flags)?; - - if writer.get_object_version() >= ObjectVersion::VER_UE4_LOAD_FOR_EDITOR_GAME { - writer.write_i32::<LE>(match self.not_always_loaded_for_editor_game { - true => 1, - false => 0, - })?; - } - - if writer.get_object_version() >= ObjectVersion::VER_UE4_COOKED_ASSETS_IN_EDITOR_SUPPORT { - writer.write_i32::<LE>(match self.is_asset { - true => 1, - false => 0, - })?; - } - - if writer.get_object_version_ue5() >= ObjectVersionUE5::OPTIONAL_RESOURCES { - writer.write_i32::<LE>(match self.generate_public_hash { - true => 1, - false => 0, - })?; - } - - if writer.get_object_version() - >= ObjectVersion::VER_UE4_PRELOAD_DEPENDENCIES_IN_COOKED_EXPORTS - { - writer.write_i32::<LE>(first_export_dependency_offset)?; - writer.write_i32::<LE>( - self.serialization_before_serialization_dependencies.len() as i32 - )?; - writer.write_i32::<LE>(self.create_before_serialization_dependencies.len() as i32)?; - writer.write_i32::<LE>(self.serialization_before_create_dependencies.len() as i32)?; - writer.write_i32::<LE>(self.create_before_create_dependencies.len() as i32)?; - } - Ok(()) - } - - /// Get `BaseExport` export map entry size for an archive - pub fn get_export_map_entry_size<Archive: ArchiveTrait>( - archive: &Archive, - ) -> Result<u64, Error> { - let mut cursor = Cursor::new(Vec::new()); - let mut raw_writer = RawWriter::new( - &mut cursor, - archive.get_object_version(), - archive.get_object_version_ue5(), - archive.use_event_driven_loader(), - archive.get_name_map(), - ); - - let default_export = BaseExport { - object_name: FName::new(0, 0, archive.get_name_map()), - ..Default::default() - }; - - match archive.get_archive_type() { - ArchiveType::UAsset => { - default_export.write_export_map_entry_uasset(&mut raw_writer, 0, 0, 0) - } - _ => Err(Error::archive_type_mismatch( - &[ArchiveType::UAsset, ArchiveType::Zen], - archive.get_archive_type(), - )), - }?; - - Ok(raw_writer.position()) - } } -impl ExportNormalTrait for BaseExport { - fn get_normal_export(&'_ self) -> Option<&'_ super::normal_export::NormalExport> { +impl<Index: PackageIndexTrait> ExportNormalTrait<Index> for BaseExport<Index> { + fn get_normal_export(&'_ self) -> Option<&'_ super::normal_export::NormalExport<Index>> { None } - fn get_normal_export_mut(&'_ mut self) -> Option<&'_ mut super::normal_export::NormalExport> { + fn get_normal_export_mut( + &'_ mut self, + ) -> Option<&'_ mut super::normal_export::NormalExport<Index>> { None } } -impl ExportBaseTrait for BaseExport { - fn get_base_export(&'_ self) -> &'_ BaseExport { +impl<Index: PackageIndexTrait> ExportBaseTrait<Index> for BaseExport<Index> { + fn get_base_export(&'_ self) -> &'_ BaseExport<Index> { self } - fn get_base_export_mut(&'_ mut self) -> &'_ mut BaseExport { + fn get_base_export_mut(&'_ mut self) -> &'_ mut BaseExport<Index> { self } } -impl ExportTrait for BaseExport { - fn write<Writer: ArchiveWriter>(&self, _asset: &mut Writer) -> Result<(), Error> { +impl<Index: PackageIndexTrait> ExportTrait<Index> for BaseExport<Index> { + fn write<Writer: ArchiveWriter<Index>>(&self, _asset: &mut Writer) -> Result<(), Error> { Ok(()) } } diff --git a/unreal_asset/unreal_asset_exports/src/class_export.rs b/unreal_asset/unreal_asset_exports/src/class_export.rs index c3670cca..d7380202 100644 --- a/unreal_asset/unreal_asset_exports/src/class_export.rs +++ b/unreal_asset/unreal_asset_exports/src/class_export.rs @@ -10,7 +10,7 @@ use unreal_asset_base::{ flags::EClassFlags, object_version::ObjectVersion, reader::{ArchiveReader, ArchiveWriter}, - types::{FName, PackageIndex}, + types::{FName, PackageIndex, PackageIndexTrait}, Error, FNameContainer, }; @@ -40,10 +40,10 @@ impl SerializedInterfaceReference { } /// Class export -#[derive(FNameContainer, Debug, Clone, Default, PartialEq, Eq)] -pub struct ClassExport { +#[derive(FNameContainer, Debug, Clone, PartialEq, Eq)] +pub struct ClassExport<Index: PackageIndexTrait> { /// Base struct export - pub struct_export: StructExport, + pub struct_export: StructExport<Index>, /// Function map pub func_map: IndexedMap<FName, PackageIndex>, @@ -70,10 +70,10 @@ pub struct ClassExport { pub class_default_object: PackageIndex, } -impl ClassExport { +impl<Index: PackageIndexTrait> ClassExport<Index> { /// Read a `ClassExport` from an asset - pub fn from_base<Reader: ArchiveReader>( - base: &BaseExport, + pub fn from_base<Reader: ArchiveReader<Index>>( + base: &BaseExport<Index>, asset: &mut Reader, ) -> Result<Self, Error> { let struct_export = StructExport::from_base(base, asset)?; @@ -160,7 +160,10 @@ impl ClassExport { } /// Serialize a `ClassExport` interface - fn serialize_interfaces<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { + fn serialize_interfaces<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<(), Error> { asset.write_i32::<LE>(self.interfaces.len() as i32)?; for interface in &self.interfaces { asset.write_i32::<LE>(interface.class.index)?; @@ -174,28 +177,30 @@ impl ClassExport { } } -impl ExportNormalTrait for ClassExport { - fn get_normal_export(&'_ self) -> Option<&'_ super::normal_export::NormalExport> { +impl<Index: PackageIndexTrait> ExportNormalTrait<Index> for ClassExport<Index> { + fn get_normal_export(&'_ self) -> Option<&'_ super::normal_export::NormalExport<Index>> { Some(&self.struct_export.normal_export) } - fn get_normal_export_mut(&'_ mut self) -> Option<&'_ mut super::normal_export::NormalExport> { + fn get_normal_export_mut( + &'_ mut self, + ) -> Option<&'_ mut super::normal_export::NormalExport<Index>> { Some(&mut self.struct_export.normal_export) } } -impl ExportBaseTrait for ClassExport { - fn get_base_export(&'_ self) -> &'_ BaseExport { +impl<Index: PackageIndexTrait> ExportBaseTrait<Index> for ClassExport<Index> { + fn get_base_export(&'_ self) -> &'_ BaseExport<Index> { &self.struct_export.normal_export.base_export } - fn get_base_export_mut(&'_ mut self) -> &'_ mut BaseExport { + fn get_base_export_mut(&'_ mut self) -> &'_ mut BaseExport<Index> { &mut self.struct_export.normal_export.base_export } } -impl ExportTrait for ClassExport { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { +impl<Index: PackageIndexTrait> ExportTrait<Index> for ClassExport<Index> { + fn write<Writer: ArchiveWriter<Index>>(&self, asset: &mut Writer) -> Result<(), Error> { self.struct_export.write(asset)?; asset.write_i32::<LE>(self.func_map.len() as i32)?; diff --git a/unreal_asset/unreal_asset_exports/src/data_table_export.rs b/unreal_asset/unreal_asset_exports/src/data_table_export.rs index eb081a8d..29ef6a1c 100644 --- a/unreal_asset/unreal_asset_exports/src/data_table_export.rs +++ b/unreal_asset/unreal_asset_exports/src/data_table_export.rs @@ -4,7 +4,7 @@ use byteorder::{ReadBytesExt, WriteBytesExt, LE}; use unreal_asset_base::{ reader::{ArchiveReader, ArchiveWriter}, - types::FName, + types::{FName, PackageIndexTrait}, unversioned::Ancestry, Error, FNameContainer, }; @@ -31,19 +31,19 @@ impl DataTable { /// Data table export #[derive(FNameContainer, Debug, Clone, PartialEq, Eq, Hash)] -pub struct DataTableExport { +pub struct DataTableExport<Index: PackageIndexTrait> { /// Base normal export - pub normal_export: NormalExport, + pub normal_export: NormalExport<Index>, /// Data table pub table: DataTable, } implement_get!(DataTableExport); -impl DataTableExport { +impl<Index: PackageIndexTrait> DataTableExport<Index> { /// Read a `DataTableExport` from an asset - pub fn from_base<Reader: ArchiveReader>( - base: &BaseExport, + pub fn from_base<Reader: ArchiveReader<Index>>( + base: &BaseExport<Index>, asset: &mut Reader, ) -> Result<Self, Error> { let normal_export = NormalExport::from_base(base, asset)?; @@ -52,8 +52,8 @@ impl DataTableExport { for data in &normal_export.properties { if let Property::ObjectProperty(property) = data { if property.name == "RowStruct" && property.value.is_import() { - if let Some(import) = asset.get_import(property.value) { - decided_struct_type = import.object_name.clone(); + if let Some(object_name) = asset.get_object_name_packageindex(property.value) { + decided_struct_type = object_name; } } } @@ -91,16 +91,16 @@ impl DataTableExport { } } -impl ExportTrait for DataTableExport { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { +impl<Index: PackageIndexTrait> ExportTrait<Index> for DataTableExport<Index> { + fn write<Writer: ArchiveWriter<Index>>(&self, asset: &mut Writer) -> Result<(), Error> { self.normal_export.write(asset)?; let mut decided_struct_type = FName::from_slice("Generic"); for data in &self.normal_export.properties { if data.get_name() == "RowStruct" { if let Property::ObjectProperty(prop) = data { - if let Some(import) = asset.get_import(prop.value) { - decided_struct_type = import.object_name; + if let Some(object_name) = asset.get_object_name_packageindex(prop.value) { + decided_struct_type = object_name; break; } } diff --git a/unreal_asset/unreal_asset_exports/src/enum_export.rs b/unreal_asset/unreal_asset_exports/src/enum_export.rs index e5268304..1d247562 100644 --- a/unreal_asset/unreal_asset_exports/src/enum_export.rs +++ b/unreal_asset/unreal_asset_exports/src/enum_export.rs @@ -9,7 +9,7 @@ use unreal_asset_base::{ custom_version::FCoreObjectVersion, object_version::ObjectVersion, reader::{ArchiveReader, ArchiveWriter}, - types::FName, + types::{FName, PackageIndexTrait}, Error, FNameContainer, }; @@ -42,7 +42,9 @@ pub struct UEnum { impl UEnum { /// Read a `UEnum` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let mut names = Vec::new(); if asset.get_object_version() < ObjectVersion::VER_UE4_TIGHTLY_PACKED_ENUMS { @@ -86,7 +88,10 @@ impl UEnum { } /// Write a `UEnum` to an asset - pub fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { + pub fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<(), Error> { asset.write_i32::<LE>(self.names.len() as i32)?; if asset.get_object_version() < ObjectVersion::VER_UE4_TIGHTLY_PACKED_ENUMS { // todo: a better algorithm? @@ -127,19 +132,19 @@ impl UEnum { /// Enum export #[derive(FNameContainer, Debug, Clone, PartialEq, Eq, Hash)] -pub struct EnumExport { +pub struct EnumExport<Index: PackageIndexTrait> { /// Base normal export - pub normal_export: NormalExport, + pub normal_export: NormalExport<Index>, /// Enum value pub value: UEnum, } implement_get!(EnumExport); -impl EnumExport { +impl<Index: PackageIndexTrait> EnumExport<Index> { /// Read an `EnumExport` from an asset - pub fn from_base<Reader: ArchiveReader>( - base: &BaseExport, + pub fn from_base<Reader: ArchiveReader<Index>>( + base: &BaseExport<Index>, asset: &mut Reader, ) -> Result<Self, Error> { let normal_export = NormalExport::from_base(base, asset)?; @@ -153,8 +158,8 @@ impl EnumExport { } } -impl ExportTrait for EnumExport { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { +impl<Index: PackageIndexTrait> ExportTrait<Index> for EnumExport<Index> { + fn write<Writer: ArchiveWriter<Index>>(&self, asset: &mut Writer) -> Result<(), Error> { self.normal_export.write(asset)?; asset.write_i32::<LE>(0)?; self.value.write(asset)?; diff --git a/unreal_asset/unreal_asset_exports/src/function_export.rs b/unreal_asset/unreal_asset_exports/src/function_export.rs index 05f9a8d9..922f4d6c 100644 --- a/unreal_asset/unreal_asset_exports/src/function_export.rs +++ b/unreal_asset/unreal_asset_exports/src/function_export.rs @@ -5,6 +5,7 @@ use byteorder::{ReadBytesExt, WriteBytesExt, LE}; use unreal_asset_base::{ flags::EFunctionFlags, reader::{ArchiveReader, ArchiveWriter}, + types::PackageIndexTrait, Error, FNameContainer, }; @@ -12,19 +13,19 @@ use crate::{BaseExport, StructExport}; use crate::{ExportBaseTrait, ExportNormalTrait, ExportTrait}; /// Function export -#[derive(FNameContainer, Debug, Clone, Default, PartialEq, Eq, Hash)] -pub struct FunctionExport { +#[derive(FNameContainer, Debug, Clone, PartialEq, Eq, Hash)] +pub struct FunctionExport<Index: PackageIndexTrait> { /// Base struct export - pub struct_export: StructExport, + pub struct_export: StructExport<Index>, /// Function flags #[container_ignore] pub function_flags: EFunctionFlags, } -impl FunctionExport { +impl<Index: PackageIndexTrait> FunctionExport<Index> { /// Read a `FunctionExport` from an asset - pub fn from_base<Reader: ArchiveReader>( - base: &BaseExport, + pub fn from_base<Reader: ArchiveReader<Index>>( + base: &BaseExport<Index>, asset: &mut Reader, ) -> Result<Self, Error> { let struct_export = StructExport::from_base(base, asset)?; @@ -37,30 +38,32 @@ impl FunctionExport { } } -impl ExportTrait for FunctionExport { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { +impl<Index: PackageIndexTrait> ExportTrait<Index> for FunctionExport<Index> { + fn write<Writer: ArchiveWriter<Index>>(&self, asset: &mut Writer) -> Result<(), Error> { self.struct_export.write(asset)?; asset.write_u32::<LE>(self.function_flags.bits())?; Ok(()) } } -impl ExportNormalTrait for FunctionExport { - fn get_normal_export(&'_ self) -> Option<&'_ super::normal_export::NormalExport> { +impl<Index: PackageIndexTrait> ExportNormalTrait<Index> for FunctionExport<Index> { + fn get_normal_export(&'_ self) -> Option<&'_ super::normal_export::NormalExport<Index>> { self.struct_export.get_normal_export() } - fn get_normal_export_mut(&'_ mut self) -> Option<&'_ mut super::normal_export::NormalExport> { + fn get_normal_export_mut( + &'_ mut self, + ) -> Option<&'_ mut super::normal_export::NormalExport<Index>> { self.struct_export.get_normal_export_mut() } } -impl ExportBaseTrait for FunctionExport { - fn get_base_export(&'_ self) -> &'_ super::base_export::BaseExport { +impl<Index: PackageIndexTrait> ExportBaseTrait<Index> for FunctionExport<Index> { + fn get_base_export(&'_ self) -> &'_ super::base_export::BaseExport<Index> { self.struct_export.get_base_export() } - fn get_base_export_mut(&'_ mut self) -> &'_ mut super::base_export::BaseExport { + fn get_base_export_mut(&'_ mut self) -> &'_ mut super::base_export::BaseExport<Index> { self.struct_export.get_base_export_mut() } } diff --git a/unreal_asset/unreal_asset_exports/src/level_export.rs b/unreal_asset/unreal_asset_exports/src/level_export.rs index 55bf3bbb..a450329e 100644 --- a/unreal_asset/unreal_asset_exports/src/level_export.rs +++ b/unreal_asset/unreal_asset_exports/src/level_export.rs @@ -4,7 +4,7 @@ use byteorder::{ReadBytesExt, WriteBytesExt, LE}; use unreal_asset_base::{ reader::{ArchiveReader, ArchiveWriter}, - types::PackageIndex, + types::{PackageIndex, PackageIndexTrait}, Error, FNameContainer, }; @@ -32,10 +32,10 @@ pub struct URL { } /// Level export -#[derive(FNameContainer, Debug, Clone, Default, PartialEq, Eq, Hash)] -pub struct LevelExport { +#[derive(FNameContainer, Debug, Clone, PartialEq, Eq, Hash)] +pub struct LevelExport<Index: PackageIndexTrait> { /// Base normal export - pub normal_export: NormalExport, + pub normal_export: NormalExport<Index>, /// Level URL info pub url: URL, @@ -61,10 +61,10 @@ pub struct LevelExport { implement_get!(LevelExport); -impl LevelExport { +impl<Index: PackageIndexTrait> LevelExport<Index> { /// Read a `LevelExport` from an asset - pub fn from_base<Reader: ArchiveReader>( - unk: &BaseExport, + pub fn from_base<Reader: ArchiveReader<Index>>( + unk: &BaseExport<Index>, asset: &mut Reader, ) -> Result<Self, Error> { let normal_export = NormalExport::from_base(unk, asset)?; @@ -92,8 +92,8 @@ impl LevelExport { } } -impl ExportTrait for LevelExport { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { +impl<Index: PackageIndexTrait> ExportTrait<Index> for LevelExport<Index> { + fn write<Writer: ArchiveWriter<Index>>(&self, asset: &mut Writer) -> Result<(), Error> { self.normal_export.write(asset)?; asset.write_i32::<LE>(0)?; diff --git a/unreal_asset/unreal_asset_exports/src/lib.rs b/unreal_asset/unreal_asset_exports/src/lib.rs index 456dd43c..1e392132 100644 --- a/unreal_asset/unreal_asset_exports/src/lib.rs +++ b/unreal_asset/unreal_asset_exports/src/lib.rs @@ -5,9 +5,7 @@ use std::fmt::Debug; -use enum_dispatch::enum_dispatch; - -use unreal_asset_base::{reader::ArchiveWriter, Error, FNameContainer}; +use unreal_asset_base::{reader::ArchiveWriter, types::PackageIndexTrait, Error, FNameContainer}; pub mod properties; @@ -36,43 +34,45 @@ pub use self::{ /// This must be implemented for all Exports /// Allows for getting a NormalExport from any export containing one /// If an export doesn't have one return None -#[enum_dispatch] -pub trait ExportNormalTrait { +pub trait ExportNormalTrait<Index: PackageIndexTrait> { /// Get a reference to `NormalExport` - fn get_normal_export(&'_ self) -> Option<&'_ NormalExport>; + fn get_normal_export(&'_ self) -> Option<&'_ NormalExport<Index>>; /// Get a mutable reference to `NormalExport` - fn get_normal_export_mut(&'_ mut self) -> Option<&'_ mut NormalExport>; + fn get_normal_export_mut(&'_ mut self) -> Option<&'_ mut NormalExport<Index>>; } /// This must be implemented for all Exports -#[enum_dispatch] -pub trait ExportBaseTrait { +pub trait ExportBaseTrait<Index: PackageIndexTrait> { /// Get a reference to `BaseExport` - fn get_base_export(&'_ self) -> &'_ BaseExport; + fn get_base_export(&'_ self) -> &'_ BaseExport<Index>; /// Get a mutable reference to `BaseExport` - fn get_base_export_mut(&'_ mut self) -> &'_ mut BaseExport; + fn get_base_export_mut(&'_ mut self) -> &'_ mut BaseExport<Index>; } /// Implement `ExportNormalTrait` + `ExportBaseTrait` for an export that contains a `NormalExport` #[macro_export] macro_rules! implement_get { ($name:ident) => { - impl $crate::ExportNormalTrait for $name { - fn get_normal_export(&self) -> Option<&NormalExport> { + impl<Index: unreal_asset_base::types::PackageIndexTrait> $crate::ExportNormalTrait<Index> + for $name<Index> + { + fn get_normal_export(&self) -> Option<&NormalExport<Index>> { Some(&self.normal_export) } - fn get_normal_export_mut(&mut self) -> Option<&mut NormalExport> { + fn get_normal_export_mut(&mut self) -> Option<&mut NormalExport<Index>> { Some(&mut self.normal_export) } } - impl $crate::ExportBaseTrait for $name { - fn get_base_export(&self) -> &BaseExport { + impl<Index: unreal_asset_base::types::PackageIndexTrait> $crate::ExportBaseTrait<Index> + for $name<Index> + { + fn get_base_export(&self) -> &BaseExport<Index> { &self.normal_export.base_export } - fn get_base_export_mut(&mut self) -> &mut BaseExport { + fn get_base_export_mut(&mut self) -> &mut BaseExport<Index> { &mut self.normal_export.base_export } } @@ -80,43 +80,116 @@ macro_rules! implement_get { } /// This must be implemented for all Exports -#[enum_dispatch] -pub trait ExportTrait: Debug + Clone + PartialEq + Eq { +pub trait ExportTrait<Index: PackageIndexTrait>: Debug + Clone + PartialEq + Eq { /// Write this `Export` to an asset - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error>; + fn write<Writer: ArchiveWriter<Index>>(&self, asset: &mut Writer) -> Result<(), Error>; } /// Export -#[enum_dispatch(ExportTrait, ExportNormalTrait, ExportBaseTrait)] #[derive(FNameContainer, Debug, Clone, PartialEq, Eq)] #[container_nobounds] -pub enum Export { +pub enum Export<Index: PackageIndexTrait> { /// Base export - BaseExport, + BaseExport(BaseExport<Index>), /// Class export - ClassExport, + ClassExport(ClassExport<Index>), /// Enum export - EnumExport, + EnumExport(EnumExport<Index>), /// Level export - LevelExport, + LevelExport(LevelExport<Index>), /// Normal export, usually the base for all other exports - NormalExport, + NormalExport(NormalExport<Index>), /// Property export - PropertyExport, + PropertyExport(PropertyExport<Index>), /// Raw export, exists if an export failed to deserialize - RawExport, + RawExport(RawExport<Index>), /// String table export - StringTableExport, + StringTableExport(StringTableExport<Index>), /// Struct export - StructExport, + StructExport(StructExport<Index>), /// User defined struct export - UserDefinedStructExport, + UserDefinedStructExport(UserDefinedStructExport<Index>), /// Function export - FunctionExport, + FunctionExport(FunctionExport<Index>), /// Data table export - DataTableExport, + DataTableExport(DataTableExport<Index>), /// World export - WorldExport, + WorldExport(WorldExport<Index>), +} + +/// Macro to mimic `enum_dispatch` functionality because we need generics in traits +macro_rules! manual_dispatch { + ($($variant:ident),*) => { + impl<Index: PackageIndexTrait> ExportTrait<Index> for Export<Index> { + fn write<Writer: ArchiveWriter<Index>>(&self, asset: &mut Writer) -> Result<(), Error> { + match self { + $( + Export::$variant(e) => e.write(asset) + ),* + } + } + } + + impl<Index: PackageIndexTrait> ExportBaseTrait<Index> for Export<Index> { + fn get_base_export(&self) -> &BaseExport<Index> { + match self { + $( + Export::$variant(e) => e.get_base_export() + ),* + } + } + + fn get_base_export_mut(&mut self) -> &mut BaseExport<Index> { + match self { + $( + Export::$variant(e) => e.get_base_export_mut() + ),* + } + } + } + + impl<Index: PackageIndexTrait> ExportNormalTrait<Index> for Export<Index> { + fn get_normal_export(&self) -> Option<&NormalExport<Index>> { + match self { + $( + Export::$variant(e) => e.get_normal_export() + ),* + } + } + + fn get_normal_export_mut(&mut self) -> Option<&mut NormalExport<Index>> { + match self { + $( + Export::$variant(e) => e.get_normal_export_mut() + ),* + } + } + } + + $( + impl<Index: PackageIndexTrait> From<$variant<Index>> for Export<Index> { + fn from(e: $variant<Index>) -> Export<Index> { + Export::$variant(e) + } + } + )* + }; +} + +manual_dispatch! { + BaseExport, + ClassExport, + EnumExport, + LevelExport, + NormalExport, + PropertyExport, + RawExport, + StringTableExport, + StructExport, + UserDefinedStructExport, + FunctionExport, + DataTableExport, + WorldExport } // todo: impl hash for export diff --git a/unreal_asset/unreal_asset_exports/src/normal_export.rs b/unreal_asset/unreal_asset_exports/src/normal_export.rs index 431c4e7c..99c41d1d 100644 --- a/unreal_asset/unreal_asset_exports/src/normal_export.rs +++ b/unreal_asset/unreal_asset_exports/src/normal_export.rs @@ -2,6 +2,7 @@ use unreal_asset_base::{ reader::{ArchiveReader, ArchiveWriter}, + types::PackageIndexTrait, unversioned::{header::UnversionedHeader, Ancestry}, Error, FNameContainer, }; @@ -13,40 +14,40 @@ use crate::{ExportBaseTrait, ExportNormalTrait, ExportTrait}; /// Normal export /// /// This export is usually the base export for all other exports -#[derive(FNameContainer, Debug, Clone, Default, PartialEq, Eq, Hash)] -pub struct NormalExport { +#[derive(FNameContainer, Debug, Clone, PartialEq, Eq, Hash)] +pub struct NormalExport<Index: PackageIndexTrait> { /// Base export - pub base_export: BaseExport, + pub base_export: BaseExport<Index>, /// Extra data pub extras: Vec<u8>, /// Properties pub properties: Vec<Property>, } -impl ExportNormalTrait for NormalExport { - fn get_normal_export(&'_ self) -> Option<&'_ NormalExport> { +impl<Index: PackageIndexTrait> ExportNormalTrait<Index> for NormalExport<Index> { + fn get_normal_export(&'_ self) -> Option<&'_ NormalExport<Index>> { Some(self) } - fn get_normal_export_mut(&'_ mut self) -> Option<&'_ mut NormalExport> { + fn get_normal_export_mut(&'_ mut self) -> Option<&'_ mut NormalExport<Index>> { Some(self) } } -impl ExportBaseTrait for NormalExport { - fn get_base_export(&'_ self) -> &'_ BaseExport { +impl<Index: PackageIndexTrait> ExportBaseTrait<Index> for NormalExport<Index> { + fn get_base_export(&'_ self) -> &'_ BaseExport<Index> { &self.base_export } - fn get_base_export_mut(&'_ mut self) -> &'_ mut BaseExport { + fn get_base_export_mut(&'_ mut self) -> &'_ mut BaseExport<Index> { &mut self.base_export } } -impl NormalExport { +impl<Index: PackageIndexTrait> NormalExport<Index> { /// Read a `NormalExport` from an asset - pub fn from_base<Reader: ArchiveReader>( - base: &BaseExport, + pub fn from_base<Reader: ArchiveReader<Index>>( + base: &BaseExport<Index>, asset: &mut Reader, ) -> Result<Self, Error> { let mut properties = Vec::new(); @@ -68,8 +69,8 @@ impl NormalExport { } } -impl ExportTrait for NormalExport { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { +impl<Index: PackageIndexTrait> ExportTrait<Index> for NormalExport<Index> { + fn write<Writer: ArchiveWriter<Index>>(&self, asset: &mut Writer) -> Result<(), Error> { let (unversioned_header, sorted_properties) = match generate_unversioned_header( asset, &self.properties, diff --git a/unreal_asset/unreal_asset_exports/src/properties/fproperty.rs b/unreal_asset/unreal_asset_exports/src/properties/fproperty.rs index 0ccf0570..cd5ae03e 100644 --- a/unreal_asset/unreal_asset_exports/src/properties/fproperty.rs +++ b/unreal_asset/unreal_asset_exports/src/properties/fproperty.rs @@ -10,7 +10,7 @@ use unreal_asset_base::{ enums::{EArrayDim, ELifetimeCondition}, flags::{EObjectFlags, EPropertyFlags}, reader::{ArchiveReader, ArchiveWriter}, - types::{fname::ToSerializedName, FName, PackageIndex}, + types::{fname::ToSerializedName, FName, PackageIndex, PackageIndexTrait}, Error, FNameContainer, }; @@ -25,7 +25,9 @@ macro_rules! parse_simple_property { impl $prop_name { /// Read an `$prop_name` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok($prop_name { generic_property: FGenericProperty::new(asset)?, }) @@ -33,7 +35,10 @@ macro_rules! parse_simple_property { } impl FPropertyTrait for $prop_name { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<(), Error> { self.generic_property.write(asset)?; Ok(()) } @@ -63,7 +68,7 @@ macro_rules! parse_simple_property_index { impl $prop_name { /// Read an `$prop_name` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>(asset: &mut Reader) -> Result<Self, Error> { Ok($prop_name { generic_property: FGenericProperty::new(asset)?, $( @@ -74,7 +79,7 @@ macro_rules! parse_simple_property_index { } impl FPropertyTrait for $prop_name { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>(&self, asset: &mut Writer) -> Result<(), Error> { self.generic_property.write(asset)?; $( asset.write_i32::<LE>(self.$index_name.index)?; @@ -106,7 +111,7 @@ macro_rules! parse_simple_property_prop { impl $prop_name { /// Read an `$prop_name` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>(asset: &mut Reader) -> Result<Self, Error> { Ok($prop_name { generic_property: FGenericProperty::new(asset)?, $( @@ -117,7 +122,7 @@ macro_rules! parse_simple_property_prop { } impl FPropertyTrait for $prop_name { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>(&self, asset: &mut Writer) -> Result<(), Error> { self.generic_property.write(asset)?; $( FProperty::write(self.$prop.as_ref(), asset)?; @@ -132,7 +137,10 @@ macro_rules! parse_simple_property_prop { #[enum_dispatch] pub trait FPropertyTrait: Debug + Clone + PartialEq + Eq + Hash { /// Write `FProperty` to an asset - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error>; + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<(), Error>; } /// FProperty @@ -180,7 +188,9 @@ impl Eq for FProperty {} impl FProperty { /// Read an `FProperty` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let serialized_type = asset.read_fname()?; serialized_type.get_content(|ty| { Ok::<FProperty, Error>(match ty { @@ -209,7 +219,7 @@ impl FProperty { } /// Write an `FProperty` to an asset - pub fn write<Writer: ArchiveWriter>( + pub fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( property: &FProperty, asset: &mut Writer, ) -> Result<(), Error> { @@ -315,7 +325,7 @@ pub struct FBoolProperty { impl FGenericProperty { /// Read an `FGenericProperty` from an asset with a serialized type - pub fn with_serialized_type<Reader: ArchiveReader>( + pub fn with_serialized_type<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, serialized_type: Option<FName>, ) -> Result<Self, Error> { @@ -344,13 +354,18 @@ impl FGenericProperty { } /// Read an `FGenericProperty` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { FGenericProperty::with_serialized_type(asset, None) } } impl FPropertyTrait for FGenericProperty { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<(), Error> { asset.write_fname(&self.name)?; asset.write_u32::<LE>(self.flags.bits())?; asset.write_i32::<LE>(self.array_dim.into())?; @@ -365,7 +380,9 @@ impl FPropertyTrait for FGenericProperty { impl FEnumProperty { /// Read an `FEnumProperty` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let generic_property = FGenericProperty::new(asset)?; let enum_value = PackageIndex::new(asset.read_i32::<LE>()?); let underlying_prop = FProperty::new(asset)?; @@ -379,7 +396,10 @@ impl FEnumProperty { } impl FPropertyTrait for FEnumProperty { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<(), Error> { self.generic_property.write(asset)?; asset.write_i32::<LE>(self.enum_value.index)?; FProperty::write(self.underlying_prop.as_ref(), asset)?; @@ -389,7 +409,9 @@ impl FPropertyTrait for FEnumProperty { impl FBoolProperty { /// Read an `FBoolProperty` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let generic_property = FGenericProperty::new(asset)?; let field_size = asset.read_u8()?; let byte_offset = asset.read_u8()?; @@ -411,7 +433,10 @@ impl FBoolProperty { } impl FPropertyTrait for FBoolProperty { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<(), Error> { self.generic_property.write(asset)?; asset.write_u8(self.field_size)?; asset.write_u8(self.byte_offset)?; diff --git a/unreal_asset/unreal_asset_exports/src/properties/uproperty.rs b/unreal_asset/unreal_asset_exports/src/properties/uproperty.rs index 68f81bbf..cd420f7e 100644 --- a/unreal_asset/unreal_asset_exports/src/properties/uproperty.rs +++ b/unreal_asset/unreal_asset_exports/src/properties/uproperty.rs @@ -11,7 +11,7 @@ use unreal_asset_base::{ enums::{EArrayDim, ELifetimeCondition}, flags::EPropertyFlags, reader::{ArchiveReader, ArchiveWriter}, - types::{FName, PackageIndex}, + types::{FName, PackageIndex, PackageIndexTrait}, Error, FNameContainer, }; @@ -26,7 +26,7 @@ macro_rules! parse_simple_property { impl $prop_name { /// Read a `$prop_name` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>(asset: &mut Reader) -> Result<Self, Error> { Ok($prop_name { generic_property: UGenericProperty::new(asset)? }) @@ -34,7 +34,7 @@ macro_rules! parse_simple_property { } impl UPropertyTrait for $prop_name { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>(&self, asset: &mut Writer) -> Result<(), Error> { self.generic_property.write(asset)?; Ok(()) } @@ -63,7 +63,7 @@ macro_rules! parse_simple_property { impl $prop_name { /// Read a `$prop_name` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>(asset: &mut Reader) -> Result<Self, Error> { Ok($prop_name { generic_property: UGenericProperty::new(asset)?, $( @@ -74,7 +74,7 @@ macro_rules! parse_simple_property { } impl UPropertyTrait for $prop_name { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>(&self, asset: &mut Writer) -> Result<(), Error> { self.generic_property.write(asset)?; $( asset.write_i32::<LE>(self.$field_name.index)?; @@ -89,7 +89,10 @@ macro_rules! parse_simple_property { #[enum_dispatch] pub trait UPropertyTrait: Debug + Clone + PartialEq + Eq + Hash { /// Write `UProperty` to an asset - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error>; + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<(), Error>; } /// UProperty @@ -159,7 +162,7 @@ impl Eq for UProperty {} impl UProperty { /// Read a `UProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, serialized_type: FName, ) -> Result<Self, Error> { @@ -240,7 +243,9 @@ pub struct UBoolProperty { impl UField { /// Read a `UField` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let next = match asset .get_custom_version::<FFrameworkObjectVersion>() .version @@ -253,7 +258,10 @@ impl UField { } /// Write a `UField` to an asset - pub fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { + pub fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<(), Error> { if asset .get_custom_version::<FFrameworkObjectVersion>() .version @@ -276,7 +284,9 @@ impl UField { impl UGenericProperty { /// Read a `UGenericProperty` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let u_field = UField::new(asset)?; let array_dim: EArrayDim = asset.read_i32::<LE>()?.try_into()?; @@ -303,7 +313,10 @@ impl UGenericProperty { } impl UPropertyTrait for UGenericProperty { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<(), Error> { self.u_field.write(asset)?; asset.write_i32::<LE>(self.array_dim.into())?; asset.write_u64::<LE>(self.property_flags.bits())?; @@ -324,7 +337,9 @@ impl UPropertyTrait for UGenericProperty { impl UBoolProperty { /// Read a `UBoolProeprty` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let generic_property = UGenericProperty::new(asset)?; let element_size = asset.read_u8()?; @@ -339,7 +354,10 @@ impl UBoolProperty { } impl UPropertyTrait for UBoolProperty { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<(), Error> { self.generic_property.write(asset)?; asset.write_u8(self.element_size)?; asset.write_bool(self.native_bool)?; diff --git a/unreal_asset/unreal_asset_exports/src/property_export.rs b/unreal_asset/unreal_asset_exports/src/property_export.rs index dfa1519c..36a18b97 100644 --- a/unreal_asset/unreal_asset_exports/src/property_export.rs +++ b/unreal_asset/unreal_asset_exports/src/property_export.rs @@ -4,6 +4,7 @@ use byteorder::{ReadBytesExt, WriteBytesExt, LE}; use unreal_asset_base::{ reader::{ArchiveReader, ArchiveWriter}, + types::PackageIndexTrait, Error, FNameContainer, }; @@ -16,19 +17,19 @@ use crate::{BaseExport, NormalExport}; /// /// This is a `UProperty` export #[derive(FNameContainer, Debug, Clone, PartialEq, Eq, Hash)] -pub struct PropertyExport { +pub struct PropertyExport<Index: PackageIndexTrait> { /// Base normal export - pub normal_export: NormalExport, + pub normal_export: NormalExport<Index>, /// Property pub property: UProperty, } implement_get!(PropertyExport); -impl PropertyExport { +impl<Index: PackageIndexTrait> PropertyExport<Index> { /// Read a `PropertyExport` from an asset - pub fn from_base<Reader: ArchiveReader>( - base: &BaseExport, + pub fn from_base<Reader: ArchiveReader<Index>>( + base: &BaseExport<Index>, asset: &mut Reader, ) -> Result<Self, Error> { let normal_export = NormalExport::from_base(base, asset)?; @@ -47,8 +48,8 @@ impl PropertyExport { } } -impl ExportTrait for PropertyExport { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { +impl<Index: PackageIndexTrait> ExportTrait<Index> for PropertyExport<Index> { + fn write<Writer: ArchiveWriter<Index>>(&self, asset: &mut Writer) -> Result<(), Error> { self.normal_export.write(asset)?; asset.write_i32::<LE>(0)?; self.property.write(asset)?; diff --git a/unreal_asset/unreal_asset_exports/src/raw_export.rs b/unreal_asset/unreal_asset_exports/src/raw_export.rs index 22bcb867..c9ccadff 100644 --- a/unreal_asset/unreal_asset_exports/src/raw_export.rs +++ b/unreal_asset/unreal_asset_exports/src/raw_export.rs @@ -2,6 +2,7 @@ use unreal_asset_base::{ reader::{ArchiveReader, ArchiveWriter}, + types::PackageIndexTrait, Error, FNameContainer, }; @@ -9,38 +10,40 @@ use crate::BaseExport; use crate::{ExportBaseTrait, ExportNormalTrait, ExportTrait}; /// An export that failed to deserialize is stored as `Vec<u8>` -#[derive(FNameContainer, Debug, Clone, Default, PartialEq, Eq, Hash)] -pub struct RawExport { +#[derive(FNameContainer, Debug, Clone, PartialEq, Eq, Hash)] +pub struct RawExport<Index: PackageIndexTrait> { /// Base export - pub base_export: BaseExport, + pub base_export: BaseExport<Index>, /// Raw data pub data: Vec<u8>, } -impl ExportNormalTrait for RawExport { - fn get_normal_export(&'_ self) -> Option<&'_ super::normal_export::NormalExport> { +impl<Index: PackageIndexTrait> ExportNormalTrait<Index> for RawExport<Index> { + fn get_normal_export(&'_ self) -> Option<&'_ super::normal_export::NormalExport<Index>> { None } - fn get_normal_export_mut(&'_ mut self) -> Option<&'_ mut super::normal_export::NormalExport> { + fn get_normal_export_mut( + &'_ mut self, + ) -> Option<&'_ mut super::normal_export::NormalExport<Index>> { None } } -impl ExportBaseTrait for RawExport { - fn get_base_export(&'_ self) -> &'_ BaseExport { +impl<Index: PackageIndexTrait> ExportBaseTrait<Index> for RawExport<Index> { + fn get_base_export(&'_ self) -> &'_ BaseExport<Index> { &self.base_export } - fn get_base_export_mut(&'_ mut self) -> &'_ mut BaseExport { + fn get_base_export_mut(&'_ mut self) -> &'_ mut BaseExport<Index> { &mut self.base_export } } -impl RawExport { +impl<Index: PackageIndexTrait> RawExport<Index> { /// Read `RawExport` from an asset - pub fn from_base<Reader: ArchiveReader>( - base: BaseExport, + pub fn from_base<Reader: ArchiveReader<impl PackageIndexTrait>>( + base: BaseExport<Index>, asset: &mut Reader, ) -> Result<Self, Error> { let mut data = vec![0u8; base.serial_size as usize]; @@ -53,8 +56,8 @@ impl RawExport { } } -impl ExportTrait for RawExport { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { +impl<Index: PackageIndexTrait> ExportTrait<Index> for RawExport<Index> { + fn write<Writer: ArchiveWriter<Index>>(&self, asset: &mut Writer) -> Result<(), Error> { asset.write_all(&self.data)?; Ok(()) } diff --git a/unreal_asset/unreal_asset_exports/src/string_table_export.rs b/unreal_asset/unreal_asset_exports/src/string_table_export.rs index ed27b81e..8bb2bcd0 100644 --- a/unreal_asset/unreal_asset_exports/src/string_table_export.rs +++ b/unreal_asset/unreal_asset_exports/src/string_table_export.rs @@ -5,6 +5,7 @@ use byteorder::{ReadBytesExt, WriteBytesExt, LE}; use unreal_asset_base::{ containers::IndexedMap, reader::{ArchiveReader, ArchiveWriter}, + types::PackageIndexTrait, Error, FNameContainer, }; @@ -13,10 +14,10 @@ use crate::ExportTrait; use crate::{BaseExport, NormalExport}; /// String table export -#[derive(FNameContainer, Debug, Clone, Default, PartialEq, Eq)] -pub struct StringTableExport { +#[derive(FNameContainer, Debug, Clone, PartialEq, Eq)] +pub struct StringTableExport<Index: PackageIndexTrait> { /// Base normal export - pub normal_export: NormalExport, + pub normal_export: NormalExport<Index>, /// String table namespace pub namespace: Option<String>, /// String table @@ -25,10 +26,10 @@ pub struct StringTableExport { implement_get!(StringTableExport); -impl StringTableExport { +impl<Index: PackageIndexTrait> StringTableExport<Index> { /// Read a `StringTableExport` from an asset - pub fn from_base<Reader: ArchiveReader>( - base: &BaseExport, + pub fn from_base<Reader: ArchiveReader<Index>>( + base: &BaseExport<Index>, asset: &mut Reader, ) -> Result<Self, Error> { let normal_export = NormalExport::from_base(base, asset)?; @@ -57,8 +58,8 @@ impl StringTableExport { } } -impl ExportTrait for StringTableExport { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { +impl<Index: PackageIndexTrait> ExportTrait<Index> for StringTableExport<Index> { + fn write<Writer: ArchiveWriter<Index>>(&self, asset: &mut Writer) -> Result<(), Error> { self.normal_export.write(asset)?; asset.write_i32::<LE>(0)?; diff --git a/unreal_asset/unreal_asset_exports/src/struct_export.rs b/unreal_asset/unreal_asset_exports/src/struct_export.rs index c5a9c42c..6dae133b 100644 --- a/unreal_asset/unreal_asset_exports/src/struct_export.rs +++ b/unreal_asset/unreal_asset_exports/src/struct_export.rs @@ -8,7 +8,7 @@ use unreal_asset_base::{ custom_version::FCoreObjectVersion, engine_version::EngineVersion, reader::{ArchiveReader, ArchiveWriter}, - types::PackageIndex, + types::{PackageIndex, PackageIndexTrait}, Error, FNameContainer, }; use unreal_asset_kismet::KismetExpression; @@ -19,10 +19,10 @@ use crate::ExportTrait; use crate::{BaseExport, NormalExport}; /// Struct export -#[derive(FNameContainer, Debug, Clone, Default, PartialEq, Eq, Hash)] -pub struct StructExport { +#[derive(FNameContainer, Debug, Clone, PartialEq, Eq, Hash)] +pub struct StructExport<Index: PackageIndexTrait> { /// Base normal export - pub normal_export: NormalExport, + pub normal_export: NormalExport<Index>, /// Field #[container_ignore] pub field: UField, @@ -44,10 +44,10 @@ pub struct StructExport { implement_get!(StructExport); -impl StructExport { +impl<Index: PackageIndexTrait> StructExport<Index> { /// Read a `StructExport` from an asset - pub fn from_base<Reader: ArchiveReader>( - base: &BaseExport, + pub fn from_base<Reader: ArchiveReader<Index>>( + base: &BaseExport<Index>, asset: &mut Reader, ) -> Result<Self, Error> { let normal_export = NormalExport::from_base(base, asset)?; @@ -82,7 +82,7 @@ impl StructExport { let mut script_bytecode = None; if asset.get_engine_version() >= EngineVersion::VER_UE4_16 { script_bytecode = - StructExport::read_bytecode(asset, start_offset, script_storage_size).ok(); + StructExport::<Index>::read_bytecode(asset, start_offset, script_storage_size).ok(); } let script_bytecode_raw = match &script_bytecode { @@ -109,7 +109,7 @@ impl StructExport { } /// Read kismet bytecode - fn read_bytecode<Reader: ArchiveReader>( + fn read_bytecode<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, start_offset: u64, storage_size: i32, @@ -122,8 +122,8 @@ impl StructExport { } } -impl ExportTrait for StructExport { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { +impl<Index: PackageIndexTrait> ExportTrait<Index> for StructExport<Index> { + fn write<Writer: ArchiveWriter<Index>>(&self, asset: &mut Writer) -> Result<(), Error> { self.normal_export.write(asset)?; asset.write_i32::<LE>(0)?; self.field.write(asset)?; diff --git a/unreal_asset/unreal_asset_exports/src/user_defined_struct_export.rs b/unreal_asset/unreal_asset_exports/src/user_defined_struct_export.rs index cbd1183c..de01f2f5 100644 --- a/unreal_asset/unreal_asset_exports/src/user_defined_struct_export.rs +++ b/unreal_asset/unreal_asset_exports/src/user_defined_struct_export.rs @@ -5,6 +5,7 @@ use byteorder::{ReadBytesExt, WriteBytesExt, LE}; use unreal_asset_base::{ flags::EStructFlags, reader::{ArchiveReader, ArchiveWriter}, + types::PackageIndexTrait, unversioned::{header::UnversionedHeader, Ancestry}, Error, FNameContainer, }; @@ -14,10 +15,10 @@ use crate::{BaseExport, NormalExport, StructExport}; use crate::{ExportBaseTrait, ExportNormalTrait, ExportTrait}; /// Struct export -#[derive(FNameContainer, Debug, Clone, Default, PartialEq, Eq, Hash)] -pub struct UserDefinedStructExport { +#[derive(FNameContainer, Debug, Clone, PartialEq, Eq, Hash)] +pub struct UserDefinedStructExport<Index: PackageIndexTrait> { /// Base struct export - pub struct_export: StructExport, + pub struct_export: StructExport<Index>, /// Struct flags #[container_ignore] pub flags: EStructFlags, @@ -25,10 +26,10 @@ pub struct UserDefinedStructExport { pub default_struct_instance: Vec<Property>, } -impl UserDefinedStructExport { +impl<Index: PackageIndexTrait> UserDefinedStructExport<Index> { /// Read a `UserDefinedStructExport` from an asset - pub fn from_base<Reader: ArchiveReader>( - base: &BaseExport, + pub fn from_base<Reader: ArchiveReader<Index>>( + base: &BaseExport<Index>, asset: &mut Reader, ) -> Result<Self, Error> { let struct_export = StructExport::from_base(base, asset)?; @@ -51,28 +52,28 @@ impl UserDefinedStructExport { } } -impl ExportNormalTrait for UserDefinedStructExport { - fn get_normal_export(&'_ self) -> Option<&'_ NormalExport> { +impl<Index: PackageIndexTrait> ExportNormalTrait<Index> for UserDefinedStructExport<Index> { + fn get_normal_export(&'_ self) -> Option<&'_ NormalExport<Index>> { Some(&self.struct_export.normal_export) } - fn get_normal_export_mut(&'_ mut self) -> Option<&'_ mut NormalExport> { + fn get_normal_export_mut(&'_ mut self) -> Option<&'_ mut NormalExport<Index>> { Some(&mut self.struct_export.normal_export) } } -impl ExportBaseTrait for UserDefinedStructExport { - fn get_base_export(&'_ self) -> &'_ BaseExport { +impl<Index: PackageIndexTrait> ExportBaseTrait<Index> for UserDefinedStructExport<Index> { + fn get_base_export(&'_ self) -> &'_ BaseExport<Index> { &self.struct_export.normal_export.base_export } - fn get_base_export_mut(&'_ mut self) -> &'_ mut BaseExport { + fn get_base_export_mut(&'_ mut self) -> &'_ mut BaseExport<Index> { &mut self.struct_export.normal_export.base_export } } -impl ExportTrait for UserDefinedStructExport { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { +impl<Index: PackageIndexTrait> ExportTrait<Index> for UserDefinedStructExport<Index> { + fn write<Writer: ArchiveWriter<Index>>(&self, asset: &mut Writer) -> Result<(), Error> { self.struct_export.write(asset)?; asset.write_u32::<LE>(self.flags.bits())?; for entry in &self.default_struct_instance { diff --git a/unreal_asset/unreal_asset_exports/src/world_export.rs b/unreal_asset/unreal_asset_exports/src/world_export.rs index 3219a547..6f0dccc3 100644 --- a/unreal_asset/unreal_asset_exports/src/world_export.rs +++ b/unreal_asset/unreal_asset_exports/src/world_export.rs @@ -4,7 +4,7 @@ use byteorder::{ReadBytesExt, WriteBytesExt, LE}; use unreal_asset_base::{ reader::{ArchiveReader, ArchiveWriter}, - types::PackageIndex, + types::{PackageIndex, PackageIndexTrait}, Error, FNameContainer, }; @@ -15,10 +15,10 @@ use crate::{BaseExport, NormalExport}; /// World export /// /// This is a `World` export -#[derive(FNameContainer, Debug, Clone, Default, PartialEq, Eq, Hash)] -pub struct WorldExport { +#[derive(FNameContainer, Debug, Clone, PartialEq, Eq, Hash)] +pub struct WorldExport<Index: PackageIndexTrait> { /// Base normal export - pub normal_export: NormalExport, + pub normal_export: NormalExport<Index>, /// Persistent level - a LevelExport #[container_ignore] pub persistent_level: PackageIndex, @@ -32,10 +32,10 @@ pub struct WorldExport { implement_get!(WorldExport); -impl WorldExport { +impl<Index: PackageIndexTrait> WorldExport<Index> { /// Read a `WorldExport` from an asset - pub fn from_base<Reader: ArchiveReader>( - base: &BaseExport, + pub fn from_base<Reader: ArchiveReader<Index>>( + base: &BaseExport<Index>, asset: &mut Reader, ) -> Result<Self, Error> { let normal_export = NormalExport::from_base(base, asset)?; @@ -51,8 +51,8 @@ impl WorldExport { } } -impl ExportTrait for WorldExport { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { +impl<Index: PackageIndexTrait> ExportTrait<Index> for WorldExport<Index> { + fn write<Writer: ArchiveWriter<Index>>(&self, asset: &mut Writer) -> Result<(), Error> { self.normal_export.write(asset)?; asset.write_i32::<LE>(0)?; diff --git a/unreal_asset/unreal_asset_kismet/src/lib.rs b/unreal_asset/unreal_asset_kismet/src/lib.rs index 2a189cf1..bc589847 100644 --- a/unreal_asset/unreal_asset_kismet/src/lib.rs +++ b/unreal_asset/unreal_asset_kismet/src/lib.rs @@ -14,6 +14,7 @@ use ordered_float::OrderedFloat; use unreal_asset_base::FNameContainer; +use unreal_asset_base::types::PackageIndexTrait; use unreal_asset_base::{ error::KismetError, object_version::{ObjectVersion, ObjectVersionUE5}, @@ -312,7 +313,9 @@ impl FieldPath { } /// Read a UTF-8 kismet string -fn read_kismet_string<Reader: ArchiveReader>(asset: &mut Reader) -> Result<String, Error> { +fn read_kismet_string<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, +) -> Result<String, Error> { let mut data = Vec::new(); loop { let read = asset.read_u8()?; @@ -325,7 +328,9 @@ fn read_kismet_string<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Strin } /// Read a UTF-16 kismet string -fn read_kismet_unicode_string<Reader: ArchiveReader>(asset: &mut Reader) -> Result<String, Error> { +fn read_kismet_unicode_string<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, +) -> Result<String, Error> { let mut data = Vec::new(); loop { let b1 = asset.read_u8()?; @@ -339,7 +344,7 @@ fn read_kismet_unicode_string<Reader: ArchiveReader>(asset: &mut Reader) -> Resu } /// Write a UTF-8 kismet string -fn write_kismet_string<Writer: ArchiveWriter>( +fn write_kismet_string<Writer: ArchiveWriter<impl PackageIndexTrait>>( string: &str, asset: &mut Writer, ) -> Result<usize, Error> { @@ -350,7 +355,7 @@ fn write_kismet_string<Writer: ArchiveWriter>( } /// Write a UTF-16 kismet string -fn write_kismet_unicode_string<Writer: ArchiveWriter>( +fn write_kismet_unicode_string<Writer: ArchiveWriter<impl PackageIndexTrait>>( string: &str, asset: &mut Writer, ) -> Result<usize, Error> { @@ -414,7 +419,7 @@ macro_rules! implement_expression { } impl KismetExpressionTrait for $name { - fn write<Writer: ArchiveWriter>(&self, _asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>(&self, _asset: &mut Writer) -> Result<usize, Error> { Ok(0) } } @@ -429,7 +434,7 @@ macro_rules! implement_expression { impl $name { /// Read `$name` from an asset - pub fn new<Reader: ArchiveReader>(_asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>(_asset: &mut Reader) -> Result<Self, Error> { Ok($name { token: EExprToken::$name }) @@ -454,7 +459,7 @@ macro_rules! implement_value_expression { ); impl $name { /// Read `$name` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>(asset: &mut Reader) -> Result<Self, Error> { Ok($name { token: EExprToken::$name, value: asset.$read_func()?, @@ -463,7 +468,7 @@ macro_rules! implement_value_expression { } impl KismetExpressionTrait for $name { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>(&self, asset: &mut Writer) -> Result<usize, Error> { asset.$write_func(self.value)?; Ok(size_of::<$param>()) } @@ -478,7 +483,7 @@ macro_rules! implement_value_expression { ); impl $name { /// Read `$name` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>(asset: &mut Reader) -> Result<Self, Error> { Ok($name { token: EExprToken::$name, value: asset.$read_func::<$endianness>()?, @@ -487,7 +492,7 @@ macro_rules! implement_value_expression { } impl KismetExpressionTrait for $name { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>(&self, asset: &mut Writer) -> Result<usize, Error> { asset.$write_func::<$endianness>(self.value)?; Ok(size_of::<$param>()) } @@ -522,7 +527,9 @@ pub struct FScriptText { impl FScriptText { /// Read a `FScriptText` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let text_literal_type: EBlueprintTextLiteralType = asset.read_u8()?.try_into()?; let ( mut localized_source, @@ -568,7 +575,10 @@ impl FScriptText { }) } - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { let mut offset = size_of::<u8>(); asset.write_u8(self.text_literal_type.into())?; match self.text_literal_type { @@ -690,7 +700,9 @@ impl KismetPropertyPointer { } /// Read a `KismetPropertyPointer` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { if asset.get_object_version() >= KismetPropertyPointer::XFER_PROP_POINTER_SWITCH_TO_SERIALIZING_AS_FIELD_PATH_VERSION { @@ -711,7 +723,10 @@ impl KismetPropertyPointer { } /// Write a `KismetPropertyPointer` to an asset - pub fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + pub fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { if asset.get_object_version() >= KismetPropertyPointer::XFER_PROP_POINTER_SWITCH_TO_SERIALIZING_AS_FIELD_PATH_VERSION { @@ -766,7 +781,10 @@ impl KismetSwitchCase { #[enum_dispatch] pub trait KismetExpressionTrait: Debug + Clone + PartialEq + Eq + Hash { /// Write a `KismetExpression` to an asset - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error>; + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error>; } /// Allows for getting a token from a KismetExpression @@ -986,7 +1004,9 @@ impl Eq for KismetExpression {} impl KismetExpression { /// Read a `KismetExpression` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let token: EExprToken = asset.read_u8()?.try_into()?; let expr: Result<Self, Error> = match token { EExprToken::ExLocalVariable => Ok(ExLocalVariable::new(asset)?.into()), @@ -1101,7 +1121,7 @@ impl KismetExpression { } /// Read an array of `KismetExpression`s stopping at end_token - pub fn read_arr<Reader: ArchiveReader>( + pub fn read_arr<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, end_token: EExprToken, ) -> Result<Vec<Self>, Error> { @@ -1117,7 +1137,7 @@ impl KismetExpression { } /// Write a `KismetExpression` - pub fn write<Writer: ArchiveWriter>( + pub fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( expr: &KismetExpression, asset: &mut Writer, ) -> Result<usize, Error> { @@ -1133,7 +1153,9 @@ declare_expression!( ); impl ExFieldPathConst { /// Read a `ExFieldPathConst` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok(ExFieldPathConst { token: EExprToken::ExFieldPathConst, value: Box::new(KismetExpression::new(asset)?), @@ -1141,7 +1163,10 @@ impl ExFieldPathConst { } } impl KismetExpressionTrait for ExFieldPathConst { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { KismetExpression::write(self.value.as_ref(), asset) } } @@ -1152,7 +1177,9 @@ declare_expression!( ); impl ExNameConst { /// Read a `ExNameConst` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok(ExNameConst { token: EExprToken::ExNameConst, value: asset.read_fname()?, @@ -1160,7 +1187,10 @@ impl ExNameConst { } } impl KismetExpressionTrait for ExNameConst { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { asset.write_fname(&self.value)?; Ok(12) } @@ -1173,7 +1203,9 @@ declare_expression!( ); impl ExObjectConst { /// Read a `ExObjectConst` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok(ExObjectConst { token: EExprToken::ExObjectConst, value: PackageIndex::new(asset.read_i32::<LE>()?), @@ -1181,7 +1213,10 @@ impl ExObjectConst { } } impl KismetExpressionTrait for ExObjectConst { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { asset.write_i32::<LE>(self.value.index)?; Ok(size_of::<u64>()) } @@ -1193,7 +1228,9 @@ declare_expression!( ); impl ExSoftObjectConst { /// Read a `ExSoftObjectConst` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok(ExSoftObjectConst { token: EExprToken::ExSoftObjectConst, value: Box::new(KismetExpression::new(asset)?), @@ -1201,7 +1238,10 @@ impl ExSoftObjectConst { } } impl KismetExpressionTrait for ExSoftObjectConst { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { KismetExpression::write(self.value.as_ref(), asset) } } @@ -1213,7 +1253,9 @@ declare_expression!( ); impl ExTransformConst { /// Read a `ExTransformConst` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let transform = match asset.get_object_version_ue5() >= ObjectVersionUE5::LARGE_WORLD_COORDINATES { true => { @@ -1263,7 +1305,10 @@ impl ExTransformConst { } } impl KismetExpressionTrait for ExTransformConst { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { match asset.get_object_version_ue5() >= ObjectVersionUE5::LARGE_WORLD_COORDINATES { true => { asset.write_f64::<LE>(self.value.rotation.x.0)?; @@ -1304,7 +1349,9 @@ declare_expression!( ); impl ExVectorConst { /// Read a `ExVectorConst` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let value = match asset.get_object_version_ue5() >= ObjectVersionUE5::LARGE_WORLD_COORDINATES { true => Vector::new( @@ -1325,7 +1372,10 @@ impl ExVectorConst { } } impl KismetExpressionTrait for ExVectorConst { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { match asset.get_object_version_ue5() >= ObjectVersionUE5::LARGE_WORLD_COORDINATES { true => { asset.write_f64::<LE>(self.value.x.0)?; @@ -1351,7 +1401,9 @@ declare_expression!( ); impl ExTextConst { /// Read a `ExTextConst` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok(ExTextConst { token: EExprToken::ExTextConst, value: Box::new(FScriptText::new(asset)?), @@ -1359,7 +1411,10 @@ impl ExTextConst { } } impl KismetExpressionTrait for ExTextConst { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { self.value.write(asset) } } @@ -1372,7 +1427,9 @@ declare_expression!( ); impl ExAddMulticastDelegate { /// Read a `ExAddMulticastDelegate` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok(ExAddMulticastDelegate { token: EExprToken::ExAddMulticastDelegate, delegate: Box::new(KismetExpression::new(asset)?), @@ -1381,7 +1438,10 @@ impl ExAddMulticastDelegate { } } impl KismetExpressionTrait for ExAddMulticastDelegate { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { let offset = KismetExpression::write(self.delegate.as_ref(), asset)? + KismetExpression::write(self.delegate_to_add.as_ref(), asset)?; Ok(offset) @@ -1396,7 +1456,9 @@ declare_expression!( ); impl ExArrayConst { /// Read a `ExArrayConst` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let inner_property = KismetPropertyPointer::new(asset)?; asset.read_i32::<LE>()?; // num_entries let elements = KismetExpression::read_arr(asset, EExprToken::ExEndArrayConst)?; @@ -1408,7 +1470,10 @@ impl ExArrayConst { } } impl KismetExpressionTrait for ExArrayConst { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { let mut offset = size_of::<i32>(); offset += self.inner_property.write(asset)?; asset.write_i32::<LE>(self.elements.len() as i32)?; @@ -1428,7 +1493,9 @@ declare_expression!( ); impl ExArrayGetByRef { /// Read a `ExArrayGetByRef` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok(ExArrayGetByRef { token: EExprToken::ExArrayGetByRef, array_variable: Box::new(KismetExpression::new(asset)?), @@ -1437,7 +1504,10 @@ impl ExArrayGetByRef { } } impl KismetExpressionTrait for ExArrayGetByRef { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { let offset = KismetExpression::write(self.array_variable.as_ref(), asset)? + KismetExpression::write(self.array_index.as_ref(), asset)?; Ok(offset) @@ -1454,7 +1524,9 @@ declare_expression!( ); impl ExAssert { /// Read a `ExAssert` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok(ExAssert { token: EExprToken::ExAssert, line_number: asset.read_u16::<LE>()?, @@ -1464,7 +1536,10 @@ impl ExAssert { } } impl KismetExpressionTrait for ExAssert { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { asset.write_u16::<LE>(self.line_number)?; asset.write_bool(self.debug_mode)?; let offset = size_of::<u32>() @@ -1484,7 +1559,9 @@ declare_expression!( ); impl ExBindDelegate { /// Read a `ExBindDelegate` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok(ExBindDelegate { token: EExprToken::ExBindDelegate, function_name: asset.read_fname()?, @@ -1494,7 +1571,10 @@ impl ExBindDelegate { } } impl KismetExpressionTrait for ExBindDelegate { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { asset.write_fname(&self.function_name)?; let offset = 12 /* FScriptName's iCode offset */ + KismetExpression::write(self.delegate.as_ref(), asset)? + @@ -1512,7 +1592,9 @@ declare_expression!( ); impl ExCallMath { /// Read a `ExCallMath` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok(ExCallMath { token: EExprToken::ExCallMath, stack_node: PackageIndex::new(asset.read_i32::<LE>()?), @@ -1521,7 +1603,10 @@ impl ExCallMath { } } impl KismetExpressionTrait for ExCallMath { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { let mut offset = size_of::<u64>(); asset.write_i32::<LE>(self.stack_node.index)?; for parameter in &self.parameters { @@ -1543,7 +1628,9 @@ declare_expression!( ); impl ExCallMulticastDelegate { /// Read a `ExCallMulticastDelegate` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let stack_node = PackageIndex::new(asset.read_i32::<LE>()?); let delegate = KismetExpression::new(asset)?; let parameters = KismetExpression::read_arr(asset, EExprToken::ExEndFunctionParms)?; @@ -1556,7 +1643,10 @@ impl ExCallMulticastDelegate { } } impl KismetExpressionTrait for ExCallMulticastDelegate { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { let mut offset = size_of::<u64>(); asset.write_i32::<LE>(self.stack_node.index)?; offset += KismetExpression::write(&self.delegate, asset)?; @@ -1580,7 +1670,9 @@ declare_expression!( ); impl ExClassContext { /// Read a `ExClassContext` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok(ExClassContext { token: EExprToken::ExClassContext, object_expression: Box::new(KismetExpression::new(asset)?), @@ -1591,7 +1683,10 @@ impl ExClassContext { } } impl KismetExpressionTrait for ExClassContext { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { let mut offset = size_of::<u32>(); offset += KismetExpression::write(self.object_expression.as_ref(), asset)?; asset.write_u32::<LE>(self.offset)?; @@ -1607,7 +1702,9 @@ declare_expression!( ); impl ExClassSparseDataVariable { /// Read a `ExClassSparseDataVariable` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok(ExClassSparseDataVariable { token: EExprToken::ExClassSparseDataVariable, variable: KismetPropertyPointer::new(asset)?, @@ -1615,7 +1712,10 @@ impl ExClassSparseDataVariable { } } impl KismetExpressionTrait for ExClassSparseDataVariable { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { self.variable.write(asset) } } @@ -1626,7 +1726,9 @@ declare_expression!( ); impl ExClearMulticastDelegate { /// Read a `ExClearMulticastDelegate` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok(ExClearMulticastDelegate { token: EExprToken::ExClearMulticastDelegate, delegate_to_clear: Box::new(KismetExpression::new(asset)?), @@ -1634,7 +1736,10 @@ impl ExClearMulticastDelegate { } } impl KismetExpressionTrait for ExClearMulticastDelegate { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { KismetExpression::write(self.delegate_to_clear.as_ref(), asset) } } @@ -1645,7 +1750,9 @@ declare_expression!( ); impl ExComputedJump { /// Read a `ExComputedJump` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok(ExComputedJump { token: EExprToken::ExComputedJump, code_offset_expression: Box::new(KismetExpression::new(asset)?), @@ -1653,7 +1760,10 @@ impl ExComputedJump { } } impl KismetExpressionTrait for ExComputedJump { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { KismetExpression::write(self.code_offset_expression.as_ref(), asset) } } @@ -1670,7 +1780,9 @@ declare_expression!( ); impl ExContext { /// Read a `ExContext` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok(ExContext { token: EExprToken::ExContext, object_expression: Box::new(KismetExpression::new(asset)?), @@ -1681,7 +1793,10 @@ impl ExContext { } } impl KismetExpressionTrait for ExContext { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { let mut offset = size_of::<u32>(); offset += KismetExpression::write(self.object_expression.as_ref(), asset)?; asset.write_u32::<LE>(self.offset)?; @@ -1703,7 +1818,9 @@ declare_expression!( ); impl ExContextFailSilent { /// Read a `ExContextFailSilent` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok(ExContextFailSilent { token: EExprToken::ExContextFailSilent, object_expression: Box::new(KismetExpression::new(asset)?), @@ -1714,7 +1831,10 @@ impl ExContextFailSilent { } } impl KismetExpressionTrait for ExContextFailSilent { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { let mut offset = size_of::<u32>(); offset += KismetExpression::write(self.object_expression.as_ref(), asset)?; asset.write_u32::<LE>(self.offset)?; @@ -1733,7 +1853,9 @@ declare_expression!( ); impl ExCrossInterfaceCast { /// Read a `ExCrossInterfaceCast` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok(ExCrossInterfaceCast { token: EExprToken::ExCrossInterfaceCast, class_ptr: PackageIndex::new(asset.read_i32::<LE>()?), @@ -1742,7 +1864,10 @@ impl ExCrossInterfaceCast { } } impl KismetExpressionTrait for ExCrossInterfaceCast { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { let mut offset = size_of::<u64>(); asset.write_i32::<LE>(self.class_ptr.index)?; offset += KismetExpression::write(self.target.as_ref(), asset)?; @@ -1756,7 +1881,9 @@ declare_expression!( ); impl ExDefaultVariable { /// Read a `ExDefaultVariable` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok(ExDefaultVariable { token: EExprToken::ExDefaultVariable, variable: KismetPropertyPointer::new(asset)?, @@ -1764,7 +1891,10 @@ impl ExDefaultVariable { } } impl KismetExpressionTrait for ExDefaultVariable { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { self.variable.write(asset) } } @@ -1778,7 +1908,9 @@ declare_expression!( ); impl ExDynamicCast { /// Read a `ExDynamicCast` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok(ExDynamicCast { token: EExprToken::ExDynamicCast, class_ptr: PackageIndex::new(asset.read_i32::<LE>()?), @@ -1787,7 +1919,10 @@ impl ExDynamicCast { } } impl KismetExpressionTrait for ExDynamicCast { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { let mut offset = size_of::<u64>(); asset.write_i32::<LE>(self.class_ptr.index)?; offset += KismetExpression::write(self.target_expression.as_ref(), asset)?; @@ -1804,7 +1939,9 @@ declare_expression!( ); impl ExFinalFunction { /// Read a `ExFinalFunction` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok(ExFinalFunction { token: EExprToken::ExFinalFunction, stack_node: PackageIndex::new(asset.read_i32::<LE>()?), @@ -1813,7 +1950,10 @@ impl ExFinalFunction { } } impl KismetExpressionTrait for ExFinalFunction { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { let mut offset = size_of::<u64>(); asset.write_i32::<LE>(self.stack_node.index)?; for parameter in &self.parameters { @@ -1830,7 +1970,9 @@ declare_expression!( ); impl ExInstanceDelegate { /// Read a `ExInstanceDelegate` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok(ExInstanceDelegate { token: EExprToken::ExInstanceDelegate, function_name: asset.read_fname()?, @@ -1838,7 +1980,10 @@ impl ExInstanceDelegate { } } impl KismetExpressionTrait for ExInstanceDelegate { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { asset.write_fname(&self.function_name)?; Ok(12) // FScriptName's iCode offset } @@ -1850,7 +1995,9 @@ declare_expression!( ); impl ExInstanceVariable { /// Read a `ExInstanceVariable` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok(ExInstanceVariable { token: EExprToken::ExInstanceVariable, variable: KismetPropertyPointer::new(asset)?, @@ -1858,7 +2005,10 @@ impl ExInstanceVariable { } } impl KismetExpressionTrait for ExInstanceVariable { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { self.variable.write(asset) } } @@ -1869,7 +2019,9 @@ declare_expression!( ); impl ExInterfaceContext { /// Read a `ExInterfaceContext` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok(ExInterfaceContext { token: EExprToken::ExInterfaceContext, interface_value: Box::new(KismetExpression::new(asset)?), @@ -1877,7 +2029,10 @@ impl ExInterfaceContext { } } impl KismetExpressionTrait for ExInterfaceContext { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { KismetExpression::write(self.interface_value.as_ref(), asset) } } @@ -1891,7 +2046,9 @@ declare_expression!( ); impl ExInterfaceToObjCast { /// Read a `ExInterfaceToObjCast` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok(ExInterfaceToObjCast { token: EExprToken::ExInterfaceToObjCast, class_ptr: PackageIndex::new(asset.read_i32::<LE>()?), @@ -1900,7 +2057,10 @@ impl ExInterfaceToObjCast { } } impl KismetExpressionTrait for ExInterfaceToObjCast { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { let mut offset = size_of::<u64>(); asset.write_i32::<LE>(self.class_ptr.index)?; offset += KismetExpression::write(self.target.as_ref(), asset)?; @@ -1914,7 +2074,9 @@ declare_expression!( ); impl ExJump { /// Read a `ExJump` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok(ExJump { token: EExprToken::ExJump, code_offset: asset.read_u32::<LE>()?, @@ -1922,7 +2084,10 @@ impl ExJump { } } impl KismetExpressionTrait for ExJump { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { asset.write_u32::<LE>(self.code_offset)?; Ok(size_of::<u32>()) } @@ -1936,7 +2101,9 @@ declare_expression!( ); impl ExJumpIfNot { /// Read a `ExJumpIfNot` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok(ExJumpIfNot { token: EExprToken::ExJumpIfNot, code_offset: asset.read_u32::<LE>()?, @@ -1945,7 +2112,10 @@ impl ExJumpIfNot { } } impl KismetExpressionTrait for ExJumpIfNot { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { let mut offset = size_of::<u32>(); asset.write_u32::<LE>(self.code_offset)?; offset += KismetExpression::write(self.boolean_expression.as_ref(), asset)?; @@ -1963,7 +2133,9 @@ declare_expression!( ); impl ExLet { /// Read a `ExLet` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok(ExLet { token: EExprToken::ExLet, value: KismetPropertyPointer::new(asset)?, @@ -1973,7 +2145,10 @@ impl ExLet { } } impl KismetExpressionTrait for ExLet { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { let mut offset = self.value.write(asset)?; offset += KismetExpression::write(self.variable.as_ref(), asset)?; offset += KismetExpression::write(self.expression.as_ref(), asset)?; @@ -1989,7 +2164,9 @@ declare_expression!( ); impl ExLetBool { /// Read a `ExLetBool` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok(ExLetBool { token: EExprToken::ExLetBool, variable_expression: Box::new(KismetExpression::new(asset)?), @@ -1998,7 +2175,10 @@ impl ExLetBool { } } impl KismetExpressionTrait for ExLetBool { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { let offset = KismetExpression::write(self.variable_expression.as_ref(), asset)? + KismetExpression::write(self.assignment_expression.as_ref(), asset)?; Ok(offset) @@ -2013,7 +2193,9 @@ declare_expression!( ); impl ExLetDelegate { /// Read a `ExLetDelegate` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok(ExLetDelegate { token: EExprToken::ExLetDelegate, variable_expression: Box::new(KismetExpression::new(asset)?), @@ -2022,7 +2204,10 @@ impl ExLetDelegate { } } impl KismetExpressionTrait for ExLetDelegate { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { let offset = KismetExpression::write(self.variable_expression.as_ref(), asset)? + KismetExpression::write(self.assignment_expression.as_ref(), asset)?; Ok(offset) @@ -2037,7 +2222,9 @@ declare_expression!( ); impl ExLetMulticastDelegate { /// Read a `ExLetMulticastDelegate` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok(ExLetMulticastDelegate { token: EExprToken::ExLetMulticastDelegate, variable_expression: Box::new(KismetExpression::new(asset)?), @@ -2046,7 +2233,10 @@ impl ExLetMulticastDelegate { } } impl KismetExpressionTrait for ExLetMulticastDelegate { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { let offset = KismetExpression::write(self.variable_expression.as_ref(), asset)? + KismetExpression::write(self.assignment_expression.as_ref(), asset)?; Ok(offset) @@ -2061,7 +2251,9 @@ declare_expression!( ); impl ExLetObj { /// Read a `ExLetObj` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok(ExLetObj { token: EExprToken::ExLetObj, variable_expression: Box::new(KismetExpression::new(asset)?), @@ -2070,7 +2262,10 @@ impl ExLetObj { } } impl KismetExpressionTrait for ExLetObj { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { let offset = KismetExpression::write(self.variable_expression.as_ref(), asset)? + KismetExpression::write(self.assignment_expression.as_ref(), asset)?; Ok(offset) @@ -2085,7 +2280,9 @@ declare_expression!( ); impl ExLetValueOnPersistentFrame { /// Read a `ExLetValueOnPersistentFrame` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok(ExLetValueOnPersistentFrame { token: EExprToken::ExLetValueOnPersistentFrame, destination_property: KismetPropertyPointer::new(asset)?, @@ -2094,7 +2291,10 @@ impl ExLetValueOnPersistentFrame { } } impl KismetExpressionTrait for ExLetValueOnPersistentFrame { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { let offset = self.destination_property.write(asset)? + KismetExpression::write(self.assignment_expression.as_ref(), asset)?; Ok(offset) @@ -2109,7 +2309,9 @@ declare_expression!( ); impl ExLetWeakObjPtr { /// Read a `ExLetWeakObjPtr` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok(ExLetWeakObjPtr { token: EExprToken::ExLetWeakObjPtr, variable_expression: Box::new(KismetExpression::new(asset)?), @@ -2118,7 +2320,10 @@ impl ExLetWeakObjPtr { } } impl KismetExpressionTrait for ExLetWeakObjPtr { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { let offset = KismetExpression::write(self.variable_expression.as_ref(), asset)? + KismetExpression::write(self.assignment_expression.as_ref(), asset)?; Ok(offset) @@ -2134,7 +2339,9 @@ declare_expression!( ); impl ExLocalFinalFunction { /// Read a `ExLocalFinalFunction` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok(ExLocalFinalFunction { token: EExprToken::ExLocalFinalFunction, stack_node: PackageIndex::new(asset.read_i32::<LE>()?), @@ -2143,7 +2350,10 @@ impl ExLocalFinalFunction { } } impl KismetExpressionTrait for ExLocalFinalFunction { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { let mut offset = size_of::<u64>(); asset.write_i32::<LE>(self.stack_node.index)?; for parameter in &self.parameters { @@ -2160,7 +2370,9 @@ declare_expression!( ); impl ExLocalOutVariable { /// Read a `ExLocalOutVariable` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok(ExLocalOutVariable { token: EExprToken::ExLocalOutVariable, variable: KismetPropertyPointer::new(asset)?, @@ -2168,7 +2380,10 @@ impl ExLocalOutVariable { } } impl KismetExpressionTrait for ExLocalOutVariable { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { self.variable.write(asset) } } @@ -2179,7 +2394,9 @@ declare_expression!( ); impl ExLocalVariable { /// Read a `ExLocalVariable` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok(ExLocalVariable { token: EExprToken::ExLocalVariable, variable: KismetPropertyPointer::new(asset)?, @@ -2187,7 +2404,10 @@ impl ExLocalVariable { } } impl KismetExpressionTrait for ExLocalVariable { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { self.variable.write(asset) } } @@ -2200,7 +2420,9 @@ declare_expression!( ); impl ExLocalVirtualFunction { /// Read a `ExLocalVirtualFunction` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok(ExLocalVirtualFunction { token: EExprToken::ExLocalVirtualFunction, virtual_function_name: asset.read_fname()?, @@ -2209,7 +2431,10 @@ impl ExLocalVirtualFunction { } } impl KismetExpressionTrait for ExLocalVirtualFunction { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { let mut offset = 12; // FScriptName's iCode offset asset.write_fname(&self.virtual_function_name)?; for parameter in &self.parameters { @@ -2230,7 +2455,9 @@ declare_expression!( ); impl ExMapConst { /// Read a `ExMapConst` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let key_property = KismetPropertyPointer::new(asset)?; let value_property = KismetPropertyPointer::new(asset)?; let _num_entries = asset.read_i32::<LE>()?; @@ -2244,7 +2471,10 @@ impl ExMapConst { } } impl KismetExpressionTrait for ExMapConst { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { let mut offset = size_of::<i32>(); offset += self.key_property.write(asset)?; offset += self.value_property.write(asset)?; @@ -2266,7 +2496,9 @@ declare_expression!( ); impl ExMetaCast { /// Read a `ExMetaCast` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok(ExMetaCast { token: EExprToken::ExMetaCast, class_ptr: PackageIndex::new(asset.read_i32::<LE>()?), @@ -2275,7 +2507,10 @@ impl ExMetaCast { } } impl KismetExpressionTrait for ExMetaCast { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { let mut offset = size_of::<u64>(); asset.write_i32::<LE>(self.class_ptr.index)?; offset += KismetExpression::write(self.target_expression.as_ref(), asset)?; @@ -2292,7 +2527,9 @@ declare_expression!( ); impl ExObjToInterfaceCast { /// Read a `ExObjToInterfaceCast` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok(ExObjToInterfaceCast { token: EExprToken::ExObjToInterfaceCast, class_ptr: PackageIndex::new(asset.read_i32::<LE>()?), @@ -2301,7 +2538,10 @@ impl ExObjToInterfaceCast { } } impl KismetExpressionTrait for ExObjToInterfaceCast { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { let mut offset = size_of::<u64>(); asset.write_i32::<LE>(self.class_ptr.index)?; offset += KismetExpression::write(self.target.as_ref(), asset)?; @@ -2315,7 +2555,9 @@ declare_expression!( ); impl ExPopExecutionFlowIfNot { /// Read a `ExPopExecutionFlowIfNot` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok(ExPopExecutionFlowIfNot { token: EExprToken::ExPopExecutionFlowIfNot, boolean_expression: Box::new(KismetExpression::new(asset)?), @@ -2323,7 +2565,10 @@ impl ExPopExecutionFlowIfNot { } } impl KismetExpressionTrait for ExPopExecutionFlowIfNot { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { KismetExpression::write(self.boolean_expression.as_ref(), asset) } } @@ -2337,7 +2582,9 @@ declare_expression!( ); impl ExPrimitiveCast { /// Read a `ExPrimitiveCast` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok(ExPrimitiveCast { token: EExprToken::ExPrimitiveCast, conversion_type: asset.read_u8()?.try_into()?, @@ -2346,7 +2593,10 @@ impl ExPrimitiveCast { } } impl KismetExpressionTrait for ExPrimitiveCast { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { let mut offset = size_of::<u8>(); asset.write_u8(self.conversion_type.into())?; offset += KismetExpression::write(self.target.as_ref(), asset)?; @@ -2360,7 +2610,9 @@ declare_expression!( ); impl ExPropertyConst { /// Read a `ExPropertyConst` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok(ExPropertyConst { token: EExprToken::ExPropertyConst, property: KismetPropertyPointer::new(asset)?, @@ -2368,7 +2620,10 @@ impl ExPropertyConst { } } impl KismetExpressionTrait for ExPropertyConst { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { self.property.write(asset) } } @@ -2379,7 +2634,9 @@ declare_expression!( ); impl ExPushExecutionFlow { /// Read a `ExPushExecutionFlow` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok(ExPushExecutionFlow { token: EExprToken::ExPushExecutionFlow, pushing_address: asset.read_u32::<LE>()?, @@ -2387,7 +2644,10 @@ impl ExPushExecutionFlow { } } impl KismetExpressionTrait for ExPushExecutionFlow { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { asset.write_u32::<LE>(self.pushing_address)?; Ok(size_of::<u32>()) } @@ -2401,7 +2661,9 @@ declare_expression!( ); impl ExRemoveMulticastDelegate { /// Read a `ExRemoveMulticastDelegate` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok(ExRemoveMulticastDelegate { token: EExprToken::ExRemoveMulticastDelegate, delegate: Box::new(KismetExpression::new(asset)?), @@ -2410,7 +2672,10 @@ impl ExRemoveMulticastDelegate { } } impl KismetExpressionTrait for ExRemoveMulticastDelegate { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { let offset = KismetExpression::write(self.delegate.as_ref(), asset)? + KismetExpression::write(self.delegate_to_add.as_ref(), asset)?; Ok(offset) @@ -2423,7 +2688,9 @@ declare_expression!( ); impl ExReturn { /// Read a `ExReturn` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok(ExReturn { token: EExprToken::ExReturn, return_expression: Box::new(KismetExpression::new(asset)?), @@ -2431,7 +2698,10 @@ impl ExReturn { } } impl KismetExpressionTrait for ExReturn { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { KismetExpression::write(self.return_expression.as_ref(), asset) } } @@ -2443,7 +2713,9 @@ declare_expression!( ); impl ExRotationConst { /// Read a `ExRotationConst` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let rotator = match asset.get_object_version_ue5() >= ObjectVersionUE5::LARGE_WORLD_COORDINATES { true => { @@ -2470,7 +2742,10 @@ impl ExRotationConst { } } impl KismetExpressionTrait for ExRotationConst { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { match asset.get_object_version_ue5() >= ObjectVersionUE5::LARGE_WORLD_COORDINATES { true => { asset.write_f64::<LE>(self.rotator.x.0)?; @@ -2499,7 +2774,9 @@ declare_expression!( ); impl ExSetArray { /// Read a `ExSetArray` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let (assigning_property, array_inner_prop) = match asset.get_object_version() >= ObjectVersion::VER_UE4_CHANGE_SETARRAY_BYTECODE { true => (Some(Box::new(KismetExpression::new(asset)?)), None), @@ -2514,7 +2791,10 @@ impl ExSetArray { } } impl KismetExpressionTrait for ExSetArray { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { let mut offset = 0; if asset.get_object_version() >= ObjectVersion::VER_UE4_CHANGE_SETARRAY_BYTECODE { offset += KismetExpression::write( @@ -2552,7 +2832,9 @@ declare_expression!( ); impl ExSetConst { /// Read a `ExSetConst` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let inner_property = KismetPropertyPointer::new(asset)?; let _num_entries = asset.read_i32::<LE>()?; let elements = KismetExpression::read_arr(asset, EExprToken::ExEndSetConst)?; @@ -2564,7 +2846,10 @@ impl ExSetConst { } } impl KismetExpressionTrait for ExSetConst { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { let mut offset = size_of::<i32>(); offset += self.inner_property.write(asset)?; asset.write_i32::<LE>(self.elements.len() as i32)?; @@ -2584,7 +2869,9 @@ declare_expression!( ); impl ExSetMap { /// Read a `ExSetMap` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let map_property = Box::new(KismetExpression::new(asset)?); let _num_entries = asset.read_i32::<LE>()?; let elements = KismetExpression::read_arr(asset, EExprToken::ExEndMap)?; @@ -2596,7 +2883,10 @@ impl ExSetMap { } } impl KismetExpressionTrait for ExSetMap { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { let mut offset = size_of::<i32>(); offset += KismetExpression::write(self.map_property.as_ref(), asset)?; asset.write_i32::<LE>(self.elements.len() as i32)?; @@ -2616,7 +2906,9 @@ declare_expression!( ); impl ExSetSet { /// Read a `ExSetSet` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let set_property = Box::new(KismetExpression::new(asset)?); let _num_entries = asset.read_i32::<LE>()?; let elements = KismetExpression::read_arr(asset, EExprToken::ExEndSet)?; @@ -2628,7 +2920,10 @@ impl ExSetSet { } } impl KismetExpressionTrait for ExSetSet { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { let mut offset = size_of::<i32>(); offset += KismetExpression::write(self.set_property.as_ref(), asset)?; asset.write_i32::<LE>(self.elements.len() as i32)?; @@ -2648,7 +2943,9 @@ declare_expression!( ); impl ExSkip { /// Read a `ExSkip` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok(ExSkip { token: EExprToken::ExSkip, code_offset: asset.read_u32::<LE>()?, @@ -2657,7 +2954,10 @@ impl ExSkip { } } impl KismetExpressionTrait for ExSkip { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { let mut offset = size_of::<u32>(); asset.write_u32::<LE>(self.code_offset)?; offset += KismetExpression::write(self.skip_expression.as_ref(), asset)?; @@ -2676,7 +2976,9 @@ declare_expression!( ); impl ExStructConst { /// Read a `ExStructConst` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok(ExStructConst { token: EExprToken::ExStructConst, struct_value: PackageIndex::new(asset.read_i32::<LE>()?), @@ -2686,7 +2988,10 @@ impl ExStructConst { } } impl KismetExpressionTrait for ExStructConst { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { let mut offset = size_of::<u64>() + size_of::<i32>(); asset.write_i32::<LE>(self.struct_value.index)?; asset.write_i32::<LE>(self.struct_size)?; @@ -2706,7 +3011,9 @@ declare_expression!( ); impl ExStructMemberContext { /// Read a `ExStructMemberContext` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let struct_member_expression = KismetPropertyPointer::new(asset)?; let struct_expression = KismetExpression::new(asset)?; Ok(ExStructMemberContext { @@ -2717,7 +3024,10 @@ impl ExStructMemberContext { } } impl KismetExpressionTrait for ExStructMemberContext { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { let mut offset = 0; offset += self.struct_member_expression.write(asset)?; offset += KismetExpression::write(self.struct_expression.as_ref(), asset)?; @@ -2737,7 +3047,9 @@ declare_expression!( ); impl ExSwitchValue { /// Read a `ExSwitchValue` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let num_cases = asset.read_u16::<LE>()?; let end_goto_offset = asset.read_u32::<LE>()?; let index_term = Box::new(KismetExpression::new(asset)?); @@ -2760,7 +3072,10 @@ impl ExSwitchValue { } } impl KismetExpressionTrait for ExSwitchValue { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { let mut offset = size_of::<u16>() + size_of::<u32>(); asset.write_u16::<LE>(self.cases.len() as u16)?; asset.write_u32::<LE>(self.end_goto_offset)?; @@ -2784,7 +3099,9 @@ declare_expression!( ); impl ExVirtualFunction { /// Read a `ExVirtualFunction` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok(ExVirtualFunction { token: EExprToken::ExVirtualFunction, virtual_function_name: asset.read_fname()?, @@ -2793,7 +3110,10 @@ impl ExVirtualFunction { } } impl KismetExpressionTrait for ExVirtualFunction { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { let mut offset = 12; // FScriptName's iCode offset asset.write_fname(&self.virtual_function_name)?; for parameter in &self.parameters { @@ -2810,7 +3130,9 @@ declare_expression!( ); impl ExStringConst { /// Read a `ExStringConst` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok(ExStringConst { token: EExprToken::ExStringConst, value: read_kismet_string(asset)?, @@ -2818,7 +3140,10 @@ impl ExStringConst { } } impl KismetExpressionTrait for ExStringConst { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { write_kismet_string(&self.value, asset) } } @@ -2829,7 +3154,9 @@ declare_expression!( ); impl ExUnicodeStringConst { /// Read a `ExUnicodeStringConst` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok(ExUnicodeStringConst { token: EExprToken::ExUnicodeStringConst, value: read_kismet_unicode_string(asset)?, @@ -2837,7 +3164,10 @@ impl ExUnicodeStringConst { } } impl KismetExpressionTrait for ExUnicodeStringConst { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { write_kismet_unicode_string(&self.value, asset) } } @@ -2852,7 +3182,9 @@ declare_expression!( ); impl ExInstrumentationEvent { /// Read a `ExInstrumentationEvent` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let event_type: EScriptInstrumentationType = EScriptInstrumentationType::try_from(asset.read_u8()?)?; @@ -2869,7 +3201,10 @@ impl ExInstrumentationEvent { } } impl KismetExpressionTrait for ExInstrumentationEvent { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { asset.write_u8(self.event_type as u8)?; if self.event_type == EScriptInstrumentationType::InlineEvent { @@ -2891,7 +3226,9 @@ declare_expression!( ); impl ExDoubleConst { /// Read a `ExDoubleConst` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok(ExDoubleConst { token: EExprToken::ExDoubleConst, value: OrderedFloat(asset.read_f64::<LE>()?), @@ -2899,7 +3236,10 @@ impl ExDoubleConst { } } impl KismetExpressionTrait for ExDoubleConst { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { asset.write_f64::<LE>(self.value.0)?; Ok(size_of::<f64>()) } @@ -2913,7 +3253,9 @@ declare_expression!( ); impl ExFloatConst { /// Read a `ExFloatConst` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok(ExFloatConst { token: EExprToken::ExFloatConst, value: OrderedFloat(asset.read_f32::<LE>()?), @@ -2921,7 +3263,10 @@ impl ExFloatConst { } } impl KismetExpressionTrait for ExFloatConst { - fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { asset.write_f32::<LE>(self.value.0)?; Ok(size_of::<f32>()) } diff --git a/unreal_asset/unreal_asset_properties/src/array_property.rs b/unreal_asset/unreal_asset_properties/src/array_property.rs index e2666d74..e1348ef8 100644 --- a/unreal_asset/unreal_asset_properties/src/array_property.rs +++ b/unreal_asset/unreal_asset_properties/src/array_property.rs @@ -1,5 +1,7 @@ //! Array property +use unreal_asset_base::types::PackageIndexTrait; + use crate::property_prelude::*; /// Array property @@ -24,7 +26,7 @@ impl_property_data_trait!(ArrayProperty); impl ArrayProperty { /// Read an `ArrayProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -70,7 +72,7 @@ impl ArrayProperty { /// Read an `ArrayProperty` from an asset without reading the property header #[allow(clippy::too_many_arguments)] - pub fn new_no_header<Reader: ArchiveReader>( + pub fn new_no_header<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -232,7 +234,7 @@ impl ArrayProperty { } /// Write an `ArrayProperty` to an asset - pub fn write_full<Writer: ArchiveWriter>( + pub fn write_full<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, @@ -331,7 +333,7 @@ impl ArrayProperty { } impl PropertyTrait for ArrayProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, diff --git a/unreal_asset/unreal_asset_properties/src/cloth_lod_property.rs b/unreal_asset/unreal_asset_properties/src/cloth_lod_property.rs index a9a64227..177f1454 100644 --- a/unreal_asset/unreal_asset_properties/src/cloth_lod_property.rs +++ b/unreal_asset/unreal_asset_properties/src/cloth_lod_property.rs @@ -1,5 +1,7 @@ //! Cloth lod property +use unreal_asset_base::types::PackageIndexTrait; + use crate::property_prelude::*; use crate::vector_property::Vector4Property; @@ -20,7 +22,9 @@ pub struct MeshToMeshVertData { impl MeshToMeshVertData { /// Read `MeshToMeshVertData` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let position_bary_coords_and_dist = Vector4Property::new( asset, asset @@ -72,7 +76,10 @@ impl MeshToMeshVertData { } /// Write `MeshToMeshVertData` to an asset - pub fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<usize, Error> { + pub fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<usize, Error> { let mut size = 0; size += self.position_bary_coords_and_dist.write(asset, false)?; size += self.normal_bary_coords_and_dist.write(asset, false)?; @@ -108,7 +115,7 @@ pub struct ClothLodDataProperty { impl ClothLodDataProperty { /// Read a `ClothLodDataProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -175,7 +182,7 @@ impl PropertyDataTrait for ClothLodDataProperty { } impl PropertyTrait for ClothLodDataProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, diff --git a/unreal_asset/unreal_asset_properties/src/color_property.rs b/unreal_asset/unreal_asset_properties/src/color_property.rs index 919a9388..33f87179 100644 --- a/unreal_asset/unreal_asset_properties/src/color_property.rs +++ b/unreal_asset/unreal_asset_properties/src/color_property.rs @@ -1,6 +1,6 @@ //! Color properties -use unreal_asset_base::types::vector::Color; +use unreal_asset_base::types::{vector::Color, PackageIndexTrait}; use crate::property_prelude::*; @@ -40,7 +40,7 @@ impl_property_data_trait!(LinearColorProperty); impl ColorProperty { /// Read a `ColorProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -60,7 +60,7 @@ impl ColorProperty { } impl PropertyTrait for ColorProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, @@ -73,7 +73,7 @@ impl PropertyTrait for ColorProperty { impl LinearColorProperty { /// Read a `LinearColorProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -98,7 +98,7 @@ impl LinearColorProperty { } impl PropertyTrait for LinearColorProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, diff --git a/unreal_asset/unreal_asset_properties/src/date_property.rs b/unreal_asset/unreal_asset_properties/src/date_property.rs index 909a3eb3..fbbb9cc9 100644 --- a/unreal_asset/unreal_asset_properties/src/date_property.rs +++ b/unreal_asset/unreal_asset_properties/src/date_property.rs @@ -1,5 +1,7 @@ //! Date properties +use unreal_asset_base::types::PackageIndexTrait; + use crate::property_prelude::*; /// Time span property @@ -36,7 +38,7 @@ impl_property_data_trait!(DateTimeProperty); impl TimeSpanProperty { /// Read a `TimeSpanProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -59,7 +61,7 @@ simple_property_write!(TimeSpanProperty, write_i64, ticks, i64); impl DateTimeProperty { /// Read a `DateTimeProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, diff --git a/unreal_asset/unreal_asset_properties/src/delegate_property.rs b/unreal_asset/unreal_asset_properties/src/delegate_property.rs index 18e3d33b..55ad3fcf 100644 --- a/unreal_asset/unreal_asset_properties/src/delegate_property.rs +++ b/unreal_asset/unreal_asset_properties/src/delegate_property.rs @@ -1,5 +1,7 @@ //! Delegate properties +use unreal_asset_base::types::PackageIndexTrait; + use crate::property_prelude::*; /// Delegate @@ -37,7 +39,7 @@ impl_property_data_trait!(DelegateProperty); impl DelegateProperty { /// Read a `DelegateProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -61,7 +63,7 @@ impl DelegateProperty { } impl PropertyTrait for DelegateProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, @@ -95,7 +97,7 @@ macro_rules! impl_multicast { impl_property_data_trait!($property_name); impl $property_name { /// Read a `$property_name` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -125,7 +127,7 @@ macro_rules! impl_multicast { } impl PropertyTrait for $property_name { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, diff --git a/unreal_asset/unreal_asset_properties/src/empty_property.rs b/unreal_asset/unreal_asset_properties/src/empty_property.rs index 2c3b3ad5..9f955c5e 100644 --- a/unreal_asset/unreal_asset_properties/src/empty_property.rs +++ b/unreal_asset/unreal_asset_properties/src/empty_property.rs @@ -1,5 +1,7 @@ //! Empty unversioned property +use unreal_asset_base::types::PackageIndexTrait; + use crate::property_prelude::*; /// Empty unversioned property @@ -51,7 +53,7 @@ impl PropertyDataTrait for EmptyProperty { } impl PropertyTrait for EmptyProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, _asset: &mut Writer, _include_header: bool, diff --git a/unreal_asset/unreal_asset_properties/src/enum_property.rs b/unreal_asset/unreal_asset_properties/src/enum_property.rs index 75f7baaa..9654be3a 100644 --- a/unreal_asset/unreal_asset_properties/src/enum_property.rs +++ b/unreal_asset/unreal_asset_properties/src/enum_property.rs @@ -1,5 +1,7 @@ //! Enum property +use unreal_asset_base::types::PackageIndexTrait; + use crate::property_prelude::*; /// Enum property @@ -24,7 +26,7 @@ impl_property_data_trait!(EnumProperty); impl EnumProperty { /// Read an `EnumProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -96,7 +98,7 @@ impl EnumProperty { } impl PropertyTrait for EnumProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, diff --git a/unreal_asset/unreal_asset_properties/src/float_range_property.rs b/unreal_asset/unreal_asset_properties/src/float_range_property.rs index 6e7d8b89..b6b524ed 100644 --- a/unreal_asset/unreal_asset_properties/src/float_range_property.rs +++ b/unreal_asset/unreal_asset_properties/src/float_range_property.rs @@ -1,5 +1,7 @@ //! Float range property +use unreal_asset_base::types::PackageIndexTrait; + use crate::property_prelude::*; /// Float range property @@ -22,7 +24,7 @@ impl_property_data_trait!(FloatRangeProperty); impl FloatRangeProperty { /// Read a `FloatRangeProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -46,7 +48,7 @@ impl FloatRangeProperty { } impl PropertyTrait for FloatRangeProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, diff --git a/unreal_asset/unreal_asset_properties/src/font_character_property.rs b/unreal_asset/unreal_asset_properties/src/font_character_property.rs index 1a9473d9..f2ca9118 100644 --- a/unreal_asset/unreal_asset_properties/src/font_character_property.rs +++ b/unreal_asset/unreal_asset_properties/src/font_character_property.rs @@ -1,5 +1,7 @@ //! Font character property +use unreal_asset_base::types::PackageIndexTrait; + use crate::property_prelude::*; /// Font character @@ -21,7 +23,9 @@ pub struct FontCharacter { impl FontCharacter { /// Read a `FontCharacter` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok(FontCharacter { start_u: asset.read_i32::<LE>()?, start_v: asset.read_i32::<LE>()?, @@ -33,7 +37,10 @@ impl FontCharacter { } /// Write a `FontCharacter` to an asset - pub fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { + pub fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<(), Error> { asset.write_i32::<LE>(self.start_u)?; asset.write_i32::<LE>(self.start_v)?; asset.write_i32::<LE>(self.size_u)?; @@ -63,7 +70,7 @@ impl_property_data_trait!(FontCharacterProperty); impl FontCharacterProperty { /// Read a `FontCharacterProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -86,7 +93,7 @@ impl FontCharacterProperty { } impl PropertyTrait for FontCharacterProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, diff --git a/unreal_asset/unreal_asset_properties/src/game_framework/unique_net_id_property.rs b/unreal_asset/unreal_asset_properties/src/game_framework/unique_net_id_property.rs index 4c7a4050..505c3d55 100644 --- a/unreal_asset/unreal_asset_properties/src/game_framework/unique_net_id_property.rs +++ b/unreal_asset/unreal_asset_properties/src/game_framework/unique_net_id_property.rs @@ -1,5 +1,7 @@ //! Unique network id property +use unreal_asset_base::types::PackageIndexTrait; + use crate::property_prelude::*; /// Unique network id @@ -29,7 +31,7 @@ impl_property_data_trait!(UniqueNetIdProperty); impl UniqueNetIdProperty { /// Read a `UniqueNetIdProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -59,7 +61,7 @@ impl UniqueNetIdProperty { } impl PropertyTrait for UniqueNetIdProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, diff --git a/unreal_asset/unreal_asset_properties/src/gameplay_tag_container_property.rs b/unreal_asset/unreal_asset_properties/src/gameplay_tag_container_property.rs index a3f4a87e..b8e9f44b 100644 --- a/unreal_asset/unreal_asset_properties/src/gameplay_tag_container_property.rs +++ b/unreal_asset/unreal_asset_properties/src/gameplay_tag_container_property.rs @@ -1,5 +1,7 @@ //! Gameplay tag container property +use unreal_asset_base::types::PackageIndexTrait; + use crate::property_prelude::*; /// Gameplay tag container property @@ -20,7 +22,7 @@ impl_property_data_trait!(GameplayTagContainerProperty); impl GameplayTagContainerProperty { /// Read a `GameplayTagContainerProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -47,7 +49,7 @@ impl GameplayTagContainerProperty { } impl PropertyTrait for GameplayTagContainerProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, diff --git a/unreal_asset/unreal_asset_properties/src/guid_property.rs b/unreal_asset/unreal_asset_properties/src/guid_property.rs index b98979ca..d926c383 100644 --- a/unreal_asset/unreal_asset_properties/src/guid_property.rs +++ b/unreal_asset/unreal_asset_properties/src/guid_property.rs @@ -1,5 +1,7 @@ //! Guid property +use unreal_asset_base::types::PackageIndexTrait; + use crate::property_prelude::*; /// Guid property @@ -20,7 +22,7 @@ impl_property_data_trait!(GuidProperty); impl GuidProperty { /// Read a `GuidProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -40,7 +42,7 @@ impl GuidProperty { } impl PropertyTrait for GuidProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, diff --git a/unreal_asset/unreal_asset_properties/src/int_property.rs b/unreal_asset/unreal_asset_properties/src/int_property.rs index 896a6ba8..cf19b0dd 100644 --- a/unreal_asset/unreal_asset_properties/src/int_property.rs +++ b/unreal_asset/unreal_asset_properties/src/int_property.rs @@ -1,5 +1,7 @@ //! Int properties +use unreal_asset_base::types::PackageIndexTrait; + use crate::property_prelude::*; /// Implement a simple integer property @@ -7,7 +9,7 @@ macro_rules! impl_int_property { ($property_type:ident, $read_func:ident, $write_func:ident, $ty:ty) => { impl $property_type { /// Read `$property_type` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -226,7 +228,7 @@ impl_property_data_trait!(DoubleProperty); impl BoolProperty { /// Read a `BoolProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -248,7 +250,7 @@ impl BoolProperty { } impl PropertyTrait for BoolProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, @@ -261,7 +263,7 @@ impl PropertyTrait for BoolProperty { impl Int8Property { /// Read an `Int8Property` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -281,7 +283,7 @@ impl Int8Property { } impl PropertyTrait for Int8Property { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, @@ -294,7 +296,7 @@ impl PropertyTrait for Int8Property { impl ByteProperty { /// Read byte property value - fn read_value<Reader: ArchiveReader>( + fn read_value<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, length: i64, ) -> Result<BytePropertyValue, Error> { @@ -333,7 +335,7 @@ impl ByteProperty { } /// Read a `ByteProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -362,7 +364,7 @@ impl ByteProperty { } impl PropertyTrait for ByteProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, @@ -391,7 +393,7 @@ impl PropertyTrait for ByteProperty { impl FloatProperty { /// Read a `FloatProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -412,7 +414,7 @@ impl FloatProperty { } impl PropertyTrait for FloatProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, @@ -425,7 +427,7 @@ impl PropertyTrait for FloatProperty { impl DoubleProperty { /// Read a `DoubleProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -446,7 +448,7 @@ impl DoubleProperty { } impl PropertyTrait for DoubleProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, diff --git a/unreal_asset/unreal_asset_properties/src/lib.rs b/unreal_asset/unreal_asset_properties/src/lib.rs index c60418a1..8025023d 100644 --- a/unreal_asset/unreal_asset_properties/src/lib.rs +++ b/unreal_asset/unreal_asset_properties/src/lib.rs @@ -14,6 +14,7 @@ use enum_dispatch::enum_dispatch; // macro reexports pub use unreal_asset_base::types::FName; +use unreal_asset_base::types::PackageIndexTrait; pub use unreal_asset_base::unversioned::Ancestry; pub use unreal_asset_base::Guid; @@ -150,7 +151,7 @@ mod property_prelude { pub use unreal_asset_base::reader::{ArchiveReader, ArchiveWriter}; pub use unreal_asset_base::types::{ fname::{FName, ToSerializedName}, - PackageIndex, + PackageIndex, PackageIndexTrait, }; pub use unreal_asset_base::unversioned::{ header::UnversionedHeader, @@ -199,7 +200,7 @@ macro_rules! optional_guid_write { macro_rules! simple_property_write { ($property_name:ident, $write_func:ident, $value_name:ident, $value_type:ty) => { impl PropertyTrait for $property_name { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, @@ -326,7 +327,7 @@ pub trait PropertyDataTrait { #[enum_dispatch] pub trait PropertyTrait: PropertyDataTrait + Debug + Hash + Clone + PartialEq + Eq { /// Write property to an asset - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, @@ -518,7 +519,7 @@ pub enum Property { impl Property { /// Tries to read a property from an ArchiveReader - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, ancestry: Ancestry, unversioned_header: Option<&mut UnversionedHeader>, @@ -623,7 +624,7 @@ impl Property { /// Tries to read a property from an ArchiveReader while specified a type and length #[allow(clippy::too_many_arguments)] - pub fn from_type<Reader: ArchiveReader>( + pub fn from_type<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, type_name: &FName, name: FName, @@ -1327,7 +1328,7 @@ impl Property { } /// Writes a property to an ArchiveWriter - pub fn write<Writer: ArchiveWriter>( + pub fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( property: &Property, asset: &mut Writer, include_header: bool, @@ -1469,8 +1470,8 @@ property_inner_serialized_name! { } /// Generate property unversioned header -pub fn generate_unversioned_header<W: ArchiveWriter>( - archive: &mut W, +pub fn generate_unversioned_header<W: ArchiveWriter<impl PackageIndexTrait>>( + archive: &W, properties: &[Property], parent_name: &FName, ) -> Result<Option<(UnversionedHeader, Vec<Property>)>, Error> { @@ -1494,7 +1495,9 @@ pub fn generate_unversioned_header<W: ArchiveWriter>( property.get_ancestry(), property.get_duplication_index() as u32, ) else { - return property.get_name().get_content(|name| Err(PropertyError::no_mapping(name, property.get_ancestry()).into())); + return property.get_name().get_content(|name| { + Err(PropertyError::no_mapping(name, property.get_ancestry()).into()) + }); }; if matches!(property, Property::EmptyProperty(_)) { diff --git a/unreal_asset/unreal_asset_properties/src/map_property.rs b/unreal_asset/unreal_asset_properties/src/map_property.rs index f1296f21..09e3a717 100644 --- a/unreal_asset/unreal_asset_properties/src/map_property.rs +++ b/unreal_asset/unreal_asset_properties/src/map_property.rs @@ -2,7 +2,7 @@ use std::hash::Hash; -use unreal_asset_base::containers::indexed_map::IndexedMap; +use unreal_asset_base::{containers::indexed_map::IndexedMap, types::PackageIndexTrait}; use crate::property_prelude::*; @@ -41,7 +41,7 @@ impl Hash for MapProperty { impl MapProperty { /// Map type_name to a `Property` and read it from an asset - fn map_type_to_class<Reader: ArchiveReader>( + fn map_type_to_class<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, type_name: FName, name: FName, @@ -117,7 +117,7 @@ impl MapProperty { } /// Read a `MapProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -208,7 +208,7 @@ impl MapProperty { } impl PropertyTrait for MapProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, diff --git a/unreal_asset/unreal_asset_properties/src/material_input_property.rs b/unreal_asset/unreal_asset_properties/src/material_input_property.rs index 49953937..678b9664 100644 --- a/unreal_asset/unreal_asset_properties/src/material_input_property.rs +++ b/unreal_asset/unreal_asset_properties/src/material_input_property.rs @@ -1,5 +1,7 @@ //! Material input property +use unreal_asset_base::types::PackageIndexTrait; + use crate::color_property::ColorProperty; use crate::property_prelude::*; use crate::vector_property::{Vector2DProperty, VectorProperty}; @@ -143,7 +145,7 @@ impl_property_data_trait!(MaterialAttributesInputProperty); impl MaterialExpression { /// Read a `MaterialExpression` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, _include_header: bool, @@ -164,7 +166,7 @@ impl MaterialExpression { } /// Write a `MaterialExpression` to an asset - pub fn write<Writer: ArchiveWriter>( + pub fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, _include_header: bool, @@ -179,7 +181,7 @@ impl MaterialExpression { impl ColorMaterialInputProperty { /// Read a `ColorMaterialInputProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -210,7 +212,7 @@ impl ColorMaterialInputProperty { } impl PropertyTrait for ColorMaterialInputProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, @@ -225,7 +227,7 @@ impl PropertyTrait for ColorMaterialInputProperty { impl ScalarMaterialInputProperty { /// Read a `ScalarMaterialInputProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -250,7 +252,7 @@ impl ScalarMaterialInputProperty { } impl PropertyTrait for ScalarMaterialInputProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, @@ -265,7 +267,7 @@ impl PropertyTrait for ScalarMaterialInputProperty { impl ShadingModelMaterialInputProperty { /// Read a `ShadingModelMaterialInputProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -289,7 +291,7 @@ impl ShadingModelMaterialInputProperty { } impl PropertyTrait for ShadingModelMaterialInputProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, @@ -304,7 +306,7 @@ impl PropertyTrait for ShadingModelMaterialInputProperty { impl VectorMaterialInputProperty { /// Read a `VectorMaterialInputProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -334,7 +336,7 @@ impl VectorMaterialInputProperty { } impl PropertyTrait for VectorMaterialInputProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, @@ -349,7 +351,7 @@ impl PropertyTrait for VectorMaterialInputProperty { impl Vector2MaterialInputProperty { /// Read a `Vector2MaterialInputProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -379,7 +381,7 @@ impl Vector2MaterialInputProperty { } impl PropertyTrait for Vector2MaterialInputProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, @@ -394,7 +396,7 @@ impl PropertyTrait for Vector2MaterialInputProperty { impl ExpressionInputProperty { /// Read a `ExpressionInputProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -415,7 +417,7 @@ impl ExpressionInputProperty { } impl PropertyTrait for ExpressionInputProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, @@ -427,7 +429,7 @@ impl PropertyTrait for ExpressionInputProperty { impl MaterialAttributesInputProperty { /// Read a `MaterialAttributesInputProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -448,7 +450,7 @@ impl MaterialAttributesInputProperty { } impl PropertyTrait for MaterialAttributesInputProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, diff --git a/unreal_asset/unreal_asset_properties/src/movies/mod.rs b/unreal_asset/unreal_asset_properties/src/movies/mod.rs index 8f0f8f2e..c8ea241b 100644 --- a/unreal_asset/unreal_asset_properties/src/movies/mod.rs +++ b/unreal_asset/unreal_asset_properties/src/movies/mod.rs @@ -1,5 +1,7 @@ //! Unreal movies +use unreal_asset_base::types::PackageIndexTrait; + use crate::property_prelude::*; use crate::rich_curve_key_property::RichCurveTangentWeightMode; @@ -40,7 +42,7 @@ pub struct MovieSceneTangentData { impl MovieSceneTangentData { /// Read `MovieSceneTangentData` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, clang_win64: bool, ) -> Result<Self, Error> { @@ -65,7 +67,10 @@ impl MovieSceneTangentData { } /// Write `MovieSceneTangentData` to an asset - pub fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { + pub fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<(), Error> { asset.write_f32::<LE>(self.arrive_tangent.0)?; asset.write_f32::<LE>(self.leave_tangent.0)?; asset.write_f32::<LE>(self.arrive_tangent_weight.0)?; diff --git a/unreal_asset/unreal_asset_properties/src/movies/movie_scene_eval_template_ptr_property.rs b/unreal_asset/unreal_asset_properties/src/movies/movie_scene_eval_template_ptr_property.rs index 140d79ec..2c288233 100644 --- a/unreal_asset/unreal_asset_properties/src/movies/movie_scene_eval_template_ptr_property.rs +++ b/unreal_asset/unreal_asset_properties/src/movies/movie_scene_eval_template_ptr_property.rs @@ -1,5 +1,7 @@ //! Movie scene evaluation template pointer property +use unreal_asset_base::types::PackageIndexTrait; + use crate::property_prelude::*; /// Movie scene evaluation template pointer property @@ -20,7 +22,7 @@ impl_property_data_trait!(MovieSceneEvalTemplatePtrProperty); impl MovieSceneEvalTemplatePtrProperty { /// Read a `MovieSceneEvalTemplatePtrProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -65,7 +67,7 @@ impl MovieSceneEvalTemplatePtrProperty { } impl PropertyTrait for MovieSceneEvalTemplatePtrProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, diff --git a/unreal_asset/unreal_asset_properties/src/movies/movie_scene_evaluation.rs b/unreal_asset/unreal_asset_properties/src/movies/movie_scene_evaluation.rs index 0e76ac50..056c6255 100644 --- a/unreal_asset/unreal_asset_properties/src/movies/movie_scene_evaluation.rs +++ b/unreal_asset/unreal_asset_properties/src/movies/movie_scene_evaluation.rs @@ -4,6 +4,7 @@ use std::fmt::Debug; use std::hash::Hash; use unreal_asset_base::types::movie::FFrameNumberRange; +use unreal_asset_base::types::PackageIndexTrait; use crate::property_prelude::*; @@ -20,7 +21,9 @@ pub struct FEntry { impl FEntry { /// Read an `FEntry` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let start_index = asset.read_i32::<LE>()?; let size = asset.read_i32::<LE>()?; let capacity = asset.read_i32::<LE>()?; @@ -33,7 +36,10 @@ impl FEntry { } /// Write an `FEntry` to an asset - pub fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { + pub fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<(), Error> { asset.write_i32::<LE>(self.start_index)?; asset.write_i32::<LE>(self.size)?; asset.write_i32::<LE>(self.capacity)?; @@ -50,14 +56,19 @@ pub struct EvaluationTreeEntryHandle { impl EvaluationTreeEntryHandle { /// Read an `EvaluationTreeEntryHandle` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let entry_index = asset.read_i32::<LE>()?; Ok(EvaluationTreeEntryHandle { entry_index }) } /// Write an `EvaluationTreeEntryHandle` to an asset - pub fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { + pub fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<(), Error> { asset.write_i32::<LE>(self.entry_index)?; Ok(()) } @@ -74,7 +85,9 @@ pub struct MovieSceneEvaluationTreeNodeHandle { impl MovieSceneEvaluationTreeNodeHandle { /// Read a `MovieSceneEvaluationTreeNodeHandle` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let children_handle = EvaluationTreeEntryHandle::new(asset)?; let index = asset.read_i32::<LE>()?; @@ -85,7 +98,10 @@ impl MovieSceneEvaluationTreeNodeHandle { } /// Write a `MovieSceneEvaluationTreeNodeHandle` to an asset - pub fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { + pub fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<(), Error> { self.children_handle.write(asset)?; asset.write_i32::<LE>(self.index)?; @@ -116,7 +132,7 @@ where } /// Read a `TEvaluationTreeEntryContainer` from an asset - pub fn read<Reader: ArchiveReader>( + pub fn read<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, item_reader: fn(&mut Reader) -> Result<T, Error>, ) -> Result<Self, Error> { @@ -138,7 +154,7 @@ where } /// Write a `TEvaluationTreeEntryContainer` to an asset - pub fn write<Writer: ArchiveWriter>( + pub fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, node_writer: fn(&mut Writer, &T) -> Result<(), Error>, @@ -191,7 +207,7 @@ where } /// Read a `TMovieSceneEvaluationTree` from an asset - pub fn read<Reader: ArchiveReader>( + pub fn read<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, data_node_reader: fn(&mut Reader) -> Result<T, Error>, ) -> Result<Self, Error> { @@ -210,7 +226,7 @@ where } /// Write a `TMovieSceneEvaluationTree` to an asset - pub fn write<Writer: ArchiveWriter>( + pub fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, data_node_writer: fn(&mut Writer, &T) -> Result<(), Error>, @@ -243,7 +259,9 @@ pub struct MovieSceneEvaluationTreeNode { impl MovieSceneEvaluationTreeNode { /// Read a `MovieSceneEvaluationTreeNode` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let range = FFrameNumberRange::new(asset)?; let parent = MovieSceneEvaluationTreeNodeHandle::new(asset)?; let children_id = EvaluationTreeEntryHandle::new(asset)?; @@ -258,7 +276,10 @@ impl MovieSceneEvaluationTreeNode { } /// Write a `MovieSceneEvaluationTreeNode` to an asset - pub fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { + pub fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<(), Error> { self.range.write(asset)?; self.parent.write(asset)?; self.children_id.write(asset)?; @@ -279,7 +300,9 @@ pub struct FEntityAndMetaDataIndex { impl FEntityAndMetaDataIndex { /// Read an `FEntityAndMetaDataIndex` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let entity_index = asset.read_i32::<LE>()?; let meta_data_index = asset.read_i32::<LE>()?; @@ -290,7 +313,10 @@ impl FEntityAndMetaDataIndex { } /// Write an `FEntityAndMetaDataIndex` to an asset - pub fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { + pub fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<(), Error> { asset.write_i32::<LE>(self.entity_index)?; asset.write_i32::<LE>(self.meta_data_index)?; @@ -307,7 +333,9 @@ pub struct MovieSceneEvaluationFieldEntityTree { impl MovieSceneEvaluationFieldEntityTree { /// Read a `MovieSceneEvaluationFieldEntityTree` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let serialized_data = TMovieSceneEvaluationTree::read(asset, |reader| FEntityAndMetaDataIndex::new(reader))?; @@ -315,7 +343,10 @@ impl MovieSceneEvaluationFieldEntityTree { } /// Write a `MovieSceneEvaluationFieldEntityTree` to an asset - pub fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { + pub fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<(), Error> { self.serialized_data.write(asset, |writer, node| { node.write(writer)?; Ok(()) diff --git a/unreal_asset/unreal_asset_properties/src/movies/movie_scene_evaluation_field_entity_tree_property.rs b/unreal_asset/unreal_asset_properties/src/movies/movie_scene_evaluation_field_entity_tree_property.rs index ca43a122..d0eb2a29 100644 --- a/unreal_asset/unreal_asset_properties/src/movies/movie_scene_evaluation_field_entity_tree_property.rs +++ b/unreal_asset/unreal_asset_properties/src/movies/movie_scene_evaluation_field_entity_tree_property.rs @@ -1,5 +1,7 @@ //! Movie scene evaluation field entity tree property +use unreal_asset_base::types::PackageIndexTrait; + use crate::property_prelude::*; use super::movie_scene_evaluation::MovieSceneEvaluationFieldEntityTree; @@ -23,7 +25,7 @@ impl_property_data_trait!(MovieSceneEvaluationFieldEntityTreeProperty); impl MovieSceneEvaluationFieldEntityTreeProperty { /// Read a `MovieSceneEvaluationFieldEntityTreeProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -45,7 +47,7 @@ impl MovieSceneEvaluationFieldEntityTreeProperty { } impl PropertyTrait for MovieSceneEvaluationFieldEntityTreeProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, diff --git a/unreal_asset/unreal_asset_properties/src/movies/movie_scene_evaluation_key_property.rs b/unreal_asset/unreal_asset_properties/src/movies/movie_scene_evaluation_key_property.rs index e39b22f4..328e1a93 100644 --- a/unreal_asset/unreal_asset_properties/src/movies/movie_scene_evaluation_key_property.rs +++ b/unreal_asset/unreal_asset_properties/src/movies/movie_scene_evaluation_key_property.rs @@ -1,5 +1,7 @@ //! Movie scene evaluation key property +use unreal_asset_base::types::PackageIndexTrait; + use crate::property_prelude::*; use super::movie_scene_sequence_id_property::MovieSceneSequenceId; @@ -18,7 +20,9 @@ pub struct MovieSceneEvaluationKey { impl MovieSceneEvaluationKey { /// Read a `MovieSceneEvaluationKey` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let sequence_id = MovieSceneSequenceId::new(asset)?; let track_identifier = MovieSceneTrackIdentifier::new(asset)?; let section_index = asset.read_u32::<LE>()?; @@ -31,7 +35,10 @@ impl MovieSceneEvaluationKey { } /// Write a `MovieSceneEvaluationKey` to an asset - pub fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { + pub fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<(), Error> { self.sequence_id.write(asset)?; self.track_identifier.write(asset)?; asset.write_u32::<LE>(self.section_index)?; @@ -59,7 +66,7 @@ impl_property_data_trait!(MovieSceneEvaluationKeyProperty); impl MovieSceneEvaluationKeyProperty { /// Read a `MovieSceneEvaluationKeyProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -81,7 +88,7 @@ impl MovieSceneEvaluationKeyProperty { } impl PropertyTrait for MovieSceneEvaluationKeyProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, diff --git a/unreal_asset/unreal_asset_properties/src/movies/movie_scene_event_parameters_property.rs b/unreal_asset/unreal_asset_properties/src/movies/movie_scene_event_parameters_property.rs index b3f9ce3e..ab178b6b 100644 --- a/unreal_asset/unreal_asset_properties/src/movies/movie_scene_event_parameters_property.rs +++ b/unreal_asset/unreal_asset_properties/src/movies/movie_scene_event_parameters_property.rs @@ -13,7 +13,9 @@ pub struct MovieSceneEventParameters { impl MovieSceneEventParameters { /// Read `MovieSceneEventParameters` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let struct_type = SoftObjectPath::new(asset)?; let struct_bytes_length = asset.read_i32::<LE>()?; @@ -27,7 +29,10 @@ impl MovieSceneEventParameters { } /// Write `MovieSceneEventParameters` to an asset - pub fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { + pub fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<(), Error> { self.struct_type.write(asset)?; asset.write_i32::<LE>(self.struct_bytes.len() as i32)?; @@ -55,7 +60,7 @@ impl_property_data_trait!(MovieSceneEventParametersProperty); impl MovieSceneEventParametersProperty { /// Read `MovieSceneEventParametersProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -76,7 +81,7 @@ impl MovieSceneEventParametersProperty { } impl PropertyTrait for MovieSceneEventParametersProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, diff --git a/unreal_asset/unreal_asset_properties/src/movies/movie_scene_float_channel_property.rs b/unreal_asset/unreal_asset_properties/src/movies/movie_scene_float_channel_property.rs index 7c3cc638..55ae5a13 100644 --- a/unreal_asset/unreal_asset_properties/src/movies/movie_scene_float_channel_property.rs +++ b/unreal_asset/unreal_asset_properties/src/movies/movie_scene_float_channel_property.rs @@ -35,7 +35,9 @@ pub struct MovieSceneFloatChannel { impl MovieSceneFloatChannel { /// Read a `MovieSceneFloatChannel` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let pre_infinity_extrap: RichCurveExtrapolation = RichCurveExtrapolation::try_from(asset.read_u8()?)?; let post_infinity_extrap: RichCurveExtrapolation = @@ -77,7 +79,10 @@ impl MovieSceneFloatChannel { } /// Write a `MovieSceneFloatChannel` to an asset - pub fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { + pub fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<(), Error> { asset.write_u8(self.pre_infinity_extrap as u8)?; asset.write_u8(self.post_infinity_extrap as u8)?; @@ -127,7 +132,7 @@ impl_property_data_trait!(MovieSceneFloatChannelProperty); impl MovieSceneFloatChannelProperty { /// Read a `MovieSceneFloatChannelProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -149,7 +154,7 @@ impl MovieSceneFloatChannelProperty { } impl PropertyTrait for MovieSceneFloatChannelProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, diff --git a/unreal_asset/unreal_asset_properties/src/movies/movie_scene_float_value_property.rs b/unreal_asset/unreal_asset_properties/src/movies/movie_scene_float_value_property.rs index 48fc76fb..131f2389 100644 --- a/unreal_asset/unreal_asset_properties/src/movies/movie_scene_float_value_property.rs +++ b/unreal_asset/unreal_asset_properties/src/movies/movie_scene_float_value_property.rs @@ -20,7 +20,7 @@ pub struct MovieSceneFloatValue { impl MovieSceneFloatValue { /// Read a `MovieSceneFloatValue` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, clang_win64: bool, ) -> Result<Self, Error> { @@ -38,7 +38,10 @@ impl MovieSceneFloatValue { } /// Write a `MovieSceneFloatValue` to an asset - pub fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { + pub fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<(), Error> { asset.write_f32::<LE>(self.value.0)?; self.tangent.write(asset)?; asset.write_i8(self.interp_mode as i8)?; @@ -66,7 +69,7 @@ impl_property_data_trait!(MovieSceneFloatValueProperty); impl MovieSceneFloatValueProperty { /// Read a `MovieSceneFloatValueProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -89,7 +92,7 @@ impl MovieSceneFloatValueProperty { } impl PropertyTrait for MovieSceneFloatValueProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, diff --git a/unreal_asset/unreal_asset_properties/src/movies/movie_scene_frame_range_property.rs b/unreal_asset/unreal_asset_properties/src/movies/movie_scene_frame_range_property.rs index 33be8853..b2f241b4 100644 --- a/unreal_asset/unreal_asset_properties/src/movies/movie_scene_frame_range_property.rs +++ b/unreal_asset/unreal_asset_properties/src/movies/movie_scene_frame_range_property.rs @@ -15,7 +15,9 @@ pub struct Int32RangeBound { impl Int32RangeBound { /// Read an `Int32RangeBound` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let ty: ERangeBoundTypes = ERangeBoundTypes::try_from(asset.read_i8()?)?; let value = asset.read_i32::<LE>()?; @@ -23,7 +25,10 @@ impl Int32RangeBound { } /// Write an `Int32RangeBound` to an asset - pub fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { + pub fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<(), Error> { asset.write_i8(self.ty as i8)?; asset.write_i32::<LE>(self.value)?; @@ -53,7 +58,7 @@ impl_property_data_trait!(MovieSceneFrameRangeProperty); impl MovieSceneFrameRangeProperty { /// Read a `MovieSceneFrameRangeProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -77,7 +82,7 @@ impl MovieSceneFrameRangeProperty { } impl PropertyTrait for MovieSceneFrameRangeProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, diff --git a/unreal_asset/unreal_asset_properties/src/movies/movie_scene_segment_property.rs b/unreal_asset/unreal_asset_properties/src/movies/movie_scene_segment_property.rs index aa178ae9..0a0e0759 100644 --- a/unreal_asset/unreal_asset_properties/src/movies/movie_scene_segment_property.rs +++ b/unreal_asset/unreal_asset_properties/src/movies/movie_scene_segment_property.rs @@ -13,14 +13,19 @@ pub struct MovieSceneSegmentIdentifier { impl MovieSceneSegmentIdentifier { /// Read a `MovieSceneSegmentIdentifier` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let identifier_index = asset.read_i32::<LE>()?; Ok(MovieSceneSegmentIdentifier { identifier_index }) } /// Write a `MovieSceneSegmentIdentifier` to an asset - pub fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { + pub fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<(), Error> { asset.write_i32::<LE>(self.identifier_index)?; Ok(()) } @@ -45,7 +50,7 @@ pub struct MovieSceneSegment { impl MovieSceneSegment { /// Read a `MovieSceneSegment` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -79,7 +84,10 @@ impl MovieSceneSegment { } /// Write a `MovieSceneSegment` to an asset - pub fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { + pub fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<(), Error> { self.range.write(asset)?; self.id.write(asset)?; @@ -133,7 +141,7 @@ impl_property_data_trait!(MovieSceneSegmentProperty); impl MovieSceneSegmentProperty { /// Read a `MovieSceneSegmentProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -156,7 +164,7 @@ impl MovieSceneSegmentProperty { } impl PropertyTrait for MovieSceneSegmentProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, @@ -190,7 +198,7 @@ impl_property_data_trait!(MovieSceneSegmentIdentifierProperty); impl MovieSceneSegmentIdentifierProperty { /// Read a `MovieSceneSegmentIdentifierProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -212,7 +220,7 @@ impl MovieSceneSegmentIdentifierProperty { } impl PropertyTrait for MovieSceneSegmentIdentifierProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, diff --git a/unreal_asset/unreal_asset_properties/src/movies/movie_scene_sequence_id_property.rs b/unreal_asset/unreal_asset_properties/src/movies/movie_scene_sequence_id_property.rs index 102b0f3e..970bc8e7 100644 --- a/unreal_asset/unreal_asset_properties/src/movies/movie_scene_sequence_id_property.rs +++ b/unreal_asset/unreal_asset_properties/src/movies/movie_scene_sequence_id_property.rs @@ -11,14 +11,19 @@ pub struct MovieSceneSequenceId { impl MovieSceneSequenceId { /// Read a `MovieSceneSequenceId` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let value = asset.read_u32::<LE>()?; Ok(MovieSceneSequenceId { value }) } /// Write a `MovieSceneSequenceId` to an asset - pub fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { + pub fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<(), Error> { asset.write_u32::<LE>(self.value)?; Ok(()) } @@ -43,7 +48,7 @@ impl_property_data_trait!(MovieSceneSequenceIdProperty); impl MovieSceneSequenceIdProperty { /// Read a `MovieSceneSequenceIdProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -65,7 +70,7 @@ impl MovieSceneSequenceIdProperty { } impl PropertyTrait for MovieSceneSequenceIdProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, diff --git a/unreal_asset/unreal_asset_properties/src/movies/movie_scene_sequence_instance_data_ptr_property.rs b/unreal_asset/unreal_asset_properties/src/movies/movie_scene_sequence_instance_data_ptr_property.rs index 4c1d1583..64a823db 100644 --- a/unreal_asset/unreal_asset_properties/src/movies/movie_scene_sequence_instance_data_ptr_property.rs +++ b/unreal_asset/unreal_asset_properties/src/movies/movie_scene_sequence_instance_data_ptr_property.rs @@ -21,7 +21,7 @@ impl_property_data_trait!(MovieSceneSequenceInstanceDataPtrProperty); impl MovieSceneSequenceInstanceDataPtrProperty { /// Read a `MovieSceneSequenceInstanceDataPtrProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -43,7 +43,7 @@ impl MovieSceneSequenceInstanceDataPtrProperty { } impl PropertyTrait for MovieSceneSequenceInstanceDataPtrProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, diff --git a/unreal_asset/unreal_asset_properties/src/movies/movie_scene_sub_sequence_tree_property.rs b/unreal_asset/unreal_asset_properties/src/movies/movie_scene_sub_sequence_tree_property.rs index ce4ad2bb..d204d61d 100644 --- a/unreal_asset/unreal_asset_properties/src/movies/movie_scene_sub_sequence_tree_property.rs +++ b/unreal_asset/unreal_asset_properties/src/movies/movie_scene_sub_sequence_tree_property.rs @@ -18,7 +18,9 @@ pub struct MovieSceneSubSequenceTreeEntry { impl MovieSceneSubSequenceTreeEntry { /// Read a `MovieSceneSubSequenceTreeEntry` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let sequence_id = MovieSceneSequenceId::new(asset)?; let flags: ESectionEvaluationFlags = ESectionEvaluationFlags::try_from(asset.read_u8()?)?; @@ -26,7 +28,10 @@ impl MovieSceneSubSequenceTreeEntry { } /// Write a `MovieSceneSubSequenceTreeEntry` to an asset - pub fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { + pub fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<(), Error> { self.sequence_id.write(asset)?; asset.write_u8(self.flags as u8)?; @@ -43,7 +48,9 @@ pub struct MovieSceneSubSequenceTree { impl MovieSceneSubSequenceTree { /// Read a `MovieSceneSubSequenceTree` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let data = TMovieSceneEvaluationTree::read(asset, |reader| { MovieSceneSubSequenceTreeEntry::new(reader) })?; @@ -52,7 +59,10 @@ impl MovieSceneSubSequenceTree { } /// Write a `MovieSceneSubSequenceTree` to an asset - pub fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { + pub fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<(), Error> { self.data.write(asset, |writer, node| { node.write(writer)?; Ok(()) @@ -81,7 +91,7 @@ impl_property_data_trait!(MovieSceneSubSequenceTreeProperty); impl MovieSceneSubSequenceTreeProperty { /// Read a `MovieSceneSubSequenceTreeProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -103,7 +113,7 @@ impl MovieSceneSubSequenceTreeProperty { } impl PropertyTrait for MovieSceneSubSequenceTreeProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, diff --git a/unreal_asset/unreal_asset_properties/src/movies/movie_scene_track_field_data_property.rs b/unreal_asset/unreal_asset_properties/src/movies/movie_scene_track_field_data_property.rs index 1c427561..08803e51 100644 --- a/unreal_asset/unreal_asset_properties/src/movies/movie_scene_track_field_data_property.rs +++ b/unreal_asset/unreal_asset_properties/src/movies/movie_scene_track_field_data_property.rs @@ -16,7 +16,9 @@ pub struct MovieSceneTrackFieldData { impl MovieSceneTrackFieldData { /// Read `MovieSceneTrackFieldData` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let field = TMovieSceneEvaluationTree::read(asset, |reader| { MovieSceneTrackIdentifier::new(reader) })?; @@ -25,7 +27,10 @@ impl MovieSceneTrackFieldData { } /// Write `MovieSceneTrackFieldData` to an asset - pub fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { + pub fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<(), Error> { self.field.write(asset, |writer, node| { node.write(writer)?; Ok(()) @@ -54,7 +59,7 @@ impl_property_data_trait!(MovieSceneTrackFieldDataProperty); impl MovieSceneTrackFieldDataProperty { /// Read a `MovieSceneTrackFieldDataProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -76,7 +81,7 @@ impl MovieSceneTrackFieldDataProperty { } impl PropertyTrait for MovieSceneTrackFieldDataProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, diff --git a/unreal_asset/unreal_asset_properties/src/movies/movie_scene_track_identifier_property.rs b/unreal_asset/unreal_asset_properties/src/movies/movie_scene_track_identifier_property.rs index c035fc84..aa6510ae 100644 --- a/unreal_asset/unreal_asset_properties/src/movies/movie_scene_track_identifier_property.rs +++ b/unreal_asset/unreal_asset_properties/src/movies/movie_scene_track_identifier_property.rs @@ -11,14 +11,19 @@ pub struct MovieSceneTrackIdentifier { impl MovieSceneTrackIdentifier { /// Read a `MovieSceneTrackIdentifier` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let value = asset.read_u32::<LE>()?; Ok(MovieSceneTrackIdentifier { value }) } /// Write a `MovieSceneTrackIdentifier` to an asset - pub fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { + pub fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<(), Error> { asset.write_u32::<LE>(self.value)?; Ok(()) } @@ -43,7 +48,7 @@ impl_property_data_trait!(MovieSceneTrackIdentifierProperty); impl MovieSceneTrackIdentifierProperty { /// Read a `MovieSceneTrackIdentifierProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -65,7 +70,7 @@ impl MovieSceneTrackIdentifierProperty { } impl PropertyTrait for MovieSceneTrackIdentifierProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, diff --git a/unreal_asset/unreal_asset_properties/src/movies/movie_scene_track_implementation_ptr_property.rs b/unreal_asset/unreal_asset_properties/src/movies/movie_scene_track_implementation_ptr_property.rs index 7c40db95..c41ad451 100644 --- a/unreal_asset/unreal_asset_properties/src/movies/movie_scene_track_implementation_ptr_property.rs +++ b/unreal_asset/unreal_asset_properties/src/movies/movie_scene_track_implementation_ptr_property.rs @@ -20,7 +20,7 @@ impl_property_data_trait!(MovieSceneTrackImplementationPtrProperty); impl MovieSceneTrackImplementationPtrProperty { /// Read a `MovieSceneTrackImplementationPtrProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -65,7 +65,7 @@ impl MovieSceneTrackImplementationPtrProperty { } impl PropertyTrait for MovieSceneTrackImplementationPtrProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, diff --git a/unreal_asset/unreal_asset_properties/src/movies/section_evaluation_data_tree_property.rs b/unreal_asset/unreal_asset_properties/src/movies/section_evaluation_data_tree_property.rs index deb9ab6d..22c993b9 100644 --- a/unreal_asset/unreal_asset_properties/src/movies/section_evaluation_data_tree_property.rs +++ b/unreal_asset/unreal_asset_properties/src/movies/section_evaluation_data_tree_property.rs @@ -13,7 +13,9 @@ pub struct SectionEvaluationTree { impl SectionEvaluationTree { /// Read a `SectionEvaluationTree` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let tree = TMovieSceneEvaluationTree::read(asset, |reader| { let mut resulting_list = Vec::new(); let mut unversioned_header = UnversionedHeader::new(reader)?; @@ -33,7 +35,10 @@ impl SectionEvaluationTree { } /// Write a `SectionEvaluationTree` to an asset - pub fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { + pub fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<(), Error> { self.tree.write(asset, |writer, node| { let (unversioned_header, sorted_properties) = match generate_unversioned_header( writer, @@ -83,7 +88,7 @@ impl_property_data_trait!(SectionEvaluationDataTreeProperty); impl SectionEvaluationDataTreeProperty { /// Read a `SectionEvaluationDataTreeProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -105,7 +110,7 @@ impl SectionEvaluationDataTreeProperty { } impl PropertyTrait for SectionEvaluationDataTreeProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, diff --git a/unreal_asset/unreal_asset_properties/src/niagara/niagara_variable_property.rs b/unreal_asset/unreal_asset_properties/src/niagara/niagara_variable_property.rs index 827115af..46d9f9d4 100644 --- a/unreal_asset/unreal_asset_properties/src/niagara/niagara_variable_property.rs +++ b/unreal_asset/unreal_asset_properties/src/niagara/niagara_variable_property.rs @@ -15,7 +15,7 @@ pub struct NiagaraVariableProperty { impl NiagaraVariableProperty { /// Read a `NiagaraVariableProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -83,7 +83,7 @@ impl PropertyDataTrait for NiagaraVariableProperty { } impl PropertyTrait for NiagaraVariableProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, _include_header: bool, @@ -130,7 +130,7 @@ pub struct NiagaraVariableWithOffsetProperty { impl NiagaraVariableWithOffsetProperty { /// Read a `NiagaraVariableWithOffsetProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -178,7 +178,7 @@ impl PropertyDataTrait for NiagaraVariableWithOffsetProperty { } impl PropertyTrait for NiagaraVariableWithOffsetProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, diff --git a/unreal_asset/unreal_asset_properties/src/object_property.rs b/unreal_asset/unreal_asset_properties/src/object_property.rs index f5397f3c..732de674 100644 --- a/unreal_asset/unreal_asset_properties/src/object_property.rs +++ b/unreal_asset/unreal_asset_properties/src/object_property.rs @@ -58,7 +58,9 @@ impl TopLevelAssetPath { } /// Read a `TopLevelAssetPath` from an asset - pub fn read<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn read<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let package_name = match asset.get_object_version_ue5() >= ObjectVersionUE5::FSOFTOBJECTPATH_REMOVE_ASSET_PATH_FNAMES { @@ -74,7 +76,10 @@ impl TopLevelAssetPath { } /// Write a `TopLevelAssetPath` to an asset - pub fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { + pub fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<(), Error> { if asset.get_object_version_ue5() >= ObjectVersionUE5::FSOFTOBJECTPATH_REMOVE_ASSET_PATH_FNAMES { @@ -102,7 +107,9 @@ pub struct SoftObjectPath { impl SoftObjectPath { /// Read a `SoftObjectPath` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let asset_path = TopLevelAssetPath::read(asset)?; let sub_path_string = asset.read_fstring()?; @@ -113,7 +120,10 @@ impl SoftObjectPath { } /// Write a `SoftObjectPath` to an asset - pub fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { + pub fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<(), Error> { self.asset_path.write(asset)?; asset.write_fstring(self.sub_path_string.as_deref())?; @@ -139,7 +149,7 @@ impl_property_data_trait!(SoftObjectProperty); impl ObjectProperty { /// Read an `ObjectProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -159,7 +169,7 @@ impl ObjectProperty { } impl PropertyTrait for ObjectProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, @@ -172,7 +182,7 @@ impl PropertyTrait for ObjectProperty { impl AssetObjectProperty { /// Read an `AssetObjectProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -192,7 +202,7 @@ impl AssetObjectProperty { } impl PropertyTrait for AssetObjectProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, @@ -204,7 +214,7 @@ impl PropertyTrait for AssetObjectProperty { impl SoftObjectProperty { /// Read a `SoftObjectProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -225,7 +235,7 @@ impl SoftObjectProperty { } impl PropertyTrait for SoftObjectProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, diff --git a/unreal_asset/unreal_asset_properties/src/per_platform_property.rs b/unreal_asset/unreal_asset_properties/src/per_platform_property.rs index 6a93f865..615ac35d 100644 --- a/unreal_asset/unreal_asset_properties/src/per_platform_property.rs +++ b/unreal_asset/unreal_asset_properties/src/per_platform_property.rs @@ -52,7 +52,7 @@ impl_property_data_trait!(PerPlatformFloatProperty); impl PerPlatformBoolProperty { /// Read a `PerPlatformBoolProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -80,7 +80,7 @@ impl PerPlatformBoolProperty { } impl PropertyTrait for PerPlatformBoolProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, @@ -96,7 +96,7 @@ impl PropertyTrait for PerPlatformBoolProperty { impl PerPlatformIntProperty { /// Read a `PerPlatformIntProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -124,7 +124,7 @@ impl PerPlatformIntProperty { } impl PropertyTrait for PerPlatformIntProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, @@ -140,7 +140,7 @@ impl PropertyTrait for PerPlatformIntProperty { impl PerPlatformFloatProperty { /// Read a `PerPlatformFloatProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -168,7 +168,7 @@ impl PerPlatformFloatProperty { } impl PropertyTrait for PerPlatformFloatProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, diff --git a/unreal_asset/unreal_asset_properties/src/raw_struct_property.rs b/unreal_asset/unreal_asset_properties/src/raw_struct_property.rs index eb45f27a..7aa89b25 100644 --- a/unreal_asset/unreal_asset_properties/src/raw_struct_property.rs +++ b/unreal_asset/unreal_asset_properties/src/raw_struct_property.rs @@ -20,7 +20,7 @@ impl_property_data_trait!(RawStructProperty); impl RawStructProperty { /// Read a `RawStructProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -44,7 +44,7 @@ impl RawStructProperty { } impl PropertyTrait for RawStructProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, diff --git a/unreal_asset/unreal_asset_properties/src/rich_curve_key_property.rs b/unreal_asset/unreal_asset_properties/src/rich_curve_key_property.rs index acdd6cf6..c54ec1a6 100644 --- a/unreal_asset/unreal_asset_properties/src/rich_curve_key_property.rs +++ b/unreal_asset/unreal_asset_properties/src/rich_curve_key_property.rs @@ -105,7 +105,7 @@ impl_property_data_trait!(RichCurveKeyProperty); impl RichCurveKeyProperty { /// Read a `RichCurveKeyProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -145,7 +145,7 @@ impl RichCurveKeyProperty { } impl PropertyTrait for RichCurveKeyProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, diff --git a/unreal_asset/unreal_asset_properties/src/sampler_property.rs b/unreal_asset/unreal_asset_properties/src/sampler_property.rs index 4044e1c3..d54b6b35 100644 --- a/unreal_asset/unreal_asset_properties/src/sampler_property.rs +++ b/unreal_asset/unreal_asset_properties/src/sampler_property.rs @@ -60,7 +60,7 @@ impl_property_data_trait!(SkeletalMeshSamplingLODBuiltDataProperty); impl WeightedRandomSamplerProperty { /// Read a `WeightedRandomSamplerProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -97,7 +97,7 @@ impl WeightedRandomSamplerProperty { } impl PropertyTrait for WeightedRandomSamplerProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, @@ -124,7 +124,7 @@ impl PropertyTrait for WeightedRandomSamplerProperty { impl SkeletalMeshAreaWeightedTriangleSampler { /// Read a `SkeletalMeshAreaWeightedTriangleSampler` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -161,7 +161,7 @@ impl SkeletalMeshAreaWeightedTriangleSampler { } impl PropertyTrait for SkeletalMeshAreaWeightedTriangleSampler { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, @@ -188,7 +188,7 @@ impl PropertyTrait for SkeletalMeshAreaWeightedTriangleSampler { impl SkeletalMeshSamplingLODBuiltDataProperty { /// Read a `SkeletalMeshSamplingLODBuiltDataProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -217,7 +217,7 @@ impl SkeletalMeshSamplingLODBuiltDataProperty { } impl PropertyTrait for SkeletalMeshSamplingLODBuiltDataProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, diff --git a/unreal_asset/unreal_asset_properties/src/set_property.rs b/unreal_asset/unreal_asset_properties/src/set_property.rs index ec3754fd..3e80fd54 100644 --- a/unreal_asset/unreal_asset_properties/src/set_property.rs +++ b/unreal_asset/unreal_asset_properties/src/set_property.rs @@ -25,7 +25,7 @@ impl_property_data_trait!(SetProperty); impl SetProperty { /// Read a `SetProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -75,7 +75,7 @@ impl SetProperty { } impl PropertyTrait for SetProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, diff --git a/unreal_asset/unreal_asset_properties/src/slate_core/font_data_property.rs b/unreal_asset/unreal_asset_properties/src/slate_core/font_data_property.rs index 71d994b6..a003f221 100644 --- a/unreal_asset/unreal_asset_properties/src/slate_core/font_data_property.rs +++ b/unreal_asset/unreal_asset_properties/src/slate_core/font_data_property.rs @@ -56,7 +56,9 @@ pub struct FontData { impl FontData { /// Read `FontData` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Option<Self>, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Option<Self>, Error> { if asset.get_custom_version::<FEditorObjectVersion>().version < FEditorObjectVersion::AddedFontFaceAssets as i32 { @@ -94,7 +96,10 @@ impl FontData { } /// Write `FontData` to an asset - pub fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { + pub fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<(), Error> { if asset.get_custom_version::<FEditorObjectVersion>().version < FEditorObjectVersion::AddedFontFaceAssets as i32 { @@ -141,7 +146,7 @@ impl_property_data_trait!(FontDataProperty); impl FontDataProperty { /// Read a `FontDataProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -164,7 +169,7 @@ impl FontDataProperty { } impl PropertyTrait for FontDataProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, diff --git a/unreal_asset/unreal_asset_properties/src/smart_name_property.rs b/unreal_asset/unreal_asset_properties/src/smart_name_property.rs index afa0d0c2..7eb56ab8 100644 --- a/unreal_asset/unreal_asset_properties/src/smart_name_property.rs +++ b/unreal_asset/unreal_asset_properties/src/smart_name_property.rs @@ -26,7 +26,7 @@ impl_property_data_trait!(SmartNameProperty); impl SmartNameProperty { /// Read a `SmartNameProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -64,7 +64,7 @@ impl SmartNameProperty { } impl PropertyTrait for SmartNameProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, diff --git a/unreal_asset/unreal_asset_properties/src/soft_path_property.rs b/unreal_asset/unreal_asset_properties/src/soft_path_property.rs index cce70499..aa046f5b 100644 --- a/unreal_asset/unreal_asset_properties/src/soft_path_property.rs +++ b/unreal_asset/unreal_asset_properties/src/soft_path_property.rs @@ -19,7 +19,9 @@ impl Default for SoftObjectPathPropertyValue { impl SoftObjectPathPropertyValue { /// Create a new `SoftObjectPathPropertyValue` instance - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { match asset.get_object_version() < ObjectVersion::VER_UE4_ADDED_SOFT_OBJECT_PATH { true => Ok(Self::Old(asset.read_fstring()?)), false => Ok(Self::New(SoftObjectPath::new(asset)?)), @@ -27,7 +29,10 @@ impl SoftObjectPathPropertyValue { } /// Write `SoftObjectPathPropertyValue` to an asset - pub fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { + pub fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<(), Error> { match self { Self::Old(e) => { asset.write_fstring(e.as_deref())?; @@ -109,7 +114,7 @@ macro_rules! impl_soft_path_property { ($property_name:ident) => { impl $property_name { /// Read `$property_name` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -131,7 +136,7 @@ macro_rules! impl_soft_path_property { } impl PropertyTrait for $property_name { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, diff --git a/unreal_asset/unreal_asset_properties/src/str_property.rs b/unreal_asset/unreal_asset_properties/src/str_property.rs index f130d99a..c8d3e740 100644 --- a/unreal_asset/unreal_asset_properties/src/str_property.rs +++ b/unreal_asset/unreal_asset_properties/src/str_property.rs @@ -110,7 +110,7 @@ impl_property_data_trait!(NameProperty); impl StrProperty { /// Read a `StrProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -130,7 +130,7 @@ impl StrProperty { } impl PropertyTrait for StrProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, @@ -144,7 +144,7 @@ impl PropertyTrait for StrProperty { impl TextProperty { /// Read a `TextProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -223,7 +223,7 @@ impl TextProperty { } impl PropertyTrait for TextProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, @@ -292,7 +292,7 @@ impl PropertyTrait for TextProperty { impl NameProperty { /// Read a `NameProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -312,7 +312,7 @@ impl NameProperty { } impl PropertyTrait for NameProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, diff --git a/unreal_asset/unreal_asset_properties/src/struct_property.rs b/unreal_asset/unreal_asset_properties/src/struct_property.rs index 2da02095..01de9708 100644 --- a/unreal_asset/unreal_asset_properties/src/struct_property.rs +++ b/unreal_asset/unreal_asset_properties/src/struct_property.rs @@ -45,7 +45,7 @@ impl StructProperty { } /// Read a `StructProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -79,7 +79,7 @@ impl StructProperty { /// Read a `StructProperty` with custom header values set #[allow(clippy::too_many_arguments)] - pub fn custom_header<Reader: ArchiveReader>( + pub fn custom_header<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -231,7 +231,7 @@ impl StructProperty { } /// Write a `StructProperty` overriding struct type - pub fn write_with_type<Writer: ArchiveWriter>( + pub fn write_with_type<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, @@ -327,7 +327,7 @@ impl StructProperty { } impl PropertyTrait for StructProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, diff --git a/unreal_asset/unreal_asset_properties/src/unknown_property.rs b/unreal_asset/unreal_asset_properties/src/unknown_property.rs index 9fbcb7e9..ade5731c 100644 --- a/unreal_asset/unreal_asset_properties/src/unknown_property.rs +++ b/unreal_asset/unreal_asset_properties/src/unknown_property.rs @@ -24,7 +24,7 @@ impl_property_data_trait!(UnknownProperty); impl UnknownProperty { /// Read an `UnknownProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -49,7 +49,7 @@ impl UnknownProperty { } impl PropertyTrait for UnknownProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, diff --git a/unreal_asset/unreal_asset_properties/src/vector_property.rs b/unreal_asset/unreal_asset_properties/src/vector_property.rs index 700e4580..54bd8239 100644 --- a/unreal_asset/unreal_asset_properties/src/vector_property.rs +++ b/unreal_asset/unreal_asset_properties/src/vector_property.rs @@ -165,7 +165,7 @@ impl_property_data_trait!(PlaneProperty); impl VectorProperty { /// Read a `VectorProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -197,7 +197,7 @@ impl VectorProperty { } impl PropertyTrait for VectorProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, @@ -223,7 +223,7 @@ impl PropertyTrait for VectorProperty { impl IntPointProperty { /// Read an `IntPointProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -245,7 +245,7 @@ impl IntPointProperty { } impl PropertyTrait for IntPointProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, @@ -259,7 +259,7 @@ impl PropertyTrait for IntPointProperty { impl Vector4Property { /// Read a `Vector4Property` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -296,7 +296,7 @@ impl Vector4Property { } impl PropertyTrait for Vector4Property { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, @@ -324,7 +324,7 @@ impl PropertyTrait for Vector4Property { impl Vector2DProperty { /// Read a `Vector2DProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -358,7 +358,7 @@ impl Vector2DProperty { } impl PropertyTrait for Vector2DProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, @@ -382,7 +382,7 @@ impl PropertyTrait for Vector2DProperty { impl QuatProperty { /// Read a `QuatProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -420,7 +420,7 @@ impl QuatProperty { } impl PropertyTrait for QuatProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, @@ -448,7 +448,7 @@ impl PropertyTrait for QuatProperty { impl RotatorProperty { /// Read a `RotatorProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -484,7 +484,7 @@ impl RotatorProperty { } impl PropertyTrait for RotatorProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, @@ -512,7 +512,7 @@ impl PropertyTrait for RotatorProperty { impl BoxProperty { /// Read a `BoxProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -542,7 +542,7 @@ impl BoxProperty { } impl PropertyTrait for BoxProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, @@ -557,7 +557,7 @@ impl PropertyTrait for BoxProperty { impl Box2DProperty { /// Read a `Box2DProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -580,7 +580,7 @@ impl Box2DProperty { } impl PropertyTrait for Box2DProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, @@ -597,7 +597,7 @@ impl PropertyTrait for Box2DProperty { impl PlaneProperty { /// Read a `PlaneProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -636,7 +636,7 @@ impl PlaneProperty { } impl PropertyTrait for PlaneProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, diff --git a/unreal_asset/unreal_asset_properties/src/view_target_blend_property.rs b/unreal_asset/unreal_asset_properties/src/view_target_blend_property.rs index d912b952..7996a192 100644 --- a/unreal_asset/unreal_asset_properties/src/view_target_blend_property.rs +++ b/unreal_asset/unreal_asset_properties/src/view_target_blend_property.rs @@ -46,7 +46,7 @@ impl_property_data_trait!(ViewTargetBlendParamsProperty); impl ViewTargetBlendParamsProperty { /// Read a `ViewTargetBlendParamsProperty` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, name: FName, ancestry: Ancestry, @@ -75,7 +75,7 @@ impl ViewTargetBlendParamsProperty { } impl PropertyTrait for ViewTargetBlendParamsProperty { - fn write<Writer: ArchiveWriter>( + fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, asset: &mut Writer, include_header: bool, diff --git a/unreal_asset/unreal_asset_properties/src/world_tile_property.rs b/unreal_asset/unreal_asset_properties/src/world_tile_property.rs index 599caac7..76d0d8f4 100644 --- a/unreal_asset/unreal_asset_properties/src/world_tile_property.rs +++ b/unreal_asset/unreal_asset_properties/src/world_tile_property.rs @@ -23,7 +23,9 @@ pub struct FWorldTileLayer { impl FWorldTileLayer { /// Read an `FWorldTileLayer` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let object_version = asset.get_object_version(); let new_ancestry = Ancestry::new(asset.get_parent_class_export_name().unwrap_or_default()); @@ -53,7 +55,10 @@ impl FWorldTileLayer { } /// Write an `FWorldTileLayer` to an asset - pub fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { + pub fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<(), Error> { let object_version = asset.get_object_version(); asset.write_fstring(self.name.as_deref())?; @@ -101,7 +106,9 @@ pub struct FWorldTileLODInfo { impl FWorldTileLODInfo { /// Read `FWorldTileLODInfo` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { Ok(FWorldTileLODInfo { relative_streaming_distance: asset.read_i32::<LE>()?, reserved_0: OrderedFloat(asset.read_f32::<LE>()?), @@ -112,7 +119,10 @@ impl FWorldTileLODInfo { } /// Write `FWorldTileLODInfo` to an asset - pub fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { + pub fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<(), Error> { asset.write_i32::<LE>(self.relative_streaming_distance)?; asset.write_f32::<LE>(self.reserved_0.0)?; asset.write_f32::<LE>(self.reserved_1.0)?; @@ -145,7 +155,9 @@ pub struct FWorldTileInfo { impl FWorldTileInfo { /// Read `FWorldTileInfo` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let version = asset.get_custom_version::<FFortniteMainBranchObjectVersion>(); let object_version = asset.get_object_version(); @@ -198,7 +210,10 @@ impl FWorldTileInfo { } /// Write `FWorldTileInfo` to an asset - pub fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { + pub fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<(), Error> { let object_version = asset.get_object_version(); if asset diff --git a/unreal_asset/unreal_asset_registry/src/lib.rs b/unreal_asset/unreal_asset_registry/src/lib.rs index 04479504..49045d82 100644 --- a/unreal_asset/unreal_asset_registry/src/lib.rs +++ b/unreal_asset/unreal_asset_registry/src/lib.rs @@ -18,6 +18,7 @@ use unreal_asset_base::{ error::RegistryError, object_version::{ObjectVersion, ObjectVersionUE5}, reader::{ArchiveReader, ArchiveTrait, ArchiveWriter, RawWriter}, + types::{PackageIndex, PackageIndexTrait}, Error, }; @@ -60,7 +61,7 @@ pub struct AssetRegistryState { impl AssetRegistryState { /// Read an `AssetRegistryState` from an asset - fn load<Reader: ArchiveReader>( + fn load<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, version: FAssetRegistryVersionType, assets_data: &mut Vec<AssetData>, @@ -110,7 +111,10 @@ impl AssetRegistryState { } /// Write an `AssetRegistryState` to an asset - fn write_data<Writer: ArchiveWriter>(&self, writer: &mut Writer) -> Result<(), Error> { + fn write_data<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + writer: &mut Writer, + ) -> Result<(), Error> { writer.write_i32::<LE>(self.assets_data.len() as i32)?; for asset_data in &self.assets_data { asset_data.write(writer)?; @@ -184,7 +188,7 @@ impl AssetRegistryState { /// /// println!("{:#?}", asset_registry); /// ``` - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<PackageIndex>>(asset: &mut Reader) -> Result<Self, Error> { let version = FAssetRegistryVersionType::new(asset)?; let mut assets_data = Vec::new(); let mut depends_nodes = Vec::new(); diff --git a/unreal_asset/unreal_asset_registry/src/name_table_reader.rs b/unreal_asset/unreal_asset_registry/src/name_table_reader.rs index bff886a4..21929f4a 100644 --- a/unreal_asset/unreal_asset_registry/src/name_table_reader.rs +++ b/unreal_asset/unreal_asset_registry/src/name_table_reader.rs @@ -8,22 +8,23 @@ use unreal_asset_base::{ custom_version::{CustomVersion, CustomVersionTrait}, engine_version::EngineVersion, object_version::{ObjectVersion, ObjectVersionUE5}, - reader::{ArchiveReader, ArchiveTrait, ArchiveType, PassthroughArchiveReader}, + passthrough_archive_reader, + reader::{ArchiveReader, ArchiveTrait, ArchiveType}, types::{FName, PackageIndex}, unversioned::Usmap, - Error, Import, + Error, }; /// Used for reading NameTable entries by modifying the behavior /// of some of the value read methods. -pub struct NameTableReader<'reader, Reader: ArchiveReader> { +pub struct NameTableReader<'reader, Reader: ArchiveReader<PackageIndex>> { /// Reader reader: &'reader mut Reader, /// Name map pub(crate) name_map: SharedResource<NameMap>, } -impl<'reader, Reader: ArchiveReader> NameTableReader<'reader, Reader> { +impl<'reader, Reader: ArchiveReader<PackageIndex>> NameTableReader<'reader, Reader> { /// Create a new `NameTableReader` from another `Reader` pub(crate) fn new(reader: &'reader mut Reader) -> Result<Self, Error> { let name_offset = reader.read_i64::<LE>()?; @@ -57,7 +58,9 @@ impl<'reader, Reader: ArchiveReader> NameTableReader<'reader, Reader> { } } -impl<'reader, Reader: ArchiveReader> ArchiveTrait for NameTableReader<'reader, Reader> { +impl<'reader, Reader: ArchiveReader<PackageIndex>> ArchiveTrait<PackageIndex> + for NameTableReader<'reader, Reader> +{ #[inline(always)] fn get_archive_type(&self) -> ArchiveType { self.reader.get_archive_type() @@ -122,27 +125,28 @@ impl<'reader, Reader: ArchiveReader> ArchiveTrait for NameTableReader<'reader, R self.reader.get_parent_class_export_name() } - fn get_import(&self, index: PackageIndex) -> Option<Import> { - self.reader.get_import(index) + fn get_object_name(&self, index: PackageIndex) -> Option<FName> { + self.reader.get_object_name(index) } -} - -impl<'reader, Reader: ArchiveReader> PassthroughArchiveReader for NameTableReader<'reader, Reader> { - type Passthrough = Reader; - #[inline(always)] - fn get_passthrough(&mut self) -> &mut Self::Passthrough { - self.reader + fn get_object_name_packageindex(&self, index: PackageIndex) -> Option<FName> { + self.reader.get_object_name_packageindex(index) } } -impl<'reader, Reader: ArchiveReader> Read for NameTableReader<'reader, Reader> { +impl<'reader, Reader: ArchiveReader<PackageIndex>> ArchiveReader<PackageIndex> + for NameTableReader<'reader, Reader> +{ + passthrough_archive_reader!(reader); +} + +impl<'reader, Reader: ArchiveReader<PackageIndex>> Read for NameTableReader<'reader, Reader> { fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { self.reader.read(buf) } } -impl<'reader, Reader: ArchiveReader> Seek for NameTableReader<'reader, Reader> { +impl<'reader, Reader: ArchiveReader<PackageIndex>> Seek for NameTableReader<'reader, Reader> { fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> { self.reader.seek(pos) } diff --git a/unreal_asset/unreal_asset_registry/src/name_table_writer.rs b/unreal_asset/unreal_asset_registry/src/name_table_writer.rs index b565be9f..7ffe4afe 100644 --- a/unreal_asset/unreal_asset_registry/src/name_table_writer.rs +++ b/unreal_asset/unreal_asset_registry/src/name_table_writer.rs @@ -6,29 +6,32 @@ use unreal_asset_base::{ custom_version::{CustomVersion, CustomVersionTrait}, engine_version::EngineVersion, object_version::{ObjectVersion, ObjectVersionUE5}, - reader::{ArchiveTrait, ArchiveType, ArchiveWriter, PassthroughArchiveWriter}, + passthrough_archive_writer, + reader::{ArchiveTrait, ArchiveType, ArchiveWriter}, types::{FName, PackageIndex}, unversioned::Usmap, - Import, + Error, }; /// Used to write NameTable entries by modifying the behavior /// of some of the value write methods. -pub struct NameTableWriter<'writer, Writer: ArchiveWriter> { +pub struct NameTableWriter<'writer, Writer: ArchiveWriter<PackageIndex>> { /// Writer writer: &'writer mut Writer, /// Name map name_map: SharedResource<NameMap>, } -impl<'writer, Writer: ArchiveWriter> NameTableWriter<'writer, Writer> { +impl<'writer, Writer: ArchiveWriter<PackageIndex>> NameTableWriter<'writer, Writer> { /// Create a new `NameTableWriter` instance from another `Writer` and a name map pub fn new(writer: &'writer mut Writer, name_map: SharedResource<NameMap>) -> Self { NameTableWriter { writer, name_map } } } -impl<'writer, Writer: ArchiveWriter> ArchiveTrait for NameTableWriter<'writer, Writer> { +impl<'writer, Writer: ArchiveWriter<PackageIndex>> ArchiveTrait<PackageIndex> + for NameTableWriter<'writer, Writer> +{ #[inline(always)] fn get_archive_type(&self) -> ArchiveType { self.writer.get_archive_type() @@ -93,19 +96,22 @@ impl<'writer, Writer: ArchiveWriter> ArchiveTrait for NameTableWriter<'writer, W self.writer.get_parent_class_export_name() } - fn get_import(&self, index: PackageIndex) -> Option<Import> { - self.writer.get_import(index) + fn get_object_name(&self, index: PackageIndex) -> Option<FName> { + self.writer.get_object_name(index) } -} -impl<'writer, Writer: ArchiveWriter> PassthroughArchiveWriter for NameTableWriter<'writer, Writer> { - type Passthrough = Writer; - fn get_passthrough(&mut self) -> &mut Self::Passthrough { - self.writer + fn get_object_name_packageindex(&self, index: PackageIndex) -> Option<FName> { + self.writer.get_object_name_packageindex(index) } } -impl<'writer, Writer: ArchiveWriter> Write for NameTableWriter<'writer, Writer> { +impl<'writer, Writer: ArchiveWriter<PackageIndex>> ArchiveWriter<PackageIndex> + for NameTableWriter<'writer, Writer> +{ + passthrough_archive_writer!(writer); +} + +impl<'writer, Writer: ArchiveWriter<PackageIndex>> Write for NameTableWriter<'writer, Writer> { fn write(&mut self, buf: &[u8]) -> io::Result<usize> { self.writer.write(buf) } @@ -115,7 +121,7 @@ impl<'writer, Writer: ArchiveWriter> Write for NameTableWriter<'writer, Writer> } } -impl<'writer, Writer: ArchiveWriter> Seek for NameTableWriter<'writer, Writer> { +impl<'writer, Writer: ArchiveWriter<PackageIndex>> Seek for NameTableWriter<'writer, Writer> { fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> { self.writer.seek(pos) } diff --git a/unreal_asset/unreal_asset_registry/src/objects/asset_bundle_data.rs b/unreal_asset/unreal_asset_registry/src/objects/asset_bundle_data.rs index 7b87d7b7..fd9f61f7 100644 --- a/unreal_asset/unreal_asset_registry/src/objects/asset_bundle_data.rs +++ b/unreal_asset/unreal_asset_registry/src/objects/asset_bundle_data.rs @@ -4,7 +4,7 @@ use byteorder::{WriteBytesExt, LE}; use unreal_asset_base::{ reader::{ArchiveReader, ArchiveWriter}, - types::FName, + types::{FName, PackageIndexTrait}, unversioned::Ancestry, Error, }; @@ -21,10 +21,9 @@ pub struct AssetBundleEntry { impl AssetBundleEntry { /// Read an `AssetBundleEntry` from an asset - pub fn new<Reader>(asset: &mut Reader) -> Result<Self, Error> - where - Reader: ArchiveReader, - { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let bundle_name = asset.read_fname()?; let bundle_assets = asset.read_array(|asset: &mut Reader| { SoftObjectPathProperty::new( @@ -52,7 +51,10 @@ impl AssetBundleEntry { } /// Write an `AssetBundleEntry` to an asset - pub fn write<Writer: ArchiveWriter>(&self, writer: &mut Writer) -> Result<(), Error> { + pub fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + writer: &mut Writer, + ) -> Result<(), Error> { writer.write_fname(&self.bundle_name)?; writer.write_i32::<LE>(self.bundle_assets.len() as i32)?; @@ -74,14 +76,19 @@ pub struct AssetBundleData { impl AssetBundleData { /// Read `AssetBundleData` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let bundles = asset.read_array(|asset: &mut Reader| AssetBundleEntry::new(asset))?; Ok(Self { bundles }) } /// Write `AssetBundleData` to an asset - pub fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { + pub fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<(), Error> { asset.write_i32::<LE>(self.bundles.len() as i32)?; for bundle in &self.bundles { diff --git a/unreal_asset/unreal_asset_registry/src/objects/asset_data.rs b/unreal_asset/unreal_asset_registry/src/objects/asset_data.rs index 578b4961..79662ede 100644 --- a/unreal_asset/unreal_asset_registry/src/objects/asset_data.rs +++ b/unreal_asset/unreal_asset_registry/src/objects/asset_data.rs @@ -7,7 +7,7 @@ use unreal_asset_base::{ custom_version::FAssetRegistryVersionType, flags::EPackageFlags, reader::{ArchiveReader, ArchiveWriter}, - types::FName, + types::{FName, PackageIndexTrait}, Error, }; @@ -24,7 +24,9 @@ pub struct TopLevelAssetPath { impl TopLevelAssetPath { /// Read a `TopLevelAssetPath` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let package_name = asset.read_fname()?; let asset_name = asset.read_fname()?; @@ -35,7 +37,10 @@ impl TopLevelAssetPath { } /// Write a `TopLevelAssetPath` to an asset - pub fn write<Writer: ArchiveWriter>(&self, writer: &mut Writer) -> Result<(), Error> { + pub fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + writer: &mut Writer, + ) -> Result<(), Error> { writer.write_fname(&self.package_name)?; writer.write_fname(&self.asset_name)?; Ok(()) @@ -74,7 +79,7 @@ pub struct AssetData { impl AssetData { /// Read `AssetData` tags - fn read_tags<Reader: ArchiveReader>( + fn read_tags<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, ) -> Result<IndexedMap<FName, Option<String>>, Error> { let size = asset.read_i32::<LE>()?; @@ -87,7 +92,7 @@ impl AssetData { } /// Write `AssetData` tags - fn write_tags<Writer: ArchiveWriter>( + fn write_tags<Writer: ArchiveWriter<impl PackageIndexTrait>>( asset: &mut Writer, tags_and_values: &IndexedMap<FName, Option<String>>, ) -> Result<(), Error> { @@ -100,7 +105,7 @@ impl AssetData { } /// Read `AssetData` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, version: FAssetRegistryVersionType, ) -> Result<Self, Error> { @@ -168,7 +173,10 @@ impl AssetData { } /// Write `AssetData` to an asset - pub fn write<Writer: ArchiveWriter>(&self, writer: &mut Writer) -> Result<(), Error> { + pub fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + writer: &mut Writer, + ) -> Result<(), Error> { writer.write_fname(&self.object_path)?; writer.write_fname(&self.package_path)?; diff --git a/unreal_asset/unreal_asset_registry/src/objects/asset_package_data.rs b/unreal_asset/unreal_asset_registry/src/objects/asset_package_data.rs index a6460cf5..ecce2b5d 100644 --- a/unreal_asset/unreal_asset_registry/src/objects/asset_package_data.rs +++ b/unreal_asset/unreal_asset_registry/src/objects/asset_package_data.rs @@ -4,6 +4,7 @@ use byteorder::{ReadBytesExt, WriteBytesExt, LE}; use unreal_asset_base::Guid; +use unreal_asset_base::types::PackageIndexTrait; use unreal_asset_base::{ custom_version::{CustomVersion, FAssetRegistryVersionType}, error::RegistryError, @@ -44,7 +45,7 @@ pub struct AssetPackageData { impl AssetPackageData { /// Read `AssetPackageData` from an asset - pub fn new<Reader: ArchiveReader>( + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, version: FAssetRegistryVersionType, ) -> Result<Self, Error> { @@ -99,7 +100,10 @@ impl AssetPackageData { } /// Write `AssetPackageData` to an asset - pub fn write<Writer: ArchiveWriter>(&self, asset: &mut Writer) -> Result<(), Error> { + pub fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + asset: &mut Writer, + ) -> Result<(), Error> { asset.write_fname(&self.package_name)?; asset.write_i64::<LE>(self.disk_size)?; // TODO change to guid method diff --git a/unreal_asset/unreal_asset_registry/src/objects/depends_node.rs b/unreal_asset/unreal_asset_registry/src/objects/depends_node.rs index 232a4246..50328646 100644 --- a/unreal_asset/unreal_asset_registry/src/objects/depends_node.rs +++ b/unreal_asset/unreal_asset_registry/src/objects/depends_node.rs @@ -11,7 +11,7 @@ use unreal_asset_base::{ error::RegistryError, flags::EDependencyProperty, reader::{ArchiveReader, ArchiveWriter}, - types::FName, + types::{FName, PackageIndexTrait}, Error, }; @@ -32,7 +32,9 @@ type LoadedDependencyNodes = (Vec<DependsNode>, Vec<DependsNode>, BitVec<u32, Ls impl AssetIdentifier { /// Read an `AssetIdentifier` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let field_bits = asset.read_u8()?; let package_name = match (field_bits & (1 << 0)) != 0 { true => Some(asset.read_fname()?), @@ -63,7 +65,10 @@ impl AssetIdentifier { } /// Write an `AssetIdentifier` to an asset - pub fn write<Writer: ArchiveWriter>(&self, writer: &mut Writer) -> Result<(), Error> { + pub fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + writer: &mut Writer, + ) -> Result<(), Error> { #[allow(clippy::identity_op)] let field_bits = (self.package_name.is_some() as u8) << 0u8 | (self.primary_asset_type.is_some() as u8) << 1u8 @@ -152,7 +157,7 @@ impl DependsNode { } /// Read `DependsNode` dependencies - fn read_dependencies<Reader: ArchiveReader>( + fn read_dependencies<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, preallocated_depends_node_buffer: &Vec<DependsNode>, flag_set_width: i32, @@ -235,7 +240,7 @@ impl DependsNode { } /// Write `DependsNode` dependencies - fn write_dependencies<Writer: ArchiveWriter>( + fn write_dependencies<Writer: ArchiveWriter<impl PackageIndexTrait>>( writer: &mut Writer, flag_set_width: i32, flags: &BitVec<u32, Lsb0>, @@ -294,7 +299,7 @@ impl DependsNode { } /// Read `DependsNode` dependencies without flags - fn read_dependencies_no_flags<Reader: ArchiveReader>( + fn read_dependencies_no_flags<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, preallocated_depends_node_buffer: &Vec<DependsNode>, ) -> Result<Vec<DependsNode>, Error> { @@ -334,7 +339,7 @@ impl DependsNode { } /// Write `DependsNode` dependencies without flags - fn write_dependencies_no_flags<Writer: ArchiveWriter>( + fn write_dependencies_no_flags<Writer: ArchiveWriter<impl PackageIndexTrait>>( writer: &mut Writer, dependencies: &Vec<DependsNode>, ) -> Result<(), Error> { @@ -363,7 +368,7 @@ impl DependsNode { } /// Load `DependsNode` dependencies - pub fn load_dependencies<Reader: ArchiveReader>( + pub fn load_dependencies<Reader: ArchiveReader<impl PackageIndexTrait>>( &mut self, asset: &mut Reader, preallocated_depends_node_buffer: &Vec<DependsNode>, @@ -407,7 +412,7 @@ impl DependsNode { } /// Save `DependsNode` dependencies - pub fn save_dependencies<Writer: ArchiveWriter>( + pub fn save_dependencies<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, writer: &mut Writer, ) -> Result<(), Error> { @@ -447,7 +452,7 @@ impl DependsNode { } /// Read `DependsNode` array - fn read_node_array<Reader: ArchiveReader>( + fn read_node_array<Reader: ArchiveReader<impl PackageIndexTrait>>( asset: &mut Reader, preallocated_depends_node_buffer: &[DependsNode], num: i32, @@ -467,7 +472,7 @@ impl DependsNode { } /// Load `DependsNode` dependencies before flags - pub fn load_dependencies_before_flags<Reader: ArchiveReader>( + pub fn load_dependencies_before_flags<Reader: ArchiveReader<impl PackageIndexTrait>>( &mut self, asset: &mut Reader, preallocated_depends_node_buffer: &[DependsNode], @@ -534,7 +539,7 @@ impl DependsNode { } /// Save `DependsNode` dependencies before flags - pub fn save_dependencies_before_flags<Writer: ArchiveWriter>( + pub fn save_dependencies_before_flags<Writer: ArchiveWriter<impl PackageIndexTrait>>( &self, writer: &mut Writer, ) -> Result<(), Error> { diff --git a/unreal_asset/unreal_asset_registry/src/objects/md5_hash.rs b/unreal_asset/unreal_asset_registry/src/objects/md5_hash.rs index f017957e..1c6005b9 100644 --- a/unreal_asset/unreal_asset_registry/src/objects/md5_hash.rs +++ b/unreal_asset/unreal_asset_registry/src/objects/md5_hash.rs @@ -4,6 +4,7 @@ use byteorder::{ReadBytesExt, WriteBytesExt, LE}; use unreal_asset_base::{ reader::{ArchiveReader, ArchiveWriter}, + types::PackageIndexTrait, Error, }; @@ -16,7 +17,9 @@ pub struct FMD5Hash { impl FMD5Hash { /// Read a `FMD5Hash` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let mut hash = None; let has_hash = asset.read_u32::<LE>()?; @@ -30,7 +33,10 @@ impl FMD5Hash { } /// Write a `FMD5Hash` to an asset - pub fn write<Writer: ArchiveWriter>(&self, writer: &mut Writer) -> Result<(), Error> { + pub fn write<Writer: ArchiveWriter<impl PackageIndexTrait>>( + &self, + writer: &mut Writer, + ) -> Result<(), Error> { if let Some(hash) = &self.hash { writer.write_u32::<LE>(1)?; writer.write_all(hash)?; diff --git a/unreal_asset/unreal_asset_registry/src/objects/store.rs b/unreal_asset/unreal_asset_registry/src/objects/store.rs index d9c08051..d55ecd91 100644 --- a/unreal_asset/unreal_asset_registry/src/objects/store.rs +++ b/unreal_asset/unreal_asset_registry/src/objects/store.rs @@ -5,7 +5,11 @@ use std::io::SeekFrom; use byteorder::{ReadBytesExt, LE}; use num_enum::{IntoPrimitive, TryFromPrimitive}; -use unreal_asset_base::{reader::ArchiveReader, types::FName, Error}; +use unreal_asset_base::{ + reader::ArchiveReader, + types::{FName, PackageIndexTrait}, + Error, +}; /// Value type #[repr(u32)] @@ -40,7 +44,9 @@ const INDEX_BITS: u32 = 32 - TYPE_BITS; impl ValueId { /// Read a `ValueId` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let id = asset.read_u32::<LE>()?; let value_type = EValueType::try_from((id << INDEX_BITS) >> INDEX_BITS)?; let index = id as i32 >> TYPE_BITS; @@ -59,7 +65,9 @@ pub struct NumberedPair { impl NumberedPair { /// Read a `NumberedPair` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let key = asset.read_fname()?; let value = ValueId::new(asset)?; @@ -77,7 +85,9 @@ pub struct NumberlessPair { impl NumberlessPair { /// Read a `NumberlessPair` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let key = asset.read_u32::<LE>()?; let value = ValueId::new(asset)?; @@ -97,7 +107,9 @@ pub struct NumberlessExportPath { impl NumberlessExportPath { /// Read a `NumberlessExportPath` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let class = asset.read_u32::<LE>()?; let object = asset.read_u32::<LE>()?; let package = asset.read_u32::<LE>()?; @@ -122,7 +134,9 @@ pub struct AssetRegistryExportPath { impl AssetRegistryExportPath { /// Read an `AssetRegistryExportPath` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let class = asset.read_fname()?; let object = asset.read_fname()?; let package = asset.read_fname()?; @@ -180,7 +194,9 @@ impl Store { } /// Read a `Store` from an asset - pub fn new<Reader: ArchiveReader>(asset: &mut Reader) -> Result<Self, Error> { + pub fn new<Reader: ArchiveReader<impl PackageIndexTrait>>( + asset: &mut Reader, + ) -> Result<Self, Error> { let magic = asset.read_u32::<LE>()?; let order = Store::get_load_order(magic)?; diff --git a/unreal_helpers/src/read_ext.rs b/unreal_helpers/src/read_ext.rs index b30c23ac..dd552002 100644 --- a/unreal_helpers/src/read_ext.rs +++ b/unreal_helpers/src/read_ext.rs @@ -75,22 +75,13 @@ pub fn read_fstring_len<R: Read + Seek>( len: i32, is_wide: bool, ) -> Result<Option<String>, FStringError> { - if !(-131072..=131072).contains(&len) { - return Err(FStringError::InvalidStringSize( - len, - reader.stream_position()?, - )); - } - if len == 0 { return Ok(None); } - if is_wide { - let len = len * size_of::<u16>() as i32 - 2; - let mut buf = vec![0u8; len as usize]; - reader.read_exact(&mut buf)?; + let result = read_fstring_len_noterm(reader, len.saturating_sub(1), is_wide)?; + if is_wide { let terminator = reader.read_u16::<LE>()?; if terminator != 0 { return Err(FStringError::InvalidStringTerminator( @@ -98,6 +89,37 @@ pub fn read_fstring_len<R: Read + Seek>( reader.stream_position()?, )); } + } else { + let terminator = reader.read_u8()?; + if terminator != 0 { + return Err(FStringError::InvalidStringTerminator( + terminator as u16, + reader.stream_position()?, + )); + } + } + + Ok(result) +} + +/// Read string of format \<string\> when length and encoding is already known. +#[inline(always)] +pub fn read_fstring_len_noterm<R: Read + Seek>( + reader: &mut R, + len: i32, + is_wide: bool, +) -> Result<Option<String>, FStringError> { + if !(-131072..=131072).contains(&len) { + return Err(FStringError::InvalidStringSize( + len, + reader.stream_position()?, + )); + } + + if is_wide { + let len = len * size_of::<u16>() as i32; + let mut buf = vec![0u8; len as usize]; + reader.read_exact(&mut buf)?; String::from_utf16( &buf.chunks(2) @@ -107,17 +129,9 @@ pub fn read_fstring_len<R: Read + Seek>( .map(Some) .map_err(|e| e.into()) } else { - let mut buf = vec![0u8; len as usize - 1]; + let mut buf = vec![0u8; len as usize]; reader.read_exact(&mut buf)?; - let terminator = reader.read_u8()?; - if terminator != 0 { - return Err(FStringError::InvalidStringTerminator( - terminator as u16, - reader.stream_position()?, - )); - } - String::from_utf8(buf).map(Some).map_err(|e| e.into()) } } diff --git a/unreal_mod_integrator/src/handlers/ue4_23/persistent_actors.rs b/unreal_mod_integrator/src/handlers/ue4_23/persistent_actors.rs index d02fc2c5..357daf83 100644 --- a/unreal_mod_integrator/src/handlers/ue4_23/persistent_actors.rs +++ b/unreal_mod_integrator/src/handlers/ue4_23/persistent_actors.rs @@ -4,7 +4,6 @@ use std::io::{self, BufReader, Cursor, ErrorKind}; use std::path::Path; use unreal_asset::engine_version::EngineVersion; -use unreal_asset::reader::ArchiveTrait; use unreal_asset::unversioned::Ancestry; use unreal_asset::Guid; use unreal_asset::{ @@ -14,7 +13,7 @@ use unreal_asset::{ array_property::ArrayProperty, enum_property::EnumProperty, int_property::BoolProperty, object_property::ObjectProperty, Property, PropertyDataTrait, }, - types::PackageIndex, + types::{PackageIndex, PackageIndexTrait}, Asset, Import, }; use unreal_pak::{PakMemory, PakReader}; @@ -175,7 +174,7 @@ pub fn handle_persistent_actors( let mut created_components = Vec::new(); if let Some(scs_location) = scs_location { let mut known_node_categories = Vec::new(); - let scs_export: &NormalExport = actor_asset.asset_data.exports[scs_location] + let scs_export: &NormalExport<_> = actor_asset.asset_data.exports[scs_location] .get_normal_export() .expect("Corrupted memory"); for i in 0..scs_export.properties.len() { @@ -203,7 +202,7 @@ pub fn handle_persistent_actors( let mut known_parents = HashMap::new(); for known_node_category in known_node_categories { - let known_category: &NormalExport = actor_asset.asset_data.exports + let known_category: &NormalExport<_> = actor_asset.asset_data.exports [known_node_category as usize - 1] .get_normal_export() .ok_or_else(|| io::Error::new(ErrorKind::Other, "Invalid export"))?; @@ -423,7 +422,7 @@ pub fn handle_persistent_actors( } for (export_index, correction_queue) in attach_parent_correcting { - let export: &mut NormalExport = asset.asset_data.exports[export_index] + let export: &mut NormalExport<_> = asset.asset_data.exports[export_index] .get_normal_export_mut() .expect("Corrupted memory"); for correction in correction_queue { diff --git a/unreal_mod_integrator/src/helpers.rs b/unreal_mod_integrator/src/helpers.rs index 98891388..ab8f1dbd 100644 --- a/unreal_mod_integrator/src/helpers.rs +++ b/unreal_mod_integrator/src/helpers.rs @@ -8,7 +8,7 @@ use unreal_pak::{PakMemory, PakReader}; use crate::{error::IntegrationError, Error}; pub fn get_asset( - integrated_pak: &mut PakMemory, + integrated_pak: &PakMemory, game_paks: &mut [PakReader<BufReader<File>>], mod_paks: &mut [PakReader<BufReader<File>>], name: &String, @@ -62,7 +62,7 @@ pub fn get_asset( ) } -pub fn find_asset(paks: &mut [PakReader<BufReader<File>>], name: &String) -> Option<usize> { +pub fn find_asset(paks: &[PakReader<BufReader<File>>], name: &String) -> Option<usize> { for (i, pak) in paks.iter().enumerate() { if pak.contains_entry(name) { return Some(i); diff --git a/unreal_mod_manager/src/background_work.rs b/unreal_mod_manager/src/background_work.rs index ada93182..bbc3fd55 100644 --- a/unreal_mod_manager/src/background_work.rs +++ b/unreal_mod_manager/src/background_work.rs @@ -638,7 +638,7 @@ where *background_thread_data.last_integration_time.lock() = Instant::now(); // update config file - write_config(&mut background_thread_data.data.lock()); + write_config(&background_thread_data.data.lock()); Ok(warnings) }; @@ -710,7 +710,7 @@ where } BackgroundThreadMessage::WriteConfig => { // update config file - write_config(&mut background_thread_data.data.lock()); + write_config(&background_thread_data.data.lock()); } BackgroundThreadMessage::Exit => { break; diff --git a/unreal_mod_manager/src/mod_config.rs b/unreal_mod_manager/src/mod_config.rs index 9f36ed80..bb42aad3 100644 --- a/unreal_mod_manager/src/mod_config.rs +++ b/unreal_mod_manager/src/mod_config.rs @@ -115,7 +115,7 @@ pub(crate) fn load_config(data: &mut ModLoaderAppData) { debug!("Loaded config"); } -pub(crate) fn write_config(data: &mut ModLoaderAppData) { +pub(crate) fn write_config(data: &ModLoaderAppData) { let config_path = data.mods_path.as_ref().unwrap().join("modconfig.json"); let mut config = ModConfig { selected_game_platform: data.selected_game_platform.clone(), diff --git a/unreal_mod_manager/src/mod_processing/index_file.rs b/unreal_mod_manager/src/mod_processing/index_file.rs index c6547a60..bc049a9c 100644 --- a/unreal_mod_manager/src/mod_processing/index_file.rs +++ b/unreal_mod_manager/src/mod_processing/index_file.rs @@ -84,7 +84,7 @@ impl IndexFileModVersion { } pub(crate) fn gather_index_files( - data: &mut ModLoaderAppData, + data: &ModLoaderAppData, filter: &[String], ) -> HashMap<String, DownloadInfo> { //let mut index_files: HashMap<String, DownloadInfo> = HashMap::new(); diff --git a/unreal_mod_manager/src/mod_processing/mod.rs b/unreal_mod_manager/src/mod_processing/mod.rs index 7032976c..355fcdb2 100644 --- a/unreal_mod_manager/src/mod_processing/mod.rs +++ b/unreal_mod_manager/src/mod_processing/mod.rs @@ -45,7 +45,7 @@ pub(crate) fn process_modfiles( // fetch index files // gather index files from all the mods - let index_files_info = gather_index_files(&mut data_guard, &filter); + let index_files_info = gather_index_files(&data_guard, &filter); // drop guard to allow UI to render while index files are being downloaded drop(data_guard);