Skip to content

Commit 90ba044

Browse files
committed
Improved custom animation hooks for readability
Rewrote HOOK_CAnimBlendAssocGroup_CopyAnimation in C++ for more clarity, it is shorter now, and thus more readable. Moved HOOK_CAnimBlendAssoc_destructor to CMultiplayerSA_HookDestructors.cpp
1 parent db75cd6 commit 90ba044

File tree

4 files changed

+68
-118
lines changed

4 files changed

+68
-118
lines changed

Client/game_sa/CAnimBlendAssociationSA.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ class CAnimBlendAssociationSAInterface
3535
short sAnimID; // 44
3636
short sFlags; // or1 = started?, or64 = referenced? // 46
3737
DWORD* pCallback; // 48
38+
DWORD* pCallbackFunc; // 52
39+
DWORD* pCallbackData; // 56
40+
// Total: 60 bytes
3841
};
3942

4043
class CAnimBlendAssociationSA : public CAnimBlendAssociation

Client/multiplayer_sa/CMultiplayerSA.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121

2222
#include "CRemoteDataSA.h"
2323

24-
typedef void(__thiscall* hCAnimBlendStaticAssociation_FreeSequenceArray)(CAnimBlendStaticAssociationSAInterface* pThis);
25-
2624
class CRemoteDataSA;
2725
#define DEFAULT_NEAR_CLIP_DISTANCE ( 0.3f )
2826

@@ -42,6 +40,13 @@ enum eRadioStationID
4240
WCTR,
4341
};
4442

