Repository navigation
Deadlock Detection and State Machine
RubyLock RPC reconstructs Deadlock's live state by combining two lightweight, read-only signals:
-
ProcessWatcher(lib/rubylock_rpc/process_watcher.rb) — detects whendeadlock.exestarts or exits. -
LogWatcher(lib/rubylock_rpc/log_watcher.rb) — tails Deadlock's-condebugoutput file (game/citadel/console.log) and feeds structured transitions intoGameState(lib/rubylock_rpc/game_state.rb).
| Phase Constant | Symbol | Hero Portrait Shown? | Description |
|---|---|---|---|
NOT_RUNNING |
:not_running |
No | Deadlock process is not active or has shut down. |
MAIN_MENU |
:main_menu |
No | Deadlock is running (or console.log initialized), before entering Hideout. |
HIDEOUT |
:hideout |
Yes | Local player is in dl_hideout. Displays hero-specific Hideout flavor text and party headcount when party_size > 1. |
IN_QUEUE |
:in_queue |
Yes | Player is searching for a match (k_EMsgClientToGCStartMatchmaking). Displays Hideout line as details and matchmaking text as state. |
MATCH_INTRO |
:match_intro |
Yes | Lobby created or non-loopback server connected; loading into match or intro phase. |
IN_MATCH |
:in_match |
Yes | Active match gameplay on a non-hideout map. Tracks elapsed match duration via Process::CLOCK_MONOTONIC. |
POST_MATCH |
:post_match |
No | Match lobby destroyed, disconnected from match server, or ChangeGameState: PostGame (6). |
SPECTATING |
:spectating |
No | Watching a live broadcast (Playing Broadcast). Hero signals and map changes are ignored while spectating. |
| Mode Constant | Display Name | Uses in_match Template? |
How Detected |
|---|---|---|---|
STANDARD |
"Standard Match" |
Yes | Map street_test / street_test_bridge, or dl_midtown with >= 9 players. |
RANKED |
"Ranked Match" |
Yes | Defined mode display & template support. |
STREET_BRAWL |
"Street Brawl" |
Yes |
dl_midtown with 4..8 players (pending_player_count >= 4 and < 9). |
BOT_MATCH |
"Bot Match" |
No (uses display name + timer) |
Initializing bot for player slot <N>: k_ECitadelBotDifficulty_* while mode is UNKNOWN. |
TRAINING_RANGE |
"Training Range" |
No (uses display name + timer) | Map new_player_basics. Allows free hero swapping. |
HERO_LABS |
"Hero Labs" |
No (uses display name + timer) | Allows free hero swapping. |
UNKNOWN |
"In Match" |
Yes | Fallback when a match map is loaded before player count or bot lines resolve the mode. |
stateDiagram-v2
[*] --> NOT_RUNNING
NOT_RUNNING --> MAIN_MENU : deadlock.exe detected / console.log found
MAIN_MENU --> HIDEOUT : Map dl_hideout
HIDEOUT --> IN_QUEUE : k_EMsgClientToGCStartMatchmaking
IN_QUEUE --> HIDEOUT : k_EMsgClientToGCStopMatchmaking
MAIN_MENU --> IN_QUEUE : k_EMsgClientToGCStartMatchmaking
HIDEOUT --> MATCH_INTRO : Lobby created / Remote server connect
IN_QUEUE --> MATCH_INTRO : Lobby created / Remote server connect
MAIN_MENU --> MATCH_INTRO : Lobby created / Remote server connect
MATCH_INTRO --> IN_MATCH : Non-hideout map physics / ChangeGameState GameInProgress (7)
HIDEOUT --> IN_MATCH : Non-hideout map loaded directly
IN_MATCH --> POST_MATCH : Lobby destroyed / Disconnect / LoopMode menu / PostGame (6)
MATCH_INTRO --> POST_MATCH : Server disconnect / LoopMode menu
POST_MATCH --> HIDEOUT : Map dl_hideout
HIDEOUT --> SPECTATING : Playing Broadcast
MAIN_MENU --> SPECTATING : Playing Broadcast
SPECTATING --> POST_MATCH : Server disconnect / LoopMode menu
IN_MATCH --> NOT_RUNNING : deadlock.exe exited / EXITING / Source2Shutdown / 300s stale
HIDEOUT --> NOT_RUNNING : deadlock.exe exited / EXITING / Source2Shutdown
Every line read from game/citadel/console.log is evaluated by LogWatcher.process_line(line, state). The table below documents every log signature recognized by RubyLock RPC:
| Pattern Key | Regex / Substring | Effect on GameState
|
|---|---|---|
local_account_id |
/\[U:1:(\d+)\]/ |
Captures the local player's Steam3 account ID (first positive match) for party reconciliation and optional Statlocker link. |
party_event |
/CMsgGCToClientPartyEvent:\s+\{\s*party_id:\s+(\d+)\s+event:\s+(k_e\w+)\s+initiator_account_id:\s+(\d+)\s*\}/ |
Updates party membership on joinedparty, leftparty / removedfromparty / kickedfromparty, and disband events. |
map_created_physics |
/\[Client\] Created physics for\s+([^\s]+)/ |
Applies map change (dl_hideout -> HIDEOUT; other maps -> IN_MATCH + mode inference). |
map_info |
/\[Client\] Map:\s+"([^"]+)"/ |
Applies map change (ignoring "start" and "<empty>"). |
| (substring) | "k_EMsgClientToGCStartMatchmaking" |
Enters IN_QUEUE from HIDEOUT or MAIN_MENU. |
| (substring) | "k_EMsgClientToGCStopMatchmaking" |
Leaves IN_QUEUE back to HIDEOUT. |
lobby_created |
/Lobby\s+\d+\s+for\s+Match\s+\d+\s+created/ |
Prepares match hero tracking and enters MATCH_INTRO (from menu/hideout/queue/intro). |
lobby_destroyed |
/Lobby\s+\d+\s+for\s+Match\s+\d+\s+destroyed/ |
Transitions to POST_MATCH and clears match_started_at. |
spectate_broadcast |
/Playing Broadcast/ |
Enters SPECTATING and sets hideout_loaded = false. |
server_connect |
/\[Client\] CL:\s+Connected to '([^']+)'/ |
For non-loopback addresses, prepares match hero tracking and enters MATCH_INTRO. |
loaded_hero |
/\[Server\] Loaded hero \d+\/(hero_\w+)/ |
Normalizes hero key and calls apply_hero_signal (ignored in HIDEOUT until hideout_loaded is true to avoid precache noise). |
client_hero_vmdl |
`/VMDL Camera Pose Success!.*models/heroes(?:_wip | _staging)?/(\w+)//` |
server_disconnect |
/\[Client\] Disconnecting from server:\s+(\S+)/ |
Resets state if reason includes EXITING; transitions active match/intro/spectating to POST_MATCH unless reason includes LOOPDEACTIVATE. |
loop_mode_menu |
/LoopMode:\s*menu/ |
Transitions IN_MATCH, MATCH_INTRO, or SPECTATING to POST_MATCH. |
change_game_state |
/ChangeGameState:\s+(\w+)\s+\((\d+)\)/ |
Ignored while spectating or in Hideout. Maps MatchIntro/4 -> MATCH_INTRO, GameInProgress/InProgress/7 -> start_match, PostGame/6 -> POST_MATCH. |
hideout_lobby_state |
/\[Hideout\] Hideout Lobby Connection State:\s+(\w+)\s+\((-?\d+)\)/ |
Clears party if lobby ID is 0 while in HIDEOUT. |
host_activate |
/\[HostStateManager\] Host activate:.*\(([^)]+)\)/ |
Marks hideout_loaded = true once dl_hideout activates. |
server_shutdown |
/\[Server\] SV:\s+Server shutting down:\s+(\S+)/ |
Resets state if reason contains EXITING. |
| (substrings) |
"Dispatching EventAppShutdown_t" or "Source2Shutdown"
|
Full state.reset on clean Source 2 engine shutdown. |
precaching_heroes |
/Precaching (\d+) heroes in CCitadelGameRules/ |
Sets hideout_loaded = false when count > 0 so bulk hero precaching does not overwrite the active hero. |
player_info |
/\[Client\] Players:\s+(\d+)\s+\(\d+ bots\)\s+\/\s+\d+ humans/ |
In HIDEOUT, reconciles Hideout player count into party_size (max 6). In MATCH_INTRO/IN_MATCH, records peak pending_player_count and triggers mode inference. |
bot_init |
/Initializing bot for player slot \d+:\s+k_ECitadelBotDifficulty_\w+/ |
Sets match_mode = BOT_MATCH when mode is still UNKNOWN during MATCH_INTRO or IN_MATCH. |
Deadlock console logs emit hero identifiers in several formats (for example hero_inferno_v2, ratking, or models/heroes/haze/haze.vmdl). Normalization converts them into canonical hero_<name> keys:
- Lowercases the raw string.
- Strips trailing version suffixes matching
_v<digits>(e.g.,hero_inferno_v2->hero_inferno,hero_ratking_v2->hero_ratking). - Prepends
hero_if not already present (e.g.,haze->hero_haze).
During a real match, Source 2 loads models for enemy and teammate heroes as well as the local player. To keep Rich Presence locked onto your hero:
-
In
MATCH_INTROandIN_MATCH:- When entering a match (
enter_match_intro/prepare_match_hero_tracking),@hero_keyis cleared and@hero_window_openis set totrue. - The first hero signal received locks
@hero_keyand closes@hero_window_open = false; subsequent different hero signals are ignored. -
Exception: In
TRAINING_RANGEandHERO_LABS,free_swapis enabled so switching heroes on the fly updates Discord immediately.
- When entering a match (
-
In
HIDEOUT: Hero signals are accepted freely oncehideout_loadedistrue(after[HostStateManager] Host activate: (dl_hideout)), so swapping heroes in the Hideout updates your portrait and flavor text immediately without being polluted by initial hero precaching. -
In
MAIN_MENU,POST_MATCH, andSPECTATING: Hero signals are ignored.
RubyLock RPC combines two sources to keep Hideout party headcounts accurate (clamped to 1..6):
-
GC Party Events (
CMsgGCToClientPartyEvent): Tracks knownparty_membersby account ID onjoinedparty/leftparty/removedfromparty/kickedfromparty/disband. When the local player joins a party,party_unknown_membersstarts at1to account for the host/other member(s) already present before subsequent events arrive. -
Hideout Player Count (
[Client] Players: N ...):apply_hideout_player_count(count)clampscountto6and reconciles@party_unknown_members = [clamped - @party_members.size, 0].max, ensuring the displayed(X of 6)badge in Discord reflects everyone physically in the Hideout even if RubyLock RPC was started mid-party.
LogWatcher#run handles every real-world lifecycle edge case of console.log:
-
Mid-Session Startup (
RESYNC_BYTES = 10 MiB): If RubyLock RPC starts after Deadlock is already running, it seeks to[file_size - 10 MiB, 0].max(skipping the first partial line if seeking past byte0), entersMAIN_MENU, and replays the tail slice to immediately reconstruct your current phase, map, mode, hero, account ID, and party size. -
Log Truncation: When Deadlock restarts and overwrites
console.log,file_size < last_postriggers an immediate reset and resync from byte0. -
Log Removal: If
console.logdisappears after initialization,GameStateresets and logs the session duration. -
Crash Staleness (
MATCH_STALE_SECS = 300): If Deadlock crashes silently duringIN_MATCHorMATCH_INTROand no bytes are appended toconsole.logfor 300 seconds,LogWatcherassumes a crash and resetsGameState. -
Invalid UTF-8 Protection: Bytes are read in binary mode (
"rb") and transcoded withencode("UTF-8", invalid: :replace, undef: :replace)so malformed console bytes never crash the watcher thread.
RubylockRpc::ProcessWatcher polls every 3 seconds (POLL_INTERVAL_S = 3) for deadlock.exe without spawning external shells or tools (tasklist, pgrep, or ps):
-
Windows (
Win32SnapshotviaFiddle):- Dynamically binds
CreateToolhelp32Snapshot,Process32First,Process32Next, andCloseHandlefromkernel32.dll. - Uses architecture-aware
PROCESSENTRY32layout (EXE_NAME_OFFSET = 44, total304bytes on 64-bit Windows;36/296bytes on 32-bit Windows). - Never flashes a console window when running under
rubyw.exe.
- Dynamically binds
-
Linux (
/procfilesystem):- Scans
/proc/[0-9]*, checking bothcommand the basename of the first NUL-delimited argument incmdline(normalizing\to/so Proton/Winedeadlock.exeprocesses match seamlessly). - Matches both
"deadlock.exe"and its stem"deadlock"case-insensitively.
- Scans
Copyright (c) 2026 Buntato (buntatoes). RubyLock RPC is free software licensed under the GNU General Public License v3.0 (GPL-3.0), based on the upstream GPL-3.0 project HeyTariq/deadlock-rpc. Not affiliated with or endorsed by Valve Corporation.
Getting Started
Core Architecture
- Architecture and Internals
- Deadlock Detection and State Machine
- Discord IPC and Rich Presence
- System Tray and Auto-Updater
Safety, Dev & Support
Links