diff --git a/Minecraft.Client/Level/MultiPlayerLevel.cpp b/Minecraft.Client/Level/MultiPlayerLevel.cpp index 0ed7f1b16..dc901fef7 100644 --- a/Minecraft.Client/Level/MultiPlayerLevel.cpp +++ b/Minecraft.Client/Level/MultiPlayerLevel.cpp @@ -702,12 +702,12 @@ void MultiPlayerLevel::animateTickDoWork() for( AUTO_VAR(it, chunksToAnimate.begin()); it != chunksToAnimate.end(); it++ ) { int packed = *it; - int cx = ( packed << 8 ) >> 24; - int cy = ( packed << 16 ) >> 24; - int cz = ( packed << 24 ) >> 24; - cx <<= 3; - cy <<= 3; - cz <<= 3; + // 4jcraft changed the extraction logic to be safe + // constantly shifting a signed integer + int cx = (int8_t)(packed >> 16) * 8; + int cy = (int8_t)(packed >> 8) * 8; + int cz = (int8_t)packed * 8; + int x = cx + random->nextInt(8); int y = cy + random->nextInt(8); int z = cz + random->nextInt(8); diff --git a/Minecraft.Client/Level/ServerLevel.cpp b/Minecraft.Client/Level/ServerLevel.cpp index f4e5d5aeb..ae949c831 100644 --- a/Minecraft.Client/Level/ServerLevel.cpp +++ b/Minecraft.Client/Level/ServerLevel.cpp @@ -475,7 +475,8 @@ void ServerLevel::tickTiles() // 4J - changes here brought forrward from 1.2.3 if (random->nextInt(16) == 0) { - randValue = randValue * 3 + addend; + //4jcraft added cast to unsigned + randValue = (unsigned)randValue * 3 + (unsigned)addend; int val = (randValue >> 2); int x = (val & 15); int z = ((val >> 8) & 15); @@ -1414,7 +1415,8 @@ int ServerLevel::runUpdate(void* lpParam) for (int j = 0; j < 80; j++) { - m_randValue[iLev] = m_randValue[iLev] * 3 + m_level[iLev]->addend; + // 4jcraft added cast to unsigned + m_randValue[iLev] = (unsigned) m_randValue[iLev] * 3 + (unsigned) m_level[iLev]->addend; int val = (m_randValue[iLev] >> 2); int x = (val & 15); if( ( x < minx ) || ( x > maxx ) ) continue; diff --git a/Minecraft.Client/Platform/Common/Tutorial/Tutorial.cpp b/Minecraft.Client/Platform/Common/Tutorial/Tutorial.cpp index 28cac32c2..9d44b000d 100644 --- a/Minecraft.Client/Platform/Common/Tutorial/Tutorial.cpp +++ b/Minecraft.Client/Platform/Common/Tutorial/Tutorial.cpp @@ -343,6 +343,9 @@ Tutorial::Tutorial(int iPad, bool isFullTutorial /*= false*/) : m_iPad( iPad ) m_bHasTickedOnce = false; m_firstTickTime = 0; + // 4jcraft added, not initialized + m_bSceneIsSplitscreen = false; + m_lastMessage = NULL; lastMessageTime = 0; @@ -1258,7 +1261,7 @@ void Tutorial::tick() else { // if we've changed mode, we may need to change scene - if(m_bSceneIsSplitscreen!=(app.GetLocalPlayerCount()>1)) + if(m_bSceneIsSplitscreen != (app.GetLocalPlayerCount() > 1)) { #ifdef _XBOX app.TutorialSceneNavigateBack(m_iPad); diff --git a/Minecraft.Client/Player/ServerPlayer.cpp b/Minecraft.Client/Player/ServerPlayer.cpp index d7eae5841..9f7081106 100644 --- a/Minecraft.Client/Player/ServerPlayer.cpp +++ b/Minecraft.Client/Player/ServerPlayer.cpp @@ -45,6 +45,9 @@ ServerPlayer::ServerPlayer(MinecraftServer *server, Level *level, const std::wst m_enteredEndExitPortal = false; lastCarried = ItemInstanceArray(5); viewDistance = 10; + + // 4jcraft added (0 initialized) + m_lastDamageSource = eTelemetryChallenges_Unknown; // gameMode->player = this; // 4J - removed to avoid use of shared_from_this in ctor, now set up externally this->gameMode = gameMode; @@ -540,7 +543,7 @@ void ServerPlayer::doTickB(bool ignorePortal) if (getHealth() != lastSentHealth || lastSentFood != foodData.getFoodLevel() || ((foodData.getSaturationLevel() == 0) != lastFoodSaturationZero)) { - // 4J Stu - Added m_lastDamageSource for telemetry + // 4J Stu - Added m_lastDamageSource for telemetry //4jcraft, nice but you never initialized it connection->send( std::shared_ptr( new SetHealthPacket(getHealth(), foodData.getFoodLevel(), foodData.getSaturationLevel(), m_lastDamageSource) ) ); lastSentHealth = getHealth(); lastSentFood = foodData.getFoodLevel(); diff --git a/Minecraft.World/AI/Navigation/Node.cpp b/Minecraft.World/AI/Navigation/Node.cpp index 061471362..a9c24caab 100644 --- a/Minecraft.World/AI/Navigation/Node.cpp +++ b/Minecraft.World/AI/Navigation/Node.cpp @@ -30,7 +30,8 @@ hash(createHash(x, y, z)) int Node::createHash(const int x, const int y, const int z) { - return (y & 0xff) | ((x & 0x7fff) << 8) | ((z & 0x7fff) << 24) | ((x < 0) ? 0x0080000000 : 0) | ((z < 0) ? 0x0000008000 : 0); + // 4jcraft added cast to higher value to be representable after shift + return (y & 0xff) | (((int64_t)x & 0x7fff) << 8) | (((int64_t)z & 0x7fff) << 24) | ((x < 0) ? 0x0080000000 : 0) | ((z < 0) ? 0x0000008000 : 0); } float Node::distanceTo(Node *to) @@ -72,4 +73,4 @@ bool Node::inOpenSet() std::wstring Node::toString() { return _toString(x) + L", " + _toString(y) + L", " + _toString(z); -} \ No newline at end of file +} diff --git a/Minecraft.World/Network/Packets/ChunkTilesUpdatePacket.cpp b/Minecraft.World/Network/Packets/ChunkTilesUpdatePacket.cpp index 48ecbf33a..d1e6cdae2 100644 --- a/Minecraft.World/Network/Packets/ChunkTilesUpdatePacket.cpp +++ b/Minecraft.World/Network/Packets/ChunkTilesUpdatePacket.cpp @@ -54,8 +54,9 @@ void ChunkTilesUpdatePacket::read(DataInputStream *dis) //throws IOException #ifdef _LARGE_WORLDS xc = dis->readShort(); zc = dis->readShort(); - xc = ( xc << 16 ) >> 16; - zc = ( zc << 16 ) >> 16; + // 4jcraft changed shift back and forth to a down cast + xc = (int16_t) xc; + zc = (int16_t) zc; #else xc = dis->read(); zc = dis->read(); diff --git a/Minecraft.World/Util/JavaIntHash.h b/Minecraft.World/Util/JavaIntHash.h index 7a1ba7710..ca79c038f 100644 --- a/Minecraft.World/Util/JavaIntHash.h +++ b/Minecraft.World/Util/JavaIntHash.h @@ -9,11 +9,12 @@ struct IntKeyHash { int operator() (const int &k) const { - int h = k; + // 4jcraft added h to be unsigned, to not cast it later + unsigned int h = k; h += ~(h << 9); - h ^= (((unsigned int)h) >> 14); + h ^= (h >> 14); h += (h << 4); - h ^= (((unsigned int)h) >> 10); + h ^= (h >> 10); return h; } }; diff --git a/Minecraft.World/Util/Random.cpp b/Minecraft.World/Util/Random.cpp index 10f58d938..509189a8f 100644 --- a/Minecraft.World/Util/Random.cpp +++ b/Minecraft.World/Util/Random.cpp @@ -88,7 +88,7 @@ int Random::nextInt(int n) if ((n & -n) == n) // i.e., n is a power of 2 - // 4jcraft added casts to unsigned + // 4jcraft added casts to unsigned (and uint64) return (unsigned int)(((__uint64)next(31) * n) >> 31); // 4J Stu - Made __int64 instead of long int bits, val; @@ -96,7 +96,8 @@ int Random::nextInt(int n) { bits = next(31); val = bits % n; - } while(bits - val + (n-1) < 0); + // 4jcraft added a cast to prevent overflow + } while((int64_t) bits - val + (n-1) < 0); return val; }