From 522814f57437669d15f14d91b92bfa90c779d12d Mon Sep 17 00:00:00 2001 From: hkc Date: Sat, 26 Aug 2023 16:45:22 +0300 Subject: [PATCH] Some more packets maybe? --- bta_proxy/dpi.py | 4 ++++ bta_proxy/packets/__init__.py | 9 +++++++++ bta_proxy/packets/base.py | 8 ++++++++ bta_proxy/packets/packet100openwindow.py | 10 ++++++++++ bta_proxy/packets/packet130updatesign.py | 12 ++++++++++++ bta_proxy/packets/packet131mapdata.py | 10 ++++++++++ bta_proxy/packets/packet133openguidebook.py | 7 +++++++ bta_proxy/packets/packet134itemdata.py | 8 ++++++++ bta_proxy/packets/packet137updateflag.py | 6 ++++++ bta_proxy/packets/packet139setpaintingmotive.py | 7 +++++++ bta_proxy/packets/packet140tileentitydata.py | 8 ++------ bta_proxy/packets/packet141updateflag.py | 11 +++++++++++ bta_proxy/packets/packet21pickupspawn.py | 3 +-- bta_proxy/packets/packet54playnoteblock.py | 11 +++++++++++ 14 files changed, 106 insertions(+), 8 deletions(-) create mode 100644 bta_proxy/packets/packet100openwindow.py create mode 100644 bta_proxy/packets/packet130updatesign.py create mode 100644 bta_proxy/packets/packet131mapdata.py create mode 100644 bta_proxy/packets/packet133openguidebook.py create mode 100644 bta_proxy/packets/packet134itemdata.py create mode 100644 bta_proxy/packets/packet137updateflag.py create mode 100644 bta_proxy/packets/packet139setpaintingmotive.py create mode 100644 bta_proxy/packets/packet141updateflag.py create mode 100644 bta_proxy/packets/packet54playnoteblock.py diff --git a/bta_proxy/dpi.py b/bta_proxy/dpi.py index 6a111b0..554a650 100644 --- a/bta_proxy/dpi.py +++ b/bta_proxy/dpi.py @@ -56,11 +56,15 @@ async def inspect_server(queue: Queue, addr: tuple[str, int]): continue case Packet51MapChunk.packet_id: continue + case Packet28EntityVelocity.packet_id: + continue case Packet31RelEntityMove.packet_id: continue case Packet32EntityLook.packet_id: continue case Packet33RelEntityMoveLook.packet_id: continue + case Packet73WeatherStatus.packet_id: + continue case _: print(f"S {delta*1000:+8.1f}ms {pkt}") diff --git a/bta_proxy/packets/__init__.py b/bta_proxy/packets/__init__.py index 85ff361..ca11702 100644 --- a/bta_proxy/packets/__init__.py +++ b/bta_proxy/packets/__init__.py @@ -65,3 +65,12 @@ from .packet22collect import Packet22Collect from .packet9respawn import Packet9Respawn from .packet60explosion import Packet60Explosion from .packet60explosion import Packet60Explosion +from .packet54playnoteblock import Packet54PlayNoteBlock +from .packet100openwindow import Packet100OpenWindow +from .packet130updatesign import Packet130UpdateSign +from .packet131mapdata import Packet131MapData +from .packet133openguidebook import Packet133OpenGuidebook +from .packet134itemdata import Packet134ItemData +from .packet137updateflag import Packet137UpdateFlag +from .packet139setpaintingmotive import Packet139SetPaintingMotive +from .packet141updateflag import Packet141UpdateFlag diff --git a/bta_proxy/packets/base.py b/bta_proxy/packets/base.py index e810e5a..05f6368 100644 --- a/bta_proxy/packets/base.py +++ b/bta_proxy/packets/base.py @@ -1,5 +1,6 @@ from typing import Any, ClassVar, Optional, Type, Union +import gzip from bta_proxy.entitydata import EntityData from bta_proxy.itemstack import ItemStack from ..datainputstream import AsyncDataInputStream @@ -144,6 +145,13 @@ class Packet: return None case "entitydata": return await EntityData.read_from(stream) + case "nbt": + size = await stream.read_short() + if size < 0: + raise ValueError("Received tag length is less than zero! Weird tag!") + if size == 0: + return None + return gzip.decompress(await stream.read_bytes(size)) case _: raise ValueError(f"unknown type {datatype}") diff --git a/bta_proxy/packets/packet100openwindow.py b/bta_proxy/packets/packet100openwindow.py new file mode 100644 index 0000000..a79066c --- /dev/null +++ b/bta_proxy/packets/packet100openwindow.py @@ -0,0 +1,10 @@ +from .base import Packet + +class Packet100OpenWindow(Packet, packet_id=100): + __slots__ = ('window_id', 'inv_type', 'title', 'slots') + FIELDS = [ + ('window_id', 'ubyte'), + ('inv_type', 'ubyte'), + ('title', 'str'), + ('slots', 'ubyte'), + ] diff --git a/bta_proxy/packets/packet130updatesign.py b/bta_proxy/packets/packet130updatesign.py new file mode 100644 index 0000000..31cedf0 --- /dev/null +++ b/bta_proxy/packets/packet130updatesign.py @@ -0,0 +1,12 @@ +from .base import Packet + +class Packet130UpdateSign(Packet, packet_id=130): + __slots__ = ('x', 'y', 'z', 'lines', 'picture', 'color') + FIELDS = [ + ('x', 'int'), + ('y', 'short'), + ('z', 'int'), + ('lines', ('list', 4, 'str')), + ('picture', 'int'), + ('color', 'int'), + ] diff --git a/bta_proxy/packets/packet131mapdata.py b/bta_proxy/packets/packet131mapdata.py new file mode 100644 index 0000000..1baa945 --- /dev/null +++ b/bta_proxy/packets/packet131mapdata.py @@ -0,0 +1,10 @@ +from .base import Packet + +class Packet131MapData(Packet, packet_id=131): + __slots__ = ('item', 'meta', 'size', 'data') + FIELDS = [ + ('item', 'short'), + ('meta', 'short'), + ('size', 'ubyte'), + ('data', ('bytes', 'size')), + ] diff --git a/bta_proxy/packets/packet133openguidebook.py b/bta_proxy/packets/packet133openguidebook.py new file mode 100644 index 0000000..a52b95b --- /dev/null +++ b/bta_proxy/packets/packet133openguidebook.py @@ -0,0 +1,7 @@ +from .base import Packet + +class Packet133OpenGuidebook(Packet, packet_id=133): + __slots__ = ('open',) + FIELDS = [ + ('open', 'bool'), + ] diff --git a/bta_proxy/packets/packet134itemdata.py b/bta_proxy/packets/packet134itemdata.py new file mode 100644 index 0000000..41538ab --- /dev/null +++ b/bta_proxy/packets/packet134itemdata.py @@ -0,0 +1,8 @@ +from .base import Packet + +class Packet134ItemData(Packet, packet_id=134): + __slots__ = ('slot', 'data') + FIELDS = [ + ('slot', 'int'), + ('data', 'nbt'), + ] diff --git a/bta_proxy/packets/packet137updateflag.py b/bta_proxy/packets/packet137updateflag.py new file mode 100644 index 0000000..d6eebed --- /dev/null +++ b/bta_proxy/packets/packet137updateflag.py @@ -0,0 +1,6 @@ +from .base import Packet + +class Packet137UpdateFlag(Packet, packet_id=137): + __slots__ = () + FIELDS = [ + ] diff --git a/bta_proxy/packets/packet139setpaintingmotive.py b/bta_proxy/packets/packet139setpaintingmotive.py new file mode 100644 index 0000000..a51efef --- /dev/null +++ b/bta_proxy/packets/packet139setpaintingmotive.py @@ -0,0 +1,7 @@ +from .base import Packet + +class Packet139SetPaintingMotive(Packet, packet_id=139): + __slots__ = ('motive',) + FIELDS = [ + ('motive', 'int'), + ] diff --git a/bta_proxy/packets/packet140tileentitydata.py b/bta_proxy/packets/packet140tileentitydata.py index 915cacd..f226988 100644 --- a/bta_proxy/packets/packet140tileentitydata.py +++ b/bta_proxy/packets/packet140tileentitydata.py @@ -2,11 +2,7 @@ from .base import Packet import gzip class Packet140TileEntityData(Packet, packet_id=140): - __slots__ = ('size', 'data') + __slots__ = ('tag',) FIELDS = [ - ('size', 'short'), - ('data', ('bytes', 'size')), + ('tag', 'nbt') ] - - def post_creation(self): - self.data = gzip.decompress(self.data) diff --git a/bta_proxy/packets/packet141updateflag.py b/bta_proxy/packets/packet141updateflag.py new file mode 100644 index 0000000..9cf6833 --- /dev/null +++ b/bta_proxy/packets/packet141updateflag.py @@ -0,0 +1,11 @@ +from .base import Packet + +class Packet141UpdateFlag(Packet, packet_id=141): + __slots__ = ('x', 'y', 'z', 'colors', 'items') + FIELDS = [ + ('x', 'int'), + ('y', 'short'), + ('z', 'int'), + ('colors', ('bytes', 384)), + ('items', ('list', 3, 'nbt')), + ] diff --git a/bta_proxy/packets/packet21pickupspawn.py b/bta_proxy/packets/packet21pickupspawn.py index 819002c..d28be4b 100644 --- a/bta_proxy/packets/packet21pickupspawn.py +++ b/bta_proxy/packets/packet21pickupspawn.py @@ -6,8 +6,7 @@ class Packet21PickupSpawn(Packet, packet_id=21): ('item_id', 'short'), ('count', 'byte'), ('damage', 'short'), - ('tag_size', 'short'), - ('tag', ('bytes', 'tag_size')), + ('tag', 'nbt'), ('x', 'int'), ('y', 'int'), ('z', 'int'), diff --git a/bta_proxy/packets/packet54playnoteblock.py b/bta_proxy/packets/packet54playnoteblock.py new file mode 100644 index 0000000..459e408 --- /dev/null +++ b/bta_proxy/packets/packet54playnoteblock.py @@ -0,0 +1,11 @@ +from .base import Packet + +class Packet54PlayNoteBlock(Packet, packet_id=54): + __slots__ = ('x', 'y', 'z', 'instrument', 'pitch') + FIELDS = [ + ('x', 'int'), + ('y', 'short'), + ('z', 'int'), + ('instrument', 'ubyte'), + ('pitch', 'ubyte'), + ]