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

This commit is contained in:
Jan 2022-05-05 21:36:27 +02:00
parent 41c652ed36
commit 13911fcb62
4 changed files with 18 additions and 0 deletions

View File

@ -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) 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. // 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 // Only return gamepad keys when gamepad enabled and only non gamepad keys when not
Utils::Hook(0x5A7890, Key_GetCommandAssignmentInternal_Stub, HOOK_JUMP).install()->quick(); 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 // Add gamepad inputs to remote control (eg predator) handling
Utils::Hook(0x5A6D4E, CL_RemoteControlMove_Stub, HOOK_CALL).install()->quick(); Utils::Hook(0x5A6D4E, CL_RemoteControlMove_Stub, HOOK_CALL).install()->quick();

View File

@ -194,6 +194,7 @@ namespace Components
static const char* GetGamePadCommand(const char* command); static const char* GetGamePadCommand(const char* command);
static int Key_GetCommandAssignmentInternal(int localClientNum, const char* cmd, int (*keys)[2]); static int Key_GetCommandAssignmentInternal(int localClientNum, const char* cmd, int (*keys)[2]);
static void Key_GetCommandAssignmentInternal_Stub(); static void Key_GetCommandAssignmentInternal_Stub();
static void Key_SetBinding_Hk(int localClientNum, int keyNum, const char* binding);
static bool IsGamePadInUse(); static bool IsGamePadInUse();
static void CL_KeyEvent_Hk(int localClientNum, int key, int down, unsigned int time); 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); static int CL_MouseEvent_Hk(int x, int y, int dx, int dy);

View File

@ -171,6 +171,7 @@ namespace Game
Key_SetCatcher_t Key_SetCatcher = Key_SetCatcher_t(0x43BD00); Key_SetCatcher_t Key_SetCatcher = Key_SetCatcher_t(0x43BD00);
Key_RemoveCatcher_t Key_RemoveCatcher = Key_RemoveCatcher_t(0x408260); Key_RemoveCatcher_t Key_RemoveCatcher = Key_RemoveCatcher_t(0x408260);
Key_IsKeyCatcherActive_t Key_IsKeyCatcherActive = Key_IsKeyCatcherActive_t(0x4DA010); Key_IsKeyCatcherActive_t Key_IsKeyCatcherActive = Key_IsKeyCatcherActive_t(0x4DA010);
Key_SetBinding_t Key_SetBinding = Key_SetBinding_t(0x494C90);
LargeLocalInit_t LargeLocalInit = LargeLocalInit_t(0x4A62A0); LargeLocalInit_t LargeLocalInit = LargeLocalInit_t(0x4A62A0);

View File

@ -420,6 +420,9 @@ namespace Game
typedef bool(__cdecl * Key_IsKeyCatcherActive_t)(int localClientNum, int catcher); typedef bool(__cdecl * Key_IsKeyCatcherActive_t)(int localClientNum, int catcher);
extern Key_IsKeyCatcherActive_t Key_IsKeyCatcherActive; 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)(); typedef void(__cdecl * LargeLocalInit_t)();
extern LargeLocalInit_t LargeLocalInit; extern LargeLocalInit_t LargeLocalInit;