windows: retry the first start instead of hiding a Steam setting
The 'Unable to initialize Steam' box comes from the server's first start after an install, with or without Steam running; the registry workaround was not the fix. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
153e44b661
commit
1cf0032927
3 files changed
+25
-23
No files matched your search
+23
-21
@@ -334,31 +334,33 @@ function Start-CsServer($root) {
|
||||
$y = $y -replace '(?m)^yb_difficulty ".*"', ('yb_difficulty "' + [int]$s.CS_BOT_DIFFICULTY + '"')
|
||||
Write-TextFile $ycfg $y
|
||||
$hargs = "-console -condebug -game cstrike -port $([int]$s.CS_PORT) +maxplayers $([int]$s.CS_MAXPLAYERS) +map $($s.CS_MAP) +log on"
|
||||
Restore-SteamClientSetting
|
||||
# With Steam installed, the server's steam_api.dll loads the Steam client's steamclient.dll
|
||||
# (found through this registry value) instead of its own, and stops with "Unable to initialize
|
||||
# Steam". So the value is hidden until the server answers queries (Steam is set up by then:
|
||||
# a few seconds) or gives up. Steam writes it again at every start, and
|
||||
# Restore-SteamClientSetting (run whenever a script loads this file) repairs an interrupted run.
|
||||
# (A 64-bit PowerShell can't see the 32-bit server's DLLs, so the query is the signal.)
|
||||
$hidden = $false
|
||||
if ((Get-ItemProperty -Path $Script:SteamKey -ErrorAction SilentlyContinue).SteamClientDll) {
|
||||
Rename-ItemProperty -Path $Script:SteamKey -Name SteamClientDll -NewName $Script:SteamHidden
|
||||
$hidden = $true
|
||||
}
|
||||
try {
|
||||
# On the very first start after an install, the server's Steam part sets itself up (appcache,
|
||||
# config) and the server stops with a "Fatal error: Unable to initialize Steam" box. The next
|
||||
# start works, so that one case gets a second try.
|
||||
for ($try = 1; $try -le 2; $try++) {
|
||||
$p = Start-Process -FilePath (Join-Path $h 'hlds.exe') -WorkingDirectory $h -ArgumentList $hargs -PassThru
|
||||
if ($hidden) {
|
||||
$end = (Get-Date).AddSeconds(90)
|
||||
while ((Get-Date) -lt $end -and -not $p.HasExited) {
|
||||
if (Get-A2SInfo '127.0.0.1' ([int]$s.CS_PORT) 1000) { break }
|
||||
Start-Sleep -Milliseconds 500
|
||||
}
|
||||
}
|
||||
} finally { if ($hidden) { Restore-SteamClientSetting } }
|
||||
if (-not (Test-SteamFailure $p ([int]$s.CS_PORT))) { break }
|
||||
Stop-Process -Id $p.Id -Force -ErrorAction SilentlyContinue
|
||||
if ($try -eq 1) { Write-Host ' (first start: Steam needed a second try)' }
|
||||
}
|
||||
return $true
|
||||
}
|
||||
|
||||
# Waits up to 40 s for the server to answer or to show the "Unable to initialize Steam" box.
|
||||
# Returns $true for that box.
|
||||
function Test-SteamFailure($p, [int]$port) {
|
||||
$end = (Get-Date).AddSeconds(40)
|
||||
while ((Get-Date) -lt $end -and -not $p.HasExited) {
|
||||
if (Get-A2SInfo '127.0.0.1' $port 1000) { return $false }
|
||||
$p.Refresh()
|
||||
if ($p.MainWindowTitle -like 'Fatal error*') { return $true }
|
||||
Start-Sleep -Milliseconds 500
|
||||
}
|
||||
return $false
|
||||
}
|
||||
|
||||
# An earlier version (2026-10-15) hid this Steam setting while starting the server; this puts it
|
||||
# back if a start was interrupted then. Harmless otherwise.
|
||||
$Script:SteamKey = 'HKCU:\Software\Valve\Steam\ActiveProcess'
|
||||
$Script:SteamHidden = 'SteamClientDll_hidden_by_cs16'
|
||||
|
||||
|
||||
Reference in new issue
Block a user