Skip to content

Commit

Permalink
Revert all refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
FileEX committed Oct 5, 2024
1 parent 5c3c5f7 commit de223c9
Show file tree
Hide file tree
Showing 25 changed files with 112 additions and 131 deletions.
5 changes: 3 additions & 2 deletions Client/game_sa/CAESoundManagerSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ CAESoundManagerSA::CAESoundManagerSA(CAESoundManagerSAInterface* pInterface) : m

void CAESoundManagerSA::CancelSoundsInBankSlot(uint uiGroup, uint uiIndex)
{
auto args = PrepareSignature(m_pInterface, uiGroup, uiIndex);
CallGTAFunction<CAESound*, __THISCALL>(FUNC_CAESoundManager__CancelSoundsInBankSlot, args);
using CAESoundManager__CancelSoundsInBankSlot = CAESound*(__thiscall*)(CAESoundManagerSAInterface*, uint, uint);
static auto pCancelSoundsInBankSlot = reinterpret_cast<CAESoundManager__CancelSoundsInBankSlot>(FUNC_CAESoundManager__CancelSoundsInBankSlot);
pCancelSoundsInBankSlot(m_pInterface, uiGroup, uiIndex);
}
6 changes: 3 additions & 3 deletions Client/game_sa/CBuildingsPoolSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ void CBuildingsPoolSA::RemoveBuilding(CBuilding* pBuilding)
pGame->GetWorld()->Remove(pInterface, CBuildingPool_Destructor);

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

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

// Remove all shadows
CallGTAFunction<void*, __CDECL>(0x711390, PrepareSignature());
using CStencilShadowObjects_dtorAll = void* (*)();
((CStencilShadowObjects_dtorAll)0x711390)();

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

Expand Down
7 changes: 3 additions & 4 deletions Client/game_sa/CCameraSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,7 @@ float CCameraSA::GetCameraRotation()
RwMatrix* CCameraSA::GetLTM()
{
// RwFrameGetLTM
auto args = PrepareSignature(GetInterface()->m_pRwCamera->object.object.parent);
return CallGTAFunction<RwMatrix*, __CDECL>(0x7F0990, args);
return ((RwMatrix*(_cdecl*)(void*))0x7F0990)(GetInterface()->m_pRwCamera->object.object.parent);
}

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

auto args = PrepareSignature(cameraInterface, radius, x, y, z);
CallGTAFunction<void, __THISCALL>(FUNC_ShakeCam, args);
using ShakeCamera_t = void(__thiscall*)(CCameraSAInterface*, float radius, float x, float y, float z);
((ShakeCamera_t)FUNC_ShakeCam)(cameraInterface, radius, x, y, z);
}

void CCameraSA::ResetShakeCamera() noexcept
Expand Down
35 changes: 6 additions & 29 deletions Client/game_sa/CEntitySA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,22 @@ extern CGameSA* pGame;

void CEntitySAInterface::TransformFromObjectSpace(CVector& outPosn, CVector const& offset)
{
auto args = PrepareSignature(this, &outPosn, &offset);
CallGTAFunction<void, __THISCALL>(0x533560, args);
((void(__thiscall*)(CEntitySAInterface*, CVector&, CVector const&))0x533560)(this, outPosn, offset);
}

CVector* CEntitySAInterface::GetBoundCentre(CVector* pOutCentre)
{
auto args = PrepareSignature(this, pOutCentre);
return CallGTAFunction<CVector*, __THISCALL>(0x534250, args);
return ((CVector * (__thiscall*)(CEntitySAInterface*, CVector*))0x534250)(this, pOutCentre);
}

void CEntitySAInterface::UpdateRW()
{
CallGTAFunction<void, __THISCALL>(0x446F90, PrepareSignature(this));
((void(__thiscall*)(CEntitySAInterface*))0x446F90)(this);
}

void CEntitySAInterface::UpdateRpHAnim()
{
CallGTAFunction<void, __THISCALL>(0x532B20, PrepareSignature(this));
((void(__thiscall*)(CEntitySAInterface*))0x532B20)(this);
}

