Skip to content

Telemetry and Save Parsing

buntatoes edited this page Nov 28, 2026 · 1 revision

Telemetry and Save Parsing

EU5 RPC combines five strictly read-only telemetry subsystems to track your Europa Universalis V campaign accurately across singleplayer, multiplayer, observer mode, mid-game nation swaps, formables, custom nations, and all 11 official languages — without ever reading game process memory or modifying game files.


Telemetry Priority & Merging

flowchart TD
    A["1. Process Detection (process.zig)"] -->|Game running| B["2. Passive Steam Rich Presence (steam_rp.zig)"]
    B -->|Country, Year, Status, Phase, MP/Observer| E["GameState"]
    A -->|Game running| C["3. Live Log Tailing (log_watcher.zig)"]
    C -->|Transitions, Version, New Country, Wars, Disasters, Exploration, Year| E
    C -->|Fallback if Steam has no country + version sync| D["4. Save & continue_game.json (save_inspector.zig)"]
    D -->|Tag, Country, Date, Version| E
    F["5. CountryLookup (country_lookup.zig)"] -->|Tag -> Localized Name| C
    F -->|Tag -> Localized Name| D
Loading
  1. Steam Rich Presence provides instant localized country names (including dynamic/formable/custom nation names), current year, live status text, lobby/main-menu phase, and multiplayer/observer flags.
  2. Live Log Tailing captures exact engine phase transitions, game version, multiplayer host status (Is Multiplayer Host: true), immediate tag swaps (New Country: <TAG>), yearly ticks (NEW YEAR:), situation start dates, wars, civil wars, explorations, and disasters.
  3. Save Header Inspection supplements missing country/date/version data using continue_game.json and the newest .eu5 save written during the current session (only when Steam Rich Presence did not already report a country).

1. Native Process Detection (src/process.zig)

EU5 RPC detects whether Europa Universalis V is running without spawning helper subprocesses (tasklist, pgrep, ps) and without opening process memory:

  • Windows: Uses CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0) + Process32First/Process32Next, matching szExeFile case-insensitively against eu5.exe.
  • Linux: Scans numeric PIDs in /proc (skipping its own PID), checking:
    1. /proc/<pid>/comm against eu5.exe or eu5.
    2. /proc/<pid>/cmdline via cmdlineMatchesTarget(), which supports:
      • Native Linux binaries (.../binaries/eu5)
      • Direct Wine/Proton Windows paths (including single-string argv with trailing flags like Z:\...\binaries\eu5.exe -gdpr)
      • Leading env [FLAGS] [VAR=VAL ...] wrappers
      • Wine/Proton wrappers: wine, wine64, wine-preloader, wine64-preloader, proton, umu-run
      • Linux runtime/overlay wrappers: reaper, pressure-vessel-adverb, srt-bwrap, bwrap, gamemoderun, gamescope, mangohud, steam-run, prime-run
      • Python-invoked Proton/umu launchers (python, python3, python3.* running proton, proton.py, or umu-run)
    • False-Positive Guards: Explicitly avoids matching eu5-rpc, steam -applaunch 3450310, shell commands (bash -c echo eu5.exe), env FOO=1 echo eu5.exe, unrelated Python scripts, or similarly named executables (my_eu5.exe).

When the user selects Quit (Close EU5 & RPC) from the tray menu, closeEu5() attempts a graceful shutdown first (WM_CLOSE via EnumWindows on Windows; SIGTERM on Linux), waits up to 3,000 ms, and only falls back to TerminateProcess / SIGKILL if the process remains unresponsive.


2. Passive Steam Rich Presence (src/steam_rp.zig)

EU5 publishes rich live campaign status to your local Steam client. EU5 RPC reads those strings passively from your local Steam client library without calling SteamAPI_Init:

  • Sets SteamAppId=3450310 and SteamGameId=3450310 in its own process environment to scope its IPC pipe to EU5.
  • Dynamically loads steamclient64.dll (Windows) or steamclient.so (Linux — searching STEAM_COMPAT_CLIENT_INSTALL_PATH, XDG_DATA_HOME, native/Debian/Flatpak/Snap Steam paths, and /usr/lib/steam/linux64/steamclient.so).
  • Calls CreateInterface("SteamClient021") and opens a local IPC pipe (CreateSteamPipe -> ConnectToGlobalUser) to acquire SteamUser023 and SteamFriends017.
  • Reads the local user's own SteamID (GetSteamID, handling the Windows x64 hidden-pointer ABI vs. System V AMD64 direct u64 return) and queries RequestFriendRichPresence, GetFriendRichPresenceKeyCount, GetFriendRichPresenceKeyByIndex, and GetFriendRichPresence for status, steam_display, country, and year.
  • Disconnects (ReleaseUser + ReleaseSteamPipe) immediately when EU5 exits.

