Permalink
Browse files

Add sanity checks

  • Loading branch information...
codenulls committed Nov 14, 2018
1 parent 3b9f57f commit 8471206edea296ba88793f7ecf97b11bd3a2deb0
@@ -14,27 +14,12 @@
CEntity* CCamSA::GetTargetEntity(void) const
{
CEntitySAInterface* pInterface = m_pInterface->CamTargetEntity;
CPoolsSA* pPools = (CPoolsSA*)pGame->GetPools();
CEntity* pReturn = NULL;

if (pPools && pInterface)
if (pInterface)
{
switch (pInterface->nType)
{
case ENTITY_TYPE_PED:
pReturn = (CEntity*)(pPools->GetPed((DWORD*)pInterface)->pEntity);
break;
case ENTITY_TYPE_VEHICLE:
pReturn = (CEntity*)(pPools->GetVehicle((DWORD*)pInterface)->pEntity);
break;
case ENTITY_TYPE_OBJECT:
pReturn = (CEntity*)(pPools->GetObject((DWORD*)pInterface)->pEntity);
break;
default:
break;
}
CPools* pPools = pGame->GetPools();
return pPools->GetEntity((DWORD*)pInterface);
}
return pReturn;
return nullptr;
}

void CCamSA::SetTargetEntity(CEntity* pEntity)
@@ -533,27 +533,12 @@ RwMatrix* CCameraSA::GetLTM(void)
CEntity* CCameraSA::GetTargetEntity(void)
{
CEntitySAInterface* pInterface = this->GetInterface()->pTargetEntity;
CPoolsSA* pPools = ((CPoolsSA*)pGame->GetPools());
CEntity* pReturn = NULL;

if (pPools && pInterface)
if (pInterface)
{
switch (pInterface->nType)
{
case ENTITY_TYPE_PED:
pReturn = (CEntity*)(pPools->GetPed((DWORD*)pInterface)->pEntity);
break;
case ENTITY_TYPE_VEHICLE:
pReturn = (CEntity*)(pPools->GetVehicle((DWORD*)pInterface)->pEntity);
break;
case ENTITY_TYPE_OBJECT:
pReturn = (CEntity*)(pPools->GetObject((DWORD*)pInterface)->pEntity);
break;
default:
break;
}
CPools* pPools = pGame->GetPools();
return pPools->GetEntity((DWORD*)pInterface);
}
return pReturn;
return nullptr;
}

void CCameraSA::SetCameraClip(bool bObjects, bool bVehicles)
@@ -66,21 +66,8 @@ CEntity* CEventDamageSA::GetInflictingEntity(void)
CEntitySAInterface* pInterface = m_pInterface->pInflictor;
if (pInterface)
{
CPoolsSA* pPools = ((CPoolsSA*)pGame->GetPools());
switch (pInterface->nType)
{
case ENTITY_TYPE_PED:
pReturn = pPools->GetPed((DWORD*)pInterface)->pEntity;
break;
case ENTITY_TYPE_VEHICLE:
pReturn = pPools->GetVehicle((DWORD*)pInterface)->pEntity;
break;
case ENTITY_TYPE_OBJECT:
pReturn = pPools->GetObject((DWORD*)pInterface)->pEntity;
break;
default:
break;
}
CPools* pPools = pGame->GetPools();
return pPools->GetEntity((DWORD*)pInterface);
}
return pReturn;
}
@@ -40,18 +40,31 @@ CEntity* CExplosionSA::GetExplosionCreator(void)
eEntityType entityType = entity->GetEntityType();
delete entity;

CPoolsSA* pools = (CPoolsSA*)pGame->GetPools();