CRect* CEntitySAInterface::GetBoundRect_(CRect* pRect)
Expand Down Expand Up @@ -73,26 +71,6 @@ void CEntitySAInterface::StaticSetHooks()
HookInstall(0x534120, &CEntitySAInterface::GetBoundRect_);
}

void CEntitySAInterface::ResolveReferences()
{
CallGTAFunction<void*, __THISCALL>(0x571A40, PrepareSignature(this));
}

void CEntitySAInterface::RemoveShadows()
{
CallGTAFunction<void*, __CDECL>(0x711730, PrepareSignature(this));
}

void CEntitySAInterface::DeleteRwObject()
{
CallGTAFunction<void, __THISCALL>(this->vtbl->DeleteRwObject, PrepareSignature(this));
}

void CEntitySAInterface::RemoveMatrix()
{
CallGTAFunction<void, __THISCALL>(0x54F3B0, PrepareSignature(this));
}

CEntitySA::CEntitySA()
{
// Set these variables to a constant state
Expand Down Expand Up @@ -459,8 +437,7 @@ eEntityStatus CEntitySA::GetEntityStatus()
RwFrame* CEntitySA::GetFrameFromId(int id)
{
// CClumpModelInfo::GetFrameFromId
auto args = PrepareSignature(m_pInterface->m_pRwObject, id);
return CallGTAFunction<RwFrame*, __CDECL>(0x4C53C0, args);
return ((RwFrame*(_cdecl*)(RpClump*, int))0x4C53C0)(m_pInterface->m_pRwObject, id);
}

RpClump* CEntitySA::GetRpClump()
Expand All @@ -471,7 +448,7 @@ RpClump* CEntitySA::GetRpClump()
RwMatrix* CEntitySA::GetLTMFromId(int id)
{
// RwFrameGetLTM
return CallGTAFunction<RwMatrix*, __CDECL>(0x7F0990, PrepareSignature(GetFrameFromId(id)));
return ((RwMatrix*(_cdecl*)(RwFrame*))0x7F0990)(GetFrameFromId(id));
}

void CEntitySA::SetAlpha(DWORD dwAlpha)
Expand Down
20 changes: 16 additions & 4 deletions Client/game_sa/CEntitySA.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,27 @@ class CEntitySAInterface
return -1;
}

void ResolveReferences();
void ResolveReferences()
{
using CEntity_ResolveReferences = void*(__thiscall*)(CEntitySAInterface*);
((CEntity_ResolveReferences)0x571A40)(this);
};

void RemoveShadows();
void RemoveShadows()
{
using CStencilShadow_dtorByOwner = void*(__cdecl*)(CEntitySAInterface * pEntity);
((CStencilShadow_dtorByOwner)0x711730)(this);
};

void DeleteRwObject();
void DeleteRwObject()
{
using vtbl_DeleteRwObject = void(__thiscall*)(CEntitySAInterface * pEntity);
((vtbl_DeleteRwObject)this->vtbl->DeleteRwObject)(this);
};

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

void RemoveMatrix();
void RemoveMatrix() { ((void(__thiscall*)(void*))0x54F3B0)(this); }
};
static_assert(sizeof(CEntitySAInterface) == 0x38, "Invalid size for CEntitySAInterface");

Expand Down
20 changes: 10 additions & 10 deletions Client/game_sa/CFileLoaderSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,26 @@ void CFileLoaderSA::StaticSetHooks()
CEntitySAInterface* CFileLoaderSA::LoadObjectInstance(SFileObjectInstance* obj)
{
// Second argument is model name. It's unused in the function
return CallGTAFunction<CEntitySAInterface*, __CDECL>(0x538090, PrepareSignature(obj, static_cast<const char*>(nullptr)));
return ((CEntitySAInterface * (__cdecl*)(SFileObjectInstance*, const char*))0x538090)(obj, nullptr);
}

