Reduce sensitivity when aiming down sights

This commit is contained in:
rackover 2021-05-04 21:45:47 +02:00
parent bac2afa028
commit 0354dd985e
5 changed files with 71 additions and 8 deletions

View File

@ -7,10 +7,12 @@ namespace Components
int XInput::xiPlayerNum = -1; int XInput::xiPlayerNum = -1;
std::chrono::milliseconds XInput::timeAtFirstHeldMaxLookX = 0ms; // "For how much time in miliseconds has the player been holding a horizontal direction on their stick, fully" (-1.0 or 1.0) std::chrono::milliseconds XInput::timeAtFirstHeldMaxLookX = 0ms; // "For how much time in miliseconds has the player been holding a horizontal direction on their stick, fully" (-1.0 or 1.0)
bool XInput::isHoldingMaxLookX = false; bool XInput::isHoldingMaxLookX = false;
bool XInput::isADS;
float XInput::lockedSensitivityMultiplier = 0.45f; float XInput::lockedSensitivityMultiplier = 0.45f;
float XInput::generalXSensitivityMultiplier = 3 * 1.5f; float XInput::generalXSensitivityMultiplier = 3 * 1.5f;
float XInput::generalYSensitivityMultiplier = 4 * 0.8f; float XInput::generalYSensitivityMultiplier = 4 * 0.8f;
float XInput::adsMultiplier = 0.3f;
float XInput::lastMenuNavigationDirection = .0f; float XInput::lastMenuNavigationDirection = .0f;
std::chrono::milliseconds XInput::lastNavigationTime = 0ms; std::chrono::milliseconds XInput::lastNavigationTime = 0ms;
@ -18,8 +20,6 @@ namespace Components
std::chrono::milliseconds XInput::msBeforeUnlockingSensitivity = 350ms; std::chrono::milliseconds XInput::msBeforeUnlockingSensitivity = 350ms;
float sensitivityMultiplier = 1.0f;
std::vector<XInput::ActionMapping> mappings = { std::vector<XInput::ActionMapping> mappings = {
XInput::ActionMapping(XINPUT_GAMEPAD_A, "gostand"), XInput::ActionMapping(XINPUT_GAMEPAD_A, "gostand"),
XInput::ActionMapping(XINPUT_GAMEPAD_B, "stance"), XInput::ActionMapping(XINPUT_GAMEPAD_B, "stance"),
@ -97,6 +97,8 @@ namespace Components
{ {
if (XInput::xiPlayerNum != -1) if (XInput::xiPlayerNum != -1)
{ {
Game::clientActive_t* clientActive = reinterpret_cast<Game::clientActive_t*>(0xB2C698);
XINPUT_STATE* xiState = &xiStates[xiPlayerNum]; XINPUT_STATE* xiState = &xiStates[xiPlayerNum];
// Deadzones // Deadzones
@ -113,12 +115,12 @@ namespace Components
if (pressingLeftTrigger != XInput::lastXiState.Gamepad.bLeftTrigger > XINPUT_GAMEPAD_TRIGGER_THRESHOLD) if (pressingLeftTrigger != XInput::lastXiState.Gamepad.bLeftTrigger > XINPUT_GAMEPAD_TRIGGER_THRESHOLD)
{ {
if (pressingLeftTrigger) { if (pressingLeftTrigger) {
Command::Execute("+toggleads_throw"); Command::Execute("+speed_throw");
Command::Execute("+speed"); XInput::isADS = true;
} }
else { else {
Command::Execute("-toggleads_throw"); Command::Execute("-speed_throw");
Command::Execute("-speed"); XInput::isADS = false;
} }
} }
@ -368,9 +370,18 @@ namespace Components
XInput::timeAtFirstHeldMaxLookX = 0ms; XInput::timeAtFirstHeldMaxLookX = 0ms;
} }
float adsMultiplier = 1.0f;
auto ps = &clientActive->snap.ps;
// DO NOT use clientActive->usingAds ! It only works for toggle ADS
if (Game::PM_IsAdsAllowed(ps) && XInput::isADS) {
adsMultiplier = XInput::adsMultiplier;
}
if (viewStickX != 0 || viewStickY != 0) { if (viewStickX != 0 || viewStickY != 0) {
*(my) = viewStickX * viewSensitivityMultiplier * generalXSensitivityMultiplier; *(my) = viewStickX * viewSensitivityMultiplier * generalXSensitivityMultiplier * adsMultiplier;
*(mx) = -viewStickY * viewSensitivityMultiplier * generalYSensitivityMultiplier; *(mx) = -viewStickY * viewSensitivityMultiplier * generalYSensitivityMultiplier * adsMultiplier;
} }
} }

View File

@ -46,6 +46,8 @@ namespace Components
static float lockedSensitivityMultiplier; static float lockedSensitivityMultiplier;
static float generalXSensitivityMultiplier; static float generalXSensitivityMultiplier;
static float generalYSensitivityMultiplier; static float generalYSensitivityMultiplier;
static float adsMultiplier;
static bool isADS;
static std::chrono::milliseconds lastNavigationTime; static std::chrono::milliseconds lastNavigationTime;
static std::chrono::milliseconds msBetweenNavigations; static std::chrono::milliseconds msBetweenNavigations;

View File

@ -970,6 +970,21 @@ namespace Game
} }
} }
bool PM_IsAdsAllowed(Game::playerState_s* playerState)
{
bool result;
__asm
{
mov esi, playerState
mov ebx, 0x5755A0
call ebx
mov result, al // AL
}
return result;
}
__declspec(naked) void FS_AddLocalizedGameDirectory(const char* /*path*/, const char* /*dir*/) __declspec(naked) void FS_AddLocalizedGameDirectory(const char* /*path*/, const char* /*dir*/)
{ {
__asm __asm

View File

@ -900,6 +900,8 @@ namespace Game
void FS_AddLocalizedGameDirectory(const char *path, const char *dir); void FS_AddLocalizedGameDirectory(const char *path, const char *dir);
bool PM_IsAdsAllowed(Game::playerState_s* playerState);
void ShowMessageBox(const std::string& message, const std::string& title); void ShowMessageBox(const std::string& message, const std::string& title);
unsigned int R_HashString(const char* string); unsigned int R_HashString(const char* string);

View File

@ -111,6 +111,39 @@ namespace Game
IMG_CATEGORY_TEMP = 0x7, IMG_CATEGORY_TEMP = 0x7,
} ; } ;
enum buttons_t
{
KB_LEFT = 0x0,
KB_RIGHT = 0x1,
KB_FORWARD = 0x2,
KB_BACK = 0x3,
KB_LOOKUP = 0x4,
KB_LOOKDOWN = 0x5,
KB_MOVELEFT = 0x6,
KB_MOVERIGHT = 0x7,
KB_STRAFE = 0x8,
KB_SPEED = 0x9,
KB_UP = 0xA,
KB_DOWN = 0xB,
KB_ANYUP = 0xC,
KB_MLOOK = 0xD,
KB_ATTACK = 0xE,
KB_BREATH = 0xF,
KB_FRAG = 0x10,
KB_OFFHANDSECONDARY = 0x11,
KB_MELEE = 0x12,
KB_ACTIVATE = 0x13,
KB_RELOAD = 0x14,
KB_USE_RELOAD = 0x15,
KB_PRONE = 0x16,
KB_CROUCH = 0x17,
KB_THROW = 0x18,
KB_SPRINT = 0x19,
KB_NIGHTVISION = 0x1A,
KB_TALK = 0x1B,
NUM_BUTTONS = 0x1C
};
enum DvarSetSource enum DvarSetSource
{ {
DVAR_SOURCE_INTERNAL = 0x0, DVAR_SOURCE_INTERNAL = 0x0,