Exemplo n.º 1
0
    def _unpack(self):
        # Discard this value; I'm not sure why this value comes out to a weird
        # float. We have the timestamp of the raw packet, so just that instead
        _ = Packet.unpack_float(self.buffer)

        self.player_id = Packet.unpack_uint8(self.buffer)
        self.state = Packet.unpack_player_state(self.buffer, self.packet.code)
Exemplo n.º 2
0
    def _load_packets(self, buf: BinaryIO) -> None:
        # We've loaded the replay header already, so let's save the current
        # starting position for the packets
        packets_start = buf.tell()

        # Get the full file size and save it
        buf.seek(0, 2)
        file_size = buf.tell()

        # Go back to the start of the packets so we can read them in
        buf.seek(packets_start)

        while True:
            packet = Packet()
            packet.unpack(buf)

            try:
                msg_code = NetworkMessage(packet.code)
                game_packet = GamePacketMap[msg_code]()
                game_packet.packet = packet
                game_packet.timestamp_offset = self.end_time
                game_packet.build()

                self.packets.append(game_packet)
            except KeyError:
                game_code: str = chars_from_code(packet.code)
                self.errors.append(
                    f'Unsupported game packet code: {game_code}')

            # We've reached the end of the replay
            if buf.tell() == file_size:
                break
Exemplo n.º 3
0
    def _unpack(self):
        count: int = Packet.unpack_uint8(self.buffer)

        for i in range(0, count):
            Packet.unpack_uint8(self.buffer)

            p_info: PlayerInfo = PlayerInfo()
            p_info.player_index = Packet.unpack_uint8(self.buffer)
            p_info.ip_address = Packet.unpack_ip_address(self.buffer)

            self.players.append(p_info)
Exemplo n.º 4
0
    def _unpack(self):
        count: int = Packet.unpack_uint8(self.buffer)

        for i in range(0, count):
            data: ScoreData = ScoreData()
            data.player_id = Packet.unpack_uint8(self.buffer)
            data.wins = Packet.unpack_uint16(self.buffer)
            data.losses = Packet.unpack_uint16(self.buffer)
            data.team_kills = Packet.unpack_uint16(self.buffer)

            self.scores.append(data)
Exemplo n.º 5
0
    def _unpack(self):
        count: int = Packet.unpack_uint8(self.buffer)

        for i in range(0, count):
            data: TeamData = TeamData()

            data.team = Packet.unpack_uint16(self.buffer)
            data.size = Packet.unpack_uint16(self.buffer)
            data.wins = Packet.unpack_uint16(self.buffer)
            data.losses = Packet.unpack_uint16(self.buffer)

            self.teams.append(data)
Exemplo n.º 6
0
    def _unpack(self):
        count: int = Packet.unpack_uint16(self.buffer)

        for i in range(0, count):
            setting: BZDBSetting = BZDBSetting()

            name_len: int = Packet.unpack_uint8(self.buffer)
            setting.name = Packet.unpack_string(self.buffer, name_len)

            value_len: int = Packet.unpack_uint8(self.buffer)
            setting.value = Packet.unpack_string(self.buffer, value_len)

            self.settings.append(setting)
Exemplo n.º 7
0
    def _unpack(self):
        count: int = Packet.unpack_uint8(self.buffer)

        for i in range(0, count):
            player = PlayerData()
            player.player_id = Packet.unpack_uint8(self.buffer)

            properties: int = Packet.unpack_uint8(self.buffer)

            player.is_registered = properties & IsRegistered == IsRegistered
            player.is_verified = properties & IsVerified == IsVerified
            player.is_admin = properties & IsAdmin == IsAdmin

            self.players.append(player)
Exemplo n.º 8
0
    def _unpack(self):
        self.player_index = Packet.unpack_uint8(self.buffer)
        self.player_type = Packet.unpack_uint16(self.buffer)
        self.team_value = Packet.unpack_uint16(self.buffer)
        self.score.wins = Packet.unpack_uint16(self.buffer)
        self.score.losses = Packet.unpack_uint16(self.buffer)
        self.score.team_kills = Packet.unpack_uint16(self.buffer)

        self.callsign = Packet.unpack_string(self.buffer, NetworkProtocol.CALLSIGN_LEN)
        self.motto = Packet.unpack_string(self.buffer, NetworkProtocol.MOTTO_LEN)
