Files
neoStudiosLCE-neoLegacy/Minecraft.Client/Common/UI/UIScene_Intro.cpp
Huckle d55a38eb84 feat: Make -ip and -port args join server on game launch (#96)
feat: Add -quitondisconnect arg

Co-authored-by: TheHuckle <crazyh.dev@gmail.com>
2026-05-20 17:45:57 +03:00

345 lines
11 KiB
C++

#include "stdafx.h"
#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)
{
// Setup all the Iggy references we need for this scene
initialiseMovie();
m_bIgnoreNavigate = false;
m_bAnimationEnded = false;
bool bSkipESRB = false;
bool bChina = false;
#if defined(__PS3__) || defined(__ORBIS__) || defined(__PSVITA__)
bSkipESRB = app.GetProductSKU() != e_sku_SCEA;
#elif defined(_XBOX) || defined(_DURANGO)
bSkipESRB = !ProfileManager.LocaleIsUSorCanada();
#endif
#ifdef _DURANGO
bChina = ProfileManager.LocaleIsChina();
#endif
// 4J Stu - These map to values in the Actionscript
#ifdef _WINDOWS64
int platformIdx = 0;
#elif defined(_XBOX)
int platformIdx = 1;
#elif defined(_DURANGO)
int platformIdx = 2;
#elif defined(__PS3__)
int platformIdx = 3;
#elif defined(__ORBIS__)
int platformIdx = 4;
#elif defined(__PSVITA__)
int platformIdx = 5;
#endif
IggyDataValue result;
IggyDataValue value[3];
value[0].type = IGGY_DATATYPE_number;
value[0].number = platformIdx;
value[1].type = IGGY_DATATYPE_boolean;
value[1].boolval = bChina?true:bSkipESRB;
value[2].type = IGGY_DATATYPE_boolean;
value[2].boolval = bChina;
IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcSetIntroPlatform , 3 , value );
#ifdef __PSVITA__
// initialise vita touch controls with ids
m_TouchToSkip.init(0);
#endif
}
wstring UIScene_Intro::getMoviePath()
{
return L"Intro";
}
void UIScene_Intro::handleInput(int iPad, int key, bool repeat, bool pressed, bool released, bool &handled)
{
ui.AnimateKeyPress(m_iPad, key, repeat, pressed, released);
switch(key)
{
case ACTION_MENU_OK:
#ifdef __ORBIS__
case ACTION_MENU_TOUCHPAD_PRESS:
#endif
if(!m_bIgnoreNavigate)
{
m_bIgnoreNavigate = true;
//ui.NavigateToHomeMenu();
#if defined(__PS3__) || defined(__ORBIS__) || defined (__PSVITA__)
// has the user seen the EULA already ? We need their options file loaded for this
C4JStorage::eOptionsCallback eStatus=app.GetOptionsCallbackStatus(0);
switch(eStatus)
{
case C4JStorage::eOptions_Callback_Read:
case C4JStorage::eOptions_Callback_Read_FileNotFound:
// we've either read it, or it wasn't found
#if 0
if(app.GetGameSettings(0,eGameSetting_PS3_EULA_Read)==0)
{
ui.NavigateToScene(0,eUIScene_EULA);
}
else
#endif
{
ui.NavigateToScene(0,eUIScene_SaveMessage);
}
break;
default:
#if 0
ui.NavigateToScene(0,eUIScene_EULA);
#else
ui.NavigateToScene(0,eUIScene_SaveMessage);
#endif
break;
}
#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<FriendSessionInfo>();
// 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<unsigned char>(nameLen);
sessionInfo->displayLabelViewableStartIndex = 0;
// name
wcsncpy_s(sessionInfo->data.hostName, XUSER_NAME_SIZE, defaultName, _TRUNCATE);
// session ids
sessionInfo->sessionId = static_cast<uint64_t>(inet_addr(g_Win64MultiplayerIP)) |
static_cast<uint64_t>(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
}
break;
}
}
#ifdef __PSVITA__
void UIScene_Intro::handleTouchInput(unsigned int iPad, S32 x, S32 y, int iId, bool bPressed, bool bRepeat, bool bReleased)
{
if(bReleased)
{
bool handled = false;
handleInput(iPad, ACTION_MENU_OK, false, true, false, handled);
}
}
#endif
void UIScene_Intro::handleAnimationEnd()
{
if(!m_bIgnoreNavigate)
{
m_bIgnoreNavigate = true;
//ui.NavigateToHomeMenu();
#if defined(__PS3__) || defined(__ORBIS__) || defined(__PSVITA__)
// has the user seen the EULA already ? We need their options file loaded for this
C4JStorage::eOptionsCallback eStatus=app.GetOptionsCallbackStatus(0);
switch(eStatus)
{
case C4JStorage::eOptions_Callback_Read:
case C4JStorage::eOptions_Callback_Read_FileNotFound:
// we've either read it, or it wasn't found
#if 0
if(app.GetGameSettings(0,eGameSetting_PS3_EULA_Read)==0)
{
ui.NavigateToScene(0,eUIScene_EULA);
}
else
#endif
{
ui.NavigateToScene(0,eUIScene_SaveMessage);
}
break;
default:
#if 0
ui.NavigateToScene(0,eUIScene_EULA);
#else
ui.NavigateToScene(0,eUIScene_SaveMessage);
#endif
break;
}
#elif defined _XBOX_ONE
// Don't navigate to the main menu if we don't have focus, as we could have the quadrant sign-in or a join game timer screen running, and then when Those finish they'll
// give the main menu focus which clears the signed in players and therefore breaks transitioning into the game
if( hasFocus( m_iPad ) )
{
ui.NavigateToScene(0,eUIScene_MainMenu);
}
else
{
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<FriendSessionInfo>();
// 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<unsigned char>(nameLen);
sessionInfo->displayLabelViewableStartIndex = 0;
// name
wcsncpy_s(sessionInfo->data.hostName, XUSER_NAME_SIZE, defaultName, _TRUNCATE);
// session ids
sessionInfo->sessionId = static_cast<uint64_t>(inet_addr(g_Win64MultiplayerIP)) |
static_cast<uint64_t>(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
}
}
void UIScene_Intro::handleGainFocus(bool navBack)
{
// Only relevant on xbox one - if we didn't navigate to the main menu at animation end due to the timer or quadrant sign-in being up, then we'll need to
// do it now in case the user has cancelled or joining a game failed
if( m_bAnimationEnded )
{
ui.NavigateToScene(0,eUIScene_MainMenu);
}
}