@@ -37,10 +37,23 @@ bool CClientIFP::LoadIFP ( const char* szFilePath, SString strBlockName )
37
37
// return false;
38
38
}
39
39
40
-
40
+ // Temporary method to avoid memory leaks, we'll need to rewrite the entire thing ;)
41
41
void CClientIFP::UnloadIFP ( void )
42
42
{
43
- // printf ("CClientIFP::UnloadIFP ( ) called!\n");
43
+ printf (" CClientIFP::UnloadIFP ( ) called!\n " );
44
+
45
+ for ( size_t i = 0 ; i < m_Animations.size (); i++ )
46
+ {
47
+ IFP_Animation * ifpAnimation = &m_Animations[i];
48
+ for (unsigned short SequenceIndex = 0 ; i < ifpAnimation->Hierarchy .m_nSeqCount ; i++)
49
+ {
50
+ _CAnimBlendSequence * pSequence = (_CAnimBlendSequence*)((BYTE*)(ifpAnimation->Hierarchy .m_pSequences ) + (sizeof (_CAnimBlendSequence) * SequenceIndex));
51
+ free ( pSequence->m_pFrames );
52
+ }
53
+ delete ifpAnimation->pSequencesMemory ;
54
+ }
55
+
56
+ printf (" IFP unloaded sucessfully\n " );
44
57
}
45
58
46
59
bool CClientIFP::LoadIFPFile (const char * FilePath)
@@ -67,7 +80,7 @@ bool CClientIFP::LoadIFPFile(const char * FilePath)
67
80
{
68
81
isVersion1 = true ;
69
82
70
- // ReadIFPVersion1 ( );
83
+ ReadIFPVersion1 ( );
71
84
}
72
85
73
86
// We are unloading the data because we don't need to read it anymore.
@@ -95,12 +108,12 @@ void CClientIFP::ReadIFPVersion2( bool anp3)
95
108
{
96
109
readBuffer < IFPHeaderV2 > ( &HeaderV2 );
97
110
98
- AnimationHierarchies.resize (HeaderV2.TotalAnimations );
99
-
100
-
101
- for (size_t i = 0 ; i < AnimationHierarchies.size (); i++)
111
+ m_Animations.resize ( HeaderV2.TotalAnimations );
112
+ for (size_t i = 0 ; i < m_Animations.size (); i++)
102
113
{
103
- _CAnimBlendHierarchy * pAnimHierarchy = &AnimationHierarchies[i];
114
+ IFP_Animation & ifpAnimation = m_Animations[i];
115
+
116
+ _CAnimBlendHierarchy * pAnimHierarchy = &ifpAnimation.Hierarchy ;
104
117
105
118
_CAnimBlendHierarchy_Constructor (pAnimHierarchy);
106
119
@@ -121,7 +134,7 @@ void CClientIFP::ReadIFPVersion2( bool anp3)
121
134
122
135
pAnimHierarchy->m_bRunningCompressed = AnimationNode.isCompressed & 1 ;
123
136
124
- pKeyFrames = (unsigned char *)OLD_CMemoryMgr_Malloc (AnimationNode.FrameSize );
137
+ pKeyFrames = (unsigned char *)malloc (AnimationNode.FrameSize );
125
138
}
126
139
127
140
OLD__CAnimBlendHierarchy_SetName (pAnimHierarchy, AnimationNode.Name );
@@ -133,6 +146,9 @@ void CClientIFP::ReadIFPVersion2( bool anp3)
133
146
const unsigned short TotalSequences = IFP_TOTAL_SEQUENCES + pAnimHierarchy->m_nSeqCount ;
134
147
char * pNewSequencesMemory = ( char * ) operator new ( 12 * TotalSequences + 4 ); // Allocate memory for sequences ( 12 * seq_count + 4 )
135
148
149
+ // Okay, we have assigned the memory. We can free it when we want to
150
+ ifpAnimation.pSequencesMemory = pNewSequencesMemory;
151
+
136
152
pAnimHierarchy->m_pSequences = ( _CAnimBlendSequence * )( pNewSequencesMemory + 4 );
137
153
138
154
std::map < std::string, _CAnimBlendSequence > MapOfSequences;
@@ -292,13 +308,13 @@ void CClientIFP::ReadIFPVersion2( bool anp3)
292
308
Call__CAnimBlendHierarchy_RemoveQuaternionFlips (pAnimHierarchy);
293
309
294
310
Call__CAnimBlendHierarchy_CalcTotalTime (pAnimHierarchy);
295
- }
311
+ }
296
312
297
313
}
298
314
}
299
315
300
316
void CClientIFP::ReadIFPVersion1 ( )
301
- {
317
+ {
302
318
uint32_t OffsetEOF;
303
319
304
320
readBuffer < uint32_t > ( &OffsetEOF );
@@ -312,12 +328,12 @@ void CClientIFP::ReadIFPVersion1 ( )
312
328
313
329
// ofs << "Total Animations: " << Info.Entries << std::endl;
314
330
315
- AnimationHierarchies.resize ( Info.Entries );
316
-
317
-
318
- for (size_t i = 0 ; i < AnimationHierarchies.size (); i++)
331
+ m_Animations.resize ( Info.Entries );
332
+ for (size_t i = 0 ; i < m_Animations.size (); i++)
319
333
{
320
- _CAnimBlendHierarchy * pAnimHierarchy = &AnimationHierarchies[i];
334
+ IFP_Animation & ifpAnimation = m_Animations[i];
335
+
336
+ _CAnimBlendHierarchy * pAnimHierarchy = &ifpAnimation.Hierarchy ;
321
337
322
338
_CAnimBlendHierarchy_Constructor (pAnimHierarchy);
323
339
@@ -356,6 +372,9 @@ void CClientIFP::ReadIFPVersion1 ( )
356
372
const unsigned short TotalSequences = IFP_TOTAL_SEQUENCES + pAnimHierarchy->m_nSeqCount ;
357
373
char * pNewSequencesMemory = ( char * ) operator new ( 12 * TotalSequences + 4 ); // Allocate memory for sequences ( 12 * seq_count + 4 )
358
374
375
+ // Okay, we have assigned the memory. We can free it when we want to
376
+ ifpAnimation.pSequencesMemory = pNewSequencesMemory;
377
+
359
378
pAnimHierarchy->m_pSequences = ( _CAnimBlendSequence * )( pNewSequencesMemory + 4 );
360
379
361
380
std::map < std::string, _CAnimBlendSequence > MapOfSequences;
@@ -438,7 +457,7 @@ void CClientIFP::ReadIFPVersion1 ( )
438
457
439
458
IFP_FrameType FrameType = getFrameTypeFromFourCC ( Kfrm.Base .FourCC );
440
459
size_t CompressedFrameSize = GetSizeOfCompressedFrame ( FrameType );
441
- BYTE * pKeyFrames = ( BYTE * ) OLD_CMemoryMgr_Malloc ( CompressedFrameSize * Anim.Frames );
460
+ BYTE * pKeyFrames = ( BYTE * ) malloc ( CompressedFrameSize * Anim.Frames );
442
461
443
462
bool bIsRoot = FrameType != IFP_FrameType::KR00;
444
463
if (bUnknownSequence)
@@ -454,17 +473,17 @@ void CClientIFP::ReadIFPVersion1 ( )
454
473
{
455
474
// ofs << " | FrameType: KRTS" << std::endl;
456
475
457
- ReadKrtsFramesAsCompressed ( pKeyFrames, Anim.Frames );
476
+ ReadKrtsFramesAsCompressed ( pKeyFrames, Anim.Frames );
458
477
}
459
478
else if (FrameType == IFP_FrameType::KRT0)
460
479
{
461
480
// ofs << " | FrameType: KRT0" << std::endl;
462
- ReadKrt0FramesAsCompressed ( pKeyFrames, Anim.Frames );
481
+ ReadKrt0FramesAsCompressed ( pKeyFrames, Anim.Frames );
463
482
}
464
483
else if (FrameType == IFP_FrameType::KR00)
465
484
{
466
485
// ofs << " | FrameType: KR00" << std::endl;
467
- ReadKr00FramesAsCompressed ( pKeyFrames, Anim.Frames , BoneID );
486
+ ReadKr00FramesAsCompressed ( pKeyFrames, Anim.Frames , BoneID );
468
487
}
469
488
470
489
if (!bUnknownSequence)
@@ -473,7 +492,7 @@ void CClientIFP::ReadIFPVersion1 ( )
473
492
}
474
493
475
494
}
476
-
495
+
477
496
std::map < std::string, _CAnimBlendSequence >::iterator it;
478
497
for (size_t SequenceIndex = 0 ; SequenceIndex < IFP_TOTAL_SEQUENCES; SequenceIndex++)
479
498
{
@@ -507,8 +526,8 @@ void CClientIFP::ReadIFPVersion1 ( )
507
526
Call__CAnimBlendHierarchy_RemoveQuaternionFlips (pAnimHierarchy);
508
527
509
528
Call__CAnimBlendHierarchy_CalcTotalTime (pAnimHierarchy);
510
- }
511
- }
529
+ }
530
+ }
512
531
}
513
532
514
533
@@ -655,7 +674,7 @@ void CClientIFP::insertAnimDummySequence ( bool anp3, _CAnimBlendHierarchy * pAn
655
674
656
675
657
676
658
- pKeyFrames = (unsigned char *)OLD_CMemoryMgr_Malloc (FramesDataSizeInBytes);
677
+ pKeyFrames = (unsigned char *)malloc (FramesDataSizeInBytes);
659
678
660
679
OLD__CAnimBlendSequence_SetNumFrames (pSequence, TotalFrames, bIsRoot, bIsCompressed, pKeyFrames);
661
680
0 commit comments