diff --git a/MinecraftClient/Crypto/AesCfb8Stream.cs b/MinecraftClient/Crypto/AesCfb8Stream.cs
index a08e4bc7..b2e769cf 100644
--- a/MinecraftClient/Crypto/AesCfb8Stream.cs
+++ b/MinecraftClient/Crypto/AesCfb8Stream.cs
@@ -16,14 +16,14 @@ namespace MinecraftClient.Crypto
private readonly Aes? Aes = null;
private readonly FastAes? FastAes = null;
-
- public Stream BaseStream { get; set; }
private bool inStreamEnded = false;
private byte[] ReadStreamIV = new byte[16];
private byte[] WriteStreamIV = new byte[16];
+ public Stream BaseStream { get; set; }
+
public AesCfb8Stream(Stream stream, byte[] key)
{
BaseStream = stream;
diff --git a/MinecraftClient/Mapping/Block.cs b/MinecraftClient/Mapping/Block.cs
index 0a9eb382..f7f1315b 100644
--- a/MinecraftClient/Mapping/Block.cs
+++ b/MinecraftClient/Mapping/Block.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Runtime.CompilerServices;
using System.Text;
using MinecraftClient.Mapping.BlockPalettes;
@@ -106,6 +107,7 @@ namespace MinecraftClient.Mapping
/// Get a block of the specified type and metadata OR block state
///
/// Type and metadata packed in the same value OR block state
+ [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public Block(ushort typeAndMeta)
{
this.blockIdAndMeta = typeAndMeta;
diff --git a/MinecraftClient/Mapping/Chunk.cs b/MinecraftClient/Mapping/Chunk.cs
index 0ee8c7ed..aefd2656 100644
--- a/MinecraftClient/Mapping/Chunk.cs
+++ b/MinecraftClient/Mapping/Chunk.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
@@ -60,6 +61,7 @@ namespace MinecraftClient.Mapping
/// Block Y
/// Block Z
/// Block
+ [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public void SetWithoutCheck(int blockX, int blockY, int blockZ, Block block)
{
blocks[blockX, blockY, blockZ] = block;
diff --git a/MinecraftClient/Mapping/Location.cs b/MinecraftClient/Mapping/Location.cs
index 1e4523ea..02ee3c23 100644
--- a/MinecraftClient/Mapping/Location.cs
+++ b/MinecraftClient/Mapping/Location.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Runtime.CompilerServices;
using System.Text;
namespace MinecraftClient.Mapping
@@ -54,6 +55,7 @@ namespace MinecraftClient.Mapping
/// Location of the block into the chunk
/// Location of the block into the world
/// Location of the block into the chunk
+ [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public Location(int chunkX, int chunkZ, int blockX, int blockY, int blockZ)
{
X = chunkX * Chunk.SizeX + blockX;
diff --git a/MinecraftClient/Protocol/Handlers/Compression/Inflate.cs b/MinecraftClient/Protocol/Handlers/Compression/Inflate.cs
index b0e07404..eaf0f909 100644
--- a/MinecraftClient/Protocol/Handlers/Compression/Inflate.cs
+++ b/MinecraftClient/Protocol/Handlers/Compression/Inflate.cs
@@ -63,6 +63,8 @@
using System;
+using System.Runtime.CompilerServices;
+
namespace Ionic.Zlib
{
sealed class InflateBlocks
@@ -140,6 +142,7 @@ namespace Ionic.Zlib
}
+ [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
internal int Process(int r)
{
int t; // temporary storage
@@ -673,6 +676,7 @@ namespace Ionic.Zlib
}
// copy as much as possible from the sliding window to the output area
+ [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
internal int Flush(int r)
{
int nBytes;
@@ -799,6 +803,7 @@ namespace Ionic.Zlib
tree = null;
}
+ [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
internal int Process(InflateBlocks blocks, int r)
{
int j; // temporary storage
@@ -1160,6 +1165,7 @@ namespace Ionic.Zlib
// (the maximum string length) and number of input bytes available
// at least ten. The ten bytes are six bytes for the longest length/
// distance pair plus four bytes for overloading the bit buffer.
+ [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
internal int InflateFast(int bl, int bd, int[] tl, int tl_index, int[] td, int td_index, InflateBlocks s, ZlibCodec z)
{
@@ -1509,6 +1515,7 @@ namespace Ionic.Zlib
}
+ [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
internal int Inflate(FlushType flush)
{
int b;
diff --git a/MinecraftClient/Protocol/Handlers/Compression/Zlib.cs b/MinecraftClient/Protocol/Handlers/Compression/Zlib.cs
index dcfe7252..8019be80 100644
--- a/MinecraftClient/Protocol/Handlers/Compression/Zlib.cs
+++ b/MinecraftClient/Protocol/Handlers/Compression/Zlib.cs
@@ -89,6 +89,7 @@
using System;
+using System.Runtime.CompilerServices;
using Interop=System.Runtime.InteropServices;
namespace Ionic.Zlib
@@ -491,6 +492,7 @@ namespace Ionic.Zlib
/// adler = Adler.Adler32(adler, buffer, index, length);
///
///
+ [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static uint Adler32(uint adler, byte[] buf, int index, int len)
{
if (buf == null)
diff --git a/MinecraftClient/Protocol/Handlers/Compression/ZlibBaseStream.cs b/MinecraftClient/Protocol/Handlers/Compression/ZlibBaseStream.cs
index 700ab7ba..e4879481 100644
--- a/MinecraftClient/Protocol/Handlers/Compression/ZlibBaseStream.cs
+++ b/MinecraftClient/Protocol/Handlers/Compression/ZlibBaseStream.cs
@@ -26,6 +26,7 @@
using System;
using System.IO;
+using System.Runtime.CompilerServices;
namespace Ionic.Zlib
{
@@ -170,6 +171,7 @@ namespace Ionic.Zlib
+ [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
private void finish()
{
if (_z == null) return;
@@ -299,6 +301,7 @@ namespace Ionic.Zlib
}
+ [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public override void Close()
{
if (_stream == null) return;
@@ -413,7 +416,7 @@ namespace Ionic.Zlib
}
-
+ [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public override System.Int32 Read(System.Byte[] buffer, System.Int32 offset, System.Int32 count)
{
// According to MS documentation, any implementation of the IO.Stream.Read function must:
diff --git a/MinecraftClient/Protocol/Handlers/Compression/ZlibCodec.cs b/MinecraftClient/Protocol/Handlers/Compression/ZlibCodec.cs
index 76d1535a..97b5882c 100644
--- a/MinecraftClient/Protocol/Handlers/Compression/ZlibCodec.cs
+++ b/MinecraftClient/Protocol/Handlers/Compression/ZlibCodec.cs
@@ -65,6 +65,7 @@
using System;
+using System.Runtime.CompilerServices;
using Interop=System.Runtime.InteropServices;
namespace Ionic.Zlib
@@ -351,6 +352,7 @@ namespace Ionic.Zlib
///
/// The flush to use when inflating.
/// Z_OK if everything goes well.
+ [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public int Inflate(FlushType flush)
{
if (istate == null)
diff --git a/MinecraftClient/Protocol/Handlers/Compression/ZlibStream.cs b/MinecraftClient/Protocol/Handlers/Compression/ZlibStream.cs
index 88ddca9d..27cead91 100644
--- a/MinecraftClient/Protocol/Handlers/Compression/ZlibStream.cs
+++ b/MinecraftClient/Protocol/Handlers/Compression/ZlibStream.cs
@@ -27,6 +27,7 @@
using System;
using System.IO;
+using System.Runtime.CompilerServices;
namespace Ionic.Zlib
{
@@ -409,6 +410,7 @@ namespace Ionic.Zlib
///
/// indicates whether the Dispose method was invoked by user code.
///
+ [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
protected override void Dispose(bool disposing)
{
try
@@ -543,6 +545,7 @@ namespace Ionic.Zlib
/// the number of bytes to read.
///
/// the number of bytes read
+ [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public override int Read(byte[] buffer, int offset, int count)
{
if (_disposed) throw new ObjectDisposedException("ZlibStream");
diff --git a/MinecraftClient/Protocol/Handlers/DataTypes.cs b/MinecraftClient/Protocol/Handlers/DataTypes.cs
index d0cdaa79..d1a90d94 100644
--- a/MinecraftClient/Protocol/Handlers/DataTypes.cs
+++ b/MinecraftClient/Protocol/Handlers/DataTypes.cs
@@ -8,6 +8,7 @@ using MinecraftClient.Crypto;
using MinecraftClient.Inventory;
using MinecraftClient.Mapping.EntityPalettes;
using MinecraftClient.Inventory.ItemPalettes;
+using System.Runtime.CompilerServices;
namespace MinecraftClient.Protocol.Handlers
{
@@ -36,6 +37,7 @@ namespace MinecraftClient.Protocol.Handlers
/// Amount of bytes to read
/// Cache of bytes to read from
/// The data read from the cache as an array
+ [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public byte[] ReadData(int offset, Queue cache)
{
byte[] result = new byte[offset];
@@ -44,11 +46,24 @@ namespace MinecraftClient.Protocol.Handlers
return result;
}
+ ///
+ /// Remove some data from the cache
+ ///
+ /// Amount of bytes to drop
+ /// Cache of bytes to drop
+ [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
+ public void DropData(int offset, Queue cache)
+ {
+ while (offset-- > 0)
+ cache.Dequeue();
+ }
+
///
/// Read a string from a cache of bytes and remove it from the cache
///
/// Cache of bytes to read from
/// The string
+ [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public string ReadNextString(Queue cache)
{
int length = ReadNextVarInt(cache);
@@ -63,6 +78,7 @@ namespace MinecraftClient.Protocol.Handlers
/// Read a boolean from a cache of bytes and remove it from the cache
///
/// The boolean value
+ [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public bool ReadNextBool(Queue cache)
{
return ReadNextByte(cache) != 0x00;
@@ -72,55 +88,65 @@ namespace MinecraftClient.Protocol.Handlers
/// Read a short integer from a cache of bytes and remove it from the cache
///
/// The short integer value
+ [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public short ReadNextShort(Queue cache)
{
- byte[] rawValue = ReadData(2, cache);
- Array.Reverse(rawValue); //Endianness
- return BitConverter.ToInt16(rawValue, 0);
+ Span rawValue = stackalloc byte[2];
+ for (int i = (2 - 1); i >= 0; --i) //Endianness
+ rawValue[i] = cache.Dequeue();
+ return BitConverter.ToInt16(rawValue);
}
///
/// Read an integer from a cache of bytes and remove it from the cache
///
/// The integer value
+ [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public int ReadNextInt(Queue cache)
{
- byte[] rawValue = ReadData(4, cache);
- Array.Reverse(rawValue); //Endianness
- return BitConverter.ToInt32(rawValue, 0);
+ Span rawValue = stackalloc byte[4];
+ for (int i = (4 - 1); i >= 0; --i) //Endianness
+ rawValue[i] = cache.Dequeue();
+ return BitConverter.ToInt32(rawValue);
}
///
/// Read a long integer from a cache of bytes and remove it from the cache
///
/// The unsigned long integer value
+ [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public long ReadNextLong(Queue cache)
{
- byte[] rawValue = ReadData(8, cache);
- Array.Reverse(rawValue); //Endianness
- return BitConverter.ToInt64(rawValue, 0);
+ Span rawValue = stackalloc byte[8];
+ for (int i = (8 - 1); i >= 0; --i) //Endianness
+ rawValue[i] = cache.Dequeue();
+ return BitConverter.ToInt64(rawValue);
}
///
/// Read an unsigned short integer from a cache of bytes and remove it from the cache
///
/// The unsigned short integer value
+ [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public ushort ReadNextUShort(Queue cache)
{
- byte[] rawValue = ReadData(2, cache);
- Array.Reverse(rawValue); //Endianness
- return BitConverter.ToUInt16(rawValue, 0);
+ Span rawValue = stackalloc byte[2];
+ for (int i = (2 - 1); i >= 0; --i) //Endianness
+ rawValue[i] = cache.Dequeue();
+ return BitConverter.ToUInt16(rawValue);
}
///
/// Read an unsigned long integer from a cache of bytes and remove it from the cache
///
/// The unsigned long integer value
+ [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public ulong ReadNextULong(Queue cache)
{
- byte[] rawValue = ReadData(8, cache);
- Array.Reverse(rawValue); //Endianness
- return BitConverter.ToUInt64(rawValue, 0);
+ Span rawValue = stackalloc byte[8];
+ for (int i = (8 - 1); i >= 0; --i) //Endianness
+ rawValue[i] = cache.Dequeue();
+ return BitConverter.ToUInt64(rawValue);
}
///
@@ -172,7 +198,9 @@ namespace MinecraftClient.Protocol.Handlers
/// The uuid
public Guid ReadNextUUID(Queue cache)
{
- byte[] javaUUID = ReadData(16, cache);
+ Span javaUUID = stackalloc byte[16];
+ for (int i = 0; i < 16; ++i)
+ javaUUID[i] = cache.Dequeue();
Guid guid = new Guid(javaUUID);
if (BitConverter.IsLittleEndian)
guid = guid.ToLittleEndian();
@@ -184,6 +212,7 @@ namespace MinecraftClient.Protocol.Handlers
///
/// Cache of bytes to read from
/// The byte array
+ [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public byte[] ReadNextByteArray(Queue cache)
{
int len = protocolversion >= Protocol18Handler.MC_1_8_Version
@@ -196,6 +225,7 @@ namespace MinecraftClient.Protocol.Handlers
/// Reads a length-prefixed array of unsigned long integers and removes it from the cache
///
/// The unsigned long integer values
+ [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public ulong[] ReadNextULongArray(Queue cache)
{
int len = ReadNextVarInt(cache);
@@ -209,28 +239,33 @@ namespace MinecraftClient.Protocol.Handlers
/// Read a double from a cache of bytes and remove it from the cache
///
/// The double value
+ [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public double ReadNextDouble(Queue cache)
{
- byte[] rawValue = ReadData(8, cache);
- Array.Reverse(rawValue); //Endianness
- return BitConverter.ToDouble(rawValue, 0);
+ Span rawValue = stackalloc byte[8];
+ for (int i = (8 - 1); i >= 0; --i) //Endianness
+ rawValue[i] = cache.Dequeue();
+ return BitConverter.ToDouble(rawValue);
}
///
/// Read a float from a cache of bytes and remove it from the cache
///
/// The float value
+ [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public float ReadNextFloat(Queue cache)
{
- byte[] rawValue = ReadData(4, cache);
- Array.Reverse(rawValue); //Endianness
- return BitConverter.ToSingle(rawValue, 0);
+ Span rawValue = stackalloc byte[4];
+ for (int i = (4 - 1); i >= 0; --i) //Endianness
+ rawValue[i] = cache.Dequeue();
+ return BitConverter.ToSingle(rawValue);
}
///
/// Read an integer from the network
///
/// The integer
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
public int ReadNextVarIntRAW(SocketWrapper socket)
{
int i = 0;
@@ -251,6 +286,7 @@ namespace MinecraftClient.Protocol.Handlers
///
/// Cache of bytes to read from
/// The integer
+ [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public int ReadNextVarInt(Queue cache)
{
int i = 0;
@@ -269,13 +305,12 @@ namespace MinecraftClient.Protocol.Handlers
/// Skip a VarInt from a cache of bytes with better performance
///
/// Cache of bytes to read from
+ [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public void SkipNextVarInt(Queue cache)
{
while (true)
- {
if ((ReadNextByte(cache) & 0x80) != 128)
break;
- }
}
///
@@ -326,6 +361,7 @@ namespace MinecraftClient.Protocol.Handlers
/// Read a single byte from a cache of bytes and remove it from the cache
///
/// The byte that was read
+ [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public byte ReadNextByte(Queue cache)
{
byte result = cache.Dequeue();
diff --git a/MinecraftClient/Protocol/Handlers/Protocol18.cs b/MinecraftClient/Protocol/Handlers/Protocol18.cs
index 610e93f9..2d68fda1 100644
--- a/MinecraftClient/Protocol/Handlers/Protocol18.cs
+++ b/MinecraftClient/Protocol/Handlers/Protocol18.cs
@@ -218,9 +218,8 @@ namespace MinecraftClient.Protocol.Handlers
while (socketWrapper.HasDataAvailable())
{
int packetID = 0;
- Queue packetData = new Queue();
- ReadNextPacket(ref packetID, packetData);
- HandlePacket(packetID, new Queue(packetData));
+ Queue packetData = ReadNextPacket(ref packetID);
+ HandlePacket(packetID, packetData);
}
}
catch (System.IO.IOException) { return false; }
@@ -235,14 +234,10 @@ namespace MinecraftClient.Protocol.Handlers
///
/// will contain packet ID
/// will contain raw packet Data
- internal void ReadNextPacket(ref int packetID, Queue packetData)
+ internal Queue ReadNextPacket(ref int packetID)
{
- packetData.Clear();
int size = dataTypes.ReadNextVarIntRAW(socketWrapper); //Packet size
- byte[] rawpacket = socketWrapper.ReadDataRAW(size); //Packet contents
-
- for (int i = 0; i < rawpacket.Length; i++)
- packetData.Enqueue(rawpacket[i]);
+ Queue packetData = new(socketWrapper.ReadDataRAW(size)); //Packet contents
//Handle packet decompression
if (protocolversion >= MC_1_8_Version
@@ -253,9 +248,7 @@ namespace MinecraftClient.Protocol.Handlers
{
byte[] toDecompress = packetData.ToArray();
byte[] uncompressed = ZlibUtils.Decompress(toDecompress, sizeUncompressed);
- packetData.Clear();
- for (int i = 0; i < uncompressed.Length; i++)
- packetData.Enqueue(uncompressed[i]);
+ packetData = new(uncompressed);
}
}
@@ -266,6 +259,8 @@ namespace MinecraftClient.Protocol.Handlers
List clone = packetData.ToList();
handler.OnNetworkPacket(packetID, clone, login_phase, true);
}
+
+ return packetData;
}
///
@@ -609,7 +604,7 @@ namespace MinecraftClient.Protocol.Handlers
dataTypes.SkipNextVarInt(packetData);
}
}
- else dataTypes.ReadData(1024 * 4, packetData); // Biomes - 1.15 and above
+ else dataTypes.DropData(1024 * 4, packetData); // Biomes - 1.15 and above
}
int dataSize = dataTypes.ReadNextVarInt(packetData);
Parallel.Invoke(() =>
@@ -1561,10 +1556,9 @@ namespace MinecraftClient.Protocol.Handlers
SendPacket(0x00, fullLoginPacket);
int packetID = -1;
- Queue packetData = new Queue();
while (true)
{
- ReadNextPacket(ref packetID, packetData);
+ Queue packetData = ReadNextPacket(ref packetID);
if (packetID == 0x00) //Login rejected
{
handler.OnConnectionLost(ChatBot.DisconnectReason.LoginRejected, ChatParser.ParseText(dataTypes.ReadNextString(packetData)));
@@ -1670,8 +1664,7 @@ namespace MinecraftClient.Protocol.Handlers
while (true)
{
int packetID = -1;
- Queue packetData = new Queue();
- ReadNextPacket(ref packetID, packetData);
+ Queue packetData = ReadNextPacket(ref packetID);
if (packetID < 0 || loopPrevention-- < 0) // Failed to read packet or too many iterations (issue #1150)
{
handler.OnConnectionLost(ChatBot.DisconnectReason.ConnectionLost, Translations.Get("error.invalid_encrypt"));
diff --git a/MinecraftClient/Protocol/Handlers/Protocol18Forge.cs b/MinecraftClient/Protocol/Handlers/Protocol18Forge.cs
index beae95e7..bfa401a0 100644
--- a/MinecraftClient/Protocol/Handlers/Protocol18Forge.cs
+++ b/MinecraftClient/Protocol/Handlers/Protocol18Forge.cs
@@ -57,11 +57,10 @@ namespace MinecraftClient.Protocol.Handlers
if (ForgeEnabled() && forgeInfo.Version == FMLVersion.FML)
{
int packetID = -1;
- Queue packetData = new Queue();
while (fmlHandshakeState != FMLHandshakeClientState.DONE)
{
- protocol18.ReadNextPacket(ref packetID, packetData);
+ Queue packetData = protocol18.ReadNextPacket(ref packetID);
if (packetID == 0x40) // Disconnect
{
diff --git a/MinecraftClient/Protocol/Handlers/Protocol18Terrain.cs b/MinecraftClient/Protocol/Handlers/Protocol18Terrain.cs
index 62459c0f..2db3b0e6 100644
--- a/MinecraftClient/Protocol/Handlers/Protocol18Terrain.cs
+++ b/MinecraftClient/Protocol/Handlers/Protocol18Terrain.cs
@@ -222,7 +222,7 @@ namespace MinecraftClient.Protocol.Handlers
dataTypes.SkipNextVarInt(cache); // Palette
}
int dataArrayLength = dataTypes.ReadNextVarInt(cache); // Data Array Length
- dataTypes.ReadData(dataArrayLength * 8, cache); // Data Array
+ dataTypes.DropData(dataArrayLength * 8, cache); // Data Array
}
}
}
@@ -394,12 +394,12 @@ namespace MinecraftClient.Protocol.Handlers
if (protocolversion < Protocol18Handler.MC_1_14_Version)
{
//Skip block light
- dataTypes.ReadData((Chunk.SizeX * Chunk.SizeY * Chunk.SizeZ) / 2, cache);
+ dataTypes.DropData((Chunk.SizeX * Chunk.SizeY * Chunk.SizeZ) / 2, cache);
//Skip sky light
if (currentDimension == 0)
// Sky light is not sent in the nether or the end
- dataTypes.ReadData((Chunk.SizeX * Chunk.SizeY * Chunk.SizeZ) / 2, cache);
+ dataTypes.DropData((Chunk.SizeX * Chunk.SizeY * Chunk.SizeZ) / 2, cache);
}
}
}
@@ -456,17 +456,17 @@ namespace MinecraftClient.Protocol.Handlers
if ((chunkMask & (1 << chunkY)) != 0)
{
//Skip block light
- dataTypes.ReadData((Chunk.SizeX * Chunk.SizeY * Chunk.SizeZ) / 2, cache);
+ dataTypes.DropData((Chunk.SizeX * Chunk.SizeY * Chunk.SizeZ) / 2, cache);
//Skip sky light
if (hasSkyLight)
- dataTypes.ReadData((Chunk.SizeX * Chunk.SizeY * Chunk.SizeZ) / 2, cache);
+ dataTypes.DropData((Chunk.SizeX * Chunk.SizeY * Chunk.SizeZ) / 2, cache);
}
}
//Skip biome metadata
if (chunksContinuous)
- dataTypes.ReadData(Chunk.SizeX * Chunk.SizeZ, cache);
+ dataTypes.DropData(Chunk.SizeX * Chunk.SizeZ, cache);
}
}
else
@@ -505,12 +505,12 @@ namespace MinecraftClient.Protocol.Handlers
}
//Skip data we don't need
- dataTypes.ReadData((Chunk.SizeX * Chunk.SizeY * Chunk.SizeZ * sectionCount) / 2, cache); //Block light
+ dataTypes.DropData((Chunk.SizeX * Chunk.SizeY * Chunk.SizeZ * sectionCount) / 2, cache); //Block light
if (hasSkyLight)
- dataTypes.ReadData((Chunk.SizeX * Chunk.SizeY * Chunk.SizeZ * sectionCount) / 2, cache); //Sky light
- dataTypes.ReadData((Chunk.SizeX * Chunk.SizeY * Chunk.SizeZ * addDataSectionCount) / 2, cache); //BlockAdd
+ dataTypes.DropData((Chunk.SizeX * Chunk.SizeY * Chunk.SizeZ * sectionCount) / 2, cache); //Sky light
+ dataTypes.DropData((Chunk.SizeX * Chunk.SizeY * Chunk.SizeZ * addDataSectionCount) / 2, cache); //BlockAdd
if (chunksContinuous)
- dataTypes.ReadData(Chunk.SizeX * Chunk.SizeZ, cache); //Biomes
+ dataTypes.DropData(Chunk.SizeX * Chunk.SizeZ, cache); //Biomes
//Load chunk data
int maxChunkY = sizeof(int) * 8 - 1 - BitOperations.LeadingZeroCount(chunkMask);
diff --git a/MinecraftClient/Protocol/Handlers/ZlibUtils.cs b/MinecraftClient/Protocol/Handlers/ZlibUtils.cs
index e281bd31..f4822f16 100644
--- a/MinecraftClient/Protocol/Handlers/ZlibUtils.cs
+++ b/MinecraftClient/Protocol/Handlers/ZlibUtils.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Runtime.CompilerServices;
using System.Text;
using Ionic.Zlib;
@@ -39,6 +40,7 @@ namespace MinecraftClient.Protocol.Handlers
/// Data to decompress
/// Size of the data once decompressed
/// Decompressed data as a byte array
+ [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static byte[] Decompress(byte[] to_decompress, int size_uncompressed)
{
ZlibStream stream = new ZlibStream(new System.IO.MemoryStream(to_decompress, false), CompressionMode.Decompress);
@@ -53,6 +55,7 @@ namespace MinecraftClient.Protocol.Handlers
///
/// Data to decompress
/// Decompressed data as byte array
+ [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static byte[] Decompress(byte[] to_decompress)
{
ZlibStream stream = new ZlibStream(new System.IO.MemoryStream(to_decompress, false), CompressionMode.Decompress);