mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-11-07 17:36:07 +00:00
auto attack
This commit is contained in:
parent
758bc2ad49
commit
0b0e3c334e
13 changed files with 2065 additions and 15 deletions
|
|
@ -324,18 +324,16 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
/// </summary>
|
||||
private Dictionary<string, object> ReadNextNbt(List<byte> cache, bool root)
|
||||
{
|
||||
Dictionary<string, object> NbtData = new Dictionary<string, object>();
|
||||
|
||||
if (root)
|
||||
{
|
||||
if (cache[0] == 0) // TAG_End
|
||||
return NbtData;
|
||||
if (cache[0] != 10) // TAG_Compound
|
||||
throw new System.IO.InvalidDataException("Failed to decode NBT: Does not start with TAG_Compound");
|
||||
ReadNextByte(cache); // Tag type (TAG_Compound)
|
||||
ReadData(ReadNextUShort(cache), cache); // NBT root name
|
||||
}
|
||||
|
||||
Dictionary<string, object> NbtData = new Dictionary<string, object>();
|
||||
|
||||
while (true)
|
||||
{
|
||||
int fieldType = ReadNextByte(cache);
|
||||
|
|
@ -447,7 +445,7 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
if (protocolversion < Protocol18Handler.MC18Version)
|
||||
{
|
||||
byte[] length = BitConverter.GetBytes((short)array.Length);
|
||||
Array.Reverse(length); //Endianness
|
||||
Array.Reverse(length);
|
||||
return ConcatBytes(length, array);
|
||||
}
|
||||
else return ConcatBytes(GetVarInt(array.Length), array);
|
||||
|
|
@ -466,7 +464,7 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a byte array representing the given location encoded as an unsigned long
|
||||
/// Get a byte array representing the given location encoded as an unsigned short
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// A modulo will be applied if the location is outside the following ranges:
|
||||
|
|
@ -477,14 +475,11 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
/// <returns>Location representation as ulong</returns>
|
||||
public byte[] GetLocation(Location location)
|
||||
{
|
||||
byte[] locationBytes;
|
||||
if (protocolversion >= Protocol18Handler.MC114Version)
|
||||
{
|
||||
locationBytes = BitConverter.GetBytes(((((ulong)location.X) & 0x3FFFFFF) << 38) | ((((ulong)location.Z) & 0x3FFFFFF) << 12) | (((ulong)location.Y) & 0xFFF));
|
||||
return BitConverter.GetBytes(((((ulong)location.X) & 0x3FFFFFF) << 38) | ((((ulong)location.Z) & 0x3FFFFFF) << 12) | (((ulong)location.Y) & 0xFFF));
|
||||
}
|
||||
else locationBytes = BitConverter.GetBytes(((((ulong)location.X) & 0x3FFFFFF) << 38) | ((((ulong)location.Y) & 0xFFF) << 26) | (((ulong)location.Z) & 0x3FFFFFF));
|
||||
Array.Reverse(locationBytes); //Endianness
|
||||
return locationBytes;
|
||||
else return BitConverter.GetBytes(((((ulong)location.X) & 0x3FFFFFF) << 38) | ((((ulong)location.Y) & 0xFFF) << 26) | (((ulong)location.Z) & 0x3FFFFFF));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -10,6 +10,9 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
/// </summary>
|
||||
enum PacketIncomingType
|
||||
{
|
||||
// modified by reinforce
|
||||
SpawnEntity,
|
||||
SpawnLivingEntity,
|
||||
KeepAlive,
|
||||
JoinGame,
|
||||
ChatMessage,
|
||||
|
|
@ -30,6 +33,12 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
OpenWindow,
|
||||
WindowItems,
|
||||
SetSlot,
|
||||
UnknownPacket
|
||||
UnknownPacket,
|
||||
DestroyEntities,
|
||||
SetCooldown,
|
||||
EntityPosition,
|
||||
EntityPositionAndRotation,
|
||||
EntityProperties,
|
||||
TimeUpdate
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,9 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
TabComplete,
|
||||
PlayerPosition,
|
||||
PlayerPositionAndLook,
|
||||
TeleportConfirm
|
||||
TeleportConfirm,
|
||||
//modified by reinforce
|
||||
HeldItemChange,
|
||||
InteractEntity
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -733,5 +733,19 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
}
|
||||
catch { return false; }
|
||||
}
|
||||
|
||||
// reinforce
|
||||
public bool SendInteractEntityPacket(int EntityID, int type)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public bool SendInteractEntityPacket(int EntityID, int type, float X, float Y, float Z, int hand)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public bool SendInteractEntityPacket(int EntityID, int type, float X, float Y, float Z)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -191,7 +191,10 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
break;
|
||||
case PacketIncomingType.JoinGame:
|
||||
handler.OnGameJoined();
|
||||
dataTypes.ReadNextInt(packetData);
|
||||
// by reinforce
|
||||
// get client player EntityID
|
||||
int playerEntityID = dataTypes.ReadNextInt(packetData);
|
||||
handler.SetPlayerEntityID(playerEntityID);
|
||||
dataTypes.ReadNextByte(packetData);
|
||||
if (protocolversion >= MC191Version)
|
||||
this.currentDimension = dataTypes.ReadNextInt(packetData);
|
||||
|
|
@ -242,7 +245,9 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
float pitch = dataTypes.ReadNextFloat(packetData);
|
||||
byte locMask = dataTypes.ReadNextByte(packetData);
|
||||
|
||||
if (handler.GetTerrainEnabled())
|
||||
// player pos is needed for calculate entity distance
|
||||
// modified by reinforce
|
||||
if (handler.GetTerrainEnabled() || true)
|
||||
{
|
||||
if (protocolversion >= MC18Version)
|
||||
{
|
||||
|
|
@ -535,6 +540,98 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
SendPacket(PacketOutgoingType.ResourcePackStatus, dataTypes.ConcatBytes(responseHeader, dataTypes.GetVarInt(3))); //Accepted pack
|
||||
SendPacket(PacketOutgoingType.ResourcePackStatus, dataTypes.ConcatBytes(responseHeader, dataTypes.GetVarInt(0))); //Successfully loaded
|
||||
break;
|
||||
// modified by reinforce
|
||||
case PacketIncomingType.SpawnLivingEntity:
|
||||
if (login_phase) break;
|
||||
int EntityID = dataTypes.ReadNextVarInt(packetData);
|
||||
Guid EntityUUID = dataTypes.ReadNextUUID(packetData);
|
||||
int EntityType = dataTypes.ReadNextVarInt(packetData);
|
||||
Double X = dataTypes.ReadNextDouble(packetData);
|
||||
Double Y = dataTypes.ReadNextDouble(packetData);
|
||||
Double Z = dataTypes.ReadNextDouble(packetData);
|
||||
byte EntityYaw = dataTypes.ReadNextByte(packetData);
|
||||
byte EntityPitch = dataTypes.ReadNextByte(packetData);
|
||||
byte EntityHeadPitch = dataTypes.ReadNextByte(packetData);
|
||||
short VelocityX = dataTypes.ReadNextShort(packetData);
|
||||
short VelocityY = dataTypes.ReadNextShort(packetData);
|
||||
short VelocityZ = dataTypes.ReadNextShort(packetData);
|
||||
|
||||
Location EntityLocation = new Location(X, Y, Z);
|
||||
|
||||
|
||||
handler.OnSpawnLivingEntity(EntityID,EntityType,EntityUUID,EntityLocation);
|
||||
break;
|
||||
case PacketIncomingType.DestroyEntities:
|
||||
int EntityCount = dataTypes.ReadNextVarInt(packetData);
|
||||
int[] EntitiesList = new int[EntityCount];
|
||||
for(int i = 0; i < EntityCount; i++)
|
||||
{
|
||||
EntitiesList[i] = dataTypes.ReadNextVarInt(packetData);
|
||||
}
|
||||
handler.OnDestroyEntities(EntitiesList);
|
||||
break;
|
||||
case PacketIncomingType.SetCooldown:
|
||||
int _itemID = dataTypes.ReadNextVarInt(packetData);
|
||||
int tick = dataTypes.ReadNextVarInt(packetData);
|
||||
handler.OnSetCooldown(_itemID, tick);
|
||||
break;
|
||||
case PacketIncomingType.EntityPosition:
|
||||
EntityID = dataTypes.ReadNextVarInt(packetData);
|
||||
Double DeltaX = Convert.ToDouble(dataTypes.ReadNextShort(packetData));
|
||||
Double DeltaY = Convert.ToDouble(dataTypes.ReadNextShort(packetData));
|
||||
Double DeltaZ = Convert.ToDouble(dataTypes.ReadNextShort(packetData));
|
||||
bool OnGround = dataTypes.ReadNextBool(packetData);
|
||||
DeltaX = DeltaX / (128 * 32);
|
||||
DeltaY = DeltaY / (128 * 32);
|
||||
DeltaZ = DeltaZ / (128 * 32);
|
||||
handler.OnEntityPosition(EntityID, DeltaX, DeltaY, DeltaZ,OnGround);
|
||||
break;
|
||||
case PacketIncomingType.EntityPositionAndRotation:
|
||||
EntityID = dataTypes.ReadNextVarInt(packetData);
|
||||
DeltaX = Convert.ToDouble(dataTypes.ReadNextShort(packetData));
|
||||
DeltaY = Convert.ToDouble(dataTypes.ReadNextShort(packetData));
|
||||
DeltaZ = Convert.ToDouble(dataTypes.ReadNextShort(packetData));
|
||||
yaw = dataTypes.ReadNextByte(packetData);
|
||||
pitch = dataTypes.ReadNextByte(packetData);
|
||||
OnGround = dataTypes.ReadNextBool(packetData);
|
||||
DeltaX = DeltaX / (128 * 32);
|
||||
DeltaY = DeltaY / (128 * 32);
|
||||
DeltaZ = DeltaZ / (128 * 32);
|
||||
handler.OnEntityPosition(EntityID, DeltaX, DeltaY, DeltaZ, OnGround);
|
||||
break;
|
||||
case PacketIncomingType.EntityProperties:
|
||||
EntityID = dataTypes.ReadNextVarInt(packetData);
|
||||
int NumberOfProperties = dataTypes.ReadNextInt(packetData);
|
||||
Dictionary<string,Double> keys = new Dictionary<string,Double>();
|
||||
for(int i = 0; i < NumberOfProperties; i++)
|
||||
{
|
||||
string _key = dataTypes.ReadNextString(packetData);
|
||||
Double _value = dataTypes.ReadNextDouble(packetData);
|
||||
|
||||
|
||||
int NumberOfModifiers = dataTypes.ReadNextVarInt(packetData);
|
||||
//if (NumberOfModifiers == 0) continue;
|
||||
for(int j = 0; j < NumberOfModifiers; j++)
|
||||
{
|
||||
dataTypes.ReadNextUUID(packetData);
|
||||
Double amount = dataTypes.ReadNextDouble(packetData);
|
||||
byte operation = dataTypes.ReadNextByte(packetData);
|
||||
switch (operation)
|
||||
{
|
||||
case 0: _value += amount; break;
|
||||
case 1: _value += (amount / 100); break;
|
||||
case 2: _value *= amount; break;
|
||||
}
|
||||
}
|
||||
keys.Add(_key, _value);
|
||||
}
|
||||
handler.OnEntityProperties(EntityID, keys);
|
||||
break;
|
||||
case PacketIncomingType.TimeUpdate:
|
||||
long WorldAge = dataTypes.ReadNextLong(packetData);
|
||||
long TimeOfday = dataTypes.ReadNextLong(packetData);
|
||||
handler.OnTimeUpdate(WorldAge, TimeOfday);
|
||||
break;
|
||||
default:
|
||||
return false; //Ignored packet
|
||||
}
|
||||
|
|
@ -1023,5 +1120,29 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// reinforce
|
||||
public bool SendInteractEntityPacket(int EntityID, int type)
|
||||
{
|
||||
try
|
||||
{
|
||||
List<byte> fields = new List<byte>();
|
||||
fields.AddRange(dataTypes.GetVarInt(EntityID));
|
||||
fields.AddRange(dataTypes.GetVarInt(type));
|
||||
SendPacket(PacketOutgoingType.InteractEntity, fields);
|
||||
return true;
|
||||
}
|
||||
catch (SocketException) { return false; }
|
||||
catch (System.IO.IOException) { return false; }
|
||||
catch (ObjectDisposedException) { return false; }
|
||||
}
|
||||
public bool SendInteractEntityPacket(int EntityID, int type, float X, float Y, float Z, int hand)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public bool SendInteractEntityPacket(int EntityID, int type, float X, float Y, float Z)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -176,6 +176,9 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
{
|
||||
switch (packetID)
|
||||
{
|
||||
// modified by reinforce
|
||||
case 0x00: return PacketIncomingType.SpawnEntity;
|
||||
case 0x03: return PacketIncomingType.SpawnLivingEntity;
|
||||
case 0x21: return PacketIncomingType.KeepAlive;
|
||||
case 0x26: return PacketIncomingType.JoinGame;
|
||||
case 0x0F: return PacketIncomingType.ChatMessage;
|
||||
|
|
@ -194,6 +197,12 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
case 0x14: return PacketIncomingType.CloseWindow;
|
||||
case 0x15: return PacketIncomingType.WindowItems;
|
||||
case 0x17: return PacketIncomingType.SetSlot;
|
||||
case 0x38: return PacketIncomingType.DestroyEntities;
|
||||
case 0x18: return PacketIncomingType.SetCooldown;
|
||||
case 0x29: return PacketIncomingType.EntityPosition;
|
||||
case 0x2A: return PacketIncomingType.EntityPositionAndRotation;
|
||||
case 0x59: return PacketIncomingType.EntityProperties;
|
||||
case 0x4F: return PacketIncomingType.TimeUpdate;
|
||||
default: return PacketIncomingType.UnknownPacket;
|
||||
}
|
||||
}
|
||||
|
|
@ -301,6 +310,8 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
case PacketOutgoingType.PlayerPosition: return 0x11;
|
||||
case PacketOutgoingType.PlayerPositionAndLook: return 0x12;
|
||||
case PacketOutgoingType.TeleportConfirm: return 0x00;
|
||||
case PacketOutgoingType.HeldItemChange: return 0x23;
|
||||
case PacketOutgoingType.InteractEntity: return 0x0E;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -84,5 +84,10 @@ namespace MinecraftClient.Protocol
|
|||
/// <param name="data">packet Data</param>
|
||||
/// <returns>True if message was successfully sent</returns>
|
||||
bool SendPluginChannelPacket(string channel, byte[] data);
|
||||
|
||||
// by reinforce
|
||||
bool SendInteractEntityPacket(int EntityID, int type);
|
||||
bool SendInteractEntityPacket(int EntityID, int type, float X, float Y, float Z, int hand);
|
||||
bool SendInteractEntityPacket(int EntityID, int type, float X, float Y, float Z);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -125,5 +125,19 @@ namespace MinecraftClient.Protocol
|
|||
/// <param name="channel">The channel the message was sent on</param>
|
||||
/// <param name="data">The data from the channel</param>
|
||||
void OnPluginChannelMessage(string channel, byte[] data);
|
||||
|
||||
void OnSpawnLivingEntity(int EntityID, int EntityType, Guid UUID, Location location);
|
||||
|
||||
void OnDestroyEntities(int[] EntityID);
|
||||
|
||||
void OnSetCooldown(int itemID, int tick);
|
||||
|
||||
void OnEntityPosition(int EntityID, Double Dx, Double Dy, Double Dz,bool onGround);
|
||||
|
||||
void OnEntityProperties(int EntityID, Dictionary<string, Double> prop);
|
||||
|
||||
void OnTimeUpdate(long WorldAge, long TimeOfDay);
|
||||
|
||||
void SetPlayerEntityID(int EntityID);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue