Expand description
Schema system for defining Total War file formats.
This module provides the infrastructure for defining and managing schemas that describe the binary structure of Total War game files, primarily database tables and localization files.
§Overview
A Schema contains Definitions that specify the exact binary layout of different file types.
Each table can have multiple definitions to support different versions across game patches. The schema
system also supports runtime patches to override field properties without modifying the base schema.
§Key Components
Schema: The main container holding all table definitions and patches for a gameDefinition: Describes one version of a table’s structure (fields, types, constraints)Field: Represents a single column in a table with its type and metadataFieldType: The data type of a field (integers, strings, booleans, sequences, etc.)DefinitionPatch: Runtime modifications to field properties
§Schema Versioning
- Each game has its own schema file (e.g.,
warhammer_3.ron) - The schema format version (currently v5) is tracked separately from table versions
- Legacy schema formats (like v4) can be automatically upgraded via
Schema::update()
§Loading and Saving
Schemas are typically stored in RON format but can also be exported to JSON:
use rpfm_lib::schema::Schema;
use std::path::Path;
// Load a schema
let schema_path = Path::new("schemas/warhammer_3.ron");
let schema = Schema::load(schema_path, None)?;
// Access table definitions
if let Some(defs) = schema.definitions_by_table_name("units_tables") {
for def in defs {
println!("Version {}: {} fields", def.version(), def.fields().len());
}
}§Patches
Patches allow modifying field properties at runtime without changing the schema:
use rpfm_lib::schema::Schema;
use std::path::Path;
let schema = Schema::load(Path::new("schema.ron"), Some(Path::new("patches.ron")))?;
// Check if a field has a patched value
if let Some(value) = schema.patch_value("units_tables", "key", "is_key") {
println!("Patched is_key value: {}", value);
}§Schema Repository
Schemas are maintained in a separate Git repository and can be updated independently from RPFM itself. The repository URL and branch are defined as constants in this module.
Structs§
- Definition
- Defines the structure of a specific version of a database table.
- Field
- Defines a single field within a table definition.
- Schema
- Represents a complete schema file containing table definitions for a Total War game.
Enums§
- Field
Type - Supported data types for table fields.
Constants§
- MERGE_
COLOUR_ NO_ NAME - Name for unnamed colour groups.
- MERGE_
COLOUR_ POST - Suffix for merged colour field names.
- SCHEMA_
BRANCH - Name of the Git branch to use when fetching schemas.
- SCHEMA_
FOLDER - Name of the folder containing all the schemas.
- SCHEMA_
REMOTE - Name of the Git remote to use when fetching schemas.
- SCHEMA_
REPO - URL of the remote Git repository containing the schema files.
Type Aliases§
- Definition
Patch - This type defines patches for specific table definitions, in a ColumnName -> [key -> value] format.