Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <vector>
- #include <windows.h>
- #include <cstring>
- #include <time.h>
- using namespace std;
- // Functions
- void update_proc_detection();
- void update_input();
- // Global variables
- const string Title = "AoK HD Hacker";
- const LPSTR LGameWindow = "Age of Empires II: HD Edition";
- const int FPS = 60;
- const int fwait = 1000 / FPS;
- const int refresh_timer = 5000;
- bool running, procOpened, refresh_needed;
- HWND HGameWindow;
- DWORD procID;
- HANDLE procHandle;
- template <typename T>
- struct HackMemory{
- DWORD base_address;
- DWORD target_address;
- vector<DWORD> offsets;
- T value;
- HackMemory(DWORD base, initializer_list<DWORD> _offsets, T _value = -1){
- base_address = base;
- value = _value;
- for(auto offset:_offsets){
- offsets.push_back(offset);
- }
- FindMemory();
- }
- void FindMemory(){
- DWORD temp;
- target_address = base_address;
- ReadProcessMemory(procHandle, (LPCVOID) target_address, &temp,
- sizeof(temp), NULL);
- int _size = offsets.size();
- for(int i=0;i<_size;i++){
- target_address = temp + offsets[i];
- ReadProcessMemory(procHandle, (LPCVOID)target_address, &temp,
- sizeof(temp), NULL);
- }
- }
- void modify(T _value = -1){
- value = _value == -1 ? value : _value;
- if(value == -1)return ;
- printf("Base/Target Address: %x/%x", base_address, target_address);
- cout << "; value: " << value << endl;
- WriteProcessMemory(procHandle,(BYTE*)target_address, &value,
- sizeof(value), NULL);
- }
- };
- void initialize(){
- running = true;
- procOpened = false;
- refresh_needed = true;
- HGameWindow = NULL;
- procID = NULL;
- procHandle = NULL;
- }
- void print_info(){
- system("CLS");
- string split_line = "------------------------------";
- int spacing = (split_line.length() - Title.length()) / 2;
- cout << split_line << endl;
- for(int i=0;i<spacing;i++)cout << ' ';
- cout << Title << endl;
- cout << split_line << endl;
- cout << "Process [" << LGameWindow << "] >> ";
- cout << (procOpened ? "Ready" : "Not detected") << '\n';
- if(procOpened){
- cout << "Press F1 to hack resources\n";
- }
- refresh_needed = false;
- }
- int main(){
- initialize();
- auto LastUpdateTime = clock();
- while(running){
- update_input();
- update_proc_detection();
- if(refresh_needed || LastUpdateTime + refresh_timer < clock()){
- LastUpdateTime = clock();
- print_info();
- }
- Sleep(fwait);
- }
- CloseHandle(procHandle);
- CloseHandle(HGameWindow);
- cout << "Program terminated\n";
- system("pause");
- return 0;
- }
- void update_input(){
- bool keys[0xff] = {0};
- for(int i=0;i<0xff;i++){
- keys[i] = GetAsyncKeyState(i);
- }
- if(keys[VK_F9]){
- running = false;
- }
- if(procOpened && keys[VK_F1]){
- string name[] = {"Wood storage","Food storage",
- "Gold storage", "Stone storage"};
- // Static pointer base address
- //DWORD RESBase = 0x157c5c0;
- DWORD RESBase = 0x007dc5c0;
- DWORD base_address[] = {RESBase, RESBase, RESBase, RESBase};
- // Pointer offsets
- vector<initializer_list<DWORD>> offsets(4);
- offsets[0] = {0xb08,0x134,0x3c,0x4};
- offsets[1] = {0xb08,0x18c,0x15c,0x3c, 0};
- offsets[2] = {0xb08,0x134,0x3c,0xc};
- offsets[3] = {0xb08,0x134,0x3c,8};
- cout << "Enter expect values(-1 for no change)\n";
- for(int i=0;i<4;i++){
- float in;
- cout << name[i] << ": "; cin >> in;
- update_proc_detection();
- if(!procOpened){
- cout << "Process closed, abort\n";
- break;
- }
- HackMemory<float> resource(base_address[i], offsets[i], in);
- resource.modify();
- }
- print_info();
- cout << "Done!\n";
- system("pause");
- }
- }
- void update_proc_detection(){
- procOpened = false;
- HGameWindow = FindWindow(NULL, LGameWindow);
- if(!HGameWindow)return ;
- GetWindowThreadProcessId(HGameWindow, &procID);
- if(!procID)return ;
- procHandle = OpenProcess(PROCESS_ALL_ACCESS, false, procID);
- if(procHandle == INVALID_HANDLE_VALUE || procHandle == NULL)return ;
- procOpened = true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement