diff --git a/Minecraft.Client/ClientConnection.cpp b/Minecraft.Client/ClientConnection.cpp index b3476836..962d0fae 100644 --- a/Minecraft.Client/ClientConnection.cpp +++ b/Minecraft.Client/ClientConnection.cpp @@ -1833,6 +1833,7 @@ void ClientConnection::handleEntityActionAtPosition(shared_ptr packet) { + app.DebugPrintf("ClientConnection::handlePreLogin ENTER (user %d)\n", m_userIndex); // printf("Client: handlePreLogin\n"); #if 1 // 4J - Check that we can play with all the players already in the game who have Friends-Only UGC set @@ -2287,7 +2288,8 @@ void ClientConnection::handlePreLogin(shared_ptr packet) } BOOL allAllowed, friendsAllowed; ProfileManager.AllowedPlayerCreatedContent(m_userIndex,true,&allAllowed,&friendsAllowed); - send( shared_ptr( new LoginPacket(minecraft->user->name, SharedConstants::NETWORK_PROTOCOL_VERSION, offlineXUID, onlineXUID, (allAllowed!=TRUE && friendsAllowed==TRUE), + 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 )))); if(!g_NetworkManager.IsHost() ) diff --git a/Minecraft.Client/Common/Network/NetworkSocketLayer.cpp b/Minecraft.Client/Common/Network/NetworkSocketLayer.cpp index 66d3ba31..36d68a5f 100644 --- a/Minecraft.Client/Common/Network/NetworkSocketLayer.cpp +++ b/Minecraft.Client/Common/Network/NetworkSocketLayer.cpp @@ -20,7 +20,8 @@ void terminate_networking() {}; #endif #if defined __PSVITA__ -int socket(int family, int type, int protocol) { return sceNetSocket(NULL, family, type, protocol); }; +// every sceNet sample names its sockets - NULL is not a documented value here +int socket(int family, int type, int protocol) { return sceNetSocket("minecraft", family, type, protocol); }; #endif C4JThread* NetworkSocketLayer::s_acceptThread = NULL; @@ -59,18 +60,16 @@ std::vector NetworkSocketLayer::s_freeSmallIds; // only goes true on a successful Initialize(), and a failed one gets retried static bool s_locksCreated = false; - -bool g_MultiplayerHost = false; -#if defined __ORBIS__ -// Orbis has direct lan networking so it can bypass psn account checks -bool g_MultiplayerJoin = true; -int g_MultiplayerPort = NETWORK_LAN_DEFAULT_PORT; -char g_MultiplayerIP[256] = ""; -#else +#if defined _WINDOWS64 +bool g_MultiplayerHost = true; bool g_MultiplayerJoin = false; -int g_MultiplayerPort = NETWORK_LAN_DEFAULT_PORT; -char g_MultiplayerIP[256] = "127.0.0.1"; +#else +bool g_MultiplayerHost = false; +bool g_MultiplayerJoin = true; #endif +int g_MultiplayerPort = NETWORK_LAN_DEFAULT_PORT; +char g_MultiplayerIP[256] = "192.168.0.69"; + bool NetworkSocketLayer::Initialize() { @@ -271,6 +270,9 @@ bool NetworkSocketLayer::HostGame(int port) SceNetSockaddrIn addr = {}; #else struct sockaddr_in addr = {}; +#endif +#ifdef __PSVITA__ + addr.sin_len = sizeof(addr); #endif addr.sin_family = AF_INET; addr.sin_addr.s_addr = htonl(INADDR_ANY); @@ -595,7 +597,7 @@ bool NetworkSocketLayer::JoinGame(const char *ip, int port) struct sockaddr_in addr = {}; #endif -#if defined(__ORBIS__) +#if defined(__ORBIS__) || defined(__PSVITA__) addr.sin_len = sizeof(addr); #endif addr.sin_family = AF_INET; @@ -608,7 +610,7 @@ bool NetworkSocketLayer::JoinGame(const char *ip, int port) app.DebugPrintf("inet_addr failed for %s:%d\n", ip, port); return false; } -#elif defined(__ORBIS__) +#elif defined(__ORBIS__) || defined(__PSVITA__) if (sceNetInetPton(SCE_NET_AF_INET, ip, &addr.sin_addr.s_addr) <= 0) { app.DebugPrintf("inet_addr failed for %s:%d\n", ip, port); @@ -655,7 +657,15 @@ bool NetworkSocketLayer::JoinGame(const char *ip, int port) tv.tv_sec = connectTimeoutMs / 1000; tv.tv_usec = (connectTimeoutMs % 1000) * 1000; #else - SceNetId eid = sceNetEpollCreate(NULL, 0); + // like sceNetSocket, this takes a name and NULL is not a documented value + SceNetId eid = sceNetEpollCreate("minecraft-connect", 0); + if (eid < 0) + { + app.DebugPrintf("sceNetEpollCreate failed: 0x%08x\n", eid); + closesocket(s_hostConnectionSocket); + s_hostConnectionSocket = INVALID_SOCKET; + continue; + } SceNetEpollEvent ev = {}; ev.events = SCE_NET_EPOLLOUT; ev.data.fd = s_hostConnectionSocket; @@ -675,6 +685,10 @@ bool NetworkSocketLayer::JoinGame(const char *ip, int port) (outEvents[0].events & (SCE_NET_EPOLLERR | SCE_NET_EPOLLHUP))) #endif { +#ifdef __PSVITA__ + app.DebugPrintf("epoll wait=%d events=0x%x errno=0x%08x\n", + selectResult, selectResult > 0 ? outEvents[0].events : 0, sys_net_errno); +#endif app.DebugPrintf("connect() to %s:%d timed out or failed (attempt %d/%d)\n", ip, port, attempt + 1, maxAttempts); closesocket(s_hostConnectionSocket); s_hostConnectionSocket = INVALID_SOCKET; @@ -708,7 +722,12 @@ bool NetworkSocketLayer::JoinGame(const char *ip, int port) setsockopt(s_hostConnectionSocket, SOL_SOCKET, SCE_NET_SO_NBIO, &blocking, sizeof(blocking)); #endif +#ifdef __PSVITA__ + // sceNet takes microseconds + int recvTimeout = 3000 * 1000; +#else DWORD recvTimeout = 3000; +#endif setsockopt(s_hostConnectionSocket, SOL_SOCKET, SO_RCVTIMEO, (const char *)&recvTimeout, sizeof(recvTimeout)); /* iResult = connect(s_hostConnectionSocket, (struct sockaddr*)&addr, sizeof(addr)); @@ -865,7 +884,13 @@ void NetworkSocketLayer::HandleDataReceived(BYTE fromSmallId, BYTE toSmallId, un INetworkPlayer *pPlayerFrom = g_NetworkManager.GetPlayerBySmallId(fromSmallId); INetworkPlayer *pPlayerTo = g_NetworkManager.GetPlayerBySmallId(toSmallId); - if (pPlayerFrom == NULL || pPlayerTo == NULL) return; + if (pPlayerFrom == NULL || pPlayerTo == NULL) + { + // dropping here is silent and looks identical to the peer never sending + app.DebugPrintf("LAN: DROPPED %u bytes - from smallId=%d(%s) to smallId=%d(%s)\n", + dataSize, fromSmallId, pPlayerFrom ? "ok" : "NULL", toSmallId, pPlayerTo ? "ok" : "NULL"); + return; + } if (s_isHost) { @@ -1135,6 +1160,14 @@ int NetworkSocketLayer::ClientRecvThreadProc(LPVOID param) break; } + static int s_recvLogged = 0; + if (s_recvLogged < 20) + { + app.DebugPrintf("LAN: recv %d bytes from host (host=%d local=%d)\n", + packetSize, s_hostSmallId, s_localSmallId); + s_recvLogged++; + } + HandleDataReceived(s_hostSmallId, s_localSmallId, &recvBuf[0], packetSize); } @@ -1247,6 +1280,9 @@ int NetworkSocketLayer::AdvertiseThreadProc(LPVOID param) struct sockaddr_in broadcastAddr; #endif memset(&broadcastAddr, 0, sizeof(broadcastAddr)); +#ifdef __PSVITA__ + broadcastAddr.sin_len = sizeof(broadcastAddr); +#endif broadcastAddr.sin_family = AF_INET; broadcastAddr.sin_port = htons(NETWORK_LAN_DISCOVERY_PORT); broadcastAddr.sin_addr.s_addr = INADDR_BROADCAST; @@ -1266,6 +1302,38 @@ int NetworkSocketLayer::AdvertiseThreadProc(LPVOID param) #ifdef __PSVITA__ int sent = sendto(s_advertiseSock, (const char *)&data, sizeof(data), 0, (const sockaddr *)&broadcastAddr, sizeof(broadcastAddr)); +#elif defined _WINDOWS64 + //Broadcast on all interfaces. + INTERFACE_INFO ifaces[32]; + DWORD ifaceBytes = 0; + int numIfaces = 0; + int sent = SOCKET_ERROR; + if (WSAIoctl(s_advertiseSock, SIO_GET_INTERFACE_LIST, NULL, 0, + ifaces, sizeof(ifaces), &ifaceBytes, NULL, NULL) != SOCKET_ERROR) + { + numIfaces = (int)(ifaceBytes / sizeof(INTERFACE_INFO)); + } + for (int i = 0; i < numIfaces; i++) + { + if (!(ifaces[i].iiFlags & IFF_UP)) continue; + if (ifaces[i].iiFlags & IFF_LOOPBACK) continue; + if (!(ifaces[i].iiFlags & IFF_BROADCAST)) continue; + + u_long ifIp = ifaces[i].iiAddress.AddressIn.sin_addr.s_addr; + u_long ifMask = ifaces[i].iiNetmask.AddressIn.sin_addr.s_addr; + broadcastAddr.sin_addr.s_addr = (ifIp & ifMask) | ~ifMask; + + int r = sendto(s_advertiseSock, (const char *)&data, sizeof(data), 0, + (struct sockaddr *)&broadcastAddr, sizeof(broadcastAddr)); + if (r != SOCKET_ERROR) sent = r; + } + if (sent == SOCKET_ERROR) + { + // no interface worked + broadcastAddr.sin_addr.s_addr = INADDR_BROADCAST; + sent = sendto(s_advertiseSock, (const char *)&data, sizeof(data), 0, + (struct sockaddr *)&broadcastAddr, sizeof(broadcastAddr)); + } #else int sent = sendto(s_advertiseSock, (const char *)&data, sizeof(data), 0, (struct sockaddr *)&broadcastAddr, sizeof(broadcastAddr)); @@ -1320,6 +1388,10 @@ bool NetworkSocketLayer::StartDiscovery() struct sockaddr_in bindAddr; #endif memset(&bindAddr, 0, sizeof(bindAddr)); +#ifdef __PSVITA__ + // sceNet rejects a sockaddr whose sin_len is unset + bindAddr.sin_len = sizeof(bindAddr); +#endif bindAddr.sin_family = AF_INET; bindAddr.sin_port = htons(NETWORK_LAN_DISCOVERY_PORT); bindAddr.sin_addr.s_addr = INADDR_ANY; @@ -1354,6 +1426,10 @@ bool NetworkSocketLayer::StartDiscovery() timeout.tv_sec = 0; timeout.tv_usec = 500000; setsockopt(s_discoverySock, SOL_SOCKET, SO_RCVTIMEO, (const char *)&timeout, sizeof(timeout)); +#elif defined __PSVITA__ + // sceNet wants microseconds in an int here + int timeout = 500000; + setsockopt(s_discoverySock, SOL_SOCKET, SO_RCVTIMEO, (const char *)&timeout, sizeof(timeout)); #endif s_discovering = true; diff --git a/Minecraft.Client/Common/Postbuilds/PSVita-postbuild.ps1 b/Minecraft.Client/Common/Postbuilds/PSVita-postbuild.ps1 index aeabac4d..2e421af3 100644 --- a/Minecraft.Client/Common/Postbuilds/PSVita-postbuild.ps1 +++ b/Minecraft.Client/Common/Postbuilds/PSVita-postbuild.ps1 @@ -12,7 +12,8 @@ $directories = @( "PSVITA_GAME\Common\Media", "PSVITA_GAME\Common\res", "PSVITA_GAME\PSVita\Sound", - "PSVITA_GAME\PSVita\Tutorial" + "PSVITA_GAME\PSVita\Tutorial", + "PSVITA_GAME\savedata" ) foreach ($dir in $directories) { diff --git a/Minecraft.Client/Common/UI/UIScene_LoadMenu.cpp b/Minecraft.Client/Common/UI/UIScene_LoadMenu.cpp index 27c961af..7c7eda77 100644 --- a/Minecraft.Client/Common/UI/UIScene_LoadMenu.cpp +++ b/Minecraft.Client/Common/UI/UIScene_LoadMenu.cpp @@ -877,6 +877,7 @@ void UIScene_LoadMenu::StartSharedLaunchFlow() app.SetGameHostOption(eGameHostOption_DisableSaving, m_MoreOptionsParams.bDisableSaving?1:0); StorageManager.SetSaveDisabled(m_MoreOptionsParams.bDisableSaving); +#ifdef _LARGE_WORLDS int newWorldSize = 0; int newHellScale = 0; switch(m_MoreOptionsParams.newWorldSize) @@ -909,6 +910,7 @@ void UIScene_LoadMenu::StartSharedLaunchFlow() app.SetGameNewWorldSize(newWorldSize, bUseMoat); app.SetGameNewHellScale(newHellScale); app.SetGameHostOption(eGameHostOption_WorldSize, m_MoreOptionsParams.newWorldSize); +#endif #endif diff --git a/Minecraft.Client/Minecraft.Client.vcxproj b/Minecraft.Client/Minecraft.Client.vcxproj index 9eab3062..cd6c2ee3 100644 --- a/Minecraft.Client/Minecraft.Client.vcxproj +++ b/Minecraft.Client/Minecraft.Client.vcxproj @@ -2092,7 +2092,7 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CUtrue Level2 Orbis\Iggy\include;$(ProjectDir);%(AdditionalIncludeDirectories) - SPLIT_SAVES;_LARGE_WORLDS;_EXTENDED_ACHIEVEMENTS;_DEBUG_MENUS_ENABLED + SPLIT_SAVES;_EXTENDED_ACHIEVEMENTS;_DEBUG_MENUS_ENABLED ..\Minecraft.World\ORBIS_Release\Minecraft.World.a;Orbis\4JLibs\libs\4j_Render.a;Orbis\4JLibs\libs\4j_Input_r.a;Orbis\4JLibs\libs\4J_Storage_r.a;Orbis\4JLibs\libs\4J_Profile_r.a;Orbis\Iggy\lib\libiggy_orbis.a;Orbis\Miles\lib\mssorbis.a;Orbis\Miles\lib\binkaorbis.a;Common\Network\Sony\sceRemoteStorage\ps4\lib\sceRemoteStorage.a;-lSceGnmDriver_stub_weak;-lSceGnmx;-lSceGnm;-lSceGpuAddress;-lSceCes;-lSceVideoOut_stub_weak;-lScePad_stub_weak;-lScePngDec_stub_weak;-lScePngEnc_stub_weak;-lSceFios2_stub_weak;-lSceUlt_stub_weak;-lSceShaderBinary;-lSceUserService_stub_weak;-lSceSysmodule_stub_weak;-lSceImeDialog_stub_weak;-lScePosix_stub_weak;-lSceAudioOut_stub_weak;-lSceSaveData_stub_weak;-lSceRtc_stub_weak;-lSceSystemService_stub_weak;-lSceNetCtl_stub_weak;-lSceNpCommon_stub_weak;-lSceNpManager_stub_weak;-lSceNpToolkit;-lSceNpToolkitUtils;-lSceNpWebApi_stub_weak;-lSceNpAuth_stub_weak;-lSceNpTrophy_stub_weak;-lSceInvitationDialog_stub_weak;-lSceGameCustomDataDialog_stub_weak;-lSceNpCommerce_stub_weak;-lSceNet_stub_weak;-lSceHttp_stub_weak;-lSceSsl_stub_weak;-lSceNpMatching2_stub_weak;-lSceNpTus_stub_weak;-lSceNpUtility_stub_weak;-lSceNpScore_stub_weak;-lSceCommonDialog_stub_weak;-lSceNpSns_stub_weak;-lSceNpSnsFacebookDialog_stub_weak;-lSceRudp_stub_weak;-lSceAppContent_stub_weak;-lSceVoice_stub_weak;-lSceAudioIn_stub_weak;-lSceRemoteplay_stub_weak;-lSceSaveDataDialog_stub_weak;-lSceErrorDialog_stub_weak;-lSceMsgDialog_stub_weak;-lSceGameLiveStreaming_stub_weak;%(AdditionalDependencies) diff --git a/Minecraft.Client/Windows64/Sound/Minecraft.msscmp b/Minecraft.Client/Windows64/Sound/Minecraft.msscmp index 0d0df508..ba22b635 100644 Binary files a/Minecraft.Client/Windows64/Sound/Minecraft.msscmp and b/Minecraft.Client/Windows64/Sound/Minecraft.msscmp differ diff --git a/Minecraft.World/Minecraft.World.vcxproj b/Minecraft.World/Minecraft.World.vcxproj index 5b74574e..a0ea8837 100644 --- a/Minecraft.World/Minecraft.World.vcxproj +++ b/Minecraft.World/Minecraft.World.vcxproj @@ -1447,7 +1447,7 @@ true true Level2 - SPLIT_SAVES;_LARGE_WORLDS;_EXTENDED_ACHIEVEMENTS;DEBUG_MENUS_ENABLED + SPLIT_SAVES;_EXTENDED_ACHIEVEMENTS;DEBUG_MENUS_ENABLED diff --git a/Minecraft.World/ThreadName.cpp b/Minecraft.World/ThreadName.cpp index a08f11b8..a21d67c8 100644 --- a/Minecraft.World/ThreadName.cpp +++ b/Minecraft.World/ThreadName.cpp @@ -20,9 +20,16 @@ void SetThreadName( DWORD dwThreadID, LPCSTR szThreadName ) info.dwFlags = 0; #if ( defined _WINDOWS64 | defined _DURANGO ) + // 0x406D1388 is a debugger protocol, not a real exception - only a debugger + // can consume it. With nothing attached it terminates the process. + if( !IsDebuggerPresent() ) + return; + __try { - RaiseException( 0x406D1388, 0, sizeof(info)/sizeof(DWORD), (ULONG_PTR *)&info ); + // count is in ULONG_PTRs, not DWORDs - on x64 the DWORD count made + // RaiseException read past the end of info + RaiseException( 0x406D1388, 0, sizeof(info)/sizeof(ULONG_PTR), (ULONG_PTR *)&info ); } __except( GetExceptionCode()==0x406D1388 ? EXCEPTION_CONTINUE_EXECUTION : EXCEPTION_EXECUTE_HANDLER ) {