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(),
                FullChunk      = br.ReadAsBoolean(),
                PrimaryBitMask = br.ReadAsVarInt(out _),
                Heightmaps     = br.ReadAsNbtTag(),
            };

            var hasBioms = result.FullChunk;

            if (hasBioms)
            {
                result.Biomes = br.ReadAsIntArray(1024);
            }

            result.Size = br.ReadAsVarInt(out _);
            var dataReader = br.ReadAsSubReader((int)result.Size);
            var data       = new List <ChunkSection>();

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

            result.NumberOfBlockEntities = br.ReadAsVarInt(out _);
            result.BlockEntities         = br.ReadAsNbtTagArray((int)result.NumberOfBlockEntities);
            return(result);
        }
Ejemplo n.º 3
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.º 4
0
 public static UpdateViewPosition Deserialize(ref SpanReader br)
 {
     return(new UpdateViewPosition
     {
         ChunkX = (int)br.ReadAsVarInt(out _),
         ChunkZ = (int)br.ReadAsVarInt(out _),
     });
 }
Ejemplo n.º 5
0
 public static EntityAction Deserialize(ref SpanReader br)
 {
     return(new EntityAction
     {
         EntityId = br.ReadAsVarInt(out _),
         ActionId = (ActionId)br.ReadAsVarInt(out _),
         JumpBoost = br.ReadAsVarInt(out _)
     });
 }
Ejemplo n.º 6
0
 public static Handshake Deserialize(ref SpanReader br)
 {
     return(new Handshake
     {
         ProtocolVersion = br.ReadAsVarInt(out _),
         ServerAddress = br.ReadAsString(),
         ServerPort = br.ReadAsUnsignedShort(),
         NextState = br.ReadAsVarInt(out _)
     });
 }
Ejemplo n.º 7
0
 public static PlayerBlockPlacement Deserialize(ref SpanReader br)
 {
     return(new PlayerBlockPlacement
     {
         Location = br.ReadAsPosition(),
         Face = (PlayerDiggingFace)br.ReadAsVarInt(out _),
         Hand = (Hand)br.ReadAsVarInt(out _),
         CursorPositionX = br.ReadAsFloat(),
         CursorPositionY = br.ReadAsFloat(),
         CursorPositionZ = br.ReadAsFloat()
     });
 }
Ejemplo n.º 8
0
 public static ClientSettings Deserialize(ref SpanReader br)
 {
     return(new ClientSettings
     {
         Locale = br.ReadAsString(),
         ViewDistance = br.ReadAsByte(),
         ChatMode = br.ReadAsVarInt(out _),
         ChatColors = br.ReadAsBoolean(),
         DisplayedSkinParts = br.ReadAsByte(),
         MainHand = br.ReadAsVarInt(out _)
     });
 }
Ejemplo n.º 9
0
 public static SetCompression Deserialize(ref SpanReader br)
 {
     return(new SetCompression
     {
         Threshold = br.ReadAsVarInt(out _),
     });
 }
Ejemplo n.º 10
0
 public static TeleportConfirm Deserialize(ref SpanReader br)
 {
     return(new TeleportConfirm
     {
         TeleportId = br.ReadAsVarInt(out _)
     });
 }
Ejemplo n.º 11
0
 public static DeclareCommands Deserialize(ref SpanReader br)
 {
     return(new DeclareCommands
     {
         Count = br.ReadAsVarInt(out _),
     });
 }
Ejemplo n.º 12
0
 public static ServerboundKeepAlive Deserialize(ref SpanReader br)
 {
     return(new ServerboundKeepAlive
     {
         KeepAliveId = br.ReadAsVarInt(out _)
     });
 }
Ejemplo n.º 13
0
 public static UseItem Deserialize(ref SpanReader br)
 {
     return(new UseItem
     {
         Hand = (Hand)br.ReadAsVarInt(out _)
     });
 }
