This commit is contained in:
BruceChen 2022-08-28 13:18:07 +08:00
parent 842c968220
commit 4757c4be53
8 changed files with 97 additions and 189 deletions

View file

@ -26,7 +26,7 @@ namespace MinecraftClient.Protocol.Handlers
private bool encrypted = false;
private int protocolversion;
private Tuple<Thread, CancellationTokenSource>? netRead = null;
Crypto.IAesStream s;
Crypto.AesCfb8Stream s;
TcpClient c;
public Protocol16Handler(TcpClient Client, int ProtocolVersion, IMinecraftComHandler Handler)
@ -568,7 +568,7 @@ namespace MinecraftClient.Protocol.Handlers
if (pid[0] == 0xFC)
{
readData(4);
s = CryptoHandler.getAesStream(c.GetStream(), secretKey);
s = new AesCfb8Stream(c.GetStream(), secretKey);
encrypted = true;
return true;
}

View file

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
//using System.Linq;
@ -34,6 +35,7 @@ namespace MinecraftClient.Protocol.Handlers
/// Reading the "Block states" field: consists of 4096 entries, representing all the blocks in the chunk section.
/// </summary>
/// <param name="cache">Cache for reading data</param>
[MethodImpl(MethodImplOptions.AggressiveOptimization)]
private Chunk? ReadBlockStatesField(Queue<byte> cache)
{
// read Block states (Type: Paletted Container)
@ -142,6 +144,7 @@ namespace MinecraftClient.Protocol.Handlers
/// <param name="cache">Cache for reading chunk data</param>
/// <param name="cancellationToken">token to cancel the task</param>
/// <returns>true if successfully loaded</returns>
[MethodImpl(MethodImplOptions.AggressiveOptimization)]
public bool ProcessChunkColumnData(int chunkX, int chunkZ, ulong[]? verticalStripBitmask, Queue<byte> cache, CancellationToken cancellationToken)
{
if (cancellationToken.IsCancellationRequested)
@ -243,6 +246,7 @@ namespace MinecraftClient.Protocol.Handlers
/// <param name="cache">Cache for reading chunk data</param>
/// <param name="cancellationToken">token to cancel the task</param>
/// <returns>true if successfully loaded</returns>
[MethodImpl(MethodImplOptions.AggressiveOptimization)]
public bool ProcessChunkColumnData(int chunkX, int chunkZ, ushort chunkMask, ushort chunkMask2, bool hasSkyLight, bool chunksContinuous, int currentDimension, Queue<byte> cache, CancellationToken cancellationToken)
{
if (cancellationToken.IsCancellationRequested)

View file

@ -10,7 +10,7 @@ namespace MinecraftClient.Protocol.Handlers
class SocketWrapper
{
TcpClient c;
IAesStream s;
AesCfb8Stream s;
bool encrypted = false;
/// <summary>
@ -49,7 +49,7 @@ namespace MinecraftClient.Protocol.Handlers
{
if (encrypted)
throw new InvalidOperationException("Stream is already encrypted!?");
this.s = CryptoHandler.getAesStream(c.GetStream(), secretKey);
this.s = new AesCfb8Stream(c.GetStream(), secretKey);
this.encrypted = true;
}