@@ -270,6 +270,7 @@ CClientGame::CClientGame ( bool bLocalPlay )
270
270
g_pMultiplayer->SetPostWorldProcessHandler ( CClientGame::StaticPostWorldProcessHandler );
271
271
g_pMultiplayer->SetPreFxRenderHandler ( CClientGame::StaticPreFxRenderHandler );
272
272
g_pMultiplayer->SetPreHudRenderHandler ( CClientGame::StaticPreHudRenderHandler );
273
+ g_pMultiplayer->SetCAnimBlendAssocDestructorHandler ( CClientGame::StaticCAnimBlendAssocDestructorHandler );
273
274
g_pMultiplayer->SetAddAnimationHandler ( CClientGame::StaticAddAnimationHandler );
274
275
g_pMultiplayer->SetAddAnimationAndSyncHandler ( CClientGame::StaticAddAnimationAndSyncHandler );
275
276
g_pMultiplayer->SetAssocGroupCopyAnimationHandler ( CClientGame::StaticAssocGroupCopyAnimationHandler );
@@ -430,6 +431,7 @@ CClientGame::~CClientGame ( void )
430
431
g_pMultiplayer->SetPostWorldProcessHandler ( NULL );
431
432
g_pMultiplayer->SetPreFxRenderHandler ( NULL );
432
433
g_pMultiplayer->SetPreHudRenderHandler ( NULL );
434
+ g_pMultiplayer->SetCAnimBlendAssocDestructorHandler ( NULL );
433
435
g_pMultiplayer->SetAddAnimationHandler ( NULL );
434
436
g_pMultiplayer->SetAddAnimationAndSyncHandler ( NULL );
435
437
g_pMultiplayer->SetAssocGroupCopyAnimationHandler ( NULL );
@@ -3697,6 +3699,11 @@ bool CClientGame::StaticChokingHandler ( unsigned char ucWeaponType )
3697
3699
return g_pClientGame->ChokingHandler ( ucWeaponType );
3698
3700
}
3699
3701
3702
+ void CClientGame::StaticCAnimBlendAssocDestructorHandler ( CAnimBlendAssociationSAInterface * pThis )
3703
+ {
3704
+ g_pClientGame->CAnimBlendAssocDestructorHandler ( pThis );
3705
+ }
3706
+
3700
3707
CAnimBlendAssociationSAInterface * CClientGame::StaticAddAnimationHandler ( RpClump * pClump, AssocGroupId animGroup, AnimationId animID )
3701
3708
{
3702
3709
return g_pClientGame->AddAnimationHandler ( pClump, animGroup, animID );
@@ -3707,14 +3714,14 @@ CAnimBlendAssociationSAInterface * CClientGame::StaticAddAnimationAndSyncHandler
3707
3714
return g_pClientGame->AddAnimationAndSyncHandler ( pClump, pAnimAssocToSyncWith, animGroup, animID );
3708
3715
}
3709
3716
3710
- void CClientGame::StaticAssocGroupCopyAnimationHandler ( CAnimBlendStaticAssociationSAInterface * pOutAnimStaticAssoc, RpClump * pClump, CAnimBlendAssocGroupSAInterface * pAnimAssocGroup, AnimationId animID )
3717
+ bool CClientGame::StaticAssocGroupCopyAnimationHandler ( CAnimBlendStaticAssociationSAInterface * pOutAnimStaticAssoc, SIFPAnimations ** pOutIFPAnimations , RpClump * pClump, CAnimBlendAssocGroupSAInterface * pAnimAssocGroup, AnimationId animID )
3711
3718
{
3712
- g_pClientGame->AssocGroupCopyAnimationHandler ( pOutAnimStaticAssoc, pClump, pAnimAssocGroup, animID );
3719
+ return g_pClientGame->AssocGroupCopyAnimationHandler ( pOutAnimStaticAssoc, pOutIFPAnimations , pClump, pAnimAssocGroup, animID );
3713
3720
}
3714
3721
3715
- CAnimBlendHierarchySAInterface * CClientGame::StaticBlendAnimationHierarchyHandler ( RpClump * pClump , CAnimBlendHierarchySAInterface * pAnimHierarchy, int flags, float fBlendDelta )
3722
+ bool CClientGame::StaticBlendAnimationHierarchyHandler ( SIFPAnimations ** pOutIFPAnimations , CAnimBlendHierarchySAInterface ** pOutAnimHierarchy, RpClump * pClump )
3716
3723
{
3717
- return g_pClientGame->BlendAnimationHierarchyHandler ( pClump, pAnimHierarchy, flags, fBlendDelta );
3724
+ return g_pClientGame->BlendAnimationHierarchyHandler ( pOutIFPAnimations, pOutAnimHierarchy, pClump );
3718
3725
}
3719
3726
3720
3727
void CClientGame::StaticPreWorldProcessHandler ( void )
@@ -3999,51 +4006,63 @@ bool CClientGame::ChokingHandler ( unsigned char ucWeaponType )
3999
4006
}
4000
4007
4001
4008
4009
+ void CClientGame::CAnimBlendAssocDestructorHandler ( CAnimBlendAssociationSAInterface * pThis )
4010
+ {
4011
+ // printf("CClientGame::CAnimBlendAssocDestructorHandler called! sAnimID: %d\n", pThis->sAnimID);
4012
+ }
4002
4013
4003
4014
4004
4015
CAnimBlendAssociationSAInterface * CClientGame::AddAnimationHandler ( RpClump * pClump, AssocGroupId animGroup, AnimationId animID )
4005
4016
{
4006
- printf ( " AddAnimationHandler called! pClump, GroupID, AnimID: %p, %d, %d\n " , (void *)pClump, animGroup, animID );
4017
+ // printf ( "AddAnimationHandler called! pClump, GroupID, AnimID: %p, %d, %d\n", (void*)pClump, animGroup, animID );
4007
4018
return nullptr ;
4008
4019
}
4009
4020
4021
+
4010
4022
CAnimBlendAssociationSAInterface * CClientGame::AddAnimationAndSyncHandler ( RpClump * pClump, CAnimBlendAssociationSAInterface * pAnimAssocToSyncWith, AssocGroupId animGroup, AnimationId animID )
4011
4023
{
4012
- printf ( " AddAnimationAndSyncHandler called! pClump, GroupID, AnimID: %p, %d, %d\n " , (void *)pClump, animGroup, animID );
4024
+ // printf ( "AddAnimationAndSyncHandler called! pClump, GroupID, AnimID: %p, %d, %d\n", (void*)pClump, animGroup, animID );
4013
4025
return nullptr ;
4014
4026
}
4015
4027
4028
+
4016
4029
typedef void (__thiscall* hCAnimBlendStaticAssociation_Init)
4017
4030
(
4018
4031
CAnimBlendStaticAssociationSAInterface * pThis,
4019
4032
RpClump * Clump,
4020
4033
CAnimBlendHierarchySAInterface * pAnimBlendHierarchy
4021
4034
);
4022
4035
4023
- void CClientGame::AssocGroupCopyAnimationHandler ( CAnimBlendStaticAssociationSAInterface * pOutAnimStaticAssoc, RpClump * pClump, CAnimBlendAssocGroupSAInterface * pAnimAssocGroup, AnimationId animID )
4024
- {
4025
- printf (" AssocGroupCopyAnimationHandler called!\n " );
4026
4036
4037
+ bool CClientGame::AssocGroupCopyAnimationHandler ( CAnimBlendStaticAssociationSAInterface * pOutAnimStaticAssoc, SIFPAnimations ** pOutIFPAnimations, RpClump * pClump, CAnimBlendAssocGroupSAInterface * pAnimAssocGroup, AnimationId animID )
4038
+ {
4027
4039
auto CAnimBlendStaticAssociation_Init = (hCAnimBlendStaticAssociation_Init)0x4CEC20 ;
4028
4040
4041
+ bool isCustomAnimationToPlay = false ;
4029
4042
CAnimManager * pAnimationManager = g_pGame->GetAnimManager ();
4030
4043
auto pOriginalAnimStaticAssoc = pAnimationManager->GetAnimStaticAssociation ( pAnimAssocGroup->groupID , animID );
4031
4044
4032
4045
CClientPed * pClientPed = GetClientPedByClump ( *pClump );
4033
4046
if ( pClientPed != nullptr )
4034
4047
{
4035
- auto pReplacedAnimHeirarchyInterface = pClientPed->getReplacedAnimation ( pOriginalAnimStaticAssoc->pAnimHeirarchy );
4036
- if ( pReplacedAnimHeirarchyInterface != nullptr )
4037
- { // Play our custom animation instead of default
4038
- CAnimBlendStaticAssociation_Init ( pOutAnimStaticAssoc, pClump, pReplacedAnimHeirarchyInterface );
4039
- }
4040
- else
4041
- { // Play default internal animation
4042
- CAnimBlendStaticAssociation_Init ( pOutAnimStaticAssoc, pClump, pOriginalAnimStaticAssoc->pAnimHeirarchy );
4048
+ auto pReplacedAnimation = pClientPed->getReplacedAnimation ( pOriginalAnimStaticAssoc->pAnimHeirarchy );
4049
+ if ( pReplacedAnimation != nullptr )
4050
+ {
4051
+ if ( pReplacedAnimation->pIFP ->isIFPLoaded ( ) )
4052
+ {
4053
+ SIFPAnimations * pIFPAnimations = pReplacedAnimation->pIFP ->GetIFPAnimationsPointer ();
4054
+ pIFPAnimations->iReferences ++;
4055
+ // Play our custom animation instead of default
4056
+ *pOutIFPAnimations = pIFPAnimations;
4057
+ CAnimBlendStaticAssociation_Init ( pOutAnimStaticAssoc, pClump, pReplacedAnimation->pAnimationHierarchy );
4058
+ isCustomAnimationToPlay = true ;
4059
+ }
4043
4060
}
4044
4061
}
4045
- else
4046
- { // Play default internal animation
4062
+
4063
+ if ( !isCustomAnimationToPlay )
4064
+ {
4065
+ // Play default internal animation
4047
4066
CAnimBlendStaticAssociation_Init ( pOutAnimStaticAssoc, pClump, pOriginalAnimStaticAssoc->pAnimHeirarchy );
4048
4067
}
4049
4068
@@ -4053,17 +4072,21 @@ void CClientGame::AssocGroupCopyAnimationHandler ( CAnimBlendStaticAssociationSA
4053
4072
// Total bones in clump. GTA SA is using 32 bones for peds/players
4054
4073
pOutAnimStaticAssoc->nNumBlendNodes = pOriginalAnimStaticAssoc->nNumBlendNodes ;
4055
4074
pOutAnimStaticAssoc->sFlags = pOriginalAnimStaticAssoc->sFlags ;
4075
+
4076
+ printf (" CClientGame::AssocGroupCopyAnimationHandler: About to return sAnimGroup: %d | sAnimID: %d !\n " , pOutAnimStaticAssoc->sAnimGroup , pOutAnimStaticAssoc->sAnimID );
4077
+ return isCustomAnimationToPlay;
4056
4078
}
4057
4079
4058
- CAnimBlendHierarchySAInterface * CClientGame::BlendAnimationHierarchyHandler ( RpClump * pClump, CAnimBlendHierarchySAInterface * pAnimHierarchy, int flags, float fBlendDelta )
4080
+
4081
+ bool CClientGame::BlendAnimationHierarchyHandler ( SIFPAnimations ** pOutIFPAnimations, CAnimBlendHierarchySAInterface ** pOutAnimHierarchy, RpClump * pClump )
4059
4082
{
4060
- printf ( " CClientGame::BlendAnimationHierarchyHandler called | pClump: %p \n " , ( void *)pClump) ;
4083
+ bool isCustomAnimationToPlay = false ;
4061
4084
4062
4085
CAnimManager * pAnimationManager = g_pGame->GetAnimManager ();
4063
- CClientPed * pClientPed = GetClientPedByClump ( *pClump ); // pAnimationManager->GetPedPointerFromMap ( pClump ); //m_pRootEntity->GetClientPedByClump ( *pClump );
4086
+ CClientPed * pClientPed = GetClientPedByClump ( *pClump );
4064
4087
if ( pClientPed != nullptr )
4065
4088
{
4066
- printf (" BlendAnimationHierarchyHandler: Found pClientPed\n " );
4089
+ printf (" CClientGame:: BlendAnimationHierarchyHandler: Found pClientPed\n " );
4067
4090
if ( pClientPed->isNextAnimationCustom () )
4068
4091
{
4069
4092
const SString & strBlockName = pClientPed->GetNextAnimationCustomBlockName ( );
@@ -4074,36 +4097,38 @@ CAnimBlendHierarchySAInterface * CClientGame::BlendAnimationHierarchyHandler ( R
4074
4097
auto pCustomAnimBlendHierarchy = pIFP->GetAnimationHierarchy ( strAnimationName );
4075
4098
if ( pCustomAnimBlendHierarchy != nullptr )
4076
4099
{
4077
- printf (" BlendAnimationHierarchyHandler: Found Hierarchy, returning \n " );
4078
-
4079
- pClientPed->setCurrentAnimationCustom ( true );
4080
-
4081
- // Modifying a hierarchy like this is just bad, it's much better to create a new CAnimBlendHierarchySAInterface for every animation
4082
- // and then delete it once animation is over
4083
- pCustomAnimBlendHierarchy->iHashKey = pAnimHierarchy->iHashKey ;
4084
- pCustomAnimBlendHierarchy->iAnimBlockID = pAnimHierarchy->iAnimBlockID ;
4085
- pClientPed->setNextAnimationNormal ( );
4086
- return pCustomAnimBlendHierarchy;
4100
+ if ( pIFP->isIFPLoaded ( ) )
4101
+ {
4102
+ SIFPAnimations * pIFPAnimations = pIFP->GetIFPAnimationsPointer ();
4103
+ pIFPAnimations->iReferences ++;
4104
+
4105
+ pClientPed->setCurrentAnimationCustom ( true );
4106
+ pClientPed->setNextAnimationNormal ( );
4107
+
4108
+ *pOutIFPAnimations = pIFPAnimations;
4109
+ *pOutAnimHierarchy = pCustomAnimBlendHierarchy;
4110
+ isCustomAnimationToPlay = true ;
4111
+ return isCustomAnimationToPlay;
4112
+ }
4087
4113
}
4088
4114
else
4089
4115
{
4090
- printf (" BlendAnimationHierarchyHandler: could not find IFP animation hierarchy '%s'\n " , strAnimationName.c_str ());
4116
+ printf (" CClientGame:: BlendAnimationHierarchyHandler: could not find IFP animation hierarchy '%s'\n " , strAnimationName.c_str ());
4091
4117
}
4092
4118
}
4093
4119
else
4094
4120
{
4095
- printf (" BlendAnimationHierarchyHandler: could not find IFP block name '%s'\n " , strBlockName.c_str ());
4121
+ printf (" CClientGame:: BlendAnimationHierarchyHandler: could not find IFP block name '%s'\n " , strBlockName.c_str ());
4096
4122
}
4097
4123
}
4098
- else
4099
- {
4100
- pClientPed->setCurrentAnimationCustom ( false );
4101
- }
4124
+
4125
+ pClientPed->setCurrentAnimationCustom ( false );
4102
4126
pClientPed->setNextAnimationNormal ( );
4103
4127
}
4104
- return pAnimHierarchy ;
4128
+ return isCustomAnimationToPlay ;
4105
4129
}
4106
4130
4131
+
4107
4132
bool CClientGame::ProcessCollisionHandler ( CEntitySAInterface* pThisInterface, CEntitySAInterface* pOtherInterface )
4108
4133
{
4109
4134
if ( pThisInterface == pOtherInterface )
@@ -6892,7 +6917,7 @@ CClientPed * CClientGame::GetClientPedByClump ( const RpClump & Clump )
6892
6917
return nullptr ;
6893
6918
}
6894
6919
6895
- void CClientGame::onClientIFPUnload ( const CClientIFP & IFP )
6920
+ void CClientGame::OnClientIFPUnload ( const CClientIFP & IFP )
6896
6921
{
6897
6922
// remove IFP animations from replaced animations of peds/players
6898
6923
for ( auto it = m_mapOfPedPointers.begin (); it != m_mapOfPedPointers.end (); it++ )
@@ -6904,3 +6929,45 @@ void CClientGame::onClientIFPUnload ( const CClientIFP & IFP )
6904
6929
}
6905
6930
}
6906
6931
}
6932
+
6933
+ void CClientGame::DeleteIFPAnimations ( SIFPAnimations * pIFPAnimations )
6934
+ {
6935
+ if ( pIFPAnimations->iReferences == 0 )
6936
+ {
6937
+ printf (" CClientGame::UnloadIFPAnimations (): iReferences are Zero\n " );
6938
+
6939
+ hCMemoryMgr_Free OLD_CMemoryMgr_Free = (hCMemoryMgr_Free)0x0072F430 ;
6940
+ auto OLD_CAnimBlendHierarchy_RemoveFromUncompressedCache = (hCAnimBlendHierarchy_RemoveFromUncompressedCache)0x004D42A0 ;
6941
+
6942
+ for ( size_t i = 0 ; i < pIFPAnimations->vecAnimations .size (); i++ )
6943
+ {
6944
+ IFP_Animation * ifpAnimation = &pIFPAnimations->vecAnimations [i];
6945
+
6946
+ OLD_CAnimBlendHierarchy_RemoveFromUncompressedCache ( (int )&ifpAnimation->Hierarchy );
6947
+
6948
+ for (unsigned short SequenceIndex = 0 ; SequenceIndex < ifpAnimation->Hierarchy .m_nSeqCount ; SequenceIndex++)
6949
+ {
6950
+ _CAnimBlendSequence * pSequence = (_CAnimBlendSequence*)((BYTE*)ifpAnimation->Hierarchy .m_pSequences + (sizeof (_CAnimBlendSequence) * SequenceIndex));
6951
+
6952
+ if ( !( (pSequence->m_nFlags >> 3 ) & 1 ) ) // If ( !OneBigChunkForAllSequences )
6953
+ {
6954
+ OLD_CMemoryMgr_Free ( pSequence->m_pFrames ); // *(void **)(pThis + 8)); //pSequence->m_pFrames );
6955
+ }
6956
+ else
6957
+ {
6958
+ if ( SequenceIndex == 0 )
6959
+ {
6960
+ // All frames of all sequences are allocated on one memory block, so free that one
6961
+ // and break the loop
6962
+ OLD_CMemoryMgr_Free ( pSequence->m_pFrames );
6963
+ break ;
6964
+ }
6965
+ }
6966
+
6967
+ }
6968
+ delete ifpAnimation->pSequencesMemory ;
6969
+ }
6970
+ delete pIFPAnimations;
6971
+ printf (" CClientGame::UnloadIFPAnimations (): IFP Animations have been unloaded successfully!\n " );
6972
+ }
6973
+ }
0 commit comments