diff --git a/Minecraft.Client/Common/Consoles_App.cpp b/Minecraft.Client/Common/Consoles_App.cpp index 82043249..7b4cdfaa 100644 --- a/Minecraft.Client/Common/Consoles_App.cpp +++ b/Minecraft.Client/Common/Consoles_App.cpp @@ -27,6 +27,9 @@ #include "../GameMode.h" #include "../Xbox/Social/SocialManager.h" #include "Tutorial/TutorialMode.h" +#ifdef _WINDOWS64 +#include "../Windows64/Network/WinsockNetLayer.h" // HUCKLE - added for quit on disconnect +#endif #if defined _XBOX || defined _WINDOWS64 #include "../Xbox/XML/ATGXmlParser.h" #include "../Xbox/XML/xmlFilesCallback.h" @@ -3388,6 +3391,15 @@ void CMinecraftApp::HandleXuiActions(void) SetAction(i,eAppAction_Idle); + // HUCKLE - added for quit game on disconnect +#ifdef _WINDOWS64 + if(g_Win64MultiplayerQuitOnDisconnect == true) + { + app.ExitGame(); + return; + } +#endif + // If we're already leaving don't exit if (g_NetworkManager.IsLeavingGame()) { diff --git a/Minecraft.Client/Common/UI/UIScene_Intro.cpp b/Minecraft.Client/Common/UI/UIScene_Intro.cpp index f4aefc40..975df407 100644 --- a/Minecraft.Client/Common/UI/UIScene_Intro.cpp +++ b/Minecraft.Client/Common/UI/UIScene_Intro.cpp @@ -2,6 +2,12 @@ #include "UI.h" #include "UIScene_Intro.h" +// HUCKLE - added below for joining game on launch +#ifdef _WINDOWS64 +#include "../../Windows64/Network/WinsockNetLayer.h" +#include "../../User.h" +#endif + UIScene_Intro::UIScene_Intro(int iPad, void *initData, UILayer *parentLayer) : UIScene(iPad, parentLayer) { @@ -104,6 +110,82 @@ void UIScene_Intro::handleInput(int iPad, int key, bool repeat, bool pressed, bo } #elif defined _XBOX_ONE ui.NavigateToScene(0,eUIScene_MainMenu); +#elif defined _WINDOWS64 + // HUCKLE - added this for auto joining servers on game launch + // THANKS so much to DrPerky and GeorgeV22 for helping with this bit, honestly got stuck for 4 hours :sob: + if(g_Win64MultiplayerJoin == true) + { + int primaryPad = ProfileManager.GetPrimaryPad(); + + if (!ProfileManager.IsSignedIn(primaryPad) || ProfileManager.IsGuest(primaryPad)) + { + UINT uiIDA[1] = { IDS_OK }; + ui.RequestErrorMessage(IDS_MUST_SIGN_IN_TITLE, IDS_MUST_SIGN_IN_TEXT, uiIDA, 1); + ui.NavigateToScene(0, eUIScene_MainMenu); + return; + } + + app.ClearSignInChangeUsersMask(); + app.ReleaseSaveThumbnail(); + ProfileManager.SetLockedProfile(primaryPad); + ProfileManager.QuerySigninStatus(); + + if (!app.DLCInstallProcessCompleted()) + app.StartInstallDLCProcess(primaryPad); + + Minecraft* pMinecraft = Minecraft::GetInstance(); + pMinecraft->user->name = convStringToWstring(ProfileManager.GetGamertag(primaryPad)); + app.ApplyGameSettingsChanged(primaryPad); + + auto sessionInfo = std::make_unique(); + + // label and name + const wchar_t* defaultName = L""; + size_t nameLen = wcslen(defaultName); + + // ip and port + strncpy_s(sessionInfo->data.hostIP, g_Win64MultiplayerIP, sizeof(sessionInfo->data.hostIP) - 1); + sessionInfo->data.hostPort = g_Win64MultiplayerPort; + + // display label + sessionInfo->displayLabel = new wchar_t[nameLen + 1]; + wcscpy_s(sessionInfo->displayLabel, nameLen + 1, defaultName); + sessionInfo->displayLabelLength = static_cast(nameLen); + sessionInfo->displayLabelViewableStartIndex = 0; + + // name + wcsncpy_s(sessionInfo->data.hostName, XUSER_NAME_SIZE, defaultName, _TRUNCATE); + + // session ids + sessionInfo->sessionId = static_cast(inet_addr(g_Win64MultiplayerIP)) | + static_cast(g_Win64MultiplayerPort) << 32; + + // random props + sessionInfo->data.isReadyToJoin = true; + sessionInfo->data.isJoinable = true; + + DWORD dwLocalUsersMask = 0; + dwLocalUsersMask |= CGameNetworkManager::GetLocalPlayerMask(ProfileManager.GetPrimaryPad()); + + CGameNetworkManager::eJoinGameResult result = g_NetworkManager.JoinGame( sessionInfo.get(), dwLocalUsersMask ); + + if (result == CGameNetworkManager::JOINGAME_PENDING) + { + ConnectionProgressParams *param = new ConnectionProgressParams(); + param->iPad = ProfileManager.GetPrimaryPad(); + param->stringId = IDS_PROGRESS_CONNECTING; + param->showTooltips = true; + param->setFailTimer = false; + param->timerTime = 0; + param->cancelFunc = nullptr; + param->cancelFuncParam = nullptr; + ui.NavigateToScene(ProfileManager.GetPrimaryPad(), eUIScene_ConnectingProgress, param); + } + } + else + { + ui.NavigateToScene(0,eUIScene_SaveMessage); + } #else ui.NavigateToScene(0,eUIScene_SaveMessage); #endif @@ -169,6 +251,82 @@ void UIScene_Intro::handleAnimationEnd() { m_bAnimationEnded = true; } +#elif defined _WINDOWS64 + // HUCKLE - added this for auto joining servers on game launch + // THANKS so much to DrPerky and GeorgeV22 for helping with this bit, honestly got stuck for 4 hours :sob: + if(g_Win64MultiplayerJoin == true) + { + int primaryPad = ProfileManager.GetPrimaryPad(); + + if (!ProfileManager.IsSignedIn(primaryPad) || ProfileManager.IsGuest(primaryPad)) + { + UINT uiIDA[1] = { IDS_OK }; + ui.RequestErrorMessage(IDS_MUST_SIGN_IN_TITLE, IDS_MUST_SIGN_IN_TEXT, uiIDA, 1); + ui.NavigateToScene(0, eUIScene_MainMenu); + return; + } + + app.ClearSignInChangeUsersMask(); + app.ReleaseSaveThumbnail(); + ProfileManager.SetLockedProfile(primaryPad); + ProfileManager.QuerySigninStatus(); + + if (!app.DLCInstallProcessCompleted()) + app.StartInstallDLCProcess(primaryPad); + + Minecraft* pMinecraft = Minecraft::GetInstance(); + pMinecraft->user->name = convStringToWstring(ProfileManager.GetGamertag(primaryPad)); + app.ApplyGameSettingsChanged(primaryPad); + + auto sessionInfo = std::make_unique(); + + // label and name + const wchar_t* defaultName = L""; + size_t nameLen = wcslen(defaultName); + + // ip and port + strncpy_s(sessionInfo->data.hostIP, g_Win64MultiplayerIP, sizeof(sessionInfo->data.hostIP) - 1); + sessionInfo->data.hostPort = g_Win64MultiplayerPort; + + // display label + sessionInfo->displayLabel = new wchar_t[nameLen + 1]; + wcscpy_s(sessionInfo->displayLabel, nameLen + 1, defaultName); + sessionInfo->displayLabelLength = static_cast(nameLen); + sessionInfo->displayLabelViewableStartIndex = 0; + + // name + wcsncpy_s(sessionInfo->data.hostName, XUSER_NAME_SIZE, defaultName, _TRUNCATE); + + // session ids + sessionInfo->sessionId = static_cast(inet_addr(g_Win64MultiplayerIP)) | + static_cast(g_Win64MultiplayerPort) << 32; + + // random props + sessionInfo->data.isReadyToJoin = true; + sessionInfo->data.isJoinable = true; + + DWORD dwLocalUsersMask = 0; + dwLocalUsersMask |= CGameNetworkManager::GetLocalPlayerMask(ProfileManager.GetPrimaryPad()); + + CGameNetworkManager::eJoinGameResult result = g_NetworkManager.JoinGame( sessionInfo.get(), dwLocalUsersMask ); + + if (result == CGameNetworkManager::JOINGAME_PENDING) + { + ConnectionProgressParams *param = new ConnectionProgressParams(); + param->iPad = ProfileManager.GetPrimaryPad(); + param->stringId = IDS_PROGRESS_CONNECTING; + param->showTooltips = true; + param->setFailTimer = false; + param->timerTime = 0; + param->cancelFunc = nullptr; + param->cancelFuncParam = nullptr; + ui.NavigateToScene(ProfileManager.GetPrimaryPad(), eUIScene_ConnectingProgress, param); + } + } + else + { + ui.NavigateToScene(0,eUIScene_SaveMessage); + } #else ui.NavigateToScene(0,eUIScene_SaveMessage); #endif diff --git a/Minecraft.Client/Windows64/Network/WinsockNetLayer.cpp b/Minecraft.Client/Windows64/Network/WinsockNetLayer.cpp index e763e3d5..904103b7 100644 --- a/Minecraft.Client/Windows64/Network/WinsockNetLayer.cpp +++ b/Minecraft.Client/Windows64/Network/WinsockNetLayer.cpp @@ -115,6 +115,7 @@ bool WinsockNetLayer::s_clientKeyStored = false; bool g_Win64MultiplayerHost = false; bool g_Win64MultiplayerJoin = false; +bool g_Win64MultiplayerQuitOnDisconnect = false; int g_Win64MultiplayerPort = WIN64_NET_DEFAULT_PORT; char g_Win64MultiplayerIP[256] = "127.0.0.1"; bool g_Win64DedicatedServer = false; diff --git a/Minecraft.Client/Windows64/Network/WinsockNetLayer.h b/Minecraft.Client/Windows64/Network/WinsockNetLayer.h index a4eb2fae..dc830c84 100644 --- a/Minecraft.Client/Windows64/Network/WinsockNetLayer.h +++ b/Minecraft.Client/Windows64/Network/WinsockNetLayer.h @@ -227,6 +227,7 @@ public: extern bool g_Win64MultiplayerHost; extern bool g_Win64MultiplayerJoin; +extern bool g_Win64MultiplayerQuitOnDisconnect; extern int g_Win64MultiplayerPort; extern char g_Win64MultiplayerIP[256]; extern bool g_Win64DedicatedServer; diff --git a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp index 48af6508..03467061 100644 --- a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp +++ b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp @@ -219,6 +219,7 @@ static Win64LaunchOptions ParseLaunchOptions() Win64LaunchOptions options = {}; options.screenMode = 0; + g_Win64MultiplayerQuitOnDisconnect = false; g_Win64MultiplayerJoin = false; g_Win64MultiplayerPort = WIN64_NET_DEFAULT_PORT; @@ -239,6 +240,10 @@ static Win64LaunchOptions ParseLaunchOptions() { CopyWideArgToAnsi(argv[++i], g_Win64Username, sizeof(g_Win64Username)); } + else if (_wcsicmp(argv[i], L"-quitondisconnect") == 0) + { + g_Win64MultiplayerQuitOnDisconnect = true; + } else if (_wcsicmp(argv[i], L"-ip") == 0 && (i + 1) < argc) { char ipBuf[256]; @@ -1759,7 +1764,7 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, return 1; } g_bResizeReady = true; - + //app.TemporaryCreateGameStart(); //Sleep(10000);