Skip to main content

Crate d2s

Crate d2s 

Source
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§

ActIIIWaypoints
Act III waypoints.
ActIIWaypoints
Act II waypoints.
ActIVWaypoints
Act IV waypoints.
ActIWaypoints
Act I waypoints.
ActVWaypoints
Act V waypoints.
CharacterFlags
Character state flags stored in the save header.
ItemCode
A 4-character item code packed little-endian into a u32 (e.g. "cap ").
ItemFlags
Item state flags (first 32 bits of an item record).
QuestFlags
Quest progress flags stored per quest per difficulty.
StatId
A stat identifier (row index in ItemStatCost.txt).

Enums§

BodyLocation
Body equipment locations.
CharacterClass
Character classes.
Composit
Appearance composit indexes (into the appearance graphics/tints arrays).
DemonType
Bound demon type.
Difficulty
Game difficulty levels.
Error
Errors produced while reading or writing save files.
GameVersion
Game version stored in the preview data of v104+ saves.
ItemMode
Item animation/storage mode.
ItemQuality
Item quality levels.
Side
Side of the skill bar a skill is assigned to.
StashTabType
Shared stash tab type (stash format >= 2).
StorePage
Storage page of a stored item.

Type Aliases§

Result
Result type used throughout this crate.