iFarbod

Reload

Nov 6th, 2015
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.37 KB | None | 0 0
  1. #include <Windows.h>
  2. #include "CPatch.h"
  3. #include <cstdint>
  4.  
  5. enum eTaskType
  6. {
  7.     TASK_SIMPLE_USE_GUN = 0x3F9
  8. };
  9.  
  10. struct CPlayerPed;
  11. struct CTask;
  12.  
  13. struct CTaskManager
  14. {
  15.     CTask *m_aPrimaryTasks[5];
  16.     CTask *m_aSecondaryTasks[6];
  17.     struct CPlayerPed *m_pPed;
  18. };
  19.  
  20. struct CPedAI
  21. {
  22.     CPlayerPed * pPed;
  23.     CTaskManager TaskManager;
  24. };
  25.  
  26. struct CPlayerPed
  27. {
  28.     BYTE Pad[0x47C];
  29.     CPedAI * pPedAI; // 0x47C
  30. };
  31.  
  32. struct CTask_VTBL
  33. {
  34.     DWORD dw1; // +0x0
  35.     DWORD dw2; // +0x4
  36.     DWORD dw3; // +0x8
  37.     DWORD dw4; // +0xC
  38.     DWORD GET_TASK_ID; // +0x10
  39. };
  40.  
  41. struct CTask
  42. {
  43.     CTask_VTBL * vtbl;
  44. };
  45.  
  46. auto FindPlayerPed = (CPlayerPed *(*)(int)) 0x56E210;
  47. auto CTaskManager__GetSimplestActiveTask = (CTask *(__thiscall *)(CTaskManager *)) 0x6819D0;
  48.  
  49. void reLoad()
  50. {
  51.     int bSlot;
  52.     int cuw;
  53.     cuw = *(int *)0xBAA410;
  54.     if (cuw >= 0 && cuw <= 1) return;//bSlot = 0;
  55.     else if (cuw >= 2 && cuw <= 9) return;//bSlot = 1;
  56.     else if (cuw >= 10 && cuw <= 15) return;//bSlot = 10;
  57.     else if ((cuw >= 16 && cuw <= 18) || cuw == 39) return;//bSlot = 8;
  58.     else if (cuw >= 22 && cuw <= 24) bSlot = 2;
  59.     else if (cuw == 25) return; //WeaponID 25 is shotgun that doesn't need reload
  60.     else if (cuw >= 26 && cuw <= 27) bSlot = 3;
  61.     else if ((cuw >= 28 && cuw <= 29) || cuw == 32) bSlot = 4;
  62.     else if (cuw >= 30 && cuw <= 31) bSlot = 5;
  63.     else if (cuw >= 33 && cuw <= 34) return;//bSlot = 6;
  64.     else if (cuw >= 35 && cuw <= 38) return;//bSlot = 7;
  65.     else if (cuw == 40) return;//bSlot = 12;
  66.     else if (cuw >= 41 && cuw <= 43) return;//bSlot = 9;
  67.     else if (cuw >= 44 && cuw <= 46) return;//bSlot = 11;
  68.     else return;
  69.     DWORD address2 = ((*(int*)0xB6F5F0) + 1440) + (28 * bSlot) + 8;
  70.     int ammohave = *(int *)address2;
  71.     switch (cuw)
  72.     {
  73.         case 22:
  74.             if (ammohave >= 17) return;
  75.             break;
  76.         case 23:
  77.             if (ammohave >= 17) return;
  78.             break;
  79.         case 24:
  80.             if (ammohave >= 7) return;
  81.             break;
  82.         case 26:
  83.             if (ammohave >= 4) return;
  84.             break;
  85.         case 27:
  86.             if (ammohave >= 7) return;
  87.             break;
  88.         case 28:
  89.             if (ammohave >= 100) return;
  90.             break;
  91.         case 29:
  92.             if (ammohave >= 30) return;
  93.             break;
  94.         case 30:
  95.             if (ammohave >= 30) return;
  96.             break;
  97.         case 31:
  98.             if (ammohave >= 50) return;
  99.             break;
  100.         case 32:
  101.             if (ammohave >= 100) return;
  102.             break;
  103.         default:
  104.             return;
  105.     }
  106.     DWORD address = ((*(int*)0xB6F5F0) + 1440) + (28 * bSlot) + 4;
  107.     CPatch::SetUInt(address, 2);
  108. }
  109.  
  110. void called()
  111. {
  112.     DWORD dwCall = 0x572D10;
  113.  
  114.     if (GetAsyncKeyState(0x52) & 0x8000)
  115.     {
  116.         CPlayerPed * pPed = FindPlayerPed(-1);
  117.         CTask* pTask = CTaskManager__GetSimplestActiveTask(&pPed->pPedAI->TaskManager);
  118.  
  119.         auto getTaskId = (int(__thiscall *)(CTask *)) pTask->vtbl->GET_TASK_ID;
  120.  
  121.         if (getTaskId(pTask) != TASK_SIMPLE_USE_GUN)
  122.         {
  123.             reLoad();
  124.         }
  125.     }
  126.  
  127.     __asm call dwCall
  128. }
  129.  
  130. BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
  131. {
  132.     if (fdwReason == DLL_PROCESS_ATTACH)
  133.     {
  134.         CPatch::RedirectCall(0x53BF49, called);
  135.     }
  136.     return TRUE;
  137. }
Advertisement
Add Comment
Please, Sign In to add comment