bl4/lib.rs
1//! # bl4
2//!
3//! Borderlands 4 save editor library - encryption, decryption, and parsing.
4//!
5//! This library provides functionality to:
6//! - Decrypt and encrypt Borderlands 4 .sav files
7//! - Parse decrypted YAML save data
8//! - Decode item serials (weapons, equipment, etc.)
9//! - Modify save data (level, currency, inventory, etc.)
10//!
11//! ## Example
12//!
13//! ```no_run
14//! use std::fs;
15//!
16//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
17//! let encrypted = fs::read("1.sav")?;
18//! let steam_id = "76561197960521364";
19//!
20//! // Decrypt and parse save file
21//! let yaml_data = bl4::decrypt_sav(&encrypted, steam_id)?;
22//! let mut save = bl4::SaveFile::from_yaml(&yaml_data)?;
23//!
24//! // Query and modify save data
25//! println!("Character: {:?}", save.get_character_name());
26//! println!("Cash: {:?}", save.get_cash());
27//!
28//! save.set_cash(999999)?;
29//! save.set_character_name("NewName")?;
30//!
31//! // Re-encrypt and save
32//! let modified_yaml = save.to_yaml()?;
33//! let encrypted = bl4::encrypt_sav(&modified_yaml, steam_id)?;
34//! fs::write("1.sav", encrypted)?;
35//! # Ok(())
36//! # }
37//! ```
38
39pub mod backup;
40pub mod crypto;
41pub mod manifest;
42pub mod parts;
43pub mod reference;
44pub mod save;
45pub mod serial;
46
47#[cfg(feature = "wasm")]
48pub mod wasm;
49
50// Re-export commonly used items
51#[doc(inline)]
52pub use backup::{smart_backup, update_after_edit, BackupError};
53#[doc(inline)]
54pub use crypto::{decrypt_sav, derive_key, encrypt_sav, CryptoError};
55#[doc(inline)]
56pub use parts::{
57 category_name, category_name_for_type, item_type_name, level_from_code, manufacturer_name,
58 serial_format, serial_id_to_parts_category, SerialFormat,
59};
60#[doc(inline)]
61pub use save::{ChangeSet, SaveError, SaveFile, StateFlags};
62#[doc(inline)]
63pub use serial::{ItemSerial, SerialError};
64
65// Manifest data lookups
66#[doc(inline)]
67pub use manifest::{all_categories, all_manufacturers, part_name, stats as manifest_stats};
68
69// Reference data (rarities, elements, weapon types, manufacturers, gear types)
70#[doc(inline)]
71pub use reference::{
72 element_by_code, gear_type_by_code, legendary_by_name, manufacturer_by_code,
73 manufacturer_name_by_code, rarity_by_code, rarity_by_tier, stat_description,
74 weapon_type_by_code, ElementType, GearType, LegendaryItem, Manufacturer, RarityTier,
75 WeaponType, ELEMENT_TYPES, GEAR_TYPES, KNOWN_LEGENDARIES, MANUFACTURERS, RARITY_TIERS,
76 WEAPON_TYPES,
77};