CS2云同步设置本地cfg生成脚本

  1. 用你的大号在游戏控制台里运行host_writeconfig
  2. 找到你的steam好友代码
  3. 找到你的steam云存档文件夹
    可能是在"H:\Program Files (x86)\Steam\userdata\<好友代码>\730\remote"
  4. 找到你的CS文件夹
    可能是在Y:\SteamLibrary\steamapps\common\Counter-Strike Global Offensive\
  5. 将以下这个脚本保存为dump_cs_config.ps1
param(
    [Parameter(Mandatory=$true)]
    [string]$ConvarVcfgPath,

    [Parameter(Mandatory=$true)]
    [string]$KeysVcfgPath,

    [Parameter(Mandatory=$true)]
    [string]$OutputCfgPath
)

# 确保输出目录存在
$outputDir = Split-Path $OutputCfgPath -Parent
if (-not (Test-Path $outputDir)) {
    Write-Host "Output directory does not exist. Creating: $outputDir"
    New-Item -ItemType Directory -Path $outputDir | Out-Null
}

$outputLines = @()
$outputLines += "// 从 CS2 VCFG 文件自动生成的配置"
$outputLines += "// 生成于 $(Get-Date)"
$outputLines += ""

# 解析 VCFG 文件特定部分的函数
function Get-VcfgSection {
    param(
        [string]$Path,
        [string]$SectionName,
        [string]$Type # "bind" 或 "convar"
    )

    if (-not (Test-Path $Path)) {
        Write-Warning "File not found: $Path"
        return
    }

    # 使用 UTF8 编码读取文件以保留特殊字符(如示例中的名称)
    $content = Get-Content -Path $Path -Encoding UTF8
    
    $inTargetSection = $false
    $braceLevel = 0
    $results = @()

    foreach ($line in $content) {
        $trimmed = $line.Trim()

        # 检查段落起始位置
        if ($trimmed -match "^`"$SectionName`"") {
            $inTargetSection = $true
            continue
        }

        if ($inTargetSection) {
            # 追踪大括号以判断段落何时结束
            if ($trimmed -eq "{") {
                $braceLevel++
                continue
            }
            if ($trimmed -eq "}") {
                $braceLevel--
                if ($braceLevel -le 0) {
                    $inTargetSection = $false
                    break # 段落处理完毕,退出循环
                }
                continue
            }

            # 用于匹配的正则表达式:"key" "value"
            # 捕获引号内的内容
            if ($trimmed -match '^"(.+?)"\s+"(.+?)"$') {
                $key = $matches[1]
                $val = $matches[2]

                if ($Type -eq "bind") {
                    # 格式:bind "key" "value"
                    # 我们在按键名周围添加引号,以安全处理像 `\` 或空格这类按键
                    $results += "bind `"$key`" `"$val`""
                }
                elseif ($Type -eq "convar") {
                    # 格式:convar "value"
                    $results += "$key `"$val`""
                }
            }
        }
    }
    return $results
}

# 1. 处理绑定 (Bindings)
Write-Host "Reading Bindings from: $KeysVcfgPath"
$outputLines += "// --- 绑定 (Bindings) ---"
$binds = Get-VcfgSection -Path $KeysVcfgPath -SectionName "bindings" -Type "bind"
$outputLines += $binds
$outputLines += ""

# 2. 处理控制台变量 (Convars)
Write-Host "Reading Convars from: $ConvarVcfgPath"
$outputLines += "// --- 控制台变量 (Convars) ---"
$convars = Get-VcfgSection -Path $ConvarVcfgPath -SectionName "convars" -Type "convar"
$outputLines += $convars

# 3. 写入输出
Write-Host "Writing config to: $OutputCfgPath"
$outputLines | Set-Content -Path $OutputCfgPath -Encoding UTF8

Write-Host "Done! Converted $($binds.Count) binds and $($convars.Count) convars."
  1. 在控制台中运行
    .\dump_cs_config.ps1 "<steam云存档文件夹>\cs2_user_convars.vcfg" "<steam云存档文件夹>\cs2_user_keys.vcfg" "CS文件夹\game\csgo\cfg\dump.cfg"
    类似
    .\dump_cs_config.ps1 "H:\Program Files (x86)\Steam\userdata\114514\730\remote\cs2_user_convars.vcfg" "C:\Program Files (x86)\Steam\userdata\114514\730\remote\cs2_user_keys.vcfg" "D:\SteamLibrary\steamapps\common\Counter-Strike Global Offensive\game\csgo\cfg\dump.cfg"
  2. 回到游戏,运行exec dump
    你的绑键,准星等都会进入这个cfg

感谢测试脚本的 @Force
@Kazelink @muxi @interstellar @Lightbringer @KagaSumire @Kel7 @skyrim @Pipita @Nik0major
以后用我小号上分的时候可以狠狠用

4 个赞

:thinking:
我的 cfg’s 本来就在 steamapps\common\Counter-Strike Global Offensive\game\core\cfg

不应该是 Counter-Strike Global Offensive\game\core\cfg\

V社更新了cfg位置,现在在用户云存档里;如果你没有专用cfg又上了别人的号,绑键会变

不清楚,但这个测试是没问题的

我都是上传以后放自己steam主页