AALC 升级到 V1.6.1 并按零协汉化核对镜牢补丁

Browse Source
- vendor/aalc: e1d1749 -> 2fcb1b4(V1.6.1)。上游 8196e72 修好了商店三个清单的
  路径, 删掉本地 install_shop_lists, test_shop_lists 改成守着上游 5/19/31。
- 上游 18deb77 把事件里找 "???" 改成 find_element 后自己点, 原事件表补丁挂在
  click_element 上会悄悄失效。改挂 find_element, 上游拿返回位置再点的那下吞掉;
  小指良单通模式再找 "???" 时返回没有, 不会改点别的选项。
- 事件表改成按同一屏其它选项的原文认事件(零协汉化的事件数据没有标题), 选项原文
  照抄 LLC_zh-CN/ActionEvents_*.json 并带事件 id; 去掉 index 规则。核对后保留
  6 条, 删掉汉化里对不上或说法矛盾的 4 条(两个睡袋、浸染棉花、终末日历); 失明巨人
  是判定, 标 check。选项比较前去标点。
- 饰品关键词按零协汉化体系名核对, 删掉汉化里从未出现的 出血。
- 事件表、饰品排序安装时检查上游源码里还有被拦截的调用, 没有就记 [ERROR] 跳过;
  包装函数带 __wrapped__, 叠装时也能查到上游源码。
