Skip to content

Commit 1dfadb5

Browse files
authored
Merge pull request #6 from saml1er/custom_ifp_animations
Custom ifp animations ( Improved Code Design )
2 parents f4d1c55 + 8bbd104 commit 1dfadb5

33 files changed

+1348
-2004
lines changed

Client/game_sa/CAnimBlendHierarchySA.cpp

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,81 @@
1212

1313
#include "StdInc.h"
1414

15+
// Careful, GetIndex will not work for custom animations
1516
int CAnimBlendHierarchySAInterface::GetIndex ( void )
1617
{
1718
return ( ( ( DWORD ) this - ARRAY_CAnimManager_Animations ) / 24 );
1819
}
20+
21+
void CAnimBlendHierarchySA::Initialize ( void )
22+
{
23+
m_pInterface->pSequences = 0;
24+
m_pInterface->usNumSequences = 0;
25+
m_pInterface->bRunningCompressed = 0;
26+
m_pInterface->pad = 0;
27+
m_pInterface->iAnimBlockID = -1;
28+
m_pInterface->fTotalTime = 0;
29+
m_pInterface->pLinkPtr = 0;
30+
}
31+
32+
void CAnimBlendHierarchySA::SetName ( const char * szName )
33+
{
34+
DWORD dwThis = ( DWORD ) m_pInterface;
35+
DWORD dwFunc = FUNC_CAnimBlendHierarchy_SetName;
36+
_asm
37+
{
38+
push szName
39+
mov ecx, dwThis
40+
call dwFunc
41+
}
42+
}
43+
44+
void CAnimBlendHierarchySA::RemoveAnimSequences ( void )
45+
{
46+
DWORD dwThis = ( DWORD ) m_pInterface;
47+
DWORD dwFunc = FUNC_CAnimBlendHierarchy_RemoveAnimSequences;
48+
_asm
49+
{
50+
mov ecx, dwThis
51+
call dwFunc
52+
}
53+
}
54+
55+
void CAnimBlendHierarchySA::RemoveFromUncompressedCache ( void )
56+
{
57+
DWORD dwThis = ( DWORD ) m_pInterface;
58+
DWORD dwFunc = FUNC_CAnimBlendHierarchy_RemoveFromUncompressedCache;
59+
_asm
60+
{
61+
mov ecx, dwThis
62+
call dwFunc
63+
}
64+
}
65+
66+
void CAnimBlendHierarchySA::RemoveQuaternionFlips ( void )
67+
{
68+
DWORD dwThis = ( DWORD ) m_pInterface;
69+
DWORD dwFunc = FUNC_CAnimBlendHierarchy_RemoveQuaternionFlips;
70+
_asm
71+
{
72+
mov ecx, dwThis
73+
call dwFunc
74+
}
75+
}
76+
77+
void CAnimBlendHierarchySA::CalculateTotalTime ( void )
78+
{
79+
DWORD dwThis = ( DWORD ) m_pInterface;
80+
DWORD dwFunc = FUNC_CAnimBlendHierarchy_CalculateTotalTime;
81+
_asm
82+
{
83+
mov ecx, dwThis
84+
call dwFunc
85+
}
86+
}
87+
88+
CAnimBlendSequenceSAInterface * CAnimBlendHierarchySA::GetSequence ( DWORD dwIndex )
89+
{
90+
BYTE * pSequences = reinterpret_cast < BYTE * > ( m_pInterface->pSequences );
91+
return reinterpret_cast < CAnimBlendSequenceSAInterface * > ( pSequences + ( sizeof ( CAnimBlendSequenceSAInterface ) * dwIndex ) );
92+
}

Client/game_sa/CAnimBlendHierarchySA.h

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,24 @@
1818
#include <game/CAnimBlendHierarchy.h>
1919
#include "Common.h"
2020

21-
#define FUNC_CAnimBlendHierarchy_GetAnimSequence 0x4ce8f0
22-
#define FUNC_CAnimBlendHierarchy_GetAnimSequences 0x4d1350
21+
#define FUNC_CAnimBlendHierarchy_SetName 0x4CF2D0
22+
#define FUNC_CAnimBlendHierarchy_RemoveAnimSequences 0x4CF8E0
23+
#define FUNC_CAnimBlendHierarchy_RemoveFromUncompressedCache 0x4D42A0
24+
#define FUNC_CAnimBlendHierarchy_RemoveQuaternionFlips 0x4CF4E0
25+
#define FUNC_CAnimBlendHierarchy_CalculateTotalTime 0x4CF2F0
26+
#define FUNC_CAnimBlendHierarchy_GetAnimSequence 0x4ce8f0
27+
#define FUNC_CAnimBlendHierarchy_GetAnimSequences 0x4d1350
2328

2429
class CAnimBlendSequence;
2530

