Reformatted gamepad patch

This commit is contained in:
Jan 2021-08-21 15:20:26 +02:00
parent d4d1520f65
commit ea8c35e063
2 changed files with 646 additions and 611 deletions

View File

@ -89,7 +89,8 @@ namespace Components
if (gamePad.enabled) if (gamePad.enabled)
{ {
if (std::fabs(gamePad.sticks[0]) > 0.0f || std::fabs(gamePad.sticks[1]) > 0.0f) { if (std::fabs(gamePad.sticks[0]) > 0.0f || std::fabs(gamePad.sticks[1]) > 0.0f)
{
// We check for 0:0 again so we don't overwrite keyboard input in case the user doesn't feel like using their gamepad, even though its plugged in // We check for 0:0 again so we don't overwrite keyboard input in case the user doesn't feel like using their gamepad, even though its plugged in
cmd->rightmove = static_cast<char>(gamePad.sticks[0] * static_cast<float>(std::numeric_limits<char>().max())); cmd->rightmove = static_cast<char>(gamePad.sticks[0] * static_cast<float>(std::numeric_limits<char>().max()));
cmd->forwardmove = static_cast<char>(gamePad.sticks[1] * static_cast<float>(std::numeric_limits<char>().max())); cmd->forwardmove = static_cast<char>(gamePad.sticks[1] * static_cast<float>(std::numeric_limits<char>().max()));
@ -99,11 +100,13 @@ namespace Components
const bool previouslyPressingLeftTrigger = gamePad.lastAnalogs[0] > TRIGGER_THRESHOLD_F; const bool previouslyPressingLeftTrigger = gamePad.lastAnalogs[0] > TRIGGER_THRESHOLD_F;
if (pressingLeftTrigger != previouslyPressingLeftTrigger) if (pressingLeftTrigger != previouslyPressingLeftTrigger)
{ {
if (pressingLeftTrigger) { if (pressingLeftTrigger)
{
Command::Execute("+speed_throw"); Command::Execute("+speed_throw");
isADS = true; isADS = true;
} }
else { else
{
Command::Execute("-speed_throw"); Command::Execute("-speed_throw");
isADS = false; isADS = false;
} }
@ -113,10 +116,12 @@ namespace Components
const bool previouslyPressingRightTrigger = gamePad.lastAnalogs[1] > TRIGGER_THRESHOLD_F; const bool previouslyPressingRightTrigger = gamePad.lastAnalogs[1] > TRIGGER_THRESHOLD_F;
if (pressingRightTrigger != previouslyPressingRightTrigger) if (pressingRightTrigger != previouslyPressingRightTrigger)
{ {
if (pressingRightTrigger) { if (pressingRightTrigger)
{
Command::Execute("+attack"); Command::Execute("+attack");
} }
else { else
{
Command::Execute("-attack"); Command::Execute("-attack");
} }
} }
@ -128,28 +133,35 @@ namespace Components
auto action = mapping.action; auto action = mapping.action;
auto antiAction = mapping.action; auto antiAction = mapping.action;
if (mapping.isReversible) { if (mapping.isReversible)
{
action = "+" + mapping.action; action = "+" + mapping.action;
antiAction = "-" + mapping.action; antiAction = "-" + mapping.action;
} }
else if (mapping.wasPressed) { else if (mapping.wasPressed)
if (gamePad.digitals & mapping.input) { {
if (gamePad.digitals & mapping.input)
{
// Button still pressed, do not send info // Button still pressed, do not send info
} }
else { else
{
i.wasPressed = false; i.wasPressed = false;
} }
continue; continue;
} }
if (gamePad.digitals & mapping.input) { if (gamePad.digitals & mapping.input)
if (mapping.spamWhenHeld || !i.wasPressed) { {
if (mapping.spamWhenHeld || !i.wasPressed)
{
Command::Execute(action); Command::Execute(action);
} }
i.wasPressed = true; i.wasPressed = true;
} }
else if (mapping.isReversible && mapping.wasPressed) { else if (mapping.isReversible && mapping.wasPressed)
{
i.wasPressed = false; i.wasPressed = false;
Command::Execute(antiAction); Command::Execute(antiAction);
} }
@ -273,35 +285,44 @@ namespace Components
std::chrono::milliseconds timeSinceLastNavigation = now - lastNavigationTime; std::chrono::milliseconds timeSinceLastNavigation = now - lastNavigationTime;
bool canNavigate = timeSinceLastNavigation > msBetweenNavigations; bool canNavigate = timeSinceLastNavigation > msBetweenNavigations;
if (gamePad.stickDown[1][GPAD_STICK_POS]) { if (gamePad.stickDown[1][GPAD_STICK_POS])
if (canNavigate) { {
if (canNavigate)
{
Game::Menu_SetPrevCursorItem(Game::uiContext, menuDef, 1); Game::Menu_SetPrevCursorItem(Game::uiContext, menuDef, 1);
lastMenuNavigationDirection = GPAD_STICK_POS; lastMenuNavigationDirection = GPAD_STICK_POS;
lastNavigationTime = now; lastNavigationTime = now;
} }
} }
else if (gamePad.stickDown[1][GPAD_STICK_NEG]) { else if (gamePad.stickDown[1][GPAD_STICK_NEG])
if (canNavigate) { {
if (canNavigate)
{
Game::Menu_SetNextCursorItem(Game::uiContext, menuDef, 1); Game::Menu_SetNextCursorItem(Game::uiContext, menuDef, 1);
lastMenuNavigationDirection = GPAD_STICK_NEG; lastMenuNavigationDirection = GPAD_STICK_NEG;
lastNavigationTime = now; lastNavigationTime = now;
} }
} }
else { else
{
lastMenuNavigationDirection = GPAD_STICK_DIR_COUNT; lastMenuNavigationDirection = GPAD_STICK_DIR_COUNT;
} }
for (auto& mapping : menuMappings) for (auto& mapping : menuMappings)
{ {
if (mapping.wasPressed) { if (mapping.wasPressed)
if (gamePad.digitals & mapping.input) { {
if (gamePad.digitals & mapping.input)
{
// Button still pressed, do not send info // Button still pressed, do not send info
} }
else { else
{
mapping.wasPressed = false; mapping.wasPressed = false;
} }
} }
else if (gamePad.digitals & mapping.input) { else if (gamePad.digitals & mapping.input)
{
Game::UI_KeyEvent(0, mapping.keystroke, 1); Game::UI_KeyEvent(0, mapping.keystroke, 1);
mapping.wasPressed = true; mapping.wasPressed = true;
} }
@ -316,15 +337,18 @@ namespace Components
if (gamePad.enabled) if (gamePad.enabled)
{ {
if (keyCode == Game::keyNum_t::K_MOUSE2) { if (keyCode == Game::keyNum_t::K_MOUSE2)
{
const bool pressingLeftTrigger = gamePad.analogs[0] > TRIGGER_THRESHOLD_F; const bool pressingLeftTrigger = gamePad.analogs[0] > TRIGGER_THRESHOLD_F;
const bool previouslyPressingLeftTrigger = gamePad.lastAnalogs[0] > TRIGGER_THRESHOLD_F; const bool previouslyPressingLeftTrigger = gamePad.lastAnalogs[0] > TRIGGER_THRESHOLD_F;
if (pressingLeftTrigger != previouslyPressingLeftTrigger) if (pressingLeftTrigger != previouslyPressingLeftTrigger)
{ {
if (pressingLeftTrigger) { if (pressingLeftTrigger)
{
return 1; return 1;
} }
else { else
{
return 0; return 0;
} }
} }
@ -353,13 +377,17 @@ namespace Components
float viewStickY = gamePad.sticks[3]; float viewStickY = gamePad.sticks[3];
// Gamepad horizontal acceleration on view // Gamepad horizontal acceleration on view
if (abs(viewStickX) > 0.80f) { if (abs(viewStickX) > 0.80f)
if (!Gamepad::isHoldingMaxLookX) { {
if (!Gamepad::isHoldingMaxLookX)
{
Gamepad::isHoldingMaxLookX = true; Gamepad::isHoldingMaxLookX = true;
Gamepad::timeAtFirstHeldMaxLookX = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()); Gamepad::timeAtFirstHeldMaxLookX = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch());
} }
else { else
std::chrono::milliseconds hasBeenHoldingLeftXForMs = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()) - Gamepad::timeAtFirstHeldMaxLookX; {
std::chrono::milliseconds hasBeenHoldingLeftXForMs = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()) -
Gamepad::timeAtFirstHeldMaxLookX;
#ifdef STEP_SENSITIVITY #ifdef STEP_SENSITIVITY
if (hasBeenHoldingLeftXForMs < msBeforeUnlockingSensitivity) { if (hasBeenHoldingLeftXForMs < msBeforeUnlockingSensitivity) {
viewStickX *= lockedSensitivityMultiplier; viewStickX *= lockedSensitivityMultiplier;
@ -370,7 +398,8 @@ namespace Components
#endif #endif
} }
} }
else { else
{
Gamepad::isHoldingMaxLookX = false; Gamepad::isHoldingMaxLookX = false;
Gamepad::timeAtFirstHeldMaxLookX = 0ms; Gamepad::timeAtFirstHeldMaxLookX = 0ms;
viewStickX *= lockedSensitivityMultiplier; viewStickX *= lockedSensitivityMultiplier;
@ -381,11 +410,13 @@ namespace Components
auto ps = &clientActive->snap.ps; auto ps = &clientActive->snap.ps;
// DO NOT use clientActive->usingAds ! It only works for toggle ADS // DO NOT use clientActive->usingAds ! It only works for toggle ADS
if (Game::PM_IsAdsAllowed(ps) && Gamepad::isADS) { if (Game::PM_IsAdsAllowed(ps) && Gamepad::isADS)
{
adsMultiplier = xpadAdsMultiplier.get<float>(); adsMultiplier = xpadAdsMultiplier.get<float>();
} }
if (viewStickX != 0 || viewStickY != 0) { if (viewStickX != 0 || viewStickY != 0)
{
*(my) = viewStickX * viewSensitivityMultiplier * generalXSensitivityMultiplier * adsMultiplier; *(my) = viewStickX * viewSensitivityMultiplier * generalXSensitivityMultiplier * adsMultiplier;
*(mx) = -viewStickY * viewSensitivityMultiplier * generalYSensitivityMultiplier * adsMultiplier; *(mx) = -viewStickY * viewSensitivityMultiplier * generalYSensitivityMultiplier * adsMultiplier;
} }
@ -397,9 +428,11 @@ namespace Components
{ {
bool* isInPredator = reinterpret_cast<bool*>(0x8EE3B8); bool* isInPredator = reinterpret_cast<bool*>(0x8EE3B8);
if (pressingRightTrigger) { if (pressingRightTrigger)
{
Utils::Hook::Set(0xA1C4F4, Game::LOC_SEL_INPUT_CONFIRM); Utils::Hook::Set(0xA1C4F4, Game::LOC_SEL_INPUT_CONFIRM);
if (*isInPredator) { if (*isInPredator)
{
// Yea, that's how we boost // Yea, that's how we boost
// Command::execute is sync by default so the predator event gets fired properly // Command::execute is sync by default so the predator event gets fired properly
Command::Execute("+attack"); Command::Execute("+attack");
@ -408,7 +441,6 @@ namespace Components
} }
} }
} }
} }
// Game -> Client DLL // Game -> Client DLL
@ -652,9 +684,11 @@ namespace Components
gpad_sticksConfig = Dvar::Register<const char*>("gpad_sticksConfig", "thumbstick_default", Game::DVAR_FLAG_SAVED, "Game pad stick configuration"); gpad_sticksConfig = Dvar::Register<const char*>("gpad_sticksConfig", "thumbstick_default", Game::DVAR_FLAG_SAVED, "Game pad stick configuration");
gpad_buttonConfig = Dvar::Register<const char*>("gpad_buttonConfig", "buttons_default", Game::DVAR_FLAG_SAVED, "Game pad button configuration"); gpad_buttonConfig = Dvar::Register<const char*>("gpad_buttonConfig", "buttons_default", Game::DVAR_FLAG_SAVED, "Game pad button configuration");
gpad_menu_scroll_delay_first = Dvar::Register<int>("gpad_menu_scroll_delay_first", 420, 0, 1000, Game::DVAR_FLAG_SAVED, "Menu scroll key-repeat delay, for the first repeat, in milliseconds"); gpad_menu_scroll_delay_first = Dvar::Register<int>("gpad_menu_scroll_delay_first", 420, 0, 1000, Game::DVAR_FLAG_SAVED, "Menu scroll key-repeat delay, for the first repeat, in milliseconds");
gpad_menu_scroll_delay_rest = Dvar::Register<int>("gpad_menu_scroll_delay_rest", 210, 0, 1000, Game::DVAR_FLAG_SAVED, "Menu scroll key-repeat delay, for repeats after the first, in milliseconds"); gpad_menu_scroll_delay_rest = Dvar::Register<int>("gpad_menu_scroll_delay_rest", 210, 0, 1000, Game::DVAR_FLAG_SAVED,
"Menu scroll key-repeat delay, for repeats after the first, in milliseconds");
gpad_rumble = Dvar::Register<bool>("gpad_rumble", true, Game::DVAR_FLAG_SAVED, "Enable game pad rumble"); gpad_rumble = Dvar::Register<bool>("gpad_rumble", true, Game::DVAR_FLAG_SAVED, "Enable game pad rumble");
gpad_stick_pressed_hysteresis = Dvar::Register<float>("gpad_stick_pressed_hysteresis", 0.1f, 0.0f, 1.0f, 0, "Game pad stick pressed no-change-zone around gpad_stick_pressed to prevent bouncing"); gpad_stick_pressed_hysteresis = Dvar::Register<float>("gpad_stick_pressed_hysteresis", 0.1f, 0.0f, 1.0f, 0,
"Game pad stick pressed no-change-zone around gpad_stick_pressed to prevent bouncing");
gpad_stick_pressed = Dvar::Register<float>("gpad_stick_pressed", 0.4f, 0.0, 1.0, 0, "Game pad stick pressed threshhold"); gpad_stick_pressed = Dvar::Register<float>("gpad_stick_pressed", 0.4f, 0.0, 1.0, 0, "Game pad stick pressed threshhold");
gpad_stick_deadzone_max = Dvar::Register<float>("gpad_stick_deadzone_max", 0.01f, 0.0f, 1.0f, 0, "Game pad maximum stick deadzone"); gpad_stick_deadzone_max = Dvar::Register<float>("gpad_stick_deadzone_max", 0.01f, 0.0f, 1.0f, 0, "Game pad maximum stick deadzone");
gpad_stick_deadzone_min = Dvar::Register<float>("gpad_stick_deadzone_min", 0.2f, 0.0f, 1.0f, 0, "Game pad minimum stick deadzone"); gpad_stick_deadzone_min = Dvar::Register<float>("gpad_stick_deadzone_min", 0.2f, 0.0f, 1.0f, 0, "Game pad minimum stick deadzone");
@ -702,7 +736,8 @@ namespace Components
xpadSensitivity = Dvar::Register<float>("xpad_sensitivity", 1.9f, 0.1f, 10.0f, Game::DVAR_FLAG_SAVED, "View sensitivity for XInput-compatible gamepads"); xpadSensitivity = Dvar::Register<float>("xpad_sensitivity", 1.9f, 0.1f, 10.0f, Game::DVAR_FLAG_SAVED, "View sensitivity for XInput-compatible gamepads");
xpadEarlyTime = Dvar::Register<int>("xpad_early_time", 130, 0, 1000, Game::DVAR_FLAG_SAVED, "Time (in milliseconds) of reduced view sensitivity"); xpadEarlyTime = Dvar::Register<int>("xpad_early_time", 130, 0, 1000, Game::DVAR_FLAG_SAVED, "Time (in milliseconds) of reduced view sensitivity");
xpadEarlyMultiplier = Dvar::Register<float>("xpad_early_multiplier", 0.25f, 0.01f, 1.0f, Game::DVAR_FLAG_SAVED, "By how much the view sensitivity is multiplied during xpad_early_time when moving the view stick"); xpadEarlyMultiplier = Dvar::Register<float>("xpad_early_multiplier", 0.25f, 0.01f, 1.0f, Game::DVAR_FLAG_SAVED,
"By how much the view sensitivity is multiplied during xpad_early_time when moving the view stick");
xpadHorizontalMultiplier = Dvar::Register<float>("xpad_horizontal_multiplier", 1.5f, 1.0f, 20.0f, Game::DVAR_FLAG_SAVED, "Horizontal view sensitivity multiplier"); xpadHorizontalMultiplier = Dvar::Register<float>("xpad_horizontal_multiplier", 1.5f, 1.0f, 20.0f, Game::DVAR_FLAG_SAVED, "Horizontal view sensitivity multiplier");
xpadVerticalMultiplier = Dvar::Register<float>("xpad_vertical_multiplier", 0.8f, 1.0f, 20.0f, Game::DVAR_FLAG_SAVED, "Vertical view sensitivity multiplier"); xpadVerticalMultiplier = Dvar::Register<float>("xpad_vertical_multiplier", 0.8f, 1.0f, 20.0f, Game::DVAR_FLAG_SAVED, "Vertical view sensitivity multiplier");
xpadAdsMultiplier = Dvar::Register<float>("xpad_ads_multiplier", 0.7f, 0.1f, 1.0f, Game::DVAR_FLAG_SAVED, "By how much the view sensitivity is multiplied when aiming down the sights."); xpadAdsMultiplier = Dvar::Register<float>("xpad_ads_multiplier", 0.7f, 0.1f, 1.0f, Game::DVAR_FLAG_SAVED, "By how much the view sensitivity is multiplied when aiming down the sights.");

View File

@ -8,8 +8,8 @@ namespace Components
static constexpr float TRIGGER_THRESHOLD_F = static_cast<float>(XINPUT_GAMEPAD_TRIGGER_THRESHOLD) / static_cast<float>(0xFF); static constexpr float TRIGGER_THRESHOLD_F = static_cast<float>(XINPUT_GAMEPAD_TRIGGER_THRESHOLD) / static_cast<float>(0xFF);
public: public:
Gamepad(); Gamepad();
enum GamePadStickDir enum GamePadStickDir
{ {
GPAD_STICK_POS = 0x0, GPAD_STICK_POS = 0x0,