Reconcile the concept of Edict & Networkable across the codebase (#1903)
* Reconcile the concept of Edict & Networkable across the codebase * There's no need to check this, it's done elsewhere. Also could be null (segfault) * This was never needed * Pseudo review changes Re-added removed null checks, and added new ones. Changed the error messages in Get/SetProp natives to better reflect reality. * Don't change the behaviour of GetEntityNetClass * Overload IGameHelpers::FindServerClass * Make error messages more accurate * Fix a dev comment * Rename FindServerClass --------- Co-authored-by: Kenzzer <[email protected]>
This commit is contained in:
@@ -76,16 +76,21 @@ bool CritManager::TryEnable()
|
||||
for (size_t i = playerhelpers->GetMaxClients() + 1; i < MAX_EDICTS; ++i)
|
||||
{
|
||||
CBaseEntity *pEntity = gamehelpers->ReferenceToEntity(i);
|
||||
if (pEntity == NULL)
|
||||
if (pEntity == nullptr)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
IServerUnknown *pUnknown = (IServerUnknown *)pEntity;
|
||||
IServerNetworkable *pNetworkable = pUnknown->GetNetworkable();
|
||||
if (!pNetworkable)
|
||||
ServerClass *pServerClass = gamehelpers->FindEntityServerClass(pEntity);
|
||||
if (pServerClass == nullptr)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!UTIL_ContainsDataTable(pNetworkable->GetServerClass()->m_pTable, TF_WEAPON_DATATABLE))
|
||||
if (!UTIL_ContainsDataTable(pServerClass->m_pTable, TF_WEAPON_DATATABLE))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
SH_ADD_MANUALHOOK(CalcIsAttackCriticalHelper, pEntity, SH_MEMBER(&g_CritManager, &CritManager::Hook_CalcIsAttackCriticalHelper), false);
|
||||
SH_ADD_MANUALHOOK(CalcIsAttackCriticalHelperNoCrits, pEntity, SH_MEMBER(&g_CritManager, &CritManager::Hook_CalcIsAttackCriticalHelperNoCrits), false);
|
||||
@@ -116,15 +121,20 @@ void CritManager::Disable()
|
||||
void CritManager::OnEntityCreated(CBaseEntity *pEntity, const char *classname)
|
||||
{
|
||||
if (!m_enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
IServerUnknown *pUnknown = (IServerUnknown *)pEntity;
|
||||
IServerNetworkable *pNetworkable = pUnknown->GetNetworkable();
|
||||
if (!pNetworkable)
|
||||
ServerClass *pServerClass = gamehelpers->FindEntityServerClass(pEntity);
|
||||
if (pServerClass == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!UTIL_ContainsDataTable(pNetworkable->GetServerClass()->m_pTable, TF_WEAPON_DATATABLE))
|
||||
if (!UTIL_ContainsDataTable(pServerClass->m_pTable, TF_WEAPON_DATATABLE))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
SH_ADD_MANUALHOOK(CalcIsAttackCriticalHelper, pEntity, SH_MEMBER(&g_CritManager, &CritManager::Hook_CalcIsAttackCriticalHelper), false);
|
||||
SH_ADD_MANUALHOOK(CalcIsAttackCriticalHelperNoCrits, pEntity, SH_MEMBER(&g_CritManager, &CritManager::Hook_CalcIsAttackCriticalHelperNoCrits), false);
|
||||
@@ -164,11 +174,9 @@ bool CritManager::Hook_CalcIsAttackCriticalHelpers(bool noCrits)
|
||||
{
|
||||
CBaseEntity *pWeapon = META_IFACEPTR(CBaseEntity);
|
||||
|
||||
// If there's an invalid ent or invalid networkable here, we've got issues elsewhere.
|
||||
|
||||
IServerNetworkable *pNetWeapon = ((IServerUnknown *)pWeapon)->GetNetworkable();
|
||||
ServerClass *pServerClass = pNetWeapon->GetServerClass();
|
||||
if (!pServerClass)
|
||||
// If there's an invalid ent or invalid server class here, we've got issues elsewhere.
|
||||
ServerClass *pServerClass = gamehelpers->FindEntityServerClass(pWeapon);
|
||||
if (pServerClass == nullptr)
|
||||
{
|
||||
g_pSM->LogError(myself, "Invalid server class on weapon.");
|
||||
RETURN_META_VALUE(MRES_IGNORED, false);
|
||||
|
||||
@@ -435,23 +435,19 @@ int FindEntityByNetClass(int start, const char *classname)
|
||||
|
||||
for (int i = ((start != -1) ? start : 0); i < gpGlobals->maxEntities; i++)
|
||||
{
|
||||
current = engine->PEntityOfEntIndex(i);
|
||||
if (current == NULL || current->IsFree())
|
||||
CBaseEntity *pEntity = gamehelpers->ReferenceToEntity(i);
|
||||
if (pEntity == nullptr)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
IServerNetworkable *network = current->GetNetworkable();
|
||||
|
||||
if (network == NULL)
|
||||
ServerClass *pServerClass = gamehelpers->FindEntityServerClass(pEntity);
|
||||
if (pServerClass == nullptr)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ServerClass *sClass = network->GetServerClass();
|
||||
const char *name = sClass->GetName();
|
||||
|
||||
|
||||
const char *name = pServerClass->GetName();
|
||||
if (strcmp(name, classname) == 0)
|
||||
{
|
||||
return i;
|
||||
|
||||
Reference in New Issue
Block a user