def execute(self): self.window_title = ".*" + ".*" window = lybwin.LYBWin('.*check.py.*') window.find_window_wildcard(self.window_title) if len(window.handle_list) < 1: print('Not found window:', self.window_title) sys.exit() # print(window.my_handle) # window.set_invisible(window.my_handle) # window.set_foreground_console(window.handle_list[0]) window.set_foreground_console(window.handle_list[0]) adj_x, adj_y = window.get_player_adjust(window.handle_list[0]) self.anchor_x, self.anchor_y, self.bx, self.by = win32gui.GetWindowRect(window.handle_list[0]) self.anchor_x += adj_x self.anchor_y += adj_y while True: x, y = pyautogui.position() position_str = 'X: ' + str(x).rjust(4) + ' Y: ' + str(y).rjust(4) + \ ' ' + str(pyautogui.pixel(x, y)).rjust(16) + \ ' ' + 'R-X: ' + str(x - self.anchor_x).rjust(4) + ' R-Y: ' + str( y - self.anchor_y).rjust(4) print(position_str, end='') print('\b' * len(position_str), end='', flush=True) time.sleep(0.5)
def __init__(self): super().__init__() self.setupUi(self) self.setWindowTitle(dogfootermacro_title) self.refresh_pushButton.clicked.connect( self.callback_refresh_pushButton_clicked) self.start_pushButton.clicked.connect( self.callback_start_pushButton_clicked) self.stop_pushButton.clicked.connect( self.callback_stop_pushButton_clicked) self.pause_pushButton.clicked.connect( self.callback_pause_pushButton_clicked) self.hide_pushButton.clicked.connect( self.callback_hide_pushButton_clicked) self.show_pushButton.clicked.connect( self.callback_show_pushButton_clicked) self.homepage_pushButton.clicked.connect( self.callback_homepage_pushButton_clicked) self.appPlayer_comboBox.currentIndexChanged.connect( self.callback_appPlayer_comboBox_currentIndexChanged) self.game_comboBox.currentIndexChanged.connect( self.callback_game_comboBox_currentIndexChanged) self.config_comboBox.currentIndexChanged.connect( self.callback_config_comboBox_currentIndexChanged) self.schedule_comboBox.currentIndexChanged.connect( self.callback_schedule_comboBox_currentIndexChanged) self.skip_signal_schedule_comboBox = False self.configure = None self.worker_thread = None self.play_thread = None self.game_object = None # self.search_comboBox.currentIndexChanged.connect(self.callback_search_comboBox_currentIndexChanged) # self.play_button.clicked.connect(self.callback_play_button_clicked) # self.upper_r_slider.valueChanged.connect(self.callback_upper_r_slider_changed) # self.upper_r_spinBox.valueChanged.connect(self.callback_upper_r_spinBox_changed) # self.upper_g_slider.valueChanged.connect(self.callback_upper_g_slider_changed) # self.upper_g_spinBox.valueChanged.connect(self.callback_upper_g_spinBox_changed) # self.upper_b_slider.valueChanged.connect(self.callback_upper_b_slider_changed) # self.upper_b_spinBox.valueChanged.connect(self.callback_upper_b_spinBox_changed) # self.lower_r_slider.valueChanged.connect(self.callback_lower_r_slider_changed) # self.lower_r_spinBox.valueChanged.connect(self.callback_lower_r_spinBox_changed) # self.lower_g_slider.valueChanged.connect(self.callback_lower_g_slider_changed) # self.lower_g_spinBox.valueChanged.connect(self.callback_lower_g_spinBox_changed) # self.lower_b_slider.valueChanged.connect(self.callback_lower_b_slider_changed) # self.lower_b_spinBox.valueChanged.connect(self.callback_lower_b_spinBox_changed) self.win = likeyoubot_win.LYBWin(dogfootermacro_title) self.hwnd_dic = {}
def callback_refresh_pushButton_clicked(self): try: with open(resource_path('lyb.cfg'), 'rb') as dat_file: self.configure = pickle.load(dat_file) self.configure.path = resource_path('lyb.cfg') dogfootermacro_logger.debug('configure.path [' + self.configure.path + ']') except FileNotFoundError: exitMessage = QMessageBox.warning( self, ' ', resource_path('lyb2.cfg') + ' 파일이 없습니다.') sys.exit(1) self.appPlayer_comboBox.clear() try: self.win.find_window_wildcard('') for each_hwnd in self.win.handle_list: dogfootermacro_logger.debug( str(each_hwnd) + ' ' + self.win.get_title(each_hwnd)) if each_hwnd in self.win.parent_handle_dic: title = self.win.get_title( self.win.parent_handle_dic[each_hwnd]) else: title = self.win.get_title(each_hwnd) self.appPlayer_comboBox.addItem(title) self.hwnd_dic[title] = each_hwnd dogfootermacro_logger.debug(self.appPlayer_comboBox.count()) if self.appPlayer_comboBox.count() > 0: self.setEnabledAllButton(True) else: self.setEnabledAllButton(False) self.callback_appPlayer_comboBox_currentIndexChanged() except: self.win = likeyoubot_win.LYBWin(dogfootermacro_title) self.hwnd_dic = {} dogfootermacro_logger.error(traceback.format_exc())
def findWindows(self): self.win = likeyoubot_win.LYBWin(self.configure.window_title, self.configure) wildcard = ".*" + self.configure.keyword + ".*" # wildcard = '.*' # print('DEBUG 1003:', wildcard) self.win.find_window_wildcard(wildcard) # print('DEBUG 1004:', self.win.handle_list) for each_hwnd in self.win.handle_list: # self.win.set_foreground(each_hwnd) time.sleep(0.1) time.sleep(0.1) # self.win.set_foreground(self.win.my_handle) return ( self.win.handle_list, self.win.side_window_dic, self.win.parent_handle_dic, self.win.multi_window_handle_dic)
def execute(self): print(sys.argv) game_name_list = [] for k, v in lybconfigure.LYBConstant.LYB_GAMES.items(): game_name_list.append(k) if len(game_name_list) > 1: if len(sys.argv) > 1: game_number = int(sys.argv[1]) else: print('----------------------') for game_name in game_name_list: print(game_name_list.index(game_name) + 1, game_name) print('----------------------') print("Select Game: ", end='') game_number = input() else: game_number = 0 if len(str(game_number)) == 0: game_number = 0 self.filename = lybconfigure.LYBConstant.LYB_GAMES[game_name_list[ int(game_number) - 1]] + '.lyb' print("filename: ", self.filename) if len(sys.argv) > 2: self.window_title = ".*" + str(sys.argv[2]) + ".*" else: self.window_title = ".*" + ".*" # self.window_title = ".*"+'녹스'+".*" # self.window_title = ".*"+'모모 5'+".*" # self.window_title = '.*' + 'NoxPlayer' + '.*' try: with open(self.resource_path(self.filename), 'rb') as resource_file: self.resource_manager = pickle.load(resource_file) except: self.resource_manager = lybresource.LYBResourceManager( lybresource.LYBPixelBoxDic(), lybresource.LYBResourceDic()) # self.resource_manager.debug() window = lybwin.LYBWin('.*cmd\.exe - python.*make_resource_file.py.*') window.find_window_wildcard(self.window_title) if len(window.handle_list) < 1: print('Not found window:', self.window_title) sys.exit() print(window.my_handle) print("'E' : New resource data") print("'G' : Pick 7x7 pixels") print("'A' : Pick 15x15 pixels") print("'S' : Pick 31x31 pixels") print("'D' : Pick 63x63 pixels") print("'F' : Remove resource data") print("'Z' : Search resource data") print("'W' : Confirm") print("'R' : Redraw") print("'T' : Delete all pixel box not in resource") print("'Q' : Save & Quit") window.set_foreground_console(window.handle_list[0]) print(window.get_player(window.handle_list[0]), game_name_list[int(game_number) - 1]) adj_x, adj_y = window.get_player_adjust(window.handle_list[0]) self.anchor_x, self.anchor_y, self.bx, self.by = win32gui.GetWindowRect( window.handle_list[0]) self.anchor_x += adj_x self.anchor_y += adj_y pass_count_for_name = 10 pixel_box = None resource_pixel_box_list = [] resource_name = '' parent_resource_name = '' current_resource = None resource_type = 'etc' is_working = False is_done = False is_ready = False while True: x, y = pyautogui.position() positionStr = 'X: ' + str(x).rjust(4) + ' Y: ' + str(y).rjust(4) + \ ' ' + str(pyautogui.pixel(x, y)).rjust(16) + \ ' ' + 'R-X: ' + str(x - self.anchor_x).rjust(4) + ' R-Y: ' + str(y - self.anchor_y).rjust(4) print(positionStr, end='') print('\b' * len(positionStr), end='', flush=True) e = win32api.GetAsyncKeyState(ord('E')) a = win32api.GetAsyncKeyState(ord('A')) g = win32api.GetAsyncKeyState(ord('G')) s = win32api.GetAsyncKeyState(ord('S')) d = win32api.GetAsyncKeyState(ord('D')) w = win32api.GetAsyncKeyState(ord('W')) c = win32api.GetAsyncKeyState(ord('C')) f = win32api.GetAsyncKeyState(ord('F')) z = win32api.GetAsyncKeyState(ord('Z')) r = win32api.GetAsyncKeyState(ord('R')) q = win32api.GetAsyncKeyState(ord('Q')) t = win32api.GetAsyncKeyState(ord('T')) h = win32api.GetAsyncKeyState(ord('H')) if pass_count_for_name > 0: pass_count_for_name -= 1 continue if e != 0: print('\nEnter resource_name: ', end='') resource_name = input() if len(resource_name) < 1: continue try: current_resource = self.resource_manager.resource_dic[ resource_name] except: if 'loc' == resource_name.split('_')[-1]: resource_type = 'location' elif 'scene' == resource_name.split('_')[-1]: resource_type = 'scene' elif 'icon' == resource_name.split('_')[-1]: resource_type = 'icon' elif 'event' == resource_name.split('_')[-1]: resource_type = 'event' else: resource_type = 'etc' print('\n', resource_type, '\n') current_resource = lybresource.LYBResource( resource_name, resource_type) pass_count_for_name = len(resource_name) print('\n') # for each_resource_name, each_resource in self.resource_manager.resource_dic.items(): # print(each_resource_name, ':', each_resource.resource_type) print('Enter parent resource_name: ', end='') parent_resource_name = input() if len(parent_resource_name) > 0: try: parent_rsc = self.resource_manager.resource_dic[ parent_resource_name] if parent_rsc.pixel_box_count > 0: for each_pixel_box_name in parent_rsc: current_resource.append(each_pixel_box_name) except: print('Not found parent resource: ', parent_resource_name) pass_count_for_name += len(parent_resource_name) # for each_name, each_resource in self.resource_manager.pixel_box_dic.items(): # print(each_name) print('Enter pixel_box_name to add: ', end='') pixel_box_name = input() plist = pixel_box_name.split(',') for pname in plist: if len(pname) > 0: if not pname in self.resource_manager.pixel_box_dic: print('Not found pixel_box_name: ', pname) else: current_resource.append(pname) pass_count_for_name += len(pixel_box_name) pixel_box = None resource_pixel_box_list = [] is_working = True is_done = False elif f != 0 and is_working == False: print('\n') # for each_resource_name, each_resource in self.resource_manager.resource_dic.items(): # print(each_resource_name, ':', each_resource.resource_type) # for each_pixel_box_name, each_resource in self.resource_manager.pixel_box_dic.items(): # print(each_pixel_box_name, ':', each_resource.height, each_resource.width) print('\nEnter resource_name to delete: ', end='') resource_name = input() if len(resource_name) < 1: continue if resource_name in self.resource_manager.resource_dic: self.resource_manager.resource_dic.pop(resource_name) print('\ndeleted resource: ', resource_name) else: if resource_name in self.resource_manager.pixel_box_dic: self.resource_manager.pixel_box_dic.pop(resource_name) print('\ndeleted pixel box: ', resource_name) for each_resource_name, each_pixel_box in self.resource_manager.resource_dic.items( ): for each_pb_name in self.resource_manager.resource_dic[ each_resource_name]: if each_pb_name == resource_name: self.resource_manager.resource_dic[ each_resource_name].remove(resource_name) print('\ndeleted pixel box name in', each_resource_name) if len(self.resource_manager. resource_dic[each_resource_name]) == 0: self.resource_manager.resource_dic.pop( each_resource_name) pass_count_for_name = len(resource_name) elif z != 0 and is_working == False: print('\nEnter resource_name to search: ', end='') resource_name = input() if len(resource_name) < 1: continue print('\n') for each_resource_name, each_resource in self.resource_manager.resource_dic.items( ): if resource_name in each_resource_name: print(each_resource_name, ':', each_resource.resource_type) for each_pixel_box_name, each_resource in self.resource_manager.pixel_box_dic.items( ): if resource_name in each_pixel_box_name: print(each_pixel_box_name, ':', each_resource.height, each_resource.width) pass_count_for_name = len(resource_name) elif t != 0 and is_working == False: print('\nEnter to confirm: ', end='') resource_name = input() if len(resource_name) < 1: continue new_pixel_box_dic = lybresource.LYBPixelBoxDic() for each_pixel_box_name, each_pixel_box in self.resource_manager.pixel_box_dic.items( ): if not resource_name in each_pixel_box_name: continue for each_resource_name, each_resource in self.resource_manager.resource_dic.items( ): if each_pixel_box in each_resource: new_pixel_box_dic[ each_pixel_box_name] = each_pixel_box break self.resource_manager.pixel_box_dic = new_pixel_box_dic pass_count_for_name = len(resource_name) elif a != 0 or s != 0 or d != 0 or g != 0 or h != 0 and is_ready == True: if h != 0: size = 4 elif g != 0: size = 8 elif a != 0: size = 16 elif s != 0: size = 32 elif d != 0: size = 64 if self.current_grab_window == None or self.epb == None: print('======================DEBUG1') self.current_grab_window = ImageGrab.grab( bbox=(self.anchor_x, self.anchor_y, self.bx, self.by)) # grabbed_image.save('test_grab.png') self.epb = lybresource.LYBExtractPixelBox( self.anchor_x, self.anchor_y, self.current_grab_window.load()) pixel_box = self.epb.extract_pixel_box(x, y, None, size) if pixel_box != None: print('\nEnter pixel box name: ', end='') pixel_box_name = input() pixel_box.pixel_box_name = pixel_box_name resource_pixel_box_list.append(pixel_box) current_resource.append(pixel_box_name) pass_count_for_name = len(pixel_box_name) is_ready = False elif w != 0: if current_resource != None and len(current_resource) > 0: if len(resource_pixel_box_list) > 0: for each_pixel_box in resource_pixel_box_list: self.resource_manager.pixel_box_dic[ each_pixel_box.pixel_box_name] = each_pixel_box self.resource_manager.resource_dic[ resource_name] = current_resource print('\n\n---------------------------------') print('resource name : ', resource_name) if len(parent_resource_name) > 0: print('parent name : ', parent_resource_name) print('pixel box name : ') for each_pixel_box_name in current_resource: print(' ', each_pixel_box_name) print('\nsuccessfully extracted') print('---------------------------------') self.current_grab_window = None else: print('Not found pixel box information') # is_working = False # is_done = True elif r != 0 and is_working == True: index = 0 print('\n') for each_pixel_box_name in self.resource_manager.resource_dic[ resource_name]: each_pixel_box = self.resource_manager.pixel_box_dic[ each_pixel_box_name] print('\n', index, '-----------------------------') print(each_pixel_box_name, each_pixel_box[0][0][0], each_pixel_box[0][0][1]) self.mouseMove(each_pixel_box_name, each_pixel_box[0][0][0] + self.anchor_x, each_pixel_box[0][0][1] + self.anchor_y) index += 1 print('\n') elif q != 0: with open(self.resource_path(self.filename), 'wb') as resource_file: pickle.dump(self.resource_manager, resource_file) sys.exit() else: if is_working == True and is_ready == False: print('\n\n---------------------------------') print('resource name : ', resource_name) if len(parent_resource_name) > 0: print('parent name : ', parent_resource_name) if len(current_resource) > 0: print('pixel box name : ') for each_pixel_box_name in current_resource: print(' ', each_pixel_box_name) print('\npick location') print('---------------------------------') is_ready = True time.sleep(0.5)
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']))