|
5 | 5 | #include <../game_sa/CAnimBlendAssociationSA.h>
|
6 | 6 | #include <../game_sa/CAnimBlendAssocGroupSA.h>
|
7 | 7 |
|
| 8 | +typedef std::map < CAnimBlendAssociationSAInterface *, SIFPAnimations * > AnimAssociations_type; |
| 9 | +static AnimAssociations_type mapOfCustomAnimationAssociations; |
| 10 | + |
8 | 11 | DWORD FUNC_NEW_OPERATOR = 0x082119A;
|
9 | 12 | DWORD FUNC_CAnimBlendAssociation_Constructor = 0x04CF080;
|
10 | 13 |
|
@@ -57,6 +60,30 @@ void CMultiplayerSA::SetBlendAnimationHierarchyHandler ( BlendAnimationHierarchy
|
57 | 60 | m_pBlendAnimationHierarchyHandler = pHandler;
|
58 | 61 | }
|
59 | 62 |
|
| 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 | + |
60 | 87 | void _declspec(naked) HOOK_CAnimBlendAssoc_Hierarchy_Constructor ()
|
61 | 88 | {
|
62 | 89 | _asm
|
@@ -94,30 +121,21 @@ void _declspec(naked) HOOK_CAnimBlendAssoc_Hierarchy_Constructor ()
|
94 | 121 | }
|
95 | 122 | }
|
96 | 123 |
|
97 |
| -void _declspec(naked) HOOK_CAnimBlendAssoc_destructor () |
| 124 | +void CAnimBlendAssoc_destructor ( CAnimBlendAssociationSAInterface * pThis ) |
98 | 125 | {
|
99 |
| - _asm |
100 |
| - { |
101 |
| - pushad |
102 |
| - } |
103 |
| - |
104 | 126 | if ( m_pCAnimBlendAssocDestructorHandler )
|
105 | 127 | {
|
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 ); |
115 | 129 | }
|
| 130 | +} |
116 | 131 |
|
| 132 | +void _declspec(naked) HOOK_CAnimBlendAssoc_destructor () |
| 133 | +{ |
117 | 134 | _asm
|
118 | 135 | {
|
119 |
| - NORMAL_FLOW_CAnimBlendAssoc_destructor: |
120 |
| - popad |
| 136 | + push ecx // this |
| 137 | + call CAnimBlendAssoc_destructor |
| 138 | + pop ecx |
121 | 139 | push esi
|
122 | 140 | mov esi, ecx
|
123 | 141 | mov eax, [esi+10h]
|
@@ -178,8 +196,8 @@ void _declspec(naked) HOOK_CAnimBlendAssocGroup_CopyAnimation ()
|
178 | 196 |
|
179 | 197 | // save eax and ecx for later to check whether current animation is custom or not
|
180 | 198 | // after calling FUNC_CAnimBlendAssociation_Constructor function
|
181 |
| - push eax |
182 |
| - push ecx |
| 199 | + push eax // isCustomAnimation ( bool ) |
| 200 | + push ecx // pIFPAnimations |
183 | 201 |
|
184 | 202 | // get "this" from stack that we pushed first
|
185 | 203 | mov ecx, [esp+8]
|
@@ -212,26 +230,31 @@ void _declspec(naked) HOOK_CAnimBlendAssocGroup_CopyAnimation ()
|
212 | 230 | call DeleteStaticAssociation
|
213 | 231 | add esp, 4
|
214 | 232 |
|
215 |
| - pop ecx |
216 |
| - pop eax |
| 233 | + mov ecx, [esp+4] // pIFPAnimations |
| 234 | + mov eax, [esp+8] // pAnimAssociation |
217 | 235 |
|
218 | 236 | // Check wether this is a custom animation or not
|
219 |
| - cmp al, 0 |
| 237 | + cmp eax, 00 |
220 | 238 | je NOT_CUSTOM_ANIMATION_CopyAnimation
|
221 | 239 |
|
222 | 240 | // 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 | + |
224 | 246 | NOT_CUSTOM_ANIMATION_CopyAnimation:
|
225 | 247 | // put CAnimBlendAssociation in eax
|
226 | 248 | mov eax, edi
|
227 |
| - add esp, 4 |
| 249 | + add esp, 0Ch |
228 | 250 | jmp RETURN_CAnimBlendAssocGroup_CopyAnimation
|
229 | 251 |
|
230 | 252 | ERROR_CopyAnimation:
|
231 |
| - // Delete our static association first |
| 253 | + add esp, 0Ch |
| 254 | + // Delete our static association |
232 | 255 | push edi
|
233 | 256 | call DeleteStaticAssociation
|
234 |
| - add esp, 4 |
| 257 | + add esp, 4 |
235 | 258 | jmp RETURN_CAnimBlendAssocGroup_CopyAnimation_ERROR
|
236 | 259 | }
|
237 | 260 | }
|
|
0 commit comments