CPools* pools = pGame->GetPools();
switch (entityType)
{
case ENTITY_TYPE_PED:
return (CEntity*)(pools->GetPed((DWORD*)this->GetInterface()->m_pEntExplosionOwner));
{
SClientEntity<CPedSA>* pPedClientEntity = pools->GetPed((DWORD*)entity->m_pInterface);
if (pPedClientEntity)
{
return pPedClientEntity->pEntity;;
}
break;
}
case ENTITY_TYPE_VEHICLE:
return (CEntity*)(pools->GetVehicle((DWORD*)this->GetInterface()->m_pEntExplosionOwner));
break;
{
SClientEntity<CVehicleSA>* pVehicleClientEntity = pools->GetVehicle((DWORD*)entity->m_pInterface);
if (pVehicleClientEntity)
{
return pVehicleClientEntity->pEntity;
break;
}
}
case ENTITY_TYPE_OBJECT:
{
break;
}
}
return NULL;
}
@@ -76,13 +76,27 @@ CEntity* CFireSA::GetCreator()
switch (createEntitySA->nType)
{
case ENTITY_TYPE_PED:
creatorEntity = pPools->GetPed((DWORD*)createEntitySA)->pEntity;
{
SClientEntity<CPedSA>* pPedClientEntity = pPools->GetPed((DWORD*)createEntitySA);
if (pPedClientEntity)
{
creatorEntity = pPedClientEntity->pEntity;
}
break;
}
case ENTITY_TYPE_VEHICLE:
creatorEntity = pPools->GetVehicle((DWORD*)createEntitySA)->pEntity;
{
SClientEntity<CVehicleSA>* pVehicleClientEntity = pPools->GetVehicle((DWORD*)createEntitySA);
if (pVehicleClientEntity)
{
creatorEntity = pVehicleClientEntity->pEntity;
}
break;
}
default:
{
creatorEntity = NULL;
}
}
}
return creatorEntity;
@@ -99,13 +113,27 @@ CEntity* CFireSA::GetEntityOnFire()
switch (TargetEntitySA->nType)
{
case ENTITY_TYPE_PED:
TargetEntity = pPools->GetPed((DWORD*)TargetEntitySA)->pEntity;
{
SClientEntity<CPedSA>* pPedClientEntity = pPools->GetPed((DWORD*)TargetEntitySA);
if (pPedClientEntity)
{
TargetEntity = pPedClientEntity->pEntity;
}
break;
}
case ENTITY_TYPE_VEHICLE:
TargetEntity = pPools->GetVehicle((DWORD*)TargetEntitySA)->pEntity;
{
SClientEntity<CVehicleSA>* pVehicleClientEntity = pPools->GetVehicle((DWORD*)TargetEntitySA);
if (pVehicleClientEntity)
{
TargetEntity = pVehicleClientEntity->pEntity;
}
break;
}
default:
{
TargetEntity = NULL;
}
}
}
return TargetEntity;
@@ -242,7 +242,10 @@ CVehicle* CPedSA::GetVehicle()
{
CVehicleSAInterface* vehicle = (CVehicleSAInterface*)(((CPedSAInterface*)this->GetInterface())->CurrentObjective);
if (vehicle)
return ((CPoolsSA*)pGame->GetPools())->GetVehicle((DWORD*)vehicle)->pEntity;
{
SClientEntity<CVehicleSA>* pVehicleClientEntity = pGame->GetPools()->GetVehicle((DWORD*)vehicle);
return pVehicleClientEntity ? pVehicleClientEntity->pEntity : nullptr;
}
}
return NULL;
}
@@ -764,24 +767,36 @@ void CPedSA::SetFightingStyle(eFightingStyle style, BYTE bStyleExtra)
CEntity* CPedSA::GetContactEntity(void)
{
CEntitySAInterface* pInterface = ((CPedSAInterface*)this->GetInterface())->pContactEntity;
CPoolsSA* pPools = ((CPoolsSA*)pGame->GetPools());
CEntity* pReturn = NULL;

if (pPools && pInterface)
if (pInterface)
{
CPools* pPools = pGame->GetPools();
switch (pInterface->nType)
{
case ENTITY_TYPE_VEHICLE:
pReturn = (CEntity*)(pPools->GetVehicle((DWORD*)pInterface)->pEntity);
{
SClientEntity<CVehicleSA>* pVehicleClientEntity = pPools->GetVehicle((DWORD*)pInterface);
if (pVehicleClientEntity)
{
return pVehicleClientEntity->pEntity;
}
break;
}
case ENTITY_TYPE_OBJECT:
pReturn = (CEntity*)(pPools->GetObject((DWORD*)pInterface)->pEntity);
{
SClientEntity<CObjectSA>* pObjectClientEntity = pPools->GetObject((DWORD*)pInterface);
if (pObjectClientEntity)
{
return pObjectClientEntity->pEntity;
}
break;
}
default:
{
break;
}
}
}
return pReturn;
return nullptr;
}

