From a2d0940d5fca69f05b1aac85cb60e3eded423da5 Mon Sep 17 00:00:00 2001 From: Forgetest <33988868+jensewe@users.noreply.github.com> Date: Thu, 26 Feb 2026 23:30:28 +0800 Subject: [PATCH 1/2] Attempt to fix NULL net prop crashing --- extension/natives.cpp | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/extension/natives.cpp b/extension/natives.cpp index 55b63ee..35f8471 100644 --- a/extension/natives.cpp +++ b/extension/natives.cpp @@ -55,15 +55,36 @@ static bool IsPropValid(const SendProp *prop, PropType type) return false; } +static ServerClass* FindEdictServerClass(edict_t *edict) +{ + if (IServerNetworkable *pNetwork = edict->GetNetworkable()) + { + return pNetwork->GetServerClass(); + } + + if (IServerUnknown *pUnk = edict->GetUnknown()) + { + if (IServerNetworkable *pNetwork = pUnk->GetNetworkable()) + return pNetwork->GetServerClass(); + } + + if (const char* pClassname = gamehelpers->GetEntityClassname(edict)) + { + return gamehelpers->FindServerClass(pClassname); + } + + return nullptr; +} + void UTIL_FindSendProp(SendProp* &ret, IPluginContext *pContext, int index, const char* propname, bool checkType, PropType type, int element) { edict_t *edict = UTIL_EdictOfIndex(index); - if (!edict) + if (!edict || edict->IsFree()) return pContext->ReportError("Invalid edict index (%d)", index); - ServerClass *sc = edict->GetNetworkable()->GetServerClass(); + ServerClass *sc = FindEdictServerClass(edict); if (!sc) - return pContext->ReportError("Cannot find ServerClass for entity %d", index); + return pContext->ReportError("Cannot find ServerClass for edict (%d)", index); sm_sendprop_info_t info; gamehelpers->FindSendPropInfo(sc->GetName(), propname, &info); From 3f7acf566cec17dd2080d7cc0515dfa9d02d072c Mon Sep 17 00:00:00 2001 From: Forgetest <33988868+jensewe@users.noreply.github.com> Date: Fri, 27 Feb 2026 17:27:21 +0800 Subject: [PATCH 2/2] Prevent use of uninitialized network prop --- extension/natives.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/extension/natives.cpp b/extension/natives.cpp index 35f8471..1e8e3c3 100644 --- a/extension/natives.cpp +++ b/extension/natives.cpp @@ -57,10 +57,14 @@ static bool IsPropValid(const SendProp *prop, PropType type) static ServerClass* FindEdictServerClass(edict_t *edict) { - if (IServerNetworkable *pNetwork = edict->GetNetworkable()) - { - return pNetwork->GetServerClass(); - } + // BUG: (See https://github.com/alliedmodders/hl2sdk/blob/72b927a0a4ee25c788148e6591ff859d1f81df65/game/server/baseentity.cpp#L403-L413) + // gEntList.AddNetworkableEntity is called right before edict()->m_pNetworkable is set + // which may lead to crashes if user establishes a hook in "OnEntityCreated". + // + // if (IServerNetworkable *pNetwork = edict->GetNetworkable()) + // { + // return pNetwork->GetServerClass(); + // } if (IServerUnknown *pUnk = edict->GetUnknown()) {