From 4c4a7464ca95070c7fb8a2f366dd19236d0230d1 Mon Sep 17 00:00:00 2001 From: LWSS Date: Tue, 28 Nov 2023 13:39:17 -0800 Subject: [PATCH] feat(extra-natives-five): add SET_PED_TURNING_THRESHOLDS. Allows tun-ability of the aiming transition threshold angles. TL;DR - It is currently faster to shoot while strafing right vs. strafing left. --- .../src/PedExtraNatives.cpp | 54 +++++++++++++++++++ ext/native-decls/SetPedTurningThresholds.md | 38 +++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 ext/native-decls/SetPedTurningThresholds.md diff --git a/code/components/extra-natives-five/src/PedExtraNatives.cpp b/code/components/extra-natives-five/src/PedExtraNatives.cpp index ef870e9bcf..2c9b51249c 100644 --- a/code/components/extra-natives-five/src/PedExtraNatives.cpp +++ b/code/components/extra-natives-five/src/PedExtraNatives.cpp @@ -11,6 +11,8 @@ #include "atArray.h" #include +#include +#include class CPedHeadBlendData { @@ -56,6 +58,13 @@ class CPedHeadBlendData static uint64_t* _id_CPedHeadBlendData; static uintptr_t _baseClipsetLocation; static uint32_t _pedSweatOffset; +static float* _motionAimingTurnTransitionThresholdMin = nullptr; +static float* _motionAimingTurnTransitionThresholdMax = nullptr; + +// There really isn't a deg2rad function anywhere (TODO: move this to a sensible spot?) +#define MATH_PI 3.14159265358979323846f +#define MATH_DEG2RAD (MATH_PI / 180.0f) +#define DEG2RAD(angle) ((angle) * MATH_DEG2RAD) static hook::cdecl_stub g_extensionList_get([]() { @@ -100,6 +109,10 @@ static HookFunction initFunction([]() g_pedPersonalities = hook::get_address(hook::get_call(hook::get_pattern("8B 86 B0 00 00 00 BB D5 46 DF E4 85 C0", 0x12)) + 15, 3, 7); + uint8_t* ptr = (uint8_t*)hook::get_pattern("0F 2F 35 ? ? ? ? 72 ? 0F 2F 35 ? ? ? ? 76 ? B0"); + _motionAimingTurnTransitionThresholdMin = hook::get_address(ptr, 3, 7); + _motionAimingTurnTransitionThresholdMax = hook::get_address(ptr + 9, 3, 7); + fx::ScriptEngine::RegisterNativeHandler("GET_PED_EYE_COLOR", [=](fx::ScriptContext& context) { int result = -1; @@ -366,4 +379,45 @@ static HookFunction initFunction([]() context.SetResult(result); }); + + + // Purpose: The game's default values for these make shooting while traveling Left quite a bit slower than shooting while traveling right + fx::ScriptEngine::RegisterNativeHandler("SET_PED_TURNING_THRESHOLDS", [](fx::ScriptContext& context) + { + // Default Min: -45 Degrees + // Default Max: 135 Degrees + // + // \ ,- ~ ||~ - , + // , ' \ x x ' , + // , \ x x x , + // , \ x x , + // , \ x x , + // , \ x , + // , \ x , + // , \ x x , + // , \ x , + // , \, ' + // ' - , _ _ _ , ' \ + // If the transition angle is within the shaded portion (x), there will be no transition(Quicker) + // The angle corresponds to where you are looking(North on the circle) vs. the heading of your character. + // Note: For some reason, the transition spin is only clockwise. + + float min = context.GetArgument(0); + float max = context.GetArgument(1); + + *_motionAimingTurnTransitionThresholdMin = DEG2RAD(min); + *_motionAimingTurnTransitionThresholdMax = DEG2RAD(max); + + fx::OMPtr runtime; + if (FX_SUCCEEDED(fx::GetCurrentScriptRuntime(&runtime))) + { + fx::Resource* resource = reinterpret_cast(runtime->GetParentObject()); + + resource->OnStop.Connect([]() + { + *_motionAimingTurnTransitionThresholdMin = DEG2RAD(45.0f); + *_motionAimingTurnTransitionThresholdMax = DEG2RAD(135.0f); + }); + } + }); }); diff --git a/ext/native-decls/SetPedTurningThresholds.md b/ext/native-decls/SetPedTurningThresholds.md new file mode 100644 index 0000000000..6e78c4e610 --- /dev/null +++ b/ext/native-decls/SetPedTurningThresholds.md @@ -0,0 +1,38 @@ +--- +ns: CFX +apiset: client +--- +## SET_PED_TURNING_THRESHOLDS + +```c +void SET_PED_TURNING_THRESHOLDS(float min, float max); +``` + +Purpose: The game's default values for these make shooting while traveling Left quite a bit slower than shooting while traveling right (This could be a game-balance thing?) + +Default Min: -45 Degrees +Default Max: 135 Degrees + + \ ,- ~ ||~ - , + , ' \ x x ' , + , \ x x x , + , \ x x , +, \ x x , +, \ x , +, \ x , + , \ x x , + , \ x , + , \, ' + ' - , _ _ _ , ' \ + +If the transition angle is within the shaded portion (x), there will be no transition(Quicker) +The angle corresponds to where you are looking(North on the circle) vs. the heading of your Ped. +Note: For some reason, + +You can set these values to whatever you'd like with this native, but keep in mind that the transitional spin is only clockwise for some reason. + +I'd personally recommend something like -135/135 + +## Parameters +* **min**: Leftside angle on the above diagram +* **max**: Rightside angle on the above diagram \ No newline at end of file