Skip to content

Commit

Permalink
Merge Verify pickup weapon component is valid on creation (pr-2797)
Browse files Browse the repository at this point in the history
15417bd - fix(game/five): verify pickup weapon component is valid on creation
  • Loading branch information
prikolium-cfx committed Oct 3, 2024
2 parents 9f4ea0e + 15417bd commit a737e50
Showing 1 changed file with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <jitasm.h>
#include <Hooking.h>
#include <Hooking.Stubs.h>
#include <CrossBuildRuntime.h>

static void (*origCPedModelInfo__SetupPedBuoyancyInfo)(void* BuoyancyInfo, const void* pCapsuleInfo, const void* FragType, bool bIsWeightless);

Expand Down Expand Up @@ -67,4 +68,56 @@ static HookFunction hookFunction([]
// CPedModelInfo::SetupPedBuoyancyInfo doesn't check that FragType isn't null.
origCPedModelInfo__SetupPedBuoyancyInfo = hook::trampoline(hook::get_call(hook::get_pattern("45 33 C9 4C 8B C0 48 8B D3 E8", 0x9)), &CPedModelInfo__SetupPedBuoyancyInfo);
}

// Not present on 1604 and we don't care about builds between 1604 and 2060
if (xbr::IsGameBuildOrGreater<2060>())
{
// Test for a valid weapon component info pointer before de-referencing it.
static struct : jitasm::Frontend
{
intptr_t retFail;
intptr_t retSuccess;

void Init(intptr_t location)
{
retFail = location + 14;
retSuccess = location + 6;
}

void InternalMain() override
{
test(rbx, rbx); // if ( rbx )
jz("fail"); // {
//
// * original code //
mov(rax, qword_ptr[rbx]); //
// [run original code]
mov(rcx, rbx); //
// * original code END //
//
mov(rax, retSuccess); //
jmp(rax); //
// }
L("fail"); //
mov(rax, retFail); //
jmp(rax); //
}

} patchStub;

// mov rax, [rbx]
auto location = hook::get_pattern<char>("7E ? 33 DB 48 8B 03", 4);

patchStub.Init(reinterpret_cast<intptr_t>(location));

/*
* nop:
*
* mov rax, [rbx]
* mov rcx, rbx
*/
hook::nop(location, 6);

hook::jump_rcx(location, patchStub.GetCode());
}
});

0 comments on commit a737e50

Please sign in to comment.