unsigned char CPedSA::GetRunState(void)
@@ -792,27 +807,12 @@ unsigned char CPedSA::GetRunState(void)
CEntity* CPedSA::GetTargetedEntity(void)
{
CEntitySAInterface* pInterface = ((CPedSAInterface*)this->GetInterface())->pTargetedEntity;
CPoolsSA* pPools = ((CPoolsSA*)pGame->GetPools());
CEntity* pReturn = NULL;

if (pPools && pInterface)
if (pInterface)
{
switch (pInterface->nType)
{
case ENTITY_TYPE_PED:
pReturn = (CEntity*)(pPools->GetPed((DWORD*)pInterface)->pEntity);
break;
case ENTITY_TYPE_VEHICLE:
pReturn = (CEntity*)(pPools->GetVehicle((DWORD*)pInterface)->pEntity);
break;
case ENTITY_TYPE_OBJECT:
pReturn = (CEntity*)(pPools->GetObject((DWORD*)pInterface)->pEntity);
break;
default:
break;
}
CPools* pPools = pGame->GetPools();
return pPools->GetEntity((DWORD*)pInterface);
}
return pReturn;
return nullptr;
}

void CPedSA::SetTargetedEntity(CEntity* pEntity)
@@ -214,27 +214,12 @@ void CPhysicalSA::SetDamageImpulseMagnitude(float fMagnitude)
CEntity* CPhysicalSA::GetDamageEntity(void)
{
CEntitySAInterface* pInterface = ((CPhysicalSAInterface*)this->GetInterface())->m_pCollidedEntity;
CPoolsSA* pPools = ((CPoolsSA*)pGame->GetPools());
CEntity* pReturn = NULL;

if (pPools && pInterface)
if (pInterface)
{
switch (pInterface->nType)
{
case ENTITY_TYPE_PED:
pReturn = (CEntity*)(pPools->GetPed((DWORD*)pInterface)->pEntity);
break;
case ENTITY_TYPE_VEHICLE:
pReturn = (CEntity*)(pPools->GetVehicle((DWORD*)pInterface)->pEntity);
break;
case ENTITY_TYPE_OBJECT:
pReturn = (CEntity*)(pPools->GetObject((DWORD*)pInterface)->pEntity);
break;
default:
break;
}
CPools* pPools = pGame->GetPools();
return pPools->GetEntity((DWORD*)pInterface);
}
return pReturn;
return nullptr;
}

void CPhysicalSA::SetDamageEntity(CEntity* pEntity)
@@ -253,27 +238,12 @@ void CPhysicalSA::ResetLastDamage(void)
CEntity* CPhysicalSA::GetAttachedEntity(void)
{
CEntitySAInterface* pInterface = ((CPhysicalSAInterface*)this->GetInterface())->m_pAttachedEntity;
CPoolsSA* pPools = ((CPoolsSA*)pGame->GetPools());
CEntity* pReturn = NULL;

if (pPools && pInterface)
if (pInterface)
{
switch (pInterface->nType)
{
case ENTITY_TYPE_PED:
pReturn = (CEntity*)(pPools->GetPed((DWORD*)pInterface)->pEntity);
break;
case ENTITY_TYPE_VEHICLE:
pReturn = (CEntity*)(pPools->GetVehicle((DWORD*)pInterface)->pEntity);
break;
case ENTITY_TYPE_OBJECT:
pReturn = (CEntity*)(pPools->GetObject((DWORD*)pInterface)->pEntity);
break;
default:
break;
}
CPools* pPools = pGame->GetPools();
return pPools->GetEntity((DWORD*)pInterface);
}
return pReturn;
return nullptr;
}

void CPhysicalSA::AttachEntityToEntity(CPhysical& Entity, const CVector& vecPosition, const CVector& vecRotation)
@@ -494,7 +494,8 @@ int GetAnimPose(int iAnim)
////////////////////////////////////////////////////////////////
__declspec(noinline) int _cdecl OnCPlayerPed_ProcessAnimGroups_Mid(CPlayerPedSAInterface* pPlayerPedSAInterface, int iReqMoveAnim)
{
CPed* pPed = pGame->GetPools()->GetPed((DWORD*)pPlayerPedSAInterface)->pEntity;
SClientEntity<CPedSA>* pPedClientEntity = pGame->GetPools()->GetPed((DWORD*)pPlayerPedSAInterface);
CPed* pPed = pPedClientEntity ? pPedClientEntity->pEntity : nullptr;

if (pPed)
{
Oops, something went wrong.

0 comments on commit 8471206

Please sign in to comment.