Fix player save data issue & multiple username implementations (#257)

* fix saving issue & multiple username implementations

* Update README.md

Updated the method for overriding in-game username from '-name' to 'username.txt'.

* remove unused include i forgot to get rid of while testing
This commit is contained in:
Slenderman
2026-03-03 11:58:22 -05:00
committed by GitHub
parent 5c91c26086
commit 515f91cad8
7 changed files with 20 additions and 50 deletions

View File

@@ -1978,7 +1978,7 @@ bool CGameNetworkManager::AllowedToPlayMultiplayer(int playerIdx)
return ProfileManager.AllowedToPlayMultiplayer(playerIdx);
}
char *CGameNetworkManager::GetOnlineName(int playerIdx)
const char *CGameNetworkManager::GetOnlineName(int playerIdx)
{
return ProfileManager.GetGamertag(playerIdx);
}

View File

@@ -196,7 +196,7 @@ private:
int GetLockedProfile();
bool IsSignedInLive(int playerIdx);
bool AllowedToPlayMultiplayer(int playerIdx);
char *GetOnlineName(int playerIdx);
const char *GetOnlineName(int playerIdx);
C4JThread::Event* m_hServerStoppedEvent;
C4JThread::Event* m_hServerReadyEvent;

View File

@@ -589,8 +589,21 @@ 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; }
#include <windows.h>
const char* C_4JProfile::GetGamertag(int iPad)
{
static std::string narrowName;
const wchar_t* wideName = g_playerName.c_str();
int sizeNeeded = WideCharToMultiByte(CP_UTF8, 0, wideName, -1, nullptr, 0, nullptr, nullptr);
narrowName.resize(sizeNeeded);
WideCharToMultiByte(CP_UTF8, 0, wideName, -1, &narrowName[0], sizeNeeded, nullptr, nullptr);
return narrowName.c_str();
}
wstring C_4JProfile::GetDisplayName(int iPad) { return g_playerName; }
#endif
bool C_4JProfile::IsFullVersion() { return s_bProfileIsFullVersion; }
void C_4JProfile::SetSignInChangeCallback(void (*Func)(LPVOID, bool, unsigned int), LPVOID lpParam) {}

View File

@@ -75,7 +75,7 @@ public:
// SYS
int GetPrimaryPad();
void SetPrimaryPad(int iPad);
char* GetGamertag(int iPad);
const char* GetGamertag(int iPad);
wstring GetDisplayName(int iPad);
bool IsFullVersion();
void SetSignInChangeCallback(void ( *Func)(LPVOID, bool, unsigned int),LPVOID lpParam);

View File

@@ -33,6 +33,7 @@ public:
virtual void TemporaryCreateGameStart();
bool m_bShutdown;
wstring g_playerName;
};
extern CConsoleMinecraftApp app;

View File

@@ -85,8 +85,6 @@ BOOL g_bWidescreen = TRUE;
int g_iScreenWidth = 1920;
int g_iScreenHeight = 1080;
char g_Win64Username[17] = { 0 };
wchar_t g_Win64UsernameW[17] = { 0 };
UINT g_ScreenWidth = 1920;
UINT g_ScreenHeight = 1080;
@@ -764,42 +762,8 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
//g_iScreenWidth = 960;
//g_iScreenHeight = 544;
}
char cmdLineA[1024];
strncpy_s(cmdLineA, sizeof(cmdLineA), lpCmdLine, _TRUNCATE);
char* nameArg = strstr(cmdLineA, "-name ");
if (nameArg)
{
nameArg += 6;
while (*nameArg == ' ') nameArg++;
char nameBuf[17];
int n = 0;
while (nameArg[n] && nameArg[n] != ' ' && n < 16) { nameBuf[n] = nameArg[n]; n++; }
nameBuf[n] = 0;
strncpy_s(g_Win64Username, 17, nameBuf, _TRUNCATE);
}
}
if (g_Win64Username[0] == 0)
{
DWORD sz = 17;
static bool seeded = false;
if (!seeded)
{
seeded = true;
srand((unsigned int)time(NULL));
}
int r = rand() % 10000; // 0<>9999
snprintf(g_Win64Username, 17, "Player%04d", r);
g_Win64Username[16] = 0;
}
MultiByteToWideChar(CP_ACP, 0, g_Win64Username, -1, g_Win64UsernameW, 17);
// Initialize global strings
MyRegisterClass(hInstance);
@@ -971,8 +935,6 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
IQNet::m_player[i].m_isHostPlayer = (i == 0);
swprintf_s(IQNet::m_player[i].m_gamertag, 32, L"Player%d", i);
}
extern wchar_t g_Win64UsernameW[17];
wcscpy_s(IQNet::m_player[0].m_gamertag, 32, g_Win64UsernameW);
WinsockNetLayer::Initialize();

View File

@@ -33,13 +33,7 @@ Basic LAN multiplayer is available on the Windows build
- Other players on the same LAN can discover the session from the in-game Join Game menu
- Game connections use TCP port `25565` by default
- LAN discovery uses UDP port `25566`
- You can override your in-game username at launch with `-name`
Example:
```powershell
Minecraft.Client.exe -name Steve
```
- You can override your in-game username at launch with `username.txt`
This feature is based on [LCEMP](https://github.com/LCEMP/LCEMP/)