Added more packets
This commit is contained in:
parent
de25182868
commit
358289cf42
|
@ -2,14 +2,26 @@
|
|||
from asyncio.queues import Queue
|
||||
|
||||
from bta_proxy.datainputstream import AsyncDataInputStream
|
||||
from bta_proxy.packets.base import Packet
|
||||
from bta_proxy.packets import *
|
||||
|
||||
|
||||
async def inspect_client(queue: Queue, addr: tuple[str, int]):
|
||||
dis = AsyncDataInputStream(queue)
|
||||
while True:
|
||||
pkt = await Packet.read_packet(dis)
|
||||
print("C", pkt)
|
||||
match pkt.packet_id:
|
||||
case Packet10Flying.packet_id:
|
||||
continue
|
||||
case Packet11PlayerPosition.packet_id:
|
||||
continue
|
||||
case Packet12PlayerLook.packet_id:
|
||||
continue
|
||||
case Packet13LookMove.packet_id:
|
||||
continue
|
||||
case Packet255KickDisconnect.packet_id:
|
||||
break
|
||||
case _:
|
||||
print("C", pkt)
|
||||
|
||||
async def inspect_server(queue: Queue, addr: tuple[str, int]):
|
||||
dis = AsyncDataInputStream(queue)
|
||||
|
|
|
@ -12,3 +12,20 @@ from .packet24mobspawn import Packet24MobSpawn
|
|||
from .packet4updatetime import Packet4UpdateTime
|
||||
from .packet138playerlist import Packet138PlayerList
|
||||
from .packet72updateplayerprofile import Packet72UpdatePlayerProfile
|
||||
from .packet135placementmode import Packet135PlacementMode
|
||||
from .packet13lookmove import Packet13LookMove
|
||||
from .packet11playerposition import Packet11PlayerPosition
|
||||
from .packet12playerlook import Packet12PlayerLook
|
||||
from .packet10flying import Packet10Flying
|
||||
from .packet101closewindow import Packet101CloseWindow
|
||||
from .packet14blockdig import Packet14BlockDig
|
||||
from .packet18animation import Packet18Animation
|
||||
from .packet19entityaction import Packet19EntityAction
|
||||
from .packet17sleep import Packet17Sleep
|
||||
from .packet17sleep import Packet17Sleep
|
||||
from .packet16blockitemswitch import Packet16BlockItemSwitch
|
||||
from .packet15place import Packet15Place
|
||||
from .packet15place import Packet15Place
|
||||
from .packet255kickdisconnect import Packet255KickDisconnect
|
||||
from .packet255kickdisconnect import Packet255KickDisconnect
|
||||
from .packet102windowclick import Packet102WindowClick
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
from typing import Any, ClassVar, Type
|
||||
|
||||
from bta_proxy.entitydata import EntityData
|
||||
from bta_proxy.itemstack import ItemStack
|
||||
from ..datainputstream import AsyncDataInputStream
|
||||
|
||||
class Packet:
|
||||
|
@ -16,11 +17,11 @@ class Packet:
|
|||
async def read_data_from(cls, stream: AsyncDataInputStream) -> 'Packet':
|
||||
fields: dict = {}
|
||||
for key, datatype in cls.FIELDS:
|
||||
fields[key] = await cls.read_field(stream, datatype)
|
||||
fields[key] = await cls.read_field(stream, datatype, fields)
|
||||
return cls(**fields)
|
||||
|
||||
@staticmethod
|
||||
async def read_field(stream: AsyncDataInputStream, datatype: Any):
|
||||
async def read_field(stream: AsyncDataInputStream, datatype: Any, fields: dict[str, Any] = {}):
|
||||
match datatype:
|
||||
case 'uint':
|
||||
return await stream.read_uint()
|
||||
|
@ -30,6 +31,10 @@ class Packet:
|
|||
return await stream.read_string()
|
||||
case 'str', length:
|
||||
return (await stream.read_string())[:length]
|
||||
case 'string':
|
||||
return await stream.read_string()
|
||||
case 'string', length:
|
||||
return (await stream.read_string())[:length]
|
||||
case 'ulong':
|
||||
return await stream.read_ulong()
|
||||
case 'long':
|
||||
|
@ -46,8 +51,22 @@ class Packet:
|
|||
return await stream.read_double()
|
||||
case 'bool':
|
||||
return await stream.read_boolean()
|
||||
case 'bytes', length:
|
||||
return await stream.read_bytes(length)
|
||||
case 'bytes', length_or_key:
|
||||
if isinstance(length_or_key, int):
|
||||
return await stream.read_bytes(length_or_key)
|
||||
elif isinstance(length_or_key, str):
|
||||
if length_or_key not in fields:
|
||||
raise KeyError(f'failed to find {length_or_key} in {fields} to read bytes length')
|
||||
return await stream.read_bytes(fields[length_or_key])
|
||||
raise ValueError(f'invalid type for bytes length_or_key: {length_or_key!r}')
|
||||
case 'itemstack':
|
||||
return await ItemStack.read_from(stream)
|
||||
case 'itemstack_optional':
|
||||
if (item_id := await stream.read_short()) >= 0:
|
||||
count = await stream.read()
|
||||
data = await stream.read_short()
|
||||
return ItemStack(item_id, count, data)
|
||||
return None
|
||||
case 'entitydata':
|
||||
return await EntityData.read_from(stream)
|
||||
case _:
|
||||
|
@ -62,7 +81,7 @@ class Packet:
|
|||
async def read_packet(cls, stream: AsyncDataInputStream) -> 'Packet':
|
||||
packet_id: int = await stream.read()
|
||||
if packet_id not in cls.REGISTRY:
|
||||
raise ValueError(f'invalid packet 0x{packet_id:02x}')
|
||||
raise ValueError(f'invalid packet 0x{packet_id:02x} ({packet_id})')
|
||||
pkt = await cls.REGISTRY[packet_id].read_data_from(stream)
|
||||
pkt.packet_id = packet_id
|
||||
return pkt
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
from .base import Packet
|
||||
|
||||
class Packet101CloseWindow(Packet, packet_id=101):
|
||||
FIELDS = [
|
||||
('window_id', 'byte'),
|
||||
]
|
|
@ -0,0 +1,13 @@
|
|||
from bta_proxy.datainputstream import AsyncDataInputStream
|
||||
from bta_proxy.itemstack import ItemStack
|
||||
from .base import Packet
|
||||
|
||||
class Packet102WindowClick(Packet, packet_id=102):
|
||||
FIELDS = [
|
||||
('window_id', 'byte'),
|
||||
('action', 'byte'),
|
||||
('size', 'byte'),
|
||||
('args', ('bytes', 'size')),
|
||||
('action_id', 'short'),
|
||||
('item', 'itemstack_optional')
|
||||
]
|
|
@ -0,0 +1,6 @@
|
|||
from .base import Packet
|
||||
|
||||
class Packet10Flying(Packet, packet_id=10):
|
||||
FIELDS = [
|
||||
('grounded', 'bool'),
|
||||
]
|
|
@ -0,0 +1,10 @@
|
|||
from .base import Packet
|
||||
|
||||
class Packet11PlayerPosition(Packet, packet_id=11):
|
||||
FIELDS = [
|
||||
('x', 'double'),
|
||||
('y', 'double'),
|
||||
('stance', 'double'),
|
||||
('z', 'double'),
|
||||
('grounded', 'bool'),
|
||||
]
|
|
@ -0,0 +1,8 @@
|
|||
from .base import Packet
|
||||
|
||||
class Packet12PlayerLook(Packet, packet_id=12):
|
||||
FIELDS = [
|
||||
('yaw', 'float'),
|
||||
('pitch', 'float'),
|
||||
('grounded', 'bool'),
|
||||
]
|
|
@ -0,0 +1,9 @@
|
|||
from .base import Packet
|
||||
|
||||
class Packet135PlacementMode(Packet, packet_id=135):
|
||||
FIELDS = [
|
||||
('rotation', 'byte'),
|
||||
('horizontal', 'byte'),
|
||||
('vertical', 'byte'),
|
||||
('mode', 'byte'),
|
||||
]
|
|
@ -0,0 +1,12 @@
|
|||
from .base import Packet
|
||||
|
||||
class Packet13LookMove(Packet, packet_id=13):
|
||||
FIELDS = [
|
||||
('x', 'double'),
|
||||
('y', 'double'),
|
||||
('stance', 'double'),
|
||||
('z', 'double'),
|
||||
('yaw', 'float'),
|
||||
('pitch', 'float'),
|
||||
('grounded', 'bool'),
|
||||
]
|
|
@ -0,0 +1,10 @@
|
|||
from .base import Packet
|
||||
|
||||
class Packet14BlockDig(Packet, packet_id=14):
|
||||
FIELDS = [
|
||||
('status', 'byte'),
|
||||
('x', 'int'),
|
||||
('y', 'byte'),
|
||||
('z', 'int'),
|
||||
('side', 'byte'),
|
||||
]
|
|
@ -0,0 +1,11 @@
|
|||
from .base import Packet
|
||||
|
||||
class Packet15Place(Packet, packet_id=15):
|
||||
FIELDS = [
|
||||
('x', 'int'),
|
||||
('y', 'byte'),
|
||||
('z', 'int'),
|
||||
('direction', 'byte'),
|
||||
('y_placed', 'double'),
|
||||
('item', 'itemstack_optional')
|
||||
]
|
|
@ -0,0 +1,6 @@
|
|||
from .base import Packet
|
||||
|
||||
class Packet16BlockItemSwitch(Packet, packet_id=16):
|
||||
FIELDS = [
|
||||
('item_id', 'short'),
|
||||
]
|
|
@ -0,0 +1,10 @@
|
|||
from .base import Packet
|
||||
|
||||
class Packet17Sleep(Packet, packet_id=17):
|
||||
FIELDS = [
|
||||
('entity_id', 'int'),
|
||||
('field_22046_e', 'byte'),
|
||||
('x', 'int'),
|
||||
('y', 'int'),
|
||||
('z', 'int'),
|
||||
]
|
|
@ -0,0 +1,7 @@
|
|||
from .base import Packet
|
||||
|
||||
class Packet18Animation(Packet, packet_id=18):
|
||||
FIELDS = [
|
||||
('entity_id', 'int'),
|
||||
('animate', 'byte'),
|
||||
]
|
|
@ -0,0 +1,7 @@
|
|||
from .base import Packet
|
||||
|
||||
class Packet19EntityAction(Packet, packet_id=19):
|
||||
FIELDS = [
|
||||
('entity_id', 'int'),
|
||||
('state', 'byte'),
|
||||
]
|
|
@ -0,0 +1,6 @@
|
|||
from .base import Packet
|
||||
|
||||
class Packet255KickDisconnect(Packet, packet_id=255):
|
||||
FIELDS = [
|
||||
('reason', ('str', 200)),
|
||||
]
|
Loading…
Reference in New Issue