From 4538095d74003210c42ad682a21d6596cb93e4ff Mon Sep 17 00:00:00 2001 From: BruceChen Date: Fri, 2 Sep 2022 09:29:24 +0800 Subject: [PATCH] Reduce merge conflicts --- MinecraftClient/McClient.cs | 18 +- .../Protocol/Handlers/Protocol18.cs | 288 +++++++++--------- 2 files changed, 155 insertions(+), 151 deletions(-) diff --git a/MinecraftClient/McClient.cs b/MinecraftClient/McClient.cs index 586798ac..fccbe126 100644 --- a/MinecraftClient/McClient.cs +++ b/MinecraftClient/McClient.cs @@ -1131,17 +1131,19 @@ namespace MinecraftClient /// Text to send to the server public void SendText(string text) { + if (String.IsNullOrEmpty(text)) + return; + + int maxLength = handler.GetMaxChatMessageLength(); + lock (chatQueue) { - if (String.IsNullOrEmpty(text)) - return; - int maxLength = handler.GetMaxChatMessageLength(); if (text.Length > maxLength) //Message is too long? { if (text[0] == '/') { //Send the first 100/256 chars of the command - text = text.Substring(0, maxLength); + text = text[..maxLength]; chatQueue.Enqueue(text); } else @@ -1149,13 +1151,15 @@ namespace MinecraftClient //Split the message into several messages while (text.Length > maxLength) { - chatQueue.Enqueue(text.Substring(0, maxLength)); - text = text.Substring(maxLength, text.Length - maxLength); + chatQueue.Enqueue(text[..maxLength]); + text = text[maxLength..]; } chatQueue.Enqueue(text); } } - else chatQueue.Enqueue(text); + else + chatQueue.Enqueue(text); + TrySendMessageToServer(); } } diff --git a/MinecraftClient/Protocol/Handlers/Protocol18.cs b/MinecraftClient/Protocol/Handlers/Protocol18.cs index 1d34bd94..81de68ff 100644 --- a/MinecraftClient/Protocol/Handlers/Protocol18.cs +++ b/MinecraftClient/Protocol/Handlers/Protocol18.cs @@ -64,7 +64,7 @@ namespace MinecraftClient.Protocol.Handlers private readonly List autocomplete_result = new List(); private readonly Dictionary window_actions = new Dictionary(); private bool login_phase = true; - private int protocolversion; + private int protocolVersion; private int currentDimension; private readonly BlockingCollection>> packetQueue = new(); @@ -87,7 +87,7 @@ namespace MinecraftClient.Protocol.Handlers ChatParser.InitTranslations(); this.socketWrapper = new SocketWrapper(Client); this.dataTypes = new DataTypes(protocolVersion); - this.protocolversion = protocolVersion; + this.protocolVersion = protocolVersion; this.handler = handler; this.pForge = new Protocol18Forge(forgeInfo, protocolVersion, dataTypes, this, handler); this.pTerrain = new Protocol18Terrain(protocolVersion, dataTypes, handler); @@ -95,26 +95,26 @@ namespace MinecraftClient.Protocol.Handlers this.log = handler.GetLogger(); this.randomGen = RandomNumberGenerator.Create(); - if (handler.GetTerrainEnabled() && protocolversion > MC_1_18_2_Version) + if (handler.GetTerrainEnabled() && protocolVersion > MC_1_18_2_Version) { log.Error(Translations.Get("extra.terrainandmovement_disabled")); handler.SetTerrainEnabled(false); } - if (handler.GetInventoryEnabled() && (protocolversion < MC_1_10_Version || protocolversion > MC_1_18_2_Version)) + if (handler.GetInventoryEnabled() && (protocolVersion < MC_1_10_Version || protocolVersion > MC_1_18_2_Version)) { log.Error(Translations.Get("extra.inventory_disabled")); handler.SetInventoryEnabled(false); } - if (handler.GetEntityHandlingEnabled() && (protocolversion < MC_1_10_Version || protocolversion > MC_1_18_2_Version)) + if (handler.GetEntityHandlingEnabled() && (protocolVersion < MC_1_10_Version || protocolVersion > MC_1_18_2_Version)) { log.Error(Translations.Get("extra.entity_disabled")); handler.SetEntityHandlingEnabled(false); } // Block palette - if (protocolversion >= MC_1_13_Version) + if (protocolVersion >= MC_1_13_Version) { if (protocolVersion > MC_1_18_2_Version && handler.GetTerrainEnabled()) throw new NotImplementedException(Translations.Get("exception.palette.block")); @@ -132,18 +132,18 @@ namespace MinecraftClient.Protocol.Handlers else Block.Palette = new Palette112(); // Entity palette - if (protocolversion >= MC_1_13_Version) + if (protocolVersion >= MC_1_13_Version) { - if (protocolversion > MC_1_18_2_Version && handler.GetEntityHandlingEnabled()) + if (protocolVersion > MC_1_18_2_Version && handler.GetEntityHandlingEnabled()) throw new NotImplementedException(Translations.Get("exception.palette.entity")); - if (protocolversion >= MC_1_17_Version) + if (protocolVersion >= MC_1_17_Version) entityPalette = new EntityPalette117(); - else if (protocolversion >= MC_1_16_2_Version) - if (protocolversion >= MC_1_16_2_Version) + else if (protocolVersion >= MC_1_16_2_Version) + if (protocolVersion >= MC_1_16_2_Version) entityPalette = new EntityPalette1162(); - else if (protocolversion >= MC_1_16_Version) + else if (protocolVersion >= MC_1_16_Version) entityPalette = new EntityPalette1161(); - else if (protocolversion >= MC_1_15_Version) + else if (protocolVersion >= MC_1_15_Version) entityPalette = new EntityPalette115(); else if (protocolVersion >= MC_1_14_Version) entityPalette = new EntityPalette114(); @@ -152,16 +152,16 @@ namespace MinecraftClient.Protocol.Handlers else entityPalette = new EntityPalette112(); // Item palette - if (protocolversion >= MC_1_16_2_Version) + if (protocolVersion >= MC_1_16_2_Version) { - if (protocolversion > MC_1_18_2_Version && handler.GetInventoryEnabled()) + if (protocolVersion > MC_1_18_2_Version && handler.GetInventoryEnabled()) throw new NotImplementedException(Translations.Get("exception.palette.item")); - if (protocolversion >= MC_1_18_1_Version) + if (protocolVersion >= MC_1_18_1_Version) itemPalette = new ItemPalette118(); - else if (protocolversion >= MC_1_17_Version) + else if (protocolVersion >= MC_1_17_Version) itemPalette = new ItemPalette117(); - else if (protocolversion >= MC_1_16_2_Version) - if (protocolversion >= MC_1_16_2_Version) + else if (protocolVersion >= MC_1_16_2_Version) + if (protocolVersion >= MC_1_16_2_Version) itemPalette = new ItemPalette1162(); else itemPalette = new ItemPalette1161(); } @@ -261,7 +261,7 @@ namespace MinecraftClient.Protocol.Handlers Queue packetData = new(socketWrapper.ReadDataRAW(size)); //Packet contents //Handle packet decompression - if (protocolversion >= MC_1_8_Version + if (protocolVersion >= MC_1_8_Version && compression_treshold > 0) { int sizeUncompressed = dataTypes.ReadNextVarInt(packetData); @@ -299,7 +299,7 @@ namespace MinecraftClient.Protocol.Handlers switch (packetID) //Packet IDs are different while logging in { case 0x03: - if (protocolversion >= MC_1_8_Version) + if (protocolVersion >= MC_1_8_Version) compression_treshold = dataTypes.ReadNextVarInt(packetData); break; case 0x04: @@ -329,12 +329,12 @@ namespace MinecraftClient.Protocol.Handlers int playerEntityID = dataTypes.ReadNextInt(packetData); handler.OnReceivePlayerEntityID(playerEntityID); - if (protocolversion >= MC_1_16_2_Version) + if (protocolVersion >= MC_1_16_2_Version) dataTypes.ReadNextBool(packetData); // Is hardcore - 1.16.2 and above handler.OnGamemodeUpdate(Guid.Empty, dataTypes.ReadNextByte(packetData)); - if (protocolversion >= MC_1_16_Version) + if (protocolVersion >= MC_1_16_Version) { dataTypes.ReadNextByte(packetData); // Previous Gamemode - 1.16 and above int worldCount = dataTypes.ReadNextVarInt(packetData); // Dimension Count (World Count) - 1.16 and above @@ -351,55 +351,55 @@ namespace MinecraftClient.Protocol.Handlers // String identifier: 1.16 and 1.16.1 // varInt: [1.9.1 to 1.15.2] // byte: below 1.9.1 - if (protocolversion >= MC_1_16_Version) + if (protocolVersion >= MC_1_16_Version) { - if (protocolversion >= MC_1_19_Version) + if (protocolVersion >= MC_1_19_Version) { dataTypes.ReadNextString(packetData); // Dimension Type: Identifier currentDimensionType = new Dictionary(); } - else if (protocolversion >= MC_1_16_2_Version) + else if (protocolVersion >= MC_1_16_2_Version) currentDimensionType = dataTypes.ReadNextNbt(packetData); // Dimension Type: NBT Tag Compound else dataTypes.ReadNextString(packetData); this.currentDimension = 0; } - else if (protocolversion >= MC_1_9_1_Version) + else if (protocolVersion >= MC_1_9_1_Version) this.currentDimension = dataTypes.ReadNextInt(packetData); else this.currentDimension = (sbyte)dataTypes.ReadNextByte(packetData); - if (protocolversion < MC_1_14_Version) + if (protocolVersion < MC_1_14_Version) dataTypes.ReadNextByte(packetData); // Difficulty - 1.13 and below - if (protocolversion >= MC_1_16_Version) + if (protocolVersion >= MC_1_16_Version) currentDimensionName = dataTypes.ReadNextString(packetData); // Dimension Name (World Name) - 1.16 and above - if (protocolversion >= MC_1_16_2_Version) + if (protocolVersion >= MC_1_16_2_Version) World.SetDimension(currentDimensionName, currentDimensionType); - if (protocolversion >= MC_1_15_Version) + if (protocolVersion >= MC_1_15_Version) dataTypes.ReadNextLong(packetData); // Hashed world seed - 1.15 and above - if (protocolversion >= MC_1_16_2_Version) + if (protocolVersion >= MC_1_16_2_Version) dataTypes.ReadNextVarInt(packetData); // Max Players - 1.16.2 and above else dataTypes.ReadNextByte(packetData); // Max Players - 1.16.1 and below - if (protocolversion < MC_1_16_Version) + if (protocolVersion < MC_1_16_Version) dataTypes.SkipNextString(packetData); // Level Type - 1.15 and below - if (protocolversion >= MC_1_14_Version) + if (protocolVersion >= MC_1_14_Version) dataTypes.ReadNextVarInt(packetData); // View distance - 1.14 and above - if (protocolversion >= MC_1_18_1_Version) + if (protocolVersion >= MC_1_18_1_Version) dataTypes.ReadNextVarInt(packetData); // Simulation Distance - 1.18 and above - if (protocolversion >= MC_1_8_Version) + if (protocolVersion >= MC_1_8_Version) dataTypes.ReadNextBool(packetData); // Reduced debug info - 1.8 and above - if (protocolversion >= MC_1_15_Version) + if (protocolVersion >= MC_1_15_Version) dataTypes.ReadNextBool(packetData); // Enable respawn screen - 1.15 and above - if (protocolversion >= MC_1_16_Version) + if (protocolVersion >= MC_1_16_Version) { dataTypes.ReadNextBool(packetData); // Is Debug - 1.16 and above dataTypes.ReadNextBool(packetData); // Is Flat - 1.16 and above } - if (protocolversion >= MC_1_19_Version) + if (protocolVersion >= MC_1_19_Version) { bool hasDeathLocation = dataTypes.ReadNextBool(packetData); // Has death location if (hasDeathLocation) @@ -412,12 +412,12 @@ namespace MinecraftClient.Protocol.Handlers case PacketTypesIn.ChatMessage: int messageType = 0; - if (protocolversion <= MC_1_18_2_Version) // 1.18 and bellow + if (protocolVersion <= MC_1_18_2_Version) // 1.18 and bellow { string message = dataTypes.ReadNextString(packetData); Guid senderUUID; - if (protocolversion >= MC_1_8_Version) + if (protocolVersion >= MC_1_8_Version) { //Hide system messages or xp bar messages? messageType = dataTypes.ReadNextByte(packetData); @@ -425,7 +425,7 @@ namespace MinecraftClient.Protocol.Handlers || (messageType == 2 && !Settings.DisplayXPBarMessages)) break; - if (protocolversion >= MC_1_16_5_Version) + if (protocolVersion >= MC_1_16_5_Version) senderUUID = dataTypes.ReadNextUUID(packetData); else senderUUID = Guid.Empty; } @@ -467,14 +467,14 @@ namespace MinecraftClient.Protocol.Handlers case PacketTypesIn.Respawn: string? dimensionNameInRespawn = null; Dictionary dimensionTypeInRespawn = null; - if (protocolversion >= MC_1_16_Version) + if (protocolVersion >= MC_1_16_Version) { - if (protocolversion >= MC_1_19_Version) + if (protocolVersion >= MC_1_19_Version) { dataTypes.ReadNextString(packetData); // Dimension Type: Identifier dimensionTypeInRespawn = new Dictionary(); } - else if (protocolversion >= MC_1_16_2_Version) + else if (protocolVersion >= MC_1_16_2_Version) dimensionTypeInRespawn = dataTypes.ReadNextNbt(packetData); // Dimension Type: NBT Tag Compound else dataTypes.ReadNextString(packetData); @@ -485,28 +485,28 @@ namespace MinecraftClient.Protocol.Handlers // 1.15 and below this.currentDimension = dataTypes.ReadNextInt(packetData); } - if (protocolversion >= MC_1_16_Version) + if (protocolVersion >= MC_1_16_Version) dimensionNameInRespawn = dataTypes.ReadNextString(packetData); // Dimension Name (World Name) - 1.16 and above - if (protocolversion >= MC_1_16_2_Version) + if (protocolVersion >= MC_1_16_2_Version) World.SetDimension(dimensionNameInRespawn, dimensionTypeInRespawn); - if (protocolversion < MC_1_14_Version) + if (protocolVersion < MC_1_14_Version) dataTypes.ReadNextByte(packetData); // Difficulty - 1.13 and below - if (protocolversion >= MC_1_15_Version) + if (protocolVersion >= MC_1_15_Version) dataTypes.ReadNextLong(packetData); // Hashed world seed - 1.15 and above dataTypes.ReadNextByte(packetData); // Gamemode - if (protocolversion >= MC_1_16_Version) + if (protocolVersion >= MC_1_16_Version) dataTypes.ReadNextByte(packetData); // Previous Game mode - 1.16 and above - if (protocolversion < MC_1_16_Version) + if (protocolVersion < MC_1_16_Version) dataTypes.SkipNextString(packetData); // Level Type - 1.15 and below - if (protocolversion >= MC_1_16_Version) + if (protocolVersion >= MC_1_16_Version) { dataTypes.ReadNextBool(packetData); // Is Debug - 1.16 and above dataTypes.ReadNextBool(packetData); // Is Flat - 1.16 and above dataTypes.ReadNextBool(packetData); // Copy metadata - 1.16 and above } - if (protocolversion >= MC_1_19_Version) + if (protocolVersion >= MC_1_19_Version) { bool hasDeathLocation = dataTypes.ReadNextBool(packetData); // Has death location if (hasDeathLocation) @@ -529,7 +529,7 @@ namespace MinecraftClient.Protocol.Handlers // entity handling require player pos for distance calculating if (handler.GetTerrainEnabled() || handler.GetEntityHandlingEnabled()) { - if (protocolversion >= MC_1_8_Version) + if (protocolVersion >= MC_1_8_Version) { Location location = handler.GetCurrentLocation(); location.X = (locMask & 1 << 0) != 0 ? location.X + x : x; @@ -540,14 +540,14 @@ namespace MinecraftClient.Protocol.Handlers else handler.UpdateLocation(new Location(x, y, z), yaw, pitch); } - if (protocolversion >= MC_1_9_Version) + if (protocolVersion >= MC_1_9_Version) { int teleportID = dataTypes.ReadNextVarInt(packetData); // Teleport confirm packet SendPacket(PacketTypesOut.TeleportConfirm, dataTypes.GetVarInt(teleportID)); } - if (protocolversion >= MC_1_17_Version) + if (protocolVersion >= MC_1_17_Version) dataTypes.ReadNextBool(packetData); // Dismount Vehicle - 1.17 and above break; case PacketTypesIn.ChunkData: @@ -558,16 +558,16 @@ namespace MinecraftClient.Protocol.Handlers int chunkX = dataTypes.ReadNextInt(packetData); int chunkZ = dataTypes.ReadNextInt(packetData); - if (protocolversion >= MC_1_17_Version) + if (protocolVersion >= MC_1_17_Version) { ulong[]? verticalStripBitmask = null; - if (protocolversion == MC_1_17_Version || protocolversion == MC_1_17_1_Version) + if (protocolVersion == MC_1_17_Version || protocolVersion == MC_1_17_1_Version) verticalStripBitmask = dataTypes.ReadNextULongArray(packetData); // Bit Mask Length and Primary Bit Mask dataTypes.ReadNextNbt(packetData); // Heightmaps - if (protocolversion == MC_1_17_Version || protocolversion == MC_1_17_1_Version) + if (protocolVersion == MC_1_17_Version || protocolVersion == MC_1_17_1_Version) { int biomesLength = dataTypes.ReadNextVarInt(packetData); // Biomes length for (int i = 0; i < biomesLength; i++) @@ -585,12 +585,12 @@ namespace MinecraftClient.Protocol.Handlers else { bool chunksContinuous = dataTypes.ReadNextBool(packetData); - if (protocolversion >= MC_1_16_Version && protocolversion <= MC_1_16_1_Version) + if (protocolVersion >= MC_1_16_Version && protocolVersion <= MC_1_16_1_Version) dataTypes.ReadNextBool(packetData); // Ignore old data - 1.16 to 1.16.1 only - ushort chunkMask = protocolversion >= MC_1_9_Version + ushort chunkMask = protocolVersion >= MC_1_9_Version ? (ushort)dataTypes.ReadNextVarInt(packetData) : dataTypes.ReadNextUShort(packetData); - if (protocolversion < MC_1_8_Version) + if (protocolVersion < MC_1_8_Version) { ushort addBitmap = dataTypes.ReadNextUShort(packetData); int compressedDataSize = dataTypes.ReadNextInt(packetData); @@ -602,15 +602,15 @@ namespace MinecraftClient.Protocol.Handlers } else { - if (protocolversion >= MC_1_14_Version) + if (protocolVersion >= MC_1_14_Version) dataTypes.ReadNextNbt(packetData); // Heightmaps - 1.14 and above int biomesLength = 0; - if (protocolversion >= MC_1_16_2_Version) + if (protocolVersion >= MC_1_16_2_Version) if (chunksContinuous) biomesLength = dataTypes.ReadNextVarInt(packetData); // Biomes length - 1.16.2 and above - if (protocolversion >= MC_1_15_Version && chunksContinuous) + if (protocolVersion >= MC_1_15_Version && chunksContinuous) { - if (protocolversion >= MC_1_16_2_Version) + if (protocolVersion >= MC_1_16_2_Version) { for (int i = 0; i < biomesLength; i++) { @@ -632,13 +632,13 @@ namespace MinecraftClient.Protocol.Handlers case PacketTypesIn.MapData: int mapid = dataTypes.ReadNextVarInt(packetData); byte scale = dataTypes.ReadNextByte(packetData); - bool trackingposition = protocolversion >= MC_1_17_Version ? false : dataTypes.ReadNextBool(packetData); + bool trackingposition = protocolVersion >= MC_1_17_Version ? false : dataTypes.ReadNextBool(packetData); bool locked = false; - if (protocolversion >= MC_1_14_Version) + if (protocolVersion >= MC_1_14_Version) { locked = dataTypes.ReadNextBool(packetData); } - if (protocolversion >= MC_1_17_Version) + if (protocolVersion >= MC_1_17_Version) { trackingposition = dataTypes.ReadNextBool(packetData); } @@ -646,7 +646,7 @@ namespace MinecraftClient.Protocol.Handlers handler.OnMapData(mapid, scale, trackingposition, locked, iconcount); break; case PacketTypesIn.TradeList: - if ((protocolversion >= MC_1_14_Version) && (handler.GetInventoryEnabled())) + if ((protocolVersion >= MC_1_14_Version) && (handler.GetInventoryEnabled())) { // MC 1.14 or greater int windowID = dataTypes.ReadNextVarInt(packetData); @@ -668,7 +668,7 @@ namespace MinecraftClient.Protocol.Handlers } break; case PacketTypesIn.Title: - if (protocolversion >= MC_1_8_Version) + if (protocolVersion >= MC_1_8_Version) { int action2 = dataTypes.ReadNextVarInt(packetData); string titletext = String.Empty; @@ -678,7 +678,7 @@ namespace MinecraftClient.Protocol.Handlers int fadein = -1; int stay = -1; int fadeout = -1; - if (protocolversion >= MC_1_10_Version) + if (protocolVersion >= MC_1_10_Version) { if (action2 == 0) { @@ -727,7 +727,7 @@ namespace MinecraftClient.Protocol.Handlers case PacketTypesIn.MultiBlockChange: if (handler.GetTerrainEnabled()) { - if (protocolversion >= MC_1_16_2_Version) + if (protocolVersion >= MC_1_16_2_Version) { long chunkSection = dataTypes.ReadNextLong(packetData); int sectionX = (int)(chunkSection >> 42); @@ -755,7 +755,7 @@ namespace MinecraftClient.Protocol.Handlers { int chunkX = dataTypes.ReadNextInt(packetData); int chunkZ = dataTypes.ReadNextInt(packetData); - int recordCount = protocolversion < MC_1_8_Version + int recordCount = protocolVersion < MC_1_8_Version ? (int)dataTypes.ReadNextShort(packetData) : dataTypes.ReadNextVarInt(packetData); @@ -765,7 +765,7 @@ namespace MinecraftClient.Protocol.Handlers ushort blockIdMeta; int blockY; - if (protocolversion < MC_1_8_Version) + if (protocolVersion < MC_1_8_Version) { blockIdMeta = dataTypes.ReadNextUShort(packetData); blockY = (ushort)dataTypes.ReadNextByte(packetData); @@ -804,7 +804,7 @@ namespace MinecraftClient.Protocol.Handlers case PacketTypesIn.BlockChange: if (handler.GetTerrainEnabled()) { - if (protocolversion < MC_1_8_Version) + if (protocolVersion < MC_1_8_Version) { int blockX = dataTypes.ReadNextInt(packetData); int blockY = dataTypes.ReadNextByte(packetData); @@ -840,14 +840,14 @@ namespace MinecraftClient.Protocol.Handlers break; case PacketTypesIn.MapChunkBulk: - if (protocolversion < MC_1_9_Version && handler.GetTerrainEnabled()) + if (protocolVersion < MC_1_9_Version && handler.GetTerrainEnabled()) { int chunkCount; bool hasSkyLight; Queue chunkData = packetData; //Read global fields - if (protocolversion < MC_1_8_Version) + if (protocolVersion < MC_1_8_Version) { chunkCount = dataTypes.ReadNextShort(packetData); int compressedDataSize = dataTypes.ReadNextInt(packetData); @@ -872,7 +872,7 @@ namespace MinecraftClient.Protocol.Handlers chunkXs[chunkColumnNo] = dataTypes.ReadNextInt(packetData); chunkZs[chunkColumnNo] = dataTypes.ReadNextInt(packetData); chunkMasks[chunkColumnNo] = dataTypes.ReadNextUShort(packetData); - addBitmaps[chunkColumnNo] = protocolversion < MC_1_8_Version + addBitmaps[chunkColumnNo] = protocolVersion < MC_1_8_Version ? dataTypes.ReadNextUShort(packetData) : (ushort)0; } @@ -887,7 +887,7 @@ namespace MinecraftClient.Protocol.Handlers } break; case PacketTypesIn.UnloadChunk: - if (protocolversion >= MC_1_9_Version && handler.GetTerrainEnabled()) + if (protocolVersion >= MC_1_9_Version && handler.GetTerrainEnabled()) { int chunkX = dataTypes.ReadNextInt(packetData); int chunkZ = dataTypes.ReadNextInt(packetData); @@ -902,7 +902,7 @@ namespace MinecraftClient.Protocol.Handlers } break; case PacketTypesIn.PlayerInfo: - if (protocolversion >= MC_1_8_Version) + if (protocolVersion >= MC_1_8_Version) { int action = dataTypes.ReadNextVarInt(packetData); // Action Name int numberOfPlayers = dataTypes.ReadNextVarInt(packetData); // Number Of Players @@ -939,7 +939,7 @@ namespace MinecraftClient.Protocol.Handlers // 1.19 Additions long? keyExpiration = null; byte[]? publicKey = null, signature = null; - if (protocolversion >= MC_1_19_Version) + if (protocolVersion >= MC_1_19_Version) { if (dataTypes.ReadNextBool(packetData)) // Has Sig Data (if true, red the following fields) { @@ -995,7 +995,7 @@ namespace MinecraftClient.Protocol.Handlers } break; case PacketTypesIn.TabComplete: - if (protocolversion >= MC_1_13_Version) + if (protocolVersion >= MC_1_13_Version) { autocomplete_transaction_id = dataTypes.ReadNextVarInt(packetData); dataTypes.ReadNextVarInt(packetData); // Start of text to replace @@ -1008,7 +1008,7 @@ namespace MinecraftClient.Protocol.Handlers for (int i = 0; i < autocomplete_count; i++) { autocomplete_result.Add(dataTypes.ReadNextString(packetData)); - if (protocolversion >= MC_1_13_Version) + if (protocolVersion >= MC_1_13_Version) { // Skip optional tooltip for each tab-complete result if (dataTypes.ReadNextBool(packetData)) @@ -1021,7 +1021,7 @@ namespace MinecraftClient.Protocol.Handlers case PacketTypesIn.PluginMessage: String channel = dataTypes.ReadNextString(packetData); // Length is unneeded as the whole remaining packetData is the entire payload of the packet. - if (protocolversion < MC_1_8_Version) + if (protocolVersion < MC_1_8_Version) pForge.ReadNextVarShort(packetData); handler.OnPluginChannelMessage(channel, packetData.ToArray()); return pForge.HandlePluginMessage(channel, packetData, ref currentDimension); @@ -1029,13 +1029,13 @@ namespace MinecraftClient.Protocol.Handlers handler.OnConnectionLost(ChatBot.DisconnectReason.InGameKick, ChatParser.ParseText(dataTypes.ReadNextString(packetData))); return false; case PacketTypesIn.SetCompression: - if (protocolversion >= MC_1_8_Version && protocolversion < MC_1_9_Version) + if (protocolVersion >= MC_1_8_Version && protocolVersion < MC_1_9_Version) compression_treshold = dataTypes.ReadNextVarInt(packetData); break; case PacketTypesIn.OpenWindow: if (handler.GetInventoryEnabled()) { - if (protocolversion < MC_1_14_Version) + if (protocolVersion < MC_1_14_Version) { // MC 1.13 or lower byte windowID = dataTypes.ReadNextByte(packetData); @@ -1072,7 +1072,7 @@ namespace MinecraftClient.Protocol.Handlers int stateId = -1; int elements = 0; - if (protocolversion >= MC_1_17_1_Version) + if (protocolVersion >= MC_1_17_1_Version) { // State ID and Elements as VarInt - 1.17.1 and above stateId = dataTypes.ReadNextVarInt(packetData); @@ -1092,7 +1092,7 @@ namespace MinecraftClient.Protocol.Handlers inventorySlots[slotId] = item; } - if (protocolversion >= MC_1_17_1_Version) // Carried Item - 1.17.1 and above + if (protocolVersion >= MC_1_17_1_Version) // Carried Item - 1.17.1 and above dataTypes.ReadNextItemSlot(packetData, itemPalette); handler.OnWindowItems(windowId, inventorySlots, stateId); @@ -1103,7 +1103,7 @@ namespace MinecraftClient.Protocol.Handlers { byte windowID = dataTypes.ReadNextByte(packetData); int stateId = -1; - if (protocolversion >= MC_1_17_1_Version) + if (protocolVersion >= MC_1_17_1_Version) stateId = dataTypes.ReadNextVarInt(packetData); // State ID - 1.17.1 and above short slotID = dataTypes.ReadNextShort(packetData); Item item = dataTypes.ReadNextItemSlot(packetData, itemPalette); @@ -1126,7 +1126,7 @@ namespace MinecraftClient.Protocol.Handlers string url = dataTypes.ReadNextString(packetData); string hash = dataTypes.ReadNextString(packetData); bool forced = true; // Assume forced for MC 1.16 and below - if (protocolversion >= MC_1_17_Version) + if (protocolVersion >= MC_1_17_Version) { forced = dataTypes.ReadNextBool(packetData); string forcedMessage = ChatParser.ParseText(dataTypes.ReadNextString(packetData)); @@ -1139,7 +1139,7 @@ namespace MinecraftClient.Protocol.Handlers break; //Send back "accepted" and "successfully loaded" responses for plugins or server config making use of resource pack mandatory byte[] responseHeader = new byte[0]; - if (protocolversion < MC_1_10_Version) //MC 1.10 does not include resource pack hash in responses + if (protocolVersion < MC_1_10_Version) //MC 1.10 does not include resource pack hash in responses responseHeader = dataTypes.ConcatBytes(dataTypes.GetVarInt(hash.Length), Encoding.UTF8.GetBytes(hash)); SendPacket(PacketTypesOut.ResourcePackStatus, dataTypes.ConcatBytes(responseHeader, dataTypes.GetVarInt(3))); //Accepted pack SendPacket(PacketTypesOut.ResourcePackStatus, dataTypes.ConcatBytes(responseHeader, dataTypes.GetVarInt(0))); //Successfully loaded @@ -1155,7 +1155,7 @@ namespace MinecraftClient.Protocol.Handlers if (handler.GetEntityHandlingEnabled()) { int entityid = dataTypes.ReadNextVarInt(packetData); - if (protocolversion >= MC_1_16_Version) + if (protocolVersion >= MC_1_16_Version) { bool hasNext; do @@ -1216,7 +1216,7 @@ namespace MinecraftClient.Protocol.Handlers bool hasFactorData = false; Dictionary? factorCodec = null; - if (protocolversion >= MC_1_19_Version) + if (protocolVersion >= MC_1_19_Version) { hasFactorData = dataTypes.ReadNextBool(packetData); factorCodec = dataTypes.ReadNextNbt(packetData); @@ -1230,7 +1230,7 @@ namespace MinecraftClient.Protocol.Handlers if (handler.GetEntityHandlingEnabled()) { int entityCount = 1; // 1.17.0 has only one entity per packet - if (protocolversion != MC_1_17_Version) + if (protocolVersion != MC_1_17_Version) entityCount = dataTypes.ReadNextVarInt(packetData); // All other versions have a "count" field int[] entityList = new int[entityCount]; for (int i = 0; i < entityCount; i++) @@ -1274,7 +1274,7 @@ namespace MinecraftClient.Protocol.Handlers if (handler.GetEntityHandlingEnabled()) { int EntityID = dataTypes.ReadNextVarInt(packetData); - int NumberOfProperties = protocolversion >= MC_1_17_Version ? dataTypes.ReadNextVarInt(packetData) : dataTypes.ReadNextInt(packetData); + int NumberOfProperties = protocolVersion >= MC_1_17_Version ? dataTypes.ReadNextVarInt(packetData) : dataTypes.ReadNextInt(packetData); Dictionary keys = new Dictionary(); for (int i = 0; i < NumberOfProperties; i++) { @@ -1313,11 +1313,11 @@ namespace MinecraftClient.Protocol.Handlers // See https://wiki.vg/Entity_metadata#Living_Entity int healthField = 7; // From 1.10 to 1.13.2 - if (protocolversion >= MC_1_14_Version) + if (protocolVersion >= MC_1_14_Version) healthField = 8; // 1.14 and above - if (protocolversion >= MC_1_17_Version) + if (protocolVersion >= MC_1_17_Version) healthField = 9; // 1.17 and above - if (protocolversion > MC_1_18_2_Version) + if (protocolVersion > MC_1_18_2_Version) throw new NotImplementedException(Translations.Get("exception.palette.healthfield")); if (metadata.ContainsKey(healthField) && metadata[healthField] != null && metadata[healthField].GetType() == typeof(float)) @@ -1361,7 +1361,7 @@ namespace MinecraftClient.Protocol.Handlers case PacketTypesIn.UpdateHealth: float health = dataTypes.ReadNextFloat(packetData); int food; - if (protocolversion >= MC_1_8_Version) + if (protocolVersion >= MC_1_8_Version) food = dataTypes.ReadNextVarInt(packetData); else food = dataTypes.ReadNextShort(packetData); @@ -1376,12 +1376,12 @@ namespace MinecraftClient.Protocol.Handlers break; case PacketTypesIn.Explosion: Location explosionLocation; - if (protocolversion >= MC_1_19_Version) + if (protocolVersion >= MC_1_19_Version) explosionLocation = new(dataTypes.ReadNextDouble(packetData), dataTypes.ReadNextDouble(packetData), dataTypes.ReadNextDouble(packetData)); else explosionLocation = new(dataTypes.ReadNextFloat(packetData), dataTypes.ReadNextFloat(packetData), dataTypes.ReadNextFloat(packetData)); float explosionStrength = dataTypes.ReadNextFloat(packetData); - int explosionBlockCount = protocolversion >= MC_1_17_Version + int explosionBlockCount = protocolVersion >= MC_1_17_Version ? dataTypes.ReadNextVarInt(packetData) : dataTypes.ReadNextInt(packetData); // Ignoring additional fields (records, pushback) @@ -1405,12 +1405,12 @@ namespace MinecraftClient.Protocol.Handlers break; case PacketTypesIn.UpdateScore: string entityname = dataTypes.ReadNextString(packetData); - int action3 = protocolversion >= MC_1_18_2_Version + int action3 = protocolVersion >= MC_1_18_2_Version ? dataTypes.ReadNextVarInt(packetData) : dataTypes.ReadNextByte(packetData); string objectivename2 = string.Empty; int value = -1; - if (action3 != 1 || protocolversion >= MC_1_8_Version) + if (action3 != 1 || protocolVersion >= MC_1_8_Version) objectivename2 = dataTypes.ReadNextString(packetData); if (action3 != 1) value = dataTypes.ReadNextVarInt(packetData); @@ -1449,7 +1449,7 @@ namespace MinecraftClient.Protocol.Handlers Translations.Get("exception.packet_process", packetPalette.GetIncommingTypeById(packetID), packetID, - protocolversion, + protocolVersion, login_phase, innerException.GetType()), innerException); @@ -1551,7 +1551,7 @@ namespace MinecraftClient.Protocol.Handlers /// True if login successful public bool Login(PlayerKeyPair? playerKeyPair, SessionToken session) { - byte[] protocol_version = dataTypes.GetVarInt(protocolversion); + byte[] protocol_version = dataTypes.GetVarInt(protocolVersion); string server_address = pForge.GetServerAddress(handler.GetServerHost()); byte[] server_port = dataTypes.GetUShort((ushort)handler.GetServerPort()); byte[] next_state = dataTypes.GetVarInt(2); @@ -1560,7 +1560,7 @@ namespace MinecraftClient.Protocol.Handlers List fullLoginPacket = new List(); fullLoginPacket.AddRange(dataTypes.GetString(handler.GetUsername())); // Username - if (protocolversion >= MC_1_19_Version) + if (protocolVersion >= MC_1_19_Version) { if (playerKeyPair == null) fullLoginPacket.AddRange(dataTypes.GetBool(false)); // Has Sig Data @@ -1651,7 +1651,7 @@ namespace MinecraftClient.Protocol.Handlers // Encryption Response packet List encryptionResponse = new(); encryptionResponse.AddRange(dataTypes.GetArray(RSAService.Encrypt(secretKey, false))); // Shared Secret - if (protocolversion >= Protocol18Handler.MC_1_19_Version) + if (protocolVersion >= Protocol18Handler.MC_1_19_Version) { if (playerKeyPair == null) { @@ -1675,7 +1675,7 @@ namespace MinecraftClient.Protocol.Handlers SendPacket(0x01, encryptionResponse); //Start client-side encryption - socketWrapper.SwitchToEncrypted(secretKey); + socketWrapper.SwitchToEncrypted(secretKey); // pre switch //Process the next packet int loopPrevention = UInt16.MaxValue; @@ -1697,7 +1697,7 @@ namespace MinecraftClient.Protocol.Handlers Guid uuidReceived = dataTypes.ReadNextUUID(packetData); string userName = dataTypes.ReadNextString(packetData); Tuple[]? playerProperty = null; - if (protocolversion >= Protocol18Handler.MC_1_19_Version) + if (protocolVersion >= Protocol18Handler.MC_1_19_Version) { int count = dataTypes.ReadNextVarInt(packetData); // Number Of Properties playerProperty = new Tuple[count]; @@ -1752,9 +1752,9 @@ namespace MinecraftClient.Protocol.Handlers byte[] tabcomplete_packet = new byte[] { }; - if (protocolversion >= MC_1_8_Version) + if (protocolVersion >= MC_1_8_Version) { - if (protocolversion >= MC_1_13_Version) + if (protocolVersion >= MC_1_13_Version) { tabcomplete_packet = dataTypes.ConcatBytes(tabcomplete_packet, transaction_id); tabcomplete_packet = dataTypes.ConcatBytes(tabcomplete_packet, dataTypes.GetString(BehindCursor)); @@ -1763,7 +1763,7 @@ namespace MinecraftClient.Protocol.Handlers { tabcomplete_packet = dataTypes.ConcatBytes(tabcomplete_packet, dataTypes.GetString(BehindCursor)); - if (protocolversion >= MC_1_9_Version) + if (protocolVersion >= MC_1_9_Version) { tabcomplete_packet = dataTypes.ConcatBytes(tabcomplete_packet, assume_command); } @@ -1869,7 +1869,7 @@ namespace MinecraftClient.Protocol.Handlers /// Max length, in characters public int GetMaxChatMessageLength() { - return protocolversion > MC_1_10_Version + return protocolVersion > MC_1_10_Version ? 256 : 100; } @@ -1883,7 +1883,7 @@ namespace MinecraftClient.Protocol.Handlers /// Minecraft Protocol version number public int GetProtocolVersion() { - return protocolversion; + return protocolVersion; } @@ -2004,7 +2004,7 @@ namespace MinecraftClient.Protocol.Handlers return true; // Process Chat Command - 1.19 and above - if (protocolversion >= MC_1_19_Version && message.StartsWith('/')) + if (protocolVersion >= MC_1_19_Version && message.StartsWith('/')) return SendChatCommand(message[1..], playerKeyPair); try @@ -2014,7 +2014,7 @@ namespace MinecraftClient.Protocol.Handlers // Message: String (up to 256 chars) fields.AddRange(dataTypes.GetString(message)); - if (protocolversion >= MC_1_19_Version) + if (protocolVersion >= MC_1_19_Version) { // Timestamp: Instant(Long) DateTimeOffset timeNow = DateTimeOffset.UtcNow; @@ -2092,7 +2092,7 @@ namespace MinecraftClient.Protocol.Handlers return false; // Plugin channels were significantly changed between Minecraft 1.12 and 1.13 // https://wiki.vg/index.php?title=Pre-release_protocol&oldid=14132#Plugin_Channels - if (protocolversion >= MC_1_13_Version) + if (protocolVersion >= MC_1_13_Version) { return SendPluginChannelPacket("minecraft:brand", dataTypes.GetString(brandInfo)); } @@ -2120,26 +2120,26 @@ namespace MinecraftClient.Protocol.Handlers List fields = new List(); fields.AddRange(dataTypes.GetString(language)); fields.Add(viewDistance); - fields.AddRange(protocolversion >= MC_1_9_Version + fields.AddRange(protocolVersion >= MC_1_9_Version ? dataTypes.GetVarInt(chatMode) : new byte[] { chatMode }); fields.Add(chatColors ? (byte)1 : (byte)0); - if (protocolversion < MC_1_8_Version) + if (protocolVersion < MC_1_8_Version) { fields.Add(difficulty); fields.Add((byte)(skinParts & 0x1)); //show cape } else fields.Add(skinParts); - if (protocolversion >= MC_1_9_Version) + if (protocolVersion >= MC_1_9_Version) fields.AddRange(dataTypes.GetVarInt(mainHand)); - if (protocolversion >= MC_1_17_Version) + if (protocolVersion >= MC_1_17_Version) { - if (protocolversion >= MC_1_18_1_Version) + if (protocolVersion >= MC_1_18_1_Version) fields.Add(0); // 1.18 and above - Enable text filtering. (Always false) else fields.Add(1); // 1.17 and 1.17.1 - Disable text filtering. (Always true) } - if (protocolversion >= MC_1_18_1_Version) + if (protocolVersion >= MC_1_18_1_Version) fields.Add(1); // 1.18 and above - Allow server listings SendPacket(PacketTypesOut.ClientSettings, fields); } @@ -2175,7 +2175,7 @@ namespace MinecraftClient.Protocol.Handlers SendPacket(packetType, dataTypes.ConcatBytes( dataTypes.GetDouble(location.X), dataTypes.GetDouble(location.Y), - protocolversion < MC_1_8_Version + protocolVersion < MC_1_8_Version ? dataTypes.GetDouble(location.Y + 1.62) : new byte[0], dataTypes.GetDouble(location.Z), @@ -2201,7 +2201,7 @@ namespace MinecraftClient.Protocol.Handlers { // In 1.7, length needs to be included. // In 1.8, it must not be. - if (protocolversion < MC_1_8_Version) + if (protocolVersion < MC_1_8_Version) { byte[] length = BitConverter.GetBytes((short)data.Length); Array.Reverse(length); @@ -2256,7 +2256,7 @@ namespace MinecraftClient.Protocol.Handlers // Is player Sneaking (Only 1.16 and above) // Currently hardcoded to false // TODO: Update to reflect the real player state - if (protocolversion >= MC_1_16_Version) + if (protocolVersion >= MC_1_16_Version) fields.AddRange(dataTypes.GetBool(false)); SendPacket(PacketTypesOut.InteractEntity, fields); @@ -2282,7 +2282,7 @@ namespace MinecraftClient.Protocol.Handlers // Is player Sneaking (Only 1.16 and above) // Currently hardcoded to false // TODO: Update to reflect the real player state - if (protocolversion >= MC_1_16_Version) + if (protocolVersion >= MC_1_16_Version) fields.AddRange(dataTypes.GetBool(false)); SendPacket(PacketTypesOut.InteractEntity, fields); return true; @@ -2302,7 +2302,7 @@ namespace MinecraftClient.Protocol.Handlers // Is player Sneaking (Only 1.16 and above) // Currently hardcoded to false // TODO: Update to reflect the real player state - if (protocolversion >= MC_1_16_Version) + if (protocolVersion >= MC_1_16_Version) fields.AddRange(dataTypes.GetBool(false)); SendPacket(PacketTypesOut.InteractEntity, fields); return true; @@ -2318,7 +2318,7 @@ namespace MinecraftClient.Protocol.Handlers public bool SendUseItem(int hand, int sequenceId) { - if (protocolversion < MC_1_9_Version) + if (protocolVersion < MC_1_9_Version) return false; // Packet does not exist prior to MC 1.9 // According to https://wiki.vg/index.php?title=Protocol&oldid=5486#Player_Block_Placement // MC 1.7 does this using Player Block Placement with special values @@ -2327,7 +2327,7 @@ namespace MinecraftClient.Protocol.Handlers { List packet = new List(); packet.AddRange(dataTypes.GetVarInt(hand)); - if (protocolversion >= MC_1_19_Version) + if (protocolVersion >= MC_1_19_Version) packet.AddRange(dataTypes.GetVarInt(sequenceId)); SendPacket(PacketTypesOut.UseItem, packet); return true; @@ -2345,7 +2345,7 @@ namespace MinecraftClient.Protocol.Handlers packet.AddRange(dataTypes.GetVarInt(status)); packet.AddRange(dataTypes.GetLocation(location)); packet.AddRange(dataTypes.GetVarInt(dataTypes.GetBlockFace(face))); - if (protocolversion >= MC_1_19_Version) + if (protocolVersion >= MC_1_19_Version) packet.AddRange(dataTypes.GetVarInt(sequenceId)); SendPacket(PacketTypesOut.PlayerDigging, packet); return true; @@ -2357,7 +2357,7 @@ namespace MinecraftClient.Protocol.Handlers public bool SendPlayerBlockPlacement(int hand, Location location, Direction face, int sequenceId) { - if (protocolversion < MC_1_14_Version) + if (protocolVersion < MC_1_14_Version) return false; // NOT IMPLEMENTED for older MC versions try { @@ -2369,7 +2369,7 @@ namespace MinecraftClient.Protocol.Handlers packet.AddRange(dataTypes.GetFloat(0.5f)); // cursorY packet.AddRange(dataTypes.GetFloat(0.5f)); // cursorZ packet.Add(0); // insideBlock = false; - if (protocolversion >= MC_1_19_Version) + if (protocolVersion >= MC_1_19_Version) packet.AddRange(dataTypes.GetVarInt(sequenceId)); SendPacket(PacketTypesOut.PlayerBlockPlacement, packet); return true; @@ -2432,13 +2432,13 @@ namespace MinecraftClient.Protocol.Handlers packet.Add((byte)windowId); // Window ID // 1.18+ - if (protocolversion >= MC_1_18_1_Version) + if (protocolVersion >= MC_1_18_1_Version) { packet.AddRange(dataTypes.GetVarInt(stateId)); // State ID packet.AddRange(dataTypes.GetShort((short)slotId)); // Slot ID } // 1.17.1 - else if (protocolversion == MC_1_17_1_Version) + else if (protocolVersion == MC_1_17_1_Version) { packet.AddRange(dataTypes.GetShort((short)slotId)); // Slot ID packet.AddRange(dataTypes.GetVarInt(stateId)); // State ID @@ -2451,15 +2451,15 @@ namespace MinecraftClient.Protocol.Handlers packet.Add(button); // Button - if (protocolversion < MC_1_17_Version) + if (protocolVersion < MC_1_17_Version) packet.AddRange(dataTypes.GetShort(actionNumber)); - if (protocolversion >= MC_1_9_Version) + if (protocolVersion >= MC_1_9_Version) packet.AddRange(dataTypes.GetVarInt(mode)); // Mode else packet.Add(mode); // 1.17+ Array of changed slots - if (protocolversion >= MC_1_17_Version) + if (protocolVersion >= MC_1_17_Version) { packet.AddRange(dataTypes.GetVarInt(changedSlots.Count)); // Length of the array foreach (var slot in changedSlots) @@ -2502,12 +2502,12 @@ namespace MinecraftClient.Protocol.Handlers { List packet = new List(); - if (protocolversion < MC_1_8_Version) + if (protocolVersion < MC_1_8_Version) { packet.AddRange(dataTypes.GetInt(playerid)); packet.Add((byte)1); // Swing arm } - else if (protocolversion < MC_1_9_Version) + else if (protocolVersion < MC_1_9_Version) { // No fields in 1.8.X } @@ -2575,7 +2575,7 @@ namespace MinecraftClient.Protocol.Handlers public bool UpdateCommandBlock(Location location, string command, CommandBlockMode mode, CommandBlockFlags flags) { - if (protocolversion <= MC_1_13_Version) + if (protocolVersion <= MC_1_13_Version) { try { @@ -2613,7 +2613,7 @@ namespace MinecraftClient.Protocol.Handlers public bool SelectTrade(int selectedSlot) { // MC 1.13 or greater - if (protocolversion >= MC_1_13_Version) + if (protocolVersion >= MC_1_13_Version) { try { @@ -2632,7 +2632,7 @@ namespace MinecraftClient.Protocol.Handlers public bool SendSpectate(Guid UUID) { // MC 1.8 or greater - if (protocolversion >= MC_1_8_Version) + if (protocolVersion >= MC_1_8_Version) { try {