Skip to content

Commit e557b62

Browse files
committed
Completed BlendAnimationHierarchy and CAnimBlendAssoc_Constructor
These two hooks are meant to work in the same way. We can use anyone we wish to. BlendAnimationHierarchy is much cleaner and easy to understand, so let's use that one. Keep in mind that these two hooks get triggered for setPedAnimation only. They have nothing to do with AddAnimation and AddAniamtionAndSync
1 parent bb4ed12 commit e557b62

File tree

5 files changed

+148
-61
lines changed

5 files changed

+148
-61
lines changed

Client/mods/deathmatch/logic/CClientGame.cpp

Lines changed: 58 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3701,9 +3701,9 @@ bool CClientGame::StaticChokingHandler ( unsigned char ucWeaponType )
37013701
return g_pClientGame->ChokingHandler ( ucWeaponType );
37023702
}
37033703

3704-
bool CClientGame::StaticCAnimBlendAssocHierConstructorHandler ( SIFPAnimations ** pOutIFPAnimations, CAnimBlendAssociationSAInterface * pThis, RpClump * pClump, CAnimBlendHierarchySAInterface * pAnimHierarchy )
3704+
bool CClientGame::StaticCAnimBlendAssocHierConstructorHandler ( SIFPAnimations ** pOutIFPAnimations, CAnimBlendAssociationSAInterface * pThis, RpClump * pClump, CAnimBlendHierarchySAInterface ** pOutAnimHierarchy )
37053705
{
3706-
return g_pClientGame->CAnimBlendAssocHierConstructorHandler ( pOutIFPAnimations, pThis, pClump, pAnimHierarchy );
3706+
return g_pClientGame->CAnimBlendAssocHierConstructorHandler ( pOutIFPAnimations, pThis, pClump, pOutAnimHierarchy );
37073707
}
37083708

37093709
void CClientGame::StaticCAnimBlendAssocDestructorHandler ( CAnimBlendAssociationSAInterface * pThis )
@@ -3726,9 +3726,9 @@ bool CClientGame::StaticAssocGroupCopyAnimationHandler ( CAnimBlendStaticAssocia
37263726
return g_pClientGame->AssocGroupCopyAnimationHandler ( pOutAnimStaticAssoc, pOutIFPAnimations, pClump, pAnimAssocGroup, animID );
37273727
}
37283728

3729-
CAnimBlendHierarchySAInterface * CClientGame::StaticBlendAnimationHierarchyHandler ( RpClump * pClump, CAnimBlendHierarchySAInterface * pAnimHierarchy, int flags, float fBlendDelta )
3729+
bool CClientGame::StaticBlendAnimationHierarchyHandler ( SIFPAnimations ** pOutIFPAnimations, CAnimBlendHierarchySAInterface ** pOutAnimHierarchy, RpClump * pClump )
37303730
{
3731-
return g_pClientGame->BlendAnimationHierarchyHandler ( pClump, pAnimHierarchy, flags, fBlendDelta );
3731+
return g_pClientGame->BlendAnimationHierarchyHandler ( pOutIFPAnimations, pOutAnimHierarchy, pClump );
37323732
}
37333733

37343734
void CClientGame::StaticPreWorldProcessHandler ( void )
@@ -4013,23 +4013,58 @@ bool CClientGame::ChokingHandler ( unsigned char ucWeaponType )
40134013
}
40144014

40154015

