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 Type | Decoding Supported | Encoding Supported |
|---|---|---|
Anim | Limited | Limited |
AnimFragmentBattle | Limited | Limited |
AnimPack | Yes | Yes |
AnimsTable | Yes | Yes |
Atlas | Yes | Yes |
Audio | No | No |
BMD | Limited | Limited |
BMD_Vegetation | Limited | Limited |
CS2_Collision | Limited | Limited |
CS2_Parsed | Limited | Limited |
Dat | Limited | Limited |
DB | Yes | Yes |
ESF | Limited | Limited |
Font | Limited | Limited |
GroupFormations | Limited | Limited |
HLSL_Compiled | Limited | Limited |
Image | Limited | Limited |
Loc | Yes | Yes |
MatchedCombat | Yes | Yes |
Pack | Yes | Yes |
PortraitSettings | Yes | Yes |
RigidModel | No | No |
SoundBank | No | No |
| SoundBankDatabase | Limited | Limited |
| SoundEvents | Limited | Limited |
Text | Yes | Yes |
TileDatabase | Yes | Yes |
UIC | No | No |
UnitVariant | Yes | Yes |
Video | Yes | Yes |
| VMD | Yes | Yes |
| WSModel | Yes | Yes |
§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§
- Decodeable
Extra Data - Additional context data for
Decodeable::decode()operations. - Encodeable
Extra Data - Additional context data for
Encodeable::encode()operations. - RFile
- Central file abstraction for rpfm_lib.
Enums§
- Container
Path - This enum represents a Path inside a Container.
- File
Type - Known file types in Total War games.
- RFile
Decoded - 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.