Skip to content

Fix Steam P2P join: resolve lobby in-process instead of worker (DllNotFoundException steam_api64) - #59

Merged
vaiserYT merged 1 commit into
vaiserYT:mainfrom
TenerexBlatta:steam-join-fix
Nov 9, 2026
Merged

vaiserYT merged 1 commit into
vaiserYT:mainfrom
TenerexBlatta:steam-join-fix

Conversation

@TenerexBlatta

Copy link
Copy Markdown
Contributor

Problem

Hosting via Steam P2P works, but accepting a Steam invite on the joining side fails:

[NetMod][Steam] TryResolveJoinEndpointFromLobbyId failed: lobbyId=... error=System.DllNotFoundException:
Unable to load DLL 'steam_api64' or one of its dependencies (0x8007007E)
   at Steamworks.NativeMethods.SteamAPI_RestartAppIfNecessary(AppId_t unOwnAppID)
   at DeadCellsMultiplayerMod.SteamConnect.ExecuteWorkerRequest(...) in SteamP2P\SteamConnect.cs:line 949
   at DeadCellsMultiplayerMod.SteamConnect.WorkerEntry() in SteamP2P\SteamConnect.cs:line 923

Reproduced on two Windows 10 x64 PCs with clean installs (Dead Cells v35 Steam, DCCM 35.13.5, mod 0.5.1, .NET 10.0.14, VC++ 2015–2022 x64).

Cause

The join path (TryResolveJoinEndpointFromLobbyId / TryResolveJoinEndpointFromClipboard) always starts the separate worker process, which has to load steam_api64.dll and init Steam again:

  1. In the worker, PrepareSteamNativePath() calls SetDllDirectory, but the Steamworks.NET DllImport doesn't pick that path up, so steam_api64 isn't found. In the game process it works only because DCCM's steam.hdll already loaded the module.
  2. When the DLL is found (for example after copying it next to Steamworks.NET.dll in coremod\core\host\), the worker calls SteamAPI.RestartAppIfNecessary(588650). In a helper process that Steam didn't launch, this can make Steam relaunch the game. After that, the real game failed Steam init on every boot until Steam was restarted.

Fix

Only SteamP2P/SteamConnect.cs changes:

  • Resolve the lobby in-process first. The game process already has SteamAPI initialized, and the P2P host already runs in-process (SteamP2PInProcessBridge.TryStartHost). The new TryRunJoin → TryRunJoinInProcess runs the existing ExecuteJoin on the existing background Task.Run thread. It doesn't take the pump lock and doesn't call SteamAPI.RunCallbacks itself: a [ThreadStatic] flag makes RunWorkerSteamCallbacks a no-op there, and the main-thread title/frame hooks keep pumping callbacks. That avoids the off-main-thread RunCallbacks crash the code comments warn about. The worker is only a fallback when in-process Steam is unavailable. Definitive errors (wrong build, own lobby, not joinable) aren't retried through the worker.
  • Remove RestartAppIfNecessary from the worker. It sets the SteamAppId/SteamGameId env vars instead.
  • Preload steam_api64.dll by full path (NativeLibrary.Load) in PrepareSteamNativePath, so later by-name loads reuse it.

BuildInfo and the network protocol are untouched, so patched and unpatched peers stay compatible.

Testing

  • The same change on top of tag 0.5.1 (branch steam-join-fix-0.5.1 in my fork) was tested on two machines. Joining through a Steam overlay invite now works; before, it failed with the DllNotFoundException above every time.
  • This branch (on top of current main) builds with 0 warnings and 0 errors (Release, DCCM MDK 35.13.5). The patch applied cleanly, but I haven't play-tested it yet.

🤖 Generated with Claude Code

…orker

Joining a Steam P2P lobby always spawned the separate worker process, which
must load steam_api64.dll and init Steam again. On some installs that throws
DllNotFoundException('steam_api64'), and when the DLL is found the worker's
SteamAPI.RestartAppIfNecessary can make Steam relaunch the game, after which
the real game fails "Steam init" until Steam is restarted.

- Resolve the lobby in the game process first (TryRunJoin ->
  TryRunJoinInProcess), using the SteamAPI the game already initialized, like
  the in-process P2P host. It runs on the existing background task, never
  takes the pump lock or calls RunCallbacks off the main thread; the worker is
  only a fallback when in-process Steam is unavailable.
- Remove RestartAppIfNecessary from the worker; set SteamAppId/SteamGameId.
- Preload steam_api64.dll by full path in PrepareSteamNativePath.
@TenerexBlatta
TenerexBlatta deleted the steam-join-fix branch November 8, 2026 23:43
@TenerexBlatta
TenerexBlatta restored the steam-join-fix branch November 8, 2026 23:44
@TenerexBlatta TenerexBlatta reopened this Nov 8, 2026
@vaiserYT
vaiserYT merged commit 10d895b into vaiserYT:main Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants