From 90fa232f4940b0059ed586c09e899b81750195f4 Mon Sep 17 00:00:00 2001 From: SkywalkerJi Date: Tue, 9 Aug 2022 20:48:02 +0800 Subject: [PATCH] supports v1.2.0 --- README.md | 4 ++- mdt.py | 35 +++++++----------------- mdt_control.py | 20 +++++++------- mdt_cv.py | 47 ++++++++++++++++---------------- mdt_deck_reader.py | 60 ++++++++++++++++++----------------------- mdt_gui.py | 12 ++++++--- mdt_service.py | 5 +++- win7/mdt_deck_reader.py | 16 +++++------ 8 files changed, 92 insertions(+), 107 deletions(-) diff --git a/README.md b/README.md index a348159..8b931f8 100644 --- a/README.md +++ b/README.md @@ -355,12 +355,14 @@ CLI版本在MDT v0.2.3版本进行拆分,拆分后对CLI版本只做基础可 ## Changelog *v0.2.23* -*v0.2.22 beta* * 对游戏steam版本1.2.0进行支持。
展开过往版本 +*v0.2.22 beta* +* 临时支持1.2.0。 + *v0.2.21* * 图像模式更新7月11日新卡hash。by wtof1996 diff --git a/mdt.py b/mdt.py index 26e5856..3878c0e 100644 --- a/mdt.py +++ b/mdt.py @@ -1,4 +1,5 @@ import configparser +import contextlib import ctypes import json import sys @@ -42,7 +43,7 @@ def read_longlongs(pm, base, offsets): return value -def get_cid(type: int): +def get_cid(type: int): # sourcery skip: inline-immediately-returned-variable global pm global deck_addr global duel_addr @@ -168,45 +169,31 @@ def config_load(): global break_point global bgm_list con = configparser.ConfigParser() - try: + with contextlib.suppress(Exception): con.read(config_file, encoding="utf-8") config = con.items("cli") config = dict(config) pause_hotkey = config["pause_hotkey"] switch_hotkey = config["switch_hotkey"] - except Exception: - pass # 加载卡片文本 - try: + with contextlib.suppress(Exception): with open("./locales/zh-CN/cards.json", "rb") as f: cards_db_CN = json.load(f) - except Exception: - pass - try: + with contextlib.suppress(Exception): with open("./locales/zh-TW/cards.json", "rb") as f: cards_db_TW = json.load(f) - except Exception: - pass - try: + with contextlib.suppress(Exception): with open("./data/ur.json", "rb") as f: ur_tier_list = json.load(f) - except Exception: - pass - try: + with contextlib.suppress(Exception): with open("./data/sr.json", "rb") as f: sr_tier_list = json.load(f) - except Exception: - pass - try: + with contextlib.suppress(Exception): with open("./data/breakpoint.json", "rb") as f: break_point = json.load(f) - except Exception: - pass - try: + with contextlib.suppress(Exception): with open("./data/bgm.json", "rb") as f: bgm_list = json.load(f) - except Exception: - pass def get_current_cid(): @@ -217,10 +204,8 @@ def get_current_cid(): def main(): uac_reload() # 加载游戏 - try: + with contextlib.suppress(Exception): get_baseAddress() - except Exception: - pass config_load() keyboard.add_hotkey(switch_hotkey, status_change, args=(True, False, False)) keyboard.add_hotkey(pause_hotkey, status_change, args=(False, True, False)) diff --git a/mdt_control.py b/mdt_control.py index f6a68a7..8f3240b 100644 --- a/mdt_control.py +++ b/mdt_control.py @@ -1,3 +1,4 @@ +import itertools import time import win32gui import pyautogui @@ -29,7 +30,7 @@ def ydk_converter(ydk_deck: list[tuple], locale: str, window, callback=None): # TODO: background click # TODO: 清空当前牌组 # TODO: 等待搜索时间可调 - if ydk_deck is None or ydk_deck == []: + if ydk_deck is None or not ydk_deck: return try: @@ -85,14 +86,11 @@ def ydk_converter(ydk_deck: list[tuple], locale: str, window, callback=None): def travel_through_deck(start, width_step, height_step, target_cid=-1): - # 竖 - for i in range(5): - # 横 - for j in range(6): - click_position = start[0] + width_step * j, start[1] + height_step * i - pyautogui.click(click_position) - cid = get_current_cid() - if cid == target_cid: - return click_position - + # 竖 横 + for i, j in itertools.product(range(5), range(6)): + click_position = start[0] + width_step * j, start[1] + height_step * i + pyautogui.click(click_position) + cid = get_current_cid() + if cid == target_cid: + return click_position return None diff --git a/mdt_cv.py b/mdt_cv.py index 4f2341d..541feea 100644 --- a/mdt_cv.py +++ b/mdt_cv.py @@ -1,3 +1,4 @@ +import contextlib import os import sys from ctypes import windll @@ -12,53 +13,51 @@ cid_show_gui = 0 n_flags = 3 -try: +with contextlib.suppress(Exception): _win_v = sys.getwindowsversion() if _win_v.major == 6 and _win_v.minor == 1: n_flags = 1 -except Exception: - pass windll.user32.SetProcessDPIAware() BOXES = ( ( - (55, 159, 126, 231), # Deck edit - (40, 178, 117, 255), # Live duel + (55, 159, 126, 231), # Deck edit + (40, 178, 117, 255), # Live duel (125, 192, 349, 414), # Card detail - (73, 172, 146, 245), # Opponent Deck + (73, 172, 146, 245), # Opponent Deck ), # 1280x720 ( - (58, 170, 135, 246), - (43, 190, 125, 272), + (58, 170, 135, 246), + (43, 190, 125, 272), (134, 205, 373, 442), - (79, 183, 156, 260), + (79, 183, 156, 260), ), # 1366x768 ( - (61, 179, 142, 259), - (45, 201, 131, 287), + (61, 179, 142, 259), + (45, 201, 131, 287), (141, 216, 392, 466), - (83, 194, 164, 275), + (83, 194, 164, 275), ), # 1440x810 ( - (68, 199, 158, 288), - (50, 223, 146, 319), + (68, 199, 158, 288), + (50, 223, 146, 319), (156, 240, 437, 518), - (93, 215, 182, 305), + (93, 215, 182, 305), ), # 1600x900 ( - (82, 239, 189, 346), - (60, 268, 176, 383), + (82, 239, 189, 346), + (60, 268, 176, 383), (187, 288, 524, 622), (111, 258, 218, 366), ), # 1920x1080 ( - (87, 255, 202, 369), - (64, 286, 187, 409), + (87, 255, 202, 369), + (64, 286, 187, 409), (200, 307, 559, 663), (119, 275, 233, 391), ), # 2048x1152 ( (109, 318, 252, 461), - (80, 357, 235, 511), + (80, 357, 235, 511), (250, 384, 698, 829), (148, 344, 292, 488), ), # 2560x1440 @@ -69,10 +68,10 @@ (186, 430, 365, 610), ), # 3200x1800 ( - (164, 478, 378, 692), - (120, 535, 352, 767), + (164, 478, 378, 692), + (120, 535, 352, 767), (374, 576, 1048, 1244), - (224, 517, 438, 732), + (224, 517, 438, 732), ), # 3840x2160 ) @@ -168,7 +167,7 @@ def get_reset_button_postion(): return position_by_template_matching("reset") -def get_scale(): +def get_scale(): # sourcery skip: inline-immediately-returned-variable # 窗口分辨率可能在程序运行时改变,所以不能是静态变量 hwnd = win32gui.FindWindow(None, "masterduel") box = win32gui.GetClientRect(hwnd) diff --git a/mdt_deck_reader.py b/mdt_deck_reader.py index 464c0ac..95af76f 100644 --- a/mdt_deck_reader.py +++ b/mdt_deck_reader.py @@ -57,14 +57,14 @@ def get_database(path): def get_deck_dict(): main_name = "masterduel.exe" module_name = "GameAssembly.dll" - ma_count_static = 0x01E9AC28 - ma_count_offsets = [0xB8, 0x00, 0xF8, 0x1C8, 0x150, 0x48] - ex_count_static = 0x01E9AC28 - ex_count_offsets = [0xB8, 0x00, 0xF8, 0x1C8, 0x150, 0x18] - ma_cards_static = 0x01E9AC28 - ma_cards_offsets = [0xB8, 0x00, 0xF8, 0x1C8, 0x150, 0x40, 0x20] - ex_cards_static = 0x01E9AC28 - ex_cards_offsets = [0xB8, 0x00, 0xF8, 0x1C8, 0x150, 0x10, 0x20] + ma_count_static = 0x01F501A8 + ma_count_offsets = [0xB8, 0x00, 0xF8, 0x1E8, 0xF0, 0x18] + ex_count_static = 0x01F501A8 + ex_count_offsets = [0xB8, 0x00, 0xF8, 0x1E8, 0x150, 0x18] + ma_cards_static = 0x01F501A8 + ma_cards_offsets = [0xB8, 0x00, 0xF8, 0x1E8, 0x150, 0x40, 0x20] + ex_cards_static = 0x01F501A8 + ex_cards_offsets = [0xB8, 0x00, 0xF8, 0x1E8, 0x150, 0x10, 0x20] deck_dict = {"error": _("无法读取卡组信息")} try: pm = get_process(main_name) @@ -104,26 +104,22 @@ def get_deck_dict(): def get_deck_string(locale: str): - db_name = "./locales/" + locale + "/cards.json" + db_name = f"./locales/{locale}/cards.json" deck_string = "" try: cards_db = get_database(db_name) deck = get_deck_dict() - except Exception: # Exception as e: - # print(e) + except Exception: deck_string += _("无法读取卡组信息") return deck_string if "error" not in deck: deck_string += f"----------------主卡组: {deck['ma_count']}----------------\n" - c = 0 - for cid in deck["ma_cid_list"]: - c += 1 + for c, cid in enumerate(deck["ma_cid_list"], start=1): card_string = "" try: card_info = cards_db[str(cid)] except Exception: card_string += "查无此卡" - try: card_string += f"{card_info['cn_name']} " card_string += f"{card_info['jp_name']} " @@ -131,17 +127,13 @@ def get_deck_string(locale: str): except Exception: card_string += " " + "该卡信息有缺失" deck_string += f"{c:<2} {card_string}\n" - deck_string += f"----------------额外卡组: {deck['ex_count']}----------------\n" - c = 0 - for cid in deck["ex_cid_list"]: - c += 1 + for c, cid in enumerate(deck["ex_cid_list"], start=1): card_string = "" try: card_info = cards_db[str(cid)] except Exception: card_string += "查无此卡" - try: card_string += f"{card_info['cn_name']} " card_string += f"{card_info['jp_name']} " @@ -149,7 +141,6 @@ def get_deck_string(locale: str): except Exception: card_string += " " + "该卡信息有缺失" deck_string += f"{c:<2} {card_string}\n" - return deck_string @@ -217,19 +208,21 @@ def _check_two_array_not_same(deck1: list[int], deck2: list[int]): 例:[1, 2, 2, 4] [2, 3, 4, 4] -> [1, 2] [3, 4] 复杂度:O(n) """ - l, r = 0, 0 + left, right = 0, 0 error1 = [] error2 = [] - while l < len(deck1) or r < len(deck2): - if l < len(deck1) and r < len(deck2) and deck1[l] == deck2[r]: - l += 1 - r += 1 - elif l < len(deck1) and (r == len(deck2) - 1 or deck1[l] < deck2[r]): - error1.append(deck1[l]) - l += 1 - elif r < len(deck2): - error2.append(deck2[r]) - r += 1 + while left < len(deck1) or right < len(deck2): + if left < len(deck1) and right < len(deck2) and deck1[left] == deck2[right]: + left += 1 + right += 1 + elif left < len(deck1) and ( + right == len(deck2) - 1 or deck1[left] < deck2[right] + ): + error1.append(deck1[left]) + left += 1 + elif right < len(deck2): + error2.append(deck2[right]) + right += 1 return error1, error2 @@ -239,8 +232,7 @@ def check_deck(ydk_deck: list[int], locale): deck1 = sorted(list(map(int, _dict["ma_cid_list"] + _dict["ex_cid_list"]))) deck2 = sorted(ydk_deck) error1, error2 = _check_two_array_not_same(deck1, deck2) - - db_name = "./locales/" + locale + "/cards.json" + db_name = f"./locales/{locale}/cards.json" cards_db = get_database(db_name) error1 = [cards_db[str(cid)]["cn_name"] for cid in error1] error2 = [cards_db[str(cid)]["cn_name"] for cid in error2] diff --git a/mdt_gui.py b/mdt_gui.py index 000d0a3..44c94ad 100644 --- a/mdt_gui.py +++ b/mdt_gui.py @@ -153,13 +153,19 @@ def show_break_point(window, cid): tier = service.get_break_point(str(cid)) text = window["-notice-"].get() if tier == 99: - window["-notice-"].update(value=f"{text} " + _("无效·断点"), background_color="#3700B3") + window["-notice-"].update( + value=f"{text} " + _("无效·断点"), background_color="#3700B3" + ) elif tier == 98: - window["-notice-"].update(value=f"{text} " + _("除外·断点"), background_color="#3700B3") + window["-notice-"].update( + value=f"{text} " + _("除外·断点"), background_color="#3700B3" + ) elif tier == 97: - window["-notice-"].update(value=f"{text} " + _("破坏·断点"), background_color="#3700B3") + window["-notice-"].update( + value=f"{text} " + _("破坏·断点"), background_color="#3700B3" + ) else: window["-notice-"].update(background_color="#3F3F3F") diff --git a/mdt_service.py b/mdt_service.py index 2a36b65..0e08e4c 100644 --- a/mdt_service.py +++ b/mdt_service.py @@ -101,7 +101,10 @@ def ydk_converter_callback(): pause() # TODO: 防止二次生成 - thread = Thread(target=mdt_control.ydk_converter, args=(tmp, locale, window, ydk_converter_callback)) + thread = Thread( + target=mdt_control.ydk_converter, + args=(tmp, locale, window, ydk_converter_callback), + ) thread.start() diff --git a/win7/mdt_deck_reader.py b/win7/mdt_deck_reader.py index 5d4b9a9..78ee353 100644 --- a/win7/mdt_deck_reader.py +++ b/win7/mdt_deck_reader.py @@ -57,14 +57,14 @@ def get_database(path): def get_deck_dict(): main_name = "masterduel.exe" module_name = "GameAssembly.dll" - ma_count_static = 0x01E9AC28 - ma_count_offsets = [0xB8, 0x00, 0xF8, 0x1C8, 0x150, 0x48] - ex_count_static = 0x01E9AC28 - ex_count_offsets = [0xB8, 0x00, 0xF8, 0x1C8, 0x150, 0x18] - ma_cards_static = 0x01E9AC28 - ma_cards_offsets = [0xB8, 0x00, 0xF8, 0x1C8, 0x150, 0x40, 0x20] - ex_cards_static = 0x01E9AC28 - ex_cards_offsets = [0xB8, 0x00, 0xF8, 0x1C8, 0x150, 0x10, 0x20] + ma_count_static = 0x01F501A8 + ma_count_offsets = [0xB8, 0x00, 0xF8, 0x1E8, 0xF0, 0x18] + ex_count_static = 0x01F501A8 + ex_count_offsets = [0xB8, 0x00, 0xF8, 0x1E8, 0x150, 0x18] + ma_cards_static = 0x01F501A8 + ma_cards_offsets = [0xB8, 0x00, 0xF8, 0x1E8, 0x150, 0x40, 0x20] + ex_cards_static = 0x01F501A8 + ex_cards_offsets = [0xB8, 0x00, 0xF8, 0x1E8, 0x150, 0x10, 0x20] deck_dict = {"error": _("无法读取卡组信息")} try: pm = get_process(main_name)