wow_mpq/patch/
mod.rs

1//! MPQ patch file support
2//!
3//! This module implements support for binary patch files (PTCH format) used in
4//! Cataclysm and later WoW expansions. Patch files contain binary diffs that must
5//! be applied to base files to reconstruct the final file.
6//!
7//! # Automatic Patch Handling
8//!
9//! **In most cases, you don't need to use this module directly.** The [`PatchChain`](crate::PatchChain)
10//! automatically detects and applies patch files when reading files from a chain of archives.
11//!
12//! ```rust,no_run
13//! use wow_mpq::PatchChain;
14//!
15//! let mut chain = PatchChain::new();
16//! chain.add_archive("base.MPQ", 0)?;
17//! chain.add_archive("patch-1.MPQ", 100)?;
18//!
19//! // If the file exists as a patch in patch-1.MPQ, it will be automatically
20//! // applied to the base file from base.MPQ
21//! let data = chain.read_file("some/file.txt")?;
22//! # Ok::<(), wow_mpq::Error>(())
23//! ```
24//!
25//! # Patch File Format
26//!
27//! Patch files use the PTCH format with three main sections:
28//!
29//! 1. **PTCH Header** - Basic metadata (sizes, signatures)
30//! 2. **MD5 Block** - Checksums for verification
31//! 3. **XFRM Block** - Patch data (COPY or BSD0 type)
32//!
33//! # Patch Types
34//!
35//! - **COPY** (`0x59504f43`) - Simple file replacement
36//! - **BSD0** (`0x30445342`) - Binary diff using bsdiff40 algorithm
37//!
38//! # Manual Patch Application
39//!
40//! For advanced use cases where you need to manually parse and apply patches:
41//!
42//! ```rust,no_run
43//! use wow_mpq::patch::{PatchFile, apply_patch};
44//!
45//! // Read patch file data (bypasses normal Archive::read_file rejection)
46//! let patch_data = /* get patch data from archive */
47//! # vec![0u8; 100];
48//! let patch = PatchFile::parse(&patch_data)?;
49//!
50//! // Apply patch to base file
51//! let base_data = /* get base file data */
52//! # vec![0u8; 100];
53//! let patched = apply_patch(&patch, &base_data)?;
54//! # Ok::<(), wow_mpq::Error>(())
55//! ```
56
57mod apply;
58mod header;
59
60pub use apply::apply_patch;
61pub use header::{PatchFile, PatchHeader, PatchType};