@@ -3719,9 +3719,9 @@ bool CClientGame::StaticAssocGroupCopyAnimationHandler ( CAnimBlendStaticAssocia
3719
3719
return g_pClientGame->AssocGroupCopyAnimationHandler ( pOutAnimStaticAssoc, pAnimAssoc, pClump, pAnimAssocGroup, animID );
3720
3720
}
3721
3721
3722
- bool CClientGame::StaticBlendAnimationHierarchyHandler ( CAnimBlendAssociationSAInterface * pAnimAssoc, CAnimBlendHierarchySAInterface ** pOutAnimHierarchy, RpClump * pClump )
3722
+ bool CClientGame::StaticBlendAnimationHierarchyHandler ( CAnimBlendAssociationSAInterface * pAnimAssoc, CAnimBlendHierarchySAInterface ** pOutAnimHierarchy, int * pFlags, RpClump * pClump )
3723
3723
{
3724
- return g_pClientGame->BlendAnimationHierarchyHandler ( pAnimAssoc, pOutAnimHierarchy, pClump );
3724
+ return g_pClientGame->BlendAnimationHierarchyHandler ( pAnimAssoc, pOutAnimHierarchy, pFlags, pClump );
3725
3725
}
3726
3726
3727
3727
void CClientGame::StaticPreWorldProcessHandler ( void )
@@ -4038,7 +4038,6 @@ typedef void (__thiscall* hCAnimBlendStaticAssociation_Init)
4038
4038
bool CClientGame::AssocGroupCopyAnimationHandler ( CAnimBlendStaticAssociationSAInterface * pOutAnimStaticAssoc, CAnimBlendAssociationSAInterface * pAnimAssoc, RpClump * pClump, CAnimBlendAssocGroupSAInterface * pAnimAssocGroup, AnimationId animID )
4039
4039
{
4040
4040
auto CAnimBlendStaticAssociation_Init = (hCAnimBlendStaticAssociation_Init)0x4CEC20 ;
4041
-
4042
4041
bool isCustomAnimationToPlay = false ;
4043
4042
4044
4043
CAnimManager * pAnimationManager = g_pGame->GetAnimManager ();
@@ -4047,7 +4046,7 @@ bool CClientGame::AssocGroupCopyAnimationHandler ( CAnimBlendStaticAssociationSA
4047
4046
CClientPed * pClientPed = GetClientPedByClump ( *pClump );
4048
4047
if ( pClientPed != nullptr )
4049
4048
{
4050
- auto pReplacedAnimation = pClientPed->getReplacedAnimation ( pOriginalAnimStaticAssoc->pAnimHeirarchy );
4049
+ auto pReplacedAnimation = pClientPed->GetReplacedAnimation ( pOriginalAnimStaticAssoc->pAnimHeirarchy );
4051
4050
if ( pReplacedAnimation != nullptr )
4052
4051
{
4053
4052
std::shared_ptr < CIFPAnimations > pIFPAnimations = pReplacedAnimation->pIFP ->GetIFPAnimationsPointer ();
@@ -4071,55 +4070,46 @@ bool CClientGame::AssocGroupCopyAnimationHandler ( CAnimBlendStaticAssociationSA
4071
4070
// Total bones in clump. GTA SA is using 32 bones for peds/players
4072
4071
pOutAnimStaticAssoc->nNumBlendNodes = pOriginalAnimStaticAssoc->nNumBlendNodes ;
4073
4072
pOutAnimStaticAssoc->sFlags = pOriginalAnimStaticAssoc->sFlags ;
4074
-
4075
- printf (" CClientGame::AssocGroupCopyAnimationHandler: About to return sAnimGroup: %d | sAnimID: %d !\n " , pOutAnimStaticAssoc->sAnimGroup , pOutAnimStaticAssoc->sAnimID );
4076
-
4077
4073
return isCustomAnimationToPlay;
4078
4074
}
4079
4075
4080
4076
4081
- bool CClientGame::BlendAnimationHierarchyHandler ( CAnimBlendAssociationSAInterface * pAnimAssoc, CAnimBlendHierarchySAInterface ** pOutAnimHierarchy, RpClump * pClump )
4077
+ bool CClientGame::BlendAnimationHierarchyHandler ( CAnimBlendAssociationSAInterface * pAnimAssoc, CAnimBlendHierarchySAInterface ** pOutAnimHierarchy, int * pFlags, RpClump * pClump )
4082
4078
{
4083
4079
bool isCustomAnimationToPlay = false ;
4084
4080
4085
4081
CAnimManager * pAnimationManager = g_pGame->GetAnimManager ();
4086
4082
CClientPed * pClientPed = GetClientPedByClump ( *pClump );
4087
4083
if ( pClientPed != nullptr )
4088
4084
{
4089
- printf (" CClientGame::BlendAnimationHierarchyHandler: Found pClientPed\n " );
4090
- if ( pClientPed->isNextAnimationCustom () )
4085
+ if ( pClientPed->IsNextAnimationCustom () )
4091
4086
{
4092
- const SString & strBlockName = pClientPed->GetNextAnimationCustomBlockName ( );
4093
- std::shared_ptr < CClientIFP > pIFP = GetIFPPointerFromMap ( strBlockName );
4087
+ std::shared_ptr < CClientIFP > pIFP = pClientPed->GetCustomAnimationIFP ( );
4094
4088
if ( pIFP )
4095
4089
{
4096
4090
const SString & strAnimationName = pClientPed->GetNextAnimationCustomName ( );
4097
4091
auto pCustomAnimBlendHierarchy = pIFP->GetAnimationHierarchy ( strAnimationName );
4098
4092
if ( pCustomAnimBlendHierarchy != nullptr )
4099
4093
{
4100
- std::shared_ptr < CIFPAnimations > pIFPAnimations = pIFP->GetIFPAnimationsPointer ();
4094
+ std::shared_ptr < CIFPAnimations > pIFPAnimations = pIFP->GetIFPAnimationsPointer ( );
4101
4095
InsertAnimationAssociationToMap ( pAnimAssoc, pIFPAnimations );
4102
4096
4103
- pClientPed->setCurrentAnimationCustom ( true );
4104
- pClientPed->setNextAnimationNormal ( );
4105
-
4097
+ pClientPed->SetCurrentAnimationCustom ( true );
4098
+ pClientPed->SetNextAnimationNormal ( );
4099
+
4100
+ if ( pIFP->IsUnloading ( ) )
4101
+ {
4102
+ pClientPed->DereferenceCustomAnimationBlock ();
4103
+ }
4106
4104
*pOutAnimHierarchy = pCustomAnimBlendHierarchy;
4107
4105
isCustomAnimationToPlay = true ;
4108
4106
return isCustomAnimationToPlay;
4109
4107
}
4110
- else
4111
- {
4112
- printf (" CClientGame::BlendAnimationHierarchyHandler: could not find IFP animation hierarchy '%s'\n " , strAnimationName.c_str ());
4113
- }
4114
- }
4115
- else
4116
- {
4117
- printf (" CClientGame::BlendAnimationHierarchyHandler: could not find IFP block name '%s'\n " , strBlockName.c_str ());
4118
4108
}
4119
4109
}
4120
4110
4121
- pClientPed->setCurrentAnimationCustom ( false );
4122
- pClientPed->setNextAnimationNormal ( );
4111
+ pClientPed->SetCurrentAnimationCustom ( false );
4112
+ pClientPed->SetNextAnimationNormal ( );
4123
4113
}
4124
4114
return isCustomAnimationToPlay;
4125
4115
}
@@ -6855,45 +6845,16 @@ void CClientGame::RestreamModel ( unsigned short usModel )
6855
6845
6856
6846
}
6857
6847
6858
- void CClientGame::InsertIFPPointerToMap ( const SString & strBlockName, const std::shared_ptr < CClientIFP > & pIFP )
6859
- {
6860
- const SString mapKey = strBlockName.ToLower ( );
6861
- if ( m_mapOfIfpPointers.count ( mapKey ) == 0 )
6862
- {
6863
- m_mapOfIfpPointers [ mapKey ] = pIFP;
6864
- }
6865
- }
6866
-
6867
- void CClientGame::RemoveIFPPointerFromMap ( const SString & strBlockName )
6868
- {
6869
- m_mapOfIfpPointers.erase ( strBlockName.ToLower ( ) );
6870
- }
6871
-
6872
- std::shared_ptr < CClientIFP > CClientGame::GetIFPPointerFromMap ( const SString & strBlockName )
6848
+ std::shared_ptr < CClientIFP > CClientGame::GetIFPPointerFromMap ( const unsigned int u32BlockNameHash )
6873
6849
{
6874
- const SString mapKey = strBlockName.ToLower ( );
6875
- auto it = m_mapOfIfpPointers.find ( mapKey );
6850
+ auto it = m_mapOfIfpPointers.find ( u32BlockNameHash );
6876
6851
if ( it != m_mapOfIfpPointers.end ( ) )
6877
6852
{
6878
6853
return it->second ;
6879
6854
}
6880
6855
return nullptr ;
6881
6856
}
6882
6857
6883
-
6884
- void CClientGame::InsertPedPointerToMap ( CClientPed * pPed )
6885
- {
6886
- if ( m_mapOfPedPointers.count ( pPed ) == 0 )
6887
- {
6888
- m_mapOfPedPointers [ pPed ] = true ;
6889
- }
6890
- }
6891
-
6892
- void CClientGame::RemovePedPointerFromMap ( CClientPed * pPed )
6893
- {
6894
- m_mapOfPedPointers.erase ( pPed );
6895
- }
6896
-
6897
6858
CClientPed * CClientGame::GetClientPedByClump ( const RpClump & Clump )
6898
6859
{
6899
6860
for ( auto it = m_mapOfPedPointers.begin (); it != m_mapOfPedPointers.end (); it++ )
@@ -6916,13 +6877,28 @@ CClientPed * CClientGame::GetClientPedByClump ( const RpClump & Clump )
6916
6877
6917
6878
void CClientGame::OnClientIFPUnload ( const std::shared_ptr < CClientIFP > & IFP )
6918
6879
{
6919
- // remove IFP animations from replaced animations of peds/players
6880
+ IFP-> MarkAsUnloading ( );
6920
6881
for ( auto it = m_mapOfPedPointers.begin (); it != m_mapOfPedPointers.end (); it++ )
6921
6882
{
6922
- CEntity * pEntity = it->first ->GetGameEntity ();
6923
- if ( pEntity != nullptr )
6924
- {
6925
- it->first ->RestoreAnimations ( IFP );
6883
+ // Remove IFP animations from replaced animations of peds/players
6884
+ it->first ->RestoreAnimations ( IFP );
6885
+
6886
+ // Make sure that streamed in pulses or changing model does not accidently
6887
+ // play our custom animation. We can do that by making the custom animation
6888
+ // untriggerable
6889
+ if ( it->first ->GetCustomAnimationBlockNameHash ( ) == IFP->GetBlockNameHash ( ) )
6890
+ {
6891
+ if ( it->first ->IsCustomAnimationPlaying ( ) )
6892
+ {
6893
+ it->first ->SetCustomAnimationUntriggerable ( );
6894
+ }
6895
+
6896
+ // Important! As we are using a shared_ptr, we need to decrement the reference counter
6897
+ // by setting the shared_ptr to nullptr, this will avoid memory leak
6898
+ if ( !it->first ->IsNextAnimationCustom ( ) && it->first ->IsCurrentAnimationCustom ( ) )
6899
+ {
6900
+ it->first ->DereferenceCustomAnimationBlock ();
6901
+ }
6926
6902
}
6927
6903
}
6928
6904
}
0 commit comments