def TalkAscii(text, type=0, hue=0x34, font=1): p = PacketWriter(0x03) p.byte(type) p.ushort(hue) p.ushort(font) p.cstring(text) return p.finish()
def VendorSellReply(vendor_serial, item_serial, amount=1): p = PacketWriter(0x9f) p.uint(vendor_serial) p.ushort(1) p.uint(item_serial) p.ushort(amount) return p.finish()
def data_received(self, data: bytes): """Called when some data is received. :param data: is a bytes object. """ self.log.debug("Received {} bytes".format(len(data))) if self._packets_compression: # TODO Compression is not working at the moment original_data = data[:] compressed_data = data[:] uncompressed_data = self._compression.decompress(compressed_data) self._input += uncompressed_data new_compressed_data = self._compression.compress(uncompressed_data) self.log.debug("Uncompressed data is {} bytes".format(len(data))) else: self._input += data while True and not self._packets_compression: packet: PacketReader = self._packet_from_buffer() if packet is None: break if packet.cmd in self.auto_answer: self.log.debug('Auto answering packet {:#4x}'.format(packet.cmd)) # answer = self.auto_answer[cmd](data=data) if packet.cmd in self.rewriters: self.log.debug('Rewriting packet {:#4x}'.format(packet.cmd)) rewriter = self.rewriters[packet.cmd](packet=packet) packet_data = rewriter.to_data() else: new_packet = PacketWriter(packet.cmd, self.packet_table[packet.cmd]) new_packet.data(packet.raw_data) packet_data = new_packet.finish() self.log.debug('UOClient data_received: packet {:#4X} len {}'.format(packet.cmd, len(packet_data))) # when we connect to the relay we turn decompression on if packet.cmd == 0x8C: self.loop.client_decompress = True # forward data to the client if not self._packets_compression: try: self.server.transport.write(packet_data) self.log.debug('UOClient serv transport write: packet {:#4X}'.format(packet.cmd)) except Exception as e: print("EXC {}".format(e)) if self._packets_compression: try: self.server.transport.write(original_data) self.log.debug('UOClient serv transport write: compressed data') except Exception as e: print("EXC {}".format(e))
def MenuResponse(serial, index): p = PacketWriter(0x7d) p.uint(serial) p.ushort(0) # menu id p.ushort(index) p.ushort(0) # item id p.ushort(0) # hue return p.finish()
def Drop(serial, x, y, z, dest_serial): p = PacketWriter(0x08) p.uint(serial) p.ushort(x) p.ushort(y) p.sbyte(z) p.uint(dest_serial) return p.finish()
def VendorBuyReply(vendor_serial, item_serial, amount=1): p = PacketWriter(0x3b) p.uint(vendor_serial) p.byte(2) # flags p.byte(0) # layer p.uint(item_serial) p.ushort(amount) return p.finish()
def WarMode(warmode): p = PacketWriter(0x72) p.boolean(warmode) p.byte(0) p.byte(0) p.byte(0) return p.finish()
def to_data(self): packet = PacketWriter(0x8C, self.packet_length) packet.ipv4(self.relay.ip) packet.ushort(self.relay.port) packet.uint(self.relay.auth_id) return packet.finish()
def __init__(self, data: bytes, transport: asyncio.WriteTransport, packet_length: int): self.data: bytes = data[:] self.p: uo.packets.UOPacket = uo.packets.UOPacket(self.data, packet_length) self.packet_length = packet_length self.razor_features = uo.packets.RazorFeatures(self.p.from_buffer()) if self.razor_features.features == 0xFE: packet = PacketWriter(0xF0, packet_length) packet.ushort(0x0004) packet.byte(0xFF) transport.write(packet.finish())
def MobileQuery(type, serial): p = PacketWriter(0x34) p.uint(0xedededed) p.byte(type) p.uint(serial) return p.finish()
def EquipRequest(item_serial, layer, target_serial): p = PacketWriter(0x13) p.uint(item_serial) p.byte(layer) p.uint(target_serial) return p.finish()
def Click(serial): p = PacketWriter(0x09) p.uint(serial) return p.finish()
def LiftRequest(serial, amount=0xffff): p = PacketWriter(0x07) p.uint(serial) p.ushort(amount) return p.finish()
def CheckSecureTrade(serial): p = PacketWriter(0x6f) p.byte(0x02) p.uint(serial) p.uint(1) return p.finish()
def RazorHandshakeResponse(): p = PacketWriter(0xf0) p.byte(0xff) return p.finish()
def TargetResponse(type, target_id, flags, serial, x, y, z, graphic): p = PacketWriter(0x6c) p.byte(type) p.uint(target_id) p.byte(flags) p.uint(serial) p.ushort(x) p.ushort(y) p.sshort(z) p.ushort(graphic) return p.finish()
def CancelSecureTrade(serial): p = PacketWriter(0x6f) p.byte(0x01) p.uint(serial) return p.finish()
def PlayCharacter(slot): p = PacketWriter(0x5d) p.uint(0) p.fixstring("", 30) p.ushort(0) p.uint(0) p.fixstring("", 24) p.uint(slot) p.uint(0xdeadbeef) return p.finish()
def SkillLock(skill, lock): p = PacketWriter(0x3a) p.ushort(skill) p.byte(lock) return p.finish()
def Resync(): p = PacketWriter(0x22) p.byte(0) p.byte(0) return p.finish()
def Use(serial): p = PacketWriter(0x06) p.uint(serial) return p.finish()
def WalkRequest(direction, seq): p = PacketWriter(0x02) p.byte(direction) p.byte(seq) p.uint(0) return p.finish()
def AccountLogin(username, password): p = PacketWriter(0x80) p.fixstring(username, 30) p.fixstring(password, 30) p.byte(0) return p.finish()
def GameLogin(username, password, auth_id): p = PacketWriter(0x91) p.uint(auth_id) p.fixstring(username, 30) p.fixstring(password, 30) return p.finish()
def TextCommand(type, command): p = PacketWriter(0x12) p.byte(type) p.cstring(command) return p.finish()
def PlayServer(index): p = PacketWriter(0xa0) p.ushort(index) return p.finish()
def StatLock(stat, lock): p = PacketWriter(0xbf) p.ushort(0x001a) p.byte(stat) p.byte(lock) return p.finish()
def ClientVersion(version): p = PacketWriter(0xbd) p.ucstring(version) return p.finish()
def TalkUnicode(text, keyword=None, type=0, hue=0x34, font=1): assert (type & 0xc0) == 0 if keyword is not None: type |= 0xc0 p = PacketWriter(0xad) p.byte(type) p.ushort(hue) p.ushort(font) p.fixstring('Eng', 4) if keyword is not None: p.byte(0x00) p.byte(0x10 | (keyword >> 8)) p.byte(keyword) p.ucstring(text) return p.finish()
def TalkUnicode(text, keyword, type=0xc0, hue=0x34, font=1): p = PacketWriter(0xad) p.byte(type) p.ushort(hue) p.ushort(font) p.fixstring('Eng', 4) p.byte(0x00) p.byte(0x10) p.byte(keyword) p.cstring(text) return p.finish()
def GumpResponse(serial, gump_id, button_id=1, switches=[]): p = PacketWriter(0xb1) p.uint(serial) p.uint(gump_id) p.uint(button_id) p.uint(len(switches)) for x in switches: p.uint(x) p.uint(0) # number of text responses return p.finish()
def ClientVersion(version): p = PacketWriter(0xbd) p.cstring(version) return p.finish()