mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2026-08-15 13:04:36 +00:00
Implemented .net 10 support. Updated all affected libraries and the code. Not testes yet.
This commit is contained in:
parent
5488140261
commit
28834e7a86
10 changed files with 107 additions and 94 deletions
|
|
@ -350,7 +350,7 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
{
|
||||
break;
|
||||
}
|
||||
catch (Ionic.Zlib.ZlibException)
|
||||
catch (System.IO.InvalidDataException)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,10 @@
|
|||
using Ionic.Zlib;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
|
||||
namespace MinecraftClient.Protocol.Handlers
|
||||
{
|
||||
/// <summary>
|
||||
/// Quick Zlib compression handling for network packet compression.
|
||||
/// Note: Underlying compression handling is taken from the DotNetZip Library.
|
||||
/// This library is open source and provided under the Microsoft Public License.
|
||||
/// More info about DotNetZip at dotnetzip.codeplex.com.
|
||||
/// </summary>
|
||||
public static class ZlibUtils
|
||||
{
|
||||
|
|
@ -17,16 +15,13 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
/// <returns>Compressed data as a byte array</returns>
|
||||
public static byte[] Compress(byte[] to_compress)
|
||||
{
|
||||
byte[] data;
|
||||
using (System.IO.MemoryStream memstream = new())
|
||||
using MemoryStream memstream = new();
|
||||
using (ZLibStream stream = new(memstream, CompressionMode.Compress, leaveOpen: true))
|
||||
{
|
||||
using (ZlibStream stream = new(memstream, CompressionMode.Compress))
|
||||
{
|
||||
stream.Write(to_compress, 0, to_compress.Length);
|
||||
}
|
||||
data = memstream.ToArray();
|
||||
stream.Write(to_compress, 0, to_compress.Length);
|
||||
}
|
||||
return data;
|
||||
|
||||
return memstream.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -37,10 +32,20 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
/// <returns>Decompressed data as a byte array</returns>
|
||||
public static byte[] Decompress(byte[] to_decompress, int size_uncompressed)
|
||||
{
|
||||
ZlibStream stream = new(new System.IO.MemoryStream(to_decompress, false), CompressionMode.Decompress);
|
||||
using MemoryStream compressedStream = new(to_decompress, writable: false);
|
||||
using ZLibStream stream = new(compressedStream, CompressionMode.Decompress);
|
||||
|
||||
byte[] packetData_decompressed = new byte[size_uncompressed];
|
||||
stream.Read(packetData_decompressed, 0, size_uncompressed);
|
||||
stream.Close();
|
||||
int totalRead = 0;
|
||||
while (totalRead < size_uncompressed)
|
||||
{
|
||||
int read = stream.Read(packetData_decompressed, totalRead, size_uncompressed - totalRead);
|
||||
if (read <= 0)
|
||||
break;
|
||||
|
||||
totalRead += read;
|
||||
}
|
||||
|
||||
return packetData_decompressed;
|
||||
}
|
||||
|
||||
|
|
@ -51,12 +56,14 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
/// <returns>Decompressed data as byte array</returns>
|
||||
public static byte[] Decompress(byte[] to_decompress)
|
||||
{
|
||||
ZlibStream stream = new(new System.IO.MemoryStream(to_decompress, false), CompressionMode.Decompress);
|
||||
using MemoryStream compressedStream = new(to_decompress, writable: false);
|
||||
using ZLibStream stream = new(compressedStream, CompressionMode.Decompress);
|
||||
byte[] buffer = new byte[16 * 1024];
|
||||
using System.IO.MemoryStream decompressedBuffer = new();
|
||||
using MemoryStream decompressedBuffer = new();
|
||||
int read;
|
||||
while ((read = stream.Read(buffer, 0, buffer.Length)) > 0)
|
||||
decompressedBuffer.Write(buffer, 0, read);
|
||||
|
||||
return decompressedBuffer.ToArray();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue