Skip to content

Commit 195f43f

Browse files
authored
Minor refactor for try-catch blocks (PR #4019)
1 parent 4d7f80c commit 195f43f

File tree

9 files changed

+107
-143
lines changed

9 files changed

+107
-143
lines changed

Client/game_sa/CHandlingManagerSA.cpp

Lines changed: 43 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ const CBikeHandlingEntry* CHandlingManagerSA::GetOriginalBikeHandlingData(std::u
274274
}
275275

276276
// Return the handling manager id
277-
eHandlingTypes CHandlingManagerSA::GetHandlingID(std::uint32_t model) const noexcept
277+
eHandlingTypes CHandlingManagerSA::GetHandlingID(std::uint32_t model) noexcept
278278
{
279279
switch (model)
280280
{
@@ -9125,53 +9125,47 @@ void CHandlingManagerSA::InitializeDefaultHandlings() noexcept
91259125
m_OriginalBikeHandlingData[13].iVehicleID = 214;
91269126
}
91279127

9128-
void CHandlingManagerSA::CheckSuspensionChanges(const CHandlingEntry* const pEntry) const noexcept
9128+
void CHandlingManagerSA::CheckSuspensionChanges(const CHandlingEntry* const entry) const noexcept
91299129
{
9130-
try
9131-
{
9132-
// Valid?
9133-
if (!pEntry)
9134-
return;
9135-
9136-
// Grab us a multiplayer_sa pointer
9137-
const CMultiplayer* const pMultiplayer = g_pCore->GetMultiplayer();
9138-
if (!pMultiplayer)
9139-
return;
9140-
9141-
// Get Handling ID
9142-
const eHandlingTypes eHandling = pEntry->GetVehicleID();
9143-
if (eHandling >= HT_MAX)
9144-
return;
9145-
9146-
const auto& entries = m_OriginalEntries[eHandling];
9147-
if (!entries)
9148-
return;
9149-
9150-
// Default bChanged to false
9151-
bool bChanged = false;
9152-
9153-
// Set bChanged to true if we find ANY change.
9154-
if (pEntry->GetSuspensionAntiDiveMultiplier() != entries->GetSuspensionAntiDiveMultiplier())
9155-
bChanged = true;
9156-
else if (pEntry->GetSuspensionDamping() != entries->GetSuspensionDamping())
9157-
bChanged = true;
9158-
else if (pEntry->GetSuspensionForceLevel() != entries->GetSuspensionForceLevel())
9159-
bChanged = true;
9160-
else if (pEntry->GetSuspensionFrontRearBias() != entries->GetSuspensionFrontRearBias())
9161-
bChanged = true;
9162-
else if (pEntry->GetSuspensionHighSpeedDamping() != entries->GetSuspensionHighSpeedDamping())
9163-
bChanged = true;
9164-
else if (pEntry->GetSuspensionLowerLimit() != entries->GetSuspensionLowerLimit())
9165-
bChanged = true;
9166-
else if (pEntry->GetSuspensionUpperLimit() != entries->GetSuspensionUpperLimit())
9167-
bChanged = true;
9168-
9169-
if (!bChanged)
9170-
return;
9171-
9172-
pMultiplayer->UpdateVehicleSuspension();
9173-
}
9174-
catch (...)
9175-
{
9176-
}
9130+
// Valid?
9131+
if (!entry)
9132+
return;
9133+
9134+
// Grab us a multiplayer pointer
9135+
const CMultiplayer* const multiplayer = g_pCore->GetMultiplayer();
9136+
if (!multiplayer)
9137+
return;
9138+
9139+
// Get handling type
9140+
const eHandlingTypes handlingType = entry->GetVehicleID();
9141+
if (handlingType >= HT_MAX)
9142+
return;
9143+
9144+
const auto& entries = m_OriginalEntries[handlingType];
9145+
if (!entries)
9146+
return;
9147+
9148+
// Not changed default
9149+
bool isChanged = false;
9150+
9151+
// Find changes
9152+
if (entry->GetSuspensionAntiDiveMultiplier() != entries->GetSuspensionAntiDiveMultiplier())
9153+
isChanged = true;
9154+
else if (entry->GetSuspensionDamping() != entries->GetSuspensionDamping())
9155+
isChanged = true;
9156+
else if (entry->GetSuspensionForceLevel() != entries->GetSuspensionForceLevel())
9157+
isChanged = true;
9158+
else if (entry->GetSuspensionFrontRearBias() != entries->GetSuspensionFrontRearBias())
9159+
isChanged = true;
9160+
else if (entry->GetSuspensionHighSpeedDamping() != entries->GetSuspensionHighSpeedDamping())
9161+
isChanged = true;
9162+
else if (entry->GetSuspensionLowerLimit() != entries->GetSuspensionLowerLimit())
9163+
isChanged = true;
9164+
else if (entry->GetSuspensionUpperLimit() != entries->GetSuspensionUpperLimit())
9165+
isChanged = true;
9166+
9167+
if (!isChanged)
9168+
return;
9169+
9170+
multiplayer->UpdateVehicleSuspension();
91779171
}

Client/game_sa/CHandlingManagerSA.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ class CHandlingManagerSA : public CHandlingManager
3535

3636
eHandlingProperty GetPropertyEnumFromName(const std::string& name) const noexcept;
3737

38-
void CheckSuspensionChanges(const CHandlingEntry* const pEntry) const noexcept;
38+
void CheckSuspensionChanges(const CHandlingEntry* const entry) const noexcept;
39+
40+
static eHandlingTypes GetHandlingID(std::uint32_t model) noexcept;
3941

4042
private:
4143
void InitializeDefaultHandlings() noexcept;
42-
43-
eHandlingTypes GetHandlingID(std::uint32_t uiModel) const noexcept;
4444
};

Client/game_sa/CModelInfoSA.cpp

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -296,15 +296,8 @@ bool CModelInfoSA::IsVehicle() const
296296

297297
bool CModelInfoSA::IsVehicleModel(std::uint32_t model) noexcept
298298
{
299-
try
300-
{
301-
const auto* const modelInfo = pGame->GetModelInfo(model);
302-
return modelInfo && modelInfo->IsVehicle();
303-
}
304-
catch (...)
305-
{
306-
return false;
307-
}
299+
const auto* const modelInfo = pGame->GetModelInfo(model);
300+
return modelInfo && modelInfo->IsVehicle();
308301
}
309302

310303
bool CModelInfoSA::IsPlayerModel()
@@ -766,14 +759,7 @@ bool CModelInfoSA::IsValid()
766759

767760
bool CModelInfoSA::IsAllocatedInArchive() const noexcept
768761
{
769-
try
770-
{
771-
return pGame->GetStreaming()->GetStreamingInfo(m_dwModelID)->sizeInBlocks > 0;
772-
}
773-
catch (...)
774-
{
775-
return false;
776-
}
762+
return pGame->GetStreaming()->GetStreamingInfo(m_dwModelID)->sizeInBlocks > 0;
777763
}
778764

779765
float CModelInfoSA::GetDistanceFromCentreOfMassToBaseOfModel()

Client/game_sa/CPhysicalSA.cpp

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -102,28 +102,22 @@ CVector* CPhysicalSA::GetTurnSpeedInternal(CVector* vecTurnSpeed)
102102

103103
void CPhysicalSA::SetMoveSpeed(const CVector& vecMoveSpeed) noexcept
104104
{
105-
try
105+
DWORD dwFunc = FUNC_GetMoveSpeed;
106+
DWORD dwThis = (DWORD)((CPhysicalSAInterface*)GetInterface());
107+
DWORD dwReturn = 0;
108+
109+
__asm
106110
{
107-
DWORD dwFunc = FUNC_GetMoveSpeed;
108-
DWORD dwThis = (DWORD)((CPhysicalSAInterface*)GetInterface());
109-
DWORD dwReturn = 0;
110-
111-
__asm
112-
{
113-
mov ecx, dwThis
114-
call dwFunc
115-
mov dwReturn, eax
116-
}
117-
MemCpyFast((void*)dwReturn, &vecMoveSpeed, sizeof(CVector));
118-
119-
if (GetInterface()->nType == ENTITY_TYPE_OBJECT)
120-
{
121-
AddToMovingList();
122-
SetStatic(false);
123-
}
111+
mov ecx, dwThis
112+
call dwFunc
113+
mov dwReturn, eax
124114
}
125-
catch (...)
115+
MemCpyFast((void*)dwReturn, &vecMoveSpeed, sizeof(CVector));
116+
117+
if (GetInterface()->nType == ENTITY_TYPE_OBJECT)
126118
{
119+
AddToMovingList();
120+
SetStatic(false);
127121
}
128122
}
129123

Client/game_sa/CPoolsSA.cpp

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -73,26 +73,28 @@ inline bool CPoolsSA::AddVehicleToPool(CClientVehicle* pClientVehicle, CVehicleS
7373

7474
CVehicle* CPoolsSA::AddVehicle(CClientVehicle* pClientVehicle, std::uint16_t model, std::uint8_t variation, std::uint8_t variation2) noexcept
7575
{
76-
try
77-
{
78-
if (m_vehiclePool.ulCount >= MAX_VEHICLES)
79-
return nullptr;
76+
if (m_vehiclePool.ulCount >= MAX_VEHICLES)
77+
return nullptr;
8078

81-
MemSetFast((void*)VAR_CVehicle_Variation1, variation, 1);
82-
MemSetFast((void*)VAR_CVehicle_Variation2, variation2, 1);
79+
MemSetFast((void*)VAR_CVehicle_Variation1, variation, 1);
80+
MemSetFast((void*)VAR_CVehicle_Variation2, variation2, 1);
8381

84-
// CCarCtrl::CreateCarForScript
85-
auto* pInterface = ((CVehicleSAInterface*(__cdecl*)(int, CVector, std::uint8_t))FUNC_CCarCtrlCreateCarForScript)(model, CVector(), 0);
86-
if (!pInterface)
87-
return nullptr;
82+
// CCarCtrl::CreateCarForScript
83+
auto* pInterface = ((CVehicleSAInterface * (__cdecl*)(int, CVector, std::uint8_t)) FUNC_CCarCtrlCreateCarForScript)(model, CVector(), 0);
84+
if (!pInterface)
85+
return nullptr;
8886

89-
// Valid model?
90-
if (!CModelInfoSA::IsVehicleModel(model))
91-
return nullptr;
87+
// Valid model?
88+
if (!CModelInfoSA::IsVehicleModel(model))
89+
return nullptr;
90+
91+
auto vehicleClass = static_cast<VehicleClass>(pGame->GetModelInfo(model)->GetVehicleType());
9292

93-
auto vehicleClass = static_cast<VehicleClass>(pGame->GetModelInfo(model)->GetVehicleType());
93+
std::unique_ptr<CVehicleSA> vehicle = nullptr;
9494

95-
std::unique_ptr<CVehicleSA> vehicle = nullptr;
95+
// Failed construct
96+
try
97+
{
9698
switch (vehicleClass)
9799
{
98100
case VehicleClass::MONSTER_TRUCK:
@@ -126,21 +128,21 @@ CVehicle* CPoolsSA::AddVehicle(CClientVehicle* pClientVehicle, std::uint16_t mod
126128
vehicle = std::make_unique<CAutomobileSA>(reinterpret_cast<CAutomobileSAInterface*>(pInterface));
127129
break;
128130
}
129-
130-
if (!vehicle || !AddVehicleToPool(pClientVehicle, vehicle.get()))
131-
return nullptr;
132-
133-
vehicle->m_ucVariant = variation;
134-
vehicle->m_ucVariant2 = variation2;
135-
136-
vehicle->DumpVehicleFrames();
137-
138-
return vehicle.release();
139131
}
140132
catch (...)
141133
{
142134
return nullptr;
143135
}
136+
137+
if (!vehicle || !AddVehicleToPool(pClientVehicle, vehicle.get()))
138+
return nullptr;
139+
140+
vehicle->m_ucVariant = variation;
141+
vehicle->m_ucVariant2 = variation2;
142+
143+
vehicle->DumpVehicleFrames();
144+
145+
return vehicle.release();
144146
}
145147

146148
void CPoolsSA::RemoveVehicle(CVehicle* pVehicle, bool bDelete)
@@ -577,16 +579,10 @@ CClientEntity* CPoolsSA::GetClientEntity(DWORD* pGameInterface)
577579
static void CreateMissionTrain(const CVector& vecPos, bool bDirection, std::uint32_t uiTrainType, CTrainSAInterface** ppTrainBeginning,
578580
CTrainSAInterface** ppTrainEnd, int iNodeIndex, int iTrackId, bool bMissionTrain) noexcept
579581
{
580-
try
581-
{
582-
auto createMissionTrain = reinterpret_cast<void(__cdecl*)(CVector, bool, std::uint32_t, CTrainSAInterface**, CTrainSAInterface**,
583-
int, int, bool)>(FUNC_CTrain_CreateMissionTrain);
582+
auto createMissionTrain = reinterpret_cast<void(__cdecl*)(CVector, bool, std::uint32_t, CTrainSAInterface**, CTrainSAInterface**,
583+
int, int, bool)>(FUNC_CTrain_CreateMissionTrain);
584584

585-
createMissionTrain(vecPos, bDirection, uiTrainType, ppTrainBeginning, ppTrainEnd, iNodeIndex, iTrackId, bMissionTrain);
586-
}
587-
catch (...)
588-
{
589-
}
585+
createMissionTrain(vecPos, bDirection, uiTrainType, ppTrainBeginning, ppTrainEnd, iNodeIndex, iTrackId, bMissionTrain);
590586
}
591587

592588
CVehicle* CPoolsSA::AddTrain(CClientVehicle* pClientVehicle, const CVector& vecPosition, std::vector<DWORD> models, bool bDirection,

Client/game_sa/CVehicleSA.cpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -301,22 +301,16 @@ CVehicleSA::~CVehicleSA()
301301

302302
void CVehicleSA::SetMoveSpeed(const CVector& vecMoveSpeed) noexcept
303303
{
304-
try
305-
{
306-
DWORD dwFunc = FUNC_GetMoveSpeed;
307-
DWORD dwThis = (DWORD)GetInterface();
308-
DWORD dwReturn = 0;
309-
_asm
310-
{
311-
mov ecx, dwThis
312-
call dwFunc
313-
mov dwReturn, eax
314-
}
315-
MemCpyFast((void*)dwReturn, &vecMoveSpeed, sizeof(CVector));
316-
}
317-
catch (...)
304+
DWORD dwFunc = FUNC_GetMoveSpeed;
305+
DWORD dwThis = (DWORD)GetInterface();
306+
DWORD dwReturn = 0;
307+
_asm
318308
{
309+
mov ecx, dwThis
310+
call dwFunc
311+
mov dwReturn, eax
319312
}
313+
MemCpyFast((void*)dwReturn, &vecMoveSpeed, sizeof(CVector));
320314

321315
// INACCURATE. Use Get/SetTrainSpeed instead of Get/SetMoveSpeed. (Causes issue #4829).
322316
#if 0

Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2890,16 +2890,16 @@ int CLuaVehicleDefs::GetVehicleHandling(lua_State* luaVM)
28902890

28912891
int CLuaVehicleDefs::GetOriginalHandling(lua_State* luaVM)
28922892
{
2893-
std::uint32_t uiModel;
2893+
std::uint32_t model;
28942894

28952895
CScriptArgReader argStream(luaVM);
2896-
argStream.ReadNumber(uiModel);
2896+
argStream.ReadNumber(model);
28972897

28982898
if (!argStream.HasErrors())
28992899
{
2900-
if (CClientVehicleManager::IsValidModel(uiModel))
2900+
if (CClientVehicleManager::IsValidModel(model))
29012901
{
2902-
if (const auto* const entry = g_pGame->GetHandlingManager()->GetOriginalHandlingData(uiModel))
2902+
if (const auto* const entry = g_pGame->GetHandlingManager()->GetOriginalHandlingData(model))
29032903
{
29042904
lua_newtable(luaVM);
29052905
lua_pushnumber(luaVM, entry->GetMass());

Client/sdk/game/CHandlingManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ class CHandlingManager
3434

3535
virtual eHandlingProperty GetPropertyEnumFromName(const std::string& name) const noexcept = 0;
3636

37-
virtual void CheckSuspensionChanges(const CHandlingEntry* const pEntry) const noexcept = 0;
37+
virtual void CheckSuspensionChanges(const CHandlingEntry* const entry) const noexcept = 0;
3838
};

Server/mods/deathmatch/logic/luadefs/CLuaHandlingDefs.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ int CLuaHandlingDefs::GetVehicleHandling(lua_State* luaVM)
616616
int CLuaHandlingDefs::GetModelHandling(lua_State* luaVM)
617617
{
618618
// table getModelHandling ( int modelId )
619-
std::uint16_t model;
619+
std::uint32_t model;
620620

621621
CScriptArgReader argStream(luaVM);
622622
argStream.ReadNumber(model);
@@ -787,7 +787,7 @@ int CLuaHandlingDefs::GetModelHandling(lua_State* luaVM)
787787
int CLuaHandlingDefs::GetOriginalHandling(lua_State* luaVM)
788788
{
789789
// table getOriginalHandling ( int modelID )
790-
std::uint16_t model;
790+
std::uint32_t model;
791791

792792
CScriptArgReader argStream(luaVM);
793793
argStream.ReadNumber(model);

0 commit comments

Comments
 (0)