Skip to content

Commit

Permalink
Add exchangeable walk and crouch key, fix trigger sensitivity.
Browse files Browse the repository at this point in the history
  • Loading branch information
gennariarmando committed May 30, 2022
1 parent 6c17d6c commit f2f804e
Show file tree
Hide file tree
Showing 7 changed files with 325 additions and 15 deletions.
6 changes: 4 additions & 2 deletions resources/ClassicAxisIII.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ ForceAutoAim = false
LockOnTargetType = 1
; While aiming with mouse, displays a triangle with the color of the health over the head of the pedestrian.
ShowTriangleForMouseRecruit = true
; Makes the player walk if the left alt key is pressed.
EnableLAltKeyWalk = true
; Makes the player walk using the defined keyboard key (NULL to disable).
WalkKey = LALT
; Makes camera while aiming similar to LCS/VCS.
StoriesAimingCoords = false
; Crosshair position from (0.0f - 1.0f) while aiming in third person (default 0.53f, 0.4f).
Expand All @@ -17,3 +17,5 @@ StoriesPointingArm = false
; Adjust right analog stick sensitivity.
RightAnalogStickSensitivityX = 1.0f
RightAnalogStickSensitivityY = 1.0f
; Makes the player crouch using the defined keyboard key (NULL to disable).
CrouchKey = C
6 changes: 3 additions & 3 deletions resources/ClassicAxisVC.ini
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[ClassicAxis]
; Force auto aim while playing with keyboard and mouse.
ForceAutoAim = false
ForceAutoAim = true
; Choose the lock on target to display while auto aiming (0 = default, 1 = SA, 2 = LCS/VCS).
LockOnTargetType = 1
; While aiming with mouse, displays a triangle with the color of the health over the head of the pedestrian.
ShowTriangleForMouseRecruit = true
; Makes the player walk if the left alt key is pressed.
EnableLAltKeyWalk = true
; Makes the player walk using the defined keyboard key (NULL to disable).
WalkKey = LALT
; Makes camera while aiming similar to LCS/VCS.
StoriesAimingCoords = false
; Crosshair position from (0.0f - 1.0f) while aiming in third person (default 0.53f, 0.4f).
Expand Down
312 changes: 304 additions & 8 deletions source/ClassicAxis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,296 @@ void ClassicAxis::ClearWeaponTarget(CPlayerPed* ped) {
gCrossHair.ClearCrossHair();
}

std::string controlKeysStrings[62] = {
"ESC",
"F1",
"F2",
"F3",
"F4",
"F5",
"F6",
"F7",
"F8",
"F9",
"F10",
"F11",
"F12",
"INS",
"DEL",
"HOME",
"END",
"PGUP",
"PGDN",
"UP",
"DOWN",
"LEFT",
"RIGHT",
"DIVIDE",
"TIMES",
"PLUS",
"MINUS",
"PADDEL",
"PADEND",
"PADDOWN",
"PADPGDN",
"PADLEFT",
"PAD5",
"NUMLOCK",
"PADRIGHT",
"PADHOME",
"PADUP",
"PADPGUP",
"PADINS",
"PADENTER",
"SCROLL",
"PAUSE",
"BACKSP",
"TAB",
"CAPSLK",
"ENTER",
"LSHIFT",
"RSHIFT",
"SHIFT",
"LCTRL",
"RCTRL",
"LALT",
"RALT",
"LWIN",
"RWIN",
"APPS",
"NULL"
};

int ClassicAxis::StringToKey(std::string str) {
int key = str[0];

if (str[0] && str[1] != '\0') {
if (!str.compare("SPACE"))
return rsSPACE;

for (int i = 0; i < arraySize(controlKeysStrings); i++) {
if (!str.compare(controlKeysStrings[i])) {
key = i + rsESC;
break;
}
}
}

return key;
}

bool ClassicAxis::GetKeyDown(int key, bool old) {
CPad* pad = CPad::GetPad(0);
CKeyboardState* keyState = NULL;

if (old)
keyState = &pad->OldKeyState;
else
keyState = &pad->NewKeyState;

if (key < 255) {
if (keyState->standardKeys[key])
return true;
}

for (int i = 0; i < 12; i++) {
if (i + rsF1 == key) {
if (keyState->FKeys[i])
return true;
}
}

switch (key) {
case rsESC:
if (keyState->esc)
return true;
break;
case rsINS:
if (keyState->insert)
return true;
break;
case rsDEL:
if (keyState->del)
return true;
break;
case rsHOME:
if (keyState->home)
return true;
break;
case rsEND:
if (keyState->end)
return true;
break;
case rsPGUP:
if (keyState->pgup)
return true;
break;
case rsPGDN:
if (keyState->pgdn)
return true;
break;
case rsUP:
if (keyState->up)
return true;
break;
case rsDOWN:
if (keyState->down)
return true;
break;
case rsLEFT:
if (keyState->left)
return true;
break;
case rsRIGHT:
if (keyState->right)
return true;
break;
case rsSCROLL:
if (keyState->scroll)
return true;
break;
case rsPAUSE:
if (keyState->pause)
return true;
break;
case rsNUMLOCK:
if (keyState->numlock)
return true;
break;
case rsDIVIDE:
if (keyState->div)
return true;
break;
case rsTIMES:
if (keyState->mul)
return true;
break;
case rsMINUS:
if (keyState->sub)
return true;
break;
case rsPLUS:
if (keyState->add)
return true;
break;
case rsPADENTER:
if (keyState->enter)
return true;
break;
case rsPADDEL:
if (keyState->decimal)
return true;
break;
case rsPADEND:
if (keyState->num1)
return true;
break;
case rsPADDOWN:
if (keyState->num2)
return true;
break;
case rsPADPGDN:
if (keyState->num3)
return true;
break;
case rsPADLEFT:
if (keyState->num4)
return true;
break;
case rsPAD5:
if (keyState->num5)
return true;
break;
case rsPADRIGHT:
if (keyState->num6)
return true;
break;
case rsPADHOME:
if (keyState->num7)
return true;
break;
case rsPADUP:
if (keyState->num8)
return true;
break;
case rsPADPGUP:
if (keyState->num9)
return true;
break;
case rsPADINS:
if (keyState->num0)
return true;
break;
case rsBACKSP:
if (keyState->back)
return true;
break;
case rsTAB:
if (keyState->tab)
return true;
break;
case rsCAPSLK:
if (keyState->capslock)
return true;
break;
case rsENTER:
if (keyState->extenter)
return true;
break;
case rsLSHIFT:
if (keyState->lshift)
return true;
break;
case rsSHIFT:
if (keyState->shift)
return true;
break;
case rsRSHIFT:
if (keyState->rshift)
return true;
break;
case rsLCTRL:
if (keyState->lctrl)
return true;
break;
case rsRCTRL:
if (keyState->rctrl)
return true;
break;
case rsLALT:
if (keyState->lmenu)
return true;
break;
case rsRALT:
if (keyState->rmenu)
return true;
break;
case rsLWIN:
if (keyState->lwin)
return true;
break;
case rsRWIN:
if (keyState->rwin)
return true;
break;
case rsAPPS:
if (keyState->apps)
return true;
break;
default:
break;
}

return false;
}

bool ClassicAxis::WalkKeyDown() {
if (CPad::GetPad(0)->DisablePlayerControls)
return false;

return GetKeyDown(StringToKey(settings.walkKey));
}

