Merge branch 'MCCTeam:master' into forge-cmds

This commit is contained in:
oldkingOK 2024-03-10 08:07:01 +08:00 committed by GitHub
commit 79910b50f7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
28 changed files with 10032 additions and 5418 deletions

View file

@ -9,6 +9,7 @@ public enum ConfigurationPacketTypesIn
Ping,
RegistryData,
ResourcePack,
RemoveResourcePack,
FeatureFlags,
UpdateTags,

View file

@ -6,6 +6,7 @@ using MinecraftClient.Inventory;
using MinecraftClient.Inventory.ItemPalettes;
using MinecraftClient.Mapping;
using MinecraftClient.Mapping.EntityPalettes;
using MinecraftClient.Protocol.Message;
namespace MinecraftClient.Protocol.Handlers
{
@ -560,19 +561,38 @@ namespace MinecraftClient.Protocol.Handlers
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)
var nextId = cache.Dequeue();
if (protocolversion < Protocol18Handler.MC_1_20_2_Version)
{
if (nextId is not 10) // TAG_Compound
throw new System.IO.InvalidDataException("Failed to decode NBT: Does not start with TAG_Compound");
// NBT root name
var rootName = Encoding.ASCII.GetString(ReadData(ReadNextUShort(cache), cache));
if (!string.IsNullOrEmpty(rootName))
nbtData[""] = rootName;
}
// In 1.20.2 The root TAG_Compound doesn't have a name
// In 1.20.3+ The root can be TAG_Compound or TAG_String
else
{
if (nextId is not (10 or 8)) // TAG_Compound or TAG_String
throw new System.IO.InvalidDataException("Failed to decode NBT: Does not start with TAG_Compound or TAG_String");
// Read TAG_String
if(nextId is 8)
{
var byteArrayLength = ReadNextUShort(cache);
var result = Encoding.UTF8.GetString(ReadData(byteArrayLength, cache));
return new Dictionary<string, object>()
{
{ "", result }
};
}
}
}
while (true)
@ -666,7 +686,6 @@ namespace MinecraftClient.Protocol.Handlers
? key >> 5 // 1.8
: ReadNextVarInt(cache); // 1.9+
EntityMetaDataType type;
try
{
@ -716,11 +735,11 @@ namespace MinecraftClient.Protocol.Handlers
value = ReadNextString(cache);
break;
case EntityMetaDataType.Chat: // Chat
value = ReadNextString(cache);
value = ReadNextChat(cache);
break;
case EntityMetaDataType.OptionalChat: // Optional Chat
if (ReadNextBool(cache))
value = ReadNextString(cache);
value = ReadNextChat(cache);
break;
case EntityMetaDataType.Slot: // Slot
value = ReadNextItemSlot(cache, itemPalette);
@ -844,21 +863,21 @@ namespace MinecraftClient.Protocol.Handlers
/// </summary>
/// <param name="cache"></param>
/// <param name="itemPalette"></param>
protected void ReadParticleData(Queue<byte> cache, ItemPalette itemPalette)
public void ReadParticleData(Queue<byte> cache, ItemPalette itemPalette)
{
if (protocolversion < Protocol18Handler.MC_1_13_Version)
return;
int ParticleID = ReadNextVarInt(cache);
var particleId = ReadNextVarInt(cache);
// Refernece:
// 1.19.3 - https://wiki.vg/index.php?title=Data_types&oldid=17986
// Documentation:
// 1.19.3+ - https://wiki.vg/index.php?title=Data_types&oldid=17986
// 1.18 - https://wiki.vg/index.php?title=Data_types&oldid=17180
// 1.17 - https://wiki.vg/index.php?title=Data_types&oldid=16740
// 1.15 - https://wiki.vg/index.php?title=Data_types&oldid=15338
// 1.13 - https://wiki.vg/index.php?title=Data_types&oldid=14271
switch (ParticleID)
switch (particleId)
{
case 2:
// 1.18 +
@ -866,14 +885,12 @@ namespace MinecraftClient.Protocol.Handlers
ReadNextVarInt(cache); // Block state (minecraft:block)
break;
case 3:
if (protocolversion < Protocol18Handler.MC_1_17_Version
|| protocolversion > Protocol18Handler.MC_1_17_1_Version)
if (protocolversion is < Protocol18Handler.MC_1_17_Version or > Protocol18Handler.MC_1_17_1_Version)
ReadNextVarInt(
cache); // Block State (minecraft:block before 1.18, minecraft:block_marker after 1.18)
break;
case 4:
if (protocolversion == Protocol18Handler.MC_1_17_Version
|| protocolversion == Protocol18Handler.MC_1_17_1_Version)
if (protocolversion is Protocol18Handler.MC_1_17_Version or Protocol18Handler.MC_1_17_1_Version)
ReadNextVarInt(cache); // Block State (minecraft:block)
break;
case 11:
@ -883,44 +900,38 @@ namespace MinecraftClient.Protocol.Handlers
break;
case 14:
// 1.15 - 1.16.5 and 1.18 - 1.19.4
if ((protocolversion >= Protocol18Handler.MC_1_15_Version &&
protocolversion < Protocol18Handler.MC_1_17_Version)
|| protocolversion > Protocol18Handler.MC_1_17_1_Version)
if (protocolversion is >= Protocol18Handler.MC_1_15_Version and < Protocol18Handler.MC_1_17_Version or > Protocol18Handler.MC_1_17_1_Version)
ReadDustParticle(cache);
break;
case 15:
if (protocolversion == Protocol18Handler.MC_1_17_Version ||
protocolversion == Protocol18Handler.MC_1_17_1_Version)
ReadDustParticle(cache);
else
switch (protocolversion)
{
if (protocolversion > Protocol18Handler.MC_1_17_1_Version)
case Protocol18Handler.MC_1_17_Version or Protocol18Handler.MC_1_17_1_Version:
ReadDustParticle(cache);
break;
case > Protocol18Handler.MC_1_17_1_Version:
ReadDustParticleColorTransition(cache);
break;
}
break;
case 16:
if (protocolversion == Protocol18Handler.MC_1_17_Version ||
protocolversion == Protocol18Handler.MC_1_17_1_Version)
if (protocolversion is Protocol18Handler.MC_1_17_Version or Protocol18Handler.MC_1_17_1_Version)
ReadDustParticleColorTransition(cache);
break;
case 23:
// 1.15 - 1.16.5
if (protocolversion >= Protocol18Handler.MC_1_15_Version &&
protocolversion < Protocol18Handler.MC_1_17_Version)
if (protocolversion is >= Protocol18Handler.MC_1_15_Version and < Protocol18Handler.MC_1_17_Version)
ReadNextVarInt(cache); // Block State (minecraft:falling_dust)
break;
case 24:
// 1.18 - 1.19.2 onwards
if (protocolversion > Protocol18Handler.MC_1_17_1_Version &&
protocolversion < Protocol18Handler.MC_1_19_3_Version)
if (protocolversion is > Protocol18Handler.MC_1_17_1_Version and < Protocol18Handler.MC_1_19_3_Version)
ReadNextVarInt(cache); // Block State (minecraft:falling_dust)
break;
case 25:
// 1.17 - 1.17.1 and 1.19.3 onwards
if (protocolversion == Protocol18Handler.MC_1_17_Version
|| protocolversion == Protocol18Handler.MC_1_17_1_Version
|| protocolversion >= Protocol18Handler.MC_1_19_3_Version)
if (protocolversion is Protocol18Handler.MC_1_17_Version or Protocol18Handler.MC_1_17_1_Version or >= Protocol18Handler.MC_1_19_3_Version)
ReadNextVarInt(cache); // Block State (minecraft:falling_dust)
break;
case 27:
@ -934,31 +945,28 @@ namespace MinecraftClient.Protocol.Handlers
break;
case 32:
// 1.15 - 1.16.5
if (protocolversion >= Protocol18Handler.MC_1_15_Version &&
protocolversion < Protocol18Handler.MC_1_17_Version)
if (protocolversion is >= Protocol18Handler.MC_1_15_Version and < Protocol18Handler.MC_1_17_Version)
ReadNextItemSlot(cache, itemPalette); // Item (minecraft:item)
break;
case 36:
// 1.17 - 1.17.1
if (protocolversion == Protocol18Handler.MC_1_17_Version ||
protocolversion == Protocol18Handler.MC_1_17_1_Version)
switch (protocolversion)
{
ReadNextItemSlot(cache, itemPalette); // Item (minecraft:item)
}
else if (protocolversion > Protocol18Handler.MC_1_17_1_Version &&
protocolversion < Protocol18Handler.MC_1_19_3_Version)
{
// minecraft:vibration
ReadNextLocation(cache); // Origin (Starting Position)
ReadNextLocation(cache); // Desitination (Ending Position)
ReadNextVarInt(cache); // Ticks
// 1.17 - 1.17.1
case Protocol18Handler.MC_1_17_Version or Protocol18Handler.MC_1_17_1_Version:
ReadNextItemSlot(cache, itemPalette); // Item (minecraft:item)
break;
case > Protocol18Handler.MC_1_17_1_Version and < Protocol18Handler.MC_1_19_3_Version:
// minecraft:vibration
ReadNextLocation(cache); // Origin (Starting Position)
ReadNextLocation(cache); // Destination (Ending Position)
ReadNextVarInt(cache); // Ticks
break;
}
break;
case 37:
// minecraft:vibration
if (protocolversion == Protocol18Handler.MC_1_17_Version
|| protocolversion == Protocol18Handler.MC_1_17_1_Version)
if (protocolversion is Protocol18Handler.MC_1_17_Version or Protocol18Handler.MC_1_17_1_Version)
{
ReadNextDouble(cache); // Origin X
ReadNextDouble(cache); // Origin Y
@ -977,15 +985,16 @@ namespace MinecraftClient.Protocol.Handlers
case 40:
if (protocolversion >= Protocol18Handler.MC_1_19_3_Version)
{
string positionSourceType = ReadNextString(cache);
if (positionSourceType == "minecraft:block")
var positionSourceType = ReadNextString(cache);
switch (positionSourceType)
{
ReadNextLocation(cache);
}
else if (positionSourceType == "minecraft:entity")
{
ReadNextVarInt(cache);
ReadNextFloat(cache);
case "minecraft:block":
ReadNextLocation(cache);
break;
case "minecraft:entity":
ReadNextVarInt(cache);
ReadNextFloat(cache);
break;
}
ReadNextVarInt(cache);
@ -1044,6 +1053,23 @@ namespace MinecraftClient.Protocol.Handlers
maximumNumberOfTradeUses, xp, specialPrice, priceMultiplier, demand);
}
public string ReadNextChat(Queue<byte> cache)
{
if (protocolversion >= Protocol18Handler.MC_1_20_4_Version)
{
// Read as NBT
var r = ReadNextNbt(cache);
var msg = ChatParser.ParseText(r);
return msg;
}
else
{
// Read as String
var json = ReadNextString(cache);
return ChatParser.ParseText(json);
}
}
/// <summary>
/// Build an uncompressed Named Binary Tag blob for sending over the network
/// </summary>

View file

@ -143,32 +143,18 @@ namespace MinecraftClient.Protocol.Handlers.Forge
case FMLVersion.FML3:
// Example ModInfo for Minecraft 1.18 and greater (FML3)
// {
// "enforcesSecureChat": true,
// "forgeData": {
// "channels": [],
// "mods": [],
// "truncated": false, // legacy versions see truncated lists, modern versions ignore this truncated flag (binary data has its own)
// "fmlNetworkVersion": 3,
// "d": "ȳ\u0000\u0000ࠨ㐤獋㙖⹌ᦘ̺⸱恤䒸⡑⛧沮婙㨹牥ఈㄵচ₀沮婙㨹牥ఈㄵচ倠⹡岙㜲獥䋊㷍᭳ႇׇ஌᜘㘴娘▅筳ص䰭宛㘲、\u0000ᠸጋ囗湌夜㘲杩棐䐱ᅱ挃☥ోᤗ㌮ఀ׈䬣 坖ɍ䮌ᤘ\r\n旉䠳ዣ◆䲌㜃瑥廮ⷉࠋ䁠奚Ҵ㔱摜䂸ᅱ獳ౠᡚ㜷汥戊䂸űဓĠ嵛㖱数嫤Ǎ塰䛶ⶎᮚ㞳晲擞ᖝ″ዣ䘆ఋʂ潦令ඕ爈䖔⺁ᥚ⾹潳棤㦥ᬻ挐؅䅀㠹楬ۨ㣄উ瀀渀嬛㘼扩搢䃀熁挂♥\r\n墋㒺摬牜ࣜ䁠嘗湌孛㜴浩惂䠙熙排٥孁㒰ͮ屢Ӏ䠐⚐䷮ᣛ㊴瑳戚䢸熁匒إ஍᜚ܴ䫜巑፻ؠ䀀ㆃ牵䋨㦥ࠫ㋣䗆䂌㨈慲䫬ᖱᮓᘧ汬尚ㆰ٫屲㣄ᆉ恳ಭ川㤷፫擨妅挫♖乮塘 㖱慰\r\n囆䓩\t"
// },
// "description": {
// "text": "A Minecraft Server"
// },
// "players": {
// "max": 100,
// "online": 0
// },
// "version": {
// "name": "1.20.1",
// "protocol": 763
// }
// }
// "forgeData": {
// "channels": [],
// "mods": [],
// "truncated": false, // legacy versions see truncated lists, modern versions ignore this truncated flag (binary data has its own)
// "fmlNetworkVersion": 3,
// "d": "ȳ\u0000\u0000ࠨ㐤獋㙖⹌ᦘ̺⸱恤䒸⡑⛧沮婙㨹牥ఈㄵচ₀沮婙㨹牥ఈㄵচ倠⹡岙㜲獥䋊㷍᭳ႇׇ஌᜘㘴娘▅筳ص䰭宛㘲、\u0000ᠸጋ囗湌夜㘲杩棐䐱ᅱ挃☥ోᤗ㌮ఀ׈䬣 坖ɍ䮌ᤘ\r\n旉䠳ዣ◆䲌㜃瑥廮ⷉࠋ䁠奚Ҵ㔱摜䂸ᅱ獳ౠᡚ㜷汥戊䂸űဓĠ嵛㖱数嫤Ǎ塰䛶ⶎᮚ㞳晲擞ᖝ″ዣ䘆ఋʂ潦令ඕ爈䖔⺁ᥚ⾹潳棤㦥ᬻ挐؅䅀㠹楬ۨ㣄উ瀀渀嬛㘼扩搢䃀熁挂♥\r\n墋㒺摬牜ࣜ䁠嘗湌孛㜴浩惂䠙熙排٥孁㒰ͮ屢Ӏ䠐⚐䷮ᣛ㊴瑳戚䢸熁匒إ஍᜚ܴ䫜巑፻ؠ䀀ㆃ牵䋨㦥ࠫ㋣䗆䂌㨈慲䫬ᖱᮓᘧ汬尚ㆰ٫屲㣄ᆉ恳ಭ川㤷፫擨妅挫♖乮塘 㖱慰\r\n囆䓩\t"
// }
// All buffer data are encoded and write to forgeData["d"]
// 1.18 and greater, the mod list and channel list is compressed to forgeData["d"] for efficiency,
// - Here is how forge encode and decode them:
// https://github.com/MinecraftForge/MinecraftForge/blob/cb12df41e13da576b781be695f80728b9594c25f/src/main/java/net/minecraftforge/network/ServerStatusPing.java#L264
// 1.18 and greater, the buffer is encoded for efficiency
// - Here is the discussion:
// see https://github.com/MinecraftForge/MinecraftForge/pull/8169
string encodedData = data.Properties["d"].StringValue;
@ -176,14 +162,21 @@ namespace MinecraftClient.Protocol.Handlers.Forge
DataTypes dataTypes = new DataTypes(Protocol18Handler.MC_1_18_1_Version);
//
// [truncated][boolean] placeholder for whether we are truncating
// [Mod Size][unsigned short] short so that we can replace it later in case of truncation
// [ Truncated ][ Bool ] // Unused
// [ Mod Size ][ Unsigned short ]
//
bool truncated = dataTypes.ReadNextBool(dataPackage);
dataTypes.ReadNextBool(dataPackage); // truncated: boolean
var modsSize = dataTypes.ReadNextUShort(dataPackage);
Dictionary<string, string> channels = new();
Dictionary<string, string> mods = new();
// Mod Array Definition:
// [ Channel Size And Version Flag ][ VarInt ] // If the value at bit Mask 0x01 is 1, The Mod Version will be ignore.
// // The one-right-shifted int is the Channel List size.
// [ Mod Id ][ String ]
// [ Mod Version ][ Optional String ] // Depends on the Flag above
// [ Channel List ][ Array ] [ Channel Name ][ String ]
// [ Channel Version ][ String ]
// [ Required On Client ][ Bool ]
for (var i = 0; i < modsSize; i++) {
var channelSizeAndVersionFlag = dataTypes.ReadNextVarInt(dataPackage);
@ -194,27 +187,24 @@ namespace MinecraftClient.Protocol.Handlers.Forge
var modId = dataTypes.ReadNextString(dataPackage);
string IGNORESERVERONLY = "";// it was "OHNOES\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31";
string IGNORESERVERONLY = "IGNORED";
var modVersion = isIgnoreServerOnly ? IGNORESERVERONLY : dataTypes.ReadNextString(dataPackage);
for (var i1 = 0; i1 < channelSize; i1++) {
var channelName = dataTypes.ReadNextString(dataPackage);
var channelVersion = dataTypes.ReadNextString(dataPackage);
var requiredOnClient = dataTypes.ReadNextBool(dataPackage);
channels.Add(modId + ":" + channelName, channelVersion + ":" + requiredOnClient);
dataTypes.ReadNextString(dataPackage); // channelName
dataTypes.ReadNextString(dataPackage); // channelVersion
dataTypes.ReadNextBool(dataPackage); // requiredOnClient
}
mods.Add(modId, modVersion);
Mods.Add(new ForgeMod(modId, modVersion));
}
var nonModChannelCount = dataTypes.ReadNextVarInt(dataPackage);
for (var i = 0; i < nonModChannelCount; i++) {
var channelName = dataTypes.ReadNextString(dataPackage);
var channelVersion = dataTypes.ReadNextString(dataPackage);
var requiredOnClient = dataTypes.ReadNextBool(dataPackage);
channels.Add(channelName, channelVersion + ":" + requiredOnClient);
}
// Ignore the left data, which is NonMod Channel List
// [ nonMod Channel Count ][ VarInt ]
// [ nonMod Channel List ][ Array ] [ Channel Name ][ String ]
// [ Channel Version ][ Bool ]
// [ Required On Client ][ Bool ]
break;
default:
@ -222,10 +212,17 @@ namespace MinecraftClient.Protocol.Handlers.Forge
}
}
// https://github.com/MinecraftForge/MinecraftForge/blob/cb12df41e13da576b781be695f80728b9594c25f/src/main/java/net/minecraftforge/network/ServerStatusPing.java#L361
// Decode binary data ForgeData["d"] to Queue<byte>
/// <summary>
/// Decompress binary data ForgeData["d"] (FML 3)
/// </summary>
/// <param name="encodedData">The encoded data.</param>
/// <returns>Decoded forge data Queue<byte>.</returns>
/// <para>
/// 1.18 and greater, the mod list and channel list is compressed for efficiency
/// The code below is converted from forge source code, see:
/// https://github.com/MinecraftForge/MinecraftForge/blob/cb12df41e13da576b781be695f80728b9594c25f/src/main/java/net/minecraftforge/network/ServerStatusPing.java#L361
/// </para>
private static Queue<byte> decodeOptimized(string encodedData) {
// Console.WriteLine("Got encoded data:" + encodedData + ", decoding...");
int size0 = encodedData[0];
int size1 = encodedData[1];
int size = size0 | (size1 << 15);

View file

@ -73,7 +73,7 @@ namespace MinecraftClient.Protocol.Handlers.packet.s2c
50 => new ParserForgeEnum(dataTypes, packetData),
_ => new ParserEmpty(dataTypes, packetData),
};
else // 1.19.4+
else if (protocolVersion <= Protocol18Handler.MC_1_20_2_Version)// 1.19.4 - 1.20.2
parser = parserId switch
{
1 => new ParserFloat(dataTypes, packetData),
@ -103,11 +103,34 @@ namespace MinecraftClient.Protocol.Handlers.packet.s2c
new ParserEmpty(dataTypes, packetData),
_ => new ParserEmpty(dataTypes, packetData),
};
else // 1.20.3+
parser = parserId switch
{
1 => new ParserFloat(dataTypes, packetData),
2 => new ParserDouble(dataTypes, packetData),
3 => new ParserInteger(dataTypes, packetData),
4 => new ParserLong(dataTypes, packetData),
5 => new ParserString(dataTypes, packetData),
6 => new ParserEntity(dataTypes, packetData),
8 => new ParserBlockPos(dataTypes, packetData),
9 => new ParserColumnPos(dataTypes, packetData),
10 => new ParserVec3(dataTypes, packetData),
11 => new ParserVec2(dataTypes, packetData),
18 => new ParserMessage(dataTypes, packetData),
27 => new ParserRotation(dataTypes, packetData),
30 => new ParserScoreHolder(dataTypes, packetData),
41 => new ParserTime(dataTypes, packetData),
42 => new ParserResourceOrTag(dataTypes, packetData),
43 => new ParserResourceOrTag(dataTypes, packetData),
44 => new ParserResource(dataTypes, packetData),
45 => new ParserResource(dataTypes, packetData),
_ => new ParserEmpty(dataTypes, packetData),
};
}
string? suggestionsType = ((flags & 0x10) == 0x10) ? dataTypes.ReadNextString(packetData) : null;
Nodes[i] = new(flags, childs, redirectNode, name, parser, suggestionsType);
Nodes[i] = new(flags, childs, redirectNode, name, parser, suggestionsType, parserId);
}
RootIdx = dataTypes.ReadNextVarInt(packetData);
@ -183,6 +206,7 @@ namespace MinecraftClient.Protocol.Handlers.packet.s2c
public string? Name;
public Parser? Paser;
public string? SuggestionsType;
public int ParserId; // Added for easy debug
public CommandNode(byte Flags,
@ -190,7 +214,8 @@ namespace MinecraftClient.Protocol.Handlers.packet.s2c
int RedirectNode = -1,
string? Name = null,
Parser? Paser = null,
string? SuggestionsType = null)
string? SuggestionsType = null,
int parserId = -1)
{
this.Flags = Flags;
this.Clildren = Clildren;
@ -198,6 +223,7 @@ namespace MinecraftClient.Protocol.Handlers.packet.s2c
this.Name = Name;
this.Paser = Paser;
this.SuggestionsType = SuggestionsType;
ParserId = parserId;
}
}

