Skip to content

Commit 66b9cd1

Browse files
committed
Replaced Animations map is now thread-safe in CClientPed
1 parent a5ddb6e commit 66b9cd1

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

Client/mods/deathmatch/logic/CClientPed.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6210,11 +6210,20 @@ void CClientPed::ReplaceAnimation ( CAnimBlendHierarchy * pInternalAnimHierarchy
62106210
SReplacedAnimation replacedAnimation;
62116211
replacedAnimation.pIFP = pIFP;
62126212
replacedAnimation.pAnimationHierarchy = pCustomAnimHierarchy;
6213+
6214+
std::lock_guard < std::mutex > mutexGuardedLock ( m_MutexOfReplacedAnimationsMap );
62136215
m_mapOfReplacedAnimations [ pInternalAnimHierarchy->GetInterface () ] = replacedAnimation;
62146216
}
62156217

6218+
void CClientPed::RestoreAnimation ( CAnimBlendHierarchy * pInternalAnimHierarchy )
6219+
{
6220+
std::lock_guard < std::mutex > mutexGuardedLock ( m_MutexOfReplacedAnimationsMap );
6221+
m_mapOfReplacedAnimations.erase ( pInternalAnimHierarchy->GetInterface () );
6222+
}
6223+
62166224
void CClientPed::RestoreAnimations ( const std::shared_ptr < CClientIFP > & IFP )
62176225
{
6226+
std::lock_guard < std::mutex > mutexGuardedLock ( m_MutexOfReplacedAnimationsMap );
62186227
for ( auto const& x : m_mapOfReplacedAnimations )
62196228
{
62206229
if ( std::addressof ( *IFP.get ( ) ) == std::addressof ( *x.second.pIFP.get ( ) ) )
@@ -6226,6 +6235,7 @@ void CClientPed::RestoreAnimations ( const std::shared_ptr < CClientIFP > & IFP
62266235

62276236
void CClientPed::RestoreAnimations ( CAnimBlock & animationBlock )
62286237
{
6238+
std::lock_guard < std::mutex > mutexGuardedLock ( m_MutexOfReplacedAnimationsMap );
62296239
const size_t cAnimations = animationBlock.GetAnimationCount ( );
62306240
for ( size_t i = 0; i < cAnimations; i++ )
62316241
{
@@ -6234,8 +6244,15 @@ void CClientPed::RestoreAnimations ( CAnimBlock & animationBlock )
62346244
}
62356245
}
62366246

6247+
void CClientPed::RestoreAllAnimations ( void )
6248+
{
6249+
std::lock_guard < std::mutex > mutexGuardedLock ( m_MutexOfReplacedAnimationsMap );
6250+
m_mapOfReplacedAnimations.clear ( );
6251+
}
6252+
62376253
SReplacedAnimation * CClientPed::GetReplacedAnimation ( CAnimBlendHierarchySAInterface * pInternalHierarchyInterface )
62386254
{
6255+
std::lock_guard < std::mutex > mutexGuardedLock ( m_MutexOfReplacedAnimationsMap );
62396256
CClientPed::ReplacedAnim_type::iterator it;
62406257
it = m_mapOfReplacedAnimations.find ( pInternalHierarchyInterface );
62416258
if ( it != m_mapOfReplacedAnimations.end ( ) )

Client/mods/deathmatch/logic/CClientPed.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,10 +485,10 @@ class CClientPed : public CClientStreamElement, public CAntiCheatModule
485485
inline const unsigned int & GetCustomAnimationNameHash ( void ) { return m_u32CustomAnimationNameHash; }
486486

487487
void ReplaceAnimation ( CAnimBlendHierarchy * pInternalAnimHierarchy, const std::shared_ptr < CClientIFP > & pIFP, CAnimBlendHierarchySAInterface * pCustomAnimHierarchy );
488-
inline void RestoreAnimation ( CAnimBlendHierarchy * pInternalAnimHierarchy ) { m_mapOfReplacedAnimations.erase ( pInternalAnimHierarchy->GetInterface () ); }
488+
void RestoreAnimation ( CAnimBlendHierarchy * pInternalAnimHierarchy );
489489
void RestoreAnimations ( const std::shared_ptr < CClientIFP > & IFP );
490490
void RestoreAnimations ( CAnimBlock & animationBlock );
491-
inline void RestoreAllAnimations ( void ) { m_mapOfReplacedAnimations.clear ( ); }
491+
void RestoreAllAnimations ( void );
492492
SReplacedAnimation * GetReplacedAnimation ( CAnimBlendHierarchySAInterface * pInternalHierarchyInterface );
493493

494494
protected:
@@ -698,6 +698,7 @@ class CClientPed : public CClientStreamElement, public CAntiCheatModule
698698

699699
// Key: Internal GTA animation, Value: Custom Animation
700700
ReplacedAnim_type m_mapOfReplacedAnimations;
701+
mutable std::mutex m_MutexOfReplacedAnimationsMap;
701702
};
702703

703704
#endif

0 commit comments

Comments
 (0)