class CAtomicModelInfo
{
public:
void CAtomicModelInfo::DeleteRwObject() { CallGTAFunction<void, __THISCALL>((*(void***)this)[8], PrepareSignature(this)); }
void CAtomicModelInfo::DeleteRwObject() { ((void(__thiscall*)(CAtomicModelInfo*))(*(void***)this)[8])(this); }

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

class CDamagableModelInfo
{
public:
void CDamagableModelInfo::SetDamagedAtomic(RpAtomic* atomic) { CallGTAFunction<void, __THISCALL>(0x4C48D0, PrepareSignature(this, atomic)); }
void CDamagableModelInfo::SetDamagedAtomic(RpAtomic* atomic) { ((void(__thiscall*)(CDamagableModelInfo*, RpAtomic*))0x4C48D0)(this, atomic); }
};

static char* GetFrameNodeName(RwFrame* frame)
{
return CallGTAFunction<char*, __CDECL>(0x72FB30, PrepareSignature(frame));
return ((char*(__cdecl*)(RwFrame*))0x72FB30)(frame);
}

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

static void CVisibilityPlugins_SetAtomicRenderCallback(RpAtomic* pRpAtomic, RpAtomic* (*renderCB)(RpAtomic*))
{
CallGTAFunction<void, __CDECL>(0x7328A0, PrepareSignature(pRpAtomic, renderCB));
return ((void(__cdecl*)(RpAtomic*, RpAtomic * (*renderCB)(RpAtomic*)))0x7328A0)(pRpAtomic, renderCB);
}

static void CVisibilityPlugins_SetAtomicId(RpAtomic* pRpAtomic, int id)
{
CallGTAFunction<void, __CDECL>(0x732230, PrepareSignature(pRpAtomic, id));
return ((void(__cdecl*)(RpAtomic*, int))0x732230)(pRpAtomic, id);
}

static void CVehicleModelInfo_UseCommonVehicleTexDicationary()
{
CallGTAFunction<void, __CDECL>(0x4C75A0, PrepareSignature());
((void(__cdecl*)())0x4C75A0)();
}

static void CVehicleModelInfo_StopUsingCommonVehicleTexDicationary()
{
CallGTAFunction<void, __CDECL>(0x4C75C0, PrepareSignature());
((void(__cdecl*)())0x4C75C0)();
}

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

return CallGTAFunction<CEntitySAInterface*, __CDECL>(0x538090, PrepareSignature(&inst));
return ((CEntitySAInterface * (__cdecl*)(SFileObjectInstance*))0x538090)(&inst);
}
5 changes: 3 additions & 2 deletions Client/game_sa/CFxManagerSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ void CFxManagerSA::OnFxSystemSAInterfaceDestroyed(CFxSystemSAInterface* pFxSyste

CFxSystemBPSAInterface* CFxManagerSA::GetFxSystemBlueprintByName(SString sName)
{
auto args = PrepareSignature(m_pInterface, static_cast<const char*>(sName));
return CallGTAFunction<CFxSystemBPSAInterface*, __THISCALL>(FUNC_FxManager_c__GetSystemByName, args);
using func_t = CFxSystemBPSAInterface*(__thiscall*)(CFxManagerSAInterface * pInterface, const char* pChars);
auto func = reinterpret_cast<func_t>(FUNC_FxManager_c__GetSystemByName);
return func(m_pInterface, sName);
}

bool CFxManagerSA::IsValidFxSystemBlueprintName(SString sName)
Expand Down
3 changes: 1 addition & 2 deletions Client/game_sa/CFxSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,6 @@ void CFxSA::AddParticle(eFxParticleSystems eFxParticle, const CVector& vecPositi
newDirection.fZ = (rand() % 10000) * 0.0001f * 4 - 2 + newDirection.fZ;

// Call FxSystem_c::AddParticle
auto args = PrepareSignature(fxParticleSystem, &vecPosition, &newDirection, 0.0f, &fxPrt, -1.0f, fBrightness, 0.0f, 0);
CallGTAFunction<int, __THISCALL>(FUNC_FXSystem_c_AddParticle, args);
((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);
}
}
22 changes: 14 additions & 8 deletions Client/game_sa/CGameSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -675,9 +675,15 @@ void CGameSA::SetWaterCreaturesEnabled(bool isEnabled)

const auto manager = reinterpret_cast<class WaterCreatureManager_c*>(0xC1DF30);
if (isEnabled)
CallGTAFunction<unsigned char, __THISCALL>(0x6E3F90, PrepareSignature(manager));
{
unsigned char(__thiscall * Init)(WaterCreatureManager_c*) = reinterpret_cast<decltype(Init)>(0x6E3F90);
Init(manager);
}
else
CallGTAFunction<void, __THISCALL>(0x6E3FD0, PrepareSignature(manager));
{
void(__thiscall * Exit)(WaterCreatureManager_c*) = reinterpret_cast<decltype(Exit)>(0x6E3FD0);
Exit(manager);
}

m_areWaterCreaturesEnabled = isEnabled;
}
Expand Down Expand Up @@ -779,17 +785,17 @@ void CGameSA::SetExtendedWaterCannonsEnabled(bool isEnabled)
{
char* currentCannon = (char*)currentACannons + i * SIZE_CWaterCannon;

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
CallGTAFunction<void, __THISCALL>(FUNC_CWaterCannon_Destructor, PrepareSignature(static_cast<void*>(currentCannon))); // CWaterCannon::~CWaterCannon
((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
((void(__thiscall*)(void*))FUNC_CWaterCannon_Destructor)(currentCannon); // CWaterCannon::~CWaterCannon
}

// Call CWaterCannon constructor & CWaterCannon::Init
for (int i = 0; i < newLimit; ++i)
{
void* currentCannon = (char*)aCannons + i * SIZE_CWaterCannon;
char* currentCannon = (char*)aCannons + i * SIZE_CWaterCannon;

CallGTAFunction<void, __THISCALL>(FUNC_CWaterCannon_Constructor, PrepareSignature(currentCannon)); // CWaterCannon::CWaterCannon
CallGTAFunction<void, __THISCALL>(FUNC_CWaterCannon_Init, PrepareSignature(currentCannon)); // CWaterCannon::Init
((void(__thiscall*)(void*))FUNC_CWaterCannon_Constructor)(currentCannon); // CWaterCannon::CWaterCannon
((void(__thiscall*)(void*))FUNC_CWaterCannon_Init)(currentCannon); // CWaterCannon::Init
}

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

// Free previous allocated memory
if (!isEnabled && currentACannons)
if (!isEnabled && currentACannons != nullptr)
free(currentACannons);

m_isExtendedWaterCannonsEnabled = isEnabled;
Expand Down
16 changes: 6 additions & 10 deletions Client/game_sa/CMatrixSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,30 @@

CMatrixSAInterface::CMatrixSAInterface(CMatrixSAInterface const& matrix)
{
auto args = PrepareSignature(this, &matrix);
CallGTAFunction<void, __THISCALL>(CMatrix_Constructor, args);
((void(__thiscall*)(CMatrixSAInterface*, CMatrixSAInterface const&))0x59BCF0)(this, matrix);
}

CMatrixSAInterface::CMatrixSAInterface(RwMatrix* matrix, bool temporary)
{
auto args = PrepareSignature(this, matrix, temporary);
CallGTAFunction<void, __THISCALL>(CMatrix_Constructor2, args);
((void(__thiscall*)(CMatrixSAInterface*, RwMatrix*, bool))0x59C050)(this, matrix, temporary);
}

// destructor detaches matrix if attached
CMatrixSAInterface::~CMatrixSAInterface()
{
CallGTAFunction<void, __THISCALL>(CMatrix_Destructor, PrepareSignature(this));
((void(__thiscall*)(CMatrixSAInterface*))0x59ACD0)(this);
}

void CMatrixSAInterface::ConvertToEulerAngles(float& x, float& y, float& z, std::int32_t flags)
{
auto args = PrepareSignature(this, &x, &y, &z, flags);
CallGTAFunction<void, __THISCALL>(FUNC_CMatrix_ConvertToEulerAngles, args);
((void(__thiscall*)(CMatrixSAInterface*, float&, float&, float&, std::int32_t))0x59A840)(this, x, y, z, flags);
}
void CMatrixSAInterface::ConvertFromEulerAngles(float x, float y, float z, std::int32_t flags)
{
auto args = PrepareSignature(this, x, y, z, flags);
CallGTAFunction<void, __THISCALL>(FUNC_CMatrix_ConvertFromEulerAngles, args);
((void(__thiscall*)(CMatrixSAInterface*, float, float, float, std::int32_t))0x59AA40)(this, x, y, z, flags);
}

void CMatrixSAInterface::UpdateRW()
{
CallGTAFunction<void, __THISCALL>(FUNC_CMatrix_UpdateRW, PrepareSignature(this));
((void(__thiscall*)(CMatrixSAInterface*))0x59BBB0)(this);
}
7 changes: 0 additions & 7 deletions Client/game_sa/CMatrixSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@
#include "CVector.h"
#include "CRenderWareSA.h"

#define CMatrix_Constructor 0x59BCF0
#define CMatrix_Constructor2 0x59C050
#define CMatrix_Destructor 0x59ACD0
#define FUNC_CMatrix_ConvertToEulerAngles 0x59A840
#define FUNC_CMatrix_ConvertFromEulerAngles 0x59AA40
#define FUNC_CMatrix_UpdateRW 0x59BBB0

class CMatrixSAInterface
{
private:
Expand Down
12 changes: 7 additions & 5 deletions Client/game_sa/CModelInfoSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,16 @@ static constexpr size_t RESOURCE_ID_COL = 25000;

static void CBaseModelInfo_SetColModel(CBaseModelInfoSAInterface* self, CColModelSAInterface* colModel, bool applyToPairedModel)
{
auto args = PrepareSignature(self, colModel, applyToPairedModel);
CallGTAFunction<void, __THISCALL>(0x4C4BC0, args);
using Signature = void(__thiscall*)(CBaseModelInfoSAInterface*, CColModelSAInterface*, bool);
auto function = reinterpret_cast<Signature>(0x4C4BC0);
function(self, colModel, applyToPairedModel);
}

static void CColAccel_addCacheCol(int idx, const CColModelSAInterface* colModel)
{
auto args = PrepareSignature(idx, colModel);
CallGTAFunction<void, __CDECL>(0x5B2C20, args);
using Signature = void(__cdecl*)(int, const CColModelSAInterface*);
auto function = reinterpret_cast<Signature>(0x5B2C20);
function(idx, colModel);
}

CModelInfoSA::CModelInfoSA()
Expand Down Expand Up @@ -1564,7 +1566,7 @@ void CModelInfoSA::SetColModel(CColModel* pColModel)
m_pInterface->bIsColLoaded = false;

// Fix random foliage on custom collisions by calling CPlantMgr::SetPlantFriendlyFlagInAtomicMI
CallGTAFunction<void, __CDECL>(0x5DB650, PrepareSignature(m_pInterface));
(reinterpret_cast<void(__cdecl*)(CBaseModelInfoSAInterface*)>(0x5DB650))(m_pInterface);

// Set some lighting for this collision if not already present
CColDataSA* pColData = pColModelInterface->m_data;
Expand Down
3 changes: 2 additions & 1 deletion Client/game_sa/CPedIKSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ RwV3d& CPedIKSAInterface::ZaxisIK = *(RwV3d*)0x8D2344;

void CPedIKSA::RotateTorso(void* bone, LimbOrientation* orientation, bool flag)
{
CallGTAFunction<void, __THISCALL>(CPedIK__RotateTorso, PrepareSignature(internalInterface, bone, orientation, flag));
auto CPedIKSA_RotateTorso = (void(__thiscall*)(CPedIKSAInterface*, void*, LimbOrientation*, bool))0x5FDDB0;
CPedIKSA_RotateTorso(internalInterface, bone, orientation, flag);
}
2 changes: 0 additions & 2 deletions Client/game_sa/CPedIKSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

#include <game/CPedIK.h>

#define CPedIK__RotateTorso 0x5FDDB0

class CPedSAInterface;
struct RwV3d;

Expand Down
Loading

0 comments on commit de223c9

Please sign in to comment.