1
1
#include < StdInc.h>
2
2
3
3
h_CAnimBlendHierarchy_SetName OLD__CAnimBlendHierarchy_SetName = (h_CAnimBlendHierarchy_SetName)0x4CF2D0 ;
4
+ hCAnimBlendHierarchy_RemoveAnimSequences OLD_CAnimBlendHierarchy_RemoveAnimSequences = (hCAnimBlendHierarchy_RemoveAnimSequences)0x4CF8E0 ;
5
+ hCAnimBlendHierarchy_RemoveFromUncompressedCache OLD_CAnimBlendHierarchy_RemoveFromUncompressedCache = (hCAnimBlendHierarchy_RemoveFromUncompressedCache)0x004D42A0 ;
4
6
5
7
hCMemoryMgr_Malloc OLD_CMemoryMgr_Malloc = (hCMemoryMgr_Malloc)0x0072F420 ;
8
+ hCMemoryMgr_Free OLD_CMemoryMgr_Free = (hCMemoryMgr_Free)0x0072F430 ;
6
9
h_CAnimBlendSequence_SetName OLD__CAnimBlendSequence_SetName = (h_CAnimBlendSequence_SetName)0x4D0C50 ;
7
10
h_CAnimBlendSequence_SetBoneTag OLD__CAnimBlendSequence_SetBoneTag = (h_CAnimBlendSequence_SetBoneTag)0x4D0C70 ;
8
11
h_CAnimBlendSequence_SetNumFrames OLD__CAnimBlendSequence_SetNumFrames = (h_CAnimBlendSequence_SetNumFrames)0x4D0CD0 ;
@@ -18,6 +21,7 @@ CClientIFP::CClientIFP ( class CClientManager* pManager, ElementID ID ) : CClien
18
21
// Init
19
22
m_pManager = pManager;
20
23
SetTypeName ( " IFP" );
24
+ m_bisIFPLoaded = false ;
21
25
}
22
26
23
27
CClientIFP::~CClientIFP ( void )
@@ -27,47 +31,59 @@ CClientIFP::~CClientIFP ( void )
27
31
28
32
bool CClientIFP::LoadIFP ( const char * szFilePath, SString strBlockName )
29
33
{
30
- // printf ("\nCClientIFP::LoadIFP: szFilePath %s\n szBlockName: %s\n\n", szFilePath, szBlockName );
34
+ printf (" \n CClientIFP::LoadIFP: szFilePath %s\n szBlockName: %s\n\n " , szFilePath, strBlockName. c_str () );
31
35
32
36
m_strBlockName = strBlockName;
33
37
34
- return LoadIFPFile ( szFilePath );
38
+ if (LoadIFPFile (szFilePath))
39
+ {
40
+ m_bisIFPLoaded = true ;
41
+ return true ;
42
+ }
43
+ return false ;
35
44
}
36
45
37
- // Temporary method to avoid memory leaks, we'll need to rewrite the entire thing ;)
46
+
38
47
void CClientIFP::UnloadIFP ( void )
39
48
{
40
- printf ( " CClientIFP::UnloadIFP ( ) called, but IFP is not unloaded, PLEASE FIX THIS LATER! \n " );
41
- /*
42
- printf ("CClientIFP::UnloadIFP ( ) called!\n");
49
+ if ( m_bisIFPLoaded )
50
+ {
51
+ printf (" CClientIFP::UnloadIFP ( ) called!\n " );
43
52
44
- for ( size_t i = 0; i < m_Animations.size(); i++ )
45
- {
46
- IFP_Animation * ifpAnimation = &m_Animations[i];
47
- if ( isVersion1 )
48
- {
53
+
54
+ for ( size_t i = 0 ; i < m_Animations.size (); i++ )
55
+ {
56
+ IFP_Animation * ifpAnimation = &m_Animations[i];
57
+
58
+ OLD_CAnimBlendHierarchy_RemoveFromUncompressedCache ( (int )&ifpAnimation->Hierarchy );
59
+
49
60
for (unsigned short SequenceIndex = 0 ; SequenceIndex < ifpAnimation->Hierarchy .m_nSeqCount ; SequenceIndex++)
50
61
{
51
62
_CAnimBlendSequence * pSequence = (_CAnimBlendSequence*)((BYTE*)ifpAnimation->Hierarchy .m_pSequences + (sizeof (_CAnimBlendSequence) * SequenceIndex));
52
- free ( pSequence->m_pFrames );
63
+
64
+ if ( !( (pSequence->m_nFlags >> 3 ) & 1 ) ) // If ( !OneBigChunkForAllSequences )
65
+ {
66
+ OLD_CMemoryMgr_Free ( pSequence->m_pFrames ); // *(void **)(pThis + 8)); //pSequence->m_pFrames );
67
+ }
68
+ else
69
+ {
70
+ if ( SequenceIndex == 0 )
71
+ {
72
+ // All frames of all sequences are allocated on one memory block, so free that one
73
+ // and break the loop
74
+ OLD_CMemoryMgr_Free ( pSequence->m_pFrames );
75
+ break ;
76
+ }
77
+ }
78
+
53
79
}
54
- }
55
- else
56
- {
57
- free ( ifpAnimation->pFramesMemoryVersion2 );
80
+ delete ifpAnimation->pSequencesMemory ;
58
81
}
59
82
60
- delete ifpAnimation->pSequencesMemory;
61
- }
83
+ g_pClientGame->RemoveIFPPointerFromMap ( m_strBlockName );
62
84
63
- for (size_t DummySequenceIndex = 0; DummySequenceIndex < m_DummySequencesKeyFrames.size(); DummySequenceIndex++)
64
- {
65
- unsigned char * pKeyFrames = m_DummySequencesKeyFrames [ DummySequenceIndex ];
66
- free ( pKeyFrames );
67
- }*/
68
-
69
- g_pClientGame->RemoveIFPPointerFromMap ( m_strBlockName );
70
- // printf ("IFP unloaded sucessfully, removed from map as well.\n");
85
+ printf (" IFP unloaded sucessfully, removed from map as well.\n " );
86
+ }
71
87
}
72
88
73
89
bool CClientIFP::LoadIFPFile (const char * FilePath)
@@ -136,17 +152,12 @@ void CClientIFP::ReadIFPVersion2( bool anp3)
136
152
137
153
printf (" Animation Name: %s | Index: %d \n " , AnimationNode.Name , i);
138
154
139
- unsigned char * pKeyFrames = nullptr ;
140
155
if (anp3)
141
156
{
142
157
readBuffer < int32_t >(&AnimationNode.FrameSize );
143
158
readBuffer < int32_t >(&AnimationNode.isCompressed );
144
159
145
- pAnimHierarchy->m_bRunningCompressed = AnimationNode.isCompressed & 1 ;
146
-
147
- pKeyFrames = (unsigned char *) OLD_CMemoryMgr_Malloc (AnimationNode.FrameSize ); // malloc(AnimationNode.FrameSize);
148
-
149
- ifpAnimation.pFramesMemoryVersion2 = pKeyFrames;
160
+ pAnimHierarchy->m_bRunningCompressed = AnimationNode.isCompressed & 1 ;
150
161
}
151
162
152
163
OLD__CAnimBlendHierarchy_SetName (pAnimHierarchy, AnimationNode.Name );
@@ -156,12 +167,9 @@ void CClientIFP::ReadIFPVersion2( bool anp3)
156
167
pAnimHierarchy->field_B = 0 ;
157
168
158
169
const unsigned short TotalSequences = IFP_TOTAL_SEQUENCES + pAnimHierarchy->m_nSeqCount ;
159
- char * pNewSequencesMemory = ( char * ) operator new ( 12 * TotalSequences + 4 ); // Allocate memory for sequences ( 12 * seq_count + 4 )
170
+ ifpAnimation. pSequencesMemory = ( char * ) operator new ( 12 * TotalSequences + 4 ); // Allocate memory for sequences ( 12 * seq_count + 4 )
160
171
161
- // Okay, we have assigned the memory. We can free it when we want to
162
- ifpAnimation.pSequencesMemory = pNewSequencesMemory;
163
-
164
- pAnimHierarchy->m_pSequences = ( _CAnimBlendSequence * )( pNewSequencesMemory + 4 );
172
+ pAnimHierarchy->m_pSequences = ( _CAnimBlendSequence * )( ifpAnimation.pSequencesMemory + 4 );
165
173
166
174
std::map < std::string, _CAnimBlendSequence > MapOfSequences;
167
175
@@ -265,6 +273,8 @@ void CClientIFP::ReadIFPVersion2( bool anp3)
265
273
}
266
274
if (!bInvalidType)
267
275
{
276
+ unsigned char * pKeyFrames = (unsigned char *) OLD_CMemoryMgr_Malloc ( data_size );
277
+
268
278
if ( bUnknownSequence )
269
279
{
270
280
OLD__CAnimBlendSequence_SetNumFrames ( pUnkownSequence, ObjectNode.TotalFrames , bIsRoot, bIsCompressed, pKeyFrames );
@@ -274,13 +284,7 @@ void CClientIFP::ReadIFPVersion2( bool anp3)
274
284
OLD__CAnimBlendSequence_SetNumFrames ( &Sequence, ObjectNode.TotalFrames , bIsRoot, bIsCompressed, pKeyFrames );
275
285
}
276
286
277
- readBytes ( Sequence.m_pFrames , data_size );
278
-
279
- if (anp3)
280
- {
281
- pKeyFrames += data_size;
282
- Sequence.m_nFlags |= 8u ;
283
- }
287
+ readBytes ( pKeyFrames, data_size );
284
288
285
289
if ( !bUnknownSequence )
286
290
{
@@ -304,11 +308,11 @@ void CClientIFP::ReadIFPVersion2( bool anp3)
304
308
}
305
309
else
306
310
{
307
- insertAnimDummySequence (anp3, pAnimHierarchy, SequenceIndex);
311
+ insertAnimDummySequence ( pAnimHierarchy, SequenceIndex );
308
312
}
309
313
}
310
-
311
- *(DWORD *)pNewSequencesMemory = IFP_TOTAL_SEQUENCES + TotalUnknownSequences;
314
+
315
+ *(DWORD *)ifpAnimation. pSequencesMemory = IFP_TOTAL_SEQUENCES + TotalUnknownSequences;
312
316
313
317
// This order is very important. As we need support for all 32 bones, we must change the total sequences count
314
318
pAnimHierarchy->m_nSeqCount = IFP_TOTAL_SEQUENCES + TotalUnknownSequences;
@@ -383,12 +387,9 @@ void CClientIFP::ReadIFPVersion1 ( )
383
387
pAnimHierarchy->field_B = 0 ;
384
388
385
389
const unsigned short TotalSequences = IFP_TOTAL_SEQUENCES + pAnimHierarchy->m_nSeqCount ;
386
- char * pNewSequencesMemory = ( char * ) operator new ( 12 * TotalSequences + 4 ); // Allocate memory for sequences ( 12 * seq_count + 4 )
387
-
388
- // Okay, we have assigned the memory. We can free it when we want to
389
- ifpAnimation.pSequencesMemory = pNewSequencesMemory;
390
+ ifpAnimation.pSequencesMemory = ( char * ) operator new ( 12 * TotalSequences + 4 ); // Allocate memory for sequences ( 12 * seq_count + 4 )
390
391
391
- pAnimHierarchy->m_pSequences = ( _CAnimBlendSequence * )( pNewSequencesMemory + 4 );
392
+ pAnimHierarchy->m_pSequences = ( _CAnimBlendSequence * )( ifpAnimation. pSequencesMemory + 4 );
392
393
393
394
std::map < std::string, _CAnimBlendSequence > MapOfSequences;
394
395
@@ -496,7 +497,7 @@ void CClientIFP::ReadIFPVersion1 ( )
496
497
else if (FrameType == IFP_FrameType::KR00)
497
498
{
498
499
// ofs << " | FrameType: KR00" << std::endl;
499
- ReadKr00FramesAsCompressed ( pKeyFrames, Anim.Frames , BoneID );
500
+ ReadKr00FramesAsCompressed ( pKeyFrames, Anim.Frames );
500
501
}
501
502
502
503
if (!bUnknownSequence)
@@ -523,11 +524,11 @@ void CClientIFP::ReadIFPVersion1 ( )
523
524
}
524
525
else
525
526
{
526
- insertAnimDummySequence ( false , pAnimHierarchy, SequenceIndex );
527
+ insertAnimDummySequence ( pAnimHierarchy, SequenceIndex );
527
528
}
528
529
}
529
530
530
- *(DWORD *)pNewSequencesMemory = IFP_TOTAL_SEQUENCES + TotalUnknownSequences;
531
+ *(DWORD *)ifpAnimation. pSequencesMemory = IFP_TOTAL_SEQUENCES + TotalUnknownSequences;
531
532
532
533
// This order is very important. As we need support for all 32 bones, we must change the total sequences count
533
534
pAnimHierarchy->m_nSeqCount = IFP_TOTAL_SEQUENCES + TotalUnknownSequences;
@@ -588,7 +589,7 @@ void CClientIFP::ReadKrt0FramesAsCompressed ( BYTE * pKeyFrames, int32_t TotalF
588
589
}
589
590
}
590
591
591
- void CClientIFP::ReadKr00FramesAsCompressed ( BYTE * pKeyFrames, int32_t TotalFrames, int32_t BoneID )
592
+ void CClientIFP::ReadKr00FramesAsCompressed ( BYTE * pKeyFrames, int32_t TotalFrames )
592
593
{
593
594
for (int32_t FrameIndex = 0 ; FrameIndex < TotalFrames; FrameIndex++)
594
595
{
@@ -654,7 +655,7 @@ IFP_FrameType CClientIFP::getFrameTypeFromFourCC ( char * FourCC )
654
655
}
655
656
656
657
657
- void CClientIFP::insertAnimDummySequence ( bool anp3, _CAnimBlendHierarchy * pAnimHierarchy, size_t SequenceIndex)
658
+ void CClientIFP::insertAnimDummySequence ( _CAnimBlendHierarchy * pAnimHierarchy, size_t SequenceIndex)
658
659
{
659
660
const char * BoneName = BoneNames [SequenceIndex ];
660
661
DWORD BoneID = BoneIds [SequenceIndex];
@@ -927,11 +928,6 @@ void CClientIFP::insertAnimDummySequence ( bool anp3, _CAnimBlendHierarchy * pAn
927
928
// ofs << " ERROR: BoneID is not being handled!" << std::endl;
928
929
}
929
930
}
930
-
931
- if (anp3)
932
- {
933
- pSequence->m_nFlags |= 8u ; // EXTERNAL_KEYFRAMES_MEM;
934
- }
935
931
}
936
932
937
933
0 commit comments