Paradox Formatting Stripping

cleanPdxText() strips Paradox rich-text formatting directives such as #V Kingdom of France#! -> Kingdom of France, while preserving raw token keys (#main_menu, #in_lobby, #playing, #playing_mp, #playing_observer, #playing_observer_mp).

All 11 Official EU5 Languages Supported

parsePresenceFields() includes UTF-8 case-folding (including Latin diacritics, Polish, Turkish İ, and Cyrillic Ё), fullwidth parenthesis/comma handling ((), 、, ,), and Russian NBSP (\u00A0) handling for every official EU5 language:

Language In-Game Pattern Multiplayer Tag Main Menu / Lobby
English <STATUS> as <COUNTRY>, <YEAR> (Multiplayer) In Main Menu / In Lobby
Brazilian Portuguese <STATUS> como <COUNTRY>, <YEAR> (Multijogador) No Menu Principal / No Lobby
French <STATUS> en tant que <COUNTRY>, <YEAR> (Multijoueur) Dans le menu principal / Dans le salon
German <STATUS> als <COUNTRY>, <YEAR> (Mehrspieler) Im Hauptmenü / In der Lobby
Spanish <STATUS> como <COUNTRY>, <YEAR> (Multijugador) En el menú principal / En sala
Polish <STATUS> jako <COUNTRY>, <YEAR> (gra wieloosobowa) W menu głównym / W lobby
Russian <STATUS> за державу <COUNTRY>, <YEAR> год (многопользовательская игра) В главном меню / В лобби
Turkish <COUNTRY> olarak <STATUS>, <YEAR> (Çok Oyunculu) Ana Menüde / Lobide
Japanese <COUNTRY>として<STATUS>、<YEAR> (マルチプレイ) メインメニュー / ロビー
Korean <YEAR>, <COUNTRY>(으)로 <STATUS> (멀티플레이어) 메인 메뉴 / 로비
Simplified Chinese 作为<COUNTRY><STATUS>,<YEAR>年 (多人游戏) 位于主菜单 / 位于多人游戏大厅

Observer strings (e.g., Observing, Observando, Observe , Beobachtet, 観測中, 관전 중, Obserwuje, Наблюдает, 观察世界, İzliyor) and raw #playing* fallback tokens are also parsed automatically.


3. Live Log Tailing (src/log_watcher.zig)

EU5 RPC tails three Paradox log files incrementally inside the detected user data folder using a 2 MiB resync cap (RESYNC_BYTES = 2 * 1024 * 1024):

  • If EU5 is not running at startup, seedInitialOffsets() skips log files older than session_started_at - 3s so stale data from previous sessions is never replayed.
  • If a log shrinks (truncated on a new EU5 launch), the read offset automatically resets to 0.
  • If the active user data directory changes (for example, switching between Native Linux and Proton), refreshUserDataDir() picks the folder with the newest log/JSON activity mtime and resets offsets.

Parsed Log Signals

Log File Pattern Effect on GameState
logs/debug.log game version <X.Y.Z[.W]> Sets game_version
logs/debug.log Running Transition <From>-><To> Maps SplashScreen / LoadingScreen -> .loading, MainMenu -> .main_menu, Game -> .in_game, Empty -> .not_running
logs/multiplayer.log Is Multiplayer: true|false Sets multiplayer
logs/multiplayer.log Is Multiplayer Host: true|false Sets multiplayer_host
logs/multiplayer.log _Player Is Observer: true|false Sets observer
logs/multiplayer.log New Country: <TAG> Resolves <TAG> via CountryLookup, updates country/tag, clears previous active event, enters .in_game (No / None clears country)
logs/multiplayer.log Destroying gamestate Clears active_event
logs/game.log NEW YEAR: <YYYY> (>= 1337) Updates year and date
logs/game.log SITUATION: ... starts on <D> <Month>, <YYYY> Updates year and date if newer or unset
logs/game.log WAR: <Attacker> declared war on <Defender> Sets At War with <Defender> or Defending vs. <Attacker> when matching player country
logs/game.log CIVIL WAR: <Rebels> against <Target> Sets In a Civil War when matching player country
logs/game.log EXPLORATION: <Country> discovered ... L;<Area>! Sets Explored <Area> when matching player country
logs/game.log DISASTER: <snake_name> starts|ends in <TAG> Title-cases to Disaster: <Nice Name> on starts, clears active event on ends

