Skip to content

Commit d8337a5

Browse files
committed
changed BlendAnimation hook to BlendAnimation_Hierarchy and hooks works fine. It is called when you execute setPedAnimation from client lua. This is where we can play custom animation
1 parent 80aec0e commit d8337a5

File tree

4 files changed

+76
-19
lines changed

4 files changed

+76
-19
lines changed

Client/mods/deathmatch/logic/CClientGame.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3697,9 +3697,9 @@ CAnimBlendAssociationSAInterface * CClientGame::StaticAddAnimationHandler ( RpCl
36973697
return g_pClientGame->AddAnimationHandler ( pClump, animGroup, animID );
36983698
}
36993699

3700-
void CClientGame::StaticBlendAnimationHandler ( RpClump * pClump, AssocGroupId animGroup, AnimationId animID, float fBlendDelta )
3700+
void CClientGame::StaticBlendAnimationHandler ( RpClump * pClump, CAnimBlendHierarchySAInterface * pAnimHierarchy, int flags, float fBlendDelta )
37013701
{
3702-
g_pClientGame->BlendAnimationHandler ( pClump, animGroup, animID, fBlendDelta );
3702+
g_pClientGame->BlendAnimationHandler ( pClump, pAnimHierarchy, flags, fBlendDelta );
37033703
}
37043704

