1
0

Add protocol mob ID remapping (#4538)

This commit is contained in:
Mat 2020-03-29 18:54:37 +03:00 committed by GitHub
parent aa9a16b0c6
commit 31ace87d28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 217 additions and 5 deletions

View File

@ -14,6 +14,7 @@
#include "../Scoreboard.h" #include "../Scoreboard.h"
#include "../ByteBuffer.h" #include "../ByteBuffer.h"
#include "../EffectID.h" #include "../EffectID.h"
#include "../World.h"
@ -236,7 +237,6 @@ public:
/** Returns the ServerID used for authentication through session.minecraft.net */ /** Returns the ServerID used for authentication through session.minecraft.net */
virtual AString GetAuthServerID(void) = 0; virtual AString GetAuthServerID(void) = 0;
protected: protected:
friend class cPacketizer; friend class cPacketizer;
@ -257,6 +257,9 @@ protected:
/** Returns the protocol-specific packet ID given the protocol-agnostic packet enum. */ /** Returns the protocol-specific packet ID given the protocol-agnostic packet enum. */
virtual UInt32 GetPacketID(ePacketType a_Packet) = 0; virtual UInt32 GetPacketID(ePacketType a_Packet) = 0;
/** Converts eMonsterType to protocol-specific mob types */
virtual UInt32 GetProtocolMobType(eMonsterType a_MobType) = 0;
/** A generic data-sending routine, all outgoing packet data needs to be routed through this so that descendants may override it. */ /** A generic data-sending routine, all outgoing packet data needs to be routed through this so that descendants may override it. */
virtual void SendData(const char * a_Data, size_t a_Size) = 0; virtual void SendData(const char * a_Data, size_t a_Size) = 0;

View File

@ -1010,6 +1010,15 @@ AString cProtocolRecognizer::GetAuthServerID(void)
UInt32 cProtocolRecognizer::GetProtocolMobType(eMonsterType a_MobType)
{
return 0;
}
void cProtocolRecognizer::SendData(const char * a_Data, size_t a_Size) void cProtocolRecognizer::SendData(const char * a_Data, size_t a_Size)
{ {
// This is used only when handling the server ping // This is used only when handling the server ping

View File

@ -141,7 +141,6 @@ public:
virtual void SendData(const char * a_Data, size_t a_Size) override; virtual void SendData(const char * a_Data, size_t a_Size) override;
protected: protected:
/** The recognized protocol */ /** The recognized protocol */
@ -156,6 +155,9 @@ protected:
/** Returns the protocol-specific packet ID given the protocol-agnostic packet enum. */ /** Returns the protocol-specific packet ID given the protocol-agnostic packet enum. */
virtual UInt32 GetPacketID(ePacketType a_PacketType) override; virtual UInt32 GetPacketID(ePacketType a_PacketType) override;
/** Converts eMonsterType to protocol-specific mob types */
virtual UInt32 GetProtocolMobType(eMonsterType a_MobType) override;
// Packet handlers while in status state (m_InPingForUnrecognizedVersion == true) // Packet handlers while in status state (m_InPingForUnrecognizedVersion == true)
void HandlePacketStatusRequest(); void HandlePacketStatusRequest();
void HandlePacketStatusPing(); void HandlePacketStatusPing();

View File

@ -388,7 +388,7 @@ void cProtocol_1_11_0::SendSpawnMob(const cMonster & a_Mob)
// TODO: Bad way to write a UUID, and it's not a true UUID, but this is functional for now. // TODO: Bad way to write a UUID, and it's not a true UUID, but this is functional for now.
Pkt.WriteBEUInt64(0); Pkt.WriteBEUInt64(0);
Pkt.WriteBEUInt64(a_Mob.GetUniqueID()); Pkt.WriteBEUInt64(a_Mob.GetUniqueID());
Pkt.WriteVarInt32(static_cast<UInt32>(a_Mob.GetMobType())); Pkt.WriteVarInt32(GetProtocolMobType(a_Mob.GetMobType()));
Vector3d LastSentPos = a_Mob.GetLastSentPos(); Vector3d LastSentPos = a_Mob.GetLastSentPos();
Pkt.WriteBEDouble(LastSentPos.x); Pkt.WriteBEDouble(LastSentPos.x);
Pkt.WriteBEDouble(LastSentPos.y); Pkt.WriteBEDouble(LastSentPos.y);
@ -539,6 +539,51 @@ void cProtocol_1_11_0::SendTitleTimes(int a_FadeInTicks, int a_DisplayTicks, int
UInt32 cProtocol_1_11_0::GetProtocolMobType(eMonsterType a_MobType)
{
switch (a_MobType)
{
// Map invalid type to Giant for easy debugging (if this ever spawns, something has gone very wrong)
case mtInvalidType: return 52;
case mtBat: return 65;
case mtBlaze: return 61;
case mtCaveSpider: return 59;
case mtChicken: return 93;
case mtCow: return 92;
case mtCreeper: return 50;
case mtEnderDragon: return 63;
case mtEnderman: return 58;
case mtGhast: return 56;
case mtGiant: return 53;
case mtGuardian: return 68;
case mtHorse: return 100;
case mtIronGolem: return 99;
case mtMagmaCube: return 62;
case mtMooshroom: return 96;
case mtOcelot: return 98;
case mtPig: return 90;
case mtRabbit: return 101;
case mtSheep: return 91;
case mtSilverfish: return 60;
case mtSkeleton: return 51;
case mtSlime: return 55;
case mtSnowGolem: return 97;
case mtSpider: return 52;
case mtSquid: return 94;
case mtVillager: return 120;
case mtWitch: return 66;
case mtWither: return 64;
case mtWolf: return 95;
case mtZombie: return 54;
case mtZombiePigman: return 57;
}
UNREACHABLE("Unsupported mob type");
}
void cProtocol_1_11_0::HandlePacketBlockPlace(cByteBuffer & a_ByteBuffer) void cProtocol_1_11_0::HandlePacketBlockPlace(cByteBuffer & a_ByteBuffer)
{ {
int BlockX, BlockY, BlockZ; int BlockX, BlockY, BlockZ;

View File

@ -37,6 +37,9 @@ public:
protected: protected:
/** Converts eMonsterType to protocol-specific mob IDs */
virtual UInt32 GetProtocolMobType(eMonsterType a_MobType) override;
virtual void HandlePacketBlockPlace (cByteBuffer & a_ByteBuffer) override; virtual void HandlePacketBlockPlace (cByteBuffer & a_ByteBuffer) override;
virtual void HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) override; virtual void HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) override;

View File

@ -26,6 +26,7 @@ Implements the 1.13 protocol classes:
#include "../ClientHandle.h" #include "../ClientHandle.h"
#include "../Root.h" #include "../Root.h"
#include "../Server.h" #include "../Server.h"
#include "../World.h"
#include "../Bindings/PluginManager.h" #include "../Bindings/PluginManager.h"
@ -395,6 +396,51 @@ void cProtocol_1_13::SendUpdateBlockEntity(cBlockEntity & a_BlockEntity)
UInt32 cProtocol_1_13::GetProtocolMobType(eMonsterType a_MobType)
{
switch (a_MobType)
{
// Map invalid type to Giant for easy debugging (if this ever spawns, something has gone very wrong)
case mtInvalidType: return 27;
case mtBat: return 3;
case mtBlaze: return 4;
case mtCaveSpider: return 6;
case mtChicken: return 7;
case mtCow: return 9;
case mtCreeper: return 10;
case mtEnderDragon: return 17;
case mtEnderman: return 18;
case mtGhast: return 26;
case mtGiant: return 27;
case mtGuardian: return 28;
case mtHorse: return 29;
case mtIronGolem: return 80;
case mtMagmaCube: return 38;
case mtMooshroom: return 47;
case mtOcelot: return 48;
case mtPig: return 51;
case mtRabbit: return 56;
case mtSheep: return 58;
case mtSilverfish: return 61;
case mtSkeleton: return 62;
case mtSlime: return 64;
case mtSnowGolem: return 66;
case mtSpider: return 69;
case mtSquid: return 70;
case mtVillager: return 79;
case mtWitch: return 82;
case mtWither: return 83;
case mtWolf: return 86;
case mtZombie: return 87;
case mtZombiePigman: return 53;
}
UNREACHABLE("Unsupported mob type");
}
bool cProtocol_1_13::ReadItem(cByteBuffer & a_ByteBuffer, cItem & a_Item, size_t a_KeepRemainingBytes) bool cProtocol_1_13::ReadItem(cByteBuffer & a_ByteBuffer, cItem & a_Item, size_t a_KeepRemainingBytes)
{ {
HANDLE_PACKET_READ(a_ByteBuffer, ReadBEInt16, Int16, ItemType); HANDLE_PACKET_READ(a_ByteBuffer, ReadBEInt16, Int16, ItemType);

View File

@ -15,6 +15,7 @@ Declares the 1.13 protocol classes:
#pragma once #pragma once
#include "Protocol_1_12.h" #include "Protocol_1_12.h"
#include "../World.h"
@ -72,6 +73,9 @@ protected:
virtual void SendTabCompletionResults (const AStringVector & a_Results) override; virtual void SendTabCompletionResults (const AStringVector & a_Results) override;
virtual void SendUpdateBlockEntity (cBlockEntity & a_BlockEntity) override; virtual void SendUpdateBlockEntity (cBlockEntity & a_BlockEntity) override;
/** Converts eMonsterType to protocol-specific mob types */
virtual UInt32 GetProtocolMobType(eMonsterType a_MobType) override;
virtual bool ReadItem(cByteBuffer & a_ByteBuffer, cItem & a_Item, size_t a_KeepRemainingBytes) override; virtual bool ReadItem(cByteBuffer & a_ByteBuffer, cItem & a_Item, size_t a_KeepRemainingBytes) override;
virtual void WriteItem(cPacketizer & a_Pkt, const cItem & a_Item) override; virtual void WriteItem(cPacketizer & a_Pkt, const cItem & a_Item) override;
virtual void WriteEntityMetadata(cPacketizer & a_Pkt, const cEntity & a_Entity) override; virtual void WriteEntityMetadata(cPacketizer & a_Pkt, const cEntity & a_Entity) override;

View File

@ -23,6 +23,7 @@ Implements the 1.8 protocol classes:
#include "../CompositeChat.h" #include "../CompositeChat.h"
#include "../Statistics.h" #include "../Statistics.h"
#include "../UUID.h" #include "../UUID.h"
#include "../World.h"
#include "../WorldStorage/FastNBT.h" #include "../WorldStorage/FastNBT.h"
#include "../WorldStorage/EnchantmentSerializer.h" #include "../WorldStorage/EnchantmentSerializer.h"
@ -1347,7 +1348,7 @@ void cProtocol_1_8_0::SendSpawnMob(const cMonster & a_Mob)
cPacketizer Pkt(*this, pktSpawnMob); cPacketizer Pkt(*this, pktSpawnMob);
Pkt.WriteVarInt32(a_Mob.GetUniqueID()); Pkt.WriteVarInt32(a_Mob.GetUniqueID());
Pkt.WriteBEUInt8(static_cast<Byte>(a_Mob.GetMobType())); Pkt.WriteBEUInt8(static_cast<Byte>(GetProtocolMobType(a_Mob.GetMobType())));
Vector3d LastSentPos = a_Mob.GetLastSentPos(); Vector3d LastSentPos = a_Mob.GetLastSentPos();
Pkt.WriteFPInt(LastSentPos.x); Pkt.WriteFPInt(LastSentPos.x);
Pkt.WriteFPInt(LastSentPos.y); Pkt.WriteFPInt(LastSentPos.y);
@ -1827,6 +1828,51 @@ int cProtocol_1_8_0::GetParticleID(const AString & a_ParticleName)
UInt32 cProtocol_1_8_0::GetProtocolMobType(eMonsterType a_MobType)
{
switch (a_MobType)
{
// Map invalid type to Giant for easy debugging (if this ever spawns, something has gone very wrong)
case mtInvalidType: return 52;
case mtBat: return 65;
case mtBlaze: return 61;
case mtCaveSpider: return 59;
case mtChicken: return 93;
case mtCow: return 92;
case mtCreeper: return 50;
case mtEnderDragon: return 63;
case mtEnderman: return 58;
case mtGhast: return 56;
case mtGiant: return 53;
case mtGuardian: return 68;
case mtHorse: return 100;
case mtIronGolem: return 99;
case mtMagmaCube: return 62;
case mtMooshroom: return 96;
case mtOcelot: return 98;
case mtPig: return 90;
case mtRabbit: return 101;
case mtSheep: return 91;
case mtSilverfish: return 60;
case mtSkeleton: return 51;
case mtSlime: return 55;
case mtSnowGolem: return 97;
case mtSpider: return 52;
case mtSquid: return 94;
case mtVillager: return 120;
case mtWitch: return 66;
case mtWither: return 64;
case mtWolf: return 95;
case mtZombie: return 54;
case mtZombiePigman: return 57;
}
UNREACHABLE("Unsupported mob type");
}
void cProtocol_1_8_0::FixItemFramePositions(int a_ObjectData, double & a_PosX, double & a_PosZ, double & a_Yaw) void cProtocol_1_8_0::FixItemFramePositions(int a_ObjectData, double & a_PosX, double & a_PosZ, double & a_Yaw)
{ {
switch (a_ObjectData) switch (a_ObjectData)

View File

@ -15,6 +15,7 @@ Declares the 1.8 protocol classes:
#include "Protocol.h" #include "Protocol.h"
#include "../ByteBuffer.h" #include "../ByteBuffer.h"
#include "../World.h"
#include "../mbedTLS++/AesCfb128Decryptor.h" #include "../mbedTLS++/AesCfb128Decryptor.h"
#include "../mbedTLS++/AesCfb128Encryptor.h" #include "../mbedTLS++/AesCfb128Encryptor.h"
@ -164,6 +165,9 @@ protected:
/** Nobody inherits 1.8, so it doesn't use this method */ /** Nobody inherits 1.8, so it doesn't use this method */
virtual UInt32 GetPacketID(ePacketType a_Packet) override; virtual UInt32 GetPacketID(ePacketType a_Packet) override;
/** Converts eMonsterType to protocol-specific mob types */
virtual UInt32 GetProtocolMobType(eMonsterType a_MobType) override;
/** Reads and handles the packet. The packet length and type have already been read. /** Reads and handles the packet. The packet length and type have already been read.
Returns true if the packet was understood, false if it was an unknown packet Returns true if the packet was understood, false if it was an unknown packet
*/ */

View File

@ -27,6 +27,7 @@ Implements the 1.9 protocol classes:
#include "../StringCompression.h" #include "../StringCompression.h"
#include "../CompositeChat.h" #include "../CompositeChat.h"
#include "../Statistics.h" #include "../Statistics.h"
#include "../World.h"
#include "../WorldStorage/FastNBT.h" #include "../WorldStorage/FastNBT.h"
@ -1408,7 +1409,7 @@ void cProtocol_1_9_0::SendSpawnMob(const cMonster & a_Mob)
// TODO: Bad way to write a UUID, and it's not a true UUID, but this is functional for now. // TODO: Bad way to write a UUID, and it's not a true UUID, but this is functional for now.
Pkt.WriteBEUInt64(0); Pkt.WriteBEUInt64(0);
Pkt.WriteBEUInt64(a_Mob.GetUniqueID()); Pkt.WriteBEUInt64(a_Mob.GetUniqueID());
Pkt.WriteBEUInt8(static_cast<Byte>(a_Mob.GetMobType())); Pkt.WriteBEUInt8(static_cast<Byte>(GetProtocolMobType(a_Mob.GetMobType())));
Vector3d LastSentPos = a_Mob.GetLastSentPos(); Vector3d LastSentPos = a_Mob.GetLastSentPos();
Pkt.WriteBEDouble(LastSentPos.x); Pkt.WriteBEDouble(LastSentPos.x);
Pkt.WriteBEDouble(LastSentPos.y); Pkt.WriteBEDouble(LastSentPos.y);
@ -1883,6 +1884,51 @@ int cProtocol_1_9_0::GetParticleID(const AString & a_ParticleName)
UInt32 cProtocol_1_9_0::GetProtocolMobType(eMonsterType a_MobType)
{
switch (a_MobType)
{
// Map invalid type to Giant for easy debugging (if this ever spawns, something has gone very wrong)
case mtInvalidType: return 52;
case mtBat: return 65;
case mtBlaze: return 61;
case mtCaveSpider: return 59;
case mtChicken: return 93;
case mtCow: return 92;
case mtCreeper: return 50;
case mtEnderDragon: return 63;
case mtEnderman: return 58;
case mtGhast: return 56;
case mtGiant: return 53;
case mtGuardian: return 68;
case mtHorse: return 100;
case mtIronGolem: return 99;
case mtMagmaCube: return 62;
case mtMooshroom: return 96;
case mtOcelot: return 98;
case mtPig: return 90;
case mtRabbit: return 101;
case mtSheep: return 91;
case mtSilverfish: return 60;
case mtSkeleton: return 51;
case mtSlime: return 55;
case mtSnowGolem: return 97;
case mtSpider: return 52;
case mtSquid: return 94;
case mtVillager: return 120;
case mtWitch: return 66;
case mtWither: return 64;
case mtWolf: return 95;
case mtZombie: return 54;
case mtZombiePigman: return 57;
}
UNREACHABLE("Unsupported mob type");
}
void cProtocol_1_9_0::FixItemFramePositions(int a_ObjectData, double & a_PosX, double & a_PosZ, double & a_Yaw) void cProtocol_1_9_0::FixItemFramePositions(int a_ObjectData, double & a_PosX, double & a_PosZ, double & a_Yaw)
{ {
switch (a_ObjectData) switch (a_ObjectData)

View File

@ -21,6 +21,7 @@ Declares the 1.9 protocol classes:
#include "Protocol.h" #include "Protocol.h"
#include "../ByteBuffer.h" #include "../ByteBuffer.h"
#include "../World.h"
#include "../mbedTLS++/AesCfb128Decryptor.h" #include "../mbedTLS++/AesCfb128Decryptor.h"
#include "../mbedTLS++/AesCfb128Encryptor.h" #include "../mbedTLS++/AesCfb128Encryptor.h"
@ -174,6 +175,9 @@ protected:
/** Get the packet ID for a given packet */ /** Get the packet ID for a given packet */
virtual UInt32 GetPacketID(ePacketType a_Packet) override; virtual UInt32 GetPacketID(ePacketType a_Packet) override;
/** Converts eMonsterType to protocol-specific mob IDs */
virtual UInt32 GetProtocolMobType(eMonsterType a_MobType) override;
/** Reads and handles the packet. The packet length and type have already been read. /** Reads and handles the packet. The packet length and type have already been read.
Returns true if the packet was understood, false if it was an unknown packet. */ Returns true if the packet was understood, false if it was an unknown packet. */
virtual bool HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketType); virtual bool HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketType);