#hoi4 #ironman

bin+lib hoi4save

Ergonomically work with HOI4 saves

12 releases

0.2.1 Jul 8, 2022
0.1.9 Mar 20, 2022
0.1.7 Nov 24, 2021
0.1.6 Jul 4, 2021
0.1.2 Mar 14, 2021

#187 in Game dev

Download history 44/week @ 2022-04-21 107/week @ 2022-04-28 89/week @ 2022-05-05 206/week @ 2022-05-12 57/week @ 2022-05-19 85/week @ 2022-05-26 127/week @ 2022-06-02 44/week @ 2022-06-09 48/week @ 2022-06-16 47/week @ 2022-06-23 84/week @ 2022-06-30 96/week @ 2022-07-07 65/week @ 2022-07-14 92/week @ 2022-07-21 47/week @ 2022-07-28 50/week @ 2022-08-04

273 downloads per month

MIT license

24KB
546 lines

ci Version

HOI4 Save

HOI4 Save is a library to ergonomically work with Hearts of Iron IV saves (plaintext + binary).

use hoi4save::{Hoi4File, Encoding, EnvTokens, models::Hoi4Save};
let data = std::fs::read("assets/saves/1.10-normal-text.hoi4")?;
let file = Hoi4File::from_slice(&data)?;
let parsed_file = file.parse()?;
let save: Hoi4Save = parsed_file.deserializer().build(&EnvTokens)?;
assert_eq!(file.encoding(), Encoding::Plaintext);
assert_eq!(save.player, String::from("FRA"));

The HOI4 binary format can be converted to plaintext

use hoi4save::{Hoi4File, EnvTokens};

let data = std::fs::read("assets/saves/1.10-ironman.hoi4")?;
let file = Hoi4File::from_slice(&data)?;
let parsed_file = file.parse()?;
let binary = parsed_file.as_binary().unwrap();
let out = binary
    .melter()
    .on_failed_resolve(hoi4save::FailedResolveStrategy::Stringify)
    .melt(&EnvTokens)?;

Binary Saves

By default, binary saves will not be decoded properly.

To enable support, one must supply an environment variable (HOI4_IRONMAN_TOKENS) that points to a newline delimited text file of token descriptions. For instance:

0xffff my_test_token
0xeeee my_test_token2

In order to comply with legal restrictions, I cannot share the list of tokens. I am also restricted from divulging how the list of tokens can be derived.

Dependencies

~1.1–1.8MB
~41K SLoC