Fixed Xbox 360 crash

This commit is contained in:
2026-08-07 04:10:27 -07:00
parent 01abe05b18
commit 7135da3f37
32 changed files with 610 additions and 214 deletions
@@ -100,12 +100,14 @@ void CGameNetworkManager::DoWork()
{
case XN_LIVE_LINK_STATE_CHANGED:
{
#ifndef _DISABLE_XBLIVE
int iPrimaryPlayer = g_NetworkManager.GetPrimaryPad();
bool bConnected = (pNotification->uiParam!=0)?true:false;
if((g_NetworkManager.GetLockedProfile()!=-1) && iPrimaryPlayer!=-1 && bConnected == false && g_NetworkManager.IsInSession() )
{
app.SetAction(iPrimaryPlayer,eAppAction_EthernetDisconnected);
}
}
#endif
}
break;
case XN_LIVE_INVITE_ACCEPTED:
@@ -782,7 +784,11 @@ int CGameNetworkManager::JoinFromInvite_SignInReturned(void *pParam,bool bContin
app.DebugPrintf("JoinFromInvite_SignInReturned, iPad %d\n",iPad);
// It's possible that the player has not signed in - they can back out
#ifndef _DISABLE_XBLIVE
if(ProfileManager.IsSignedIn(iPad) && ProfileManager.IsSignedInLive(iPad) )
#else
if(ProfileManager.IsSignedIn(iPad))
#endif
{
app.DebugPrintf("JoinFromInvite_SignInReturned, passed sign-in tests\n");
int localUsersMask = 0;
@@ -794,7 +800,9 @@ int CGameNetworkManager::JoinFromInvite_SignInReturned(void *pParam,bool bContin
if(ProfileManager.IsSignedIn(index) )
{
++joiningUsers;
#ifndef _DISABLE_XBLIVE
if( !ProfileManager.AllowedToPlayMultiplayer(index) ) noPrivileges = true;
#endif
localUsersMask |= GetLocalPlayerMask( index );
}
}
@@ -905,7 +913,7 @@ int CGameNetworkManager::RunNetworkGameThreadProc( void* lpParameter )
TexturePack *tPack = Minecraft::GetInstance()->skins->getSelected();
while ( tPack->isLoadingData() || (Minecraft::GetInstance()->skins->needsUIUpdate() || ui.IsReloadingSkin()) )
{
Sleep(1);
Sleep(0);
}
ui.CleanUpSkinReload();
if(app.GetDisconnectReason() == DisconnectPacket::eDisconnect_None)
@@ -942,7 +950,7 @@ int CGameNetworkManager::ServerThreadProc( void* lpParameter )
{
while((Minecraft::GetInstance()->skins->needsUIUpdate() || ui.IsReloadingSkin()))
{
Sleep(1);
Sleep(0);
}
param->levelGen->loadBaseSaveData();
}
@@ -984,7 +992,7 @@ int CGameNetworkManager::ExitAndJoinFromInviteThreadProc( void* lpParam )
while( g_NetworkManager.IsInSession() )
{
Sleep(1);
Sleep(0);
}
// Xbox should always be online when receiving invites - on PS3 we need to check & ask the user to sign in
@@ -1260,7 +1268,7 @@ int CGameNetworkManager::ChangeSessionTypeThreadProc( void* lpParam )
// wait for the current session to end
while( g_NetworkManager.IsInSession() )
{
Sleep(1);
Sleep(0);
}
// Reset this flag as the we don't need to know that we only lost the room only from this point onwards, the behaviour is exactly the same
@@ -1662,6 +1670,7 @@ void CGameNetworkManager::GameInviteReceived( int userIndex, const INVITE_INFO *
{
if (ProfileManager.IsSignedIn(i) && (i == ProfileManager.GetPrimaryPad() || isLocalMultiplayerAvailable))
{
#ifndef _DISABLE_XBLIVE
if (isSignedInLive && !ProfileManager.IsSignedInLive(i))
{
// Record the first non signed in live pad
@@ -1669,6 +1678,9 @@ void CGameNetworkManager::GameInviteReceived( int userIndex, const INVITE_INFO *
}
isSignedInLive = isSignedInLive && ProfileManager.IsSignedInLive(i);
#else
isSignedInLive = true;
#endif
}
}
@@ -1740,7 +1752,9 @@ void CGameNetworkManager::GameInviteReceived( int userIndex, const INVITE_INFO *
if(index==userIndex || pMinecraft->localplayers[index]!=NULL )
{
++joiningUsers;
#ifndef _DISABLE_XBLIVE
if( !ProfileManager.AllowedToPlayMultiplayer(index) ) noPrivileges = true;
#endif
localUsersMask |= GetLocalPlayerMask( index );
}
}
@@ -1895,6 +1909,7 @@ void CGameNetworkManager::HandleInviteWhenInMenus( int userIndex, const INVITE_I
if(!app.IsLocalMultiplayerAvailable())
#endif
{
#ifndef _DISABLE_XBLIVE
bool noPrivileges=!ProfileManager.AllowedToPlayMultiplayer(userIndex);
if(noPrivileges)
@@ -1905,6 +1920,7 @@ void CGameNetworkManager::HandleInviteWhenInMenus( int userIndex, const INVITE_I
}
else
{
#endif
ProfileManager.SetLockedProfile(userIndex);
ProfileManager.SetPrimaryPad(userIndex);
@@ -1927,7 +1943,9 @@ void CGameNetworkManager::HandleInviteWhenInMenus( int userIndex, const INVITE_I
{
app.DebugPrintf( "Failed joining game from invite\n" );
}
#ifndef _DISABLE_XBLIVE
}
#endif
}
else
{
@@ -14,6 +14,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
@@ -160,6 +163,8 @@ bool CPlatformNetworkManagerStub::Initialise(CGameNetworkManager *pGameNetworkMa
{
playerChangedCallback[ i ] = NULL;
}
WinsockNetLayer::Initialize();
m_bLeavingGame = false;
m_bLeaveGameOnTick = false;
@@ -348,6 +353,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 = WIN64_NET_DEFAULT_PORT;
@@ -388,6 +396,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';
WinsockNetLayer::StopDiscovery();
@@ -754,7 +763,22 @@ vector<FriendSessionInfo *> *CPlatformNetworkManagerStub::GetSessionList(int iPa
{
vector<FriendSessionInfo *> *filteredList = new vector<FriendSessionInfo *>();
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;
}
@@ -802,9 +826,11 @@ void CPlatformNetworkManagerStub::removeNetworkPlayer(IQNetPlayer *pQNetPlayer)
if( *it == pNetworkPlayer )
{
currentNetworkPlayers.erase(it);
return;
break;
}
}
pQNetPlayer->SetCustomDataValue(0);
}
INetworkPlayer *CPlatformNetworkManagerStub::getNetworkPlayer(IQNetPlayer *pQNetPlayer)
@@ -361,31 +361,41 @@ bool WinsockNetLayer::JoinGame(const char *ip, int port)
return false;
}
#elif defined _XBOX
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;
}
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;
int iResult = XNetDnsLookup(ip, NULL, &pDns);
if (iResult != 0 || pDns == NULL)
{
app.DebugPrintf("XNetDnsLookup failed for %s - %d\n", ip, iResult);
return false;
}
int timeoutTicks = 500;
while (pDns->iStatus == WSAEINPROGRESS && --timeoutTicks > 0)
{
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);
}
s_hostConnectionSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (s_hostConnectionSocket == INVALID_SOCKET)
@@ -397,7 +407,7 @@ bool WinsockNetLayer::JoinGame(const char *ip, int port)
int noDelay = 1;
setsockopt(s_hostConnectionSocket, IPPROTO_TCP, TCP_NODELAY, (const char *)&noDelay, sizeof(noDelay));
iResult = connect(s_hostConnectionSocket, (struct sockaddr*)&addr, sizeof(addr));
int iResult = connect(s_hostConnectionSocket, (struct sockaddr*)&addr, sizeof(addr));
if (iResult == SOCKET_ERROR)
{
app.DebugPrintf("connect() to %s:%d failed: %d\n", ip, port, WSAGetLastError());
@@ -613,7 +623,7 @@ int WinsockNetLayer::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);
@@ -858,7 +868,7 @@ void WinsockNetLayer::StopAdvertising()
{
s_advertising = false;
#if defined _WINDOWS64
#if defined _WINDOWS64 || defined _XBOX
if (s_advertiseSock != INVALID_SOCKET)
{
closesocket(s_advertiseSock);
@@ -984,8 +994,16 @@ bool WinsockNetLayer::StartDiscovery()
return false;
}
#endif
#if defined _WINDOWS64
DWORD timeout = 500;
setsockopt(s_discoverySock, SOL_SOCKET, SO_RCVTIMEO, (const char *)&timeout, sizeof(timeout));
#elif defined _XBOX || defined __PS3__
struct timeval timeout;
timeout.tv_sec = 0;
timeout.tv_usec = 500000;
setsockopt(s_discoverySock, SOL_SOCKET, SO_RCVTIMEO, (const char *)&timeout, sizeof(timeout));
#endif
s_discovering = true;
s_discoveryThread = new C4JThread(DiscoveryThreadProc, NULL, "DiscoveryThreadProc");
@@ -1028,9 +1046,11 @@ void WinsockNetLayer::StopDiscovery()
std::vector<Win64LANSession> WinsockNetLayer::GetDiscoveredSessions()
{
std::vector<Win64LANSession> result;
EnterCriticalSection(&s_discoveryLock);
result = s_discoveredSessions;
LeaveCriticalSection(&s_discoveryLock);
if (TryEnterCriticalSection(&s_discoveryLock))
{
result = s_discoveredSessions;
LeaveCriticalSection(&s_discoveryLock);
}
return result;
}