Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Windows.h>
- #include "CPatch.h"
- #include <cstdint>
- enum eTaskType
- {
- TASK_SIMPLE_USE_GUN = 0x3F9
- };
- struct CPlayerPed;
- struct CTask;
- struct CTaskManager
- {
- CTask *m_aPrimaryTasks[5];
- CTask *m_aSecondaryTasks[6];
- struct CPlayerPed *m_pPed;
- };
- struct CPedAI
- {
- CPlayerPed * pPed;
- CTaskManager TaskManager;
- };
- struct CPlayerPed
- {
- BYTE Pad[0x47C];
- CPedAI * pPedAI; // 0x47C
- };
- struct CTask_VTBL
- {
- DWORD dw1; // +0x0
- DWORD dw2; // +0x4
- DWORD dw3; // +0x8
- DWORD dw4; // +0xC
- DWORD GET_TASK_ID; // +0x10
- };
- struct CTask
- {
- CTask_VTBL * vtbl;
- };
- auto FindPlayerPed = (CPlayerPed *(*)(int)) 0x56E210;
- auto CTaskManager__GetSimplestActiveTask = (CTask *(__thiscall *)(CTaskManager *)) 0x6819D0;
- void reLoad()
- {
- int bSlot;
- int cuw;
- cuw = *(int *)0xBAA410;
- if (cuw >= 0 && cuw <= 1) return;//bSlot = 0;
- else if (cuw >= 2 && cuw <= 9) return;//bSlot = 1;
- else if (cuw >= 10 && cuw <= 15) return;//bSlot = 10;
- else if ((cuw >= 16 && cuw <= 18) || cuw == 39) return;//bSlot = 8;
- else if (cuw >= 22 && cuw <= 24) bSlot = 2;
- else if (cuw == 25) return; //WeaponID 25 is shotgun that doesn't need reload
- else if (cuw >= 26 && cuw <= 27) bSlot = 3;
- else if ((cuw >= 28 && cuw <= 29) || cuw == 32) bSlot = 4;
- else if (cuw >= 30 && cuw <= 31) bSlot = 5;
- else if (cuw >= 33 && cuw <= 34) return;//bSlot = 6;
- else if (cuw >= 35 && cuw <= 38) return;//bSlot = 7;
- else if (cuw == 40) return;//bSlot = 12;
- else if (cuw >= 41 && cuw <= 43) return;//bSlot = 9;
- else if (cuw >= 44 && cuw <= 46) return;//bSlot = 11;
- else return;
- DWORD address2 = ((*(int*)0xB6F5F0) + 1440) + (28 * bSlot) + 8;
- int ammohave = *(int *)address2;
- switch (cuw)
- {
- case 22:
- if (ammohave >= 17) return;
- break;
- case 23:
- if (ammohave >= 17) return;
- break;
- case 24:
- if (ammohave >= 7) return;
- break;
- case 26:
- if (ammohave >= 4) return;
- break;
- case 27:
- if (ammohave >= 7) return;
- break;
- case 28:
- if (ammohave >= 100) return;
- break;
- case 29:
- if (ammohave >= 30) return;
- break;
- case 30:
- if (ammohave >= 30) return;
- break;
- case 31:
- if (ammohave >= 50) return;
- break;
- case 32:
- if (ammohave >= 100) return;
- break;
- default:
- return;
- }
- DWORD address = ((*(int*)0xB6F5F0) + 1440) + (28 * bSlot) + 4;
- CPatch::SetUInt(address, 2);
- }
- void called()
- {
- DWORD dwCall = 0x572D10;
- if (GetAsyncKeyState(0x52) & 0x8000)
- {
- CPlayerPed * pPed = FindPlayerPed(-1);
- CTask* pTask = CTaskManager__GetSimplestActiveTask(&pPed->pPedAI->TaskManager);
- auto getTaskId = (int(__thiscall *)(CTask *)) pTask->vtbl->GET_TASK_ID;
- if (getTaskId(pTask) != TASK_SIMPLE_USE_GUN)
- {
- reLoad();
- }
- }
- __asm call dwCall
- }
- BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
- {
- if (fdwReason == DLL_PROCESS_ATTACH)
- {
- CPatch::RedirectCall(0x53BF49, called);
- }
- return TRUE;
- }
Advertisement
Add Comment
Please, Sign In to add comment