From d06f14d055b3ffbfc7f4fb2d94b5504d44b3034f Mon Sep 17 00:00:00 2001
From: Bas950 <34792838+Bas950@users.noreply.github.com>
Date: Sat, 27 Jun 2020 16:48:46 +0200
Subject: [PATCH 01/13] :sparkles: Added 1.16(.1) support
---
MinecraftClient/Program.cs | 2 +-
MinecraftClient/Protocol/Handlers/Protocol18.cs | 8 +++++---
MinecraftClient/Protocol/ProtocolHandler.cs | 7 ++++++-
3 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/MinecraftClient/Program.cs b/MinecraftClient/Program.cs
index f46537c6..a03fe6cc 100644
--- a/MinecraftClient/Program.cs
+++ b/MinecraftClient/Program.cs
@@ -32,7 +32,7 @@ namespace MinecraftClient
public const string Version = MCHighestVersion;
public const string MCLowestVersion = "1.4.6";
- public const string MCHighestVersion = "1.15.2";
+ public const string MCHighestVersion = "1.16.1";
public static readonly string BuildInfo = null;
private static Thread offlinePrompt = null;
diff --git a/MinecraftClient/Protocol/Handlers/Protocol18.cs b/MinecraftClient/Protocol/Handlers/Protocol18.cs
index 9e0dafb3..4276adbc 100644
--- a/MinecraftClient/Protocol/Handlers/Protocol18.cs
+++ b/MinecraftClient/Protocol/Handlers/Protocol18.cs
@@ -38,6 +38,8 @@ namespace MinecraftClient.Protocol.Handlers
internal const int MC114Version = 477;
internal const int MC115Version = 573;
internal const int MC1152Version = 578;
+ internal const int MC116Version = 735;
+ internal const int MC1161Version = 736;
private int compression_treshold = 0;
private bool autocomplete_received = false;
@@ -67,7 +69,7 @@ namespace MinecraftClient.Protocol.Handlers
this.pForge = new Protocol18Forge(forgeInfo, protocolVersion, dataTypes, this, handler);
this.pTerrain = new Protocol18Terrain(protocolVersion, dataTypes, handler);
- if (handler.GetTerrainEnabled() && protocolversion > MC1152Version)
+ if (handler.GetTerrainEnabled() && protocolversion > MC1161Version)
{
ConsoleIO.WriteLineFormatted("§8Terrain & Movements currently not handled for that MC version.");
handler.SetTerrainEnabled(false);
@@ -87,7 +89,7 @@ namespace MinecraftClient.Protocol.Handlers
if (protocolversion >= MC113Version)
{
- if (protocolVersion > MC1152Version && handler.GetTerrainEnabled())
+ if (protocolVersion > MC1161Version && handler.GetTerrainEnabled())
throw new NotImplementedException("Please update block types handling for this Minecraft version. See Material.cs");
if (protocolVersion >= MC115Version)
Block.Palette = new Palette115();
@@ -1389,7 +1391,7 @@ namespace MinecraftClient.Protocol.Handlers
catch (System.IO.IOException) { return false; }
catch (ObjectDisposedException) { return false; }
}
-
+
public bool SendPlayerDigging(int status, Location location, Direction face)
{
try
diff --git a/MinecraftClient/Protocol/ProtocolHandler.cs b/MinecraftClient/Protocol/ProtocolHandler.cs
index 4b6fa5ad..6a0a6b8e 100644
--- a/MinecraftClient/Protocol/ProtocolHandler.cs
+++ b/MinecraftClient/Protocol/ProtocolHandler.cs
@@ -116,7 +116,7 @@ namespace MinecraftClient.Protocol
int[] supportedVersions_Protocol16 = { 51, 60, 61, 72, 73, 74, 78 };
if (Array.IndexOf(supportedVersions_Protocol16, ProtocolVersion) > -1)
return new Protocol16Handler(Client, ProtocolVersion, Handler);
- int[] supportedVersions_Protocol18 = { 4, 5, 47, 107, 108, 109, 110, 210, 315, 316, 335, 338, 340, 393, 401, 404, 477, 480, 485, 490, 498, 573, 575, 578};
+ int[] supportedVersions_Protocol18 = { 4, 5, 47, 107, 108, 109, 110, 210, 315, 316, 335, 338, 340, 393, 401, 404, 477, 480, 485, 490, 498, 573, 575, 578, 735, 736};
if (Array.IndexOf(supportedVersions_Protocol18, ProtocolVersion) > -1)
return new Protocol18Handler(Client, ProtocolVersion, Handler, forgeInfo);
throw new NotSupportedException("The protocol version no." + ProtocolVersion + " is not supported.");
@@ -223,6 +223,11 @@ namespace MinecraftClient.Protocol
return 575;
case "1.15.2":
return 578;
+ case "1.16":
+ case "1.16.1":
+ return 735;
+ case "1.16.1":
+ return 736;
default:
return 0;
}
From c82c91705c85f02bd60297054041453802889102 Mon Sep 17 00:00:00 2001
From: Bas950 <34792838+Bas950@users.noreply.github.com>
Date: Sat, 27 Jun 2020 16:51:25 +0200
Subject: [PATCH 02/13] :recycle: Whoopsy..
---
MinecraftClient/Protocol/ProtocolHandler.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/MinecraftClient/Protocol/ProtocolHandler.cs b/MinecraftClient/Protocol/ProtocolHandler.cs
index 6a0a6b8e..6f14eb70 100644
--- a/MinecraftClient/Protocol/ProtocolHandler.cs
+++ b/MinecraftClient/Protocol/ProtocolHandler.cs
@@ -224,7 +224,7 @@ namespace MinecraftClient.Protocol
case "1.15.2":
return 578;
case "1.16":
- case "1.16.1":
+ case "1.16.0":
return 735;
case "1.16.1":
return 736;
From eb891cc91f48cd470157e732e4918ec6947bd503 Mon Sep 17 00:00:00 2001
From: Bas950 <34792838+Bas950@users.noreply.github.com>
Date: Sun, 28 Jun 2020 02:15:54 +0200
Subject: [PATCH 03/13] :recycle: Undo Terrain Handling update
---
.../Protocol/Handlers/Protocol18.cs | 4 +-
.../Handlers/Protocol18PacketTypes.cs | 73 ++++++++++++++++++-
2 files changed, 73 insertions(+), 4 deletions(-)
diff --git a/MinecraftClient/Protocol/Handlers/Protocol18.cs b/MinecraftClient/Protocol/Handlers/Protocol18.cs
index 4276adbc..f4a043ba 100644
--- a/MinecraftClient/Protocol/Handlers/Protocol18.cs
+++ b/MinecraftClient/Protocol/Handlers/Protocol18.cs
@@ -69,7 +69,7 @@ namespace MinecraftClient.Protocol.Handlers
this.pForge = new Protocol18Forge(forgeInfo, protocolVersion, dataTypes, this, handler);
this.pTerrain = new Protocol18Terrain(protocolVersion, dataTypes, handler);
- if (handler.GetTerrainEnabled() && protocolversion > MC1161Version)
+ if (handler.GetTerrainEnabled() && protocolversion > MC1152Version)
{
ConsoleIO.WriteLineFormatted("§8Terrain & Movements currently not handled for that MC version.");
handler.SetTerrainEnabled(false);
@@ -89,7 +89,7 @@ namespace MinecraftClient.Protocol.Handlers
if (protocolversion >= MC113Version)
{
- if (protocolVersion > MC1161Version && handler.GetTerrainEnabled())
+ if (protocolVersion > MC1152Version && handler.GetTerrainEnabled())
throw new NotImplementedException("Please update block types handling for this Minecraft version. See Material.cs");
if (protocolVersion >= MC115Version)
Block.Palette = new Palette115();
diff --git a/MinecraftClient/Protocol/Handlers/Protocol18PacketTypes.cs b/MinecraftClient/Protocol/Handlers/Protocol18PacketTypes.cs
index 6714baf5..a988feb3 100644
--- a/MinecraftClient/Protocol/Handlers/Protocol18PacketTypes.cs
+++ b/MinecraftClient/Protocol/Handlers/Protocol18PacketTypes.cs
@@ -288,7 +288,7 @@ namespace MinecraftClient.Protocol.Handlers
case 0x4F: return PacketIncomingType.Title;
}
}
- else // MC 1.15
+ else if (protocol <= Protocol18Handler.MC1152Version) // MC 1.15 to 1.15.2
{
switch (packetID)
{
@@ -331,6 +331,48 @@ namespace MinecraftClient.Protocol.Handlers
case 0x27: return PacketIncomingType.MapData;
case 0x50: return PacketIncomingType.Title;
}
+ } else {
+ switch (packetID)
+ {
+ case 0x20: return PacketIncomingType.KeepAlive;
+ case 0x25: return PacketIncomingType.JoinGame;
+ case 0x0E: return PacketIncomingType.ChatMessage;
+ case 0x3A: return PacketIncomingType.Respawn;
+ case 0x35: return PacketIncomingType.PlayerPositionAndLook;
+ case 0x21: return PacketIncomingType.ChunkData;
+ case 0x0F: return PacketIncomingType.MultiBlockChange;
+ case 0x0B: return PacketIncomingType.BlockChange;
+ // MapChunkBulk does not exist since 1.9
+ case 0x1D: return PacketIncomingType.UnloadChunk;
+ case 0x33: return PacketIncomingType.PlayerListUpdate;
+ case 0x10: return PacketIncomingType.TabCompleteResult;
+ case 0x18: return PacketIncomingType.PluginMessage;
+ case 0x1A: return PacketIncomingType.KickPacket;
+ // NetworkCompressionTreshold does not exist since 1.9
+ case 0x39: return PacketIncomingType.ResourcePackSend;
+ case 0x13: return PacketIncomingType.CloseWindow;
+ case 0x2E: return PacketIncomingType.OpenWindow;
+ case 0x14: return PacketIncomingType.WindowItems;
+ case 0x16: return PacketIncomingType.SetSlot;
+ case 0x00: return PacketIncomingType.SpawnEntity;
+ case 0x02: return PacketIncomingType.SpawnLivingEntity;
+ case 0x04: return PacketIncomingType.SpawnPlayer;
+ case 0x37: return PacketIncomingType.DestroyEntities;
+ case 0x17: return PacketIncomingType.SetCooldown;
+ case 0x28: return PacketIncomingType.EntityPosition;
+ case 0x29: return PacketIncomingType.EntityPositionAndRotation;
+ case 0x58: return PacketIncomingType.EntityProperties;
+ case 0x56: return PacketIncomingType.EntityTeleport;
+ case 0x46: return PacketIncomingType.EntityVelocity;
+ case 0x47: return PacketIncomingType.EntityEquipment;
+ case 0x4E: return PacketIncomingType.TimeUpdate;
+ case 0x49: return PacketIncomingType.UpdateHealth;
+ case 0x48: return PacketIncomingType.SetExperience;
+ case 0x3F: return PacketIncomingType.HeldItemChange;
+ case 0x1C: return PacketIncomingType.Explosion;
+ case 0x26: return PacketIncomingType.MapData;
+ case 0x4F: return PacketIncomingType.Title;
+ }
}
return PacketIncomingType.UnknownPacket;
@@ -485,7 +527,7 @@ namespace MinecraftClient.Protocol.Handlers
case PacketOutgoingType.UpdateSign: return 0x26;
}
}
- else // MC 1.14 to 1.15
+ else if (protocol <= Protocol18Handler.MC1152Version) //MC 1.14 to 1.15.2
{
switch (packet)
{
@@ -512,6 +554,33 @@ namespace MinecraftClient.Protocol.Handlers
case PacketOutgoingType.UpdateSign: return 0x29;
}
}
+ else
+ {
+ switch (packet)
+ {
+ case PacketOutgoingType.KeepAlive: return 0x10;
+ case PacketOutgoingType.ResourcePackStatus: return 0x20;
+ case PacketOutgoingType.ChatMessage: return 0x03;
+ case PacketOutgoingType.ClientStatus: return 0x04;
+ case PacketOutgoingType.ClientSettings: return 0x05;
+ case PacketOutgoingType.PluginMessage: return 0x0B;
+ case PacketOutgoingType.TabComplete: return 0x06;
+ case PacketOutgoingType.EntityAction: return 0x1C;
+ case PacketOutgoingType.PlayerPosition: return 0x12;
+ case PacketOutgoingType.PlayerPositionAndLook: return 0x13;
+ case PacketOutgoingType.TeleportConfirm: return 0x00;
+ case PacketOutgoingType.HeldItemChange: return 0x24;
+ case PacketOutgoingType.InteractEntity: return 0x0E;
+ case PacketOutgoingType.UseItem: return 0x2E;
+ case PacketOutgoingType.ClickWindow: return 0x09;
+ case PacketOutgoingType.CloseWindow: return 0x0A;
+ case PacketOutgoingType.PlayerBlockPlacement: return 0x2C;
+ case PacketOutgoingType.CreativeInventoryAction: return 0x27;
+ case PacketOutgoingType.Animation: return 0x2B;
+ case PacketOutgoingType.PlayerDigging: return 0x1B;
+ case PacketOutgoingType.UpdateSign: return 0x2A;
+ }
+ }
throw new System.ComponentModel.InvalidEnumArgumentException("Unknown PacketOutgoingType (protocol=" + protocol + ")", (int)packet, typeof(PacketOutgoingType));
}
From 2d2b1e95cbaccb8fd1359c12fb7d5e9bb430b3fb Mon Sep 17 00:00:00 2001
From: Bas950 <34792838+Bas950@users.noreply.github.com>
Date: Sun, 28 Jun 2020 02:16:01 +0200
Subject: [PATCH 04/13] Revert ":recycle: Undo Terrain Handling update"
This reverts commit eb891cc91f48cd470157e732e4918ec6947bd503.
---
.../Protocol/Handlers/Protocol18.cs | 4 +-
.../Handlers/Protocol18PacketTypes.cs | 73 +------------------
2 files changed, 4 insertions(+), 73 deletions(-)
diff --git a/MinecraftClient/Protocol/Handlers/Protocol18.cs b/MinecraftClient/Protocol/Handlers/Protocol18.cs
index f4a043ba..4276adbc 100644
--- a/MinecraftClient/Protocol/Handlers/Protocol18.cs
+++ b/MinecraftClient/Protocol/Handlers/Protocol18.cs
@@ -69,7 +69,7 @@ namespace MinecraftClient.Protocol.Handlers
this.pForge = new Protocol18Forge(forgeInfo, protocolVersion, dataTypes, this, handler);
this.pTerrain = new Protocol18Terrain(protocolVersion, dataTypes, handler);
- if (handler.GetTerrainEnabled() && protocolversion > MC1152Version)
+ if (handler.GetTerrainEnabled() && protocolversion > MC1161Version)
{
ConsoleIO.WriteLineFormatted("§8Terrain & Movements currently not handled for that MC version.");
handler.SetTerrainEnabled(false);
@@ -89,7 +89,7 @@ namespace MinecraftClient.Protocol.Handlers
if (protocolversion >= MC113Version)
{
- if (protocolVersion > MC1152Version && handler.GetTerrainEnabled())
+ if (protocolVersion > MC1161Version && handler.GetTerrainEnabled())
throw new NotImplementedException("Please update block types handling for this Minecraft version. See Material.cs");
if (protocolVersion >= MC115Version)
Block.Palette = new Palette115();
diff --git a/MinecraftClient/Protocol/Handlers/Protocol18PacketTypes.cs b/MinecraftClient/Protocol/Handlers/Protocol18PacketTypes.cs
index a988feb3..6714baf5 100644
--- a/MinecraftClient/Protocol/Handlers/Protocol18PacketTypes.cs
+++ b/MinecraftClient/Protocol/Handlers/Protocol18PacketTypes.cs
@@ -288,7 +288,7 @@ namespace MinecraftClient.Protocol.Handlers
case 0x4F: return PacketIncomingType.Title;
}
}
- else if (protocol <= Protocol18Handler.MC1152Version) // MC 1.15 to 1.15.2
+ else // MC 1.15
{
switch (packetID)
{
@@ -331,48 +331,6 @@ namespace MinecraftClient.Protocol.Handlers
case 0x27: return PacketIncomingType.MapData;
case 0x50: return PacketIncomingType.Title;
}
- } else {
- switch (packetID)
- {
- case 0x20: return PacketIncomingType.KeepAlive;
- case 0x25: return PacketIncomingType.JoinGame;
- case 0x0E: return PacketIncomingType.ChatMessage;
- case 0x3A: return PacketIncomingType.Respawn;
- case 0x35: return PacketIncomingType.PlayerPositionAndLook;
- case 0x21: return PacketIncomingType.ChunkData;
- case 0x0F: return PacketIncomingType.MultiBlockChange;
- case 0x0B: return PacketIncomingType.BlockChange;
- // MapChunkBulk does not exist since 1.9
- case 0x1D: return PacketIncomingType.UnloadChunk;
- case 0x33: return PacketIncomingType.PlayerListUpdate;
- case 0x10: return PacketIncomingType.TabCompleteResult;
- case 0x18: return PacketIncomingType.PluginMessage;
- case 0x1A: return PacketIncomingType.KickPacket;
- // NetworkCompressionTreshold does not exist since 1.9
- case 0x39: return PacketIncomingType.ResourcePackSend;
- case 0x13: return PacketIncomingType.CloseWindow;
- case 0x2E: return PacketIncomingType.OpenWindow;
- case 0x14: return PacketIncomingType.WindowItems;
- case 0x16: return PacketIncomingType.SetSlot;
- case 0x00: return PacketIncomingType.SpawnEntity;
- case 0x02: return PacketIncomingType.SpawnLivingEntity;
- case 0x04: return PacketIncomingType.SpawnPlayer;
- case 0x37: return PacketIncomingType.DestroyEntities;
- case 0x17: return PacketIncomingType.SetCooldown;
- case 0x28: return PacketIncomingType.EntityPosition;
- case 0x29: return PacketIncomingType.EntityPositionAndRotation;
- case 0x58: return PacketIncomingType.EntityProperties;
- case 0x56: return PacketIncomingType.EntityTeleport;
- case 0x46: return PacketIncomingType.EntityVelocity;
- case 0x47: return PacketIncomingType.EntityEquipment;
- case 0x4E: return PacketIncomingType.TimeUpdate;
- case 0x49: return PacketIncomingType.UpdateHealth;
- case 0x48: return PacketIncomingType.SetExperience;
- case 0x3F: return PacketIncomingType.HeldItemChange;
- case 0x1C: return PacketIncomingType.Explosion;
- case 0x26: return PacketIncomingType.MapData;
- case 0x4F: return PacketIncomingType.Title;
- }
}
return PacketIncomingType.UnknownPacket;
@@ -527,7 +485,7 @@ namespace MinecraftClient.Protocol.Handlers
case PacketOutgoingType.UpdateSign: return 0x26;
}
}
- else if (protocol <= Protocol18Handler.MC1152Version) //MC 1.14 to 1.15.2
+ else // MC 1.14 to 1.15
{
switch (packet)
{
@@ -554,33 +512,6 @@ namespace MinecraftClient.Protocol.Handlers
case PacketOutgoingType.UpdateSign: return 0x29;
}
}
- else
- {
- switch (packet)
- {
- case PacketOutgoingType.KeepAlive: return 0x10;
- case PacketOutgoingType.ResourcePackStatus: return 0x20;
- case PacketOutgoingType.ChatMessage: return 0x03;
- case PacketOutgoingType.ClientStatus: return 0x04;
- case PacketOutgoingType.ClientSettings: return 0x05;
- case PacketOutgoingType.PluginMessage: return 0x0B;
- case PacketOutgoingType.TabComplete: return 0x06;
- case PacketOutgoingType.EntityAction: return 0x1C;
- case PacketOutgoingType.PlayerPosition: return 0x12;
- case PacketOutgoingType.PlayerPositionAndLook: return 0x13;
- case PacketOutgoingType.TeleportConfirm: return 0x00;
- case PacketOutgoingType.HeldItemChange: return 0x24;
- case PacketOutgoingType.InteractEntity: return 0x0E;
- case PacketOutgoingType.UseItem: return 0x2E;
- case PacketOutgoingType.ClickWindow: return 0x09;
- case PacketOutgoingType.CloseWindow: return 0x0A;
- case PacketOutgoingType.PlayerBlockPlacement: return 0x2C;
- case PacketOutgoingType.CreativeInventoryAction: return 0x27;
- case PacketOutgoingType.Animation: return 0x2B;
- case PacketOutgoingType.PlayerDigging: return 0x1B;
- case PacketOutgoingType.UpdateSign: return 0x2A;
- }
- }
throw new System.ComponentModel.InvalidEnumArgumentException("Unknown PacketOutgoingType (protocol=" + protocol + ")", (int)packet, typeof(PacketOutgoingType));
}
From e0aba29b7a5cb24b5145ecbbd8a5f21ea10f6d1c Mon Sep 17 00:00:00 2001
From: Bas950 <34792838+Bas950@users.noreply.github.com>
Date: Sun, 28 Jun 2020 02:17:11 +0200
Subject: [PATCH 05/13] Revert "Revert ":recycle: Undo Terrain Handling
update""
This reverts commit 2d2b1e95cbaccb8fd1359c12fb7d5e9bb430b3fb.
---
.../Protocol/Handlers/Protocol18.cs | 4 +-
.../Handlers/Protocol18PacketTypes.cs | 73 ++++++++++++++++++-
2 files changed, 73 insertions(+), 4 deletions(-)
diff --git a/MinecraftClient/Protocol/Handlers/Protocol18.cs b/MinecraftClient/Protocol/Handlers/Protocol18.cs
index 4276adbc..f4a043ba 100644
--- a/MinecraftClient/Protocol/Handlers/Protocol18.cs
+++ b/MinecraftClient/Protocol/Handlers/Protocol18.cs
@@ -69,7 +69,7 @@ namespace MinecraftClient.Protocol.Handlers
this.pForge = new Protocol18Forge(forgeInfo, protocolVersion, dataTypes, this, handler);
this.pTerrain = new Protocol18Terrain(protocolVersion, dataTypes, handler);
- if (handler.GetTerrainEnabled() && protocolversion > MC1161Version)
+ if (handler.GetTerrainEnabled() && protocolversion > MC1152Version)
{
ConsoleIO.WriteLineFormatted("§8Terrain & Movements currently not handled for that MC version.");
handler.SetTerrainEnabled(false);
@@ -89,7 +89,7 @@ namespace MinecraftClient.Protocol.Handlers
if (protocolversion >= MC113Version)
{
- if (protocolVersion > MC1161Version && handler.GetTerrainEnabled())
+ if (protocolVersion > MC1152Version && handler.GetTerrainEnabled())
throw new NotImplementedException("Please update block types handling for this Minecraft version. See Material.cs");
if (protocolVersion >= MC115Version)
Block.Palette = new Palette115();
diff --git a/MinecraftClient/Protocol/Handlers/Protocol18PacketTypes.cs b/MinecraftClient/Protocol/Handlers/Protocol18PacketTypes.cs
index 6714baf5..a988feb3 100644
--- a/MinecraftClient/Protocol/Handlers/Protocol18PacketTypes.cs
+++ b/MinecraftClient/Protocol/Handlers/Protocol18PacketTypes.cs
@@ -288,7 +288,7 @@ namespace MinecraftClient.Protocol.Handlers
case 0x4F: return PacketIncomingType.Title;
}
}
- else // MC 1.15
+ else if (protocol <= Protocol18Handler.MC1152Version) // MC 1.15 to 1.15.2
{
switch (packetID)
{
@@ -331,6 +331,48 @@ namespace MinecraftClient.Protocol.Handlers
case 0x27: return PacketIncomingType.MapData;
case 0x50: return PacketIncomingType.Title;
}
+ } else {
+ switch (packetID)
+ {
+ case 0x20: return PacketIncomingType.KeepAlive;
+ case 0x25: return PacketIncomingType.JoinGame;
+ case 0x0E: return PacketIncomingType.ChatMessage;
+ case 0x3A: return PacketIncomingType.Respawn;
+ case 0x35: return PacketIncomingType.PlayerPositionAndLook;
+ case 0x21: return PacketIncomingType.ChunkData;
+ case 0x0F: return PacketIncomingType.MultiBlockChange;
+ case 0x0B: return PacketIncomingType.BlockChange;
+ // MapChunkBulk does not exist since 1.9
+ case 0x1D: return PacketIncomingType.UnloadChunk;
+ case 0x33: return PacketIncomingType.PlayerListUpdate;
+ case 0x10: return PacketIncomingType.TabCompleteResult;
+ case 0x18: return PacketIncomingType.PluginMessage;
+ case 0x1A: return PacketIncomingType.KickPacket;
+ // NetworkCompressionTreshold does not exist since 1.9
+ case 0x39: return PacketIncomingType.ResourcePackSend;
+ case 0x13: return PacketIncomingType.CloseWindow;
+ case 0x2E: return PacketIncomingType.OpenWindow;
+ case 0x14: return PacketIncomingType.WindowItems;
+ case 0x16: return PacketIncomingType.SetSlot;
+ case 0x00: return PacketIncomingType.SpawnEntity;
+ case 0x02: return PacketIncomingType.SpawnLivingEntity;
+ case 0x04: return PacketIncomingType.SpawnPlayer;
+ case 0x37: return PacketIncomingType.DestroyEntities;
+ case 0x17: return PacketIncomingType.SetCooldown;
+ case 0x28: return PacketIncomingType.EntityPosition;
+ case 0x29: return PacketIncomingType.EntityPositionAndRotation;
+ case 0x58: return PacketIncomingType.EntityProperties;
+ case 0x56: return PacketIncomingType.EntityTeleport;
+ case 0x46: return PacketIncomingType.EntityVelocity;
+ case 0x47: return PacketIncomingType.EntityEquipment;
+ case 0x4E: return PacketIncomingType.TimeUpdate;
+ case 0x49: return PacketIncomingType.UpdateHealth;
+ case 0x48: return PacketIncomingType.SetExperience;
+ case 0x3F: return PacketIncomingType.HeldItemChange;
+ case 0x1C: return PacketIncomingType.Explosion;
+ case 0x26: return PacketIncomingType.MapData;
+ case 0x4F: return PacketIncomingType.Title;
+ }
}
return PacketIncomingType.UnknownPacket;
@@ -485,7 +527,7 @@ namespace MinecraftClient.Protocol.Handlers
case PacketOutgoingType.UpdateSign: return 0x26;
}
}
- else // MC 1.14 to 1.15
+ else if (protocol <= Protocol18Handler.MC1152Version) //MC 1.14 to 1.15.2
{
switch (packet)
{
@@ -512,6 +554,33 @@ namespace MinecraftClient.Protocol.Handlers
case PacketOutgoingType.UpdateSign: return 0x29;
}
}
+ else
+ {
+ switch (packet)
+ {
+ case PacketOutgoingType.KeepAlive: return 0x10;
+ case PacketOutgoingType.ResourcePackStatus: return 0x20;
+ case PacketOutgoingType.ChatMessage: return 0x03;
+ case PacketOutgoingType.ClientStatus: return 0x04;
+ case PacketOutgoingType.ClientSettings: return 0x05;
+ case PacketOutgoingType.PluginMessage: return 0x0B;
+ case PacketOutgoingType.TabComplete: return 0x06;
+ case PacketOutgoingType.EntityAction: return 0x1C;
+ case PacketOutgoingType.PlayerPosition: return 0x12;
+ case PacketOutgoingType.PlayerPositionAndLook: return 0x13;
+ case PacketOutgoingType.TeleportConfirm: return 0x00;
+ case PacketOutgoingType.HeldItemChange: return 0x24;
+ case PacketOutgoingType.InteractEntity: return 0x0E;
+ case PacketOutgoingType.UseItem: return 0x2E;
+ case PacketOutgoingType.ClickWindow: return 0x09;
+ case PacketOutgoingType.CloseWindow: return 0x0A;
+ case PacketOutgoingType.PlayerBlockPlacement: return 0x2C;
+ case PacketOutgoingType.CreativeInventoryAction: return 0x27;
+ case PacketOutgoingType.Animation: return 0x2B;
+ case PacketOutgoingType.PlayerDigging: return 0x1B;
+ case PacketOutgoingType.UpdateSign: return 0x2A;
+ }
+ }
throw new System.ComponentModel.InvalidEnumArgumentException("Unknown PacketOutgoingType (protocol=" + protocol + ")", (int)packet, typeof(PacketOutgoingType));
}
From 424eab29dd2d4848142d368b6458ddc7e7cae1b1 Mon Sep 17 00:00:00 2001
From: Bas950 <34792838+Bas950@users.noreply.github.com>
Date: Mon, 29 Jun 2020 16:05:12 +0200
Subject: [PATCH 06/13] Join Game and Respawn encoding/decoding & added
ReadNextVarIntArray
---
.../Protocol/Handlers/DataTypes.cs | 1733 ++++-----
.../Protocol/Handlers/Protocol18.cs | 3105 +++++++++--------
2 files changed, 2446 insertions(+), 2392 deletions(-)
diff --git a/MinecraftClient/Protocol/Handlers/DataTypes.cs b/MinecraftClient/Protocol/Handlers/DataTypes.cs
index 5a077073..0b7ae768 100644
--- a/MinecraftClient/Protocol/Handlers/DataTypes.cs
+++ b/MinecraftClient/Protocol/Handlers/DataTypes.cs
@@ -10,864 +10,885 @@ using MinecraftClient.Mapping.EntityPalettes;
namespace MinecraftClient.Protocol.Handlers
{
+ ///
+ /// Handle data types encoding / decoding
+ ///
+ class DataTypes
+ {
///
- /// Handle data types encoding / decoding
+ /// Protocol version for adjusting data types
///
- class DataTypes
+ private int protocolversion;
+
+ ///
+ /// Initialize a new DataTypes instance
+ ///
+ /// Protocol version
+ public DataTypes(int protocol)
{
- ///
- /// Protocol version for adjusting data types
- ///
- private int protocolversion;
-
- ///
- /// Initialize a new DataTypes instance
- ///
- /// Protocol version
- public DataTypes(int protocol)
- {
- this.protocolversion = protocol;
- }
-
- ///
- /// Read some data from a cache of bytes and remove it from the cache
- ///
- /// Amount of bytes to read
- /// Cache of bytes to read from
- /// The data read from the cache as an array
- public byte[] ReadData(int offset, Queue cache)
- {
- byte[] result = new byte[offset];
- for (int i = 0; i < offset; i++)
- result[i] = cache.Dequeue();
- return result;
- }
-
- ///
- /// Read a string from a cache of bytes and remove it from the cache
- ///
- /// Cache of bytes to read from
- /// The string
- public string ReadNextString(Queue cache)
- {
- int length = ReadNextVarInt(cache);
- if (length > 0)
- {
- return Encoding.UTF8.GetString(ReadData(length, cache));
- }
- else return "";
- }
-
- ///
- /// Read a boolean from a cache of bytes and remove it from the cache
- ///
- /// The boolean value
- public bool ReadNextBool(Queue cache)
- {
- return ReadNextByte(cache) != 0x00;
- }
-
- ///
- /// Read a short integer from a cache of bytes and remove it from the cache
- ///
- /// The short integer value
- public short ReadNextShort(Queue cache)
- {
- byte[] rawValue = ReadData(2, cache);
- Array.Reverse(rawValue); //Endianness
- return BitConverter.ToInt16(rawValue, 0);
- }
-
- ///
- /// Read an integer from a cache of bytes and remove it from the cache
- ///
- /// The integer value
- public int ReadNextInt(Queue cache)
- {
- byte[] rawValue = ReadData(4, cache);
- Array.Reverse(rawValue); //Endianness
- return BitConverter.ToInt32(rawValue, 0);
- }
-
- ///
- /// Read a long integer from a cache of bytes and remove it from the cache
- ///
- /// The unsigned long integer value
- public long ReadNextLong(Queue cache)
- {
- byte[] rawValue = ReadData(8, cache);
- Array.Reverse(rawValue); //Endianness
- return BitConverter.ToInt64(rawValue, 0);
- }
-
- ///
- /// Read an unsigned short integer from a cache of bytes and remove it from the cache
- ///
- /// The unsigned short integer value
- public ushort ReadNextUShort(Queue cache)
- {
- byte[] rawValue = ReadData(2, cache);
- Array.Reverse(rawValue); //Endianness
- return BitConverter.ToUInt16(rawValue, 0);
- }
-
- ///
- /// Read an unsigned long integer from a cache of bytes and remove it from the cache
- ///
- /// The unsigned long integer value
- public ulong ReadNextULong(Queue cache)
- {
- byte[] rawValue = ReadData(8, cache);
- Array.Reverse(rawValue); //Endianness
- return BitConverter.ToUInt64(rawValue, 0);
- }
-
- ///
- /// Read a Location encoded as an ulong field and remove it from the cache
- ///
- /// The Location value
- public Location ReadNextLocation(Queue cache)
- {
- ulong locEncoded = ReadNextULong(cache);
- int x, y, z;
- if (protocolversion >= Protocol18Handler.MC114Version)
- {
- x = (int)(locEncoded >> 38);
- y = (int)(locEncoded & 0xFFF);
- z = (int)(locEncoded << 26 >> 38);
- }
- else
- {
- x = (int)(locEncoded >> 38);
- y = (int)((locEncoded >> 26) & 0xFFF);
- z = (int)(locEncoded << 38 >> 38);
- }
- if (x >= 33554432)
- x -= 67108864;
- if (y >= 2048)
- y -= 4096;
- if (z >= 33554432)
- z -= 67108864;
- return new Location(x, y, z);
- }
-
- ///
- /// Read several little endian unsigned short integers at once from a cache of bytes and remove them from the cache
- ///
- /// The unsigned short integer value
- public ushort[] ReadNextUShortsLittleEndian(int amount, Queue cache)
- {
- byte[] rawValues = ReadData(2 * amount, cache);
- ushort[] result = new ushort[amount];
- for (int i = 0; i < amount; i++)
- result[i] = BitConverter.ToUInt16(rawValues, i * 2);
- return result;
- }
-
- ///
- /// Read a uuid from a cache of bytes and remove it from the cache
- ///
- /// Cache of bytes to read from
- /// The uuid
- public Guid ReadNextUUID(Queue cache)
- {
- byte[] javaUUID = ReadData(16, cache);
- Guid guid;
- if (BitConverter.IsLittleEndian)
- {
- // Convert big-endian Java UUID to little-endian .NET GUID
- byte[] netGUID = new byte[16];
- for (int i = 8; i < 16; i++)
- netGUID[i] = javaUUID[i];
- netGUID[3] = javaUUID[0];
- netGUID[2] = javaUUID[1];
- netGUID[1] = javaUUID[2];
- netGUID[0] = javaUUID[3];
- netGUID[5] = javaUUID[4];
- netGUID[4] = javaUUID[5];
- netGUID[6] = javaUUID[7];
- netGUID[7] = javaUUID[6];
- guid = new Guid(netGUID);
- }
- else
- {
- guid = new Guid(javaUUID);
- }
- return guid;
- }
-
- ///
- /// Read a byte array from a cache of bytes and remove it from the cache
- ///
- /// Cache of bytes to read from
- /// The byte array
- public byte[] ReadNextByteArray(Queue cache)
- {
- int len = protocolversion >= Protocol18Handler.MC18Version
- ? ReadNextVarInt(cache)
- : ReadNextShort(cache);
- return ReadData(len, cache);
- }
-
- ///
- /// Reads a length-prefixed array of unsigned long integers and removes it from the cache
- ///
- /// The unsigned long integer values
- public ulong[] ReadNextULongArray(Queue cache)
- {
- int len = ReadNextVarInt(cache);
- ulong[] result = new ulong[len];
- for (int i = 0; i < len; i++)
- result[i] = ReadNextULong(cache);
- return result;
- }
-
- ///
- /// Read a double from a cache of bytes and remove it from the cache
- ///
- /// The double value
- public double ReadNextDouble(Queue cache)
- {
- byte[] rawValue = ReadData(8, cache);
- Array.Reverse(rawValue); //Endianness
- return BitConverter.ToDouble(rawValue, 0);
- }
-
- ///
- /// Read a float from a cache of bytes and remove it from the cache
- ///
- /// The float value
- public float ReadNextFloat(Queue cache)
- {
- byte[] rawValue = ReadData(4, cache);
- Array.Reverse(rawValue); //Endianness
- return BitConverter.ToSingle(rawValue, 0);
- }
-
- ///
- /// Read an integer from the network
- ///
- /// The integer
- public int ReadNextVarIntRAW(SocketWrapper socket)
- {
- int i = 0;
- int j = 0;
- int k = 0;
- while (true)
- {
- k = socket.ReadDataRAW(1)[0];
- i |= (k & 0x7F) << j++ * 7;
- if (j > 5) throw new OverflowException("VarInt too big");
- if ((k & 0x80) != 128) break;
- }
- return i;
- }
-
- ///
- /// Read an integer from a cache of bytes and remove it from the cache
- ///
- /// Cache of bytes to read from
- /// The integer
- public int ReadNextVarInt(Queue cache)
- {
- string rawData = BitConverter.ToString(cache.ToArray());
- 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;
- }
-
- ///
- /// 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
- /// bit is set, it has an extra byte.
- ///
- /// Cache of bytes to read from
- /// The int
- public int ReadNextVarShort(Queue cache)
- {
- ushort low = ReadNextUShort(cache);
- byte high = 0;
- if ((low & 0x8000) != 0)
- {
- low &= 0x7FFF;
- high = ReadNextByte(cache);
- }
- return ((high & 0xFF) << 15) | low;
- }
-
- ///
- /// Read a single byte from a cache of bytes and remove it from the cache
- ///
- /// The byte that was read
- public byte ReadNextByte(Queue cache)
- {
- byte result = cache.Dequeue();
- return result;
- }
-
- ///
- /// Read an uncompressed Named Binary Tag blob and remove it from the cache
- ///
- public Dictionary ReadNextNbt(Queue cache)
- {
- return ReadNextNbt(cache, true);
- }
-
- ///
- /// Read a single item slot from a cache of bytes and remove it from the cache
- ///
- /// The item that was read or NULL for an empty slot
- public Item ReadNextItemSlot(Queue cache)
- {
- List slotData = new List();
- if (protocolversion > Protocol18Handler.MC113Version)
- {
- // MC 1.13 and greater
- bool itemPresent = ReadNextBool(cache);
- if (itemPresent)
- {
- int itemID = ReadNextVarInt(cache);
- byte itemCount = ReadNextByte(cache);
- Dictionary nbt = ReadNextNbt(cache);
- return new Item(itemID, itemCount, nbt);
- }
- else return null;
- }
- else
- {
- // MC 1.12.2 and lower
- short itemID = ReadNextShort(cache);
- if (itemID == -1)
- return null;
- byte itemCount = ReadNextByte(cache);
- short itemDamage = ReadNextShort(cache);
- Dictionary nbt = ReadNextNbt(cache);
- return new Item(itemID, itemCount, nbt);
- }
- }
-
- ///
- /// Read entity information from a cache of bytes and remove it from the cache
- ///
- /// Mappings for converting entity type Ids to EntityType
- /// TRUE for living entities (layout differs)
- /// Entity information
- public Entity ReadNextEntity(Queue cache, EntityPalette entityPalette, bool living)
- {
- int entityID = ReadNextVarInt(cache);
- Guid entityUUID = Guid.Empty;
-
- if (protocolversion > Protocol18Handler.MC18Version)
- {
- entityUUID = ReadNextUUID(cache);
- }
-
- EntityType entityType = entityPalette.FromId(ReadNextVarInt(cache), living);
- Double entityX = ReadNextDouble(cache);
- Double entityY = ReadNextDouble(cache);
- Double entityZ = ReadNextDouble(cache);
- byte entityYaw = ReadNextByte(cache);
- byte entityPitch = ReadNextByte(cache);
-
- if (living)
- {
- byte entityHeadPitch = ReadNextByte(cache);
- }
- else
- {
- int metadata = ReadNextInt(cache);
- }
-
- short velocityX = ReadNextShort(cache);
- short velocityY = ReadNextShort(cache);
- short velocityZ = ReadNextShort(cache);
-
- return new Entity(entityID, entityType, new Location(entityX, entityY, entityZ));
- }
-
- ///
- /// Read an uncompressed Named Binary Tag blob and remove it from the cache (internal)
- ///
- private Dictionary ReadNextNbt(Queue cache, bool root)
- {
- Dictionary nbtData = new Dictionary();
-
- if (root)
- {
- if (cache.Peek() == 0) // TAG_End
- {
- cache.Dequeue();
- return nbtData;
- }
- if (cache.Peek() != 10) // TAG_Compound
- throw new System.IO.InvalidDataException("Failed to decode NBT: Does not start with TAG_Compound");
- ReadNextByte(cache); // Tag type (TAG_Compound)
-
- // NBT root name
- string rootName = Encoding.ASCII.GetString(ReadData(ReadNextUShort(cache), cache));
- if (!String.IsNullOrEmpty(rootName))
- nbtData[""] = rootName;
- }
-
- while (true)
- {
- int fieldType = ReadNextByte(cache);
-
- if (fieldType == 0) // TAG_End
- return nbtData;
-
- int fieldNameLength = ReadNextUShort(cache);
- string fieldName = Encoding.ASCII.GetString(ReadData(fieldNameLength, cache));
- object fieldValue = ReadNbtField(cache, fieldType);
-
- // This will override previous tags with the same name
- nbtData[fieldName] = fieldValue;
- }
- }
-
- ///
- /// Read a single Named Binary Tag field of the specified type and remove it from the cache
- ///
- private object ReadNbtField(Queue cache, int fieldType)
- {
- switch (fieldType)
- {
- case 1: // TAG_Byte
- return ReadNextByte(cache);
- case 2: // TAG_Short
- return ReadNextShort(cache);
- case 3: // TAG_Int
- return ReadNextInt(cache);
- case 4: // TAG_Long
- return ReadNextLong(cache);
- case 5: // TAG_Float
- return ReadNextFloat(cache);
- case 6: // TAG_Double
- return ReadNextDouble(cache);
- case 7: // TAG_Byte_Array
- return ReadData(ReadNextInt(cache), cache);
- case 8: // TAG_String
- return Encoding.UTF8.GetString(ReadData(ReadNextUShort(cache), cache));
- case 9: // TAG_List
- int listType = ReadNextByte(cache);
- int listLength = ReadNextInt(cache);
- object[] listItems = new object[listLength];
- for (int i = 0; i < listLength; i++)
- listItems[i] = ReadNbtField(cache, listType);
- return listItems;
- case 10: // TAG_Compound
- return ReadNextNbt(cache, false);
- case 11: // TAG_Int_Array
- listType = 3;
- listLength = ReadNextInt(cache);
- listItems = new object[listLength];
- for (int i = 0; i < listLength; i++)
- listItems[i] = ReadNbtField(cache, listType);
- return listItems;
- case 12: // TAG_Long_Array
- listType = 4;
- listLength = ReadNextInt(cache);
- listItems = new object[listLength];
- for (int i = 0; i < listLength; i++)
- listItems[i] = ReadNbtField(cache, listType);
- return listItems;
- default:
- throw new System.IO.InvalidDataException("Failed to decode NBT: Unknown field type " + fieldType);
- }
- }
-
- ///
- /// Build an uncompressed Named Binary Tag blob for sending over the network
- ///
- /// Dictionary to encode as Nbt
- /// Byte array for this NBT tag
- public byte[] GetNbt(Dictionary nbt)
- {
- return GetNbt(nbt, true);
- }
-
- ///
- /// Build an uncompressed Named Binary Tag blob for sending over the network (internal)
- ///
- /// Dictionary to encode as Nbt
- /// TRUE if starting a new NBT tag, FALSE if processing a nested NBT tag
- /// Byte array for this NBT tag
- private byte[] GetNbt(Dictionary nbt, bool root)
- {
- if (nbt == null || nbt.Count == 0)
- return new byte[] { 0 }; // TAG_End
-
- List bytes = new List();
-
- if (root)
- {
- bytes.Add(10); // TAG_Compound
-
- // NBT root name
- string rootName = null;
- if (nbt.ContainsKey(""))
- rootName = nbt[""] as string;
- if (rootName == null)
- rootName = "";
- bytes.AddRange(GetUShort((ushort)rootName.Length));
- bytes.AddRange(Encoding.ASCII.GetBytes(rootName));
- }
-
- foreach (var item in nbt)
- {
- // Skip NBT root name
- if (item.Key == "" && root)
- continue;
-
- byte fieldType;
- byte[] fieldNameLength = GetUShort((ushort)item.Key.Length);
- byte[] fieldName = Encoding.ASCII.GetBytes(item.Key);
- byte[] fieldData = GetNbtField(item.Value, out fieldType);
- bytes.Add(fieldType);
- bytes.AddRange(fieldNameLength);
- bytes.AddRange(fieldName);
- bytes.AddRange(fieldData);
- }
-
- bytes.Add(0); // TAG_End
- return bytes.ToArray();
- }
-
- ///
- /// Convert a single object into its NBT representation (internal)
- ///
- /// Object to convert
- /// Field type for the passed object
- /// Binary data for the passed object
- private byte[] GetNbtField(object obj, out byte fieldType)
- {
- if (obj is byte)
- {
- fieldType = 1; // TAG_Byte
- return new[] { (byte)obj };
- }
- else if (obj is short)
- {
- fieldType = 2; // TAG_Short
- return GetShort((short)obj);
- }
- else if (obj is int)
- {
- fieldType = 3; // TAG_Int
- return GetInt((int)obj);
- }
- else if (obj is long)
- {
- fieldType = 4; // TAG_Long
- return GetLong((long)obj);
- }
- else if (obj is float)
- {
- fieldType = 5; // TAG_Float
- return GetFloat((float)obj);
- }
- else if (obj is double)
- {
- fieldType = 6; // TAG_Double
- return GetDouble((double)obj);
- }
- else if (obj is byte[])
- {
- fieldType = 7; // TAG_Byte_Array
- return (byte[])obj;
- }
- else if (obj is string)
- {
- fieldType = 8; // TAG_String
- byte[] stringBytes = Encoding.UTF8.GetBytes((string)obj);
- return ConcatBytes(GetUShort((ushort)stringBytes.Length), stringBytes);
- }
- else if (obj is object[])
- {
- fieldType = 9; // TAG_List
-
- List