update lcemp networking

This commit is contained in:
2026-08-14 07:02:50 +03:00
parent 125819419f
commit 6853eab85f
51 changed files with 629 additions and 183 deletions
+146 -15
View File
@@ -355,7 +355,7 @@ DWORD XEnableGuestSignin(BOOL fEnable) { return 0; }
/////////////////////////////////////////////// Profile library
#ifdef _WINDOWS64
static void *profileData[4];
static bool s_bProfileIsFullVersion;
static bool s_bProfileIsFullVersion = true;
void C_4JProfile::Initialise( DWORD dwTitleID,
DWORD dwOfferID,
unsigned short usProfileVersion,
@@ -374,6 +374,7 @@ void C_4JProfile::Initialise( DWORD dwTitleID,
GAME_SETTINGS *pGameSettings = (GAME_SETTINGS *)profileData[i];
pGameSettings->ucMenuSensitivity=100; //eGameSetting_Sensitivity_InMenu
pGameSettings->ucInterfaceOpacity=80; //eGameSetting_Sensitivity_InMenu
pGameSettings->ucGamma=100; //eGameSetting_Gamma
pGameSettings->usBitmaskValues|=0x0200; //eGameSetting_DisplaySplitscreenGamertags - on
pGameSettings->usBitmaskValues|=0x0400; //eGameSetting_Hints - on
pGameSettings->usBitmaskValues|=0x1000; //eGameSetting_Autosave - 2
@@ -437,7 +438,95 @@ DWORD IQNetPlayer::GetCurrentRtt() { return 0; }
bool IQNetPlayer::IsHost() { return m_isHostPlayer; }
bool IQNetPlayer::IsGuest() { return false; }
bool IQNetPlayer::IsLocal() { return !m_isRemote; }
PlayerUID IQNetPlayer::GetXuid() { return (PlayerUID)(0xe000d45248242f2e + m_smallId); }
static void Win64_BuildSplitName(int iPad, char *outName, int outSize);
PlayerUID IQNetPlayer::GetXuid()
{
#if defined(_WINDOWS64) || defined(DISABLE_PSN) || defined(_DISABLE_XBLIVE)
if (!m_isRemote)
{
int idx = (int)(this - &IQNet::m_player[0]);
if (idx == 0)
{
extern char g_Win64Username[17];
return Win64_UsernameToXuid(g_Win64Username);
}
if (idx > 0 && idx < XUSER_MAX_COUNT)
{
char splitName[32];
Win64_BuildSplitName(idx, splitName, sizeof(splitName));
return Win64_UsernameToXuid(splitName);
}
}
#endif
return (PlayerUID)(0xe000d45248242f2e + m_smallId);
}
PlayerUID Win64_UsernameToXuid(const char* username)
{
uint64_t hash = 14695981039346656037ULL;
for (const char* p = username; *p; ++p)
{
hash ^= (uint64_t)(unsigned char)(*p);
hash *= 1099511628211ULL;
}
const uint64_t WIN64_XUID_BASE = 0xe000d45248242f2e;
if (hash >= WIN64_XUID_BASE && hash <= WIN64_XUID_BASE + MINECRAFT_NET_MAX_PLAYERS)
hash = WIN64_XUID_BASE + MINECRAFT_NET_MAX_PLAYERS + 1;
if (hash == 0)
hash = 1;
return (PlayerUID)hash;
}
PlayerUID Win64_UsernameToXuid(const wchar_t* username)
{
char narrow[64];
int i = 0;
for (; username[i] && i < 63; ++i)
narrow[i] = (char)(unsigned char)(username[i] & 0xFF);
narrow[i] = 0;
return Win64_UsernameToXuid(narrow);
}
static void Win64_BuildSplitName(int iPad, char *outName, int outSize)
{
extern char g_Win64Username[17];
char candidate[32];
sprintf(candidate, "%s_%d", g_Win64Username, iPad);
for (DWORD i = 0; i < MINECRAFT_NET_MAX_PLAYERS; i++)
{
if (!IQNet::m_player[i].m_isRemote) continue;
if (IQNet::m_player[i].m_gamertag[0] == 0) continue;
char remoteName[64];
int j = 0;
for (; IQNet::m_player[i].m_gamertag[j] && j < 63; ++j)
remoteName[j] = (char)(unsigned char)(IQNet::m_player[i].m_gamertag[j] & 0xFF);
remoteName[j] = 0;
#if defined(_MSC_VER)
if (_stricmp(candidate, remoteName) == 0)
#else
if (strcasecmp(candidate, remoteName) == 0)
#endif
{
sprintf(candidate, "%s_%d_L", g_Win64Username, iPad);
break;
}
}
strncpy(outName, candidate, outSize - 1);
outName[outSize - 1] = 0;
}
static void Win64_BuildSplitNameW(int iPad, wchar_t *outName, int outSize)
{
char narrow[32];
Win64_BuildSplitName(iPad, narrow, sizeof(narrow));
for (int i = 0; i < outSize - 1 && narrow[i]; ++i)
{
outName[i] = (wchar_t)(unsigned char)narrow[i];
outName[i + 1] = 0;
}
}
LPCWSTR IQNetPlayer::GetGamertag() { return m_gamertag; }
int IQNetPlayer::GetSessionIndex() { return m_smallId; }
bool IQNetPlayer::IsTalking() { return false; }
@@ -470,15 +559,30 @@ void Win64_SetupRemoteQNetPlayer(IQNetPlayer *player, BYTE smallId, bool isHost,
static bool Win64_IsActivePlayer(IQNetPlayer *p, DWORD index);
HRESULT IQNet::AddLocalPlayerByUserIndex(DWORD dwUserIndex){ return S_OK; }
HRESULT IQNet::AddLocalPlayerByUserIndex(DWORD dwUserIndex)
{
// no E_FAIL on PS3.
if (dwUserIndex >= MINECRAFT_NET_MAX_PLAYERS) return (HRESULT)0x80004005L;
m_player[dwUserIndex].m_isRemote = false;
m_player[dwUserIndex].m_smallId = (BYTE)dwUserIndex;
if (dwUserIndex > 0)
{
wchar_t splitNameW[32];
Win64_BuildSplitNameW((int)dwUserIndex, splitNameW, 32);
wcsncpy(m_player[dwUserIndex].m_gamertag, splitNameW, 32 - 1);
m_player[dwUserIndex].m_gamertag[32 - 1] = 0;
}
if (dwUserIndex >= (DWORD)s_playerCount)
s_playerCount = dwUserIndex + 1;
return S_OK;
}
IQNetPlayer *IQNet::GetHostPlayer() { return &m_player[0]; }
IQNetPlayer *IQNet::GetLocalPlayerByUserIndex(DWORD dwUserIndex)
{
if (s_isHosting)
{
if (dwUserIndex < MINECRAFT_NET_MAX_PLAYERS &&
!m_player[dwUserIndex].m_isRemote &&
Win64_IsActivePlayer(&m_player[dwUserIndex], dwUserIndex))
!m_player[dwUserIndex].m_isRemote)
return &m_player[dwUserIndex];
return NULL;
}
@@ -575,7 +679,7 @@ void C_4JProfile::SetTrialTextStringTable(CXuiStringTable *pStringTable,int i
void C_4JProfile::SetTrialAwardText(eAwardType AwardType,int iTitle,int iText) {}
int C_4JProfile::GetLockedProfile() { return 0; }
void C_4JProfile::SetLockedProfile(int iProf) {}
bool C_4JProfile::IsSignedIn(int iQuadrant) { return ( iQuadrant == 0); }
bool C_4JProfile::IsSignedIn(int iQuadrant) { return (iQuadrant >= 0 && iQuadrant < XUSER_MAX_COUNT); }
bool C_4JProfile::IsSignedInLive(int iProf) { return true; }
bool C_4JProfile::IsGuest(int iQuadrant) { return false; }
UINT C_4JProfile::RequestSignInUI(bool bFromInvite,bool bLocalGame,bool bNoGuestsAllowed,bool bMultiplayerSignIn,bool bAddUser, int( *Func)(LPVOID,const bool, const int iPad),LPVOID lpParam,int iQuadrant) { return 0; }
@@ -585,16 +689,21 @@ void C_4JProfile::SetPrimaryPlayerChanged(bool bVal) {}
bool C_4JProfile::QuerySigninStatus(void) { return true; }
void C_4JProfile::GetXUID(int iPad, PlayerUID *pXuid,bool bOnlineXuid)
{
if (iPad != 0)
if (iPad == 0)
{
// previously INVALID_XUID
*pXuid = 0;
return;
extern char g_Win64Username[17];
*pXuid = Win64_UsernameToXuid(g_Win64Username);
}
else if (iPad > 0 && iPad < XUSER_MAX_COUNT)
{
char splitName[32];
Win64_BuildSplitName(iPad, splitName, sizeof(splitName));
*pXuid = Win64_UsernameToXuid(splitName);
}
if (IQNet::s_isHosting)
*pXuid = 0xe000d45248242f2e;
else
*pXuid = 0xe000d45248242f2e + NetworkSocketLayer::GetLocalSmallId();
{
*pXuid = INVALID_XUID;
}
}
BOOL C_4JProfile::AreXUIDSEqual(PlayerUID xuid1,PlayerUID xuid2) { return xuid1 == xuid2; }
BOOL C_4JProfile::XUIDIsGuest(PlayerUID xuid) { return false; }
@@ -623,8 +732,30 @@ char fakeGamerTag[32] = "PlayerName";
void SetFakeGamertag(char *name){ strcpy_s(fakeGamerTag, name); }
char* C_4JProfile::GetGamertag(int iPad){ return fakeGamerTag; }
#else
char* C_4JProfile::GetGamertag(int iPad){ extern char g_Win64Username[17]; return g_Win64Username; }
wstring C_4JProfile::GetDisplayName(int iPad){ extern wchar_t g_Win64UsernameW[17]; return g_Win64UsernameW; }
static char s_win64SplitNames[4][32];
char* C_4JProfile::GetGamertag(int iPad)
{
extern char g_Win64Username[17];
if (iPad == 0) return g_Win64Username;
if (iPad > 0 && iPad < XUSER_MAX_COUNT)
{
Win64_BuildSplitName(iPad, s_win64SplitNames[iPad], sizeof(s_win64SplitNames[iPad]));
return s_win64SplitNames[iPad];
}
return g_Win64Username;
}
wstring C_4JProfile::GetDisplayName(int iPad)
{
extern wchar_t g_Win64UsernameW[17];
if (iPad == 0) return g_Win64UsernameW;
if (iPad > 0 && iPad < XUSER_MAX_COUNT)
{
wchar_t buf[32];
Win64_BuildSplitNameW(iPad, buf, 32);
return buf;
}
return g_Win64UsernameW;
}
#endif
bool C_4JProfile::IsFullVersion() { return s_bProfileIsFullVersion; }
void C_4JProfile::SetSignInChangeCallback(void ( *Func)(LPVOID, bool, unsigned int),LPVOID lpParam) {}