@@ -297,7 +297,6 @@ static void Event_BulletImpact(void)
297297CPedSAInterface* pAPed = NULL ;
298298float fTempPosX = 0 , fTempPosY = 0 , fTempPosZ = 0 ;
299299CPed* pATargetingPed = NULL ;
300- SClientEntity<CPedSA>* pATargetingPedClient = nullptr ;
301300CVector* pTempVec;
302301bool * pSkipAim;
303302CRemoteDataStorageSA* pTempRemote;
@@ -322,6 +321,12 @@ VOID _declspec(naked) HOOK_CTaskSimpleUsegun_ProcessPed()
322321 }
323322}
324323
324+ static CPed * GetTargetingPed ()
325+ {
326+ SClientEntity<CPedSA>* pClientEntity = m_pools->GetPed ((DWORD*)pAPed);
327+ return pClientEntity ? pClientEntity->pEntity : nullptr ;
328+ }
329+
325330VOID _declspec (naked) HOOK_SkipAim()
326331{
327332 // We can use ECX
@@ -338,17 +343,7 @@ VOID _declspec(naked) HOOK_SkipAim()
338343 pushad
339344 }
340345
341- pATargetingPedClient = m_pools->GetPed ((DWORD*)pAPed);
342- if (pATargetingPedClient)
343- {
344- // access pEntity member, not using [0] will crash it
345- pATargetingPed = reinterpret_cast <CPed*>(((DWORD*)pATargetingPedClient)[0 ]);
346- }
347- else
348- {
349- pATargetingPed = nullptr ;
350- }
351-
346+ pATargetingPed = GetTargetingPed ();
352347 if (pATargetingPed)
353348 {
354349 // If this is the local player
@@ -419,18 +414,7 @@ VOID _declspec(naked) HOOK_IKChainManager_PointArm()
419414 pushad
420415 }
421416
422- pATargetingPedClient = m_pools->GetPed ((DWORD*)pAPed);
423-
424- if (pATargetingPedClient)
425- {
426- // access pEntity member, not using [0] will crash it
427- pATargetingPed = reinterpret_cast <CPed*>(((DWORD*)pATargetingPedClient)[0 ]);
428- }
429- else
430- {
431- pATargetingPed = nullptr ;
432- }
433-
417+ pATargetingPed = GetTargetingPed ();
434418 if (pATargetingPed)
435419 {
436420 // If this is the local player
@@ -493,18 +477,7 @@ VOID _declspec(naked) HOOK_IKChainManager_LookAt()
493477 // Jax: this gets called on vehicle collision and pTargetVector is null
494478 if (pTargetVector)
495479 {
496- pATargetingPedClient = m_pools->GetPed ((DWORD*)pAPed);
497-
498- if (pATargetingPedClient)
499- {
500- // access pEntity member, not using [0] will crash it
501- pATargetingPed = reinterpret_cast <CPed*>(((DWORD*)pATargetingPedClient)[0 ]);
502- }
503- else
504- {
505- pATargetingPed = nullptr ;
506- }
507-
480+ pATargetingPed = GetTargetingPed ();
508481 if (pATargetingPed)
509482 {
510483 // If this is the local player
0 commit comments