Skip to main content

Crate rpfm_lib

Crate rpfm_lib 

Source
Expand description

Core library for reading and writing Total War game files.

This crate provides comprehensive support for reading, writing, and manipulating file formats used by Creative Assembly in Total War games since Empire: Total War. It forms the foundation of the Rusted PackFile Manager (RPFM) project.

§Supported Games

  • Total War: Pharaoh - Dynasties
  • Total War: Pharaoh
  • Total War: Warhammer 3
  • Total War Saga: Troy
  • Total War: Three Kingdoms
  • Total War: Warhammer 2
  • Total War: Warhammer
  • Total War Saga: Thrones of Britannia
  • Total War: Attila
  • Total War: Rome 2
  • Total War: Shogun 2
  • Total War: Napoleon
  • Total War: Empire

§Supported File Formats

The library supports 30+ file types including:

  • Pack Files (.pack): Container format for all game assets
  • Database Tables (db/): Game data with versioned schemas
  • Localisation Files (.loc): Translated text strings
  • 3D Models (.rigid_model_v2): Unit and building meshes
  • Animations: AnimPack, AnimFragment, AnimsTable, MatchedCombat
  • Audio: Sound banks (.bnk), sound events, DAT containers
  • Images: DDS textures, atlases
  • Maps: BMD (battle map data), tile databases, vegetation
  • Campaign: ESF (save files), startpos
  • UI: UIC components, portrait settings, fonts
  • Scripts: Lua, XML, and other text formats

See the files module for detailed information on each file type and its support level.

§Architecture

The library is organized into several key modules:

  • files: File format parsers and writers (30+ types)
  • schema: Database table schema definitions and versioning
  • binary: Low-level binary I/O utilities
  • games: Game-specific configuration and version detection
  • compression: LZ4, ZStd, and LZMA compression support
  • encryption: Pack file encryption/decryption
  • error: Error types and result handling
  • integrations: Optional Assembly Kit and Git integration

§Feature Flags

  • integration_assembly_kit: Enable Assembly Kit raw table parsing
  • integration_git: Enable Git repository operations

§Examples

§Reading a Pack File

use rpfm_lib::files::pack::Pack;
use rpfm_lib::games::supported_games::{SupportedGames, KEY_WARHAMMER_3};
use std::path::PathBuf;

let path = PathBuf::from("path/to/pack.pack");
let games = SupportedGames::default();
let game_info = games.game(&KEY_WARHAMMER_3).unwrap();
let pack = Pack::read_and_merge(&[path], game_info, true, false, false)?;

for file in pack.files().values() {
    println!("{}", file.path_in_container_raw());
}

§Working with Database Tables

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

let schema_path = Path::new("path/to/schema.ron");
let schema = Schema::load(&schema_path, None)?;
let mut extra_data = DecodeableExtraData::default();
extra_data.set_schema(Some(&schema));

// Decode a DB file (assuming pack is loaded)
// let mut file = pack.files_by_path(&path, false).first().unwrap();
// file.decode(&Some(extra_data), false, true)?;
//
// if let Ok(RFileDecoded::DB(db)) = file.decoded() {
//     println!("Table {} has {} rows", db.table_name(), db.data().len());
// }
  • rpfm_extensions: Higher-level features (dependencies, diagnostics, search, optimizer)
  • rpfm_ui: Qt-based desktop application

Modules§

binary
This module contains the traits ReadBytes and WriteBytes, used to read binary data into known types and write them back to binary.
compression
This module contains the code to compress/decompress data for Total War games.
encryption
This module contains the code to decrypt encrypted data in Total War PackFiles.
error
Error types and result handling for the RPFM library.
files
This module contains the definition of RFile, the file abstraction used by this lib to decode/encode files.
games
Game-specific configuration and metadata for Total War games.
integrations
Optional integrations with external tools and services.
notes
Module for managing user notes attached to PackFile entries.
schema
Schema system for defining Total War file formats.
utils
Generic utility functions for the crate.

Statics§

REGEX_DB
Regular expression to identify database table file paths.
REGEX_PORTRAIT_SETTINGS
Regular expression to identify portrait settings file paths.