Skip to content

Commit b42a4a4

Browse files
authored
Revert "Revert "Win64: configurable username (username.txt) and persistent ga…" (#235)
This reverts commit 7f7d995.
1 parent 7f7d995 commit b42a4a4

File tree

5 files changed

+132
-8
lines changed

5 files changed

+132
-8
lines changed

Minecraft.Client/Common/Consoles_App.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,43 @@ bool CMinecraftApp::LoadBeaconMenu(int iPad ,shared_ptr<Inventory> inventory, sh
760760
//////////////////////////////////////////////
761761
// GAME SETTINGS
762762
//////////////////////////////////////////////
763+
764+
#ifdef _WINDOWS64
765+
static void Win64_GetSettingsPath(char *outPath, DWORD size)
766+
{
767+
GetModuleFileNameA(NULL, outPath, size);
768+
char *lastSlash = strrchr(outPath, '\\');
769+
if (lastSlash) *(lastSlash + 1) = '\0';
770+
strncat_s(outPath, size, "settings.dat", _TRUNCATE);
771+
}
772+
static void Win64_SaveSettings(GAME_SETTINGS *gs)
773+
{
774+
if (!gs) return;
775+
char filePath[MAX_PATH] = {};
776+
Win64_GetSettingsPath(filePath, MAX_PATH);
777+
FILE *f = NULL;
778+
if (fopen_s(&f, filePath, "wb") == 0 && f)
779+
{
780+
fwrite(gs, sizeof(GAME_SETTINGS), 1, f);
781+
fclose(f);
782+
}
783+
}
784+
static void Win64_LoadSettings(GAME_SETTINGS *gs)
785+
{
786+
if (!gs) return;
787+
char filePath[MAX_PATH] = {};
788+
Win64_GetSettingsPath(filePath, MAX_PATH);
789+
FILE *f = NULL;
790+
if (fopen_s(&f, filePath, "rb") == 0 && f)
791+
{
792+
GAME_SETTINGS temp = {};
793+
if (fread(&temp, sizeof(GAME_SETTINGS), 1, f) == 1)
794+
memcpy(gs, &temp, sizeof(GAME_SETTINGS));
795+
fclose(f);
796+
}
797+
}
798+
#endif
799+
763800
void CMinecraftApp::InitGameSettings()
764801
{
765802
for(int i=0;i<XUSER_MAX_COUNT;i++)
@@ -780,6 +817,8 @@ void CMinecraftApp::InitGameSettings()
780817
// clear this for now - it will come from reading the system values
781818
memset(pProfileSettings,0,sizeof(C_4JProfile::PROFILESETTINGS));
782819
SetDefaultOptions(pProfileSettings,i);
820+
Win64_LoadSettings(GameSettingsA[i]);
821+
ApplyGameSettingsChanged(i);
783822
#elif defined __PS3__ || defined __ORBIS__ || defined _DURANGO || defined __PSVITA__
784823
C4JStorage::PROFILESETTINGS *pProfileSettings=StorageManager.GetDashboardProfileSettings(i);
785824
// 4J-PB - don't cause an options write to happen here
@@ -2372,6 +2411,9 @@ void CMinecraftApp::CheckGameSettingsChanged(bool bOverride5MinuteTimer, int iPa
23722411
StorageManager.WriteToProfile(i,true, bOverride5MinuteTimer);
23732412
#else
23742413
ProfileManager.WriteToProfile(i,true, bOverride5MinuteTimer);
2414+
#ifdef _WINDOWS64
2415+
Win64_SaveSettings(GameSettingsA[i]);
2416+
#endif
23752417
#endif
23762418
GameSettingsA[i]->bSettingsChanged=false;
23772419
}
@@ -2385,6 +2427,9 @@ void CMinecraftApp::CheckGameSettingsChanged(bool bOverride5MinuteTimer, int iPa
23852427
StorageManager.WriteToProfile(iPad,true, bOverride5MinuteTimer);
23862428
#else
23872429
ProfileManager.WriteToProfile(iPad,true, bOverride5MinuteTimer);
2430+
#ifdef _WINDOWS64
2431+
Win64_SaveSettings(GameSettingsA[iPad]);
2432+
#endif
23882433
#endif
23892434
GameSettingsA[iPad]->bSettingsChanged=false;
23902435
}

Minecraft.Client/Extrax64Stubs.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,11 @@ DWORD IQNetPlayer::GetSendQueueSize(IQNetPlayer * player, DWORD dwFlags) { retur
199199
DWORD IQNetPlayer::GetCurrentRtt() { return 0; }
200200
bool IQNetPlayer::IsHost() { return m_isHostPlayer; }
201201
bool IQNetPlayer::IsGuest() { return false; }
202-
bool IQNetPlayer::IsLocal() { return !m_isRemote; }
203-
PlayerUID IQNetPlayer::GetXuid() { return (PlayerUID)(0xe000d45248242f2e + m_smallId); }
204-
LPCWSTR IQNetPlayer::GetGamertag() { return m_gamertag; }
205-
int IQNetPlayer::GetSessionIndex() { return m_smallId; }
202+
bool IQNetPlayer::IsLocal() { return true; }
203+
PlayerUID IQNetPlayer::GetXuid() { return INVALID_XUID; }
204+
extern wstring g_playerName;
205+
LPCWSTR IQNetPlayer::GetGamertag() { return g_playerName.empty() ? L"Windows" : g_playerName.c_str(); }
206+
int IQNetPlayer::GetSessionIndex() { return 0; }
206207
bool IQNetPlayer::IsTalking() { return false; }
207208
bool IQNetPlayer::IsMutedByLocalUser(DWORD dwUserIndex) { return false; }
208209
bool IQNetPlayer::HasVoice() { return false; }

Minecraft.Client/Windows64/Windows64_App.cpp

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,46 @@
1010
#include "..\..\Minecraft.World\BiomeSource.h"
1111
#include "..\..\Minecraft.World\LevelType.h"
1212

13+
wstring g_playerName;
14+
1315
CConsoleMinecraftApp app;
1416

17+
static void LoadPlayerName()
18+
{
19+
if (!g_playerName.empty()) return;
20+
g_playerName = L"Windows";
21+
22+
char exePath[MAX_PATH] = {};
23+
GetModuleFileNameA(NULL, exePath, MAX_PATH);
24+
char *lastSlash = strrchr(exePath, '\\');
25+
if (lastSlash) *(lastSlash + 1) = '\0';
26+
char filePath[MAX_PATH] = {};
27+
_snprintf_s(filePath, sizeof(filePath), _TRUNCATE, "%susername.txt", exePath);
28+
29+
FILE *f = NULL;
30+
if (fopen_s(&f, filePath, "r") == 0 && f)
31+
{
32+
char buf[128] = {};
33+
if (fgets(buf, sizeof(buf), f))
34+
{
35+
int len = (int)strlen(buf);
36+
while (len > 0 && (buf[len-1] == '\n' || buf[len-1] == '\r' || buf[len-1] == ' '))
37+
buf[--len] = '\0';
38+
if (len > 0)
39+
{
40+
wchar_t wbuf[128] = {};
41+
mbstowcs(wbuf, buf, 127);
42+
g_playerName = wbuf;
43+
}
44+
}
45+
fclose(f);
46+
}
47+
}
48+
1549
CConsoleMinecraftApp::CConsoleMinecraftApp() : CMinecraftApp()
1650
{
1751
m_bShutdown = false;
52+
LoadPlayerName();
1853
}
1954

2055
void CConsoleMinecraftApp::SetRichPresenceContext(int iPad, int contextId)
@@ -35,9 +70,27 @@ void CConsoleMinecraftApp::FatalLoadError()
3570

3671
void CConsoleMinecraftApp::CaptureSaveThumbnail()
3772
{
73+
RenderManager.CaptureThumbnail(&m_ThumbnailBuffer);
3874
}
3975
void CConsoleMinecraftApp::GetSaveThumbnail(PBYTE *pbData,DWORD *pdwSize)
4076
{
77+
// On a save caused by a create world, the thumbnail capture won't have happened
78+
if (m_ThumbnailBuffer.Allocated())
79+
{
80+
if (pbData)
81+
{
82+
*pbData = new BYTE[m_ThumbnailBuffer.GetBufferSize()];
83+
*pdwSize = m_ThumbnailBuffer.GetBufferSize();
84+
memcpy(*pbData, m_ThumbnailBuffer.GetBufferPointer(), *pdwSize);
85+
}
86+
m_ThumbnailBuffer.Release();
87+
}
88+
else
89+
{
90+
// No capture happened (e.g. first save on world creation) leave thumbnail as NULL
91+
if (pbData) *pbData = NULL;
92+
if (pdwSize) *pdwSize = 0;
93+
}
4194
}
4295
void CConsoleMinecraftApp::ReleaseSaveThumbnail()
4396
{
@@ -57,8 +110,8 @@ void CConsoleMinecraftApp::TemporaryCreateGameStart()
57110
Minecraft *pMinecraft=Minecraft::GetInstance();
58111
app.ReleaseSaveThumbnail();
59112
ProfileManager.SetLockedProfile(0);
60-
extern wchar_t g_Win64UsernameW[17];
61-
pMinecraft->user->name = g_Win64UsernameW;
113+
LoadPlayerName();
114+
pMinecraft->user->name = g_playerName;
62115
app.ApplyGameSettingsChanged(0);
63116

64117
////////////////////////////////////////////////////////////////////////////////////////////// From CScene_MultiGameJoinLoad::OnInit

Minecraft.Client/Windows64/Windows64_App.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#pragma once
2+
#include "4JLibs\inc\4J_Render.h"
23

34
class CConsoleMinecraftApp : public CMinecraftApp
45
{
6+
ImageFileBuffer m_ThumbnailBuffer;
57
public:
68
CConsoleMinecraftApp();
79

Minecraft.Client/Windows64/Windows64_Minecraft.cpp

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,16 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
729729
UNREFERENCED_PARAMETER(hPrevInstance);
730730
UNREFERENCED_PARAMETER(lpCmdLine);
731731

732-
dyn_SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE);
732+
// 4J-Win64: set CWD to exe dir so asset paths resolve correctly
733+
{
734+
char szExeDir[MAX_PATH] = {};
735+
GetModuleFileNameA(NULL, szExeDir, MAX_PATH);
736+
char *pSlash = strrchr(szExeDir, '\\');
737+
if (pSlash) { *(pSlash + 1) = '\0'; SetCurrentDirectoryA(szExeDir); }
738+
}
739+
740+
// Declare DPI awareness so GetSystemMetrics returns physical pixels
741+
SetProcessDPIAware();
733742
g_iScreenWidth = GetSystemMetrics(SM_CXSCREEN);
734743
g_iScreenHeight = GetSystemMetrics(SM_CYSCREEN);
735744

@@ -1263,7 +1272,21 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
12631272
}
12641273
}
12651274

1266-
// F11 toggles fullscreen
1275+
// F3 toggles the debug console overlay, F11 toggles fullscreen
1276+
if (KMInput.IsKeyPressed(VK_F3))
1277+
{
1278+
static bool s_debugConsole = false;
1279+
s_debugConsole = !s_debugConsole;
1280+
ui.ShowUIDebugConsole(s_debugConsole);
1281+
}
1282+
1283+
#ifdef _DEBUG_MENUS_ENABLED
1284+
if (KMInput.IsKeyPressed(VK_F4))
1285+
{
1286+
ui.NavigateToScene(ProfileManager.GetPrimaryPad(), eUIScene_DebugOverlay, NULL, eUILayer_Debug);
1287+
}
1288+
#endif
1289+
12671290
if (KMInput.IsKeyPressed(VK_F11))
12681291
{
12691292
ToggleFullscreen();

0 commit comments

Comments
 (0)