43+
typedef void(__thiscall* hCAnimBlendStaticAssociation_FreeSequenceArray)(CAnimBlendStaticAssociationSAInterface* pThis);
44+
typedef void(__cdecl * hUncompressAnimation) (CAnimBlendHierarchySAInterface * pAnimBlendHierarchyInterface);
45+
typedef void *(__cdecl * hCAnimBlendAssociation_NewOperator) (size_t iSizeInBytes);
46+
47+
typedef CAnimBlendAssociationSAInterface * (__thiscall * hCAnimBlendAssociation_Constructor_staticAssocByReference)
48+
(CAnimBlendAssociationSAInterface * pThis, CAnimBlendStaticAssociationSAInterface& StaticAssociationByReference);
49+
4550
class CMultiplayerSA : public CMultiplayer
4651
{
4752
friend class COffsetsMP;

Client/multiplayer_sa/CMultiplayerSA_CustomAnimations.cpp

Lines changed: 24 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,28 @@
55
#include <../game_sa/CAnimBlendAssociationSA.h>
66
#include <../game_sa/CAnimBlendAssocGroupSA.h>
77

8-
DWORD FUNC_NEW_OPERATOR = 0x082119A;
9-
DWORD FUNC_CAnimBlendAssociation_Constructor = 0x04CF080;
108
DWORD FUNC_CAnimBlendAssociation__ReferenceAnimBlock = 0x4CEA50;
119
DWORD FUNC_UncompressAnimation = 0x4D41C0;
1210
DWORD FUNC_CAnimBlendAssociation__CAnimBlendAssociation_hierarchy = 0x4CEFC0;
1311

14-
DWORD RETURN_CAnimBlendAssoc_destructor = 0x4CECF6;
1512
DWORD RETURN_CAnimBlendAssocGroup_CopyAnimation_NORMALFLOW = 0x4CE151;
1613
DWORD RETURN_CAnimBlendAssocGroup_CopyAnimation = 0x4CE187;
1714
DWORD RETURN_CAnimBlendAssocGroup_CopyAnimation_ERROR = 0x4CE199;
1815
DWORD RETURN_CAnimManager_AddAnimation = 0x4D3AB1;
1916
DWORD RETURN_CAnimManager_AddAnimationAndSync = 0x4D3B41;
2017
DWORD RETURN_CAnimManager_BlendAnimation_Hierarchy = 0x4D4577;
2118

22-
CAnimBlendAssocDestructorHandler* m_pCAnimBlendAssocDestructorHandler = nullptr;
19+
auto CAnimBlendStaticAssociation_FreeSequenceArray = (hCAnimBlendStaticAssociation_FreeSequenceArray)0x4ce9a0;
20+
auto UncompressAnimation = (hUncompressAnimation)0x4d41c0;
21+
auto CAnimBlendAssociation_NewOperator = (hCAnimBlendAssociation_NewOperator)0x082119A;
22+
auto CAnimBlendAssociation_Constructor_staticAssocByReference = (hCAnimBlendAssociation_Constructor_staticAssocByReference)0x4CF080;
23+
2324
AddAnimationHandler* m_pAddAnimationHandler = nullptr;
2425
AddAnimationAndSyncHandler* m_pAddAnimationAndSyncHandler = nullptr;
2526
AssocGroupCopyAnimationHandler* m_pAssocGroupCopyAnimationHandler = nullptr;
2627
BlendAnimationHierarchyHandler* m_pBlendAnimationHierarchyHandler = nullptr;
2728

2829
int _cdecl OnCAnimBlendAssocGroupCopyAnimation(AssocGroupId animGroup, int iAnimId);
29-
auto CAnimBlendStaticAssociation_FreeSequenceArray = (hCAnimBlendStaticAssociation_FreeSequenceArray)0x4ce9a0;
30-
31-
void CMultiplayerSA::SetCAnimBlendAssocDestructorHandler(CAnimBlendAssocDestructorHandler* pHandler)
32-
{
33-
m_pCAnimBlendAssocDestructorHandler = pHandler;
34-
}
3530

3631
void CMultiplayerSA::SetAddAnimationHandler(AddAnimationHandler* pHandler)
3732
{
@@ -53,42 +48,22 @@ void CMultiplayerSA::SetBlendAnimationHierarchyHandler(BlendAnimationHierarchyHa
5348
m_pBlendAnimationHierarchyHandler = pHandler;
5449
}
5550

56-
void __cdecl CAnimBlendAssoc_destructor(CAnimBlendAssociationSAInterface* pThis)
57-
{
58-
if (m_pCAnimBlendAssocDestructorHandler)
59-
{
60-
m_pCAnimBlendAssocDestructorHandler(pThis);
61-
}
62-
}
63-
64-
void _declspec(naked) HOOK_CAnimBlendAssoc_destructor()
51+
CAnimBlendAssociationSAInterface * __cdecl CAnimBlendAssocGroup_CopyAnimation ( RpClump* pClump, CAnimBlendAssocGroupSAInterface* pAnimAssocGroupInterface, AnimationId animID )
6552
{
66-
_asm
67-
{
68-
push ecx
53+
auto pAnimAssociationInterface = reinterpret_cast < CAnimBlendAssociationSAInterface * > (CAnimBlendAssociation_NewOperator ( sizeof (CAnimBlendAssociationSAInterface)));
54+
if (pAnimAssociationInterface)
55+
{
56+
CAnimBlendStaticAssociationSAInterface staticAnimAssociationInterface;
6957

70-
push ecx
71-
call CAnimBlendAssoc_destructor
72-
add esp, 0x4
58+
m_pAssocGroupCopyAnimationHandler(&staticAnimAssociationInterface, pAnimAssociationInterface, pClump, pAnimAssocGroupInterface, animID);
7359

74-
pop ecx
60+
UncompressAnimation(staticAnimAssociationInterface.pAnimHeirarchy);
7561

76-
push esi
77-
mov esi, ecx
78-
mov eax, [esi+10h]
79-
jmp RETURN_CAnimBlendAssoc_destructor
80-
}
81-
}
62+
CAnimBlendAssociation_Constructor_staticAssocByReference(pAnimAssociationInterface, staticAnimAssociationInterface);
8263

83-
CAnimBlendStaticAssociationSAInterface* __cdecl AllocateStaticAssociationMemory(void)
84-
{
85-
return new CAnimBlendStaticAssociationSAInterface;
86-
}
87-
88-
void __cdecl DeleteStaticAssociation(CAnimBlendStaticAssociationSAInterface* pAnimStaticAssoc)
89-
{
90-
CAnimBlendStaticAssociation_FreeSequenceArray(pAnimStaticAssoc);
91-
delete pAnimStaticAssoc;
64+
CAnimBlendStaticAssociation_FreeSequenceArray(&staticAnimAssociationInterface);
65+
}
66+
return pAnimAssociationInterface;
9267
}
9368

9469
void _declspec(naked) HOOK_CAnimBlendAssocGroup_CopyAnimation()
@@ -104,88 +79,21 @@ void _declspec(naked) HOOK_CAnimBlendAssocGroup_CopyAnimation()
10479
{
10580
popad
10681

107-
push ecx
108-
push ebp
109-
mov ebp, esp
110-
sub esp, 4
111-
112-
push eax
113-
push ecx
114-
push edi
115-
116-
// create CAnimBlendAssociation
117-
push 3Ch
118-
call FUNC_NEW_OPERATOR
119-
add esp, 4
120-
121-
mov [ebp-4], eax
122-
push eax
123-
124-
// Allocate memory for our new static association
125-
call AllocateStaticAssociationMemory
126-
mov edi, eax
127-
128-
// push the static association
129-
push edi
130-
call m_pAssocGroupCopyAnimationHandler //CAnimBlendAssocGroup_CopyAnimation
131-
add esp, 14h
82+
push esi
13283

133-
mov ecx, [ebp-4]
84+
push eax // animID
85+
push ecx // pAnimAssocGroupInterface
86+
push edi // pClump
87+
call CAnimBlendAssocGroup_CopyAnimation
88+
add esp, 0Ch
13489

135-
add esp, 4 // remove space for local var
136-
mov esp, ebp
137-
pop ebp
138-
139-
// save eax and ecx for later to check whether current animation is custom or not
140-
// after calling FUNC_CAnimBlendAssociation_Constructor function
141-
push eax // isCustomAnimation ( bool )
142-
push ecx // pIFPAnimations
143-
144-
// get "this" from stack that we pushed first
145-
mov ecx, [esp+8]
146-
mov ecx, [ecx+4]
147-
sub eax, edx
148-
push esi
149-
150-
// copy the static association to esi
151-
mov esi, edi
152-
test esi, esi
153-
jz ERROR_CopyAnimation
154-
mov eax, [esi+10h]
155-
push eax
156-
mov eax, 04D41C0h
157-
call eax
158-
add esp, 4
159-
mov eax, [esp+4] // pAnimAssociation
160-
mov [esp+20h], eax
16190
test eax, eax
162-
mov [esp+18h], 0
16391
jz ERROR_CopyAnimation
164-
push esi
165-
mov ecx, eax
166-
call FUNC_CAnimBlendAssociation_Constructor
167-
mov edi, eax
168-
169-
// Delete our static association, since we no longer need it
170-
push esi
171-
call DeleteStaticAssociation
172-
add esp, 4
173-
174-
mov ecx, [esp+4] // pIFPAnimations
175-
mov eax, [esp+8] // isCustomAnimation
17692

177-
// put CAnimBlendAssociation in eax
178-
mov eax, edi
179-
add esp, 0Ch
18093
jmp RETURN_CAnimBlendAssocGroup_CopyAnimation
18194

182-
ERROR_CopyAnimation:
183-
add esp, 0Ch
184-
// Delete our static association
185-
push edi
186-
call DeleteStaticAssociation
187-
add esp, 4
188-
jmp RETURN_CAnimBlendAssocGroup_CopyAnimation_ERROR
95+
ERROR_CopyAnimation:
96+
jmp RETURN_CAnimBlendAssocGroup_CopyAnimation_ERROR
18997
}
19098
}
19199

Client/multiplayer_sa/CMultiplayerSA_HookDestructors.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace
1515
{
16+
CAnimBlendAssocDestructorHandler* m_pCAnimBlendAssocDestructorHandler = nullptr;
1617
GameObjectDestructHandler* pGameObjectDestructHandler = NULL;
1718
GameVehicleDestructHandler* pGameVehicleDestructHandler = NULL;
1819
GamePlayerDestructHandler* pGamePlayerDestructHandler = NULL;
@@ -140,6 +141,34 @@ namespace
140141

141142
////////////////////////////////////////////////////////////////////////////////////////////////
142143
//
144+
void __cdecl CAnimBlendAssoc_destructor(CAnimBlendAssociationSAInterface* pThis)
145+
{
146+
if (m_pCAnimBlendAssocDestructorHandler)
147+
{
148+
m_pCAnimBlendAssocDestructorHandler(pThis);
149+
}
150+
}
151+
152+
DWORD RETURN_CAnimBlendAssoc_destructor = 0x4CECF6;
153+
void _declspec(naked) HOOK_CAnimBlendAssoc_destructor()
154+
{
155+
_asm
156+
{
157+
push ecx
158+
159+
push ecx
160+
call CAnimBlendAssoc_destructor
161+
add esp, 0x4
162+
163+
pop ecx
164+
165+
push esi
166+
mov esi, ecx
167+
mov eax, [esi + 10h]
168+
jmp RETURN_CAnimBlendAssoc_destructor
169+
}
170+
}
171+
143172
void _cdecl OnCObjectDestructor(DWORD calledFrom, CObjectSAInterface* pObject)
144173
{
145174
// Tell client to check for things going away
@@ -489,6 +518,11 @@ void _declspec(naked) HOOK_CStreamingRemoveModel()
489518
// Set handlers
490519
//
491520
//////////////////////////////////////////////////////////////////////////////////////////
521+
void CMultiplayerSA::SetCAnimBlendAssocDestructorHandler(CAnimBlendAssocDestructorHandler* pHandler)
522+
{
523+
m_pCAnimBlendAssocDestructorHandler = pHandler;
524+
}
525+
492526
void CMultiplayerSA::SetGameObjectDestructHandler(GameObjectDestructHandler* pHandler)
493527
{
494528
pGameObjectDestructHandler = pHandler;

0 commit comments

Comments
 (0)