Skip to main content

Pack

Struct Pack 

Source
pub struct Pack { /* private fields */ }
Expand description

Packs are a container-type file, used for “packing” all game assets into single files, to speed up disk reads.

Their format has passed through multiple iterations since empire, getting changes on almost all iterations, like timestamps, encryption, compression,…

§Pack Structure

BytesTypeData
20-384PackHeaderHeader of the Pack. Lenght depends on Pack version and flags enabled.
*Pack IndexIndex containing the list of Packs this Pack depends on.
*File IndexIndex containing the list of Files this Pack depends on
*File DataData of the files contained in this Pack.
256AppendixUnknown data at the end of the Pack. Only seen in Arena’s encrypted Packs.

§Pack Index

The Pack Index contains a list of Packs that will be force-loaded before this mod.

BytesTypeData
*Null-terminated StringU8Pack file name.

§File Index

The File Index contains the metadata of the Files this Pack contains, in the same order their data is, further in the Pack.

BytesTypeData
4u32Size of the file’s data, in bytes.
8u64Timestamp of the file, if the header has the HAS_INDEX_WITH_TIMESTAMPS flag enabled. Only in PFH2 and PFH3.
4u32Truncated timestamp of the file, if the header has the HAS_INDEX_WITH_TIMESTAMPS flag enabled. Only since PFH4.
1boolIf the file is compressed. Only since PFH5.
*Null-terminated StringU8File’s path within the Pack.

§File Data

The raw data of the files contained by this Pack, in the same order as their indexes. Not much to explain here.

Implementations§

Source§

impl Pack

Source

pub fn disk_file_path(&self) -> &String

The path of the Pack on disk, if exists. If not, then this should be empty.

Source

pub fn disk_file_offset(&self) -> &u64

The offset on the disk file the data of this Pack starts. Usually 0.

Source

pub fn local_timestamp(&self) -> &u64

Timestamp from the moment this Pack was open. To check if the file was edited on disk while we had it open.

Source

pub fn header(&self) -> &PackHeader

Header data of this Pack.

Source

pub fn dependencies(&self) -> &Vec<(bool, String)>

List of Packs this Pack depends on. If the boolean is true, the packs are also required to be loaded before himself when starting the game.

In other places, we may refer to this as the Dependency List.

Source

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

List of files this Pack contains.

Source

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

List of file paths lowercased, with their casing counterparts. To quickly find files.

Source

pub fn notes(&self) -> &PackNotes

Notes added to the Pack. Exclusive of this lib.

Source

pub fn settings(&self) -> &PackSettings

Settings stored in the Pack itself, to be able to share them between installations.

Source§

impl Pack

Source

pub fn disk_file_path_mut(&mut self) -> &mut String

The path of the Pack on disk, if exists. If not, then this should be empty.

Source

pub fn disk_file_offset_mut(&mut self) -> &mut u64

The offset on the disk file the data of this Pack starts. Usually 0.

Source

pub fn local_timestamp_mut(&mut self) -> &mut u64

Timestamp from the moment this Pack was open. To check if the file was edited on disk while we had it open.

Source

pub fn header_mut(&mut self) -> &mut PackHeader

Header data of this Pack.

Source

pub fn dependencies_mut(&mut self) -> &mut Vec<(bool, String)>

List of Packs this Pack depends on. If the boolean is true, the packs are also required to be loaded before himself when starting the game.

In other places, we may refer to this as the Dependency List.

Source

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

List of files this Pack contains.

Source

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

List of file paths lowercased, with their casing counterparts. To quickly find files.

Source

pub fn notes_mut(&mut self) -> &mut PackNotes

Notes added to the Pack. Exclusive of this lib.

Source

pub fn settings_mut(&mut self) -> &mut PackSettings

Settings stored in the Pack itself, to be able to share them between installations.

Source§

impl Pack

Source

pub fn set_disk_file_path(&mut self, val: String) -> &mut Self

The path of the Pack on disk, if exists. If not, then this should be empty.

Source

pub fn set_disk_file_offset(&mut self, val: u64) -> &mut Self

The offset on the disk file the data of this Pack starts. Usually 0.