4016-
bool CClientGame::CAnimBlendAssocHierConstructorHandler ( SIFPAnimations ** pOutIFPAnimations, CAnimBlendAssociationSAInterface * pThis, RpClump * pClump, CAnimBlendHierarchySAInterface * pAnimHierarchy )
4016+
bool CClientGame::CAnimBlendAssocHierConstructorHandler ( SIFPAnimations ** pOutIFPAnimations, CAnimBlendAssociationSAInterface * pThis, RpClump * pClump, CAnimBlendHierarchySAInterface ** pOutAnimHierarchy )
40174017
{
4018-
printf("CClientGame::CAnimBlendAssocHierConstructorHandler called! sAnimID: %d\n", pThis->sAnimID);
40194018
bool isCustomAnimationToPlay = false;
40204019

4020+
CAnimBlendHierarchySAInterface * pAnimHierarchy = *pOutAnimHierarchy;
4021+
4022+
printf("pAnimHierarchy->usNumSequences: %d\n", pAnimHierarchy->usNumSequences);
4023+
40214024
CAnimManager * pAnimationManager = g_pGame->GetAnimManager();
40224025
CClientPed * pClientPed = GetClientPedByClump ( *pClump );
40234026
if ( pClientPed != nullptr )
40244027
{
4025-
printf("CAnimBlendAssocHierConstructorHandler: got pClientPed\n\n");
4026-
if ( pClientPed->IsCurrentAnimationCustom ( ) )
4027-
{
4028-
printf("CAnimBlendAssocHierConstructorHandler: current animation is custom\n\n");
4029-
*pOutIFPAnimations = pClientPed->GetIFPAnimationsPointer ();
4030-
isCustomAnimationToPlay = true;
4028+
printf ("CAnimBlendAssocHierConstructorHandler: Found pClientPed\n");
4029+
if ( pClientPed->isNextAnimationCustom () )
4030+
{
4031+
const SString & strBlockName = pClientPed->GetNextAnimationCustomBlockName ( );
4032+
CClientIFP * pIFP = GetIFPPointerFromMap ( strBlockName );
4033+
if ( pIFP )
4034+
{
4035+
const SString & strAnimationName = pClientPed->GetNextAnimationCustomName ( );
4036+
auto pCustomAnimBlendHierarchy = pIFP->GetAnimationHierarchy ( strAnimationName );
4037+
if ( pCustomAnimBlendHierarchy != nullptr )
4038+
{
4039+
if ( pIFP->isIFPLoaded ( ) )
4040+
{
4041+
SIFPAnimations * pIFPAnimations = pIFP->GetIFPAnimationsPointer ();
4042+
pIFPAnimations->iReferences ++;
4043+
4044+
pClientPed->setCurrentAnimationCustom ( true );
4045+
pClientPed->setNextAnimationNormal ( );
4046+
4047+
*pOutIFPAnimations = pIFPAnimations;
4048+
*pOutAnimHierarchy = pCustomAnimBlendHierarchy;
4049+
isCustomAnimationToPlay = true;
4050+
return isCustomAnimationToPlay;
4051+
}
4052+
}
4053+
else
4054+
{
4055+
printf ("CAnimBlendAssocHierConstructorHandler: could not find IFP animation hierarchy '%s'\n", strAnimationName.c_str());
4056+
}
4057+
}
4058+
else
4059+
{
4060+
printf("CAnimBlendAssocHierConstructorHandler: could not find IFP block name '%s'\n", strBlockName.c_str());
4061+
}
40314062
}
4063+
4064+
pClientPed->setCurrentAnimationCustom ( false );
4065+
pClientPed->setNextAnimationNormal ( );
40324066
}
4067+
printf("CClientGame::CAnimBlendAssocHierConstructorHandler RETURNING! sAnimID: %d\n", pThis->sAnimID);
40334068
return isCustomAnimationToPlay;
40344069
}
40354070

@@ -4106,15 +4141,15 @@ bool CClientGame::AssocGroupCopyAnimationHandler ( CAnimBlendStaticAssociationSA
41064141
}
41074142

41084143

4109-
CAnimBlendHierarchySAInterface * CClientGame::BlendAnimationHierarchyHandler ( RpClump * pClump, CAnimBlendHierarchySAInterface * pAnimHierarchy, int flags, float fBlendDelta )
4144+
bool CClientGame::BlendAnimationHierarchyHandler ( SIFPAnimations ** pOutIFPAnimations, CAnimBlendHierarchySAInterface ** pOutAnimHierarchy, RpClump * pClump )
41104145
{
4111-
printf("CClientGame::BlendAnimationHierarchyHandler called | pClump: %p\n", (void*)pClump);
4146+
bool isCustomAnimationToPlay = false;
41124147

41134148
CAnimManager * pAnimationManager = g_pGame->GetAnimManager();
4114-
CClientPed * pClientPed = GetClientPedByClump ( *pClump ); //pAnimationManager->GetPedPointerFromMap ( pClump ); //m_pRootEntity->GetClientPedByClump ( *pClump );
4149+
CClientPed * pClientPed = GetClientPedByClump ( *pClump );
41154150
if ( pClientPed != nullptr )
41164151
{
4117-
printf ("BlendAnimationHierarchyHandler: Found pClientPed\n");
4152+
printf ("CAnimBlendAssocHierConstructorHandler: Found pClientPed\n");
41184153
if ( pClientPed->isNextAnimationCustom () )
41194154
{
41204155
const SString & strBlockName = pClientPed->GetNextAnimationCustomBlockName ( );
@@ -4131,32 +4166,29 @@ CAnimBlendHierarchySAInterface * CClientGame::BlendAnimationHierarchyHandler ( R
41314166
pIFPAnimations->iReferences ++;
41324167

41334168
pClientPed->setCurrentAnimationCustom ( true );
4134-
pClientPed->SetIFPAnimationsPointer ( pIFPAnimations );
4135-
// Modifying a hierarchy like this is just bad, it's much better to create a new CAnimBlendHierarchySAInterface for every animation
4136-
// and then delete it once animation is over
4137-
pCustomAnimBlendHierarchy->iHashKey = pAnimHierarchy->iHashKey;
4138-
pCustomAnimBlendHierarchy->iAnimBlockID = pAnimHierarchy->iAnimBlockID;
41394169
pClientPed->setNextAnimationNormal ( );
41404170

4141-
printf ("BlendAnimationHierarchyHandler: Found Hierarchy, returning \n");
4142-
return pCustomAnimBlendHierarchy;
4171+
*pOutIFPAnimations = pIFPAnimations;
4172+
*pOutAnimHierarchy = pCustomAnimBlendHierarchy;
4173+
isCustomAnimationToPlay = true;
4174+
return isCustomAnimationToPlay;
41434175
}
41444176
}
41454177
else
41464178
{
4147-
printf ("BlendAnimationHierarchyHandler: could not find IFP animation hierarchy '%s'\n", strAnimationName.c_str());
4179+
printf ("CAnimBlendAssocHierConstructorHandler: could not find IFP animation hierarchy '%s'\n", strAnimationName.c_str());
41484180
}
41494181
}
41504182
else
41514183
{
4152-
printf("BlendAnimationHierarchyHandler: could not find IFP block name '%s'\n", strBlockName.c_str());
4184+
printf("CAnimBlendAssocHierConstructorHandler: could not find IFP block name '%s'\n", strBlockName.c_str());
41534185
}
41544186
}
41554187

41564188
pClientPed->setCurrentAnimationCustom ( false );
41574189
pClientPed->setNextAnimationNormal ( );
41584190
}
4159-
return pAnimHierarchy;
4191+
return isCustomAnimationToPlay;
41604192
}
41614193