2631
class CAnimBlendHierarchySAInterface
2732
{
2833
public:
34+
// Careful, GetIndex will not work for custom animations
2935
int GetIndex ( void );
36+
3037
unsigned int iHashKey;
31-
DWORD * pSequences;
38+
CAnimBlendSequenceSAInterface * pSequences;
3239
unsigned short usNumSequences;
3340
bool bRunningCompressed;
3441
BYTE pad;
@@ -41,10 +48,23 @@ class CAnimBlendHierarchySAInterface
4148
class CAnimBlendHierarchySA : public CAnimBlendHierarchy
4249
{
4350
public:
44-
CAnimBlendHierarchySA ( CAnimBlendHierarchySAInterface * pInterface ) { m_pInterface = pInterface; }
45-
46-
CAnimBlendHierarchySAInterface * GetInterface ( void ) { return m_pInterface; }
47-
int GetAnimBlockID ( void ) { return m_pInterface->iAnimBlockID; }
51+
CAnimBlendHierarchySA ( CAnimBlendHierarchySAInterface * pInterface ) { m_pInterface = pInterface; }
52+
void Initialize ( void );
53+
void SetName ( const char * szName );
54+
void SetSequences ( CAnimBlendSequenceSAInterface * pSequences ) { m_pInterface->pSequences = pSequences; }
55+
void SetNumSequences ( unsigned short uNumSequences ) { m_pInterface->usNumSequences = uNumSequences; }
56+
void SetRunningCompressed ( bool bCompressed ) { m_pInterface->bRunningCompressed = bCompressed; }
57+
void SetAnimationBlockID ( int iBlockID ) { m_pInterface->iAnimBlockID = iBlockID; }
58+
void RemoveAnimSequences ( void );
59+
void RemoveFromUncompressedCache ( void );
60+
void RemoveQuaternionFlips ( void );
61+
void CalculateTotalTime ( void );
62+
CAnimBlendSequenceSAInterface * GetSequence ( DWORD dwIndex );
63+
CAnimBlendSequenceSAInterface * GetSequences ( void ) { return m_pInterface->pSequences; }
64+
unsigned short GetNumSequences ( void ) { return m_pInterface->usNumSequences; }
65+
bool isRunningCompressed ( void ) { return m_pInterface->bRunningCompressed; }
66+
int GetAnimBlockID ( void ) { return m_pInterface->iAnimBlockID; }
67+
CAnimBlendHierarchySAInterface * GetInterface ( void ) { return m_pInterface; }
4868

4969
protected:
5070
CAnimBlendHierarchySAInterface * m_pInterface;

Client/game_sa/CAnimBlendSequenceSA.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,50 @@
1111
*****************************************************************************/
1212

1313
#include "StdInc.h"
14+
15+
void CAnimBlendSequenceSA::Initialize ( void )
16+
{
17+
m_pInterface->m_boneId = -1;
18+
m_pInterface->sFlags = 0;
19+
m_pInterface->sNumKeyFrames = 0;
20+
m_pInterface->pKeyFrames = 0;
21+
}
22+
23+
void CAnimBlendSequenceSA::SetName ( const char * szName )
24+
{
25+
DWORD dwThis = ( DWORD ) m_pInterface;
26+
DWORD dwFunc = FUNC_CAnimBlendSequence_SetName;
27+
_asm
28+
{
29+
push szName
30+
mov ecx, dwThis
31+
call dwFunc
32+
}
33+
}
34+
35+
void CAnimBlendSequenceSA::SetBoneTag ( int32_t i32BoneID )
36+
{
37+
DWORD dwThis = ( DWORD ) m_pInterface;
38+
DWORD dwFunc = FUNC_CAnimBlendSequence_SetBoneTag;
39+
_asm
40+
{
41+
push i32BoneID
42+
mov ecx, dwThis
43+
call dwFunc
44+
}
45+
}
46+
47+
void CAnimBlendSequenceSA::SetKeyFrames ( size_t cKeyFrames, bool bRoot, bool bCompressed, void * pKeyFrames )
48+
{
49+
DWORD dwThis = ( DWORD ) m_pInterface;
50+
DWORD dwFunc = FUNC_CAnimBlendSequence_SetKeyFrames;
51+
_asm
52+
{
53+
push pKeyFrames
54+
push bCompressed
55+
push bRoot
56+
push cKeyFrames
57+
mov ecx, dwThis
58+
call dwFunc
59+
}
60+
}

Client/game_sa/CAnimBlendSequenceSA.h

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,36 @@
1515

1616
#include <game/CAnimBlendSequence.h>
1717

18+
#define FUNC_CAnimBlendSequence_SetName 0x4D0C50
19+
#define FUNC_CAnimBlendSequence_SetBoneTag 0x4D0C70
20+
#define FUNC_CAnimBlendSequence_SetKeyFrames 0x4D0CD0
21+
1822
class CAnimBlendSequenceSAInterface
1923
{
2024
public:
21-
unsigned int iHashKey; // Get/SetBoneTag accesses the first? 2 bytes here
22-
short sFlags; // 4 // or16=bHasBoneTag
23-
short sNumKeyFrames; // 6
24-
class CAnimBlendKeyFrame * pKeyFrames; // ?
25+
union
26+
{
27+
uint16_t m_boneId; // m_boneId is set if ( sFlags & 0x10u ) is true
28+
uint32_t m_hash; // otherwise m_hash is set
29+
};
30+
unsigned short sFlags;
31+
unsigned short sNumKeyFrames;
32+
void * pKeyFrames;
2533
};
2634

2735
class CAnimBlendSequenceSA : public CAnimBlendSequence
2836
{
2937
public:
30-
CAnimBlendSequenceSA ( CAnimBlendSequenceSAInterface * pInterface ) { m_pInterface = pInterface; }
38+
CAnimBlendSequenceSA ( CAnimBlendSequenceSAInterface * pInterface ) { m_pInterface = pInterface; }
39+
void Initialize ( void );
40+
void SetName ( const char * szName );
41+
void SetBoneTag ( int32_t i32BoneID );
42+
void SetKeyFrames ( size_t cKeyFrames, bool bRoot, bool bCompressed, void * pKeyFrames );
43+
uint32_t GetHash ( void ) { return m_pInterface->m_hash; }
44+
uint16_t GetBoneTag ( void ) { return m_pInterface->m_boneId; }
45+
void * GetKeyFrames ( void ) { return m_pInterface->pKeyFrames; }
46+
unsigned short GetKeyFramesCount ( void ) { return m_pInterface->sNumKeyFrames; }
47+
CAnimBlendSequenceSAInterface * GetInterface ( void ) { return m_pInterface; }
3148

3249
protected:
3350
CAnimBlendSequenceSAInterface * m_pInterface;

Client/game_sa/CAnimManagerSA.cpp

Lines changed: 48 additions & 1 deletion
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;
@@ -760,7 +797,17 @@ CAnimBlendHierarchy * CAnimManagerSA::GetAnimBlendHierarchy ( CAnimBlendHierarch
760797
}
761798
return NULL;
762799
}
763-
800+
801+
std::unique_ptr < CAnimBlendHierarchy > CAnimManagerSA::GetCustomAnimBlendHierarchy ( CAnimBlendHierarchySAInterface * pInterface )
802+
{
803+
return std::make_unique < CAnimBlendHierarchySA > ( pInterface );
804+
}
805+
806+
std::unique_ptr < CAnimBlendSequence > CAnimManagerSA::GetCustomAnimBlendSequence ( CAnimBlendSequenceSAInterface * pInterface )
807+
{
808+
return std::make_unique < CAnimBlendSequenceSA > ( pInterface );
809+
}
810+
764811
bool CAnimManagerSA::isGateWayAnimationHierarchy ( CAnimBlendHierarchySAInterface * pInterface )
765812
{
766813
return pGame->GetKeyGen()->GetUppercaseKey ( m_kGateWayAnimationName.c_str ( ) ) == pInterface->iHashKey;

Client/game_sa/CAnimManagerSA.h

Lines changed: 10 additions & 2 deletions
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 );
@@ -149,7 +153,11 @@ class CAnimManagerSA : public CAnimManager
149153
CAnimBlendAssocGroup * GetAnimBlendAssocGroup ( CAnimBlendAssocGroupSAInterface * pInterface );
150154
CAnimBlock * GetAnimBlock ( CAnimBlockSAInterface * pInterface );
151155
CAnimBlendHierarchy * GetAnimBlendHierarchy ( CAnimBlendHierarchySAInterface * pInterface );
152-
156+
157+
// MTA members, but use this strictly for custom animations only
158+
std::unique_ptr < CAnimBlendHierarchy > GetCustomAnimBlendHierarchy ( CAnimBlendHierarchySAInterface * pInterface );
159+
std::unique_ptr < CAnimBlendSequence > GetCustomAnimBlendSequence ( CAnimBlendSequenceSAInterface * pInterface );
160+
153161
bool isGateWayAnimationHierarchy ( CAnimBlendHierarchySAInterface * pInterface );
154162
const SString & GetGateWayBlockName ( void );
155163
const SString & GetGateWayAnimationName ( void );

Client/mods/deathmatch/logic/CClientEntity.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class CClientManager;
4343
#define IS_COLSHAPE(entity) ((entity)->GetType()==CCLIENTCOLSHAPE)
4444
#define IS_PROJECTILE(entity) ((entity)->GetType()==CCLIENTPROJECTILE)
4545
#define IS_GUI(entity) ((entity)->GetType()==CCLIENTGUI)
46+
#define IS_IFP(entity) ((entity)->GetType()==CCLIENTIFP)
4647
#define CHECK_CGUI(entity,type) (((CClientGUIElement*)entity)->GetCGUIElement()->GetType()==type)
4748

4849
enum eClientEntityType

0 commit comments

Comments
 (0)