Source

pub fn set_local_timestamp(&mut self, val: u64) -> &mut Self

Timestamp from the moment this Pack was open. To check if the file was edited on disk while we had it open.

Source

pub fn set_header(&mut self, val: PackHeader) -> &mut Self

Header data of this Pack.

Source

pub fn set_dependencies(&mut self, val: Vec<(bool, String)>) -> &mut Self

List of Packs this Pack depends on. If the boolean is true, the packs are also required to be loaded before himself when starting the game.

In other places, we may refer to this as the Dependency List.

Source

pub fn set_files(&mut self, val: HashMap<String, RFile>) -> &mut Self

List of files this Pack contains.

Source

pub fn set_paths(&mut self, val: HashMap<String, Vec<String>>) -> &mut Self

List of file paths lowercased, with their casing counterparts. To quickly find files.

Source

pub fn set_notes(&mut self, val: PackNotes) -> &mut Self

Notes added to the Pack. Exclusive of this lib.

Source

pub fn set_settings(&mut self, val: PackSettings) -> &mut Self

Settings stored in the Pack itself, to be able to share them between installations.

Source§

impl Pack

Implementation of Pack.

Source

pub fn new_with_version(pfh_version: PFHVersion) -> Self

This function creates a new empty Pack with a specific PFHVersion.

Source

pub fn new_with_name_and_version(name: &str, pfh_version: PFHVersion) -> Self

This function creates a new empty Pack with a name and a specific PFHVersion.

Source

pub fn read_and_merge_ca_packs( game: &GameInfo, game_path: &Path, ) -> Result<Self>

This function reads and returns all CA Packs for the provided game merged as one, for easy manipulation.

This needs a GameInfo to get the Packs from, and a game path to search the Packs on.

Source

pub fn read_and_merge( pack_paths: &[PathBuf], game: &GameInfo, lazy_load: bool, ignore_mods: bool, keep_order: bool, ) -> Result<Self>

Convenience function to open multiple Packs as one, taking care of overwriting files when needed.

If this function receives only one path, it works as a normal read_from_disk function. If it receives none, an error will be returned.

Source

pub fn merge(packs: &[Self]) -> Result<Self>

Convenience function to merge open Packs as one, taking care of overwriting files when needed.

Packs are merged in the order they are provided. If you need to use a custom order, sort them before merging, or use the read_and_merge function instead.

Internal files are left in the state they were before. If you need them loaded, do it after this.

Source

