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
@@ -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;
}