Skip to content

Commit

Permalink
supports v1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
SkywalkerJi committed Aug 9, 2022
1 parent 18063a9 commit 90fa232
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 107 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -355,12 +355,14 @@ CLI版本在MDT v0.2.3版本进行拆分,拆分后对CLI版本只做基础可
## Changelog

*v0.2.23*
*v0.2.22 beta*
* 对游戏steam版本1.2.0进行支持。

<details>
<summary>展开过往版本</summary>

*v0.2.22 beta*
* 临时支持1.2.0。

*v0.2.21*
* 图像模式更新7月11日新卡hash。by wtof1996

Expand Down
35 changes: 10 additions & 25 deletions mdt.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import configparser
import contextlib
import ctypes
import json
import sys
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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():
Expand All @@ -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))
Expand Down
20 changes: 9 additions & 11 deletions mdt_control.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import itertools
import time
import win32gui
import pyautogui
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
47 changes: 23 additions & 24 deletions mdt_cv.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import contextlib
import os
import sys
from ctypes import windll
Expand All @@ -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
Expand All @@ -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
)

Expand Down Expand Up @@ -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)
Expand Down
60 changes: 26 additions & 34 deletions mdt_deck_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -104,52 +104,43 @@ 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']} "
card_string += f"{card_info['en_name']}"
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']} "
card_string += f"{card_info['en_name']}"
except Exception:
card_string += " " + "该卡信息有缺失"
deck_string += f"{c:<2} {card_string}\n"

return deck_string


Expand Down Expand Up @@ -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


Expand All @@ -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]
Expand Down
12 changes: 9 additions & 3 deletions mdt_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
5 changes: 4 additions & 1 deletion mdt_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand Down
Loading

0 comments on commit 90fa232

Please sign in to comment.