Added pynbt in order to decompress and read nbt data into a more friendly format
This commit is contained in:
1 parent
5cd8554908
commit
7d50e325ba
5 files changed
+382
-2
No files matched your search
@@ -1,5 +1,7 @@
|
||||
import struct
|
||||
import types
|
||||
from io import BytesIO
|
||||
from pynbt import NBTFile
|
||||
|
||||
def readBoolean(FileObject):
|
||||
return struct.unpack('?', FileObject.read(1))[0]
|
||||
@@ -104,10 +106,11 @@ def readSlotData(FileObject):
|
||||
MetadataLength = readShort(FileObject)
|
||||
if(MetadataLength != -1):
|
||||
ByteArray = readByteArray(FileObject, MetadataLength)
|
||||
NBTData = NBTFile(BytesIO(ByteArray), compression=NBTFile.Compression.GZIP)
|
||||
return {'BlockID' : BlockID,
|
||||
'ItemCount' : ItemCount,
|
||||
'Damage' : Damage,
|
||||
'Data' : ByteArray
|
||||
'Data' : NBTData
|
||||
}
|
||||
return {'BlockID' : BlockID,
|
||||
'ItemCount' : ItemCount,
|
||||
|
||||
@@ -129,12 +129,17 @@ class EncryptedFileObjectHandler():
|
||||
def __init__(self, fileobject, cipher):
|
||||
self.fileobject = fileobject
|
||||
self.cipher = cipher
|
||||
self.length = 0
|
||||
|
||||
def read(self, length):
|
||||
rawData = self.fileobject.read(length)
|
||||
self.length += length
|
||||
unencryptedData = self.cipher.decrypt(rawData)
|
||||
return unencryptedData
|
||||
|
||||
def tell(self):
|
||||
return self.length
|
||||
|
||||
class EncryptedSocketObjectHandler():
|
||||
|
||||
def __init__(self, socket, cipher):
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import DataUtil
|
||||
import PacketSenderManager
|
||||
from io import BytesIO
|
||||
from pynbt import NBTFile
|
||||
|
||||
def handle00(FileObject, socket):
|
||||
KAid = DataUtil.readInt(FileObject)
|
||||
@@ -647,7 +649,8 @@ def handle84(FileObject):
|
||||
Action = DataUtil.readByte(FileObject)
|
||||
DataLength = DataUtil.readShort(FileObject)
|
||||
if (DataLength != -1):
|
||||
NBTData = DataUtil.readByteArray(FileObject, DataLength)
|
||||
ByteArray = DataUtil.readByteArray(FileObject, DataLength)
|
||||
NBTData = NBTFile(BytesIO(ByteArray), compression=NBTFile.Compression.GZIP)
|
||||
return {'x' : X,
|
||||
'y' : Y,
|
||||
'z' : Z,
|
||||
|
||||
Reference in new issue
Block a user