 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
deathmock5 How do I cheat?
Reputation: 0
Joined: 19 Nov 2015 Posts: 2
|
Posted: Thu Nov 19, 2015 10:44 pm Post subject: [c++] problem with getting value. |
|
|
So, haveng small problem with getting some data.
One value of type double, works without a hitch.
Another value, of type byte, dosnt work at all.
| Code: |
//#include "stdafx.h" //Not used in example
//#include "Serial.h" //Ditto
#include <windows.h>
#include <stdio.h>
#include <iostream> // std::cout
#include <string>
#include <sstream>
#include <iomanip>
#include <Windows.h>
#include <TlHelp32.h> //PROCESSENTRY
#include <thread>
#include <mutex> // std::mutex
#include <conio.h>
#include <fstream>
#include <algorithm>
//Definitions for information.
#define _CRT_SECURE_NO_WARNINGS
#define UNINITIALIZED 0xFFFFFFFF
#define PRINTKEY 0x42
#define JUMPPRINT 0x50
#define CASHKEY 0x36
using namespace std;
//variables.
std::mutex mtx; // mutex for critical section
const DWORD MONEYADDRESS = 0x004B7560;
const DWORD WINDOWOPEN = 0x0012FA8F;
const string GAMENAME = "PTGAME.EXE";
const char* WINDOWNAME = "4.044a";
DWORD processID_ = NULL;
DWORD processBaseAddress_ = UNINITIALIZED;
DWORD bace = NULL;
HANDLE phandle = NULL;
HWND hwnd = NULL; //Finally a handle to our window
DWORD pid = NULL;
int main()
{
if (getSetup())
{
double cash = getValFromMemoryAddress(MONEYADDRESS, cash);
cout << "Cash:" << cash << endl; //Works perfectly fine.
byte gstate = getValFromMemoryAddress(WINDOWOPEN, gstate); //Object is a byte(boolean) for what menu is up, either like 0 or 1.
cout << "STATE: " << gstate << "size:" << sizeof(gstate)<< endl; //Allways 0. and no idea why.
return 1;
}
cin.get();
return 0;
}
DWORD getBaceAddress(const char* processName_)
{
// 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
{
char *str = new char[4046];
wcstombs(str, GetWC(processEntry_.szExeFile), 12);
// Compare the name of the process to the one we want
if (!strcmp(str, 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;
HWND hwnd = FindWindow(0, TEXT("4.044a"));
GetWindowThreadProcessId(hwnd, &processID_);
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 NULL;
}
string lowercase = mtoLower(processName_);
cout << "Finding bace address of: " << processName_ << "||" << lowercase << endl;
// Find base address
do
{
char *str = new char[4046];
wcstombs(str, GetWC(moduleEntry_.szModule), 12);
// Compare the name of the process to the one we want
cout << "MOD: " << str;
if (!strcmp(str, processName_) || !strcmp(str, lowercase.c_str())) //?
{
cout << "==" << processName_ << endl;
// Save the processID and break out
processBaseAddress_ = (unsigned int)moduleEntry_.modBaseAddr;
break;
}
else
{
cout << " != " << processName_ << " || " << lowercase << endl;
}
} while (Module32Next(moduleSnapshotHandle_, &moduleEntry_));
if (processBaseAddress_ == UNINITIALIZED)
{
cout << "Failed to find the bace address." << endl;
}
// Found module and base address successfully
CloseHandle(moduleSnapshotHandle_);
}
return processBaseAddress_;
}
template<typename T>
T getValFromMemoryAddress(DWORD address,T want)
{
SIZE_T stBytes = 0;
if (ReadProcessMemory(phandle, (LPVOID)(address + bace), &want, sizeof(want), &stBytes)) {
return want;
}
else {
cout << "Unable to read memory at (bace+address): " << (address + bace) << endl;
cout << "It is posible that this address is not in the program" << endl;
cout << "It is also posible that we were unable to determine the bace address of the program correctly." << endl;
cin.get();
}
return NULL;
}
const wchar_t *GetWC(const char *c)
{
const size_t cSize = strlen(c) + 1;
wchar_t* wc = new wchar_t[cSize];
mbstowcs(wc, c, cSize);
return wc;
}
template<typename T>
std::string toString(T val)
{
std::stringstream ss("");
ss << val;
return ss.str();
}
char* tochar(string s)
{
char *cstr = new char[s.length() + 1];
strcpy(cstr, s.c_str());
return cstr;
}
string mtoLower(const char* input)
{
string output = string(input);
std::transform(output.begin(), output.end(), output.begin(), ::tolower);
return string(output);
}
|
I think this is a working example, i just ripped it from my code and removed alot of the unnecessary components.
I also removed my threading and serial components cause it wouldn't work right with them in.
The problem is the window open variable. Everything else, (As far as i can tell) works perfectly fine.
As for the game, it wouldn't help much me giving you the name of it, as there is very few who have it and can run it, it requires a special setup with a serial board to function, a custom usb stick to enable a normal windows environment and runs in windows SE.
Tried pointer scanning, after reboot it always returns 0.
Strangely tho, the address in the scan results is always the same. After reboot, switing users, always.
|
|
| Back to top |
|
 |
Zanzer I post too much
Reputation: 126
Joined: 09 Jun 2013 Posts: 3278
|
Posted: Thu Nov 19, 2015 11:49 pm Post subject: |
|
|
| Have you tried printing the address it is accessing and seeing if it's what you expect?
|
|
| Back to top |
|
 |
deathmock5 How do I cheat?
Reputation: 0
Joined: 19 Nov 2015 Posts: 2
|
Posted: Fri Nov 20, 2015 7:44 pm Post subject: |
|
|
So after combing the entire thing, i figured out the problem, first. the game is retarded. It stores the cash in memory in like... 20k places which explains why the money worked. (Just think about that for a second, i was doing bace+bace+value instead of just b+v and it still worked)
But changed it, and both of them work.
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|