From 1005e646294c9d56ce9e59bbc2dc39c3a0cba893 Mon Sep 17 00:00:00 2001 From: 552eden <552eden@gmail.com> Date: Thu, 13 Aug 2026 00:04:53 +0300 Subject: [PATCH] added 360 support and fixed vita again again --- Minecraft.Client/ClientConnection.cpp | 6 +- Minecraft.Client/Common/LivePrivileges.h | 32 ++ .../Common/Network/GameNetworkManager.cpp | 9 +- .../Common/Network/NetworkSocketLayer.cpp | 77 ++- .../Common/Network/PlatformNetworkManager.cpp | 74 ++- .../Common/XUI/XUI_LoadSettings.cpp | 13 +- .../Common/XUI/XUI_MultiGameCreate.cpp | 15 +- .../Common/XUI/XUI_MultiGameInfo.cpp | 25 +- .../Common/XUI/XUI_MultiGameJoinLoad.cpp | 11 +- .../XUI/XUI_MultiGameLaunchMoreOptions.cpp | 5 +- Minecraft.Client/Minecraft.Client.vcxproj | 453 +++++++++++++----- Minecraft.Client/Minecraft.cpp | 11 +- Minecraft.Client/Xbox/Xbox_Minecraft.cpp | 4 + Minecraft.World/BlockRegionUpdatePacket.cpp | 4 +- Minecraft.World/Minecraft.World.vcxproj | 2 +- Minecraft.World/compression.cpp | 47 +- Minecraft.World/compression.h | 11 +- 17 files changed, 591 insertions(+), 208 deletions(-) create mode 100644 Minecraft.Client/Common/LivePrivileges.h diff --git a/Minecraft.Client/ClientConnection.cpp b/Minecraft.Client/ClientConnection.cpp index 962d0fae..eea3177c 100644 --- a/Minecraft.Client/ClientConnection.cpp +++ b/Minecraft.Client/ClientConnection.cpp @@ -1,4 +1,5 @@ #include "stdafx.h" +#include "Common\LivePrivileges.h" #include "ClientConnection.h" #include "MultiPlayerLevel.h" #include "MultiPlayerLocalPlayer.h" @@ -1855,7 +1856,8 @@ void ClientConnection::handlePreLogin(shared_ptr packet) } } -#ifdef _XBOX +// A LAN build has no Live friends list or UGC entitlements +#if defined _XBOX && !defined _DISABLE_XBLIVE if(!g_NetworkManager.IsHost() && !app.GetGameHostOption(eGameHostOption_FriendsOfFriends)) { if(m_userIndex == ProfileManager.GetPrimaryPad() ) @@ -2287,7 +2289,7 @@ void ClientConnection::handlePreLogin(shared_ptr packet) ProfileManager.GetXUID(m_userIndex,&offlineXUID,false); } BOOL allAllowed, friendsAllowed; - ProfileManager.AllowedPlayerCreatedContent(m_userIndex,true,&allAllowed,&friendsAllowed); + Live_AllowedPlayerCreatedContent(m_userIndex,true,&allAllowed,&friendsAllowed); app.DebugPrintf("ClientConnection::handlePreLogin SENDING LoginPacket (user %d)\n", m_userIndex); send( shared_ptr( new LoginPacket(minecraft->user->name, SharedConstants::NETWORK_PROTOCOL_VERSION, offlineXUID, onlineXUID, (allAllowed!=TRUE && friendsAllowed==TRUE), packet->m_ugcPlayersVersion, app.GetPlayerSkinId(m_userIndex), app.GetPlayerCapeId(m_userIndex), ProfileManager.IsGuest( m_userIndex )))); diff --git a/Minecraft.Client/Common/LivePrivileges.h b/Minecraft.Client/Common/LivePrivileges.h new file mode 100644 index 00000000..e1cc59bd --- /dev/null +++ b/Minecraft.Client/Common/LivePrivileges.h @@ -0,0 +1,32 @@ +#pragma once + +// Wrappers around the 4J profile library's Xbox Live entitlement queries. +// Include this after stdafx.h; it needs ProfileManager to be declared. + +inline bool Live_MultiplayerAllowed(int iPad) +{ +#ifdef _DISABLE_XBLIVE + return true; +#else + return ProfileManager.IsSignedInLive(iPad) && ProfileManager.AllowedToPlayMultiplayer(iPad); +#endif +} + +inline bool Live_AllowedToPlayMultiplayer(int iPad) +{ +#ifdef _DISABLE_XBLIVE + return true; +#else + return ProfileManager.AllowedToPlayMultiplayer(iPad); +#endif +} + +inline void Live_AllowedPlayerCreatedContent(int iPad, bool thisQuadrantOnly, BOOL *allAllowed, BOOL *friendsAllowed) +{ +#ifdef _DISABLE_XBLIVE + if(allAllowed != NULL) *allAllowed = TRUE; + if(friendsAllowed != NULL) *friendsAllowed = TRUE; +#else + ProfileManager.AllowedPlayerCreatedContent(iPad, thisQuadrantOnly, allAllowed, friendsAllowed); +#endif +} diff --git a/Minecraft.Client/Common/Network/GameNetworkManager.cpp b/Minecraft.Client/Common/Network/GameNetworkManager.cpp index e7a63676..48bdde1c 100644 --- a/Minecraft.Client/Common/Network/GameNetworkManager.cpp +++ b/Minecraft.Client/Common/Network/GameNetworkManager.cpp @@ -1,4 +1,5 @@ #include "stdafx.h" +#include "..\LivePrivileges.h" #include "..\..\..\Minecraft.World\StringHelpers.h" #include "..\..\..\Minecraft.World\AABB.h" #include "..\..\..\Minecraft.World\Vec3.h" @@ -794,7 +795,7 @@ int CGameNetworkManager::JoinFromInvite_SignInReturned(void *pParam,bool bContin if(ProfileManager.IsSignedIn(index) ) { ++joiningUsers; - if( !ProfileManager.AllowedToPlayMultiplayer(index) ) noPrivileges = true; + if( !Live_AllowedToPlayMultiplayer(index) ) noPrivileges = true; localUsersMask |= GetLocalPlayerMask( index ); } } @@ -1743,7 +1744,7 @@ void CGameNetworkManager::GameInviteReceived( int userIndex, const INVITE_INFO * if(index==userIndex || pMinecraft->localplayers[index]!=NULL ) { ++joiningUsers; - if( !ProfileManager.AllowedToPlayMultiplayer(index) ) noPrivileges = true; + if( !Live_AllowedToPlayMultiplayer(index) ) noPrivileges = true; localUsersMask |= GetLocalPlayerMask( index ); } } @@ -1757,7 +1758,7 @@ void CGameNetworkManager::GameInviteReceived( int userIndex, const INVITE_INFO * #if defined(__PS3__) || defined(__PSVITA__) ProfileManager.GetChatAndContentRestrictions(userIndex,false,&noUGC,&bContentRestricted,NULL); #else - ProfileManager.AllowedPlayerCreatedContent(ProfileManager.GetPrimaryPad(),false,&pccAllowed,&pccFriendsAllowed); + Live_AllowedPlayerCreatedContent(ProfileManager.GetPrimaryPad(),false,&pccAllowed,&pccFriendsAllowed); if(!pccAllowed && !pccFriendsAllowed) noUGC = true; #endif @@ -1898,7 +1899,7 @@ void CGameNetworkManager::HandleInviteWhenInMenus( int userIndex, const INVITE_I if(!app.IsLocalMultiplayerAvailable()) #endif { - bool noPrivileges=!ProfileManager.AllowedToPlayMultiplayer(userIndex); + bool noPrivileges=!Live_AllowedToPlayMultiplayer(userIndex); if(noPrivileges) { diff --git a/Minecraft.Client/Common/Network/NetworkSocketLayer.cpp b/Minecraft.Client/Common/Network/NetworkSocketLayer.cpp index 36d68a5f..c917be98 100644 --- a/Minecraft.Client/Common/Network/NetworkSocketLayer.cpp +++ b/Minecraft.Client/Common/Network/NetworkSocketLayer.cpp @@ -88,6 +88,25 @@ bool NetworkSocketLayer::Initialize() } #if defined _WINDOWS64 || defined _XBOX +#if defined _XBOX + // XNet has to be up before Winsock, and it has to be up insecure. + static bool s_xnetStarted = false; + if (!s_xnetStarted) + { + XNetStartupParams xnsp; + memset(&xnsp, 0, sizeof(xnsp)); + xnsp.cfgSizeOfStruct = sizeof(XNetStartupParams); + xnsp.cfgFlags = XNET_STARTUP_BYPASS_SECURITY; + + int xnetResult = XNetStartup(&xnsp); + if (xnetResult != 0) + { + app.DebugPrintf("XNetStartup failed: %d\n", xnetResult); + return false; + } + s_xnetStarted = true; + } +#endif WSADATA wsaData; int result = WSAStartup(MAKEWORD(2, 2), &wsaData); if (result != 0) @@ -486,31 +505,43 @@ bool NetworkSocketLayer::JoinGame(const char *ip, int port) s_hostConnectionSocket = INVALID_SOCKET; } - XNDNS *pDns = NULL; - int iResult = XNetDnsLookup(ip, NULL, &pDns); - if (iResult != 0 || pDns == NULL) - { - app.DebugPrintf("XNetDnsLookup failed for %s - %d\n", ip, iResult); - return false; - } - - while (pDns->iStatus == WSAEINPROGRESS) - { - Sleep(10); - } - - if (pDns->iStatus != 0 || pDns->cina == 0) - { - app.DebugPrintf("pDns->iStatus failed for %s - %d\n", ip, iResult); - XNetDnsRelease(pDns); - return false; - } + int iResult; struct sockaddr_in addr = {}; addr.sin_family = AF_INET; addr.sin_port = htons((WORD)port); - addr.sin_addr = pDns->aina[0]; - XNetDnsRelease(pDns); + + // The discovery broadcast always hands an ip and a LAN has no reason to run a DNS server, so only fall back to XNetDnsLookup for actual host names. + unsigned long literalAddr = inet_addr(ip); + if (literalAddr != INADDR_NONE) + { + addr.sin_addr.s_addr = literalAddr; + } + else + { + XNDNS *pDns = NULL; + iResult = XNetDnsLookup(ip, NULL, &pDns); + if (iResult != 0 || pDns == NULL) + { + app.DebugPrintf("XNetDnsLookup failed for %s - %d\n", ip, iResult); + return false; + } + + while (pDns->iStatus == WSAEINPROGRESS) + { + Sleep(10); + } + + if (pDns->iStatus != 0 || pDns->cina == 0) + { + app.DebugPrintf("pDns->iStatus failed for %s - %d\n", ip, pDns->iStatus); + XNetDnsRelease(pDns); + return false; + } + + addr.sin_addr = pDns->aina[0]; + XNetDnsRelease(pDns); + } bool connected = false; BYTE assignedSmallId = 0; @@ -1224,7 +1255,7 @@ void NetworkSocketLayer::StopAdvertising() { s_advertising = false; -#if defined _WINDOWS64 +#if defined _WINDOWS64 || defined _XBOX if (s_advertiseSock != INVALID_SOCKET) { closesocket(s_advertiseSock); @@ -1507,7 +1538,7 @@ int NetworkSocketLayer::DiscoveryThreadProc(LPVOID param) (struct sockaddr *)&senderAddr, &senderLen); #endif -#ifdef _WINDOWS64 +#if defined _WINDOWS64 || defined _XBOX if (recvLen == SOCKET_ERROR) { continue; diff --git a/Minecraft.Client/Common/Network/PlatformNetworkManager.cpp b/Minecraft.Client/Common/Network/PlatformNetworkManager.cpp index 5f6d43e1..3eb68662 100644 --- a/Minecraft.Client/Common/Network/PlatformNetworkManager.cpp +++ b/Minecraft.Client/Common/Network/PlatformNetworkManager.cpp @@ -379,6 +379,17 @@ void CPlatformNetworkManagerStub::HostGame(int localUsersMask, bool bOnlineGame, if (!NetworkSocketLayer::IsActive()) NetworkSocketLayer::HostGame(port); + //Fall back to the local name. + if (IQNet::m_player[0].m_gamertag[0] == 0) + { + Minecraft *pMinecraft = Minecraft::GetInstance(); + if (pMinecraft != NULL && pMinecraft->user != NULL) + { + wcsncpy(IQNet::m_player[0].m_gamertag, pMinecraft->user->name.c_str(), 31); + IQNet::m_player[0].m_gamertag[31] = L'\0'; + } + } + const wchar_t *hostName = IQNet::m_player[0].m_gamertag; unsigned int settings = app.GetGameHostOption(eGameHostOption_All); NetworkSocketLayer::StartAdvertising(port, hostName, settings, 0, 0, MINECRAFT_NET_VERSION); @@ -731,19 +742,47 @@ void CPlatformNetworkManagerStub::SearchForGames() } } - for (size_t i = 0; i < friendsSessions[0].size(); i++) - delete friendsSessions[0][i]; - friendsSessions[0].clear(); + std::vector updatedSessions; for (size_t i = 0; i < lanSessions.size(); i++) { - FriendSessionInfo *info = new FriendSessionInfo(); - size_t nameLen = wcslen(lanSessions[i].hostName); - info->displayLabel = new wchar_t[nameLen + 1]; - wcsncpy(info->displayLabel, lanSessions[i].hostName, nameLen); - info->displayLabel[nameLen] = L'\0'; - info->displayLabelLength = (unsigned char)nameLen; - info->displayLabelViewableStartIndex = 0; +#if defined(__ORBIS__) || defined(__PSVITA__) + SceNetInAddr ip_addr = {}; + sceNetInetPton(SCE_NET_AF_INET, lanSessions[i].hostIP, &ip_addr); + SessionID sessionId = (ULONGLONG)((uint64_t)ip_addr.s_addr | ((uint64_t)lanSessions[i].hostPort << 32)); +#else + SessionID sessionId = (ULONGLONG)((unsigned __int64)inet_addr(lanSessions[i].hostIP) | ((unsigned __int64)lanSessions[i].hostPort << 32)); +#endif + + FriendSessionInfo *info = NULL; + for (size_t j = 0; j < friendsSessions[0].size(); j++) + { + if (friendsSessions[0][j] != NULL && friendsSessions[0][j]->sessionId == sessionId) + { + info = friendsSessions[0][j]; + friendsSessions[0][j] = NULL; + break; + } + } + + if (info == NULL) + info = new FriendSessionInfo(); + + info->sessionId = sessionId; + + // Only reallocate the label when the name actually changed, so it stays put as well + if (info->displayLabel == NULL || wcscmp(info->displayLabel, lanSessions[i].hostName) != 0) + { + size_t nameLen = wcslen(lanSessions[i].hostName); + wchar_t *newLabel = new wchar_t[nameLen + 1]; + wcsncpy(newLabel, lanSessions[i].hostName, nameLen); + newLabel[nameLen] = L'\0'; + + delete [] info->displayLabel; + info->displayLabel = newLabel; + info->displayLabelLength = (unsigned char)nameLen; + info->displayLabelViewableStartIndex = 0; + } info->data.netVersion = lanSessions[i].netVersion; info->data.m_uiGameHostSettings = lanSessions[i].gameHostSettings; @@ -770,16 +809,14 @@ void CPlatformNetworkManagerStub::SearchForGames() } } -#if defined(__ORBIS__) || defined(__PSVITA__) - SceNetInAddr ip_addr = {}; - sceNetInetPton(SCE_NET_AF_INET, lanSessions[i].hostIP, &ip_addr); - info->sessionId = (ULONGLONG)((uint64_t)ip_addr.s_addr | ((uint64_t)lanSessions[i].hostPort << 32)); -#else - info->sessionId = (ULONGLONG)((unsigned __int64)inet_addr(lanSessions[i].hostIP) | ((unsigned __int64)lanSessions[i].hostPort << 32)); -#endif - friendsSessions[0].push_back(info); + updatedSessions.push_back(info); } + for (size_t j = 0; j < friendsSessions[0].size(); j++) + delete friendsSessions[0][j]; + + friendsSessions[0] = updatedSessions; + m_searchResultsCount[0] = (int)friendsSessions[0].size(); if (m_SessionsUpdatedCallback != NULL) @@ -820,6 +857,7 @@ bool CPlatformNetworkManagerStub::GetGameSessionInfo(int iPad, SessionID session return true; } } + return false; } void CPlatformNetworkManagerStub::SetSessionsUpdatedCallback( void (*SessionsUpdatedCallback)(LPVOID pParam), LPVOID pSearchParam ) diff --git a/Minecraft.Client/Common/XUI/XUI_LoadSettings.cpp b/Minecraft.Client/Common/XUI/XUI_LoadSettings.cpp index 7f32ff89..28ce482a 100644 --- a/Minecraft.Client/Common/XUI/XUI_LoadSettings.cpp +++ b/Minecraft.Client/Common/XUI/XUI_LoadSettings.cpp @@ -1,4 +1,5 @@ #include "stdafx.h" +#include "..\LivePrivileges.h" #include #include #include @@ -76,7 +77,7 @@ HRESULT CScene_LoadGameSettings::OnInit( XUIMessageInit* pInitData, BOOL& bHandl XuiControlSetText(m_ButtonLoad,app.GetString(IDS_LOAD)); XuiControlSetText(m_pTexturePacksList->m_hObj,app.GetString(IDS_DLC_MENU_TEXTUREPACKS)); - m_bMultiplayerAllowed = ProfileManager.IsSignedInLive( m_iPad ) && ProfileManager.AllowedToPlayMultiplayer(m_iPad); + m_bMultiplayerAllowed = Live_MultiplayerAllowed( m_iPad ); // 4J-PB - read the settings for the online flag. We'll only save this setting if the user changed it. bool bGameSetting_Online=(app.GetGameSettings(m_iPad,eGameSetting_Online)!=0); m_MoreOptionsParams.bOnlineSettingChangedBySystem=false; @@ -741,7 +742,7 @@ HRESULT CScene_LoadGameSettings::OnTimer( XUIMessageTimer *pTimer, BOOL& bHandle { case GAME_CREATE_ONLINE_TIMER_ID: { - bool bMultiplayerAllowed = ProfileManager.IsSignedInLive( m_iPad ) && ProfileManager.AllowedToPlayMultiplayer(m_iPad); + bool bMultiplayerAllowed = Live_MultiplayerAllowed( m_iPad ); if(bMultiplayerAllowed != m_bMultiplayerAllowed) { @@ -859,7 +860,7 @@ int CScene_LoadGameSettings::LoadSaveDataReturned(void *pParam,bool bContinue) bool noUGC = false; BOOL pccAllowed = TRUE; BOOL pccFriendsAllowed = TRUE; - ProfileManager.AllowedPlayerCreatedContent(ProfileManager.GetPrimaryPad(),false,&pccAllowed,&pccFriendsAllowed); + Live_AllowedPlayerCreatedContent(ProfileManager.GetPrimaryPad(),false,&pccAllowed,&pccFriendsAllowed); if(!pccAllowed && !pccFriendsAllowed) noUGC = true; if(isClientSide && noUGC ) @@ -1015,7 +1016,7 @@ int CScene_LoadGameSettings::StartGame_SignInReturned(void *pParam,bool bContinu { if(ProfileManager.IsSignedIn(index) ) { - if( !ProfileManager.AllowedToPlayMultiplayer(index) ) noPrivileges = true; + if( !Live_AllowedToPlayMultiplayer(index) ) noPrivileges = true; dwLocalUsersMask |= CGameNetworkManager::GetLocalPlayerMask(index); } } @@ -1024,7 +1025,7 @@ int CScene_LoadGameSettings::StartGame_SignInReturned(void *pParam,bool bContinu bool noUGC = false; BOOL pccAllowed = TRUE; BOOL pccFriendsAllowed = TRUE; - ProfileManager.AllowedPlayerCreatedContent(ProfileManager.GetPrimaryPad(), false, &pccAllowed,&pccFriendsAllowed); + Live_AllowedPlayerCreatedContent(ProfileManager.GetPrimaryPad(), false, &pccAllowed,&pccFriendsAllowed); if(!pccAllowed && !pccFriendsAllowed) noUGC = true; if(isClientSide && (noPrivileges || noUGC) ) @@ -1407,7 +1408,7 @@ void CScene_LoadGameSettings::LoadLevelGen(LevelGenerationOptions *levelGen) bool noUGC = false; BOOL pccAllowed = TRUE; BOOL pccFriendsAllowed = TRUE; - ProfileManager.AllowedPlayerCreatedContent(ProfileManager.GetPrimaryPad(),false,&pccAllowed,&pccFriendsAllowed); + Live_AllowedPlayerCreatedContent(ProfileManager.GetPrimaryPad(),false,&pccAllowed,&pccFriendsAllowed); if(!pccAllowed && !pccFriendsAllowed) noUGC = true; if(isClientSide && noUGC ) diff --git a/Minecraft.Client/Common/XUI/XUI_MultiGameCreate.cpp b/Minecraft.Client/Common/XUI/XUI_MultiGameCreate.cpp index b3608b06..169c1923 100644 --- a/Minecraft.Client/Common/XUI/XUI_MultiGameCreate.cpp +++ b/Minecraft.Client/Common/XUI/XUI_MultiGameCreate.cpp @@ -1,4 +1,5 @@ #include "stdafx.h" +#include "..\LivePrivileges.h" #include "..\..\..\Minecraft.World\Random.h" #include "..\..\..\Minecraft.World\StringHelpers.h" #include "XUI_MultiGameCreate.h" @@ -67,7 +68,7 @@ HRESULT CScene_MultiGameCreate::OnInit( XUIMessageInit* pInitData, BOOL& bHandle m_iPad=params->iPad; delete params; - m_bMultiplayerAllowed = ProfileManager.IsSignedInLive( m_iPad ) && ProfileManager.AllowedToPlayMultiplayer(m_iPad); + m_bMultiplayerAllowed = Live_MultiplayerAllowed( m_iPad ); // 4J-PB - read the settings for the online flag. We'll only save this setting if the user changed it. bool bGameSetting_Online=(app.GetGameSettings(m_iPad,eGameSetting_Online)!=0); m_MoreOptionsParams.bOnlineSettingChangedBySystem=false; @@ -476,7 +477,7 @@ HRESULT CScene_MultiGameCreate::OnNotifyPressEx(HXUIOBJ hObjPressed, XUINotifyPr bool noUGC = false; BOOL pccAllowed = TRUE; BOOL pccFriendsAllowed = TRUE; - ProfileManager.AllowedPlayerCreatedContent(ProfileManager.GetPrimaryPad(),false,&pccAllowed,&pccFriendsAllowed); + Live_AllowedPlayerCreatedContent(ProfileManager.GetPrimaryPad(),false,&pccAllowed,&pccFriendsAllowed); if(!pccAllowed && !pccFriendsAllowed) noUGC = true; if(isClientSide && noUGC ) @@ -581,7 +582,7 @@ int CScene_MultiGameCreate::WarningTrialTexturePackReturned(void *pParam,int iPa bool noUGC = false; BOOL pccAllowed = TRUE; BOOL pccFriendsAllowed = TRUE; - ProfileManager.AllowedPlayerCreatedContent(ProfileManager.GetPrimaryPad(),false,&pccAllowed,&pccFriendsAllowed); + Live_AllowedPlayerCreatedContent(ProfileManager.GetPrimaryPad(),false,&pccAllowed,&pccFriendsAllowed); if(!pccAllowed && !pccFriendsAllowed) noUGC = true; if(isClientSide && noUGC ) @@ -663,7 +664,7 @@ HRESULT CScene_MultiGameCreate::OnTimer( XUIMessageTimer *pTimer, BOOL& bHandled case GAME_CREATE_ONLINE_TIMER_ID: { - bool bMultiplayerAllowed = ProfileManager.IsSignedInLive( m_iPad ) && ProfileManager.AllowedToPlayMultiplayer(m_iPad); + bool bMultiplayerAllowed = Live_MultiplayerAllowed( m_iPad ); if(bMultiplayerAllowed != m_bMultiplayerAllowed) { @@ -778,7 +779,7 @@ int CScene_MultiGameCreate::ConfirmCreateReturned(void *pParam,int iPad,C4JStora bool noUGC = false; BOOL pccAllowed = TRUE; BOOL pccFriendsAllowed = TRUE; - ProfileManager.AllowedPlayerCreatedContent(ProfileManager.GetPrimaryPad(),false,&pccAllowed,&pccFriendsAllowed); + Live_AllowedPlayerCreatedContent(ProfileManager.GetPrimaryPad(),false,&pccAllowed,&pccFriendsAllowed); if(!pccAllowed && !pccFriendsAllowed) noUGC = true; if(isClientSide && noUGC ) @@ -824,7 +825,7 @@ int CScene_MultiGameCreate::StartGame_SignInReturned(void *pParam,bool bContinue { if(ProfileManager.IsSignedIn(index) ) { - if( !ProfileManager.AllowedToPlayMultiplayer(index) ) noPrivileges = true; + if( !Live_AllowedToPlayMultiplayer(index) ) noPrivileges = true; dwLocalUsersMask |= CGameNetworkManager::GetLocalPlayerMask(index); } } @@ -833,7 +834,7 @@ int CScene_MultiGameCreate::StartGame_SignInReturned(void *pParam,bool bContinue bool noUGC = false; BOOL pccAllowed = TRUE; BOOL pccFriendsAllowed = TRUE; - ProfileManager.AllowedPlayerCreatedContent(ProfileManager.GetPrimaryPad(),false,&pccAllowed,&pccFriendsAllowed); + Live_AllowedPlayerCreatedContent(ProfileManager.GetPrimaryPad(),false,&pccAllowed,&pccFriendsAllowed); if(!pccAllowed && !pccFriendsAllowed) noUGC = true; if(isClientSide && (noPrivileges || noUGC) ) diff --git a/Minecraft.Client/Common/XUI/XUI_MultiGameInfo.cpp b/Minecraft.Client/Common/XUI/XUI_MultiGameInfo.cpp index 1d59730a..ad6488a9 100644 --- a/Minecraft.Client/Common/XUI/XUI_MultiGameInfo.cpp +++ b/Minecraft.Client/Common/XUI/XUI_MultiGameInfo.cpp @@ -6,6 +6,7 @@ #include "..\..\..\Minecraft.World\StringHelpers.h" #include "XUI_MultiGameInfo.h" #include "XUI_MultiGameJoinLoad.h" +#include "..\LivePrivileges.h" #include "..\..\..\Minecraft.World\LevelSettings.h" #include "..\..\..\Minecraft.World\Difficulty.h" @@ -37,7 +38,19 @@ HRESULT CScene_MultiGameInfo::OnInit( XUIMessageInit* pInitData, BOOL& bHandled // 4J-PB - don't delete this - it's part of the joinload structure //delete initData; -#ifndef _DISABLE_XBLIVE +#ifdef _DISABLE_XBLIVE + // No gamercards on a LAN session - the names come straight out of the broadcast + for(unsigned int i = 0; i < MINECRAFT_NET_MAX_PLAYERS; ++i) + { + if( m_selectedSession->data.players[i] == 0 || m_selectedSession->data.szPlayers[i][0] == 0 ) + { + break; + } + + playersList.InsertItems(i,1); + playersList.SetText(i, convStringToWstring( m_selectedSession->data.szPlayers[i] ).c_str() ); + } +#else for(unsigned int i = 0; i < MINECRAFT_NET_MAX_PLAYERS; ++i) { if( m_selectedSession->data.players[i] != NULL ) @@ -223,7 +236,11 @@ HRESULT CScene_MultiGameInfo::OnNotifySetFocus(HXUIOBJ hObjSource, XUINotifyFocu { if( playersList.TreeHasFocus() && playersList.GetItemCount() > 0 ) { +#ifdef _DISABLE_XBLIVE + ui.SetTooltips( DEFAULT_XUI_MENU_USER, -1, IDS_TOOLTIPS_BACK ); +#else ui.SetTooltips( DEFAULT_XUI_MENU_USER, -1, IDS_TOOLTIPS_BACK, -1, IDS_TOOLTIPS_VIEW_GAMERCARD ); +#endif bHandled = TRUE; } return S_OK; @@ -274,7 +291,7 @@ void CScene_MultiGameInfo::JoinGame(CScene_MultiGameInfo* pClass) if(ProfileManager.IsSignedIn(index) ) { ++dwSignedInUsers; - if( !ProfileManager.AllowedToPlayMultiplayer(index) ) noPrivileges = true; + if( !Live_AllowedToPlayMultiplayer(index) ) noPrivileges = true; dwLocalUsersMask |= CGameNetworkManager::GetLocalPlayerMask(index); } } @@ -284,7 +301,7 @@ void CScene_MultiGameInfo::JoinGame(CScene_MultiGameInfo* pClass) if(ProfileManager.IsSignedIn(ProfileManager.GetPrimaryPad()) ) { ++dwSignedInUsers; - if( !ProfileManager.AllowedToPlayMultiplayer(ProfileManager.GetPrimaryPad()) ) noPrivileges = true; + if( !Live_AllowedToPlayMultiplayer(ProfileManager.GetPrimaryPad()) ) noPrivileges = true; dwLocalUsersMask |= CGameNetworkManager::GetLocalPlayerMask(ProfileManager.GetPrimaryPad()); } } @@ -293,7 +310,7 @@ void CScene_MultiGameInfo::JoinGame(CScene_MultiGameInfo* pClass) bool noUGC = false; BOOL pccAllowed = TRUE; BOOL pccFriendsAllowed = TRUE; - ProfileManager.AllowedPlayerCreatedContent(ProfileManager.GetPrimaryPad(),false,&pccAllowed,&pccFriendsAllowed); + Live_AllowedPlayerCreatedContent(ProfileManager.GetPrimaryPad(),false,&pccAllowed,&pccFriendsAllowed); if(!pccAllowed && !pccFriendsAllowed) noUGC = true; if(noUGC) diff --git a/Minecraft.Client/Common/XUI/XUI_MultiGameJoinLoad.cpp b/Minecraft.Client/Common/XUI/XUI_MultiGameJoinLoad.cpp index 1c4f3f21..b57e07fe 100644 --- a/Minecraft.Client/Common/XUI/XUI_MultiGameJoinLoad.cpp +++ b/Minecraft.Client/Common/XUI/XUI_MultiGameJoinLoad.cpp @@ -18,6 +18,7 @@ #include "XUI_LoadSettings.h" #include "XUI_MultiGameInfo.h" #include "XUI_MultiGameJoinLoad.h" +#include "..\LivePrivileges.h" #include "XUI_MultiGameCreate.h" #include "..\..\MinecraftServer.h" #include "..\..\Options.h" @@ -73,8 +74,8 @@ HRESULT CScene_MultiGameJoinLoad::OnInit( XUIMessageInit* pInitData, BOOL& bHand // } m_initData= new JoinMenuInitData(); - m_bMultiplayerAllowed = ProfileManager.IsSignedInLive( m_iPad ) && ProfileManager.AllowedToPlayMultiplayer(m_iPad); - + m_bMultiplayerAllowed = Live_MultiplayerAllowed( m_iPad ); + XPARTY_USER_LIST partyList; if((XPartyGetUserList( &partyList ) != XPARTY_E_NOT_IN_PARTY ) && (partyList.dwUserCount>1)) @@ -768,8 +769,8 @@ HRESULT CScene_MultiGameJoinLoad::OnNavReturn(HXUIOBJ hSceneFrom,BOOL& rfHandled // start the texture pack timer again XuiSetTimer(m_hObj,CHECKFORAVAILABLETEXTUREPACKS_TIMER_ID,CHECKFORAVAILABLETEXTUREPACKS_TIMER_TIME); - m_bMultiplayerAllowed = ProfileManager.IsSignedInLive( m_iPad ) && ProfileManager.AllowedToPlayMultiplayer(m_iPad); - + m_bMultiplayerAllowed = Live_MultiplayerAllowed( m_iPad ); + // re-enable button presses m_bIgnoreInput=false; @@ -1643,7 +1644,7 @@ HRESULT CScene_MultiGameJoinLoad::OnTimer( XUIMessageTimer *pTimer, BOOL& bHandl m_bInParty=false; } - bool bMultiplayerAllowed = ProfileManager.IsSignedInLive( m_iPad ) && ProfileManager.AllowedToPlayMultiplayer(m_iPad); + bool bMultiplayerAllowed = Live_MultiplayerAllowed( m_iPad ); if(bMultiplayerAllowed != m_bMultiplayerAllowed) { if( bMultiplayerAllowed ) diff --git a/Minecraft.Client/Common/XUI/XUI_MultiGameLaunchMoreOptions.cpp b/Minecraft.Client/Common/XUI/XUI_MultiGameLaunchMoreOptions.cpp index 08656111..942e31bf 100644 --- a/Minecraft.Client/Common/XUI/XUI_MultiGameLaunchMoreOptions.cpp +++ b/Minecraft.Client/Common/XUI/XUI_MultiGameLaunchMoreOptions.cpp @@ -1,4 +1,5 @@ #include "stdafx.h" +#include "..\LivePrivileges.h" #include "XUI_MultiGameCreate.h" #include "XUI_MultiGameLaunchMoreOptions.h" #include "..\..\TexturePackRepository.h" @@ -99,7 +100,7 @@ HRESULT CScene_MultiGameLaunchMoreOptions::OnInit( XUIMessageInit* pInitData, BO m_CheckboxInviteOnly.SetCheck(m_params->bInviteOnly); m_CheckboxAllowFoF.SetCheck(m_params->bAllowFriendsOfFriends); - m_bMultiplayerAllowed = ProfileManager.IsSignedInLive( m_params->iPad ) && ProfileManager.AllowedToPlayMultiplayer(m_params->iPad); + m_bMultiplayerAllowed = Live_MultiplayerAllowed( m_params->iPad ); if(m_params->bOnlineSettingChangedBySystem) { m_CheckboxOnline.SetCheck(FALSE); @@ -270,7 +271,7 @@ HRESULT CScene_MultiGameLaunchMoreOptions::OnTimer( XUIMessageTimer *pTimer, BOO // 4J-PB - TODO - Don't think we can do this - if a 2nd player signs in here with an offline profile, the signed in LIVE player gets re-logged in, and bMultiplayerAllowed is false briefly if( pTimer->nId == GAME_CREATE_ONLINE_TIMER_ID) { - bool bMultiplayerAllowed = ProfileManager.IsSignedInLive( m_params->iPad ) && ProfileManager.AllowedToPlayMultiplayer(m_params->iPad); + bool bMultiplayerAllowed = Live_MultiplayerAllowed( m_params->iPad ); if(bMultiplayerAllowed != m_bMultiplayerAllowed) { diff --git a/Minecraft.Client/Minecraft.Client.vcxproj b/Minecraft.Client/Minecraft.Client.vcxproj index 8f0e115c..e0e7d52e 100644 --- a/Minecraft.Client/Minecraft.Client.vcxproj +++ b/Minecraft.Client/Minecraft.Client.vcxproj @@ -1027,7 +1027,7 @@ xcopy /q /y /i /s /e $(ProjectDir)DurangoMedia\CU $(LayoutDir)Image\Loose\CUfalse $(OutDir)$(ProjectName).pch MultiThreaded - _LARGE_WORLDS;_DEBUG_MENUS_ENABLED;_CRT_NON_CONFORMING_SWPRINTFS;_CRT_SECURE_NO_WARNINGS;_WINDOWS64;%(PreprocessorDefinitions) + _DEBUG_MENUS_ENABLED;_CRT_NON_CONFORMING_SWPRINTFS;_CRT_SECURE_NO_WARNINGS;_WINDOWS64;%(PreprocessorDefinitions) Disabled Windows64\Iggy\include;$(ProjectDir);%(AdditionalIncludeDirectories) true @@ -4085,6 +4085,7 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CUtrue + @@ -23445,13 +23446,13 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CUtrue - true - true - true - true - true - true - true + false + false + false + false + false + false + false false true false @@ -23489,15 +23490,29 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CU NotUsing - + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + - true - true - true - true - true - true - true + false + false + false + false + false + false + false false true false @@ -23533,15 +23548,29 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CUfalse NotUsing false - + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + - true - true - true - true - true - true - true + false + false + false + false + false + false + false false true false @@ -23577,15 +23606,29 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CUfalse NotUsing false - + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + - true - true - true - true - true - true - true + false + false + false + false + false + false + false false true false @@ -23621,15 +23664,29 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CUfalse NotUsing false - + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + - true - true - true - true - true - true - true + false + false + false + false + false + false + false false true false @@ -23672,15 +23729,29 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CUtrue NotUsing false - + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + - true - true - true - true - true - true - true + false + false + false + false + false + false + false false true false @@ -23723,15 +23794,29 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CUtrue NotUsing false - + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + - true - true - true - true - true - true - true + false + false + false + false + false + false + false false true false @@ -23774,15 +23859,29 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CUtrue NotUsing false - + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + - true - true - true - true - true - true - true + false + false + false + false + false + false + false false true false @@ -23825,15 +23924,29 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CUtrue NotUsing false - + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + - true - true - true - true - true - true - true + false + false + false + false + false + false + false false true false @@ -23869,15 +23982,29 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CUfalse NotUsing false - + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + - true - true - true - true - true - true - true + false + false + false + false + false + false + false false true false @@ -23913,15 +24040,29 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CUfalse NotUsing false - + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + - true - true - true - true - true - true - true + false + false + false + false + false + false + false false true false @@ -23957,15 +24098,29 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CUfalse NotUsing false - + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + - true - true - true - true - true - true - true + false + false + false + false + false + false + false false true false @@ -24001,15 +24156,29 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CUfalse NotUsing false - + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + - true - true - true - true - true - true - true + false + false + false + false + false + false + false false true false @@ -24045,15 +24214,29 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CUfalse NotUsing false - + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + - true - true - true - true - true - true - true + false + false + false + false + false + false + false false true false @@ -24089,15 +24272,29 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CUfalse NotUsing false - + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + - true - true - true - true - true - true - true + false + false + false + false + false + false + false false true false @@ -24133,7 +24330,21 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CUfalse NotUsing false - + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + diff --git a/Minecraft.Client/Minecraft.cpp b/Minecraft.Client/Minecraft.cpp index 7ec3330f..17023247 100644 --- a/Minecraft.Client/Minecraft.cpp +++ b/Minecraft.Client/Minecraft.cpp @@ -1,4 +1,5 @@ #include "stdafx.h" +#include "Common\LivePrivileges.h" #include "Minecraft.h" #include "GameMode.h" #include "Timer.h" @@ -1486,7 +1487,7 @@ void Minecraft::run_middle() if(ProfileManager.IsSignedIn(i)) { // if this is a local game, then the player just needs to be signed in - if( g_NetworkManager.IsLocalGame() || (ProfileManager.IsSignedInLive(i) && ProfileManager.AllowedToPlayMultiplayer(i) ) ) + if( g_NetworkManager.IsLocalGame() || Live_MultiplayerAllowed(i) ) { #ifdef __ORBIS__ bool contentRestricted = false; @@ -1539,7 +1540,7 @@ void Minecraft::run_middle() } else { - if( ProfileManager.IsSignedInLive(ProfileManager.GetPrimaryPad()) && !ProfileManager.AllowedToPlayMultiplayer(i) ) + if( ProfileManager.IsSignedInLive(ProfileManager.GetPrimaryPad()) && !Live_AllowedToPlayMultiplayer(i) ) { ProfileManager.RequestConvertOfflineToGuestUI( &Minecraft::InGame_SignInReturned, this,i); // 4J Stu - Don't allow converting to guests as we don't allow any guest sign-in while in the game @@ -4814,7 +4815,7 @@ void Minecraft::inGameSignInCheckAllPrivilegesCallback(LPVOID lpParam, bool hasP ui.RequestErrorMessage(IDS_MULTIPLAYER_FULL_TITLE, IDS_MULTIPLAYER_FULL_TEXT, uiIDA, 1); ProfileManager.RemoveGamepadFromGame(iPad); } - else if( ProfileManager.IsSignedInLive(iPad) && ProfileManager.AllowedToPlayMultiplayer(iPad) ) + else if( Live_MultiplayerAllowed(iPad) ) { // create the local player for the iPad shared_ptr player = pClass->localplayers[iPad]; @@ -4878,7 +4879,7 @@ int Minecraft::InGame_SignInReturned(void *pParam,bool bContinue, int iPad) #endif } // if this is a local game then profiles just need to be signed in - else if( g_NetworkManager.IsLocalGame() || (ProfileManager.IsSignedInLive(iPad) && ProfileManager.AllowedToPlayMultiplayer(iPad)) ) + else if( g_NetworkManager.IsLocalGame() || Live_MultiplayerAllowed(iPad) ) { #ifdef __ORBIS__ bool contentRestricted = false; @@ -4909,7 +4910,7 @@ int Minecraft::InGame_SignInReturned(void *pParam,bool bContinue, int iPad) } } } - else if( ProfileManager.IsSignedInLive(ProfileManager.GetPrimaryPad()) && !ProfileManager.AllowedToPlayMultiplayer(iPad) ) + else if( ProfileManager.IsSignedInLive(ProfileManager.GetPrimaryPad()) && !Live_AllowedToPlayMultiplayer(iPad) ) { // 4J Stu - Don't allow converting to guests as we don't allow any guest sign-in while in the game // Fix for #66516 - TCR #124: MPS Guest Support ; #001: BAS Game Stability: TU8: The game crashes when second Guest signs-in on console which takes part in Xbox LIVE multiplayer session. diff --git a/Minecraft.Client/Xbox/Xbox_Minecraft.cpp b/Minecraft.Client/Xbox/Xbox_Minecraft.cpp index 1db73176..0764aa03 100644 --- a/Minecraft.Client/Xbox/Xbox_Minecraft.cpp +++ b/Minecraft.Client/Xbox/Xbox_Minecraft.cpp @@ -29,6 +29,7 @@ #else #include "..\Windows64\Leaderboards\WindowsLeaderboardManager.h" #endif +#include "..\Common\Network\NetworkSocketLayer.h" #include "..\Common\XUI\XUI_Scene_Container.h" #include "..\..\Minecraft.Client\Tesselator.h" #include "..\..\Minecraft.Client\Options.h" @@ -494,6 +495,9 @@ int __cdecl main() // ProfileManager for XN_LIVE_INVITE_ACCEPTED for QNet. g_NetworkManager.Initialise(); + // Brings up XNet/Winsock and starts the LAN discovery listener + NetworkSocketLayer::Initialize(); + app.InitGameSettings(); // debug switch to trial version diff --git a/Minecraft.World/BlockRegionUpdatePacket.cpp b/Minecraft.World/BlockRegionUpdatePacket.cpp index 441501d6..ea91971d 100644 --- a/Minecraft.World/BlockRegionUpdatePacket.cpp +++ b/Minecraft.World/BlockRegionUpdatePacket.cpp @@ -74,7 +74,7 @@ BlockRegionUpdatePacket::BlockRegionUpdatePacket(int x, int y, int z, int xs, in unsigned char *ucTemp = new unsigned char[(256 * 16 * 16 * 5)/2]; unsigned int inputSize = (256 * 16 * 16 * 5)/2; - Compression::getCompression()->CompressLZXRLE(ucTemp, &inputSize, rawBuffer.data, (unsigned int) rawBuffer.length); + Compression::getCompression()->CompressNetworkRLE(ucTemp, &inputSize, rawBuffer.data, (unsigned int) rawBuffer.length); //app.DebugPrintf("Chunk (%d,%d) compressed from %d to size %d\n", x>>4, z>>4, rawBuffer.length, inputSize); unsigned char *ucTemp2 = new unsigned char[inputSize]; memcpy(ucTemp2,ucTemp,inputSize); @@ -120,7 +120,7 @@ void BlockRegionUpdatePacket::read(DataInputStream *dis) //throws IOException if( success ) { - Compression::getCompression()->DecompressLZXRLE( buffer.data, &outputSize, compressedBuffer.data, size); + Compression::getCompression()->DecompressNetworkRLE( buffer.data, &outputSize, compressedBuffer.data, size); } else { diff --git a/Minecraft.World/Minecraft.World.vcxproj b/Minecraft.World/Minecraft.World.vcxproj index 43c52d16..a0ea8837 100644 --- a/Minecraft.World/Minecraft.World.vcxproj +++ b/Minecraft.World/Minecraft.World.vcxproj @@ -858,7 +858,7 @@ false $(OutDir)$(ProjectName).pch MultiThreaded - _LARGE_WORLDS;_DEBUG_MENUS_ENABLED;_LIB;_CRT_NON_CONFORMING_SWPRINTFS;_CRT_SECURE_NO_WARNINGS;_WINDOWS64;%(PreprocessorDefinitions) + _DEBUG_MENUS_ENABLED;_LIB;_CRT_NON_CONFORMING_SWPRINTFS;_CRT_SECURE_NO_WARNINGS;_WINDOWS64;%(PreprocessorDefinitions) Disabled true false diff --git a/Minecraft.World/compression.cpp b/Minecraft.World/compression.cpp index bada5069..86bbe14e 100644 --- a/Minecraft.World/compression.cpp +++ b/Minecraft.World/compression.cpp @@ -1,6 +1,6 @@ #include "stdafx.h" #include "compression.h" -#if defined __ORBIS__ || defined __PS3__ || defined _DURANGO || defined _WIN64 +#if defined __ORBIS__ || defined __PS3__ || defined _DURANGO || defined _WIN64 || defined _XBOX #include "..\Minecraft.Client\Common\zlib\zlib.h" #endif @@ -54,7 +54,7 @@ Compression *Compression::getCompression() return tls->compression; } -HRESULT Compression::CompressLZXRLE(void *pDestination, unsigned int *pDestSize, void *pSource, unsigned int SrcSize) +HRESULT Compression::CompressLZXRLE(void *pDestination, unsigned int *pDestSize, void *pSource, unsigned int SrcSize, bool bForceZlib) { EnterCriticalSection(&rleCompressLock); //static unsigned char rleBuf[1024*100]; @@ -105,7 +105,8 @@ HRESULT Compression::CompressLZXRLE(void *pDestination, unsigned int *pDestSize, PIXEndNamedEvent(); PIXBeginNamedEvent(0,"Secondary compression"); - Compress(pDestination, pDestSize, rleCompressBuf, rleSize); + if( bForceZlib ) CompressZlib(pDestination, pDestSize, rleCompressBuf, rleSize); + else Compress(pDestination, pDestSize, rleCompressBuf, rleSize); PIXEndNamedEvent(); LeaveCriticalSection(&rleCompressLock); // printf("Compressed from %d to %d to %d\n",SrcSize,rleSize,*pDestSize); @@ -180,7 +181,7 @@ HRESULT Compression::CompressRLE(void *pDestination, unsigned int *pDestSize, vo return S_OK; } -HRESULT Compression::DecompressLZXRLE(void *pDestination, unsigned int *pDestSize, void *pSource, unsigned int SrcSize) +HRESULT Compression::DecompressLZXRLE(void *pDestination, unsigned int *pDestSize, void *pSource, unsigned int SrcSize, bool bForceZlib) { EnterCriticalSection(&rleDecompressLock); // 4J Stu - Fix for #13676 - Crash: Crash while attempting to load a world after updating TU @@ -200,12 +201,14 @@ HRESULT Compression::DecompressLZXRLE(void *pDestination, unsigned int *pDestSiz { rleSize = *pDestSize; dynamicRleBuf = new unsigned char[rleSize]; - Decompress(dynamicRleBuf, &rleSize, pSource, SrcSize); + if( bForceZlib ) DecompressZlib(dynamicRleBuf, &rleSize, pSource, SrcSize); + else Decompress(dynamicRleBuf, &rleSize, pSource, SrcSize); pucIn = (unsigned char *)dynamicRleBuf; } else { - Decompress(rleDecompressBuf, &rleSize, pSource, SrcSize); + if( bForceZlib ) DecompressZlib(rleDecompressBuf, &rleSize, pSource, SrcSize); + else Decompress(rleDecompressBuf, &rleSize, pSource, SrcSize); pucIn = (unsigned char *)rleDecompressBuf; } @@ -297,8 +300,40 @@ HRESULT Compression::DecompressRLE(void *pDestination, unsigned int *pDestSize, } +// zlib on every platform. +HRESULT Compression::CompressZlib(void *pDestination, unsigned int *pDestSize, void *pSource, unsigned int SrcSize) +{ +#if defined __PS3__ + uint32_t destSize = (uint32_t)(*pDestSize); + bool res = EdgeZLib::Compress(pDestination, &destSize, pSource, SrcSize); + *pDestSize = (unsigned int)destSize; + return ( ( res ) ? S_OK : -1 ); +#else + uLongf destSize = (uLongf)(*pDestSize); + int res = ::compress((Bytef *)pDestination, &destSize, (Bytef *)pSource, SrcSize); + *pDestSize = (unsigned int)destSize; + return ( ( res == Z_OK ) ? S_OK : -1 ); +#endif +} + +HRESULT Compression::DecompressZlib(void *pDestination, unsigned int *pDestSize, void *pSource, unsigned int SrcSize) +{ +#if defined __PS3__ + uLongf destSize = (uLongf)(*pDestSize); + bool res = uncompress((Bytef *)pDestination, &destSize, (Bytef *)pSource, SrcSize); + *pDestSize = (unsigned int)destSize; + return ( ( res ) ? S_OK : -1 ); +#else + uLongf destSize = (uLongf)(*pDestSize); + int res = ::uncompress((Bytef *)pDestination, &destSize, (Bytef *)pSource, SrcSize); + *pDestSize = (unsigned int)destSize; + return ( ( res == Z_OK ) ? S_OK : -1 ); +#endif +} + HRESULT Compression::Compress(void *pDestination, unsigned int *pDestSize, void *pSource, unsigned int SrcSize) { + //THIS IS THE OLD IMPL. USE HRESULT Compression::CompressZlib() // Using zlib for x64 compression - 360 is using native 360 compression and PS3 a stubbed non-compressing version of this #if defined __ORBIS__ || defined _DURANGO || defined _WIN64 || defined __PSVITA__ SIZE_T destSize = (SIZE_T)(*pDestSize); diff --git a/Minecraft.World/compression.h b/Minecraft.World/compression.h index 97dc819b..53ad4b88 100644 --- a/Minecraft.World/compression.h +++ b/Minecraft.World/compression.h @@ -41,8 +41,12 @@ public: public: HRESULT Compress(void *pDestination, unsigned int *pDestSize, void *pSource, unsigned int SrcSize); HRESULT Decompress(void *pDestination, unsigned int *pDestSize, void *pSource, unsigned int SrcSize); - HRESULT CompressLZXRLE(void *pDestination, unsigned int *pDestSize, void *pSource, unsigned int SrcSize); - HRESULT DecompressLZXRLE(void *pDestination, unsigned int *pDestSize, void *pSource, unsigned int SrcSize); + HRESULT CompressLZXRLE(void *pDestination, unsigned int *pDestSize, void *pSource, unsigned int SrcSize, bool bForceZlib = false); + HRESULT DecompressLZXRLE(void *pDestination, unsigned int *pDestSize, void *pSource, unsigned int SrcSize, bool bForceZlib = false); + HRESULT CompressNetworkRLE(void *pDestination, unsigned int *pDestSize, void *pSource, unsigned int SrcSize) + { return CompressLZXRLE(pDestination, pDestSize, pSource, SrcSize, true); } + HRESULT DecompressNetworkRLE(void *pDestination, unsigned int *pDestSize, void *pSource, unsigned int SrcSize) + { return DecompressLZXRLE(pDestination, pDestSize, pSource, SrcSize, true); } HRESULT CompressRLE(void *pDestination, unsigned int *pDestSize, void *pSource, unsigned int SrcSize); HRESULT DecompressRLE(void *pDestination, unsigned int *pDestSize, void *pSource, unsigned int SrcSize); #ifndef _XBOX @@ -59,6 +63,9 @@ private: HRESULT DecompressWithType(void *pDestination, unsigned int *pDestSize, void *pSource, unsigned int SrcSize); + HRESULT CompressZlib(void *pDestination, unsigned int *pDestSize, void *pSource, unsigned int SrcSize); + HRESULT DecompressZlib(void *pDestination, unsigned int *pDestSize, void *pSource, unsigned int SrcSize); + #if defined __ORBIS__ || defined __PS3__ #else XMEMCOMPRESSION_CONTEXT compressionContext;