From 75bf7ee54a2d4bbaded95453ac699c5d2d529628 Mon Sep 17 00:00:00 2001 From: Vvis <76018445+Lambdagon@users.noreply.github.com> Date: Sun, 1 Mar 2026 22:33:18 -0700 Subject: Allow TAB to open host options (#97) --- Minecraft.Client/Windows64/Windows64_Minecraft.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'Minecraft.Client/Windows64/Windows64_Minecraft.cpp') diff --git a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp index 1bffe317..540c3c53 100644 --- a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp +++ b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp @@ -1220,6 +1220,17 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, ToggleFullscreen(); } + // TAB opens host options menu. - Vvis :3 + if (KMInput.IsKeyPressed(VK_TAB)) + { + if (Minecraft* pMinecraft = Minecraft::GetInstance()) + { + { + ui.NavigateToScene(0, eUIScene_InGameHostOptionsMenu); + } + } + } + #if 0 // has the game defined profile data been changed (by a profile load) if(app.uiGameDefinedDataChangedBitmask!=0) -- cgit v1.2.3 From df2925a4ede5e86e39d9589f1fb8755c63e6263c Mon Sep 17 00:00:00 2001 From: void_17 Date: Mon, 2 Mar 2026 13:32:41 +0700 Subject: Fix Iggy player crashes on systems with DPI changed The code that was supposed to make the game DPI-aware was broken. I remove it until a proper implementation. --- Minecraft.Client/Windows64/Windows64_Minecraft.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'Minecraft.Client/Windows64/Windows64_Minecraft.cpp') diff --git a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp index 540c3c53..a6fdd7f2 100644 --- a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp +++ b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp @@ -716,6 +716,7 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); + /* // Declare DPI awareness so GetSystemMetrics returns physical pixels SetProcessDPIAware(); g_iScreenWidth = GetSystemMetrics(SM_CXSCREEN); @@ -726,6 +727,8 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, sprintf(buf, "Screen resolution: %dx%d\n", g_iScreenWidth, g_iScreenHeight); OutputDebugStringA(buf); } + */ + if(lpCmdLine) { @@ -1220,7 +1223,7 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, ToggleFullscreen(); } - // TAB opens host options menu. - Vvis :3 + // TAB opens host options menu. - Vvis :3 if (KMInput.IsKeyPressed(VK_TAB)) { if (Minecraft* pMinecraft = Minecraft::GetInstance()) -- cgit v1.2.3 From f9b266e02c3f317e0bfdc23b4756dd48df95b7fb Mon Sep 17 00:00:00 2001 From: DFelipeh Date: Mon, 2 Mar 2026 12:03:40 +0000 Subject: add minecraft icon to windows version (#126) --- Minecraft.Client/Windows64/Windows64_Minecraft.cpp | 2 +- Minecraft.Client/Xbox/MinecraftWindows.ico | Bin 2998 -> 332190 bytes 2 files changed, 1 insertion(+), 1 deletion(-) (limited to 'Minecraft.Client/Windows64/Windows64_Minecraft.cpp') diff --git a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp index a6fdd7f2..399bf59f 100644 --- a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp +++ b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp @@ -443,7 +443,7 @@ ATOM MyRegisterClass(HINSTANCE hInstance) wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcex.lpszMenuName = "Minecraft"; wcex.lpszClassName = "MinecraftClass"; - wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL)); + wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_MINECRAFTWINDOWS)); return RegisterClassEx(&wcex); } diff --git a/Minecraft.Client/Xbox/MinecraftWindows.ico b/Minecraft.Client/Xbox/MinecraftWindows.ico index 449296f4..f171b2a6 100644 Binary files a/Minecraft.Client/Xbox/MinecraftWindows.ico and b/Minecraft.Client/Xbox/MinecraftWindows.ico differ -- cgit v1.2.3 From 59339a7afc5d4869c7ba96240da38e2f5657cc8c Mon Sep 17 00:00:00 2001 From: Jean <124172979+jeanmajid@users.noreply.github.com> Date: Mon, 2 Mar 2026 14:00:02 +0100 Subject: Bound F3 and F4 to open debug menus (#94) * feat: Added f3 and f4 keys to open debug stuff * fix: only open debug overlay when ingame, to avoid crashes * docs: added keybinds to docs * docs: moved the keybinds to the bottom, as they are less important * fix: add missing # ifdef --- Minecraft.Client/Windows64/Windows64_Minecraft.cpp | 27 ++++++++++++++++++++++ README.md | 2 ++ 2 files changed, 29 insertions(+) (limited to 'Minecraft.Client/Windows64/Windows64_Minecraft.cpp') diff --git a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp index 399bf59f..d822e943 100644 --- a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp +++ b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp @@ -1234,6 +1234,33 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, } } +#ifdef _DEBUG_MENUS_ENABLED + // F3 toggles onscreen debug info + if (KMInput.IsKeyPressed(VK_F3)) + { + if (Minecraft* pMinecraft = Minecraft::GetInstance()) + { + if (pMinecraft->options && app.DebugSettingsOn()) + { + pMinecraft->options->renderDebug = !pMinecraft->options->renderDebug; + } + } + } + + // F4 opens debug overlay + if (KMInput.IsKeyPressed(VK_F4)) + { + if (Minecraft* pMinecraft = Minecraft::GetInstance()) + { + if (pMinecraft->options && app.DebugSettingsOn() && + app.GetGameStarted() && !ui.GetMenuDisplayed(0) && pMinecraft->screen == NULL) + { + ui.NavigateToScene(0, eUIScene_DebugOverlay, NULL, eUILayer_Debug); + } + } + } +#endif + #if 0 // has the game defined profile data been changed (by a profile load) if(app.uiGameDefinedDataChangedBitmask!=0) diff --git a/README.md b/README.md index a0f1870d..53323cc0 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,8 @@ This project contains the source code of Minecraft Legacy Console Edition v1.3.0 - **Select Item**: `Mouse Wheel` or keys `1` to `9` - **Accept or Decline Tutorial hints**: `Enter` to accept and `B` to decline - **Host Options**: `TAB` +- **Toggle Debug Info**: `F3` +- **Open Debug Overlay**: `F4` ## Build & Run -- cgit v1.2.3 From afa4efbc8513cbb8565b9700cae48648e3dffe29 Mon Sep 17 00:00:00 2001 From: daoge <3523206925@qq.com> Date: Mon, 2 Mar 2026 23:52:18 +0800 Subject: fix: fix resolution detection (#133) * fix: fix UI skin/scene resolution mismatch and readd screen resolution detection * fix: fix build in vs2022 --- CMakeLists.txt | 1 + Minecraft.Client/Common/UI/UIController.cpp | 8 ++++---- Minecraft.Client/Minecraft.Client.vcxproj | 6 +++--- Minecraft.Client/Windows64/Windows64_Minecraft.cpp | 13 ++----------- README.md | 1 + 5 files changed, 11 insertions(+), 18 deletions(-) (limited to 'Minecraft.Client/Windows64/Windows64_Minecraft.cpp') diff --git a/CMakeLists.txt b/CMakeLists.txt index a9ce5f69..7b055af0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,6 +54,7 @@ target_link_libraries(MinecraftClient PRIVATE MinecraftWorld d3d11 XInput9_1_0 + Shcore "${CMAKE_CURRENT_SOURCE_DIR}/Minecraft.Client/Windows64/Iggy/lib/iggy_w64.lib" "${CMAKE_CURRENT_SOURCE_DIR}/Minecraft.Client/Windows64/Miles/lib/mss64.lib" $<$: diff --git a/Minecraft.Client/Common/UI/UIController.cpp b/Minecraft.Client/Common/UI/UIController.cpp index eb33b6b3..87c495d2 100644 --- a/Minecraft.Client/Common/UI/UIController.cpp +++ b/Minecraft.Client/Common/UI/UIController.cpp @@ -426,7 +426,7 @@ void UIController::loadSkins() #elif defined __PSVITA__ platformSkinPath = L"skinVita.swf"; #elif defined _WINDOWS64 - if(m_fScreenHeight>=1080.0f) + if(m_fScreenHeight>720.0f) { platformSkinPath = L"skinHDWin.swf"; } @@ -435,7 +435,7 @@ void UIController::loadSkins() platformSkinPath = L"skinWin.swf"; } #elif defined _DURANGO - if(m_fScreenHeight>=1080.0f) + if(m_fScreenHeight>720.0f) { platformSkinPath = L"skinHDDurango.swf"; } @@ -444,7 +444,7 @@ void UIController::loadSkins() platformSkinPath = L"skinDurango.swf"; } #elif defined __ORBIS__ - if(m_fScreenHeight>=1080.0f) + if(m_fScreenHeight>720.0f) { platformSkinPath = L"skinHDOrbis.swf"; } @@ -455,7 +455,7 @@ void UIController::loadSkins() #endif // Every platform has one of these, so nothing shared - if(m_fScreenHeight>=1080.0f) + if(m_fScreenHeight>720.0f) { m_iggyLibraries[eLibrary_Platform] = loadSkin(platformSkinPath, L"platformskinHD.swf"); } diff --git a/Minecraft.Client/Minecraft.Client.vcxproj b/Minecraft.Client/Minecraft.Client.vcxproj index 4e8d46be..607d158c 100644 --- a/Minecraft.Client/Minecraft.Client.vcxproj +++ b/Minecraft.Client/Minecraft.Client.vcxproj @@ -1296,7 +1296,7 @@ if not exist "$(TargetDir)\savedata" mkdir "$(TargetDir)\savedata" true $(OutDir)$(ProjectName).pdb - d3d11.lib;..\Minecraft.World\x64_Debug\Minecraft.World.lib;%(AdditionalDependencies);XInput9_1_0.lib;..\Minecraft.Client\Windows64\Miles\Lib\mss64.lib + d3d11.lib;Shcore.lib;..\Minecraft.World\x64_Debug\Minecraft.World.lib;%(AdditionalDependencies);XInput9_1_0.lib;..\Minecraft.Client\Windows64\Miles\Lib\mss64.lib NotSet false MultiplyDefinedSymbolOnly @@ -1429,7 +1429,7 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CU true $(OutDir)$(ProjectName).pdb - d3d11.lib;..\Minecraft.World\x64_Release\Minecraft.World.lib;XInput9_1_0.lib;Windows64\Iggy\lib\iggy_w64.lib;%(AdditionalDependencies) + d3d11.lib;Shcore.lib;..\Minecraft.World\x64_Release\Minecraft.World.lib;XInput9_1_0.lib;Windows64\Iggy\lib\iggy_w64.lib;%(AdditionalDependencies) NotSet false @@ -1474,7 +1474,7 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CU true $(OutDir)$(ProjectName).pdb - d3d11.lib;..\Minecraft.World\x64_Release\Minecraft.World.lib;XInput9_1_0.lib;Windows64\Iggy\lib\iggy_w64.lib;%(AdditionalDependencies) + d3d11.lib;Shcore.lib;..\Minecraft.World\x64_Release\Minecraft.World.lib;XInput9_1_0.lib;Windows64\Iggy\lib\iggy_w64.lib;%(AdditionalDependencies) NotSet false diff --git a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp index d822e943..3268a02b 100644 --- a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp +++ b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp @@ -4,6 +4,7 @@ #include "stdafx.h" #include +#include #include "GameConfig\Minecraft.spa.h" #include "..\MinecraftServer.h" #include "..\LocalPlayer.h" @@ -716,20 +717,10 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); - /* - // Declare DPI awareness so GetSystemMetrics returns physical pixels - SetProcessDPIAware(); + SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE); g_iScreenWidth = GetSystemMetrics(SM_CXSCREEN); g_iScreenHeight = GetSystemMetrics(SM_CYSCREEN); - { - char buf[128]; - sprintf(buf, "Screen resolution: %dx%d\n", g_iScreenWidth, g_iScreenHeight); - OutputDebugStringA(buf); - } - */ - - if(lpCmdLine) { if(lpCmdLine[0] == '1') diff --git a/README.md b/README.md index a7196d38..2ee9feac 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ This project contains the source code of Minecraft Legacy Console Edition v1.3.0 - Added support for keyboard and mouse input - Added fullscreen mode support (toggle using F11) - Disabled V-Sync for better performance +- Device's screen resolution will be used as the game resolution instead of using a fixed resolution (1920x1080) ## Controls (Keyboard & Mouse) -- cgit v1.2.3 From 8c18926d5911343975604b93c51efbcd926c133a Mon Sep 17 00:00:00 2001 From: void_17 <61356189+void2012@users.noreply.github.com> Date: Mon, 2 Mar 2026 22:56:56 +0700 Subject: Revert "fix: fix resolution detection (#133)" (#143) This reverts commit afa4efbc8513cbb8565b9700cae48648e3dffe29. --- CMakeLists.txt | 1 - Minecraft.Client/Common/UI/UIController.cpp | 8 ++++---- Minecraft.Client/Minecraft.Client.vcxproj | 6 +++--- Minecraft.Client/Windows64/Windows64_Minecraft.cpp | 13 +++++++++++-- README.md | 1 - 5 files changed, 18 insertions(+), 11 deletions(-) (limited to 'Minecraft.Client/Windows64/Windows64_Minecraft.cpp') diff --git a/CMakeLists.txt b/CMakeLists.txt index 7b055af0..a9ce5f69 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,7 +54,6 @@ target_link_libraries(MinecraftClient PRIVATE MinecraftWorld d3d11 XInput9_1_0 - Shcore "${CMAKE_CURRENT_SOURCE_DIR}/Minecraft.Client/Windows64/Iggy/lib/iggy_w64.lib" "${CMAKE_CURRENT_SOURCE_DIR}/Minecraft.Client/Windows64/Miles/lib/mss64.lib" $<$: diff --git a/Minecraft.Client/Common/UI/UIController.cpp b/Minecraft.Client/Common/UI/UIController.cpp index 87c495d2..eb33b6b3 100644 --- a/Minecraft.Client/Common/UI/UIController.cpp +++ b/Minecraft.Client/Common/UI/UIController.cpp @@ -426,7 +426,7 @@ void UIController::loadSkins() #elif defined __PSVITA__ platformSkinPath = L"skinVita.swf"; #elif defined _WINDOWS64 - if(m_fScreenHeight>720.0f) + if(m_fScreenHeight>=1080.0f) { platformSkinPath = L"skinHDWin.swf"; } @@ -435,7 +435,7 @@ void UIController::loadSkins() platformSkinPath = L"skinWin.swf"; } #elif defined _DURANGO - if(m_fScreenHeight>720.0f) + if(m_fScreenHeight>=1080.0f) { platformSkinPath = L"skinHDDurango.swf"; } @@ -444,7 +444,7 @@ void UIController::loadSkins() platformSkinPath = L"skinDurango.swf"; } #elif defined __ORBIS__ - if(m_fScreenHeight>720.0f) + if(m_fScreenHeight>=1080.0f) { platformSkinPath = L"skinHDOrbis.swf"; } @@ -455,7 +455,7 @@ void UIController::loadSkins() #endif // Every platform has one of these, so nothing shared - if(m_fScreenHeight>720.0f) + if(m_fScreenHeight>=1080.0f) { m_iggyLibraries[eLibrary_Platform] = loadSkin(platformSkinPath, L"platformskinHD.swf"); } diff --git a/Minecraft.Client/Minecraft.Client.vcxproj b/Minecraft.Client/Minecraft.Client.vcxproj index 607d158c..4e8d46be 100644 --- a/Minecraft.Client/Minecraft.Client.vcxproj +++ b/Minecraft.Client/Minecraft.Client.vcxproj @@ -1296,7 +1296,7 @@ if not exist "$(TargetDir)\savedata" mkdir "$(TargetDir)\savedata" true $(OutDir)$(ProjectName).pdb - d3d11.lib;Shcore.lib;..\Minecraft.World\x64_Debug\Minecraft.World.lib;%(AdditionalDependencies);XInput9_1_0.lib;..\Minecraft.Client\Windows64\Miles\Lib\mss64.lib + d3d11.lib;..\Minecraft.World\x64_Debug\Minecraft.World.lib;%(AdditionalDependencies);XInput9_1_0.lib;..\Minecraft.Client\Windows64\Miles\Lib\mss64.lib NotSet false MultiplyDefinedSymbolOnly @@ -1429,7 +1429,7 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CU true $(OutDir)$(ProjectName).pdb - d3d11.lib;Shcore.lib;..\Minecraft.World\x64_Release\Minecraft.World.lib;XInput9_1_0.lib;Windows64\Iggy\lib\iggy_w64.lib;%(AdditionalDependencies) + d3d11.lib;..\Minecraft.World\x64_Release\Minecraft.World.lib;XInput9_1_0.lib;Windows64\Iggy\lib\iggy_w64.lib;%(AdditionalDependencies) NotSet false @@ -1474,7 +1474,7 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CU true $(OutDir)$(ProjectName).pdb - d3d11.lib;Shcore.lib;..\Minecraft.World\x64_Release\Minecraft.World.lib;XInput9_1_0.lib;Windows64\Iggy\lib\iggy_w64.lib;%(AdditionalDependencies) + d3d11.lib;..\Minecraft.World\x64_Release\Minecraft.World.lib;XInput9_1_0.lib;Windows64\Iggy\lib\iggy_w64.lib;%(AdditionalDependencies) NotSet false diff --git a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp index 3268a02b..d822e943 100644 --- a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp +++ b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp @@ -4,7 +4,6 @@ #include "stdafx.h" #include -#include #include "GameConfig\Minecraft.spa.h" #include "..\MinecraftServer.h" #include "..\LocalPlayer.h" @@ -717,10 +716,20 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); - SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE); + /* + // Declare DPI awareness so GetSystemMetrics returns physical pixels + SetProcessDPIAware(); g_iScreenWidth = GetSystemMetrics(SM_CXSCREEN); g_iScreenHeight = GetSystemMetrics(SM_CYSCREEN); + { + char buf[128]; + sprintf(buf, "Screen resolution: %dx%d\n", g_iScreenWidth, g_iScreenHeight); + OutputDebugStringA(buf); + } + */ + + if(lpCmdLine) { if(lpCmdLine[0] == '1') diff --git a/README.md b/README.md index 2ee9feac..a7196d38 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,6 @@ This project contains the source code of Minecraft Legacy Console Edition v1.3.0 - Added support for keyboard and mouse input - Added fullscreen mode support (toggle using F11) - Disabled V-Sync for better performance -- Device's screen resolution will be used as the game resolution instead of using a fixed resolution (1920x1080) ## Controls (Keyboard & Mouse) -- cgit v1.2.3 From 7ad6102763131a617d564dbf2d778612ba5046df Mon Sep 17 00:00:00 2001 From: void_17 <61356189+void2012@users.noreply.github.com> Date: Mon, 2 Mar 2026 23:01:57 +0700 Subject: Revert "Revert "fix: fix resolution detection (#133)" (#143)" (#144) This reverts commit 8c18926d5911343975604b93c51efbcd926c133a. --- CMakeLists.txt | 1 + Minecraft.Client/Common/UI/UIController.cpp | 8 ++++---- Minecraft.Client/Minecraft.Client.vcxproj | 6 +++--- Minecraft.Client/Windows64/Windows64_Minecraft.cpp | 13 ++----------- README.md | 1 + 5 files changed, 11 insertions(+), 18 deletions(-) (limited to 'Minecraft.Client/Windows64/Windows64_Minecraft.cpp') diff --git a/CMakeLists.txt b/CMakeLists.txt index a9ce5f69..7b055af0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,6 +54,7 @@ target_link_libraries(MinecraftClient PRIVATE MinecraftWorld d3d11 XInput9_1_0 + Shcore "${CMAKE_CURRENT_SOURCE_DIR}/Minecraft.Client/Windows64/Iggy/lib/iggy_w64.lib" "${CMAKE_CURRENT_SOURCE_DIR}/Minecraft.Client/Windows64/Miles/lib/mss64.lib" $<$: diff --git a/Minecraft.Client/Common/UI/UIController.cpp b/Minecraft.Client/Common/UI/UIController.cpp index eb33b6b3..87c495d2 100644 --- a/Minecraft.Client/Common/UI/UIController.cpp +++ b/Minecraft.Client/Common/UI/UIController.cpp @@ -426,7 +426,7 @@ void UIController::loadSkins() #elif defined __PSVITA__ platformSkinPath = L"skinVita.swf"; #elif defined _WINDOWS64 - if(m_fScreenHeight>=1080.0f) + if(m_fScreenHeight>720.0f) { platformSkinPath = L"skinHDWin.swf"; } @@ -435,7 +435,7 @@ void UIController::loadSkins() platformSkinPath = L"skinWin.swf"; } #elif defined _DURANGO - if(m_fScreenHeight>=1080.0f) + if(m_fScreenHeight>720.0f) { platformSkinPath = L"skinHDDurango.swf"; } @@ -444,7 +444,7 @@ void UIController::loadSkins() platformSkinPath = L"skinDurango.swf"; } #elif defined __ORBIS__ - if(m_fScreenHeight>=1080.0f) + if(m_fScreenHeight>720.0f) { platformSkinPath = L"skinHDOrbis.swf"; } @@ -455,7 +455,7 @@ void UIController::loadSkins() #endif // Every platform has one of these, so nothing shared - if(m_fScreenHeight>=1080.0f) + if(m_fScreenHeight>720.0f) { m_iggyLibraries[eLibrary_Platform] = loadSkin(platformSkinPath, L"platformskinHD.swf"); } diff --git a/Minecraft.Client/Minecraft.Client.vcxproj b/Minecraft.Client/Minecraft.Client.vcxproj index 4e8d46be..607d158c 100644 --- a/Minecraft.Client/Minecraft.Client.vcxproj +++ b/Minecraft.Client/Minecraft.Client.vcxproj @@ -1296,7 +1296,7 @@ if not exist "$(TargetDir)\savedata" mkdir "$(TargetDir)\savedata" true $(OutDir)$(ProjectName).pdb - d3d11.lib;..\Minecraft.World\x64_Debug\Minecraft.World.lib;%(AdditionalDependencies);XInput9_1_0.lib;..\Minecraft.Client\Windows64\Miles\Lib\mss64.lib + d3d11.lib;Shcore.lib;..\Minecraft.World\x64_Debug\Minecraft.World.lib;%(AdditionalDependencies);XInput9_1_0.lib;..\Minecraft.Client\Windows64\Miles\Lib\mss64.lib NotSet false MultiplyDefinedSymbolOnly @@ -1429,7 +1429,7 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CU true $(OutDir)$(ProjectName).pdb - d3d11.lib;..\Minecraft.World\x64_Release\Minecraft.World.lib;XInput9_1_0.lib;Windows64\Iggy\lib\iggy_w64.lib;%(AdditionalDependencies) + d3d11.lib;Shcore.lib;..\Minecraft.World\x64_Release\Minecraft.World.lib;XInput9_1_0.lib;Windows64\Iggy\lib\iggy_w64.lib;%(AdditionalDependencies) NotSet false @@ -1474,7 +1474,7 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CU true $(OutDir)$(ProjectName).pdb - d3d11.lib;..\Minecraft.World\x64_Release\Minecraft.World.lib;XInput9_1_0.lib;Windows64\Iggy\lib\iggy_w64.lib;%(AdditionalDependencies) + d3d11.lib;Shcore.lib;..\Minecraft.World\x64_Release\Minecraft.World.lib;XInput9_1_0.lib;Windows64\Iggy\lib\iggy_w64.lib;%(AdditionalDependencies) NotSet false diff --git a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp index d822e943..3268a02b 100644 --- a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp +++ b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp @@ -4,6 +4,7 @@ #include "stdafx.h" #include +#include #include "GameConfig\Minecraft.spa.h" #include "..\MinecraftServer.h" #include "..\LocalPlayer.h" @@ -716,20 +717,10 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); - /* - // Declare DPI awareness so GetSystemMetrics returns physical pixels - SetProcessDPIAware(); + SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE); g_iScreenWidth = GetSystemMetrics(SM_CXSCREEN); g_iScreenHeight = GetSystemMetrics(SM_CYSCREEN); - { - char buf[128]; - sprintf(buf, "Screen resolution: %dx%d\n", g_iScreenWidth, g_iScreenHeight); - OutputDebugStringA(buf); - } - */ - - if(lpCmdLine) { if(lpCmdLine[0] == '1') diff --git a/README.md b/README.md index f6a93d21..be3e745b 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ This project contains the source code of Minecraft Legacy Console Edition v1.3.0 - Added support for keyboard and mouse input - Added fullscreen mode support (toggle using F11) - Disabled V-Sync for better performance +- Device's screen resolution will be used as the game resolution instead of using a fixed resolution (1920x1080) ## Controls (Keyboard & Mouse) -- cgit v1.2.3 From a4691f58e8e4d51908199135a226efc9aab85d6b Mon Sep 17 00:00:00 2001 From: Alex <37753918+Acplay5@users.noreply.github.com> Date: Mon, 2 Mar 2026 19:02:52 +0300 Subject: Only handle host options when there is no menu on screen (#140) --- Minecraft.Client/Windows64/Windows64_Minecraft.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Minecraft.Client/Windows64/Windows64_Minecraft.cpp') diff --git a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp index 3268a02b..c2034b8c 100644 --- a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp +++ b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp @@ -1215,7 +1215,7 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, } // TAB opens host options menu. - Vvis :3 - if (KMInput.IsKeyPressed(VK_TAB)) + if (KMInput.IsKeyPressed(VK_TAB) && !ui.GetMenuDisplayed(0)) { if (Minecraft* pMinecraft = Minecraft::GetInstance()) { -- cgit v1.2.3 From 5a9e512117da0c94b39b879fe0e282615668ae13 Mon Sep 17 00:00:00 2001 From: void_17 <61356189+void2012@users.noreply.github.com> Date: Tue, 3 Mar 2026 02:20:24 +0700 Subject: Restore Windows 7 compatibility (#160) * Call SetProcessDpiAwareness via GetProcAddress to preserve Windows 7 compatibility Shcore.dll and SetProcessDpiAwareness were introduced in Windows 8 and higher, so to keep compatibility with Windows 7, we use GetProcAddress to call this function dynamically, avoiding linker writing binary dependency on shcore.dll in the import table * Revert "Call SetProcessDpiAwareness via GetProcAddress to preserve Windows 7 compatibility" This reverts commit f1f397fdbe64e64ab8f7b5457e8206e9193cece0. * Reapply the fix --- Minecraft.Client/Windows64/Windows64_Minecraft.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'Minecraft.Client/Windows64/Windows64_Minecraft.cpp') diff --git a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp index c2034b8c..e24bc374 100644 --- a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp +++ b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp @@ -707,7 +707,19 @@ void CleanupDevice() if( g_pd3dDevice ) g_pd3dDevice->Release(); } - +typedef HRESULT(__stdcall* SetProcessDpiAwareness_f)(PROCESS_DPI_AWARENESS); +static HRESULT dyn_SetProcessDpiAwareness(PROCESS_DPI_AWARENESS value) +{ + static const auto ptr = reinterpret_cast( + reinterpret_cast(::GetProcAddress(static_cast(LoadLibraryExW(L"Shcore.dll", nullptr, 0)), "SetProcessDpiAwareness"))); + if (ptr == nullptr) + { + SetLastError(ERROR_CALL_NOT_IMPLEMENTED); + return E_NOTIMPL; + } + + return ptr(value); +} int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, @@ -717,7 +729,7 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); - SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE); + dyn_SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE); g_iScreenWidth = GetSystemMetrics(SM_CXSCREEN); g_iScreenHeight = GetSystemMetrics(SM_CYSCREEN); -- cgit v1.2.3 From f917335b132f527c436a32f07636f503614c4e69 Mon Sep 17 00:00:00 2001 From: Andrew <146450267+semiloker@users.noreply.github.com> Date: Mon, 2 Mar 2026 22:17:10 +0200 Subject: Fix Windows64 mouse capture and static initialization crashes (#177) --- Minecraft.Client/Windows64/Windows64_Minecraft.cpp | 9 +++++++++ Minecraft.World/Packet.cpp | 6 +++--- 2 files changed, 12 insertions(+), 3 deletions(-) (limited to 'Minecraft.Client/Windows64/Windows64_Minecraft.cpp') diff --git a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp index e24bc374..7d38ff99 100644 --- a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp +++ b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp @@ -403,6 +403,15 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) if (LOWORD(wParam) == WA_INACTIVE) KMInput.SetCapture(false); break; + case WM_SETFOCUS: + { + // Re-capture when window receives focus (e.g., after clicking on it) + Minecraft *pMinecraft = Minecraft::GetInstance(); + bool shouldCapture = pMinecraft && app.GetGameStarted() && !ui.GetMenuDisplayed(0) && pMinecraft->screen == NULL; + if (shouldCapture) + KMInput.SetCapture(true); + } + break; case WM_KILLFOCUS: KMInput.SetCapture(false); KMInput.ClearAllState(); diff --git a/Minecraft.World/Packet.cpp b/Minecraft.World/Packet.cpp index 93f02399..f1630db5 100644 --- a/Minecraft.World/Packet.cpp +++ b/Minecraft.World/Packet.cpp @@ -169,9 +169,9 @@ Packet::Packet() : createTime( System::currentTimeMillis() ) unordered_map Packet::idToCreateMap; -unordered_set Packet::clientReceivedPackets = unordered_set(); -unordered_set Packet::serverReceivedPackets = unordered_set(); -unordered_set Packet::sendToAnyClientPackets = unordered_set(); +unordered_set Packet::clientReceivedPackets; +unordered_set Packet::serverReceivedPackets; +unordered_set Packet::sendToAnyClientPackets; // 4J Added unordered_map Packet::outgoingStatistics = unordered_map(); -- cgit v1.2.3 From 41ded31af8767a6a0a0da2075d6bcd7d17078873 Mon Sep 17 00:00:00 2001 From: Fayaz Shaikh <61674751+fayaz12g@users.noreply.github.com> Date: Mon, 2 Mar 2026 18:04:53 -0500 Subject: Add dynamic resolution (#203) --- Minecraft.Client/Windows64/Windows64_Minecraft.cpp | 86 ++++++++++++++++++++++ Minecraft.Client/glWrapper.cpp | 6 +- 2 files changed, 91 insertions(+), 1 deletion(-) (limited to 'Minecraft.Client/Windows64/Windows64_Minecraft.cpp') diff --git a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp index 7d38ff99..743da44b 100644 --- a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp +++ b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp @@ -84,6 +84,9 @@ BOOL g_bWidescreen = TRUE; int g_iScreenWidth = 1920; int g_iScreenHeight = 1080; +UINT g_ScreenWidth = 1920; +UINT g_ScreenHeight = 1080; + // Fullscreen toggle state static bool g_isFullscreen = false; static WINDOWPLACEMENT g_wpPrev = { sizeof(g_wpPrev) }; @@ -425,7 +428,90 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) return TRUE; } return DefWindowProc(hWnd, message, wParam, lParam); + case WM_SIZE: + { + if (wParam == SIZE_MINIMIZED) + return 0; + + UINT width = LOWORD(lParam); + UINT height = HIWORD(lParam); + + if (width == 0 || height == 0) + return 0; + + g_ScreenWidth = width; + g_ScreenHeight = height; + + if (g_pSwapChain) + { + g_pImmediateContext->OMSetRenderTargets(0, 0, 0); + g_pImmediateContext->ClearState(); + g_pImmediateContext->Flush(); + + if (g_pRenderTargetView) + { + g_pRenderTargetView->Release(); + g_pRenderTargetView = nullptr; + } + + if (g_pDepthStencilView) + { + g_pDepthStencilView->Release(); + g_pDepthStencilView = nullptr; + } + if (g_pDepthStencilBuffer) + { + g_pDepthStencilBuffer->Release(); + g_pDepthStencilBuffer = nullptr; + } + + HRESULT hr = g_pSwapChain->ResizeBuffers( + 0, + width, + height, + DXGI_FORMAT_UNKNOWN, + 0 + ); + + if (FAILED(hr)) + { + app.DebugPrintf("ResizeBuffers Failed! HRESULT: 0x%X\n", hr); + return 0; + } + + ID3D11Texture2D* pBackBuffer = nullptr; + g_pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (void**)&pBackBuffer); + + g_pd3dDevice->CreateRenderTargetView(pBackBuffer, NULL, &g_pRenderTargetView); + pBackBuffer->Release(); + + D3D11_TEXTURE2D_DESC descDepth = {}; + descDepth.Width = width; + descDepth.Height = height; + descDepth.MipLevels = 1; + descDepth.ArraySize = 1; + descDepth.Format = DXGI_FORMAT_D24_UNORM_S8_UINT; + descDepth.SampleDesc.Count = 1; + descDepth.BindFlags = D3D11_BIND_DEPTH_STENCIL; + + g_pd3dDevice->CreateTexture2D(&descDepth, NULL, &g_pDepthStencilBuffer); + g_pd3dDevice->CreateDepthStencilView(g_pDepthStencilBuffer, NULL, &g_pDepthStencilView); + + g_pImmediateContext->OMSetRenderTargets(1, &g_pRenderTargetView, g_pDepthStencilView); + + D3D11_VIEWPORT vp = {}; + vp.Width = (FLOAT)width; + vp.Height = (FLOAT)height; + vp.MinDepth = 0.0f; + vp.MaxDepth = 1.0f; + vp.TopLeftX = 0; + vp.TopLeftY = 0; + + g_pImmediateContext->RSSetViewports(1, &vp); + } + } + break; default: return DefWindowProc(hWnd, message, wParam, lParam); } diff --git a/Minecraft.Client/glWrapper.cpp b/Minecraft.Client/glWrapper.cpp index b120d30b..5e0fab2c 100644 --- a/Minecraft.Client/glWrapper.cpp +++ b/Minecraft.Client/glWrapper.cpp @@ -48,9 +48,13 @@ void glLoadIdentity() RenderManager.MatrixSetIdentity(); } +extern UINT g_ScreenWidth; +extern UINT g_ScreenHeight; + void gluPerspective(float fovy, float aspect, float zNear, float zFar) { - RenderManager.MatrixPerspective(fovy,aspect,zNear,zFar); + float dynamicAspect = (float)g_ScreenWidth / (float)g_ScreenHeight; + RenderManager.MatrixPerspective(fovy, dynamicAspect, zNear, zFar); } void glOrtho(float left,float right,float bottom,float top,float zNear,float zFar) -- cgit v1.2.3 From f731a684229562cf42fb025c9688c3fcd8f4c47d Mon Sep 17 00:00:00 2001 From: DetectivEren <55319774+detectiveren@users.noreply.github.com> Date: Mon, 2 Mar 2026 23:23:59 +0000 Subject: TAB key opens up game info instead of host options (#204) * TAB key opens up game info instead of host options TAB key opens up game info menu instead of host options menu because the player accesses host options from game info * Update README.md --- Minecraft.Client/Windows64/Windows64_Minecraft.cpp | 5 +++-- README.md | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'Minecraft.Client/Windows64/Windows64_Minecraft.cpp') diff --git a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp index 743da44b..95c10a2b 100644 --- a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp +++ b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp @@ -1321,13 +1321,14 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, ToggleFullscreen(); } - // TAB opens host options menu. - Vvis :3 + // TAB opens game info menu. - Vvis :3 - Updated by detectiveren if (KMInput.IsKeyPressed(VK_TAB) && !ui.GetMenuDisplayed(0)) { if (Minecraft* pMinecraft = Minecraft::GetInstance()) { { - ui.NavigateToScene(0, eUIScene_InGameHostOptionsMenu); + ui.NavigateToScene(0, eUIScene_InGameInfoMenu); + } } } diff --git a/README.md b/README.md index b24ef159..69038ef7 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ This project contains the source code of Minecraft Legacy Console Edition v1.6.0 - **Use / Place**: `Right Click` - **Select Item**: `Mouse Wheel` or keys `1` to `9` - **Accept or Decline Tutorial hints**: `Enter` to accept and `B` to decline -- **Host Options**: `TAB` +- **Game Info (Player list and Host Options)**: `TAB` - **Toggle Debug Info**: `F3` - **Open Debug Overlay**: `F4` -- cgit v1.2.3 From 8b28c20d7adc3824f96fbcc34ad65d778a97a05b Mon Sep 17 00:00:00 2001 From: lspepinho <162769565+lspepinho@users.noreply.github.com> Date: Mon, 2 Mar 2026 20:30:22 -0300 Subject: Fixes for PR #96 (#170) * Implement basic multiplayer functionality * Update README.md --------- Co-authored-by: Slenderman --- Minecraft.Client/ClientConnection.cpp | 4 +- Minecraft.Client/Common/Consoles_App.cpp | 2 +- .../Common/Network/GameNetworkManager.cpp | 10 +- .../Network/PlatformNetworkManagerInterface.h | 1 + .../Common/Network/PlatformNetworkManagerStub.cpp | 225 +++++- .../Common/Network/PlatformNetworkManagerStub.h | 3 +- Minecraft.Client/Common/Network/SessionInfo.h | 36 +- .../Common/UI/UIScene_LoadOrJoinMenu.cpp | 9 +- Minecraft.Client/Extrax64Stubs.cpp | 526 +++++++------ Minecraft.Client/Minecraft.Client.vcxproj | 2 + Minecraft.Client/Minecraft.Client.vcxproj.filters | 14 +- Minecraft.Client/MultiPlayerGameMode.cpp | 9 + Minecraft.Client/PendingConnection.cpp | 28 + Minecraft.Client/PlayerList.cpp | 45 +- .../Windows64/Network/WinsockNetLayer.cpp | 844 +++++++++++++++++++++ .../Windows64/Network/WinsockNetLayer.h | 147 ++++ Minecraft.Client/Windows64/Windows64_App.cpp | 3 +- Minecraft.Client/Windows64/Windows64_Minecraft.cpp | 48 +- Minecraft.World/x64headers/extraX64.h | 14 +- README.md | 1 + 20 files changed, 1705 insertions(+), 266 deletions(-) create mode 100644 Minecraft.Client/Windows64/Network/WinsockNetLayer.cpp create mode 100644 Minecraft.Client/Windows64/Network/WinsockNetLayer.h (limited to 'Minecraft.Client/Windows64/Windows64_Minecraft.cpp') diff --git a/Minecraft.Client/ClientConnection.cpp b/Minecraft.Client/ClientConnection.cpp index 52cec351..f3510d33 100644 --- a/Minecraft.Client/ClientConnection.cpp +++ b/Minecraft.Client/ClientConnection.cpp @@ -757,7 +757,7 @@ void ClientConnection::handleAddPlayer(shared_ptr packet) return; } } -#ifdef _WINDOWS64 +/*#ifdef _WINDOWS64 // On Windows64 all XUIDs are INVALID_XUID so the XUID check above never fires. // packet->m_playerIndex is the server-assigned sequential index (set via LoginPacket), // NOT the controller slot — so we must scan all local player slots and match by @@ -771,7 +771,7 @@ void ClientConnection::handleAddPlayer(shared_ptr packet) return; } } -#endif +#endif*/ double x = packet->x / 32.0; double y = packet->y / 32.0; diff --git a/Minecraft.Client/Common/Consoles_App.cpp b/Minecraft.Client/Common/Consoles_App.cpp index 38397814..0e02ab40 100644 --- a/Minecraft.Client/Common/Consoles_App.cpp +++ b/Minecraft.Client/Common/Consoles_App.cpp @@ -3402,7 +3402,7 @@ void CMinecraftApp::HandleXuiActions(void) bool gameStarted = false; for(int j = 0; j < pMinecraft->levels.length; j++) { - if (pMinecraft->levels.data[i] != NULL) + if (pMinecraft->levels.data[i] != nullptr) { gameStarted = true; break; diff --git a/Minecraft.Client/Common/Network/GameNetworkManager.cpp b/Minecraft.Client/Common/Network/GameNetworkManager.cpp index 940a148e..b3fb5cd7 100644 --- a/Minecraft.Client/Common/Network/GameNetworkManager.cpp +++ b/Minecraft.Client/Common/Network/GameNetworkManager.cpp @@ -167,6 +167,11 @@ bool CGameNetworkManager::_RunNetworkGame(LPVOID lpParameter) return true; } } + else + { + // Client needs QNET_STATE_GAME_PLAY so that IsInGameplay() returns true + s_pPlatformNetworkManager->SetGamePlayState(); + } if( g_NetworkManager.IsLeavingGame() ) return false; @@ -1479,7 +1484,10 @@ void CGameNetworkManager::CreateSocket( INetworkPlayer *pNetworkPlayer, bool loc Minecraft *pMinecraft = Minecraft::GetInstance(); Socket *socket = NULL; - shared_ptr mpPlayer = pMinecraft->localplayers[pNetworkPlayer->GetUserIndex()]; + shared_ptr mpPlayer = nullptr; + int userIdx = pNetworkPlayer->GetUserIndex(); + if (userIdx >= 0 && userIdx < XUSER_MAX_COUNT) + mpPlayer = pMinecraft->localplayers[userIdx]; if( localPlayer && mpPlayer != NULL && mpPlayer->connection != NULL) { // If we already have a MultiplayerLocalPlayer here then we are doing a session type change diff --git a/Minecraft.Client/Common/Network/PlatformNetworkManagerInterface.h b/Minecraft.Client/Common/Network/PlatformNetworkManagerInterface.h index 901e59e7..31c415a7 100644 --- a/Minecraft.Client/Common/Network/PlatformNetworkManagerInterface.h +++ b/Minecraft.Client/Common/Network/PlatformNetworkManagerInterface.h @@ -84,6 +84,7 @@ public: virtual void HandleSignInChange() = 0; virtual bool _RunNetworkGame() = 0; + virtual void SetGamePlayState() {} private: virtual bool _LeaveGame(bool bMigrateHost, bool bLeaveRoom) = 0; diff --git a/Minecraft.Client/Common/Network/PlatformNetworkManagerStub.cpp b/Minecraft.Client/Common/Network/PlatformNetworkManagerStub.cpp index b6b0fe12..10d1a6a5 100644 --- a/Minecraft.Client/Common/Network/PlatformNetworkManagerStub.cpp +++ b/Minecraft.Client/Common/Network/PlatformNetworkManagerStub.cpp @@ -2,7 +2,12 @@ #include "..\..\..\Minecraft.World\Socket.h" #include "..\..\..\Minecraft.World\StringHelpers.h" #include "PlatformNetworkManagerStub.h" -#include "..\..\Xbox\Network\NetworkPlayerXbox.h" // TODO - stub version of this? +#include "..\..\Xbox\Network\NetworkPlayerXbox.h" +#ifdef _WINDOWS64 +#include "..\..\Windows64\Network\WinsockNetLayer.h" +#include "..\..\Minecraft.h" +#include "..\..\User.h" +#endif CPlatformNetworkManagerStub *g_pPlatformNetworkManager; @@ -114,10 +119,43 @@ void CPlatformNetworkManagerStub::NotifyPlayerJoined(IQNetPlayer *pQNetPlayer ) } } +void CPlatformNetworkManagerStub::NotifyPlayerLeaving(IQNetPlayer* pQNetPlayer) +{ + app.DebugPrintf("Player 0x%p \"%ls\" leaving.\n", pQNetPlayer, pQNetPlayer->GetGamertag()); + + INetworkPlayer* networkPlayer = getNetworkPlayer(pQNetPlayer); + if (networkPlayer == NULL) + return; + + Socket* socket = networkPlayer->GetSocket(); + if (socket != NULL) + { + if (m_pIQNet->IsHost()) + g_NetworkManager.CloseConnection(networkPlayer); + } + + if (m_pIQNet->IsHost()) + { + SystemFlagRemovePlayer(networkPlayer); + } + + g_NetworkManager.PlayerLeaving(networkPlayer); + + for (int idx = 0; idx < XUSER_MAX_COUNT; ++idx) + { + if (playerChangedCallback[idx] != NULL) + playerChangedCallback[idx](playerChangedCallbackParam[idx], networkPlayer, true); + } + + removeNetworkPlayer(pQNetPlayer); +} + + bool CPlatformNetworkManagerStub::Initialise(CGameNetworkManager *pGameNetworkManager, int flagIndexSize) { m_pGameNetworkManager = pGameNetworkManager; m_flagIndexSize = flagIndexSize; + m_pIQNet = new IQNet(); g_pPlatformNetworkManager = this; for( int i = 0; i < XUSER_MAX_COUNT; i++ ) { @@ -174,6 +212,37 @@ bool CPlatformNetworkManagerStub::isSystemPrimaryPlayer(IQNetPlayer *pQNetPlayer // We call this twice a frame, either side of the render call so is a good place to "tick" things void CPlatformNetworkManagerStub::DoWork() { +#ifdef _WINDOWS64 + extern QNET_STATE _iQNetStubState; + if (_iQNetStubState == QNET_STATE_SESSION_STARTING && app.GetGameStarted()) + { + _iQNetStubState = QNET_STATE_GAME_PLAY; + if (m_pIQNet->IsHost()) + WinsockNetLayer::UpdateAdvertiseJoinable(true); + } + if (_iQNetStubState == QNET_STATE_IDLE) + TickSearch(); + if (_iQNetStubState == QNET_STATE_GAME_PLAY && m_pIQNet->IsHost()) + { + BYTE disconnectedSmallId; + while (WinsockNetLayer::PopDisconnectedSmallId(&disconnectedSmallId)) + { + IQNetPlayer* qnetPlayer = m_pIQNet->GetPlayerBySmallId(disconnectedSmallId); + if (qnetPlayer != NULL && qnetPlayer->m_smallId == disconnectedSmallId) + { + NotifyPlayerLeaving(qnetPlayer); + qnetPlayer->m_smallId = 0; + qnetPlayer->m_isRemote = false; + qnetPlayer->m_isHostPlayer = false; + qnetPlayer->m_gamertag[0] = 0; + qnetPlayer->SetCustomDataValue(0); + WinsockNetLayer::PushFreeSmallId(disconnectedSmallId); + if (IQNet::s_playerCount > 1) + IQNet::s_playerCount--; + } + } + } +#endif } int CPlatformNetworkManagerStub::GetPlayerCount() @@ -232,6 +301,10 @@ bool CPlatformNetworkManagerStub::LeaveGame(bool bMigrateHost) m_bLeavingGame = true; +#ifdef _WINDOWS64 + WinsockNetLayer::StopAdvertising(); +#endif + // If we are the host wait for the game server to end if(m_pIQNet->IsHost() && g_NetworkManager.ServerStoppedValid()) { @@ -239,6 +312,22 @@ bool CPlatformNetworkManagerStub::LeaveGame(bool bMigrateHost) g_NetworkManager.ServerStoppedWait(); g_NetworkManager.ServerStoppedDestroy(); } + else + { + m_pIQNet->EndGame(); + } + + for (AUTO_VAR(it, currentNetworkPlayers.begin()); it != currentNetworkPlayers.end(); it++) + delete* it; + currentNetworkPlayers.clear(); + m_machineQNetPrimaryPlayers.clear(); + SystemFlagReset(); + +#ifdef _WINDOWS64 + WinsockNetLayer::Shutdown(); + WinsockNetLayer::Initialize(); +#endif + return true; } @@ -262,7 +351,24 @@ void CPlatformNetworkManagerStub::HostGame(int localUsersMask, bool bOnlineGame, m_pIQNet->HostGame(); +#ifdef _WINDOWS64 + IQNet::m_player[0].m_smallId = 0; + IQNet::m_player[0].m_isRemote = false; + IQNet::m_player[0].m_isHostPlayer = true; + IQNet::s_playerCount = 1; +#endif + _HostGame( localUsersMask, publicSlots, privateSlots ); + +#ifdef _WINDOWS64 + int port = WIN64_NET_DEFAULT_PORT; + if (!WinsockNetLayer::IsActive()) + WinsockNetLayer::HostGame(port); + + const wchar_t* hostName = IQNet::m_player[0].m_gamertag; + unsigned int settings = app.GetGameHostOption(eGameHostOption_All); + WinsockNetLayer::StartAdvertising(port, hostName, settings, 0, 0, MINECRAFT_NET_VERSION); +#endif //#endif } @@ -275,9 +381,54 @@ bool CPlatformNetworkManagerStub::_StartGame() return true; } -int CPlatformNetworkManagerStub::JoinGame(FriendSessionInfo *searchResult, int localUsersMask, int primaryUserIndex) +int CPlatformNetworkManagerStub::JoinGame(FriendSessionInfo* searchResult, int localUsersMask, int primaryUserIndex) { +#ifdef _WINDOWS64 + if (searchResult == NULL) + return CGameNetworkManager::JOINGAME_FAIL_GENERAL; + + const char* hostIP = searchResult->data.hostIP; + int hostPort = searchResult->data.hostPort; + + if (hostPort <= 0 || hostIP[0] == 0) + return CGameNetworkManager::JOINGAME_FAIL_GENERAL; + + m_bLeavingGame = false; + IQNet::s_isHosting = false; + m_pIQNet->ClientJoinGame(); + + IQNet::m_player[0].m_smallId = 0; + IQNet::m_player[0].m_isRemote = true; + IQNet::m_player[0].m_isHostPlayer = true; + wcsncpy_s(IQNet::m_player[0].m_gamertag, 32, searchResult->data.hostName, _TRUNCATE); + + WinsockNetLayer::StopDiscovery(); + + if (!WinsockNetLayer::JoinGame(hostIP, hostPort)) + { + app.DebugPrintf("Win64 LAN: Failed to connect to %s:%d\n", hostIP, hostPort); + return CGameNetworkManager::JOINGAME_FAIL_GENERAL; + } + + BYTE localSmallId = WinsockNetLayer::GetLocalSmallId(); + + IQNet::m_player[localSmallId].m_smallId = localSmallId; + IQNet::m_player[localSmallId].m_isRemote = false; + IQNet::m_player[localSmallId].m_isHostPlayer = false; + + Minecraft* pMinecraft = Minecraft::GetInstance(); + wcscpy_s(IQNet::m_player[localSmallId].m_gamertag, 32, pMinecraft->user->name.c_str()); + IQNet::s_playerCount = localSmallId + 1; + + NotifyPlayerJoined(&IQNet::m_player[0]); + NotifyPlayerJoined(&IQNet::m_player[localSmallId]); + + m_pGameNetworkManager->StateChange_AnyToStarting(); + return CGameNetworkManager::JOINGAME_SUCCESS; +#else + return CGameNetworkManager::JOINGAME_SUCCESS; +#endif } bool CPlatformNetworkManagerStub::SetLocalGame(bool isLocal) @@ -315,6 +466,22 @@ void CPlatformNetworkManagerStub::HandleSignInChange() bool CPlatformNetworkManagerStub::_RunNetworkGame() { +#ifdef _WINDOWS64 + extern QNET_STATE _iQNetStubState; + _iQNetStubState = QNET_STATE_GAME_PLAY; + + for (DWORD i = 0; i < IQNet::s_playerCount; i++) + { + if (IQNet::m_player[i].m_isRemote) + { + INetworkPlayer* pNetworkPlayer = getNetworkPlayer(&IQNet::m_player[i]); + if (pNetworkPlayer != NULL && pNetworkPlayer->GetSocket() != NULL) + { + Socket::addIncomingSocket(pNetworkPlayer->GetSocket()); + } + } + } +#endif return true; } @@ -503,10 +670,60 @@ wstring CPlatformNetworkManagerStub::GatherRTTStats() void CPlatformNetworkManagerStub::TickSearch() { +#ifdef _WINDOWS64 + if (m_SessionsUpdatedCallback == NULL) + return; + + static DWORD lastSearchTime = 0; + DWORD now = GetTickCount(); + if (now - lastSearchTime < 2000) + return; + lastSearchTime = now; + + SearchForGames(); +#endif } void CPlatformNetworkManagerStub::SearchForGames() { +#ifdef _WINDOWS64 + std::vector lanSessions = WinsockNetLayer::GetDiscoveredSessions(); + + for (size_t i = 0; i < friendsSessions[0].size(); i++) + delete friendsSessions[0][i]; + friendsSessions[0].clear(); + + for (size_t i = 0; i < lanSessions.size(); i++) + { + FriendSessionInfo* info = new FriendSessionInfo(); + size_t nameLen = wcslen(lanSessions[i].hostName); + info->displayLabel = new wchar_t[nameLen + 1]; + wcscpy_s(info->displayLabel, nameLen + 1, lanSessions[i].hostName); + info->displayLabelLength = (unsigned char)nameLen; + info->displayLabelViewableStartIndex = 0; + + info->data.netVersion = lanSessions[i].netVersion; + info->data.m_uiGameHostSettings = lanSessions[i].gameHostSettings; + info->data.texturePackParentId = lanSessions[i].texturePackParentId; + info->data.subTexturePackId = lanSessions[i].subTexturePackId; + info->data.isReadyToJoin = lanSessions[i].isJoinable; + info->data.isJoinable = lanSessions[i].isJoinable; + strncpy_s(info->data.hostIP, sizeof(info->data.hostIP), lanSessions[i].hostIP, _TRUNCATE); + info->data.hostPort = lanSessions[i].hostPort; + wcsncpy_s(info->data.hostName, XUSER_NAME_SIZE, lanSessions[i].hostName, _TRUNCATE); + info->data.playerCount = lanSessions[i].playerCount; + info->data.maxPlayers = lanSessions[i].maxPlayers; + + info->sessionId = (SessionID)((unsigned __int64)inet_addr(lanSessions[i].hostIP) | ((unsigned __int64)lanSessions[i].hostPort << 32)); + + friendsSessions[0].push_back(info); + } + + m_searchResultsCount[0] = (int)friendsSessions[0].size(); + + if (m_SessionsUpdatedCallback != NULL) + m_SessionsUpdatedCallback(m_pSearchParam); +#endif } int CPlatformNetworkManagerStub::SearchForGamesThreadProc( void* lpParameter ) @@ -522,7 +739,9 @@ void CPlatformNetworkManagerStub::SetSearchResultsReady(int resultCount) vector *CPlatformNetworkManagerStub::GetSessionList(int iPad, int localPlayers, bool partyOnly) { - vector *filteredList = new vector();; + vector* filteredList = new vector(); + for (size_t i = 0; i < friendsSessions[0].size(); i++) + filteredList->push_back(friendsSessions[0][i]); return filteredList; } diff --git a/Minecraft.Client/Common/Network/PlatformNetworkManagerStub.h b/Minecraft.Client/Common/Network/PlatformNetworkManagerStub.h index f997dece..28953cec 100644 --- a/Minecraft.Client/Common/Network/PlatformNetworkManagerStub.h +++ b/Minecraft.Client/Common/Network/PlatformNetworkManagerStub.h @@ -161,8 +161,9 @@ public: virtual void GetFullFriendSessionInfo( FriendSessionInfo *foundSession, void (* FriendSessionUpdatedFn)(bool success, void *pParam), void *pParam ); virtual void ForceFriendsSessionRefresh(); -private: +public: void NotifyPlayerJoined( IQNetPlayer *pQNetPlayer ); + void NotifyPlayerLeaving(IQNetPlayer* pQNetPlayer); #ifndef _XBOX void FakeLocalPlayerJoined() { NotifyPlayerJoined(m_pIQNet->GetLocalPlayerByUserIndex(0)); } diff --git a/Minecraft.Client/Common/Network/SessionInfo.h b/Minecraft.Client/Common/Network/SessionInfo.h index 31472a19..ce6365bc 100644 --- a/Minecraft.Client/Common/Network/SessionInfo.h +++ b/Minecraft.Client/Common/Network/SessionInfo.h @@ -23,9 +23,9 @@ typedef struct _GameSessionData _GameSessionData() { netVersion = 0; - memset(hostName,0,XUSER_NAME_SIZE); - memset(players,0,MINECRAFT_NET_MAX_PLAYERS*sizeof(players[0])); - memset(szPlayers,0,MINECRAFT_NET_MAX_PLAYERS*XUSER_NAME_SIZE); + memset(hostName, 0, XUSER_NAME_SIZE); + memset(players, 0, MINECRAFT_NET_MAX_PLAYERS * sizeof(players[0])); + memset(szPlayers, 0, MINECRAFT_NET_MAX_PLAYERS * XUSER_NAME_SIZE); isJoinable = true; m_uiGameHostSettings = 0; texturePackParentId = 0; @@ -50,7 +50,7 @@ typedef struct _GameSessionData _GameSessionData() { netVersion = 0; - memset(players,0,MINECRAFT_NET_MAX_PLAYERS*sizeof(players[0])); + memset(players, 0, MINECRAFT_NET_MAX_PLAYERS * sizeof(players[0])); isJoinable = true; m_uiGameHostSettings = 0; texturePackParentId = 0; @@ -63,12 +63,19 @@ typedef struct _GameSessionData #else typedef struct _GameSessionData { - unsigned short netVersion; // 2 bytes - unsigned int m_uiGameHostSettings; // 4 bytes - unsigned int texturePackParentId; // 4 bytes - unsigned char subTexturePackId; // 1 byte + unsigned short netVersion; + unsigned int m_uiGameHostSettings; + unsigned int texturePackParentId; + unsigned char subTexturePackId; - bool isReadyToJoin; // 1 byte + bool isReadyToJoin; + bool isJoinable; + + char hostIP[64]; + int hostPort; + wchar_t hostName[XUSER_NAME_SIZE]; + unsigned char playerCount; + unsigned char maxPlayers; _GameSessionData() { @@ -76,6 +83,13 @@ typedef struct _GameSessionData m_uiGameHostSettings = 0; texturePackParentId = 0; subTexturePackId = 0; + isReadyToJoin = false; + isJoinable = true; + memset(hostIP, 0, sizeof(hostIP)); + hostPort = 0; + memset(hostName, 0, sizeof(hostName)); + playerCount = 0; + maxPlayers = MINECRAFT_NET_MAX_PLAYERS; } } GameSessionData; #endif @@ -91,7 +105,7 @@ public: #elif defined(_DURANGO) DQRNetworkManager::SessionSearchResult searchResult; #endif - wchar_t *displayLabel; + wchar_t* displayLabel; unsigned char displayLabelLength; unsigned char displayLabelViewableStartIndex; GameSessionData data; @@ -107,7 +121,7 @@ public: ~FriendSessionInfo() { - if(displayLabel!=NULL) + if (displayLabel != NULL) delete displayLabel; } }; diff --git a/Minecraft.Client/Common/UI/UIScene_LoadOrJoinMenu.cpp b/Minecraft.Client/Common/UI/UIScene_LoadOrJoinMenu.cpp index 4e48e395..2059c76f 100644 --- a/Minecraft.Client/Common/UI/UIScene_LoadOrJoinMenu.cpp +++ b/Minecraft.Client/Common/UI/UIScene_LoadOrJoinMenu.cpp @@ -284,13 +284,8 @@ UIScene_LoadOrJoinMenu::~UIScene_LoadOrJoinMenu() g_NetworkManager.SetSessionsUpdatedCallback( NULL, NULL ); app.SetLiveLinkRequired( false ); - if(m_currentSessions) - { - for(AUTO_VAR(it, m_currentSessions->begin()); it < m_currentSessions->end(); ++it) - { - delete (*it); - } - } + delete m_currentSessions; + m_currentSessions = NULL; #if TO_BE_IMPLEMENTED // Reset the background downloading, in case we changed it by attempting to download a texture pack diff --git a/Minecraft.Client/Extrax64Stubs.cpp b/Minecraft.Client/Extrax64Stubs.cpp index f6ad76c1..f368afed 100644 --- a/Minecraft.Client/Extrax64Stubs.cpp +++ b/Minecraft.Client/Extrax64Stubs.cpp @@ -20,6 +20,7 @@ #include "StatsCounter.h" #include "Windows64\Social\SocialManager.h" #include "Windows64\Sentient\DynamicConfigurations.h" +#include "Windows64\Network\WinsockNetLayer.h" #elif defined __PSVITA__ #include "PSVita\Sentient\SentientManager.h" #include "StatsCounter.h" @@ -46,63 +47,63 @@ CXuiStringTable StringTable; #ifndef _XBOX_ONE ATG::XMLParser::XMLParser() {} ATG::XMLParser::~XMLParser() {} -HRESULT ATG::XMLParser::ParseXMLBuffer( CONST CHAR* strBuffer, UINT uBufferSize ) { return S_OK; } -VOID ATG::XMLParser::RegisterSAXCallbackInterface( ISAXCallback *pISAXCallback ) {} +HRESULT ATG::XMLParser::ParseXMLBuffer(CONST CHAR* strBuffer, UINT uBufferSize) { return S_OK; } +VOID ATG::XMLParser::RegisterSAXCallbackInterface(ISAXCallback* pISAXCallback) {} #endif bool CSocialManager::IsTitleAllowedToPostAnything() { return false; } bool CSocialManager::AreAllUsersAllowedToPostImages() { return false; } bool CSocialManager::IsTitleAllowedToPostImages() { return false; } -bool CSocialManager::PostLinkToSocialNetwork( ESocialNetwork eSocialNetwork, DWORD dwUserIndex, bool bUsingKinect ) { return false; } -bool CSocialManager::PostImageToSocialNetwork( ESocialNetwork eSocialNetwork, DWORD dwUserIndex, bool bUsingKinect ) { return false; } -CSocialManager *CSocialManager::Instance() { return NULL; } +bool CSocialManager::PostLinkToSocialNetwork(ESocialNetwork eSocialNetwork, DWORD dwUserIndex, bool bUsingKinect) { return false; } +bool CSocialManager::PostImageToSocialNetwork(ESocialNetwork eSocialNetwork, DWORD dwUserIndex, bool bUsingKinect) { return false; } +CSocialManager* CSocialManager::Instance() { return NULL; } void CSocialManager::SetSocialPostText(LPCWSTR Title, LPCWSTR Caption, LPCWSTR Desc) {}; DWORD XShowPartyUI(DWORD dwUserIndex) { return 0; } DWORD XShowFriendsUI(DWORD dwUserIndex) { return 0; } -HRESULT XPartyGetUserList(XPARTY_USER_LIST *pUserList) { return S_OK; } -DWORD XContentGetThumbnail(DWORD dwUserIndex, const XCONTENT_DATA *pContentData, PBYTE pbThumbnail, PDWORD pcbThumbnail, PXOVERLAPPED *pOverlapped) { return 0; } +HRESULT XPartyGetUserList(XPARTY_USER_LIST* pUserList) { return S_OK; } +DWORD XContentGetThumbnail(DWORD dwUserIndex, const XCONTENT_DATA* pContentData, PBYTE pbThumbnail, PDWORD pcbThumbnail, PXOVERLAPPED* pOverlapped) { return 0; } void XShowAchievementsUI(int i) {} DWORD XBackgroundDownloadSetMode(XBACKGROUND_DOWNLOAD_MODE Mode) { return 0; } #ifndef _DURANGO -void PIXAddNamedCounter(int a, char *b, ...) {} +void PIXAddNamedCounter(int a, char* b, ...) {} //#define PS3_USE_PIX_EVENTS //#define PS4_USE_PIX_EVENTS -void PIXBeginNamedEvent(int a, char *b, ...) +void PIXBeginNamedEvent(int a, char* b, ...) { #ifdef PS4_USE_PIX_EVENTS char buf[512]; - va_list args; - va_start(args,b); - vsprintf(buf,b,args); + va_list args; + va_start(args, b); + vsprintf(buf, b, args); sceRazorCpuPushMarker(buf, 0xffffffff, SCE_RAZOR_MARKER_ENABLE_HUD); #endif #ifdef PS3_USE_PIX_EVENTS char buf[256]; wchar_t wbuf[256]; - va_list args; - va_start(args,b); - vsprintf(buf,b,args); + va_list args; + va_start(args, b); + vsprintf(buf, b, args); snPushMarker(buf); -// mbstowcs(wbuf,buf,256); -// RenderManager.BeginEvent(wbuf); - va_end(args); + // mbstowcs(wbuf,buf,256); + // RenderManager.BeginEvent(wbuf); + va_end(args); #endif } #if 0//__PSVITA__ - if( PixDepth < 64 ) - { - char buf[512]; - va_list args; - va_start(args,b); - vsprintf(buf,b,args); - sceRazorCpuPushMarkerWithHud(buf, 0xffffffff, SCE_RAZOR_MARKER_ENABLE_HUD); - } - PixDepth += 1; +if (PixDepth < 64) +{ + char buf[512]; + va_list args; + va_start(args, b); + vsprintf(buf, b, args); + sceRazorCpuPushMarkerWithHud(buf, 0xffffffff, SCE_RAZOR_MARKER_ENABLE_HUD); +} +PixDepth += 1; #endif @@ -113,17 +114,17 @@ void PIXEndNamedEvent() #endif #ifdef PS3_USE_PIX_EVENTS snPopMarker(); -// RenderManager.EndEvent(); + // RenderManager.EndEvent(); #endif #if 0//__PSVITA__ - if( PixDepth <= 64 ) + if (PixDepth <= 64) { sceRazorCpuPopMarker(); } PixDepth -= 1; #endif } -void PIXSetMarkerDeprecated(int a, char *b, ...) {} +void PIXSetMarkerDeprecated(int a, char* b, ...) {} #else // 4J Stu - Removed this implementation in favour of a macro that will convert our string format // conversion at compile time rather than at runtime @@ -175,38 +176,33 @@ bool IsEqualXUID(PlayerUID a, PlayerUID b) #endif } -void XMemCpy(void *a, const void *b, size_t s) { memcpy(a, b, s); } -void XMemSet(void *a, int t, size_t s) { memset(a, t, s); } -void XMemSet128(void *a, int t, size_t s) { memset(a, t, s); } -void *XPhysicalAlloc(SIZE_T a, ULONG_PTR b, ULONG_PTR c, DWORD d) { return malloc(a); } -void XPhysicalFree(void *a) { free(a); } +void XMemCpy(void* a, const void* b, size_t s) { memcpy(a, b, s); } +void XMemSet(void* a, int t, size_t s) { memset(a, t, s); } +void XMemSet128(void* a, int t, size_t s) { memset(a, t, s); } +void* XPhysicalAlloc(SIZE_T a, ULONG_PTR b, ULONG_PTR c, DWORD d) { return malloc(a); } +void XPhysicalFree(void* a) { free(a); } D3DXVECTOR3::D3DXVECTOR3() {} -D3DXVECTOR3::D3DXVECTOR3(float x,float y,float z) : x(x), y(y), z(z) {} -D3DXVECTOR3& D3DXVECTOR3::operator += ( CONST D3DXVECTOR3& add ) { x += add.x; y += add.y; z += add.z; return *this; } +D3DXVECTOR3::D3DXVECTOR3(float x, float y, float z) : x(x), y(y), z(z) {} +D3DXVECTOR3& D3DXVECTOR3::operator += (CONST D3DXVECTOR3 & add) { x += add.x; y += add.y; z += add.z; return *this; } -BYTE IQNetPlayer::GetSmallId() { return 0; } -void IQNetPlayer::SendData(IQNetPlayer *player, const void *pvData, DWORD dwDataSize, DWORD dwFlags) +BYTE IQNetPlayer::GetSmallId() { return m_smallId; } +void IQNetPlayer::SendData(IQNetPlayer * player, const void* pvData, DWORD dwDataSize, DWORD dwFlags) { - app.DebugPrintf("Sending from 0x%x to 0x%x %d bytes\n",this,player,dwDataSize); + if (WinsockNetLayer::IsActive()) + { + WinsockNetLayer::SendToSmallId(player->m_smallId, pvData, dwDataSize); + } } -bool IQNetPlayer::IsSameSystem(IQNetPlayer *player) { return true; } -DWORD IQNetPlayer::GetSendQueueSize( IQNetPlayer *player, DWORD dwFlags ) { return 0; } +bool IQNetPlayer::IsSameSystem(IQNetPlayer * player) { return (this == player) || (!m_isRemote && !player->m_isRemote); } +DWORD IQNetPlayer::GetSendQueueSize(IQNetPlayer * player, DWORD dwFlags) { return 0; } DWORD IQNetPlayer::GetCurrentRtt() { return 0; } -bool IQNetPlayer::IsHost() { return this == &IQNet::m_player[0]; } +bool IQNetPlayer::IsHost() { return m_isHostPlayer; } bool IQNetPlayer::IsGuest() { return false; } -bool IQNetPlayer::IsLocal() { return true; } -PlayerUID IQNetPlayer::GetXuid() { return INVALID_XUID; } -LPCWSTR IQNetPlayer::GetGamertag() -{ - static wchar_t tags[4][16]; - int idx = GetUserIndex(); - if(idx < 0 || idx >= 4) idx = 0; - mbstowcs(tags[idx], ProfileManager.GetGamertag(idx), 15); - tags[idx][15] = L'\0'; - return tags[idx]; -} -int IQNetPlayer::GetSessionIndex() { return 0; } +bool IQNetPlayer::IsLocal() { return !m_isRemote; } +PlayerUID IQNetPlayer::GetXuid() { return (PlayerUID)(0xe000d45248242f2e + m_smallId); } +LPCWSTR IQNetPlayer::GetGamertag() { return m_gamertag; } +int IQNetPlayer::GetSessionIndex() { return m_smallId; } bool IQNetPlayer::IsTalking() { return false; } bool IQNetPlayer::IsMutedByLocalUser(DWORD dwUserIndex) { return false; } bool IQNetPlayer::HasVoice() { return false; } @@ -219,22 +215,104 @@ ULONG_PTR IQNetPlayer::GetCustomDataValue() { return m_customData; } -IQNetPlayer IQNet::m_player[4]; +IQNetPlayer IQNet::m_player[MINECRAFT_NET_MAX_PLAYERS]; +DWORD IQNet::s_playerCount = 1; +bool IQNet::s_isHosting = true; + +QNET_STATE _iQNetStubState = QNET_STATE_IDLE; -bool _bQNetStubGameRunning = false; +void Win64_SetupRemoteQNetPlayer(IQNetPlayer * player, BYTE smallId, bool isHost, bool isLocal) +{ + player->m_smallId = smallId; + player->m_isRemote = !isLocal; + player->m_isHostPlayer = isHost; + swprintf_s(player->m_gamertag, 32, L"Player%d", smallId); + if (smallId >= IQNet::s_playerCount) + IQNet::s_playerCount = smallId + 1; +} -HRESULT IQNet::AddLocalPlayerByUserIndex(DWORD dwUserIndex){ return S_OK; } -IQNetPlayer *IQNet::GetHostPlayer() { return &m_player[0]; } -IQNetPlayer *IQNet::GetLocalPlayerByUserIndex(DWORD dwUserIndex) { return &m_player[dwUserIndex]; } -IQNetPlayer *IQNet::GetPlayerByIndex(DWORD dwPlayerIndex) { return &m_player[0]; } -IQNetPlayer *IQNet::GetPlayerBySmallId(BYTE SmallId){ return &m_player[0]; } -IQNetPlayer *IQNet::GetPlayerByXuid(PlayerUID xuid){ return &m_player[0]; } -DWORD IQNet::GetPlayerCount() { return 1; } -QNET_STATE IQNet::GetState() { return _bQNetStubGameRunning ? QNET_STATE_GAME_PLAY : QNET_STATE_IDLE; } -bool IQNet::IsHost() { return true; } -HRESULT IQNet::JoinGameFromInviteInfo(DWORD dwUserIndex, DWORD dwUserMask, const INVITE_INFO *pInviteInfo) { return S_OK; } -void IQNet::HostGame() { _bQNetStubGameRunning = true; } -void IQNet::EndGame() { _bQNetStubGameRunning = false; } +HRESULT IQNet::AddLocalPlayerByUserIndex(DWORD dwUserIndex) { 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) + return &m_player[dwUserIndex]; + return NULL; + } + if (dwUserIndex != 0) + return NULL; + for (DWORD i = 0; i < s_playerCount; i++) + { + if (!m_player[i].m_isRemote) + return &m_player[i]; + } + return NULL; +} +static bool Win64_IsActivePlayer(IQNetPlayer * p, DWORD index) +{ + if (index == 0) return true; + return (p->GetCustomDataValue() != 0); +} + +IQNetPlayer* IQNet::GetPlayerByIndex(DWORD dwPlayerIndex) +{ + DWORD found = 0; + for (DWORD i = 0; i < s_playerCount; i++) + { + if (Win64_IsActivePlayer(&m_player[i], i)) + { + if (found == dwPlayerIndex) return &m_player[i]; + found++; + } + } + return &m_player[0]; +} +IQNetPlayer* IQNet::GetPlayerBySmallId(BYTE SmallId) +{ + for (DWORD i = 0; i < s_playerCount; i++) + { + if (m_player[i].m_smallId == SmallId && Win64_IsActivePlayer(&m_player[i], i)) return &m_player[i]; + } + return NULL; +} +IQNetPlayer* IQNet::GetPlayerByXuid(PlayerUID xuid) +{ + for (DWORD i = 0; i < s_playerCount; i++) + { + if (Win64_IsActivePlayer(&m_player[i], i) && m_player[i].GetXuid() == xuid) return &m_player[i]; + } + return &m_player[0]; +} +DWORD IQNet::GetPlayerCount() +{ + DWORD count = 0; + for (DWORD i = 0; i < s_playerCount; i++) + { + if (Win64_IsActivePlayer(&m_player[i], i)) count++; + } + return count; +} +QNET_STATE IQNet::GetState() { return _iQNetStubState; } +bool IQNet::IsHost() { return s_isHosting; } +HRESULT IQNet::JoinGameFromInviteInfo(DWORD dwUserIndex, DWORD dwUserMask, const INVITE_INFO * pInviteInfo) { return S_OK; } +void IQNet::HostGame() { _iQNetStubState = QNET_STATE_SESSION_STARTING; s_isHosting = true; } +void IQNet::ClientJoinGame() { _iQNetStubState = QNET_STATE_SESSION_STARTING; s_isHosting = false; } +void IQNet::EndGame() +{ + _iQNetStubState = QNET_STATE_IDLE; + s_isHosting = false; + s_playerCount = 1; + for (int i = 1; i < MINECRAFT_NET_MAX_PLAYERS; i++) + { + m_player[i].m_smallId = 0; + m_player[i].m_isRemote = false; + m_player[i].m_isHostPlayer = false; + m_player[i].m_gamertag[0] = 0; + m_player[i].SetCustomDataValue(0); + } +} DWORD MinecraftDynamicConfigurations::GetTrialTime() { return DYNAMIC_CONFIG_DEFAULT_TRIAL_TIME; } @@ -244,9 +322,9 @@ void XSetThreadProcessor(HANDLE a, int b) {} // #endif // __PS3__ DWORD XUserGetSigninInfo( - DWORD dwUserIndex, - DWORD dwFlags, - PXUSER_SIGNIN_INFO pSigninInfo + DWORD dwUserIndex, + DWORD dwFlags, + PXUSER_SIGNIN_INFO pSigninInfo ) { return 0; @@ -257,16 +335,16 @@ LPCWSTR CXuiStringTable::Lookup(UINT nIndex) { return L"String"; } void CXuiStringTable::Clear() {} HRESULT CXuiStringTable::Load(LPCWSTR szId) { return S_OK; } -DWORD XUserAreUsersFriends( DWORD dwUserIndex, PPlayerUID pXuids, DWORD dwXuidCount, PBOOL pfResult, void *pOverlapped) { return 0; } +DWORD XUserAreUsersFriends(DWORD dwUserIndex, PPlayerUID pXuids, DWORD dwXuidCount, PBOOL pfResult, void* pOverlapped) { return 0; } #if defined __ORBIS__ || defined __PS3__ || defined _XBOX_ONE #else HRESULT XMemDecompress( - XMEMDECOMPRESSION_CONTEXT Context, - VOID *pDestination, - SIZE_T *pDestSize, - CONST VOID *pSource, - SIZE_T SrcSize + XMEMDECOMPRESSION_CONTEXT Context, + VOID * pDestination, + SIZE_T * pDestSize, + CONST VOID * pSource, + SIZE_T SrcSize ) { memcpy(pDestination, pSource, SrcSize); @@ -276,12 +354,12 @@ HRESULT XMemDecompress( /* DECOMPRESSOR_HANDLE Decompressor = (DECOMPRESSOR_HANDLE)Context; if( Decompress( - Decompressor, // Decompressor handle - (void *)pSource, // Compressed data - SrcSize, // Compressed data size - pDestination, // Decompressed buffer - *pDestSize, // Decompressed buffer size - pDestSize) ) // Decompressed data size + Decompressor, // Decompressor handle + (void *)pSource, // Compressed data + SrcSize, // Compressed data size + pDestination, // Decompressed buffer + *pDestSize, // Decompressed buffer size + pDestSize) ) // Decompressed data size { return S_OK; } @@ -293,11 +371,11 @@ HRESULT XMemDecompress( } HRESULT XMemCompress( - XMEMCOMPRESSION_CONTEXT Context, - VOID *pDestination, - SIZE_T *pDestSize, - CONST VOID *pSource, - SIZE_T SrcSize + XMEMCOMPRESSION_CONTEXT Context, + VOID * pDestination, + SIZE_T * pDestSize, + CONST VOID * pSource, + SIZE_T SrcSize ) { memcpy(pDestination, pSource, SrcSize); @@ -324,10 +402,10 @@ HRESULT XMemCompress( } HRESULT XMemCreateCompressionContext( - XMEMCODEC_TYPE CodecType, - CONST VOID *pCodecParams, - DWORD Flags, - XMEMCOMPRESSION_CONTEXT *pContext + XMEMCODEC_TYPE CodecType, + CONST VOID * pCodecParams, + DWORD Flags, + XMEMCOMPRESSION_CONTEXT * pContext ) { /* @@ -345,10 +423,10 @@ HRESULT XMemCreateCompressionContext( } HRESULT XMemCreateDecompressionContext( - XMEMCODEC_TYPE CodecType, - CONST VOID *pCodecParams, - DWORD Flags, - XMEMDECOMPRESSION_CONTEXT *pContext + XMEMCODEC_TYPE CodecType, + CONST VOID * pCodecParams, + DWORD Flags, + XMEMDECOMPRESSION_CONTEXT * pContext ) { /* @@ -367,14 +445,14 @@ HRESULT XMemCreateDecompressionContext( void XMemDestroyCompressionContext(XMEMCOMPRESSION_CONTEXT Context) { -// COMPRESSOR_HANDLE Compressor = (COMPRESSOR_HANDLE)Context; -// CloseCompressor(Compressor); + // COMPRESSOR_HANDLE Compressor = (COMPRESSOR_HANDLE)Context; + // CloseCompressor(Compressor); } void XMemDestroyDecompressionContext(XMEMDECOMPRESSION_CONTEXT Context) { -// DECOMPRESSOR_HANDLE Decompressor = (DECOMPRESSOR_HANDLE)Context; -// CloseDecompressor(Decompressor); + // DECOMPRESSOR_HANDLE Decompressor = (DECOMPRESSOR_HANDLE)Context; + // CloseDecompressor(Decompressor); } #endif @@ -389,62 +467,62 @@ DWORD XEnableGuestSignin(BOOL fEnable) { return 0; } /////////////////////////////////////////////// Profile library #ifdef _WINDOWS64 -static void *profileData[4]; +static void* profileData[4]; static bool s_bProfileIsFullVersion; -void C_4JProfile::Initialise( DWORD dwTitleID, - DWORD dwOfferID, - unsigned short usProfileVersion, - UINT uiProfileValuesC, - UINT uiProfileSettingsC, - DWORD *pdwProfileSettingsA, - int iGameDefinedDataSizeX4, - unsigned int *puiGameDefinedDataChangedBitmask) +void C_4JProfile::Initialise(DWORD dwTitleID, + DWORD dwOfferID, + unsigned short usProfileVersion, + UINT uiProfileValuesC, + UINT uiProfileSettingsC, + DWORD * pdwProfileSettingsA, + int iGameDefinedDataSizeX4, + unsigned int* puiGameDefinedDataChangedBitmask) { - for( int i = 0; i < 4; i++ ) + for (int i = 0; i < 4; i++) { - profileData[i] = new byte[iGameDefinedDataSizeX4/4]; - ZeroMemory(profileData[i],sizeof(byte)*iGameDefinedDataSizeX4/4); + profileData[i] = new byte[iGameDefinedDataSizeX4 / 4]; + ZeroMemory(profileData[i], sizeof(byte) * iGameDefinedDataSizeX4 / 4); // Set some sane initial values! - GAME_SETTINGS *pGameSettings = (GAME_SETTINGS *)profileData[i]; - pGameSettings->ucMenuSensitivity=100; //eGameSetting_Sensitivity_InMenu - pGameSettings->ucInterfaceOpacity=80; //eGameSetting_Sensitivity_InMenu - pGameSettings->usBitmaskValues|=0x0200; //eGameSetting_DisplaySplitscreenGamertags - on - pGameSettings->usBitmaskValues|=0x0400; //eGameSetting_Hints - on - pGameSettings->usBitmaskValues|=0x1000; //eGameSetting_Autosave - 2 - pGameSettings->usBitmaskValues|=0x8000; //eGameSetting_Tooltips - on - pGameSettings->uiBitmaskValues=0L; // reset - pGameSettings->uiBitmaskValues|=GAMESETTING_CLOUDS; //eGameSetting_Clouds - on - pGameSettings->uiBitmaskValues|=GAMESETTING_ONLINE; //eGameSetting_GameSetting_Online - on - pGameSettings->uiBitmaskValues|=GAMESETTING_FRIENDSOFFRIENDS; //eGameSetting_GameSetting_FriendsOfFriends - on - pGameSettings->uiBitmaskValues|=GAMESETTING_DISPLAYUPDATEMSG; //eGameSetting_DisplayUpdateMessage (counter) - pGameSettings->uiBitmaskValues&=~GAMESETTING_BEDROCKFOG; //eGameSetting_BedrockFog - off - pGameSettings->uiBitmaskValues|=GAMESETTING_DISPLAYHUD; //eGameSetting_DisplayHUD - on - pGameSettings->uiBitmaskValues|=GAMESETTING_DISPLAYHAND; //eGameSetting_DisplayHand - on - pGameSettings->uiBitmaskValues|=GAMESETTING_CUSTOMSKINANIM; //eGameSetting_CustomSkinAnim - on - pGameSettings->uiBitmaskValues|=GAMESETTING_DEATHMESSAGES; //eGameSetting_DeathMessages - on - pGameSettings->uiBitmaskValues|=(GAMESETTING_UISIZE&0x00000800); // uisize 2 - pGameSettings->uiBitmaskValues|=(GAMESETTING_UISIZE_SPLITSCREEN&0x00004000); // splitscreen ui size 3 - pGameSettings->uiBitmaskValues|=GAMESETTING_ANIMATEDCHARACTER; //eGameSetting_AnimatedCharacter - on + GAME_SETTINGS* pGameSettings = (GAME_SETTINGS*)profileData[i]; + pGameSettings->ucMenuSensitivity = 100; //eGameSetting_Sensitivity_InMenu + pGameSettings->ucInterfaceOpacity = 80; //eGameSetting_Sensitivity_InMenu + pGameSettings->usBitmaskValues |= 0x0200; //eGameSetting_DisplaySplitscreenGamertags - on + pGameSettings->usBitmaskValues |= 0x0400; //eGameSetting_Hints - on + pGameSettings->usBitmaskValues |= 0x1000; //eGameSetting_Autosave - 2 + pGameSettings->usBitmaskValues |= 0x8000; //eGameSetting_Tooltips - on + pGameSettings->uiBitmaskValues = 0L; // reset + pGameSettings->uiBitmaskValues |= GAMESETTING_CLOUDS; //eGameSetting_Clouds - on + pGameSettings->uiBitmaskValues |= GAMESETTING_ONLINE; //eGameSetting_GameSetting_Online - on + pGameSettings->uiBitmaskValues |= GAMESETTING_FRIENDSOFFRIENDS; //eGameSetting_GameSetting_FriendsOfFriends - on + pGameSettings->uiBitmaskValues |= GAMESETTING_DISPLAYUPDATEMSG; //eGameSetting_DisplayUpdateMessage (counter) + pGameSettings->uiBitmaskValues &= ~GAMESETTING_BEDROCKFOG; //eGameSetting_BedrockFog - off + pGameSettings->uiBitmaskValues |= GAMESETTING_DISPLAYHUD; //eGameSetting_DisplayHUD - on + pGameSettings->uiBitmaskValues |= GAMESETTING_DISPLAYHAND; //eGameSetting_DisplayHand - on + pGameSettings->uiBitmaskValues |= GAMESETTING_CUSTOMSKINANIM; //eGameSetting_CustomSkinAnim - on + pGameSettings->uiBitmaskValues |= GAMESETTING_DEATHMESSAGES; //eGameSetting_DeathMessages - on + pGameSettings->uiBitmaskValues |= (GAMESETTING_UISIZE & 0x00000800); // uisize 2 + pGameSettings->uiBitmaskValues |= (GAMESETTING_UISIZE_SPLITSCREEN & 0x00004000); // splitscreen ui size 3 + pGameSettings->uiBitmaskValues |= GAMESETTING_ANIMATEDCHARACTER; //eGameSetting_AnimatedCharacter - on // TU12 // favorite skins added, but only set in TU12 - set to FFs - for(int i=0;iuiFavoriteSkinA[i]=0xFFFFFFFF; + pGameSettings->uiFavoriteSkinA[i] = 0xFFFFFFFF; } - pGameSettings->ucCurrentFavoriteSkinPos=0; + pGameSettings->ucCurrentFavoriteSkinPos = 0; // Added a bitmask in TU13 to enable/disable display of the Mash-up pack worlds in the saves list pGameSettings->uiMashUpPackWorldsDisplay = 0xFFFFFFFF; // PS3DEC13 - pGameSettings->uiBitmaskValues&=~GAMESETTING_PS3EULAREAD; //eGameSetting_PS3_EULA_Read - off + pGameSettings->uiBitmaskValues &= ~GAMESETTING_PS3EULAREAD; //eGameSetting_PS3_EULA_Read - off // PS3 1.05 - added Greek pGameSettings->ucLanguage = MINECRAFT_LANGUAGE_DEFAULT; // use the system language // PS Vita - network mode added - pGameSettings->uiBitmaskValues&=~GAMESETTING_PSVITANETWORKMODEADHOC; //eGameSetting_PSVita_NetworkModeAdhoc - off + pGameSettings->uiBitmaskValues &= ~GAMESETTING_PSVITANETWORKMODEADHOC; //eGameSetting_PSVita_NetworkModeAdhoc - off // Tutorials for most menus, and a few other things @@ -453,90 +531,91 @@ void C_4JProfile::Initialise( DWORD dwTitleID, pGameSettings->ucTutorialCompletion[2] = 0xF; // Has gone halfway through the tutorial - pGameSettings->ucTutorialCompletion[28] |= 1<<0; + pGameSettings->ucTutorialCompletion[28] |= 1 << 0; } } -void C_4JProfile::SetTrialTextStringTable(CXuiStringTable *pStringTable,int iAccept,int iReject) {} -void C_4JProfile::SetTrialAwardText(eAwardType AwardType,int iTitle,int iText) {} +void C_4JProfile::SetTrialTextStringTable(CXuiStringTable * pStringTable, int iAccept, int iReject) {} +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); } 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; } -UINT C_4JProfile::DisplayOfflineProfile(int( *Func)(LPVOID,const bool, const int iPad),LPVOID lpParam,int iQuadrant) { return 0; } -UINT C_4JProfile::RequestConvertOfflineToGuestUI(int( *Func)(LPVOID,const bool, const int iPad),LPVOID lpParam,int iQuadrant) { return 0; } +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; } +UINT C_4JProfile::DisplayOfflineProfile(int(*Func)(LPVOID, const bool, const int iPad), LPVOID lpParam, int iQuadrant) { return 0; } +UINT C_4JProfile::RequestConvertOfflineToGuestUI(int(*Func)(LPVOID, const bool, const int iPad), LPVOID lpParam, int iQuadrant) { return 0; } void C_4JProfile::SetPrimaryPlayerChanged(bool bVal) {} bool C_4JProfile::QuerySigninStatus(void) { return true; } -void C_4JProfile::GetXUID(int iPad, PlayerUID *pXuid,bool bOnlineXuid) {*pXuid = 0xe000d45248242f2e; } -BOOL C_4JProfile::AreXUIDSEqual(PlayerUID xuid1,PlayerUID xuid2) { return false; } +void C_4JProfile::GetXUID(int iPad, PlayerUID * pXuid, bool bOnlineXuid) +{ +#ifdef _WINDOWS64 + if (iPad != 0) + { + *pXuid = INVALID_XUID; + return; + } + if (IQNet::s_isHosting) + *pXuid = 0xe000d45248242f2e; + else + *pXuid = 0xe000d45248242f2e + WinsockNetLayer::GetLocalSmallId(); +#else + * pXuid = 0xe000d45248242f2e + iPad; +#endif +} +BOOL C_4JProfile::AreXUIDSEqual(PlayerUID xuid1, PlayerUID xuid2) { return xuid1 == xuid2; } BOOL C_4JProfile::XUIDIsGuest(PlayerUID xuid) { return false; } bool C_4JProfile::AllowedToPlayMultiplayer(int iProf) { return true; } #if defined(__ORBIS__) -bool C_4JProfile::GetChatAndContentRestrictions(int iPad, bool thisQuadrantOnly, bool *pbChatRestricted,bool *pbContentRestricted,int *piAge) +bool C_4JProfile::GetChatAndContentRestrictions(int iPad, bool thisQuadrantOnly, bool* pbChatRestricted, bool* pbContentRestricted, int* piAge) { - if(pbChatRestricted) *pbChatRestricted = false; - if(pbContentRestricted) *pbContentRestricted = false; - if(piAge) *piAge = 100; + if (pbChatRestricted) *pbChatRestricted = false; + if (pbContentRestricted) *pbContentRestricted = false; + if (piAge) *piAge = 100; return true; } #endif void C_4JProfile::StartTrialGame() {} -void C_4JProfile::AllowedPlayerCreatedContent(int iPad, bool thisQuadrantOnly, BOOL *allAllowed, BOOL *friendsAllowed) {} -BOOL C_4JProfile::CanViewPlayerCreatedContent(int iPad, bool thisQuadrantOnly, PPlayerUID pXuids, DWORD dwXuidCount ) { return true; } -bool C_4JProfile::GetProfileAvatar(int iPad,int( *Func)(LPVOID lpParam,PBYTE pbThumbnail,DWORD dwThumbnailBytes), LPVOID lpParam) { return false; } +void C_4JProfile::AllowedPlayerCreatedContent(int iPad, bool thisQuadrantOnly, BOOL * allAllowed, BOOL * friendsAllowed) {} +BOOL C_4JProfile::CanViewPlayerCreatedContent(int iPad, bool thisQuadrantOnly, PPlayerUID pXuids, DWORD dwXuidCount) { return true; } +bool C_4JProfile::GetProfileAvatar(int iPad, int(*Func)(LPVOID lpParam, PBYTE pbThumbnail, DWORD dwThumbnailBytes), LPVOID lpParam) { return false; } void C_4JProfile::CancelProfileAvatarRequest() {} int C_4JProfile::GetPrimaryPad() { return 0; } void C_4JProfile::SetPrimaryPad(int iPad) {} #ifdef _DURANGO char fakeGamerTag[32] = "PlayerName"; -void SetFakeGamertag(char *name){ strcpy_s(fakeGamerTag, name); } -char* C_4JProfile::GetGamertag(int iPad){ return fakeGamerTag; } +void SetFakeGamertag(char* name) { strcpy_s(fakeGamerTag, name); } +char* C_4JProfile::GetGamertag(int iPad) { return fakeGamerTag; } #else -char* C_4JProfile::GetGamertag(int iPad) -{ - static char tags[4][16] = { "Player 1", "Player 2", "Player 3", "Player 4" }; - if(iPad >= 0 && iPad < 4) return tags[iPad]; - return tags[0]; -} -wstring C_4JProfile::GetDisplayName(int iPad) -{ - switch(iPad) - { - case 1: return L"Player 2"; - case 2: return L"Player 3"; - case 3: return L"Player 4"; - default: return L"Player 1"; - } -} +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; } #endif bool C_4JProfile::IsFullVersion() { return s_bProfileIsFullVersion; } -void C_4JProfile::SetSignInChangeCallback(void ( *Func)(LPVOID, bool, unsigned int),LPVOID lpParam) {} -void C_4JProfile::SetNotificationsCallback(void ( *Func)(LPVOID, DWORD, unsigned int),LPVOID lpParam) {} +void C_4JProfile::SetSignInChangeCallback(void (*Func)(LPVOID, bool, unsigned int), LPVOID lpParam) {} +void C_4JProfile::SetNotificationsCallback(void (*Func)(LPVOID, DWORD, unsigned int), LPVOID lpParam) {} bool C_4JProfile::RegionIsNorthAmerica(void) { return false; } bool C_4JProfile::LocaleIsUSorCanada(void) { return false; } HRESULT C_4JProfile::GetLiveConnectionStatus() { return S_OK; } bool C_4JProfile::IsSystemUIDisplayed() { return false; } -void C_4JProfile::SetProfileReadErrorCallback(void ( *Func)(LPVOID), LPVOID lpParam) {} -int( *defaultOptionsCallback)(LPVOID,C_4JProfile::PROFILESETTINGS *, const int iPad) = NULL; +void C_4JProfile::SetProfileReadErrorCallback(void (*Func)(LPVOID), LPVOID lpParam) {} +int(*defaultOptionsCallback)(LPVOID, C_4JProfile::PROFILESETTINGS*, const int iPad) = NULL; LPVOID lpProfileParam = NULL; -int C_4JProfile::SetDefaultOptionsCallback(int( *Func)(LPVOID,PROFILESETTINGS *, const int iPad),LPVOID lpParam) +int C_4JProfile::SetDefaultOptionsCallback(int(*Func)(LPVOID, PROFILESETTINGS*, const int iPad), LPVOID lpParam) { defaultOptionsCallback = Func; lpProfileParam = lpParam; return 0; } -int C_4JProfile::SetOldProfileVersionCallback(int( *Func)(LPVOID,unsigned char *, const unsigned short,const int),LPVOID lpParam) { return 0; } +int C_4JProfile::SetOldProfileVersionCallback(int(*Func)(LPVOID, unsigned char*, const unsigned short, const int), LPVOID lpParam) { return 0; } // To store the dashboard preferences for controller flipped, etc. C_4JProfile::PROFILESETTINGS ProfileSettingsA[XUSER_MAX_COUNT]; -C_4JProfile::PROFILESETTINGS * C_4JProfile::GetDashboardProfileSettings(int iPad) { return &ProfileSettingsA[iPad]; } +C_4JProfile::PROFILESETTINGS* C_4JProfile::GetDashboardProfileSettings(int iPad) { return &ProfileSettingsA[iPad]; } void C_4JProfile::WriteToProfile(int iQuadrant, bool bGameDefinedDataChanged, bool bOverride5MinuteLimitOnProfileWrites) {} void C_4JProfile::ForceQueuedProfileWrites(int iPad) {} -void *C_4JProfile::GetGameDefinedProfileData(int iQuadrant) +void* C_4JProfile::GetGameDefinedProfileData(int iQuadrant) { // 4J Stu - Don't reset the options when we call this!! //defaultOptionsCallback(lpProfileParam, (C_4JProfile::PROFILESETTINGS *)profileData[iQuadrant], iQuadrant); @@ -545,9 +624,10 @@ void *C_4JProfile::GetGameDefinedProfileData(int iQuadrant) return profileData[iQuadrant]; } void C_4JProfile::ResetProfileProcessState() {} -void C_4JProfile::Tick( void ) {} -void C_4JProfile::RegisterAward(int iAwardNumber,int iGamerconfigID, eAwardType eType, bool bLeaderboardAffected, - CXuiStringTable*pStringTable, int iTitleStr, int iTextStr, int iAcceptStr, char *pszThemeName, unsigned int ulThemeSize) {} +void C_4JProfile::Tick(void) {} +void C_4JProfile::RegisterAward(int iAwardNumber, int iGamerconfigID, eAwardType eType, bool bLeaderboardAffected, + CXuiStringTable * pStringTable, int iTitleStr, int iTextStr, int iAcceptStr, char* pszThemeName, unsigned int ulThemeSize) { +} int C_4JProfile::GetAwardId(int iAwardNumber) { return 0; } eAwardType C_4JProfile::GetAwardType(int iAwardNumber) { return eAwardType_Achievement; } bool C_4JProfile::CanBeAwarded(int iQuadrant, int iAwardNumber) { return false; } @@ -555,11 +635,11 @@ void C_4JProfile::Award(int iQuadrant, int iAwardNumber, bool bForce) {} bool C_4JProfile::IsAwardsFlagSet(int iQuadrant, int iAward) { return false; } void C_4JProfile::RichPresenceInit(int iPresenceCount, int iContextCount) {} void C_4JProfile::RegisterRichPresenceContext(int iGameConfigContextID) {} -void C_4JProfile::SetRichPresenceContextValue(int iPad,int iContextID, int iVal) {} -void C_4JProfile::SetCurrentGameActivity(int iPad,int iNewPresence, bool bSetOthersToIdle) {} +void C_4JProfile::SetRichPresenceContextValue(int iPad, int iContextID, int iVal) {} +void C_4JProfile::SetCurrentGameActivity(int iPad, int iNewPresence, bool bSetOthersToIdle) {} void C_4JProfile::DisplayFullVersionPurchase(bool bRequired, int iQuadrant, int iUpsellParam) {} -void C_4JProfile::SetUpsellCallback(void ( *Func)(LPVOID lpParam, eUpsellType type, eUpsellResponse response, int iUserData),LPVOID lpParam) {} -void C_4JProfile::SetDebugFullOverride(bool bVal) {s_bProfileIsFullVersion = bVal;} +void C_4JProfile::SetUpsellCallback(void (*Func)(LPVOID lpParam, eUpsellType type, eUpsellResponse response, int iUserData), LPVOID lpParam) {} +void C_4JProfile::SetDebugFullOverride(bool bVal) { s_bProfileIsFullVersion = bVal; } void C_4JProfile::ShowProfileCard(int iPad, PlayerUID targetUid) {} /////////////////////////////////////////////// Storage library @@ -567,60 +647,60 @@ void C_4JProfile::ShowProfileCard(int iPad, PlayerUID targetUid) {} #if 0 C4JStorage::C4JStorage() {} void C4JStorage::Tick() {} -C4JStorage::EMessageResult C4JStorage::RequestMessageBox(UINT uiTitle, UINT uiText, UINT *uiOptionA,UINT uiOptionC, DWORD dwPad, int( *Func)(LPVOID,int,const C4JStorage::EMessageResult),LPVOID lpParam, C4JStringTable *pStringTable, WCHAR *pwchFormatString,DWORD dwFocusButton) { return C4JStorage::EMessage_Undefined; } -C4JStorage::EMessageResult C4JStorage::GetMessageBoxResult() { return C4JStorage::EMessage_Undefined; } -bool C4JStorage::SetSaveDevice(int( *Func)(LPVOID,const bool),LPVOID lpParam, bool bForceResetOfSaveDevice) { return true; } -void C4JStorage::Init(LPCWSTR pwchDefaultSaveName,char *pszSavePackName,int iMinimumSaveSize, int( *Func)(LPVOID, const ESavingMessage, int),LPVOID lpParam) {} +C4JStorage::EMessageResult C4JStorage::RequestMessageBox(UINT uiTitle, UINT uiText, UINT * uiOptionA, UINT uiOptionC, DWORD dwPad, int(*Func)(LPVOID, int, const C4JStorage::EMessageResult), LPVOID lpParam, C4JStringTable * pStringTable, WCHAR * pwchFormatString, DWORD dwFocusButton) { return C4JStorage::EMessage_Undefined; } +C4JStorage::EMessageResult C4JStorage::GetMessageBoxResult() { return C4JStorage::EMessage_Undefined; } +bool C4JStorage::SetSaveDevice(int(*Func)(LPVOID, const bool), LPVOID lpParam, bool bForceResetOfSaveDevice) { return true; } +void C4JStorage::Init(LPCWSTR pwchDefaultSaveName, char* pszSavePackName, int iMinimumSaveSize, int(*Func)(LPVOID, const ESavingMessage, int), LPVOID lpParam) {} void C4JStorage::ResetSaveData() {} void C4JStorage::SetDefaultSaveNameForKeyboardDisplay(LPCWSTR pwchDefaultSaveName) {} void C4JStorage::SetSaveTitle(LPCWSTR pwchDefaultSaveName) {} LPCWSTR C4JStorage::GetSaveTitle() { return L""; } -bool C4JStorage::GetSaveUniqueNumber(INT *piVal) { return true; } -bool C4JStorage::GetSaveUniqueFilename(char *pszName) { return true; } -void C4JStorage::SetSaveUniqueFilename(char *szFilename) { } -void C4JStorage::SetState(ESaveGameControlState eControlState,int( *Func)(LPVOID,const bool),LPVOID lpParam) {} +bool C4JStorage::GetSaveUniqueNumber(INT * piVal) { return true; } +bool C4JStorage::GetSaveUniqueFilename(char* pszName) { return true; } +void C4JStorage::SetSaveUniqueFilename(char* szFilename) {} +void C4JStorage::SetState(ESaveGameControlState eControlState, int(*Func)(LPVOID, const bool), LPVOID lpParam) {} void C4JStorage::SetSaveDisabled(bool bDisable) {} bool C4JStorage::GetSaveDisabled(void) { return false; } unsigned int C4JStorage::GetSaveSize() { return 0; } -void C4JStorage::GetSaveData(void *pvData,unsigned int *pulBytes) {} +void C4JStorage::GetSaveData(void* pvData, unsigned int* pulBytes) {} PVOID C4JStorage::AllocateSaveData(unsigned int ulBytes) { return new char[ulBytes]; } -void C4JStorage::SaveSaveData(unsigned int ulBytes,PBYTE pbThumbnail,DWORD cbThumbnail,PBYTE pbTextData, DWORD dwTextLen) {} -void C4JStorage::CopySaveDataToNewSave(PBYTE pbThumbnail,DWORD cbThumbnail,WCHAR *wchNewName,int ( *Func)(LPVOID lpParam, bool), LPVOID lpParam) {} -void C4JStorage::SetSaveDeviceSelected(unsigned int uiPad,bool bSelected) {} +void C4JStorage::SaveSaveData(unsigned int ulBytes, PBYTE pbThumbnail, DWORD cbThumbnail, PBYTE pbTextData, DWORD dwTextLen) {} +void C4JStorage::CopySaveDataToNewSave(PBYTE pbThumbnail, DWORD cbThumbnail, WCHAR * wchNewName, int (*Func)(LPVOID lpParam, bool), LPVOID lpParam) {} +void C4JStorage::SetSaveDeviceSelected(unsigned int uiPad, bool bSelected) {} bool C4JStorage::GetSaveDeviceSelected(unsigned int iPad) { return true; } -C4JStorage::ELoadGameStatus C4JStorage::DoesSaveExist(bool *pbExists) { return C4JStorage::ELoadGame_Idle; } +C4JStorage::ELoadGameStatus C4JStorage::DoesSaveExist(bool* pbExists) { return C4JStorage::ELoadGame_Idle; } bool C4JStorage::EnoughSpaceForAMinSaveGame() { return true; } void C4JStorage::SetSaveMessageVPosition(float fY) {} //C4JStorage::ESGIStatus C4JStorage::GetSavesInfo(int iPad,bool ( *Func)(LPVOID, int, CACHEINFOSTRUCT *, int, HRESULT),LPVOID lpParam,char *pszSavePackName) { return C4JStorage::ESGIStatus_Idle; } -C4JStorage::ESaveGameState C4JStorage::GetSavesInfo(int iPad,int ( *Func)(LPVOID lpParam,SAVE_DETAILS *pSaveDetails,const bool),LPVOID lpParam,char *pszSavePackName) { return C4JStorage::ESaveGame_Idle; } +C4JStorage::ESaveGameState C4JStorage::GetSavesInfo(int iPad, int (*Func)(LPVOID lpParam, SAVE_DETAILS * pSaveDetails, const bool), LPVOID lpParam, char* pszSavePackName) { return C4JStorage::ESaveGame_Idle; } -void C4JStorage::GetSaveCacheFileInfo(DWORD dwFile,XCONTENT_DATA &xContentData) {} -void C4JStorage::GetSaveCacheFileInfo(DWORD dwFile, PBYTE *ppbImageData, DWORD *pdwImageBytes) {} -C4JStorage::ESaveGameState C4JStorage::LoadSaveData(PSAVE_INFO pSaveInfo,int( *Func)(LPVOID lpParam,const bool, const bool), LPVOID lpParam) {return C4JStorage::ESaveGame_Idle;} -C4JStorage::EDeleteGameStatus C4JStorage::DeleteSaveData(PSAVE_INFO pSaveInfo,int( *Func)(LPVOID lpParam,const bool), LPVOID lpParam) { return C4JStorage::EDeleteGame_Idle; } -PSAVE_DETAILS C4JStorage::ReturnSavesInfo() {return NULL;} +void C4JStorage::GetSaveCacheFileInfo(DWORD dwFile, XCONTENT_DATA & xContentData) {} +void C4JStorage::GetSaveCacheFileInfo(DWORD dwFile, PBYTE * ppbImageData, DWORD * pdwImageBytes) {} +C4JStorage::ESaveGameState C4JStorage::LoadSaveData(PSAVE_INFO pSaveInfo, int(*Func)(LPVOID lpParam, const bool, const bool), LPVOID lpParam) { return C4JStorage::ESaveGame_Idle; } +C4JStorage::EDeleteGameStatus C4JStorage::DeleteSaveData(PSAVE_INFO pSaveInfo, int(*Func)(LPVOID lpParam, const bool), LPVOID lpParam) { return C4JStorage::EDeleteGame_Idle; } +PSAVE_DETAILS C4JStorage::ReturnSavesInfo() { return NULL; } -void C4JStorage::RegisterMarketplaceCountsCallback(int ( *Func)(LPVOID lpParam, C4JStorage::DLC_TMS_DETAILS *, int), LPVOID lpParam ) {} -void C4JStorage::SetDLCPackageRoot(char *pszDLCRoot) {} -C4JStorage::EDLCStatus C4JStorage::GetDLCOffers(int iPad,int( *Func)(LPVOID, int, DWORD, int),LPVOID lpParam, DWORD dwOfferTypesBitmaskT) { return C4JStorage::EDLC_Idle; } +void C4JStorage::RegisterMarketplaceCountsCallback(int (*Func)(LPVOID lpParam, C4JStorage::DLC_TMS_DETAILS*, int), LPVOID lpParam) {} +void C4JStorage::SetDLCPackageRoot(char* pszDLCRoot) {} +C4JStorage::EDLCStatus C4JStorage::GetDLCOffers(int iPad, int(*Func)(LPVOID, int, DWORD, int), LPVOID lpParam, DWORD dwOfferTypesBitmaskT) { return C4JStorage::EDLC_Idle; } DWORD C4JStorage::CancelGetDLCOffers() { return 0; } void C4JStorage::ClearDLCOffers() {} -XMARKETPLACE_CONTENTOFFER_INFO& C4JStorage::GetOffer(DWORD dw) { static XMARKETPLACE_CONTENTOFFER_INFO retval = {0}; return retval; } +XMARKETPLACE_CONTENTOFFER_INFO& C4JStorage::GetOffer(DWORD dw) { static XMARKETPLACE_CONTENTOFFER_INFO retval = { 0 }; return retval; } int C4JStorage::GetOfferCount() { return 0; } -DWORD C4JStorage::InstallOffer(int iOfferIDC,ULONGLONG *ullOfferIDA,int( *Func)(LPVOID, int, int),LPVOID lpParam, bool bTrial) { return 0; } -DWORD C4JStorage::GetAvailableDLCCount( int iPad) { return 0; } -XCONTENT_DATA& C4JStorage::GetDLC(DWORD dw) { static XCONTENT_DATA retval = {0}; return retval; } -C4JStorage::EDLCStatus C4JStorage::GetInstalledDLC(int iPad,int( *Func)(LPVOID, int, int),LPVOID lpParam) { return C4JStorage::EDLC_Idle; } -DWORD C4JStorage::MountInstalledDLC(int iPad,DWORD dwDLC,int( *Func)(LPVOID, int, DWORD,DWORD),LPVOID lpParam,LPCSTR szMountDrive) { return 0; } +DWORD C4JStorage::InstallOffer(int iOfferIDC, ULONGLONG * ullOfferIDA, int(*Func)(LPVOID, int, int), LPVOID lpParam, bool bTrial) { return 0; } +DWORD C4JStorage::GetAvailableDLCCount(int iPad) { return 0; } +XCONTENT_DATA& C4JStorage::GetDLC(DWORD dw) { static XCONTENT_DATA retval = { 0 }; return retval; } +C4JStorage::EDLCStatus C4JStorage::GetInstalledDLC(int iPad, int(*Func)(LPVOID, int, int), LPVOID lpParam) { return C4JStorage::EDLC_Idle; } +DWORD C4JStorage::MountInstalledDLC(int iPad, DWORD dwDLC, int(*Func)(LPVOID, int, DWORD, DWORD), LPVOID lpParam, LPCSTR szMountDrive) { return 0; } DWORD C4JStorage::UnmountInstalledDLC(LPCSTR szMountDrive) { return 0; } -C4JStorage::ETMSStatus C4JStorage::ReadTMSFile(int iQuadrant,eGlobalStorage eStorageFacility,C4JStorage::eTMS_FileType eFileType, WCHAR *pwchFilename,BYTE **ppBuffer,DWORD *pdwBufferSize,int( *Func)(LPVOID, WCHAR *,int, bool, int),LPVOID lpParam, int iAction) { return C4JStorage::ETMSStatus_Idle; } -bool C4JStorage::WriteTMSFile(int iQuadrant,eGlobalStorage eStorageFacility,WCHAR *pwchFilename,BYTE *pBuffer,DWORD dwBufferSize) { return true; } -bool C4JStorage::DeleteTMSFile(int iQuadrant,eGlobalStorage eStorageFacility,WCHAR *pwchFilename) { return true; } -void C4JStorage::StoreTMSPathName(WCHAR *pwchName) {} -unsigned int C4JStorage::CRC(unsigned char *buf, int len) { return 0; } +C4JStorage::ETMSStatus C4JStorage::ReadTMSFile(int iQuadrant, eGlobalStorage eStorageFacility, C4JStorage::eTMS_FileType eFileType, WCHAR * pwchFilename, BYTE * *ppBuffer, DWORD * pdwBufferSize, int(*Func)(LPVOID, WCHAR*, int, bool, int), LPVOID lpParam, int iAction) { return C4JStorage::ETMSStatus_Idle; } +bool C4JStorage::WriteTMSFile(int iQuadrant, eGlobalStorage eStorageFacility, WCHAR * pwchFilename, BYTE * pBuffer, DWORD dwBufferSize) { return true; } +bool C4JStorage::DeleteTMSFile(int iQuadrant, eGlobalStorage eStorageFacility, WCHAR * pwchFilename) { return true; } +void C4JStorage::StoreTMSPathName(WCHAR * pwchName) {} +unsigned int C4JStorage::CRC(unsigned char* buf, int len) { return 0; } struct PTMSPP_FILEDATA; -C4JStorage::ETMSStatus C4JStorage::TMSPP_ReadFile(int iPad,C4JStorage::eGlobalStorage eStorageFacility,C4JStorage::eTMS_FILETYPEVAL eFileTypeVal,LPCSTR szFilename,int( *Func)(LPVOID,int,int,PTMSPP_FILEDATA, LPCSTR)/*=NULL*/,LPVOID lpParam/*=NULL*/, int iUserData/*=0*/) {return C4JStorage::ETMSStatus_Idle;} +C4JStorage::ETMSStatus C4JStorage::TMSPP_ReadFile(int iPad, C4JStorage::eGlobalStorage eStorageFacility, C4JStorage::eTMS_FILETYPEVAL eFileTypeVal, LPCSTR szFilename, int(*Func)(LPVOID, int, int, PTMSPP_FILEDATA, LPCSTR)/*=NULL*/, LPVOID lpParam/*=NULL*/, int iUserData/*=0*/) { return C4JStorage::ETMSStatus_Idle; } #endif // _WINDOWS64 #endif // __PS3__ @@ -636,8 +716,8 @@ BOOL CSentientManager::RecordHeartBeat(DWORD dwUserId) { return true; } BOOL CSentientManager::RecordLevelStart(DWORD dwUserId, ESen_FriendOrMatch friendsOrMatch, ESen_CompeteOrCoop competeOrCoop, int difficulty, DWORD numberOfLocalPlayers, DWORD numberOfOnlinePlayers) { return true; } BOOL CSentientManager::RecordLevelExit(DWORD dwUserId, ESen_LevelExitStatus levelExitStatus) { return true; } BOOL CSentientManager::RecordLevelSaveOrCheckpoint(DWORD dwUserId, INT saveOrCheckPointID, INT saveSizeInBytes) { return true; } -BOOL CSentientManager::RecordLevelResume(DWORD dwUserId, ESen_FriendOrMatch friendsOrMatch, ESen_CompeteOrCoop competeOrCoop, int difficulty, DWORD numberOfLocalPlayers, DWORD numberOfOnlinePlayers, INT saveOrCheckPointID) { return true; } -BOOL CSentientManager::RecordPauseOrInactive(DWORD dwUserId) { return true; } +BOOL CSentientManager::RecordLevelResume(DWORD dwUserId, ESen_FriendOrMatch friendsOrMatch, ESen_CompeteOrCoop competeOrCoop, int difficulty, DWORD numberOfLocalPlayers, DWORD numberOfOnlinePlayers, INT saveOrCheckPointID) { return true; } +BOOL CSentientManager::RecordPauseOrInactive(DWORD dwUserId) { return true; } BOOL CSentientManager::RecordUnpauseOrActive(DWORD dwUserId) { return true; } BOOL CSentientManager::RecordMenuShown(DWORD dwUserId, INT menuID, INT optionalMenuSubID) { return true; } BOOL CSentientManager::RecordAchievementUnlocked(DWORD dwUserId, INT achievementID, INT achievementGamerscore) { return true; } diff --git a/Minecraft.Client/Minecraft.Client.vcxproj b/Minecraft.Client/Minecraft.Client.vcxproj index 2398f0bf..97befd61 100644 --- a/Minecraft.Client/Minecraft.Client.vcxproj +++ b/Minecraft.Client/Minecraft.Client.vcxproj @@ -21547,6 +21547,7 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CUtrue true + true true @@ -38310,6 +38311,7 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CUtrue true + true true diff --git a/Minecraft.Client/Minecraft.Client.vcxproj.filters b/Minecraft.Client/Minecraft.Client.vcxproj.filters index ab31a46e..fe61baa4 100644 --- a/Minecraft.Client/Minecraft.Client.vcxproj.filters +++ b/Minecraft.Client/Minecraft.Client.vcxproj.filters @@ -723,9 +723,13 @@ {0061db22-43de-4b54-a161-c43958cdcd7e} - + {889a84db-3009-4a7c-8234-4bf93d412690} + + {e5d7fb24-25b8-413c-84ec-974bf0d4a3d1} + + @@ -3613,7 +3617,7 @@ Common\Source Files\UI\Scenes - + Common\Source Files\Leaderboards @@ -3769,6 +3773,9 @@ Common\Source Files\Leaderboards + + Windows64\Source Files\Network + @@ -5916,6 +5923,9 @@ Source Files + + Windows64\Source Files\Network + diff --git a/Minecraft.Client/MultiPlayerGameMode.cpp b/Minecraft.Client/MultiPlayerGameMode.cpp index cbf8a7ab..e7611b37 100644 --- a/Minecraft.Client/MultiPlayerGameMode.cpp +++ b/Minecraft.Client/MultiPlayerGameMode.cpp @@ -6,6 +6,7 @@ #include "Minecraft.h" #include "ClientConnection.h" #include "LevelRenderer.h" +#include "Common\Network\GameNetworkManager.h" #include "..\Minecraft.World\net.minecraft.world.level.h" #include "..\Minecraft.World\net.minecraft.world.item.h" #include "..\Minecraft.World\net.minecraft.world.entity.player.h" @@ -85,6 +86,14 @@ bool MultiPlayerGameMode::destroyBlock(int x, int y, int z, int face) if (oldTile == NULL) return false; +#ifdef _WINDOWS64 + if (g_NetworkManager.IsHost()) + { + level->levelEvent(LevelEvent::PARTICLES_DESTROY_BLOCK, x, y, z, oldTile->id + (level->getData(x, y, z) << Tile::TILE_NUM_SHIFT)); + return true; + } +#endif + level->levelEvent(LevelEvent::PARTICLES_DESTROY_BLOCK, x, y, z, oldTile->id + (level->getData(x, y, z) << Tile::TILE_NUM_SHIFT)); int data = level->getData(x, y, z); diff --git a/Minecraft.Client/PendingConnection.cpp b/Minecraft.Client/PendingConnection.cpp index e9b37fc6..8034dff2 100644 --- a/Minecraft.Client/PendingConnection.cpp +++ b/Minecraft.Client/PendingConnection.cpp @@ -20,6 +20,10 @@ Random *PendingConnection::random = new Random(); +#ifdef _WINDOWS64 +bool g_bRejectDuplicateNames = true; +#endif + PendingConnection::PendingConnection(MinecraftServer *server, Socket *socket, const wstring& id) { // 4J - added initialisers @@ -166,6 +170,30 @@ void PendingConnection::handleLogin(shared_ptr packet) { disconnect(DisconnectPacket::eDisconnect_Banned); } +#ifdef _WINDOWS64 + else if (g_bRejectDuplicateNames) + { + bool nameTaken = false; + vector >& pl = server->getPlayers()->players; + for (unsigned int i = 0; i < pl.size(); i++) + { + if (pl[i] != NULL && pl[i]->name == name) + { + nameTaken = true; + break; + } + } + if (nameTaken) + { + app.DebugPrintf("Rejecting duplicate name: %ls\n", name.c_str()); + disconnect(DisconnectPacket::eDisconnect_Banned); + } + else + { + handleAcceptedLogin(packet); + } + } +#endif else { handleAcceptedLogin(packet); diff --git a/Minecraft.Client/PlayerList.cpp b/Minecraft.Client/PlayerList.cpp index 9fbef2a2..3cf47a1c 100644 --- a/Minecraft.Client/PlayerList.cpp +++ b/Minecraft.Client/PlayerList.cpp @@ -25,7 +25,7 @@ #include "..\Minecraft.World\net.minecraft.world.level.saveddata.h" #include "..\Minecraft.World\JavaMath.h" #include "..\Minecraft.World\EntityIO.h" -#ifdef _XBOX +#if defined(_XBOX) || defined(_WINDOWS64) #include "Xbox\Network\NetworkPlayerXbox.h" #elif defined(__PS3__) || defined(__ORBIS__) #include "Common\Network\Sony\NetworkPlayerSony.h" @@ -56,6 +56,11 @@ PlayerList::PlayerList(MinecraftServer *server) maxPlayers = server->settings->getInt(L"max-players", 20); doWhiteList = false; +#ifdef _WINDOWS64 + maxPlayers = MINECRAFT_NET_MAX_PLAYERS; +#else + maxPlayers = server->settings->getInt(L"max-players", 20); +#endif InitializeCriticalSection(&m_kickPlayersCS); InitializeCriticalSection(&m_closePlayersCS); } @@ -100,7 +105,14 @@ void PlayerList::placeNewPlayer(Connection *connection, shared_ptr } } #endif - +#ifdef _WINDOWS64 + if (networkPlayer != NULL && !networkPlayer->IsLocal()) + { + NetworkPlayerXbox* nxp = (NetworkPlayerXbox*)networkPlayer; + IQNetPlayer* qnp = nxp->GetQNetPlayer(); + wcsncpy_s(qnp->m_gamertag, 32, player->name.c_str(), _TRUNCATE); + } +#endif // 4J Stu - TU-1 hotfix // Fix for #13150 - When a player loads/joins a game after saving/leaving in the nether, sometimes they are spawned on top of the nether and cannot mine down validatePlayerSpawnPosition(player); @@ -227,7 +239,7 @@ void PlayerList::placeNewPlayer(Connection *connection, shared_ptr sendLevelInfo(player, level); // 4J-PB - removed, since it needs to be localised in the language the client is in - //server->players->broadcastAll( shared_ptr( new ChatPacket(L"§e" + playerEntity->name + L" joined the game.") ) ); + //server->players->broadcastAll( shared_ptr( new ChatPacket(L"�e" + playerEntity->name + L" joined the game.") ) ); broadcastAll( shared_ptr( new ChatPacket(player->name, ChatPacket::e_ChatPlayerJoinedGame) ) ); MemSect(14); @@ -428,7 +440,7 @@ void PlayerList::add(shared_ptr player) // Some code from here has been moved to the above validatePlayerSpawnPosition function // 4J Stu - Swapped these lines about so that we get the chunk visiblity packet way ahead of all the add tracked entity packets - // Fix for #9169 - ART : Sign text is replaced with the words “Awaiting approval”. + // Fix for #9169 - ART : Sign text is replaced with the words �Awaiting approval�. changeDimension(player, NULL); level->addEntity(player); @@ -469,14 +481,12 @@ void PlayerList::remove(shared_ptr player) //4J Stu - We don't want to save the map data for guests, so when we are sure that the player is gone delete the map if(player->isGuest()) playerIo->deleteMapFilesForPlayer(player); ServerLevel *level = player->getLevel(); - if (player->riding != NULL) +if (player->riding != NULL) { - // remove mount first because the player unmounts when being - // removed, also remove mount because it's saved in the player's - // save tag level->removeEntityImmediately(player->riding); app.DebugPrintf("removing player mount"); } + level->getTracker()->removeEntity(player); level->removeEntity(player); level->getChunkMap()->remove(player); AUTO_VAR(it, find(players.begin(),players.end(),player)); @@ -497,17 +507,30 @@ void PlayerList::remove(shared_ptr player) shared_ptr PlayerList::getPlayerForLogin(PendingConnection *pendingConnection, const wstring& userName, PlayerUID xuid, PlayerUID onlineXuid) { - if (players.size() >= maxPlayers) +#ifdef _WINDOWS64 + if (players.size() >= (unsigned int)MINECRAFT_NET_MAX_PLAYERS) +#else + if (players.size() >= (unsigned int)maxPlayers) +#endif { pendingConnection->disconnect(DisconnectPacket::eDisconnect_ServerFull); return shared_ptr(); } - shared_ptr player = shared_ptr(new ServerPlayer(server, server->getLevel(0), userName, new ServerPlayerGameMode(server->getLevel(0)) )); player->gameMode->player = player; // 4J added as had to remove this assignment from ServerPlayer ctor player->setXuid( xuid ); // 4J Added player->setOnlineXuid( onlineXuid ); // 4J Added - +#ifdef _WINDOWS64 + { + INetworkPlayer* np = pendingConnection->connection->getSocket()->getPlayer(); + if (np != NULL) + { + PlayerUID realXuid = np->GetUID(); + player->setXuid(realXuid); + player->setOnlineXuid(realXuid); + } + } +#endif // Work out the base server player settings INetworkPlayer *networkPlayer = pendingConnection->connection->getSocket()->getPlayer(); if(networkPlayer != NULL && !networkPlayer->IsHost()) diff --git a/Minecraft.Client/Windows64/Network/WinsockNetLayer.cpp b/Minecraft.Client/Windows64/Network/WinsockNetLayer.cpp new file mode 100644 index 00000000..19fc2598 --- /dev/null +++ b/Minecraft.Client/Windows64/Network/WinsockNetLayer.cpp @@ -0,0 +1,844 @@ +#include "stdafx.h" + +#ifdef _WINDOWS64 + +#include "WinsockNetLayer.h" +#include "..\..\Common\Network\PlatformNetworkManagerStub.h" +#include "..\..\..\Minecraft.World\Socket.h" + +SOCKET WinsockNetLayer::s_listenSocket = INVALID_SOCKET; +SOCKET WinsockNetLayer::s_hostConnectionSocket = INVALID_SOCKET; +HANDLE WinsockNetLayer::s_acceptThread = NULL; +HANDLE WinsockNetLayer::s_clientRecvThread = NULL; + +bool WinsockNetLayer::s_isHost = false; +bool WinsockNetLayer::s_connected = false; +bool WinsockNetLayer::s_active = false; +bool WinsockNetLayer::s_initialized = false; + +BYTE WinsockNetLayer::s_localSmallId = 0; +BYTE WinsockNetLayer::s_hostSmallId = 0; +BYTE WinsockNetLayer::s_nextSmallId = 1; + +CRITICAL_SECTION WinsockNetLayer::s_sendLock; +CRITICAL_SECTION WinsockNetLayer::s_connectionsLock; + +std::vector WinsockNetLayer::s_connections; + +SOCKET WinsockNetLayer::s_advertiseSock = INVALID_SOCKET; +HANDLE WinsockNetLayer::s_advertiseThread = NULL; +volatile bool WinsockNetLayer::s_advertising = false; +Win64LANBroadcast WinsockNetLayer::s_advertiseData = {}; +CRITICAL_SECTION WinsockNetLayer::s_advertiseLock; +int WinsockNetLayer::s_hostGamePort = WIN64_NET_DEFAULT_PORT; + +SOCKET WinsockNetLayer::s_discoverySock = INVALID_SOCKET; +HANDLE WinsockNetLayer::s_discoveryThread = NULL; +volatile bool WinsockNetLayer::s_discovering = false; +CRITICAL_SECTION WinsockNetLayer::s_discoveryLock; +std::vector WinsockNetLayer::s_discoveredSessions; + +CRITICAL_SECTION WinsockNetLayer::s_disconnectLock; +std::vector WinsockNetLayer::s_disconnectedSmallIds; + +CRITICAL_SECTION WinsockNetLayer::s_freeSmallIdLock; +std::vector WinsockNetLayer::s_freeSmallIds; + +bool g_Win64MultiplayerHost = false; +bool g_Win64MultiplayerJoin = false; +int g_Win64MultiplayerPort = WIN64_NET_DEFAULT_PORT; +char g_Win64MultiplayerIP[256] = "127.0.0.1"; + +bool WinsockNetLayer::Initialize() +{ + if (s_initialized) return true; + + WSADATA wsaData; + int result = WSAStartup(MAKEWORD(2, 2), &wsaData); + if (result != 0) + { + app.DebugPrintf("WSAStartup failed: %d\n", result); + return false; + } + + InitializeCriticalSection(&s_sendLock); + InitializeCriticalSection(&s_connectionsLock); + InitializeCriticalSection(&s_advertiseLock); + InitializeCriticalSection(&s_discoveryLock); + InitializeCriticalSection(&s_disconnectLock); + InitializeCriticalSection(&s_freeSmallIdLock); + + s_initialized = true; + + StartDiscovery(); + + return true; +} + +void WinsockNetLayer::Shutdown() +{ + StopAdvertising(); + StopDiscovery(); + + s_active = false; + s_connected = false; + + if (s_listenSocket != INVALID_SOCKET) + { + closesocket(s_listenSocket); + s_listenSocket = INVALID_SOCKET; + } + + if (s_hostConnectionSocket != INVALID_SOCKET) + { + closesocket(s_hostConnectionSocket); + s_hostConnectionSocket = INVALID_SOCKET; + } + + EnterCriticalSection(&s_connectionsLock); + for (size_t i = 0; i < s_connections.size(); i++) + { + s_connections[i].active = false; + if (s_connections[i].tcpSocket != INVALID_SOCKET) + { + closesocket(s_connections[i].tcpSocket); + } + } + s_connections.clear(); + LeaveCriticalSection(&s_connectionsLock); + + if (s_acceptThread != NULL) + { + WaitForSingleObject(s_acceptThread, 2000); + CloseHandle(s_acceptThread); + s_acceptThread = NULL; + } + + if (s_clientRecvThread != NULL) + { + WaitForSingleObject(s_clientRecvThread, 2000); + CloseHandle(s_clientRecvThread); + s_clientRecvThread = NULL; + } + + if (s_initialized) + { + DeleteCriticalSection(&s_sendLock); + DeleteCriticalSection(&s_connectionsLock); + DeleteCriticalSection(&s_advertiseLock); + DeleteCriticalSection(&s_discoveryLock); + DeleteCriticalSection(&s_disconnectLock); + s_disconnectedSmallIds.clear(); + DeleteCriticalSection(&s_freeSmallIdLock); + s_freeSmallIds.clear(); + WSACleanup(); + s_initialized = false; + } +} + +bool WinsockNetLayer::HostGame(int port) +{ + if (!s_initialized && !Initialize()) return false; + + s_isHost = true; + s_localSmallId = 0; + s_hostSmallId = 0; + s_nextSmallId = 1; + s_hostGamePort = port; + + EnterCriticalSection(&s_freeSmallIdLock); + s_freeSmallIds.clear(); + LeaveCriticalSection(&s_freeSmallIdLock); + + struct addrinfo hints = {}; + struct addrinfo *result = NULL; + + hints.ai_family = AF_INET; + hints.ai_socktype = SOCK_STREAM; + hints.ai_protocol = IPPROTO_TCP; + hints.ai_flags = AI_PASSIVE; + + char portStr[16]; + sprintf_s(portStr, "%d", port); + + int iResult = getaddrinfo(NULL, portStr, &hints, &result); + if (iResult != 0) + { + app.DebugPrintf("getaddrinfo failed: %d\n", iResult); + return false; + } + + s_listenSocket = socket(result->ai_family, result->ai_socktype, result->ai_protocol); + if (s_listenSocket == INVALID_SOCKET) + { + app.DebugPrintf("socket() failed: %d\n", WSAGetLastError()); + freeaddrinfo(result); + return false; + } + + int opt = 1; + setsockopt(s_listenSocket, SOL_SOCKET, SO_REUSEADDR, (const char *)&opt, sizeof(opt)); + + iResult = ::bind(s_listenSocket, result->ai_addr, (int)result->ai_addrlen); + freeaddrinfo(result); + if (iResult == SOCKET_ERROR) + { + app.DebugPrintf("bind() failed: %d\n", WSAGetLastError()); + closesocket(s_listenSocket); + s_listenSocket = INVALID_SOCKET; + return false; + } + + iResult = listen(s_listenSocket, SOMAXCONN); + if (iResult == SOCKET_ERROR) + { + app.DebugPrintf("listen() failed: %d\n", WSAGetLastError()); + closesocket(s_listenSocket); + s_listenSocket = INVALID_SOCKET; + return false; + } + + s_active = true; + s_connected = true; + + s_acceptThread = CreateThread(NULL, 0, AcceptThreadProc, NULL, 0, NULL); + + app.DebugPrintf("Win64 LAN: Hosting on port %d\n", port); + return true; +} + +bool WinsockNetLayer::JoinGame(const char *ip, int port) +{ + if (!s_initialized && !Initialize()) return false; + + s_isHost = false; + s_hostSmallId = 0; + + struct addrinfo hints = {}; + struct addrinfo *result = NULL; + + hints.ai_family = AF_INET; + hints.ai_socktype = SOCK_STREAM; + hints.ai_protocol = IPPROTO_TCP; + + char portStr[16]; + sprintf_s(portStr, "%d", port); + + int iResult = getaddrinfo(ip, portStr, &hints, &result); + if (iResult != 0) + { + app.DebugPrintf("getaddrinfo failed for %s:%d - %d\n", ip, port, iResult); + return false; + } + + s_hostConnectionSocket = socket(result->ai_family, result->ai_socktype, result->ai_protocol); + if (s_hostConnectionSocket == INVALID_SOCKET) + { + app.DebugPrintf("socket() failed: %d\n", WSAGetLastError()); + freeaddrinfo(result); + return false; + } + + int noDelay = 1; + setsockopt(s_hostConnectionSocket, IPPROTO_TCP, TCP_NODELAY, (const char *)&noDelay, sizeof(noDelay)); + + iResult = connect(s_hostConnectionSocket, result->ai_addr, (int)result->ai_addrlen); + freeaddrinfo(result); + if (iResult == SOCKET_ERROR) + { + app.DebugPrintf("connect() to %s:%d failed: %d\n", ip, port, WSAGetLastError()); + closesocket(s_hostConnectionSocket); + s_hostConnectionSocket = INVALID_SOCKET; + return false; + } + + BYTE assignBuf[1]; + int bytesRecv = recv(s_hostConnectionSocket, (char *)assignBuf, 1, 0); + if (bytesRecv != 1) + { + app.DebugPrintf("Failed to receive small ID assignment from host\n"); + closesocket(s_hostConnectionSocket); + s_hostConnectionSocket = INVALID_SOCKET; + return false; + } + s_localSmallId = assignBuf[0]; + + app.DebugPrintf("Win64 LAN: Connected to %s:%d, assigned smallId=%d\n", ip, port, s_localSmallId); + + s_active = true; + s_connected = true; + + s_clientRecvThread = CreateThread(NULL, 0, ClientRecvThreadProc, NULL, 0, NULL); + + return true; +} + +bool WinsockNetLayer::SendOnSocket(SOCKET sock, const void *data, int dataSize) +{ + if (sock == INVALID_SOCKET || dataSize <= 0) return false; + + EnterCriticalSection(&s_sendLock); + + BYTE header[4]; + header[0] = (BYTE)((dataSize >> 24) & 0xFF); + header[1] = (BYTE)((dataSize >> 16) & 0xFF); + header[2] = (BYTE)((dataSize >> 8) & 0xFF); + header[3] = (BYTE)(dataSize & 0xFF); + + int totalSent = 0; + int toSend = 4; + while (totalSent < toSend) + { + int sent = send(sock, (const char *)header + totalSent, toSend - totalSent, 0); + if (sent == SOCKET_ERROR || sent == 0) + { + LeaveCriticalSection(&s_sendLock); + return false; + } + totalSent += sent; + } + + totalSent = 0; + while (totalSent < dataSize) + { + int sent = send(sock, (const char *)data + totalSent, dataSize - totalSent, 0); + if (sent == SOCKET_ERROR || sent == 0) + { + LeaveCriticalSection(&s_sendLock); + return false; + } + totalSent += sent; + } + + LeaveCriticalSection(&s_sendLock); + return true; +} + +bool WinsockNetLayer::SendToSmallId(BYTE targetSmallId, const void *data, int dataSize) +{ + if (!s_active) return false; + + if (s_isHost) + { + SOCKET sock = GetSocketForSmallId(targetSmallId); + if (sock == INVALID_SOCKET) return false; + return SendOnSocket(sock, data, dataSize); + } + else + { + return SendOnSocket(s_hostConnectionSocket, data, dataSize); + } +} + +SOCKET WinsockNetLayer::GetSocketForSmallId(BYTE smallId) +{ + EnterCriticalSection(&s_connectionsLock); + for (size_t i = 0; i < s_connections.size(); i++) + { + if (s_connections[i].smallId == smallId && s_connections[i].active) + { + SOCKET sock = s_connections[i].tcpSocket; + LeaveCriticalSection(&s_connectionsLock); + return sock; + } + } + LeaveCriticalSection(&s_connectionsLock); + return INVALID_SOCKET; +} + +static bool RecvExact(SOCKET sock, BYTE *buf, int len) +{ + int totalRecv = 0; + while (totalRecv < len) + { + int r = recv(sock, (char *)buf + totalRecv, len - totalRecv, 0); + if (r <= 0) return false; + totalRecv += r; + } + return true; +} + +void WinsockNetLayer::HandleDataReceived(BYTE fromSmallId, BYTE toSmallId, unsigned char *data, unsigned int dataSize) +{ + INetworkPlayer *pPlayerFrom = g_NetworkManager.GetPlayerBySmallId(fromSmallId); + INetworkPlayer *pPlayerTo = g_NetworkManager.GetPlayerBySmallId(toSmallId); + + if (pPlayerFrom == NULL || pPlayerTo == NULL) return; + + if (s_isHost) + { + ::Socket *pSocket = pPlayerFrom->GetSocket(); + if (pSocket != NULL) + pSocket->pushDataToQueue(data, dataSize, false); + } + else + { + ::Socket *pSocket = pPlayerTo->GetSocket(); + if (pSocket != NULL) + pSocket->pushDataToQueue(data, dataSize, true); + } +} + +DWORD WINAPI WinsockNetLayer::AcceptThreadProc(LPVOID param) +{ + while (s_active) + { + SOCKET clientSocket = accept(s_listenSocket, NULL, NULL); + if (clientSocket == INVALID_SOCKET) + { + if (s_active) + app.DebugPrintf("accept() failed: %d\n", WSAGetLastError()); + break; + } + + int noDelay = 1; + setsockopt(clientSocket, IPPROTO_TCP, TCP_NODELAY, (const char *)&noDelay, sizeof(noDelay)); + + extern QNET_STATE _iQNetStubState; + if (_iQNetStubState != QNET_STATE_GAME_PLAY) + { + app.DebugPrintf("Win64 LAN: Rejecting connection, game not ready\n"); + closesocket(clientSocket); + continue; + } + + BYTE assignedSmallId; + EnterCriticalSection(&s_freeSmallIdLock); + if (!s_freeSmallIds.empty()) + { + assignedSmallId = s_freeSmallIds.back(); + s_freeSmallIds.pop_back(); + } + else if (s_nextSmallId < MINECRAFT_NET_MAX_PLAYERS) + { + assignedSmallId = s_nextSmallId++; + } + else + { + LeaveCriticalSection(&s_freeSmallIdLock); + app.DebugPrintf("Win64 LAN: Server full, rejecting connection\n"); + closesocket(clientSocket); + continue; + } + LeaveCriticalSection(&s_freeSmallIdLock); + + BYTE assignBuf[1] = { assignedSmallId }; + int sent = send(clientSocket, (const char *)assignBuf, 1, 0); + if (sent != 1) + { + app.DebugPrintf("Failed to send small ID to client\n"); + closesocket(clientSocket); + continue; + } + + Win64RemoteConnection conn; + conn.tcpSocket = clientSocket; + conn.smallId = assignedSmallId; + conn.active = true; + conn.recvThread = NULL; + + EnterCriticalSection(&s_connectionsLock); + s_connections.push_back(conn); + int connIdx = (int)s_connections.size() - 1; + LeaveCriticalSection(&s_connectionsLock); + + app.DebugPrintf("Win64 LAN: Client connected, assigned smallId=%d\n", assignedSmallId); + + IQNetPlayer *qnetPlayer = &IQNet::m_player[assignedSmallId]; + + extern void Win64_SetupRemoteQNetPlayer(IQNetPlayer *player, BYTE smallId, bool isHost, bool isLocal); + Win64_SetupRemoteQNetPlayer(qnetPlayer, assignedSmallId, false, false); + + extern CPlatformNetworkManagerStub *g_pPlatformNetworkManager; + g_pPlatformNetworkManager->NotifyPlayerJoined(qnetPlayer); + + DWORD *threadParam = new DWORD; + *threadParam = connIdx; + HANDLE hThread = CreateThread(NULL, 0, RecvThreadProc, threadParam, 0, NULL); + + EnterCriticalSection(&s_connectionsLock); + if (connIdx < (int)s_connections.size()) + s_connections[connIdx].recvThread = hThread; + LeaveCriticalSection(&s_connectionsLock); + } + return 0; +} + +DWORD WINAPI WinsockNetLayer::RecvThreadProc(LPVOID param) +{ + DWORD connIdx = *(DWORD *)param; + delete (DWORD *)param; + + EnterCriticalSection(&s_connectionsLock); + if (connIdx >= (DWORD)s_connections.size()) + { + LeaveCriticalSection(&s_connectionsLock); + return 0; + } + SOCKET sock = s_connections[connIdx].tcpSocket; + BYTE clientSmallId = s_connections[connIdx].smallId; + LeaveCriticalSection(&s_connectionsLock); + + BYTE *recvBuf = new BYTE[WIN64_NET_RECV_BUFFER_SIZE]; + + while (s_active) + { + BYTE header[4]; + if (!RecvExact(sock, header, 4)) + { + app.DebugPrintf("Win64 LAN: Client smallId=%d disconnected (header)\n", clientSmallId); + break; + } + + int packetSize = (header[0] << 24) | (header[1] << 16) | (header[2] << 8) | header[3]; + + if (packetSize <= 0 || packetSize > WIN64_NET_RECV_BUFFER_SIZE) + { + app.DebugPrintf("Win64 LAN: Invalid packet size %d from client smallId=%d\n", packetSize, clientSmallId); + break; + } + + if (!RecvExact(sock, recvBuf, packetSize)) + { + app.DebugPrintf("Win64 LAN: Client smallId=%d disconnected (body)\n", clientSmallId); + break; + } + + HandleDataReceived(clientSmallId, s_hostSmallId, recvBuf, packetSize); + } + + delete[] recvBuf; + + EnterCriticalSection(&s_connectionsLock); + for (size_t i = 0; i < s_connections.size(); i++) + { + if (s_connections[i].smallId == clientSmallId) + { + s_connections[i].active = false; + closesocket(s_connections[i].tcpSocket); + s_connections[i].tcpSocket = INVALID_SOCKET; + break; + } + } + LeaveCriticalSection(&s_connectionsLock); + + EnterCriticalSection(&s_disconnectLock); + s_disconnectedSmallIds.push_back(clientSmallId); + LeaveCriticalSection(&s_disconnectLock); + + return 0; +} + +bool WinsockNetLayer::PopDisconnectedSmallId(BYTE *outSmallId) +{ + bool found = false; + EnterCriticalSection(&s_disconnectLock); + if (!s_disconnectedSmallIds.empty()) + { + *outSmallId = s_disconnectedSmallIds.back(); + s_disconnectedSmallIds.pop_back(); + found = true; + } + LeaveCriticalSection(&s_disconnectLock); + return found; +} + +void WinsockNetLayer::PushFreeSmallId(BYTE smallId) +{ + EnterCriticalSection(&s_freeSmallIdLock); + s_freeSmallIds.push_back(smallId); + LeaveCriticalSection(&s_freeSmallIdLock); +} + +DWORD WINAPI WinsockNetLayer::ClientRecvThreadProc(LPVOID param) +{ + BYTE *recvBuf = new BYTE[WIN64_NET_RECV_BUFFER_SIZE]; + + while (s_active && s_hostConnectionSocket != INVALID_SOCKET) + { + BYTE header[4]; + if (!RecvExact(s_hostConnectionSocket, header, 4)) + { + app.DebugPrintf("Win64 LAN: Disconnected from host (header)\n"); + break; + } + + int packetSize = (header[0] << 24) | (header[1] << 16) | (header[2] << 8) | header[3]; + + if (packetSize <= 0 || packetSize > WIN64_NET_RECV_BUFFER_SIZE) + { + app.DebugPrintf("Win64 LAN: Invalid packet size %d from host\n", packetSize); + break; + } + + if (!RecvExact(s_hostConnectionSocket, recvBuf, packetSize)) + { + app.DebugPrintf("Win64 LAN: Disconnected from host (body)\n"); + break; + } + + HandleDataReceived(s_hostSmallId, s_localSmallId, recvBuf, packetSize); + } + + delete[] recvBuf; + + s_connected = false; + return 0; +} + +bool WinsockNetLayer::StartAdvertising(int gamePort, const wchar_t *hostName, unsigned int gameSettings, unsigned int texPackId, unsigned char subTexId, unsigned short netVer) +{ + if (s_advertising) return true; + if (!s_initialized) return false; + + EnterCriticalSection(&s_advertiseLock); + memset(&s_advertiseData, 0, sizeof(s_advertiseData)); + s_advertiseData.magic = WIN64_LAN_BROADCAST_MAGIC; + s_advertiseData.netVersion = netVer; + s_advertiseData.gamePort = (WORD)gamePort; + wcsncpy_s(s_advertiseData.hostName, 32, hostName, _TRUNCATE); + s_advertiseData.playerCount = 1; + s_advertiseData.maxPlayers = MINECRAFT_NET_MAX_PLAYERS; + s_advertiseData.gameHostSettings = gameSettings; + s_advertiseData.texturePackParentId = texPackId; + s_advertiseData.subTexturePackId = subTexId; + s_advertiseData.isJoinable = 0; + s_hostGamePort = gamePort; + LeaveCriticalSection(&s_advertiseLock); + + s_advertiseSock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); + if (s_advertiseSock == INVALID_SOCKET) + { + app.DebugPrintf("Win64 LAN: Failed to create advertise socket: %d\n", WSAGetLastError()); + return false; + } + + BOOL broadcast = TRUE; + setsockopt(s_advertiseSock, SOL_SOCKET, SO_BROADCAST, (const char *)&broadcast, sizeof(broadcast)); + + s_advertising = true; + s_advertiseThread = CreateThread(NULL, 0, AdvertiseThreadProc, NULL, 0, NULL); + + app.DebugPrintf("Win64 LAN: Started advertising on UDP port %d\n", WIN64_LAN_DISCOVERY_PORT); + return true; +} + +void WinsockNetLayer::StopAdvertising() +{ + s_advertising = false; + + if (s_advertiseSock != INVALID_SOCKET) + { + closesocket(s_advertiseSock); + s_advertiseSock = INVALID_SOCKET; + } + + if (s_advertiseThread != NULL) + { + WaitForSingleObject(s_advertiseThread, 2000); + CloseHandle(s_advertiseThread); + s_advertiseThread = NULL; + } +} + +void WinsockNetLayer::UpdateAdvertisePlayerCount(BYTE count) +{ + EnterCriticalSection(&s_advertiseLock); + s_advertiseData.playerCount = count; + LeaveCriticalSection(&s_advertiseLock); +} + +void WinsockNetLayer::UpdateAdvertiseJoinable(bool joinable) +{ + EnterCriticalSection(&s_advertiseLock); + s_advertiseData.isJoinable = joinable ? 1 : 0; + LeaveCriticalSection(&s_advertiseLock); +} + +DWORD WINAPI WinsockNetLayer::AdvertiseThreadProc(LPVOID param) +{ + struct sockaddr_in broadcastAddr; + memset(&broadcastAddr, 0, sizeof(broadcastAddr)); + broadcastAddr.sin_family = AF_INET; + broadcastAddr.sin_port = htons(WIN64_LAN_DISCOVERY_PORT); + broadcastAddr.sin_addr.s_addr = INADDR_BROADCAST; + + while (s_advertising) + { + EnterCriticalSection(&s_advertiseLock); + Win64LANBroadcast data = s_advertiseData; + LeaveCriticalSection(&s_advertiseLock); + + int sent = sendto(s_advertiseSock, (const char *)&data, sizeof(data), 0, + (struct sockaddr *)&broadcastAddr, sizeof(broadcastAddr)); + + if (sent == SOCKET_ERROR && s_advertising) + { + app.DebugPrintf("Win64 LAN: Broadcast sendto failed: %d\n", WSAGetLastError()); + } + + Sleep(1000); + } + + return 0; +} + +bool WinsockNetLayer::StartDiscovery() +{ + if (s_discovering) return true; + if (!s_initialized) return false; + + s_discoverySock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); + if (s_discoverySock == INVALID_SOCKET) + { + app.DebugPrintf("Win64 LAN: Failed to create discovery socket: %d\n", WSAGetLastError()); + return false; + } + + BOOL reuseAddr = TRUE; + setsockopt(s_discoverySock, SOL_SOCKET, SO_REUSEADDR, (const char *)&reuseAddr, sizeof(reuseAddr)); + + struct sockaddr_in bindAddr; + memset(&bindAddr, 0, sizeof(bindAddr)); + bindAddr.sin_family = AF_INET; + bindAddr.sin_port = htons(WIN64_LAN_DISCOVERY_PORT); + bindAddr.sin_addr.s_addr = INADDR_ANY; + + if (::bind(s_discoverySock, (struct sockaddr *)&bindAddr, sizeof(bindAddr)) == SOCKET_ERROR) + { + app.DebugPrintf("Win64 LAN: Discovery bind failed: %d\n", WSAGetLastError()); + closesocket(s_discoverySock); + s_discoverySock = INVALID_SOCKET; + return false; + } + + DWORD timeout = 500; + setsockopt(s_discoverySock, SOL_SOCKET, SO_RCVTIMEO, (const char *)&timeout, sizeof(timeout)); + + s_discovering = true; + s_discoveryThread = CreateThread(NULL, 0, DiscoveryThreadProc, NULL, 0, NULL); + + app.DebugPrintf("Win64 LAN: Listening for LAN games on UDP port %d\n", WIN64_LAN_DISCOVERY_PORT); + return true; +} + +void WinsockNetLayer::StopDiscovery() +{ + s_discovering = false; + + if (s_discoverySock != INVALID_SOCKET) + { + closesocket(s_discoverySock); + s_discoverySock = INVALID_SOCKET; + } + + if (s_discoveryThread != NULL) + { + WaitForSingleObject(s_discoveryThread, 2000); + CloseHandle(s_discoveryThread); + s_discoveryThread = NULL; + } + + EnterCriticalSection(&s_discoveryLock); + s_discoveredSessions.clear(); + LeaveCriticalSection(&s_discoveryLock); +} + +std::vector WinsockNetLayer::GetDiscoveredSessions() +{ + std::vector result; + EnterCriticalSection(&s_discoveryLock); + result = s_discoveredSessions; + LeaveCriticalSection(&s_discoveryLock); + return result; +} + +DWORD WINAPI WinsockNetLayer::DiscoveryThreadProc(LPVOID param) +{ + char recvBuf[512]; + + while (s_discovering) + { + struct sockaddr_in senderAddr; + int senderLen = sizeof(senderAddr); + + int recvLen = recvfrom(s_discoverySock, recvBuf, sizeof(recvBuf), 0, + (struct sockaddr *)&senderAddr, &senderLen); + + if (recvLen == SOCKET_ERROR) + { + continue; + } + + if (recvLen < (int)sizeof(Win64LANBroadcast)) + continue; + + Win64LANBroadcast *broadcast = (Win64LANBroadcast *)recvBuf; + if (broadcast->magic != WIN64_LAN_BROADCAST_MAGIC) + continue; + + char senderIP[64]; + inet_ntop(AF_INET, &senderAddr.sin_addr, senderIP, sizeof(senderIP)); + + DWORD now = GetTickCount(); + + EnterCriticalSection(&s_discoveryLock); + + bool found = false; + for (size_t i = 0; i < s_discoveredSessions.size(); i++) + { + if (strcmp(s_discoveredSessions[i].hostIP, senderIP) == 0 && + s_discoveredSessions[i].hostPort == (int)broadcast->gamePort) + { + s_discoveredSessions[i].netVersion = broadcast->netVersion; + wcsncpy_s(s_discoveredSessions[i].hostName, 32, broadcast->hostName, _TRUNCATE); + s_discoveredSessions[i].playerCount = broadcast->playerCount; + s_discoveredSessions[i].maxPlayers = broadcast->maxPlayers; + s_discoveredSessions[i].gameHostSettings = broadcast->gameHostSettings; + s_discoveredSessions[i].texturePackParentId = broadcast->texturePackParentId; + s_discoveredSessions[i].subTexturePackId = broadcast->subTexturePackId; + s_discoveredSessions[i].isJoinable = (broadcast->isJoinable != 0); + s_discoveredSessions[i].lastSeenTick = now; + found = true; + break; + } + } + + if (!found) + { + Win64LANSession session; + memset(&session, 0, sizeof(session)); + strncpy_s(session.hostIP, sizeof(session.hostIP), senderIP, _TRUNCATE); + session.hostPort = (int)broadcast->gamePort; + session.netVersion = broadcast->netVersion; + wcsncpy_s(session.hostName, 32, broadcast->hostName, _TRUNCATE); + session.playerCount = broadcast->playerCount; + session.maxPlayers = broadcast->maxPlayers; + session.gameHostSettings = broadcast->gameHostSettings; + session.texturePackParentId = broadcast->texturePackParentId; + session.subTexturePackId = broadcast->subTexturePackId; + session.isJoinable = (broadcast->isJoinable != 0); + session.lastSeenTick = now; + s_discoveredSessions.push_back(session); + + app.DebugPrintf("Win64 LAN: Discovered game \"%ls\" at %s:%d\n", + session.hostName, session.hostIP, session.hostPort); + } + + for (size_t i = s_discoveredSessions.size(); i > 0; i--) + { + if (now - s_discoveredSessions[i - 1].lastSeenTick > 5000) + { + app.DebugPrintf("Win64 LAN: Session \"%ls\" at %s timed out\n", + s_discoveredSessions[i - 1].hostName, s_discoveredSessions[i - 1].hostIP); + s_discoveredSessions.erase(s_discoveredSessions.begin() + (i - 1)); + } + } + + LeaveCriticalSection(&s_discoveryLock); + } + + return 0; +} + +#endif diff --git a/Minecraft.Client/Windows64/Network/WinsockNetLayer.h b/Minecraft.Client/Windows64/Network/WinsockNetLayer.h new file mode 100644 index 00000000..96b03c9b --- /dev/null +++ b/Minecraft.Client/Windows64/Network/WinsockNetLayer.h @@ -0,0 +1,147 @@ +#pragma once + +#ifdef _WINDOWS64 + +#include +#include +#include +#include "..\..\Common\Network\NetworkPlayerInterface.h" + +#pragma comment(lib, "Ws2_32.lib") + +#define WIN64_NET_DEFAULT_PORT 25565 +#define WIN64_NET_MAX_CLIENTS 7 +#define WIN64_NET_RECV_BUFFER_SIZE 65536 +#define WIN64_LAN_DISCOVERY_PORT 25566 +#define WIN64_LAN_BROADCAST_MAGIC 0x4D434C4E + +class Socket; + +#pragma pack(push, 1) +struct Win64LANBroadcast +{ + DWORD magic; + WORD netVersion; + WORD gamePort; + wchar_t hostName[32]; + BYTE playerCount; + BYTE maxPlayers; + DWORD gameHostSettings; + DWORD texturePackParentId; + BYTE subTexturePackId; + BYTE isJoinable; +}; +#pragma pack(pop) + +struct Win64LANSession +{ + char hostIP[64]; + int hostPort; + wchar_t hostName[32]; + unsigned short netVersion; + unsigned char playerCount; + unsigned char maxPlayers; + unsigned int gameHostSettings; + unsigned int texturePackParentId; + unsigned char subTexturePackId; + bool isJoinable; + DWORD lastSeenTick; +}; + +struct Win64RemoteConnection +{ + SOCKET tcpSocket; + BYTE smallId; + HANDLE recvThread; + volatile bool active; +}; + +class WinsockNetLayer +{ +public: + static bool Initialize(); + static void Shutdown(); + + static bool HostGame(int port); + static bool JoinGame(const char *ip, int port); + + static bool SendToSmallId(BYTE targetSmallId, const void *data, int dataSize); + static bool SendOnSocket(SOCKET sock, const void *data, int dataSize); + + static bool IsHosting() { return s_isHost; } + static bool IsConnected() { return s_connected; } + static bool IsActive() { return s_active; } + + static BYTE GetLocalSmallId() { return s_localSmallId; } + static BYTE GetHostSmallId() { return s_hostSmallId; } + + static SOCKET GetSocketForSmallId(BYTE smallId); + + static void HandleDataReceived(BYTE fromSmallId, BYTE toSmallId, unsigned char *data, unsigned int dataSize); + + static bool PopDisconnectedSmallId(BYTE *outSmallId); + static void PushFreeSmallId(BYTE smallId); + + static bool StartAdvertising(int gamePort, const wchar_t *hostName, unsigned int gameSettings, unsigned int texPackId, unsigned char subTexId, unsigned short netVer); + static void StopAdvertising(); + static void UpdateAdvertisePlayerCount(BYTE count); + static void UpdateAdvertiseJoinable(bool joinable); + + static bool StartDiscovery(); + static void StopDiscovery(); + static std::vector GetDiscoveredSessions(); + + static int GetHostPort() { return s_hostGamePort; } + +private: + static DWORD WINAPI AcceptThreadProc(LPVOID param); + static DWORD WINAPI RecvThreadProc(LPVOID param); + static DWORD WINAPI ClientRecvThreadProc(LPVOID param); + static DWORD WINAPI AdvertiseThreadProc(LPVOID param); + static DWORD WINAPI DiscoveryThreadProc(LPVOID param); + + static SOCKET s_listenSocket; + static SOCKET s_hostConnectionSocket; + static HANDLE s_acceptThread; + static HANDLE s_clientRecvThread; + + static bool s_isHost; + static bool s_connected; + static bool s_active; + static bool s_initialized; + + static BYTE s_localSmallId; + static BYTE s_hostSmallId; + static BYTE s_nextSmallId; + + static CRITICAL_SECTION s_sendLock; + static CRITICAL_SECTION s_connectionsLock; + + static std::vector s_connections; + + static SOCKET s_advertiseSock; + static HANDLE s_advertiseThread; + static volatile bool s_advertising; + static Win64LANBroadcast s_advertiseData; + static CRITICAL_SECTION s_advertiseLock; + static int s_hostGamePort; + + static SOCKET s_discoverySock; + static HANDLE s_discoveryThread; + static volatile bool s_discovering; + static CRITICAL_SECTION s_discoveryLock; + static std::vector s_discoveredSessions; + + static CRITICAL_SECTION s_disconnectLock; + static std::vector s_disconnectedSmallIds; + + static CRITICAL_SECTION s_freeSmallIdLock; + static std::vector s_freeSmallIds; +}; + +extern bool g_Win64MultiplayerHost; +extern bool g_Win64MultiplayerJoin; +extern int g_Win64MultiplayerPort; +extern char g_Win64MultiplayerIP[256]; + +#endif diff --git a/Minecraft.Client/Windows64/Windows64_App.cpp b/Minecraft.Client/Windows64/Windows64_App.cpp index bba33cad..dbc1bfc5 100644 --- a/Minecraft.Client/Windows64/Windows64_App.cpp +++ b/Minecraft.Client/Windows64/Windows64_App.cpp @@ -57,7 +57,8 @@ void CConsoleMinecraftApp::TemporaryCreateGameStart() Minecraft *pMinecraft=Minecraft::GetInstance(); app.ReleaseSaveThumbnail(); ProfileManager.SetLockedProfile(0); - pMinecraft->user->name = L"Windows"; + extern wchar_t g_Win64UsernameW[17]; + pMinecraft->user->name = g_Win64UsernameW; app.ApplyGameSettingsChanged(0); ////////////////////////////////////////////////////////////////////////////////////////////// From CScene_MultiGameJoinLoad::OnInit diff --git a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp index 95c10a2b..5bd1a546 100644 --- a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp +++ b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp @@ -37,6 +37,7 @@ #include "Resource.h" #include "..\..\Minecraft.World\compression.h" #include "..\..\Minecraft.World\OldChunkStorage.h" +#include "Network\WinsockNetLayer.h" #include "Xbox/resource.h" @@ -84,6 +85,8 @@ 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; @@ -850,8 +853,41 @@ 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); @@ -1017,7 +1053,17 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, // ProfileManager for XN_LIVE_INVITE_ACCEPTED for QNet. g_NetworkManager.Initialise(); + for (int i = 0; i < MINECRAFT_NET_MAX_PLAYERS; i++) + { + IQNet::m_player[i].m_smallId = (BYTE)i; + IQNet::m_player[i].m_isRemote = false; + 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(); // 4J-PB moved further down //app.InitGameSettings(); @@ -1189,7 +1235,7 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, PIXEndNamedEvent(); PIXBeginNamedEvent(0,"Network manager do work #1"); - // g_NetworkManager.DoWork(); + g_NetworkManager.DoWork(); PIXEndNamedEvent(); // LeaderboardManager::Instance()->Tick(); diff --git a/Minecraft.World/x64headers/extraX64.h b/Minecraft.World/x64headers/extraX64.h index 2205ae05..b89998ac 100644 --- a/Minecraft.World/x64headers/extraX64.h +++ b/Minecraft.World/x64headers/extraX64.h @@ -215,10 +215,17 @@ public: int GetUserIndex(); void SetCustomDataValue(ULONG_PTR ulpCustomDataValue); ULONG_PTR GetCustomDataValue(); + + BYTE m_smallId; + bool m_isRemote; + bool m_isHostPlayer; + wchar_t m_gamertag[32]; private: ULONG_PTR m_customData; }; +void Win64_SetupRemoteQNetPlayer(IQNetPlayer* player, BYTE smallId, bool isHost, bool isLocal); + const int QNET_GETSENDQUEUESIZE_SECONDARY_TYPE = 0; const int QNET_GETSENDQUEUESIZE_MESSAGES = 0; const int QNET_GETSENDQUEUESIZE_BYTES = 0; @@ -309,9 +316,12 @@ public: bool IsHost(); HRESULT JoinGameFromInviteInfo(DWORD dwUserIndex, DWORD dwUserMask, const INVITE_INFO *pInviteInfo); void HostGame(); - void EndGame(); + void ClientJoinGame(); + void EndGame(); - static IQNetPlayer m_player[4]; + static IQNetPlayer m_player[MINECRAFT_NET_MAX_PLAYERS]; + static DWORD s_playerCount; + static bool s_isHosting; }; #ifdef _DURANGO diff --git a/README.md b/README.md index 69038ef7..b1178d7a 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ This project contains the source code of Minecraft Legacy Console Edition v1.6.0 - Disabled V-Sync for better performance - Added a high-resolution timer path on Windows for smoother high-FPS gameplay timing - Device's screen resolution will be used as the game resolution instead of using a fixed resolution (1920x1080) +- LAN Multiplayer & Discovery based on https://github.com/LCEMP/LCEMP/ ## Controls (Keyboard & Mouse) -- cgit v1.2.3 From b8a7f816b52775fdcfb3503f0000accb8cd65765 Mon Sep 17 00:00:00 2001 From: dtentiion Date: Mon, 2 Mar 2026 23:50:45 +0000 Subject: Win64: configurable username (username.txt) and persistent game settings (settings.dat) (#195) --- Minecraft.Client/Common/Consoles_App.cpp | 45 +++++++++++++++++ Minecraft.Client/Extrax64Stubs.cpp | 9 ++-- Minecraft.Client/Windows64/Windows64_App.cpp | 57 +++++++++++++++++++++- Minecraft.Client/Windows64/Windows64_App.h | 2 + Minecraft.Client/Windows64/Windows64_Minecraft.cpp | 27 +++++++++- 5 files changed, 132 insertions(+), 8 deletions(-) (limited to 'Minecraft.Client/Windows64/Windows64_Minecraft.cpp') diff --git a/Minecraft.Client/Common/Consoles_App.cpp b/Minecraft.Client/Common/Consoles_App.cpp index 0e02ab40..b476ca90 100644 --- a/Minecraft.Client/Common/Consoles_App.cpp +++ b/Minecraft.Client/Common/Consoles_App.cpp @@ -760,6 +760,43 @@ bool CMinecraftApp::LoadBeaconMenu(int iPad ,shared_ptr inventory, sh ////////////////////////////////////////////// // GAME SETTINGS ////////////////////////////////////////////// + +#ifdef _WINDOWS64 +static void Win64_GetSettingsPath(char *outPath, DWORD size) +{ + GetModuleFileNameA(NULL, outPath, size); + char *lastSlash = strrchr(outPath, '\\'); + if (lastSlash) *(lastSlash + 1) = '\0'; + strncat_s(outPath, size, "settings.dat", _TRUNCATE); +} +static void Win64_SaveSettings(GAME_SETTINGS *gs) +{ + if (!gs) return; + char filePath[MAX_PATH] = {}; + Win64_GetSettingsPath(filePath, MAX_PATH); + FILE *f = NULL; + if (fopen_s(&f, filePath, "wb") == 0 && f) + { + fwrite(gs, sizeof(GAME_SETTINGS), 1, f); + fclose(f); + } +} +static void Win64_LoadSettings(GAME_SETTINGS *gs) +{ + if (!gs) return; + char filePath[MAX_PATH] = {}; + Win64_GetSettingsPath(filePath, MAX_PATH); + FILE *f = NULL; + if (fopen_s(&f, filePath, "rb") == 0 && f) + { + GAME_SETTINGS temp = {}; + if (fread(&temp, sizeof(GAME_SETTINGS), 1, f) == 1) + memcpy(gs, &temp, sizeof(GAME_SETTINGS)); + fclose(f); + } +} +#endif + void CMinecraftApp::InitGameSettings() { for(int i=0;ibSettingsChanged=false; } @@ -2385,6 +2427,9 @@ void CMinecraftApp::CheckGameSettingsChanged(bool bOverride5MinuteTimer, int iPa StorageManager.WriteToProfile(iPad,true, bOverride5MinuteTimer); #else ProfileManager.WriteToProfile(iPad,true, bOverride5MinuteTimer); +#ifdef _WINDOWS64 + Win64_SaveSettings(GameSettingsA[iPad]); +#endif #endif GameSettingsA[iPad]->bSettingsChanged=false; } diff --git a/Minecraft.Client/Extrax64Stubs.cpp b/Minecraft.Client/Extrax64Stubs.cpp index f368afed..23b2c7f0 100644 --- a/Minecraft.Client/Extrax64Stubs.cpp +++ b/Minecraft.Client/Extrax64Stubs.cpp @@ -199,10 +199,11 @@ DWORD IQNetPlayer::GetSendQueueSize(IQNetPlayer * player, DWORD dwFlags) { retur 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); } -LPCWSTR IQNetPlayer::GetGamertag() { return m_gamertag; } -int IQNetPlayer::GetSessionIndex() { return m_smallId; } +bool IQNetPlayer::IsLocal() { return true; } +PlayerUID IQNetPlayer::GetXuid() { return INVALID_XUID; } +extern wstring g_playerName; +LPCWSTR IQNetPlayer::GetGamertag() { return g_playerName.empty() ? L"Windows" : g_playerName.c_str(); } +int IQNetPlayer::GetSessionIndex() { return 0; } bool IQNetPlayer::IsTalking() { return false; } bool IQNetPlayer::IsMutedByLocalUser(DWORD dwUserIndex) { return false; } bool IQNetPlayer::HasVoice() { return false; } diff --git a/Minecraft.Client/Windows64/Windows64_App.cpp b/Minecraft.Client/Windows64/Windows64_App.cpp index dbc1bfc5..461e8c34 100644 --- a/Minecraft.Client/Windows64/Windows64_App.cpp +++ b/Minecraft.Client/Windows64/Windows64_App.cpp @@ -10,11 +10,46 @@ #include "..\..\Minecraft.World\BiomeSource.h" #include "..\..\Minecraft.World\LevelType.h" +wstring g_playerName; + CConsoleMinecraftApp app; +static void LoadPlayerName() +{ + if (!g_playerName.empty()) return; + g_playerName = L"Windows"; + + 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 = NULL; + 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) + { + wchar_t wbuf[128] = {}; + mbstowcs(wbuf, buf, 127); + g_playerName = wbuf; + } + } + fclose(f); + } +} + CConsoleMinecraftApp::CConsoleMinecraftApp() : CMinecraftApp() { m_bShutdown = false; + LoadPlayerName(); } void CConsoleMinecraftApp::SetRichPresenceContext(int iPad, int contextId) @@ -35,9 +70,27 @@ void CConsoleMinecraftApp::FatalLoadError() void CConsoleMinecraftApp::CaptureSaveThumbnail() { + RenderManager.CaptureThumbnail(&m_ThumbnailBuffer); } void CConsoleMinecraftApp::GetSaveThumbnail(PBYTE *pbData,DWORD *pdwSize) { + // On a save caused by a create world, the thumbnail capture won't have happened + if (m_ThumbnailBuffer.Allocated()) + { + if (pbData) + { + *pbData = new BYTE[m_ThumbnailBuffer.GetBufferSize()]; + *pdwSize = m_ThumbnailBuffer.GetBufferSize(); + memcpy(*pbData, m_ThumbnailBuffer.GetBufferPointer(), *pdwSize); + } + m_ThumbnailBuffer.Release(); + } + else + { + // No capture happened (e.g. first save on world creation) leave thumbnail as NULL + if (pbData) *pbData = NULL; + if (pdwSize) *pdwSize = 0; + } } void CConsoleMinecraftApp::ReleaseSaveThumbnail() { @@ -57,8 +110,8 @@ void CConsoleMinecraftApp::TemporaryCreateGameStart() Minecraft *pMinecraft=Minecraft::GetInstance(); app.ReleaseSaveThumbnail(); ProfileManager.SetLockedProfile(0); - extern wchar_t g_Win64UsernameW[17]; - pMinecraft->user->name = g_Win64UsernameW; + LoadPlayerName(); + pMinecraft->user->name = g_playerName; app.ApplyGameSettingsChanged(0); ////////////////////////////////////////////////////////////////////////////////////////////// From CScene_MultiGameJoinLoad::OnInit diff --git a/Minecraft.Client/Windows64/Windows64_App.h b/Minecraft.Client/Windows64/Windows64_App.h index de8f6d85..bff916ec 100644 --- a/Minecraft.Client/Windows64/Windows64_App.h +++ b/Minecraft.Client/Windows64/Windows64_App.h @@ -1,7 +1,9 @@ #pragma once +#include "4JLibs\inc\4J_Render.h" class CConsoleMinecraftApp : public CMinecraftApp { + ImageFileBuffer m_ThumbnailBuffer; public: CConsoleMinecraftApp(); diff --git a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp index 5bd1a546..a1bdcd0f 100644 --- a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp +++ b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp @@ -827,7 +827,16 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); - dyn_SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE); + // 4J-Win64: set CWD to exe dir so asset paths resolve correctly + { + char szExeDir[MAX_PATH] = {}; + GetModuleFileNameA(NULL, szExeDir, MAX_PATH); + char *pSlash = strrchr(szExeDir, '\\'); + if (pSlash) { *(pSlash + 1) = '\0'; SetCurrentDirectoryA(szExeDir); } + } + + // Declare DPI awareness so GetSystemMetrics returns physical pixels + SetProcessDPIAware(); g_iScreenWidth = GetSystemMetrics(SM_CXSCREEN); g_iScreenHeight = GetSystemMetrics(SM_CYSCREEN); @@ -1361,7 +1370,21 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, } } - // F11 toggles fullscreen + // F3 toggles the debug console overlay, F11 toggles fullscreen + if (KMInput.IsKeyPressed(VK_F3)) + { + static bool s_debugConsole = false; + s_debugConsole = !s_debugConsole; + ui.ShowUIDebugConsole(s_debugConsole); + } + +#ifdef _DEBUG_MENUS_ENABLED + if (KMInput.IsKeyPressed(VK_F4)) + { + ui.NavigateToScene(ProfileManager.GetPrimaryPad(), eUIScene_DebugOverlay, NULL, eUILayer_Debug); + } +#endif + if (KMInput.IsKeyPressed(VK_F11)) { ToggleFullscreen(); -- cgit v1.2.3 From dea460381fd80af44d1d84ec6444a056000a3365 Mon Sep 17 00:00:00 2001 From: void_17 Date: Tue, 3 Mar 2026 07:00:55 +0700 Subject: Remove dyn_SetProcessDpiAwareness --- Minecraft.Client/Windows64/Windows64_Minecraft.cpp | 14 -------------- 1 file changed, 14 deletions(-) (limited to 'Minecraft.Client/Windows64/Windows64_Minecraft.cpp') diff --git a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp index a1bdcd0f..52939930 100644 --- a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp +++ b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp @@ -805,20 +805,6 @@ void CleanupDevice() if( g_pd3dDevice ) g_pd3dDevice->Release(); } -typedef HRESULT(__stdcall* SetProcessDpiAwareness_f)(PROCESS_DPI_AWARENESS); -static HRESULT dyn_SetProcessDpiAwareness(PROCESS_DPI_AWARENESS value) -{ - static const auto ptr = reinterpret_cast( - reinterpret_cast(::GetProcAddress(static_cast(LoadLibraryExW(L"Shcore.dll", nullptr, 0)), "SetProcessDpiAwareness"))); - if (ptr == nullptr) - { - SetLastError(ERROR_CALL_NOT_IMPLEMENTED); - return E_NOTIMPL; - } - - return ptr(value); -} - int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPTSTR lpCmdLine, -- cgit v1.2.3 From a5e3cb04b3fa2dba86fbb3ff84e5354ad530c14c Mon Sep 17 00:00:00 2001 From: void_17 Date: Tue, 3 Mar 2026 08:45:26 +0700 Subject: Remove #203 core code before a cleaner implementation --- Minecraft.Client/Windows64/Windows64_Minecraft.cpp | 88 +--------------------- Minecraft.Client/glWrapper.cpp | 3 +- 2 files changed, 3 insertions(+), 88 deletions(-) (limited to 'Minecraft.Client/Windows64/Windows64_Minecraft.cpp') diff --git a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp index 52939930..48040c66 100644 --- a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp +++ b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp @@ -431,90 +431,6 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) return TRUE; } return DefWindowProc(hWnd, message, wParam, lParam); - case WM_SIZE: - { - if (wParam == SIZE_MINIMIZED) - return 0; - - UINT width = LOWORD(lParam); - UINT height = HIWORD(lParam); - - if (width == 0 || height == 0) - return 0; - - g_ScreenWidth = width; - g_ScreenHeight = height; - - if (g_pSwapChain) - { - g_pImmediateContext->OMSetRenderTargets(0, 0, 0); - g_pImmediateContext->ClearState(); - g_pImmediateContext->Flush(); - - if (g_pRenderTargetView) - { - g_pRenderTargetView->Release(); - g_pRenderTargetView = nullptr; - } - - if (g_pDepthStencilView) - { - g_pDepthStencilView->Release(); - g_pDepthStencilView = nullptr; - } - - if (g_pDepthStencilBuffer) - { - g_pDepthStencilBuffer->Release(); - g_pDepthStencilBuffer = nullptr; - } - - HRESULT hr = g_pSwapChain->ResizeBuffers( - 0, - width, - height, - DXGI_FORMAT_UNKNOWN, - 0 - ); - - if (FAILED(hr)) - { - app.DebugPrintf("ResizeBuffers Failed! HRESULT: 0x%X\n", hr); - return 0; - } - - ID3D11Texture2D* pBackBuffer = nullptr; - g_pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (void**)&pBackBuffer); - - g_pd3dDevice->CreateRenderTargetView(pBackBuffer, NULL, &g_pRenderTargetView); - pBackBuffer->Release(); - - D3D11_TEXTURE2D_DESC descDepth = {}; - descDepth.Width = width; - descDepth.Height = height; - descDepth.MipLevels = 1; - descDepth.ArraySize = 1; - descDepth.Format = DXGI_FORMAT_D24_UNORM_S8_UINT; - descDepth.SampleDesc.Count = 1; - descDepth.BindFlags = D3D11_BIND_DEPTH_STENCIL; - - g_pd3dDevice->CreateTexture2D(&descDepth, NULL, &g_pDepthStencilBuffer); - g_pd3dDevice->CreateDepthStencilView(g_pDepthStencilBuffer, NULL, &g_pDepthStencilView); - - g_pImmediateContext->OMSetRenderTargets(1, &g_pRenderTargetView, g_pDepthStencilView); - - D3D11_VIEWPORT vp = {}; - vp.Width = (FLOAT)width; - vp.Height = (FLOAT)height; - vp.MinDepth = 0.0f; - vp.MaxDepth = 1.0f; - vp.TopLeftX = 0; - vp.TopLeftY = 0; - - g_pImmediateContext->RSSetViewports(1, &vp); - } - } - break; default: return DefWindowProc(hWnd, message, wParam, lParam); } @@ -1383,7 +1299,7 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, { { ui.NavigateToScene(0, eUIScene_InGameInfoMenu); - + } } } @@ -1406,7 +1322,7 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, { if (Minecraft* pMinecraft = Minecraft::GetInstance()) { - if (pMinecraft->options && app.DebugSettingsOn() && + if (pMinecraft->options && app.DebugSettingsOn() && app.GetGameStarted() && !ui.GetMenuDisplayed(0) && pMinecraft->screen == NULL) { ui.NavigateToScene(0, eUIScene_DebugOverlay, NULL, eUILayer_Debug); diff --git a/Minecraft.Client/glWrapper.cpp b/Minecraft.Client/glWrapper.cpp index 5e0fab2c..93b13d40 100644 --- a/Minecraft.Client/glWrapper.cpp +++ b/Minecraft.Client/glWrapper.cpp @@ -53,8 +53,7 @@ extern UINT g_ScreenHeight; void gluPerspective(float fovy, float aspect, float zNear, float zFar) { - float dynamicAspect = (float)g_ScreenWidth / (float)g_ScreenHeight; - RenderManager.MatrixPerspective(fovy, dynamicAspect, zNear, zFar); + RenderManager.MatrixPerspective(fovy,aspect,zNear,zFar); } void glOrtho(float left,float right,float bottom,float top,float zNear,float zFar) -- cgit v1.2.3 From 7f7d99501cf87fcc234a5d3af453e7e0642f96a3 Mon Sep 17 00:00:00 2001 From: void_17 <61356189+void2012@users.noreply.github.com> Date: Tue, 3 Mar 2026 10:23:28 +0700 Subject: Revert "Win64: configurable username (username.txt) and persistent game setti…" (#234) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit b8a7f816b52775fdcfb3503f0000accb8cd65765. --- Minecraft.Client/Common/Consoles_App.cpp | 45 ----------------- Minecraft.Client/Extrax64Stubs.cpp | 9 ++-- Minecraft.Client/Windows64/Windows64_App.cpp | 57 +--------------------- Minecraft.Client/Windows64/Windows64_App.h | 2 - Minecraft.Client/Windows64/Windows64_Minecraft.cpp | 27 +--------- 5 files changed, 8 insertions(+), 132 deletions(-) (limited to 'Minecraft.Client/Windows64/Windows64_Minecraft.cpp') diff --git a/Minecraft.Client/Common/Consoles_App.cpp b/Minecraft.Client/Common/Consoles_App.cpp index b476ca90..0e02ab40 100644 --- a/Minecraft.Client/Common/Consoles_App.cpp +++ b/Minecraft.Client/Common/Consoles_App.cpp @@ -760,43 +760,6 @@ bool CMinecraftApp::LoadBeaconMenu(int iPad ,shared_ptr inventory, sh ////////////////////////////////////////////// // GAME SETTINGS ////////////////////////////////////////////// - -#ifdef _WINDOWS64 -static void Win64_GetSettingsPath(char *outPath, DWORD size) -{ - GetModuleFileNameA(NULL, outPath, size); - char *lastSlash = strrchr(outPath, '\\'); - if (lastSlash) *(lastSlash + 1) = '\0'; - strncat_s(outPath, size, "settings.dat", _TRUNCATE); -} -static void Win64_SaveSettings(GAME_SETTINGS *gs) -{ - if (!gs) return; - char filePath[MAX_PATH] = {}; - Win64_GetSettingsPath(filePath, MAX_PATH); - FILE *f = NULL; - if (fopen_s(&f, filePath, "wb") == 0 && f) - { - fwrite(gs, sizeof(GAME_SETTINGS), 1, f); - fclose(f); - } -} -static void Win64_LoadSettings(GAME_SETTINGS *gs) -{ - if (!gs) return; - char filePath[MAX_PATH] = {}; - Win64_GetSettingsPath(filePath, MAX_PATH); - FILE *f = NULL; - if (fopen_s(&f, filePath, "rb") == 0 && f) - { - GAME_SETTINGS temp = {}; - if (fread(&temp, sizeof(GAME_SETTINGS), 1, f) == 1) - memcpy(gs, &temp, sizeof(GAME_SETTINGS)); - fclose(f); - } -} -#endif - void CMinecraftApp::InitGameSettings() { for(int i=0;ibSettingsChanged=false; } @@ -2427,9 +2385,6 @@ void CMinecraftApp::CheckGameSettingsChanged(bool bOverride5MinuteTimer, int iPa StorageManager.WriteToProfile(iPad,true, bOverride5MinuteTimer); #else ProfileManager.WriteToProfile(iPad,true, bOverride5MinuteTimer); -#ifdef _WINDOWS64 - Win64_SaveSettings(GameSettingsA[iPad]); -#endif #endif GameSettingsA[iPad]->bSettingsChanged=false; } diff --git a/Minecraft.Client/Extrax64Stubs.cpp b/Minecraft.Client/Extrax64Stubs.cpp index 23b2c7f0..f368afed 100644 --- a/Minecraft.Client/Extrax64Stubs.cpp +++ b/Minecraft.Client/Extrax64Stubs.cpp @@ -199,11 +199,10 @@ DWORD IQNetPlayer::GetSendQueueSize(IQNetPlayer * player, DWORD dwFlags) { retur DWORD IQNetPlayer::GetCurrentRtt() { return 0; } bool IQNetPlayer::IsHost() { return m_isHostPlayer; } bool IQNetPlayer::IsGuest() { return false; } -bool IQNetPlayer::IsLocal() { return true; } -PlayerUID IQNetPlayer::GetXuid() { return INVALID_XUID; } -extern wstring g_playerName; -LPCWSTR IQNetPlayer::GetGamertag() { return g_playerName.empty() ? L"Windows" : g_playerName.c_str(); } -int IQNetPlayer::GetSessionIndex() { return 0; } +bool IQNetPlayer::IsLocal() { return !m_isRemote; } +PlayerUID IQNetPlayer::GetXuid() { return (PlayerUID)(0xe000d45248242f2e + m_smallId); } +LPCWSTR IQNetPlayer::GetGamertag() { return m_gamertag; } +int IQNetPlayer::GetSessionIndex() { return m_smallId; } bool IQNetPlayer::IsTalking() { return false; } bool IQNetPlayer::IsMutedByLocalUser(DWORD dwUserIndex) { return false; } bool IQNetPlayer::HasVoice() { return false; } diff --git a/Minecraft.Client/Windows64/Windows64_App.cpp b/Minecraft.Client/Windows64/Windows64_App.cpp index 461e8c34..dbc1bfc5 100644 --- a/Minecraft.Client/Windows64/Windows64_App.cpp +++ b/Minecraft.Client/Windows64/Windows64_App.cpp @@ -10,46 +10,11 @@ #include "..\..\Minecraft.World\BiomeSource.h" #include "..\..\Minecraft.World\LevelType.h" -wstring g_playerName; - CConsoleMinecraftApp app; -static void LoadPlayerName() -{ - if (!g_playerName.empty()) return; - g_playerName = L"Windows"; - - 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 = NULL; - 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) - { - wchar_t wbuf[128] = {}; - mbstowcs(wbuf, buf, 127); - g_playerName = wbuf; - } - } - fclose(f); - } -} - CConsoleMinecraftApp::CConsoleMinecraftApp() : CMinecraftApp() { m_bShutdown = false; - LoadPlayerName(); } void CConsoleMinecraftApp::SetRichPresenceContext(int iPad, int contextId) @@ -70,27 +35,9 @@ void CConsoleMinecraftApp::FatalLoadError() void CConsoleMinecraftApp::CaptureSaveThumbnail() { - RenderManager.CaptureThumbnail(&m_ThumbnailBuffer); } void CConsoleMinecraftApp::GetSaveThumbnail(PBYTE *pbData,DWORD *pdwSize) { - // On a save caused by a create world, the thumbnail capture won't have happened - if (m_ThumbnailBuffer.Allocated()) - { - if (pbData) - { - *pbData = new BYTE[m_ThumbnailBuffer.GetBufferSize()]; - *pdwSize = m_ThumbnailBuffer.GetBufferSize(); - memcpy(*pbData, m_ThumbnailBuffer.GetBufferPointer(), *pdwSize); - } - m_ThumbnailBuffer.Release(); - } - else - { - // No capture happened (e.g. first save on world creation) leave thumbnail as NULL - if (pbData) *pbData = NULL; - if (pdwSize) *pdwSize = 0; - } } void CConsoleMinecraftApp::ReleaseSaveThumbnail() { @@ -110,8 +57,8 @@ void CConsoleMinecraftApp::TemporaryCreateGameStart() Minecraft *pMinecraft=Minecraft::GetInstance(); app.ReleaseSaveThumbnail(); ProfileManager.SetLockedProfile(0); - LoadPlayerName(); - pMinecraft->user->name = g_playerName; + extern wchar_t g_Win64UsernameW[17]; + pMinecraft->user->name = g_Win64UsernameW; app.ApplyGameSettingsChanged(0); ////////////////////////////////////////////////////////////////////////////////////////////// From CScene_MultiGameJoinLoad::OnInit diff --git a/Minecraft.Client/Windows64/Windows64_App.h b/Minecraft.Client/Windows64/Windows64_App.h index bff916ec..de8f6d85 100644 --- a/Minecraft.Client/Windows64/Windows64_App.h +++ b/Minecraft.Client/Windows64/Windows64_App.h @@ -1,9 +1,7 @@ #pragma once -#include "4JLibs\inc\4J_Render.h" class CConsoleMinecraftApp : public CMinecraftApp { - ImageFileBuffer m_ThumbnailBuffer; public: CConsoleMinecraftApp(); diff --git a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp index 48040c66..272b29bf 100644 --- a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp +++ b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp @@ -729,16 +729,7 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); - // 4J-Win64: set CWD to exe dir so asset paths resolve correctly - { - char szExeDir[MAX_PATH] = {}; - GetModuleFileNameA(NULL, szExeDir, MAX_PATH); - char *pSlash = strrchr(szExeDir, '\\'); - if (pSlash) { *(pSlash + 1) = '\0'; SetCurrentDirectoryA(szExeDir); } - } - - // Declare DPI awareness so GetSystemMetrics returns physical pixels - SetProcessDPIAware(); + dyn_SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE); g_iScreenWidth = GetSystemMetrics(SM_CXSCREEN); g_iScreenHeight = GetSystemMetrics(SM_CYSCREEN); @@ -1272,21 +1263,7 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, } } - // F3 toggles the debug console overlay, F11 toggles fullscreen - if (KMInput.IsKeyPressed(VK_F3)) - { - static bool s_debugConsole = false; - s_debugConsole = !s_debugConsole; - ui.ShowUIDebugConsole(s_debugConsole); - } - -#ifdef _DEBUG_MENUS_ENABLED - if (KMInput.IsKeyPressed(VK_F4)) - { - ui.NavigateToScene(ProfileManager.GetPrimaryPad(), eUIScene_DebugOverlay, NULL, eUILayer_Debug); - } -#endif - + // F11 toggles fullscreen if (KMInput.IsKeyPressed(VK_F11)) { ToggleFullscreen(); -- cgit v1.2.3 From b42a4a4e4d72f6dea0a243c77247f7b9e739f5eb Mon Sep 17 00:00:00 2001 From: void_17 <61356189+void2012@users.noreply.github.com> Date: Tue, 3 Mar 2026 10:31:09 +0700 Subject: Revert "Revert "Win64: configurable username (username.txt) and persistent ga…" (#235) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 7f7d99501cf87fcc234a5d3af453e7e0642f96a3. --- Minecraft.Client/Common/Consoles_App.cpp | 45 +++++++++++++++++ Minecraft.Client/Extrax64Stubs.cpp | 9 ++-- Minecraft.Client/Windows64/Windows64_App.cpp | 57 +++++++++++++++++++++- Minecraft.Client/Windows64/Windows64_App.h | 2 + Minecraft.Client/Windows64/Windows64_Minecraft.cpp | 27 +++++++++- 5 files changed, 132 insertions(+), 8 deletions(-) (limited to 'Minecraft.Client/Windows64/Windows64_Minecraft.cpp') diff --git a/Minecraft.Client/Common/Consoles_App.cpp b/Minecraft.Client/Common/Consoles_App.cpp index 0e02ab40..b476ca90 100644 --- a/Minecraft.Client/Common/Consoles_App.cpp +++ b/Minecraft.Client/Common/Consoles_App.cpp @@ -760,6 +760,43 @@ bool CMinecraftApp::LoadBeaconMenu(int iPad ,shared_ptr inventory, sh ////////////////////////////////////////////// // GAME SETTINGS ////////////////////////////////////////////// + +#ifdef _WINDOWS64 +static void Win64_GetSettingsPath(char *outPath, DWORD size) +{ + GetModuleFileNameA(NULL, outPath, size); + char *lastSlash = strrchr(outPath, '\\'); + if (lastSlash) *(lastSlash + 1) = '\0'; + strncat_s(outPath, size, "settings.dat", _TRUNCATE); +} +static void Win64_SaveSettings(GAME_SETTINGS *gs) +{ + if (!gs) return; + char filePath[MAX_PATH] = {}; + Win64_GetSettingsPath(filePath, MAX_PATH); + FILE *f = NULL; + if (fopen_s(&f, filePath, "wb") == 0 && f) + { + fwrite(gs, sizeof(GAME_SETTINGS), 1, f); + fclose(f); + } +} +static void Win64_LoadSettings(GAME_SETTINGS *gs) +{ + if (!gs) return; + char filePath[MAX_PATH] = {}; + Win64_GetSettingsPath(filePath, MAX_PATH); + FILE *f = NULL; + if (fopen_s(&f, filePath, "rb") == 0 && f) + { + GAME_SETTINGS temp = {}; + if (fread(&temp, sizeof(GAME_SETTINGS), 1, f) == 1) + memcpy(gs, &temp, sizeof(GAME_SETTINGS)); + fclose(f); + } +} +#endif + void CMinecraftApp::InitGameSettings() { for(int i=0;ibSettingsChanged=false; } @@ -2385,6 +2427,9 @@ void CMinecraftApp::CheckGameSettingsChanged(bool bOverride5MinuteTimer, int iPa StorageManager.WriteToProfile(iPad,true, bOverride5MinuteTimer); #else ProfileManager.WriteToProfile(iPad,true, bOverride5MinuteTimer); +#ifdef _WINDOWS64 + Win64_SaveSettings(GameSettingsA[iPad]); +#endif #endif GameSettingsA[iPad]->bSettingsChanged=false; } diff --git a/Minecraft.Client/Extrax64Stubs.cpp b/Minecraft.Client/Extrax64Stubs.cpp index f368afed..23b2c7f0 100644 --- a/Minecraft.Client/Extrax64Stubs.cpp +++ b/Minecraft.Client/Extrax64Stubs.cpp @@ -199,10 +199,11 @@ DWORD IQNetPlayer::GetSendQueueSize(IQNetPlayer * player, DWORD dwFlags) { retur 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); } -LPCWSTR IQNetPlayer::GetGamertag() { return m_gamertag; } -int IQNetPlayer::GetSessionIndex() { return m_smallId; } +bool IQNetPlayer::IsLocal() { return true; } +PlayerUID IQNetPlayer::GetXuid() { return INVALID_XUID; } +extern wstring g_playerName; +LPCWSTR IQNetPlayer::GetGamertag() { return g_playerName.empty() ? L"Windows" : g_playerName.c_str(); } +int IQNetPlayer::GetSessionIndex() { return 0; } bool IQNetPlayer::IsTalking() { return false; } bool IQNetPlayer::IsMutedByLocalUser(DWORD dwUserIndex) { return false; } bool IQNetPlayer::HasVoice() { return false; } diff --git a/Minecraft.Client/Windows64/Windows64_App.cpp b/Minecraft.Client/Windows64/Windows64_App.cpp index dbc1bfc5..461e8c34 100644 --- a/Minecraft.Client/Windows64/Windows64_App.cpp +++ b/Minecraft.Client/Windows64/Windows64_App.cpp @@ -10,11 +10,46 @@ #include "..\..\Minecraft.World\BiomeSource.h" #include "..\..\Minecraft.World\LevelType.h" +wstring g_playerName; + CConsoleMinecraftApp app; +static void LoadPlayerName() +{ + if (!g_playerName.empty()) return; + g_playerName = L"Windows"; + + 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 = NULL; + 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) + { + wchar_t wbuf[128] = {}; + mbstowcs(wbuf, buf, 127); + g_playerName = wbuf; + } + } + fclose(f); + } +} + CConsoleMinecraftApp::CConsoleMinecraftApp() : CMinecraftApp() { m_bShutdown = false; + LoadPlayerName(); } void CConsoleMinecraftApp::SetRichPresenceContext(int iPad, int contextId) @@ -35,9 +70,27 @@ void CConsoleMinecraftApp::FatalLoadError() void CConsoleMinecraftApp::CaptureSaveThumbnail() { + RenderManager.CaptureThumbnail(&m_ThumbnailBuffer); } void CConsoleMinecraftApp::GetSaveThumbnail(PBYTE *pbData,DWORD *pdwSize) { + // On a save caused by a create world, the thumbnail capture won't have happened + if (m_ThumbnailBuffer.Allocated()) + { + if (pbData) + { + *pbData = new BYTE[m_ThumbnailBuffer.GetBufferSize()]; + *pdwSize = m_ThumbnailBuffer.GetBufferSize(); + memcpy(*pbData, m_ThumbnailBuffer.GetBufferPointer(), *pdwSize); + } + m_ThumbnailBuffer.Release(); + } + else + { + // No capture happened (e.g. first save on world creation) leave thumbnail as NULL + if (pbData) *pbData = NULL; + if (pdwSize) *pdwSize = 0; + } } void CConsoleMinecraftApp::ReleaseSaveThumbnail() { @@ -57,8 +110,8 @@ void CConsoleMinecraftApp::TemporaryCreateGameStart() Minecraft *pMinecraft=Minecraft::GetInstance(); app.ReleaseSaveThumbnail(); ProfileManager.SetLockedProfile(0); - extern wchar_t g_Win64UsernameW[17]; - pMinecraft->user->name = g_Win64UsernameW; + LoadPlayerName(); + pMinecraft->user->name = g_playerName; app.ApplyGameSettingsChanged(0); ////////////////////////////////////////////////////////////////////////////////////////////// From CScene_MultiGameJoinLoad::OnInit diff --git a/Minecraft.Client/Windows64/Windows64_App.h b/Minecraft.Client/Windows64/Windows64_App.h index de8f6d85..bff916ec 100644 --- a/Minecraft.Client/Windows64/Windows64_App.h +++ b/Minecraft.Client/Windows64/Windows64_App.h @@ -1,7 +1,9 @@ #pragma once +#include "4JLibs\inc\4J_Render.h" class CConsoleMinecraftApp : public CMinecraftApp { + ImageFileBuffer m_ThumbnailBuffer; public: CConsoleMinecraftApp(); diff --git a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp index 272b29bf..48040c66 100644 --- a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp +++ b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp @@ -729,7 +729,16 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); - dyn_SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE); + // 4J-Win64: set CWD to exe dir so asset paths resolve correctly + { + char szExeDir[MAX_PATH] = {}; + GetModuleFileNameA(NULL, szExeDir, MAX_PATH); + char *pSlash = strrchr(szExeDir, '\\'); + if (pSlash) { *(pSlash + 1) = '\0'; SetCurrentDirectoryA(szExeDir); } + } + + // Declare DPI awareness so GetSystemMetrics returns physical pixels + SetProcessDPIAware(); g_iScreenWidth = GetSystemMetrics(SM_CXSCREEN); g_iScreenHeight = GetSystemMetrics(SM_CYSCREEN); @@ -1263,7 +1272,21 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, } } - // F11 toggles fullscreen + // F3 toggles the debug console overlay, F11 toggles fullscreen + if (KMInput.IsKeyPressed(VK_F3)) + { + static bool s_debugConsole = false; + s_debugConsole = !s_debugConsole; + ui.ShowUIDebugConsole(s_debugConsole); + } + +#ifdef _DEBUG_MENUS_ENABLED + if (KMInput.IsKeyPressed(VK_F4)) + { + ui.NavigateToScene(ProfileManager.GetPrimaryPad(), eUIScene_DebugOverlay, NULL, eUILayer_Debug); + } +#endif + if (KMInput.IsKeyPressed(VK_F11)) { ToggleFullscreen(); -- cgit v1.2.3 From 7ce1fa3452a25980fb40311b031fbc67145899b9 Mon Sep 17 00:00:00 2001 From: 4win <4winyt@gmail.com> Date: Mon, 2 Mar 2026 23:32:26 -0600 Subject: feat: bind F1 to toggle the HUD settings (#244) --- Minecraft.Client/Windows64/Windows64_Minecraft.cpp | 10 +++++++++- README.md | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'Minecraft.Client/Windows64/Windows64_Minecraft.cpp') diff --git a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp index 48040c66..b49af853 100644 --- a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp +++ b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp @@ -1272,7 +1272,15 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, } } - // F3 toggles the debug console overlay, F11 toggles fullscreen + // F1 toggles the HUD, F3 toggles the debug console overlay, F11 toggles fullscreen + if (KMInput.IsKeyPressed(VK_F1)) + { + int primaryPad = ProfileManager.GetPrimaryPad(); + unsigned char displayHud = app.GetGameSettings(primaryPad, eGameSetting_DisplayHUD); + app.SetGameSettings(primaryPad, eGameSetting_DisplayHUD, displayHud ? 0 : 1); + app.SetGameSettings(primaryPad, eGameSetting_DisplayHand, displayHud ? 0 : 1); + } + if (KMInput.IsKeyPressed(VK_F3)) { static bool s_debugConsole = false; diff --git a/README.md b/README.md index ba02cdda..999626e9 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,7 @@ This feature is based on [LCEMP](https://github.com/LCEMP/LCEMP/) - **Select Item**: `Mouse Wheel` or keys `1` to `9` - **Accept or Decline Tutorial hints**: `Enter` to accept and `B` to decline - **Game Info (Player list and Host Options)**: `TAB` +- **Toggle HUD**: `F1` - **Toggle Debug Info**: `F3` - **Open Debug Overlay**: `F4` -- cgit v1.2.3 From 515f91cad8e0625334954acd4024c6bfefcc89e8 Mon Sep 17 00:00:00 2001 From: Slenderman Date: Tue, 3 Mar 2026 11:58:22 -0500 Subject: 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 --- .../Common/Network/GameNetworkManager.cpp | 2 +- .../Common/Network/GameNetworkManager.h | 2 +- Minecraft.Client/Extrax64Stubs.cpp | 17 ++++++++-- Minecraft.Client/Windows64/4JLibs/inc/4J_Profile.h | 2 +- Minecraft.Client/Windows64/Windows64_App.h | 1 + Minecraft.Client/Windows64/Windows64_Minecraft.cpp | 38 ---------------------- README.md | 8 +---- 7 files changed, 20 insertions(+), 50 deletions(-) (limited to 'Minecraft.Client/Windows64/Windows64_Minecraft.cpp') diff --git a/Minecraft.Client/Common/Network/GameNetworkManager.cpp b/Minecraft.Client/Common/Network/GameNetworkManager.cpp index b3fb5cd7..a65a61aa 100644 --- a/Minecraft.Client/Common/Network/GameNetworkManager.cpp +++ b/Minecraft.Client/Common/Network/GameNetworkManager.cpp @@ -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); } diff --git a/Minecraft.Client/Common/Network/GameNetworkManager.h b/Minecraft.Client/Common/Network/GameNetworkManager.h index 01db2724..bb7633c2 100644 --- a/Minecraft.Client/Common/Network/GameNetworkManager.h +++ b/Minecraft.Client/Common/Network/GameNetworkManager.h @@ -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; diff --git a/Minecraft.Client/Extrax64Stubs.cpp b/Minecraft.Client/Extrax64Stubs.cpp index 3a86cbea..22ad578f 100644 --- a/Minecraft.Client/Extrax64Stubs.cpp +++ b/Minecraft.Client/Extrax64Stubs.cpp @@ -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 + +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) {} diff --git a/Minecraft.Client/Windows64/4JLibs/inc/4J_Profile.h b/Minecraft.Client/Windows64/4JLibs/inc/4J_Profile.h index f1bd85bb..f7718a83 100644 --- a/Minecraft.Client/Windows64/4JLibs/inc/4J_Profile.h +++ b/Minecraft.Client/Windows64/4JLibs/inc/4J_Profile.h @@ -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); diff --git a/Minecraft.Client/Windows64/Windows64_App.h b/Minecraft.Client/Windows64/Windows64_App.h index bff916ec..32d204ad 100644 --- a/Minecraft.Client/Windows64/Windows64_App.h +++ b/Minecraft.Client/Windows64/Windows64_App.h @@ -33,6 +33,7 @@ public: virtual void TemporaryCreateGameStart(); bool m_bShutdown; + wstring g_playerName; }; extern CConsoleMinecraftApp app; diff --git a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp index b49af853..78ab76fe 100644 --- a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp +++ b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp @@ -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(); diff --git a/README.md b/README.md index 999626e9..bc45ef22 100644 --- a/README.md +++ b/README.md @@ -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/) -- cgit v1.2.3 From ac480f674500e15c3cdb1633bcc17278cc08337e Mon Sep 17 00:00:00 2001 From: Slenderman Date: Tue, 3 Mar 2026 16:50:28 -0500 Subject: Update username logic and implement latest LCEMP changes (#311) * Update username logic and implement latest LCEMP changes * Update old reference * Fix tutorial world crash * Restore deleted comment --- Minecraft.Client/ClientConnection.cpp | 65 ++++++- Minecraft.Client/Extrax64Stubs.cpp | 52 ++--- Minecraft.Client/Windows64/4JLibs/inc/4J_Profile.h | 2 +- .../Windows64/Network/WinsockNetLayer.cpp | 215 ++++++++++++++------- .../Windows64/Network/WinsockNetLayer.h | 16 +- Minecraft.Client/Windows64/Windows64_App.cpp | 39 +--- Minecraft.Client/Windows64/Windows64_App.h | 1 - Minecraft.Client/Windows64/Windows64_Minecraft.cpp | 44 +++++ 8 files changed, 287 insertions(+), 147 deletions(-) (limited to 'Minecraft.Client/Windows64/Windows64_Minecraft.cpp') diff --git a/Minecraft.Client/ClientConnection.cpp b/Minecraft.Client/ClientConnection.cpp index f3510d33..8123a2f0 100644 --- a/Minecraft.Client/ClientConnection.cpp +++ b/Minecraft.Client/ClientConnection.cpp @@ -55,6 +55,12 @@ #endif #include "DLCTexturePack.h" +#ifdef _WINDOWS64 +#include "Xbox\Network\NetworkPlayerXbox.h" +#include "Common\Network\PlatformNetworkManagerStub.h" +#endif + + #ifdef _DURANGO #include "..\Minecraft.World\DurangoStats.h" #include "..\Minecraft.World\GenericStats.h" @@ -421,7 +427,6 @@ void ClientConnection::handleAddEntity(shared_ptr packet) { case AddEntityPacket::MINECART: e = Minecart::createMinecart(level, x, y, z, packet->data); - break; case AddEntityPacket::FISH_HOOK: { // 4J Stu - Brought forward from 1.4 to be able to drop XP from fishing @@ -444,7 +449,7 @@ void ClientConnection::handleAddEntity(shared_ptr packet) } } - if (owner->instanceof(eTYPE_PLAYER)) + if (owner != NULL && owner->instanceof(eTYPE_PLAYER)) { shared_ptr player = dynamic_pointer_cast(owner); shared_ptr hook = shared_ptr( new FishingHook(level, x, y, z, player) ); @@ -793,7 +798,28 @@ void ClientConnection::handleAddPlayer(shared_ptr packet) if (networkPlayer != NULL) player->m_displayName = networkPlayer->GetDisplayName(); #else // On all other platforms display name is just gamertag so don't check with the network manager - player->m_displayName = player->name; + player->m_displayName = player->getName(); +#endif + +#ifdef _WINDOWS64 + { + PlayerUID pktXuid = player->getXuid(); + const PlayerUID WIN64_XUID_BASE = (PlayerUID)0xe000d45248242f2e; + if (pktXuid >= WIN64_XUID_BASE && pktXuid < WIN64_XUID_BASE + MINECRAFT_NET_MAX_PLAYERS) + { + BYTE smallId = (BYTE)(pktXuid - WIN64_XUID_BASE); + INetworkPlayer* np = g_NetworkManager.GetPlayerBySmallId(smallId); + if (np != NULL) + { + NetworkPlayerXbox* npx = (NetworkPlayerXbox*)np; + IQNetPlayer* qp = npx->GetQNetPlayer(); + if (qp != NULL && qp->m_gamertag[0] == 0) + { + wcsncpy_s(qp->m_gamertag, 32, packet->name.c_str(), _TRUNCATE); + } + } + } + } #endif // printf("\t\t\t\t%d: Add player\n",packet->id,packet->yRot); @@ -938,6 +964,39 @@ void ClientConnection::handleMoveEntitySmall(shared_ptr p void ClientConnection::handleRemoveEntity(shared_ptr packet) { +#ifdef _WINDOWS64 + if (!g_NetworkManager.IsHost()) + { + for (int i = 0; i < packet->ids.length; i++) + { + shared_ptr entity = getEntity(packet->ids[i]); + if (entity != NULL && entity->GetType() == eTYPE_PLAYER) + { + shared_ptr player = dynamic_pointer_cast(entity); + if (player != NULL) + { + PlayerUID xuid = player->getXuid(); + INetworkPlayer* np = g_NetworkManager.GetPlayerByXuid(xuid); + if (np != NULL) + { + NetworkPlayerXbox* npx = (NetworkPlayerXbox*)np; + IQNetPlayer* qp = npx->GetQNetPlayer(); + if (qp != NULL) + { + extern CPlatformNetworkManagerStub* g_pPlatformNetworkManager; + g_pPlatformNetworkManager->NotifyPlayerLeaving(qp); + qp->m_smallId = 0; + qp->m_isRemote = false; + qp->m_isHostPlayer = false; + qp->m_gamertag[0] = 0; + qp->SetCustomDataValue(0); + } + } + } + } + } + } +#endif for (int i = 0; i < packet->ids.length; i++) { level->removeEntity(packet->ids[i]); diff --git a/Minecraft.Client/Extrax64Stubs.cpp b/Minecraft.Client/Extrax64Stubs.cpp index 22ad578f..5a3c5279 100644 --- a/Minecraft.Client/Extrax64Stubs.cpp +++ b/Minecraft.Client/Extrax64Stubs.cpp @@ -199,11 +199,10 @@ DWORD IQNetPlayer::GetSendQueueSize(IQNetPlayer * player, DWORD dwFlags) { retur DWORD IQNetPlayer::GetCurrentRtt() { return 0; } bool IQNetPlayer::IsHost() { return m_isHostPlayer; } bool IQNetPlayer::IsGuest() { return false; } -bool IQNetPlayer::IsLocal() { return true; } +bool IQNetPlayer::IsLocal() { return !m_isRemote; } PlayerUID IQNetPlayer::GetXuid() { return (PlayerUID)(0xe000d45248242f2e + m_smallId); } // todo: restore to INVALID_XUID once saves support this -extern wstring g_playerName; -LPCWSTR IQNetPlayer::GetGamertag() { return g_playerName.empty() ? L"Windows" : g_playerName.c_str(); } -int IQNetPlayer::GetSessionIndex() { return 0; } +LPCWSTR IQNetPlayer::GetGamertag() { return m_gamertag; } +int IQNetPlayer::GetSessionIndex() { return m_smallId; } bool IQNetPlayer::IsTalking() { return false; } bool IQNetPlayer::IsMutedByLocalUser(DWORD dwUserIndex) { return false; } bool IQNetPlayer::HasVoice() { return false; } @@ -232,13 +231,17 @@ void Win64_SetupRemoteQNetPlayer(IQNetPlayer * player, BYTE smallId, bool isHost IQNet::s_playerCount = smallId + 1; } +static bool Win64_IsActivePlayer(IQNetPlayer* p, DWORD index); + HRESULT IQNet::AddLocalPlayerByUserIndex(DWORD dwUserIndex) { 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) + if (dwUserIndex < MINECRAFT_NET_MAX_PLAYERS && + !m_player[dwUserIndex].m_isRemote && + Win64_IsActivePlayer(&m_player[dwUserIndex], dwUserIndex)) return &m_player[dwUserIndex]; return NULL; } @@ -246,7 +249,7 @@ IQNetPlayer* IQNet::GetLocalPlayerByUserIndex(DWORD dwUserIndex) return NULL; for (DWORD i = 0; i < s_playerCount; i++) { - if (!m_player[i].m_isRemote) + if (!m_player[i].m_isRemote && Win64_IsActivePlayer(&m_player[i], i)) return &m_player[i]; } return NULL; @@ -299,15 +302,28 @@ QNET_STATE IQNet::GetState() { return _iQNetStubState; } bool IQNet::IsHost() { return s_isHosting; } HRESULT IQNet::JoinGameFromInviteInfo(DWORD dwUserIndex, DWORD dwUserMask, const INVITE_INFO * pInviteInfo) { return S_OK; } void IQNet::HostGame() { _iQNetStubState = QNET_STATE_SESSION_STARTING; s_isHosting = true; } -void IQNet::ClientJoinGame() { _iQNetStubState = QNET_STATE_SESSION_STARTING; s_isHosting = false; } +void IQNet::ClientJoinGame() +{ + _iQNetStubState = QNET_STATE_SESSION_STARTING; + s_isHosting = false; + + for (int i = 0; i < MINECRAFT_NET_MAX_PLAYERS; i++) + { + m_player[i].m_smallId = (BYTE)i; + m_player[i].m_isRemote = true; + m_player[i].m_isHostPlayer = false; + m_player[i].m_gamertag[0] = 0; + m_player[i].SetCustomDataValue(0); + } +} void IQNet::EndGame() { _iQNetStubState = QNET_STATE_IDLE; s_isHosting = false; s_playerCount = 1; - for (int i = 1; i < MINECRAFT_NET_MAX_PLAYERS; i++) + for (int i = 0; i < MINECRAFT_NET_MAX_PLAYERS; i++) { - m_player[i].m_smallId = 0; + m_player[i].m_smallId = (BYTE)i; m_player[i].m_isRemote = false; m_player[i].m_isHostPlayer = false; m_player[i].m_gamertag[0] = 0; @@ -587,23 +603,9 @@ void C_4JProfile::SetPrimaryPad(int iPad) {} #ifdef _DURANGO char fakeGamerTag[32] = "PlayerName"; void SetFakeGamertag(char* name) { strcpy_s(fakeGamerTag, name); } -char* C_4JProfile::GetGamertag(int iPad) { return fakeGamerTag; } #else -#include - -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; } +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; } #endif bool C_4JProfile::IsFullVersion() { return s_bProfileIsFullVersion; } void C_4JProfile::SetSignInChangeCallback(void (*Func)(LPVOID, bool, unsigned int), LPVOID lpParam) {} diff --git a/Minecraft.Client/Windows64/4JLibs/inc/4J_Profile.h b/Minecraft.Client/Windows64/4JLibs/inc/4J_Profile.h index f7718a83..f1bd85bb 100644 --- a/Minecraft.Client/Windows64/4JLibs/inc/4J_Profile.h +++ b/Minecraft.Client/Windows64/4JLibs/inc/4J_Profile.h @@ -75,7 +75,7 @@ public: // SYS int GetPrimaryPad(); void SetPrimaryPad(int iPad); - const char* GetGamertag(int iPad); + char* GetGamertag(int iPad); wstring GetDisplayName(int iPad); bool IsFullVersion(); void SetSignInChangeCallback(void ( *Func)(LPVOID, bool, unsigned int),LPVOID lpParam); diff --git a/Minecraft.Client/Windows64/Network/WinsockNetLayer.cpp b/Minecraft.Client/Windows64/Network/WinsockNetLayer.cpp index 19fc2598..d3ea1c3a 100644 --- a/Minecraft.Client/Windows64/Network/WinsockNetLayer.cpp +++ b/Minecraft.Client/Windows64/Network/WinsockNetLayer.cpp @@ -1,3 +1,6 @@ +// Code implemented by LCEMP, credit if used on other repos +// https://github.com/LCEMP/LCEMP + #include "stdafx.h" #ifdef _WINDOWS64 @@ -151,7 +154,7 @@ bool WinsockNetLayer::HostGame(int port) LeaveCriticalSection(&s_freeSmallIdLock); struct addrinfo hints = {}; - struct addrinfo *result = NULL; + struct addrinfo* result = NULL; hints.ai_family = AF_INET; hints.ai_socktype = SOCK_STREAM; @@ -177,7 +180,7 @@ bool WinsockNetLayer::HostGame(int port) } int opt = 1; - setsockopt(s_listenSocket, SOL_SOCKET, SO_REUSEADDR, (const char *)&opt, sizeof(opt)); + setsockopt(s_listenSocket, SOL_SOCKET, SO_REUSEADDR, (const char*)&opt, sizeof(opt)); iResult = ::bind(s_listenSocket, result->ai_addr, (int)result->ai_addrlen); freeaddrinfo(result); @@ -207,15 +210,23 @@ bool WinsockNetLayer::HostGame(int port) return true; } -bool WinsockNetLayer::JoinGame(const char *ip, int port) +bool WinsockNetLayer::JoinGame(const char* ip, int port) { if (!s_initialized && !Initialize()) return false; s_isHost = false; s_hostSmallId = 0; + s_connected = false; + s_active = false; + + if (s_hostConnectionSocket != INVALID_SOCKET) + { + closesocket(s_hostConnectionSocket); + s_hostConnectionSocket = INVALID_SOCKET; + } struct addrinfo hints = {}; - struct addrinfo *result = NULL; + struct addrinfo* result = NULL; hints.ai_family = AF_INET; hints.ai_socktype = SOCK_STREAM; @@ -231,37 +242,55 @@ bool WinsockNetLayer::JoinGame(const char *ip, int port) return false; } - s_hostConnectionSocket = socket(result->ai_family, result->ai_socktype, result->ai_protocol); - if (s_hostConnectionSocket == INVALID_SOCKET) + bool connected = false; + BYTE assignedSmallId = 0; + const int maxAttempts = 12; + + for (int attempt = 0; attempt < maxAttempts; ++attempt) { - app.DebugPrintf("socket() failed: %d\n", WSAGetLastError()); - freeaddrinfo(result); - return false; - } + s_hostConnectionSocket = socket(result->ai_family, result->ai_socktype, result->ai_protocol); + if (s_hostConnectionSocket == INVALID_SOCKET) + { + app.DebugPrintf("socket() failed: %d\n", WSAGetLastError()); + break; + } - int noDelay = 1; - setsockopt(s_hostConnectionSocket, IPPROTO_TCP, TCP_NODELAY, (const char *)&noDelay, sizeof(noDelay)); + int noDelay = 1; + setsockopt(s_hostConnectionSocket, IPPROTO_TCP, TCP_NODELAY, (const char*)&noDelay, sizeof(noDelay)); - iResult = connect(s_hostConnectionSocket, result->ai_addr, (int)result->ai_addrlen); - freeaddrinfo(result); - if (iResult == SOCKET_ERROR) - { - app.DebugPrintf("connect() to %s:%d failed: %d\n", ip, port, WSAGetLastError()); - closesocket(s_hostConnectionSocket); - s_hostConnectionSocket = INVALID_SOCKET; - return false; + iResult = connect(s_hostConnectionSocket, result->ai_addr, (int)result->ai_addrlen); + if (iResult == SOCKET_ERROR) + { + int err = WSAGetLastError(); + app.DebugPrintf("connect() to %s:%d failed (attempt %d/%d): %d\n", ip, port, attempt + 1, maxAttempts, err); + closesocket(s_hostConnectionSocket); + s_hostConnectionSocket = INVALID_SOCKET; + Sleep(200); + continue; + } + + BYTE assignBuf[1]; + int bytesRecv = recv(s_hostConnectionSocket, (char*)assignBuf, 1, 0); + if (bytesRecv != 1) + { + app.DebugPrintf("Failed to receive small ID assignment from host (attempt %d/%d)\n", attempt + 1, maxAttempts); + closesocket(s_hostConnectionSocket); + s_hostConnectionSocket = INVALID_SOCKET; + Sleep(200); + continue; + } + + assignedSmallId = assignBuf[0]; + connected = true; + break; } + freeaddrinfo(result); - BYTE assignBuf[1]; - int bytesRecv = recv(s_hostConnectionSocket, (char *)assignBuf, 1, 0); - if (bytesRecv != 1) + if (!connected) { - app.DebugPrintf("Failed to receive small ID assignment from host\n"); - closesocket(s_hostConnectionSocket); - s_hostConnectionSocket = INVALID_SOCKET; return false; } - s_localSmallId = assignBuf[0]; + s_localSmallId = assignedSmallId; app.DebugPrintf("Win64 LAN: Connected to %s:%d, assigned smallId=%d\n", ip, port, s_localSmallId); @@ -273,7 +302,7 @@ bool WinsockNetLayer::JoinGame(const char *ip, int port) return true; } -bool WinsockNetLayer::SendOnSocket(SOCKET sock, const void *data, int dataSize) +bool WinsockNetLayer::SendOnSocket(SOCKET sock, const void* data, int dataSize) { if (sock == INVALID_SOCKET || dataSize <= 0) return false; @@ -289,7 +318,7 @@ bool WinsockNetLayer::SendOnSocket(SOCKET sock, const void *data, int dataSize) int toSend = 4; while (totalSent < toSend) { - int sent = send(sock, (const char *)header + totalSent, toSend - totalSent, 0); + int sent = send(sock, (const char*)header + totalSent, toSend - totalSent, 0); if (sent == SOCKET_ERROR || sent == 0) { LeaveCriticalSection(&s_sendLock); @@ -301,7 +330,7 @@ bool WinsockNetLayer::SendOnSocket(SOCKET sock, const void *data, int dataSize) totalSent = 0; while (totalSent < dataSize) { - int sent = send(sock, (const char *)data + totalSent, dataSize - totalSent, 0); + int sent = send(sock, (const char*)data + totalSent, dataSize - totalSent, 0); if (sent == SOCKET_ERROR || sent == 0) { LeaveCriticalSection(&s_sendLock); @@ -314,7 +343,7 @@ bool WinsockNetLayer::SendOnSocket(SOCKET sock, const void *data, int dataSize) return true; } -bool WinsockNetLayer::SendToSmallId(BYTE targetSmallId, const void *data, int dataSize) +bool WinsockNetLayer::SendToSmallId(BYTE targetSmallId, const void* data, int dataSize) { if (!s_active) return false; @@ -346,34 +375,34 @@ SOCKET WinsockNetLayer::GetSocketForSmallId(BYTE smallId) return INVALID_SOCKET; } -static bool RecvExact(SOCKET sock, BYTE *buf, int len) +static bool RecvExact(SOCKET sock, BYTE* buf, int len) { int totalRecv = 0; while (totalRecv < len) { - int r = recv(sock, (char *)buf + totalRecv, len - totalRecv, 0); + int r = recv(sock, (char*)buf + totalRecv, len - totalRecv, 0); if (r <= 0) return false; totalRecv += r; } return true; } -void WinsockNetLayer::HandleDataReceived(BYTE fromSmallId, BYTE toSmallId, unsigned char *data, unsigned int dataSize) +void WinsockNetLayer::HandleDataReceived(BYTE fromSmallId, BYTE toSmallId, unsigned char* data, unsigned int dataSize) { - INetworkPlayer *pPlayerFrom = g_NetworkManager.GetPlayerBySmallId(fromSmallId); - INetworkPlayer *pPlayerTo = g_NetworkManager.GetPlayerBySmallId(toSmallId); + INetworkPlayer* pPlayerFrom = g_NetworkManager.GetPlayerBySmallId(fromSmallId); + INetworkPlayer* pPlayerTo = g_NetworkManager.GetPlayerBySmallId(toSmallId); if (pPlayerFrom == NULL || pPlayerTo == NULL) return; if (s_isHost) { - ::Socket *pSocket = pPlayerFrom->GetSocket(); + ::Socket* pSocket = pPlayerFrom->GetSocket(); if (pSocket != NULL) pSocket->pushDataToQueue(data, dataSize, false); } else { - ::Socket *pSocket = pPlayerTo->GetSocket(); + ::Socket* pSocket = pPlayerTo->GetSocket(); if (pSocket != NULL) pSocket->pushDataToQueue(data, dataSize, true); } @@ -392,7 +421,7 @@ DWORD WINAPI WinsockNetLayer::AcceptThreadProc(LPVOID param) } int noDelay = 1; - setsockopt(clientSocket, IPPROTO_TCP, TCP_NODELAY, (const char *)&noDelay, sizeof(noDelay)); + setsockopt(clientSocket, IPPROTO_TCP, TCP_NODELAY, (const char*)&noDelay, sizeof(noDelay)); extern QNET_STATE _iQNetStubState; if (_iQNetStubState != QNET_STATE_GAME_PLAY) @@ -423,7 +452,7 @@ DWORD WINAPI WinsockNetLayer::AcceptThreadProc(LPVOID param) LeaveCriticalSection(&s_freeSmallIdLock); BYTE assignBuf[1] = { assignedSmallId }; - int sent = send(clientSocket, (const char *)assignBuf, 1, 0); + int sent = send(clientSocket, (const char*)assignBuf, 1, 0); if (sent != 1) { app.DebugPrintf("Failed to send small ID to client\n"); @@ -444,15 +473,15 @@ DWORD WINAPI WinsockNetLayer::AcceptThreadProc(LPVOID param) app.DebugPrintf("Win64 LAN: Client connected, assigned smallId=%d\n", assignedSmallId); - IQNetPlayer *qnetPlayer = &IQNet::m_player[assignedSmallId]; + IQNetPlayer* qnetPlayer = &IQNet::m_player[assignedSmallId]; - extern void Win64_SetupRemoteQNetPlayer(IQNetPlayer *player, BYTE smallId, bool isHost, bool isLocal); + extern void Win64_SetupRemoteQNetPlayer(IQNetPlayer * player, BYTE smallId, bool isHost, bool isLocal); Win64_SetupRemoteQNetPlayer(qnetPlayer, assignedSmallId, false, false); - extern CPlatformNetworkManagerStub *g_pPlatformNetworkManager; + extern CPlatformNetworkManagerStub* g_pPlatformNetworkManager; g_pPlatformNetworkManager->NotifyPlayerJoined(qnetPlayer); - DWORD *threadParam = new DWORD; + DWORD* threadParam = new DWORD; *threadParam = connIdx; HANDLE hThread = CreateThread(NULL, 0, RecvThreadProc, threadParam, 0, NULL); @@ -466,8 +495,8 @@ DWORD WINAPI WinsockNetLayer::AcceptThreadProc(LPVOID param) DWORD WINAPI WinsockNetLayer::RecvThreadProc(LPVOID param) { - DWORD connIdx = *(DWORD *)param; - delete (DWORD *)param; + DWORD connIdx = *(DWORD*)param; + delete (DWORD*)param; EnterCriticalSection(&s_connectionsLock); if (connIdx >= (DWORD)s_connections.size()) @@ -479,7 +508,8 @@ DWORD WINAPI WinsockNetLayer::RecvThreadProc(LPVOID param) BYTE clientSmallId = s_connections[connIdx].smallId; LeaveCriticalSection(&s_connectionsLock); - BYTE *recvBuf = new BYTE[WIN64_NET_RECV_BUFFER_SIZE]; + std::vector recvBuf; + recvBuf.resize(WIN64_NET_RECV_BUFFER_SIZE); while (s_active) { @@ -490,33 +520,47 @@ DWORD WINAPI WinsockNetLayer::RecvThreadProc(LPVOID param) break; } - int packetSize = (header[0] << 24) | (header[1] << 16) | (header[2] << 8) | header[3]; + int packetSize = + ((uint32_t)header[0] << 24) | + ((uint32_t)header[1] << 16) | + ((uint32_t)header[2] << 8) | + ((uint32_t)header[3]); - if (packetSize <= 0 || packetSize > WIN64_NET_RECV_BUFFER_SIZE) + if (packetSize <= 0 || packetSize > WIN64_NET_MAX_PACKET_SIZE) { - app.DebugPrintf("Win64 LAN: Invalid packet size %d from client smallId=%d\n", packetSize, clientSmallId); + app.DebugPrintf("Win64 LAN: Invalid packet size %d from client smallId=%d (max=%d)\n", + packetSize, + clientSmallId, + (int)WIN64_NET_MAX_PACKET_SIZE); break; } - if (!RecvExact(sock, recvBuf, packetSize)) + if ((int)recvBuf.size() < packetSize) + { + recvBuf.resize(packetSize); + app.DebugPrintf("Win64 LAN: Resized host recv buffer to %d bytes for client smallId=%d\n", packetSize, clientSmallId); + } + + if (!RecvExact(sock, &recvBuf[0], packetSize)) { app.DebugPrintf("Win64 LAN: Client smallId=%d disconnected (body)\n", clientSmallId); break; } - HandleDataReceived(clientSmallId, s_hostSmallId, recvBuf, packetSize); + HandleDataReceived(clientSmallId, s_hostSmallId, &recvBuf[0], packetSize); } - delete[] recvBuf; - EnterCriticalSection(&s_connectionsLock); for (size_t i = 0; i < s_connections.size(); i++) { if (s_connections[i].smallId == clientSmallId) { s_connections[i].active = false; - closesocket(s_connections[i].tcpSocket); - s_connections[i].tcpSocket = INVALID_SOCKET; + if (s_connections[i].tcpSocket != INVALID_SOCKET) + { + closesocket(s_connections[i].tcpSocket); + s_connections[i].tcpSocket = INVALID_SOCKET; + } break; } } @@ -529,7 +573,7 @@ DWORD WINAPI WinsockNetLayer::RecvThreadProc(LPVOID param) return 0; } -bool WinsockNetLayer::PopDisconnectedSmallId(BYTE *outSmallId) +bool WinsockNetLayer::PopDisconnectedSmallId(BYTE* outSmallId) { bool found = false; EnterCriticalSection(&s_disconnectLock); @@ -550,9 +594,26 @@ void WinsockNetLayer::PushFreeSmallId(BYTE smallId) LeaveCriticalSection(&s_freeSmallIdLock); } +void WinsockNetLayer::CloseConnectionBySmallId(BYTE smallId) +{ + EnterCriticalSection(&s_connectionsLock); + for (size_t i = 0; i < s_connections.size(); i++) + { + if (s_connections[i].smallId == smallId && s_connections[i].active && s_connections[i].tcpSocket != INVALID_SOCKET) + { + closesocket(s_connections[i].tcpSocket); + s_connections[i].tcpSocket = INVALID_SOCKET; + app.DebugPrintf("Win64 LAN: Force-closed TCP connection for smallId=%d\n", smallId); + break; + } + } + LeaveCriticalSection(&s_connectionsLock); +} + DWORD WINAPI WinsockNetLayer::ClientRecvThreadProc(LPVOID param) { - BYTE *recvBuf = new BYTE[WIN64_NET_RECV_BUFFER_SIZE]; + std::vector recvBuf; + recvBuf.resize(WIN64_NET_RECV_BUFFER_SIZE); while (s_active && s_hostConnectionSocket != INVALID_SOCKET) { @@ -565,28 +626,34 @@ DWORD WINAPI WinsockNetLayer::ClientRecvThreadProc(LPVOID param) int packetSize = (header[0] << 24) | (header[1] << 16) | (header[2] << 8) | header[3]; - if (packetSize <= 0 || packetSize > WIN64_NET_RECV_BUFFER_SIZE) + if (packetSize <= 0 || packetSize > WIN64_NET_MAX_PACKET_SIZE) { - app.DebugPrintf("Win64 LAN: Invalid packet size %d from host\n", packetSize); + app.DebugPrintf("Win64 LAN: Invalid packet size %d from host (max=%d)\n", + packetSize, + (int)WIN64_NET_MAX_PACKET_SIZE); break; } - if (!RecvExact(s_hostConnectionSocket, recvBuf, packetSize)) + if ((int)recvBuf.size() < packetSize) + { + recvBuf.resize(packetSize); + app.DebugPrintf("Win64 LAN: Resized client recv buffer to %d bytes\n", packetSize); + } + + if (!RecvExact(s_hostConnectionSocket, &recvBuf[0], packetSize)) { app.DebugPrintf("Win64 LAN: Disconnected from host (body)\n"); break; } - HandleDataReceived(s_hostSmallId, s_localSmallId, recvBuf, packetSize); + HandleDataReceived(s_hostSmallId, s_localSmallId, &recvBuf[0], packetSize); } - delete[] recvBuf; - s_connected = false; return 0; } -bool WinsockNetLayer::StartAdvertising(int gamePort, const wchar_t *hostName, unsigned int gameSettings, unsigned int texPackId, unsigned char subTexId, unsigned short netVer) +bool WinsockNetLayer::StartAdvertising(int gamePort, const wchar_t* hostName, unsigned int gameSettings, unsigned int texPackId, unsigned char subTexId, unsigned short netVer) { if (s_advertising) return true; if (!s_initialized) return false; @@ -614,7 +681,7 @@ bool WinsockNetLayer::StartAdvertising(int gamePort, const wchar_t *hostName, un } BOOL broadcast = TRUE; - setsockopt(s_advertiseSock, SOL_SOCKET, SO_BROADCAST, (const char *)&broadcast, sizeof(broadcast)); + setsockopt(s_advertiseSock, SOL_SOCKET, SO_BROADCAST, (const char*)&broadcast, sizeof(broadcast)); s_advertising = true; s_advertiseThread = CreateThread(NULL, 0, AdvertiseThreadProc, NULL, 0, NULL); @@ -669,8 +736,8 @@ DWORD WINAPI WinsockNetLayer::AdvertiseThreadProc(LPVOID param) Win64LANBroadcast data = s_advertiseData; LeaveCriticalSection(&s_advertiseLock); - int sent = sendto(s_advertiseSock, (const char *)&data, sizeof(data), 0, - (struct sockaddr *)&broadcastAddr, sizeof(broadcastAddr)); + int sent = sendto(s_advertiseSock, (const char*)&data, sizeof(data), 0, + (struct sockaddr*)&broadcastAddr, sizeof(broadcastAddr)); if (sent == SOCKET_ERROR && s_advertising) { @@ -696,7 +763,7 @@ bool WinsockNetLayer::StartDiscovery() } BOOL reuseAddr = TRUE; - setsockopt(s_discoverySock, SOL_SOCKET, SO_REUSEADDR, (const char *)&reuseAddr, sizeof(reuseAddr)); + setsockopt(s_discoverySock, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuseAddr, sizeof(reuseAddr)); struct sockaddr_in bindAddr; memset(&bindAddr, 0, sizeof(bindAddr)); @@ -704,7 +771,7 @@ bool WinsockNetLayer::StartDiscovery() bindAddr.sin_port = htons(WIN64_LAN_DISCOVERY_PORT); bindAddr.sin_addr.s_addr = INADDR_ANY; - if (::bind(s_discoverySock, (struct sockaddr *)&bindAddr, sizeof(bindAddr)) == SOCKET_ERROR) + if (::bind(s_discoverySock, (struct sockaddr*)&bindAddr, sizeof(bindAddr)) == SOCKET_ERROR) { app.DebugPrintf("Win64 LAN: Discovery bind failed: %d\n", WSAGetLastError()); closesocket(s_discoverySock); @@ -713,7 +780,7 @@ bool WinsockNetLayer::StartDiscovery() } DWORD timeout = 500; - setsockopt(s_discoverySock, SOL_SOCKET, SO_RCVTIMEO, (const char *)&timeout, sizeof(timeout)); + setsockopt(s_discoverySock, SOL_SOCKET, SO_RCVTIMEO, (const char*)&timeout, sizeof(timeout)); s_discovering = true; s_discoveryThread = CreateThread(NULL, 0, DiscoveryThreadProc, NULL, 0, NULL); @@ -763,7 +830,7 @@ DWORD WINAPI WinsockNetLayer::DiscoveryThreadProc(LPVOID param) int senderLen = sizeof(senderAddr); int recvLen = recvfrom(s_discoverySock, recvBuf, sizeof(recvBuf), 0, - (struct sockaddr *)&senderAddr, &senderLen); + (struct sockaddr*)&senderAddr, &senderLen); if (recvLen == SOCKET_ERROR) { @@ -773,7 +840,7 @@ DWORD WINAPI WinsockNetLayer::DiscoveryThreadProc(LPVOID param) if (recvLen < (int)sizeof(Win64LANBroadcast)) continue; - Win64LANBroadcast *broadcast = (Win64LANBroadcast *)recvBuf; + Win64LANBroadcast* broadcast = (Win64LANBroadcast*)recvBuf; if (broadcast->magic != WIN64_LAN_BROADCAST_MAGIC) continue; @@ -841,4 +908,4 @@ DWORD WINAPI WinsockNetLayer::DiscoveryThreadProc(LPVOID param) return 0; } -#endif +#endif \ No newline at end of file diff --git a/Minecraft.Client/Windows64/Network/WinsockNetLayer.h b/Minecraft.Client/Windows64/Network/WinsockNetLayer.h index 96b03c9b..029dd0a7 100644 --- a/Minecraft.Client/Windows64/Network/WinsockNetLayer.h +++ b/Minecraft.Client/Windows64/Network/WinsockNetLayer.h @@ -1,3 +1,5 @@ +// Code implemented by LCEMP, credit if used on other repos +// https://github.com/LCEMP/LCEMP #pragma once #ifdef _WINDOWS64 @@ -12,6 +14,7 @@ #define WIN64_NET_DEFAULT_PORT 25565 #define WIN64_NET_MAX_CLIENTS 7 #define WIN64_NET_RECV_BUFFER_SIZE 65536 +#define WIN64_NET_MAX_PACKET_SIZE (4 * 1024 * 1024) #define WIN64_LAN_DISCOVERY_PORT 25566 #define WIN64_LAN_BROADCAST_MAGIC 0x4D434C4E @@ -63,10 +66,10 @@ public: static void Shutdown(); static bool HostGame(int port); - static bool JoinGame(const char *ip, int port); + static bool JoinGame(const char* ip, int port); - static bool SendToSmallId(BYTE targetSmallId, const void *data, int dataSize); - static bool SendOnSocket(SOCKET sock, const void *data, int dataSize); + static bool SendToSmallId(BYTE targetSmallId, const void* data, int dataSize); + static bool SendOnSocket(SOCKET sock, const void* data, int dataSize); static bool IsHosting() { return s_isHost; } static bool IsConnected() { return s_connected; } @@ -77,12 +80,13 @@ public: static SOCKET GetSocketForSmallId(BYTE smallId); - static void HandleDataReceived(BYTE fromSmallId, BYTE toSmallId, unsigned char *data, unsigned int dataSize); + static void HandleDataReceived(BYTE fromSmallId, BYTE toSmallId, unsigned char* data, unsigned int dataSize); - static bool PopDisconnectedSmallId(BYTE *outSmallId); + static bool PopDisconnectedSmallId(BYTE* outSmallId); static void PushFreeSmallId(BYTE smallId); + static void CloseConnectionBySmallId(BYTE smallId); - static bool StartAdvertising(int gamePort, const wchar_t *hostName, unsigned int gameSettings, unsigned int texPackId, unsigned char subTexId, unsigned short netVer); + static bool StartAdvertising(int gamePort, const wchar_t* hostName, unsigned int gameSettings, unsigned int texPackId, unsigned char subTexId, unsigned short netVer); static void StopAdvertising(); static void UpdateAdvertisePlayerCount(BYTE count); static void UpdateAdvertiseJoinable(bool joinable); diff --git a/Minecraft.Client/Windows64/Windows64_App.cpp b/Minecraft.Client/Windows64/Windows64_App.cpp index 461e8c34..ad9e1f24 100644 --- a/Minecraft.Client/Windows64/Windows64_App.cpp +++ b/Minecraft.Client/Windows64/Windows64_App.cpp @@ -10,46 +10,11 @@ #include "..\..\Minecraft.World\BiomeSource.h" #include "..\..\Minecraft.World\LevelType.h" -wstring g_playerName; - CConsoleMinecraftApp app; -static void LoadPlayerName() -{ - if (!g_playerName.empty()) return; - g_playerName = L"Windows"; - - 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 = NULL; - 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) - { - wchar_t wbuf[128] = {}; - mbstowcs(wbuf, buf, 127); - g_playerName = wbuf; - } - } - fclose(f); - } -} - CConsoleMinecraftApp::CConsoleMinecraftApp() : CMinecraftApp() { m_bShutdown = false; - LoadPlayerName(); } void CConsoleMinecraftApp::SetRichPresenceContext(int iPad, int contextId) @@ -110,8 +75,8 @@ void CConsoleMinecraftApp::TemporaryCreateGameStart() Minecraft *pMinecraft=Minecraft::GetInstance(); app.ReleaseSaveThumbnail(); ProfileManager.SetLockedProfile(0); - LoadPlayerName(); - pMinecraft->user->name = g_playerName; + extern wchar_t g_Win64UsernameW[17]; + pMinecraft->user->name = g_Win64UsernameW; app.ApplyGameSettingsChanged(0); ////////////////////////////////////////////////////////////////////////////////////////////// From CScene_MultiGameJoinLoad::OnInit diff --git a/Minecraft.Client/Windows64/Windows64_App.h b/Minecraft.Client/Windows64/Windows64_App.h index 32d204ad..bff916ec 100644 --- a/Minecraft.Client/Windows64/Windows64_App.h +++ b/Minecraft.Client/Windows64/Windows64_App.h @@ -33,7 +33,6 @@ public: virtual void TemporaryCreateGameStart(); bool m_bShutdown; - wstring g_playerName; }; extern CConsoleMinecraftApp app; diff --git a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp index 78ab76fe..4a3d835c 100644 --- a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp +++ b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp @@ -88,6 +88,9 @@ int g_iScreenHeight = 1080; UINT g_ScreenWidth = 1920; UINT g_ScreenHeight = 1080; +char g_Win64Username[17] = { 0 }; +wchar_t g_Win64UsernameW[17] = { 0 }; + // Fullscreen toggle state static bool g_isFullscreen = false; static WINDOWPLACEMENT g_wpPrev = { sizeof(g_wpPrev) }; @@ -762,8 +765,47 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, //g_iScreenWidth = 960; //g_iScreenHeight = 544; } + + // Default username will be "Windows" + strncpy_s(g_Win64Username, sizeof(g_Win64Username), "Windows", _TRUNCATE); + + 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); + } } + if (g_Win64Username[0] == 0) + { + DWORD sz = 17; + if (!GetUserNameA(g_Win64Username, &sz)) + strncpy_s(g_Win64Username, 17, "Player", _TRUNCATE); + g_Win64Username[16] = 0; + } + + MultiByteToWideChar(CP_ACP, 0, g_Win64Username, -1, g_Win64UsernameW, 17); + // Initialize global strings MyRegisterClass(hInstance); @@ -935,6 +977,8 @@ 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(); -- cgit v1.2.3 From b1b622c303a40a5533962fc63559a0346cfbca04 Mon Sep 17 00:00:00 2001 From: rtm516 Date: Wed, 4 Mar 2026 04:31:47 +0000 Subject: Fix overlapping debug menus and screens (#294) * Fix overlapping debug menus and screens Also resolves a formatting issue with clang-format * Update readme --- .clang-format | 4 +- Minecraft.Client/Minecraft.cpp | 14 ++--- Minecraft.Client/Windows64/Windows64_Minecraft.cpp | 67 ++++++++++------------ README.md | 1 + 4 files changed, 38 insertions(+), 48 deletions(-) (limited to 'Minecraft.Client/Windows64/Windows64_Minecraft.cpp') diff --git a/.clang-format b/.clang-format index 383e6210..a4d4a4c2 100644 --- a/.clang-format +++ b/.clang-format @@ -39,9 +39,7 @@ RemoveSemicolon: false SeparateDefinitionBlocks: Leave ShortNamespaceLines: 1 SkipMacroDefinitionBody: false -SortIncludes: - Enabled: true - IgnoreCase: false +SortIncludes: CaseSensitive SpacesInParens: Never SpacesInParensOptions: ExceptDoubleParentheses: false diff --git a/Minecraft.Client/Minecraft.cpp b/Minecraft.Client/Minecraft.cpp index 164417ab..bd75a61a 100644 --- a/Minecraft.Client/Minecraft.cpp +++ b/Minecraft.Client/Minecraft.cpp @@ -3618,8 +3618,6 @@ void Minecraft::tick(bool bFirst, bool bUpdateTextures) if((player->ullButtonsPressed&(1LL<renderDebug = !options->renderDebug; #ifdef _XBOX app.EnableDebugOverlay(options->renderDebug,iPad); #else @@ -3629,13 +3627,11 @@ void Minecraft::tick(bool bFirst, bool bUpdateTextures) #endif } - if((player->ullButtonsPressed&(1LL< mob = dynamic_pointer_cast(Creeper::_class->newInstance( level )); - //shared_ptr mob = dynamic_pointer_cast(Wolf::_class->newInstance( level )); - shared_ptr mob = dynamic_pointer_cast(shared_ptr(new Spider( level ))); - mob->moveTo(player->x+1, player->y, player->z+1, level->random->nextFloat() * 360, 0); - level->addEntity(mob); + if((player->ullButtonsPressed&(1LL<renderDebug = !options->renderDebug; +#endif } } diff --git a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp index 4a3d835c..9d9537c5 100644 --- a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp +++ b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp @@ -1278,7 +1278,7 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, } } - // F1 toggles the HUD, F3 toggles the debug console overlay, F11 toggles fullscreen + // F1 toggles the HUD if (KMInput.IsKeyPressed(VK_F1)) { int primaryPad = ProfileManager.GetPrimaryPad(); @@ -1286,21 +1286,43 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, app.SetGameSettings(primaryPad, eGameSetting_DisplayHUD, displayHud ? 0 : 1); app.SetGameSettings(primaryPad, eGameSetting_DisplayHand, displayHud ? 0 : 1); } - + + // F3 toggles onscreen debug info if (KMInput.IsKeyPressed(VK_F3)) { - static bool s_debugConsole = false; - s_debugConsole = !s_debugConsole; - ui.ShowUIDebugConsole(s_debugConsole); + if (Minecraft* pMinecraft = Minecraft::GetInstance()) + { + if (pMinecraft->options) + { + pMinecraft->options->renderDebug = !pMinecraft->options->renderDebug; + } + } } #ifdef _DEBUG_MENUS_ENABLED - if (KMInput.IsKeyPressed(VK_F4)) - { - ui.NavigateToScene(ProfileManager.GetPrimaryPad(), eUIScene_DebugOverlay, NULL, eUILayer_Debug); - } + // F4 Open debug overlay + if (KMInput.IsKeyPressed(VK_F4)) + { + if (Minecraft *pMinecraft = Minecraft::GetInstance()) + { + if (pMinecraft->options && + app.GetGameStarted() && !ui.GetMenuDisplayed(0) && pMinecraft->screen == NULL) + { + ui.NavigateToScene(0, eUIScene_DebugOverlay, NULL, eUILayer_Debug); + } + } + } + + // F6 Open debug console + if (KMInput.IsKeyPressed(VK_F6)) + { + static bool s_debugConsole = false; + s_debugConsole = !s_debugConsole; + ui.ShowUIDebugConsole(s_debugConsole); + } #endif + // F11 Toggle fullscreen if (KMInput.IsKeyPressed(VK_F11)) { ToggleFullscreen(); @@ -1318,33 +1340,6 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, } } -#ifdef _DEBUG_MENUS_ENABLED - // F3 toggles onscreen debug info - if (KMInput.IsKeyPressed(VK_F3)) - { - if (Minecraft* pMinecraft = Minecraft::GetInstance()) - { - if (pMinecraft->options && app.DebugSettingsOn()) - { - pMinecraft->options->renderDebug = !pMinecraft->options->renderDebug; - } - } - } - - // F4 opens debug overlay - if (KMInput.IsKeyPressed(VK_F4)) - { - if (Minecraft* pMinecraft = Minecraft::GetInstance()) - { - if (pMinecraft->options && app.DebugSettingsOn() && - app.GetGameStarted() && !ui.GetMenuDisplayed(0) && pMinecraft->screen == NULL) - { - ui.NavigateToScene(0, eUIScene_DebugOverlay, NULL, eUILayer_Debug); - } - } - } -#endif - #if 0 // has the game defined profile data been changed (by a profile load) if(app.uiGameDefinedDataChangedBitmask!=0) diff --git a/README.md b/README.md index bc45ef22..71c067b0 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,7 @@ This feature is based on [LCEMP](https://github.com/LCEMP/LCEMP/) - **Toggle HUD**: `F1` - **Toggle Debug Info**: `F3` - **Open Debug Overlay**: `F4` +- **Toggle Debug Console**: `F6` ## Build & Run -- cgit v1.2.3 From 8ecfc525471720012f36a0016d88a4f0f4cfaa1d Mon Sep 17 00:00:00 2001 From: daoge_cmd <3523206925@qq.com> Date: Wed, 4 Mar 2026 15:33:52 +0800 Subject: feat: add support for username, IP, and port configuration via launch arguments --- Minecraft.Client/Windows64/Windows64_Minecraft.cpp | 57 +++++++++++++--------- README.md | 14 +++++- 2 files changed, 47 insertions(+), 24 deletions(-) (limited to 'Minecraft.Client/Windows64/Windows64_Minecraft.cpp') diff --git a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp index 9d9537c5..3d5eec00 100644 --- a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp +++ b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp @@ -766,33 +766,44 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, //g_iScreenHeight = 544; } - // Default username will be "Windows" - strncpy_s(g_Win64Username, sizeof(g_Win64Username), "Windows", _TRUNCATE); + char cmdLineA[1024]; + strncpy_s(cmdLineA, sizeof(cmdLineA), lpCmdLine, _TRUNCATE); - 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); + 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); + } - FILE* f = nullptr; - if (fopen_s(&f, filePath, "r") == 0 && f) + char *ipArg = strstr(cmdLineA, "-ip "); + if (ipArg) { - 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'; + ipArg += 4; + while (*ipArg == ' ') ipArg++; + char ipBuf[256]; + int n = 0; + while (ipArg[n] && ipArg[n] != ' ' && n < 255) { ipBuf[n] = ipArg[n]; n++; } + ipBuf[n] = 0; + strncpy_s(g_Win64MultiplayerIP, 256, ipBuf, _TRUNCATE); + g_Win64MultiplayerJoin = true; + } - if (len > 0) - { - strncpy_s(g_Win64Username, sizeof(g_Win64Username), buf, _TRUNCATE); - } - } - fclose(f); + char *portArg = strstr(cmdLineA, "-port "); + if (portArg) + { + portArg += 6; + while (*portArg == ' ') portArg++; + char portBuf[16]; + int n = 0; + while (portArg[n] && portArg[n] != ' ' && n < 15) { portBuf[n] = portArg[n]; n++; } + portBuf[n] = 0; + g_Win64MultiplayerPort = atoi(portBuf); } } diff --git a/README.md b/README.md index 6e9f18ae..e6583e76 100644 --- a/README.md +++ b/README.md @@ -33,10 +33,22 @@ 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 `username.txt` This feature is based on [LCEMP](https://github.com/LCEMP/LCEMP/) +### Launch Arguments + +| Argument | Description | +|--------------------|----------------------------------------------------------------------------------------------------------------| +| `-name ` | Sets your in-game username | +| `-ip
` | Manually connect to an IP if LAN advertising does not work or if the server cannot be discovered automatically | +| `-port ` | Override the default port if it was changed in the source | + +Example: +``` +Minecraft.Client.exe -name Steve -ip 192.168.0.25 -port 25565 +``` + ## Controls (Keyboard & Mouse) - **Movement**: `W` `A` `S` `D` -- cgit v1.2.3 From d112090fde200c545a70ec5dc33fe91cca0f26ec Mon Sep 17 00:00:00 2001 From: daoge_cmd <3523206925@qq.com> Date: Wed, 4 Mar 2026 16:18:47 +0800 Subject: feat: headless server --- CMakeLists.txt | 1 + .../Common/Network/PlatformNetworkManagerStub.cpp | 19 +- Minecraft.Client/Minecraft.Client.vcxproj | 5 +- Minecraft.Client/MinecraftServer.cpp | 470 ++++++++++++++- Minecraft.Client/MinecraftServer.h | 1 + Minecraft.Client/Settings.cpp | 80 ++- Minecraft.Client/Settings.h | 6 +- .../Windows64/Network/WinsockNetLayer.cpp | 21 +- .../Windows64/Network/WinsockNetLayer.h | 5 +- Minecraft.Client/Windows64/Windows64_Minecraft.cpp | 639 ++++++++++++--------- Minecraft.World/Minecraft.World.vcxproj | 5 +- README.md | 12 +- 12 files changed, 973 insertions(+), 291 deletions(-) (limited to 'Minecraft.Client/Windows64/Windows64_Minecraft.cpp') diff --git a/CMakeLists.txt b/CMakeLists.txt index 74851754..2d83c5c8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,6 +17,7 @@ function(configure_msvc_target target) $<$>,$>:/W3> $<$,$>:/W0> $<$:/MP> + $<$:/FS> $<$:/EHsc> $<$,$>:/GL /O2 /Oi /GT /GF> ) diff --git a/Minecraft.Client/Common/Network/PlatformNetworkManagerStub.cpp b/Minecraft.Client/Common/Network/PlatformNetworkManagerStub.cpp index 10d1a6a5..c2466fe3 100644 --- a/Minecraft.Client/Common/Network/PlatformNetworkManagerStub.cpp +++ b/Minecraft.Client/Common/Network/PlatformNetworkManagerStub.cpp @@ -362,12 +362,23 @@ void CPlatformNetworkManagerStub::HostGame(int localUsersMask, bool bOnlineGame, #ifdef _WINDOWS64 int port = WIN64_NET_DEFAULT_PORT; + const char* bindIp = NULL; + if (g_Win64DedicatedServer) + { + if (g_Win64DedicatedServerPort > 0) + port = g_Win64DedicatedServerPort; + if (g_Win64DedicatedServerBindIP[0] != 0) + bindIp = g_Win64DedicatedServerBindIP; + } if (!WinsockNetLayer::IsActive()) - WinsockNetLayer::HostGame(port); + WinsockNetLayer::HostGame(port, bindIp); - const wchar_t* hostName = IQNet::m_player[0].m_gamertag; - unsigned int settings = app.GetGameHostOption(eGameHostOption_All); - WinsockNetLayer::StartAdvertising(port, hostName, settings, 0, 0, MINECRAFT_NET_VERSION); + if (WinsockNetLayer::IsActive()) + { + const wchar_t* hostName = IQNet::m_player[0].m_gamertag; + unsigned int settings = app.GetGameHostOption(eGameHostOption_All); + WinsockNetLayer::StartAdvertising(port, hostName, settings, 0, 0, MINECRAFT_NET_VERSION); + } #endif //#endif } diff --git a/Minecraft.Client/Minecraft.Client.vcxproj b/Minecraft.Client/Minecraft.Client.vcxproj index 54915636..d7c49acf 100644 --- a/Minecraft.Client/Minecraft.Client.vcxproj +++ b/Minecraft.Client/Minecraft.Client.vcxproj @@ -1545,6 +1545,7 @@ if not exist "$(TargetDir)\savedata" mkdir "$(TargetDir)\savedata" true Default false + /FS %(AdditionalOptions) true @@ -1773,7 +1774,7 @@ xcopy /q /y /i /s /e $(ProjectDir)DurangoMedia\CU $(LayoutDir)Image\Loose\CUtrue true true - /Ob3 + /FS /Ob3 %(AdditionalOptions) true @@ -48677,4 +48678,4 @@ xcopy /q /y /i /s /e $(ProjectDir)Durango\CU $(LayoutDir)Image\Loose\CU - \ No newline at end of file + diff --git a/Minecraft.Client/MinecraftServer.cpp b/Minecraft.Client/MinecraftServer.cpp index 4206a399..974c7405 100644 --- a/Minecraft.Client/MinecraftServer.cpp +++ b/Minecraft.Client/MinecraftServer.cpp @@ -27,6 +27,11 @@ #include "..\Minecraft.World\Pos.h" #include "..\Minecraft.World\System.h" #include "..\Minecraft.World\StringHelpers.h" +#include "..\Minecraft.World\net.minecraft.world.entity.item.h" +#include "..\Minecraft.World\net.minecraft.world.item.h" +#include "..\Minecraft.World\net.minecraft.world.item.enchantment.h" +#include "..\Minecraft.World\net.minecraft.world.damagesource.h" +#include #ifdef SPLIT_SAVES #include "..\Minecraft.World\ConsoleSaveFileSplit.h" #endif @@ -78,6 +83,438 @@ bool MinecraftServer::s_slowQueuePacketSent = false; unordered_map MinecraftServer::ironTimers; +static void PrintConsoleLine(const wchar_t *prefix, const wstring &message) +{ + wprintf(L"%ls%ls\n", prefix, message.c_str()); + fflush(stdout); +} + +static bool TryParseIntValue(const wstring &text, int &value) +{ + std::wistringstream stream(text); + stream >> value; + return !stream.fail() && stream.eof(); +} + +static vector SplitConsoleCommand(const wstring &command) +{ + vector tokens; + std::wistringstream stream(command); + wstring token; + while (stream >> token) + { + tokens.push_back(token); + } + return tokens; +} + +static wstring JoinConsoleCommandTokens(const vector &tokens, size_t startIndex) +{ + wstring joined; + for (size_t i = startIndex; i < tokens.size(); ++i) + { + if (!joined.empty()) joined += L" "; + joined += tokens[i]; + } + return joined; +} + +static shared_ptr FindPlayerByName(PlayerList *playerList, const wstring &name) +{ + if (playerList == NULL) return nullptr; + + for (size_t i = 0; i < playerList->players.size(); ++i) + { + shared_ptr player = playerList->players[i]; + if (player != NULL && equalsIgnoreCase(player->getName(), name)) + { + return player; + } + } + + return nullptr; +} + +static void SetAllLevelTimes(MinecraftServer *server, int value) +{ + for (unsigned int i = 0; i < server->levels.length; ++i) + { + if (server->levels[i] != NULL) + { + server->levels[i]->setDayTime(value); + } + } +} + +static bool ExecuteConsoleCommand(MinecraftServer *server, const wstring &rawCommand) +{ + if (server == NULL) + return false; + + wstring command = trimString(rawCommand); + if (command.empty()) + return true; + + if (command[0] == L'/') + { + command = trimString(command.substr(1)); + } + + vector tokens = SplitConsoleCommand(command); + if (tokens.empty()) + return true; + + const wstring action = toLower(tokens[0]); + PlayerList *playerList = server->getPlayers(); + + if (action == L"help" || action == L"?") + { + server->info(L"Commands: help, stop, list, say , save-all, time , weather [seconds], tp , give [amount] [aux], enchant [level], kill "); + return true; + } + + if (action == L"stop") + { + server->info(L"Stopping server..."); + MinecraftServer::HaltServer(); + return true; + } + + if (action == L"list") + { + wstring playerNames = (playerList != NULL) ? playerList->getPlayerNames() : L""; + if (playerNames.empty()) playerNames = L"(none)"; + server->info(L"Players (" + _toString((playerList != NULL) ? playerList->getPlayerCount() : 0) + L"): " + playerNames); + return true; + } + + if (action == L"say") + { + if (tokens.size() < 2) + { + server->warn(L"Usage: say "); + return false; + } + + wstring message = L"[Server] " + JoinConsoleCommandTokens(tokens, 1); + if (playerList != NULL) + { + playerList->broadcastAll(shared_ptr(new ChatPacket(message))); + } + server->info(message); + return true; + } + + if (action == L"save-all") + { + if (playerList != NULL) + { + playerList->saveAll(NULL, false); + } + server->info(L"World saved."); + return true; + } + + if (action == L"time") + { + if (tokens.size() < 2) + { + server->warn(L"Usage: time set | time add "); + return false; + } + + if (toLower(tokens[1]) == L"add") + { + if (tokens.size() < 3) + { + server->warn(L"Usage: time add "); + return false; + } + + int delta = 0; + if (!TryParseIntValue(tokens[2], delta)) + { + server->warn(L"Invalid tick value: " + tokens[2]); + return false; + } + + for (unsigned int i = 0; i < server->levels.length; ++i) + { + if (server->levels[i] != NULL) + { + server->levels[i]->setDayTime(server->levels[i]->getDayTime() + delta); + } + } + + server->info(L"Added " + _toString(delta) + L" ticks."); + return true; + } + + wstring timeValue = toLower(tokens[1]); + if (timeValue == L"set") + { + if (tokens.size() < 3) + { + server->warn(L"Usage: time set "); + return false; + } + timeValue = toLower(tokens[2]); + } + + int targetTime = 0; + if (timeValue == L"day") + { + targetTime = 0; + } + else if (timeValue == L"night") + { + targetTime = 12500; + } + else if (!TryParseIntValue(timeValue, targetTime)) + { + server->warn(L"Invalid time value: " + timeValue); + return false; + } + + SetAllLevelTimes(server, targetTime); + server->info(L"Time set to " + _toString(targetTime) + L"."); + return true; + } + + if (action == L"weather") + { + if (tokens.size() < 2) + { + server->warn(L"Usage: weather [seconds]"); + return false; + } + + int durationSeconds = 600; + if (tokens.size() >= 3 && !TryParseIntValue(tokens[2], durationSeconds)) + { + server->warn(L"Invalid duration: " + tokens[2]); + return false; + } + + if (server->levels[0] == NULL) + { + server->warn(L"The overworld is not loaded."); + return false; + } + + LevelData *levelData = server->levels[0]->getLevelData(); + int duration = durationSeconds * SharedConstants::TICKS_PER_SECOND; + levelData->setRainTime(duration); + levelData->setThunderTime(duration); + + wstring weather = toLower(tokens[1]); + if (weather == L"clear") + { + levelData->setRaining(false); + levelData->setThundering(false); + } + else if (weather == L"rain") + { + levelData->setRaining(true); + levelData->setThundering(false); + } + else if (weather == L"thunder") + { + levelData->setRaining(true); + levelData->setThundering(true); + } + else + { + server->warn(L"Usage: weather [seconds]"); + return false; + } + + server->info(L"Weather set to " + weather + L"."); + return true; + } + + if (action == L"tp" || action == L"teleport") + { + if (tokens.size() < 3) + { + server->warn(L"Usage: tp "); + return false; + } + + shared_ptr subject = FindPlayerByName(playerList, tokens[1]); + shared_ptr destination = FindPlayerByName(playerList, tokens[2]); + if (subject == NULL) + { + server->warn(L"Unknown player: " + tokens[1]); + return false; + } + if (destination == NULL) + { + server->warn(L"Unknown player: " + tokens[2]); + return false; + } + if (subject->level->dimension->id != destination->level->dimension->id || !subject->isAlive()) + { + server->warn(L"Teleport failed because the players are not in the same dimension or the source player is dead."); + return false; + } + + subject->ride(nullptr); + subject->connection->teleport(destination->x, destination->y, destination->z, destination->yRot, destination->xRot); + server->info(L"Teleported " + subject->getName() + L" to " + destination->getName() + L"."); + return true; + } + + if (action == L"give") + { + if (tokens.size() < 3) + { + server->warn(L"Usage: give [amount] [aux]"); + return false; + } + + shared_ptr player = FindPlayerByName(playerList, tokens[1]); + if (player == NULL) + { + server->warn(L"Unknown player: " + tokens[1]); + return false; + } + + int itemId = 0; + int amount = 1; + int aux = 0; + if (!TryParseIntValue(tokens[2], itemId)) + { + server->warn(L"Invalid item id: " + tokens[2]); + return false; + } + if (tokens.size() >= 4 && !TryParseIntValue(tokens[3], amount)) + { + server->warn(L"Invalid amount: " + tokens[3]); + return false; + } + if (tokens.size() >= 5 && !TryParseIntValue(tokens[4], aux)) + { + server->warn(L"Invalid aux value: " + tokens[4]); + return false; + } + if (itemId <= 0 || Item::items[itemId] == NULL) + { + server->warn(L"Unknown item id: " + _toString(itemId)); + return false; + } + if (amount <= 0) + { + server->warn(L"Amount must be positive."); + return false; + } + + shared_ptr itemInstance(new ItemInstance(itemId, amount, aux)); + shared_ptr drop = player->drop(itemInstance); + if (drop != NULL) + { + drop->throwTime = 0; + } + server->info(L"Gave item " + _toString(itemId) + L" x" + _toString(amount) + L" to " + player->getName() + L"."); + return true; + } + + if (action == L"enchant") + { + if (tokens.size() < 3) + { + server->warn(L"Usage: enchant [level]"); + return false; + } + + shared_ptr player = FindPlayerByName(playerList, tokens[1]); + if (player == NULL) + { + server->warn(L"Unknown player: " + tokens[1]); + return false; + } + + int enchantmentId = 0; + int enchantmentLevel = 1; + if (!TryParseIntValue(tokens[2], enchantmentId)) + { + server->warn(L"Invalid enchantment id: " + tokens[2]); + return false; + } + if (tokens.size() >= 4 && !TryParseIntValue(tokens[3], enchantmentLevel)) + { + server->warn(L"Invalid enchantment level: " + tokens[3]); + return false; + } + + shared_ptr selectedItem = player->getSelectedItem(); + if (selectedItem == NULL) + { + server->warn(L"The player is not holding an item."); + return false; + } + + Enchantment *enchantment = Enchantment::enchantments[enchantmentId]; + if (enchantment == NULL) + { + server->warn(L"Unknown enchantment id: " + _toString(enchantmentId)); + return false; + } + if (!enchantment->canEnchant(selectedItem)) + { + server->warn(L"That enchantment cannot be applied to the selected item."); + return false; + } + + if (enchantmentLevel < enchantment->getMinLevel()) enchantmentLevel = enchantment->getMinLevel(); + if (enchantmentLevel > enchantment->getMaxLevel()) enchantmentLevel = enchantment->getMaxLevel(); + + if (selectedItem->hasTag()) + { + ListTag *enchantmentTags = selectedItem->getEnchantmentTags(); + if (enchantmentTags != NULL) + { + for (int i = 0; i < enchantmentTags->size(); i++) + { + int type = enchantmentTags->get(i)->getShort((wchar_t *)ItemInstance::TAG_ENCH_ID); + if (Enchantment::enchantments[type] != NULL && !Enchantment::enchantments[type]->isCompatibleWith(enchantment)) + { + server->warn(L"That enchantment conflicts with an existing enchantment on the selected item."); + return false; + } + } + } + } + + selectedItem->enchant(enchantment, enchantmentLevel); + server->info(L"Enchanted " + player->getName() + L"'s held item with " + _toString(enchantmentId) + L" " + _toString(enchantmentLevel) + L"."); + return true; + } + + if (action == L"kill") + { + if (tokens.size() < 2) + { + server->warn(L"Usage: kill "); + return false; + } + + shared_ptr player = FindPlayerByName(playerList, tokens[1]); + if (player == NULL) + { + server->warn(L"Unknown player: " + tokens[1]); + return false; + } + + player->hurt(DamageSource::outOfWorld, 3.4e38f); + server->info(L"Killed " + player->getName() + L"."); + return true; + } + + server->warn(L"Unknown command: " + command); + return false; +} + MinecraftServer::MinecraftServer() { // 4J - added initialisers @@ -107,12 +544,14 @@ MinecraftServer::MinecraftServer() forceGameType = false; commandDispatcher = new ServerCommandDispatcher(); + InitializeCriticalSection(&m_consoleInputCS); DispenserBootstrap::bootStrap(); } MinecraftServer::~MinecraftServer() { + DeleteCriticalSection(&m_consoleInputCS); } bool MinecraftServer::initServer(__int64 seed, NetworkGameInitData *initData, DWORD initSettings, bool findSeed) @@ -150,6 +589,15 @@ bool MinecraftServer::initServer(__int64 seed, NetworkGameInitData *initData, DW #endif settings = new Settings(new File(L"server.properties")); + app.SetGameHostOption(eGameHostOption_Difficulty, settings->getInt(L"difficulty", app.GetGameHostOption(eGameHostOption_Difficulty))); + app.SetGameHostOption(eGameHostOption_GameType, settings->getInt(L"gamemode", app.GetGameHostOption(eGameHostOption_GameType))); + app.SetGameHostOption(eGameHostOption_Structures, settings->getBoolean(L"generate-structures", app.GetGameHostOption(eGameHostOption_Structures) > 0) ? 1 : 0); + app.SetGameHostOption(eGameHostOption_BonusChest, settings->getBoolean(L"bonus-chest", app.GetGameHostOption(eGameHostOption_BonusChest) > 0) ? 1 : 0); + app.SetGameHostOption(eGameHostOption_PvP, settings->getBoolean(L"pvp", app.GetGameHostOption(eGameHostOption_PvP) > 0) ? 1 : 0); + app.SetGameHostOption(eGameHostOption_TrustPlayers, settings->getBoolean(L"trust-players", app.GetGameHostOption(eGameHostOption_TrustPlayers) > 0) ? 1 : 0); + app.SetGameHostOption(eGameHostOption_FireSpreads, settings->getBoolean(L"fire-spreads", app.GetGameHostOption(eGameHostOption_FireSpreads) > 0) ? 1 : 0); + app.SetGameHostOption(eGameHostOption_TNT, settings->getBoolean(L"tnt", app.GetGameHostOption(eGameHostOption_TNT) > 0) ? 1 : 0); + app.DebugPrintf("\n*** SERVER SETTINGS ***\n"); app.DebugPrintf("ServerSettings: host-friends-only is %s\n",(app.GetGameHostOption(eGameHostOption_FriendsOfFriends)>0)?"on":"off"); app.DebugPrintf("ServerSettings: game-type is %s\n",(app.GetGameHostOption(eGameHostOption_GameType)==0)?"Survival Mode":"Creative Mode"); @@ -169,11 +617,11 @@ bool MinecraftServer::initServer(__int64 seed, NetworkGameInitData *initData, DW setAnimals(settings->getBoolean(L"spawn-animals", true)); setNpcsEnabled(settings->getBoolean(L"spawn-npcs", true)); - setPvpAllowed(app.GetGameHostOption( eGameHostOption_PvP )>0?true:false); // settings->getBoolean(L"pvp", true); + setPvpAllowed(app.GetGameHostOption( eGameHostOption_PvP )>0?true:false); // 4J Stu - We should never have hacked clients flying when they shouldn't be like the PC version, so enable flying always // Fix for #46612 - TU5: Code: Multiplayer: A client can be banned for flying when accidentaly being blown by dynamite - setFlightAllowed(true); //settings->getBoolean(L"allow-flight", false); + setFlightAllowed(settings->getBoolean(L"allow-flight", true)); // 4J Stu - Enabling flight to stop it kicking us when we use it #ifdef _DEBUG_MENUS_ENABLED @@ -1707,17 +2155,23 @@ void MinecraftServer::tick() void MinecraftServer::handleConsoleInput(const wstring& msg, ConsoleInputSource *source) { + EnterCriticalSection(&m_consoleInputCS); consoleInput.push_back(new ConsoleInput(msg, source)); + LeaveCriticalSection(&m_consoleInputCS); } void MinecraftServer::handleConsoleInputs() { - while (consoleInput.size() > 0) + vector pendingInputs; + EnterCriticalSection(&m_consoleInputCS); + pendingInputs.swap(consoleInput); + LeaveCriticalSection(&m_consoleInputCS); + + for (size_t i = 0; i < pendingInputs.size(); ++i) { - AUTO_VAR(it, consoleInput.begin()); - ConsoleInput *input = *it; - consoleInput.erase(it); - // commands->handleCommand(input); // 4J - removed - TODO - do we want equivalent of console commands? + ConsoleInput *input = pendingInputs[i]; + ExecuteConsoleCommand(this, input->msg); + delete input; } } @@ -1750,10 +2204,12 @@ File *MinecraftServer::getFile(const wstring& name) void MinecraftServer::info(const wstring& string) { + PrintConsoleLine(L"[INFO] ", string); } void MinecraftServer::warn(const wstring& string) { + PrintConsoleLine(L"[WARN] ", string); } wstring MinecraftServer::getConsoleName() diff --git a/Minecraft.Client/MinecraftServer.h b/Minecraft.Client/MinecraftServer.h index 5f33fa85..ec0218e0 100644 --- a/Minecraft.Client/MinecraftServer.h +++ b/Minecraft.Client/MinecraftServer.h @@ -103,6 +103,7 @@ private: // vector tickables = new ArrayList(); // 4J - removed CommandDispatcher *commandDispatcher; vector consoleInput; // 4J - was synchronizedList - TODO - investigate + CRITICAL_SECTION m_consoleInputCS; public: bool onlineMode; bool animals; diff --git a/Minecraft.Client/Settings.cpp b/Minecraft.Client/Settings.cpp index 89946773..4223b001 100644 --- a/Minecraft.Client/Settings.cpp +++ b/Minecraft.Client/Settings.cpp @@ -1,18 +1,90 @@ #include "stdafx.h" #include "Settings.h" +#include "..\Minecraft.World\File.h" #include "..\Minecraft.World\StringHelpers.h" +#include + +static wstring ParsePropertyText(const string &text) +{ + return trimString(convStringToWstring(text)); +} + +static bool TryParseBoolean(const wstring &text, bool defaultValue) +{ + wstring lowered = toLower(trimString(text)); + if (lowered == L"true" || lowered == L"1" || lowered == L"yes" || lowered == L"on") + return true; + if (lowered == L"false" || lowered == L"0" || lowered == L"no" || lowered == L"off") + return false; + return defaultValue; +} -// 4J - TODO - serialise/deserialise from file Settings::Settings(File *file) { + if (file != NULL) + { + filePath = file->getPath(); + } + + if (filePath.empty()) + return; + + std::ifstream stream(wstringtofilename(filePath), std::ios::in | std::ios::binary); + if (!stream.is_open()) + return; + + string line; + while (std::getline(stream, line)) + { + if (!line.empty() && line[line.size() - 1] == '\r') + line.erase(line.size() - 1); + + if (line.size() >= 3 && + (unsigned char)line[0] == 0xEF && + (unsigned char)line[1] == 0xBB && + (unsigned char)line[2] == 0xBF) + { + line.erase(0, 3); + } + + size_t commentPos = line.find_first_of("#;"); + if (commentPos != string::npos && line.find_first_not_of(" \t") == commentPos) + continue; + + size_t separatorPos = line.find('='); + if (separatorPos == string::npos) + continue; + + wstring key = ParsePropertyText(line.substr(0, separatorPos)); + if (key.empty()) + continue; + + wstring value = ParsePropertyText(line.substr(separatorPos + 1)); + properties[key] = value; + } } void Settings::generateNewProperties() { + saveProperties(); } void Settings::saveProperties() { + if (filePath.empty()) + return; + + std::ofstream stream(wstringtofilename(filePath), std::ios::out | std::ios::binary | std::ios::trunc); + if (!stream.is_open()) + return; + + stream << "# MinecraftConsoles dedicated server properties\r\n"; + for (unordered_map::const_iterator it = properties.begin(); it != properties.end(); ++it) + { + string key = string(wstringtochararray(it->first)); + string value = string(wstringtochararray(it->second)); + stream << key << "=" << value << "\r\n"; + } } wstring Settings::getString(const wstring& key, const wstring& defaultValue) @@ -39,17 +111,17 @@ bool Settings::getBoolean(const wstring& key, bool defaultValue) { if(properties.find(key) == properties.end()) { - properties[key] = _toString(defaultValue); + properties[key] = defaultValue ? L"true" : L"false"; saveProperties(); } MemSect(35); - bool retval = _fromString(properties[key]); + bool retval = TryParseBoolean(properties[key], defaultValue); MemSect(0); return retval; } void Settings::setBooleanAndSave(const wstring& key, bool value) { - properties[key] = _toString(value); + properties[key] = value ? L"true" : L"false"; saveProperties(); } \ No newline at end of file diff --git a/Minecraft.Client/Settings.h b/Minecraft.Client/Settings.h index b6a2c018..4a3c130b 100644 --- a/Minecraft.Client/Settings.h +++ b/Minecraft.Client/Settings.h @@ -7,8 +7,8 @@ class Settings // public static Logger logger = Logger.getLogger("Minecraft"); // private Properties properties = new Properties(); private: - unordered_map properties; // 4J - TODO was Properties type, will need to implement something we can serialise/deserialise too - //File *file; + unordered_map properties; + wstring filePath; public: Settings(File *file); @@ -18,4 +18,4 @@ public: int getInt(const wstring& key, int defaultValue); bool getBoolean(const wstring& key, bool defaultValue); void setBooleanAndSave(const wstring& key, bool value); -}; +}; \ No newline at end of file diff --git a/Minecraft.Client/Windows64/Network/WinsockNetLayer.cpp b/Minecraft.Client/Windows64/Network/WinsockNetLayer.cpp index d3ea1c3a..ca1d62af 100644 --- a/Minecraft.Client/Windows64/Network/WinsockNetLayer.cpp +++ b/Minecraft.Client/Windows64/Network/WinsockNetLayer.cpp @@ -51,6 +51,9 @@ bool g_Win64MultiplayerHost = false; bool g_Win64MultiplayerJoin = false; int g_Win64MultiplayerPort = WIN64_NET_DEFAULT_PORT; char g_Win64MultiplayerIP[256] = "127.0.0.1"; +bool g_Win64DedicatedServer = false; +int g_Win64DedicatedServerPort = WIN64_NET_DEFAULT_PORT; +char g_Win64DedicatedServerBindIP[256] = ""; bool WinsockNetLayer::Initialize() { @@ -139,7 +142,7 @@ void WinsockNetLayer::Shutdown() } } -bool WinsockNetLayer::HostGame(int port) +bool WinsockNetLayer::HostGame(int port, const char* bindIp) { if (!s_initialized && !Initialize()) return false; @@ -159,15 +162,19 @@ bool WinsockNetLayer::HostGame(int port) hints.ai_family = AF_INET; hints.ai_socktype = SOCK_STREAM; hints.ai_protocol = IPPROTO_TCP; - hints.ai_flags = AI_PASSIVE; + hints.ai_flags = (bindIp == NULL || bindIp[0] == 0) ? AI_PASSIVE : 0; char portStr[16]; sprintf_s(portStr, "%d", port); - int iResult = getaddrinfo(NULL, portStr, &hints, &result); + const char* resolvedBindIp = (bindIp != NULL && bindIp[0] != 0) ? bindIp : NULL; + int iResult = getaddrinfo(resolvedBindIp, portStr, &hints, &result); if (iResult != 0) { - app.DebugPrintf("getaddrinfo failed: %d\n", iResult); + app.DebugPrintf("getaddrinfo failed for %s:%d - %d\n", + resolvedBindIp != NULL ? resolvedBindIp : "*", + port, + iResult); return false; } @@ -206,7 +213,9 @@ bool WinsockNetLayer::HostGame(int port) s_acceptThread = CreateThread(NULL, 0, AcceptThreadProc, NULL, 0, NULL); - app.DebugPrintf("Win64 LAN: Hosting on port %d\n", port); + app.DebugPrintf("Win64 LAN: Hosting on %s:%d\n", + resolvedBindIp != NULL ? resolvedBindIp : "*", + port); return true; } @@ -908,4 +917,4 @@ DWORD WINAPI WinsockNetLayer::DiscoveryThreadProc(LPVOID param) return 0; } -#endif \ No newline at end of file +#endif diff --git a/Minecraft.Client/Windows64/Network/WinsockNetLayer.h b/Minecraft.Client/Windows64/Network/WinsockNetLayer.h index 029dd0a7..fd1280f7 100644 --- a/Minecraft.Client/Windows64/Network/WinsockNetLayer.h +++ b/Minecraft.Client/Windows64/Network/WinsockNetLayer.h @@ -65,7 +65,7 @@ public: static bool Initialize(); static void Shutdown(); - static bool HostGame(int port); + static bool HostGame(int port, const char* bindIp = NULL); static bool JoinGame(const char* ip, int port); static bool SendToSmallId(BYTE targetSmallId, const void* data, int dataSize); @@ -147,5 +147,8 @@ extern bool g_Win64MultiplayerHost; extern bool g_Win64MultiplayerJoin; extern int g_Win64MultiplayerPort; extern char g_Win64MultiplayerIP[256]; +extern bool g_Win64DedicatedServer; +extern int g_Win64DedicatedServerPort; +extern char g_Win64DedicatedServerBindIP[256]; #endif diff --git a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp index 3d5eec00..ed6781a3 100644 --- a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp +++ b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp @@ -4,7 +4,9 @@ #include "stdafx.h" #include +#include #include +#include #include "GameConfig\Minecraft.spa.h" #include "..\MinecraftServer.h" #include "..\LocalPlayer.h" @@ -34,6 +36,7 @@ #include "Sentient\SentientManager.h" #include "..\..\Minecraft.World\IntCache.h" #include "..\Textures.h" +#include "..\Settings.h" #include "Resource.h" #include "..\..\Minecraft.World\compression.h" #include "..\..\Minecraft.World\OldChunkStorage.h" @@ -95,6 +98,148 @@ wchar_t g_Win64UsernameW[17] = { 0 }; static bool g_isFullscreen = false; static WINDOWPLACEMENT g_wpPrev = { sizeof(g_wpPrev) }; +struct Win64LaunchOptions +{ + int screenMode; + bool serverMode; +}; + +static void CopyWideArgToAnsi(LPCWSTR source, char* dest, size_t destSize) +{ + if (destSize == 0) + return; + + dest[0] = 0; + if (source == NULL) + return; + + WideCharToMultiByte(CP_ACP, 0, source, -1, dest, (int)destSize, NULL, NULL); + dest[destSize - 1] = 0; +} + +static void ApplyScreenMode(int screenMode) +{ + switch (screenMode) + { + case 1: + g_iScreenWidth = 1280; + g_iScreenHeight = 720; + break; + case 2: + g_iScreenWidth = 640; + g_iScreenHeight = 480; + break; + case 3: + g_iScreenWidth = 720; + g_iScreenHeight = 408; + break; + default: + break; + } +} + +static Win64LaunchOptions ParseLaunchOptions() +{ + Win64LaunchOptions options = {}; + options.screenMode = 0; + options.serverMode = false; + + g_Win64MultiplayerJoin = false; + g_Win64MultiplayerPort = WIN64_NET_DEFAULT_PORT; + g_Win64DedicatedServer = false; + g_Win64DedicatedServerPort = WIN64_NET_DEFAULT_PORT; + g_Win64DedicatedServerBindIP[0] = 0; + + int argc = 0; + LPWSTR* argv = CommandLineToArgvW(GetCommandLineW(), &argc); + if (argv == NULL) + return options; + + if (argc > 1 && lstrlenW(argv[1]) == 1) + { + if (argv[1][0] >= L'1' && argv[1][0] <= L'3') + options.screenMode = argv[1][0] - L'0'; + } + + for (int i = 1; i < argc; ++i) + { + if (_wcsicmp(argv[i], L"-server") == 0) + { + options.serverMode = true; + break; + } + } + + g_Win64DedicatedServer = options.serverMode; + + for (int i = 1; i < argc; ++i) + { + if (_wcsicmp(argv[i], L"-name") == 0 && (i + 1) < argc) + { + CopyWideArgToAnsi(argv[++i], g_Win64Username, sizeof(g_Win64Username)); + } + else if (_wcsicmp(argv[i], L"-ip") == 0 && (i + 1) < argc) + { + char ipBuf[256]; + CopyWideArgToAnsi(argv[++i], ipBuf, sizeof(ipBuf)); + if (options.serverMode) + { + strncpy_s(g_Win64DedicatedServerBindIP, sizeof(g_Win64DedicatedServerBindIP), ipBuf, _TRUNCATE); + } + else + { + strncpy_s(g_Win64MultiplayerIP, sizeof(g_Win64MultiplayerIP), ipBuf, _TRUNCATE); + g_Win64MultiplayerJoin = true; + } + } + else if (_wcsicmp(argv[i], L"-port") == 0 && (i + 1) < argc) + { + wchar_t* endPtr = NULL; + long port = wcstol(argv[++i], &endPtr, 10); + if (endPtr != argv[i] && *endPtr == 0 && port > 0 && port <= 65535) + { + if (options.serverMode) + g_Win64DedicatedServerPort = (int)port; + else + g_Win64MultiplayerPort = (int)port; + } + } + } + + LocalFree(argv); + return options; +} + +static BOOL WINAPI HeadlessServerCtrlHandler(DWORD ctrlType) +{ + switch (ctrlType) + { + case CTRL_C_EVENT: + case CTRL_BREAK_EVENT: + case CTRL_CLOSE_EVENT: + case CTRL_SHUTDOWN_EVENT: + app.m_bShutdown = true; + MinecraftServer::HaltServer(); + return TRUE; + default: + return FALSE; + } +} + +static void SetupHeadlessServerConsole() +{ + if (AllocConsole()) + { + FILE* stream = NULL; + freopen_s(&stream, "CONIN$", "r", stdin); + freopen_s(&stream, "CONOUT$", "w", stdout); + freopen_s(&stream, "CONOUT$", "w", stderr); + SetConsoleTitleA("Minecraft Server"); + } + + SetConsoleCtrlHandler(HeadlessServerCtrlHandler, TRUE); +} + void DefineActions(void) { // The app needs to define the actions required, and the possible mappings for these @@ -722,6 +867,225 @@ void CleanupDevice() if( g_pd3dDevice ) g_pd3dDevice->Release(); } +static Minecraft* InitialiseMinecraftRuntime() +{ + app.loadMediaArchive(); + + RenderManager.Initialise(g_pd3dDevice, g_pSwapChain); + + app.loadStringTable(); + ui.init(g_pd3dDevice, g_pImmediateContext, g_pRenderTargetView, g_pDepthStencilView, g_iScreenWidth, g_iScreenHeight); + + InputManager.Initialise(1, 3, MINECRAFT_ACTION_MAX, ACTION_MAX_MENU); + KMInput.Init(g_hWnd); + DefineActions(); + InputManager.SetJoypadMapVal(0, 0); + InputManager.SetKeyRepeatRate(0.3f, 0.2f); + + ProfileManager.Initialise(TITLEID_MINECRAFT, + app.m_dwOfferID, + PROFILE_VERSION_10, + NUM_PROFILE_VALUES, + NUM_PROFILE_SETTINGS, + dwProfileSettingsA, + app.GAME_DEFINED_PROFILE_DATA_BYTES * XUSER_MAX_COUNT, + &app.uiGameDefinedDataChangedBitmask + ); + ProfileManager.SetDefaultOptionsCallback(&CConsoleMinecraftApp::DefaultOptionsCallback, (LPVOID)&app); + + g_NetworkManager.Initialise(); + + for (int i = 0; i < MINECRAFT_NET_MAX_PLAYERS; i++) + { + IQNet::m_player[i].m_smallId = (BYTE)i; + IQNet::m_player[i].m_isRemote = false; + IQNet::m_player[i].m_isHostPlayer = (i == 0); + swprintf_s(IQNet::m_player[i].m_gamertag, 32, L"Player%d", i); + } + wcscpy_s(IQNet::m_player[0].m_gamertag, 32, g_Win64UsernameW); + + WinsockNetLayer::Initialize(); + + ProfileManager.SetDebugFullOverride(true); + + Tesselator::CreateNewThreadStorage(1024 * 1024); + AABB::CreateNewThreadStorage(); + Vec3::CreateNewThreadStorage(); + IntCache::CreateNewThreadStorage(); + Compression::CreateNewThreadStorage(); + OldChunkStorage::CreateNewThreadStorage(); + Level::enableLightingCache(); + Tile::CreateNewThreadStorage(); + + Minecraft::main(); + Minecraft* pMinecraft = Minecraft::GetInstance(); + if (pMinecraft == NULL) + return NULL; + + app.InitGameSettings(); + app.InitialiseTips(); + + pMinecraft->options->set(Options::Option::MUSIC, 1.0f); + pMinecraft->options->set(Options::Option::SOUND, 1.0f); + + return pMinecraft; +} + +static int HeadlessServerConsoleThreadProc(void* lpParameter) +{ + UNREFERENCED_PARAMETER(lpParameter); + + std::string line; + while (!app.m_bShutdown) + { + if (!std::getline(std::cin, line)) + { + if (std::cin.eof()) + { + break; + } + + std::cin.clear(); + Sleep(50); + continue; + } + + wstring command = trimString(convStringToWstring(line)); + if (command.empty()) + continue; + + MinecraftServer* server = MinecraftServer::getInstance(); + if (server != NULL) + { + server->handleConsoleInput(command, server); + } + } + + return 0; +} + +static int RunHeadlessServer() +{ + SetupHeadlessServerConsole(); + + Settings serverSettings(new File(L"server.properties")); + wstring configuredBindIp = serverSettings.getString(L"server-ip", L""); + + const char* bindIp = "*"; + if (g_Win64DedicatedServerBindIP[0] != 0) + { + bindIp = g_Win64DedicatedServerBindIP; + } + else if (!configuredBindIp.empty()) + { + bindIp = wstringtochararray(configuredBindIp); + } + + const int port = g_Win64DedicatedServerPort > 0 ? g_Win64DedicatedServerPort : serverSettings.getInt(L"server-port", WIN64_NET_DEFAULT_PORT); + + printf("Starting headless server on %s:%d\n", bindIp, port); + fflush(stdout); + + Minecraft* pMinecraft = InitialiseMinecraftRuntime(); + if (pMinecraft == NULL) + { + fprintf(stderr, "Failed to initialise the Minecraft runtime.\n"); + return 1; + } + + app.SetGameHostOption(eGameHostOption_Difficulty, serverSettings.getInt(L"difficulty", 1)); + app.SetGameHostOption(eGameHostOption_Gamertags, 1); + app.SetGameHostOption(eGameHostOption_GameType, serverSettings.getInt(L"gamemode", 0)); + app.SetGameHostOption(eGameHostOption_LevelType, 0); + app.SetGameHostOption(eGameHostOption_Structures, serverSettings.getBoolean(L"generate-structures", true) ? 1 : 0); + app.SetGameHostOption(eGameHostOption_BonusChest, serverSettings.getBoolean(L"bonus-chest", false) ? 1 : 0); + app.SetGameHostOption(eGameHostOption_PvP, serverSettings.getBoolean(L"pvp", true) ? 1 : 0); + app.SetGameHostOption(eGameHostOption_TrustPlayers, serverSettings.getBoolean(L"trust-players", true) ? 1 : 0); + app.SetGameHostOption(eGameHostOption_FireSpreads, serverSettings.getBoolean(L"fire-spreads", true) ? 1 : 0); + app.SetGameHostOption(eGameHostOption_TNT, serverSettings.getBoolean(L"tnt", true) ? 1 : 0); + app.SetGameHostOption(eGameHostOption_HostCanFly, 1); + app.SetGameHostOption(eGameHostOption_HostCanChangeHunger, 1); + app.SetGameHostOption(eGameHostOption_HostCanBeInvisible, 1); + app.SetGameHostOption(eGameHostOption_MobGriefing, 1); + app.SetGameHostOption(eGameHostOption_KeepInventory, 0); + app.SetGameHostOption(eGameHostOption_DoMobSpawning, 1); + app.SetGameHostOption(eGameHostOption_DoMobLoot, 1); + app.SetGameHostOption(eGameHostOption_DoTileDrops, 1); + app.SetGameHostOption(eGameHostOption_NaturalRegeneration, 1); + app.SetGameHostOption(eGameHostOption_DoDaylightCycle, 1); + + MinecraftServer::resetFlags(); + g_NetworkManager.HostGame(0, false, true, MINECRAFT_NET_MAX_PLAYERS, 0); + + if (!WinsockNetLayer::IsActive()) + { + fprintf(stderr, "Failed to bind the server socket on %s:%d.\n", bindIp, port); + return 1; + } + + g_NetworkManager.FakeLocalPlayerJoined(); + + NetworkGameInitData* param = new NetworkGameInitData(); + param->seed = 0; + param->settings = app.GetGameHostOption(eGameHostOption_All); + + g_NetworkManager.ServerStoppedCreate(true); + g_NetworkManager.ServerReadyCreate(true); + + C4JThread* thread = new C4JThread(&CGameNetworkManager::ServerThreadProc, param, "Server", 256 * 1024); + thread->SetProcessor(CPU_CORE_SERVER); + thread->Run(); + + g_NetworkManager.ServerReadyWait(); + g_NetworkManager.ServerReadyDestroy(); + + if (MinecraftServer::serverHalted()) + { + fprintf(stderr, "The server halted during startup.\n"); + g_NetworkManager.LeaveGame(false); + return 1; + } + + app.SetGameStarted(true); + g_NetworkManager.DoWork(); + + printf("Server ready on %s:%d\n", bindIp, port); + printf("Type 'help' for server commands.\n"); + fflush(stdout); + + C4JThread* consoleThread = new C4JThread(&HeadlessServerConsoleThreadProc, NULL, "Server console", 128 * 1024); + consoleThread->Run(); + + MSG msg = { 0 }; + while (WM_QUIT != msg.message && !app.m_bShutdown && !MinecraftServer::serverHalted()) + { + if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + continue; + } + + app.UpdateTime(); + ProfileManager.Tick(); + StorageManager.Tick(); + RenderManager.Tick(); + ui.tick(); + g_NetworkManager.DoWork(); + app.HandleXuiActions(); + + Sleep(10); + } + + printf("Stopping server...\n"); + fflush(stdout); + + app.m_bShutdown = true; + MinecraftServer::HaltServer(); + g_NetworkManager.LeaveGame(false); + return 0; +} + int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPTSTR lpCmdLine, @@ -742,70 +1106,8 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, SetProcessDPIAware(); g_iScreenWidth = GetSystemMetrics(SM_CXSCREEN); g_iScreenHeight = GetSystemMetrics(SM_CYSCREEN); - - if(lpCmdLine) - { - if(lpCmdLine[0] == '1') - { - g_iScreenWidth = 1280; - g_iScreenHeight = 720; - } - else if(lpCmdLine[0] == '2') - { - g_iScreenWidth = 640; - g_iScreenHeight = 480; - } - else if(lpCmdLine[0] == '3') - { - // Vita - g_iScreenWidth = 720; - g_iScreenHeight = 408; - - // Vita native - //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); - } - - char *ipArg = strstr(cmdLineA, "-ip "); - if (ipArg) - { - ipArg += 4; - while (*ipArg == ' ') ipArg++; - char ipBuf[256]; - int n = 0; - while (ipArg[n] && ipArg[n] != ' ' && n < 255) { ipBuf[n] = ipArg[n]; n++; } - ipBuf[n] = 0; - strncpy_s(g_Win64MultiplayerIP, 256, ipBuf, _TRUNCATE); - g_Win64MultiplayerJoin = true; - } - - char *portArg = strstr(cmdLineA, "-port "); - if (portArg) - { - portArg += 6; - while (*portArg == ' ') portArg++; - char portBuf[16]; - int n = 0; - while (portArg[n] && portArg[n] != ' ' && n < 15) { portBuf[n] = portArg[n]; n++; } - portBuf[n] = 0; - g_Win64MultiplayerPort = atoi(portBuf); - } - } + Win64LaunchOptions launchOptions = ParseLaunchOptions(); + ApplyScreenMode(launchOptions.screenMode); if (g_Win64Username[0] == 0) { @@ -821,7 +1123,7 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, MyRegisterClass(hInstance); // Perform application initialization: - if (!InitInstance (hInstance, nCmdShow)) + if (!InitInstance (hInstance, launchOptions.serverMode ? SW_HIDE : nCmdShow)) { return FALSE; } @@ -834,6 +1136,13 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, return 0; } + if (launchOptions.serverMode) + { + int serverResult = RunHeadlessServer(); + CleanupDevice(); + return serverResult; + } + #if 0 // Main message loop MSG msg = {0}; @@ -886,203 +1195,13 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, } #endif - app.loadMediaArchive(); - - RenderManager.Initialise(g_pd3dDevice, g_pSwapChain); - - app.loadStringTable(); - ui.init(g_pd3dDevice,g_pImmediateContext,g_pRenderTargetView,g_pDepthStencilView,g_iScreenWidth,g_iScreenHeight); - - //////////////// - // Initialise // - //////////////// - - // Set the number of possible joypad layouts that the user can switch between, and the number of actions - InputManager.Initialise(1,3,MINECRAFT_ACTION_MAX, ACTION_MAX_MENU); - - // Initialize keyboard/mouse input - KMInput.Init(g_hWnd); - - // Set the default joypad action mappings for Minecraft - DefineActions(); - InputManager.SetJoypadMapVal(0,0); - InputManager.SetKeyRepeatRate(0.3f,0.2f); - - // Initialise the profile manager with the game Title ID, Offer ID, a profile version number, and the number of profile values and settings - ProfileManager.Initialise(TITLEID_MINECRAFT, - app.m_dwOfferID, - PROFILE_VERSION_10, - NUM_PROFILE_VALUES, - NUM_PROFILE_SETTINGS, - dwProfileSettingsA, - app.GAME_DEFINED_PROFILE_DATA_BYTES*XUSER_MAX_COUNT, - &app.uiGameDefinedDataChangedBitmask - ); -#if 0 - // register the awards - ProfileManager.RegisterAward(eAward_TakingInventory, ACHIEVEMENT_01, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_GettingWood, ACHIEVEMENT_02, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_Benchmarking, ACHIEVEMENT_03, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_TimeToMine, ACHIEVEMENT_04, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_HotTopic, ACHIEVEMENT_05, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_AquireHardware, ACHIEVEMENT_06, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_TimeToFarm, ACHIEVEMENT_07, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_BakeBread, ACHIEVEMENT_08, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_TheLie, ACHIEVEMENT_09, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_GettingAnUpgrade, ACHIEVEMENT_10, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_DeliciousFish, ACHIEVEMENT_11, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_OnARail, ACHIEVEMENT_12, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_TimeToStrike, ACHIEVEMENT_13, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_MonsterHunter, ACHIEVEMENT_14, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_CowTipper, ACHIEVEMENT_15, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_WhenPigsFly, ACHIEVEMENT_16, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_LeaderOfThePack, ACHIEVEMENT_17, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_MOARTools, ACHIEVEMENT_18, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_DispenseWithThis, ACHIEVEMENT_19, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_InToTheNether, ACHIEVEMENT_20, eAwardType_Achievement); - - ProfileManager.RegisterAward(eAward_mine100Blocks, GAMER_PICTURE_GAMERPIC1, eAwardType_GamerPic,false,app.GetStringTable(),IDS_AWARD_TITLE,IDS_AWARD_GAMERPIC1,IDS_CONFIRM_OK); - ProfileManager.RegisterAward(eAward_kill10Creepers, GAMER_PICTURE_GAMERPIC2, eAwardType_GamerPic,false,app.GetStringTable(),IDS_AWARD_TITLE,IDS_AWARD_GAMERPIC2,IDS_CONFIRM_OK); - - ProfileManager.RegisterAward(eAward_eatPorkChop, AVATARASSETAWARD_PORKCHOP_TSHIRT, eAwardType_AvatarItem,false,app.GetStringTable(),IDS_AWARD_TITLE,IDS_AWARD_AVATAR1,IDS_CONFIRM_OK); - ProfileManager.RegisterAward(eAward_play100Days, AVATARASSETAWARD_WATCH, eAwardType_AvatarItem,false,app.GetStringTable(),IDS_AWARD_TITLE,IDS_AWARD_AVATAR2,IDS_CONFIRM_OK); - ProfileManager.RegisterAward(eAward_arrowKillCreeper, AVATARASSETAWARD_CAP, eAwardType_AvatarItem,false,app.GetStringTable(),IDS_AWARD_TITLE,IDS_AWARD_AVATAR3,IDS_CONFIRM_OK); - - ProfileManager.RegisterAward(eAward_socialPost, 0, eAwardType_Theme,false,app.GetStringTable(),IDS_AWARD_TITLE,IDS_AWARD_THEME,IDS_CONFIRM_OK,THEME_NAME,THEME_FILESIZE); - - // Rich Presence init - number of presences, number of contexts - ProfileManager.RichPresenceInit(4,1); - ProfileManager.RegisterRichPresenceContext(CONTEXT_GAME_STATE); - - // initialise the storage manager with a default save display name, a Minimum save size, and a callback for displaying the saving message - StorageManager.Init(app.GetString(IDS_DEFAULT_SAVENAME),"savegame.dat",FIFTY_ONE_MB,&CConsoleMinecraftApp::DisplaySavingMessage,(LPVOID)&app); - // Set up the global title storage path - StorageManager.StoreTMSPathName(); - - // set a function to be called when there's a sign in change, so we can exit a level if the primary player signs out - ProfileManager.SetSignInChangeCallback(&CConsoleMinecraftApp::SignInChangeCallback,(LPVOID)&app); - - // set a function to be called when the ethernet is disconnected, so we can back out if required - ProfileManager.SetNotificationsCallback(&CConsoleMinecraftApp::NotificationsCallback,(LPVOID)&app); - -#endif - // Set a callback for the default player options to be set - when there is no profile data for the player - ProfileManager.SetDefaultOptionsCallback(&CConsoleMinecraftApp::DefaultOptionsCallback,(LPVOID)&app); -#if 0 - // Set a callback to deal with old profile versions needing updated to new versions - ProfileManager.SetOldProfileVersionCallback(&CConsoleMinecraftApp::OldProfileVersionCallback,(LPVOID)&app); - - // Set a callback for when there is a read error on profile data - ProfileManager.SetProfileReadErrorCallback(&CConsoleMinecraftApp::ProfileReadErrorCallback,(LPVOID)&app); - -#endif - // QNet needs to be setup after profile manager, as we do not want its Notify listener to handle - // XN_SYS_SIGNINCHANGED notifications. This does mean that we need to have a callback in the - // ProfileManager for XN_LIVE_INVITE_ACCEPTED for QNet. - g_NetworkManager.Initialise(); - - for (int i = 0; i < MINECRAFT_NET_MAX_PLAYERS; i++) + Minecraft *pMinecraft = InitialiseMinecraftRuntime(); + if (pMinecraft == NULL) { - IQNet::m_player[i].m_smallId = (BYTE)i; - IQNet::m_player[i].m_isRemote = false; - 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(); - - // 4J-PB moved further down - //app.InitGameSettings(); - - // debug switch to trial version - ProfileManager.SetDebugFullOverride(true); - -#if 0 - //ProfileManager.AddDLC(2); - StorageManager.SetDLCPackageRoot("DLCDrive"); - StorageManager.RegisterMarketplaceCountsCallback(&CConsoleMinecraftApp::MarketplaceCountsCallback,(LPVOID)&app); - // Kinect ! - - if(XNuiGetHardwareStatus()!=0) - { - // If the Kinect Sensor is not physically connected, this function returns 0. - NuiInitialize(NUI_INITIALIZE_FLAG_USES_HIGH_QUALITY_COLOR | NUI_INITIALIZE_FLAG_USES_DEPTH | - NUI_INITIALIZE_FLAG_EXTRAPOLATE_FLOOR_PLANE | NUI_INITIALIZE_FLAG_USES_FITNESS | NUI_INITIALIZE_FLAG_NUI_GUIDE_DISABLED | NUI_INITIALIZE_FLAG_SUPPRESS_AUTOMATIC_UI,NUI_INITIALIZE_DEFAULT_HARDWARE_THREAD ); + CleanupDevice(); + return 1; } - // Sentient ! - hr = TelemetryManager->Init(); - -#endif - // Initialise TLS for tesselator, for this main thread - Tesselator::CreateNewThreadStorage(1024*1024); - // Initialise TLS for AABB and Vec3 pools, for this main thread - AABB::CreateNewThreadStorage(); - Vec3::CreateNewThreadStorage(); - IntCache::CreateNewThreadStorage(); - Compression::CreateNewThreadStorage(); - OldChunkStorage::CreateNewThreadStorage(); - Level::enableLightingCache(); - Tile::CreateNewThreadStorage(); - - Minecraft::main(); - Minecraft *pMinecraft=Minecraft::GetInstance(); - - app.InitGameSettings(); - -#if 0 - //bool bDisplayPauseMenu=false; - - // set the default gamma level - float fVal=50.0f*327.68f; - RenderManager.UpdateGamma((unsigned short)fVal); - - // load any skins - //app.AddSkinsToMemoryTextureFiles(); - - // set the achievement text for a trial achievement, now we have the string table loaded - ProfileManager.SetTrialTextStringTable(app.GetStringTable(),IDS_CONFIRM_OK, IDS_CONFIRM_CANCEL); - ProfileManager.SetTrialAwardText(eAwardType_Achievement,IDS_UNLOCK_TITLE,IDS_UNLOCK_ACHIEVEMENT_TEXT); - ProfileManager.SetTrialAwardText(eAwardType_GamerPic,IDS_UNLOCK_TITLE,IDS_UNLOCK_GAMERPIC_TEXT); - ProfileManager.SetTrialAwardText(eAwardType_AvatarItem,IDS_UNLOCK_TITLE,IDS_UNLOCK_AVATAR_TEXT); - ProfileManager.SetTrialAwardText(eAwardType_Theme,IDS_UNLOCK_TITLE,IDS_UNLOCK_THEME_TEXT); - ProfileManager.SetUpsellCallback(&app.UpsellReturnedCallback,&app); - - // Set up a debug character press sequence -#ifndef _FINAL_BUILD - app.SetDebugSequence("LRLRYYY"); -#endif - - // Initialise the social networking manager. - CSocialManager::Instance()->Initialise(); - - // Update the base scene quick selects now that the minecraft class exists - //CXuiSceneBase::UpdateScreenSettings(0); -#endif - app.InitialiseTips(); -#if 0 - - DWORD initData=0; - -#ifndef _FINAL_BUILD -#ifndef _DEBUG -#pragma message(__LOC__"Need to define the _FINAL_BUILD before submission") -#endif -#endif - - // Set the default sound levels - pMinecraft->options->set(Options::Option::MUSIC,1.0f); - pMinecraft->options->set(Options::Option::SOUND,1.0f); - - app.NavigateToScene(XUSER_INDEX_ANY,eUIScene_Intro,&initData); -#endif - - // Set the default sound levels - pMinecraft->options->set(Options::Option::MUSIC,1.0f); - pMinecraft->options->set(Options::Option::SOUND,1.0f); - //app.TemporaryCreateGameStart(); //Sleep(10000); @@ -1637,4 +1756,4 @@ void MemPixStuff() PIXAddNamedCounter(((float)allSectsTotal)/(4096.0f),"MemSect total pages"); } -#endif \ No newline at end of file +#endif diff --git a/Minecraft.World/Minecraft.World.vcxproj b/Minecraft.World/Minecraft.World.vcxproj index 58880529..7ab7c4ce 100644 --- a/Minecraft.World/Minecraft.World.vcxproj +++ b/Minecraft.World/Minecraft.World.vcxproj @@ -1257,6 +1257,7 @@ false true Default + /FS %(AdditionalOptions) true @@ -1355,7 +1356,7 @@ true true true - /Ob3 + /FS /Ob3 %(AdditionalOptions) true @@ -4957,4 +4958,4 @@ - \ No newline at end of file + diff --git a/README.md b/README.md index e6583e76..a84ee508 100644 --- a/README.md +++ b/README.md @@ -41,14 +41,22 @@ This feature is based on [LCEMP](https://github.com/LCEMP/LCEMP/) | Argument | Description | |--------------------|----------------------------------------------------------------------------------------------------------------| | `-name ` | Sets your in-game username | -| `-ip
` | Manually connect to an IP if LAN advertising does not work or if the server cannot be discovered automatically | -| `-port ` | Override the default port if it was changed in the source | +| `-server` | Launches a headless server instead of the client | +| `-ip
` | Client mode: manually connect to an IP. Server mode: override the bind IP from `server.properties` | +| `-port ` | Client mode: override the join port. Server mode: override the listen port from `server.properties` | Example: ``` Minecraft.Client.exe -name Steve -ip 192.168.0.25 -port 25565 ``` +Headless server example: +``` +Minecraft.Client.exe -server -ip 0.0.0.0 -port 25565 +``` + +The headless server also reads and writes `server.properties` in the working directory. If `-ip` / `-port` are omitted in `-server` mode, it falls back to `server-ip` / `server-port` from that file. Dedicated-server host options such as `trust-players`, `pvp`, `fire-spreads`, `tnt`, `difficulty`, `gamemode`, `spawn-animals`, and `spawn-npcs` are persisted there as well. + ## Controls (Keyboard & Mouse) - **Movement**: `W` `A` `S` `D` -- cgit v1.2.3