From 13ebfa267974a798d60c92fd9b4953afc293950f Mon Sep 17 00:00:00 2001 From: trent <109549513+bleenobtw@users.noreply.github.com> Date: Tue, 21 Oct 2025 15:15:13 +0100 Subject: [PATCH] feat(extra-natives/five): weapon range getter & setter natives --- .../src/WeaponExtraNatives.cpp | 20 ++++++++++++++++++ ext/native-decls/GetWeaponRange.md | 21 +++++++++++++++++++ ext/native-decls/SetWeaponRange.md | 18 ++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 ext/native-decls/GetWeaponRange.md create mode 100644 ext/native-decls/SetWeaponRange.md diff --git a/code/components/extra-natives-five/src/WeaponExtraNatives.cpp b/code/components/extra-natives-five/src/WeaponExtraNatives.cpp index 87c8c10f7a..01d8142fd2 100644 --- a/code/components/extra-natives-five/src/WeaponExtraNatives.cpp +++ b/code/components/extra-natives-five/src/WeaponExtraNatives.cpp @@ -21,6 +21,7 @@ static int PedOffset = 0x10; static int CurrentPitchOffset = 0x1CC; static int NetworkObjectOffset = 0xD0; static int IsCloneOffset = 0x4B; +static int RangeOffset = 0x28C; static uint16_t* g_weaponCount; static uint64_t** g_weaponList; @@ -461,6 +462,25 @@ static HookFunction hookFunction([]() } }); + fx::ScriptEngine::RegisterNativeHandler("GET_WEAPON_RANGE", [](fx::ScriptContext& context) + { + float weaponRange = 0.0f; + if (uintptr_t weapon = getWeaponFromHash(context)) + { + weaponRange = reinterpret_cast(weapon)->Get(RangeOffset); + } + context.SetResult(weaponRange); + }); + + fx::ScriptEngine::RegisterNativeHandler("SET_WEAPON_RANGE", [](fx::ScriptContext& context) + { + if (uintptr_t weapon = getWeaponFromHash(context)) + { + float weaponRange = context.GetArgument(1); + reinterpret_cast(weapon)->Set(RangeOffset, weaponRange); + } + }); + fx::ScriptEngine::RegisterNativeHandler("SET_FLASH_LIGHT_KEEP_ON_WHILE_MOVING", [](fx::ScriptContext& context) { bool value = context.GetArgument(0); diff --git a/ext/native-decls/GetWeaponRange.md b/ext/native-decls/GetWeaponRange.md new file mode 100644 index 0000000000..a2d20dc3f2 --- /dev/null +++ b/ext/native-decls/GetWeaponRange.md @@ -0,0 +1,21 @@ +--- +ns: CFX +apiset: client +game: gta5 +--- + +## GET_WEAPON_RANGE + +```c +float GET_WEAPON_RANGE(Hash weaponHash); +``` + +A getter for the range of a weapon. + +## Parameters + +- **weaponHash**: Weapon name hash. + +## Return value + +The range of the weapon as a float. diff --git a/ext/native-decls/SetWeaponRange.md b/ext/native-decls/SetWeaponRange.md new file mode 100644 index 0000000000..06900c8dab --- /dev/null +++ b/ext/native-decls/SetWeaponRange.md @@ -0,0 +1,18 @@ +--- +ns: CFX +apiset: client +game: gta5 +--- + +## SET_WEAPON_RANGE + +```c +void SET_WEAPON_RANGE(Hash weaponHash, float range); +``` + +A setter for the range of a weapon. + +## Parameters + +- **weaponHash**: Weapon name hash. +- **range**: Ramge.