Skip to content

Commit a94fcb6

Browse files
saml1ercodenulls
andauthored
Fix #1659: attached markers having 2 ids causes server crash (#1668)
* Fix #1659: attached markers having 2 ids causes server crash * don't return marker's colshape in getAttachedElements * Make pickup and marker colshapes indestructible destroyElement function will have no effect on pickup and marker colshapes * Make colshapes visible to getAttachedElements * make marker colshapes indestructible (typo fix) * Move indestructible check to DestroyElement funciton Co-authored-by: saml1er <[email protected]>
1 parent d369075 commit a94fcb6

File tree

8 files changed

+26
-6
lines changed

8 files changed

+26
-6
lines changed

Client/mods/deathmatch/logic/CClientEntity.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,9 @@ class CClientEntity : public CClientEntityBase
322322
bool IsCallPropagationEnabled() { return m_bCallPropagationEnabled; }
323323
virtual void SetCallPropagationEnabled(bool bEnabled) { m_bCallPropagationEnabled = bEnabled; }
324324

325+
bool CanBeDestroyedByScript() { return m_canBeDestroyedByScript; }
326+
void SetCanBeDestroyedByScript(bool canBeDestroyedByScript) { m_canBeDestroyedByScript = canBeDestroyedByScript; }
327+
325328
protected:
326329
CClientManager* m_pManager;
327330
CClientEntity* m_pParent;
@@ -368,7 +371,8 @@ class CClientEntity : public CClientEntityBase
368371
bool m_bWorldIgnored;
369372
bool m_bCallPropagationEnabled;
370373
bool m_bDisallowCollisions;
371-
374+
bool m_canBeDestroyedByScript = true; // If true, destroyElement function will
375+
// have no effect on this element
372376
public:
373377
// Optimization for getElementsByType starting at root
374378
static void StartupEntitiesFromRoot();

Client/mods/deathmatch/logic/CClientMarker.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,8 @@ void CClientMarker::SetPosition(const CVector& vecPosition)
9292
void CClientMarker::AttachTo(CClientEntity* pEntity)
9393
{
9494
CClientEntity::AttachTo(pEntity);
95-
if (m_pCollision){
96-
m_pCollision->AttachTo(pEntity);
97-
}
95+
if (m_pCollision)
96+
m_pCollision->AttachTo(this);
9897
}
9998

10099
void CClientMarker::SetAttachedOffsets(CVector& vecPosition, CVector& vecRotation)
@@ -485,6 +484,8 @@ void CClientMarker::CreateOfType(int iType)
485484
default:
486485
break;
487486
}
487+
if (m_pCollision)
488+
m_pCollision->SetCanBeDestroyedByScript(false);
488489
}
489490

490491
CSphere CClientMarker::GetWorldBoundingSphere()

Client/mods/deathmatch/logic/CClientPickup.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ void CClientPickup::Create()
157157
m_pCollision = new CClientColSphere(g_pClientGame->GetManager(), NULL, m_vecPosition, 1.0f);
158158
m_pCollision->m_pOwningPickup = this;
159159
m_pCollision->SetHitCallback(this);
160+
m_pCollision->SetCanBeDestroyedByScript(false);
160161

161162
// Increment pickup counter
162163
++m_pPickupManager->m_uiPickupCount;

Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,9 @@ CClientDummy* CStaticFunctionDefinitions::CreateElement(CResource& Resource, con
928928

929929
bool CStaticFunctionDefinitions::DestroyElement(CClientEntity& Entity)
930930
{
931+
if (!Entity.CanBeDestroyedByScript())
932+
return false;
933+
931934
// Run us on all its children
932935
CChildListType ::const_iterator iter = Entity.IterBegin();
933936
while (iter != Entity.IterEnd())

Server/mods/deathmatch/logic/CElement.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,9 @@ class CElement
229229
bool IsCallPropagationEnabled() { return m_bCallPropagationEnabled; }
230230
void SetCallPropagationEnabled(bool bEnabled) { m_bCallPropagationEnabled = bEnabled; }
231231

232+
bool CanBeDestroyedByScript() { return m_canBeDestroyedByScript; }
233+
void SetCanBeDestroyedByScript(bool canBeDestroyedByScript) { m_canBeDestroyedByScript = canBeDestroyedByScript; }
234+
232235
protected:
233236
CElement* GetRootElement();
234237
virtual bool ReadSpecialData(const int iLine) = 0;
@@ -277,7 +280,8 @@ class CElement
277280
bool m_bDoubleSided;
278281
bool m_bUpdatingSpatialData;
279282
bool m_bCallPropagationEnabled;
280-
283+
bool m_canBeDestroyedByScript = true; // If true, destroyElement function will
284+
// have no effect on this element
281285
// Optimization for getElementsByType starting at root
282286
public:
283287
static void StartupEntitiesFromRoot();

Server/mods/deathmatch/logic/CMarker.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ CMarker::CMarker(CMarkerManager* pMarkerManager, CColManager* pColManager, CElem
2828
m_pCollision = new CColCircle(pColManager, nullptr, m_vecPosition, m_fSize, true);
2929
m_pCollision->SetCallback(this);
3030
m_pCollision->SetAutoCallEvent(false);
31+
m_pCollision->SetCanBeDestroyedByScript(false);
3132

3233
// Add us to the marker manager
3334
pMarkerManager->AddToList(this);
@@ -173,7 +174,8 @@ void CMarker::SetPosition(const CVector& vecPosition)
173174
void CMarker::AttachTo(CElement* pElement)
174175
{
175176
CElement::AttachTo(pElement);
176-
m_pCollision->AttachTo(pElement);
177+
if (m_pCollision)
178+
m_pCollision->AttachTo(this);
177179
}
178180

179181
void CMarker::SetAttachedOffsets(CVector& vecPosition, CVector& vecRotation)
@@ -382,6 +384,7 @@ void CMarker::UpdateCollisionObject(unsigned char ucOldType)
382384

383385
m_pCollision->SetCallback(this);
384386
m_pCollision->SetAutoCallEvent(false);
387+
m_pCollision->SetCanBeDestroyedByScript(false);
385388
}
386389

387390
// Set the radius after the size

Server/mods/deathmatch/logic/CPickup.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ CPickup::CPickup(CElement* pParent, CPickupManager* pPickupManager, CColManager*
2121
m_pCollision->SetEnabled(false);
2222
m_pCollision->SetCallback(this);
2323
m_pCollision->SetAutoCallEvent(false);
24+
m_pCollision->SetCanBeDestroyedByScript(false);
2425

2526
// Add us to the pickup manager's list and grab an unique id
2627
pPickupManager->AddToList(this);

Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,9 @@ CDummy* CStaticFunctionDefinitions::CreateElement(CResource* pResource, const ch
246246

247247
bool CStaticFunctionDefinitions::DestroyElement(CElement* pElement)
248248
{
249+
if (!pElement->CanBeDestroyedByScript())
250+
return false;
251+
249252
// Run us on all its children
250253
CChildListType ::const_iterator iter = pElement->IterBegin();
251254
while (iter != pElement->IterEnd())

0 commit comments

Comments
 (0)