def load(self): with open(PathManager.get_config_file_path(), 'r') as stream: data = yaml.load(stream, Loader=yaml.Loader) self.config = json.loads( json.dumps(data), object_hook=lambda d: namedtuple('Configs', d.keys())(*d.values()) ) return self
def load(self): filename = f'{self.cell_map:03}{self.cell_x:02}{self.cell_y:02}.map' maps_path = PathManager.get_map_file_path(filename) Logger.debug(f'[Maps] Loading map file: {filename}') if not path.exists(maps_path): Logger.warning(f'Unable to locate map file: {filename}') else: with open(maps_path, "rb") as map_tiles: version = PacketReader.read_string(map_tiles.read(10), 0) if version != MapTile.EXPECTED_VERSION: Logger.error(f'Unexpected map version. Expected "{MapTile.EXPECTED_VERSION}", received "{version}".') return # TODO: AreaFlags # for x in range(0, RESOLUTION_FLAGS + 1): # for y in range(0, RESOLUTION_FLAGS + 1): # self.explore_flag[x][y] = unpack('<H', map_tiles.read(2))[0] # # TODO: AreaTerrain # for x in range(0, RESOLUTION_TERRAIN + 1): # for y in range(0, RESOLUTION_TERRAIN + 1): # self.area_terrain[x][y] = map_tiles.read(1)[0] # # TODO: Liquids # for x in range(0, RESOLUTION_WATER + 1): # for y in range(0, RESOLUTION_WATER + 1): # self.water_level[x][y] = unpack('<f', map_tiles.read(4))[0] # Height Map for x in range(0, RESOLUTION_ZMAP + 1): for y in range(0, RESOLUTION_ZMAP + 1): self.z_coords[x][y] = unpack('<f', map_tiles.read(4))[0]
def load(self): # Set as initialized to avoid another load() call from another thread. self.initialized = True filename = f'{self.cell_map:03}{self.cell_x:02}{self.cell_y:02}.map' maps_path = PathManager.get_map_file_path(filename) Logger.debug( f'[Maps] Loading map file: {filename}, Map:{self.cell_map} Tile:{self.cell_x},{self.cell_y}' ) if not path.exists(maps_path): Logger.warning( f'Unable to locate map file: {filename}, Map:{self.cell_map} Tile:{self.cell_x},{self.cell_y}' ) return else: with open(maps_path, "rb") as map_tiles: version = PacketReader.read_string(map_tiles.read(10), 0) if version != MapTile.EXPECTED_VERSION: Logger.error( f'Unexpected map version. Expected "{MapTile.EXPECTED_VERSION}", found "{version}".' ) return # Height Map for x in range(RESOLUTION_ZMAP): for y in range(RESOLUTION_ZMAP): self.z_height_map[x][y] = unpack( '<f', map_tiles.read(4))[0] # ZoneID, AreaNumber, AreaFlags, AreaLevel, AreaExploreFlag(Bit), AreaFactionMask for x in range(RESOLUTION_AREA_INFO): for y in range(RESOLUTION_AREA_INFO): zone_id = unpack('<i', map_tiles.read(4))[0] if zone_id == -1: # No area information. continue area_number = unpack('<I', map_tiles.read(4))[0] area_flags = unpack('<B', map_tiles.read(1))[0] area_level = unpack('<B', map_tiles.read(1))[0] area_explore_bit = unpack('<H', map_tiles.read(2))[0] area_faction_mask = unpack('<B', map_tiles.read(1))[0] # noinspection PyTypeChecker self.area_information[x][y] = AreaInformation( zone_id, area_number, area_flags, area_level, area_explore_bit, area_faction_mask) # Liquids for x in range(RESOLUTION_LIQUIDS): for y in range(RESOLUTION_LIQUIDS): liquid_type = unpack('<b', map_tiles.read(1))[0] if liquid_type == -1: # No liquid information / not rendered. continue height = unpack('<f', map_tiles.read(4))[0] # noinspection PyTypeChecker self.liquid_information[x][y] = LiquidInformation( liquid_type, height) # This is a valid tile, set as loaded. self.is_valid = True
def get_head_path(): try: with open( path.join(PathManager.get_git_path(), GitUtils.HEAD_FILE_NAME), 'r') as git_head_file: # Contains e.g. ref: ref/heads/master if on "master". git_head_data = str(git_head_file.read()) return git_head_data.split(' ')[1].strip() except (FileNotFoundError, KeyError): return None
def get_current_commit_hash(): head_path = GitUtils.get_head_path() if not head_path: return None try: refs_path = path.join(PathManager.get_git_path(), head_path) # Get the commit hash. with open(refs_path, 'r') as git_head_ref_file: commit_id = git_head_ref_file.read() return commit_id.strip() except FileNotFoundError: return None
def validate_version(): # Use the first available tile map. filename = '0000000.map' maps_path = PathManager.get_map_file_path(filename) if not path.exists(maps_path): return False with open(maps_path, "rb") as map_tiles: version = PacketReader.read_string(map_tiles.read(10), 0) if version != MapTile.EXPECTED_VERSION: return False return True
def release_process(process): retry = True while retry: try: process.close() except ValueError: sleep(0.1) finally: retry = False if __name__ == '__main__': # Initialize colorama colorama.init() # Initialize path PathManager.set_root_path(os.path.realpath(__file__)) # if platform != 'win32': # from signal import signal, SIGPIPE, SIG_DFL # # https://stackoverflow.com/a/30091579 # signal(SIGPIPE, SIG_DFL) # Semaphore objects are leaked on shutdown in macOS if using spawn for some reason. if platform == 'darwin': context = multiprocessing.get_context('fork') else: context = multiprocessing.get_context('spawn') login_process = context.Process( target=RealmManager.LoginServerSessionHandler.start) login_process.start()