11#include < StdInc.h>
22#include " ../game_sa/CAnimBlendSequenceSA.h"
33
4- hCMemoryMgr_Malloc OLD_CMemoryMgr_Malloc = (hCMemoryMgr_Malloc)0x0072F420 ;
5- hCMemoryMgr_Free OLD_CMemoryMgr_Free = (hCMemoryMgr_Free)0x0072F430 ;
6-
7- extern DWORD BoneIds[];
8- extern char BoneNames[][24 ];
9-
104CClientIFP::CClientIFP ( class CClientManager * pManager, ElementID ID ) : CClientEntity ( ID )
115{
126 // Init
@@ -21,7 +15,7 @@ CClientIFP::~CClientIFP ( void )
2115{
2216}
2317
24- bool CClientIFP::LoadIFP ( const char * szFilePath, SString strBlockName )
18+ bool CClientIFP::LoadIFP ( const char * szFilePath, const SString & strBlockName )
2519{
2620 printf (" \n CClientIFP::LoadIFP: szFilePath %s\n szBlockName: %s\n\n " , szFilePath, strBlockName.c_str ());
2721
@@ -37,14 +31,14 @@ bool CClientIFP::LoadIFP ( const char* szFilePath, SString strBlockName )
3731
3832bool CClientIFP::LoadIFPFile ( const char * szFilePath )
3933{
40- createLoader ( szFilePath );
34+ CreateLoader ( szFilePath );
4135
42- if ( loadFile ( ) )
36+ if ( LoadFile ( ) )
4337 {
4438 printf (" IfpLoader: File loaded. Parsing it now.\n " );
4539
4640 char Version [ 4 ];
47- readBytes ( Version, sizeof ( Version ) );
41+ ReadBytes ( Version, sizeof ( Version ) );
4842
4943 bool bAnp3 = strncmp ( Version, " ANP3" , sizeof ( Version ) ) == 0 ;
5044 bool bAnp2 = strncmp ( Version, " ANP2" , sizeof ( Version ) ) == 0 ;
@@ -61,7 +55,7 @@ bool CClientIFP::LoadIFPFile ( const char * szFilePath )
6155
6256 // We are unloading the data because we don't need to read it anymore.
6357 // This function does not unload IFP, to unload ifp call unloadIFP function
64- unloadFile ( );
58+ UnloadFile ( );
6559 }
6660 else
6761 {
@@ -80,11 +74,9 @@ void CClientIFP::ReadIFPVersion1 ( )
8074 ReadHeaderVersion1 ( Info );
8175
8276 m_pVecAnimations->resize ( Info.Entries );
83-
8477 for ( auto it = m_pVecAnimations->begin (); it != m_pVecAnimations->end (); ++it )
8578 {
8679 ReadAnimationNameVersion1 ( it->Name );
87-
8880 printf (" Animation Name: %s \n " , it->Name .c_str ( ) );
8981
9082 IFP_DGAN Dgan;
@@ -104,7 +96,7 @@ void CClientIFP::ReadIFPVersion1 ( )
10496void CClientIFP::ReadIFPVersion2 ( bool bAnp3 )
10597{
10698 IFPHeaderV2 Header;
107- readBuffer < IFPHeaderV2 > ( &Header );
99+ ReadBuffer < IFPHeaderV2 > ( &Header );
108100
109101 m_pVecAnimations->resize ( Header.TotalAnimations );
110102 for ( auto it = m_pVecAnimations->begin (); it != m_pVecAnimations->end (); ++it )
@@ -218,11 +210,11 @@ WORD CClientIFP::ReadSequencesVersion2 ( std::unique_ptr < CAnimBlendHierarchy >
218210int32_t CClientIFP::ReadSequenceVersion1 ( IFP_ANIM & Anim )
219211{
220212 IFP_CPAN Cpan;
221- readBuffer < IFP_CPAN > ( &Cpan );
213+ ReadBuffer < IFP_CPAN > ( &Cpan );
222214 RoundSize ( Cpan.Base .Size );
223- readBytes ( &Anim, sizeof ( IFP_BASE ) );
215+ ReadBytes ( &Anim, sizeof ( IFP_BASE ) );
224216 RoundSize ( Anim.Base .Size );
225- readBytes ( &Anim.Name , Anim.Base .Size );
217+ ReadBytes ( &Anim.Name , Anim.Base .Size );
226218
227219 int32_t iBoneID = -1 ;
228220 if ( Anim.Base .Size == 0x2C )
@@ -240,7 +232,7 @@ int32_t CClientIFP::ReadSequenceVersion1 ( IFP_ANIM & Anim )
240232
241233void CClientIFP::ReadSequenceVersion2 ( Object & ObjectNode )
242234{
243- readBuffer < Object > ( &ObjectNode );
235+ ReadBuffer < Object > ( &ObjectNode );
244236 std::string BoneName = ConvertStringToMapKey ( ObjectNode.Name );
245237 std::string strCorrectBoneName;
246238 if (ObjectNode.BoneID == -1 )
@@ -266,7 +258,7 @@ bool CClientIFP::ReadSequenceKeyFrames ( std::unique_ptr < CAnimBlendSequence >
266258 size_t iCompressedFrameSize = GetSizeOfCompressedFrame ( iFrameType );
267259 if ( iCompressedFrameSize )
268260 {
269- BYTE * pKeyFrames = static_cast < BYTE * > ( OLD_CMemoryMgr_Malloc ( iCompressedFrameSize * iFrames ) );
261+ BYTE * pKeyFrames = m_pAnimManager-> AllocateKeyFramesMemory ( iCompressedFrameSize * iFrames );
270262 pAnimationSequence->SetKeyFrames ( iFrames, IsKeyFramesTypeRoot ( iFrameType ), m_kbAllKeyFramesCompressed, pKeyFrames );
271263 ReadKeyFramesAsCompressed ( iFrameType, pKeyFrames, iFrames );
272264 return true ;
@@ -277,47 +269,47 @@ bool CClientIFP::ReadSequenceKeyFrames ( std::unique_ptr < CAnimBlendSequence >
277269void CClientIFP::ReadHeaderVersion1 ( IFP_INFO & Info )
278270{
279271 uint32_t OffsetEOF;
280- readBuffer < uint32_t > ( &OffsetEOF );
272+ ReadBuffer < uint32_t > ( &OffsetEOF );
281273 RoundSize ( OffsetEOF );
282- readBytes ( &Info, sizeof ( IFP_BASE ) );
274+ ReadBytes ( &Info, sizeof ( IFP_BASE ) );
283275 RoundSize ( Info.Base .Size );
284- readBytes ( &Info.Entries , Info.Base .Size );
276+ ReadBytes ( &Info.Entries , Info.Base .Size );
285277}
286278
287279void CClientIFP::ReadAnimationNameVersion1 ( SString & strAnimationName )
288280{
289281 IFP_NAME Name;
290- readBuffer < IFP_NAME > ( &Name );
282+ ReadBuffer < IFP_NAME > ( &Name );
291283 RoundSize ( Name.Base .Size );
292284
293285 char szAnimationName [ 24 ];
294- readCString ( szAnimationName, Name.Base .Size );
286+ ReadCString ( szAnimationName, Name.Base .Size );
295287 strAnimationName = szAnimationName;
296288}
297289
298290void CClientIFP::ReadDgan ( IFP_DGAN & Dgan )
299291{
300- readBytes ( &Dgan, sizeof ( IFP_BASE ) * 2 );
292+ ReadBytes ( &Dgan, sizeof ( IFP_BASE ) * 2 );
301293 RoundSize ( Dgan.Base .Size );
302294 RoundSize ( Dgan.Info .Base .Size );
303- readBytes ( &Dgan.Info .Entries , Dgan.Info .Base .Size );
295+ ReadBytes ( &Dgan.Info .Entries , Dgan.Info .Base .Size );
304296}
305297
306298CClientIFP::IFP_FrameType CClientIFP::ReadKfrm ( void )
307299{
308300 IFP_KFRM Kfrm;
309- readBuffer < IFP_KFRM > ( &Kfrm );
301+ ReadBuffer < IFP_KFRM > ( &Kfrm );
310302 return GetFrameTypeFromFourCC ( Kfrm.Base .FourCC );
311303}
312304
313305void CClientIFP::ReadAnimationHeaderVersion2 ( Animation & AnimationNode, bool bAnp3 )
314306{
315- readCString ( ( char * ) &AnimationNode.Name , sizeof ( Animation::Name ) );
316- readBuffer < int32_t > ( &AnimationNode.TotalObjects );
307+ ReadCString ( ( char * ) &AnimationNode.Name , sizeof ( Animation::Name ) );
308+ ReadBuffer < int32_t > ( &AnimationNode.TotalObjects );
317309 if ( bAnp3 )
318310 {
319- readBuffer < int32_t > ( &AnimationNode.FrameSize );
320- readBuffer < int32_t > ( &AnimationNode.isCompressed );
311+ ReadBuffer < int32_t > ( &AnimationNode.FrameSize );
312+ ReadBuffer < int32_t > ( &AnimationNode.isCompressed );
321313 }
322314}
323315
@@ -360,7 +352,7 @@ void CClientIFP::ReadKrtsFramesAsCompressed ( BYTE * pKeyFrames, int32_t TotalF
360352 IFP_Compressed_KRT0 * CompressedKrt0 = (IFP_Compressed_KRT0 *)((BYTE*)pKeyFrames + sizeof (IFP_Compressed_KRT0) * FrameIndex);
361353
362354 IFP_KRTS Krts;
363- readBuffer < IFP_KRTS >(&Krts);
355+ ReadBuffer < IFP_KRTS >(&Krts);
364356
365357 CompressedKrt0->Rotation .X = static_cast < int16_t > ( ((-Krts.Rotation .X ) * 4096 .0f ) );
366358 CompressedKrt0->Rotation .Y = static_cast < int16_t > ( ((-Krts.Rotation .Y ) * 4096 .0f ) );
@@ -382,7 +374,7 @@ void CClientIFP::ReadKrt0FramesAsCompressed ( BYTE * pKeyFrames, int32_t TotalF
382374 IFP_Compressed_KRT0 * CompressedKrt0 = (IFP_Compressed_KRT0 *)((BYTE*)pKeyFrames + sizeof (IFP_Compressed_KRT0) * FrameIndex);
383375
384376 IFP_KRT0 Krt0;
385- readBuffer < IFP_KRT0 > ( &Krt0 );
377+ ReadBuffer < IFP_KRT0 > ( &Krt0 );
386378
387379 CompressedKrt0->Rotation .X = static_cast < int16_t > ( ((-Krt0.Rotation .X ) * 4096 .0f ) );
388380 CompressedKrt0->Rotation .Y = static_cast < int16_t > ( ((-Krt0.Rotation .Y ) * 4096 .0f ) );
@@ -404,7 +396,7 @@ void CClientIFP::ReadKr00FramesAsCompressed ( BYTE * pKeyFrames, int32_t TotalF
404396 IFP_Compressed_KR00 * CompressedKr00 = (IFP_Compressed_KR00 *)((BYTE*)pKeyFrames + sizeof (IFP_Compressed_KR00) * FrameIndex);
405397
406398 IFP_KR00 Kr00;
407- readBuffer < IFP_KR00 > ( &Kr00 );
399+ ReadBuffer < IFP_KR00 > ( &Kr00 );
408400
409401 CompressedKr00->Rotation .X = static_cast < int16_t > ( ((-Kr00.Rotation .X ) * 4096 .0f ) );
410402 CompressedKr00->Rotation .Y = static_cast < int16_t > ( ((-Kr00.Rotation .Y ) * 4096 .0f ) );
@@ -418,13 +410,13 @@ void CClientIFP::ReadKr00FramesAsCompressed ( BYTE * pKeyFrames, int32_t TotalF
418410void CClientIFP::ReadKr00CompressedFrames ( BYTE * pKeyFrames, int32_t TotalFrames )
419411{
420412 size_t iSizeInBytes = sizeof ( IFP_Compressed_KR00 ) * TotalFrames;
421- readBytes ( pKeyFrames, iSizeInBytes );
413+ ReadBytes ( pKeyFrames, iSizeInBytes );
422414}
423415
424416void CClientIFP::ReadKrt0CompressedFrames ( BYTE * pKeyFrames, int32_t TotalFrames )
425417{
426418 size_t iSizeInBytes = sizeof ( IFP_Compressed_KRT0 ) * TotalFrames;
427- readBytes ( pKeyFrames, iSizeInBytes );
419+ ReadBytes ( pKeyFrames, iSizeInBytes );
428420}
429421
430422size_t CClientIFP::GetSizeOfCompressedFrame ( IFP_FrameType iFrameType )
@@ -484,8 +476,8 @@ void CClientIFP::CopySequencesWithDummies ( std::unique_ptr < CAnimBlendHierarch
484476{
485477 for (size_t SequenceIndex = 0 ; SequenceIndex < m_kcIFPSequences; SequenceIndex++)
486478 {
487- std::string BoneName = BoneNames [SequenceIndex];
488- DWORD BoneID = BoneIds [SequenceIndex];
479+ std::string BoneName = m_karrstrBoneNames [SequenceIndex];
480+ DWORD BoneID = m_karruBoneIds [SequenceIndex];
489481
490482 CAnimBlendSequenceSAInterface * pAnimationSequenceInterface = pAnimationHierarchy->GetSequence ( SequenceIndex );
491483 auto it = mapOfSequences.find ( BoneID );
@@ -507,17 +499,17 @@ BYTE * CClientIFP::AllocateSequencesMemory ( std::unique_ptr < CAnimBlendHierarc
507499 return static_cast < BYTE * > ( operator new ( 12 * cMaxSequences + 4 ) );
508500}
509501
510- CClientIFP::IFP_FrameType CClientIFP::GetFrameTypeFromFourCC ( char * FourCC )
502+ CClientIFP::IFP_FrameType CClientIFP::GetFrameTypeFromFourCC ( const char * szFourCC )
511503{
512- if (strncmp (FourCC , " KRTS" , 4 ) == 0 )
504+ if ( strncmp ( szFourCC , " KRTS" , 4 ) == 0 )
513505 {
514506 return IFP_FrameType::KRTS;
515507 }
516- else if (strncmp (FourCC , " KRT0" , 4 ) == 0 )
508+ else if ( strncmp ( szFourCC , " KRT0" , 4 ) == 0 )
517509 {
518510 return IFP_FrameType::KRT0;
519511 }
520- else if (strncmp (FourCC , " KR00" , 4 ) == 0 )
512+ else if ( strncmp ( szFourCC , " KR00" , 4 ) == 0 )
521513 {
522514 return IFP_FrameType::KR00;
523515 }
@@ -549,7 +541,7 @@ void CClientIFP::InsertAnimationDummySequence ( std::unique_ptr < CAnimBlendSequ
549541 }
550542
551543 const size_t FramesDataSizeInBytes = FrameSize * cKeyFrames;
552- BYTE * pKeyFrames = static_cast < BYTE * > ( OLD_CMemoryMgr_Malloc ( FramesDataSizeInBytes ) );
544+ BYTE * pKeyFrames = m_pAnimManager-> AllocateKeyFramesMemory ( FramesDataSizeInBytes );
553545 pAnimationSequence->SetKeyFrames ( cKeyFrames, bHasTranslationValues, bKeyFrameCompressed, pKeyFrames );
554546 CopyDummyKeyFrameByBoneID ( pKeyFrames, dwBoneID );
555547}
@@ -769,7 +761,7 @@ std::string CClientIFP::ConvertStringToMapKey ( const char * szString )
769761
770762constexpr void CClientIFP::RoundSize ( uint32_t & u32Size )
771763{
772- if ( u32Size & 3 )
764+ if ( u32Size & 3 )
773765 {
774766 u32Size += 4 - ( u32Size & 3 );
775767 }
0 commit comments