mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Join Game and Respawn encoding/decoding & added ReadNextVarIntArray
This commit is contained in:
parent
e0aba29b7a
commit
424eab29dd
2 changed files with 2446 additions and 2392 deletions
|
|
@ -284,6 +284,27 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
return i;
|
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>
|
/// <summary>
|
||||||
/// Read an "extended short", which is actually an int of some kind, from the cache of bytes.
|
/// 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
|
/// This is only done with forge. It looks like it's a normal short, except that if the high
|
||||||
|
|
|
||||||
|
|
@ -220,22 +220,41 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
int playerEntityID = dataTypes.ReadNextInt(packetData);
|
int playerEntityID = dataTypes.ReadNextInt(packetData);
|
||||||
handler.OnReceivePlayerEntityID(playerEntityID);
|
handler.OnReceivePlayerEntityID(playerEntityID);
|
||||||
handler.OnGamemodeUpdate(Guid.Empty, dataTypes.ReadNextByte(packetData));
|
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)
|
if (protocolversion >= MC191Version)
|
||||||
this.currentDimension = dataTypes.ReadNextInt(packetData);
|
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
|
else
|
||||||
this.currentDimension = (sbyte)dataTypes.ReadNextByte(packetData);
|
this.currentDimension = (sbyte)dataTypes.ReadNextByte(packetData);
|
||||||
if (protocolversion < MC114Version)
|
if (protocolversion < MC114Version)
|
||||||
dataTypes.ReadNextByte(packetData); // Difficulty - 1.13 and below
|
dataTypes.ReadNextByte(packetData); // Difficulty - 1.13 and below
|
||||||
|
if (protocolversion >= MC116Version)
|
||||||
|
dataTypes.ReadNextString(packetData); // World Name - 1.16 and above
|
||||||
if (protocolversion >= MC115Version)
|
if (protocolversion >= MC115Version)
|
||||||
dataTypes.ReadNextLong(packetData); // Hashed world seed - 1.15 and above
|
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)
|
if (protocolversion >= MC114Version)
|
||||||
dataTypes.ReadNextVarInt(packetData); // View distance - 1.14 and above
|
dataTypes.ReadNextVarInt(packetData); // View distance - 1.14 and above
|
||||||
if (protocolversion >= MC18Version)
|
if (protocolversion >= MC18Version)
|
||||||
dataTypes.ReadNextBool(packetData); // Reduced debug info - 1.8 and above
|
dataTypes.ReadNextBool(packetData); // Reduced debug info - 1.8 and above
|
||||||
if (protocolversion >= MC115Version)
|
if (protocolversion >= MC115Version)
|
||||||
dataTypes.ReadNextBool(packetData); // Enable respawn screen - 1.15 and above
|
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;
|
break;
|
||||||
case PacketIncomingType.ChatMessage:
|
case PacketIncomingType.ChatMessage:
|
||||||
string message = dataTypes.ReadNextString(packetData);
|
string message = dataTypes.ReadNextString(packetData);
|
||||||
|
|
@ -251,13 +270,27 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
handler.OnTextReceived(message, true);
|
handler.OnTextReceived(message, true);
|
||||||
break;
|
break;
|
||||||
case PacketIncomingType.Respawn:
|
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);
|
this.currentDimension = dataTypes.ReadNextInt(packetData);
|
||||||
|
if (protocolversion >= MC116Version)
|
||||||
|
dataTypes.ReadNextString(packetData); // World Name - 1.16 and above
|
||||||
if (protocolversion < MC114Version)
|
if (protocolversion < MC114Version)
|
||||||
dataTypes.ReadNextByte(packetData); // Difficulty - 1.13 and below
|
dataTypes.ReadNextByte(packetData); // Difficulty - 1.13 and below
|
||||||
if (protocolversion >= MC115Version)
|
if (protocolversion >= MC115Version)
|
||||||
dataTypes.ReadNextLong(packetData); // Hashed world seed - 1.15 and above
|
dataTypes.ReadNextLong(packetData); // Hashed world seed - 1.15 and above
|
||||||
dataTypes.ReadNextByte(packetData);
|
dataTypes.ReadNextByte(packetData); // Gamemode
|
||||||
dataTypes.ReadNextString(packetData);
|
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();
|
handler.OnRespawn();
|
||||||
break;
|
break;
|
||||||
case PacketIncomingType.PlayerPositionAndLook:
|
case PacketIncomingType.PlayerPositionAndLook:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue