Skip to content

Commit 5feedfa

Browse files
committed
all __thiscall & some __cdecl
1 parent abffd87 commit 5feedfa

26 files changed

+190
-112
lines changed

Client/game_sa/CAESoundManagerSA.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ CAESoundManagerSA::CAESoundManagerSA(CAESoundManagerSAInterface* pInterface) : m
2323

2424
void CAESoundManagerSA::CancelSoundsInBankSlot(uint uiGroup, uint uiIndex)
2525
{
26-
using CAESoundManager__CancelSoundsInBankSlot = CAESound*(__thiscall*)(CAESoundManagerSAInterface*, uint, uint);
27-
static auto pCancelSoundsInBankSlot = reinterpret_cast<CAESoundManager__CancelSoundsInBankSlot>(FUNC_CAESoundManager__CancelSoundsInBankSlot);
28-
pCancelSoundsInBankSlot(m_pInterface, uiGroup, uiIndex);
26+
auto args = PrepareSignature(m_pInterface, uiGroup, uiIndex);
27+
CallGTAFunction<CAESound*, __THISCALL>(FUNC_CAESoundManager__CancelSoundsInBankSlot, args);
2928
}

Client/game_sa/CBuildingsPoolSA.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ void CBuildingsPoolSA::RemoveBuilding(CBuilding* pBuilding)
108108
pGame->GetWorld()->Remove(pInterface, CBuildingPool_Destructor);
109109

110110
// Call virtual destructor
111-
((void*(__thiscall*)(void*, char))pInterface->vtbl->SCALAR_DELETING_DESTRUCTOR)(pInterface, 0);
111+
auto args = PrepareSignature(pInterface, 0);
112+
CallGTAFunction<void*, __THISCALL>(pInterface->vtbl->SCALAR_DELETING_DESTRUCTOR, args);
112113

113114
// Remove col reference
114115
auto modelInfo = pGame->GetModelInfo(pBuilding->GetModelIndex());
@@ -137,8 +138,7 @@ void CBuildingsPoolSA::RemoveAllBuildings()
137138
pGame->GetPlantManager()->RemoveAllPlants();
138139

139140
// Remove all shadows
140-
using CStencilShadowObjects_dtorAll = void* (*)();
141-
((CStencilShadowObjects_dtorAll)0x711390)();
141+
CallGTAFunction<void*, __CDECL>(0x711390, PrepareSignature());
142142

143143
m_pOriginalBuildingsBackup = std::make_unique<std::array<std::pair<bool, CBuildingSAInterface>, MAX_BUILDINGS>>();
144144

Client/game_sa/CCameraSA.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,8 @@ float CCameraSA::GetCameraRotation()
358358
RwMatrix* CCameraSA::GetLTM()
359359
{
360360
// RwFrameGetLTM
361-
return ((RwMatrix*(_cdecl*)(void*))0x7F0990)(GetInterface()->m_pRwCamera->object.object.parent);
361+
auto args = PrepareSignature(GetInterface()->m_pRwCamera->object.object.parent);
362+
return CallGTAFunction<RwMatrix*, __CDECL>(0x7F0990, args);
362363
}
363364

364365
CEntity* CCameraSA::GetTargetEntity()
@@ -450,8 +451,8 @@ void CCameraSA::ShakeCamera(float radius, float x, float y, float z) noexcept
450451
if (radius <= 0.0f)
451452
return ResetShakeCamera();
452453

453-
using ShakeCamera_t = void(__thiscall*)(CCameraSAInterface*, float radius, float x, float y, float z);
454-
((ShakeCamera_t)FUNC_ShakeCam)(cameraInterface, radius, x, y, z);
454+
auto args = PrepareSignature(cameraInterface, radius, x, y, z);
455+
CallGTAFunction<void, __THISCALL>(FUNC_ShakeCam, args);
455456
}
456457

457458
void CCameraSA::ResetShakeCamera() noexcept

Client/game_sa/CEntitySA.cpp

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,24 @@ extern CGameSA* pGame;
2525

2626
void CEntitySAInterface::TransformFromObjectSpace(CVector& outPosn, CVector const& offset)
2727
{
28-
((void(__thiscall*)(CEntitySAInterface*, CVector&, CVector const&))0x533560)(this, outPosn, offset);
28+
auto args = PrepareSignature(this, &outPosn, &offset);
29+
CallGTAFunction<void, __THISCALL>(0x533560, args);
2930
}
3031

