def main_process(accept=True, times=1, time_used=7): global STOP STOP.clear() STOP.set() img_dir = os.path.join(__file__, "..", "img") accept_path = os.path.join(img_dir, "accept.png") reject_path = os.path.join(img_dir, "reject.png") while (True): if not env.get("game_multi"): if accept: u.click_if_exists(accept_path, threshold=0.9) else: u.click_if_exists(reject_path, threshold=0.9) u.random_sleep(1, 0.2) else: l = GameInstance(env.get("game_leader_handle"), "xie_zuo") m = GameInstance(env.get("game_member_handle"), "xie_zuo") if accept: l.click_if_exists(accept_path, threshold=0.9) m.click_if_exists(accept_path, threshold=0.9) else: l.click_if_exists(reject_path, threshold=0.9) m.click_if_exists(reject_path, threshold=0.9) u.random_sleep(1, 0.2) if STOP.is_set(): break
def init(): set_debug() center_window(500, 700) # 设置相关路径 mod_path = env.get("game_mods_path") sys.path.append(mod_path) mod_path = env.get("game_utils_path") sys.path.append(mod_path) set_default_game_handle()
def get_mods_list(path=env.get("game_mods_path")): def exclude_dir(dir_name): exclude_dirs = ["__pycache__", "mod_base.py"] if dir_name in exclude_dirs: return False else: return True return list(filter(exclude_dir, os.listdir(path)))
def main_process(times=3): h = env.get("game_leader_handle") l = GameInstance(h, "bai_gui_ye_xing_multi") h = env.get("game_member_handle") m = GameInstance(h, "bai_gui_ye_xing_multi") th1 = threading.Thread(target=b.main_process, args=( times, l.get_handle(), )) th1.setDaemon(True) th1.start() th2 = threading.Thread(target=b.main_process, args=( times, m.get_handle(), )) th2.setDaemon(True) th2.start()
def main_process(threshold=0.7): if env.get("game_multi"): leader_handle = env.get("game_leader_handle") member_handle = env.get("game_member_handle") l = GameInstance(leader_handle, "match_test") m = GameInstance(member_handle, "match_test") template = cv2.imread(l.img_path("template")) l.match(l.get_screenshot(), template, show_result=True) m.match(m.get_screenshot(), template, show_result=True) else: h = env.get("game_default_handle") g = GameInstance(h, "match_test") template = cv2.imread(g.img_path("template")) g.match(g.get_screenshot(), template, threshold=threshold, show_result=True)
def main_process(threshold=0.7, type=0, times=5, time_used=35): h = env.get("game_leader_handle") l = GameInstance(h, "mod_test") h = env.get("game_member_handle") m = GameInstance(h, "mod_test") th1 = threading.Thread(target=leader.main_process, args=( times, time_used, l.get_handle(), )) th1.setDaemon(True) th1.start() th2 = threading.Thread(target=member.main_process, args=( times, time_used, m.get_handle(), )) th2.setDaemon(True) th2.start()
def set_debug(): """ 调试单选框 """ global var_debug if var_debug.get(): logging.basicConfig( format="[%(asctime)s]: %(levelname)s - %(message)s", datefmt='%Y-%m-%d %H:%M:%S', level=logging.DEBUG, handlers=[ logging.FileHandler(env.get("game_log_file_path")), logging.StreamHandler() ]) else: logging.getLogger().setLevel(logging.INFO)
def main_process(times=30, time_used=7): h = env.get("game_default_handle") g = GameInstance(h, "general") for i in range(times): logging.info("Start for times: " + str(i + 1) + ".") logging.info("Search for tiao_zhan.png.") p = g.wait_until(g.img_path("tiao_zhan"), timeout=time_used) g.random_sleep(1) g.random_click(p, 10) p = g.wait_until(g.img_path("sheng_li"), timeout=time_used * 5) p = u.offset_position(p, (300, 300)) u.random_sleep(1, 0.3) u.random_click(p, 20) p = g.wait_until(g.img_path("jie_suan"), timeout=time_used) u.random_sleep(2, 0.3) u.random_click(p, 20) u.toast("执行" + str(times) + "次完成.")
def set_default_game_handle(): """ 设置默认窗口句柄 """ handle = u.get_window_handle(env.get("game_title")) env.set("game_default_handle", handle)
def generate_mods_button(): mods = get_mods_list() row_idx = 0 for mod_name in mods: mod_frame = tk.Frame(window) mod_frame.pack() info_path = os.path.join(env.get("game_mods_path"), mod_name, "package.json") mod = importlib.import_module("mods." + mod_name + ".process") col_idx = 0 with open(info_path, encoding='UTF-8') as f: mod_info = json.load(f) # 可见性 if "visible" in mod_info: if not mod_info["visible"]: continue # 显示名称 if "text" in mod_info: tk.Label(mod_frame, text=mod_info["text"]).grid(row=row_idx, column=col_idx) else: tk.Label(mod_frame, text=mod_name).grid(row=row_idx, column=col_idx) # 常驻后台 if "always_on" in mod_info: th = threading.Thread(target=mod.main_process) th.setDaemon(True) th.start() # 列加一 col_idx = col_idx + 1 if "params" in mod_info: entries = [] param_t = [] for param in mod_info["params"]: if "text" in param: tk.Label(mod_frame, text=param["text"]).grid(row=row_idx, column=col_idx) else: tk.Label(mod_frame, text=param["param"]).grid(row=row_idx, column=col_idx) col_idx = col_idx + 1 entry = tk.Entry(mod_frame, width=5) entries.append(entry) entry.grid(row=row_idx, column=col_idx) if "default" in param: entry.insert(0, str(param["default"])) col_idx = col_idx + 1 if "param_t" in param: param_t.append(param["param_t"]) tk.Button(mod_frame, text="开始", command=partial(button_clicked, mod.main_process, entries, param_t, mod_name=mod_name)).grid(row=row_idx, column=col_idx) else: tk.Button(mod_frame, text="开始", command=partial(mod.main_process)).grid(row=row_idx, column=col_idx) col_idx = col_idx + 1 row_idx = row_idx + 1
from onmyoji import utils as u from gui import multi as m from onmyoji import env import ctypes def SetProcessDPIAware(): # 设置高DPI敏感 ctypes.windll.user32.SetProcessDPIAware() SetProcessDPIAware() window = tk.Tk() window.title(env.get("game_ui_title")) CURRENT_MOD = None var_background = tk.BooleanVar() var_background.set(env.get("game_background")) var_debug = tk.BooleanVar() var_debug.set(True) var_image_grab = tk.BooleanVar() var_image_grab.set(False) var_multi = tk.BooleanVar() var_multi.set(env.get("game_multi"))
def img_path(self, img_name): if self.mod_name_ is None: return None mods_path = env.get("game_mods_path") return os.path.join(mods_path, self.mod_name_, "img", img_name + ".png")