Skip to content

feat(extra-natives/five): GET_WEAPON_ACCURACY_SPREAD & SET_WEAPON_ACC… #3356

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions code/components/extra-natives-five/src/WeaponExtraNatives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
static int WeaponDamageModifierOffset;
static int WeaponAnimationOverrideOffset;
static int WeaponRecoilShakeAmplitudeOffset;
static int weapon_spread_offset;
static int ObjectWeaponOffset;

static int PedOffset = 0x10;
Expand Down Expand Up @@ -354,6 +355,7 @@ static HookFunction hookFunction([]()
WeaponDamageModifierOffset = *hook::get_pattern<int>("48 8B 0C F8 89 B1", 6);
WeaponAnimationOverrideOffset = *hook::get_pattern<int>("8B 9F ? ? ? ? 85 DB 75 3E", 2);
WeaponRecoilShakeAmplitudeOffset = *hook::get_pattern<int>("48 8B 47 40 F3 0F 10 B0 ? ? ? ?", 8);
weapon_spread_offset = *hook::get_pattern<uint8_t>("F3 0F 59 59 ? F3 0F 59 D8", 4);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use same name styling as above please


ObjectWeaponOffset = *hook::get_pattern<int>("74 5C 48 83 BB ? ? ? ? 00 75 52", 5);

Expand Down Expand Up @@ -396,6 +398,27 @@ static HookFunction hookFunction([]()
}
});

fx::ScriptEngine::RegisterNativeHandler("GET_WEAPON_ACCURACY_SPREAD", [](fx::ScriptContext& context)
{
int accuracy_spread = 0;

if (auto weapon = getWeaponFromHash(context))
{
accuracy_spread = *(int*)(weapon + weapon_spread_offset);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use hook::FlexStruct to make this code easier to read please?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And same notice about variable name styling

}

context.SetResult<int>(accuracy_spread);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why in GET we return it as int and in SET we set float?

});

fx::ScriptEngine::RegisterNativeHandler("SET_WEAPON_ACCURACY_SPREAD", [](fx::ScriptContext& context)
{
if (auto weapon = getWeaponFromHash(context))
{
float weapon_spread_accuracy = context.GetArgument<float>(1);

*(float*)(weapon + weapon_spread_offset) = weapon_spread_accuracy;
}
});

fx::ScriptEngine::RegisterNativeHandler("SET_FLASH_LIGHT_KEEP_ON_WHILE_MOVING", [](fx::ScriptContext& context)
{
Expand Down
21 changes: 21 additions & 0 deletions ext/native-decls/GetWeaponAccuracySpread.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
ns: CFX
apiset: client
game: gta5
---

## GET_WEAPON_ACCURACY_SPREAD

```c
float GET_WEAPON_ACCURACY_SPREAD(Hash weaponHash);
```

A getter for the accuracy spread of a weapon.

## Parameters

- **weaponHash**: Weapon name hash.

## Return value

The accuracy spread of a weapon.
18 changes: 18 additions & 0 deletions ext/native-decls/SetWeaponAccuracySpread.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
ns: CFX
apiset: client
game: gta5
---

## SET_WEAPON_ACCURACY_SPREAD

```c
void SET_WEAPON_ACCURACY_SPREAD(Hash weaponHash, float spread);
```

A setter for the accuracy spread of a weapon.

## Parameters

- **weaponHash**: Weapon name hash.
- **spread**: Accuracy spread
Loading