From ed30bfb9ca79739d1825c6baeb7badea808e101e Mon Sep 17 00:00:00 2001 From: Inder00 Date: Thu, 6 Jan 2022 00:22:33 +0100 Subject: [PATCH 1/4] Don't restore default handling for server-sided vehicle changed their model on client-side That commit won't break any backwards compatibility. Changing the model for vehicles created on the server side resets the handling only if the vehicle is created locally (client - resets client handling, server - resets server handling). The problem was caused by the client not checking if the vehicle belongs to them (if it is local) and resetting the handling without checking. --- Client/mods/deathmatch/logic/CClientModel.cpp | 2 +- .../mods/deathmatch/logic/CClientVehicle.cpp | 45 ++++++++++--------- Client/mods/deathmatch/logic/CClientVehicle.h | 2 +- .../logic/CStaticFunctionDefinitions.cpp | 2 +- .../deathmatch/logic/rpc/CElementRPCs.cpp | 2 +- 5 files changed, 28 insertions(+), 25 deletions(-) diff --git a/Client/mods/deathmatch/logic/CClientModel.cpp b/Client/mods/deathmatch/logic/CClientModel.cpp index 6812bda39b..617f504352 100644 --- a/Client/mods/deathmatch/logic/CClientModel.cpp +++ b/Client/mods/deathmatch/logic/CClientModel.cpp @@ -137,7 +137,7 @@ void CClientModel::RestoreEntitiesUsingThisModel() unsigned short usParentID = g_pGame->GetModelInfo(m_iModelID)->GetParentID(); unloadModelsAndCallEvents(pVehicleManager->IterBegin(), pVehicleManager->IterEnd(), usParentID, - [=](auto& element) { element.SetModelBlocking(usParentID, 255, 255); }); + [=](auto& element) { element.SetModelBlocking(usParentID, 255, 255, element.IsLocalEntity()); }); break; } } diff --git a/Client/mods/deathmatch/logic/CClientVehicle.cpp b/Client/mods/deathmatch/logic/CClientVehicle.cpp index 06b7f25e22..4aa2b7c604 100644 --- a/Client/mods/deathmatch/logic/CClientVehicle.cpp +++ b/Client/mods/deathmatch/logic/CClientVehicle.cpp @@ -1006,7 +1006,7 @@ void CClientVehicle::SetTurretRotation(float fHorizontal, float fVertical) m_fTurretVertical = fVertical; } -void CClientVehicle::SetModelBlocking(unsigned short usModel, unsigned char ucVariant, unsigned char ucVariant2) +void CClientVehicle::SetModelBlocking(unsigned short usModel, unsigned char ucVariant, unsigned char ucVariant2, bool restoreHandling) { // Different vehicle ID than we have now? if (m_usModel != usModel) @@ -1068,32 +1068,35 @@ void CClientVehicle::SetModelBlocking(unsigned short usModel, unsigned char ucVa m_ucMaxPassengers = CClientVehicleManager::GetMaxPassengerCount(usModel); // Reset handling to fit the vehicle - ushort usHandlingModelID = usModel; - if (usHandlingModelID < 400 || usHandlingModelID > 611) - usHandlingModelID = m_pModelInfo->GetParentID(); + if (restoreHandling) + { + ushort usHandlingModelID = usModel; + if (usHandlingModelID < 400 || usHandlingModelID > 611) + usHandlingModelID = m_pModelInfo->GetParentID(); - m_pOriginalHandlingEntry = g_pGame->GetHandlingManager()->GetOriginalHandlingData((eVehicleTypes)usHandlingModelID); - m_pHandlingEntry->Assign(m_pOriginalHandlingEntry); + m_pOriginalHandlingEntry = g_pGame->GetHandlingManager()->GetOriginalHandlingData((eVehicleTypes)usHandlingModelID); + m_pHandlingEntry->Assign(m_pOriginalHandlingEntry); - m_pOriginalFlyingHandlingEntry = g_pGame->GetHandlingManager()->GetOriginalFlyingHandlingData((eVehicleTypes)usHandlingModelID); - m_pFlyingHandlingEntry->Assign(m_pOriginalFlyingHandlingEntry); + m_pOriginalFlyingHandlingEntry = g_pGame->GetHandlingManager()->GetOriginalFlyingHandlingData((eVehicleTypes)usHandlingModelID); + m_pFlyingHandlingEntry->Assign(m_pOriginalFlyingHandlingEntry); - m_pOriginalBoatHandlingEntry = g_pGame->GetHandlingManager()->GetOriginalBoatHandlingData((eVehicleTypes)usHandlingModelID); - if (m_pOriginalBoatHandlingEntry) - { - if (!m_pBoatHandlingEntry) - m_pBoatHandlingEntry = g_pGame->GetHandlingManager()->CreateBoatHandlingData(); + m_pOriginalBoatHandlingEntry = g_pGame->GetHandlingManager()->GetOriginalBoatHandlingData((eVehicleTypes)usHandlingModelID); + if (m_pOriginalBoatHandlingEntry) + { + if (!m_pBoatHandlingEntry) + m_pBoatHandlingEntry = g_pGame->GetHandlingManager()->CreateBoatHandlingData(); - m_pBoatHandlingEntry->Assign(m_pOriginalBoatHandlingEntry); - } + m_pBoatHandlingEntry->Assign(m_pOriginalBoatHandlingEntry); + } - m_pOriginalBikeHandlingEntry = g_pGame->GetHandlingManager()->GetOriginalBikeHandlingData((eVehicleTypes)usHandlingModelID); - if (m_pOriginalBikeHandlingEntry) - { - if (!m_pBikeHandlingEntry) - m_pBikeHandlingEntry = g_pGame->GetHandlingManager()->CreateBikeHandlingData(); + m_pOriginalBikeHandlingEntry = g_pGame->GetHandlingManager()->GetOriginalBikeHandlingData((eVehicleTypes)usHandlingModelID); + if (m_pOriginalBikeHandlingEntry) + { + if (!m_pBikeHandlingEntry) + m_pBikeHandlingEntry = g_pGame->GetHandlingManager()->CreateBikeHandlingData(); - m_pBikeHandlingEntry->Assign(m_pOriginalBikeHandlingEntry); + m_pBikeHandlingEntry->Assign(m_pOriginalBikeHandlingEntry); + } } ApplyHandling(); diff --git a/Client/mods/deathmatch/logic/CClientVehicle.h b/Client/mods/deathmatch/logic/CClientVehicle.h index 3c60977e04..331f155c5b 100644 --- a/Client/mods/deathmatch/logic/CClientVehicle.h +++ b/Client/mods/deathmatch/logic/CClientVehicle.h @@ -229,7 +229,7 @@ class CClientVehicle : public CClientStreamElement void SetTurretRotation(float fHorizontal, float fVertical); unsigned short GetModel() { return m_usModel; }; - void SetModelBlocking(unsigned short usModel, unsigned char ucVariant, unsigned char ucVariant2); + void SetModelBlocking(unsigned short usModel, unsigned char ucVariant, unsigned char ucVariant2, bool restoreHandling); unsigned char GetVariant() { return m_ucVariation; }; unsigned char GetVariant2() { return m_ucVariation2; }; diff --git a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index df0dffb8c5..113e2276f1 100644 --- a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -1504,7 +1504,7 @@ bool CStaticFunctionDefinitions::SetElementModel(CClientEntity& Entity, unsigned if (!CClientVehicleManager::IsValidModel(usModel)) return false; - Vehicle.SetModelBlocking(usModel, 255, 255); + Vehicle.SetModelBlocking(usModel, 255, 255, Entity.IsLocalEntity()); CLuaArguments Arguments; Arguments.PushNumber(usCurrentModel); diff --git a/Client/mods/deathmatch/logic/rpc/CElementRPCs.cpp b/Client/mods/deathmatch/logic/rpc/CElementRPCs.cpp index 1b5da5c780..95c9c44473 100644 --- a/Client/mods/deathmatch/logic/rpc/CElementRPCs.cpp +++ b/Client/mods/deathmatch/logic/rpc/CElementRPCs.cpp @@ -474,7 +474,7 @@ void CElementRPCs::SetElementModel(CClientEntity* pSource, NetBitStreamInterface if (usCurrentModel != usModel) { - pVehicle->SetModelBlocking(usModel, ucVariant, ucVariant2); + pVehicle->SetModelBlocking(usModel, ucVariant, ucVariant2, true); CLuaArguments Arguments; Arguments.PushNumber(usCurrentModel); From 26793c38e9755da9f46102b4dddf73736efe7874 Mon Sep 17 00:00:00 2001 From: Inder00 Date: Sun, 16 Oct 2022 18:19:28 +0200 Subject: [PATCH 2/4] Fixes --- Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index 113e2276f1..451254de9c 100644 --- a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -1518,7 +1518,7 @@ bool CStaticFunctionDefinitions::SetElementModel(CClientEntity& Entity, unsigned if (!bContinue) { // Change canceled - Vehicle.SetModelBlocking(usCurrentModel, 255, 255); + Vehicle.SetModelBlocking(usCurrentModel, 255, 255, Entity.IsLocalEntity()); return false; } From 97b648999e06e06a3b590ed3f17a1e81e649a259 Mon Sep 17 00:00:00 2001 From: Inder00 Date: Fri, 2 Dec 2022 23:33:19 +0100 Subject: [PATCH 3/4] Remove unnecessary "restoreHandling" param and use IsLocalEntity instead --- Client/mods/deathmatch/logic/CClientModel.cpp | 2 +- Client/mods/deathmatch/logic/CClientVehicle.cpp | 4 ++-- Client/mods/deathmatch/logic/CClientVehicle.h | 2 +- Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp | 4 ++-- Client/mods/deathmatch/logic/rpc/CElementRPCs.cpp | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Client/mods/deathmatch/logic/CClientModel.cpp b/Client/mods/deathmatch/logic/CClientModel.cpp index 617f504352..6812bda39b 100644 --- a/Client/mods/deathmatch/logic/CClientModel.cpp +++ b/Client/mods/deathmatch/logic/CClientModel.cpp @@ -137,7 +137,7 @@ void CClientModel::RestoreEntitiesUsingThisModel() unsigned short usParentID = g_pGame->GetModelInfo(m_iModelID)->GetParentID(); unloadModelsAndCallEvents(pVehicleManager->IterBegin(), pVehicleManager->IterEnd(), usParentID, - [=](auto& element) { element.SetModelBlocking(usParentID, 255, 255, element.IsLocalEntity()); }); + [=](auto& element) { element.SetModelBlocking(usParentID, 255, 255); }); break; } } diff --git a/Client/mods/deathmatch/logic/CClientVehicle.cpp b/Client/mods/deathmatch/logic/CClientVehicle.cpp index 4aa2b7c604..253d3252bf 100644 --- a/Client/mods/deathmatch/logic/CClientVehicle.cpp +++ b/Client/mods/deathmatch/logic/CClientVehicle.cpp @@ -1006,7 +1006,7 @@ void CClientVehicle::SetTurretRotation(float fHorizontal, float fVertical) m_fTurretVertical = fVertical; } -void CClientVehicle::SetModelBlocking(unsigned short usModel, unsigned char ucVariant, unsigned char ucVariant2, bool restoreHandling) +void CClientVehicle::SetModelBlocking(unsigned short usModel, unsigned char ucVariant, unsigned char ucVariant2) { // Different vehicle ID than we have now? if (m_usModel != usModel) @@ -1068,7 +1068,7 @@ void CClientVehicle::SetModelBlocking(unsigned short usModel, unsigned char ucVa m_ucMaxPassengers = CClientVehicleManager::GetMaxPassengerCount(usModel); // Reset handling to fit the vehicle - if (restoreHandling) + if (IsLocalEntity()) { ushort usHandlingModelID = usModel; if (usHandlingModelID < 400 || usHandlingModelID > 611) diff --git a/Client/mods/deathmatch/logic/CClientVehicle.h b/Client/mods/deathmatch/logic/CClientVehicle.h index 331f155c5b..3c60977e04 100644 --- a/Client/mods/deathmatch/logic/CClientVehicle.h +++ b/Client/mods/deathmatch/logic/CClientVehicle.h @@ -229,7 +229,7 @@ class CClientVehicle : public CClientStreamElement void SetTurretRotation(float fHorizontal, float fVertical); unsigned short GetModel() { return m_usModel; }; - void SetModelBlocking(unsigned short usModel, unsigned char ucVariant, unsigned char ucVariant2, bool restoreHandling); + void SetModelBlocking(unsigned short usModel, unsigned char ucVariant, unsigned char ucVariant2); unsigned char GetVariant() { return m_ucVariation; }; unsigned char GetVariant2() { return m_ucVariation2; }; diff --git a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index 451254de9c..df0dffb8c5 100644 --- a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -1504,7 +1504,7 @@ bool CStaticFunctionDefinitions::SetElementModel(CClientEntity& Entity, unsigned if (!CClientVehicleManager::IsValidModel(usModel)) return false; - Vehicle.SetModelBlocking(usModel, 255, 255, Entity.IsLocalEntity()); + Vehicle.SetModelBlocking(usModel, 255, 255); CLuaArguments Arguments; Arguments.PushNumber(usCurrentModel); @@ -1518,7 +1518,7 @@ bool CStaticFunctionDefinitions::SetElementModel(CClientEntity& Entity, unsigned if (!bContinue) { // Change canceled - Vehicle.SetModelBlocking(usCurrentModel, 255, 255, Entity.IsLocalEntity()); + Vehicle.SetModelBlocking(usCurrentModel, 255, 255); return false; } diff --git a/Client/mods/deathmatch/logic/rpc/CElementRPCs.cpp b/Client/mods/deathmatch/logic/rpc/CElementRPCs.cpp index 95c9c44473..1b5da5c780 100644 --- a/Client/mods/deathmatch/logic/rpc/CElementRPCs.cpp +++ b/Client/mods/deathmatch/logic/rpc/CElementRPCs.cpp @@ -474,7 +474,7 @@ void CElementRPCs::SetElementModel(CClientEntity* pSource, NetBitStreamInterface if (usCurrentModel != usModel) { - pVehicle->SetModelBlocking(usModel, ucVariant, ucVariant2, true); + pVehicle->SetModelBlocking(usModel, ucVariant, ucVariant2); CLuaArguments Arguments; Arguments.PushNumber(usCurrentModel); From 5212eeb0494bbcb25811222eaccbd8129854225a Mon Sep 17 00:00:00 2001 From: Inder00 Date: Sun, 4 Dec 2022 01:16:28 +0100 Subject: [PATCH 4/4] Apply fixes for checking vehicle entity --- Client/mods/deathmatch/logic/CClientVehicle.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Client/mods/deathmatch/logic/CClientVehicle.cpp b/Client/mods/deathmatch/logic/CClientVehicle.cpp index 253d3252bf..a084a662ac 100644 --- a/Client/mods/deathmatch/logic/CClientVehicle.cpp +++ b/Client/mods/deathmatch/logic/CClientVehicle.cpp @@ -1068,7 +1068,7 @@ void CClientVehicle::SetModelBlocking(unsigned short usModel, unsigned char ucVa m_ucMaxPassengers = CClientVehicleManager::GetMaxPassengerCount(usModel); // Reset handling to fit the vehicle - if (IsLocalEntity()) + if (IsLocalEntity() || !(usModel < 400 || usModel > 611)) { ushort usHandlingModelID = usModel; if (usHandlingModelID < 400 || usHandlingModelID > 611)