3132
CVector* CEntitySAInterface::GetBoundCentre(CVector* pOutCentre)
3233
{
33-
return ((CVector * (__thiscall*)(CEntitySAInterface*, CVector*))0x534250)(this, pOutCentre);
34+
auto args = PrepareSignature(this, pOutCentre);
35+
return CallGTAFunction<CVector*, __THISCALL>(0x534250, args);
3436
}
3537

3638
void CEntitySAInterface::UpdateRW()
3739
{
38-
((void(__thiscall*)(CEntitySAInterface*))0x446F90)(this);
40+
CallGTAFunction<void, __THISCALL>(0x446F90, PrepareSignature(this));
3941
}
4042

4143
void CEntitySAInterface::UpdateRpHAnim()
4244
{
43-
((void(__thiscall*)(CEntitySAInterface*))0x532B20)(this);
45+
CallGTAFunction<void, __THISCALL>(0x532B20, PrepareSignature(this));
4446
}
4547

4648
CRect* CEntitySAInterface::GetBoundRect_(CRect* pRect)
@@ -71,6 +73,26 @@ void CEntitySAInterface::StaticSetHooks()
7173
HookInstall(0x534120, &CEntitySAInterface::GetBoundRect_);
7274
}
7375

76+
void CEntitySAInterface::ResolveReferences()
77+
{
78+
CallGTAFunction<void*, __THISCALL>(0x571A40, PrepareSignature(this));
79+
}
80+
81+
void CEntitySAInterface::RemoveShadows()
82+
{
83+
CallGTAFunction<void*, __CDECL>(0x711730, PrepareSignature(this));
84+
}
85+
86+
void CEntitySAInterface::DeleteRwObject()
87+
{
88+
CallGTAFunction<void, __THISCALL>(this->vtbl->DeleteRwObject, PrepareSignature(this));
89+
}
90+
91+
void CEntitySAInterface::RemoveMatrix()
92+
{
93+
CallGTAFunction<void, __THISCALL>(0x54F3B0, PrepareSignature(this));
94+
}
95+
7496
CEntitySA::CEntitySA()
7597
{
7698
// Set these variables to a constant state
@@ -437,7 +459,8 @@ eEntityStatus CEntitySA::GetEntityStatus()
437459
RwFrame* CEntitySA::GetFrameFromId(int id)
438460
{
439461
// CClumpModelInfo::GetFrameFromId
440-
return ((RwFrame*(_cdecl*)(RpClump*, int))0x4C53C0)(m_pInterface->m_pRwObject, id);
462+
auto args = PrepareSignature(m_pInterface->m_pRwObject, id);
463+
return CallGTAFunction<RwFrame*, __CDECL>(0x4C53C0, args);
441464
}
442465

443466
RpClump* CEntitySA::GetRpClump()
@@ -448,7 +471,7 @@ RpClump* CEntitySA::GetRpClump()
448471
RwMatrix* CEntitySA::GetLTMFromId(int id)
449472
{
450473
// RwFrameGetLTM
451-
return ((RwMatrix*(_cdecl*)(RwFrame*))0x7F0990)(GetFrameFromId(id));
474+
return CallGTAFunction<RwMatrix*, __CDECL>(0x7F0990, PrepareSignature(GetFrameFromId(id)));
452475
}
453476

454477
void CEntitySA::SetAlpha(DWORD dwAlpha)

Client/game_sa/CEntitySA.h

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -225,27 +225,15 @@ class CEntitySAInterface
225225
return -1;
226226
}
227227

228-
void ResolveReferences()
229-
{
230-
using CEntity_ResolveReferences = void*(__thiscall*)(CEntitySAInterface*);
231-
((CEntity_ResolveReferences)0x571A40)(this);
232-
};
228+
void ResolveReferences();
233229

234-
void RemoveShadows()
235-
{
236-
using CStencilShadow_dtorByOwner = void*(__cdecl*)(CEntitySAInterface * pEntity);
237-
((CStencilShadow_dtorByOwner)0x711730)(this);
238-
};
230+
void RemoveShadows();
239231

240-
void DeleteRwObject()
241-
{
242-
using vtbl_DeleteRwObject = void(__thiscall*)(CEntitySAInterface * pEntity);
243-
((vtbl_DeleteRwObject)this->vtbl->DeleteRwObject)(this);
244-
};
232+
void DeleteRwObject();
245233

246234
bool HasMatrix() const noexcept { return Placeable.matrix != nullptr; }
247235

