diff --git a/Client/mods/deathmatch/logic/CPacketHandler.cpp b/Client/mods/deathmatch/logic/CPacketHandler.cpp index 339110ff311..cd893a61548 100644 --- a/Client/mods/deathmatch/logic/CPacketHandler.cpp +++ b/Client/mods/deathmatch/logic/CPacketHandler.cpp @@ -4195,7 +4195,7 @@ void CPacketHandler::Packet_EntityAdd(NetBitStreamInterface& bitStream) { assert(0); break; - } + } } if (pEntity) @@ -4278,6 +4278,27 @@ void CPacketHandler::Packet_EntityAdd(NetBitStreamInterface& bitStream) } newEntitiesStuff.clear(); g_pCore->UpdateDummyProgress(0); + + + unsigned int count = 0; + bitStream.ReadCompressed(count); + for (unsigned int i = 0; i < count; ++i) + { + ElementID id1, id2; + bool canCollide; + bitStream.Read(id1); + bitStream.Read(id2); + bitStream.ReadBit(canCollide); + // Use id1, id2, canCollide + + CClientEntity* pEntity1 = CElementIDs::GetElement(id1); + CClientEntity* pEntity2 = CElementIDs::GetElement(id2); + + pEntity1->SetCollidableWith(pEntity2, canCollide); + } + SString strCount = SString("Collision pairs count: %u", count); + CStaticFunctionDefinitions::OutputConsole(strCount); + } void CPacketHandler::Packet_EntityRemove(NetBitStreamInterface& bitStream) diff --git a/Client/mods/deathmatch/logic/rpc/CElementRPCs.cpp b/Client/mods/deathmatch/logic/rpc/CElementRPCs.cpp index 756c0e10adc..6c34341b21d 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) \ @@ -859,3 +860,19 @@ void CElementRPCs::SetElementOnFire(CClientEntity* pSource, NetBitStreamInterfac { pSource->SetOnFire(bitStream.ReadBit()); } + +void CElementRPCs::SetElementCollidableWith(CClientEntity* pSource, NetBitStreamInterface& bitStream) +{ + ElementID ElementID; + + if (!bitStream.Can(eBitStreamVersion::SetElementCollidableWith_Serverside)) + return; + + bitStream.Read(ElementID); + + CClientEntity* collidableWith = CElementIDs::GetElement(ElementID); + + if (collidableWith == nullptr) // validity check + return; + pSource->SetCollidableWith(collidableWith, bitStream.ReadBit()); +} diff --git a/Client/mods/deathmatch/logic/rpc/CElementRPCs.h b/Client/mods/deathmatch/logic/rpc/CElementRPCs.h index 2800d239fbb..de328b68f45 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 cdebcedcc24..66a29568ce6 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 52695b056fc..82e3ce944e9 100644 --- a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -12668,3 +12668,38 @@ bool CStaticFunctionDefinitions::SpawnVehicleFlyingComponent(CVehicle* const veh return true; } + +bool CStaticFunctionDefinitions::SetElementCollidableWith(CElement* element, CElement* withElement, bool canCollide) +{ + 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 false; +} diff --git a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h index 388f38b4439..facfe2d9acb 100644 --- a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h +++ b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h @@ -771,4 +771,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 7d339104fb3..d214ca374dd 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp +++ b/Server/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp @@ -11,6 +11,9 @@ #include "StdInc.h" #include "CLuaElementDefs.h" + +std::vector CLuaElementDefs::elements; + #include "CStaticFunctionDefinitions.h" #include "CScriptArgReader.h" #include "CDummy.h" @@ -104,6 +107,7 @@ void CLuaElementDefs::LoadFunctions() {"setElementFrozen", setElementFrozen}, {"setLowLODElement", setLowLODElement}, {"setElementOnFire", ArgumentParser}, + {"setElementCollidableWith", ArgumentParser}, }; // Add functions @@ -2460,3 +2464,11 @@ bool CLuaElementDefs::SetElementOnFire(CElement* element, bool onFire) noexcept { return CStaticFunctionDefinitions::SetElementOnFire(element, onFire); } + + bool CLuaElementDefs::SetElementCollidableWith(CElement* element, CElement* withElement, bool canCollide) +{ + + elements.push_back({element, withElement, canCollide}); // Store the pair in the vector + return CStaticFunctionDefinitions::SetElementCollidableWith(element, withElement, canCollide); // Set collision state + +} diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaElementDefs.h b/Server/mods/deathmatch/logic/luadefs/CLuaElementDefs.h index 89745b5a3fb..41df7335a35 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaElementDefs.h +++ b/Server/mods/deathmatch/logic/luadefs/CLuaElementDefs.h @@ -108,4 +108,14 @@ 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); + + struct ElementPair + { + CElement* element1; // Could be any type + CElement* element2; + bool canCollide; + }; + + static vector elements; }; diff --git a/Server/mods/deathmatch/logic/packets/CEntityAddPacket.cpp b/Server/mods/deathmatch/logic/packets/CEntityAddPacket.cpp index f87a776f1ea..4ab616da70e 100644 --- a/Server/mods/deathmatch/logic/packets/CEntityAddPacket.cpp +++ b/Server/mods/deathmatch/logic/packets/CEntityAddPacket.cpp @@ -27,6 +27,7 @@ #include "CVehicleManager.h" #include "CHandlingManager.h" #include "CGame.h" +#include // // Temporary helper functions for fixing crashes on pre r6459 clients. @@ -1142,6 +1143,19 @@ bool CEntityAddPacket::Write(NetBitStreamInterface& BitStream) const } } + auto& pair = CLuaElementDefs::elements; // Static vector of ElementPair + + BitStream.WriteCompressed(pair.size()); // Get the size of the vector and write it to the bitstream + printf("Server: CLuaElementDefs::elements size: %zu\n", pair.size()); + + for (const auto& data : pair) + { + printf("SetElementCollidableWith called: %p %p %d\n", data.element1, data.element2, data.canCollide); + BitStream.Write(data.element1->GetID()); + BitStream.Write(data.element2->GetID()); + BitStream.WriteBit(data.canCollide); + } + // Success return true; } diff --git a/Shared/sdk/net/bitstream.h b/Shared/sdk/net/bitstream.h index f38deb1dd0b..dfb1a782e1e 100644 --- a/Shared/sdk/net/bitstream.h +++ b/Shared/sdk/net/bitstream.h @@ -412,6 +412,267 @@ class NetBitStreamInterface : public CRefCountable } }; +// eBitStreamVersion allows us to track what BitStream version is being used without placing magic numbers everywhere. +// It also helps us know what code branches can be removed when we increment a major version of MTA. +// Make sure you only add new items to the end of the list, above the "Latest" entry. +enum class eBitStreamVersion : unsigned short +{ + Unk = 0x030, + + + // + // 1.5.0 UNSTABLE - 2015-01-17 + // + + // Add "quickstand" to setGlitchEnabled + // 2015-07-13 0x063 209837dcdc30d267519abc12e1361a1d18cd1553 + QuickStandGlitch, + + // + // 1.5.0 RC RELEASED - 2015-07-15 + // + + // + // 1.5.1 RELEASED - 2015-11-05 + // + + // Update fix #9038 (bugged shotgun with bullet sync) to only work if all connected clients support it + // 2015-10-17 0x064 edbc6d37a734914b7349c693edf9a087a5a78a3d + ShotgunDamageFix, + + // + // 1.5.2 RELEASED - 2016-01-24 + // + + // Add blend parameter to setPedAnimation (#62) + // 2016-09-05 0x065 f51983c3e3385b4de8d754e11efe329acaee9301 + SetPedAnimation_Blend, + + // Update net module version + // 2016-09-24 0x066 3de7e5bd2d425747617a24350f2974e02cddc6dc + NetUpdate_0x09E, + + // + // 1.5.3 RELEASED - 2016-10-20 + // + + // Fix player nametag unicode characters missing on player join + // 2016-12-09 0x067 2e582453b476c1183bd9fae5363a7cffdb531834 + UnicodeNametags, + + // Add -1 parameter to setElementDimension (only to objects) (#111) + // 2017-02-22 0x068 2e319aa823929360da9e1f48c7eb233f1d6f29e5 + DimensionOmnipresence, + + // Add support for more special detections + // 2017-02-26 0x069 9b6187b3c2eaa655624254f8d83acb35b31243e7 + MoreSpecialDetections_Nice69, + + // Add option to enable fakelag command for testing sync issues + // 2017-03-08 0x06A a99fa0afa3b55e84f15aed335ab542520f39126d + FakeLagCommand, + + // + // 1.5.4 RELEASED - 2017-04-17 + // + + // Add player element for onClientChatMessage (#138) + // 2017-07-04 0x06B 8c7095599c6d54784692bf93a1e6c7f56392c323 + OnClientChatMessage_PlayerSource, + + // + // 1.5.5 RELEASED - 2017-08-07 + // + + // Add bShallow argument for server-side water as well (#240) + // 2018-08-05 0x06C 1321b538559efe6d70deb5b784c2d392d52658f5 + Water_bShallow_ServerSide, + + // + // 1.5.6 RELEASED - 2018-09-07 + // 1.5.7 RELEASED - 2019-08-31 + // + + // Add option to disable spawning components by setVehicleDoorState + // 2019-10-11 0x06D e79d97195439f70ac66ece1859152b4c4896af31 + SetVehicleDoorState_SpawnFlyingComponent, + + // Increment BitStream version for Discord update (#1330) + // 2020-03-27 0x06E a0ce68f284487ba636e839b06c103bc2442d95e0 + Discord_InitialImplementation, + + // Add analog control sync for accelerate and brake_reverse (#1164) + // 2020-04-02 0x06F 41e36cc67520dded2a5203727a726c4261c65e31 + AnalogControlSync_AccelBrakeReverse, + + // + // 1.5.8 RELEASED - 2020-10-11 + // + + // setWaterLevel: add bIncludeWorldSeaLevel and bIncludeOutsideWorldLevel + // 2020-11-03 0x70 + SetWaterLevel_ChangeOutsideWorldLevel, + + // Implement entering/exiting/jacking for peds #1748 + // 2020-11-10 0x71 + PedEnterExit, + + // Add height for colpolygon (#1908) + // 2021-01-16 0x72 + SetColPolygonHeight, + + // Support for vehicle blow without explosion and blow state synchronisation + // 2021-02-26 0x73 + VehicleBlowStateSupport, + + // Implement messageType parameter to onClientChatMessage (#1020) + // 2021-05-15 0x74 + OnClientChatMessage_MessageType, + + // Add serverside event "onPlayerResourceStart" (#2150) + // 2021-08-30 0x75 + OnPlayerResourceStart, + + // + // 1.5.9 RELEASED - 2021-10-01 + // + + // Remove "old" Discord implementation (#2499) + // 2022-01-16 0x76 + Discord_Cleanup, + + // + // 1.6.0 RELEASED - 2023-04-07 + // + + CEntityAddPacket_ObjectBreakable, + + // Add serverside setWorldSpecialPropertyEnabled + // 2023-08-17 + WorldSpecialProperties, + + // Add "fireballdestruct" to setWorldSpecialPropertyEnabled + // 2023-09-09 + WorldSpecialProperty_FireballDestruct, + + // Send server name to player in CPlayerJoinCompletePacket + // 2023-10-12 + CPlayerJoinCompletePacket_ServerName, + + // Add "roadsignstext" to setWorldSpecialPropertyEnabled + // 2024-05-17 + WorldSpecialProperty_RoadSignsText, + + // Add "extendedwatercannons" to setWorldSpecialPropertyEnabled + // 2024-05-23 + WorldSpecialProperty_ExtendedWaterCannons, + + // Add breakObject to serverside as well + // 2024-05-31 + BreakObject_Serverside, + + // Ped syncronization revision + // 2024-06-16 + PedSync_Revision, + + // Add "tunnelweatherblend" to setWorldSpecialPropertyEnabled + // 2024-06-30 + WorldSpecialProperty_TunnelWeatherBlend, + + // Checkpoint & arrow alpha fix + // 2024-07-03 + Marker_IgnoreAlphaLimits, + + // Add "setMarkerTargetArrowProperties" + // 2024-07-05 + SetMarkerTargetArrowProperties, + + // Add respawnObject and toggleObjectRespawn to serverside + // 2024-09-04 + RespawnObject_Serverside, + + // Add check_duplicate_serials + // 2024-09-04 + CheckDuplicateSerials, + + // Add ignorefirestate special world property + // 2024-11-07 + WorldSpecialProperty_IgnoreFireState, + + // Fix iPedSyncerDistance and iUnoccupiedVehicleSyncerDistance sync + // 2024-11-22 + FixSyncerDistance, + + // Add onPlayerChangesWorldSpecialProperty + // 2024-11-26 + WorldSpecialPropertyEvent, + + // Add setElementOnFire function + // 2024-12-30 + SetElementOnFire, + + // Add "spawnFlyingComponent" to setVehiclePanelState + // 2024-12-31 + SetVehiclePanelState_SpawnFlyingComponent, + + // Ped animations synchronization + // 2025-01-01 + AnimationsSync, + + // Add server side isPedReloadingWeapon + // 2025-01-09 + IsPedReloadingWeapon, + + // Add "flyingcomponents" to setWorldSpecialPropertyEnabled + // 2025-01-10 + WorldSpecialProperty_FlyingComponents, + + // Ped's camera synchronization + // 2025-01-29 + PedSync_CameraRotation, + + // Add "vehicleburnexplosions" to setWorldSpecialPropertyEnabled + // 2025-02-20 + WorldSpecialProperty_VehicleBurnExplosions, + + //Add setElementCollidableWith serverside + // 2025-03-14 + SetElementCollidableWith_Serverside, + + // Add serverside building support + // 2025-05-26 + ServersideBuildingElement, + + // Add "vehenginemanualmode" to setWorldSpecialPropertyEnabled + // 2025-06-02 + WorldSpecialProperty_VehicleEngineAutoStart, + + // DESCRIPTION + // YYYY-MM-DD + // Name, + + // 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, + Latest = Next - 1, +}; + +class NetBitStreamInterface : public NetBitStreamInterfaceNoVersion +{ + NetBitStreamInterface(const NetBitStreamInterface&); + const NetBitStreamInterface& operator=(const NetBitStreamInterface&); + +protected: + NetBitStreamInterface() { DEBUG_CREATE_COUNT("NetBitStreamInterface"); } + virtual ~NetBitStreamInterface() { DEBUG_DESTROY_COUNT("NetBitStreamInterface"); } + +public: + virtual operator NetBitStreamInterface&() { return *this; } + virtual unsigned short Version() const = 0; + + bool Can(eBitStreamVersion query) { return static_cast(Version()) >= query; } +}; + // Interface for all sync structures struct ISyncStructure { diff --git a/Shared/sdk/net/rpc_enums.h b/Shared/sdk/net/rpc_enums.h index 84c7518bc45..db0f2cb0bee 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 };