Skip to content
Merged
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
31 changes: 28 additions & 3 deletions extension/natives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,40 @@ static bool IsPropValid(const SendProp *prop, PropType type)
return false;
}

static ServerClass* FindEdictServerClass(edict_t *edict)
{
// 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())
{
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);
Expand Down