Skip to content

Commit f968363

Browse files
authored
Fix Hydraulics stops working when using setVehicleHandling with player inside vehicle (#3647)
1 parent 9f579f3 commit f968363

File tree

1 file changed

+38
-35
lines changed

1 file changed

+38
-35
lines changed

Client/game_sa/CVehicleSA.cpp

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,17 @@ void CVehicleSA::RemoveVehicleUpgrade(DWORD dwModelID)
684684
push dwModelID
685685
call dwFunc
686686
}
687+
688+
// GTA SA only does this when CVehicle::ClearVehicleUpgradeFlags returns false.
689+
// In the case of hydraulics and nitro, this function does not return false and the upgrade is never removed from the array
690+
for (std::int16_t& upgrade : GetVehicleInterface()->m_upgrades)
691+
{
692+
if (upgrade == dwModelID)
693+
{
694+
upgrade = -1;
695+
break;
696+
}
697+
}
687698
}
688699

689700
bool CVehicleSA::DoesSupportUpgrade(const SString& strFrameName)
@@ -1322,49 +1333,41 @@ void CVehicleSA::RecalculateHandling()
13221333
// Put it in our interface
13231334
CVehicleSAInterface* pInt = GetVehicleInterface();
13241335
unsigned int uiHandlingFlags = m_pHandlingData->GetInterface()->uiHandlingFlags;
1325-
// user error correction - NOS_INST = NOS Installed t/f
1326-
// if nos is installed we need the flag set
1327-
if (pInt->m_upgrades[0] && pInt->m_upgrades[0] >= 1008 && pInt->m_upgrades[0] <= 1010)
1336+
bool hydralicsInstalled = false, nitroInstalled = false;
1337+
1338+
// We check whether the user has not set incorrect flags via handlingFlags in the case of nitro and hydraulics
1339+
// If this happened, we need to correct it
1340+
for (const std::int16_t& upgradeID : pInt->m_upgrades)
13281341
{
1329-
// Flag not enabled?
1330-
if (uiHandlingFlags | HANDLING_NOS_Flag)
1342+
// Empty upgrades value is -1
1343+
if (upgradeID < 0)
1344+
continue;
1345+
1346+
// If NOS is installed we need set the flag
1347+
if ((upgradeID >= 1008 && upgradeID <= 1010) && !(uiHandlingFlags & HANDLING_NOS_Flag))
13311348
{
1332-
// Set zee flag
13331349
uiHandlingFlags |= HANDLING_NOS_Flag;
1334-
m_pHandlingData->SetHandlingFlags(uiHandlingFlags);
1335-
}
1336-
}
1337-
else
1338-
{
1339-
// Flag Enabled?
1340-
if (uiHandlingFlags & HANDLING_NOS_Flag)
1341-
{
1342-
// Unset the flag
1343-
uiHandlingFlags &= ~HANDLING_NOS_Flag;
1344-
m_pHandlingData->SetHandlingFlags(uiHandlingFlags);
1350+
nitroInstalled = true;
13451351
}
1346-
}
1347-
// Hydraulics Flag fixing
1348-
if (pInt->m_upgrades[1] && pInt->m_upgrades[1] == 1087)
1349-
{
1350-
// Flag not enabled?
1351-
if (uiHandlingFlags | HANDLING_Hydraulics_Flag)
1352+
1353+
// If hydraulics is installed we need set the flag
1354+
if ((upgradeID == 1087) && !(uiHandlingFlags & HANDLING_Hydraulics_Flag))
13521355
{
1353-
// Set zee flag
13541356
uiHandlingFlags |= HANDLING_Hydraulics_Flag;
1355-
m_pHandlingData->SetHandlingFlags(uiHandlingFlags);
1356-
}
1357-
}
1358-
else
1359-
{
1360-
// Flag Enabled?
1361-
if (uiHandlingFlags & HANDLING_Hydraulics_Flag)
1362-
{
1363-
// Unset the flag
1364-
uiHandlingFlags &= ~HANDLING_Hydraulics_Flag;
1365-
m_pHandlingData->SetHandlingFlags(uiHandlingFlags);
1357+
hydralicsInstalled = true;
13661358
}
13671359
}
1360+
1361+
// If hydraulics isn't installed we need unset the flag
1362+
if ((!hydralicsInstalled) && (uiHandlingFlags & HANDLING_Hydraulics_Flag))
1363+
uiHandlingFlags &= ~HANDLING_Hydraulics_Flag;
1364+
1365+
// If NOS isn't installed we need unset the flag
1366+
if ((!nitroInstalled) && (uiHandlingFlags & HANDLING_NOS_Flag))
1367+
uiHandlingFlags &= ~HANDLING_NOS_Flag;
1368+
1369+
m_pHandlingData->SetHandlingFlags(uiHandlingFlags);
1370+
13681371
pInt->dwHandlingFlags = uiHandlingFlags;
13691372
pInt->m_fMass = m_pHandlingData->GetInterface()->fMass;
13701373
pInt->m_fTurnMass = m_pHandlingData->GetInterface()->fTurnMass; // * pGame->GetHandlingManager()->GetTurnMassMultiplier();

0 commit comments

Comments
 (0)