View file

@ -0,0 +1,215 @@
using System.Collections.Generic;
namespace MinecraftClient.Protocol.Handlers.PacketPalettes;
public class PacketPalette1204 : PacketTypePalette
{
private readonly Dictionary<int, PacketTypesIn> typeIn = new()
{
{ 0x00, PacketTypesIn.Bundle }, // Added in 1.19.4
{ 0x01, PacketTypesIn.SpawnEntity }, // Changed in 1.19 (Wiki name: Spawn Entity)
{ 0x02, PacketTypesIn.SpawnExperienceOrb }, // (Wiki name: Spawn Exeprience Orb)
{ 0x03, PacketTypesIn.EntityAnimation }, // (Wiki name: Entity Animation (clientbound))
{ 0x04, PacketTypesIn.Statistics }, // (Wiki name: Award Statistics)
{ 0x05, PacketTypesIn.BlockChangedAck }, // Added 1.19 (Wiki name: Acknowledge Block Change)
{ 0x06, PacketTypesIn.BlockBreakAnimation }, // (Wiki name: Set Block Destroy Stage)
{ 0x07, PacketTypesIn.BlockEntityData }, //
{ 0x08, PacketTypesIn.BlockAction }, //
{ 0x09, PacketTypesIn.BlockChange }, // (Wiki name: Block Update)
{ 0x0A, PacketTypesIn.BossBar }, //
{ 0x0B, PacketTypesIn.ServerDifficulty }, // (Wiki name: Change Difficulty)
{ 0x0C, PacketTypesIn.ChunkBatchFinished }, // Added in 1.20.2
{ 0x0D, PacketTypesIn.ChunkBatchStarted }, // Added in 1.20.2
{ 0x0E, PacketTypesIn.ChunksBiomes }, // Added in 1.19.4
{ 0x0F, PacketTypesIn.ClearTiles }, //
{ 0x10, PacketTypesIn.TabComplete }, // (Wiki name: Command Suggestions Response)
{ 0x11, PacketTypesIn.DeclareCommands }, // (Wiki name: Commands)
{ 0x12, PacketTypesIn.CloseWindow }, // (Wiki name: Close Container (clientbound))
{ 0x13, PacketTypesIn.WindowItems }, // (Wiki name: Set Container Content)
{ 0x14, PacketTypesIn.WindowProperty }, // (Wiki name: Set Container Property)
{ 0x15, PacketTypesIn.SetSlot }, // (Wiki name: Set Container Slot)
{ 0x16, PacketTypesIn.SetCooldown }, //
{ 0x17, PacketTypesIn.ChatSuggestions }, // Added in 1.19.1
{ 0x18, PacketTypesIn.PluginMessage }, // (Wiki name: Plugin Message (clientbound))
{ 0x19, PacketTypesIn.DamageEvent }, // Added in 1.19.4
{ 0x1A, PacketTypesIn.HideMessage }, // Added in 1.19.1
{ 0x1B, PacketTypesIn.Disconnect }, //
{ 0x1C, PacketTypesIn.ProfilelessChatMessage }, // Added in 1.19.3 (Wiki name: Disguised Chat Message)
{ 0x1D, PacketTypesIn.EntityStatus }, // (Wiki name: Entity Event)
{ 0x1E, PacketTypesIn.Explosion }, // Changed in 1.19 (Location fields are now Double instead of Float) (Wiki name: Explosion)
{ 0x1F, PacketTypesIn.UnloadChunk }, // (Wiki name: Forget Chunk)
{ 0x20, PacketTypesIn.ChangeGameState }, // (Wiki name: Game Event)
{ 0x21, PacketTypesIn.OpenHorseWindow }, // (Wiki name: Horse Screen Open)
{ 0x22, PacketTypesIn.HurtAnimation }, // Added in 1.19.4
{ 0x23, PacketTypesIn.InitializeWorldBorder }, //
{ 0x24, PacketTypesIn.KeepAlive }, //
{ 0x25, PacketTypesIn.ChunkData }, //
{ 0x26, PacketTypesIn.Effect }, // (Wiki name: World Event)
{ 0x27, PacketTypesIn.Particle }, // Changed in 1.19 (Wiki name: Level Particle) (No need to be implemented)
{ 0x28, PacketTypesIn.UpdateLight }, // (Wiki name: Light Update)
{ 0x29, PacketTypesIn.JoinGame }, // Changed in 1.20.2 (Wiki name: Login (play))
{ 0x2A, PacketTypesIn.MapData }, // (Wiki name: Map Item Data)
{ 0x2B, PacketTypesIn.TradeList }, // (Wiki name: Merchant Offers)
{ 0x2C, PacketTypesIn.EntityPosition }, // (Wiki name: Move Entity Position)
{ 0x2D, PacketTypesIn.EntityPositionAndRotation }, // (Wiki name: Move Entity Position and Rotation)
{ 0x2E, PacketTypesIn.EntityRotation }, // (Wiki name: Move Entity Rotation)
{ 0x2F, PacketTypesIn.VehicleMove }, // (Wiki name: Move Vehicle)
{ 0x30, PacketTypesIn.OpenBook }, //
{ 0x31, PacketTypesIn.OpenWindow }, // (Wiki name: Open Screen)
{ 0x32, PacketTypesIn.OpenSignEditor }, //
{ 0x33, PacketTypesIn.Ping }, // (Wiki name: Ping (play))
{ 0x34, PacketTypesIn.PingResponse }, // Added in 1.20.2
{ 0x35, PacketTypesIn.CraftRecipeResponse }, // (Wiki name: Place Ghost Recipe)
{ 0x36, PacketTypesIn.PlayerAbilities }, //
{ 0x37, PacketTypesIn.ChatMessage }, // Changed in 1.19 (Completely changed) (Wiki name: Player Chat Message)
{ 0x38, PacketTypesIn.EndCombatEvent }, // (Wiki name: End Combat)
{ 0x39, PacketTypesIn.EnterCombatEvent }, // (Wiki name: Enter Combat)
{ 0x3A, PacketTypesIn.DeathCombatEvent }, // (Wiki name: Combat Death)
{ 0x3B, PacketTypesIn.PlayerRemove }, // Added in 1.19.3 (Not used)
{ 0x3C, PacketTypesIn.PlayerInfo }, // Changed in 1.19 (Heavy changes)
{ 0x3D, PacketTypesIn.FacePlayer }, // (Wiki name: Player Look At)
{ 0x3E, PacketTypesIn.PlayerPositionAndLook }, // (Wiki name: Synchronize Player Position)
{ 0x3F, PacketTypesIn.UnlockRecipes }, // (Wiki name: Update Recipe Book)
{ 0x40, PacketTypesIn.DestroyEntities }, // (Wiki name: Remove Entites)
{ 0x41, PacketTypesIn.RemoveEntityEffect }, //
{ 0x42, PacketTypesIn.ResetScore }, // Added in 1.20.3
{ 0x43, PacketTypesIn.RemoveResourcePack }, // Added in 1.20.3
{ 0x44, PacketTypesIn.ResourcePackSend }, // (Wiki name: Add Resource pack (play))
{ 0x45, PacketTypesIn.Respawn }, // Changed in 1.20.2
{ 0x46, PacketTypesIn.EntityHeadLook }, // (Wiki name: Set Head Rotation)
{ 0x47, PacketTypesIn.MultiBlockChange }, // (Wiki name: Update Section Blocks)
{ 0x48, PacketTypesIn.SelectAdvancementTab }, //
{ 0x49, PacketTypesIn.ServerData }, // Added in 1.19
{ 0x4A, PacketTypesIn.ActionBar }, // (Wiki name: Set Action Bar Text)
{ 0x4B, PacketTypesIn.WorldBorderCenter }, // (Wiki name: Set Border Center)
{ 0x4C, PacketTypesIn.WorldBorderLerpSize }, //
{ 0x4D, PacketTypesIn.WorldBorderSize }, // (Wiki name: Set World Border Size)
{ 0x4E, PacketTypesIn.WorldBorderWarningDelay }, // (Wiki name: Set World Border Warning Delay)
{ 0x4F, PacketTypesIn.WorldBorderWarningReach }, // (Wiki name: Set Border Warning Distance)
{ 0x50, PacketTypesIn.Camera }, // (Wiki name: Set Camera)
{ 0x51, PacketTypesIn.HeldItemChange }, // (Wiki name: Set Held Item)
{ 0x52, PacketTypesIn.UpdateViewPosition }, // (Wiki name: Set Center Chunk)
{ 0x53, PacketTypesIn.UpdateViewDistance }, // (Wiki name: Set Render Distance)
{ 0x54, PacketTypesIn.SpawnPosition }, // (Wiki name: Set Default Spawn Position)
{ 0x55, PacketTypesIn.DisplayScoreboard }, // (Wiki name: Set Display Objective)
{ 0x56, PacketTypesIn.EntityMetadata }, // (Wiki name: Set Entity Metadata)
{ 0x57, PacketTypesIn.AttachEntity }, // (Wiki name: Link Entities)
{ 0x58, PacketTypesIn.EntityVelocity }, // (Wiki name: Set Entity Velocity)
{ 0x59, PacketTypesIn.EntityEquipment }, // (Wiki name: Set Equipment)
{ 0x5A, PacketTypesIn.SetExperience }, // Changed in 1.20.2
{ 0x5B, PacketTypesIn.UpdateHealth }, // (Wiki name: Set Health)
{ 0x5C, PacketTypesIn.ScoreboardObjective }, // (Wiki name: Update Objectives) - Changed in 1.20.3
{ 0x5D, PacketTypesIn.SetPassengers }, //
{ 0x5E, PacketTypesIn.Teams }, // (Wiki name: Update Teams)
{ 0x5F, PacketTypesIn.UpdateScore }, // (Wiki name: Update Score)
{ 0x60, PacketTypesIn.UpdateSimulationDistance }, // (Wiki name: Set Simulation Distance)
{ 0x61, PacketTypesIn.SetTitleSubTitle }, // (Wiki name: Set Subtitle Test)
{ 0x62, PacketTypesIn.TimeUpdate }, // (Wiki name: Set Time)
{ 0x63, PacketTypesIn.SetTitleText }, // (Wiki name: Set Title)
{ 0x64, PacketTypesIn.SetTitleTime }, // (Wiki name: Set Title Animation Times)
{ 0x65, PacketTypesIn.EntitySoundEffect }, // (Wiki name: Sound Entity)
{ 0x66, PacketTypesIn.SoundEffect }, // Changed in 1.19 (Added "Seed" field) (Wiki name: Sound Effect) (No need to be implemented)
{ 0x67, PacketTypesIn.StartConfiguration }, // Added in 1.20.2
{ 0x68, PacketTypesIn.StopSound }, //
{ 0x69, PacketTypesIn.SystemChat }, // Added in 1.19 (Wiki name: System Chat Message)
{ 0x6A, PacketTypesIn.PlayerListHeaderAndFooter }, // (Wiki name: Set Tab List Header And Footer)
{ 0x6B, PacketTypesIn.NBTQueryResponse }, // (Wiki name: Tag Query Response)
{ 0x6C, PacketTypesIn.CollectItem }, // (Wiki name: Pickup Item)
{ 0x6D, PacketTypesIn.EntityTeleport }, // (Wiki name: Teleport Entity)
{ 0x6E, PacketTypesIn.SetTickingState }, // Added in 1.20.3
{ 0x6F, PacketTypesIn.StepTick }, // Added in 1.20.3
{ 0x70, PacketTypesIn.Advancements }, // (Wiki name: Update Advancements) (Unused)
{ 0x71, PacketTypesIn.EntityProperties }, // (Wiki name: Update Attributes)
{ 0x72, PacketTypesIn.EntityEffect }, // Changed in 1.19 (Added "Has Factor Data" and "Factor Codec" fields) (Wiki name: Entity Effect)
{ 0x73, PacketTypesIn.DeclareRecipes }, // (Wiki name: Update Recipes) (Unused)
{ 0x74, PacketTypesIn.Tags }, // (Wiki name: Update Tags)
};
private readonly Dictionary<int, PacketTypesOut> typeOut = new()
{
{ 0x00, PacketTypesOut.TeleportConfirm }, // (Wiki name: Confirm Teleportation)
{ 0x01, PacketTypesOut.QueryBlockNBT }, // (Wiki name: Query Block Entity Tag)
{ 0x02, PacketTypesOut.SetDifficulty }, // (Wiki name: Change Difficulty)
{ 0x03, PacketTypesOut.MessageAcknowledgment }, // Added in 1.19.1
{ 0x04, PacketTypesOut.ChatCommand }, // Added in 1.19
{ 0x05, PacketTypesOut.ChatMessage }, // Changed in 1.19 (Completely changed) (Wiki name: Chat)
{ 0x06, PacketTypesOut.PlayerSession }, // Added in 1.19.3
{ 0x07, PacketTypesOut.ChunkBatchReceived }, // Added in 1.20.2
{ 0x08, PacketTypesOut.ClientStatus }, // (Wiki name: Client Command)
{ 0x09, PacketTypesOut.ClientSettings }, // (Wiki name: Client Information)
{ 0x0A, PacketTypesOut.TabComplete }, // (Wiki name: Command Suggestions Request)
{ 0x0B, PacketTypesOut.AcknowledgeConfiguration }, // Added in 1.20.2
{ 0x0C, PacketTypesOut.ClickWindowButton }, // (Wiki name: Click Container Button)
{ 0x0D, PacketTypesOut.ClickWindow }, // (Wiki name: Click Container)
{ 0x0E, PacketTypesOut.CloseWindow }, // (Wiki name: Close Container (serverbound))
{ 0x0F, PacketTypesOut.ChangeContainerSlotState }, // Added in 1.20.3
{ 0x10, PacketTypesOut.PluginMessage }, // (Wiki name: Serverbound Plugin Message)
{ 0x11, PacketTypesOut.EditBook }, //
{ 0x12, PacketTypesOut.EntityNBTRequest }, // (Wiki name: Query Entity Tag)
{ 0x13, PacketTypesOut.InteractEntity }, // (Wiki name: Interact)
{ 0x14, PacketTypesOut.GenerateStructure }, // (Wiki name: Jigsaw Generate)
{ 0x15, PacketTypesOut.KeepAlive }, // (Wiki name: Serverbound Keep Alive (play))
{ 0x16, PacketTypesOut.LockDifficulty }, //
{ 0x17, PacketTypesOut.PlayerPosition }, // (Wiki name: Move Player Position)
{ 0x18, PacketTypesOut.PlayerPositionAndRotation }, // (Wiki name: Set Player Position and Rotation)
{ 0x19, PacketTypesOut.PlayerRotation }, // (Wiki name: Set Player Rotation)
{ 0x1A, PacketTypesOut.PlayerMovement }, // (Wiki name: Set Player On Ground)
{ 0x1B, PacketTypesOut.VehicleMove }, // (Wiki name: Move Vehicle (serverbound))
{ 0x1C, PacketTypesOut.SteerBoat }, // (Wiki name: Paddle Boat)
{ 0x1D, PacketTypesOut.PickItem }, //
{ 0x1E, PacketTypesOut.PingRequest }, // Added in 1.20.2
{ 0x1F, PacketTypesOut.CraftRecipeRequest }, // (Wiki name: Place recipe)
{ 0x20, PacketTypesOut.PlayerAbilities }, //
{ 0x21, PacketTypesOut.PlayerDigging }, // Changed in 1.19 (Added a "Sequence" field) (Wiki name: Player Action)
{ 0x22, PacketTypesOut.EntityAction }, // (Wiki name: Player Command)
{ 0x23, PacketTypesOut.SteerVehicle }, // (Wiki name: Player Input)
{ 0x24, PacketTypesOut.Pong }, // (Wiki name: Pong (play))
{ 0x25, PacketTypesOut.SetDisplayedRecipe }, // (Wiki name: Recipe Book Change Settings)
{ 0x26, PacketTypesOut.SetRecipeBookState }, // (Wiki name: Recipe Book Seen Recipe)
{ 0x27, PacketTypesOut.NameItem }, // (Wiki name: Rename Item)
{ 0x28, PacketTypesOut.ResourcePackStatus }, // (Wiki name: Resource Pack (serverbound))
{ 0x29, PacketTypesOut.AdvancementTab }, // (Wiki name: Seen Advancements)
{ 0x2A, PacketTypesOut.SelectTrade }, //
{ 0x2B, PacketTypesOut.SetBeaconEffect }, // Changed in 1.19 (No need to be implemented yet)
{ 0x2C, PacketTypesOut.HeldItemChange }, // (Wiki name: Set Carried Item (serverbound))
{ 0x2D, PacketTypesOut.UpdateCommandBlock }, // (Wiki name: Program Command Block)
{ 0x2E, PacketTypesOut.UpdateCommandBlockMinecart }, // (Wiki name: Program Command Block Minecart)
{ 0x2F, PacketTypesOut.CreativeInventoryAction }, // (Wiki name: Set Creative Mode Slot)
{ 0x30, PacketTypesOut.UpdateJigsawBlock }, // (Wiki name: Program Jigsaw Block)
{ 0x31, PacketTypesOut.UpdateStructureBlock }, // (Wiki name: Program Structure Block)
{ 0x32, PacketTypesOut.UpdateSign }, // (Wiki name: Update Sign)
{ 0x33, PacketTypesOut.Animation }, // (Wiki name: Swing Arm)
{ 0x34, PacketTypesOut.Spectate }, // (Wiki name: Teleport To Entity)
{ 0x35, PacketTypesOut.PlayerBlockPlacement }, // Changed in 1.19 (Added a "Sequence" field) (Wiki name: Use Item On)
{ 0x36, PacketTypesOut.UseItem }, // Changed in 1.19 (Added a "Sequence" field) (Wiki name: Use Item)
};
private readonly Dictionary<int, ConfigurationPacketTypesIn> configurationTypesIn = new()
{
{ 0x00, ConfigurationPacketTypesIn.PluginMessage },
{ 0x01, ConfigurationPacketTypesIn.Disconnect },
{ 0x02, ConfigurationPacketTypesIn.FinishConfiguration },
{ 0x03, ConfigurationPacketTypesIn.KeepAlive },
{ 0x04, ConfigurationPacketTypesIn.Ping },
{ 0x05, ConfigurationPacketTypesIn.RegistryData },
{ 0x06, ConfigurationPacketTypesIn.RemoveResourcePack },
{ 0x07, ConfigurationPacketTypesIn.ResourcePack },
{ 0x08, ConfigurationPacketTypesIn.FeatureFlags },
{ 0x09, ConfigurationPacketTypesIn.UpdateTags },
};
private readonly Dictionary<int, ConfigurationPacketTypesOut> configurationTypesOut = new()
{
{ 0x00, ConfigurationPacketTypesOut.ClientInformation },
{ 0x01, ConfigurationPacketTypesOut.PluginMessage },
{ 0x02, ConfigurationPacketTypesOut.FinishConfiguration },
{ 0x03, ConfigurationPacketTypesOut.KeepAlive },
{ 0x04, ConfigurationPacketTypesOut.Pong },
{ 0x05, ConfigurationPacketTypesOut.ResourcePackResponse }
};
protected override Dictionary<int, PacketTypesIn> GetListIn() => typeIn;
protected override Dictionary<int, PacketTypesOut> GetListOut() => typeOut;
protected override Dictionary<int, ConfigurationPacketTypesIn> GetConfigurationListIn() => configurationTypesIn!;
protected override Dictionary<int, ConfigurationPacketTypesOut> GetConfigurationListOut() => configurationTypesOut!;
}

