Skip to content

Commit

Permalink
feat(extra-natives-five): add SET_PED_TURNING_THRESHOLDS. Allows tun-…
Browse files Browse the repository at this point in the history
…ability of the aiming transition threshold angles.

TL;DR - It is currently faster to shoot while strafing right vs. strafing left.
  • Loading branch information
LWSS committed Nov 28, 2023
1 parent b10006d commit 4c4a746
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
54 changes: 54 additions & 0 deletions code/components/extra-natives-five/src/PedExtraNatives.cpp
Expand Up @@ -11,6 +11,8 @@
#include "atArray.h"

#include <GameInit.h>
#include <fxScripting.h>
#include <Resource.h>

class CPedHeadBlendData
{
Expand Down Expand Up @@ -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<uint64_t(void* entity, uint64_t list)> g_extensionList_get([]()
{
Expand Down Expand Up @@ -100,6 +109,10 @@ static HookFunction initFunction([]()

g_pedPersonalities = hook::get_address<decltype(g_pedPersonalities)>(hook::get_call(hook::get_pattern<char>("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<float*>(ptr, 3, 7);
_motionAimingTurnTransitionThresholdMax = hook::get_address<float*>(ptr + 9, 3, 7);

fx::ScriptEngine::RegisterNativeHandler("GET_PED_EYE_COLOR", [=](fx::ScriptContext& context)
{
int result = -1;
Expand Down Expand Up @@ -366,4 +379,45 @@ static HookFunction initFunction([]()

context.SetResult<bool>(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<float>(0);
float max = context.GetArgument<float>(1);

*_motionAimingTurnTransitionThresholdMin = DEG2RAD(min);
*_motionAimingTurnTransitionThresholdMax = DEG2RAD(max);

fx::OMPtr<IScriptRuntime> runtime;
if (FX_SUCCEEDED(fx::GetCurrentScriptRuntime(&runtime)))
{
fx::Resource* resource = reinterpret_cast<fx::Resource*>(runtime->GetParentObject());

resource->OnStop.Connect([]()
{
*_motionAimingTurnTransitionThresholdMin = DEG2RAD(45.0f);
*_motionAimingTurnTransitionThresholdMax = DEG2RAD(135.0f);
});
}
});
});
38 changes: 38 additions & 0 deletions 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

0 comments on commit 4c4a746

Please sign in to comment.