248-
void RemoveMatrix() { ((void(__thiscall*)(void*))0x54F3B0)(this); }
236+
void RemoveMatrix();
249237
};
250238
static_assert(sizeof(CEntitySAInterface) == 0x38, "Invalid size for CEntitySAInterface");
251239

Client/game_sa/CFileLoaderSA.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,26 @@ void CFileLoaderSA::StaticSetHooks()
3131
CEntitySAInterface* CFileLoaderSA::LoadObjectInstance(SFileObjectInstance* obj)
3232
{
3333
// Second argument is model name. It's unused in the function
34-
return ((CEntitySAInterface * (__cdecl*)(SFileObjectInstance*, const char*))0x538090)(obj, nullptr);
34+
return CallGTAFunction<CEntitySAInterface*, __CDECL>(0x538090, PrepareSignature(obj, static_cast<const char*>(nullptr)));
3535
}
3636

3737
class CAtomicModelInfo
3838
{
3939
public:
40-
void CAtomicModelInfo::DeleteRwObject() { ((void(__thiscall*)(CAtomicModelInfo*))(*(void***)this)[8])(this); }
40+
void CAtomicModelInfo::DeleteRwObject() { CallGTAFunction<void, __THISCALL>((*(void***)this)[8], PrepareSignature(this)); }
4141

42-
void CAtomicModelInfo::SetAtomic(RpAtomic* atomic) { ((void(__thiscall*)(CAtomicModelInfo*, RpAtomic*))(*(void***)this)[15])(this, atomic); }
42+
void CAtomicModelInfo::SetAtomic(RpAtomic* atomic) { CallGTAFunction<void, __THISCALL>((*(void***)this)[15], PrepareSignature(this, atomic)); }
4343
};
4444

4545
class CDamagableModelInfo
4646
{
4747
public:
48-
void CDamagableModelInfo::SetDamagedAtomic(RpAtomic* atomic) { ((void(__thiscall*)(CDamagableModelInfo*, RpAtomic*))0x4C48D0)(this, atomic); }
48+
void CDamagableModelInfo::SetDamagedAtomic(RpAtomic* atomic) { CallGTAFunction<void, __THISCALL>(0x4C48D0, PrepareSignature(this, atomic)); }
4949
};
5050

5151
static char* GetFrameNodeName(RwFrame* frame)
5252
{
53-
return ((char*(__cdecl*)(RwFrame*))0x72FB30)(frame);
53+
return CallGTAFunction<char*, __CDECL>(0x72FB30, PrepareSignature(frame));
5454
}
5555

5656
// Originally there was a possibility for this function to cause buffer overflow
@@ -97,22 +97,22 @@ void GetNameAndDamage(const char* nodeName, char (&outName)[OutBuffSize], bool&
9797

9898
static void CVisibilityPlugins_SetAtomicRenderCallback(RpAtomic* pRpAtomic, RpAtomic* (*renderCB)(RpAtomic*))
9999
{
100-
return ((void(__cdecl*)(RpAtomic*, RpAtomic * (*renderCB)(RpAtomic*)))0x7328A0)(pRpAtomic, renderCB);
100+
CallGTAFunction<void, __CDECL>(0x7328A0, PrepareSignature(pRpAtomic, renderCB));
101101
}
102102

103103
static void CVisibilityPlugins_SetAtomicId(RpAtomic* pRpAtomic, int id)
104104
{
105-
return ((void(__cdecl*)(RpAtomic*, int))0x732230)(pRpAtomic, id);
105+
CallGTAFunction<void, __CDECL>(0x732230, PrepareSignature(pRpAtomic, id));
106106
}
107107

108108
static void CVehicleModelInfo_UseCommonVehicleTexDicationary()
109109
{
110-
((void(__cdecl*)())0x4C75A0)();
110+
CallGTAFunction<void, __CDECL>(0x4C75A0, PrepareSignature());
111111
}
112112

113113
static void CVehicleModelInfo_StopUsingCommonVehicleTexDicationary()
114114
{
115-
((void(__cdecl*)())0x4C75C0)();
115+
CallGTAFunction<void, __CDECL>(0x4C75C0, PrepareSignature());
116116
}
117117

118118
static auto CModelInfo_ms_modelInfoPtrs = (CBaseModelInfoSAInterface**)ARRAY_ModelInfo;
@@ -223,5 +223,5 @@ CEntitySAInterface* CFileLoader_LoadObjectInstance(const char* szLine)
223223
if (fLenSq > 0.0f && std::fabs(fLenSq - 1.0f) > std::numeric_limits<float>::epsilon())
224224
inst.rotation /= std::sqrt(fLenSq);
225225

226-
return ((CEntitySAInterface * (__cdecl*)(SFileObjectInstance*))0x538090)(&inst);
226+
return CallGTAFunction<CEntitySAInterface*, __CDECL>(0x538090, PrepareSignature(&inst));
227227
}

