Ejemplo n.º 1
0
        public static ChunkSection Deserialize(ref SpanReader br, bool isOverworld)
        {
            var result = new ChunkSection
            {
                BitsPerBlock  = br.ReadAsByte(),
                PaletteLength = br.ReadAsVarInt(out _)
            };

            if (result.PaletteLength != 0)
            {
                var paletteReader = br.ReadAsSubReader((int)result.PaletteLength);
                var palette       = new List <uint>();
                while (!paletteReader.IsCosumed)
                {
                    palette.Add(paletteReader.ReadAsVarInt(out _));
                }
                result.Palette = palette.ToArray();
            }

            result.DataArrayLength = br.ReadAsVarInt(out _);
            var dataArray = new ulong[result.DataArrayLength];

            for (int i = 0; i < dataArray.Length; i++)
            {
                dataArray[i] = br.ReadAsUnsignedLong();
            }
            result.DataArray  = dataArray;
            result.BlockLight = br.ReadAsByteArray(ChunkConstants.BlocksInSection / 2);
            if (isOverworld)
            {
                result.SkyLight = br.ReadAsByteArray(ChunkConstants.BlocksInSection / 2);
            }
            return(result);
        }
Ejemplo n.º 2
0
        public static ChunkData Deserialize(ref SpanReader br, bool isOverworld)
        {
            var result = new ChunkData
            {
                ChunkX             = br.ReadAsInt(),
                ChunkZ             = br.ReadAsInt(),
                GroundUpContinuous = br.ReadAsBoolean(),
                PrimaryBitMask     = br.ReadAsVarInt(out _)
            };

            var hasBioms = result.GroundUpContinuous;

            result.Size = br.ReadAsVarInt(out _);
            var dataReader = br.ReadAsSubReader((int)result.Size - (hasBioms ? 256 : 0));
            var data       = new List <ChunkSection>();

            while (!dataReader.IsCosumed)
            {
                data.Add(ChunkSection.Deserialize(ref dataReader, isOverworld));
            }
            result.Data = data.ToArray();

            if (hasBioms)
            {
                result.Biomes = br.ReadAsByteArray(256);
            }
            result.NumberOfBlockEntities = br.ReadAsVarInt(out _);
            return(result);
        }
Ejemplo n.º 3
0
 public static ServerboundPluginMessage Deserialize(ref SpanReader br)
 {
     return(new ServerboundPluginMessage
     {
         Channel = br.ReadAsString(),
         Data = br.ReadAsByteArray()
     });
 }
Ejemplo n.º 4
0
        public static EncryptionResponse Deserialize(ref SpanReader br)
        {
            uint sharedSecretLength = br.ReadAsVarInt(out _);

            byte[] sharedSecret      = br.ReadAsByteArray((int)sharedSecretLength);
            uint   verifyTokenLength = br.ReadAsVarInt(out _);

            byte[] verifyToken = br.ReadAsByteArray((int)verifyTokenLength);

            return(new EncryptionResponse
            {
                SharedSecretLength = sharedSecretLength,
                SharedSecret = sharedSecret,
                VerifyTokenLength = verifyTokenLength,
                VerifyToken = verifyToken
            });
        }
Ejemplo n.º 5
0
        public static EncryptionRequest Deserialize(ref SpanReader br)
        {
            string serverID        = br.ReadAsString();
            uint   publicKeyLength = br.ReadAsVarInt(out _);

            byte[] publicKey         = br.ReadAsByteArray((int)publicKeyLength);
            uint   verifyTokenLength = br.ReadAsVarInt(out _);

            byte[] verifyToken = br.ReadAsByteArray((int)verifyTokenLength);

            return(new EncryptionRequest
            {
                ServerID = serverID,
                PublicKeyLength = publicKeyLength,
                PublicKey = publicKey,
                VerifyTokenLength = verifyTokenLength,
                VerifyToken = verifyToken
            });
        }