41624194

Client/mods/deathmatch/logic/CClientGame.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -503,12 +503,12 @@ class CClientGame
503503
static void StaticPostWorldProcessHandler ( void );
504504
static void StaticPreFxRenderHandler ( void );
505505
static void StaticPreHudRenderHandler ( void );
506-
static bool StaticCAnimBlendAssocHierConstructorHandler ( SIFPAnimations ** pOutIFPAnimations, CAnimBlendAssociationSAInterface * pThis, RpClump * pClump, CAnimBlendHierarchySAInterface * pAnimHierarchy );
506+
static bool StaticCAnimBlendAssocHierConstructorHandler ( SIFPAnimations ** pOutIFPAnimations, CAnimBlendAssociationSAInterface * pThis, RpClump * pClump, CAnimBlendHierarchySAInterface ** pOutAnimHierarchy );
507507
static void StaticCAnimBlendAssocDestructorHandler ( CAnimBlendAssociationSAInterface * pThis );
508508
static CAnimBlendAssociationSAInterface * StaticAddAnimationHandler ( RpClump * pClump, AssocGroupId animGroup, AnimationId animID );
509509
static CAnimBlendAssociationSAInterface * StaticAddAnimationAndSyncHandler( RpClump * pClump, CAnimBlendAssociationSAInterface * pAnimAssocToSyncWith, AssocGroupId animGroup, AnimationId animID );
510510
static bool StaticAssocGroupCopyAnimationHandler ( CAnimBlendStaticAssociationSAInterface * pOutAnimStaticAssoc, SIFPAnimations ** pOutIFPAnimations, RpClump * pClump, CAnimBlendAssocGroupSAInterface * pAnimAssocGroup, AnimationId animID );
511-
static CAnimBlendHierarchySAInterface * StaticBlendAnimationHierarchyHandler ( RpClump * pClump, CAnimBlendHierarchySAInterface * pAnimHierarchy, int flags, float fBlendDelta );
511+
static bool StaticBlendAnimationHierarchyHandler ( SIFPAnimations ** pOutIFPAnimations, CAnimBlendHierarchySAInterface ** pOutAnimHierarchy, RpClump * pClump );
512512
static bool StaticProcessCollisionHandler ( CEntitySAInterface* pThisInterface, CEntitySAInterface* pOtherInterface );
513513
static bool StaticVehicleCollisionHandler ( CVehicleSAInterface* pThisInterface, CEntitySAInterface* pOtherInterface, int iModelIndex, float fDamageImpulseMag, float fCollidingDamageImpulseMag, uint16 usPieceType, CVector vecCollisionPos, CVector vecCollisionVelocity );
514514
static bool StaticVehicleDamageHandler ( CEntitySAInterface* pVehicleInterface, float fLoss, CEntitySAInterface* pAttackerInterface, eWeaponType weaponType, const CVector& vecDamagePos, uchar ucTyre );
@@ -538,12 +538,12 @@ class CClientGame
538538
bool ChokingHandler ( unsigned char ucWeaponType );
539539
void PreWorldProcessHandler ( void );
540540
void PostWorldProcessHandler ( void );
541-
bool CAnimBlendAssocHierConstructorHandler ( SIFPAnimations ** pOutIFPAnimations, CAnimBlendAssociationSAInterface * pThis, RpClump * pClump, CAnimBlendHierarchySAInterface * pAnimHierarchy );
541+
bool CAnimBlendAssocHierConstructorHandler ( SIFPAnimations ** pOutIFPAnimations, CAnimBlendAssociationSAInterface * pThis, RpClump * pClump, CAnimBlendHierarchySAInterface ** pOutAnimHierarchy );
542542
void CAnimBlendAssocDestructorHandler ( CAnimBlendAssociationSAInterface * pThis );
543543
CAnimBlendAssociationSAInterface * AddAnimationHandler ( RpClump * pClump, AssocGroupId animGroup, AnimationId animID );
544544
CAnimBlendAssociationSAInterface * AddAnimationAndSyncHandler ( RpClump * pClump, CAnimBlendAssociationSAInterface * pAnimAssocToSyncWith, AssocGroupId animGroup, AnimationId animID );
545545
bool AssocGroupCopyAnimationHandler ( CAnimBlendStaticAssociationSAInterface * pOutAnimStaticAssoc, SIFPAnimations ** pOutIFPAnimations, RpClump * pClump, CAnimBlendAssocGroupSAInterface * pAnimAssocGroup, AnimationId animID );
546-
CAnimBlendHierarchySAInterface * BlendAnimationHierarchyHandler ( RpClump * pClump, CAnimBlendHierarchySAInterface * pAnimHierarchy, int flags, float fBlendDelta );
546+
bool BlendAnimationHierarchyHandler ( SIFPAnimations ** pOutIFPAnimations, CAnimBlendHierarchySAInterface ** pOutAnimHierarchy, RpClump * pClump );
547547
bool ProcessCollisionHandler ( CEntitySAInterface* pThisInterface, CEntitySAInterface* pOtherInterface );
548548
bool VehicleCollisionHandler ( CVehicleSAInterface* pCollidingVehicle, CEntitySAInterface* pCollidedVehicle, int iModelIndex, float fDamageImpulseMag, float fCollidingDamageImpulseMag, uint16 usPieceType, CVector vecCollisionPos, CVector vecCollisionVelocity );
549549
bool VehicleDamageHandler ( CEntitySAInterface* pVehicleInterface, float fLoss, CEntitySAInterface* pAttackerInterface, eWeaponType weaponType, const CVector& vecDamagePos, uchar ucTyre );