37053705
void CClientGame::StaticPreWorldProcessHandler ( void )
@@ -3994,8 +3994,6 @@ CAnimBlendAssociationSAInterface * CClientGame::AddAnimationHandler ( RpClump *
39943994
{
39953995
if ( pClientPed->isNextAnimationCustom () )
39963996
{
3997-
printf("pClientPed->isNextAnimationCustom () is true\n");
3998-
39993997
auto pAnimStaticAssoc = pAnimationManager->GetAnimStaticAssociation ( animGroup, animID );
40003998
if ( pAnimationManager->isGateWayAnimationHierarchy ( pAnimStaticAssoc->pAnimHeirarchy ) )
40013999
{
@@ -4012,9 +4010,10 @@ CAnimBlendAssociationSAInterface * CClientGame::AddAnimationHandler ( RpClump *
40124010
return pAnimAssociation;
40134011
}
40144012

4015-
void CClientGame::BlendAnimationHandler ( RpClump * pClump, AssocGroupId animGroup, AnimationId animID, float fBlendDelta )
4013+
void CClientGame::BlendAnimationHandler ( RpClump * pClump, CAnimBlendHierarchySAInterface * pAnimHierarchy, int flags, float fBlendDelta )
40164014
{
40174015
//CClientPed * pPed = m_pPedManager->Get ( pClump, true );
4016+
printf ("CClientGame::BlendAnimationHandler called! pClump: %p\n", pClump);
40184017
}
40194018

40204019
bool CClientGame::ProcessCollisionHandler ( CEntitySAInterface* pThisInterface, CEntitySAInterface* pOtherInterface )

Client/mods/deathmatch/logic/CClientGame.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ class CClientGame
504504
static void StaticPreFxRenderHandler ( void );
505505
static void StaticPreHudRenderHandler ( void );
506506
static CAnimBlendAssociationSAInterface * StaticAddAnimationHandler ( RpClump * pClump, AssocGroupId animGroup, AnimationId animID );
507-
static void StaticBlendAnimationHandler ( RpClump * pClump, AssocGroupId animGroup, AnimationId animID, float fBlendDelta );
507+
static void StaticBlendAnimationHandler ( RpClump * pClump, CAnimBlendHierarchySAInterface * pAnimHierarchy, int flags, float fBlendDelta );
508508
static bool StaticProcessCollisionHandler ( CEntitySAInterface* pThisInterface, CEntitySAInterface* pOtherInterface );
509509
static bool StaticVehicleCollisionHandler ( CVehicleSAInterface* pThisInterface, CEntitySAInterface* pOtherInterface, int iModelIndex, float fDamageImpulseMag, float fCollidingDamageImpulseMag, uint16 usPieceType, CVector vecCollisionPos, CVector vecCollisionVelocity );
510510
static bool StaticVehicleDamageHandler ( CEntitySAInterface* pVehicleInterface, float fLoss, CEntitySAInterface* pAttackerInterface, eWeaponType weaponType, const CVector& vecDamagePos, uchar ucTyre );
@@ -535,7 +535,7 @@ class CClientGame
535535
void PreWorldProcessHandler ( void );
536536
void PostWorldProcessHandler ( void );
537537
CAnimBlendAssociationSAInterface * AddAnimationHandler ( RpClump * pClump, AssocGroupId animGroup, AnimationId animID );
538-
void BlendAnimationHandler ( RpClump * pClump, AssocGroupId animGroup, AnimationId animID, float fBlendDelta );
538+
void BlendAnimationHandler ( RpClump * pClump, CAnimBlendHierarchySAInterface * pAnimHierarchy, int flags, float fBlendDelta );
539539
bool ProcessCollisionHandler ( CEntitySAInterface* pThisInterface, CEntitySAInterface* pOtherInterface );
540540
bool VehicleCollisionHandler ( CVehicleSAInterface* pCollidingVehicle, CEntitySAInterface* pCollidedVehicle, int iModelIndex, float fDamageImpulseMag, float fCollidingDamageImpulseMag, uint16 usPieceType, CVector vecCollisionPos, CVector vecCollisionVelocity );
541541
bool VehicleDamageHandler ( CEntitySAInterface* pVehicleInterface, float fLoss, CEntitySAInterface* pAttackerInterface, eWeaponType weaponType, const CVector& vecDamagePos, uchar ucTyre );

Client/multiplayer_sa/CMultiplayerSA.cpp

Lines changed: 69 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,13 @@ DWORD RETURN_CEventHandler_ComputeKnockOffBikeResponse = 0x4BA076;
158158
#define HOOKPOS_CAnimManager_AddAnimation 0x4d3aa0
159159
DWORD RETURN_CAnimManager_AddAnimation = 0x4D3AAA;
160160
DWORD RETURN_CAnimManager_AddAnimation_SkipCopyAnimation = 0x4D3ABC;
161-
#define HOOKPOS_CAnimManager_BlendAnimation 0x4D4610
162-
DWORD RETURN_CAnimManager_BlendAnimation = 0x4D4617;
161+
162+
#define HOOKPOS_CAnimManager_AddAnimationAndSync 0x4D3B30
163+
DWORD RETURN_CAnimManager_AddAnimationAndSync = 0x4D3B3A;
164+
DWORD RETURN_CAnimManager_AddAnimationAndSync_SkipCopyAnimation = 0x4D3B4C;
165+
166+
#define HOOKPOS_CAnimManager_BlendAnimation_Hierarchy 0x4D4410 //0x4D4425
167+
DWORD RETURN_CAnimManager_BlendAnimation_Hierarchy = 0x4D4417; //0x4D442D;
163168

164169
#define HOOKPOS_CPed_GetWeaponSkill 0x5e3b60
165170
DWORD RETURN_CPed_GetWeaponSkill = 0x5E3B68;
@@ -424,7 +429,8 @@ void HOOK_RenderScene_end ();
424429
void HOOK_CPlantMgr_Render ();
425430
void HOOK_CEventHandler_ComputeKnockOffBikeResponse ();
426431
void HOOK_CAnimManager_AddAnimation ();
427-
void HOOK_CAnimManager_BlendAnimation ();
432+
void HOOK_CAnimManager_AddAnimationAndSync ();
433+
void HOOK_CAnimManager_BlendAnimation_Hierarchy ();
428434
void HOOK_CPed_GetWeaponSkill ();
429435
void HOOK_CPed_AddGogglesModel ();
430436
void HOOK_CPhysical_ProcessCollisionSectorList ();
@@ -631,7 +637,8 @@ void CMultiplayerSA::InitHooks()
631637
HookInstall(HOOKPOS_Idle, (DWORD)HOOK_Idle, 10 );
632638
HookInstall(HOOKPOS_CEventHandler_ComputeKnockOffBikeResponse, (DWORD)HOOK_CEventHandler_ComputeKnockOffBikeResponse, 7 );
633639
HookInstall(HOOKPOS_CAnimManager_AddAnimation, (DWORD)HOOK_CAnimManager_AddAnimation, 10 );
634-
HookInstall(HOOKPOS_CAnimManager_BlendAnimation, (DWORD)HOOK_CAnimManager_BlendAnimation, 7 );
640+
HookInstall(HOOKPOS_CAnimManager_AddAnimationAndSync, (DWORD)HOOK_CAnimManager_AddAnimationAndSync, 10 );
641+
HookInstall(HOOKPOS_CAnimManager_BlendAnimation_Hierarchy, (DWORD)HOOK_CAnimManager_BlendAnimation_Hierarchy, 7 );
635642
HookInstall(HOOKPOS_CPed_GetWeaponSkill, (DWORD)HOOK_CPed_GetWeaponSkill, 8 );
636643
HookInstall(HOOKPOS_CPed_AddGogglesModel, (DWORD)HOOK_CPed_AddGogglesModel, 6);
637644
HookInstall(HOOKPOS_CPhysical_ProcessCollisionSectorList, (DWORD)HOOK_CPhysical_ProcessCollisionSectorList, 7 );
@@ -5372,34 +5379,85 @@ void _declspec(naked) HOOK_CAnimManager_AddAnimation ()
53725379
}
53735380
}
53745381

5375-
float animationBlendDelta;
5376-
void _declspec(naked) HOOK_CAnimManager_BlendAnimation ()
5382+
5383+
CAnimBlendAssociationSAInterface * pAnimAssociationToSyncWith = nullptr;
5384+
void _declspec(naked) HOOK_CAnimManager_AddAnimationAndSync ()
53775385
{
53785386
_asm
53795387
{
53805388
mov eax, [esp+4]
53815389
mov animationClump, eax
53825390
mov eax, [esp+8]
5383-
mov animationGroup, eax
5391+
mov pAnimAssociationToSyncWith, eax
53845392
mov eax, [esp+12]
5393+
mov animationGroup, eax
5394+
mov eax, [esp+16]
53855395
mov animationID, eax
5396+
pushad
5397+
}
5398+
5399+
if ( m_pAddAnimationHandler )
5400+
{
5401+
pAnimAssociation = m_pAddAnimationHandler ( animationClump, animationGroup, animationID );
5402+
}
5403+
else
5404+
{
5405+
// This will avoid crash if m_pAddAnimationHandler is removed
5406+
// continue the normal flow of AddAnimationAndSync function, instead of skipping CopyAnimation
5407+
5408+
_asm
5409+
{
5410+
popad
5411+
mov eax,dword ptr [esp+0Ch]
5412+
mov edx,dword ptr ds:[0B4EA34h]
5413+
jmp RETURN_CAnimManager_AddAnimation
5414+
}
5415+
}
5416+
5417+
5418+
// As we are manually creating animation association, so skip CopyAnimation call
5419+
_asm
5420+
{
5421+
popad
5422+
push esi
5423+
push edi
5424+
mov eax, pAnimAssociation
5425+
jmp RETURN_CAnimManager_AddAnimation_SkipCopyAnimation
5426+
}
5427+
}
5428+
5429+
5430+
CAnimBlendHierarchySAInterface * pAnimHierarchy = nullptr;
5431+
int flags = 0;
5432+
float animationBlendDelta = 0.0f;
5433+
void _declspec(naked) HOOK_CAnimManager_BlendAnimation_Hierarchy ()
5434+
{
5435+
_asm
5436+
{
5437+
mov eax, [esp+4]
5438+
mov animationClump, eax
5439+
mov eax, [esp+8]
5440+
mov pAnimHierarchy, eax
5441+
mov eax, [esp+12]
5442+
mov flags, eax
53865443
mov eax, [esp+16]
53875444
mov animationBlendDelta, eax
53885445
pushad
53895446
}
53905447

53915448
if ( m_pBlendAnimationHandler )
53925449
{
5393-
m_pBlendAnimationHandler ( animationClump, animationGroup, animationID, animationBlendDelta );
5450+
m_pBlendAnimationHandler ( animationClump, pAnimHierarchy, flags, animationBlendDelta );
53945451
}
53955452

53965453
_asm
53975454
{
53985455
popad
5399-
sub esp,14h
5400-
mov ecx,dword ptr [esp+18h]
5401-
jmp RETURN_CAnimManager_BlendAnimation
5456+
push 0FFFFFFFFh
5457+
push 04D4410h
5458+
jmp RETURN_CAnimManager_BlendAnimation_Hierarchy
54025459
}
5460+
54035461
}
54045462

54055463
CPedSAInterface * weaponSkillPed;

Client/sdk/multiplayer/CMultiplayer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ typedef void ( IdleHandler ) ( void );
6666
typedef void ( PreFxRenderHandler ) ( void );
6767
typedef void ( PreHudRenderHandler ) ( void );
6868
typedef CAnimBlendAssociationSAInterface * ( AddAnimationHandler ) ( RpClump * pClump, AssocGroupId animGroup, AnimationId animID );
69-
typedef void ( BlendAnimationHandler ) ( RpClump * pClump, AssocGroupId animGroup, AnimationId animID, float fBlendDelta );
69+
typedef void ( BlendAnimationHandler ) ( RpClump * pClump, CAnimBlendHierarchySAInterface * pAnimHierarchy, int flags, float fBlendDelta );
7070
typedef bool ( ProcessCollisionHandler ) ( class CEntitySAInterface* pThisInterface, class CEntitySAInterface* pOtherInterface );
7171
typedef bool ( VehicleCollisionHandler ) ( class CVehicleSAInterface* pCollidingVehicle, class CEntitySAInterface* pCollidedVehicle, int iModelIndex, float fDamageImpulseMag, float fCollidingDamageImpulseMag, uint16 usPieceType, CVector vecCollisionPos, CVector vecCollisionVelocity );
7272
typedef bool ( VehicleDamageHandler ) ( CEntitySAInterface* pVehicle, float fLoss, CEntitySAInterface* pAttacker, eWeaponType weaponType, const CVector& vecDamagePos, uchar ucTyre );

0 commit comments

Comments
 (0)