Skip to main content

Module files

Module files 

Source
Expand description

This module contains the definition of RFile, the file abstraction used by this lib to decode/encode files.

There is an additional type: Unknown. This type is used as a wildcard, so you can get the raw data of any non-supported file type and manipulate it yourself in a safe way.

For more information about specific file types, including their binary format spec, please check their respective documentation.

§Core Abstractions

§RFile

The RFile struct is the central abstraction for all files in rpfm_lib. It can represent:

  • Files within PackFiles (or any Container)
  • Files on the filesystem
  • Files in memory only

Key features:

  • Lazy Loading: Files can be loaded on-demand to reduce memory usage
  • Type Detection: Automatically identifies file types based on path and content
  • Caching: Supports caching decoded data or raw bytes
  • Metadata: Tracks path, timestamp, container name, and file type

§File States

Files can be in one of three internal states:

  • OnDisk: Data not yet loaded (lazy loading)
  • Cached: Raw bytes loaded but not decoded
  • Decoded: Fully parsed into a type-specific structure

§Decoding/Encoding

All file types implement the Decodeable and Encodeable traits:

  • Decodeable: Parse binary data into structured format
  • Encodeable: Serialize structured format back to binary

Extra data can be passed via DecodeableExtraData and EncodeableExtraData to provide context like schemas, game info, or file names.

§Known file types

File TypeDecoding SupportedEncoding Supported
AnimLimitedLimited
AnimFragmentBattleLimitedLimited
AnimPackYesYes
AnimsTableYesYes
AtlasYesYes
AudioNoNo
BMDLimitedLimited
BMD_VegetationLimitedLimited
CS2_CollisionLimitedLimited
CS2_ParsedLimitedLimited
DatLimitedLimited
DBYesYes
ESFLimitedLimited
FontLimitedLimited
GroupFormationsLimitedLimited
HLSL_CompiledLimitedLimited
ImageLimitedLimited
LocYesYes
MatchedCombatYesYes
PackYesYes
PortraitSettingsYesYes
RigidModelNoNo
SoundBankNoNo
SoundBankDatabaseLimitedLimited
SoundEventsLimitedLimited
TextYesYes
TileDatabaseYesYes
UICNoNo
UnitVariantYesYes
VideoYesYes
VMDYesYes
WSModelYesYes

§Example Usage

use rpfm_lib::files::{RFile, Decodeable, db::DB, DecodeableExtraData, table::Table};
use rpfm_lib::schema::Schema;
use std::path::Path;

// Load a DB table from disk
let schema = Schema::load(Path::new("path/to/schema.ron"), None).unwrap();
let mut extra = DecodeableExtraData::default();
extra.set_schema(Some(&schema));
extra.set_table_name(Some("units_tables"));

let rfile = RFile::from_disk(Path::new("units"), &extra).unwrap();

// Access the decoded data
if let Some(db) = rfile.decoded().and_then(|d| d.db()) {
    println!("Table has {} rows", db.table().len());
}

Modules§

anim
Animation file handler with partial support.
anim_fragment_battle
Animation fragment battle file format support.
animpack
AnimPack container file format support.
anims_table
Animation table file format support.
atlas
Atlas texture coordinate mapping file format support.
audio
Audio file passthrough handler.
bmd
Battle Map Definition (BMD) file format support.
bmd_vegetation
BMD Vegetation file format support.
cs2_collision
CS2 Collision file format support.
cs2_parsed
CS2 Parsed file format support.
dat
DAT audio configuration file format support.
db
Database table files for Total War game data.
esf
This module provides support for reading and writing ESF (Empire Save File) files.
font
CUF (Creative Assembly Unicode Font) file format support.
group_formations
This module contains the implementation of the Group Formations file format for Total War games.
hlsl_compiled
HLSL compiled shader file format support (FASTBIN0/DXBC).
image
Image file handling with DDS conversion support.
loc
Localisation table files for Total War games.
matched_combat
This module contains the implementation of the Matched Combat file format for Total War games.
pack
PackFile (.pack) container format for Total War games.
portrait_settings
Portrait settings for unit and character portraits.
rigidmodel
RigidModel file format support for Total War games.
sound_bank
Wwise SoundBank (.bnk) file support.
sound_bank_database
Sound bank database for older Total War games.
sound_events
Sound events configuration for older Total War games.
table
Table data structures and encoding/decoding for Total War game data.
text
Plain text file handling with encoding detection and format recognition.
tile_database
Tile database files for Total War terrain systems.
uic
UI Component (UIC) files for Total War games.
unit_variant
This is a module to read/write binary UnitVariant files.
unknown
Wildcard handler for unsupported or unrecognized file types.
video
CA_VP8 are a custom version of a VP8 video by CA. These files contain only video data, no audio.

Structs§

DecodeableExtraData
Additional context data for Decodeable::decode() operations.
EncodeableExtraData
Additional context data for Encodeable::encode() operations.
RFile
Central file abstraction for rpfm_lib.

Enums§

ContainerPath
This enum represents a Path inside a Container.
FileType
Known file types in Total War games.
RFileDecoded
This enum allow us to store any kind of decoded file type on a common place.

Traits§

Container
Interface for working with container-like files.
Decodeable
Generic trait for decoding binary data into structured types.
Encodeable
Generic trait for encoding structured types into binary data.