4. Save File & continue_game.json Inspection (src/save_inspector.zig)

Strictly read-only inspection without modifying saves or checksums:

  1. continue_game.json: Always checked for rawGameVersion (and title if needed) using a zero-allocation JSON string extractor.
  2. Newest .eu5 Save: Scans <user_data_dir>/save games/*.eu5 for the most recently modified file. During live gameplay, saves are only read if their mtime (or continue_game.json mtime) is within the current session (>= session_started_at - 5s) and only when Steam Rich Presence did not already supply a country.
  3. Filename Parsing: Parses Paradox's naming pattern:
    (SP|MP)_<TAG>_<YYYY>_<MM>_<DD>_... .eu5
    
    Extracts multiplayer (SP_ vs. MP_), country_tag, year, and date (YYYY.M.D).
  4. Binary Header Parsing: Reads only the first 2 KiB (2048 bytes) of the .eu5 file (opened with full Windows shared-read/write/delete flags) to extract:
    • Date & localized country name (<YYYY.M.D> - <Country Name>, stripping trailing #<hex> suffixes)
    • 3-character tag block (<TAG>={)
    • Game version (<X.Y.Z>)

5. User Data Folder & Game Install Discovery (src/eu5_files.zig)

When user_data_folder is empty in config.toml, EU5 RPC evaluates all candidate directories and selects the one with the most recently modified EU5 activity file (logs/debug.log, logs/game.log, logs/multiplayer.log, or continue_game.json), falling back to the first existing directory:

  • Windows:
    1. SHGetFolderPathW(CSIDL_PERSONAL) (automatically resolves OneDrive-redirected and localized Documents folders) + \Paradox Interactive\Europa Universalis V
    2. Registry HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders -> Personal
    3. %USERPROFILE%\OneDrive\Documents\Paradox Interactive\Europa Universalis V and %USERPROFILE%\Documents\Paradox Interactive\Europa Universalis V
  • Linux:
    1. $XDG_DATA_HOME/Paradox Interactive/Europa Universalis V and $XDG_DATA_HOME/Steam
    2. $STEAM_COMPAT_DATA_PATH/pfx, $WINEPREFIX, and $STEAM_COMPAT_CLIENT_INSTALL_PATH
    3. Proton prefixes (steamapps/compatdata/3450310/pfx/drive_c/users/<steamuser|$USER>/Documents/Paradox Interactive/Europa Universalis V) across standard, Debian, Flatpak, and Snap Steam roots plus every Steam library drive listed in steamapps/libraryfolders.vdf and config/libraryfolders.vdf
    4. Native Linux paths (~/.local/share/Paradox Interactive/Europa Universalis V, ~/.paradoxinteractive/Europa Universalis V, Flatpak/Snap Steam data dirs, ~/Documents/Paradox Interactive/Europa Universalis V)

Game install discovery (findEu5GameInstallDir) similarly parses libraryfolders.vdf and steamapps/appmanifest_3450310.acf (installdir) across all drives.


6. Dynamic CountryLookup & Historical Ages

CountryLookup (src/country_lookup.zig)

On startup (or when EU5 is first detected), EU5 RPC reads two localization files from <EU5 Install Dir>/game/main_menu/localization/english/:

  • country_names_l_english.yml
  • formable_countries_l_english.yml

It parses entries matching <TAG>:<optional_version> "<Name>" (skipping dynamic $VARIABLE$ placeholders) into an arena-backed hash map covering all ~2,350+ nations and formables. If the game install cannot be located, it falls back to 54 built-in common starting/major tags (such as FRA -> France, BYZ -> Byzantium, CAS -> Castile, TUR -> Ottomans, KOR -> Goryeo, YUA -> Yuan), and finally to the uppercased tag itself. Tags "NO" and "NONE" resolve to null.

Six Historical Ages (src/game_state.zig)

Year Range Historical Age
1337 – 1436 Age of Traditions
1437 – 1536 Age of Renaissance
1537 – 1636 Age of Discovery
1637 – 1736 Age of Reformation
1737 – 1836 Age of Absolutism
1837+ Age of Revolutions
< 1337 (none)

Clone this wiki locally