Exemplo n.º 9
0
    def _calc_timestamps(self, buf: BinaryIO) -> None:
        # We want to load the first packet (a null packet) so we can get its
        # timestamp
        packet: Packet = Packet()
        packet.unpack(buf)

        if packet.timestamp is None:
            raise PacketInvalidError

        self.start_time = packet.timestamp
        self.end_time = packet.timestamp + timedelta(
            microseconds=self.header.file_time)
Exemplo n.º 10
0
    def _unpack(self):
        self.victim_id = Packet.unpack_uint8(self.buffer)
        self.killer_id = Packet.unpack_uint8(self.buffer)
        self.reason = Packet.unpack_uint16(self.buffer)
        self.shot_id = Packet.unpack_uint16(self.buffer)
        self.flag = Packet.unpack_flag(self.buffer)

        if self.reason == code_from_chars('pd'):
            self.physics_driver_id = Packet.unpack_uint32(self.buffer)
Exemplo n.º 11
0
 def _unpack(self):
     self.player_id = Packet.unpack_uint8(self.buffer)
     self.flag_id = Packet.unpack_uint16(self.buffer)
     self.team = Packet.unpack_uint16(self.buffer)
Exemplo n.º 12
0
 def _unpack(self):
     self.player_id = Packet.unpack_uint8(self.buffer)
     self.position = Packet.unpack_vector(self.buffer)
     self.azimuth = Packet.unpack_float(self.buffer)
Exemplo n.º 13
0
 def _unpack(self):
     self.player_id = Packet.unpack_uint8(self.buffer)
     self.from_ = Packet.unpack_uint16(self.buffer)
     self.to = Packet.unpack_uint16(self.buffer)
Exemplo n.º 14
0
 def _unpack(self):
     self.from_ = Packet.unpack_uint8(self.buffer)
     self.to = Packet.unpack_uint8(self.buffer)
     self.flag = Packet.unpack_flag(self.buffer)
Exemplo n.º 15
0
 def _unpack(self):
     self.msb = Packet.unpack_uint32(self.buffer)
     self.lsb = Packet.unpack_uint32(self.buffer)
Exemplo n.º 16
0
 def _unpack(self):
     self.target = Packet.unpack_uint8(self.buffer)
     self.shot = Packet.unpack_shot(self.buffer)
Exemplo n.º 17
0
 def _unpack(self):
     self.player_id = Packet.unpack_uint8(self.buffer)
     self.flag = Packet.unpack_flag(self.buffer)
Exemplo n.º 18
0
    def unpack(self, buf: BinaryIO) -> None:
        self.magic_number = Packet.unpack_uint32(buf)
        self.version = Packet.unpack_uint32(buf)
        self.offset = Packet.unpack_uint32(buf)
        self.file_time = Packet.unpack_int64(buf)
        self.player = Packet.unpack_uint32(buf)
        self.flags_size = Packet.unpack_uint32(buf)
        self.world_size = Packet.unpack_uint32(buf)
        self.callsign = Packet.unpack_string(buf, NetworkProtocol.CALLSIGN_LEN)
        self.motto = Packet.unpack_string(buf, NetworkProtocol.MOTTO_LEN)
        self.server_version = Packet.unpack_string(buf,
                                                   NetworkProtocol.SERVER_LEN)
        self.app_version = Packet.unpack_string(buf,
                                                NetworkProtocol.MESSAGE_LEN)
        self.real_hash = Packet.unpack_string(buf, NetworkProtocol.HASH_LEN)

        self.length = ReplayDuration(self.file_time)

        # Skip the appropriate number of bytes since we're not making use of this
        # data yet

        buf.read(4 + NetworkProtocol.WORLD_SETTING_SIZE)

        if self.flags_size > 0:
            buf.read(self.flags_size)

        buf.read(self.world_size)
Exemplo n.º 19
0
 def _unpack(self):
     self.player_from_id = Packet.unpack_uint8(self.buffer)
     self.player_to_id = Packet.unpack_uint8(self.buffer)
     self.message = Packet.unpack_string(self.buffer, -1)
Exemplo n.º 20
0
 def _unpack(self):
     self.firing_info = Packet.unpack_firing_info(self.buffer)
Exemplo n.º 21
0
 def _unpack(self):
     self.player_id = Packet.unpack_uint8(self.buffer)
     self.paused = Packet.unpack_uint8(self.buffer)
Exemplo n.º 22
0
 def _unpack(self):
     self.time_left = Packet.unpack_int32(self.buffer)