def from_bytes(data): movement = Movement() data_io = io.BytesIO(data) header_data = read_struct(data_io, Movement.HEADER_BIN) movement.flags, movement.time = header_data movement.position = Position.from_io(data_io) if movement.flags & MovementFlags.ON_TRANSPORT.value: transport_data = read_struct(data_io, Movement.TRANSPORT_HEADER_BIN) movement.transport_guid = transport_data[0] movement.transport_position = Position.from_io(data_io) if movement.flags & MovementFlags.IS_SWIMMING.value: swimming_data = read_struct(data_io, Movement.SWIMMING_BIN) movement.swim_pitch = swimming_data[0] if movement.flags & MovementFlags.IS_FALLING.value: movement.jump_data = JumpData.from_io(data_io) if movement.flags & MovementFlags.SPLINE_ELEVATION.value: elevation_data = read_struct(data_io, Movement.SPLINE_ELEVATION_BIN) movement.spline_elevation_unk = elevation_data[0] return movement
def _parse_packet(self, packet): packet_io = io.BytesIO(packet) part1_data = read_struct(packet_io, self.PACKET_PART1_BIN) self.build = part1_data[0] self.unk = part1_data[1] account_name_bytes = read_cstring(packet_io, packet_io.tell()) self.account_name = account_name_bytes.decode("ascii") part2_data = read_struct(packet_io, self.PACKET_PART2_BIN) self.client_seed = part2_data[0] self.client_hash = part2_data[1]
def _parse_packet(self, packet): packet_io = io.BytesIO(packet) part1_data = read_struct(packet_io, self.PACKET_PART1_BIN) self.build = part1_data[0] self.unk = part1_data[1] account_name_bytes = read_cstring(packet_io) self.account_name = account_name_bytes.decode("ascii") part2_data = read_struct(packet_io, self.PACKET_PART2_BIN) self.client_seed = part2_data[0] self.client_hash = part2_data[1]
def load(self, dcx_file, dca_offset): dcx_file.seek(dca_offset) unpacked = read_struct(dcx_file, self.ZLIB_CONTAINER_BIN) self.magic = unpacked[0] self.data_offset = unpacked[1] assert self.magic == self.MAGIC assert self.data_offset == self.CONST_OFFSET
def load(self, dcx_file, dcs_offset): dcx_file.seek(dcs_offset) unpacked = read_struct(dcx_file, self.SIZES_BIN) self.magic = unpacked[0] self.uncompressed_size = unpacked[1] self.compressed_size = unpacked[2] assert self.magic == self.MAGIC
def from_io(bytes_io): position = Position() position_data = read_struct(bytes_io, Position.BIN) position.x = position_data[0] position.y = position_data[1] position.z = position_data[2] position.o = position_data[3] return position
def load(self, tpf_file): unpacked = read_struct(tpf_file, self.BIN) self.position = unpacked[0] self.size = unpacked[1] self.unk1 = unpacked[2] self.name_position = unpacked[3] self.unk3 = unpacked[4] self._load_name_and_data(tpf_file)
def _load_entries(self, tpf_file): tpf_file.seek(0) unpacked = read_struct(tpf_file, self.HEADER_BIN) num_entries = unpacked[2] self.data_entries = [None] * num_entries for index in range(num_entries): entry = TpfDataEntry() entry.load(tpf_file) self.data_entries[index] = entry
def _parse_packet(self, packet): packet_io = io.BytesIO(packet) char_name_bytes = read_cstring(packet_io, 0) self.char_name = char_name_bytes.decode("utf8") char_data = read_struct(packet_io, self.PACKET_CHAR_BIN) self.char_race = CharacterRace(char_data[0]) self.char_class = CharacterClass(char_data[1]) self.char_gender = CharacterGender(char_data[2]) self.char_features = char_data[3:8] self.unk_value = char_data[8]
def _parse_packet(self, packet): packet_io = io.BytesIO(packet) char_name_bytes = read_cstring(packet_io) self.char_name = char_name_bytes.decode("utf8") char_data = read_struct(packet_io, self.PACKET_CHAR_BIN) self.char_race = CharacterRace(char_data[0]) self.char_class = CharacterClass(char_data[1]) self.char_gender = CharacterGender(char_data[2]) self.char_features = char_data[3:8] self.unk_value = char_data[8]
def _load_header(self, bnd_file): unpacked = read_struct(bnd_file, self.HEADER_BIN) self.magic = unpacked[0] self.flags = unpacked[1] self.num_entries = unpacked[2] self.data_position = unpacked[3] if self.magic not in self.KNOWN_MAGICS: LOG.debug("Unknown magic {}".format(self.magic.decode("ascii"))) if self.flags not in self.KNOWN_FLAGS: LOG.debug("Unknown flags {}".format(hex(self.flags))) self._set_entry_bin()
def _load_header(self, dcx_file): dcx_file.seek(0) unpacked = read_struct(dcx_file, self.HEADER_BIN) self.magic = unpacked[0] self.unk1 = unpacked[1] self.dcs_offset = unpacked[2] self.dcp_offset = unpacked[3] self.unk2 = unpacked[4] self.unk3 = unpacked[5] assert self.magic == self.MAGIC assert self.unk1 == self.CONST_UNK1 assert self.dcs_offset == self.HEADER_BIN.size assert self.dcp_offset == self.dcs_offset + DcxSizes.SIZES_BIN.size assert self.unk2 == self.dcp_offset assert self.unk3 == self.dcp_offset + 0x8
def from_client(data): message = ClientChatMessage() data_io = io.BytesIO(data) header_data = read_struct(data_io, ClientChatMessage.HEADER_BIN) message.message_type = ChatMessageType(header_data[0]) message.language = Language(header_data[1]) if message.message_type == ChatMessageType.CHANNEL: channel_name = read_cstring(data_io) message.channel_name = channel_name.decode("utf8") content = read_cstring(data_io) message.content = content.decode("utf8") return message
def from_client(data): message = ClientChatMessage() data_io = io.BytesIO(data) header_data = read_struct(data_io, ClientChatMessage.HEADER_BIN) message.message_type = ChatMessageType(header_data[0]) message.language = Language(header_data[1]) if message.message_type == ChatMessageType.CHANNEL: channel_name = read_cstring(data_io, data_io.tell()) message.channel_name = channel_name.decode("utf8") content = read_cstring(data_io, data_io.tell()) message.content = content.decode("utf8") return message
def load(self, dcx_file, dcp_offset): dcx_file.seek(dcp_offset) unpacked = read_struct(dcx_file, self.PARAMETERS_BIN) self.magic = unpacked[0] self.method = unpacked[1] self.dca_offset = unpacked[2] self.unk1 = unpacked[3] self.unk2 = unpacked[4] self.unk3 = unpacked[5] self.unk4 = unpacked[6] self.unk5 = unpacked[7] assert self.magic == self.MAGIC assert self.method == self.METHOD assert self.dca_offset == self.PARAMETERS_BIN.size assert self.unk1 == self.CONST_UNK1 assert self.unk2 == 0 assert self.unk3 == 0 assert self.unk4 == 0 assert self.unk5 == self.CONST_UNK5
def load(self, bnd_flags, bnd_file): """ Load the BND entry, decode its path and load its data. """ if bnd_flags & BndFlags.HAS_24B_ENTRIES: entry_struct = self.ENTRY_24B_BIN else: entry_struct = self.ENTRY_20B_BIN unpacked = read_struct(bnd_file, entry_struct) self.unk1 = unpacked[0] self.data_size = unpacked[1] self.data_position = unpacked[2] self.ident = unpacked[3] self.path_position = unpacked[4] if len(unpacked) > 5: self.unk2 = unpacked[5] else: self.unk2 = self.data_size assert self.unk1 == self.CONST_UNK1 assert self.unk2 == self.data_size self._load_name_and_data(bnd_file)
def from_io(bytes_io): jump = JumpData() data = read_struct(bytes_io, JumpData.BIN) jump.time, jump.velocity, jump.sin, jump.cos, jump.xy_speed = data return jump