Expand description
EU4 Save is a library to ergonomically work with EU4 saves (ironman + mp).
use eu4save::{Eu4File, Encoding, CountryTag, EnvTokens};
let data = std::fs::read("assets/saves/eng.txt.compressed.eu4")?;
let file = Eu4File::from_slice(&data)?;
let save = file.deserializer().build_save(&EnvTokens)?;
assert_eq!(file.encoding(), Encoding::TextZip);
assert_eq!(save.meta.player, "ENG".parse()?);
§Querying
Even once decoded, the data might be too low level. For example a country can have an income ledger that looks like:
income = { 1.000 0 2.000 0.000 1.500 }
While the structure will decoded successfully into a vector, the context of what each index means is missing. What value represents the income from trade?
To help solve questions like these, the Query
API was created
use eu4save::{Eu4File, Encoding, CountryTag, EnvTokens, query::Query};
use std::io::Cursor;
let data = std::fs::read("assets/saves/eng.txt.compressed.eu4")?;
let file = Eu4File::from_slice(&data)?;
let save = file.deserializer().build_save(&EnvTokens)?;
let save_query = Query::from_save(save);
let trade = save_query.country(&"ENG".parse()?)
.map(|country| save_query.country_income_breakdown(country))
.map(|income| income.trade);
assert_eq!(Some(17.982), trade);
§Ironman
By default, ironman saves will not be decoded properly.
To enable support, one must supply an environment variable
(EU4_IRONMAN_TOKENS
) that points to a newline delimited
text file of token descriptions. For instance:
0xffff my_test_token
0xeeee my_test_token2
PDS has declared that in order to comply with EU4’s terms of use, the list of tokens must not be shared. I am also restricted from divulging how the list of tokens can be derived.
You may look to other projects EU4 ironman projects like ironmelt or paperman for inspiration.
Modules§
- file
- Parsing and deserializing EU4 save files
- models
- Repository of raw structs extracted from a save file
- query
- Ergonomic module for querying info from a save file
Structs§
- Country
Tag - Wrapper around a Country’s unique three byte tag
- EnvTokens
- Builtin token resolver based on
EU4_IRONMAN_TOKENS
- Eu4Date
- Struct specialized to parsing, formatting, and manipulating dates in EU4 A date without a time component
- Eu4Error
- An EU4 Error
- Eu4File
- Entrypoint for parsing EU4 saves
- Eu4Melter
- Convert a binary save to plaintext
- Melted
Document - Output from melting a binary save to plaintext
- Province
Id - An province numerical identifier
- TagData
- A tag value and where it is stored in the save
- TagResolver
- Tracks tag progression throughput history
- TagResolver
Dated - Resolves tag up until a certain point in time
Enums§
- Encoding
- Describes the format of the save before decoding
- Eu4Error
Kind - Specific type of error
- Failed
Resolve Strategy - Customize how the deserializer reacts when a token can’t be resolved
Traits§
- PdsDate
- Common set of methods between all the date components
Functions§
- dlc_id
- Map dlc name to its id
- eu4_
start_ date - EU4’s start date