def damage_request(name='damage_request'): return Struct(name, UBInt32('source_entity_id'), UBInt32('target_entity_id'), UBInt8('hit_type'), UBInt8('damage_type'), BFloat32('damage'), BFloat32('knockback_x'), BFloat32('knockback_y'), UBInt32('source_entity_id_wut'), star_string('damage_source_kind'), GreedyRange(star_string('stuats_effects')))
def world_start(name='world_start'): return Struct( name, Variant('planet'), StarByteArray('sky_data'), StarByteArray('weather_data'), BFloat32('x'), BFloat32('y'), # Dungeon ID stuff here Variant('world_properties'), UBInt32('client_id'), Flag('local_interpolation'))
def _parse(self, stream, context): l = VLQ('').parse_stream(stream) c = {} for x in range(l): junk1 = Byte('').parse_stream(stream) junk2 = Byte('').parse_stream(stream) junk3 = BFloat32('').parse_stream(stream) junk4 = Byte('').parse_stream(stream) junk5 = StarByteArray('').parse_stream(stream) return c
DUMP_ALL_PACKETS = False # Our tricky Java string decoder. # Note that Java has a weird encoding for the NULL byte which we do not # respect or honor since no client will generate it. Instead, we will get two # NULL bytes in a row. AlphaString = functools.partial(PascalString, length_field=UBInt16("length"), encoding="utf8") # Flying, position, and orientation, reused in several places. grounded = Struct("grounded", UBInt8("grounded")) position = Struct("position", BFloat64("x"), BFloat64("y"), BFloat64("stance"), BFloat64("z")) orientation = Struct("orientation", BFloat32("rotation"), BFloat32("pitch")) # Notchian item packing items = Struct( "items", SBInt16("primary"), If( lambda context: context["primary"] >= 0, Embed( Struct( "item_information", UBInt8("count"), UBInt16("secondary"), )), ), )
def entity_interact(name='entity_interact'): return Struct(name, UBInt32('source_entity_id'), BFloat32('source_x'), BFloat32('source_y'), UBInt32('target_entity_id'))
VERSION=1, DATA_START=2, DATA_STOP=3, SENSOR_MAP=9, DATA_RATE=10 ), UBInt32('sending_node'), # byes 16-19 If(lambda ctx: ctx.payload_length > 8, # Message data is optional # message_length: bytes 20-23, message: bytes 24+ PascalString('message', length_field=UBInt32('message_length'), encoding='ascii') ) ) _EEG_data = Struct('embedded', BFloat32('timestamp'), # bytes 12-15 UBInt8('data_counter'), # byte 16; Unused, just 0 currently Field('ADC_status', 6), # bytes 17-22 Array(lambda ctx: (ctx.payload_length - 11)/4, BFloat32('sensor_data')) # bytes 23-26, 27-30, etc. ) _null = Struct('embedded', Array(111, UBInt8('none')) ) DSI_streamer_packet = Struct('DSI_streamer_packet', Embed(_header), Switch('payload', lambda ctx: ctx.type, {"NULL": Embed(_null),
encoding="ucs2", ) # Boolean converter. def Bool(*args, **kwargs): return Flag(*args, default=True, **kwargs) # Flying, position, and orientation, reused in several places. grounded = Struct("grounded", UBInt8("grounded")) position = Struct("position", BFloat64("x"), BFloat64("y"), BFloat64("stance"), BFloat64("z")) orientation = Struct("orientation", BFloat32("yaw"), BFloat32("pitch")) def ByteString(name, size_name, encoding=None): return StringAdapter(MetaField("data", lambda ctx: ctx[size_name]), encoding=encoding) class NBTAdapter(Adapter): def _decode(self, obj, context): return NBTFile(StringIO(obj), compression=NBTFile.Compression.GZIP) def NBTdata(name, size_name): return NBTAdapter(MetaField(name, lambda ctx: ctx[size_name]))
MetaField("data", lambda ctx: ctx["length"] * 2), )), encoding="ucs2", ) # Boolean converter. def Bool(*args, **kwargs): return Flag(*args, default=True, **kwargs) # Flying, position, and orientation, reused in several places. grounded = Struct("grounded", UBInt8("grounded")) position = Struct("position", BFloat64("x"), BFloat64("y"), BFloat64("stance"), BFloat64("z")) orientation = Struct("orientation", BFloat32("rotation"), BFloat32("pitch")) # TODO: this must be replaced with 'slot' (see below) # Notchian item packing (slot data) items = Struct( "items", SBInt16("primary"), If( lambda context: context["primary"] >= 0, Embed( Struct( "item_information", UBInt8("count"), UBInt16("secondary"), Magic("\xff\xff"), )),
encoding="ucs2", ) # Boolean converter. def Bool(*args, **kwargs): return Flag(*args, default=True, **kwargs) # Flying, position, and orientation, reused in several places. grounded = Struct("grounded", UBInt8("grounded")) position = Struct("position", BFloat64("x"), BFloat64("y"), BFloat64("stance"), BFloat64("z") ) orientation = Struct("orientation", BFloat32("rotation"), BFloat32("pitch")) # Notchian item packing items = Struct("items", SBInt16("primary"), If(lambda context: context["primary"] >= 0, Embed(Struct("item_information", UBInt8("count"), UBInt16("secondary"), Magic("\xff\xff"), )), ), ) Metadata = namedtuple("Metadata", "type value") metadata_types = ["byte", "short", "int", "float", "string", "slot",
FXB_REGULAR='FxBk', FXB_OPAQUE_CHUNK='FBCh', ), UBInt32('version'), UBInt32('fxID'), UBInt32('fxVersion'), UBInt32('count'), Switch( 'data', lambda ctx: ctx['fxMagic'], { 'FXP_PARAMS': Struct( 'data', String('prgName', 28, padchar='\0'), Array(lambda ctx: ctx['_']['count'], BFloat32('params')), ), 'FXP_OPAQUE_CHUNK': Struct( 'data', String('prgName', 28, padchar='\0'), UBInt32('size'), Bytes('chunk', lambda ctx: ctx['size']), ), 'FXB_REGULAR': Struct( 'data', Bytes('future', 128), # zeros # Array of FXP_PARAMS vst2preset Array(lambda ctx: ctx['_']['count'], LazyBound('presets', lambda: vst2preset)),
MetaField("data", lambda ctx: ctx["length"] * 2), )), encoding="ucs2", ) dimensions = { "earth": 0, "sky": 1, } dimension = Enum(UBInt8("dimension"), **dimensions) grounded = Struct("grounded", UBInt8("grounded")) position = Struct("position", BFloat64("x"), BFloat64("y"), BFloat64("stance"), BFloat64("z")) orientation = Struct("orientation", BFloat32("rotation"), BFloat32("pitch")) faces = { "noop": -1, "-y": 0, "+y": 1, "-z": 2, "+z": 3, "-x": 4, "+x": 5, } face = Enum(SBInt8("face"), **faces) packets = { 0: Struct(
MetaField("data", lambda ctx: ctx["length"] * 2), )), encoding="ucs2", ) # Boolean converter. def Bool(*args, **kwargs): return Flag(*args, default=True, **kwargs) # Flying, position, and orientation, reused in several places. grounded = Struct("grounded", UBInt8("grounded")) position = Struct("position", BFloat64("x"), BFloat64("y"), BFloat64("stance"), BFloat64("z")) orientation = Struct("orientation", BFloat32("rotation"), BFloat32("pitch")) # Notchian item packing items = Struct( "items", SBInt16("primary"), If( lambda context: context["primary"] >= 0, Embed( Struct( "item_information", UBInt8("count"), UBInt16("secondary"), )), ), )