View file

@ -48,7 +48,7 @@ namespace MinecraftClient.Protocol.Handlers
{
PacketTypePalette p = protocol switch
{
> Protocol18Handler.MC_1_20_2_Version => throw new NotImplementedException(Translations
> Protocol18Handler.MC_1_20_4_Version => throw new NotImplementedException(Translations
.exception_palette_packet),
<= Protocol18Handler.MC_1_8_Version => new PacketPalette17(),
<= Protocol18Handler.MC_1_11_2_Version => new PacketPalette110(),
@ -64,8 +64,9 @@ namespace MinecraftClient.Protocol.Handlers
<= Protocol18Handler.MC_1_19_Version => new PacketPalette119(),
<= Protocol18Handler.MC_1_19_2_Version => new PacketPalette1192(),
<= Protocol18Handler.MC_1_19_3_Version => new PacketPalette1193(),
< Protocol18Handler.MC_1_20_2_Version => new PacketPalette1194(),
_ => new PacketPalette1202()
<= Protocol18Handler.MC_1_19_4_Version => new PacketPalette1194(),
<= Protocol18Handler.MC_1_20_2_Version => new PacketPalette1202(),
_ => new PacketPalette1204()
};
p.SetForgeEnabled(forgeEnabled);

View file

@ -1,7 +1,7 @@
namespace MinecraftClient.Protocol.Handlers
{
/// <summary>
/// Incomming packet types
/// Incoming packet types
/// </summary>
public enum PacketTypesIn
{
@ -84,6 +84,8 @@
PluginMessage, //
ProfilelessChatMessage, // Added in 1.19.3
RemoveEntityEffect, //
RemoveResourcePack, // Added in 1.20.3
ResetScore, // Added in 1.20.3
ResourcePackSend, //
Respawn, //
ScoreboardObjective, //
@ -96,6 +98,8 @@
SetExperience, //
SetPassengers, //
SetSlot, //
SetTickingState, // Added in 1.20.3
StepTick, // Added in 1.20.3
SetTitleSubTitle, //
SetTitleText, //
SetTitleTime, //

View file

@ -8,6 +8,7 @@
AcknowledgeConfiguration, // Added in 1.20.2
AdvancementTab, //
Animation, //
ChangeContainerSlotState, // Added in 1.20.3
ChatCommand, // Added in 1.19
ChatMessage, //
ChatPreview, // Added in 1.19

View file

@ -69,6 +69,7 @@ namespace MinecraftClient.Protocol.Handlers
internal const int MC_1_19_4_Version = 762;
internal const int MC_1_20_Version = 763;
internal const int MC_1_20_2_Version = 764;
internal const int MC_1_20_4_Version = 765;
private int compression_treshold = 0;
private int autocomplete_transaction_id = 0;
@ -120,21 +121,21 @@ namespace MinecraftClient.Protocol.Handlers
lastSeenMessagesCollector = protocolVersion >= MC_1_19_3_Version ? new(20) : new(5);
chunkBatchStartTime = GetNanos();
if (handler.GetTerrainEnabled() && protocolVersion > MC_1_20_2_Version)
if (handler.GetTerrainEnabled() && protocolVersion > MC_1_20_4_Version)
{
log.Error($"§c{Translations.extra_terrainandmovement_disabled}");
handler.SetTerrainEnabled(false);
}
if (handler.GetInventoryEnabled() &&
protocolVersion is < MC_1_9_Version or > MC_1_20_2_Version)
protocolVersion is < MC_1_9_Version or > MC_1_20_4_Version)
{
log.Error($"§c{Translations.extra_inventory_disabled}");
handler.SetInventoryEnabled(false);
}
if (handler.GetEntityHandlingEnabled() &&
protocolVersion is < MC_1_8_Version or > MC_1_20_2_Version)
protocolVersion is < MC_1_8_Version or > MC_1_20_4_Version)
{
log.Error($"§c{Translations.extra_entity_disabled}");
handler.SetEntityHandlingEnabled(false);
@ -143,8 +144,9 @@ namespace MinecraftClient.Protocol.Handlers
Block.Palette = protocolVersion switch
{
// Block palette
> MC_1_20_2_Version when handler.GetTerrainEnabled() =>
> MC_1_20_4_Version when handler.GetTerrainEnabled() =>
throw new NotImplementedException(Translations.exception_palette_block),
>= MC_1_20_4_Version => new Palette1204(),
>= MC_1_20_Version => new Palette120(),
MC_1_19_4_Version => new Palette1194(),
MC_1_19_3_Version => new Palette1193(),
@ -160,8 +162,9 @@ namespace MinecraftClient.Protocol.Handlers
entityPalette = protocolVersion switch
{
// Entity palette
> MC_1_20_2_Version when handler.GetEntityHandlingEnabled() =>
> MC_1_20_4_Version when handler.GetEntityHandlingEnabled() =>
throw new NotImplementedException(Translations.exception_palette_entity),
>= MC_1_20_4_Version => new EntityPalette1204(),
>= MC_1_20_Version => new EntityPalette120(),
MC_1_19_4_Version => new EntityPalette1194(),
MC_1_19_3_Version => new EntityPalette1193(),
@ -181,8 +184,9 @@ namespace MinecraftClient.Protocol.Handlers
itemPalette = protocolVersion switch
{
// Item palette
> MC_1_20_2_Version when handler.GetInventoryEnabled() =>
> MC_1_20_4_Version when handler.GetInventoryEnabled() =>
throw new NotImplementedException(Translations.exception_palette_item),
>= MC_1_20_4_Version => new ItemPalette1204(),
>= MC_1_20_Version => new ItemPalette120(),
MC_1_19_4_Version => new ItemPalette1194(),
MC_1_19_3_Version => new ItemPalette1193(),
@ -397,18 +401,18 @@ namespace MinecraftClient.Protocol.Handlers
{
case ConfigurationPacketTypesIn.Disconnect:
handler.OnConnectionLost(ChatBot.DisconnectReason.InGameKick,
ChatParser.ParseText(dataTypes.ReadNextString(packetData)));
dataTypes.ReadNextChat(packetData));
return false;
case ConfigurationPacketTypesIn.FinishConfiguration:
currentState = CurrentState.Play;
SendPacket(ConfigurationPacketTypesOut.FinishConfiguration, new List<byte>());
break;
case ConfigurationPacketTypesIn.KeepAlive:
SendPacket(ConfigurationPacketTypesOut.KeepAlive, packetData);
break;
case ConfigurationPacketTypesIn.Ping:
SendPacket(ConfigurationPacketTypesOut.Pong, packetData);
break;
@ -421,29 +425,14 @@ namespace MinecraftClient.Protocol.Handlers
World.StoreDimensionList(registryCodec);
break;
case ConfigurationPacketTypesIn.RemoveResourcePack:
if (dataTypes.ReadNextBool(packetData)) // Has UUID
dataTypes.ReadNextUUID(packetData); // UUID
break;
case ConfigurationPacketTypesIn.ResourcePack:
var url = dataTypes.ReadNextString(packetData);
var hash = dataTypes.ReadNextString(packetData);
dataTypes.ReadNextBool(packetData); // Forced
var hasPromptMessage =
dataTypes.ReadNextBool(packetData);
if (hasPromptMessage)
dataTypes.SkipNextString(packetData);
// Some server plugins may send invalid resource packs to probe the client and we need to ignore them (issue #1056)
if (!url.StartsWith("http") &&
hash.Length != 40) // Some server may have null hash value
break;
//Send back "accepted" and "successfully loaded" responses for plugins or server config making use of resource pack mandatory
var responseHeader = Array.Empty<byte>();
SendPacket(ConfigurationPacketTypesOut.ResourcePackResponse,
dataTypes.ConcatBytes(responseHeader, DataTypes.GetVarInt(3))); // Accepted pack
SendPacket(ConfigurationPacketTypesOut.ResourcePackResponse,
dataTypes.ConcatBytes(responseHeader,
DataTypes.GetVarInt(0))); // Successfully loaded
HandleResourcePackPacket(packetData);
break;
// Ignore other packets at this stage
@ -480,6 +469,54 @@ namespace MinecraftClient.Protocol.Handlers
return true;
}
public void HandleResourcePackPacket(Queue<byte> packetData)
{
var uuid = Guid.Empty;
if (protocolVersion >= MC_1_20_4_Version)
uuid = dataTypes.ReadNextUUID(packetData);
var url = dataTypes.ReadNextString(packetData);
var hash = dataTypes.ReadNextString(packetData);
if (protocolVersion >= MC_1_17_Version)
{
dataTypes.ReadNextBool(packetData); // Forced
if (dataTypes.ReadNextBool(packetData)) // Has Prompt Message
dataTypes.ReadNextChat(packetData); // Prompt Message
}
// Some server plugins may send invalid resource packs to probe the client and we need to ignore them (issue #1056)
if (!url.StartsWith("http") &&
hash.Length != 40) // Some server may have null hash value
return;
//Send back "accepted" and "successfully loaded" responses for plugins or server config making use of resource pack mandatory
var responseHeader =
protocolVersion < MC_1_10_Version // After 1.10, the MC does not include resource pack hash in responses
? dataTypes.ConcatBytes(DataTypes.GetVarInt(hash.Length), Encoding.UTF8.GetBytes(hash))
: Array.Empty<byte>();
var basePacketData = protocolVersion >= MC_1_20_4_Version && uuid != Guid.Empty
? dataTypes.ConcatBytes(responseHeader, DataTypes.GetUUID(uuid))
: responseHeader;
var acceptedResourcePackData = dataTypes.ConcatBytes(basePacketData, DataTypes.GetVarInt(3));
var loadedResourcePackData = dataTypes.ConcatBytes(basePacketData, DataTypes.GetVarInt(0));
if (currentState == CurrentState.Configuration)
{
SendPacket(ConfigurationPacketTypesOut.ResourcePackResponse, acceptedResourcePackData); // Accepted
SendPacket(ConfigurationPacketTypesOut.ResourcePackResponse,
loadedResourcePackData); // Successfully loaded
}
else
{
SendPacket(PacketTypesOut.ResourcePackStatus, acceptedResourcePackData); // Accepted
SendPacket(PacketTypesOut.ResourcePackStatus, loadedResourcePackData); // Successfully loaded
}
}
private bool HandlePlayPackets(int packetId, Queue<byte> packetData)
{
switch (packetPalette.GetIncomingTypeById(packetId))
@ -886,7 +923,7 @@ namespace MinecraftClient.Protocol.Handlers
// Other
var unsignedChatContent = dataTypes.ReadNextBool(packetData)
? dataTypes.ReadNextString(packetData)
? dataTypes.ReadNextChat(packetData)
: null;
var filterType = (MessageFilterType)dataTypes.ReadNextVarInt(packetData);
@ -897,26 +934,17 @@ namespace MinecraftClient.Protocol.Handlers
// Network Target
// net.minecraft.network.message.MessageType.Serialized#write
var chatTypeId = dataTypes.ReadNextVarInt(packetData);
var chatName = dataTypes.ReadNextString(packetData);
var chatName = dataTypes.ReadNextChat(packetData);
var targetName = dataTypes.ReadNextBool(packetData)
? dataTypes.ReadNextString(packetData)
? dataTypes.ReadNextChat(packetData)
: null;
var messageTypeEnum =
ChatParser.ChatId2Type!.GetValueOrDefault(chatTypeId, ChatParser.MessageType.CHAT);
var chatInfo =
Json.ParseJson(targetName ?? chatName).Properties;
var senderDisplayName = chatInfo != null && chatInfo.Count > 0
? (chatInfo.ContainsKey("insertion") ? chatInfo["insertion"] : chatInfo["text"])
.StringValue
: "";
string? senderTeamName = null;
if (targetName != null &&
messageTypeEnum is ChatParser.MessageType.TEAM_MSG_COMMAND_INCOMING
or ChatParser.MessageType.TEAM_MSG_COMMAND_OUTGOING)
senderTeamName = Json.ParseJson(targetName).Properties["with"].DataArray[0]
.Properties["text"].StringValue;
//var chatInfo = Json.ParseJson(targetName ?? chatName).Properties;
var senderDisplayName = chatName;
string? senderTeamName = targetName;
if (string.IsNullOrWhiteSpace(senderDisplayName))
{
@ -924,7 +952,7 @@ namespace MinecraftClient.Protocol.Handlers
if (player != null && (player.DisplayName != null || player.Name != null) &&
string.IsNullOrWhiteSpace(senderDisplayName))
{
senderDisplayName = ChatParser.ParseText(player.DisplayName ?? player.Name);
senderDisplayName = player.DisplayName ?? player.Name;
if (string.IsNullOrWhiteSpace(senderDisplayName))
senderDisplayName = player.DisplayName ?? player.Name;
else
@ -989,7 +1017,7 @@ namespace MinecraftClient.Protocol.Handlers
$"HideMessage was not processed! (SigLen={hideMessageSignature.Length})");
break;
case PacketTypesIn.SystemChat:
var systemMessage = dataTypes.ReadNextString(packetData);
var systemMessage = dataTypes.ReadNextChat(packetData);
if (protocolVersion >= MC_1_19_3_Version)
{
@ -1005,7 +1033,7 @@ namespace MinecraftClient.Protocol.Handlers
break;
}
handler.OnTextReceived(new(systemMessage, null, true, -1, Guid.Empty, true));
handler.OnTextReceived(new(systemMessage, null, false, -1, Guid.Empty, true));
}
else
{
@ -1017,15 +1045,15 @@ namespace MinecraftClient.Protocol.Handlers
break;
case PacketTypesIn.ProfilelessChatMessage:
var message_ = dataTypes.ReadNextString(packetData);
var message_ = dataTypes.ReadNextChat(packetData);
var messageType_ = dataTypes.ReadNextVarInt(packetData);
var messageName = dataTypes.ReadNextString(packetData);
var messageName = dataTypes.ReadNextChat(packetData);
var targetName_ = dataTypes.ReadNextBool(packetData)
? dataTypes.ReadNextString(packetData)
? dataTypes.ReadNextChat(packetData)
: null;
ChatMessage profilelessChat = new(message_, targetName_ ?? messageName, true, messageType_,
ChatMessage profilelessChat = new(message_, targetName_ ?? messageName, false, messageType_,
Guid.Empty, true);
profilelessChat.isSenderJson = true;
profilelessChat.isSenderJson = false;
handler.OnTextReceived(profilelessChat);
break;
case PacketTypesIn.CombatEvent:
@ -1051,7 +1079,7 @@ namespace MinecraftClient.Protocol.Handlers
handler.OnPlayerKilled(
protocolVersion >= MC_1_20_Version ? -1 : dataTypes.ReadNextInt(packetData),
ChatParser.ParseText(dataTypes.ReadNextString(packetData))
ChatParser.ParseText(dataTypes.ReadNextChat(packetData))
);
break;
@ -1450,7 +1478,7 @@ namespace MinecraftClient.Protocol.Handlers
if (dataTypes.ReadNextBool(packetData)) // Has Display Name?
mapIcon.DisplayName =
ChatParser.ParseText(dataTypes.ReadNextString(packetData));
ChatParser.ParseText(dataTypes.ReadNextChat(packetData));
}
icons.Add(mapIcon);
@ -1638,18 +1666,26 @@ namespace MinecraftClient.Protocol.Handlers
hasMotd = dataTypes.ReadNextBool(packetData);
if (hasMotd)
motd = ChatParser.ParseText(dataTypes.ReadNextString(packetData));
motd = ChatParser.ParseText(dataTypes.ReadNextChat(packetData));
}
else
{
hasMotd = true;
motd = ChatParser.ParseText(dataTypes.ReadNextString(packetData));
motd = ChatParser.ParseText(dataTypes.ReadNextChat(packetData));
}
var iconBase64 = "-";
var hasIcon = dataTypes.ReadNextBool(packetData);
if (hasIcon)
iconBase64 = dataTypes.ReadNextString(packetData);
{
if (protocolVersion < MC_1_20_2_Version)
iconBase64 = dataTypes.ReadNextString(packetData);
else
{
var pngData = dataTypes.ReadNextByteArray(packetData);
iconBase64 = Convert.ToBase64String(pngData);
}
}
var previewsChat = false;
if (protocolVersion < MC_1_19_3_Version)
@ -1849,7 +1885,7 @@ namespace MinecraftClient.Protocol.Handlers
// Actions bit 5: update display name
if ((actionBitset & 1 << 5) <= 0) continue;
player.DisplayName = dataTypes.ReadNextBool(packetData)
? dataTypes.ReadNextString(packetData)
? dataTypes.ReadNextChat(packetData)
: null;
}
}
@ -1995,7 +2031,7 @@ namespace MinecraftClient.Protocol.Handlers
// Skip optional tooltip for each tab-complete resul`t
if (dataTypes.ReadNextBool(packetData))
dataTypes.SkipNextString(packetData);
dataTypes.ReadNextChat(packetData);
}
handler.OnAutoCompleteDone(oldTransactionId, autocompleteResult);
@ -2009,7 +2045,7 @@ namespace MinecraftClient.Protocol.Handlers
return pForge.HandlePluginMessage(channel, packetData, ref currentDimension);
case PacketTypesIn.Disconnect:
handler.OnConnectionLost(ChatBot.DisconnectReason.InGameKick,
ChatParser.ParseText(dataTypes.ReadNextString(packetData)));
ChatParser.ParseText(dataTypes.ReadNextChat(packetData)));
return false;
case PacketTypesIn.SetCompression:
if (protocolVersion is >= MC_1_8_Version and < MC_1_9_Version)
@ -2026,7 +2062,7 @@ namespace MinecraftClient.Protocol.Handlers
.ToUpper();
var inventoryType =
(ContainerTypeOld)Enum.Parse(typeof(ContainerTypeOld), type);
var title = dataTypes.ReadNextString(packetData);
var title = dataTypes.ReadNextChat(packetData);
var slots = dataTypes.ReadNextByte(packetData);
Container inventory = new(windowId, inventoryType, ChatParser.ParseText(title));
handler.OnInventoryOpen(windowId, inventory);
@ -2036,7 +2072,7 @@ namespace MinecraftClient.Protocol.Handlers
// MC 1.14 or greater
var windowId = dataTypes.ReadNextVarInt(packetData);
var windowType = dataTypes.ReadNextVarInt(packetData);
var title = dataTypes.ReadNextString(packetData);
var title = dataTypes.ReadNextChat(packetData);
Container inventory = new(windowId, windowType, ChatParser.ParseText(title));
handler.OnInventoryOpen(windowId, inventory);
}
@ -2120,34 +2156,18 @@ namespace MinecraftClient.Protocol.Handlers
}
break;
case PacketTypesIn.RemoveResourcePack:
if (dataTypes.ReadNextBool(packetData)) // Has UUID
dataTypes.ReadNextUUID(packetData); // UUID
break;
case PacketTypesIn.ResourcePackSend:
var url = dataTypes.ReadNextString(packetData);
var hash = dataTypes.ReadNextString(packetData);
var forced = true; // Assume forced for MC 1.16 and below
if (protocolVersion >= MC_1_17_Version)
{
forced = dataTypes.ReadNextBool(packetData);
var hasPromptMessage =
dataTypes.ReadNextBool(packetData); // Has Prompt Message (Boolean) - 1.17 and above
if (hasPromptMessage)
dataTypes.SkipNextString(
packetData); // Prompt Message (Optional Chat) - 1.17 and above
}
HandleResourcePackPacket(packetData);
break;
case PacketTypesIn.ResetScore:
dataTypes.ReadNextString(packetData); // Entity Name
if (dataTypes.ReadNextBool(packetData)) // Has Objective Name
dataTypes.ReadNextString(packetData); // Objective Name
// Some server plugins may send invalid resource packs to probe the client and we need to ignore them (issue #1056)
if (!url.StartsWith("http") && hash.Length != 40) // Some server may have null hash value
break;
//Send back "accepted" and "successfully loaded" responses for plugins or server config making use of resource pack mandatory
var responseHeader = Array.Empty<byte>();
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
break;
case PacketTypesIn.SpawnEntity:
if (handler.GetEntityHandlingEnabled())
@ -2396,7 +2416,7 @@ namespace MinecraftClient.Protocol.Handlers
// Also make a palette for field? Will be a lot of work
var healthField = protocolVersion switch
{
> MC_1_20_2_Version => throw new NotImplementedException(Translations
> MC_1_20_4_Version => throw new NotImplementedException(Translations
.exception_palette_healthfield),
// 1.17 and above
>= MC_1_17_Version => 9,
@ -2482,15 +2502,29 @@ namespace MinecraftClient.Protocol.Handlers
var explosionStrength = dataTypes.ReadNextFloat(packetData);
var explosionBlockCount = protocolVersion >= MC_1_17_Version
? dataTypes.ReadNextVarInt(packetData)
: dataTypes.ReadNextInt(packetData);
: dataTypes.ReadNextInt(packetData); // Record count
// Records
for (var i = 0; i < explosionBlockCount; i++)
dataTypes.ReadData(3, packetData);
// Maybe use in the future when the physics are implemented
var playerVelocityX = dataTypes.ReadNextFloat(packetData);
var playerVelocityY = dataTypes.ReadNextFloat(packetData);
var playerVelocityZ = dataTypes.ReadNextFloat(packetData);
dataTypes.ReadNextFloat(packetData); // Player Motion X
dataTypes.ReadNextFloat(packetData); // Player Motion Y
dataTypes.ReadNextFloat(packetData); // Player Motion Z
if (protocolVersion >= MC_1_20_4_Version)
{
dataTypes.ReadNextVarInt(packetData); // Block Interaction
dataTypes.ReadParticleData(packetData, itemPalette); // Small Explosion Particles
dataTypes.ReadParticleData(packetData, itemPalette); // Large Explosion Particles
// Explosion Sound
dataTypes.ReadNextString(packetData); // Sound Name
var hasFixedRange = dataTypes.ReadNextBool(packetData);
if (hasFixedRange)
dataTypes.ReadNextFloat(packetData); // Range
}
handler.OnExplosion(explosionLocation, explosionStrength, explosionBlockCount);
break;
@ -2498,30 +2532,63 @@ namespace MinecraftClient.Protocol.Handlers
handler.OnHeldItemChange(dataTypes.ReadNextByte(packetData)); // Slot
break;
case PacketTypesIn.ScoreboardObjective:
var objectiveName2 = dataTypes.ReadNextString(packetData);
var objectiveName = dataTypes.ReadNextString(packetData);
var mode = dataTypes.ReadNextByte(packetData);
var objectiveValue = string.Empty;
var type2 = -1;
var objectiveType = -1;
var numberFormat = 0;
if (mode is 0 or 2)
{
objectiveValue = dataTypes.ReadNextString(packetData);
type2 = dataTypes.ReadNextVarInt(packetData);
objectiveValue = dataTypes.ReadNextChat(packetData);
objectiveType = dataTypes.ReadNextVarInt(packetData);
if (protocolVersion >= MC_1_20_4_Version)
{
if (dataTypes.ReadNextBool(packetData)) // Has Number Format
numberFormat = dataTypes.ReadNextVarInt(packetData); // Number Format
}
}
handler.OnScoreboardObjective(objectiveName2, mode, objectiveValue, type2);
handler.OnScoreboardObjective(objectiveName, mode, objectiveValue, objectiveType, numberFormat);
break;
case PacketTypesIn.UpdateScore:
var entityName = dataTypes.ReadNextString(packetData);
var action3 = protocolVersion >= MC_1_18_2_Version
? dataTypes.ReadNextVarInt(packetData)
: dataTypes.ReadNextByte(packetData);
var action3 = 0;
var objectiveName3 = string.Empty;
var value = -1;
if (action3 != 1 || protocolVersion >= MC_1_8_Version)
objectiveName3 = dataTypes.ReadNextString(packetData);
if (action3 != 1)
value = dataTypes.ReadNextVarInt(packetData);
handler.OnUpdateScore(entityName, action3, objectiveName3, value);
var objectiveValue2 = -1;
var objectiveDisplayName3 = string.Empty;
var numberFormat2 = 0;
if (protocolVersion >= MC_1_20_4_Version)
{
objectiveName3 = dataTypes.ReadNextString(packetData); // Objective Name
objectiveValue2 = dataTypes.ReadNextVarInt(packetData); // Value
if (dataTypes.ReadNextBool(packetData)) // Has Display Name
objectiveDisplayName3 =
ChatParser.ParseText(dataTypes.ReadNextString(packetData)); // Has Display Name
if (dataTypes.ReadNextBool(packetData)) // Has Number Format
numberFormat2 = dataTypes.ReadNextVarInt(packetData); // Number Format
}
else
{
action3 = protocolVersion >= MC_1_18_2_Version
? dataTypes.ReadNextVarInt(packetData)
: dataTypes.ReadNextByte(packetData);
if (action3 != 1 || protocolVersion >= MC_1_8_Version)
objectiveName3 = dataTypes.ReadNextString(packetData);
if (action3 != 1)
objectiveValue2 = dataTypes.ReadNextVarInt(packetData);
}
handler.OnUpdateScore(entityName, action3, objectiveName3, objectiveDisplayName3, objectiveValue2,
numberFormat2);
break;
case PacketTypesIn.BlockChangedAck:
handler.OnBlockChangeAck(dataTypes.ReadNextVarInt(packetData));
@ -2567,6 +2634,11 @@ namespace MinecraftClient.Protocol.Handlers
break;*/
case PacketTypesIn.SetTickingState:
dataTypes.ReadNextFloat(packetData);
dataTypes.ReadNextBool(packetData);
break;
default:
return false; //Ignored packet
}
@ -2635,7 +2707,7 @@ namespace MinecraftClient.Protocol.Handlers
{
SendPacket(packetPalette.GetOutgoingIdByType(packet), packetData);
}
/// <summary>
/// Send a configuration packet to the server. Packet ID, compression, and encryption will be handled automatically.
/// </summary>
@ -4176,7 +4248,7 @@ namespace MinecraftClient.Protocol.Handlers
}
}
public bool SendAnimation(int animation, int playerid)
public bool SendAnimation(int animation, int playerId)
{
try
{
@ -4187,7 +4259,7 @@ namespace MinecraftClient.Protocol.Handlers
switch (protocolVersion)
{
case < MC_1_8_Version:
packet.AddRange(DataTypes.GetInt(playerid));
packet.AddRange(DataTypes.GetInt(playerId));
packet.Add(1); // Swing arm
break;
case < MC_1_9_Version:
@ -4424,10 +4496,8 @@ namespace MinecraftClient.Protocol.Handlers
return false;
}
}
else
{
return false;
}
return false;
}
public bool SendRenameItem(string itemName)

