修复 background_click=false 时 setForeground 崩溃
现象: 改 set_win_size 后任务在 init_game() 里直接崩, exit code 3, traceback: screen.py:343 _set_win -> handle.setForeground() -> win32gui.SetForegroundWindow(hwnd) -> pywintypes.error: (0, 'SetForegroundWindow', 'No error message is available') 原因: screen.py:342 在 cfg.background_click=False 时才调 setForeground, 而原生 实现(screen.py:167-171)只有一句裸调用, 没有任何兜底。Windows 不允许非前台进程 抢占前台, 失败就抛异常, 这个异常在 set_win() 里没被捕获, 整个任务崩掉。 也就是说: 我为了修抓图黑屏把 background_click 改成 false, 反而踩出了这条 一直存在但从没被走到的崩溃路径。 修复: install_robust_set_foreground —— 先试原生调用, 失败则用 MSDN 认可的标准 手法兜底: 把自己的线程输入队列 AttachThreadInput 到当前前台窗口线程上, 借它的 前台权限 BringWindowToTop + SetForegroundWindow, 完成后解挂。兜底也失败只记日志 不抛异常 —— 抢不到前台不该让整个任务死掉。 验证: 同样的 set_win_size=720 配置, 修复前 exit 3 崩溃, 修复后正常走到"一次镜牢"。 附带发现: 驱动级输入这次被 preflight 正确拒绝了(GetForegroundWindow=0)。 用户改用 ToDesk 连接后桌面变成独立会话(主屏是 Todesk Virtual Display Adapter), 驱动级注入在这种会话里本来就不生效 —— 拒绝并回退普通注入是正确行为。
This commit is contained in:
+3
-1
@@ -11,7 +11,8 @@ import sys
|
|||||||
|
|
||||||
from . import preflight
|
from . import preflight
|
||||||
from .aalc_engine import bootstrap
|
from .aalc_engine import bootstrap
|
||||||
from .aalc_patches import WindowGuard, install_driver_click, install_exact_team_match
|
from .aalc_patches import (WindowGuard, install_driver_click, install_exact_team_match,
|
||||||
|
install_robust_set_foreground)
|
||||||
|
|
||||||
# 任务 -> {参数名: AALC 配置项}; 参数只在本次运行内生效
|
# 任务 -> {参数名: AALC 配置项}; 参数只在本次运行内生效
|
||||||
TASKS = {
|
TASKS = {
|
||||||
@@ -82,6 +83,7 @@ def run(task, params):
|
|||||||
return PREFLIGHT_EXIT
|
return PREFLIGHT_EXIT
|
||||||
|
|
||||||
install_exact_team_match(auto, log)
|
install_exact_team_match(auto, log)
|
||||||
|
install_robust_set_foreground(screen, log=log)
|
||||||
guard = WindowGuard(screen, cfg, log=log)
|
guard = WindowGuard(screen, cfg, log=log)
|
||||||
guard.start()
|
guard.start()
|
||||||
restore_path = os.environ.get(RESTORE_ENV)
|
restore_path = os.environ.get(RESTORE_ENV)
|
||||||
|
|||||||
Reference in New Issue
Block a user