diff options
-rw-r--r-- | src/Protocol/Protocol.h | 5 | ||||
-rw-r--r-- | src/Protocol/ProtocolRecognizer.cpp | 9 | ||||
-rw-r--r-- | src/Protocol/ProtocolRecognizer.h | 4 | ||||
-rw-r--r-- | src/Protocol/Protocol_1_11.cpp | 47 | ||||
-rw-r--r-- | src/Protocol/Protocol_1_11.h | 3 | ||||
-rw-r--r-- | src/Protocol/Protocol_1_13.cpp | 46 | ||||
-rw-r--r-- | src/Protocol/Protocol_1_13.h | 4 | ||||
-rw-r--r-- | src/Protocol/Protocol_1_8.cpp | 48 | ||||
-rw-r--r-- | src/Protocol/Protocol_1_8.h | 4 | ||||
-rw-r--r-- | src/Protocol/Protocol_1_9.cpp | 48 | ||||
-rw-r--r-- | src/Protocol/Protocol_1_9.h | 4 |
11 files changed, 217 insertions, 5 deletions
diff --git a/src/Protocol/Protocol.h b/src/Protocol/Protocol.h index c71b295ad..cad007f5c 100644 --- a/src/Protocol/Protocol.h +++ b/src/Protocol/Protocol.h @@ -14,6 +14,7 @@ #include "../Scoreboard.h" #include "../ByteBuffer.h" #include "../EffectID.h" +#include "../World.h" @@ -236,7 +237,6 @@ public: /** Returns the ServerID used for authentication through session.minecraft.net */ virtual AString GetAuthServerID(void) = 0; - protected: friend class cPacketizer; @@ -257,6 +257,9 @@ protected: /** Returns the protocol-specific packet ID given the protocol-agnostic packet enum. */ 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. */ virtual void SendData(const char * a_Data, size_t a_Size) = 0; diff --git a/src/Protocol/ProtocolRecognizer.cpp b/src/Protocol/ProtocolRecognizer.cpp index 17b42dae9..a572ea9c2 100644 --- a/src/Protocol/ProtocolRecognizer.cpp +++ b/src/Protocol/ProtocolRecognizer.cpp @@ -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) { // This is used only when handling the server ping diff --git a/src/Protocol/ProtocolRecognizer.h b/src/Protocol/ProtocolRecognizer.h index cca1facb3..da87ba6bd 100644 --- a/src/Protocol/ProtocolRecognizer.h +++ b/src/Protocol/ProtocolRecognizer.h @@ -141,7 +141,6 @@ public: virtual void SendData(const char * a_Data, size_t a_Size) override; - protected: /** The recognized protocol */ @@ -156,6 +155,9 @@ protected: /** Returns the protocol-specific packet ID given the protocol-agnostic packet enum. */ 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) void HandlePacketStatusRequest(); void HandlePacketStatusPing(); diff --git a/src/Protocol/Protocol_1_11.cpp b/src/Protocol/Protocol_1_11.cpp index 9aea81cc3..1346d64cf 100644 --- a/src/Protocol/Protocol_1_11.cpp +++ b/src/Protocol/Protocol_1_11.cpp @@ -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. Pkt.WriteBEUInt64(0); Pkt.WriteBEUInt64(a_Mob.GetUniqueID()); - Pkt.WriteVarInt32(static_cast<UInt32>(a_Mob.GetMobType())); + Pkt.WriteVarInt32(GetProtocolMobType(a_Mob.GetMobType())); Vector3d LastSentPos = a_Mob.GetLastSentPos(); Pkt.WriteBEDouble(LastSentPos.x); 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) { int BlockX, BlockY, BlockZ; diff --git a/src/Protocol/Protocol_1_11.h b/src/Protocol/Protocol_1_11.h index 362d4a310..71d0be827 100644 --- a/src/Protocol/Protocol_1_11.h +++ b/src/Protocol/Protocol_1_11.h @@ -37,6 +37,9 @@ public: protected: + /** Converts eMonsterType to protocol-specific mob IDs */ + virtual UInt32 GetProtocolMobType(eMonsterType a_MobType) override; + virtual void HandlePacketBlockPlace (cByteBuffer & a_ByteBuffer) override; virtual void HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) override; diff --git a/src/Protocol/Protocol_1_13.cpp b/src/Protocol/Protocol_1_13.cpp index f058e8d59..5aa23e763 100644 --- a/src/Protocol/Protocol_1_13.cpp +++ b/src/Protocol/Protocol_1_13.cpp @@ -26,6 +26,7 @@ Implements the 1.13 protocol classes: #include "../ClientHandle.h" #include "../Root.h" #include "../Server.h" +#include "../World.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) { HANDLE_PACKET_READ(a_ByteBuffer, ReadBEInt16, Int16, ItemType); diff --git a/src/Protocol/Protocol_1_13.h b/src/Protocol/Protocol_1_13.h index ee7c2e048..baafd3fd5 100644 --- a/src/Protocol/Protocol_1_13.h +++ b/src/Protocol/Protocol_1_13.h @@ -15,6 +15,7 @@ Declares the 1.13 protocol classes: #pragma once #include "Protocol_1_12.h" +#include "../World.h" @@ -72,6 +73,9 @@ protected: virtual void SendTabCompletionResults (const AStringVector & a_Results) 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 void WriteItem(cPacketizer & a_Pkt, const cItem & a_Item) override; virtual void WriteEntityMetadata(cPacketizer & a_Pkt, const cEntity & a_Entity) override; diff --git a/src/Protocol/Protocol_1_8.cpp b/src/Protocol/Protocol_1_8.cpp index 4d70eadfa..d381f0a42 100644 --- a/src/Protocol/Protocol_1_8.cpp +++ b/src/Protocol/Protocol_1_8.cpp @@ -23,6 +23,7 @@ Implements the 1.8 protocol classes: #include "../CompositeChat.h" #include "../Statistics.h" #include "../UUID.h" +#include "../World.h" #include "../WorldStorage/FastNBT.h" #include "../WorldStorage/EnchantmentSerializer.h" @@ -1347,7 +1348,7 @@ void cProtocol_1_8_0::SendSpawnMob(const cMonster & a_Mob) cPacketizer Pkt(*this, pktSpawnMob); 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(); Pkt.WriteFPInt(LastSentPos.x); 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) { switch (a_ObjectData) diff --git a/src/Protocol/Protocol_1_8.h b/src/Protocol/Protocol_1_8.h index e71c8fbe5..527db15b7 100644 --- a/src/Protocol/Protocol_1_8.h +++ b/src/Protocol/Protocol_1_8.h @@ -15,6 +15,7 @@ Declares the 1.8 protocol classes: #include "Protocol.h" #include "../ByteBuffer.h" +#include "../World.h" #include "../mbedTLS++/AesCfb128Decryptor.h" #include "../mbedTLS++/AesCfb128Encryptor.h" @@ -164,6 +165,9 @@ protected: /** Nobody inherits 1.8, so it doesn't use this method */ 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. Returns true if the packet was understood, false if it was an unknown packet */ diff --git a/src/Protocol/Protocol_1_9.cpp b/src/Protocol/Protocol_1_9.cpp index 9eb47fa26..eac539ce3 100644 --- a/src/Protocol/Protocol_1_9.cpp +++ b/src/Protocol/Protocol_1_9.cpp @@ -27,6 +27,7 @@ Implements the 1.9 protocol classes: #include "../StringCompression.h" #include "../CompositeChat.h" #include "../Statistics.h" +#include "../World.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. Pkt.WriteBEUInt64(0); 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(); Pkt.WriteBEDouble(LastSentPos.x); 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) { switch (a_ObjectData) diff --git a/src/Protocol/Protocol_1_9.h b/src/Protocol/Protocol_1_9.h index 793367734..b6b4ddffa 100644 --- a/src/Protocol/Protocol_1_9.h +++ b/src/Protocol/Protocol_1_9.h @@ -21,6 +21,7 @@ Declares the 1.9 protocol classes: #include "Protocol.h" #include "../ByteBuffer.h" +#include "../World.h" #include "../mbedTLS++/AesCfb128Decryptor.h" #include "../mbedTLS++/AesCfb128Encryptor.h" @@ -174,6 +175,9 @@ protected: /** Get the packet ID for a given packet */ 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. Returns true if the packet was understood, false if it was an unknown packet. */ virtual bool HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketType); |