SHARE
TWEET

bullet impact dehook

a guest Jan 28th, 2020 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. CPedSAInterface*    pBulletImpactInitiator;
  2. CEntitySAInterface* pBulletImpactVictim;
  3. CVector*            pBulletImpactStartPosition;
  4. CVector*            pBulletImpactEndPosition;
  5. void Aim() {
  6.     struct cactor_info *localped = (struct cactor_info *)(UINT_PTR) * (uint32_t *)ACTOR_POINTER_SELF;
  7.     if (localped) {
  8.         GetClosestCrosshairTarget(&hd.last_ped, hd.WEAPON_SETTINGS[getScriptCurrentWeaponName(localped)].FOV);
  9.         struct cactor_info *ped = (cactor_info*)hd.last_ped;
  10.         if (ped) {
  11.             if (ped == localped) return; //ped self
  12.  
  13.             CVector myPos;
  14.             ULONG readed;
  15.             myPos = *(CVector*)(0xB6F258 + 0xE0);
  16.             CVector target_bone;
  17.             switch (hd.WEAPON_SETTINGS[getScriptCurrentWeaponName(localped)].BODY_PART) {
  18.                 case eAimTar::HEAD:
  19.                     GetBonePosition((CPed*)ped, &target_bone, eBone::BONE_HEAD);
  20.                     break;
  21.                 case eAimTar::BODY:
  22.                     GetBonePosition((CPed*)ped, &target_bone, eBone::BONE_SPINE1);
  23.                     break;
  24.                 case eAimTar::AUTO:
  25.                     if (ped->state == 50) //driving
  26.                         GetBonePosition((CPed*)ped, &target_bone, eBone::BONE_HEAD);
  27.                     else
  28.                         GetBonePosition((CPed*)ped, &target_bone, eBone::BONE_SPINE1);
  29.                     break;
  30.                 }
  31.             target_bone.fZ += 0.03219923;
  32.             //so we have target bone, and now we need CEntitySAInteface...
  33.             *(DWORD*)&pBulletImpactInitiator = (DWORD)localped;
  34.             *(DWORD*)&pBulletImpactVictim = (DWORD)ped;
  35.             pBulletImpactEndPosition = new CVector(target_bone);
  36.         }
  37.     }
  38. }
  39.  
  40. #define HOOKPOS_CWeapon_DoBulletImpact                  0x73B550
  41. DWORD MTAHookAddr;
  42. DWORD MTADelta;
  43.  
  44. void _declspec(naked) BulletImpactHook() {
  45.     _asm
  46.     {
  47.         mov     eax, [esp + 4]
  48.         mov     pBulletImpactInitiator, eax
  49.         mov     eax, [esp + 8]
  50.         mov     pBulletImpactVictim, eax
  51.         mov     eax, [esp + 12]
  52.         mov     pBulletImpactStartPosition, eax
  53.         mov     eax, [esp + 16]
  54.         mov     pBulletImpactEndPosition, eax
  55.         pushad
  56.     }
  57.     //some actions if need
  58.     Aim();
  59.     _asm
  60.     {
  61.         popad
  62.         push    0xFFFFFFFF
  63.         push    0x00848E50
  64.         jmp     MTAHookAddr
  65.     }
  66. }
  67.  
  68. void SetupBulletImpactHook() {
  69.     //we need to change mta inline hook, namely - jmp delta
  70.     if (*(BYTE*)(HOOKPOS_CWeapon_DoBulletImpact) == 0xE9) {
  71.         MTADelta = *(DWORD*)(HOOKPOS_CWeapon_DoBulletImpact + 1);
  72.         MTAHookAddr = *(DWORD*)(HOOKPOS_CWeapon_DoBulletImpact + 1) + HOOKPOS_CWeapon_DoBulletImpact; //save it for subsequent jump
  73.         *(DWORD*)(HOOKPOS_CWeapon_DoBulletImpact + 1) = (DWORD)&BulletImpactHook - (HOOKPOS_CWeapon_DoBulletImpact + 5);
  74.     }
  75. }
  76. void RemoveBulletImpactHook() {
  77.     *(DWORD*)(HOOKPOS_CWeapon_DoBulletImpact + 1) = MTADelta;
  78. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top