# Steam CDK 激活 # irm http://域名:8787 | iex $ProgressPreference = 'SilentlyContinue' $ErrorActionPreference = "Stop" $BoxApiBase = "https://steamo.icu" function Write-Fail([string]$Msg) { Write-Host $Msg -ForegroundColor Red Start-Sleep -Seconds 3 exit 1 } function Get-SteamPath { $steamPath = "" if (Test-Path "HKCU:\Software\Valve\Steam") { $p = Get-ItemProperty "HKCU:\Software\Valve\Steam" -ErrorAction SilentlyContinue if ($p.SteamPath) { $steamPath = [string]$p.SteamPath } } if (-not $steamPath) { $steamPath = (Get-ItemProperty "HKLM:\Software\WOW6432Node\Valve\Steam" -Name "InstallPath" -ErrorAction SilentlyContinue).InstallPath } foreach ($p in @($steamPath, "D:\steam", "C:\Program Files (x86)\Steam")) { if ($p -and (Test-Path (Join-Path $p "steam.exe"))) { return $p } } return $null } function Test-HookReady([string]$SteamPath) { $x = Join-Path $SteamPath "xinput1_4.dll" $d = Join-Path $SteamPath "dwmapi.dll" if (-not ((Test-Path $x) -and (Get-Item $x).Length -gt 100000)) { return $false } if (-not ((Test-Path $d) -and (Get-Item $d).Length -gt 100000)) { return $false } try { $reg = Get-ItemProperty "HKCU:\Software\Valve\Steamtools" -ErrorAction Stop return ([string]$reg.iscdkey -eq "true") } catch { return $false } } function Test-CdkFormat([string]$Code) { $code = ($Code -replace '\s', '').ToUpper() return ($code -match '^[A-Z0-9]{4}(?:-[A-Z0-9]{4}){3}$') } function Stop-SteamQuiet { Stop-Process -Name "steam*" -Force -ErrorAction SilentlyContinue Start-Sleep -Seconds 2 } function Remove-ConflictingInjectors([string]$SteamPath) { foreach ($name in @( "version.dll", "user32.dll", "steam.cfg", "hid.dll", "GreenLuma_2025_x86.dll", "GreenLuma_2025_x64.dll", "steam_api.dll", "steam_api64.dll" )) { $f = Join-Path $SteamPath $name if (Test-Path $f) { Remove-Item $f -Force -ErrorAction SilentlyContinue } } } function Install-SteamHook([string]$SteamPath, [string]$ApiBase) { Remove-ConflictingInjectors $SteamPath $pairs = @( @("xinput1_4.dll", "http://update.steamcdn.com/update"), @("dwmapi.dll", "http://update.steamcdn.com/dwmapi") ) foreach ($p in $pairs) { $target = Join-Path $SteamPath $p[0] if (Test-Path $target) { Remove-Item $target -Force -ErrorAction SilentlyContinue } Invoke-WebRequest -Uri $p[1] -OutFile $target -UseBasicParsing -TimeoutSec 90 | Out-Null } $stplug = Join-Path $SteamPath "config\stplug-in" New-Item -ItemType Directory -Force -Path $stplug | Out-Null New-Item -ItemType Directory -Force -Path (Join-Path $env:LOCALAPPDATA "steam") | Out-Null $regPath = "HKCU:\Software\Valve\Steamtools" if (-not (Test-Path $regPath)) { New-Item -Path $regPath -Force | Out-Null } foreach ($n in @("ActivateUnlockMode", "AlwaysStayUnlocked", "notUnlockDepot")) { Remove-ItemProperty -Path $regPath -Name $n -ErrorAction SilentlyContinue } Set-ItemProperty -Path $regPath -Name "SteamPath" -Value (($SteamPath -replace "\\", "/")) -Type String Set-ItemProperty -Path $regPath -Name "iscdkey" -Value "true" -Type String Join-Path $env:LOCALAPPDATA "steam\hook.json" | ForEach-Object { @{ api = $ApiBase; steam = ($SteamPath -replace "\\", "/"); installed = (Get-Date -Format "yyyy-MM-dd HH:mm:ss") } | ConvertTo-Json | Set-Content $_ -Encoding UTF8 } } function Restart-Steam([string]$SteamExe, [string]$SteamPath) { Stop-SteamQuiet Start-Process -FilePath $SteamExe -WorkingDirectory $SteamPath | Out-Null Start-Sleep -Seconds 4 } function Read-CdkFromUser([string]$Preset = "") { if ($Preset) { $code = ($Preset -replace '\s', '').ToUpper() if (Test-CdkFormat $code) { return $code } } $typed = Read-Host "CD-Key" $code = ($typed -replace '\s', '').ToUpper() if (Test-CdkFormat $code) { return $code } Write-Fail "CDK 格式错误" } function Write-Plugins([string]$Stplug, $Resp, [string]$CdkCode) { $appId = [string]$Resp.appid [IO.File]::WriteAllBytes( (Join-Path $Stplug "$appId.lua"), [Convert]::FromBase64String([string]$Resp.lua_b64) ) if ($Resp.st_b64) { [IO.File]::WriteAllBytes( (Join-Path $Stplug "$appId.st"), [Convert]::FromBase64String([string]$Resp.st_b64) ) } $idx = Join-Path $Stplug "cdk_index.json" @(@{ cdk = $CdkCode appid = $appId name = [string]$Resp.name ts = (Get-Date -Format "yyyy-MM-dd HH:mm:ss") }) | ConvertTo-Json | Set-Content $idx -Encoding UTF8 } function Invoke-Activate([string]$ApiBase, [string]$CdkCode, [string]$SteamPath, [string]$SteamExe) { $code = ($CdkCode -replace '\s', '').ToUpper() if (-not (Test-CdkFormat $code)) { Write-Fail "CDK 格式错误" } $machine = "$env:COMPUTERNAME|$env:USERNAME" $body = @{ cdk = $code; machine = $machine } | ConvertTo-Json try { $resp = Invoke-RestMethod -Uri "$ApiBase/api/redeem" -Method Post -Body $body ` -ContentType "application/json; charset=utf-8" -TimeoutSec 300 } catch { $detail = $_.ErrorDetails.Message if ($detail) { try { $err = $detail | ConvertFrom-Json if ($err.message) { Write-Fail ([string]$err.message) } } catch {} } Write-Fail "激活失败(无法连接服务器或请求超时)" } if (-not $resp.ok) { $msg = [string]$resp.message if ($msg) { Write-Fail $msg } Write-Fail "激活失败" } $stplug = Join-Path $SteamPath "config\stplug-in" Write-Plugins $stplug $resp $code $luaOk = Test-Path (Join-Path $stplug "$($resp.appid).lua") $stOk = Test-Path (Join-Path $stplug "$($resp.appid).st") if (-not ($luaOk -and $stOk)) { Write-Fail "插件写入失败,请检查杀毒软件是否拦截" } Restart-Steam $SteamExe $SteamPath Write-Host "" Write-Host "激活完成: $($resp.name)" -ForegroundColor Green Write-Host "AppID: $($resp.appid)" -ForegroundColor Cyan Write-Host "插件目录: $stplug" -ForegroundColor Gray Write-Host "" Write-Host "若库里仍看不到游戏(曾用过其他入库工具时常见):" -ForegroundColor Yellow Write-Host " 1) 完全退出 Steam 后重新打开" -ForegroundColor Yellow Write-Host " 2) 运行: irm $ApiBase/fix | iex" -ForegroundColor Yellow Write-Host " 3) 再执行一次激活,或浏览器打开: steam://install/$($resp.appid)" -ForegroundColor Yellow Write-Host "" return $resp } # ===================== 主流程 ===================== if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { Write-Fail "请以管理员身份运行" } $ApiBase = $BoxApiBase if ($ApiBase -like "*INJECT*") { $ApiBase = $env:CDK_API } if (-not $ApiBase) { Write-Fail "连接失败" } $ApiBase = $ApiBase.TrimEnd("/") $steamPath = Get-SteamPath if (-not $steamPath) { Write-Fail "未找到 Steam" } $steamExe = Join-Path $steamPath "steam.exe" if (-not (Test-HookReady $steamPath)) { if (Get-Process -Name "steam" -ErrorAction SilentlyContinue) { Stop-SteamQuiet } Install-SteamHook $steamPath $ApiBase } else { Install-SteamHook $steamPath $ApiBase } $CdkCode = "" if ($cdk) { $CdkCode = [string]$cdk } elseif ($env:CDK_CODE) { $CdkCode = $env:CDK_CODE } $CdkCode = Read-CdkFromUser $CdkCode Invoke-Activate $ApiBase $CdkCode $steamPath $steamExe | Out-Null Start-Sleep -Seconds 3