用户要求: 这次不打任何关卡, 只挂机等体力恢复、把体力合成成模块, 合成完关掉游戏。
一、新增 scripts/convert_modules.py(启动游戏->合成->关掉)
单独一个脚本, 不走 AALC 的任务系统 —— AALC 的 make_enkephalin_module 是挂在
Luxcavation 流程里的(打完一次才顺手换一次), 没有独立入口, 而这次不能打关卡。
界面流程(1600x900 基准, lc_ui 负责换算):
主界面点模组图标 -> Charge Enkephalin -> [Modules]/[Use Lunacy]/[Use Boxes]
-> 停在 Modules(免费) -> » 取最大 -> Confirm -> 20 体力换 1 模块
三条硬规则:
1. 绝不点 Use Lunacy 页签。USE_LUNACY_TAB 常量只用于"确认没点到它",
并写了 AST 检查的测试: 任何 click() 传入该坐标都会让测试失败。
2. 不打任何关卡, 全程只碰底栏模组图标和合成面板。
3. 合成前后各读一次狂气做相对比对, 不一致就报错退出。
实机验证: 模组 23 -> 29(+6)、体力 132 -> 13(6x20)、狂气 6636 未变。
二、修窗口尺寸: RDP 断线重连会把客户区改成 1278x719(实测), 之后 OCR 连底栏
的 LUNACY 标签都读不出来, 狂气校验直接退化成"读不到, 跳过"。AALC 的
WindowGuard 只在跑任务时生效, 这个脚本不跑任务, 所以自己做 MoveWindow。
三、新增 scripts/install_convert_task.ps1: 每 4 小时一轮(LcMCPConvertModules)。
体力每 6 分钟回 1 点、上限 126, 合成 1 个模块要 20 点 -> 4 小时约能换 2 个。
与 LcMCPDailyCycle 完全分开, 刷取任务保持禁用。
四、修 keep_display.ps1 的一个真 bug:
(Get-Content $out -Raw) 在文件为空/被当通配时返回数组, 后面的 .Trim() 报
"does not contain a method named Trim"。看门狗本身照常工作, 但每次都会
吐一条红字, 掩盖真正的失败。改成先拼接再裁剪。
五、⛔ 修掉一个我自己写坏的测试, 它会让整个测试进程崩掉:
poll_task 的循环上限是按墙钟判的(time.time()), 而测试里把 sleep 换成空函数
却没换时钟 —— 于是 timeout_s=3600 真的空转了一小时, 每圈还往 mcp.calls 里
塞一条, 内存吃爆后进程以 0xC0000005 退出。表现就是"跑测试跑崩了"。
改成 FakeTime 快进时钟。全套从 156 秒(且崩)降到 14 秒, 246/246 通过。
新增 tests/test_convert_modules.py 13 个用例(屏幕判定/资源读数/狂气众数/禁用坐标)。
其中"禁用坐标"那条也验证过能失败: 故意把 click(*TAB_MODULES) 改成
click(*USE_LUNACY_TAB), 它准确报出违规行号。
99 lines
4.7 KiB
PowerShell
99 lines
4.7 KiB
PowerShell
# 看门狗: 会话掉回 "Disc" 时重新挂到物理控制台, 恢复桌面渲染。
|
|
#
|
|
# 背景: DSH / lc-mcp 常驻服务跑在会话 2。RDP 断开后 Windows 会拆掉该会话的
|
|
# 显示表面, 截图变全黑, AALC 直接失明。把会话挂到 console 后即使无人连接
|
|
# 也持续渲染。
|
|
#
|
|
# 只在会话状态为 Disc(无人连接) 时动作; 用户正通过 RDP/ToDesk 连着
|
|
# (Active/Conn) 时绝不插手, 否则会把用户挤下线。
|
|
#
|
|
# tscon 需要 SeTcbPrivilege, 普通令牌拿不到, 所以用 -Verb RunAs 提权。
|
|
# 本机 ConsentPromptBehaviorAdmin=0(从不通知), 提权静默通过, 不会弹框。
|
|
#
|
|
# 会话号默认取游戏进程所在会话, 找不到游戏时取本脚本所在会话(计划任务以
|
|
# 登录用户身份运行, 与桌面同一会话)。重启或重新登录后会话号会变, 不要写死。
|
|
|
|
param(
|
|
[int]$SessionId = -1,
|
|
[string]$Python = "",
|
|
[string]$LogPath = "$env:USERPROFILE\lc_mcp\keep_display.log",
|
|
[switch]$Verbose,
|
|
[switch]$ForceDisc
|
|
)
|
|
|
|
function Write-Log([string]$msg) {
|
|
$dir = Split-Path -Parent $LogPath
|
|
if (-not (Test-Path $dir)) { New-Item -ItemType Directory -Path $dir -Force | Out-Null }
|
|
Add-Content -Path $LogPath -Value ("[{0}] {1}" -f (Get-Date -Format 'yyyy-MM-dd HH:mm:ss'), $msg) -Encoding UTF8
|
|
$all = @(Get-Content $LogPath -ErrorAction SilentlyContinue)
|
|
if ($all.Count -gt 400) { $all | Select-Object -Last 400 | Set-Content $LogPath -Encoding UTF8 }
|
|
}
|
|
|
|
# 会话状态: 用 WTS API (qwinsta 在计划任务上下文里拿不到输出)
|
|
$py = if ($Python) { $Python } else { Join-Path $PSScriptRoot '..\vendor\aalc\.venv\Scripts\python.exe' }
|
|
if ($SessionId -lt 0) {
|
|
$game = Get-Process -Name LimbusCompany -ErrorAction SilentlyContinue | Select-Object -First 1
|
|
$SessionId = if ($game) { $game.SessionId } else { (Get-Process -Id $PID).SessionId }
|
|
}
|
|
$statePy = Join-Path $PSScriptRoot 'session_state.py'
|
|
if (-not (Test-Path $py) -or -not (Test-Path $statePy)) {
|
|
Write-Log "missing python ($py) or session_state.py ($statePy); abort"
|
|
exit 1
|
|
}
|
|
$state = (& $py -X utf8 $statePy $SessionId 2>&1 | Out-String).Trim()
|
|
if ($state -notin @('Active', 'Connected', 'Disc', 'Idle')) {
|
|
Write-Log "session $SessionId state unreadable ('$state'); abort"
|
|
exit 1
|
|
}
|
|
|
|
if ($ForceDisc) {
|
|
Write-Log "ForceDisc: skipping state check (real state was '$state')"
|
|
$state = 'Disc'
|
|
} elseif ($state -ne 'Disc') {
|
|
if ($Verbose) { Write-Log "session $SessionId is $state; nothing to do" }
|
|
exit 0
|
|
}
|
|
|
|
Write-Log "session $SessionId is Disc -> re-attaching to console via elevated tscon"
|
|
$out = Join-Path (Split-Path -Parent $LogPath) 'tscon_last.txt'
|
|
Remove-Item $out -ErrorAction SilentlyContinue
|
|
# 之前的版本把命令拼成 -Command 字符串交给 Start-Process, 10-05 的 41 次失败
|
|
# 全部只留下 "(no output file)", 连 tscon 有没有跑都看不出(多半是引号在
|
|
# 命令行拼接时被吃掉, 重定向没生效)。改用 -EncodedCommand 原样传递,
|
|
# 并用 -PassThru 拿提权进程的退出码(= tscon 的退出码)。
|
|
# 32 位宿主里 System32 会被重定向到 SysWOW64, 那里没有 tscon.exe, 用 Sysnative 绕过。
|
|
$sysDir = if (Test-Path "$env:SystemRoot\Sysnative") { "$env:SystemRoot\Sysnative" } else { "$env:SystemRoot\System32" }
|
|
$inner = "& '$sysDir\tscon.exe' $SessionId /dest:console *> '$out'; exit `$LASTEXITCODE"
|
|
$encoded = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($inner))
|
|
try {
|
|
$proc = Start-Process -FilePath "$sysDir\WindowsPowerShell\v1.0\powershell.exe" `
|
|
-ArgumentList @('-NoProfile', '-NonInteractive', '-EncodedCommand', $encoded) `
|
|
-Verb RunAs -WindowStyle Hidden -Wait -PassThru -ErrorAction Stop
|
|
} catch {
|
|
Write-Log "elevated tscon launch FAILED: $($_.Exception.Message)"
|
|
exit 1
|
|
}
|
|
Start-Sleep -Seconds 2
|
|
# Get-Content -Raw 一般返回单个字符串, 但文件为空或 $out 被当成通配时可能返回数组,
|
|
# 那时 .Trim() 会报 "does not contain a method named 'Trim'"。先拼接成字符串再用。
|
|
$tsconOut = ''
|
|
if (Test-Path $out) {
|
|
$raw = @(Get-Content $out -ErrorAction SilentlyContinue) -join ' '
|
|
$tsconOut = ($raw -replace '\s+', ' ').Trim()
|
|
}
|
|
if (-not $tsconOut) { $tsconOut = '(no output)' }
|
|
$after = (& $py -X utf8 $statePy $SessionId 2>&1 | Out-String).Trim()
|
|
Write-Log "tscon exit=$($proc.ExitCode) said: $tsconOut | session $SessionId now: $after"
|
|
|
|
# 渲染自检: BitBlt 屏幕 DC 成功 = 桌面在出图
|
|
$renderPy = Join-Path $PSScriptRoot 'render_check.py'
|
|
if (Test-Path $renderPy) {
|
|
$rc = (& $py -X utf8 $renderPy 2>&1 | Out-String).Trim()
|
|
Write-Log "render check: $rc"
|
|
}
|
|
|
|
if ($after -ne 'Active' -and $after -ne 'Connected') {
|
|
Write-Log "WARN: session $SessionId still '$after' after tscon"
|
|
exit 1
|
|
}
|