Fix the evasive dive miscalculating the angle, resulting in peds diving towards the vehicle

Fixes #3
This commit is contained in:
Silent 2024-03-13 22:15:34 +01:00
parent e4190105bc
commit 56ac3b8795
No known key found for this signature in database
GPG Key ID: AE53149BB0C45AF1
2 changed files with 99 additions and 5 deletions

View File

@ -1,10 +1,12 @@
#ifndef __MATHS__H #pragma once
#define __MATHS__H
#define _USE_MATH_DEFINES
#include <math.h>
#include <rwcore.h> #include <rwcore.h>
constexpr double RAD_TO_DEG (180.0/3.1415926535897932385); constexpr double RAD_TO_DEG (180.0/M_PI);
constexpr double DEG_TO_RAD (3.1415926535897932385/180.0); constexpr double DEG_TO_RAD (M_PI/180.0);
class CRGBA class CRGBA
{ {
@ -515,4 +517,56 @@ inline CVector& CVector::FromMultiply3X3(const CMatrix& mat, const CVector& vec)
return *this = Multiply3x3(mat, vec); return *this = Multiply3x3(mat, vec);
} }
#endif class CGeneral
{
public:
static float GetRadianAngleBetweenPoints(float x1, float y1, float x2, float y2)
{
float x = x2 - x1;
float y = y2 - y1;
if (y == 0.0f)
{
y = 0.0001f;
}
if (x > 0.0f)
{
if (y > 0.0f)
{
return static_cast<float>(M_PI - std::atan2(x / y, 1.0f));
}
else
{
return -std::atan2(x / y, 1.0f);
}
}
else
{
if (y > 0.0f)
{
return -static_cast<float>(M_PI + std::atan2(x / y, 1.0f));
}
else
{
return -std::atan2(x / y, 1.0f);
}
}
}
static float LimitRadianAngle(float angle)
{
while (angle >= M_PI)
{
angle -= static_cast<float>(2.0f * M_PI);
}
while (angle < -M_PI)
{
angle += static_cast<float>(2.0f * M_PI);
}
return angle;
}
};

View File

@ -544,6 +544,35 @@ namespace SkinTextureFilter
} }
// ============= Fix the evasive dive miscalculating the angle, resulting in peds diving towards the vehicle =============
namespace EvasiveDiveFix
{
static float CalculateAngle(float x, float y)
{
float angle = static_cast<float>(CGeneral::GetRadianAngleBetweenPoints(x, y, 0.0f, 0.0f) - M_PI_2);
if ((rand() & 1) != 0)
{
angle += static_cast<float>(M_PI);
}
return CGeneral::LimitRadianAngle(angle);
}
__declspec(naked) void CalculateAngle_Hook()
{
_asm
{
push dword ptr [esi+7Ch]
push dword ptr [esi+78h]
call CalculateAngle
add esp, 8
mov ecx, ebp
retn
}
}
}
void InjectDelayedPatches_III_Common( bool bHasDebugMenu, const wchar_t* wcModulePath ) void InjectDelayedPatches_III_Common( bool bHasDebugMenu, const wchar_t* wcModulePath )
{ {
using namespace Memory; using namespace Memory;
@ -1353,6 +1382,17 @@ void Patch_III_Common()
InterceptCall(setEnvironmentMap, CVehicleModelInfo::orgSetEnvironmentMap, &CVehicleModelInfo::SetEnvironmentMap_ExtraComps); InterceptCall(setEnvironmentMap, CVehicleModelInfo::orgSetEnvironmentMap, &CVehicleModelInfo::SetEnvironmentMap_ExtraComps);
} }
// Fix the evasive dive miscalculating the angle, resulting in peds diving towards the vehicle
{
using namespace EvasiveDiveFix;
auto setEvasiveDive = pattern("D9 44 24 10 89 E9 D9 9D ? ? ? ? E8 ? ? ? ? 89 E9 E8 ? ? ? ? 89 E9 E8 ? ? ? ? C7 85").get_one();
Nop(setEvasiveDive.get<void>(), 1);
InjectHook(setEvasiveDive.get<void>(1), &CalculateAngle_Hook, HookType::Call);
}
} }
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)