Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <TlHelp32.h>
- #include <iostream>
- #include <TCHAR.h>
- using namespace std;
- DWORD PositionOffsets[] = { 0xE0, 0x620, 0x1E8, 0x90, 0x274 }; //5 LEVEL pointer
- DWORD_PTR dwGetModuleBaseAddress(DWORD dwProcID, TCHAR *szModuleName)
- {
- DWORD_PTR dwModuleBaseAddress = 0;
- HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, dwProcID);
- if (hSnapshot != INVALID_HANDLE_VALUE)
- {
- MODULEENTRY32 ModuleEntry32;
- ModuleEntry32.dwSize = sizeof(MODULEENTRY32);
- if (Module32First(hSnapshot, &ModuleEntry32))
- {
- do
- {
- if (_tcsicmp(ModuleEntry32.szModule, szModuleName) == 0)
- {
- dwModuleBaseAddress = (DWORD_PTR)ModuleEntry32.modBaseAddr;
- break;
- }
- } while (Module32Next(hSnapshot, &ModuleEntry32));
- }
- CloseHandle(hSnapshot);
- }
- return dwModuleBaseAddress;
- }
- //Handles Dynamic memory allocation
- //Receives how high the pointer level is e.g. 4 levels and from that calculates the initial address
- //the offset values and the memory addresses for those offsets
- DWORD FindDmaAddy(int PointerLevel, HANDLE hProcHandle, DWORD Offsets[], DWORD BaseAddress)
- {
- //DECLARE BASE ADDRESS
- DWORD pointer = BaseAddress; // Declare a pointer of DWORD
- //USED TO output the contents in the pointer
- DWORD pTemp;
- DWORD pointerAddr;
- for (int i = 0; i < PointerLevel; i++)
- {
- if (i == 0)
- {
- ReadProcessMemory(hProcHandle, (LPCVOID)pointer, &pTemp, 4, NULL);
- }
- //add first offset to that address
- pointerAddr = pTemp + Offsets[i]; // Set p1 to content of p + offset
- //Read memory one more time and exit the loop
- ReadProcessMemory(hProcHandle, (LPCVOID)pointerAddr, &pTemp, 4, NULL);
- }
- return pointerAddr;
- }
- int main()
- {
- //Simply Finds Window ID from Name
- DWORD pid;
- HWND window = FindWindow(0, ("[Conquer] King-Dragon-Warrior"));
- if (window == 0) {
- printf("Window not found!\n");
- char f;
- cin >> f;
- return 0;
- }
- GetWindowThreadProcessId(window, &pid);
- HANDLE pHandle = OpenProcess(PROCESS_VM_READ, FALSE, pid);
- DWORD modBase;
- DWORD address = 0;
- //Grab our module Base address
- modBase = dwGetModuleBaseAddress(pid, _T("tqanp.dll"));
- cout << &modBase; // This output does not match up with that in cheat engine.
- cout << "\n";
- modBase += 0x2D9EE0; //Add base address to the module address
- ReadProcessMemory(pHandle, (void*)modBase, &address, sizeof(address), nullptr); //read the base address
- DWORD xPosition = FindDmaAddy(5, pHandle, PositionOffsets, address); //Add our offsets to get to xPosition
- cout << xPosition; //Print x Position after finding out what pointer is point to (It's wrong)
- cout << "\n";
- //This works Fine when reading the actuall address.
- ReadProcessMemory(pHandle, (void*)0x58B4A64, &xPosition, sizeof(xPosition), nullptr);
- cout << xPosition; //Correctvalue!
- cin >> xPosition; //Just used to pause program
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement