Reformatted gamepad patch
This commit is contained in:
parent
d4d1520f65
commit
ea8c35e063
@ -67,21 +67,21 @@ namespace Components
|
||||
Gamepad::MenuMapping(XINPUT_GAMEPAD_DPAD_DOWN, Game::keyNum_t::K_KP_DOWNARROW)
|
||||
};
|
||||
|
||||
// void Gamepad::Vibrate(int leftVal, int rightVal)
|
||||
// {
|
||||
// // Create a Vibraton State
|
||||
// XINPUT_VIBRATION Vibration;
|
||||
//
|
||||
// // Zeroise the Vibration
|
||||
// ZeroMemory(&Vibration, sizeof(XINPUT_VIBRATION));
|
||||
//
|
||||
// // Set the Vibration Values
|
||||
// Vibration.wLeftMotorSpeed = leftVal;
|
||||
// Vibration.wRightMotorSpeed = rightVal;
|
||||
//
|
||||
// // Vibrate the controller
|
||||
// XInputSetState(xiPlayerNum, &Vibration);
|
||||
// }
|
||||
// void Gamepad::Vibrate(int leftVal, int rightVal)
|
||||
// {
|
||||
// // Create a Vibraton State
|
||||
// XINPUT_VIBRATION Vibration;
|
||||
//
|
||||
// // Zeroise the Vibration
|
||||
// ZeroMemory(&Vibration, sizeof(XINPUT_VIBRATION));
|
||||
//
|
||||
// // Set the Vibration Values
|
||||
// Vibration.wLeftMotorSpeed = leftVal;
|
||||
// Vibration.wRightMotorSpeed = rightVal;
|
||||
//
|
||||
// // Vibrate the controller
|
||||
// XInputSetState(xiPlayerNum, &Vibration);
|
||||
// }
|
||||
|
||||
void Gamepad::CL_GamepadMove(int, Game::usercmd_s* cmd)
|
||||
{
|
||||
@ -89,7 +89,8 @@ namespace Components
|
||||
|
||||
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
|
||||
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()));
|
||||
@ -99,11 +100,13 @@ namespace Components
|
||||
const bool previouslyPressingLeftTrigger = gamePad.lastAnalogs[0] > TRIGGER_THRESHOLD_F;
|
||||
if (pressingLeftTrigger != previouslyPressingLeftTrigger)
|
||||
{
|
||||
if (pressingLeftTrigger) {
|
||||
if (pressingLeftTrigger)
|
||||
{
|
||||
Command::Execute("+speed_throw");
|
||||
isADS = true;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
Command::Execute("-speed_throw");
|
||||
isADS = false;
|
||||
}
|
||||
@ -113,10 +116,12 @@ namespace Components
|
||||
const bool previouslyPressingRightTrigger = gamePad.lastAnalogs[1] > TRIGGER_THRESHOLD_F;
|
||||
if (pressingRightTrigger != previouslyPressingRightTrigger)
|
||||
{
|
||||
if (pressingRightTrigger) {
|
||||
if (pressingRightTrigger)
|
||||
{
|
||||
Command::Execute("+attack");
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
Command::Execute("-attack");
|
||||
}
|
||||
}
|
||||
@ -128,28 +133,35 @@ namespace Components
|
||||
auto action = mapping.action;
|
||||
auto antiAction = mapping.action;
|
||||
|
||||
if (mapping.isReversible) {
|
||||
if (mapping.isReversible)
|
||||
{
|
||||
action = "+" + mapping.action;
|
||||
antiAction = "-" + mapping.action;
|
||||
}
|
||||
else if (mapping.wasPressed) {
|
||||
if (gamePad.digitals & mapping.input) {
|
||||
else if (mapping.wasPressed)
|
||||
{
|
||||
if (gamePad.digitals & mapping.input)
|
||||
{
|
||||
// Button still pressed, do not send info
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
i.wasPressed = false;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (gamePad.digitals & mapping.input) {
|
||||
if (mapping.spamWhenHeld || !i.wasPressed) {
|
||||
if (gamePad.digitals & mapping.input)
|
||||
{
|
||||
if (mapping.spamWhenHeld || !i.wasPressed)
|
||||
{
|
||||
Command::Execute(action);
|
||||
}
|
||||
i.wasPressed = true;
|
||||
}
|
||||
else if (mapping.isReversible && mapping.wasPressed) {
|
||||
else if (mapping.isReversible && mapping.wasPressed)
|
||||
{
|
||||
i.wasPressed = false;
|
||||
Command::Execute(antiAction);
|
||||
}
|
||||
@ -273,35 +285,44 @@ namespace Components
|
||||
std::chrono::milliseconds timeSinceLastNavigation = now - lastNavigationTime;
|
||||
bool canNavigate = timeSinceLastNavigation > msBetweenNavigations;
|
||||
|
||||
if (gamePad.stickDown[1][GPAD_STICK_POS]) {
|
||||
if (canNavigate) {
|
||||
if (gamePad.stickDown[1][GPAD_STICK_POS])
|
||||
{
|
||||
if (canNavigate)
|
||||
{
|
||||
Game::Menu_SetPrevCursorItem(Game::uiContext, menuDef, 1);
|
||||
lastMenuNavigationDirection = GPAD_STICK_POS;
|
||||
lastNavigationTime = now;
|
||||
}
|
||||
}
|
||||
else if (gamePad.stickDown[1][GPAD_STICK_NEG]) {
|
||||
if (canNavigate) {
|
||||
else if (gamePad.stickDown[1][GPAD_STICK_NEG])
|
||||
{
|
||||
if (canNavigate)
|
||||
{
|
||||
Game::Menu_SetNextCursorItem(Game::uiContext, menuDef, 1);
|
||||
lastMenuNavigationDirection = GPAD_STICK_NEG;
|
||||
lastNavigationTime = now;
|
||||
}
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
lastMenuNavigationDirection = GPAD_STICK_DIR_COUNT;
|
||||
}
|
||||
|
||||
for (auto& mapping : menuMappings)
|
||||
{
|
||||
if (mapping.wasPressed) {
|
||||
if (gamePad.digitals & mapping.input) {
|
||||
if (mapping.wasPressed)
|
||||
{
|
||||
if (gamePad.digitals & mapping.input)
|
||||
{
|
||||
// Button still pressed, do not send info
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
mapping.wasPressed = false;
|
||||
}
|
||||
}
|
||||
else if (gamePad.digitals & mapping.input) {
|
||||
else if (gamePad.digitals & mapping.input)
|
||||
{
|
||||
Game::UI_KeyEvent(0, mapping.keystroke, 1);
|
||||
mapping.wasPressed = true;
|
||||
}
|
||||
@ -316,15 +337,18 @@ namespace Components
|
||||
|
||||
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 previouslyPressingLeftTrigger = gamePad.lastAnalogs[0] > TRIGGER_THRESHOLD_F;
|
||||
if (pressingLeftTrigger != previouslyPressingLeftTrigger)
|
||||
{
|
||||
if (pressingLeftTrigger) {
|
||||
if (pressingLeftTrigger)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -353,13 +377,17 @@ namespace Components
|
||||
float viewStickY = gamePad.sticks[3];
|
||||
|
||||
// Gamepad horizontal acceleration on view
|
||||
if (abs(viewStickX) > 0.80f) {
|
||||
if (!Gamepad::isHoldingMaxLookX) {
|
||||
if (abs(viewStickX) > 0.80f)
|
||||
{
|
||||
if (!Gamepad::isHoldingMaxLookX)
|
||||
{
|
||||
Gamepad::isHoldingMaxLookX = true;
|
||||
Gamepad::timeAtFirstHeldMaxLookX = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch());
|
||||
}
|
||||
else {
|
||||
std::chrono::milliseconds hasBeenHoldingLeftXForMs = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()) - Gamepad::timeAtFirstHeldMaxLookX;
|
||||
else
|
||||
{
|
||||
std::chrono::milliseconds hasBeenHoldingLeftXForMs = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()) -
|
||||
Gamepad::timeAtFirstHeldMaxLookX;
|
||||
#ifdef STEP_SENSITIVITY
|
||||
if (hasBeenHoldingLeftXForMs < msBeforeUnlockingSensitivity) {
|
||||
viewStickX *= lockedSensitivityMultiplier;
|
||||
@ -370,7 +398,8 @@ namespace Components
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
Gamepad::isHoldingMaxLookX = false;
|
||||
Gamepad::timeAtFirstHeldMaxLookX = 0ms;
|
||||
viewStickX *= lockedSensitivityMultiplier;
|
||||
@ -381,11 +410,13 @@ namespace Components
|
||||
auto ps = &clientActive->snap.ps;
|
||||
|
||||
// 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>();
|
||||
}
|
||||
|
||||
if (viewStickX != 0 || viewStickY != 0) {
|
||||
if (viewStickX != 0 || viewStickY != 0)
|
||||
{
|
||||
*(my) = viewStickX * viewSensitivityMultiplier * generalXSensitivityMultiplier * adsMultiplier;
|
||||
*(mx) = -viewStickY * viewSensitivityMultiplier * generalYSensitivityMultiplier * adsMultiplier;
|
||||
}
|
||||
@ -397,9 +428,11 @@ namespace Components
|
||||
{
|
||||
bool* isInPredator = reinterpret_cast<bool*>(0x8EE3B8);
|
||||
|
||||
if (pressingRightTrigger) {
|
||||
if (pressingRightTrigger)
|
||||
{
|
||||
Utils::Hook::Set(0xA1C4F4, Game::LOC_SEL_INPUT_CONFIRM);
|
||||
if (*isInPredator) {
|
||||
if (*isInPredator)
|
||||
{
|
||||
// Yea, that's how we boost
|
||||
// Command::execute is sync by default so the predator event gets fired properly
|
||||
Command::Execute("+attack");
|
||||
@ -408,7 +441,6 @@ namespace Components
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Game -> Client DLL
|
||||
@ -499,9 +531,9 @@ namespace Components
|
||||
|
||||
auto& gamePad = gamePads[gamePadIndex];
|
||||
|
||||
for(auto stickIndex = 0u; stickIndex < std::extent_v<decltype(GamePad::sticks)>; stickIndex++)
|
||||
for (auto stickIndex = 0u; stickIndex < std::extent_v<decltype(GamePad::sticks)>; stickIndex++)
|
||||
{
|
||||
for(auto dir = 0; dir < GPAD_STICK_DIR_COUNT; dir++)
|
||||
for (auto dir = 0; dir < GPAD_STICK_DIR_COUNT; dir++)
|
||||
{
|
||||
gamePad.stickDownLast[stickIndex][dir] = gamePad.stickDown[stickIndex][dir];
|
||||
|
||||
@ -512,7 +544,7 @@ namespace Components
|
||||
else
|
||||
threshold += gpad_stick_pressed_hysteresis.get<float>();
|
||||
|
||||
if(dir == GPAD_STICK_POS)
|
||||
if (dir == GPAD_STICK_POS)
|
||||
{
|
||||
gamePad.stickDown[stickIndex][dir] = gamePad.sticks[stickIndex] > threshold;
|
||||
}
|
||||
@ -546,8 +578,8 @@ namespace Components
|
||||
|
||||
GPad_UpdateSticksDown(gamePadIndex);
|
||||
|
||||
#ifdef DEBUG
|
||||
if(gpad_debug.get<bool>())
|
||||
#ifdef DEBUG
|
||||
if (gpad_debug.get<bool>())
|
||||
{
|
||||
Logger::Print("Left: X: %f Y: %f\n", lVec[0], lVec[1]);
|
||||
Logger::Print("Right: X: %f Y: %f\n", rVec[0], rVec[1]);
|
||||
@ -556,7 +588,7 @@ namespace Components
|
||||
gamePad.stickDown[2][GPAD_STICK_POS], gamePad.stickDown[2][GPAD_STICK_NEG],
|
||||
gamePad.stickDown[3][GPAD_STICK_POS], gamePad.stickDown[3][GPAD_STICK_NEG]);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void Gamepad::GPad_UpdateDigitals(const int gamePadIndex, const XINPUT_GAMEPAD& state)
|
||||
@ -569,10 +601,10 @@ namespace Components
|
||||
gamePad.digitals = state.wButtons;
|
||||
|
||||
const auto leftDeflect = gpad_button_lstick_deflect_max.get<float>();
|
||||
if(std::fabs(gamePad.sticks[0]) > leftDeflect || std::fabs(gamePad.sticks[1]) > leftDeflect)
|
||||
if (std::fabs(gamePad.sticks[0]) > leftDeflect || std::fabs(gamePad.sticks[1]) > leftDeflect)
|
||||
gamePad.digitals &= ~static_cast<short>(XINPUT_GAMEPAD_LEFT_THUMB);
|
||||
const auto rightDeflect = gpad_button_rstick_deflect_max.get<float>();
|
||||
if(std::fabs(gamePad.sticks[2]) > leftDeflect || std::fabs(gamePad.sticks[3]) > rightDeflect)
|
||||
if (std::fabs(gamePad.sticks[2]) > leftDeflect || std::fabs(gamePad.sticks[3]) > rightDeflect)
|
||||
gamePad.digitals &= ~static_cast<short>(XINPUT_GAMEPAD_RIGHT_THUMB);
|
||||
|
||||
#ifdef DEBUG
|
||||
@ -614,14 +646,14 @@ namespace Components
|
||||
{
|
||||
GPad_RefreshAll();
|
||||
|
||||
for(auto currentGamePadIndex = 0; currentGamePadIndex < MAX_GAMEPADS; currentGamePadIndex++)
|
||||
for (auto currentGamePadIndex = 0; currentGamePadIndex < MAX_GAMEPADS; currentGamePadIndex++)
|
||||
{
|
||||
const auto& gamePad = gamePads[currentGamePadIndex];
|
||||
if(!gamePad.enabled)
|
||||
if (!gamePad.enabled)
|
||||
continue;
|
||||
|
||||
XINPUT_STATE inputState;
|
||||
if(XInputGetState(gamePad.portIndex, &inputState) != ERROR_SUCCESS)
|
||||
if (XInputGetState(gamePad.portIndex, &inputState) != ERROR_SUCCESS)
|
||||
continue;
|
||||
|
||||
GPad_UpdateSticks(currentGamePadIndex, inputState.Gamepad);
|
||||
@ -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_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_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_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_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");
|
||||
@ -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");
|
||||
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");
|
||||
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.");
|
||||
|
@ -8,8 +8,8 @@ namespace Components
|
||||
static constexpr float TRIGGER_THRESHOLD_F = static_cast<float>(XINPUT_GAMEPAD_TRIGGER_THRESHOLD) / static_cast<float>(0xFF);
|
||||
|
||||
public:
|
||||
|
||||
Gamepad();
|
||||
|
||||
enum GamePadStickDir
|
||||
{
|
||||
GPAD_STICK_POS = 0x0,
|
||||
|
Loading…
Reference in New Issue
Block a user