Skip to content

Commit 8bbd104

Browse files
committed
Added new functions to CAnimManager for CClientIFP
1 parent 1330cb4 commit 8bbd104

File tree

6 files changed

+98
-51
lines changed

6 files changed

+98
-51
lines changed

Client/game_sa/CAnimManagerSA.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,16 @@ void CAnimManagerSA::RemoveFromUncompressedCache ( CAnimBlendHierarchy * pHierar
521521
}
522522
}
523523

524+
void CAnimManagerSA::RemoveFromUncompressedCache ( CAnimBlendHierarchySAInterface * pHierarchyInterface )
525+
{
526+
DWORD dwFunc = FUNC_CAnimManager_RemoveFromUncompressedCache;
527+
_asm
528+
{
529+
push pHierarchyInterface
530+
call dwFunc
531+
add esp, 0x4
532+
}
533+
}
524534

525535
void CAnimManagerSA::LoadAnimFile ( const char * szFile )
526536
{
@@ -568,6 +578,33 @@ void CAnimManagerSA::RemoveLastAnimFile ( void )
568578
}
569579

570580

581+
BYTE * CAnimManagerSA::AllocateKeyFramesMemory ( uint32_t u32BytesToAllocate )
582+
{
583+
BYTE * pKeyFrames = nullptr;
584+
DWORD dwFunc = FUNC_CAnimManager_AllocateKeyFramesMemory;
585+
_asm
586+
{
587+
push u32BytesToAllocate
588+
call dwFunc
589+
add esp, 0x4
590+
mov pKeyFrames, eax
591+
}
592+
return pKeyFrames;
593+
}
594+
595+
596+
void CAnimManagerSA::FreeKeyFramesMemory ( void * pKeyFrames )
597+
{
598+
DWORD dwFunc = FUNC_CAnimManager_FreeKeyFramesMemory;
599+
_asm
600+
{
601+
push pKeyFrames
602+
call dwFunc
603+
add esp, 0x4
604+
}
605+
}
606+
607+
571608
bool CAnimManagerSA::HasAnimGroupLoaded ( AssocGroupId groupID )
572609
{
573610
bool bReturn;

Client/game_sa/CAnimManagerSA.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@
5757
#define FUNC_CAnimManager_LoadAnimFile 0x4d55d0
5858
#define FUNC_CAnimManager_LoadAnimFile_stream 0x4d47f0
5959
#define FUNC_CAnimManager_LoadAnimFiles 0x4d5620
60+
#define FUNC_CAnimManager_AllocateKeyFramesMemory 0x72F420
61+
#define FUNC_CAnimManager_FreeKeyFramesMemory 0x72F430
6062
#define ARRAY_CAnimManager_AnimAssocGroups 0xb4ea34
6163
#define ARRAY_CAnimManager_Animations 0xb4ea40
6264
#define ARRAY_CAnimManager_AnimBlocks 0xb5d4a0
@@ -128,11 +130,13 @@ class CAnimManagerSA : public CAnimManager
128130

129131
void UncompressAnimation ( CAnimBlendHierarchy * pHierarchy );
130132
void RemoveFromUncompressedCache ( CAnimBlendHierarchy * pHierarchy );
131-
133+
void RemoveFromUncompressedCache ( CAnimBlendHierarchySAInterface * pInterface );
132134
void LoadAnimFile ( const char * szFile );
133135
void LoadAnimFile ( RwStream * pStream, bool b1, const char * sz1 );
134136
void LoadAnimFiles ( void );
135137
void RemoveLastAnimFile ( void );
138+
BYTE * AllocateKeyFramesMemory ( uint32_t u32BytesToAllocate );
139+
void FreeKeyFramesMemory ( void * pKeyFrames );
136140

137141
// Non members
138142
bool HasAnimGroupLoaded ( AssocGroupId groupID );

Client/mods/deathmatch/logic/CClientIFP.cpp

Lines changed: 36 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
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-
104
CClientIFP::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 ("\nCClientIFP::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

3832
bool 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 ( )
10496
void 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 >
218210
int32_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

241233
void 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 >
277269
void 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

287279
void 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

298290
void 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

306298
CClientIFP::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

313305
void 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
418410
void 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

424416
void 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

430422
size_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

770762
constexpr void CClientIFP::RoundSize ( uint32_t & u32Size )
771763
{
772-
if( u32Size & 3 )
764+
if ( u32Size & 3 )
773765
{
774766
u32Size += 4 - ( u32Size & 3 );
775767
}

Client/mods/deathmatch/logic/CClientIFP.h

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
#define __CCLIENTIFP_H
55

66
#include "CClientEntity.h"
7-
#include "IFP/IFPLoader.h"
8-
#include "IFP/CIFPAnimations.h"
7+
#include "CFileReader.h"
8+
#include "CIFPAnimations.h"
99
#include <algorithm>
1010

11-
class CClientIFP: public CClientEntity, FileLoader
11+
class CClientIFP: public CClientEntity, CFileReader
1212
{
1313
public:
1414
typedef CIFPAnimations::IFP_Animation IFP_Animation;
@@ -206,7 +206,7 @@ class CClientIFP: public CClientEntity, FileLoader
206206
virtual eClientEntityType GetType ( void ) const { return CCLIENTIFP; }
207207

208208
const SString & GetBlockName ( void ) { return m_strBlockName; }
209-
bool LoadIFP ( const char* szFilePath, SString strBlockName );
209+
bool LoadIFP ( const char* szFilePath, const SString & strBlockName );
210210

211211
bool LoadIFPFile ( const char * szFilePath );
212212
void ReadIFPVersion1 ( void );
@@ -246,7 +246,7 @@ class CClientIFP: public CClientEntity, FileLoader
246246
constexpr void RoundSize ( uint32_t & u32Size );
247247
constexpr bool IsKeyFramesTypeRoot ( IFP_FrameType iFrameType );
248248

249-
IFP_FrameType GetFrameTypeFromFourCC ( char * FourCC );
249+
IFP_FrameType GetFrameTypeFromFourCC ( const char * szFourCC );
250250
size_t GetSizeOfCompressedFrame ( IFP_FrameType FrameType );
251251
int32_t GetBoneIDFromName ( std::string const& BoneName );
252252
std::string GetCorrectBoneNameFromName ( std::string const& BoneName );
@@ -274,6 +274,16 @@ class CClientIFP: public CClientEntity, FileLoader
274274
// them, when it's going to play the animation. We don't need to worry about it.
275275
const bool m_kbAllKeyFramesCompressed = true;
276276

277+
const DWORD m_karruBoneIds [ 32 ] =
278+
{
279+
0, 1, 2, 3, 4, 5, 8, 6, 7, 31, 32, 33, 34, 35, 36, 21, 22, 23, 24, 25, 26, 302, 301, 201, 41, 42, 43, 44, 51, 52, 53, 54
280+
};
281+
const char m_karrstrBoneNames [ 32 ] [ 24 ] =
282+
{
283+
"Normal", "Pelvis", "Spine", "Spine1", "Neck", "Head", "Jaw", "L Brow", "R Brow", "Bip01 L Clavicle", "L UpperArm",
284+
"L ForeArm", "L Hand", "L Finger", "L Finger01", "Bip01 R Clavicle", "R UpperArm", "R ForeArm", "R Hand", "R Finger",
285+
"R Finger01", "L breast", "R breast", "Belly", "L Thigh", "L Calf", "L Foot", "L Toe0", "R Thigh", "R Calf", "R Foot", "R Toe0"
286+
};
277287
};
278288

279289
#endif

Client/mods/deathmatch/logic/CClientPed.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6222,9 +6222,10 @@ void CClientPed::RestoreAnimations ( CAnimBlock & animationBlock )
62226222
{
62236223
const CAnimBlockSAInterface * pInternalBlockInterface = animationBlock.GetInterface ( );
62246224
DWORD iAnimationIndex = pInternalBlockInterface->idOffset;
6225+
DWORD dwARRAY_CAnimManager_Animations = 0xb4ea40;
62256226
for ( size_t i = 0; i < pInternalBlockInterface->nAnimations; i++ )
62266227
{
6227-
auto pAnimHierarchyInterface = (CAnimBlendHierarchySAInterface*)((BYTE*)ARRAY_CAnimManager_Animations + sizeof(CAnimBlendHierarchySAInterface) * iAnimationIndex);
6228+
auto pAnimHierarchyInterface = (CAnimBlendHierarchySAInterface*)((BYTE*)dwARRAY_CAnimManager_Animations + sizeof(CAnimBlendHierarchySAInterface) * iAnimationIndex);
62286229
m_mapOfReplacedAnimations.erase ( pAnimHierarchyInterface );
62296230
iAnimationIndex ++;
62306231
}

0 commit comments

Comments
 (0)