Skip to content
Permalink
Browse files

protect pAssociationArray instead of iIDOffset member (CreateAnimAsso…

…cGroups hook)
  • Loading branch information...
codenulls committed Jun 29, 2019
1 parent 48878af commit 91ca881492fc2e6d4e8dfa4fed708474041767d2
@@ -50,6 +50,8 @@ unsigned long CMultiplayerSA::ADDR_GotFocus;

unsigned long CMultiplayerSA::FUNC_CPlayerInfoBase;

std::array<unsigned int, 3> CMultiplayerSA::arrGroupsToProtect = {{ANIM_GROUP_BBBAT_1, ANIM_GROUP_MUSCULAR, ANIM_GROUP_SWORD_1}};

#define HOOKPOS_FxManager_CreateFxSystem 0x4A9BE0
#define HOOKPOS_FxManager_DestroyFxSystem 0x4A9810

@@ -288,10 +288,11 @@ class CMultiplayerSA : public CMultiplayer
DWORD GetLastStaticAnimationID() { return m_dwLastStaticAnimID; }
DWORD GetLastAnimArrayAddress() { return m_dwLastAnimArrayAddress; }

CVector m_vecAkimboTarget;
bool m_bAkimboTargetUp;
static char* ms_PlayerImgCachePtr;
bool m_bBadDrivebyHitboxesDisabled;
CVector m_vecAkimboTarget;
bool m_bAkimboTargetUp;
static char* ms_PlayerImgCachePtr;
static std::array<unsigned int, 3> arrGroupsToProtect;
bool m_bBadDrivebyHitboxesDisabled;

private:
bool m_bSuspensionEnabled;
@@ -1525,32 +1525,40 @@ void _declspec(naked) HOOK_CAnimBlendNode_GetCurrentTranslation()
//
// CAnimManager_CreateAnimAssocGroups
//
// Protect `iIDOffset` member of specific anim groups (CAnimBlendAssocGroupSAInterface)
// Protect `pAssociationsArray` member of specific anim groups (CAnimBlendAssocGroupSAInterface)
// from corruption by placing a WRITE operation breakpoint on its address.
//
//////////////////////////////////////////////////////////////////////////////////////////
void __cdecl OnMY_CAnimManager_CreateAnimAssocGroups_Protect(CAnimBlendAssocGroupSAInterface* pGroupInterface)
{
std::array<unsigned int, 3> arrGroupsToProtect = {ANIM_GROUP_BBBAT_1, ANIM_GROUP_MUSCULAR, ANIM_GROUP_SWORD_1};
for (auto groupID : arrGroupsToProtect)
static std::set<unsigned int> setOfGroupBreakpointsAdded;

void* ppAssociationsArray = reinterpret_cast<void*>(&pGroupInterface->pAssociationsArray);
for (auto groupID : CMultiplayerSA::arrGroupsToProtect)
{
if (pGroupInterface->groupID == groupID)
if (pGroupInterface->groupID == groupID && !MapContains(setOfGroupBreakpointsAdded, groupID))
{
HANDLE mainThread = OpenThread(THREAD_ALL_ACCESS, TRUE, SharedUtil::GetMainThreadId());
assert(mainThread != NULL);

void* pIdOffsetMember = reinterpret_cast<void*>(&pGroupInterface->iIDOffset);
SetHardwareBreakpoint(mainThread, HWBRK_TYPE_WRITE, HWBRK_SIZE_4, pIdOffsetMember);
SetHardwareBreakpoint(mainThread, HWBRK_TYPE_WRITE, HWBRK_SIZE_4, ppAssociationsArray);

CloseHandle(mainThread);

setOfGroupBreakpointsAdded.insert(groupID);

LogEvent(511, "Breakpoint", "Hardware Breakpoint set on WRITE access",
SString("groupID: %u | pGroupInterface: %#.8x, pIdOffsetMember = %#.8x | iIDOffset: %d", groupID, pGroupInterface, pIdOffsetMember,
pGroupInterface->iIDOffset),
SString("groupID: %u | pGroupInterface: %#.8x, ppAssociationsArray = %#.8x | pAssociationsArray: %p", groupID, pGroupInterface,
ppAssociationsArray, pGroupInterface->pAssociationsArray),
511);
break;
return;
}
}

LogEvent(512, "GroupLoaded", "Anim group loaded",
SString("groupID: %u | pGroupInterface: %#.8x, ppAssociationsArray = %#.8x | pAssociationsArray: %p", pGroupInterface->groupID, pGroupInterface,
ppAssociationsArray, pGroupInterface->pAssociationsArray),
512);
}

// Hook info
@@ -39,6 +39,7 @@
#include "..\game_sa\CEntitySA.h"
#include "..\game_sa\CBuildingSA.h"
#include "..\game_sa\CPedSA.h"
#include "..\game_sa\CAnimBlendAssocGroupSA.h"
#include "..\game_sa\common.h"
#include "..\core\CCrashDumpWriter.h"

0 comments on commit 91ca881

Please sign in to comment.
You can’t perform that action at this time.