From 66644937930502611f1b68f7fbb75b1052e94adc Mon Sep 17 00:00:00 2001 From: lag <115616336+lag@users.noreply.github.com> Date: Fri, 6 Mar 2026 11:20:23 -0600 Subject: [PATCH] Multiplayer 8 to max byte increase. Made-with: Cursor --- Minecraft.Client/ClientConnection.cpp | 3 +- Minecraft.Client/PendingConnection.cpp | 4 +- Minecraft.Client/PlayerList.cpp | 18 +++++-- Minecraft.Client/PlayerList.h | 2 +- Minecraft.Client/PlayerRenderer.cpp | 51 ++++++++++++++----- Minecraft.Client/PlayerRenderer.h | 3 -- .../Windows64/Network/WinsockNetLayer.cpp | 6 +-- .../Windows64/Network/WinsockNetLayer.h | 4 +- Minecraft.World/PlayerIO.h | 2 +- Minecraft.World/x64headers/extraX64.h | 2 +- 10 files changed, 63 insertions(+), 32 deletions(-) diff --git a/Minecraft.Client/ClientConnection.cpp b/Minecraft.Client/ClientConnection.cpp index 9b9bb86a7..fd4f064f2 100644 --- a/Minecraft.Client/ClientConnection.cpp +++ b/Minecraft.Client/ClientConnection.cpp @@ -830,8 +830,9 @@ void ClientConnection::handleAddPlayer(shared_ptr packet) // Current Win64 path: identify QNet player by name and attach packet XUID. if (matchedQNetPlayer == NULL) { - for (BYTE smallId = 0; smallId < MINECRAFT_NET_MAX_PLAYERS; ++smallId) + for (int i = 0; i < MINECRAFT_NET_MAX_PLAYERS; ++i) { + BYTE smallId = static_cast(i); INetworkPlayer* np = g_NetworkManager.GetPlayerBySmallId(smallId); if (np == NULL) continue; diff --git a/Minecraft.Client/PendingConnection.cpp b/Minecraft.Client/PendingConnection.cpp index 72b8f3825..29ab7c281 100644 --- a/Minecraft.Client/PendingConnection.cpp +++ b/Minecraft.Client/PendingConnection.cpp @@ -136,7 +136,9 @@ void PendingConnection::sendPreLoginResponse() else #endif { - connection->send( shared_ptr( new PreLoginPacket(L"-", ugcXuids, ugcXuidCount, ugcFriendsOnlyBits, server->m_ugcPlayersVersion,szUniqueMapName,app.GetGameHostOption(eGameHostOption_All),hostIndex, server->m_texturePackId) ) ); + DWORD cappedCount = (ugcXuidCount > 255u) ? 255u : static_cast(ugcXuidCount); + BYTE cappedHostIndex = (hostIndex >= 255u) ? 254 : static_cast(hostIndex); + connection->send( shared_ptr( new PreLoginPacket(L"-", ugcXuids, cappedCount, ugcFriendsOnlyBits, server->m_ugcPlayersVersion,szUniqueMapName,app.GetGameHostOption(eGameHostOption_All),cappedHostIndex, server->m_texturePackId) ) ); } } diff --git a/Minecraft.Client/PlayerList.cpp b/Minecraft.Client/PlayerList.cpp index 42724a4f4..8fa013d47 100644 --- a/Minecraft.Client/PlayerList.cpp +++ b/Minecraft.Client/PlayerList.cpp @@ -79,7 +79,7 @@ PlayerList::~PlayerList() DeleteCriticalSection(&m_closePlayersCS); } -void PlayerList::placeNewPlayer(Connection *connection, shared_ptr player, shared_ptr packet) +bool PlayerList::placeNewPlayer(Connection *connection, shared_ptr player, shared_ptr packet) { CompoundTag *playerTag = load(player); @@ -129,13 +129,13 @@ void PlayerList::placeNewPlayer(Connection *connection, shared_ptr ServerLevel *level = server->getLevel(player->dimension); - DWORD playerIndex = 0; + DWORD playerIndex = (DWORD)MINECRAFT_NET_MAX_PLAYERS; { bool usedIndexes[MINECRAFT_NET_MAX_PLAYERS]; ZeroMemory( &usedIndexes, MINECRAFT_NET_MAX_PLAYERS * sizeof(bool) ); - for (auto& player : players ) + for (auto& p : players ) { - usedIndexes[player->getPlayerIndex()] = true; + usedIndexes[p->getPlayerIndex()] = true; } for(unsigned int i = 0; i < MINECRAFT_NET_MAX_PLAYERS; ++i) { @@ -146,6 +146,12 @@ void PlayerList::placeNewPlayer(Connection *connection, shared_ptr } } } + if (playerIndex >= (unsigned int)MINECRAFT_NET_MAX_PLAYERS) + { + connection->send(shared_ptr(new DisconnectPacket(DisconnectPacket::eDisconnect_ServerFull))); + connection->sendAndQuit(); + return false; + } player->setPlayerIndex( playerIndex ); player->setCustomSkin( packet->m_playerSkinId ); player->setCustomCape( packet->m_playerCapeId ); @@ -233,8 +239,9 @@ void PlayerList::placeNewPlayer(Connection *connection, shared_ptr addPlayerToReceiving( player ); + int maxPlayersForPacket = getMaxPlayers() > 255 ? 255 : getMaxPlayers(); playerConnection->send( shared_ptr( new LoginPacket(L"", player->entityId, level->getLevelData()->getGenerator(), level->getSeed(), player->gameMode->getGameModeForPlayer()->getId(), - (byte) level->dimension->id, (byte) level->getMaxBuildHeight(), (byte) getMaxPlayers(), + (byte) level->dimension->id, (byte) level->getMaxBuildHeight(), (byte) maxPlayersForPacket, level->difficulty, TelemetryManager->GetMultiplayerInstanceID(), (BYTE)playerIndex, level->useNewSeaLevel(), player->getAllPlayerGamePrivileges(), level->getLevelData()->getXZSize(), level->getLevelData()->getHellScale() ) ) ); playerConnection->send( shared_ptr( new SetSpawnPositionPacket(spawnPos->x, spawnPos->y, spawnPos->z) ) ); @@ -296,6 +303,7 @@ void PlayerList::placeNewPlayer(Connection *connection, shared_ptr } } } + return true; } void PlayerList::updateEntireScoreboard(ServerScoreboard *scoreboard, shared_ptr player) diff --git a/Minecraft.Client/PlayerList.h b/Minecraft.Client/PlayerList.h index 6a6ee94c9..03ed2398b 100644 --- a/Minecraft.Client/PlayerList.h +++ b/Minecraft.Client/PlayerList.h @@ -64,7 +64,7 @@ public: public: PlayerList(MinecraftServer *server); ~PlayerList(); - void placeNewPlayer(Connection *connection, shared_ptr player, shared_ptr packet); + bool placeNewPlayer(Connection *connection, shared_ptr player, shared_ptr packet); protected: void updateEntireScoreboard(ServerScoreboard *scoreboard, shared_ptr player); diff --git a/Minecraft.Client/PlayerRenderer.cpp b/Minecraft.Client/PlayerRenderer.cpp index 71c05067b..ff930a133 100644 --- a/Minecraft.Client/PlayerRenderer.cpp +++ b/Minecraft.Client/PlayerRenderer.cpp @@ -14,19 +14,44 @@ #include "..\Minecraft.World\net.minecraft.h" #include "..\Minecraft.World\StringHelpers.h" -const unsigned int PlayerRenderer::s_nametagColors[MINECRAFT_NET_MAX_PLAYERS] = +static unsigned int nametagColorForIndex(int index) { - 0xff000000, // WHITE (represents the "white" player, but using black as the colour) - 0xff33cc33, // GREEN - 0xffcc3333, // RED - 0xff3333cc, // BLUE -#ifndef __PSVITA__ // only 4 player on Vita - 0xffcc33cc, // PINK - 0xffcc6633, // ORANGE - 0xffcccc33, // YELLOW - 0xff33dccc, // TURQUOISE + static const unsigned int s_firstColors[] = { + 0xff000000, // WHITE (represents the "white" player, but using black as the colour) + 0xff33cc33, // GREEN + 0xffcc3333, // RED + 0xff3333cc, // BLUE + 0xffcc33cc, // PINK + 0xffcc6633, // ORANGE + 0xffcccc33, // YELLOW + 0xff33dccc // TURQUOISE + }; +#ifndef __PSVITA__ + if (index >= 0 && index < 8) // Use original colors for the first 8 players + return s_firstColors[index]; + if (index >= 8 && index < MINECRAFT_NET_MAX_PLAYERS) + { + float h = (float)((index * 137) % 360) / 60.f; + int i = (int)h; + float f = h - i; + float q = 1.f - f; + float t = 1.f - (1.f - f); + float r = 0.f, g = 0.f, b = 0.f; + switch (i % 6) + { + case 0: r = 1.f; g = t; b = 0.f; break; + case 1: r = q; g = 1.f; b = 0.f; break; + case 2: r = 0.f; g = 1.f; b = t; break; + case 3: r = 0.f; g = q; b = 1.f; break; + case 4: r = t; g = 0.f; b = 1.f; break; + default: r = 1.f; g = 0.f; b = q; break; + } + int ri = (int)(r * 255.f) & 0xff, gi = (int)(g * 255.f) & 0xff, bi = (int)(b * 255.f) & 0xff; + return 0xff000000u | (ri << 16) | (gi << 8) | bi; + } #endif -}; + return 0xFF000000; //Fallback if exceeds 256 somehow +} ResourceLocation PlayerRenderer::DEFAULT_LOCATION = ResourceLocation(TN_MOB_CHAR); @@ -41,9 +66,7 @@ PlayerRenderer::PlayerRenderer() : LivingEntityRenderer( new HumanoidModel(0), 0 unsigned int PlayerRenderer::getNametagColour(int index) { if( index >= 0 && index < MINECRAFT_NET_MAX_PLAYERS) - { - return s_nametagColors[index]; - } + return nametagColorForIndex(index); return 0xFF000000; } diff --git a/Minecraft.Client/PlayerRenderer.h b/Minecraft.Client/PlayerRenderer.h index 25c32a308..494ff795f 100644 --- a/Minecraft.Client/PlayerRenderer.h +++ b/Minecraft.Client/PlayerRenderer.h @@ -13,9 +13,6 @@ public: static ResourceLocation DEFAULT_LOCATION; private: - // 4J Added - static const unsigned int s_nametagColors[MINECRAFT_NET_MAX_PLAYERS]; - HumanoidModel *humanoidModel; HumanoidModel *armorParts1; HumanoidModel *armorParts2; diff --git a/Minecraft.Client/Windows64/Network/WinsockNetLayer.cpp b/Minecraft.Client/Windows64/Network/WinsockNetLayer.cpp index ca1d62af7..bda5062dd 100644 --- a/Minecraft.Client/Windows64/Network/WinsockNetLayer.cpp +++ b/Minecraft.Client/Windows64/Network/WinsockNetLayer.cpp @@ -21,7 +21,7 @@ bool WinsockNetLayer::s_initialized = false; BYTE WinsockNetLayer::s_localSmallId = 0; BYTE WinsockNetLayer::s_hostSmallId = 0; -BYTE WinsockNetLayer::s_nextSmallId = 1; +unsigned int WinsockNetLayer::s_nextSmallId = 1; CRITICAL_SECTION WinsockNetLayer::s_sendLock; CRITICAL_SECTION WinsockNetLayer::s_connectionsLock; @@ -447,9 +447,9 @@ DWORD WINAPI WinsockNetLayer::AcceptThreadProc(LPVOID param) assignedSmallId = s_freeSmallIds.back(); s_freeSmallIds.pop_back(); } - else if (s_nextSmallId < MINECRAFT_NET_MAX_PLAYERS) + else if (s_nextSmallId < (unsigned int)MINECRAFT_NET_MAX_PLAYERS) { - assignedSmallId = s_nextSmallId++; + assignedSmallId = (BYTE)s_nextSmallId++; } else { diff --git a/Minecraft.Client/Windows64/Network/WinsockNetLayer.h b/Minecraft.Client/Windows64/Network/WinsockNetLayer.h index fd1280f7d..59be9c6b8 100644 --- a/Minecraft.Client/Windows64/Network/WinsockNetLayer.h +++ b/Minecraft.Client/Windows64/Network/WinsockNetLayer.h @@ -12,7 +12,7 @@ #pragma comment(lib, "Ws2_32.lib") #define WIN64_NET_DEFAULT_PORT 25565 -#define WIN64_NET_MAX_CLIENTS 7 +#define WIN64_NET_MAX_CLIENTS 255 #define WIN64_NET_RECV_BUFFER_SIZE 65536 #define WIN64_NET_MAX_PACKET_SIZE (4 * 1024 * 1024) #define WIN64_LAN_DISCOVERY_PORT 25566 @@ -116,7 +116,7 @@ private: static BYTE s_localSmallId; static BYTE s_hostSmallId; - static BYTE s_nextSmallId; + static unsigned int s_nextSmallId; static CRITICAL_SECTION s_sendLock; static CRITICAL_SECTION s_connectionsLock; diff --git a/Minecraft.World/PlayerIO.h b/Minecraft.World/PlayerIO.h index 153c55e34..2b13cab9c 100644 --- a/Minecraft.World/PlayerIO.h +++ b/Minecraft.World/PlayerIO.h @@ -3,7 +3,7 @@ using namespace std; // If we have more than MAX_PLAYER_DATA_SAVES player.dat's then we delete the oldest ones // This value can be no higher than MAXIMUM_MAP_SAVE_DATA/3 (3 being the number of dimensions in future versions) -#define MAX_PLAYER_DATA_SAVES 80 +#define MAX_PLAYER_DATA_SAVES 0x7FFFFFFF class Player; diff --git a/Minecraft.World/x64headers/extraX64.h b/Minecraft.World/x64headers/extraX64.h index fa6ee0f99..dc01f3b3b 100644 --- a/Minecraft.World/x64headers/extraX64.h +++ b/Minecraft.World/x64headers/extraX64.h @@ -21,7 +21,7 @@ const int XUSER_MAX_COUNT = 1; const int MINECRAFT_NET_MAX_PLAYERS = 4; #else const int XUSER_MAX_COUNT = 4; -const int MINECRAFT_NET_MAX_PLAYERS = 8; +const int MINECRAFT_NET_MAX_PLAYERS = 256; #endif