Update DeclareCommands for 1.19.3

This commit is contained in:
BruceChen 2023-01-14 20:43:32 +08:00
parent ba0d9ba3fc
commit d4b3c42d8c
4 changed files with 50 additions and 28 deletions

View file

@ -8,7 +8,7 @@ namespace MinecraftClient.Protocol.Handlers.packet.s2c
private static int RootIdx; private static int RootIdx;
private static CommandNode[] Nodes = Array.Empty<CommandNode>(); private static CommandNode[] Nodes = Array.Empty<CommandNode>();
public static void Read(DataTypes dataTypes, Queue<byte> packetData) public static void Read(DataTypes dataTypes, Queue<byte> packetData, int protocolVersion)
{ {
int count = dataTypes.ReadNextVarInt(packetData); int count = dataTypes.ReadNextVarInt(packetData);
Nodes = new CommandNode[count]; Nodes = new CommandNode[count];
@ -21,7 +21,7 @@ namespace MinecraftClient.Protocol.Handlers.packet.s2c
for (int j = 0; j < childCount; ++j) for (int j = 0; j < childCount; ++j)
childs[j] = dataTypes.ReadNextVarInt(packetData); childs[j] = dataTypes.ReadNextVarInt(packetData);
int redirectNode = ((flags & 0x08) > 0) ? dataTypes.ReadNextVarInt(packetData) : -1; int redirectNode = ((flags & 0x08) == 0x08) ? dataTypes.ReadNextVarInt(packetData) : -1;
string? name = ((flags & 0x03) == 1 || (flags & 0x03) == 2) ? dataTypes.ReadNextString(packetData) : null; string? name = ((flags & 0x03) == 1 || (flags & 0x03) == 2) ? dataTypes.ReadNextString(packetData) : null;
@ -29,28 +29,51 @@ namespace MinecraftClient.Protocol.Handlers.packet.s2c
Paser? paser = null; Paser? paser = null;
if ((flags & 0x03) == 2) if ((flags & 0x03) == 2)
{ {
paser = paserId switch if (protocolVersion <= Protocol18Handler.MC_1_19_2_Version)
{ paser = paserId switch
1 => new PaserFloat(dataTypes, packetData), {
2 => new PaserDouble(dataTypes, packetData), 1 => new PaserFloat(dataTypes, packetData),
3 => new PaserInteger(dataTypes, packetData), 2 => new PaserDouble(dataTypes, packetData),
4 => new PaserLong(dataTypes, packetData), 3 => new PaserInteger(dataTypes, packetData),
5 => new PaserString(dataTypes, packetData), 4 => new PaserLong(dataTypes, packetData),
6 => new PaserEntity(dataTypes, packetData), 5 => new PaserString(dataTypes, packetData),
8 => new PaserBlockPos(dataTypes, packetData), 6 => new PaserEntity(dataTypes, packetData),
9 => new PaserColumnPos(dataTypes, packetData), 8 => new PaserBlockPos(dataTypes, packetData),
10 => new PaserVec3(dataTypes, packetData), 9 => new PaserColumnPos(dataTypes, packetData),
11 => new PaserVec2(dataTypes, packetData), 10 => new PaserVec3(dataTypes, packetData),
18 => new PaserMessage(dataTypes, packetData), 11 => new PaserVec2(dataTypes, packetData),
27 => new PaserRotation(dataTypes, packetData), 18 => new PaserMessage(dataTypes, packetData),
29 => new PaserScoreHolder(dataTypes, packetData), 27 => new PaserRotation(dataTypes, packetData),
43 => new PaserResourceOrTag(dataTypes, packetData), 29 => new PaserScoreHolder(dataTypes, packetData),
44 => new PaserResource(dataTypes, packetData), 43 => new PaserResourceOrTag(dataTypes, packetData),
_ => new PaserEmpty(dataTypes, packetData), 44 => new PaserResource(dataTypes, packetData),
}; _ => new PaserEmpty(dataTypes, packetData),
};
else // protocolVersion >= MC_1_19_3_Version
paser = paserId switch
{
1 => new PaserFloat(dataTypes, packetData),
2 => new PaserDouble(dataTypes, packetData),
3 => new PaserInteger(dataTypes, packetData),
4 => new PaserLong(dataTypes, packetData),
5 => new PaserString(dataTypes, packetData),
6 => new PaserEntity(dataTypes, packetData),
8 => new PaserBlockPos(dataTypes, packetData),
9 => new PaserColumnPos(dataTypes, packetData),
10 => new PaserVec3(dataTypes, packetData),
11 => new PaserVec2(dataTypes, packetData),
18 => new PaserMessage(dataTypes, packetData),
27 => new PaserRotation(dataTypes, packetData),
29 => new PaserScoreHolder(dataTypes, packetData),
41 => new PaserResourceOrTag(dataTypes, packetData),
42 => new PaserResourceOrTag(dataTypes, packetData),
43 => new PaserResource(dataTypes, packetData),
44 => new PaserResource(dataTypes, packetData),
_ => new PaserEmpty(dataTypes, packetData),
};
} }
string? suggestionsType = ((flags & 0x10) > 0) ? dataTypes.ReadNextString(packetData) : null; string? suggestionsType = ((flags & 0x10) == 0x10) ? dataTypes.ReadNextString(packetData) : null;
Nodes[i] = new(flags, childs, redirectNode, name, paser, suggestionsType); Nodes[i] = new(flags, childs, redirectNode, name, paser, suggestionsType);
} }

View file

@ -459,7 +459,7 @@ namespace MinecraftClient.Protocol.Handlers
break; break;
case PacketTypesIn.DeclareCommands: case PacketTypesIn.DeclareCommands:
if (protocolVersion >= MC_1_19_Version) if (protocolVersion >= MC_1_19_Version)
DeclareCommands.Read(dataTypes, packetData); DeclareCommands.Read(dataTypes, packetData, protocolVersion);
break; break;
case PacketTypesIn.ChatMessage: case PacketTypesIn.ChatMessage:
int messageType = 0; int messageType = 0;
@ -1997,9 +1997,9 @@ namespace MinecraftClient.Protocol.Handlers
innerException); innerException);
} }
#else #else
catch (SocketException) { } catch (SocketException) { throw; }
catch (ThreadAbortException) { } catch (ThreadAbortException) { throw; }
catch (ObjectDisposedException) { } catch (ObjectDisposedException) { throw; }
#endif #endif
} }

View file

@ -3,8 +3,8 @@ using System.Collections.Generic;
using MinecraftClient.Inventory; using MinecraftClient.Inventory;
using MinecraftClient.Logger; using MinecraftClient.Logger;
using MinecraftClient.Mapping; using MinecraftClient.Mapping;
using MinecraftClient.Protocol.Keys;
using MinecraftClient.Protocol.Message; using MinecraftClient.Protocol.Message;
using MinecraftClient.Protocol.ProfileKey;
using MinecraftClient.Scripting; using MinecraftClient.Scripting;
namespace MinecraftClient.Protocol namespace MinecraftClient.Protocol

View file

@ -4,7 +4,6 @@ using System.Data.SqlTypes;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using MinecraftClient.Protocol.Handlers; using MinecraftClient.Protocol.Handlers;
using MinecraftClient.Protocol.Keys;
using MinecraftClient.Protocol.Message; using MinecraftClient.Protocol.Message;
using MinecraftClient.Protocol.ProfileKey; using MinecraftClient.Protocol.ProfileKey;