#ironman #eu4

bin+lib eu4save

Ergonomically work with all EU4 saves (ironman and multiplayer)

26 unstable releases (4 breaking)

0.5.3 Jul 4, 2021
0.5.1 May 29, 2021
0.4.3 Mar 14, 2021
0.3.3 Nov 10, 2020

#121 in Game dev

Download history 108/week @ 2021-05-29 97/week @ 2021-06-05 46/week @ 2021-06-12 44/week @ 2021-06-19 44/week @ 2021-06-26 79/week @ 2021-07-03 50/week @ 2021-07-10 71/week @ 2021-07-17 58/week @ 2021-07-24 122/week @ 2021-07-31 51/week @ 2021-08-07 79/week @ 2021-08-14 45/week @ 2021-08-21 42/week @ 2021-08-28 21/week @ 2021-09-04 23/week @ 2021-09-11

338 downloads per month

MIT license

3.5K SLoC

ci Version

EU4 Save

EU4 Save is a library to ergonomically work with EU4 saves (ironman + mp).

use eu4save::{Eu4Extractor, Encoding, CountryTag};
use std::io::Cursor;

let data = std::fs::read("assets/saves/eng.txt.compressed.eu4")?;
let (save, encoding) = Eu4Extractor::extract_save(Cursor::new(&data[..]))?;
assert_eq!(encoding, Encoding::TextZip);
assert_eq!(save.meta.player, CountryTag::from("ENG"));

Eu4Extractor will deserialize both plaintext (used for mods, multiplayer, non-ironman saves) and binary (ironman) encoded saves into the same structure.


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::{Eu4Extractor, Encoding, CountryTag, query::Query};
use std::io::Cursor;

let data = std::fs::read("assets/saves/eng.txt.compressed.eu4")?;
let (save, _encoding) = Eu4Extractor::extract_save(Cursor::new(&data[..]))?;
let save_query = Query::from_save(save);
let trade = save_query.save().game.countries.get(&CountryTag::from("ENG"))
    .map(|country| save_query.country_income_breakdown(country))
    .map(|income| income.trade);
assert_eq!(Some(17.982), trade);


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.


~55K SLoC