From 8e1b3e5d920110a467a1eb4321e39bc27b91ed83 Mon Sep 17 00:00:00 2001 From: FileEX Date: Fri, 16 Aug 2024 00:47:39 +0200 Subject: [PATCH 1/4] Fix old bug --- Client/game_sa/CVehicleSA.cpp | 62 +++++++++++++++-------------------- 1 file changed, 27 insertions(+), 35 deletions(-) diff --git a/Client/game_sa/CVehicleSA.cpp b/Client/game_sa/CVehicleSA.cpp index 91fb5440e0..9a0dbe5c54 100644 --- a/Client/game_sa/CVehicleSA.cpp +++ b/Client/game_sa/CVehicleSA.cpp @@ -1322,49 +1322,41 @@ void CVehicleSA::RecalculateHandling() // Put it in our interface CVehicleSAInterface* pInt = GetVehicleInterface(); unsigned int uiHandlingFlags = m_pHandlingData->GetInterface()->uiHandlingFlags; - // user error correction - NOS_INST = NOS Installed t/f - // if nos is installed we need the flag set - if (pInt->m_upgrades[0] && pInt->m_upgrades[0] >= 1008 && pInt->m_upgrades[0] <= 1010) + bool hydralicsInstalled, nitroInstalled; + + // We check whether the user has not set incorrect flags via handlingFlags in the case of nitro and hydraulics + // If this happened, we need to correct it + for (std::int16_t upgradeID : pInt->m_upgrades) { - // Flag not enabled? - if (uiHandlingFlags | HANDLING_NOS_Flag) + // Empty upgrades value is -1 + if (upgradeID < 0) + continue; + + // If NOS is installed we need set the flag + if ((upgradeID >= 1008 && upgradeID <= 1010) && uiHandlingFlags | HANDLING_NOS_Flag) { - // Set zee flag uiHandlingFlags |= HANDLING_NOS_Flag; - m_pHandlingData->SetHandlingFlags(uiHandlingFlags); - } - } - else - { - // Flag Enabled? - if (uiHandlingFlags & HANDLING_NOS_Flag) - { - // Unset the flag - uiHandlingFlags &= ~HANDLING_NOS_Flag; - m_pHandlingData->SetHandlingFlags(uiHandlingFlags); + nitroInstalled = true; } - } - // Hydraulics Flag fixing - if (pInt->m_upgrades[1] && pInt->m_upgrades[1] == 1087) - { - // Flag not enabled? - if (uiHandlingFlags | HANDLING_Hydraulics_Flag) + + // If hydraulics is installed we need set the flag + if (upgradeID == 1087 && uiHandlingFlags | HANDLING_Hydraulics_Flag) { - // Set zee flag uiHandlingFlags |= HANDLING_Hydraulics_Flag; - m_pHandlingData->SetHandlingFlags(uiHandlingFlags); - } - } - else - { - // Flag Enabled? - if (uiHandlingFlags & HANDLING_Hydraulics_Flag) - { - // Unset the flag - uiHandlingFlags &= ~HANDLING_Hydraulics_Flag; - m_pHandlingData->SetHandlingFlags(uiHandlingFlags); + hydralicsInstalled = true; } } + + // If hydraulics isn't installed we need unset the flag + if (!hydralicsInstalled && uiHandlingFlags & HANDLING_Hydraulics_Flag) + uiHandlingFlags &= ~HANDLING_Hydraulics_Flag; + + // If NOS isn't installed we need unset the flag + if (!nitroInstalled && uiHandlingFlags & HANDLING_NOS_Flag) + uiHandlingFlags &= ~HANDLING_NOS_Flag; + + m_pHandlingData->SetHandlingFlags(uiHandlingFlags); + pInt->dwHandlingFlags = uiHandlingFlags; pInt->m_fMass = m_pHandlingData->GetInterface()->fMass; pInt->m_fTurnMass = m_pHandlingData->GetInterface()->fTurnMass; // * pGame->GetHandlingManager()->GetTurnMassMultiplier(); From 9c394954e01b440559cc227f27a898af77b16d4a Mon Sep 17 00:00:00 2001 From: FileEX Date: Fri, 16 Aug 2024 14:14:29 +0200 Subject: [PATCH 2/4] Fix another related issue --- Client/game_sa/CVehicleSA.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Client/game_sa/CVehicleSA.cpp b/Client/game_sa/CVehicleSA.cpp index 9a0dbe5c54..d55261a659 100644 --- a/Client/game_sa/CVehicleSA.cpp +++ b/Client/game_sa/CVehicleSA.cpp @@ -684,6 +684,17 @@ void CVehicleSA::RemoveVehicleUpgrade(DWORD dwModelID) push dwModelID call dwFunc } + + // GTA SA only does this when CVehicle::ClearVehicleUpgradeFlags returns false. + // In the case of hydraulics and nitro, this function does not return false and the upgrade is never removed from the array + for (auto& upgrade : GetVehicleInterface()->m_upgrades) + { + if (upgrade == dwModelID) + { + upgrade = -1; + break; + } + } } bool CVehicleSA::DoesSupportUpgrade(const SString& strFrameName) @@ -1326,7 +1337,7 @@ void CVehicleSA::RecalculateHandling() // We check whether the user has not set incorrect flags via handlingFlags in the case of nitro and hydraulics // If this happened, we need to correct it - for (std::int16_t upgradeID : pInt->m_upgrades) + for (auto& upgradeID : pInt->m_upgrades) { // Empty upgrades value is -1 if (upgradeID < 0) From cb8faf4d690b252640ff345992f006adb6e67b5e Mon Sep 17 00:00:00 2001 From: FileEX Date: Sat, 17 Aug 2024 14:18:12 +0200 Subject: [PATCH 3/4] Review --- Client/game_sa/CVehicleSA.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Client/game_sa/CVehicleSA.cpp b/Client/game_sa/CVehicleSA.cpp index d55261a659..1ce841549e 100644 --- a/Client/game_sa/CVehicleSA.cpp +++ b/Client/game_sa/CVehicleSA.cpp @@ -687,7 +687,7 @@ void CVehicleSA::RemoveVehicleUpgrade(DWORD dwModelID) // GTA SA only does this when CVehicle::ClearVehicleUpgradeFlags returns false. // In the case of hydraulics and nitro, this function does not return false and the upgrade is never removed from the array - for (auto& upgrade : GetVehicleInterface()->m_upgrades) + for (std::int16_t upgrade : GetVehicleInterface()->m_upgrades) { if (upgrade == dwModelID) { @@ -1333,25 +1333,25 @@ void CVehicleSA::RecalculateHandling() // Put it in our interface CVehicleSAInterface* pInt = GetVehicleInterface(); unsigned int uiHandlingFlags = m_pHandlingData->GetInterface()->uiHandlingFlags; - bool hydralicsInstalled, nitroInstalled; + bool hydralicsInstalled = false, nitroInstalled = false; // We check whether the user has not set incorrect flags via handlingFlags in the case of nitro and hydraulics // If this happened, we need to correct it - for (auto& upgradeID : pInt->m_upgrades) + for (const std::int16_t upgradeID : pInt->m_upgrades) { // Empty upgrades value is -1 if (upgradeID < 0) continue; // If NOS is installed we need set the flag - if ((upgradeID >= 1008 && upgradeID <= 1010) && uiHandlingFlags | HANDLING_NOS_Flag) + if ((upgradeID >= 1008 && upgradeID <= 1010) && (uiHandlingFlags | HANDLING_NOS_Flag)) { uiHandlingFlags |= HANDLING_NOS_Flag; nitroInstalled = true; } // If hydraulics is installed we need set the flag - if (upgradeID == 1087 && uiHandlingFlags | HANDLING_Hydraulics_Flag) + if ((upgradeID == 1087) && (uiHandlingFlags | HANDLING_Hydraulics_Flag)) { uiHandlingFlags |= HANDLING_Hydraulics_Flag; hydralicsInstalled = true; @@ -1359,11 +1359,11 @@ void CVehicleSA::RecalculateHandling() } // If hydraulics isn't installed we need unset the flag - if (!hydralicsInstalled && uiHandlingFlags & HANDLING_Hydraulics_Flag) + if ((!hydralicsInstalled) && (uiHandlingFlags & HANDLING_Hydraulics_Flag)) uiHandlingFlags &= ~HANDLING_Hydraulics_Flag; // If NOS isn't installed we need unset the flag - if (!nitroInstalled && uiHandlingFlags & HANDLING_NOS_Flag) + if ((!nitroInstalled) && (uiHandlingFlags & HANDLING_NOS_Flag)) uiHandlingFlags &= ~HANDLING_NOS_Flag; m_pHandlingData->SetHandlingFlags(uiHandlingFlags); From bab1c8de01d7dd0c9985ef1a2f8eb230a05294e9 Mon Sep 17 00:00:00 2001 From: FileEX Date: Sat, 17 Aug 2024 16:29:14 +0200 Subject: [PATCH 4/4] Fix flags checking --- Client/game_sa/CVehicleSA.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Client/game_sa/CVehicleSA.cpp b/Client/game_sa/CVehicleSA.cpp index 1ce841549e..ab1635c91d 100644 --- a/Client/game_sa/CVehicleSA.cpp +++ b/Client/game_sa/CVehicleSA.cpp @@ -687,7 +687,7 @@ void CVehicleSA::RemoveVehicleUpgrade(DWORD dwModelID) // GTA SA only does this when CVehicle::ClearVehicleUpgradeFlags returns false. // In the case of hydraulics and nitro, this function does not return false and the upgrade is never removed from the array - for (std::int16_t upgrade : GetVehicleInterface()->m_upgrades) + for (std::int16_t& upgrade : GetVehicleInterface()->m_upgrades) { if (upgrade == dwModelID) { @@ -1337,21 +1337,21 @@ void CVehicleSA::RecalculateHandling() // We check whether the user has not set incorrect flags via handlingFlags in the case of nitro and hydraulics // If this happened, we need to correct it - for (const std::int16_t upgradeID : pInt->m_upgrades) + for (const std::int16_t& upgradeID : pInt->m_upgrades) { // Empty upgrades value is -1 if (upgradeID < 0) continue; // If NOS is installed we need set the flag - if ((upgradeID >= 1008 && upgradeID <= 1010) && (uiHandlingFlags | HANDLING_NOS_Flag)) + if ((upgradeID >= 1008 && upgradeID <= 1010) && !(uiHandlingFlags & HANDLING_NOS_Flag)) { uiHandlingFlags |= HANDLING_NOS_Flag; nitroInstalled = true; } // If hydraulics is installed we need set the flag - if ((upgradeID == 1087) && (uiHandlingFlags | HANDLING_Hydraulics_Flag)) + if ((upgradeID == 1087) && !(uiHandlingFlags & HANDLING_Hydraulics_Flag)) { uiHandlingFlags |= HANDLING_Hydraulics_Flag; hydralicsInstalled = true;