Client/multiplayer_sa/CMultiplayerSA.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ DWORD RETURN_CEventHandler_ComputeKnockOffBikeResponse = 0x4BA076;
162162
#define HOOKPOS_CAnimBlendAssocGroup_CopyAnimation 0x4CE14C
163163
#define HOOKPOS_CAnimManager_AddAnimation 0x4d3aa0
164164
#define HOOKPOS_CAnimManager_AddAnimationAndSync 0x4D3B30
165-
#define HOOKPOS_CAnimManager_BlendAnimation_Hierarchy 0x4D4410
165+
#define HOOKPOS_CAnimManager_BlendAnimation_Hierarchy 0x4D453E
166166

167167
#define HOOKPOS_CPed_GetWeaponSkill 0x5e3b60
168168
DWORD RETURN_CPed_GetWeaponSkill = 0x5E3B68;
@@ -636,12 +636,12 @@ void CMultiplayerSA::InitHooks()
636636
HookInstall(HOOKPOS_CGame_Process, (DWORD)HOOK_CGame_Process, 10 );
637637
HookInstall(HOOKPOS_Idle, (DWORD)HOOK_Idle, 10 );
638638
HookInstall(HOOKPOS_CEventHandler_ComputeKnockOffBikeResponse, (DWORD)HOOK_CEventHandler_ComputeKnockOffBikeResponse, 7 );
639-
HookInstall(HOOKPOS_CAnimBlendAssoc_Hierarchy_Constructor, (DWORD)HOOK_CAnimBlendAssoc_Hierarchy_Constructor, 5 );
639+
//HookInstall(HOOKPOS_CAnimBlendAssoc_Hierarchy_Constructor, (DWORD)HOOK_CAnimBlendAssoc_Hierarchy_Constructor, 5 );
640640
HookInstall(HOOKPOS_CAnimBlendAssoc_destructor, (DWORD)HOOK_CAnimBlendAssoc_destructor, 6 );
641641
HookInstall(HOOKPOS_CAnimManager_AddAnimation, (DWORD)HOOK_CAnimManager_AddAnimation, 10 );
642642
HookInstall(HOOKPOS_CAnimManager_AddAnimationAndSync, (DWORD)HOOK_CAnimManager_AddAnimationAndSync, 10 );
643643
HookInstall(HOOKPOS_CAnimBlendAssocGroup_CopyAnimation, (DWORD)HOOK_CAnimBlendAssocGroup_CopyAnimation, 5 );
644-
HookInstall(HOOKPOS_CAnimManager_BlendAnimation_Hierarchy, (DWORD)HOOK_CAnimManager_BlendAnimation_Hierarchy, 7 );
644+
HookInstall(HOOKPOS_CAnimManager_BlendAnimation_Hierarchy, (DWORD)HOOK_CAnimManager_BlendAnimation_Hierarchy, 5 );
645645
HookInstall(HOOKPOS_CPed_GetWeaponSkill, (DWORD)HOOK_CPed_GetWeaponSkill, 8 );
646646
HookInstall(HOOKPOS_CPed_AddGogglesModel, (DWORD)HOOK_CPed_AddGogglesModel, 6);
647647
HookInstall(HOOKPOS_CPhysical_ProcessCollisionSectorList, (DWORD)HOOK_CPhysical_ProcessCollisionSectorList, 7 );

0 commit comments

Comments
 (0)