mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-11-07 17:36:07 +00:00
Implemented "Click Window" for 1.18 (now sending the new required fields), formated few files with Visual Studio formatting. PS: left debug for people to see, I'll remove it once everything is working
This commit is contained in:
parent
b5c4cd7566
commit
3d8c112159
7 changed files with 94 additions and 29 deletions
|
|
@ -401,7 +401,7 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
{
|
||||
entityType = entityPalette.FromId(ReadNextByte(cache), living);
|
||||
}
|
||||
|
||||
|
||||
Double entityX = ReadNextDouble(cache);
|
||||
Double entityY = ReadNextDouble(cache);
|
||||
Double entityZ = ReadNextDouble(cache);
|
||||
|
|
@ -1028,6 +1028,23 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
return slotData.ToArray();
|
||||
}
|
||||
|
||||
public string ByteArrayToString(byte[] ba)
|
||||
{
|
||||
return BitConverter.ToString(ba).Replace("-", " ");
|
||||
}
|
||||
|
||||
public byte[] GetSlotsArray(Dictionary<int, Item> items, ItemPalette itemPalette)
|
||||
{
|
||||
byte[] slotsArray = new byte[items.Count];
|
||||
|
||||
foreach (KeyValuePair<int, Item> item in items)
|
||||
{
|
||||
slotsArray = ConcatBytes(slotsArray, GetShort((short)item.Key), GetItemSlot(item.Value, itemPalette));
|
||||
}
|
||||
|
||||
return slotsArray;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get protocol block face from Direction
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -94,7 +94,8 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
int nbr = 0;
|
||||
switch (id)
|
||||
{
|
||||
case 0x00: byte[] keepalive = new byte[5] { 0, 0, 0, 0, 0 };
|
||||
case 0x00:
|
||||
byte[] keepalive = new byte[5] { 0, 0, 0, 0, 0 };
|
||||
Receive(keepalive, 1, 4, SocketFlags.None);
|
||||
handler.OnServerKeepAlive();
|
||||
Send(keepalive); break;
|
||||
|
|
@ -183,11 +184,13 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
case 0xCF: if (protocolversion > 51) { readNextString(); readData(1); readNextString(); } readData(4); break;
|
||||
case 0xD0: if (protocolversion > 51) { readData(1); readNextString(); } break;
|
||||
case 0xD1: if (protocolversion > 51) { readNextTeamData(); } break;
|
||||
case 0xFA: string channel = readNextString();
|
||||
case 0xFA:
|
||||
string channel = readNextString();
|
||||
byte[] payload = readNextByteArray();
|
||||
handler.OnPluginChannelMessage(channel, payload);
|
||||
break;
|
||||
case 0xFF: string reason = readNextString();
|
||||
case 0xFF:
|
||||
string reason = readNextString();
|
||||
handler.OnConnectionLost(ChatBot.DisconnectReason.InGameKick, reason); break;
|
||||
default: return false; //unknown packet!
|
||||
}
|
||||
|
|
@ -666,12 +669,12 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
}
|
||||
catch (SocketException) { return false; }
|
||||
}
|
||||
|
||||
|
||||
public bool SendUpdateSign(Location location, string line1, string line2, string line3, string line4)
|
||||
{
|
||||
return false; //Currently not implemented
|
||||
}
|
||||
|
||||
|
||||
public bool SendBrandInfo(string brandInfo)
|
||||
{
|
||||
return false; //Only supported since MC 1.7
|
||||
|
|
@ -701,23 +704,23 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
{
|
||||
return false; //Currently not implemented
|
||||
}
|
||||
|
||||
|
||||
public bool SendInteractEntity(int EntityID, int type, int hand)
|
||||
{
|
||||
return false; //Currently not implemented
|
||||
}
|
||||
|
||||
|
||||
public bool UpdateCommandBlock(Location location, string command, CommandBlockMode mode, CommandBlockFlags flags)
|
||||
{
|
||||
return false; //Currently not implemented
|
||||
}
|
||||
|
||||
|
||||
public bool SendUseItem(int hand)
|
||||
{
|
||||
return false; //Currently not implemented
|
||||
}
|
||||
|
||||
public bool SendWindowAction(int windowId, int slotId, WindowActionType action, Item item)
|
||||
public bool SendWindowAction(int windowId, int slotId, WindowActionType action, Item item, Dictionary<int, Item> Items, int stateId)
|
||||
{
|
||||
return false; //Currently not implemented
|
||||
}
|
||||
|
|
@ -759,7 +762,8 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
/// <param name="data">packet Data</param>
|
||||
public bool SendPluginChannelPacket(string channel, byte[] data)
|
||||
{
|
||||
try {
|
||||
try
|
||||
{
|
||||
byte[] channelLength = BitConverter.GetBytes((short)channel.Length);
|
||||
Array.Reverse(channelLength);
|
||||
|
||||
|
|
|
|||
|
|
@ -850,7 +850,7 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
if (item != null)
|
||||
inventorySlots[slotId] = item;
|
||||
}
|
||||
handler.OnWindowItems(windowId, inventorySlots);
|
||||
handler.OnWindowItems(windowId, inventorySlots, stateId);
|
||||
}
|
||||
break;
|
||||
case PacketTypesIn.SetSlot:
|
||||
|
|
@ -1895,7 +1895,7 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
catch (ObjectDisposedException) { return false; }
|
||||
}
|
||||
|
||||
public bool SendWindowAction(int windowId, int slotId, WindowActionType action, Item item)
|
||||
public bool SendWindowAction(int windowId, int slotId, WindowActionType action, Item item, Dictionary<int, Item> items, int stateId)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
@ -1931,14 +1931,51 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
}
|
||||
|
||||
List<byte> packet = new List<byte>();
|
||||
|
||||
log.Info("Window id: " + windowId + " - State id: " + stateId + " - Slot id: " + slotId + " - Mode: " + mode);
|
||||
log.Info("Bytes > " + (byte)windowId + " - State id: " + dataTypes.ByteArrayToString(dataTypes.GetVarInt(stateId)) + " - Slot id: " + dataTypes.ByteArrayToString(dataTypes.GetVarInt(slotId)) + " - Mode: " + dataTypes.ByteArrayToString(dataTypes.GetVarInt(mode)));
|
||||
|
||||
packet.Add((byte)windowId);
|
||||
packet.AddRange(dataTypes.GetShort((short)slotId));
|
||||
|
||||
// 1.18+
|
||||
if (protocolversion > MC1171Version)
|
||||
{
|
||||
packet.AddRange(dataTypes.GetVarInt(stateId));
|
||||
packet.AddRange(dataTypes.GetShort((short)slotId));
|
||||
}
|
||||
// 1.17.1
|
||||
else if (protocolversion == MC1171Version)
|
||||
{
|
||||
packet.AddRange(dataTypes.GetShort((short)slotId));
|
||||
packet.AddRange(dataTypes.GetVarInt(stateId));
|
||||
}
|
||||
// Older
|
||||
else
|
||||
{
|
||||
packet.AddRange(dataTypes.GetShort((short)slotId));
|
||||
}
|
||||
|
||||
packet.Add(button);
|
||||
if (protocolversion < MC117Version) packet.AddRange(dataTypes.GetShort(actionNumber));
|
||||
if (protocolversion >= MC19Version)
|
||||
if (protocolversion >= MC1165Version)
|
||||
packet.AddRange(dataTypes.GetVarInt(mode));
|
||||
else packet.Add(mode);
|
||||
|
||||
// 1.17+
|
||||
if (protocolversion >= MC117Version)
|
||||
{
|
||||
byte[] arrayOfSlots = dataTypes.GetSlotsArray(items, itemPalette);
|
||||
|
||||
log.Info("Length: " + sizeof(byte) * arrayOfSlots.Length);
|
||||
log.Info("Array: " + dataTypes.ByteArrayToString(arrayOfSlots));
|
||||
|
||||
packet.AddRange(dataTypes.GetVarInt(sizeof(byte) * arrayOfSlots.Length));
|
||||
packet.AddRange(arrayOfSlots);
|
||||
}
|
||||
|
||||
packet.AddRange(dataTypes.GetItemSlot(item, itemPalette));
|
||||
|
||||
log.Info("Packet data: " + dataTypes.ByteArrayToString(packet.ToArray()));
|
||||
|
||||
SendPacket(PacketTypesOut.ClickWindow, packet);
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue