Skip to main content

rpfm_extensions/
lib.rs

1//---------------------------------------------------------------------------//
2// Copyright (c) 2017-2026 Ismael Gutiérrez González. All rights reserved.
3//
4// This file is part of the Rusted PackFile Manager (RPFM) project,
5// which can be found here: https://github.com/Frodo45127/rpfm.
6//
7// This file is licensed under the MIT license, which can be found here:
8// https://github.com/Frodo45127/rpfm/blob/master/LICENSE.
9//---------------------------------------------------------------------------//
10
11//! High-level extensions for Total War modding built on top of `rpfm_lib`.
12//!
13//! This crate provides advanced features that build upon the core file handling
14//! capabilities of `rpfm_lib`. While `rpfm_lib` focuses on low-level file format
15//! parsing and encoding, this crate implements higher-level modding workflows
16//! and analysis tools.
17//!
18//! # Modules
19//!
20//! ## Dependencies Management
21//!
22//! The [`dependencies`] module provides a comprehensive system for managing
23//! dependencies between packs and vanilla game files:
24//!
25//! - Loading and caching vanilla game data for reference lookups
26//! - Managing parent mod dependencies with automatic recursive loading
27//! - Building reference data for DB table foreign key relationships
28//! - Assembly Kit integration for tables not present in game files
29//!
30//! ## Diagnostics
31//!
32//! The [`diagnostics`] module implements validation and error checking:
33//!
34//! - DB/Loc table validation (invalid references, empty keys, duplicates)
35//! - Pack-level checks (conflicting files, missing dependencies)
36//! - Portrait settings validation
37//! - Animation fragment validation
38//! - Configurable diagnostic levels (Info, Warning, Error)
39//!
40//! ## Global Search
41//!
42//! The [`search`] module provides search and replace functionality across
43//! entire packs:
44//!
45//! - Pattern and regex-based searching
46//! - Case-sensitive and case-insensitive modes
47//! - Search across multiple file types (DB, Loc, Text, etc.)
48//! - Search in vanilla/parent dependencies
49//! - Batch replace operations
50//!
51//! ## Pack Optimizer
52//!
53//! The [`optimizer`] module helps reduce pack size and improve compatibility:
54//!
55//! - Remove files identical to vanilla (ITM - Identical To Master)
56//! - Remove duplicate and ITM table rows
57//! - Clean up unused Portrait Settings entries
58//! - Remove unnecessary XML and auxiliary files
59//! - Datacore management for `twad_key_deletes` tables
60//!
61//! ## Translation Support
62//!
63//! The [`translator`] module assists with mod localization:
64//!
65//! - Extract translatable strings from packs
66//! - Track translation status and changes
67//! - Auto-translate from vanilla localisation data
68//! - Export/import translation files
69//!
70//! ## glTF Export
71//!
72//! The [`gltf`] module provides 3D model export capabilities:
73//!
74//! - Convert RigidModel files to glTF format
75//! - Preserve mesh data, materials, and textures
76//! - Support for multiple LOD levels as separate scenes
77
78// Disabled `Clippy` linters, with the reasons why they were disabled.
79#![allow(
80    clippy::too_many_arguments,             // Disabled because it gets annoying really quick.
81    clippy::field_reassign_with_default,    // Disabled because it gets annoying on tests.
82    clippy::assigning_clones,
83    clippy::type_complexity,
84)]
85
86use std::{sync::{mpsc::Sender, Arc, LazyLock, RwLock}, thread::JoinHandle};
87
88pub mod dependencies;
89pub mod diagnostics;
90pub mod gltf;
91pub mod optimizer;
92pub mod search;
93pub mod translator;
94
95/// Current version of the rpfm_extensions crate.
96///
97/// Used for versioning the dependencies cache to ensure compatibility.
98const VERSION: &str = env!("CARGO_PKG_VERSION");
99
100/// Background thread handle for startpos generation.
101///
102/// Some games have a bug where the startpos build process deletes a folder that it
103/// also requires to exist. This background thread repeatedly recreates the folder
104/// to work around the issue. This static holds the thread handles and communication
105/// channels for that process.
106static START_POS_WORKAROUND_THREAD: LazyLock<Arc<RwLock<Option<Vec<(Sender<bool>, JoinHandle<()>)>>>>> = LazyLock::new(|| Arc::new(RwLock::new(None)));