合并 main 的合并前复核修复到镜牢选队分支

Browse Source
分支从 8a9495b 分出,缺 main 上 a74fda0 的急停与驱动复核修复。
两边都保留,不取单边:

- 急停:沿用分支的 GetAsyncKeyState 轮询与 End 键(pynput 钩子在该
  机器收不到键,F12 是 Steam 截图键);移植 main 的 on_stop 释放驱动
  按住的鼠标键、250 毫秒强退兜底、listening() 管理监听生命周期。
  按键状态改为独立绑定(SHORT 返回值),接口不可用时启动即报告。
- 驱动输入:同时保留句柄级前台校验、press_ms/settle 与 main 的
  停止标志、输入锁和按键记录;点击经 down()/up() 以便急停释放。
  前台校验改用本模块的类型化 _api 绑定。
- 代理每次点击按当前句柄重新 bind_window:代理复用时不再拿安装时
  的旧句柄拒绝游戏重启后的全部点击。
- aalc_task:listening() 包住整个任务,内部安装两个选队补丁。
- 分支新增测试改为替换模块接口,不再直接 patch ctypes.windll
  (Linux 上 9 项报错);README 急停键改为 End。

验证:Linux / Python 3.12 全套 474 项通过;git diff --check 通过。
Windows 热键、驱动和选队仍需实机回归。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
yws
2026-11-14 03:19:53 +00:00
co-authored by Claude Opus 5.5
14 changed files with 490 additions and 182 deletions
+46 -50
View File
@@ -9,12 +9,11 @@ import json
import os
import sys
from . import preflight
from . import killswitch, preflight
from .aalc_engine import bootstrap
from . import killswitch
from .aalc_patches import (WindowGuard, driver_click_tasks, install_default_battle_team,
install_exact_team_match, install_robust_set_foreground,
install_system_team_selection)
install_system_team_selection, stop_driver_click)
# 任务 -> {参数名: AALC 配置项}; 参数只在本次运行内生效
TASKS = {
@@ -77,55 +76,52 @@ def run(task, params):
from tasks.battle import battle
from utils.path_manager import path_manager
# 急停热键: 装得越早越好。驱动级点击期间鼠标被人和程序抢来抢去,
# 用户没法用鼠标点停止按钮, 键盘是唯一可靠的中断手段。
kill_listener = killswitch.install(log=log)
with killswitch.listening(log=log, on_stop=lambda: stop_driver_click(auto)):
problems = preflight.check(preflight.collect(cfg), task,
desktop=None if cfg.simulator else preflight.desktop_size())
if problems:
for p in problems:
log('[ERROR] [lc_mcp] preflight: %s' % p)
return PREFLIGHT_EXIT
problems = preflight.check(preflight.collect(cfg), task,
desktop=None if cfg.simulator else preflight.desktop_size())
if problems:
for p in problems:
log('[ERROR] [lc_mcp] preflight: %s' % p)
return PREFLIGHT_EXIT
install_exact_team_match(auto, log)
install_robust_set_foreground(screen, log=log)
# 日常本(经验/纽本)不翻队伍列表: 队伍是自定义名字时按名字找必然失败,
# 白等 60 秒还会把界面滚乱, 后面 to_battle 就找不到 "进入战斗" 了。
if task in ('daily', 'all'):
install_default_battle_team(scheme, log=log)
# 镜牢: 编队是自定义名字(体系名), AALC 只会找 "编队#N"; 改成按体系名点选。
if task in ('mirror', 'all'):
install_system_team_selection(log=log)
guard = WindowGuard(screen, cfg, log=log)
guard.start()
restore_path = os.environ.get(RESTORE_ENV)
originals = apply_overrides(cfg, task, params, restore_path)
with driver_click_tasks(scheme, auto, screen, cfg, log=log):
try:
if task == 'all':
scheme.script_task()
install_exact_team_match(auto, log)
install_robust_set_foreground(screen, log=log)
# 日常本(经验/纽本)不翻队伍列表: 队伍是自定义名字时按名字找必然失败,
# 白等 60 秒还会把界面滚乱, 后面 to_battle 就找不到 "进入战斗" 了。
if task in ('daily', 'all'):
install_default_battle_team(scheme, log=log)
# 镜牢: 编队是自定义名字(体系名), AALC 只会找 "编队#N"; 改成按体系名点选。
if task in ('mirror', 'all'):
install_system_team_selection(log=log)
guard = WindowGuard(screen, cfg, log=log)
guard.start()
restore_path = os.environ.get(RESTORE_ENV)
originals = apply_overrides(cfg, task, params, restore_path)
with driver_click_tasks(scheme, auto, screen, cfg, log=log):
try:
if task == 'all':
scheme.script_task()
return 0
# 与 script_task() 相同的前置步骤
scheme.init_game()
path_manager.initialize_paths()
auto.clear_img_cache()
retry_monitor.start()
get_reward = None
if auto.click_element('battle/turn_assets.png', take_screenshot=True):
print('[lc_mcp] 检测到正在战斗, 先打完', flush=True)
get_reward = battle.fight()
{
'daily': scheme.Daily_task_wrapper(get_reward=get_reward),
'reward': scheme.to_get_reward,
'enkephalin': scheme.Buy_enkephalin,
'mirror': scheme.Mirror_task,
}[task]()
return 0
# 与 script_task() 相同的前置步骤
scheme.init_game()
path_manager.initialize_paths()
auto.clear_img_cache()
retry_monitor.start()
get_reward = None
if auto.click_element('battle/turn_assets.png', take_screenshot=True):
print('[lc_mcp] 检测到正在战斗, 先打完', flush=True)
get_reward = battle.fight()
{
'daily': scheme.Daily_task_wrapper(get_reward=get_reward),
'reward': scheme.to_get_reward,
'enkephalin': scheme.Buy_enkephalin,
'mirror': scheme.Mirror_task,
}[task]()
return 0
finally:
guard.stop()
retry_monitor.stop()
restore(cfg, originals, restore_path)
finally:
guard.stop()
retry_monitor.stop()
restore(cfg, originals, restore_path)
def main(argv):