Skip to content

Commit 05289e1

Browse files
committed
[FIX] Fixed custom animations crashing by changing keyframes memory allocator from malloc to OLD_CMemoryMgr_Malloc which is GTA SA function
1 parent ac2ef96 commit 05289e1

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

Client/mods/deathmatch/logic/CClientIFP.cpp

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ bool CClientIFP::LoadIFP ( const char* szFilePath, SString strBlockName )
3737
// Temporary method to avoid memory leaks, we'll need to rewrite the entire thing ;)
3838
void CClientIFP::UnloadIFP ( void )
3939
{
40+
printf ("CClientIFP::UnloadIFP ( ) called, but IFP is not unloaded, PLEASE FIX THIS LATER!\n");
41+
/*
4042
printf ("CClientIFP::UnloadIFP ( ) called!\n");
4143
4244
for ( size_t i = 0; i < m_Animations.size(); i++ )
@@ -62,10 +64,10 @@ void CClientIFP::UnloadIFP ( void )
6264
{
6365
unsigned char * pKeyFrames = m_DummySequencesKeyFrames [ DummySequenceIndex ];
6466
free ( pKeyFrames );
65-
}
67+
}*/
6668

6769
g_pClientGame->RemoveIFPPointerFromMap ( m_strBlockName );
68-
printf ("IFP unloaded sucessfully, removed from map as well.\n");
70+
//printf ("IFP unloaded sucessfully, removed from map as well.\n");
6971
}
7072

7173
bool CClientIFP::LoadIFPFile(const char * FilePath)
@@ -91,7 +93,6 @@ bool CClientIFP::LoadIFPFile(const char * FilePath)
9193
else
9294
{
9395
isVersion1 = true;
94-
9596
ReadIFPVersion1 ( );
9697
}
9798

@@ -128,6 +129,7 @@ void CClientIFP::ReadIFPVersion2( bool anp3)
128129
Animation AnimationNode;
129130

130131
readCString((char *)&AnimationNode.Name, sizeof(Animation::Name));
132+
ifpAnimation.Name = AnimationNode.Name;
131133
readBuffer < int32_t >(&AnimationNode.TotalObjects);
132134

133135
//ofs << "Animation Name: " << AnimationNode.Name << " | Index: " << i << std::endl;
@@ -142,7 +144,7 @@ void CClientIFP::ReadIFPVersion2( bool anp3)
142144

143145
pAnimHierarchy->m_bRunningCompressed = AnimationNode.isCompressed & 1;
144146

145-
pKeyFrames = (unsigned char*)malloc(AnimationNode.FrameSize);
147+
pKeyFrames = (unsigned char*) OLD_CMemoryMgr_Malloc(AnimationNode.FrameSize); //malloc(AnimationNode.FrameSize);
146148

147149
ifpAnimation.pFramesMemoryVersion2 = pKeyFrames;
148150
}
@@ -353,6 +355,7 @@ void CClientIFP::ReadIFPVersion1 ( )
353355

354356
char AnimationName [ 24 ];
355357
readCString (AnimationName, Name.Base.Size);
358+
ifpAnimation.Name = AnimationName;
356359

357360
//ofs << "Animation Name: " << AnimationName << " | Index: " << i << std::endl;
358361
printf("Animation Name: %s | Index: %d \n", AnimationName, i);
@@ -467,7 +470,7 @@ void CClientIFP::ReadIFPVersion1 ( )
467470

468471
IFP_FrameType FrameType = getFrameTypeFromFourCC ( Kfrm.Base.FourCC );
469472
size_t CompressedFrameSize = GetSizeOfCompressedFrame ( FrameType );
470-
BYTE * pKeyFrames = ( BYTE * ) malloc ( CompressedFrameSize * Anim.Frames );
473+
BYTE * pKeyFrames = ( BYTE * ) OLD_CMemoryMgr_Malloc ( CompressedFrameSize * Anim.Frames ); // malloc ( CompressedFrameSize * Anim.Frames );
471474

472475
bool bIsRoot = FrameType != IFP_FrameType::KR00;
473476
if (bUnknownSequence)
@@ -682,9 +685,8 @@ void CClientIFP::insertAnimDummySequence ( bool anp3, _CAnimBlendHierarchy * pAn
682685
const size_t FramesDataSizeInBytes = FrameSize * TotalFrames;
683686
unsigned char* pKeyFrames = nullptr;
684687

685-
686-
687-
pKeyFrames = (unsigned char*)malloc(FramesDataSizeInBytes);
688+
pKeyFrames = (unsigned char*)OLD_CMemoryMgr_Malloc(FramesDataSizeInBytes);
689+
//pKeyFrames = (unsigned char*)malloc(FramesDataSizeInBytes);
688690

689691
if ( !isVersion1 )
690692
{
@@ -1170,6 +1172,18 @@ std::string CClientIFP::getCorrectBoneNameFromName(std::string const& BoneName)
11701172
return BoneName;
11711173
}
11721174

1175+
CAnimBlendHierarchySAInterface * CClientIFP::GetAnimationHierarchy ( const SString & strAnimationName )
1176+
{
1177+
for (auto it = m_Animations.begin(); it != m_Animations.end(); ++it)
1178+
{
1179+
if (strAnimationName.ToLower() == it->Name.ToLower())
1180+
{
1181+
return (CAnimBlendHierarchySAInterface *)&it->Hierarchy;
1182+
}
1183+
}
1184+
return nullptr;
1185+
}
1186+
11731187
// ----------------------------------------------------------------------------------------------------------
11741188
// -------------------------------------- For Hierarchy ----------------------------------------------------
11751189
// ----------------------------------------------------------------------------------------------------------

Client/mods/deathmatch/logic/CClientIFP.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ class CClientIFP: public CClientEntity, FileLoader
3939
std::string getCorrectBoneNameFromID(int32_t & BoneID);
4040
size_t getCorrectBoneIndexFromID(int32_t & BoneID);
4141

42+
CAnimBlendHierarchySAInterface * GetAnimationHierarchy ( const SString & strAnimationName );
43+
4244
// Sorta a hack that these are required by CClientEntity...
4345
void Unlink ( void ) {};
4446
void GetPosition ( CVector& vecPosition ) const {};

0 commit comments

Comments
 (0)