diff options
Diffstat (limited to 'src/Protocol/Protocol_1_12.cpp')
-rw-r--r-- | src/Protocol/Protocol_1_12.cpp | 1111 |
1 files changed, 4 insertions, 1107 deletions
diff --git a/src/Protocol/Protocol_1_12.cpp b/src/Protocol/Protocol_1_12.cpp index a8e38a4e0..166078aef 100644 --- a/src/Protocol/Protocol_1_12.cpp +++ b/src/Protocol/Protocol_1_12.cpp @@ -985,360 +985,6 @@ void cProtocol_1_12::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mo -void cProtocol_1_12::SendEntityRelMove(const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) -{ - ASSERT(m_State == 3); // In game mode? - - cPacketizer Pkt(*this, 0x26); // Entity Relative Move packet - Pkt.WriteVarInt32(a_Entity.GetUniqueID()); - // TODO: 1.9 changed these from chars to shorts, meaning that there can be more percision and data. Other code needs to be updated for that. - Pkt.WriteBEInt16(a_RelX * 128); - Pkt.WriteBEInt16(a_RelY * 128); - Pkt.WriteBEInt16(a_RelZ * 128); - Pkt.WriteBool(a_Entity.IsOnGround()); -} - - - - - -void cProtocol_1_12::SendEntityRelMoveLook(const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) -{ - ASSERT(m_State == 3); // In game mode? - - cPacketizer Pkt(*this, 0x27); // Entity Look And Relative Move packet - Pkt.WriteVarInt32(a_Entity.GetUniqueID()); - // TODO: 1.9 changed these from chars to shorts, meaning that there can be more percision and data. Other code needs to be updated for that. - Pkt.WriteBEInt16(a_RelX * 128); - Pkt.WriteBEInt16(a_RelY * 128); - Pkt.WriteBEInt16(a_RelZ * 128); - Pkt.WriteByteAngle(a_Entity.GetYaw()); - Pkt.WriteByteAngle(a_Entity.GetPitch()); - Pkt.WriteBool(a_Entity.IsOnGround()); -} - - - - - -void cProtocol_1_12::SendEntityLook(const cEntity & a_Entity) -{ - ASSERT(m_State == 3); // In game mode? - - cPacketizer Pkt(*this, 0x28); // Entity Look packet - Pkt.WriteVarInt32(a_Entity.GetUniqueID()); - Pkt.WriteByteAngle(a_Entity.GetYaw()); - Pkt.WriteByteAngle(a_Entity.GetPitch()); - Pkt.WriteBool(a_Entity.IsOnGround()); -} - - - - - -void cProtocol_1_12::SendDestroyEntity(const cEntity & a_Entity) -{ - ASSERT(m_State == 3); // In game mode? - - cPacketizer Pkt(*this, 0x31); // Destroy Entities packet - Pkt.WriteVarInt32(1); - Pkt.WriteVarInt32(a_Entity.GetUniqueID()); -} - - - - - -void cProtocol_1_12::SendRemoveEntityEffect(const cEntity & a_Entity, int a_EffectID) -{ - ASSERT(m_State == 3); // In game mode? - - cPacketizer Pkt(*this, 0x32); // Remove entity effect packet - Pkt.WriteVarInt32(a_Entity.GetUniqueID()); - Pkt.WriteBEUInt8(static_cast<UInt8>(a_EffectID)); -} - - - - - -void cProtocol_1_12::SendRespawn(eDimension a_Dimension) -{ - cPacketizer Pkt(*this, 0x34); // Respawn packet - cPlayer * Player = m_Client->GetPlayer(); - Pkt.WriteBEInt32(static_cast<Int32>(a_Dimension)); - Pkt.WriteBEUInt8(2); // TODO: Difficulty (set to Normal) - Pkt.WriteBEUInt8(static_cast<Byte>(Player->GetEffectiveGameMode())); - Pkt.WriteString("default"); -} - - - - - -void cProtocol_1_12::SendEntityHeadLook(const cEntity & a_Entity) -{ - ASSERT(m_State == 3); // In game mode? - - cPacketizer Pkt(*this, 0x35); // Entity Head Look packet - Pkt.WriteVarInt32(a_Entity.GetUniqueID()); - Pkt.WriteByteAngle(a_Entity.GetHeadYaw()); -} - - - - - -void cProtocol_1_12::SendCameraSetTo(const cEntity & a_Entity) -{ - cPacketizer Pkt(*this, 0x38); // Camera Packet (Attach the camera of a player at another entity in spectator mode) - Pkt.WriteVarInt32(a_Entity.GetUniqueID()); -} - - - - - -void cProtocol_1_12::SendDisplayObjective(const AString & a_Objective, cScoreboard::eDisplaySlot a_Display) -{ - ASSERT(m_State == 3); // In game mode? - - cPacketizer Pkt(*this, 0x3a); // Display scoreboard packet - Pkt.WriteBEUInt8(static_cast<UInt8>(a_Display)); - Pkt.WriteString(a_Objective); -} - - - - - -void cProtocol_1_12::SendEntityMetadata(const cEntity & a_Entity) -{ - ASSERT(m_State == 3); // In game mode? - - cPacketizer Pkt(*this, 0x3b); // Entity Metadata packet - Pkt.WriteVarInt32(a_Entity.GetUniqueID()); - WriteEntityMetadata(Pkt, a_Entity); - Pkt.WriteBEUInt8(0xff); // The termination byte -} - - - - - -void cProtocol_1_12::SendLeashEntity(const cEntity & a_Entity, const cEntity & a_EntityLeashedTo) -{ - ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x3c); // Set Attach Entity packet - Pkt.WriteBEUInt32(a_Entity.GetUniqueID()); - Pkt.WriteBEUInt32(a_EntityLeashedTo.GetUniqueID()); -} - - - - - -void cProtocol_1_12::SendUnleashEntity(const cEntity & a_Entity) -{ - ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x3c); // Set Attach Entity packet - Pkt.WriteBEUInt32(a_Entity.GetUniqueID()); - Pkt.WriteBEInt32(-1); // Unleash a_Entity -} - - - - - -void cProtocol_1_12::SendEntityVelocity(const cEntity & a_Entity) -{ - ASSERT(m_State == 3); // In game mode? - - cPacketizer Pkt(*this, 0x3d); // Entity Velocity packet - Pkt.WriteVarInt32(a_Entity.GetUniqueID()); - // 400 = 8000 / 20 ... Conversion from our speed in m / s to 8000 m / tick - Pkt.WriteBEInt16(static_cast<Int16>(a_Entity.GetSpeedX() * 400)); - Pkt.WriteBEInt16(static_cast<Int16>(a_Entity.GetSpeedY() * 400)); - Pkt.WriteBEInt16(static_cast<Int16>(a_Entity.GetSpeedZ() * 400)); -} - - - - - -void cProtocol_1_12::SendEntityEquipment(const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item) -{ - ASSERT(m_State == 3); // In game mode? - - cPacketizer Pkt(*this, 0x3e); // Entity Equipment packet - Pkt.WriteVarInt32(a_Entity.GetUniqueID()); - // Needs to be adjusted due to the insertion of offhand at slot 1 - if (a_SlotNum > 0) - { - a_SlotNum++; - } - Pkt.WriteVarInt32(static_cast<UInt32>(a_SlotNum)); - WriteItem(Pkt, a_Item); -} - - - - - -void cProtocol_1_12::SendExperience(void) -{ - ASSERT(m_State == 3); // In game mode? - - cPacketizer Pkt(*this, 0x3f); // Set Experience Packet - cPlayer * Player = m_Client->GetPlayer(); - Pkt.WriteBEFloat(Player->GetXpPercentage()); - Pkt.WriteVarInt32(static_cast<UInt32>(Player->GetXpLevel())); - Pkt.WriteVarInt32(static_cast<UInt32>(Player->GetCurrentXp())); -} - - - - - -void cProtocol_1_12::SendHealth(void) -{ - ASSERT(m_State == 3); // In game mode? - - cPacketizer Pkt(*this, 0x40); // Update Health packet - cPlayer * Player = m_Client->GetPlayer(); - Pkt.WriteBEFloat(static_cast<float>(Player->GetHealth())); - Pkt.WriteVarInt32(static_cast<UInt32>(Player->GetFoodLevel())); - Pkt.WriteBEFloat(static_cast<float>(Player->GetFoodSaturationLevel())); -} - - - - - -void cProtocol_1_12::SendScoreboardObjective(const AString & a_Name, const AString & a_DisplayName, Byte a_Mode) -{ - ASSERT(m_State == 3); // In game mode? - - cPacketizer Pkt(*this, 0x41); // Scoreboard objective packet - Pkt.WriteString(a_Name); - Pkt.WriteBEUInt8(a_Mode); - if ((a_Mode == 0) || (a_Mode == 2)) - { - Pkt.WriteString(a_DisplayName); - Pkt.WriteString("integer"); - } -} - - - - - -void cProtocol_1_12::SendAttachEntity(const cEntity & a_Entity, const cEntity & a_Vehicle) -{ - ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x42); // Set Passengers packet - Pkt.WriteVarInt32(a_Vehicle.GetUniqueID()); - Pkt.WriteVarInt32(1); // 1 passenger - Pkt.WriteVarInt32(a_Entity.GetUniqueID()); -} - - - - - -void cProtocol_1_12::SendDetachEntity(const cEntity & a_Entity, const cEntity & a_PreviousVehicle) -{ - ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x42); // Set Passengers packet - Pkt.WriteVarInt32(a_PreviousVehicle.GetUniqueID()); - Pkt.WriteVarInt32(0); // No passangers -} - - - - - -void cProtocol_1_12::SendScoreUpdate(const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode) -{ - ASSERT(m_State == 3); // In game mode? - - cPacketizer Pkt(*this, 0x44); // Update score packet - Pkt.WriteString(a_Player); - Pkt.WriteBEUInt8(a_Mode); - Pkt.WriteString(a_Objective); - - if (a_Mode != 1) - { - Pkt.WriteVarInt32(static_cast<UInt32>(a_Score)); - } -} - - - - - -void cProtocol_1_12::SendLogin(const cPlayer & a_Player, const cWorld & a_World) -{ - // Send the Join Game packet: - { - cServer * Server = cRoot::Get()->GetServer(); - cPacketizer Pkt(*this, 0x23); // Join Game packet - Pkt.WriteBEUInt32(a_Player.GetUniqueID()); - Pkt.WriteBEUInt8(static_cast<UInt8>(a_Player.GetEffectiveGameMode()) | (Server->IsHardcore() ? 0x08 : 0)); // Hardcore flag bit 4 - Pkt.WriteBEInt32(static_cast<Int32>(a_World.GetDimension())); - Pkt.WriteBEUInt8(2); // TODO: Difficulty (set to Normal) - Pkt.WriteBEUInt8(static_cast<UInt8>(Clamp<size_t>(Server->GetMaxPlayers(), 0, 255))); - Pkt.WriteString("default"); // Level type - wtf? - Pkt.WriteBool(false); // Reduced Debug Info - wtf? - } - - // Send the spawn position: - { - cPacketizer Pkt(*this, 0x45); // Spawn Position packet - Pkt.WritePosition64(FloorC(a_World.GetSpawnX()), FloorC(a_World.GetSpawnY()), FloorC(a_World.GetSpawnZ())); - } - - // Send the server difficulty: - { - cPacketizer Pkt(*this, 0x0d); // Server difficulty packet - Pkt.WriteBEInt8(1); - } - - // Send player abilities: - SendPlayerAbilities(); -} - - - - - -void cProtocol_1_12::SendUpdateBlockEntity(cBlockEntity & a_BlockEntity) -{ - ASSERT(m_State == 3); // In game mode? - - cPacketizer Pkt(*this, 0x09); // Update tile entity packet - Pkt.WritePosition64(a_BlockEntity.GetPosX(), a_BlockEntity.GetPosY(), a_BlockEntity.GetPosZ()); - - Byte Action = 0; - switch (a_BlockEntity.GetBlockType()) - { - case E_BLOCK_MOB_SPAWNER: Action = 1; break; // Update mob spawner spinny mob thing - case E_BLOCK_COMMAND_BLOCK: Action = 2; break; // Update command block text - case E_BLOCK_BEACON: Action = 3; break; // Update beacon entity - case E_BLOCK_HEAD: Action = 4; break; // Update Mobhead entity - case E_BLOCK_FLOWER_POT: Action = 5; break; // Update flower pot - case E_BLOCK_BED: Action = 11; break; // Update bed color - default: ASSERT(!"Unhandled or unimplemented BlockEntity update request!"); break; - } - Pkt.WriteBEUInt8(Action); - - WriteBlockEntity(Pkt, a_BlockEntity); -} - - - - - void cProtocol_1_12::HandlePacketCraftingBookData(cByteBuffer & a_ByteBuffer) { a_ByteBuffer.SkipRead(a_ByteBuffer.GetReadableSpace() - 1); @@ -1359,57 +1005,11 @@ void cProtocol_1_12::HandlePacketAdvancementTab(cByteBuffer & a_ByteBuffer) -void cProtocol_1_12::SendTimeUpdate(Int64 a_WorldAge, Int64 a_TimeOfDay, bool a_DoDaylightCycle) -{ - ASSERT(m_State == 3); // In game mode? - if (!a_DoDaylightCycle) - { - // When writing a "-" before the number the client ignores it but it will stop the client-side time expiration. - a_TimeOfDay = std::min(-a_TimeOfDay, -1LL); - } - - cPacketizer Pkt(*this, 0x46); // Time update packet - Pkt.WriteBEInt64(a_WorldAge); - Pkt.WriteBEInt64(a_TimeOfDay); -} - - - - - -void cProtocol_1_12::SendSetRawTitle(const AString & a_Title) -{ - ASSERT(m_State == 3); // In game mode? - - cPacketizer Pkt(*this, 0x47); // Title packet - Pkt.WriteVarInt32(0); // Set title - - Pkt.WriteString(a_Title); -} - - - - - -void cProtocol_1_12::SendSetRawSubTitle(const AString & a_SubTitle) -{ - ASSERT(m_State == 3); // In game mode? - - cPacketizer Pkt(*this, 0x47); // Title packet - Pkt.WriteVarInt32(1); // Set subtitle - - Pkt.WriteString(a_SubTitle); -} - - - - - void cProtocol_1_12::SendTitleTimes(int a_FadeInTicks, int a_DisplayTicks, int a_FadeOutTicks) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x47); // Title packet + cPacketizer Pkt(*this, GetPacketId(sendTitle)); // Title packet Pkt.WriteVarInt32(3); // Set title display times Pkt.WriteBEInt32(a_FadeInTicks); Pkt.WriteBEInt32(a_DisplayTicks); @@ -1424,7 +1024,7 @@ void cProtocol_1_12::SendHideTitle(void) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x47); // Title packet + cPacketizer Pkt(*this, GetPacketId(sendTitle)); // Title packet Pkt.WriteVarInt32(4); // Hide title } @@ -1436,7 +1036,7 @@ void cProtocol_1_12::SendResetTitle(void) { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x47); // Title packet + cPacketizer Pkt(*this, GetPacketId(sendTitle)); // Title packet Pkt.WriteVarInt32(5); // Reset title } @@ -1448,7 +1048,7 @@ void cProtocol_1_12::SendCollectEntity(const cEntity & a_Entity, const cPlayer & { ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x4a); // Collect Item packet + cPacketizer Pkt(*this, GetPacketId(sendCollectEntity)); // Collect Item packet Pkt.WriteVarInt32(a_Entity.GetUniqueID()); Pkt.WriteVarInt32(a_Player.GetUniqueID()); Pkt.WriteVarInt32(static_cast<UInt32>(a_Count)); @@ -1458,83 +1058,6 @@ void cProtocol_1_12::SendCollectEntity(const cEntity & a_Entity, const cPlayer & -void cProtocol_1_12::SendTeleportEntity(const cEntity & a_Entity) -{ - ASSERT(m_State == 3); // In game mode? - - cPacketizer Pkt(*this, 0x4b); // Entity teleport packet - Pkt.WriteVarInt32(a_Entity.GetUniqueID()); - Pkt.WriteBEDouble(a_Entity.GetPosX()); - Pkt.WriteBEDouble(a_Entity.GetPosY()); - Pkt.WriteBEDouble(a_Entity.GetPosZ()); - Pkt.WriteByteAngle(a_Entity.GetYaw()); - Pkt.WriteByteAngle(a_Entity.GetPitch()); - Pkt.WriteBool(a_Entity.IsOnGround()); -} - - - - - -void cProtocol_1_12::SendEntityProperties(const cEntity & a_Entity) -{ - ASSERT(m_State == 3); // In game mode? - - - cPacketizer Pkt(*this, 0x4d); // Entity Properties packet - Pkt.WriteVarInt32(a_Entity.GetUniqueID()); - WriteEntityProperties(Pkt, a_Entity); -} - - - - - -void cProtocol_1_12::SendPlayerMaxSpeed(void) -{ - ASSERT(m_State == 3); // In game mode? - - cPacketizer Pkt(*this, 0x4d); // Entity Properties - cPlayer * Player = m_Client->GetPlayer(); - Pkt.WriteVarInt32(Player->GetUniqueID()); - Pkt.WriteBEInt32(1); // Count - Pkt.WriteString("generic.movementSpeed"); - // The default game speed is 0.1, multiply that value by the relative speed: - Pkt.WriteBEDouble(0.1 * Player->GetNormalMaxSpeed()); - if (Player->IsSprinting()) - { - Pkt.WriteVarInt32(1); // Modifier count - Pkt.WriteBEUInt64(0x662a6b8dda3e4c1c); - Pkt.WriteBEUInt64(0x881396ea6097278d); // UUID of the modifier - Pkt.WriteBEDouble(Player->GetSprintingMaxSpeed() - Player->GetNormalMaxSpeed()); - Pkt.WriteBEUInt8(2); - } - else - { - Pkt.WriteVarInt32(0); // Modifier count - } -} - - - - - -void cProtocol_1_12::SendEntityEffect(const cEntity & a_Entity, int a_EffectID, int a_Amplifier, short a_Duration) -{ - ASSERT(m_State == 3); // In game mode? - - cPacketizer Pkt(*this, 0x4e); // Entity Effect packet - Pkt.WriteVarInt32(a_Entity.GetUniqueID()); - Pkt.WriteBEUInt8(static_cast<UInt8>(a_EffectID)); - Pkt.WriteBEUInt8(static_cast<UInt8>(a_Amplifier)); - Pkt.WriteVarInt32(static_cast<UInt32>(a_Duration)); - Pkt.WriteBool(false); // Hide particles -} - - - - - bool cProtocol_1_12::HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketType) { switch (m_State) @@ -1668,7 +1191,6 @@ void cProtocol_1_12_1::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["version"] = Version; ResponseValue["players"] = Players; ResponseValue["description"] = Description; - m_Client->ForgeAugmentServerListPing(ResponseValue); if (!Favicon.empty()) { ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); @@ -1684,631 +1206,6 @@ void cProtocol_1_12_1::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) -void cProtocol_1_12_1::SendRespawn(eDimension a_Dimension) -{ - cPacketizer Pkt(*this, 0x35); // Respawn packet - cPlayer * Player = m_Client->GetPlayer(); - Pkt.WriteBEInt32(static_cast<Int32>(a_Dimension)); - Pkt.WriteBEUInt8(2); // TODO: Difficulty (set to Normal) - Pkt.WriteBEUInt8(static_cast<Byte>(Player->GetEffectiveGameMode())); - Pkt.WriteString("default"); -} - - - - - -void cProtocol_1_12_1::SendPlayerListAddPlayer(const cPlayer & a_Player) -{ - ASSERT(m_State == 3); // In game mode? - - cPacketizer Pkt(*this, 0x2e); // Player List Item packet - Pkt.WriteVarInt32(0); - Pkt.WriteVarInt32(1); - Pkt.WriteUUID(a_Player.GetUUID()); - Pkt.WriteString(a_Player.GetPlayerListName()); - - const Json::Value & Properties = a_Player.GetClientHandle()->GetProperties(); - Pkt.WriteVarInt32(Properties.size()); - for (auto & Node : Properties) - { - Pkt.WriteString(Node.get("name", "").asString()); - Pkt.WriteString(Node.get("value", "").asString()); - AString Signature = Node.get("signature", "").asString(); - if (Signature.empty()) - { - Pkt.WriteBool(false); - } - else - { - Pkt.WriteBool(true); - Pkt.WriteString(Signature); - } - } - - Pkt.WriteVarInt32(static_cast<UInt32>(a_Player.GetGameMode())); - Pkt.WriteVarInt32(static_cast<UInt32>(a_Player.GetClientHandle()->GetPing())); - Pkt.WriteBool(false); -} - - - - - -void cProtocol_1_12_1::SendPlayerListRemovePlayer(const cPlayer & a_Player) -{ - ASSERT(m_State == 3); // In game mode? - - cPacketizer Pkt(*this, 0x2e); // Player List Item packet - Pkt.WriteVarInt32(4); - Pkt.WriteVarInt32(1); - Pkt.WriteUUID(a_Player.GetUUID()); -} - - - - - -void cProtocol_1_12_1::SendPlayerListUpdateGameMode(const cPlayer & a_Player) -{ - ASSERT(m_State == 3); // In game mode? - - cPacketizer Pkt(*this, 0x2e); // Player List Item packet - Pkt.WriteVarInt32(1); - Pkt.WriteVarInt32(1); - Pkt.WriteUUID(a_Player.GetUUID()); - Pkt.WriteVarInt32(static_cast<UInt32>(a_Player.GetGameMode())); -} - - - - - -void cProtocol_1_12_1::SendPlayerListUpdatePing(const cPlayer & a_Player) -{ - ASSERT(m_State == 3); // In game mode? - - auto ClientHandle = a_Player.GetClientHandlePtr(); - if (ClientHandle != nullptr) - { - cPacketizer Pkt(*this, 0x2e); // Player List Item packet - Pkt.WriteVarInt32(2); - Pkt.WriteVarInt32(1); - Pkt.WriteUUID(a_Player.GetUUID()); - Pkt.WriteVarInt32(static_cast<UInt32>(ClientHandle->GetPing())); - } -} - - - - - -void cProtocol_1_12_1::SendPlayerListUpdateDisplayName(const cPlayer & a_Player, const AString & a_CustomName) -{ - ASSERT(m_State == 3); // In game mode? - - cPacketizer Pkt(*this, 0x2e); // Player List Item packet - Pkt.WriteVarInt32(3); - Pkt.WriteVarInt32(1); - Pkt.WriteUUID(a_Player.GetUUID()); - - if (a_CustomName.empty()) - { - Pkt.WriteBool(false); - } - else - { - Pkt.WriteBool(true); - Pkt.WriteString(Printf("{\"text\":\"%s\"}", a_CustomName.c_str())); - } -} - - - - - -void cProtocol_1_12_1::SendPlayerAbilities(void) -{ - ASSERT(m_State == 3); // In game mode? - - cPacketizer Pkt(*this, 0x2c); // Player Abilities packet - Byte Flags = 0; - cPlayer * Player = m_Client->GetPlayer(); - if (Player->IsGameModeCreative()) - { - Flags |= 0x01; - Flags |= 0x08; // Godmode, used for creative - } - if (Player->IsFlying()) - { - Flags |= 0x02; - } - if (Player->CanFly()) - { - Flags |= 0x04; - } - Pkt.WriteBEUInt8(Flags); - Pkt.WriteBEFloat(static_cast<float>(0.05 * Player->GetFlyingMaxSpeed())); - Pkt.WriteBEFloat(static_cast<float>(0.1 * Player->GetNormalMaxSpeed())); -} - - - - - -void cProtocol_1_12_1::SendPlayerMoveLook(void) -{ - ASSERT(m_State == 3); // In game mode? - - cPacketizer Pkt(*this, 0x2f); // Player Position And Look packet - cPlayer * Player = m_Client->GetPlayer(); - Pkt.WriteBEDouble(Player->GetPosX()); - Pkt.WriteBEDouble(Player->GetPosY()); - Pkt.WriteBEDouble(Player->GetPosZ()); - Pkt.WriteBEFloat(static_cast<float>(Player->GetYaw())); - Pkt.WriteBEFloat(static_cast<float>(Player->GetPitch())); - Pkt.WriteBEUInt8(0); - Pkt.WriteVarInt32(++m_OutstandingTeleportId); - - // This teleport ID hasn't been confirmed yet - m_IsTeleportIdConfirmed = false; -} - - - - - -void cProtocol_1_12_1::SendUseBed(const cEntity & a_Entity, int a_BlockX, int a_BlockY, int a_BlockZ) -{ - ASSERT(m_State == 3); // In game mode? - - cPacketizer Pkt(*this, 0x30); // Use bed - Pkt.WriteVarInt32(a_Entity.GetUniqueID()); - Pkt.WritePosition64(a_BlockX, a_BlockY, a_BlockZ); -} - - - - - -void cProtocol_1_12_1::SendDestroyEntity(const cEntity & a_Entity) -{ - ASSERT(m_State == 3); // In game mode? - - cPacketizer Pkt(*this, 0x32); // Destroy Entities packet - Pkt.WriteVarInt32(1); - Pkt.WriteVarInt32(a_Entity.GetUniqueID()); -} - - - - - -void cProtocol_1_12_1::SendRemoveEntityEffect(const cEntity & a_Entity, int a_EffectID) -{ - ASSERT(m_State == 3); // In game mode? - - cPacketizer Pkt(*this, 0x33); // Remove entity effect packet - Pkt.WriteVarInt32(a_Entity.GetUniqueID()); - Pkt.WriteBEUInt8(static_cast<UInt8>(a_EffectID)); -} - - - - - -void cProtocol_1_12_1::SendEntityHeadLook(const cEntity & a_Entity) -{ - ASSERT(m_State == 3); // In game mode? - - cPacketizer Pkt(*this, 0x36); // Entity Head Look packet - Pkt.WriteVarInt32(a_Entity.GetUniqueID()); - Pkt.WriteByteAngle(a_Entity.GetHeadYaw()); -} - - - - - -void cProtocol_1_12_1::SendCameraSetTo(const cEntity & a_Entity) -{ - cPacketizer Pkt(*this, 0x39); // Camera packet (Attach the camera of a player at another entity in spectator mode) - Pkt.WriteVarInt32(a_Entity.GetUniqueID()); -} - - - - - -void cProtocol_1_12_1::SendDisplayObjective(const AString & a_Objective, cScoreboard::eDisplaySlot a_Display) -{ - ASSERT(m_State == 3); // In game mode? - - cPacketizer Pkt(*this, 0x3b); // Display Scoreboard packet - Pkt.WriteBEUInt8(static_cast<UInt8>(a_Display)); - Pkt.WriteString(a_Objective); -} - - - - - -void cProtocol_1_12_1::SendEntityMetadata(const cEntity & a_Entity) -{ - ASSERT(m_State == 3); // In game mode? - - cPacketizer Pkt(*this, 0x3c); // Entity Metadata packet - Pkt.WriteVarInt32(a_Entity.GetUniqueID()); - WriteEntityMetadata(Pkt, a_Entity); - Pkt.WriteBEUInt8(0xff); // The termination byte -} - - - - - -void cProtocol_1_12_1::SendLeashEntity(const cEntity & a_Entity, const cEntity & a_EntityLeashedTo) -{ - ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x3d); // Set Attach Entity packet - Pkt.WriteBEUInt32(a_Entity.GetUniqueID()); - Pkt.WriteBEUInt32(a_EntityLeashedTo.GetUniqueID()); -} - - - - - -void cProtocol_1_12_1::SendUnleashEntity(const cEntity & a_Entity) -{ - ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x3d); // Set Attach Entity packet - Pkt.WriteBEUInt32(a_Entity.GetUniqueID()); - Pkt.WriteBEInt32(-1); // Unleash a_Entity -} - - - - - -void cProtocol_1_12_1::SendEntityVelocity(const cEntity & a_Entity) -{ - ASSERT(m_State == 3); // In game mode? - - cPacketizer Pkt(*this, 0x3e); // Entity Velocity packet - Pkt.WriteVarInt32(a_Entity.GetUniqueID()); - // 400 = 8000 / 20 ... Conversion from our speed in m / s to 8000 m / tick - Pkt.WriteBEInt16(static_cast<Int16>(a_Entity.GetSpeedX() * 400)); - Pkt.WriteBEInt16(static_cast<Int16>(a_Entity.GetSpeedY() * 400)); - Pkt.WriteBEInt16(static_cast<Int16>(a_Entity.GetSpeedZ() * 400)); -} - - - - - -void cProtocol_1_12_1::SendEntityEquipment(const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item) -{ - ASSERT(m_State == 3); // In game mode? - - cPacketizer Pkt(*this, 0x3f); // Entity Equipment packet - Pkt.WriteVarInt32(a_Entity.GetUniqueID()); - // Needs to be adjusted due to the insertion of offhand at slot 1 - if (a_SlotNum > 0) - { - a_SlotNum++; - } - Pkt.WriteVarInt32(static_cast<UInt32>(a_SlotNum)); - WriteItem(Pkt, a_Item); -} - - - - - -void cProtocol_1_12_1::SendExperience(void) -{ - ASSERT(m_State == 3); // In game mode? - - cPacketizer Pkt(*this, 0x40); // Set Experience packet - cPlayer * Player = m_Client->GetPlayer(); - Pkt.WriteBEFloat(Player->GetXpPercentage()); - Pkt.WriteVarInt32(static_cast<UInt32>(Player->GetXpLevel())); - Pkt.WriteVarInt32(static_cast<UInt32>(Player->GetCurrentXp())); -} - - - - - -void cProtocol_1_12_1::SendHealth(void) -{ - ASSERT(m_State == 3); // In game mode? - - cPacketizer Pkt(*this, 0x41); // Update Health packet - cPlayer * Player = m_Client->GetPlayer(); - Pkt.WriteBEFloat(static_cast<float>(Player->GetHealth())); - Pkt.WriteVarInt32(static_cast<UInt32>(Player->GetFoodLevel())); - Pkt.WriteBEFloat(static_cast<float>(Player->GetFoodSaturationLevel())); -} - - - - - -void cProtocol_1_12_1::SendScoreboardObjective(const AString & a_Name, const AString & a_DisplayName, Byte a_Mode) -{ - ASSERT(m_State == 3); // In game mode? - - cPacketizer Pkt(*this, 0x42); // Scoreboard Objective packet - Pkt.WriteString(a_Name); - Pkt.WriteBEUInt8(a_Mode); - if ((a_Mode == 0) || (a_Mode == 2)) - { - Pkt.WriteString(a_DisplayName); - Pkt.WriteString("integer"); - } -} - - - - - -void cProtocol_1_12_1::SendAttachEntity(const cEntity & a_Entity, const cEntity & a_Vehicle) -{ - ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x43); // Set Passengers packet - Pkt.WriteVarInt32(a_Vehicle.GetUniqueID()); - Pkt.WriteVarInt32(1); // 1 passenger - Pkt.WriteVarInt32(a_Entity.GetUniqueID()); -} - - - - - -void cProtocol_1_12_1::SendDetachEntity(const cEntity & a_Entity, const cEntity & a_PreviousVehicle) -{ - ASSERT(m_State == 3); // In game mode? - cPacketizer Pkt(*this, 0x43); // Set Passengers packet - Pkt.WriteVarInt32(a_PreviousVehicle.GetUniqueID()); - Pkt.WriteVarInt32(0); // No passangers -} - - - - - -void cProtocol_1_12_1::SendScoreUpdate(const AString & a_Objective, const AString & a_Player, cObjective::Score a_Score, Byte a_Mode) -{ - ASSERT(m_State == 3); // In game mode? - - cPacketizer Pkt(*this, 0x45); // Update Score packet - Pkt.WriteString(a_Player); - Pkt.WriteBEUInt8(a_Mode); - Pkt.WriteString(a_Objective); - - if (a_Mode != 1) - { - Pkt.WriteVarInt32(static_cast<UInt32>(a_Score)); - } -} - - - - - -void cProtocol_1_12_1::SendLogin(const cPlayer & a_Player, const cWorld & a_World) -{ - // Send the Join Game packet: - { - cServer * Server = cRoot::Get()->GetServer(); - cPacketizer Pkt(*this, 0x23); // Join Game packet - Pkt.WriteBEUInt32(a_Player.GetUniqueID()); - Pkt.WriteBEUInt8(static_cast<UInt8>(a_Player.GetEffectiveGameMode()) | (Server->IsHardcore() ? 0x08 : 0)); // Hardcore flag bit 4 - Pkt.WriteBEInt32(static_cast<Int32>(a_World.GetDimension())); - Pkt.WriteBEUInt8(2); // TODO: Difficulty (set to Normal) - Pkt.WriteBEUInt8(static_cast<UInt8>(Clamp<size_t>(Server->GetMaxPlayers(), 0, 255))); - Pkt.WriteString("default"); // Level type - wtf? - Pkt.WriteBool(false); // Reduced Debug Info - wtf? - } - - // Send the spawn position: - { - cPacketizer Pkt(*this, 0x46); // Spawn Position packet - Pkt.WritePosition64(FloorC(a_World.GetSpawnX()), FloorC(a_World.GetSpawnY()), FloorC(a_World.GetSpawnZ())); - } - - // Send the server difficulty: - { - cPacketizer Pkt(*this, 0x0d); // Server difficulty packet - Pkt.WriteBEInt8(1); - } - - // Send player abilities: - SendPlayerAbilities(); -} - - - - - -void cProtocol_1_12_1::SendTimeUpdate(Int64 a_WorldAge, Int64 a_TimeOfDay, bool a_DoDaylightCycle) -{ - ASSERT(m_State == 3); // In game mode? - if (!a_DoDaylightCycle) - { - // When writing a "-" before the number the client ignores it but it will stop the client-side time expiration. - a_TimeOfDay = std::min(-a_TimeOfDay, -1LL); - } - - cPacketizer Pkt(*this, 0x47); // Time update packet - Pkt.WriteBEInt64(a_WorldAge); - Pkt.WriteBEInt64(a_TimeOfDay); -} - - - - - -void cProtocol_1_12_1::SendSetRawTitle(const AString & a_Title) -{ - ASSERT(m_State == 3); // In game mode? - - cPacketizer Pkt(*this, 0x48); // Title packet - Pkt.WriteVarInt32(0); // Set title - - Pkt.WriteString(a_Title); -} - - - - - -void cProtocol_1_12_1::SendSetRawSubTitle(const AString & a_SubTitle) -{ - ASSERT(m_State == 3); // In game mode? - - cPacketizer Pkt(*this, 0x48); // Title packet - Pkt.WriteVarInt32(1); // Set subtitle - - Pkt.WriteString(a_SubTitle); -} - - - - - -void cProtocol_1_12_1::SendTitleTimes(int a_FadeInTicks, int a_DisplayTicks, int a_FadeOutTicks) -{ - ASSERT(m_State == 3); // In game mode? - - cPacketizer Pkt(*this, 0x48); // Title packet - Pkt.WriteVarInt32(3); // Set title display times - Pkt.WriteBEInt32(a_FadeInTicks); - Pkt.WriteBEInt32(a_DisplayTicks); - Pkt.WriteBEInt32(a_FadeOutTicks); -} - - - - - -void cProtocol_1_12_1::SendHideTitle(void) -{ - ASSERT(m_State == 3); // In game mode? - - cPacketizer Pkt(*this, 0x48); // Title packet - Pkt.WriteVarInt32(4); // Hide title -} - - - - - -void cProtocol_1_12_1::SendResetTitle(void) -{ - ASSERT(m_State == 3); // In game mode? - - cPacketizer Pkt(*this, 0x48); // Title packet - Pkt.WriteVarInt32(5); // Reset title -} - - - - - -void cProtocol_1_12_1::SendCollectEntity(const cEntity & a_Entity, const cPlayer & a_Player, int a_Count) -{ - ASSERT(m_State == 3); // In game mode? - - cPacketizer Pkt(*this, 0x4b); // Collect Item packet - Pkt.WriteVarInt32(a_Entity.GetUniqueID()); - Pkt.WriteVarInt32(a_Player.GetUniqueID()); - Pkt.WriteVarInt32(static_cast<UInt32>(a_Count)); -} - - - - - -void cProtocol_1_12_1::SendTeleportEntity(const cEntity & a_Entity) -{ - ASSERT(m_State == 3); // In game mode? - - cPacketizer Pkt(*this, 0x4c); // Entity teleport packet - Pkt.WriteVarInt32(a_Entity.GetUniqueID()); - Pkt.WriteBEDouble(a_Entity.GetPosX()); - Pkt.WriteBEDouble(a_Entity.GetPosY()); - Pkt.WriteBEDouble(a_Entity.GetPosZ()); - Pkt.WriteByteAngle(a_Entity.GetYaw()); - Pkt.WriteByteAngle(a_Entity.GetPitch()); - Pkt.WriteBool(a_Entity.IsOnGround()); -} - - - - - -void cProtocol_1_12_1::SendEntityProperties(const cEntity & a_Entity) -{ - ASSERT(m_State == 3); // In game mode? - - - cPacketizer Pkt(*this, 0x4e); // Entity Properties packet - Pkt.WriteVarInt32(a_Entity.GetUniqueID()); - WriteEntityProperties(Pkt, a_Entity); -} - - - - - -void cProtocol_1_12_1::SendEntityEffect(const cEntity & a_Entity, int a_EffectID, int a_Amplifier, short a_Duration) -{ - ASSERT(m_State == 3); // In game mode? - - cPacketizer Pkt(*this, 0x4f); // Entity Effect packet - Pkt.WriteVarInt32(a_Entity.GetUniqueID()); - Pkt.WriteBEUInt8(static_cast<UInt8>(a_EffectID)); - Pkt.WriteBEUInt8(static_cast<UInt8>(a_Amplifier)); - Pkt.WriteVarInt32(static_cast<UInt32>(a_Duration)); - Pkt.WriteBool(false); // Hide particles -} - - - - - -void cProtocol_1_12_1::SendPlayerMaxSpeed(void) -{ - ASSERT(m_State == 3); // In game mode? - - cPacketizer Pkt(*this, 0x4e); // Entity Properties - cPlayer * Player = m_Client->GetPlayer(); - Pkt.WriteVarInt32(Player->GetUniqueID()); - Pkt.WriteBEInt32(1); // Count - Pkt.WriteString("generic.movementSpeed"); - // The default game speed is 0.1, multiply that value by the relative speed: - Pkt.WriteBEDouble(0.1 * Player->GetNormalMaxSpeed()); - if (Player->IsSprinting()) - { - Pkt.WriteVarInt32(1); // Modifier count - Pkt.WriteBEUInt64(0x662a6b8dda3e4c1c); - Pkt.WriteBEUInt64(0x881396ea6097278d); // UUID of the modifier - Pkt.WriteBEDouble(Player->GetSprintingMaxSpeed() - Player->GetNormalMaxSpeed()); - Pkt.WriteBEUInt8(2); - } - else - { - Pkt.WriteVarInt32(0); // Modifier count - } -} - - - - - bool cProtocol_1_12_1::HandlePacket(cByteBuffer & a_ByteBuffer, UInt32 a_PacketType) { switch (m_State) |