Skip to content

Commit 47ea233

Browse files
committed
Fixed CopyAnim hook and added mapOfCustomAnimationAssociations and its functions.
1 parent fee333b commit 47ea233

File tree

1 file changed

+49
-26
lines changed

1 file changed

+49
-26
lines changed

Client/multiplayer_sa/CMultiplayerSA_CustomAnimations.cpp

Lines changed: 49 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
#include <../game_sa/CAnimBlendAssociationSA.h>
66
#include <../game_sa/CAnimBlendAssocGroupSA.h>
77

8+
typedef std::map < CAnimBlendAssociationSAInterface *, SIFPAnimations * > AnimAssociations_type;
9+
static AnimAssociations_type mapOfCustomAnimationAssociations;
10+
811
DWORD FUNC_NEW_OPERATOR = 0x082119A;
912
DWORD FUNC_CAnimBlendAssociation_Constructor = 0x04CF080;
1013

@@ -57,6 +60,30 @@ void CMultiplayerSA::SetBlendAnimationHierarchyHandler ( BlendAnimationHierarchy
5760
m_pBlendAnimationHierarchyHandler = pHandler;
5861
}
5962

63+
void InsertAnimationAssociationToMap ( CAnimBlendAssociationSAInterface * pAnimAssociation, SIFPAnimations * pIFPAnimations )
64+
{
65+
// We don't increment pIFPAnimations->iReferences here because it's done
66+
// in custom animation handler functions in CClientGame.cpp
67+
//mapOfCustomAnimationAssociations [ pAnimAssociation ] = pIFPAnimations;
68+
//printf("InsertAnimationAssociationToMap: sAnimID: %d | iReferences: %d \n", pAnimAssociation->sAnimID, pIFPAnimations->iReferences);
69+
}
70+
71+
void RemoveAnimationAssociationFromMap ( CAnimBlendAssociationSAInterface * pAnimAssociation )
72+
{
73+
AnimAssociations_type::iterator it;
74+
it = mapOfCustomAnimationAssociations.find ( pAnimAssociation );
75+
if ( it != mapOfCustomAnimationAssociations.end ( ) )
76+
{
77+
it->second->iReferences --;
78+
if ( ( it->second->bUnloadOnZeroReferences == true ) && ( it->second->iReferences == 0 ) )
79+
{
80+
// iReferences are zero, custom animation hierarchies are not being used anywhere.
81+
// It's safe to unload IFP animations here.
82+
}
83+
mapOfCustomAnimationAssociations.erase ( pAnimAssociation );
84+
}
85+
}
86+
6087
void _declspec(naked) HOOK_CAnimBlendAssoc_Hierarchy_Constructor ()
6188
{
6289
_asm
@@ -94,30 +121,21 @@ void _declspec(naked) HOOK_CAnimBlendAssoc_Hierarchy_Constructor ()
94121
}
95122
}
96123

97-
void _declspec(naked) HOOK_CAnimBlendAssoc_destructor ()
124+
void CAnimBlendAssoc_destructor ( CAnimBlendAssociationSAInterface * pThis )
98125
{
99-
_asm
100-
{
101-
pushad
102-
}
103-
104126
if ( m_pCAnimBlendAssocDestructorHandler )
105127
{
106-
_asm
107-
{
108-
popad
109-
push ecx // this
110-
call m_pCAnimBlendAssocDestructorHandler
111-
pop ecx
112-
pushad
113-
jmp NORMAL_FLOW_CAnimBlendAssoc_destructor
114-
}
128+
m_pCAnimBlendAssocDestructorHandler ( pThis );
115129
}
130+
}
116131

132+
void _declspec(naked) HOOK_CAnimBlendAssoc_destructor ()
133+
{
117134
_asm
118135
{
119-
NORMAL_FLOW_CAnimBlendAssoc_destructor:
120-
popad
136+
push ecx // this
137+
call CAnimBlendAssoc_destructor
138+
pop ecx
121139
push esi
122140
mov esi, ecx
123141
mov eax, [esi+10h]
@@ -178,8 +196,8 @@ void _declspec(naked) HOOK_CAnimBlendAssocGroup_CopyAnimation ()
178196

179197
// save eax and ecx for later to check whether current animation is custom or not
180198
// after calling FUNC_CAnimBlendAssociation_Constructor function
181-
push eax
182-
push ecx
199+
push eax // isCustomAnimation ( bool )
200+
push ecx // pIFPAnimations
183201

184202
// get "this" from stack that we pushed first
185203
mov ecx, [esp+8]
@@ -212,26 +230,31 @@ void _declspec(naked) HOOK_CAnimBlendAssocGroup_CopyAnimation ()
212230
call DeleteStaticAssociation
213231
add esp, 4
214232

215-
pop ecx
216-
pop eax
233+
mov ecx, [esp+4] // pIFPAnimations
234+
mov eax, [esp+8] // pAnimAssociation
217235

218236
// Check wether this is a custom animation or not
219-
cmp al, 0
237+
cmp eax, 00
220238
je NOT_CUSTOM_ANIMATION_CopyAnimation
221239

222240
// It's a custom animation, store it in a map
223-
241+
push ecx // pIFPAnimations
242+
push edi // pAnimAssociation
243+
call InsertAnimationAssociationToMap
244+
add esp, 8
245+
224246
NOT_CUSTOM_ANIMATION_CopyAnimation:
225247
// put CAnimBlendAssociation in eax
226248
mov eax, edi
227-
add esp, 4
249+
add esp, 0Ch
228250
jmp RETURN_CAnimBlendAssocGroup_CopyAnimation
229251

230252
ERROR_CopyAnimation:
231-
// Delete our static association first
253+
add esp, 0Ch
254+
// Delete our static association
232255
push edi
233256
call DeleteStaticAssociation
234-
add esp, 4
257+
add esp, 4
235258
jmp RETURN_CAnimBlendAssocGroup_CopyAnimation_ERROR
236259
}
237260
}

0 commit comments

Comments
 (0)