View file

@ -417,21 +417,13 @@ namespace MinecraftClient.Protocol.Handlers
case 5:
// FML 3
// Server Config: FMLHandshakeMessages.java > S2CModData > decode()
// [ Size ][ VarInt ]
// [ Mod Data List ][ Array ] [ Mod Id ][ String ]
// [ Display Name ][ String ]
// [ Version ][ String ]
//
// We're ignoring this packet in MCC
/*
// Uncomment this code block if needed
var size = dataTypes.ReadNextVarInt(packetData);
Dictionary<string, string> modsData = new();
for (int i = 0; i < size; i++)
{
var modId = dataTypes.ReadNextString(packetData);
var displayName = dataTypes.ReadNextString(packetData);
var version = dataTypes.ReadNextString(packetData);
modsData.Add(modId, displayName + ":" + version);
}
*/
if (Settings.Config.Logging.DebugMessages)
{
ConsoleIO.WriteLineFormatted("§8" + "Received FML3 Server Mod Data List");
@ -441,20 +433,11 @@ namespace MinecraftClient.Protocol.Handlers
case 6:
// FML 3
// Server Config: FMLHandshakeMessages.java > S2CChannelMismatchData > decode()
//
// [ Size ][ VarInt ]
// [ Mismatched Mod List ][ Array ] [ Mod Id ][ String ]
// [ Version ][ String ]
// We're ignoring this packet in MCC
/*
// Uncomment this code block if needed
Dictionary<string, string> mismatchedMods = new();
var size0 = dataTypes.ReadNextVarInt(packetData);
for (int i = 0; i < size0; i++)
{
var modId = dataTypes.ReadNextString(packetData);
var version = dataTypes.ReadNextString(packetData);
mismatchedMods.Add(modId, version);
}
*/
if (Settings.Config.Logging.DebugMessages)
{
ConsoleIO.WriteLineFormatted("§8" + "Received FML3 Server Mismatched Mods List");
@ -523,15 +506,15 @@ namespace MinecraftClient.Protocol.Handlers
/// </summary>
/// <param name="protocolVersion">Minecraft protocol version</param>
/// <returns>ForgeInfo item stating that Forge is enabled</returns>
/// <para>
/// 1.18 change the fml version to 3
/// https://github.com/MinecraftForge/MinecraftForge/commit/997d8e0aa28b831edcd712e59a96181d3b2117d4
/// </para>
public static ForgeInfo ServerForceForge(int protocolVersion)
{
if (ServerMayForceForge(protocolVersion))
{
// 1.17 is still FML2
// https://github.com/MinecraftForge/MinecraftForge/blob/50b5414033de82f46be23201db50484f36c37d4f/src/main/java/net/minecraftforge/fmllegacy/network/FMLNetworkConstants.java#L37C29-L37C42
// 1.18 change the constant FMLNETVERSION to 3
// https://github.com/MinecraftForge/MinecraftForge/blob/cb12df41e13da576b781be695f80728b9594c25f/src/main/java/net/minecraftforge/network/NetworkConstants.java#L28
if (protocolVersion > ProtocolHandler.MCVer2ProtocolVersion("1.18"))
{
if (protocolVersion >= ProtocolHandler.MCVer2ProtocolVersion("1.18"))
{
return new ForgeInfo(FMLVersion.FML3);
}