void ClassicAxis::ProcessPlayerPedControl(CPlayerPed* playa) {
CPad* pad = CPad::GetPad(0);
CCam& cam = TheCamera.m_asCams[TheCamera.m_nActiveCam];
Expand All @@ -844,7 +1134,7 @@ void ClassicAxis::ProcessPlayerPedControl(CPlayerPed* playa) {
CWeaponInfo* info = CWeaponInfo::GetWeaponInfo(weaponType);
const bool hasPadInHands = pXboxPad->HasPadInHands();

if (pad->NewKeyState.lmenu && settings.altKeyWalk) {
if (WalkKeyDown()) {
playa->m_fMoveSpeed = 0.0f;
}

Expand Down Expand Up @@ -903,12 +1193,12 @@ void ClassicAxis::ProcessPlayerPedControl(CPlayerPed* playa) {
transitionDone = false;

if ((transitionDone && ((pXboxPad->HasPadInHands() &&
(pad->Mode == 4 ? pad->NewState.LeftShoulder2 < 99 : (pad->LookAroundLeftRight() || pad->LookAroundUpDown()))) || (abs(mouseX) > 1.0f || abs(mouseY) > 1.0f))) ||
(pad->Mode == 4 ? pad->NewState.LeftShoulder2 < 254 : (pad->LookAroundLeftRight() || pad->LookAroundUpDown()))) || (abs(mouseX) > 1.0f || abs(mouseY) > 1.0f))) ||
diff.Magnitude() < 0.5f)
ClearWeaponTarget(playa);
}
else {
if (/*!pad->SecondaryFireJustDown() && */(pad->Mode == 4 ? pad->NewState.LeftShoulder2 >= 100 : pad->ShiftTargetLeftJustDown() || pad->ShiftTargetRightJustDown()))
if (/*!pad->SecondaryFireJustDown() && */(pad->Mode == 4 ? pad->NewState.LeftShoulder2 >= 254 : pad->ShiftTargetLeftJustDown() || pad->ShiftTargetRightJustDown()))
playa->FindWeaponLockOnTarget();
}
}
Expand Down Expand Up @@ -1062,11 +1352,7 @@ void ClassicAxis::ProcessPlayerPedControl(CPlayerPed* playa) {

#ifdef GTA3
if (!pad->DisablePlayerControls && (mode == MODE_FOLLOW_PED || mode == MODE_AIMWEAPON) && IsAbleToAim(playa)) {
const char key = 'C';
bool duckJustDown = pad->NewKeyState.standardKeys[key] && !pad->OldKeyState.standardKeys[key];

if (hasPadInHands)
duckJustDown |= pad->NewState.ShockButtonL && !pad->OldState.ShockButtonL;
bool duckJustDown = DuckKeyDown();

if (!playa->m_nPedFlags.bIsDucking && duckJustDown && playa->m_eMoveState != PEDMOVE_SPRINT) {
playa->m_nPedFlags.bCrouchWhenShooting = true;
Expand Down Expand Up @@ -1145,6 +1431,16 @@ void ClassicAxis::Find3rdPersonMouseTarget(CPlayerPed* ped) {
}

#ifdef GTA3
bool ClassicAxis::DuckKeyDown() {
if (CPad::GetPad(0)->DisablePlayerControls)
return false;

if (classicAxis.pXboxPad->HasPadInHands())
return CPad::GetPad(0)->NewState.ShockButtonL && !CPad::GetPad(0)->OldState.ShockButtonL;

return GetKeyDown(StringToKey(settings.crouchKey)) && !GetKeyDown(StringToKey(settings.crouchKey), true);
}

void ClassicAxis::SetDuck(CPlayerPed* ped) {
if (ped->m_nPedFlags.bIsDucking || CTimer::m_snTimeInMilliseconds <= ped->m_nDuckTimer) {
if (CTimer::m_snTimeInMilliseconds + 60000 > ped->m_nDuckTimer)
Expand Down
4 changes: 4 additions & 0 deletions source/ClassicAxis.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,15 @@ class ClassicAxis {
void DrawAutoAimTarget();
void DrawTriangleForMouseRecruitPed();
void ClearWeaponTarget(CPlayerPed* ped);
int StringToKey(std::string str);
bool GetKeyDown(int key, bool old = false);
bool WalkKeyDown();
void ProcessPlayerPedControl(CPlayerPed* ped);
float Find3rdPersonQuickAimPitch(float y);
void Find3rdPersonMouseTarget(CPlayerPed* ped);

#ifdef GTA3
bool DuckKeyDown();
void SetDuck(CPlayerPed* ped);
void ClearDuck(CPlayerPed* ped);
void AdjustWeaponInfoForCrouch(CPlayerPed* ped);
Expand Down
Loading

0 comments on commit f2f804e

Please sign in to comment.