Skip to main content

Module search

Module search 

Source
Expand description

Global search and replace functionality for Pack files.

This module provides comprehensive search capabilities across entire packs, supporting multiple file types and search modes. It’s designed for finding and optionally replacing text across DB tables, Loc files, scripts, and more.

§Features

  • Pattern Matching: Simple string pattern search with optional case sensitivity
  • Regex Support: Full regular expression matching via the regex crate
  • Multi-file Search: Search across all files in a pack simultaneously
  • Dependency Search: Optionally include vanilla and parent mod files
  • Replace Support: Batch replacement for supported file types

§Supported File Types

Search is implemented for the following file types via the Searchable trait:

  • DB/Loc Tables (table): Search cell contents by column or across all columns
  • Text Files (text): Lua scripts, XML, and other text formats
  • Atlas Files (atlas): Texture atlas definitions
  • Portrait Settings (portrait_settings): Unit portrait configurations
  • Animation Fragments (anim_fragment_battle): Battle animation data
  • Rigid Models (rigid_model): 3D model metadata
  • Unit Variants (unit_variant): Unit variant definitions
  • Schema (schema): Search within schema definitions
  • Unknown Files (unknown): Raw binary search

§Search Sources

Searches can target different data sources:

  • Pack Only: Search only the currently loaded pack
  • Parent Mods: Include files from parent mod dependencies
  • Vanilla Files: Include game’s vanilla data
  • All Sources: Search everywhere

§Usage Example

use rpfm_extensions::search::{GlobalSearch, SearchSource, SearchOn};

let mut search = GlobalSearch::default();
search.set_pattern("swordsmen".to_string());
search.set_case_sensitive(false);
search.set_use_regex(false);
search.set_sources(vec![SearchSource::Pack("my_pack".to_string())]);
search.set_search_on(SearchOn::all());

// Perform the search
search.search(&mut pack, &schema, &dependencies);

// Access results
for match_holder in search.matches().db() {
    println!("Found in {}: {} matches", match_holder.path(), match_holder.matches().len());
}

// Perform replacement
search.set_replace_text("spearmen".to_string());
search.replace(&mut pack, &schema);

§Matching Modes

The MatchingMode enum determines how the search pattern is interpreted:

  • Pattern: Standard string matching with optional regex fallback
  • Regex: Full regex pattern matching with capture groups

Modules§

anim_fragment_battle
atlas
portrait_settings
rigid_model
schema
Module with all the code related to the SchemaMatches.
table
Module with all the code related to the TableMatches.
text
Module with all the code related to the TextMatches.
unit_variant
unknown

Structs§

GlobalSearch
Configuration and results for a global search operation.
Matches
This struct stores the search matches, separated by file type.
SearchOn
Configuration for which file types to include in a search.

Enums§

MatchHolder
Container for search matches from any file type.
MatchingMode
How the search pattern should be interpreted.
SearchSource
Data source to search within.

Traits§

Replaceable
Trait for searchable types that also support replacement.
Searchable
Trait for file types that support text searching.