Skip to content
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

fix(gta-core-five): validate bounds collisions #3182

Merged
merged 1 commit into from
Mar 12, 2025
Merged
Changes from all commits
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
59 changes: 59 additions & 0 deletions code/components/gta-core-five/src/CrashFixes.SelfCollision.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include "StdInc.h"

#include "Hooking.Patterns.h"
#include "Hooking.Stubs.h"
#include <DirectXMath.h>

namespace rage {
struct alignas(16) Vec3V
{
float x;
float y;
float z;
float pad;

Vec3V()
: x(0), y(0), z(0), pad(NAN)
{
}

Vec3V(float x, float y, float z)
: x(x), y(y), z(z), pad(NAN)
{
}
};
struct phBound
{
uint8_t m_Type;
uint8_t m_Flags;
uint8_t m_PartIndex;
float m_RadiusAroundCentroid;
};
using Mat34V = DirectX::XMMATRIX;

struct phBoundComposite : phBound {
phBound** m_Bounds;
rage::Mat34V* m_CurrentMatrices;
rage::Mat34V* m_LastMatrices;
rage::Vec3V* m_LocalBoxMinMaxs;
uint32_t* m_TypeAndIncludeFlags;
uint32_t* m_OwnedTypeAndIncludeFlags;
uint16_t m_MaxNumBounds;
uint16_t m_NumBounds;
};
}

static void (*g_origProcessSelfCollision)(void* self, rage::phBoundComposite* boundComposite, rage::Mat34V* a3, rage::Mat34V a4, void* phManifold, unsigned __int8* a6, unsigned __int8* a7, int a8, bool a9);
static void ProcessSelfCollision(void* self, rage::phBoundComposite* boundComposite, rage::Mat34V* a3, rage::Mat34V a4, void* phManifold, unsigned __int8* a6, unsigned __int8* a7, int a8, bool a9)
{
if (!boundComposite || !boundComposite->m_Bounds)
{
return;
}
g_origProcessSelfCollision(self, boundComposite, a3, a4, phManifold, a6, a7, a8, a9);
}

static HookFunction hookFunction([]()
{
g_origProcessSelfCollision = hook::trampoline(hook::get_pattern("48 8B C4 48 89 58 ? 4C 89 48 ? 4C 89 40 ? 48 89 50 ? 55 56 57 41 54 41 55 41 56 41 57 48 8D A8 ? ? ? ? B8"), ProcessSelfCollision);
});
Loading