- BACKLOG 记录这次升级对各补丁的影响和核对结果。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
yws
2026-11-14 08:43:27 +00:00
co-authored by Claude Opus 5.5
parent 51525722cd
commit 72d2ca1a5b
10 changed files with 410 additions and 345 deletions
+108 -132
View File
@@ -676,62 +676,6 @@ def install_system_team_selection(log=print):
return original
# ---------------------------------------------------------------- 镜牢商店清单
# 上游 ebb6629 把图片挪到 assets/images/<主题>/<语言>/ 下, tasks/mirror/__init__.py 却仍按
# ./assets/images/share/mirror/shop/... 列目录, 三个清单恒为空。2026-11-14 实测进店 51 秒,
# 打印三次 "开始购买必买项" 一件没买; 弃用饰品识别与公式合成也一起空转。
# 按名字找图(mirror/shop/<清单>/<文件>)由 path_manager 依次搜各主题/语言目录, 那一层没坏。
SHOP_LISTS = ('must_purchase', 'must_be_abandoned', 'fusion_result')
IMAGE_ROOTS = ('dark/zh_cn', 'dark/en', 'dark/share', 'default/zh_cn', 'default/en', 'default/share')
def shop_list_images(kind, images_dir=os.path.join('assets', 'images'), roots=IMAGE_ROOTS):
"""各主题/语言目录下 mirror/shop/<kind> 的图片, 按 AALC 图片名格式去重排序。"""
names = set()
for root in roots:
folder = os.path.join(images_dir, *root.split('/'), 'mirror', 'shop', kind)
try:
entries = os.listdir(folder)
except OSError:
continue
names.update(name for name in entries
if name.lower().endswith('.png') and os.path.isfile(os.path.join(folder, name)))
return ['mirror/shop/%s/%s' % (kind, name) for name in sorted(names)]
def install_shop_lists(log=print, images_dir=os.path.join('assets', 'images')):
"""原地补齐 tasks.mirror 的三个商店清单; 上游清单已非空时不动。
in_shop 用 from tasks.mirror import ... 在导入时绑定列表对象, 所以必须原地 extend,
给模块属性重新赋值对它无效。
"""
try:
import tasks.mirror as mirror_pkg
except Exception as e:
log('[lc_mcp] 商店清单补丁跳过: 无法导入 tasks.mirror: %s' % e)
return {}
try:
from utils.path_manager import PathManager
roots = tuple(PathManager.DEFAULT_ACTIVE_PATHS)
except Exception:
roots = IMAGE_ROOTS
filled = {}
for kind in SHOP_LISTS:
current = getattr(mirror_pkg, kind, None)
if not isinstance(current, list):
log('[lc_mcp] 商店清单补丁跳过 %s: 上游没有这个列表' % kind)
continue
if current:
continue # 上游已修好或已补过
current.extend(shop_list_images(kind, images_dir, roots))
filled[kind] = len(current)
if filled:
log('[lc_mcp] patch: 镜牢商店清单按 assets/images/<主题>/<语言> 补齐: %s'
% ', '.join('%s=%d' % item for item in filled.items()))
return filled
# ---------------------------------------------------------------- 镜牢键盘寻路按节点类型
# config.yaml 开着 mirror_keyboard_simple_pathfinding 时, AALC 每一步只按 ↑ 进最上面的节点,
@@ -961,6 +905,10 @@ def install_gift_preference(log=print, env=None):
if original is None:
log('[lc_mcp] 饰品体系优先补丁跳过: 上游没有 Mirror.acquire_ego_gift')
return None
if _source_calls(original, 'find_element', GIFT_CARD) is False:
log('[ERROR] [lc_mcp] 饰品体系优先补丁跳过: 上游 Mirror.acquire_ego_gift 不再调用 find_element(%r), 挂不上'
% GIFT_CARD)
return None
def prefer(cards, system, keywords):
hits = gift_card_hits(cards, _ocr_lines(auto), keywords, cfg.set_win_size / 1440)
@@ -998,6 +946,7 @@ def install_gift_preference(log=print, env=None):
with _override(auto, 'find_element', find_element):
return original(self, *args, **kwargs)
acquire_ego_gift.__wrapped__ = original # 让后装的补丁查得到上游源码
mirror_mod.Mirror.acquire_ego_gift = acquire_ego_gift
log('[lc_mcp] patch: 镜牢饰品选择按体系关键词排序(%s)' % os.path.basename(path))
return original
@@ -1006,45 +955,68 @@ def install_gift_preference(log=print, env=None):
# ---------------------------------------------------------------- 事件选项表
# 2026-11-14 核对: Mirror.event_handling() 不认事件, 有 "???"/直接拿饰品/优势判定就选它, 否则点第一个选项。
# 这里在上游每轮挑选项之前(它先找 event/unknown_event.png)插一步: 画面上有选项时整屏 OCR,
# 认出表里的事件就按选项文字(或第几项)点; 没认出、或表里的选项不在画面上, 交给上游原逻辑。
# 这里在上游每轮挑选项之前(它先 find_element("event/unknown_event.png"))插一步: 画面上有选项时整屏 OCR,
# 选项文字对上表里某个事件就点表里那一项; 对不上交给上游原逻辑。
# 零协汉化的事件数据没有标题字段, 画面上也不保证有事件名, 所以按同一屏其它选项的原文认事件。
EVENT_CHOICES_ENV = 'LCP_EVENT_CHOICES' # 0 = 关闭; 文件路径 = 用这张表代替默认表
EVENT_CHOICES_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data', 'event_choices.json')
EVENT_OPTION = 'event/select_first_option_assets.png' # 每个选项框的左边缘, 多目标匹配得到每一项
EVENT_HOOK = 'event/unknown_event.png' # 上游每轮挑选项的第一步
EVENT_OPTION_ROW = 60 # 选项文字与选项框左边缘的最大纵向距离(1440 标定; 选项框高约 107)
EVENT_OPTION_LEFT = 20 # 选项文字至多比左边缘再靠左这么多
EVENT_TEXT_CLICKS = 5 # 一次事件里按文字最多点几次
EVENT_INDEX_TRIES = 3 # 按编号点: 只在第一屏选项, 画面没变时最多重试几次
EVENT_TEXT_CLICKS = 5 # 一次事件里按表最多点几次(点了没反应时不死循环)
def normalize_event_text(text):
"""选项文字归一: 与队名相同的归一, 再去掉标点(OCR 常漏句号, 全角半角也不一)。"""
return ''.join(ch for ch in normalize_team_name(text) if not unicodedata.category(ch).startswith('P'))
def _upstream_source(func):
"""上游函数的源码; 先顺着 __wrapped__ 剥掉本模块包的几层。拿不到返回 None。"""
import inspect
try:
return inspect.getsource(inspect.unwrap(func))
except (OSError, TypeError, ValueError):
return None
def _source_calls(func, method, target):
"""上游函数源码里有没有 auto.<method>("<target>" 这样的调用; 拿不到源码返回 None。
补丁靠拦截这类调用挂进上游流程, 上游改了写法就挂不上; 安装时查一下, 免得悄悄失效。
"""
source = _upstream_source(func)
if source is None:
return None
return re.search(r'\.%s\(\s*["\']%s["\']' % (re.escape(method), re.escape(target)), source) is not None
def load_event_choices(path=EVENT_CHOICES_FILE):
"""读事件表, 返回 [{'name', 'match', 'text', 'index'}]; 格式不对抛 ValueError。"""
"""读事件表, 返回 [{'name', 'id', 'options', 'text'}]; 格式不对抛 ValueError。
options 是同一屏其它选项的原文, 全部出现在画面上才认定是这个事件; text 是要点的那一项。
"""
with open(path, encoding='utf-8') as f:
raw = json.load(f)
events = raw.get('events') if isinstance(raw, dict) else None
if not isinstance(events, list):
raise ValueError('顶层应是 {"events": [...]}')
def words(item, key):
value = item.get(key, [])
if not isinstance(value, list) or not all(isinstance(w, str) for w in value):
raise ValueError('%s 的 %s 应是字符串列表' % (item.get('name', '?'), key))
return tuple(normalize_team_name(w) for w in value if normalize_team_name(w))
rules = []
for item in events:
if not isinstance(item, dict):
raise ValueError('events 的每一项应是对象')
name = str(item.get('name') or '?')
index = item.get('index')
if index is not None and (isinstance(index, bool) or not isinstance(index, int) or index < 1):
raise ValueError('%s 的 index 应是 >= 1 的整数' % name)
rule = {'name': name, 'match': words(item, 'match'), 'text': words(item, 'text'), 'index': index}
if not rule['match']:
raise ValueError('%s 缺少 match' % name)
if not rule['text'] and index is None:
raise ValueError('%s 至少要有 text 或 index' % name)
text, others = item.get('text'), item.get('options')
if not isinstance(text, str) or not normalize_event_text(text):
raise ValueError('%s 的 text 应是非空字符串(要点的选项原文)' % name)
if not isinstance(others, list) or not others or \
not all(isinstance(w, str) and normalize_event_text(w) for w in others):
raise ValueError('%s 的 options 应是非空字符串列表(同一屏其它选项的原文)' % name)
rule = {'name': name, 'id': item.get('id'), 'text': normalize_event_text(text),
'options': tuple(normalize_event_text(w) for w in others)}
if any(w in rule['text'] or rule['text'] in w for w in rule['options']):
raise ValueError('%s 的 options 与 text 互相包含, 认不出是哪一项' % name)
rules.append(rule)
return rules
@@ -1057,30 +1029,19 @@ def event_options(markers, lines, scale):
rows = [i for i, m in enumerate(markers)
if x >= float(m[0]) - EVENT_OPTION_LEFT * scale and abs(y - float(m[1])) <= EVENT_OPTION_ROW * scale]
if rows:
texts[min(rows, key=lambda i: abs(y - float(markers[i][1])))].append(normalize_team_name(text))
texts[min(rows, key=lambda i: abs(y - float(markers[i][1])))].append(normalize_event_text(text))
return [(m, ''.join(t)) for m, t in zip(markers, texts)]
def match_event_rule(rules, lines):
"""画面上的文字命中的第一条规则; 没有返回 None。"""
screen = [normalize_team_name(text) for text, _, _ in lines]
def choose_event_option(rules, texts):
"""按画面上的选项认事件: 返回 (规则, 要点第几项(0 起))。
没认出返回 (None, None); 认出了但要点的那项没读到返回 (规则, None)。
"""
for rule in rules:
if any(word in text for word in rule['match'] for text in screen):
return rule
return None
def choose_event_option(rule, texts):
"""返回 (第几项(0 起), 'text'|'index', 理由); 选不出返回 (None, None, 理由)。"""
for word in rule['text']:
for i, text in enumerate(texts):
if word in text:
return i, 'text', '选项文字含「%s」' % word
if rule['index'] is not None:
if rule['index'] <= len(texts):
return rule['index'] - 1, 'index', '按表选第 %d 项' % rule['index']
return None, None, '表里是第 %d 项, 画面上只有 %d 项' % (rule['index'], len(texts))
return None, None, '表里的选项文字不在画面上'
if all(any(word in text for text in texts) for word in rule['options']):
return rule, next((i for i, text in enumerate(texts) if rule['text'] in text), None)
return None, None
def install_event_choices(log=print, env=None):
@@ -1107,17 +1068,18 @@ def install_event_choices(log=print, env=None):
if original is None:
log('[lc_mcp] 事件选项表补丁跳过: 上游没有 Mirror.event_handling')
return None
if _source_calls(original, 'find_element', EVENT_HOOK) is False:
log('[ERROR] [lc_mcp] 事件选项表补丁跳过: 上游 Mirror.event_handling 不再调用 find_element(%r), 挂不上'
% EVENT_HOOK)
return None
def decide(state):
"""按表点了一个选项返回 True; 其余情况返回 False 交给上游。"""
"""按表点了一个选项返回点的位置; 其余情况返回 None 交给上游。"""
markers = auto.find_element(EVENT_OPTION, find_type='image_with_multiple_targets', threshold=0.75)
if not markers:
return False
lines = _ocr_lines(auto)
options = event_options(markers, lines, cfg.set_win_size / 1440)
return None
options = event_options(markers, _ocr_lines(auto), cfg.set_win_size / 1440)
texts = tuple(text for _, text in options)
state['rule'] = state['rule'] or match_event_rule(rules, lines)
rule = state['rule']
shown = ' | '.join('%d=%s' % (i + 1, text or '?') for i, text in enumerate(texts))
def once(message):
@@ -1127,46 +1089,59 @@ def install_event_choices(log=print, env=None):
log(message)
return True
rule, i = choose_event_option(rules, texts)
if rule is None:
if once('[lc_mcp] 事件选项: %s; 表里没有这个事件, 交给 AALC' % shown):
decisions.record('event', None, 'not_in_table', options=list(texts))
return False
i, how, reason = choose_event_option(rule, texts)
if how == 'text' and state['text_clicks'] >= EVENT_TEXT_CLICKS:
how, reason = None, '按文字已点 %d 次' % EVENT_TEXT_CLICKS
if how == 'index' and (state['signature'] not in (None, texts) or state['index_tries'] >= EVENT_INDEX_TRIES):
how, reason = None, '编号只用于第一屏选项'
if how is None:
if once('[lc_mcp] 事件 %s: %s; %s, 交给 AALC' % (rule['name'], shown, reason)):
decisions.record('event', None, 'deferred', event=rule['name'], options=list(texts), why=reason)
return False
if how == 'text':
state['text_clicks'] += 1
else:
state['index_tries'] += 1
state['signature'] = texts
log('[lc_mcp] 事件 %s: %s; 选第 %d 项(%s)' % (rule['name'], shown, i + 1, reason))
decisions.record('event', i + 1, how, event=rule['name'], options=list(texts), why=reason)
position = options[i][0]
return None
why = None
if i is None:
why = '表里要点的「%s」没读到' % rule['text']
elif state['clicks'] >= EVENT_TEXT_CLICKS:
why = '这次事件已按表点了 %d 次' % EVENT_TEXT_CLICKS
if why:
if once('[lc_mcp] 事件 %s: %s; %s, 交给 AALC' % (rule['name'], shown, why)):
decisions.record('event', None, 'deferred', event=rule['name'], event_id=rule['id'],
options=list(texts), why=why)
return None
state['clicks'] += 1
log('[lc_mcp] 事件 %s: %s; 按表选第 %d 项「%s」' % (rule['name'], shown, i + 1, rule['text']))
decisions.record('event', i + 1, 'text', event=rule['name'], event_id=rule['id'], options=list(texts))
position = (float(options[i][0][0]), float(options[i][0][1]))
auto.mouse_click(position[0], position[1])
return True
return position
def event_handling(self, *args, **kwargs):
state = {'rule': None, 'signature': None, 'index_tries': 0, 'text_clicks': 0, 'logged': set()}
real = auto.click_element
state = {'clicks': 0, 'logged': set(), 'clicked': None}
real_find, real_click = auto.find_element, auto.mouse_click
def click_element(target, *a, **kw):
if target == EVENT_HOOK:
try:
if decide(state):
return True # 上游当作点到了选项: event_chance -= 1, 重新截图
except Exception as e:
log('[lc_mcp] 事件选项表出错(%s: %s), 交给 AALC' % (type(e).__name__, e))
return real(target, *a, **kw)
def find_element(target, *a, **kw):
if target != EVENT_HOOK:
return real_find(target, *a, **kw)
if state['clicked'] is not None:
# 刚按表点过: 小指良单通模式的 click_option_avoiding_unknown 会再找一次 "???", 别让它再点
state['clicked'] = None
return None
try:
clicked = decide(state)
except Exception as e:
log('[lc_mcp] 事件选项表出错(%s: %s), 交给 AALC' % (type(e).__name__, e))
clicked = None
if clicked is None:
return real_find(target, *a, **kw)
state['clicked'] = clicked
return clicked # 上游当作找到了 "???": event_chance -= 1, 重新截图
with _override(auto, 'click_element', click_element):
def mouse_click(x, y, *a, **kw):
if state['clicked'] is not None and (x, y) == state['clicked']:
state['clicked'] = None # 上游拿返回的位置再点一次; 已经点过了, 吞掉
return True
return real_click(x, y, *a, **kw)
with _override(auto, 'find_element', find_element), _override(auto, 'mouse_click', mouse_click):
return original(self, *args, **kwargs)
event_handling.__wrapped__ = original # 让后装的补丁查得到上游源码
mirror_mod.Mirror.event_handling = event_handling
log('[lc_mcp] patch: 镜牢事件按选项表选择(%s, %d 条)' % (os.path.basename(path), len(rules)))
return original
@@ -1214,6 +1189,7 @@ def install_shop_audit(log=print):
_override(auto, 'mouse_action_with_pos', mouse_action_with_pos):
return original(self, *args, **kwargs)
buy_gifts.__wrapped__ = original # 让后装的补丁查得到上游源码
Shop.buy_gifts = buy_gifts
log('[lc_mcp] patch: 商店购买写入决策审计')
return original