Client/game_sa/CFxManagerSA.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,8 @@ void CFxManagerSA::OnFxSystemSAInterfaceDestroyed(CFxSystemSAInterface* pFxSyste
7171

7272
CFxSystemBPSAInterface* CFxManagerSA::GetFxSystemBlueprintByName(SString sName)
7373
{
74-
using func_t = CFxSystemBPSAInterface*(__thiscall*)(CFxManagerSAInterface * pInterface, const char* pChars);
75-
auto func = reinterpret_cast<func_t>(FUNC_FxManager_c__GetSystemByName);
76-
return func(m_pInterface, sName);
74+
auto args = PrepareSignature(m_pInterface, static_cast<const char*>(sName));
75+
return CallGTAFunction<CFxSystemBPSAInterface*, __THISCALL>(FUNC_FxManager_c__GetSystemByName, args);
7776
}
7877

7978
bool CFxManagerSA::IsValidFxSystemBlueprintName(SString sName)

Client/game_sa/CFxSA.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ void CFxSA::AddParticle(eFxParticleSystems eFxParticle, const CVector& vecPositi
326326
newDirection.fZ = (rand() % 10000) * 0.0001f * 4 - 2 + newDirection.fZ;
327327

328328
// Call FxSystem_c::AddParticle
329-
((int(__thiscall*)(FxSystem_c*, const CVector*, const CVector*, float, FxPrtMult_c*, float, float, float, int))FUNC_FXSystem_c_AddParticle)(fxParticleSystem, &vecPosition, &newDirection, 0, &fxPrt, -1.0f, fBrightness, 0, 0);
329+
auto args = PrepareSignature(fxParticleSystem, &vecPosition, &newDirection, 0.0f, &fxPrt, -1.0f, fBrightness, 0.0f, 0);
330+
CallGTAFunction<int, __THISCALL>(FUNC_FXSystem_c_AddParticle, args);
330331
}
331332
}

Client/game_sa/CGameSA.cpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -675,15 +675,9 @@ void CGameSA::SetWaterCreaturesEnabled(bool isEnabled)
675675

676676
const auto manager = reinterpret_cast<class WaterCreatureManager_c*>(0xC1DF30);
677677
if (isEnabled)
678-
{
679-
unsigned char(__thiscall * Init)(WaterCreatureManager_c*) = reinterpret_cast<decltype(Init)>(0x6E3F90);
680-
Init(manager);
681-
}
678+
CallGTAFunction<unsigned char, __THISCALL>(0x6E3F90, PrepareSignature(manager));
682679
else
683-
{
684-
void(__thiscall * Exit)(WaterCreatureManager_c*) = reinterpret_cast<decltype(Exit)>(0x6E3FD0);
685-
Exit(manager);
686-
}
680+
CallGTAFunction<void, __THISCALL>(0x6E3FD0, PrepareSignature(manager));
687681

688682
m_areWaterCreaturesEnabled = isEnabled;
689683
}
@@ -785,17 +779,17 @@ void CGameSA::SetExtendedWaterCannonsEnabled(bool isEnabled)
785779
{
786780
char* currentCannon = (char*)currentACannons + i * SIZE_CWaterCannon;
787781

788-
((void(__thiscall*)(int, void*, bool))FUNC_CAESoundManager_CancelSoundsOwnedByAudioEntity)(STRUCT_CAESoundManager, currentCannon + NUM_CWaterCannon_Audio_Offset, true); // CAESoundManager::CancelSoundsOwnedByAudioEntity to prevent random crashes from CAESound::UpdateParameters
789-
((void(__thiscall*)(void*))FUNC_CWaterCannon_Destructor)(currentCannon); // CWaterCannon::~CWaterCannon
782+
CallGTAFunction<void, __THISCALL>(FUNC_CAESoundManager_CancelSoundsOwnedByAudioEntity, PrepareSignature(STRUCT_CAESoundManager, static_cast<void*>(currentCannon + NUM_CWaterCannon_Audio_Offset), true)); // CAESoundManager::CancelSoundsOwnedByAudioEntity to prevent random crashes from CAESound::UpdateParameters
783+
CallGTAFunction<void, __THISCALL>(FUNC_CWaterCannon_Destructor, PrepareSignature(static_cast<void*>(currentCannon))); // CWaterCannon::~CWaterCannon
790784
}
791785

