From 7eafbdd65162bc7a8096fac7c810b904ae2a1f2b Mon Sep 17 00:00:00 2001 From: Codex Agent Date: Thu, 22 Oct 2026 11:55:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=A9=B1=E5=8A=A8=E7=82=B9?= =?UTF-8?q?=E5=87=BB=E6=8E=A5=E7=AE=A1=E8=A2=AB=20init=5Fgame()=20?= =?UTF-8?q?=E8=A6=86=E7=9B=96=EF=BC=88=E8=A1=A5=E8=BF=BD=E8=B8=AA=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题: 日志里能看到 "鼠标点击已切到罗技驱动级输入", 但驱动点击一次都没发生 (追踪文件只有 2 行 install 记录, [driver] 日志 0 条, 而 automation.py:152 的 点击日志有 58 次)。 原因: 安装在 scheme.init_game() **之前**。init_game() 会重建 auto.input_handler (automation.py:46/65/72/77/84/89/94/98 多处赋值), 把装好的代理覆盖掉。所以 patch 日志打了, 但真正点击时 getattr(self.input_handler, 'mouse_click') 取到的 是原来的 handler。 修复: 把安装挪到 init_game() 之后。 另外加了 LCP_DRIVER_TRACE 文件追踪(install 时记录原 handler 与 auto.mouse_click 的原绑定, mouse_click 每次调用都记一行) —— 普通日志会被 AALC 的 logger 吞掉, 文件追踪是这次能定位到根因的关键。 这个问题说明测试覆盖不足: 单元测试用 Mock 造 auto, 没有复现 automation.py 真实的 别名/gate 接线, 所以没能发现"装完被覆盖"。后续要补一个贴近真实接线的测试。 --- lc_mcp/aalc_patches.py | 29 ++++++++++++++++++++++++++++- lc_mcp/aalc_task.py | 8 ++++---- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/lc_mcp/aalc_patches.py b/lc_mcp/aalc_patches.py index e23e9ce..178f190 100644 --- a/lc_mcp/aalc_patches.py +++ b/lc_mcp/aalc_patches.py @@ -12,6 +12,7 @@ 一次, 之后全部模板匹配分数掉到阈值以下, 表现为原地空转、不报错。这里在后台定期 检查客户区尺寸, 偏离 set_win_size 时调回去。 """ +import os import re import threading import time @@ -128,8 +129,24 @@ class DriverClickProxy: hwnd = self._screen.handle.hwnd return client_to_screen(hwnd, x, y) + def _trace(self, msg): + """排障用的文件追踪: 日志被 AALC 的 logger 吞掉时靠它看真实调用。""" + path = os.environ.get('LCP_DRIVER_TRACE') + if not path: + return + try: + with open(path, 'a', encoding='utf-8') as fh: + fh.write('%s %s\n' % (time.strftime('%H:%M:%S'), msg)) + except OSError: + pass + def mouse_click(self, x, y, times=1, *args, **kwargs): - sx, sy = self._screen_pos(x, y) + self._trace('mouse_click(%s,%s,times=%s)' % (x, y, times)) + try: + sx, sy = self._screen_pos(x, y) + except Exception as e: + self._trace('screen_pos 失败: %s: %s' % (type(e).__name__, e)) + raise if self._driver.click(sx, sy, times=times): self.clicks += 1 self.log('[driver] 点击客户区(%d,%d) -> 屏幕(%d,%d)' % (x, y, sx, sy)) @@ -170,6 +187,16 @@ def install_driver_click(auto, screen, driver=None, log=print): return None proxy = DriverClickProxy(auto.input_handler, drv, screen, log=log) + trace = os.environ.get('LCP_DRIVER_TRACE') + if trace: + try: + with open(trace, 'a', encoding='utf-8') as fh: + fh.write('%s install: 原 handler=%s -> proxy\n' + % (time.strftime('%H:%M:%S'), type(auto.input_handler).__name__)) + fh.write('%s install: auto.mouse_click 原绑定=%r\n' + % (time.strftime('%H:%M:%S'), getattr(auto, 'mouse_click', None))) + except OSError: + pass auto.input_handler = proxy for name in REBIND_NAMES: if hasattr(proxy, name): diff --git a/lc_mcp/aalc_task.py b/lc_mcp/aalc_task.py index 2ebec16..1d9c275 100644 --- a/lc_mcp/aalc_task.py +++ b/lc_mcp/aalc_task.py @@ -82,10 +82,6 @@ def run(task, params): return PREFLIGHT_EXIT install_exact_team_match(auto, log) - # 驱动级鼠标点击: 默认关闭, 设 LCP_DRIVER_INPUT=1 才启用。 - # 条件不满足(非物理会话 / 指针加速没关 / 驱动没装)时什么都不改, 保持原样。 - if os.environ.get('LCP_DRIVER_INPUT', '').strip() == '1': - install_driver_click(auto, screen, log=log) guard = WindowGuard(screen, cfg, log=log) guard.start() restore_path = os.environ.get(RESTORE_ENV) @@ -96,6 +92,10 @@ def run(task, params): return 0 # 与 script_task() 相同的前置步骤 scheme.init_game() + # ⚠ 必须放在 init_game() 之后: 它会把 auto.input_handler 重建一次, + # 放在前面装好的代理会被覆盖掉(2026-10-22 实测: 日志有 patch 记录但代理从未被调用)。 + if os.environ.get('LCP_DRIVER_INPUT', '').strip() == '1': + install_driver_click(auto, screen, log=log) path_manager.initialize_paths() auto.clear_img_cache() retry_monitor.start()