mirror of
https://forge.banditvault.co.uk/racoon/MinecraftConsoles.git
synced 2026-06-09 05:44:35 +00:00
feat: Implement LCELive username handling and logging for Windows64 client
This commit is contained in:
@@ -205,6 +205,9 @@ static bool g_bResizeReady = false;
|
||||
|
||||
char g_Win64Username[17] = { 0 };
|
||||
wchar_t g_Win64UsernameW[17] = { 0 };
|
||||
static char g_Win64FallbackUsername[17] = { 0 };
|
||||
static const char *g_Win64FallbackUsernameSource = "default";
|
||||
static bool g_Win64NameLockedToLaunchOverride = false;
|
||||
|
||||
// Fullscreen toggle state
|
||||
static bool g_isFullscreen = false;
|
||||
@@ -214,6 +217,7 @@ struct Win64LaunchOptions
|
||||
{
|
||||
int screenMode;
|
||||
bool fullscreen;
|
||||
bool usernameOverride;
|
||||
};
|
||||
|
||||
static void CopyWideArgToAnsi(LPCWSTR source, char* dest, size_t destSize)
|
||||
@@ -229,6 +233,53 @@ static void CopyWideArgToAnsi(LPCWSTR source, char* dest, size_t destSize)
|
||||
dest[destSize - 1] = 0;
|
||||
}
|
||||
|
||||
static void ApplyWin64Username(const char *username, const char *source, bool updateRuntime)
|
||||
{
|
||||
if (username == nullptr || username[0] == 0)
|
||||
return;
|
||||
|
||||
char nextUsername[sizeof(g_Win64Username)] = {};
|
||||
strncpy_s(nextUsername, sizeof(nextUsername), username, _TRUNCATE);
|
||||
if (nextUsername[0] == 0)
|
||||
return;
|
||||
|
||||
const bool changed = strcmp(g_Win64Username, nextUsername) != 0;
|
||||
strncpy_s(g_Win64Username, sizeof(g_Win64Username), nextUsername, _TRUNCATE);
|
||||
MultiByteToWideChar(CP_ACP, 0, g_Win64Username, -1, g_Win64UsernameW, static_cast<int>(_countof(g_Win64UsernameW)));
|
||||
|
||||
if (changed)
|
||||
GameLog("[IDENTITY] Using %s username: %s\n", source != nullptr ? source : "configured", g_Win64Username);
|
||||
|
||||
if (updateRuntime)
|
||||
{
|
||||
wcsncpy_s(IQNet::m_player[0].m_gamertag, 32, g_Win64UsernameW, _TRUNCATE);
|
||||
|
||||
Minecraft *minecraft = Minecraft::GetInstance();
|
||||
if (minecraft != nullptr && minecraft->user != nullptr)
|
||||
minecraft->user->name = g_Win64UsernameW;
|
||||
}
|
||||
}
|
||||
|
||||
static void RefreshWin64UsernameFromIdentity(bool updateRuntime)
|
||||
{
|
||||
if (!g_Win64NameLockedToLaunchOverride)
|
||||
{
|
||||
std::wstring lceLiveUsername;
|
||||
if (Win64LceLive::GetSignedInUsername(&lceLiveUsername) && !lceLiveUsername.empty())
|
||||
{
|
||||
char lceLiveUsernameAnsi[sizeof(g_Win64Username)] = {};
|
||||
CopyWideArgToAnsi(lceLiveUsername.c_str(), lceLiveUsernameAnsi, sizeof(lceLiveUsernameAnsi));
|
||||
if (lceLiveUsernameAnsi[0] != 0)
|
||||
{
|
||||
ApplyWin64Username(lceLiveUsernameAnsi, "LCELive", updateRuntime);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ApplyWin64Username(g_Win64FallbackUsername, g_Win64FallbackUsernameSource, updateRuntime);
|
||||
}
|
||||
|
||||
// ---------- Persistent options (options.txt next to exe) ----------
|
||||
static void GetOptionsFilePath(char *out, size_t outSize)
|
||||
{
|
||||
@@ -318,6 +369,7 @@ static Win64LaunchOptions ParseLaunchOptions()
|
||||
if (_wcsicmp(argv[i], L"-name") == 0 && (i + 1) < argc)
|
||||
{
|
||||
CopyWideArgToAnsi(argv[++i], g_Win64Username, sizeof(g_Win64Username));
|
||||
options.usernameOverride = g_Win64Username[0] != 0;
|
||||
}
|
||||
else if (_wcsicmp(argv[i], L"-ip") == 0 && (i + 1) < argc)
|
||||
{
|
||||
@@ -1535,6 +1587,7 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
|
||||
if (len > 0)
|
||||
{
|
||||
strncpy_s(g_Win64Username, sizeof(g_Win64Username), buf, _TRUNCATE);
|
||||
g_Win64FallbackUsernameSource = "username.txt";
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
@@ -1542,6 +1595,9 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
|
||||
|
||||
// Load stuff from launch options, including username
|
||||
const Win64LaunchOptions launchOptions = ParseLaunchOptions();
|
||||
g_Win64NameLockedToLaunchOverride = launchOptions.usernameOverride;
|
||||
if (launchOptions.usernameOverride)
|
||||
g_Win64FallbackUsernameSource = "launch argument";
|
||||
ApplyScreenMode(launchOptions.screenMode);
|
||||
|
||||
// Ensure uid.dat exists from startup (before any multiplayer/login path).
|
||||
@@ -1552,9 +1608,11 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
|
||||
{
|
||||
// Default username will be "Player"
|
||||
strncpy_s(g_Win64Username, sizeof(g_Win64Username), "Player", _TRUNCATE);
|
||||
g_Win64FallbackUsernameSource = "default";
|
||||
}
|
||||
|
||||
MultiByteToWideChar(CP_ACP, 0, g_Win64Username, -1, g_Win64UsernameW, 17);
|
||||
strncpy_s(g_Win64FallbackUsername, sizeof(g_Win64FallbackUsername), g_Win64Username, _TRUNCATE);
|
||||
RefreshWin64UsernameFromIdentity(false);
|
||||
|
||||
// convert servers.txt to servers.db
|
||||
if (GetFileAttributesA("servers.txt") != INVALID_FILE_ATTRIBUTES &&
|
||||
@@ -1855,6 +1913,7 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
|
||||
|
||||
// LceLive platform service ticks — keep auth token fresh, drive P2P + signaling.
|
||||
Win64LceLive::Tick();
|
||||
RefreshWin64UsernameFromIdentity(true);
|
||||
Win64LceLiveP2P::P2PTick();
|
||||
Win64LceLiveSignaling::Tick();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user