Skip to main content

AnimPack

Struct AnimPack 

Source
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 detection
  • paths: Lowercase path lookup cache for case-insensitive file searches
  • files: Map of file paths to their RFile data

§Binary Format

BytesTypeData
4u32File Count
X * File CountFile ListList of files inside the AnimPack File

§File Structure

BytesTypeData
*Sized StringU8File Path
4u32File Length in bytes
File Length&[u8]File Data

§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_path to 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 Clone for AnimPack

Source§

fn clone(&self) -> AnimPack

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Container for AnimPack

Source§

fn disk_file_path(&self) -> &str

Returns the full path on disk where this container is stored. Read more
Source§

fn files(&self) -> &HashMap<String, RFile>

Returns a reference to the internal file map. Read more
Source§

fn files_mut(&mut self) -> &mut HashMap<String, RFile>

Returns a mutable reference to the internal file map. Read more
Source§

fn disk_file_offset(&self) -> u64

Returns the byte offset of this container’s data within its disk file. Read more
Source§

fn paths_cache(&self) -> &HashMap<String, Vec<String>>

Returns the paths cache mapping lowercase paths to their original-cased variants. Read more
Source§

fn paths_cache_mut(&mut self) -> &mut HashMap<String, Vec<String>>

Returns a mutable reference to the paths cache. Read more
Source§

fn local_timestamp(&self) -> u64

This method returns the Last modified date the filesystem reports for the container file, in seconds. Read more
Source§

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>>

Extracts files from the container to disk. Read more
Source§

fn extract_metadata(&mut self, _destination_path: &Path) -> Result<Vec<PathBuf>>

Extracts container metadata as .json files. Read more
Source§

fn insert(&mut self, file: RFile) -> Result<Option<ContainerPath>>

Inserts an RFile into the container. Read more
Source§

fn insert_file( &mut self, source_path: &Path, container_path_folder: &str, schema: &Option<Schema>, ) -> Result<Option<ContainerPath>>

Inserts a file from disk into the container. Read more
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>>

Inserts an entire folder from disk into the container recursively. Read more
Source§

fn remove(&mut self, path: &ContainerPath) -> Vec<ContainerPath>

Removes files matching the provided ContainerPath from the container. Read more
Source§

fn disk_file_name(&self) -> String

Returns the filename of the container on disk. Read more
Source§

fn has_file(&self, path: &str) -> bool

Checks if a file with the specified path exists in the container. Read more
Source§

fn has_folder(&self, path: &str) -> bool

Checks if a non-empty folder exists at the specified path. Read more
Source§

fn file(&self, path: &str, case_insensitive: bool) -> Option<&RFile>

Returns a reference to an RFile in the container by path. Read more
Source§

fn file_mut(&mut self, path: &str, case_insensitive: bool) -> Option<&mut RFile>

Returns a mutable reference to an RFile in the container by path. Read more
Source§

fn files_by_type(&self, file_types: &[FileType]) -> Vec<&RFile>

Returns references to all files of the specified types. Read more
Source§

fn files_by_type_mut(&mut self, file_types: &[FileType]) -> Vec<&mut RFile>

Returns mutable references to all files of the specified types. Read more
Source§

fn files_by_path( &self, path: &ContainerPath, case_insensitive: bool, ) -> Vec<&RFile>

Returns references to files matching the provided ContainerPath. Read more
Source§

fn files_by_path_mut( &mut self, path: &ContainerPath, case_insensitive: bool, ) -> Vec<&mut RFile>

Returns mutable references to files matching the provided ContainerPath. Read more
Source§

fn files_by_paths( &self, paths: &[ContainerPath], case_insensitive: bool, ) -> Vec<&RFile>

Returns references to files matching any of the provided ContainerPaths. Read more
Source§

fn files_by_paths_mut( &mut self, paths: &[ContainerPath], case_insensitive: bool, ) -> Vec<&mut RFile>

Returns mutable references to files matching any of the provided ContainerPaths. Read more
Source§

fn files_by_type_and_paths( &self, file_types: &[FileType], paths: &[ContainerPath], case_insensitive: bool, ) -> Vec<&RFile>

Returns references to files matching both type and path criteria. Read more
Source§

fn files_by_type_and_paths_mut( &mut self, file_types: &[FileType], paths: &[ContainerPath], case_insensitive: bool, ) -> Vec<&mut RFile>

Returns mutable references to files matching both type and path criteria. Read more
Source§

fn paths_cache_generate(&mut self)

Regenerates the internal paths cache from the current file list. Read more
Source§

fn paths_cache_insert_path(&mut self, path: &str)

Adds a single path to the paths cache. Read more
Source§

fn paths_cache_remove_path(&mut self, path: &str)

Removes a single path from the paths cache. Read more
Source§

fn paths_folders_raw(&self) -> HashSet<String>

Returns a set of all folder paths contained within the container. Read more
Source§

fn paths(&self) -> Vec<ContainerPath>

This method returns the list of ContainerPath corresponding to RFiles within the provided Container.
Source§

fn paths_raw(&self) -> Vec<&str>

This method returns the list of paths (as &str) corresponding to RFiles within the provided Container.
Source§

fn paths_raw_from_container_path(&self, path: &ContainerPath) -> Vec<String>

This function returns the list of paths (as String) corresponding to RFiles that match the provided ContainerPath.
Source§

fn internal_timestamp(&self) -> u64

This method returns the Last modified date stored on the provided Container, in seconds. Read more
Source§

fn preload(&mut self) -> Result<()>

This function preloads to memory any lazy-loaded RFile within this container.
Source§

fn move_paths( &mut self, in_out_paths: &[(ContainerPath, ContainerPath)], ) -> Result<Vec<(ContainerPath, ContainerPath)>>

This function allows you to move multiple RFiles or folders of RFiles from one folder to another. Read more
Source§

fn move_path( &mut self, source_path: &ContainerPath, destination_path: &ContainerPath, ) -> Result<Vec<(ContainerPath, ContainerPath)>>

This function allows you to move any RFile or folder of RFiles from one folder to another. Read more
Source§

fn clean_undecoded(&mut self)

This function removes all not-in-memory-already Files from the Container. Read more
Source§

impl Debug for AnimPack

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Decodeable for AnimPack

Source§

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 implementing ReadBytes
  • extra_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 encrypted
  • disk_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 bytes
  • timestamp: Last modified timestamp in seconds (0 for in-memory)
§Returns
  • Ok(AnimPack): Successfully decoded AnimPack with all files
  • Err(_): 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_path to 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 Default for AnimPack

Source§

fn default() -> AnimPack

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for AnimPack

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Encodeable for AnimPack

Source§

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 implementing WriteBytes
  • extra_data: Encoding options (not used, pass None)
§Returns
  • Ok(()): Successfully encoded AnimPack
  • Err(_): 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)?;
Source§

impl PartialEq for AnimPack

Source§

fn eq(&self, other: &AnimPack) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for AnimPack

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for AnimPack

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,