From c709597ec36024a03357962743582cf12f6a1047 Mon Sep 17 00:00:00 2001 From: Proxy-99 <77501848+Proxy-99@users.noreply.github.com> Date: Fri, 14 Mar 2025 12:29:50 +0300 Subject: [PATCH 1/3] add function serverside --- Client/mods/deathmatch/logic/rpc/CElementRPCs.cpp | 13 +++++++++++++ Client/mods/deathmatch/logic/rpc/CElementRPCs.h | 1 + .../deathmatch/logic/CPerfStat.RPCPacketUsage.cpp | 1 + .../deathmatch/logic/CStaticFunctionDefinitions.cpp | 12 +++++++++++- .../deathmatch/logic/CStaticFunctionDefinitions.h | 1 + .../deathmatch/logic/luadefs/CLuaElementDefs.cpp | 6 ++++++ .../mods/deathmatch/logic/luadefs/CLuaElementDefs.h | 1 + Shared/sdk/net/rpc_enums.h | 2 ++ 8 files changed, 36 insertions(+), 1 deletion(-) diff --git a/Client/mods/deathmatch/logic/rpc/CElementRPCs.cpp b/Client/mods/deathmatch/logic/rpc/CElementRPCs.cpp index 65eca46286..d9509a4e89 100644 --- a/Client/mods/deathmatch/logic/rpc/CElementRPCs.cpp +++ b/Client/mods/deathmatch/logic/rpc/CElementRPCs.cpp @@ -50,6 +50,7 @@ void CElementRPCs::LoadFunctions() AddHandler(SET_PROPAGATE_CALLS_ENABLED, SetCallPropagationEnabled, "setCallPropagationEnabled"); AddHandler(SET_COLPOLYGON_HEIGHT, SetColPolygonHeight, "setColShapePolygonHeight"); AddHandler(SET_ELEMENT_ON_FIRE, SetElementOnFire, "setElementOnFire"); + AddHandler(SET_ELEMENT_COLLIDABLE_WITH, SetElementCollidableWith, "setElementCollidableWith"); } #define RUN_CHILDREN_SERVER(func) \ @@ -765,3 +766,15 @@ void CElementRPCs::SetElementOnFire(CClientEntity* pSource, NetBitStreamInterfac { pSource->SetOnFire(bitStream.ReadBit()); } + +void CElementRPCs::SetElementCollidableWith(CClientEntity* pSource, NetBitStreamInterface& bitStream) +{ + ElementID ElementID; + bool bCollidable; + + bitStream.Read(ElementID); + bitStream.ReadBit(bCollidable); + + CClientEntity* pCollidableWith = CElementIDs::GetElement(ElementID); + pSource->SetCollidableWith(pCollidableWith, bCollidable); +} diff --git a/Client/mods/deathmatch/logic/rpc/CElementRPCs.h b/Client/mods/deathmatch/logic/rpc/CElementRPCs.h index 7a0d1f6f5c..09e1a6ec23 100644 --- a/Client/mods/deathmatch/logic/rpc/CElementRPCs.h +++ b/Client/mods/deathmatch/logic/rpc/CElementRPCs.h @@ -51,4 +51,5 @@ class CElementRPCs : public CRPCFunctions DECLARE_ELEMENT_RPC(SetCallPropagationEnabled); DECLARE_ELEMENT_RPC(SetColPolygonHeight); DECLARE_ELEMENT_RPC(SetElementOnFire); + DECLARE_ELEMENT_RPC(SetElementCollidableWith); }; diff --git a/Server/mods/deathmatch/logic/CPerfStat.RPCPacketUsage.cpp b/Server/mods/deathmatch/logic/CPerfStat.RPCPacketUsage.cpp index f188cf4f50..ca721f513d 100644 --- a/Server/mods/deathmatch/logic/CPerfStat.RPCPacketUsage.cpp +++ b/Server/mods/deathmatch/logic/CPerfStat.RPCPacketUsage.cpp @@ -232,6 +232,7 @@ ADD_ENUM1(TOGGLE_OBJECT_RESPAWN) ADD_ENUM1(RESET_WORLD_PROPERTIES) ADD_ENUM1(SPAWN_VEHICLE_FLYING_COMPONENT) ADD_ENUM1(SET_ELEMENT_ON_FIRE) +ADD_ENUM1(SET_ELEMENT_COLLIDABLE_WITH) IMPLEMENT_ENUM_END("eElementRPCFunctions") DECLARE_ENUM(CRPCFunctions::eRPCFunctions); diff --git a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index 85963144ab..d4fd5d7a05 100644 --- a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -64,7 +64,6 @@ #include "packets/CChatEchoPacket.h" #include "packets/CConsoleEchoPacket.h" #include "packets/CChatClearPacket.h" -#include "packets/CElementRPCPacket.h" #include "version.h" #include @@ -12566,3 +12565,14 @@ bool CStaticFunctionDefinitions::SpawnVehicleFlyingComponent(CVehicle* const veh return true; } + +bool CStaticFunctionDefinitions::SetElementCollidableWith(CElement* element, CElement* withElement, bool canCollide) +{ + CBitStream BitStream; + BitStream.pBitStream->Write(withElement->GetID()); + BitStream.pBitStream->WriteBit(canCollide); + + m_pPlayerManager->BroadcastOnlyJoined(CElementRPCPacket(element, SET_ELEMENT_COLLIDABLE_WITH, *BitStream.pBitStream)); + + return true; +} diff --git a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h index 93859842c1..3606937e7c 100644 --- a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h +++ b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h @@ -770,4 +770,5 @@ class CStaticFunctionDefinitions static const char* GetOperatingSystemName(); static const char* GetVersionBuildTag(); static CMtaVersion GetVersionSortable(); + static bool SetElementCollidableWith(CElement* element, CElement* withElement, bool canCollide); }; diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp b/Server/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp index 6a5afcad58..0840d1436b 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp +++ b/Server/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp @@ -104,6 +104,7 @@ void CLuaElementDefs::LoadFunctions() {"setElementFrozen", setElementFrozen}, {"setLowLODElement", setLowLODElement}, {"setElementOnFire", ArgumentParser}, + {"setElementCollidableWith", ArgumentParser}, }; // Add functions @@ -2460,3 +2461,8 @@ bool CLuaElementDefs::SetElementOnFire(CElement* element, bool onFire) noexcept { return CStaticFunctionDefinitions::SetElementOnFire(element, onFire); } + + bool CLuaElementDefs::SetElementCollidableWith(CElement* element, CElement* withElement, bool canCollide) +{ + return CStaticFunctionDefinitions::SetElementCollidableWith(element, withElement, canCollide); +} diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaElementDefs.h b/Server/mods/deathmatch/logic/luadefs/CLuaElementDefs.h index 565c1fc5c8..c440f12489 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaElementDefs.h +++ b/Server/mods/deathmatch/logic/luadefs/CLuaElementDefs.h @@ -108,4 +108,5 @@ class CLuaElementDefs : public CLuaDefs LUA_DECLARE(setLowLODElement); LUA_DECLARE(setElementCallPropagationEnabled); static bool SetElementOnFire(CElement* element, bool onFire) noexcept; + static bool SetElementCollidableWith(CElement* element, CElement* withElement, bool canCollide); }; diff --git a/Shared/sdk/net/rpc_enums.h b/Shared/sdk/net/rpc_enums.h index 5f41b5bb07..50366422d5 100644 --- a/Shared/sdk/net/rpc_enums.h +++ b/Shared/sdk/net/rpc_enums.h @@ -293,5 +293,7 @@ enum eElementRPCFunctions SET_ELEMENT_ON_FIRE, + SET_ELEMENT_COLLIDABLE_WITH, + NUM_RPC_FUNCS // Add above this line }; From 97171c1283df59e6c257c29f404376f02ff4ad9e Mon Sep 17 00:00:00 2001 From: Proxy-99 <77501848+Proxy-99@users.noreply.github.com> Date: Fri, 14 Mar 2025 12:50:30 +0300 Subject: [PATCH 2/3] element checks --- .../logic/CStaticFunctionDefinitions.cpp | 41 +++++++++++++++---- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index d4fd5d7a05..06540825c7 100644 --- a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -12567,12 +12567,37 @@ bool CStaticFunctionDefinitions::SpawnVehicleFlyingComponent(CVehicle* const veh } bool CStaticFunctionDefinitions::SetElementCollidableWith(CElement* element, CElement* withElement, bool canCollide) -{ - CBitStream BitStream; - BitStream.pBitStream->Write(withElement->GetID()); - BitStream.pBitStream->WriteBit(canCollide); - - m_pPlayerManager->BroadcastOnlyJoined(CElementRPCPacket(element, SET_ELEMENT_COLLIDABLE_WITH, *BitStream.pBitStream)); + { + switch (element->GetType()) + { + case EElementType::PLAYER: + case EElementType::PED: + case EElementType::OBJECT: + case EElementType::WEAPON: + case EElementType::VEHICLE: + { + switch (withElement->GetType()) + { + case EElementType::PLAYER: + case EElementType::PED: + case EElementType::OBJECT: + case EElementType::WEAPON: + case EElementType::VEHICLE: + { + CBitStream BitStream; + BitStream.pBitStream->Write(withElement->GetID()); + BitStream.pBitStream->WriteBit(canCollide); + m_pPlayerManager->BroadcastOnlyJoined(CElementRPCPacket(element, SET_ELEMENT_COLLIDABLE_WITH, *BitStream.pBitStream)); + return true; + } + default: + break; + } + break; + } + default: + break; + } - return true; -} + return false; + } From 1ba901f33e8d2291fb3d951239ece41f5e9807c4 Mon Sep 17 00:00:00 2001 From: Proxy-99 <77501848+Proxy-99@users.noreply.github.com> Date: Fri, 14 Mar 2025 14:41:41 +0300 Subject: [PATCH 3/3] review fixes --- .../deathmatch/logic/rpc/CElementRPCs.cpp | 12 +++-- .../logic/CStaticFunctionDefinitions.cpp | 49 +++++++++---------- Shared/sdk/net/bitstream.h | 4 ++ 3 files changed, 36 insertions(+), 29 deletions(-) diff --git a/Client/mods/deathmatch/logic/rpc/CElementRPCs.cpp b/Client/mods/deathmatch/logic/rpc/CElementRPCs.cpp index d9509a4e89..b8cad89c4e 100644 --- a/Client/mods/deathmatch/logic/rpc/CElementRPCs.cpp +++ b/Client/mods/deathmatch/logic/rpc/CElementRPCs.cpp @@ -770,11 +770,15 @@ void CElementRPCs::SetElementOnFire(CClientEntity* pSource, NetBitStreamInterfac void CElementRPCs::SetElementCollidableWith(CClientEntity* pSource, NetBitStreamInterface& bitStream) { ElementID ElementID; - bool bCollidable; + + if (!bitStream.Can(eBitStreamVersion::SetElementCollidableWith_Serverside)) + return; bitStream.Read(ElementID); - bitStream.ReadBit(bCollidable); - CClientEntity* pCollidableWith = CElementIDs::GetElement(ElementID); - pSource->SetCollidableWith(pCollidableWith, bCollidable); + CClientEntity* collidableWith = CElementIDs::GetElement(ElementID); + + if (collidableWith == nullptr) // validity check + return; + pSource->SetCollidableWith(collidableWith, bitStream.ReadBit()); } diff --git a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index 06540825c7..8e0ba012cf 100644 --- a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -12567,37 +12567,36 @@ bool CStaticFunctionDefinitions::SpawnVehicleFlyingComponent(CVehicle* const veh } bool CStaticFunctionDefinitions::SetElementCollidableWith(CElement* element, CElement* withElement, bool canCollide) +{ + switch (element->GetType()) { - switch (element->GetType()) + case EElementType::PLAYER: + case EElementType::PED: + case EElementType::OBJECT: + case EElementType::WEAPON: + case EElementType::VEHICLE: { - case EElementType::PLAYER: - case EElementType::PED: - case EElementType::OBJECT: - case EElementType::WEAPON: - case EElementType::VEHICLE: + switch (withElement->GetType()) { - switch (withElement->GetType()) + case EElementType::PLAYER: + case EElementType::PED: + case EElementType::OBJECT: + case EElementType::WEAPON: + case EElementType::VEHICLE: { - case EElementType::PLAYER: - case EElementType::PED: - case EElementType::OBJECT: - case EElementType::WEAPON: - case EElementType::VEHICLE: - { - CBitStream BitStream; - BitStream.pBitStream->Write(withElement->GetID()); - BitStream.pBitStream->WriteBit(canCollide); - m_pPlayerManager->BroadcastOnlyJoined(CElementRPCPacket(element, SET_ELEMENT_COLLIDABLE_WITH, *BitStream.pBitStream)); - return true; - } - default: - break; + CBitStream BitStream; + BitStream.pBitStream->Write(withElement->GetID()); + BitStream.pBitStream->WriteBit(canCollide); + m_pPlayerManager->BroadcastOnlyJoined(CElementRPCPacket(element, SET_ELEMENT_COLLIDABLE_WITH, *BitStream.pBitStream)); + return true; } + default: break; } - default: - break; + break; } - - return false; + default: + break; } + return false; +} diff --git a/Shared/sdk/net/bitstream.h b/Shared/sdk/net/bitstream.h index f0a61b6666..f9ce3de4c1 100644 --- a/Shared/sdk/net/bitstream.h +++ b/Shared/sdk/net/bitstream.h @@ -612,6 +612,10 @@ enum class eBitStreamVersion : unsigned short // 2025-01-29 PedSync_CameraRotation, + //Add setElementCollidableWith serverside + // 2025-03-14 + SetElementCollidableWith_Serverside, + // This allows us to automatically increment the BitStreamVersion when things are added to this enum. // Make sure you only add things above this comment. Next,