Join Game and Respawn encoding/decoding & added ReadNextVarIntArray

This commit is contained in:
Bas950 2020-06-29 16:05:12 +02:00
parent e0aba29b7a
commit 424eab29dd
2 changed files with 2446 additions and 2392 deletions

View file

@ -284,6 +284,27 @@ namespace MinecraftClient.Protocol.Handlers
return i;
}
/// <summary>
/// Read an integer from a cache of bytes and remove it from the cache
/// </summary>
/// <param name="cache">Cache of bytes to read from</param>
/// <returns>The integer</returns>
public int[] ReadNextVarIntArray(Queue<byte> cache)
{
string rawData = BitConverter.ToString(cache);
int i = 0;
int j = 0;
int k = 0;
while (true)
{
k = ReadNextByte(cache);
i |= (k & 0x7F) << j++ * 7;
if (j > 5) throw new OverflowException("VarInt too big " + rawData);
if ((k & 0x80) != 128) break;
}
return i;
}
/// <summary>
/// Read an "extended short", which is actually an int of some kind, from the cache of bytes.
/// This is only done with forge. It looks like it's a normal short, except that if the high

View file

@ -220,22 +220,41 @@ namespace MinecraftClient.Protocol.Handlers
int playerEntityID = dataTypes.ReadNextInt(packetData);
handler.OnReceivePlayerEntityID(playerEntityID);
handler.OnGamemodeUpdate(Guid.Empty, dataTypes.ReadNextByte(packetData));
if (protocolversion >= MC116Version)
dataTypes.ReadNextByte(packetData); // Previous Gamemode - 1.16 and above
if (protocolversion >= MC116Version)
dataTypes.ReadNextVarInt(packetData); // World Count - 1.16 and above
if (protocolversion >= MC116Version)
dataTypes.ReadNextVarIntArray(packetData); // World Names - 1.16 and above
if (protocolversion >= MC116Version)
dataTypes.ReadNextNbt(packetData); // Dimension Codec - 1.16 and above
if (protocolversion >= MC191Version)
this.currentDimension = dataTypes.ReadNextInt(packetData);
else if (protocolversion >= MC116Version)
this.currentDimension = dataTypes.ReadNextString(packetData); //In 1.16 it was changed to "Identifier" which seems to be a string
else
this.currentDimension = (sbyte)dataTypes.ReadNextByte(packetData);
if (protocolversion < MC114Version)
dataTypes.ReadNextByte(packetData); // Difficulty - 1.13 and below
if (protocolversion >= MC116Version)
dataTypes.ReadNextString(packetData); // World Name - 1.16 and above
if (protocolversion >= MC115Version)
dataTypes.ReadNextLong(packetData); // Hashed world seed - 1.15 and above
dataTypes.ReadNextByte(packetData);
dataTypes.ReadNextString(packetData);
dataTypes.ReadNextByte(packetData); // Max Players
if (protocolversion < MC116Version)
dataTypes.ReadNextString(packetData); // Level Type - 1.15 and below
if (protocolversion >= MC114Version)
dataTypes.ReadNextVarInt(packetData); // View distance - 1.14 and above
if (protocolversion >= MC18Version)
dataTypes.ReadNextBool(packetData); // Reduced debug info - 1.8 and above
if (protocolversion >= MC115Version)
dataTypes.ReadNextBool(packetData); // Enable respawn screen - 1.15 and above
if (protocolversion >= MC116Version)
dataTypes.ReadNextBool(packetData); // Is Debug - 1.16 and above
if (protocolversion >= MC116Version)
dataTypes.ReadNextBool(packetData); // Is Flat - 1.16 and above
break;
case PacketIncomingType.ChatMessage:
string message = dataTypes.ReadNextString(packetData);
@ -251,13 +270,27 @@ namespace MinecraftClient.Protocol.Handlers
handler.OnTextReceived(message, true);
break;
case PacketIncomingType.Respawn:
if (protocolversion >= MC116Version)
this.currentDimension = dataTypes.ReadNextString(packetData); //In 1.16 it was changed to "Identifier" which seems to be a string
else
this.currentDimension = dataTypes.ReadNextInt(packetData);
if (protocolversion >= MC116Version)
dataTypes.ReadNextString(packetData); // World Name - 1.16 and above
if (protocolversion < MC114Version)
dataTypes.ReadNextByte(packetData); // Difficulty - 1.13 and below
if (protocolversion >= MC115Version)
dataTypes.ReadNextLong(packetData); // Hashed world seed - 1.15 and above
dataTypes.ReadNextByte(packetData);
dataTypes.ReadNextString(packetData);
dataTypes.ReadNextByte(packetData); // Gamemode
if (protocolversion >= MC116Version)
dataTypes.ReadNextByte(packetData); // Previous Game mode - 1.16 and above
if (protocolversion < MC116Version)
dataTypes.ReadNextString(packetData); // Level Type - 1.15 and below
if (protocolversion >= MC116Version)
dataTypes.ReadNextBool(packetData); // Is Debug - 1.16 and above
if (protocolversion >= MC116Version)
dataTypes.ReadNextBool(packetData); // Is Flat - 1.16 and above
if (protocolversion >= MC116Version)
dataTypes.ReadNextBool(packetData); // Copy metadata - 1.16 and above
handler.OnRespawn();
break;
case PacketIncomingType.PlayerPositionAndLook: