Expand description
Read and write Diablo 2 save files: .d2s character saves and .d2i shared stash files.
Supports the original Lord of Destruction format (version 96) and Diablo 2 Resurrected formats (versions 97-105), including conversion between them. Reading and writing an unmodified file produces byte-identical output.
use d2s::{D2Save, StatId};
let bytes = std::fs::read("MyCharacter.d2s")?;
let mut save = D2Save::from_bytes(&bytes)?;
println!("{} (level {})", save.name(), save.character.level);
save.stats.set(StatId::STRENGTH, 200);
for item in &save.items {
println!("{} {:?}", item.code, item.quality);
}
std::fs::write("MyCharacter.d2s", save.to_bytes()?)?;Parsing items requires game data (bit widths of stats, item classifications).
The data for versions 96, 97, 99 and 105 is embedded (feature embedded-data,
enabled by default); modded games can load their own .txt files with
TxtData::from_dir and use the *_with methods.
Re-exports§
pub use data::ExternalData;pub use data::ItemTypeInfo;pub use data::StatInfo;pub use data::TxtData;pub use model::*;
Modules§
- bits
- Low-level bit reader and writer.
- checksum
- Save file checksum.
- data
- Game data required to parse items and stats.
- huffman
- Huffman coding of item codes used by D2R (save version > 96).
- model
- Save file model types.
- overlay
- Zero-copy views over the fixed-size header sections of save files.
Structs§
- ActIII
Waypoints - Act III waypoints.
- ActII
Waypoints - Act II waypoints.
- ActIV
Waypoints - Act IV waypoints.
- ActI
Waypoints - Act I waypoints.
- ActV
Waypoints - Act V waypoints.
- Character
Flags - Character state flags stored in the save header.
- Item
Code - A 4-character item code packed little-endian into a
u32(e.g."cap "). - Item
Flags - Item state flags (first 32 bits of an item record).
- Quest
Flags - Quest progress flags stored per quest per difficulty.
- StatId
- A stat identifier (row index in ItemStatCost.txt).
Enums§
- Body
Location - Body equipment locations.
- Character
Class - Character classes.
- Composit
- Appearance composit indexes (into the appearance graphics/tints arrays).
- Demon
Type - Bound demon type.
- Difficulty
- Game difficulty levels.
- Error
- Errors produced while reading or writing save files.
- Game
Version - Game version stored in the preview data of v104+ saves.
- Item
Mode - Item animation/storage mode.
- Item
Quality - Item quality levels.
- Side
- Side of the skill bar a skill is assigned to.
- Stash
TabType - Shared stash tab type (stash format >= 2).
- Store
Page - Storage page of a stored item.
Type Aliases§
- Result
- Result type used throughout this crate.