From 8dcbe14ea0bb562d04a8fde57a7b3d4759ddaefa Mon Sep 17 00:00:00 2001 From: CookieCat <81494827+CookieCat45@users.noreply.github.com> Date: Tue, 20 Feb 2024 10:14:00 -0500 Subject: [PATCH] Throw an error when attempting to remove worldspawn in RemoveEntity/RemoveEdict (#2104) * Check for worldspawn in RemoveEntity and RemoveEdict * A little more info --- core/smn_entities.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/core/smn_entities.cpp b/core/smn_entities.cpp index 139da9cc..d2986ca4 100644 --- a/core/smn_entities.cpp +++ b/core/smn_entities.cpp @@ -285,6 +285,11 @@ static cell_t RemoveEdict(IPluginContext *pContext, const cell_t *params) return pContext->ThrowNativeError("Edict %d (%d) is not a valid edict", g_HL2.ReferenceToIndex(params[1]), params[1]); } + if (g_HL2.ReferenceToIndex(params[1]) == 0) + { + return pContext->ThrowNativeError("Cannot remove worldspawn (edict 0)"); + } + engine->RemoveEdict(pEdict); return 1; @@ -298,6 +303,11 @@ static cell_t RemoveEntity(IPluginContext *pContext, const cell_t *params) return pContext->ThrowNativeError("Entity %d (%d) is not a valid entity", g_HL2.ReferenceToIndex(params[1]), params[1]); } + if (g_HL2.ReferenceToIndex(params[1]) == 0) + { + return pContext->ThrowNativeError("Cannot remove worldspawn (entity 0)"); + } + // Some games have UTIL_Remove exposed on IServerTools, but for consistence, we'll // use this method for all. Results in DeathNotice( this ) being called on parent, // and parent being cleared (both if any parent) before UTIL_Remove is called.