def callback_pause_pushButton_clicked(self): self.worker_thread.command_queue.put_nowait( likeyoubot_message.LYBMessage('pause', None)) if '일시' in self.pause_pushButton.text(): self.pause_pushButton.setText('재시작') else: self.pause_pushButton.setText('일시 정지')
def callback_start_pushButton_clicked(self): self.setEnabledStartButton(False) pass_config = copy.deepcopy(self.configure) pass_config.window_config[self.appPlayer_comboBox.currentText()][self.game_comboBox.currentText()]['schedule_list'] = \ copy.deepcopy(pass_config.window_config['custom_config_dic'][self.config_comboBox.currentText()]['schedule_list']) dogfootermacro_logger.debug( pass_config.window_config[self.appPlayer_comboBox.currentText()][ self.game_comboBox.currentText()]['schedule_list']) self.worker_thread = likeyoubot_worker.LYBWorker( 'Worker', pass_config, queue.Queue(), queue.Queue()) self.worker_thread.daemon = True self.worker_thread.start() hwnd = self.hwnd_dic[self.appPlayer_comboBox.currentText()] side_hwnd = None if hwnd in self.win.side_window_dic: side_hwnd = self.win.side_window_dic[hwnd] parent_hwnd = None if hwnd in self.win.parent_handle_dic: parent_hwnd = self.win.parent_handle_dic[hwnd] started_window_name = self.appPlayer_comboBox.currentText() started_game_name = self.game_comboBox.currentText() if started_game_name in pass_config.window_config[started_window_name]: started_option = pass_config.get_window_config( started_window_name, started_game_name) else: started_option = pass_config.common_config[started_game_name] for key, value in pass_config.common_config[started_game_name].items(): dogfootermacro_logger.debug(key) self.worker_thread.command_queue.put_nowait( likeyoubot_message.LYBMessage('start', [ self.schedule_comboBox.currentIndex() + 1, hwnd, self.appPlayer_comboBox.currentText(), self.game_comboBox.currentText(), started_option, pass_config, pass_config.window_config[ self.appPlayer_comboBox.currentText()], side_hwnd, parent_hwnd, self.win.multi_window_handle_dic, None, ])) self.setWindowTitle(dogfootermacro_title + ' - ' + self.appPlayer_comboBox.currentText() + ' : ' + self.game_comboBox.currentText()) self.play_thread = PlayThread(self) self.play_thread.start()
def callback_hide_pushButton_clicked(self): worker_thread = likeyoubot_worker.LYBWorker('Worker', self.configure, queue.Queue(), queue.Queue()) worker_thread.daemon = True worker_thread.start() worker_thread.command_queue.put_nowait( likeyoubot_message.LYBMessage('watchout2', [ self.configure, 'hide', self.appPlayer_comboBox.currentText(), self.win, self.hwnd_dic ]))
def callback_stop_pushButton_clicked(self): self.setEnabledStartButton(True) self.setWindowTitle(dogfootermacro_title) self.worker_thread.command_queue.put_nowait( likeyoubot_message.LYBMessage('end', None))
def run(self): threading.currentThread().setName('워커쓰레드') recv_msg = None # logger.debug('['+self.name+']'+' start:'+str(threading.currentThread())) while True: try: if self.pause_flag: if self.game is not None: self.game.interval = 9999999 recv_msg = self.command_queue.get() else: recv_msg = self.command_queue.get_nowait() if recv_msg.type == 'end': self.response_queue.put_nowait(likeyoubot_message.LYBMessage('end_return', str(self.window_title))) self.response_queue.join() break elif recv_msg.type == 'start_app_player': self.logger.warn('WORKER: start_app_player') player_type = recv_msg.message[0] multi_hwnd_dic = recv_msg.message[1] window_title = recv_msg.message[2] configure = recv_msg.message[3] window_config = configure.window_config[window_title] window = likeyoubot_win.LYBWin(configure.window_title, configure) if player_type == 'nox': if lybconstant.LYB_MULTI_APP_PLAYER_NAME_NOX in multi_hwnd_dic: mHwnd = multi_hwnd_dic[lybconstant.LYB_MULTI_APP_PLAYER_NAME_NOX] app_player_index = int( window_config[lybconstant.LYB_DO_BOOLEAN_FIX_WINDOW_LOCATION + 'number']) - 1 self.logger.debug('app_player_index: ' + str(app_player_index)) window.mouse_click(mHwnd, 523, 116 + (57 * app_player_index)) elif player_type == 'momo': if lybconstant.LYB_MULTI_APP_PLAYER_NAME_MOMO in multi_hwnd_dic: mHwnd = multi_hwnd_dic[lybconstant.LYB_MULTI_APP_PLAYER_NAME_MOMO] app_player_index = int( window_config[lybconstant.LYB_DO_BOOLEAN_FIX_WINDOW_LOCATION + 'number']) - 1 self.logger.debug('app_player_index: ' + str(app_player_index)) window.mouse_click(mHwnd, 387, 116 + (50 * app_player_index)) self.response_queue.put_nowait( likeyoubot_message.LYBMessage('end_start_app_player', str(self.window_title))) self.response_queue.join() break elif recv_msg.type == 'GetWindowLocation': self.ui = recv_msg.message (handle_list, side_handle_dic, parent_handle_dic, multi_handle_dic) = self.findWindows() for h in handle_list: (anchor_x, anchor_y, end_x, end_y) = self.win.get_window_location(h) if h in parent_handle_dic: window_title = self.win.get_title(parent_handle_dic[h]) else: window_title = self.win.get_title(h) self.logger.info( '창 [' + str(window_title) + '] 위치 정보 현재 위치로 업데이트: ' + str((anchor_x, anchor_y))) if window_title == str(self.ui.app_player_process.get()): self.ui.gui_config_dic[lybconstant.LYB_DO_BOOLEAN_FIX_WINDOW_LOCATION + 'x'].set(anchor_x) self.ui.gui_config_dic[lybconstant.LYB_DO_BOOLEAN_FIX_WINDOW_LOCATION + 'y'].set(anchor_y) self.ui.configure.window_config[window_title][ lybconstant.LYB_DO_BOOLEAN_FIX_WINDOW_LOCATION + 'x'] = anchor_x self.ui.configure.window_config[window_title][ lybconstant.LYB_DO_BOOLEAN_FIX_WINDOW_LOCATION + 'y'] = anchor_y # self.response_queue.put_nowait(likeyoubot_message.LYBMessage('search_hwnd_return', rhwnds_dic)) # self.response_queue.put_nowait(likeyoubot_message.LYBMessage('search_side_hwnd_return', side_handle_dic)) # self.response_queue.put_nowait(likeyoubot_message.LYBMessage('search_parent_hwnd_return', parent_handle_dic)) # self.response_queue.put_nowait(likeyoubot_message.LYBMessage('search_multi_hwnd_return', multi_handle_dic)) # self.response_queue.put_nowait(likeyoubot_message.LYBMessage('search_title_return', window_list)) # self.response_queue.join() break elif recv_msg.type == 'search': window_config = recv_msg.message (handle_list, side_handle_dic, parent_handle_dic, multi_handle_dic) = self.findWindows() self.logger.debug(handle_list) self.logger.debug(parent_handle_dic) window_list, rhwnds_dic = self.set_location(window_config, handle_list, side_handle_dic, parent_handle_dic) self.logger.debug('search window handle list: ' + str(window_list)) self.response_queue.put_nowait(likeyoubot_message.LYBMessage('search_hwnd_return', rhwnds_dic)) self.response_queue.put_nowait( likeyoubot_message.LYBMessage('search_side_hwnd_return', side_handle_dic)) self.response_queue.put_nowait( likeyoubot_message.LYBMessage('search_parent_hwnd_return', parent_handle_dic)) self.response_queue.put_nowait( likeyoubot_message.LYBMessage('search_multi_hwnd_return', multi_handle_dic)) self.response_queue.put_nowait(likeyoubot_message.LYBMessage('search_title_return', window_list)) self.response_queue.join() break # elif recv_msg.type =='hide': # self.ui = recv_msg.message # self.logger.warn('창 숨기기') # self.win = likeyoubot_win.LYBWin(self.ui.configure.window_title, self.ui.configure) # if len(self.ui.parent_hwnds) > 0: # hwnds = self.ui.parent_hwnds # else: # hwnds = self.ui.hwnds # # (handle_list, side_handle_dic, parent_handle_dic, multi_handle_dic) = self.findWindows() # handle_list = [] # for key, each_handle in self.ui.hwnds.items(): # handle_list.append(each_handle) # self.logger.warn(handle_list) # parent_handle_dic = self.ui.parent_hwnds # side_handle_dic = self.ui.side_hwnds # window_list, rhwnds_dic = self.set_location( # self.ui.configure.window_config, # handle_list, # side_handle_dic, # parent_handle_dic, # custom_loc_x=self.ui.master.winfo_screenwidth(), # custom_loc_y=self.ui.master.winfo_screenheight() ) # for key, each_hwnd in hwnds.items(): # self.win.set_invisible(int(each_hwnd)) # self.response_queue.join() # break elif recv_msg.type == 'watchout' or recv_msg.type == 'watchout2': if recv_msg.type == 'watchout': self.ui = recv_msg.message[0] configure = self.ui.configure resolution_w = self.ui.master.winfo_screenwidth() resolution_h = self.ui.master.winfo_screenheight() hwnds = self.ui.hwnds parent_hwnds = self.ui.parent_hwnds side_hwnds = self.ui.side_hwnds else: configure = recv_msg.message[0] win = recv_msg.message[3] resolution_w = win32api.GetSystemMetrics(0) resolution_h = win32api.GetSystemMetrics(1) hwnds = recv_msg.message[4] parent_hwnds = win.parent_handle_dic side_hwnds = win.side_window_dic cmd = recv_msg.message[1] window_name = recv_msg.message[2] self.win = likeyoubot_win.LYBWin(configure.window_title, configure) if cmd == 'show': self.logger.warn('창 보이기') custom_loc_x = 0 custom_loc_y = 0 else: self.logger.warn('창 숨기기' + ' ' + str(resolution_w) + ', ' + str(resolution_h)) custom_loc_x = resolution_w custom_loc_y = resolution_h if window_name == None: # if len(self.ui.parent_hwnds) > 0: # hwnds = self.ui.parent_hwnds # else: # hwnds = self.ui.hwnds # self.ui.searchWindow(None) handle_list = [] for key, each_handle in hwnds.items(): handle_list.append(each_handle) parent_handle_dic = parent_hwnds side_handle_dic = side_hwnds else: win_hwnds = hwnds[window_name] handle_list = [win_hwnds] parent_handle_dic = {} try: parent_handle_dic[win_hwnds] = parent_hwnds[win_hwnds] except: pass side_handle_dic = {} try: side_handle_dic[win_hwnds] = side_hwnds[win_hwnds] except: pass window_list, rhwnds_dic = self.set_location( configure.window_config, handle_list, side_handle_dic, parent_handle_dic, custom_loc_x=custom_loc_x, custom_loc_y=custom_loc_y) if cmd == 'show': for each_hwnd in handle_list: if each_hwnd in parent_hwnds: self.win.set_visible(parent_hwnds[each_hwnd]) else: self.win.set_visible(each_hwnd) else: for each_hwnd in handle_list: if each_hwnd in parent_hwnds: self.win.set_invisible(parent_hwnds[each_hwnd]) else: self.win.set_invisible(each_hwnd) self.response_queue.join() break elif recv_msg.type == 'websocket': self.ui = recv_msg.message threading.currentThread().setName('websocket_worker') # websocket.enableTrace(True) # ws = websocket.WebSocketApp("ws://localhost:18091", # on_message=self.on_message, # on_error=self.on_error, # on_close=self.on_close) # ws.on_open = self.on_open if self.ui.ws is not None: self.ui.ws.run_forever() elif recv_msg.type == 'long_polling': self.ui = recv_msg.message threading.currentThread().setName('long_polling_worker') # self.logger.debug('long_polling_worker started') if self.win is None: self.win = likeyoubot_win.LYBWin(self.ui.configure.window_title, self.ui.configure) elif recv_msg.type == 'thumbnail': self.ui = recv_msg.message[0] window_name = recv_msg.message[1] # img = self.win.get_window_screenshot(self.multi_hwnd, 2) # img_np = np.array(img) # frame = cv2.cvtColor(img_np, cv2.COLOR_BGR2RGB) # cv2.imshow("test", frame) # cv2.waitKey(0) # cv2.destroyAllWindows() win_hwnds = self.ui.hwnds[window_name] self.win = likeyoubot_win.LYBWin(self.ui.configure.window_title, self.ui.configure) (anchor_x, anchor_y, end_x, end_y) = self.win.get_window_location(win_hwnds) adj_x, adj_y = self.win.get_player_adjust(win_hwnds) width = int(self.ui.configure.common_config[lybconstant.LYB_DO_STRING_THUMBNAIL_SIZE + 'width']) height = int(self.ui.configure.common_config[lybconstant.LYB_DO_STRING_THUMBNAIL_SIZE + 'height']) is_shortcut = self.ui.configure.common_config[lybconstant.LYB_DO_STRING_THUMBNAIL_SIZE + 'shortcut'] while (True): win_hwnds = self.ui.hwnds[window_name] # img = ImageGrab.grab(bbox=(anchor_x - adj_x, anchor_y - adj_y, end_x, end_y)) try: img = self.win.get_window_screenshot(win_hwnds, 2) # img = ImageGrab.grab(bbox=(100,10,400,780)) #bbox specifies specific region (bbox= x,y,width,height) except: # self.logger.error(traceback.format_exc()) pass img_np = np.array(img) img_np = cv2.resize(img_np, (width, height), interpolation=cv2.INTER_AREA) frame = cv2.cvtColor(img_np, cv2.COLOR_BGR2RGB) if is_shortcut == True: title = "Press ESC or Q " + str(win_hwnds) else: title = "DogFooter " + str(win_hwnds) cv2.imshow(title, frame) wait_key = cv2.waitKey(25) if is_shortcut == True: if wait_key & 0xFF == ord('q'): break elif wait_key == 27: break if cv2.getWindowProperty(title, 0) == -1: break cv2.destroyAllWindows() break elif recv_msg.type == 'start': self.start_action = True self.start_flag = recv_msg.message[0] self.hwnd = recv_msg.message[1] self.window_title = recv_msg.message[2] self.game_name = recv_msg.message[3] self.game_option = recv_msg.message[4] self.config = recv_msg.message[5] self.common_config = self.config.common_config self.window_config = recv_msg.message[6] self.side_hwnd = recv_msg.message[7] self.parent_hwnd = recv_msg.message[8] self.multi_handle_dic = recv_msg.message[9] self.game_tab = recv_msg.message[10] threading.currentThread().setName(self.window_title) if self.win == None: self.win = likeyoubot_win.LYBWin(self.configure.window_title, self.configure) if self.window_config[lybconstant.LYB_DO_BOOLEAN_USE_INACTIVE_MODE] == False: self.win.set_foreground(self.hwnd) # 무슨 게임이냐에 따라서 try: if self.game_name == lybconstant.LYB_GAME_V4: self.game = likeyoubot_v4.LYBV4(None, None, self.win) # elif self.game_name == lybconstant.LYB_GAME_HUNDREDSOUL: # self.game = likeyoubot_hundredsoul.LYBHundredSoul(None, None, self.win) # elif self.game_name == lybconstant.LYB_GAME_BLACKDESERT: # self.game = likeyoubot_blackdesert.LYBBlackDesert(None, None, self.win) # elif self.game_name == lybconstant.LYB_GAME_BLADE2: # self.game = likeyoubot_blade2.LYBBlade2(None, None, self.win) # elif self.game_name == lybconstant.LYB_GAME_ICARUS: # self.game = likeyoubot_icarus.LYBIcarus(None, None, self.win) # elif self.game_name == lybconstant.LYB_GAME_TALION: # self.game = likeyoubot_talion.LYBTalion(None, None, self.win) self.game.setGameTab(self.game_tab) self.game.setLoggingQueue(self.response_queue) self.game.setCommonConfig(self.config) self.game.setWindowConfig(self.window_config) self.game.setWindowHandle(self.hwnd, self.side_hwnd, self.parent_hwnd, self.multi_handle_dic) self.game.setStartFlag(self.start_flag) except: self.logger.error(traceback.format_exc()) # self.response_queue.put_nowait(likeyoubot_message.LYBMessage('log', 'Thread Game Init Exception:' + str(sys.exc_info()[0]) + '(' +str(sys.exc_info()[1]) + ')')) self.response_queue.put_nowait( likeyoubot_message.LYBMessage('end_return', 'Fail to initialize')) self.response_queue.join() break self.logger.info('[' + self.window_title + '] 창, [' + self.game_name + '] 게임 작업 시작') # self.response_queue.put_nowait( # likeyoubot_message.LYBMessage('log', # '[' + self.window_title + '] 창에서 [' + self.game_name + '] 게임에 대해 작업을 시작합니다') # ) self.app_player_type, resolution = self.win.get_player(self.hwnd) win_width, win_height = self.win.get_player_size(self.hwnd) # print(win_width, win_height) if (self.app_player_type == 'momo' or self.app_player_type == 'memu' ): self.response_queue.put_nowait( likeyoubot_message.LYBMessage('log', '[' + self.window_title + '] 창 크기: ' + str( (win_width, win_height)) + ', 플레이어 종류: ' + '모모/미뮤') ) if (self.window_config[lybconstant.LYB_DO_STRING_INACTIVE_MODE_FLAG] == '윈7' or self.window_config[lybconstant.LYB_DO_BOOLEAN_USE_INACTIVE_MODE] == False): self.logger.warn('앱 플레이어 재시작 기능은 Windows 10 비활성 모드 필수') else: if lybconstant.LYB_MULTI_APP_PLAYER_NAME_MOMO in self.multi_handle_dic: self.multi_hwnd = self.multi_handle_dic[lybconstant.LYB_MULTI_APP_PLAYER_NAME_MOMO] self.logger.critical(str(lybconstant.LYB_MULTI_APP_PLAYER_NAME_MOMO) + '(' + str( self.multi_hwnd) + ') 검색됨') self.logger.critical('앱 플레이어 재시작 기능 사용 가능') # img = self.win.get_window_screenshot(self.multi_hwnd, 2) # img_np = np.array(img) # frame = cv2.cvtColor(img_np, cv2.COLOR_BGR2RGB) # cv2.imshow("test", frame) # cv2.waitKey(0) # cv2.destroyAllWindows() # (anchor_x, anchor_y, end_x, end_y) = self.win.get_window_location(self.hwnd) # adj_x, adj_y = self.win.get_player_adjust(self.hwnd) # self.logger.warn('CP1') # while(True): # # img = ImageGrab.grab(bbox=(anchor_x - adj_x, anchor_y - adj_y, end_x, end_y)) # img = self.win.get_window_screenshot(self.hwnd, 2) # # img = ImageGrab.grab(bbox=(100,10,400,780)) #bbox specifies specific region (bbox= x,y,width,height) # img_np = np.array(img) # img_np = cv2.resize(img_np, (64, 36), interpolation = cv2.INTER_AREA) # frame = cv2.cvtColor(img_np, cv2.COLOR_BGR2RGB) # cv2.imshow("test", frame) # if cv2.waitKey(25) & 0xFF == ord('q'): # break # cv2.destroyAllWindows() # self.logger.warn('CP2') elif self.app_player_type == 'nox': self.response_queue.put_nowait( likeyoubot_message.LYBMessage('log', '[' + self.window_title + '] 창 크기: ' + str( (win_width, win_height)) + ', 플레이어 종류: ' + '녹스') ) else: self.response_queue.put_nowait( likeyoubot_message.LYBMessage('log', '[' + self.window_title + '] 창 크기: ' + str( (win_width, win_height)) + ' - (' + str(likeyoubot_win.LYBWin.WIDTH) + 'x' + str(likeyoubot_win.LYBWin.HEIGHT) + ') 불일치') ) self.response_queue.put_nowait( likeyoubot_message.LYBMessage('end_return', 'Fail to initialize')) self.response_queue.join() break self.game.setAppPlayer(self.app_player_type) elif recv_msg.type == 'pause': if self.pause_flag == True: if self.game != None: self.game.interval = None self.logger.warn("Resume") self.pause_flag = False else: self.logger.warn("Paused") self.pause_flag = True except queue.Empty: pass except: self.logger.error(traceback.format_exc()) self.response_queue.put_nowait(likeyoubot_message.LYBMessage('end_return', str(traceback.format_exc()))) self.response_queue.join() break try: if self.start_action: s = time.time() rc = self.letsgetit() if rc < 0: self.response_queue.put_nowait( likeyoubot_message.LYBMessage('end_return', self.window_title + ' 비정상')) break elif rc == 7000051: self.logger.warn('DEBUG CP - 1') self.response_queue.put_nowait(likeyoubot_message.LYBMessage('stop_app', self.game)) self.response_queue.join() self.game.interval = int( self.common_config[lybconstant.LYB_DO_BOOLEAN_USE_RESTART_APP_PLAYER + 'delay']) - 1 else: self.response_queue.put_nowait(likeyoubot_message.LYBMessage('game_object', self.game)) e = time.time() # print('[DEBUG] Process Game:', round(e-s, 2)) else: if recv_msg is not None and recv_msg.type == 'long_polling': if self.ui is not None: # self.logger.info('long_polling start') rc = self.long_polling() if rc < 0: self.logger.error('long_polling_worker is terminated abnormally.') break except: self.logger.error(traceback.format_exc()) # self.logger.error(str(sys.exc_info()[0]) + '(' +str(sys.exc_info()[1]) + ')') self.response_queue.put_nowait(likeyoubot_message.LYBMessage('end_return', str(traceback.format_exc()))) self.response_queue.join() break if self.game != None and self.game.interval != None: # print('[GAME INTERVAL]:', self.game.interval) if self.game.interval > 0: time.sleep(self.game.interval) self.game.interval = None else: if self.common_config == None: time.sleep(1) else: # print('[INTERVAL]:', float(self.common_config['wakeup_period_entry'])) time.sleep(float(self.common_config['wakeup_period_entry']))