Advertisement
Guest User

Untitled

a guest
May 26th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.55 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <windows.h>
  5. #include <cstring>
  6. #include <time.h>
  7.  
  8. using namespace std;
  9.  
  10. // Functions
  11. void update_proc_detection();
  12. void update_input();
  13.  
  14. // Global variables
  15. const string Title = "AoK HD Hacker";
  16. const LPSTR LGameWindow = "Age of Empires II: HD Edition";
  17. const int FPS   = 60;
  18. const int fwait = 1000 / FPS;
  19. const int refresh_timer = 5000;
  20. bool running, procOpened, refresh_needed;
  21. HWND HGameWindow;
  22. DWORD procID;
  23. HANDLE procHandle;
  24.  
  25. template <typename T>
  26. struct HackMemory{
  27.  
  28.     DWORD base_address;
  29.     DWORD target_address;
  30.     vector<DWORD> offsets;
  31.     T value;
  32.  
  33.     HackMemory(DWORD base, initializer_list<DWORD> _offsets, T _value = -1){
  34.         base_address = base;
  35.         value = _value;
  36.         for(auto offset:_offsets){
  37.             offsets.push_back(offset);
  38.         }
  39.         FindMemory();
  40.     }
  41.  
  42.     void FindMemory(){
  43.         DWORD temp;
  44.         target_address = base_address;
  45.         ReadProcessMemory(procHandle, (LPCVOID) target_address, &temp,
  46.                            sizeof(temp), NULL);
  47.  
  48.         int _size = offsets.size();
  49.         for(int i=0;i<_size;i++){
  50.             target_address = temp + offsets[i];
  51.             ReadProcessMemory(procHandle, (LPCVOID)target_address, &temp,
  52.                               sizeof(temp), NULL);
  53.         }
  54.     }
  55.  
  56.     void modify(T _value = -1){
  57.         value = _value == -1 ? value : _value;
  58.         if(value == -1)return ;
  59.         printf("Base/Target Address: %x/%x", base_address, target_address);
  60.         cout << "; value: " << value << endl;
  61.         WriteProcessMemory(procHandle,(BYTE*)target_address, &value,
  62.                            sizeof(value), NULL);
  63.     }
  64. };
  65.  
  66. void initialize(){
  67.     running        = true;
  68.     procOpened     = false;
  69.     refresh_needed = true;
  70.     HGameWindow    = NULL;
  71.     procID         = NULL;
  72.     procHandle     = NULL;
  73. }
  74.  
  75. void print_info(){
  76.     system("CLS");
  77.     string split_line = "------------------------------";
  78.     int spacing = (split_line.length() - Title.length()) / 2;
  79.     cout << split_line << endl;
  80.     for(int i=0;i<spacing;i++)cout << ' ';
  81.     cout << Title << endl;
  82.     cout << split_line << endl;
  83.     cout << "Process [" << LGameWindow << "] >> ";
  84.     cout << (procOpened ? "Ready" : "Not detected") << '\n';
  85.     if(procOpened){
  86.         cout << "Press F1 to hack resources\n";
  87.     }
  88.     refresh_needed = false;
  89. }
  90.  
  91. int main(){
  92.     initialize();
  93.     auto LastUpdateTime = clock();
  94.     while(running){
  95.         update_input();
  96.         update_proc_detection();
  97.         if(refresh_needed || LastUpdateTime + refresh_timer < clock()){
  98.             LastUpdateTime = clock();
  99.             print_info();
  100.         }
  101.         Sleep(fwait);
  102.     }
  103.     CloseHandle(procHandle);
  104.     CloseHandle(HGameWindow);
  105.     cout << "Program terminated\n";
  106.     system("pause");
  107.     return 0;
  108. }
  109.  
  110.  
  111. void update_input(){
  112.     bool keys[0xff] = {0};
  113.     for(int i=0;i<0xff;i++){
  114.         keys[i] = GetAsyncKeyState(i);
  115.     }
  116.  
  117.     if(keys[VK_F9]){
  118.         running = false;
  119.     }
  120.  
  121.     if(procOpened && keys[VK_F1]){
  122.         string name[] = {"Wood storage","Food storage",
  123.                          "Gold storage", "Stone storage"};
  124.         // Static pointer base address
  125.         //DWORD RESBase = 0x157c5c0;
  126.         DWORD RESBase = 0x007dc5c0;
  127.         DWORD base_address[] = {RESBase, RESBase, RESBase, RESBase};
  128.         // Pointer offsets
  129.         vector<initializer_list<DWORD>> offsets(4);
  130.         offsets[0] = {0xb08,0x134,0x3c,0x4};
  131.         offsets[1] = {0xb08,0x18c,0x15c,0x3c, 0};
  132.         offsets[2] = {0xb08,0x134,0x3c,0xc};
  133.         offsets[3] = {0xb08,0x134,0x3c,8};
  134.  
  135.         cout << "Enter expect values(-1 for no change)\n";
  136.         for(int i=0;i<4;i++){
  137.             float in;
  138.             cout << name[i] << ": "; cin >> in;
  139.             update_proc_detection();
  140.             if(!procOpened){
  141.                 cout << "Process closed, abort\n";
  142.                 break;
  143.             }
  144.             HackMemory<float> resource(base_address[i], offsets[i], in);
  145.             resource.modify();
  146.         }
  147.         print_info();
  148.         cout << "Done!\n";
  149.         system("pause");
  150.     }
  151. }
  152.  
  153. void update_proc_detection(){
  154.     procOpened = false;
  155.     HGameWindow = FindWindow(NULL, LGameWindow);
  156.     if(!HGameWindow)return ;
  157.  
  158.     GetWindowThreadProcessId(HGameWindow, &procID);
  159.     if(!procID)return ;
  160.  
  161.     procHandle = OpenProcess(PROCESS_ALL_ACCESS, false, procID);
  162.     if(procHandle == INVALID_HANDLE_VALUE || procHandle == NULL)return ;
  163.     procOpened = true;
  164. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement