Skip to content

Commit

Permalink
Fix Hydraulics stops working when using setVehicleHandling with playe…
Browse files Browse the repository at this point in the history
…r inside vehicle (multitheftauto#3647)
  • Loading branch information
FileEX authored Oct 3, 2024
1 parent 9f579f3 commit f968363
Showing 1 changed file with 38 additions and 35 deletions.
73 changes: 38 additions & 35 deletions Client/game_sa/CVehicleSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 (std::int16_t& upgrade : GetVehicleInterface()->m_upgrades)
{
if (upgrade == dwModelID)
{
upgrade = -1;
break;
}
}
}

bool CVehicleSA::DoesSupportUpgrade(const SString& strFrameName)
Expand Down Expand Up @@ -1322,49 +1333,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 = 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 (const 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();
Expand Down

0 comments on commit f968363

Please sign in to comment.