From 13911fcb620754b514427fc72776d2dff508837d Mon Sep 17 00:00:00 2001 From: Jan Date: Thu, 5 May 2022 21:36:27 +0200 Subject: [PATCH] Whenever a gamepad button is rebound with a menu bind field, set the button config to custom so gamepad config shows a changed button layout --- src/Components/Modules/Gamepad.cpp | 13 +++++++++++++ src/Components/Modules/Gamepad.hpp | 1 + src/Game/Functions.cpp | 1 + src/Game/Functions.hpp | 3 +++ 4 files changed, 18 insertions(+) diff --git a/src/Components/Modules/Gamepad.cpp b/src/Components/Modules/Gamepad.cpp index 3cad580b..fa97f155 100644 --- a/src/Components/Modules/Gamepad.cpp +++ b/src/Components/Modules/Gamepad.cpp @@ -1846,6 +1846,14 @@ namespace Components } } + void Gamepad::Key_SetBinding_Hk(const int localClientNum, const int keyNum, const char* binding) + { + if(Key_IsValidGamePadChar(keyNum)) + gpad_buttonConfig.set("custom"); + + Game::Key_SetBinding(localClientNum, keyNum, binding); + } + void Gamepad::CL_KeyEvent_Hk(const int localClientNum, const int key, const int down, const unsigned time) { // A keyboard key has been pressed. Mark controller as unused. @@ -1984,6 +1992,11 @@ namespace Components // Only return gamepad keys when gamepad enabled and only non gamepad keys when not Utils::Hook(0x5A7890, Key_GetCommandAssignmentInternal_Stub, HOOK_JUMP).install()->quick(); + // Whenever a key binding for a gamepad key is replaced update the button config + Utils::Hook(0x47D473, Key_SetBinding_Hk, HOOK_CALL).install()->quick(); + Utils::Hook(0x47D485, Key_SetBinding_Hk, HOOK_CALL).install()->quick(); + Utils::Hook(0x47D49D, Key_SetBinding_Hk, HOOK_CALL).install()->quick(); + // Add gamepad inputs to remote control (eg predator) handling Utils::Hook(0x5A6D4E, CL_RemoteControlMove_Stub, HOOK_CALL).install()->quick(); diff --git a/src/Components/Modules/Gamepad.hpp b/src/Components/Modules/Gamepad.hpp index 36c969e9..f468dacd 100644 --- a/src/Components/Modules/Gamepad.hpp +++ b/src/Components/Modules/Gamepad.hpp @@ -194,6 +194,7 @@ namespace Components static const char* GetGamePadCommand(const char* command); static int Key_GetCommandAssignmentInternal(int localClientNum, const char* cmd, int (*keys)[2]); static void Key_GetCommandAssignmentInternal_Stub(); + static void Key_SetBinding_Hk(int localClientNum, int keyNum, const char* binding); static bool IsGamePadInUse(); static void CL_KeyEvent_Hk(int localClientNum, int key, int down, unsigned int time); static int CL_MouseEvent_Hk(int x, int y, int dx, int dy); diff --git a/src/Game/Functions.cpp b/src/Game/Functions.cpp index f617cb4e..343466db 100644 --- a/src/Game/Functions.cpp +++ b/src/Game/Functions.cpp @@ -171,6 +171,7 @@ namespace Game Key_SetCatcher_t Key_SetCatcher = Key_SetCatcher_t(0x43BD00); Key_RemoveCatcher_t Key_RemoveCatcher = Key_RemoveCatcher_t(0x408260); Key_IsKeyCatcherActive_t Key_IsKeyCatcherActive = Key_IsKeyCatcherActive_t(0x4DA010); + Key_SetBinding_t Key_SetBinding = Key_SetBinding_t(0x494C90); LargeLocalInit_t LargeLocalInit = LargeLocalInit_t(0x4A62A0); diff --git a/src/Game/Functions.hpp b/src/Game/Functions.hpp index 48f02c0a..da3ab84e 100644 --- a/src/Game/Functions.hpp +++ b/src/Game/Functions.hpp @@ -420,6 +420,9 @@ namespace Game typedef bool(__cdecl * Key_IsKeyCatcherActive_t)(int localClientNum, int catcher); extern Key_IsKeyCatcherActive_t Key_IsKeyCatcherActive; + typedef void(__cdecl * Key_SetBinding_t)(int localClientNum, int keyNum, const char* binding); + extern Key_SetBinding_t Key_SetBinding; + typedef void(__cdecl * LargeLocalInit_t)(); extern LargeLocalInit_t LargeLocalInit;