cysio528 How do I cheat?
Reputation: 0
Joined: 06 Feb 2017 Posts: 1
|
Posted: Wed Feb 08, 2017 6:19 am Post subject: Writting Cheat Engine pointer into c++ code |
|
|
Hello
At the beggining i would like to apologise for my english.
So i'm not new to programming in general, but i'm new to this type of low lvl programming. I have problem with translating pointer that i found in cheat engine into my c++ aplication.
So first, this is my pointer (it works on other PCs and after restarting the game)
(Image below since i cannot post urls)
And there is my code which i use trying to get that value;
pastebin: pastebin,com/ej0ati8s (change , to .)
code:
Code: | // ConsoleApplication3.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <windows.h>
#include <String.h>
#include <TlHelp32.h>
#include <tchar.h>
DWORD getBaseAddress(const char* processName) {
#define _CRT_SECURE_NO_WARNINGS
#define UNINITIALIZED 0xFFFFFFFF
const char* processName_ = processName;
DWORD processID_ = NULL;
DWORD processBaseAddress_ = UNINITIALIZED;
/* Get the process ID */
{
PROCESSENTRY32 processEntry_; // Entry into process you wish to inject to
HANDLE hProcSnapshot_ = NULL;
/* Takes a snapshot of the system's processes */
hProcSnapshot_ = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); //?
/* While process has not been found, keep looking for it */
while (!processID_)
{
/* If a process on the system exists */
if (Process32First(hProcSnapshot_, &processEntry_)) //?
{
/* Check all processes in the system's processes snapshot */
do
{
/* Compare the name of the process to the one we want */
if (!strcmp(processEntry_.szExeFile, processName_)) //?
{
/* Save the processID and break out */
processID_ = processEntry_.th32ProcessID;
break;
}
} while (Process32Next(hProcSnapshot_, &processEntry_));
}
/* Didnt find process, sleep for a bit */
if (!processID_)
{
system("CLS");
std::cout << "Make sure " << processName_ << " is running." << std::endl;
Sleep(200);
}
}
/* Process found */
std::cout << "Found Process: " << processName_ << std::endl;
}
/* Find Base Address of process */
{
HANDLE moduleSnapshotHandle_ = INVALID_HANDLE_VALUE;
MODULEENTRY32 moduleEntry_;
/* Take snapshot of all the modules in the process */
moduleSnapshotHandle_ = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, processID_);
/* Snapshot failed */
if (moduleSnapshotHandle_ == INVALID_HANDLE_VALUE)
{
std::cout << "Module Snapshot error" << std::endl;
return 0;
}
/* Size the structure before usage */
moduleEntry_.dwSize = sizeof(MODULEENTRY32);
/* Retrieve information about the first module */
if (!Module32First(moduleSnapshotHandle_, &moduleEntry_))
{
std::cout << "First module not found" << std::endl;
CloseHandle(moduleSnapshotHandle_);
return 0;
}
/* Find base address */
while (processBaseAddress_ == UNINITIALIZED)
{
/* Find module of the executable */
do
{
/* Compare the name of the process to the one we want */
if (!strcmp(moduleEntry_.szModule, processName_)) //?
{
/* Save the processID and break out */
processBaseAddress_ = (unsigned int)moduleEntry_.modBaseAddr;
break;
}
} while (Module32Next(moduleSnapshotHandle_, &moduleEntry_));
if (processBaseAddress_ == UNINITIALIZED)
{
system("CLS");
std::cout << "Failed to find module" << processName_ << std::endl;
Sleep(200);
}
}
/* Found module and base address successfully */
std::cout << "Base Address: " << std::hex << processBaseAddress_ << std::dec << std::endl;
CloseHandle(moduleSnapshotHandle_);
}
return processBaseAddress_;
}
int main()
{
const char* processName= "xxx.exe";
DWORD baseAdress = getBaseAddress(processName);
HWND window = FindWindow(NULL, "xxx");
DWORD processId;
GetWindowThreadProcessId(window, &processId);
HANDLE processHandleRead = OpenProcess(PROCESS_VM_READ, false, processId);
DWORD pointer1, pointer2;
double mana;
//offsets
int baseOffset = 0x00545A94;
int manaOffset = 0x360;
ReadProcessMemory(processHandleRead, (LPCVOID)(baseAdress + baseOffset), &pointer1, sizeof(double), NULL);
ReadProcessMemory(processHandleRead, (LPCVOID)(baseAdress + manaOffset), &mana, sizeof(double), NULL);
std::cout << std::hex << pointer1 << "\n";
std::cout << std::hex << baseAdress << "\n";
std::cout << mana;
std::cin.get();
return 0;
} |
And i get wrong values for some reason. Or maybe they are not wrong, but these are not the one i would expect and i need. I guess its problem with
from cheat engine pointer that i dont know how to translate it into c++. Shouldnt "xxx.exe" be base address that i get from getBaseAddress function? Or am i wrong?
///edit
i found my mistake, i in
Code: | ReadProcessMemory(processHandleRead, (LPCVOID)(baseAdress + baseOffset), &pointer1, sizeof(DWORD), NULL);
ReadProcessMemory(processHandleRead, (LPCVOID)(baseAdress + manaOffset), &mana, sizeof(double), NULL); |
i had 2 time baseAdress instead of baseAddress and pointer1
Description: |
|
Filesize: |
28.6 KB |
Viewed: |
3580 Time(s) |

|
|
|