From 76a7d4102a7685ac7106e1559e9f7edc6fd21c59 Mon Sep 17 00:00:00 2001 From: NSDeathman Date: Mon, 9 Mar 2026 17:50:21 +0300 Subject: [PATCH] Fix gamepad hot-plug detection (controller connected after launch now works) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### Problem Currently, the game checks `InputManager.IsPadConnected(0)` once at startup to determine whether a gamepad is available. If a controller is connected after the program has already started, this flag remains `false`, and the input system never switches to gamepad mode — even when buttons or sticks are used. ### Solution Remove the static `IsPadConnected` check from the main input loop. Instead, directly evaluate whether any gamepad input (buttons or stick movements) is present. The underlying input functions (`ButtonPressed`, `GetJoypadStick_...`) safely return `false`/`0.0f` when no controller is connected. Once a gamepad is plugged in and the player uses it, `controllerUsed` becomes `true` and the input mode switches to gamepad as expected. This change: - Eliminates the need for runtime connection polling. - Works with any controller that becomes available after launch. - Simplifies the input‑mode logic. ### Testing Verified that a gamepad connected after the game is running is immediately recognized as soon as a button is pressed. No regressions observed with keyboard/mouse input. --- Minecraft.Client/Common/BuildVer.h | 4 ++-- Minecraft.Client/Minecraft.Client.vcxproj | 3 ++- .../Windows64/Windows64_Minecraft.cpp | 23 +++++++------------ Minecraft.World/Minecraft.World.vcxproj | 3 ++- 4 files changed, 14 insertions(+), 19 deletions(-) diff --git a/Minecraft.Client/Common/BuildVer.h b/Minecraft.Client/Common/BuildVer.h index eaa77d26a..a5a9494ac 100644 --- a/Minecraft.Client/Common/BuildVer.h +++ b/Minecraft.Client/Common/BuildVer.h @@ -1,7 +1,7 @@ #pragma once #define VER_PRODUCTBUILD 560 -#define VER_PRODUCTVERSION_STR_W L"DEV (unknown version)" +#define VER_PRODUCTVERSION_STR_W L"" #define VER_FILEVERSION_STR_W VER_PRODUCTVERSION_STR_W -#define VER_BRANCHVERSION_STR_W L"UNKNOWN BRANCH" +#define VER_BRANCHVERSION_STR_W L"UNKNOWN/" #define VER_NETWORK VER_PRODUCTBUILD diff --git a/Minecraft.Client/Minecraft.Client.vcxproj b/Minecraft.Client/Minecraft.Client.vcxproj index d97cbc383..cb8e15af1 100644 --- a/Minecraft.Client/Minecraft.Client.vcxproj +++ b/Minecraft.Client/Minecraft.Client.vcxproj @@ -235,6 +235,7 @@ SAK Xbox360Proj title + 10.0 @@ -309,7 +310,7 @@ Application MultiByte - v143 + v142 true diff --git a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp index 70aeb22bf..3ab47affc 100644 --- a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp +++ b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp @@ -1806,23 +1806,16 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, InputManager.Tick(); // Detect KBM vs controller input mode - if (InputManager.IsPadConnected(0)) - { - const bool controllerUsed = InputManager.ButtonPressed(0) || - InputManager.GetJoypadStick_LX(0, false) != 0.0f || - InputManager.GetJoypadStick_LY(0, false) != 0.0f || - InputManager.GetJoypadStick_RX(0, false) != 0.0f || - InputManager.GetJoypadStick_RY(0, false) != 0.0f; + const bool controllerUsed = InputManager.ButtonPressed(0) || + InputManager.GetJoypadStick_LX(0, false) != 0.0f || + InputManager.GetJoypadStick_LY(0, false) != 0.0f || + InputManager.GetJoypadStick_RX(0, false) != 0.0f || + InputManager.GetJoypadStick_RY(0, false) != 0.0f; - if (controllerUsed) - g_KBMInput.SetKBMActive(false); - else if (g_KBMInput.HasAnyInput()) - g_KBMInput.SetKBMActive(true); - } - else - { + if (controllerUsed) + g_KBMInput.SetKBMActive(false); + else if (g_KBMInput.HasAnyInput()) g_KBMInput.SetKBMActive(true); - } if (!g_KBMInput.IsMouseGrabbed()) { diff --git a/Minecraft.World/Minecraft.World.vcxproj b/Minecraft.World/Minecraft.World.vcxproj index b6af91538..fb7d00453 100644 --- a/Minecraft.World/Minecraft.World.vcxproj +++ b/Minecraft.World/Minecraft.World.vcxproj @@ -235,6 +235,7 @@ SAK SAK title + 10.0 @@ -306,7 +307,7 @@ StaticLibrary MultiByte - v143 + v142 true