# Victoria3-Tools Tools and written procedures for reading and surgically editing Victoria 3 `.v3` save files, and for researching game mechanics from the shipped scripts. Verified against **Victoria 3 1.13.11**. Paths in the docs are for the Linux Steam install. ## What's here | Path | Contents | |---|---| | `lib/pdxsave.py` | Byte-exact save reader/writer: container, compression and checksum. Its output is byte-identical to saves the game writes. | | `lib/murinv.py` | Pure-Python murmur3-32 (fallback when `mmh3` isn't installed) and inverter | | `lib/salt_attach.gdb` | gdb script used to recover the checksum salt from the running game | | `tools/reroll.py` | Rerolls pending RNG outcomes (law enactments, queued events, the global stream) | | `operations/` | Step-by-step procedures for specific edits and investigations | | `CLAUDE.md` | Entry point and rules for AI agents working in this repo | ## Setup Python 3.10+. `mmh3` is optional but much faster for checksums (~35 ms vs ~3 s on a 20 MB save): ```bash python3 -m venv .venv .venv/bin/pip install mmh3 ``` ### Steam ID (required for writing saves) Every save carries a checksum salted with the player's SteamID64. A save written with the wrong salt still loads, but that save line **permanently loses achievement eligibility**. The ID is not stored in the repo; provide it one of two ways: ```bash export VIC3_STEAM_ID=7656119XXXXXXXXXX # or echo 7656119XXXXXXXXXX > lib/steam_id.local # gitignored ``` `SteamID64 = 76561197960265728 + account_id`, where `account_id` is the numeric directory under `~/.steam/*/userdata/`. The game also logs it at startup as `Caching Steam ID: …`. See `operations/achievements.md`. ### rakaly (for reading) Melting a save to text for inspection uses the [rakaly CLI](https://github.com/rakaly/cli/releases). It is a reader only; edits are made in the binary token stream. See `operations/melt-and-inspect.md`. ## Usage ### Writing a save ```python import sys; sys.path.insert(0, 'lib') from pdxsave import read_save, write_save, fix_checksum, vic3_checksum preamble, entries, order = read_save('in.v3') # ... patch entries['gamestate'] (binary tokens) ... write_save('out.v3', preamble, entries, order) fix_checksum('out.v3') raw = open('out.v3', 'rb').read() assert int(raw[7:15], 16) == vic3_checksum(raw) ``` Always write to a new file and leave the original untouched. ### Rerolling RNG ```bash .venv/bin/python tools/reroll.py --list # show what would change .venv/bin/python tools/reroll.py # newest save, all targets, prompts first .venv/bin/python tools/reroll.py --enactments # law enactments only ``` Writes `REROLL.v3` into the save folder with a valid checksum. See `operations/reroll-rng.md` for all options. ## Operations | File | Covers | |---|---| | `save-file-format.md` | Container anatomy, header flags, the relative-offset trap, rebuild recipe | | `melt-and-inspect.md` | Getting rakaly, melting, locating things in a 100 MB+ dump | | `token-editing.md` | Binary token encoding, the 1.13.11 token table, patch/insert/delete recipes | | `achievements.md` | The save checksum and how to keep achievements | | `law-enactment.md` | Enactment phases, advancing or passing a law | | `construction-queue.md` | Construction queues, finishing queued buildings | | `timed-modifiers.md` | Adding and removing timed modifiers | | `characters-and-event-scopes.md` | Character records, changing which character an event picked | | `diplomacy-and-relations.md` | Relations, pacts, subjects | | `war-goals-and-peace.md` | War goals, infamy, war support, peace outcomes | | `civil-war-and-revolutions.md` | Reading and defusing civil wars and revolutions | | `colonization.md` | Colony progress and colonizable targets | | `research-and-technology.md` | Technology records and research progress | | `pops-literacy-and-qualifications.md` | Pop records, literacy, qualifications | | `economy-diagnosis.md` | Reading the budget, finding what drains money | | `game-data-research.md` | Answering mechanics questions from scripts, defines and localization | | `reroll-rng.md` | `tools/reroll.py` | ## Caveats - The token table and formats are version-specific. A different game version may change token ids. - Edited saves use the game's own format and a correct checksum, but an edit can still leave game state inconsistent. Keep the original save. ## License MIT — see [LICENSE](LICENSE). Victoria 3 is a trademark of Paradox Interactive; this project is not affiliated with or endorsed by Paradox.