Skip to content

Commit 1398945

Browse files
committed
[FIX] Fixed AddAnimation hook and disabled AddAnimationAndSync hook.
I used Original code for AddAnimation hook in CClientGame::AddAnimationHandler. It works well. Now, it's time to create our own CAnimBlendAssociationSAInterface instead of using CopyAnimation. I'll need to enable AddAnimationAndSync hook as well because this is called for almost every internal GTA animation.
1 parent 7e4ad6c commit 1398945

File tree

2 files changed

+68
-102
lines changed

2 files changed

+68
-102
lines changed

Client/mods/deathmatch/logic/CClientGame.cpp

Lines changed: 54 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -3989,96 +3989,65 @@ CAnimBlendAssociationSAInterface * CClientGame::AddAnimationHandler ( RpClump *
39893989
{
39903990
printf ( "AddAnimationHandler called! pClump, GroupID, AnimID: %p, %d, %d\n", (void*)pClump, animGroup, animID );
39913991

3992-
CClientPed * pClientPed = GetClientPedByClump ( *pClump ); //pAnimationManager->GetPedPointerFromMap ( pClump ); //m_pRootEntity->GetClientPedByClump ( *pClump );
3993-
if ( pClientPed != nullptr )
3994-
{
3995-
//pClientPed->setCurrentAnimationCustom ( false );
3996-
}
3997-
/*
39983992
hCAnimBlendAssocGroup_CopyAnimation CAnimBlendAssocGroup_CopyAnimation = (hCAnimBlendAssocGroup_CopyAnimation)0x004CE130;
39993993
hUncompressAnimation UncompressAnimation = (hUncompressAnimation)0x4d41c0;
40003994
hCAnimBlendAssoc_Constructor_staticAssocRef OLD_CAnimBlendAssoc_Constructor_staticAssocRef = (hCAnimBlendAssoc_Constructor_staticAssocRef)0x4CF080;
40013995
hCAnimBlendStaticAssoc_Constructor OLD_CAnimBlendStaticAssoc_Constructor = *(hCAnimBlendStaticAssoc_Constructor)0x4CE940;
40023996
hCAnimBlendStaticAssoc_Init OLD_CAnimBlendStaticAssoc_Init = (hCAnimBlendStaticAssoc_Init)0x004CEC20;
4003-
4004-
CAnimManager * pAnimationManager = g_pGame->GetAnimManager();
4005-
auto pOriginalAnimStaticAssoc = pAnimationManager->GetAnimStaticAssociation ( animGroup, animID );
4006-
4007-
CClientPed * pClientPed = pAnimationManager->GetPedPointerFromMap ( pClump );
4008-
if ( pClientPed != nullptr )
4009-
{
4010-
printf("AddAnimationHandler: found client ped pointer from map\n");
4011-
4012-
const SString & strBlockName = pClientPed->GetNextAnimationCustomBlockName ( );
4013-
CClientIFP * pIFP = GetIFPPointerFromMap ( strBlockName );
4014-
if ( pIFP )
4015-
{
4016-
printf("AddAnimationHandler: found IFP pointer from map\n");
4017-
4018-
const SString & strAnimationName = pClientPed->GetNextAnimationCustomName ( );
4019-
_CAnimBlendHierarchy * pCustomAnimBlendHierarchy = (_CAnimBlendHierarchy *)pIFP->GetAnimationHierarchy ( strAnimationName );
4020-
if ( pCustomAnimBlendHierarchy != nullptr )
4021-
{
4022-
printf("AddAnimationHandler:got custom animation hierarchy\n");
4023-
4024-
if ( animGroup == 0 && animID == 55 ) // if it's crouch animation
4025-
{
4026-
printf("AddAnimationHandler: Internal GTA Courch Animation Total Sequences: %d\n", pOriginalAnimStaticAssoc->pAnimHeirarchy->usNumSequences);
4027-
4028-
4029-
auto pCrouchAnimStaticAssoc = pAnimationManager->GetAnimStaticAssociation ( 0, 55 ); // 0, 55 for crouch animation
4030-
4031-
CAnimBlendStaticAssoc * pOriginalAnimStaticAssoc = (CAnimBlendStaticAssoc *)pCrouchAnimStaticAssoc;
4032-
4033-
// let's play the original crouch animation instead for testing ^^
4034-
pCustomAnimBlendHierarchy = pOriginalAnimStaticAssoc->m_pAnimBlendHier;
4035-
4036-
pCustomAnimBlendHierarchy->m_hashKey = pOriginalAnimStaticAssoc->m_pAnimBlendHier->m_hashKey;
4037-
pCustomAnimBlendHierarchy->m_nAnimBlockId = pOriginalAnimStaticAssoc->m_pAnimBlendHier->m_nAnimBlockId;
4038-
4039-
CAnimBlendStaticAssoc CustomAnimStaticAssoc;
4040-
OLD_CAnimBlendStaticAssoc_Constructor ( &CustomAnimStaticAssoc );
4041-
4042-
CustomAnimStaticAssoc.m_nFlags = pOriginalAnimStaticAssoc->m_nFlags;
4043-
4044-
OLD_CAnimBlendStaticAssoc_Init ( &CustomAnimStaticAssoc, pClump, pCustomAnimBlendHierarchy);
4045-
4046-
CustomAnimStaticAssoc.m_nAnimGroup = pOriginalAnimStaticAssoc->m_nAnimGroup;
4047-
CustomAnimStaticAssoc.m_nAnimID = pOriginalAnimStaticAssoc->m_nAnimID;
4048-
4049-
UncompressAnimation ( CustomAnimStaticAssoc.m_pAnimBlendHier );
4050-
CAnimBlendAssoc * pAnimAssoc = (CAnimBlendAssoc *)malloc(sizeof(CAnimBlendAssoc));
4051-
OLD_CAnimBlendAssoc_Constructor_staticAssocRef ( pAnimAssoc, CustomAnimStaticAssoc);
4052-
4053-
pAnimAssoc->m_nAnimGroup = pOriginalAnimStaticAssoc->m_nAnimGroup;
4054-
pAnimAssoc->m_nFlags = pOriginalAnimStaticAssoc->m_nFlags;
4055-
4056-
printf("AddAnimationHandler: returning pAnimAssoc\n");
4057-
return (CAnimBlendAssociationSAInterface * ) pAnimAssoc;
4058-
//auto pAnimStaticAssoc = pAnimationManager->GetAnimStaticAssociation ( 0, 55 ); // 0, 55 for crouch animation
4059-
//return pAnimStaticAssoc->pAnimHeirarchy;
4060-
}
4061-
}
4062-
else
4063-
{
4064-
printf ("AddAnimationHandler: could not find IFP animation hierarchy '%s'\n", strAnimationName.c_str());
4065-
}
4066-
}
4067-
else
4068-
{
4069-
printf("AddAnimationHandler: could not find IFP block name '%s'\n", strBlockName.c_str());
4070-
}
4071-
}
4072-
4073-
printf("AddAnimationHandler: executing normal flow instead of custom animation\n");
4074-
*/
4075-
// normal flow
4076-
std::unique_ptr < CAnimBlendAssocGroup > pAnimAssocGroup = g_pGame->CreateAnimBlendAssocGroup ( animGroup );
4077-
CAnimBlendAssociationSAInterface * pAnimAssociation = pAnimAssocGroup->CopyAnimation ( animID );
4078-
4079-
printf("\n");
4080-
4081-
return pAnimAssociation;
3997+
hCAnimBlendAssoc_SyncAnimation CAnimBlendAssoc_SyncAnimation = (hCAnimBlendAssoc_SyncAnimation)0x004CEB40;
3998+
hCAnimBlendAssoc_Start CAnimBlendAssoc_Start = (hCAnimBlendAssoc_Start)0x004CEB70;
3999+
4000+
CAnimBlendAssoc * pAnimAssoc; // esi
4001+
int *clumpData; // edi
4002+
int *next; // eax
4003+
DWORD *tempAssoc; // eax
4004+
int *nextAssoc; // ecx
4005+
// We need to remove this line and add some code here for running animations simultaneously
4006+
pAnimAssoc = CAnimBlendAssocGroup_CopyAnimation((DWORD *) (*(DWORD*)0x00B4EA34) + 5 * animGroup, animID);
4007+
4008+
////ofs << "Done calling CAnimBlendAssocGroup_CopyAnimation " << std::endl;
4009+
4010+
clumpData = *(int **)( (*(DWORD*)0xB5F878) + ((int)pClump));
4011+
4012+
if ( !((*((BYTE *)pAnimAssoc + 46) >> 5) & 1) )
4013+
goto LABEL_5;
4014+
next = (int *)*clumpData;
4015+
if ( !*clumpData )
4016+
goto LABEL_5;
4017+
while ( !((*((BYTE *)next + 42) >> 5) & 1) )
4018+
{
4019+
next = (int *)*next;
4020+
if ( !next )
4021+
goto LABEL_5;
4022+
}
4023+
if ( next )
4024+
{
4025+
CAnimBlendAssoc_SyncAnimation(pAnimAssoc, (CAnimBlendAssoc *)(next - 1));
4026+
*((BYTE *)pAnimAssoc + 46) |= 1u;
4027+
}
4028+
else
4029+
{
4030+
LABEL_5:
4031+
CAnimBlendAssoc_Start(pAnimAssoc, 0);
4032+
}
4033+
4034+
tempAssoc = ((DWORD*)pAnimAssoc) + 1;
4035+
4036+
if ( *clumpData ) // clumpData->nextAssoc
4037+
*(DWORD *)(*clumpData + 4) = (DWORD)tempAssoc;
4038+
4039+
nextAssoc = (int *)*clumpData;
4040+
4041+
DWORD * dwpAnimAssoc = (DWORD*) pAnimAssoc;
4042+
4043+
dwpAnimAssoc[2] = (DWORD)clumpData;
4044+
//pAnimAssoc[2] = clumpData;
4045+
4046+
*tempAssoc = (DWORD)nextAssoc;
4047+
4048+
*clumpData = (int)tempAssoc;
4049+
4050+
return (CAnimBlendAssociationSAInterface *)pAnimAssoc;
40824051
}
40834052

40844053
CAnimBlendHierarchySAInterface * CClientGame::BlendAnimationHandler ( RpClump * pClump, CAnimBlendHierarchySAInterface * pAnimHierarchy, int flags, float fBlendDelta )

Client/multiplayer_sa/CMultiplayerSA.cpp

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ DWORD RETURN_CPlantMgr_Render_fail = 0x5DBDAA;
156156
DWORD RETURN_CEventHandler_ComputeKnockOffBikeResponse = 0x4BA076;
157157

158158
#define HOOKPOS_CAnimManager_AddAnimation 0x4d3aa0
159-
DWORD RETURN_CAnimManager_AddAnimation = 0x4D3AAA;
159+
DWORD RETURN_CAnimManager_AddAnimation = 0x004D3B16; //0x4D3AAA;
160160
DWORD RETURN_CAnimManager_AddAnimation_SkipCopyAnimation = 0x4D3ABC;
161161

162162
#define HOOKPOS_CAnimManager_AddAnimationAndSync 0x4D3B30
@@ -637,7 +637,7 @@ void CMultiplayerSA::InitHooks()
637637
HookInstall(HOOKPOS_Idle, (DWORD)HOOK_Idle, 10 );
638638
HookInstall(HOOKPOS_CEventHandler_ComputeKnockOffBikeResponse, (DWORD)HOOK_CEventHandler_ComputeKnockOffBikeResponse, 7 );
639639
HookInstall(HOOKPOS_CAnimManager_AddAnimation, (DWORD)HOOK_CAnimManager_AddAnimation, 10 );
640-
HookInstall(HOOKPOS_CAnimManager_AddAnimationAndSync, (DWORD)HOOK_CAnimManager_AddAnimationAndSync, 10 );
640+
//HookInstall(HOOKPOS_CAnimManager_AddAnimationAndSync, (DWORD)HOOK_CAnimManager_AddAnimationAndSync, 10 );
641641
HookInstall(HOOKPOS_CAnimManager_BlendAnimation_Hierarchy, (DWORD)HOOK_CAnimManager_BlendAnimation_Hierarchy, 7 );
642642
HookInstall(HOOKPOS_CPed_GetWeaponSkill, (DWORD)HOOK_CPed_GetWeaponSkill, 8 );
643643
HookInstall(HOOKPOS_CPed_AddGogglesModel, (DWORD)HOOK_CPed_AddGogglesModel, 6);
@@ -5354,20 +5354,8 @@ void _declspec(naked) HOOK_CAnimManager_AddAnimation ()
53545354
{
53555355
pAnimAssociation = m_pAddAnimationHandler ( animationClump, animationGroup, animationID );
53565356
}
5357-
else
5358-
{
5359-
// This will avoid crash if m_pAddAnimationHandler is removed
5360-
// continue the normal flow of AddAnimation function, instead of skipping CopyAnimation
5361-
5362-
_asm
5363-
{
5364-
popad
5365-
mov eax,dword ptr [esp+0Ch]
5366-
mov edx,dword ptr ds:[0B4EA34h]
5367-
jmp RETURN_CAnimManager_AddAnimation
5368-
}
5369-
}
53705357

5358+
/*
53715359
// As we are manually creating animation association, so skip CopyAnimation call
53725360
_asm
53735361
{
@@ -5376,6 +5364,14 @@ void _declspec(naked) HOOK_CAnimManager_AddAnimation ()
53765364
push edi
53775365
mov eax, pAnimAssociation
53785366
jmp RETURN_CAnimManager_AddAnimation_SkipCopyAnimation
5367+
} */
5368+
5369+
// As we are manually creating animation association, so skip CopyAnimation call
5370+
_asm
5371+
{
5372+
popad
5373+
mov eax, pAnimAssociation
5374+
jmp RETURN_CAnimManager_AddAnimation
53795375
}
53805376
}
53815377

@@ -5410,10 +5406,11 @@ void _declspec(naked) HOOK_CAnimManager_AddAnimationAndSync ()
54105406
popad
54115407
mov eax,dword ptr [esp+0Ch]
54125408
mov edx,dword ptr ds:[0B4EA34h]
5413-
jmp RETURN_CAnimManager_AddAnimation
5409+
jmp RETURN_CAnimManager_AddAnimationAndSync
54145410
}
54155411
}
54165412

5413+
printf("HOOK_CAnimManager_AddAnimationAndSync: m_nAnimGroup: %d | m_nAnimID: %d\n\n", pAnimAssociation->sAnimGroup, pAnimAssociation->sAnimID);
54175414

54185415
// As we are manually creating animation association, so skip CopyAnimation call
54195416
_asm
@@ -5422,7 +5419,7 @@ void _declspec(naked) HOOK_CAnimManager_AddAnimationAndSync ()
54225419
push esi
54235420
push edi
54245421
mov eax, pAnimAssociation
5425-
jmp RETURN_CAnimManager_AddAnimation_SkipCopyAnimation
5422+
jmp RETURN_CAnimManager_AddAnimationAndSync_SkipCopyAnimation
54265423
}
54275424
}
54285425

0 commit comments

Comments
 (0)