Ejemplo n.º 14
0
 public static ServerboundAnimation Deserialize(ref SpanReader br)
 {
     return(new ServerboundAnimation
     {
         Hand = (Hand)br.ReadAsVarInt(out _)
     });
 }
Ejemplo n.º 15
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.º 16
0
 public static PlayerDigging Deserialize(ref SpanReader br)
 {
     return(new PlayerDigging
     {
         Status = (PlayerDiggingStatus)br.ReadAsVarInt(out _),
         Location = br.ReadAsPosition(),
         Face = (PlayerDiggingFace)br.ReadAsByte()
     });
 }
Ejemplo n.º 17
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
            });
        }
Ejemplo n.º 18
0
        public void Deserialize(ref SpanReader br)
        {
            Target = (int)br.ReadAsVarInt(out _);
            Type   = (int)br.ReadAsVarInt(out _);

            // Only if Type is interact at
            if (Type == 2)
            {
                TargetX = br.ReadAsFloat();
                TargetY = br.ReadAsFloat();
                TargetZ = br.ReadAsFloat();
            }

            // Only if Type is interact or interact at
            if (Type == 0 || Type == 2)
            {
                Hand = (int)br.ReadAsVarInt(out _);
            }
        }
Ejemplo n.º 19
0
        public static UseEntity Deserialize(ref SpanReader br)
        {
            var packet = new UseEntity
            {
                Target = (int)br.ReadAsVarInt(out _),
                Type = (int)br.ReadAsVarInt(out _)
            };

            // Only if Type is interact at
            if (packet.Type == 2)
            {
                packet.TargetX = br.ReadAsFloat();
                packet.TargetY = br.ReadAsFloat();
                packet.TargetZ = br.ReadAsFloat();
            }

            // Only if Type is interact or interact at
            if (packet.Type == 0 || packet.Type == 2)
                packet.Hand = (int)br.ReadAsVarInt(out _);
            return packet;
        }
Ejemplo n.º 20
0
 public static ClickWindow Deserialize(ref SpanReader br)
 {
     return(new ClickWindow
     {
         WindowId = br.ReadAsByte(),
         Slot = br.ReadAsShort(),
         Button = br.ReadAsByte(),
         ActionNumber = br.ReadAsShort(),
         Mode = br.ReadAsVarInt(out _),
         ClickedItem = br.ReadAsSlot()
     });
 }
Ejemplo n.º 21
0
 public static EntityLookAndRelativeMove Deserialize(ref SpanReader br)
 {
     return(new EntityLookAndRelativeMove
     {
         EID = br.ReadAsVarInt(out _),
         DeltaX = br.ReadAsShort(),
         DeltaY = br.ReadAsShort(),
         DeltaZ = br.ReadAsShort(),
         Yaw = br.ReadAsByte(),
         Pitch = br.ReadAsByte(),
         OnGround = br.ReadAsBoolean()
     });
 }
Ejemplo n.º 22
0
        public static ChunkSection Deserialize(ref SpanReader br, bool isOverworld)
        {
            var result = new ChunkSection
            {
                BlockCount    = br.ReadAsShort(),
                BitsPerBlock  = br.ReadAsByte(),
                PaletteLength = br.ReadAsVarInt(out _)
            };

            if (result.BitsPerBlock < 4)
            {
                throw new InvalidDataException("ChunkSection: BitsPerBlock should be greater than or equal to 4.");
            }
            else if (result.BitsPerBlock >= 5 && result.BitsPerBlock < 9)
            {
                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;
            return(result);
        }
Ejemplo n.º 23
0
        private static uint GetCompressionThreshold(UncompressedPacket packet)
        {
            var br = new SpanReader(packet.Data);

            return(br.ReadAsVarInt(out _));
        }
Ejemplo n.º 24
0
 public void Deserialize(ref SpanReader br)
 {
     Count = br.ReadAsVarInt(out _);
 }