from dpnet.packet import Packet class MSG_CHANGE_TEAM(): def __init__(self, player, teamid: int, respawn: bool = True): self.player = player self.teamid = teamid self.respawn = respawn if self.teamid > 255: raise ValueError("Team ID must be < 256") def to_packet(self): p = Packet() p.putByte(0x10) # opcode p.putByte(self.teamid) p.putULong(self.player.id) p.putByte(self.respawn) p.putByte(0x00) # end return p.getvalue() class MSG_MOVE_PLAYER(): def __init__(self, player, direction, orientation): self.player = player self.direction = direction self.orientation = orientation def to_packet(self): p = Packet() p.putByte(0x0f) # opcode p.putByte(0x12) # opcode2? p.putByte(0x00) # unknown p.putByte(0x00) # unknown p.putByte(0x00) # unknown p.putByte(self.player) # player index p.putShort(self.player.oid) p.putByte(0x00) # unknown p.putByte(0x00) # unknown p.putULong(self.player.model()) p.putShort(self.direction) p.putShort(self.orientation) p.putByte(0x00) # end return p.getvalue() class MSG_PLAYER_PING(): def __init__(self, player, ping): self.player = player self.ping = ping def to_packet(self): p = Packet() p.putByte(0x2f) # opcode p.putByte(self.player.get_index()) p.putByte(0x00) # unknown p.putByte(0x00) # unknown p.putShort(self.ping) # ping p.putByte(0x00) # end return p.getvalue() class MSG_SWITCH_WEAPON(): def __init__(self, player, newweapon): self.player = player self.newweapon = newweapon def to_packet(self): p = Packet() p.putByte(0x09) # opcode p.putByte(0x0f) # opcode2? p.putByte(0x00) p.putShort(0x0000) p.putByte(self.player.get_index()) p.putShort(self.player.oid) p.putByte(0x00) p.putByte(0x0a) p.putULong(0x02) p.putByte(self.newweapon) p.putByte(0x00) # end return p.getvalue() class MSG_DROP_WEAPON(): def __init__(self, player, oid, weapon, ammo): self.player = player self.weapon = weapon self.ammo = ammo self.oid = oid def to_packet(self): p = Packet() p.putByte(0x20) # opcode # TODO: fixit p.putShort(0x012e) # can also be 1303 ... oid? my oid was 7 at the time #p.putShort(self.oid) # can also be 1303 ... oid? my oid was 7 at the time p.putShort(0x0000) p.putByte(self.player.get_index()) p.putByte(0x38) p.putShort(0x0000) p.putFloat(self.player.x) p.putFloat(self.player.y) p.putFloat(self.player.z) p.putFloat(self.player.o) p.putFloat(0xc79e28c1) # ?? p.putShort(0x0000) p.putULong(0x70410000) p.putByte(self.weapon) p.putByte(0x00) p.putULong(self.ammo) p.putShort(0x0000) p.putShort(0x0000) p.putByte(0x00) return p.getvalue() class MSG_NEW_PROJECTILE(): def __init__(self, player, oid, projectiletype, x, y, z, o): self.player = player self.x = x self.y = y self.z = z self.o = o self.projectiletype = projectiletype self.oid = oid def to_packet(self): p = Packet() p.putByte(0x09) # opcode p.putULong(0x23) p.putByte(self.player.get_index()) p.putShort(self.player.oid) p.putByte(0x00) p.putByte(0x10) p.putULong(0x02) p.putFloat(self.x) p.putFloat(self.y) p.putFloat(self.z) p.putULong(self.o) p.putShort(self.oid) p.putShort(0x00) p.putByte(self.projectiletype) p.putByte(0x00) return p.getvalue() class MSG_BULLET_EXPLOSION(): def __init__(self, player, oid, x, y, z, isbackpackitem): self.player = player self.oid = oid self.x = x self.y = y self.z = z self.isbackpackitem = isbackpackitem def to_packet(self): p = Packet() p.putByte(0x09) # opcode p.putULong(0x1a) p.putByte(self.player.get_index()) p.putShort(self.oid) p.putByte(0x00) p.putByte(0x03) if not self.isbackpackitem else p.putByte(0x01) # 0x01 for backpackitem, 0x03 for anything else? p.putULong(0x4d) p.putFloat(self.x) p.putFloat(self.y) p.putFloat(self.z) p.putByte(0x00) return p.getvalue() class MSG_PLAYER_DIE(): def __init__(self, player, deathtype): self.player = player self.deathtype = deathtype def to_packet(self): p = Packet() p.putByte(0x0b) # opcode p.putULong(0x1a) p.putByte(0x00) p.putByte(self.player.get_index()) p.putByte(0x07) p.putShort(0x0000) p.putFloat(self.player.x) p.putFloat(self.player.y) p.putFloat(self.player.z) p.putFloat(self.player.o) p.putShort(0x1409) # oid? p.putByte(0x00) p.putShort(0x0000) p.putByte(self.player.get_index()) p.putByte(0x07) p.putShort(0x0000) p.putByte(0x04) p.putByte(0x02) p.putShort(0x0000) p.putByte(0x00) p.putULong(self.deathtype) p.putByte(0x00) p.putByte(0x00) # end return p.getvalue() class MSG_PLAYER_TELEPORT(): def __init__(self, player, newx, newy, newz, newo): self.player = player self.newx = newx self.newy = newy self.newz = newz self.newo = newo def to_packet(self): p = Packet() p.putByte(0x13) # opcode p.putByte(self.player.get_index()) p.putShort(self.player.oid) p.putByte(0x00) p.putFloat(0x00000000) p.putFloat(self.newx) p.putFloat(self.newy) p.putFloat(self.newz) p.putByte(0x00) return p.getvalue() class MSG_PLAYER_USE_BACKPACK(): def __init__(self, player, backpackitem): self.player = player self.backpackitem = backpackitem def to_packet(self): p = Packet() p.putByte(0x09) # opcode p.putULong(0x12) p.putByte(self.player.get_index()) p.putShort(self.player.oid) p.putByte(0x00) p.putByte(self.backpackitem) # popup? p.putULong(0x02) p.putULong(0x46aae90a) # ? p.putByte(0x00) return p.getvalue() class MSG_PLAYER_DROP_BACKPACK(): def __init__(self, player): self.player = player def to_packet(self): p = Packet() p.putByte(0x09) # opcode p.putULong(0x13) p.putByte(self.player.get_index()) p.putShort(self.player.oid) p.putByte(0x11) p.putULong(0x02) p.putULong(0x3a04) p.putByte(0x0a) p.putByte(0x00) return p.getvalue()