def get_tekken_window_rect(self, foreground_only=False): """ """ window_rect = None try: window_handler = None if foreground_only: if self.is_tekken_foreground_wnd(): window_handler = user32.get_foreground_window() else: window_handler = user32.find_window( lp_class_name='UnrealWindow', lp_window_name='TEKKEN 7 ') if window_handler: if not self.is_tekken_fullscreen(): # Unstyled window + titlebar rect window_rect = actual_rect.get_actual_rect(window_handler) self.adapt_window_rect_to_title_bar(window_rect) else: window_rect = user32.get_window_placement( window_handler).rc_normal_position except OSError: pass return window_rect
def get_updated_state(self, rollback_frame=0): """ """ if self.is_pid_valid() and self.module_address is not None: game_state = [None, None] process_handle = kernel32.open_process(kernel32.PROCESS_VM_READ, False, self.pid) try: if not self.window_handler: try: self.window_handler = user32.find_window( lp_class_name='UnrealWindow', lp_window_name='TEKKEN 7 ') except OSError: pass else: game_state[0] = self.get_graphic_settings(process_handle) player_data_base_address = self.module_address for i, offset in enumerate(self.player_data_pointer_offset): player_data_base_address = self.get_pointer_value( process_handle, player_data_base_address + offset) if not player_data_base_address: break if player_data_base_address == 0: if not self.reacquire_game_state: sys.stdout.write( 'No fight detected. Gamestate not updated.') self.is_in_battle = False self.reacquire_game_state = True self.reacquire_names = True else: last_eight_frames = [] second_address_base = self.get_value_from_address( process_handle, player_data_base_address, is_64bit=True) # for rollback purposes, there are 8 copies of the # game state, each one updatating once every 8 frames for i in range(8): potential_second_address = ( second_address_base + i * self.config['MemoryAddressOffsets'] ['rollback_frame_offset']) potential_frame_count = self.get_value_from_address( process_handle, potential_second_address + self.config['GameDataAddress']['frame_count']) last_eight_frames.append( (potential_frame_count, potential_second_address)) if rollback_frame >= len(last_eight_frames): sys.stdout.write( 'ERROR: requesting {} frame of {} '.format( rollback_frame, len(last_eight_frames)) + 'long rollback frame') rollback_frame = len(last_eight_frames) - 1 best_frame_count, player_data_second_address = sorted( last_eight_frames, key=lambda x: -x[0])[rollback_frame] player_data_frame = self.get_block_data( process_handle, player_data_second_address, self.config['MemoryAddressOffsets'] ['rollback_frame_offset']) bot_facing = self.get_value_from_data_block( player_data_frame, self.config['GameDataAddress']['facing']) timer_in_frames = self.get_value_from_data_block( player_data_frame, self.config['GameDataAddress']['timer_in_frames']) p1_bot, p2_bot = self.initialize_bots( player_data_frame, bot_facing, best_frame_count) if self.reacquire_game_state: self.reacquire_game_state = False sys.stdout.write('Fight detected. Updating gamestate.') self.is_in_battle = True if self.reacquire_names: if (p1_bot.is_character_name_loaded() and p2_bot.is_character_name_loaded()): self.opponent_name = ( self.get_value_at_end_of_pointer_trail( process_handle, 'opponent_name', True)) self.opponent_side = ( self.get_value_at_end_of_pointer_trail( process_handle, 'opponent_side', False)) self.is_player_player_one = ( self.opponent_side == 1) # sys.stdout.write(self.opponent_char_id) # sys.stdout.write(self.is_player_player_one) self.p1_movelist_to_use = ( p1_bot.get_movelist_to_use()) self.p2_movelist_to_use = ( p2_bot.get_movelist_to_use()) p1_movelist_block, p1_movelist_address = ( self.populate_movelists( process_handle, 'p1_movelist')) p2_movelist_block, p2_movelist_address = ( self.populate_movelists( process_handle, 'p2_movelist')) self.p1_movelist_parser = ( MovelistParser.MovelistParser( p1_movelist_block, p1_movelist_address)) self.p2_movelist_parser = ( MovelistParser.MovelistParser( p2_movelist_block, p2_movelist_address)) # self.write_movelists_to_file( # p1_movelist_block, p1_bot.character_name # ) # self.write_movelists_to_file( # p2_movelist_block, p2_bot.character_name # ) # TODO: figure out the actual size of the name # movelist self.p1_movelist_names = p1_movelist_block[ 0x2E8:200000].split(b'\00') self.p2_movelist_names = p2_movelist_block[ 0x2E8:200000].split(b'\00') #sys.stdout.write(p1_movelist_names[(1572 * 2)]) self.reacquire_names = False game_state[1] = GameSnapshot(p1_bot, p2_bot, best_frame_count, timer_in_frames, bot_facing, self.opponent_name, self.is_player_player_one) except (OSError, struct.error, TypeError): self.reacquire_everything() raise OSError finally: kernel32.close_handle(process_handle) return game_state raise OSError('invalid PID or module address')
def is_tekken_minimized(self): window_handler = user32.find_window(lp_class_name='UnrealWindow', lp_window_name='TEKKEN 7 ') return user32.is_iconic(window_handler)