pub fn save( &mut self, path: Option<&Path>, game_info: &GameInfo, extra_data: &Option<EncodeableExtraData<'_>>, ) -> Result<()>

Convenience function to easily save a Pack to disk.

If a path is provided, the Pack will be saved to that path. Otherwise, it’ll use whatever path it had set before.

Source

pub fn pfh_version(&self) -> PFHVersion

This function returns the current PFH Version of the provided Pack.

Source

pub fn pfh_file_type(&self) -> PFHFileType

This function returns the current PFH File Type of the provided Pack.

Source

pub fn bitmask(&self) -> PFHFlags

This function returns the bitmask applied to the provided Pack.

Source

pub fn internal_timestamp(&self) -> u64

This function returns the timestamp of the last time the Pack was saved.

Source

pub fn game_version(&self) -> u32

This function returns the Game version this Pack is intended for.

Source

pub fn build_number(&self) -> u32

This function returns the build number of the game this Pack is intended for.

Source

pub fn authoring_tool(&self) -> &str

This function returns the tool that created the Pack. Max 8 characters, 00-padded.

Source

pub fn extra_subheader_data(&self) -> &[u8]

This function returns the Extra Subheader Data, if any.

Source

pub fn compression_format(&self) -> CompressionFormat

This function returns the compression format of the Pack.

Source

pub fn set_pfh_version(&mut self, version: PFHVersion)

This function sets the current Pack PFH Version to the provided one.

Source

pub fn set_pfh_file_type(&mut self, file_type: PFHFileType)

This function sets the current Pack PFH File Type to the provided one.

Source

pub fn set_bitmask(&mut self, bitmask: PFHFlags)

This function sets the current Pack bitmask to the provided one.

Source

pub fn set_internal_timestamp(&mut self, timestamp: u64)

This function sets the current Pack timestamp to the provided one.

Source

pub fn set_game_version(&mut self, game_version: u32)

This function sets the game version (as in X.Y.Z) this Pack is for.

Source

pub fn set_build_number(&mut self, build_number: u32)

This function sets the build number this Pack is for.

Source

pub fn set_authoring_tool(&mut self, authoring_tool: &str)

This function sets the authoring tool that last edited this Pack.

Source

pub fn set_extra_subheader_data(&mut self, extra_subheader_data: &[u8])

This function sets the Extra Subheader Data of the Pack.

Source

pub fn set_compression_format( &mut self, cf: CompressionFormat, game_info: &GameInfo, ) -> CompressionFormat

This function sets the compression format the pack should use.

Returns the new compression format. Support for each format varies depending on the game.

Source

pub fn spoof_ca_authoring_tool(&mut self, spoof: bool)

This function allows to toggle CA Authoring tool spoofing for this Pack.

Passing spoof as false will reset the Authoring Tool to the default one.

Source

pub fn is_compressible(&self) -> bool

This function returns if the Pack is compressible or not.

Source

pub fn missing_locs_paths(&self) -> (String, String)

This function returns the paths (as Strings) of the files used for missing loc data generation for the loaded Pack.

The first one is the one for existing entries. The second one is the one for new entries.

Source

pub fn generate_missing_loc_data( &mut self, existing_locs: &HashMap<String, String>, ) -> Result<Vec<ContainerPath>>

This function is used to generate all loc entries missing from a Pack into a missing.loc file.

Source

pub fn patch_siege_ai(&mut self) -> Result<(String, Vec<ContainerPath>)>

This function is used to patch Warhammer I & II Siege map packs so their AI actually works.

This also removes the useless xml files left by Terry in the Pack.

Source

pub fn live_export( &mut self, game: &GameInfo, game_path: &Path, disable_regen_table_guid: bool, keys_first: bool, ) -> Result<()>

Function to perform a live extraction, meaning the files will be extracted while the game is running, allowing for real-time updates and modifications without the need for a full game restart.

Only works in Warhammer 3.

Source

pub fn update_anim_ids( &mut self, game: &GameInfo, starting_id: i32, offset: i32, ) -> Result<Vec<ContainerPath>>

Function to update the anim ids of the pack on mass, based on a starting id and an offset.

Trait Implementations§

Source§

impl Clone for Pack

Source§

fn clone(&self) -> Pack

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 Pack

Source§

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

This method allows us to extract the metadata associated to the provided container as .json or .md files.

Pack implementation extracts the PackSettings of the provided Pack and its associated notes.

Source§

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

This function allows you to move any RFile of folder of RFiles from one folder to another.

It returns a list with all the new ContainerPath.

Source§

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

Inserts an RFile into the container. Read more
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 internal_timestamp(&self) -> u64

This method returns the Last modified date stored on the provided Container, in seconds. 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 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 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 clean_undecoded(&mut self)

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

impl Debug for Pack

Source§

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

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

impl Decodeable for Pack

Source§

fn decode<R: ReadBytes>( data: &mut R, extra_data: &Option<DecodeableExtraData<'_>>, ) -> Result<Self>

Decodes binary data into the implementing type. Read more
Source§

impl Default for Pack

Source§

fn default() -> Pack

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

impl<'de> Deserialize<'de> for Pack

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 Pack

Source§

fn encode<W: WriteBytes>( &mut self, buffer: &mut W, extra_data: &Option<EncodeableExtraData<'_>>, ) -> Result<()>

Encodes the implementing type into binary data. Read more
Source§

impl PartialEq for Pack

Source§

fn eq(&self, other: &Pack) -> 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 Pack

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 Pack

Auto Trait Implementations§

§

impl Freeze for Pack

§

impl RefUnwindSafe for Pack

§

impl Send for Pack

§

impl Sync for Pack

§

impl Unpin for Pack

§

impl UnsafeUnpin for Pack

§

impl UnwindSafe for Pack

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,