From 125819419ffb055c132d1d2aa3343146291379bb Mon Sep 17 00:00:00 2001 From: qloak Date: Sat, 8 Aug 2026 12:23:28 +0000 Subject: [PATCH] Xbox 360 fixes (again...) (#29) Merging main repo undid a lot of my changes so this PR reimplements them. Fixes build and playthrough. Has been tested.Reviewed-on: https://gitea.str1k3r.xyz/pieeebot/cafeberry/pulls/29 Co-authored-by: qloak --- .../Common/Network/NetworkSocketLayer.cpp | 59 +-- .../Common/Network/NetworkSocketLayer.h | 6 +- .../Common/Network/PlatformNetworkManager.cpp | 44 +- .../Common/Network/PlatformNetworkManager.h | 1 + Minecraft.Client/Minecraft.Client.vcxproj | 390 +++++++++++++----- Minecraft.Client/Xbox/Xbox_Minecraft.cpp | 3 + 6 files changed, 368 insertions(+), 135 deletions(-) diff --git a/Minecraft.Client/Common/Network/NetworkSocketLayer.cpp b/Minecraft.Client/Common/Network/NetworkSocketLayer.cpp index 008a94dd..a17aae00 100644 --- a/Minecraft.Client/Common/Network/NetworkSocketLayer.cpp +++ b/Minecraft.Client/Common/Network/NetworkSocketLayer.cpp @@ -486,31 +486,41 @@ 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 = 0; struct sockaddr_in addr = {}; addr.sin_family = AF_INET; addr.sin_port = htons((WORD)port); - addr.sin_addr = pDns->aina[0]; - XNetDnsRelease(pDns); + + unsigned long ipAddr = inet_addr(ip); + if (ipAddr != INADDR_NONE) + { + addr.sin_addr.s_addr = ipAddr; + } + 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, iResult); + XNetDnsRelease(pDns); + return false; + } + + addr.sin_addr = pDns->aina[0]; + XNetDnsRelease(pDns); + } bool connected = false; BYTE assignedSmallId = 0; @@ -935,7 +945,7 @@ int NetworkSocketLayer::AcceptThreadProc(LPVOID param) setsockopt(clientSocket, IPPROTO_TCP, TCP_NODELAY, (const char *)&noDelay, sizeof(noDelay)); extern QNET_STATE _iQNetStubState; - if (_iQNetStubState != QNET_STATE_GAME_PLAY) + if (_iQNetStubState != QNET_STATE_GAME_PLAY && _iQNetStubState != QNET_STATE_SESSION_STARTING) { app.DebugPrintf("Win64 LAN: Rejecting connection, game not ready\n"); closesocket(clientSocket); @@ -1260,7 +1270,8 @@ void NetworkSocketLayer::UpdateAdvertisePlayerNames(BYTE count, const char playe s_advertiseData.playerCount = count; for (int i = 0; i < count && i < 8; i++) { - memcpy(s_advertiseData.playerNames[i], playerNames[i], XUSER_NAME_SIZE); + memcpy(s_advertiseData.playerNames[i], playerNames[i], + NETWORK_LAN_PLAYER_NAME_SIZE < (int)XUSER_NAME_SIZE ? NETWORK_LAN_PLAYER_NAME_SIZE : (int)XUSER_NAME_SIZE); } LeaveCriticalSection(&s_advertiseLock); } diff --git a/Minecraft.Client/Common/Network/NetworkSocketLayer.h b/Minecraft.Client/Common/Network/NetworkSocketLayer.h index 62da1eb9..9949bdfd 100644 --- a/Minecraft.Client/Common/Network/NetworkSocketLayer.h +++ b/Minecraft.Client/Common/Network/NetworkSocketLayer.h @@ -100,6 +100,8 @@ typedef SceNetSocklen_t socklen_t; class Socket; +#define NETWORK_LAN_PLAYER_NAME_SIZE 32 + #pragma pack(push, 1) struct LANBroadcast { @@ -113,7 +115,7 @@ struct LANBroadcast DWORD texturePackParentId; BYTE subTexturePackId; BYTE isJoinable; - char playerNames[8][XUSER_NAME_SIZE]; + char playerNames[8][NETWORK_LAN_PLAYER_NAME_SIZE]; }; #pragma pack(pop) @@ -130,7 +132,7 @@ struct LANSession unsigned char subTexturePackId; bool isJoinable; DWORD lastSeenTick; - char playerNames[8][XUSER_NAME_SIZE]; + char playerNames[8][NETWORK_LAN_PLAYER_NAME_SIZE]; }; struct RemoteConnection diff --git a/Minecraft.Client/Common/Network/PlatformNetworkManager.cpp b/Minecraft.Client/Common/Network/PlatformNetworkManager.cpp index 56f40fbe..125183e4 100644 --- a/Minecraft.Client/Common/Network/PlatformNetworkManager.cpp +++ b/Minecraft.Client/Common/Network/PlatformNetworkManager.cpp @@ -12,6 +12,9 @@ CPlatformNetworkManagerStub *g_pPlatformNetworkManager; void CPlatformNetworkManagerStub::NotifyPlayerJoined(IQNetPlayer *pQNetPlayer ) { + if (getNetworkPlayer(pQNetPlayer) != NULL) + return; + const char * pszDescription; // 4J Stu - We create a fake socket for every where that we need an INBOUND queue of game data. Outbound @@ -164,6 +167,8 @@ bool CPlatformNetworkManagerStub::Initialise(CGameNetworkManager *pGameNetworkMa playerChangedCallback[ i ] = NULL; } + NetworkSocketLayer::Initialize(); + m_bLeavingGame = false; m_bLeaveGameOnTick = false; m_bHostChanged = false; @@ -373,6 +378,9 @@ void CPlatformNetworkManagerStub::HostGame(int localUsersMask, bool bOnlineGame, IQNet::m_player[0].m_isHostPlayer = true; IQNet::s_playerCount = 1; + if (getNetworkPlayer(&IQNet::m_player[0]) == NULL) + NotifyPlayerJoined(&IQNet::m_player[0]); + _HostGame( localUsersMask, publicSlots, privateSlots ); int port = NETWORK_LAN_DEFAULT_PORT; @@ -413,6 +421,7 @@ int CPlatformNetworkManagerStub::JoinGame(FriendSessionInfo *searchResult, int l IQNet::m_player[0].m_isRemote = true; IQNet::m_player[0].m_isHostPlayer = true; wcsncpy(IQNet::m_player[0].m_gamertag, searchResult->data.hostName, 31); + IQNet::m_player[0].m_gamertag[31] = L'\0'; NetworkSocketLayer::StopDiscovery(); @@ -435,8 +444,6 @@ int CPlatformNetworkManagerStub::JoinGame(FriendSessionInfo *searchResult, int l NotifyPlayerJoined(&IQNet::m_player[0]); NotifyPlayerJoined(&IQNet::m_player[localSmallId]); - m_pGameNetworkManager->StateChange_AnyToStarting(); - return CGameNetworkManager::JOINGAME_SUCCESS; } @@ -495,6 +502,18 @@ bool CPlatformNetworkManagerStub::_RunNetworkGame() return true; } +void CPlatformNetworkManagerStub::SetGamePlayState() +{ + extern QNET_STATE _iQNetStubState; + + _iQNetStubState = QNET_STATE_GAME_PLAY; + + if (m_pIQNet->IsHost()) + { + NetworkSocketLayer::UpdateAdvertiseJoinable(true); + } +} + void CPlatformNetworkManagerStub::UpdateAndSetGameSessionData(INetworkPlayer *pNetworkPlayerLeaving /*= NULL*/) { if (this->m_bLeavingGame) @@ -801,7 +820,22 @@ vector *CPlatformNetworkManagerStub::GetSessionList(int iPa { vector *filteredList = new vector(); for (size_t i = 0; i < friendsSessions[0].size(); i++) - filteredList->push_back(friendsSessions[0][i]); + { + FriendSessionInfo *src = friendsSessions[0][i]; + FriendSessionInfo *copy = new FriendSessionInfo(); + *copy = *src; + if (src->displayLabel != NULL) + { + copy->displayLabel = new wchar_t[(size_t)src->displayLabelLength + 1]; + wcsncpy(copy->displayLabel, src->displayLabel, src->displayLabelLength); + copy->displayLabel[src->displayLabelLength] = L'\0'; + } + else + { + copy->displayLabel = NULL; + } + filteredList->push_back(copy); + } return filteredList; } @@ -861,9 +895,11 @@ void CPlatformNetworkManagerStub::removeNetworkPlayer(IQNetPlayer *pQNetPlayer) if( *it == pNetworkPlayer ) { currentNetworkPlayers.erase(it); - return; + break; } } + + pQNetPlayer->SetCustomDataValue(0); } INetworkPlayer *CPlatformNetworkManagerStub::getNetworkPlayer(IQNetPlayer *pQNetPlayer) diff --git a/Minecraft.Client/Common/Network/PlatformNetworkManager.h b/Minecraft.Client/Common/Network/PlatformNetworkManager.h index b0f9fdcb..3db399e0 100644 --- a/Minecraft.Client/Common/Network/PlatformNetworkManager.h +++ b/Minecraft.Client/Common/Network/PlatformNetworkManager.h @@ -54,6 +54,7 @@ public: virtual void HandleSignInChange(); + virtual void SetGamePlayState(); virtual bool _RunNetworkGame(); private: diff --git a/Minecraft.Client/Minecraft.Client.vcxproj b/Minecraft.Client/Minecraft.Client.vcxproj index b71c2a79..d1674507 100644 --- a/Minecraft.Client/Minecraft.Client.vcxproj +++ b/Minecraft.Client/Minecraft.Client.vcxproj @@ -23445,13 +23445,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 @@ -23465,6 +23465,18 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CUfalse false true + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing NotUsing NotUsing NotUsing @@ -23491,13 +23503,13 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CUNotUsing - true - true - true - true - true - true - true + false + false + false + false + false + false + false false true false @@ -23511,6 +23523,18 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CUfalse false true + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing NotUsing NotUsing NotUsing @@ -23535,13 +23559,13 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CUfalse - true - true - true - true - true - true - true + false + false + false + false + false + false + false false true false @@ -23555,6 +23579,18 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CUfalse false true + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing NotUsing NotUsing NotUsing @@ -23579,13 +23615,13 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CUfalse - true - true - true - true - true - true - true + false + false + false + false + false + false + false false true false @@ -23599,6 +23635,18 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CUfalse false true + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing NotUsing NotUsing NotUsing @@ -23623,13 +23671,13 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CUfalse - true - true - true - true - true - true - true + false + false + false + false + false + false + false false true false @@ -23643,6 +23691,18 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CUfalse false true + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing NotUsing NotUsing NotUsing @@ -23674,13 +23734,13 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CUfalse - true - true - true - true - true - true - true + false + false + false + false + false + false + false false true false @@ -23694,6 +23754,18 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CUfalse false true + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing NotUsing NotUsing NotUsing @@ -23725,13 +23797,13 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CUfalse - true - true - true - true - true - true - true + false + false + false + false + false + false + false false true false @@ -23745,6 +23817,18 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CUfalse false true + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing NotUsing NotUsing NotUsing @@ -23776,13 +23860,13 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CUfalse - true - true - true - true - true - true - true + false + false + false + false + false + false + false false true false @@ -23796,6 +23880,18 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CUfalse false true + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing NotUsing NotUsing NotUsing @@ -23827,13 +23923,13 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CUfalse - true - true - true - true - true - true - true + false + false + false + false + false + false + false false true false @@ -23847,6 +23943,18 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CUfalse false true + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing NotUsing NotUsing NotUsing @@ -23871,13 +23979,13 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CUfalse - true - true - true - true - true - true - true + false + false + false + false + false + false + false false true false @@ -23891,6 +23999,18 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CUfalse false true + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing NotUsing NotUsing NotUsing @@ -23915,13 +24035,13 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CUfalse - true - true - true - true - true - true - true + false + false + false + false + false + false + false false true false @@ -23935,6 +24055,18 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CUfalse false true + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing NotUsing NotUsing NotUsing @@ -23959,13 +24091,13 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CUfalse - true - true - true - true - true - true - true + false + false + false + false + false + false + false false true false @@ -23979,6 +24111,18 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CUfalse false true + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing NotUsing NotUsing NotUsing @@ -24003,13 +24147,13 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CUfalse - true - true - true - true - true - true - true + false + false + false + false + false + false + false false true false @@ -24023,6 +24167,18 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CUfalse false true + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing NotUsing NotUsing NotUsing @@ -24047,13 +24203,13 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CUfalse - true - true - true - true - true - true - true + false + false + false + false + false + false + false false true false @@ -24067,6 +24223,18 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CUfalse false true + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing NotUsing NotUsing NotUsing @@ -24091,13 +24259,13 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CUfalse - true - true - true - true - true - true - true + false + false + false + false + false + false + false false true false @@ -24111,6 +24279,18 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CUfalse false true + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + CompileAsC + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing + NotUsing NotUsing NotUsing NotUsing diff --git a/Minecraft.Client/Xbox/Xbox_Minecraft.cpp b/Minecraft.Client/Xbox/Xbox_Minecraft.cpp index 1db73176..30c88dc9 100644 --- a/Minecraft.Client/Xbox/Xbox_Minecraft.cpp +++ b/Minecraft.Client/Xbox/Xbox_Minecraft.cpp @@ -30,6 +30,7 @@ #include "..\Windows64\Leaderboards\WindowsLeaderboardManager.h" #endif #include "..\Common\XUI\XUI_Scene_Container.h" +#include "..\Common\Network\NetworkSocketLayer.h" #include "..\..\Minecraft.Client\Tesselator.h" #include "..\..\Minecraft.Client\Options.h" #include "Sentient\SentientManager.h" @@ -494,6 +495,8 @@ int __cdecl main() // ProfileManager for XN_LIVE_INVITE_ACCEPTED for QNet. g_NetworkManager.Initialise(); + NetworkSocketLayer::Initialize(); + app.InitGameSettings(); // debug switch to trial version