OriHackingTutorials

game hacking memory writing

Sep 10th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.14 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <Windows.h>
  4. #include <ctime>
  5. #include <string>
  6. #include <cmath>
  7. DWORD FindDmaAddy(int PointerLevel, HANDLE hProcHandle, DWORD Offsets[], DWORD BaseAddress);
  8. void WriteToMemory(HANDLE hProcHandle);
  9. using namespace std;
  10. std::string GameName = "AssaultCube";
  11. LPCSTR LGameWindow = "AssaultCube";
  12. std::string GameStatus;
  13.  
  14. bool IsGameAvail;
  15. bool UpdateOnNextRun;
  16.  
  17. //ammo variable
  18. bool AmmoStatus;
  19. BYTE AmmoValue[] = {0xA3, 0x1C, 0x0, 0x0};
  20. DWORD AmmoBaseAddress = {0x509B74};
  21. DWORD AmmoOffsets[] = {0x374, 0x14, 0x0};
  22.  
  23. //health variable
  24. bool HealthStatus;
  25. BYTE HealthValue[] = { 0x39, 0x5, 0x0, 0x0 };
  26. DWORD HealthBaseAddress = {0x50f4f4};
  27. DWORD HealthOffsets[] = {0xf8};
  28.  
  29.  
  30.  
  31. int main()
  32. {
  33.     HWND hGameWindow = NULL;
  34.     int timeSinceLastUpdate = clock();
  35.     int GameAvailTMR = clock();
  36.     int onePressTMR = clock();
  37.     DWORD dwProcID = NULL;
  38.     HANDLE hProcHandle = NULL;
  39.     UpdateOnNextRun = true;
  40.     std::string sAmmoStatus = "OFF";
  41.     std::string sHealthStatus = "OFF";
  42.  
  43.     while (!GetAsyncKeyState(VK_INSERT)) {
  44.         if (clock() - GameAvailTMR > 100) {
  45.             GameAvailTMR = clock();
  46.             IsGameAvail = false;
  47.             hGameWindow = FindWindow(NULL, LGameWindow);
  48.             if (hGameWindow) {
  49.                 GetWindowThreadProcessId(hGameWindow, &dwProcID);
  50.                 if (dwProcID != 0)
  51.                 {
  52.                     hProcHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcID);
  53.                     if (hProcHandle == INVALID_HANDLE_VALUE || hProcHandle == NULL) {
  54.                         GameStatus = "failed to open process for valid handle";
  55.                     }
  56.                     else {
  57.                         GameStatus = "AssaultCube Ready To Hack";
  58.                         IsGameAvail = true;
  59.                     }
  60.                 }
  61.                 else GameStatus = "failed to get process id";
  62.  
  63.             }
  64.             else {
  65.                 GameStatus = "Assault not found";
  66.             }
  67.             if (UpdateOnNextRun || clock() - timeSinceLastUpdate > 5000) {
  68.                 system("cls");
  69.                 cout << " ----------------------------------------------------   \n";
  70.                 cout << "|  AssaultCube Memory Hack by Ori's hacking tutorials|   \n";
  71.                 cout << " ----------------------------------------------------   \n";
  72.                 cout << "Game status: " << GameStatus << endl <<endl;
  73.                 cout << "[F1] Unlimited Ammo --> " << sAmmoStatus << " <--" << endl << endl;
  74.                 cout << "[F2] Unlimited Health --> " << sHealthStatus << " <--" << endl << endl;
  75.                 cout << "[INSERT] Exit" <<endl;
  76.                 UpdateOnNextRun = false;
  77.                 timeSinceLastUpdate = clock();
  78.             }
  79.             if (IsGameAvail) {
  80.  
  81.                 //write to memory
  82.                 WriteToMemory(hProcHandle);
  83.             }
  84.         }
  85.         if (clock() - onePressTMR > 400) {
  86.             if (IsGameAvail) {
  87.                 //ammo
  88.  
  89.                 if (GetAsyncKeyState(VK_F1)) {
  90.                     onePressTMR = clock();
  91.                     AmmoStatus = !AmmoStatus;
  92.                     UpdateOnNextRun = true;
  93.                     if (AmmoStatus)sAmmoStatus = "ON";
  94.                     else sAmmoStatus = "OFF";
  95.                 } // if press f1
  96.  
  97.                 //health
  98.                 else if (GetAsyncKeyState(VK_F2)) {
  99.                     onePressTMR = clock();
  100.                     HealthStatus = !HealthStatus;
  101.                     UpdateOnNextRun = true;
  102.                     if (HealthStatus)sHealthStatus = "ON";
  103.                     else sHealthStatus = "OFF";
  104.                 } // if press F2
  105.                 else if (GetAsyncKeyState(VK_INSERT)) {
  106.                     return false;
  107.  
  108.                 }
  109.  
  110.             } // is game avail
  111.         }// if
  112.  
  113.     } // stop while
  114.     //CloseHandle(hProcHandle);
  115.     //CloseHandle(hGameWindow);
  116.  
  117.     return ERROR_SUCCESS;
  118.  
  119. } // main
  120.  
  121. DWORD FindDmaAddy(int PointerLevel, HANDLE hProcHandle, DWORD Offsets[], DWORD BaseAddress) {
  122.     DWORD pointer = BaseAddress;
  123.     DWORD pTemp;
  124.     DWORD pointerAddr;
  125.  
  126.     for (int c = 0; c < PointerLevel; c++) {
  127.         if (c == 0) {
  128.             ReadProcessMemory(hProcHandle, (LPCVOID)pointer, &pTemp, sizeof(pTemp), NULL);
  129.         }
  130.         pointerAddr = pTemp + Offsets[c];
  131.         ReadProcessMemory(hProcHandle, (LPCVOID)pointerAddr, &pTemp, sizeof(pTemp), NULL);
  132.  
  133.     }
  134.     return pointerAddr;
  135. }
  136.  
  137. void WriteToMemory(HANDLE hProcHandle) {
  138.     DWORD AddressToWrite;
  139.     if (AmmoStatus) {
  140.         AddressToWrite = FindDmaAddy(3, hProcHandle,AmmoOffsets, AmmoBaseAddress);
  141.         WriteProcessMemory(hProcHandle, (BYTE*)AddressToWrite, &AmmoValue, sizeof(AmmoValue), NULL);
  142.  
  143.     }
  144.     if (HealthStatus) {
  145.         AddressToWrite = FindDmaAddy(1, hProcHandle, HealthOffsets, HealthBaseAddress);
  146.         WriteProcessMemory(hProcHandle, (BYTE*)AddressToWrite, &HealthValue, sizeof(HealthValue), NULL);
  147.                                              
  148.     }
  149. }
Add Comment
Please, Sign In to add comment