diff --git a/Client/game_sa/CHandlingManagerSA.cpp b/Client/game_sa/CHandlingManagerSA.cpp index d967bec9680..98660656231 100644 --- a/Client/game_sa/CHandlingManagerSA.cpp +++ b/Client/game_sa/CHandlingManagerSA.cpp @@ -274,7 +274,7 @@ const CBikeHandlingEntry* CHandlingManagerSA::GetOriginalBikeHandlingData(std::u } // Return the handling manager id -eHandlingTypes CHandlingManagerSA::GetHandlingID(std::uint32_t model) const noexcept +eHandlingTypes CHandlingManagerSA::GetHandlingID(std::uint32_t model) noexcept { switch (model) { @@ -9125,53 +9125,47 @@ void CHandlingManagerSA::InitializeDefaultHandlings() noexcept m_OriginalBikeHandlingData[13].iVehicleID = 214; } -void CHandlingManagerSA::CheckSuspensionChanges(const CHandlingEntry* const pEntry) const noexcept +void CHandlingManagerSA::CheckSuspensionChanges(const CHandlingEntry* const entry) const noexcept { - try - { - // Valid? - if (!pEntry) - return; - - // Grab us a multiplayer_sa pointer - const CMultiplayer* const pMultiplayer = g_pCore->GetMultiplayer(); - if (!pMultiplayer) - return; - - // Get Handling ID - const eHandlingTypes eHandling = pEntry->GetVehicleID(); - if (eHandling >= HT_MAX) - return; - - const auto& entries = m_OriginalEntries[eHandling]; - if (!entries) - return; - - // Default bChanged to false - bool bChanged = false; - - // Set bChanged to true if we find ANY change. - if (pEntry->GetSuspensionAntiDiveMultiplier() != entries->GetSuspensionAntiDiveMultiplier()) - bChanged = true; - else if (pEntry->GetSuspensionDamping() != entries->GetSuspensionDamping()) - bChanged = true; - else if (pEntry->GetSuspensionForceLevel() != entries->GetSuspensionForceLevel()) - bChanged = true; - else if (pEntry->GetSuspensionFrontRearBias() != entries->GetSuspensionFrontRearBias()) - bChanged = true; - else if (pEntry->GetSuspensionHighSpeedDamping() != entries->GetSuspensionHighSpeedDamping()) - bChanged = true; - else if (pEntry->GetSuspensionLowerLimit() != entries->GetSuspensionLowerLimit()) - bChanged = true; - else if (pEntry->GetSuspensionUpperLimit() != entries->GetSuspensionUpperLimit()) - bChanged = true; - - if (!bChanged) - return; - - pMultiplayer->UpdateVehicleSuspension(); - } - catch (...) - { - } + // Valid? + if (!entry) + return; + + // Grab us a multiplayer pointer + const CMultiplayer* const multiplayer = g_pCore->GetMultiplayer(); + if (!multiplayer) + return; + + // Get handling type + const eHandlingTypes handlingType = entry->GetVehicleID(); + if (handlingType >= HT_MAX) + return; + + const auto& entries = m_OriginalEntries[handlingType]; + if (!entries) + return; + + // Not changed default + bool isChanged = false; + + // Find changes + if (entry->GetSuspensionAntiDiveMultiplier() != entries->GetSuspensionAntiDiveMultiplier()) + isChanged = true; + else if (entry->GetSuspensionDamping() != entries->GetSuspensionDamping()) + isChanged = true; + else if (entry->GetSuspensionForceLevel() != entries->GetSuspensionForceLevel()) + isChanged = true; + else if (entry->GetSuspensionFrontRearBias() != entries->GetSuspensionFrontRearBias()) + isChanged = true; + else if (entry->GetSuspensionHighSpeedDamping() != entries->GetSuspensionHighSpeedDamping()) + isChanged = true; + else if (entry->GetSuspensionLowerLimit() != entries->GetSuspensionLowerLimit()) + isChanged = true; + else if (entry->GetSuspensionUpperLimit() != entries->GetSuspensionUpperLimit()) + isChanged = true; + + if (!isChanged) + return; + + multiplayer->UpdateVehicleSuspension(); } diff --git a/Client/game_sa/CHandlingManagerSA.h b/Client/game_sa/CHandlingManagerSA.h index d27ec2459f6..f40df598a6a 100644 --- a/Client/game_sa/CHandlingManagerSA.h +++ b/Client/game_sa/CHandlingManagerSA.h @@ -35,10 +35,10 @@ class CHandlingManagerSA : public CHandlingManager eHandlingProperty GetPropertyEnumFromName(const std::string& name) const noexcept; - void CheckSuspensionChanges(const CHandlingEntry* const pEntry) const noexcept; + void CheckSuspensionChanges(const CHandlingEntry* const entry) const noexcept; + + static eHandlingTypes GetHandlingID(std::uint32_t model) noexcept; private: void InitializeDefaultHandlings() noexcept; - - eHandlingTypes GetHandlingID(std::uint32_t uiModel) const noexcept; }; diff --git a/Client/game_sa/CModelInfoSA.cpp b/Client/game_sa/CModelInfoSA.cpp index 1c9e4ed4bfc..8f1b624b906 100644 --- a/Client/game_sa/CModelInfoSA.cpp +++ b/Client/game_sa/CModelInfoSA.cpp @@ -296,15 +296,8 @@ bool CModelInfoSA::IsVehicle() const bool CModelInfoSA::IsVehicleModel(std::uint32_t model) noexcept { - try - { - const auto* const modelInfo = pGame->GetModelInfo(model); - return modelInfo && modelInfo->IsVehicle(); - } - catch (...) - { - return false; - } + const auto* const modelInfo = pGame->GetModelInfo(model); + return modelInfo && modelInfo->IsVehicle(); } bool CModelInfoSA::IsPlayerModel() @@ -766,14 +759,7 @@ bool CModelInfoSA::IsValid() bool CModelInfoSA::IsAllocatedInArchive() const noexcept { - try - { - return pGame->GetStreaming()->GetStreamingInfo(m_dwModelID)->sizeInBlocks > 0; - } - catch (...) - { - return false; - } + return pGame->GetStreaming()->GetStreamingInfo(m_dwModelID)->sizeInBlocks > 0; } float CModelInfoSA::GetDistanceFromCentreOfMassToBaseOfModel() diff --git a/Client/game_sa/CPhysicalSA.cpp b/Client/game_sa/CPhysicalSA.cpp index ec05a42225b..5caae9e9e8e 100644 --- a/Client/game_sa/CPhysicalSA.cpp +++ b/Client/game_sa/CPhysicalSA.cpp @@ -102,28 +102,22 @@ CVector* CPhysicalSA::GetTurnSpeedInternal(CVector* vecTurnSpeed) void CPhysicalSA::SetMoveSpeed(const CVector& vecMoveSpeed) noexcept { - try + DWORD dwFunc = FUNC_GetMoveSpeed; + DWORD dwThis = (DWORD)((CPhysicalSAInterface*)GetInterface()); + DWORD dwReturn = 0; + + __asm { - DWORD dwFunc = FUNC_GetMoveSpeed; - DWORD dwThis = (DWORD)((CPhysicalSAInterface*)GetInterface()); - DWORD dwReturn = 0; - - __asm - { - mov ecx, dwThis - call dwFunc - mov dwReturn, eax - } - MemCpyFast((void*)dwReturn, &vecMoveSpeed, sizeof(CVector)); - - if (GetInterface()->nType == ENTITY_TYPE_OBJECT) - { - AddToMovingList(); - SetStatic(false); - } + mov ecx, dwThis + call dwFunc + mov dwReturn, eax } - catch (...) + MemCpyFast((void*)dwReturn, &vecMoveSpeed, sizeof(CVector)); + + if (GetInterface()->nType == ENTITY_TYPE_OBJECT) { + AddToMovingList(); + SetStatic(false); } } diff --git a/Client/game_sa/CPoolsSA.cpp b/Client/game_sa/CPoolsSA.cpp index d5f86f6feaf..2ed82f491eb 100644 --- a/Client/game_sa/CPoolsSA.cpp +++ b/Client/game_sa/CPoolsSA.cpp @@ -73,26 +73,28 @@ inline bool CPoolsSA::AddVehicleToPool(CClientVehicle* pClientVehicle, CVehicleS CVehicle* CPoolsSA::AddVehicle(CClientVehicle* pClientVehicle, std::uint16_t model, std::uint8_t variation, std::uint8_t variation2) noexcept { - try - { - if (m_vehiclePool.ulCount >= MAX_VEHICLES) - return nullptr; + if (m_vehiclePool.ulCount >= MAX_VEHICLES) + return nullptr; - MemSetFast((void*)VAR_CVehicle_Variation1, variation, 1); - MemSetFast((void*)VAR_CVehicle_Variation2, variation2, 1); + MemSetFast((void*)VAR_CVehicle_Variation1, variation, 1); + MemSetFast((void*)VAR_CVehicle_Variation2, variation2, 1); - // CCarCtrl::CreateCarForScript - auto* pInterface = ((CVehicleSAInterface*(__cdecl*)(int, CVector, std::uint8_t))FUNC_CCarCtrlCreateCarForScript)(model, CVector(), 0); - if (!pInterface) - return nullptr; + // CCarCtrl::CreateCarForScript + auto* pInterface = ((CVehicleSAInterface * (__cdecl*)(int, CVector, std::uint8_t)) FUNC_CCarCtrlCreateCarForScript)(model, CVector(), 0); + if (!pInterface) + return nullptr; - // Valid model? - if (!CModelInfoSA::IsVehicleModel(model)) - return nullptr; + // Valid model? + if (!CModelInfoSA::IsVehicleModel(model)) + return nullptr; + + auto vehicleClass = static_cast(pGame->GetModelInfo(model)->GetVehicleType()); - auto vehicleClass = static_cast(pGame->GetModelInfo(model)->GetVehicleType()); + std::unique_ptr vehicle = nullptr; - std::unique_ptr vehicle = nullptr; + // Failed construct + try + { switch (vehicleClass) { case VehicleClass::MONSTER_TRUCK: @@ -126,21 +128,21 @@ CVehicle* CPoolsSA::AddVehicle(CClientVehicle* pClientVehicle, std::uint16_t mod vehicle = std::make_unique(reinterpret_cast(pInterface)); break; } - - if (!vehicle || !AddVehicleToPool(pClientVehicle, vehicle.get())) - return nullptr; - - vehicle->m_ucVariant = variation; - vehicle->m_ucVariant2 = variation2; - - vehicle->DumpVehicleFrames(); - - return vehicle.release(); } catch (...) { return nullptr; } + + if (!vehicle || !AddVehicleToPool(pClientVehicle, vehicle.get())) + return nullptr; + + vehicle->m_ucVariant = variation; + vehicle->m_ucVariant2 = variation2; + + vehicle->DumpVehicleFrames(); + + return vehicle.release(); } void CPoolsSA::RemoveVehicle(CVehicle* pVehicle, bool bDelete) @@ -577,16 +579,10 @@ CClientEntity* CPoolsSA::GetClientEntity(DWORD* pGameInterface) static void CreateMissionTrain(const CVector& vecPos, bool bDirection, std::uint32_t uiTrainType, CTrainSAInterface** ppTrainBeginning, CTrainSAInterface** ppTrainEnd, int iNodeIndex, int iTrackId, bool bMissionTrain) noexcept { - try - { - auto createMissionTrain = reinterpret_cast(FUNC_CTrain_CreateMissionTrain); + auto createMissionTrain = reinterpret_cast(FUNC_CTrain_CreateMissionTrain); - createMissionTrain(vecPos, bDirection, uiTrainType, ppTrainBeginning, ppTrainEnd, iNodeIndex, iTrackId, bMissionTrain); - } - catch (...) - { - } + createMissionTrain(vecPos, bDirection, uiTrainType, ppTrainBeginning, ppTrainEnd, iNodeIndex, iTrackId, bMissionTrain); } CVehicle* CPoolsSA::AddTrain(CClientVehicle* pClientVehicle, const CVector& vecPosition, std::vector models, bool bDirection, diff --git a/Client/game_sa/CVehicleSA.cpp b/Client/game_sa/CVehicleSA.cpp index 898add2961f..e397be884a0 100644 --- a/Client/game_sa/CVehicleSA.cpp +++ b/Client/game_sa/CVehicleSA.cpp @@ -301,22 +301,16 @@ CVehicleSA::~CVehicleSA() void CVehicleSA::SetMoveSpeed(const CVector& vecMoveSpeed) noexcept { - try - { - DWORD dwFunc = FUNC_GetMoveSpeed; - DWORD dwThis = (DWORD)GetInterface(); - DWORD dwReturn = 0; - _asm - { - mov ecx, dwThis - call dwFunc - mov dwReturn, eax - } - MemCpyFast((void*)dwReturn, &vecMoveSpeed, sizeof(CVector)); - } - catch (...) + DWORD dwFunc = FUNC_GetMoveSpeed; + DWORD dwThis = (DWORD)GetInterface(); + DWORD dwReturn = 0; + _asm { + mov ecx, dwThis + call dwFunc + mov dwReturn, eax } + MemCpyFast((void*)dwReturn, &vecMoveSpeed, sizeof(CVector)); // INACCURATE. Use Get/SetTrainSpeed instead of Get/SetMoveSpeed. (Causes issue #4829). #if 0 diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp index 2c9fe673ad4..447a27d4be2 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp @@ -2890,16 +2890,16 @@ int CLuaVehicleDefs::GetVehicleHandling(lua_State* luaVM) int CLuaVehicleDefs::GetOriginalHandling(lua_State* luaVM) { - std::uint32_t uiModel; + std::uint32_t model; CScriptArgReader argStream(luaVM); - argStream.ReadNumber(uiModel); + argStream.ReadNumber(model); if (!argStream.HasErrors()) { - if (CClientVehicleManager::IsValidModel(uiModel)) + if (CClientVehicleManager::IsValidModel(model)) { - if (const auto* const entry = g_pGame->GetHandlingManager()->GetOriginalHandlingData(uiModel)) + if (const auto* const entry = g_pGame->GetHandlingManager()->GetOriginalHandlingData(model)) { lua_newtable(luaVM); lua_pushnumber(luaVM, entry->GetMass()); diff --git a/Client/sdk/game/CHandlingManager.h b/Client/sdk/game/CHandlingManager.h index d10e55c8af7..2191655137e 100644 --- a/Client/sdk/game/CHandlingManager.h +++ b/Client/sdk/game/CHandlingManager.h @@ -34,5 +34,5 @@ class CHandlingManager virtual eHandlingProperty GetPropertyEnumFromName(const std::string& name) const noexcept = 0; - virtual void CheckSuspensionChanges(const CHandlingEntry* const pEntry) const noexcept = 0; + virtual void CheckSuspensionChanges(const CHandlingEntry* const entry) const noexcept = 0; }; diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaHandlingDefs.cpp b/Server/mods/deathmatch/logic/luadefs/CLuaHandlingDefs.cpp index e30f6aa3e4e..68358e4d1f9 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaHandlingDefs.cpp +++ b/Server/mods/deathmatch/logic/luadefs/CLuaHandlingDefs.cpp @@ -616,7 +616,7 @@ int CLuaHandlingDefs::GetVehicleHandling(lua_State* luaVM) int CLuaHandlingDefs::GetModelHandling(lua_State* luaVM) { // table getModelHandling ( int modelId ) - std::uint16_t model; + std::uint32_t model; CScriptArgReader argStream(luaVM); argStream.ReadNumber(model); @@ -787,7 +787,7 @@ int CLuaHandlingDefs::GetModelHandling(lua_State* luaVM) int CLuaHandlingDefs::GetOriginalHandling(lua_State* luaVM) { // table getOriginalHandling ( int modelID ) - std::uint16_t model; + std::uint32_t model; CScriptArgReader argStream(luaVM); argStream.ReadNumber(model);