Skip to content

Commit 6a32184

Browse files
committed
feat(core/five): Crash fix for grcProgramResource vtable
1 parent 3db90c5 commit 6a32184

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include <StdInc.h>
2+
3+
#include <jitasm.h>
4+
#include <Hooking.h>
5+
6+
static void* SafeGetSrvFromResource(void* resource)
7+
{
8+
__try
9+
{
10+
void** vtable = *(void***)resource;
11+
using GetSrvFn = void* (__fastcall*)(void*);
12+
return ((GetSrvFn)vtable[22])(resource); // 0xB0 / sizeof(void*)
13+
}
14+
__except (EXCEPTION_EXECUTE_HANDLER)
15+
{
16+
static bool warned = false;
17+
if (!warned)
18+
{
19+
warned = true;
20+
trace("WARNING: SetTextureResourcesUsingVectorDXAPICall: skipped freed grcProgramResource (vtable AV)\n");
21+
}
22+
return nullptr;
23+
}
24+
}
25+
26+
static HookFunction hookFunction([]
27+
{
28+
static struct : jitasm::Frontend
29+
{
30+
void InternalMain() override
31+
{
32+
sub(rsp, 0x28);
33+
mov(rax, reinterpret_cast<uintptr_t>(&SafeGetSrvFromResource));
34+
call(rax);
35+
add(rsp, 0x28);
36+
ret();
37+
}
38+
} safeSrvStub;
39+
40+
auto location = hook::get_pattern<char>("48 8B 01 FF 90 ? ? ? ? 4C 8D 05 ? ? ? ? EB");
41+
hook::nop(location, 9);
42+
hook::call(location, safeSrvStub.GetCode());
43+
});

0 commit comments

Comments
 (0)