Skip to content
Draft
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
23 changes: 22 additions & 1 deletion Client/mods/deathmatch/logic/CPacketHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4184,7 +4184,7 @@ void CPacketHandler::Packet_EntityAdd(NetBitStreamInterface& bitStream)
{
assert(0);
break;
}
}
}

if (pEntity)
Expand Down Expand Up @@ -4267,6 +4267,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)
Expand Down
17 changes: 17 additions & 0 deletions Client/mods/deathmatch/logic/rpc/CElementRPCs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down Expand Up @@ -852,3 +853,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;
Comment on lines +868 to +869
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (!collidableWith)
    return;

pSource->SetCollidableWith(collidableWith, bitStream.ReadBit());
}
1 change: 1 addition & 0 deletions Client/mods/deathmatch/logic/rpc/CElementRPCs.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,5 @@ class CElementRPCs : public CRPCFunctions
DECLARE_ELEMENT_RPC(SetCallPropagationEnabled);
DECLARE_ELEMENT_RPC(SetColPolygonHeight);
DECLARE_ELEMENT_RPC(SetElementOnFire);
DECLARE_ELEMENT_RPC(SetElementCollidableWith);
};
1 change: 1 addition & 0 deletions Server/mods/deathmatch/logic/CPerfStat.RPCPacketUsage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
36 changes: 35 additions & 1 deletion Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
#include "packets/CChatEchoPacket.h"
#include "packets/CConsoleEchoPacket.h"
#include "packets/CChatClearPacket.h"
#include "packets/CElementRPCPacket.h"
#include "version.h"
#include <net/rpc_enums.h>

Expand Down Expand Up @@ -12610,3 +12609,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;
}
1 change: 1 addition & 0 deletions Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
12 changes: 12 additions & 0 deletions Server/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

#include "StdInc.h"
#include "CLuaElementDefs.h"

std::vector<CLuaElementDefs::ElementPair> CLuaElementDefs::elements;

#include "CStaticFunctionDefinitions.h"
#include "CScriptArgReader.h"
#include "CDummy.h"
Expand Down Expand Up @@ -104,6 +107,7 @@ void CLuaElementDefs::LoadFunctions()
{"setElementFrozen", setElementFrozen},
{"setLowLODElement", setLowLODElement},
{"setElementOnFire", ArgumentParser<SetElementOnFire>},
{"setElementCollidableWith", ArgumentParser<SetElementCollidableWith>},
};

// Add functions
Expand Down Expand Up @@ -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

}
10 changes: 10 additions & 0 deletions Server/mods/deathmatch/logic/luadefs/CLuaElementDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<ElementPair> elements;
};
14 changes: 14 additions & 0 deletions Server/mods/deathmatch/logic/packets/CEntityAddPacket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "CVehicleManager.h"
#include "CHandlingManager.h"
#include "CGame.h"
#include <luadefs/CLuaElementDefs.h>

//
// Temporary helper functions for fixing crashes on pre r6459 clients.
Expand Down Expand Up @@ -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;
}
Expand Down
Loading