Exemplo n.º 1
0
def unpack(bbuff, data_type):
	if data_type in mcdata.data_types:
		format = mcdata.data_types[data_type]
		return struct.unpack(endian+format[0], bbuff.recv(format[1]))[0]
	
	if data_type == "string":
		length = unpack(bbuff, 'short')
		return bbuff.recv(2*length).decode('utf-16be')

	if data_type == "slot":
		o = {}
		o["id"] = unpack(bbuff, 'short')
		if o["id"] > 0:
			o["amount"] = unpack(bbuff, 'byte')
			o["damage"] = unpack(bbuff, 'short')
			length = unpack(bbuff, 'short')
			if length > 0:
				ench = bbuff.recv(length)
				try:
					ench = nbt.decode_nbt(ench)
					o["enchantments"] = ench
				except:
					o["enchantment_data"] = ench
		return o

	if data_type == "metadata":
		metadata = []
		x = unpack(bbuff, 'ubyte')
		while x != 127:
			key = x & 0x1F # Lower 5 bits
			ty = x >> 5 # Upper 3 bits
			if ty == 0: val = unpack(bbuff, 'byte')
			if ty == 1: val = unpack(bbuff, 'short')
			if ty == 2: val = unpack(bbuff, 'int')
			if ty == 3: val = unpack(bbuff, 'float')
			if ty == 4: val = unpack(bbuff, 'string')
			if ty == 5:
				val = {}
				val["id"] = unpack(bbuff, 'short')
				val["count"] = unpack(bbuff, 'byte')
				val["damage"] = unpack(bbuff, 'short')
			if ty == 6:
				val = []
				for i in range(3):
					val.append(unpack(bbuff, 'int'))
			metadata.append((key, (ty, val)))
			x = unpack(bbuff, 'byte')
		return metadata
Exemplo n.º 2
0
from spock.mcp import nbt
from spock.bound_buffer import BoundBuffer

magic = open("bigtest.nbt").read()

tags = nbt.decode_nbt(magic)
foo = nbt.encode_nbt(tags)
tags = nbt.decode_nbt(foo)
print tags.pretty_tree()
Exemplo n.º 3
0
from spock.mcp import nbt
from spock.bound_buffer import BoundBuffer

magic = open('bigtest.nbt').read()

tags = nbt.decode_nbt(magic)
foo = nbt.encode_nbt(tags)
tags = nbt.decode_nbt(foo)
print tags.pretty_tree()