792786
// Call CWaterCannon constructor & CWaterCannon::Init
793787
for (int i = 0; i < newLimit; ++i)
794788
{
795-
char* currentCannon = (char*)aCannons + i * SIZE_CWaterCannon;
789+
void* currentCannon = (char*)aCannons + i * SIZE_CWaterCannon;
796790

797-
((void(__thiscall*)(void*))FUNC_CWaterCannon_Constructor)(currentCannon); // CWaterCannon::CWaterCannon
798-
((void(__thiscall*)(void*))FUNC_CWaterCannon_Init)(currentCannon); // CWaterCannon::Init
791+
CallGTAFunction<void, __THISCALL>(FUNC_CWaterCannon_Constructor, PrepareSignature(currentCannon)); // CWaterCannon::CWaterCannon
792+
CallGTAFunction<void, __THISCALL>(FUNC_CWaterCannon_Init, PrepareSignature(currentCannon)); // CWaterCannon::Init
799793
}
800794

801795
// Patch references to array
@@ -831,7 +825,7 @@ void CGameSA::SetExtendedWaterCannonsEnabled(bool isEnabled)
831825
MemPut<BYTE>(0x856BF6, newLimit);
832826

833827
// Free previous allocated memory
834-
if (!isEnabled && currentACannons != nullptr)
828+
if (!isEnabled && currentACannons)
835829
free(currentACannons);
836830

837831
m_isExtendedWaterCannonsEnabled = isEnabled;

Client/game_sa/CMatrixSA.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,34 @@
33

44
CMatrixSAInterface::CMatrixSAInterface(CMatrixSAInterface const& matrix)
55
{
6-
((void(__thiscall*)(CMatrixSAInterface*, CMatrixSAInterface const&))0x59BCF0)(this, matrix);
6+
auto args = PrepareSignature(this, &matrix);
7+
CallGTAFunction<void, __THISCALL>(CMatrix_Constructor, args);
78
}
89

910
CMatrixSAInterface::CMatrixSAInterface(RwMatrix* matrix, bool temporary)
1011
{
11-
((void(__thiscall*)(CMatrixSAInterface*, RwMatrix*, bool))0x59C050)(this, matrix, temporary);
12+
auto args = PrepareSignature(this, matrix, temporary);
13+
CallGTAFunction<void, __THISCALL>(CMatrix_Constructor2, args);
1214
}
1315

1416
// destructor detaches matrix if attached
1517
CMatrixSAInterface::~CMatrixSAInterface()
1618
{
17-
((void(__thiscall*)(CMatrixSAInterface*))0x59ACD0)(this);
19+
CallGTAFunction<void, __THISCALL>(CMatrix_Destructor, PrepareSignature(this));
1820
}
1921

2022
void CMatrixSAInterface::ConvertToEulerAngles(float& x, float& y, float& z, std::int32_t flags)
2123
{
22-
((void(__thiscall*)(CMatrixSAInterface*, float&, float&, float&, std::int32_t))0x59A840)(this, x, y, z, flags);
24+
auto args = PrepareSignature(this, &x, &y, &z, flags);
25+
CallGTAFunction<void, __THISCALL>(FUNC_CMatrix_ConvertToEulerAngles, args);
2326
}
2427
void CMatrixSAInterface::ConvertFromEulerAngles(float x, float y, float z, std::int32_t flags)
2528
{
26-
((void(__thiscall*)(CMatrixSAInterface*, float, float, float, std::int32_t))0x59AA40)(this, x, y, z, flags);
29+
auto args = PrepareSignature(this, x, y, z, flags);
30+
CallGTAFunction<void, __THISCALL>(FUNC_CMatrix_ConvertFromEulerAngles, args);
2731
}
2832

2933
void CMatrixSAInterface::UpdateRW()
3034
{
31-
((void(__thiscall*)(CMatrixSAInterface*))0x59BBB0)(this);
35+
CallGTAFunction<void, __THISCALL>(FUNC_CMatrix_UpdateRW, PrepareSignature(this));
3236
}

0 commit comments

Comments
 (0)