From 514c4cf102f349bbb59fe2ec2e6ebd6cab3eeeb0 Mon Sep 17 00:00:00 2001 From: Revela Date: Fri, 13 Mar 2026 07:12:26 -0500 Subject: [PATCH] `smartcmd/MinecraftConsoles` and `itsRevela/MinecraftConsoles` network packet compatibility fix: LoginPacket.cpp: - read(): Extracts hardcore from bit 3 of gameType (gameType & 0x8), then masks it off (gameType & ~0x8) - write(): Encodes hardcore into gameType via gameType | (m_isHardcore ? 0x8 : 0) - Removed the separate readBoolean()/writeBoolean() for m_isHardcore - Removed trailing + sizeof(bool) from getEstimatedSize() RespawnPacket.cpp: - read(): Extracts hardcore from bit 3 of the playerGameType byte, then masks it off before passing to GameType::byId() - write(): Encodes hardcore into the playerGameType byte via getId() | (m_isHardcore ? 0x8 : 0) - Removed the separate readBoolean()/writeBoolean() for m_isHardcore - Reverted getEstimatedSize() from 14+length to 13+length --- Minecraft.World/LoginPacket.cpp | 8 ++++---- Minecraft.World/RespawnPacket.cpp | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Minecraft.World/LoginPacket.cpp b/Minecraft.World/LoginPacket.cpp index 74b6d8da..37ab70a3 100644 --- a/Minecraft.World/LoginPacket.cpp +++ b/Minecraft.World/LoginPacket.cpp @@ -109,6 +109,8 @@ void LoginPacket::read(DataInputStream *dis) //throws IOException } seed = dis->readLong(); gameType = dis->readInt(); + m_isHardcore = (gameType & 0x8) != 0; + gameType = gameType & ~0x8; dimension = dis->readByte(); mapHeight = dis->readByte(); maxPlayers = dis->readByte(); @@ -130,7 +132,6 @@ void LoginPacket::read(DataInputStream *dis) //throws IOException m_xzSize = dis->readShort(); m_hellScale = dis->read(); #endif - m_isHardcore = dis->readBoolean(); app.DebugPrintf("LoginPacket::read - Difficulty = %d\n",difficulty); } @@ -148,7 +149,7 @@ void LoginPacket::write(DataOutputStream *dos) //throws IOException writeUtf(m_pLevelType->getGeneratorName(), dos); } dos->writeLong(seed); - dos->writeInt(gameType); + dos->writeInt(gameType | (m_isHardcore ? 0x8 : 0)); dos->writeByte(dimension); dos->writeByte(mapHeight); dos->writeByte(maxPlayers); @@ -168,7 +169,6 @@ void LoginPacket::write(DataOutputStream *dos) //throws IOException dos->writeShort(m_xzSize); dos->write(m_hellScale); #endif - dos->writeBoolean(m_isHardcore); } void LoginPacket::handle(PacketListener *listener) @@ -184,5 +184,5 @@ int LoginPacket::getEstimatedSize() length = static_cast(m_pLevelType->getGeneratorName().length()); } - return static_cast(sizeof(int) + userName.length() + 4 + 6 + sizeof(int64_t) + sizeof(char) + sizeof(int) + (2 * sizeof(PlayerUID)) + 1 + sizeof(char) + sizeof(BYTE) + sizeof(bool) + sizeof(bool) + length + sizeof(unsigned int) + sizeof(bool)); + return static_cast(sizeof(int) + userName.length() + 4 + 6 + sizeof(int64_t) + sizeof(char) + sizeof(int) + (2 * sizeof(PlayerUID)) + 1 + sizeof(char) + sizeof(BYTE) + sizeof(bool) + sizeof(bool) + length + sizeof(unsigned int)); } diff --git a/Minecraft.World/RespawnPacket.cpp b/Minecraft.World/RespawnPacket.cpp index 174dd720..7e456af0 100644 --- a/Minecraft.World/RespawnPacket.cpp +++ b/Minecraft.World/RespawnPacket.cpp @@ -45,7 +45,9 @@ void RespawnPacket::handle(PacketListener *listener) void RespawnPacket::read(DataInputStream *dis) //throws IOException { dimension = dis->readByte(); - playerGameType = GameType::byId(dis->readByte()); + int rawGameType = dis->readByte(); + m_isHardcore = (rawGameType & 0x8) != 0; + playerGameType = GameType::byId(rawGameType & ~0x8); mapHeight = dis->readShort(); wstring typeName = readUtf(dis, 16); m_pLevelType = LevelType::getLevelType(typeName); @@ -61,7 +63,6 @@ void RespawnPacket::read(DataInputStream *dis) //throws IOException m_xzSize = dis->readShort(); m_hellScale = dis->read(); #endif - m_isHardcore = dis->readBoolean(); app.DebugPrintf("RespawnPacket::read - Difficulty = %d\n",difficulty); } @@ -69,7 +70,7 @@ void RespawnPacket::read(DataInputStream *dis) //throws IOException void RespawnPacket::write(DataOutputStream *dos) //throws IOException { dos->writeByte(dimension); - dos->writeByte(playerGameType->getId()); + dos->writeByte(playerGameType->getId() | (m_isHardcore ? 0x8 : 0)); dos->writeShort(mapHeight); if (m_pLevelType == nullptr) { @@ -87,7 +88,6 @@ void RespawnPacket::write(DataOutputStream *dos) //throws IOException dos->writeShort(m_xzSize); dos->write(m_hellScale); #endif - dos->writeBoolean(m_isHardcore); } int RespawnPacket::getEstimatedSize() @@ -97,5 +97,5 @@ int RespawnPacket::getEstimatedSize() { length = static_cast(m_pLevelType->getGeneratorName().length()); } - return 14+length; + return 13+length; }