diff options
| author | Loki Rautio <lokirautio@gmail.com> | 2026-03-04 05:57:56 -0600 |
|---|---|---|
| committer | Loki Rautio <lokirautio@gmail.com> | 2026-03-04 05:57:56 -0600 |
| commit | ea17b152b70122d8c58783fd9a67f45ecd8330cf (patch) | |
| tree | 8a86e346cbc7669efaebdbd2b5cda71c4adec013 /Minecraft.Client/Windows64 | |
| parent | 0993e628abc392821cb9049f4730cbb8f3d70522 (diff) | |
Restore username.txt loading without conflict
Still allows for -name launch argument, but restores old expected behavior
Diffstat (limited to 'Minecraft.Client/Windows64')
| -rw-r--r-- | Minecraft.Client/Windows64/Windows64_Minecraft.cpp | 42 |
1 files changed, 37 insertions, 5 deletions
diff --git a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp index c36ceee5..ec89feb1 100644 --- a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp +++ b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp @@ -1106,16 +1106,48 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, SetProcessDPIAware(); g_iScreenWidth = GetSystemMetrics(SM_CXSCREEN); g_iScreenHeight = GetSystemMetrics(SM_CYSCREEN); + + // Load username from username.txt + char exePath[MAX_PATH] = {}; + GetModuleFileNameA(NULL, exePath, MAX_PATH); + char *lastSlash = strrchr(exePath, '\\'); + if (lastSlash) + { + *(lastSlash + 1) = '\0'; + } + + char filePath[MAX_PATH] = {}; + _snprintf_s(filePath, sizeof(filePath), _TRUNCATE, "%susername.txt", exePath); + + FILE *f = nullptr; + if (fopen_s(&f, filePath, "r") == 0 && f) + { + char buf[128] = {}; + if (fgets(buf, sizeof(buf), f)) + { + int len = (int)strlen(buf); + while (len > 0 && (buf[len - 1] == '\n' || buf[len - 1] == '\r' || buf[len - 1] == ' ')) + { + buf[--len] = '\0'; + } + + if (len > 0) + { + strncpy_s(g_Win64Username, sizeof(g_Win64Username), buf, _TRUNCATE); + } + } + fclose(f); + } + + // Load stuff from launch options, including username Win64LaunchOptions launchOptions = ParseLaunchOptions(); ApplyScreenMode(launchOptions.screenMode); + // If no username, let's fall back if (g_Win64Username[0] == 0) { - DWORD sz = 17; - //if (!GetUserNameA(g_Win64Username, &sz)) - // todo: SET USERNAMES PROPERLY - strncpy_s(g_Win64Username, 17, "Player", _TRUNCATE); - g_Win64Username[16] = 0; + // Default username will be "Player" + strncpy_s(g_Win64Username, sizeof(g_Win64Username), "Player", _TRUNCATE); } MultiByteToWideChar(CP_ACP, 0, g_Win64Username, -1, g_Win64UsernameW, 17); |
