pub struct AnimPack { /* private fields */ }Expand description
Represents an AnimPack file decoded in memory.
AnimPacks are container files that bundle animation-related assets into a single archive. This struct holds the complete AnimPack structure including metadata and all contained files.
§Fields
disk_file_path: Path to the AnimPack file on disk (empty if in-memory only)disk_file_offset: Byte offset within the disk file (0 if standalone file)local_timestamp: Last modified timestamp for change detectionpaths: Lowercase path lookup cache for case-insensitive file searchesfiles: Map of file paths to theirRFiledata
§Binary Format
§File Structure
§Container Implementation
AnimPack implements the Container trait, providing:
- File extraction and insertion
- Case-insensitive path lookup via paths cache
- Lazy loading support (when unencrypted)
- Timestamp-based change detection
§Lazy Loading
When lazy_load is enabled in DecodeableExtraData, file data is not read
immediately but loaded on-demand. This reduces memory usage for large AnimPacks.
Lazy loading requires:
- Valid
disk_file_pathto a file on disk - Unencrypted data (encrypted files are always fully loaded)
§Example
use rpfm_lib::files::animpack::AnimPack;
use rpfm_lib::files::Container;
// Create a new empty AnimPack
let mut animpack = AnimPack::default();
// Add a file
animpack.insert(rfile, "battle/animations/unit.bin")?;
// Look up a file (case-insensitive)
if let Some(file) = animpack.file_by_path("BATTLE/animations/UNIT.bin") {
println!("Found file!");
}Trait Implementations§
Source§impl Container for AnimPack
impl Container for AnimPack
Source§fn disk_file_path(&self) -> &str
fn disk_file_path(&self) -> &str
Source§fn files(&self) -> &HashMap<String, RFile>
fn files(&self) -> &HashMap<String, RFile>
Source§fn files_mut(&mut self) -> &mut HashMap<String, RFile>
fn files_mut(&mut self) -> &mut HashMap<String, RFile>
Source§fn disk_file_offset(&self) -> u64
fn disk_file_offset(&self) -> u64
Source§fn paths_cache(&self) -> &HashMap<String, Vec<String>>
fn paths_cache(&self) -> &HashMap<String, Vec<String>>
Source§fn paths_cache_mut(&mut self) -> &mut HashMap<String, Vec<String>>
fn paths_cache_mut(&mut self) -> &mut HashMap<String, Vec<String>>
Source§fn local_timestamp(&self) -> u64
fn local_timestamp(&self) -> u64
Last modified date the filesystem reports for the container file, in seconds. Read moreSource§fn extract(
&mut self,
container_path: ContainerPath,
destination_path: &Path,
keep_container_path_structure: bool,
schema: &Option<Schema>,
case_insensitive: bool,
keys_first: bool,
extra_data: &Option<EncodeableExtraData<'_>>,
keep_data_in_memory: bool,
) -> Result<Vec<PathBuf>>
fn extract( &mut self, container_path: ContainerPath, destination_path: &Path, keep_container_path_structure: bool, schema: &Option<Schema>, case_insensitive: bool, keys_first: bool, extra_data: &Option<EncodeableExtraData<'_>>, keep_data_in_memory: bool, ) -> Result<Vec<PathBuf>>
Source§fn extract_metadata(&mut self, _destination_path: &Path) -> Result<Vec<PathBuf>>
fn extract_metadata(&mut self, _destination_path: &Path) -> Result<Vec<PathBuf>>
.json files. Read moreSource§fn insert_file(
&mut self,
source_path: &Path,
container_path_folder: &str,
schema: &Option<Schema>,
) -> Result<Option<ContainerPath>>
fn insert_file( &mut self, source_path: &Path, container_path_folder: &str, schema: &Option<Schema>, ) -> Result<Option<ContainerPath>>
Source§fn insert_folder(
&mut self,
source_path: &Path,
container_path_folder: &str,
ignored_paths: &Option<Vec<&str>>,
schema: &Option<Schema>,
include_base_folder: bool,
) -> Result<Vec<ContainerPath>>
fn insert_folder( &mut self, source_path: &Path, container_path_folder: &str, ignored_paths: &Option<Vec<&str>>, schema: &Option<Schema>, include_base_folder: bool, ) -> Result<Vec<ContainerPath>>
Source§fn remove(&mut self, path: &ContainerPath) -> Vec<ContainerPath>
fn remove(&mut self, path: &ContainerPath) -> Vec<ContainerPath>
ContainerPath from the container. Read moreSource§fn disk_file_name(&self) -> String
fn disk_file_name(&self) -> String
Source§fn has_file(&self, path: &str) -> bool
fn has_file(&self, path: &str) -> bool
Source§fn has_folder(&self, path: &str) -> bool
fn has_folder(&self, path: &str) -> bool
Source§fn files_by_type(&self, file_types: &[FileType]) -> Vec<&RFile>
fn files_by_type(&self, file_types: &[FileType]) -> Vec<&RFile>
Source§fn files_by_type_mut(&mut self, file_types: &[FileType]) -> Vec<&mut RFile>
fn files_by_type_mut(&mut self, file_types: &[FileType]) -> Vec<&mut RFile>
Source§fn files_by_path(
&self,
path: &ContainerPath,
case_insensitive: bool,
) -> Vec<&RFile>
fn files_by_path( &self, path: &ContainerPath, case_insensitive: bool, ) -> Vec<&RFile>
ContainerPath. Read moreSource§fn files_by_path_mut(
&mut self,
path: &ContainerPath,
case_insensitive: bool,
) -> Vec<&mut RFile>
fn files_by_path_mut( &mut self, path: &ContainerPath, case_insensitive: bool, ) -> Vec<&mut RFile>
ContainerPath. Read moreSource§fn files_by_paths(
&self,
paths: &[ContainerPath],
case_insensitive: bool,
) -> Vec<&RFile>
fn files_by_paths( &self, paths: &[ContainerPath], case_insensitive: bool, ) -> Vec<&RFile>
ContainerPaths. Read moreSource§fn files_by_paths_mut(
&mut self,
paths: &[ContainerPath],
case_insensitive: bool,
) -> Vec<&mut RFile>
fn files_by_paths_mut( &mut self, paths: &[ContainerPath], case_insensitive: bool, ) -> Vec<&mut RFile>
ContainerPaths. Read moreSource§fn files_by_type_and_paths(
&self,
file_types: &[FileType],
paths: &[ContainerPath],
case_insensitive: bool,
) -> Vec<&RFile>
fn files_by_type_and_paths( &self, file_types: &[FileType], paths: &[ContainerPath], case_insensitive: bool, ) -> Vec<&RFile>
Source§fn files_by_type_and_paths_mut(
&mut self,
file_types: &[FileType],
paths: &[ContainerPath],
case_insensitive: bool,
) -> Vec<&mut RFile>
fn files_by_type_and_paths_mut( &mut self, file_types: &[FileType], paths: &[ContainerPath], case_insensitive: bool, ) -> Vec<&mut RFile>
Source§fn paths_cache_generate(&mut self)
fn paths_cache_generate(&mut self)
Source§fn paths_cache_insert_path(&mut self, path: &str)
fn paths_cache_insert_path(&mut self, path: &str)
Source§fn paths_cache_remove_path(&mut self, path: &str)
fn paths_cache_remove_path(&mut self, path: &str)
Source§fn paths_folders_raw(&self) -> HashSet<String>
fn paths_folders_raw(&self) -> HashSet<String>
Source§fn paths(&self) -> Vec<ContainerPath>
fn paths(&self) -> Vec<ContainerPath>
Source§fn paths_raw(&self) -> Vec<&str>
fn paths_raw(&self) -> Vec<&str>
Source§fn paths_raw_from_container_path(&self, path: &ContainerPath) -> Vec<String>
fn paths_raw_from_container_path(&self, path: &ContainerPath) -> Vec<String>
Source§fn internal_timestamp(&self) -> u64
fn internal_timestamp(&self) -> u64
Last modified date stored on the provided Container, in seconds. Read moreSource§fn preload(&mut self) -> Result<()>
fn preload(&mut self) -> Result<()>
Source§fn move_paths(
&mut self,
in_out_paths: &[(ContainerPath, ContainerPath)],
) -> Result<Vec<(ContainerPath, ContainerPath)>>
fn move_paths( &mut self, in_out_paths: &[(ContainerPath, ContainerPath)], ) -> Result<Vec<(ContainerPath, ContainerPath)>>
Source§fn move_path(
&mut self,
source_path: &ContainerPath,
destination_path: &ContainerPath,
) -> Result<Vec<(ContainerPath, ContainerPath)>>
fn move_path( &mut self, source_path: &ContainerPath, destination_path: &ContainerPath, ) -> Result<Vec<(ContainerPath, ContainerPath)>>
Source§fn clean_undecoded(&mut self)
fn clean_undecoded(&mut self)
Source§impl Decodeable for AnimPack
impl Decodeable for AnimPack
Source§fn decode<R: ReadBytes>(
data: &mut R,
extra_data: &Option<DecodeableExtraData<'_>>,
) -> Result<Self>
fn decode<R: ReadBytes>( data: &mut R, extra_data: &Option<DecodeableExtraData<'_>>, ) -> Result<Self>
Decodes an AnimPack from a binary data source.
§Parameters
data: Binary reader implementingReadBytesextra_data: Required decoding context (see below)
§Required Extra Data Fields
This implementation requires DecodeableExtraData with:
lazy_load: Enable lazy loading (ignored if encrypted)is_encrypted: Whether the AnimPack data is encrypteddisk_file_path: Path to file on disk (required for lazy loading)disk_file_offset: Offset within disk file (0 for standalone files)data_size: Total size of AnimPack data in bytestimestamp: Last modified timestamp in seconds (0 for in-memory)
§Returns
Ok(AnimPack): Successfully decoded AnimPack with all filesErr(_): I/O error, malformed data, or missing required extra data
§Lazy Loading Behavior
When lazy_load is true and data is unencrypted:
- File metadata is read immediately
- File data is loaded on-demand when accessed
- Requires valid
disk_file_pathto a file on disk
When encrypted or lazy loading disabled:
- All file data is read into memory immediately
§Example
use std::fs::File;
use std::io::BufReader;
use rpfm_lib::binary::ReadBytes;
use rpfm_lib::files::{Decodeable, DecodeableExtraData, animpack::AnimPack};
use rpfm_lib::utils::last_modified_time_from_file;
let path = "animations/unit.animpack";
let mut reader = BufReader::new(File::open(path)?);
let mut extra_data = DecodeableExtraData::default();
extra_data.set_disk_file_path(Some(path));
extra_data.set_data_size(reader.len()?);
extra_data.set_timestamp(last_modified_time_from_file(reader.get_ref())?);
let animpack = AnimPack::decode(&mut reader, &Some(extra_data))?;Source§impl<'de> Deserialize<'de> for AnimPack
impl<'de> Deserialize<'de> for AnimPack
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Encodeable for AnimPack
impl Encodeable for AnimPack
Source§fn encode<W: WriteBytes>(
&mut self,
buffer: &mut W,
extra_data: &Option<EncodeableExtraData<'_>>,
) -> Result<()>
fn encode<W: WriteBytes>( &mut self, buffer: &mut W, extra_data: &Option<EncodeableExtraData<'_>>, ) -> Result<()>
Encodes this AnimPack to a binary data stream.
§Parameters
buffer: Binary writer implementingWriteBytesextra_data: Encoding options (not used, passNone)
§Returns
Ok(()): Successfully encoded AnimPackErr(_): I/O error, file too large, or encoding error
§Encoding Behavior
- Files are sorted alphabetically by path (case-insensitive)
- Paths use forward slashes (
/) not backslashes (\) - Each file is encoded inline with its size prefix
- Files larger than 4GB (u32::MAX) return an error
§Path Format
Important: Encoded paths use forward slashes because animation sets created by assed tool break if backslashes are used.
§Example
use std::fs::File;
use std::io::{BufWriter, Write};
use rpfm_lib::files::{Encodeable, animpack::AnimPack};
let mut animpack = AnimPack::default();
// ... add files to animpack ...
let mut encoded = vec![];
animpack.encode(&mut encoded, &None)?;
// Write to disk
let mut writer = BufWriter::new(File::create("output.animpack")?);
writer.write_all(&encoded)?;impl StructuralPartialEq for AnimPack
Auto Trait Implementations§
impl Freeze for AnimPack
impl RefUnwindSafe for AnimPack
impl Send for AnimPack
impl Sync for AnimPack
impl Unpin for AnimPack
impl UnsafeUnpin for AnimPack
impl UnwindSafe for AnimPack
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.