Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 43 additions & 49 deletions Client/game_sa/CHandlingManagerSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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();
}
6 changes: 3 additions & 3 deletions Client/game_sa/CHandlingManagerSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
20 changes: 3 additions & 17 deletions Client/game_sa/CModelInfoSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
32 changes: 13 additions & 19 deletions Client/game_sa/CPhysicalSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
64 changes: 30 additions & 34 deletions Client/game_sa/CPoolsSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<VehicleClass>(pGame->GetModelInfo(model)->GetVehicleType());

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

std::unique_ptr<CVehicleSA> vehicle = nullptr;
// Failed construct
try
{
switch (vehicleClass)
{
case VehicleClass::MONSTER_TRUCK:
Expand Down Expand Up @@ -126,21 +128,21 @@ CVehicle* CPoolsSA::AddVehicle(CClientVehicle* pClientVehicle, std::uint16_t mod
vehicle = std::make_unique<CAutomobileSA>(reinterpret_cast<CAutomobileSAInterface*>(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)
Expand Down Expand Up @@ -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<void(__cdecl*)(CVector, bool, std::uint32_t, CTrainSAInterface**, CTrainSAInterface**,
int, int, bool)>(FUNC_CTrain_CreateMissionTrain);
auto createMissionTrain = reinterpret_cast<void(__cdecl*)(CVector, bool, std::uint32_t, CTrainSAInterface**, CTrainSAInterface**,
int, int, bool)>(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<DWORD> models, bool bDirection,
Expand Down
22 changes: 8 additions & 14 deletions Client/game_sa/CVehicleSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions Client/mods/deathmatch/logic/luadefs/CLuaVehicleDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion Client/sdk/game/CHandlingManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
4 changes: 2 additions & 2 deletions Server/mods/deathmatch/logic/luadefs/CLuaHandlingDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Loading