-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge Fixed crash when switching to an invalid ped drawable (mr-466)
558eecb - fix: fixed crash when switching to an invalid ped drawable
- Loading branch information
Showing
2 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
code/components/gta-core-five/src/CrashFixes.PedClothController.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include <StdInc.h> | ||
|
||
#include <Hooking.h> | ||
#include <Hooking.Stubs.h> | ||
#include <Hooking.FlexStruct.h> | ||
|
||
static void (*orig_CPedVariationStream__ApplyStreamPedFiles)(hook::FlexStruct* pPed, void* pNewVarData, void* pPSGfx); | ||
static uint32_t off_CPed__m_CClothController; | ||
|
||
// CPed holds non-owning pointers to each component's characterClothController. | ||
// ApplyStreamPedFiles should update all of these, since they will stop existing soon afterwards. | ||
// However, if a new component does not have a texture or drawable, the update loop will skip it without nulling the existing pointer. | ||
static void CPedVariationStream__ApplyStreamPedFiles(hook::FlexStruct* pPed, void* pNewVarData, void* pPSGfx) | ||
{ | ||
void** controllers = pPed->At<void*[]>(off_CPed__m_CClothController); | ||
void* oldControllers[12]; | ||
|
||
for (int i = 0; i < 12; ++i) | ||
{ | ||
oldControllers[i] = controllers[i]; | ||
} | ||
|
||
orig_CPedVariationStream__ApplyStreamPedFiles(pPed, pNewVarData, pPSGfx); | ||
|
||
for (int i = 0; i < 12; ++i) | ||
{ | ||
if (controllers[i] && controllers[i] == oldControllers[i]) | ||
{ | ||
// We're still holding a pointer to the old controller! | ||
trace("Stale cloth controller pointer crash prevented [CFX-1735]\n"); | ||
controllers[i] = nullptr; | ||
} | ||
} | ||
} | ||
|
||
static HookFunction hookFunction([] | ||
{ | ||
orig_CPedVariationStream__ApplyStreamPedFiles = hook::trampoline(hook::get_call(hook::get_pattern("4C 8B C3 48 8B D6 E8 ? ? ? ? 48 8B D7", 6)), &CPedVariationStream__ApplyStreamPedFiles); | ||
|
||
off_CPed__m_CClothController = *(uint32_t*)hook::get_pattern<char>("40 88 B8 ? ? ? ? 4A 89 BC E6", 11); | ||
}); |