School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!
Welcome to Dream.In.Code
Become an Expert!

Join 340,125 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 4,048 people online right now. Registration is fast and FREE... Join Now!



C++ Basic Game Cheating

Page 1 of 1

C++ Basic Game Cheating Memory value modification explained. Rate Topic: ****- 4 Votes

#1 RodgerB  Icon User is offline

  • D.I.C Lover
  • Icon
  • View blog
  • Group: Expert w/DIC++
  • Posts: 2,244
  • Joined: 21-September 07


Dream Kudos: 2200

Expert In: Dot Net Technologies

Posted 22 September 2007 - 01:15 AM

In this tutorial, Basic Game Cheating, we will look at creating a basic trainer for MS 3D Pinball.

The Trainer will have the ability to:
  • Determine whether the process is open.
  • Change memory values.
  • Cheat in a game.

Applications we will be using for this tutorial:
  • Microsoft Visual Studio 2005.
  • Cheat Engine 5.x.
  • Microsoft 3D Pinball. (Comes with Windows XP).

Step 1: Finding the memory addresses.

When you want to cheat in a game, in most cases Memory Editing is the best way to go. Its clean, effective and requires no knowledge of ASM. To get these addresses however, it is important that you have the right tools. For this tutorial, we will be using Cheat Engine.
Finding memory addresses can be very time consuming, but as you learn, the faster it will get.

Watch out! - Some memory addresses are dynamic, and change their allocation every time the application is started. These addresses can be very hard to use.

a. Open MS Pinball and start a new game.
You should be able to see the score with the integer value of 0. This is the value we want to get.

b. Open Cheat Engine.
Press the glowing button in the top left hand corner of the program. A Process List Box will appear. Scroll down the list and find PINBALL.EXE, click on it and press ok.

c. Do an initial search.
Because we already know the exact value for the score (0), we can start a search for it. Press the First Scan button. You will see at the top left of the application the amount of memory addresses it found. It is normal for this to be a relatively high value, as the values could represent boolean values, unused variables, etc.

d. Get back into the game, and attempt to score change the value of the score.
This will make the value change in the memory address, and will make our search a hell of a lot easier. Score some points, and pause or kill yourself.

e. Do another search.
We can determine an actual value for the address, and I'll presume its pretty unique so do a Next Scan. If there is more than two addresses in the bar to the left, go back to step d.

f. Trial and Error.
When we only have a 50/50 chance of an address not working, and they both mimic the same value, why not test both? Double click on both of the values and they will be put into Cheat Engine's Memory Address list. Double click on the value on the value column and change it to whatever you like.

After doing this, you would have found out one memory address contains the literal score value (0xA90C62), and another address just copies it (0xA94D1C).

Once you have found the memory address that we need to edit, 0xA90C62, now lets create a C++ app to manipulate this value.

Step 2: Creating our C++ Application.

Here is the code we are going to use, I will explain it further down.

#include <windows.h>
#include <tlhelp32.h>
#include <conio.h>
#include <stdlib.h>

bool ChangeMemVal(const char * ProcessName, LPVOID MemAddress, int NewVal, int size);

void main()
{
	 printf("=== Pinball Trainer Example. Made by <your name here> ===\n\n");
	 if(ChangeMemVal("PINBALL.EXE", (void*) 0xA90C62, 100000000, 4))
		  printf("The score has been edited successfully.\n");
	 else
		  printf("An error occured while attempting edit the score.\n");
	 system("PAUSE");
	 return 0;
}


/* This function modifys a memory address according to its arguments.
   Arguments :
			 ProcessName - the process we want to modify
			 MemAddress - the memory address we want to modify
			 NewVal - the value we want to change the memory address to
			 size - the size of the memory address
   Returns :
		   the success of the edit.
   */


bool ChangeMemVal(const char * ProcessName, LPVOID MemAddress, int NewVal, int size)
{
	 HANDLE hProcessSnap;
	 HANDLE hProcess = NULL;
	 PROCESSENTRY32 pe32;	 
	 hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
	 pe32.dwSize = sizeof( PROCESSENTRY32 );
	 Process32First(hProcessSnap, &pe32);
	 do
	 {		  
		  if(!strcmp(pe32.szExeFile, ProcessName))
		  {
			   hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pe32.th32ProcessID);
			   break;
		  }
	 }
	 while(Process32Next(hProcessSnap, &pe32));
	 CloseHandle( hProcessSnap );
	 if(hProcess != NULL)
	 {
		  WriteProcessMemory(hProcess, MemAddress, &NewVal, size, NULL);	 // write the value		  
		  CloseHandle(hProcess);	 
		  return true;
	 }	 
	 return false;
}



This is a rather simple program. It displays a message, and informs the user if their action was successful. Looking at the arguments of ChangeMemVal(), ProcessName is the name of the process we were editing, if you are unsure of the exact way it is spelt, you can always ctrl+alt+del and see what the process names are. Remember, they are case sensitive. The (void*) typecast is to convert the value to the function can parse it. NewVal is obviously the new value we want the memory address to change to, and size is the size of the memory address. In this case, it is 4 bytes.

Have fun using it! Keep in mind that some anti-cheats may hide their process, and this will result in failure to edit the memory address. As always, your comments are appreciated.
Was This Post Helpful? 0
  • +
  • -


#2 ZachR  Icon User is offline

  • D.I.C Head
  • Icon
  • View blog
  • Group: Contributors
  • Posts: 126
  • Joined: 15-June 08


Dream Kudos: 150

Posted 18 June 2008 - 11:26 PM

This worked greatly! Thanks for the post. Keep it up! xD
Was This Post Helpful? 0
  • +
  • -

#3 tuxWishful  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: New Members
  • Posts: 6
  • Joined: 31-July 08


Dream Kudos: 0

Posted 20 August 2008 - 07:33 AM

This is great! Keep it up the great work you do! ;)
Was This Post Helpful? 0
  • +
  • -

#4 astropirit  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: Members
  • Posts: 17
  • Joined: 22-August 08


Dream Kudos: 0

Posted 09 January 2009 - 06:35 PM

Thanks! got it working outside Microsoft Visual Studio by adding
#include <iostream>

and changing void main() to int main()

Again thanks, helped allot!
Was This Post Helpful? 0
  • +
  • -

#5 parkour86  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: Members
  • Posts: 20
  • Joined: 26-January 09


Dream Kudos: 0

Posted 28 January 2009 - 12:26 PM

The program works great. Is there a way to add to the code so it can freeze the value?

I'm thinking if I put it in an endless loop it will freeze the value or is there a better way?

For example, maybe add a comma after the 4 and put true. If true then freeze the value.

Before:
ChangeMemVal("pinball.exe", (void*) 0x00EB0C62, 10000000, 4)

After:
ChangeMemVal("pinball.exe", (void*) 0x00EB0C62, 10000000, 4, TRUE)

Also are there any good resources on understanding all the commands in the ChangeMemVal function? I don't understand what it's doing.
Was This Post Helpful? 0
  • +
  • -

#6 Cha0sBG  Icon User is offline

  • D.I.C Head
  • Icon
  • Group: Contributors
  • Posts: 149
  • Joined: 09-April 09


Dream Kudos: 50

Posted 18 May 2009 - 03:37 AM

Dont know why but i get an error :S
Score is not changing and all the time it sayd

An error occured while attempting edit the score.


Any suggestions why ? :S


EDIT: ok after i went true the code a few times i figured out why...
On XP PROCESS_ALL_ACESS gives errors :) i just replaced it with

PROCESS_VM_READ | PROCESS_VM_WRITE

but after it "successfully changed the score i didn't saw the score changing :S ....

This post has been edited by Cha0sBG: 18 May 2009 - 03:47 AM

Was This Post Helpful? 0
  • +
  • -

#7 gibson_junk  Icon User is offline

  • D.I.C Head
  • PipPip
  • Group: Members
  • Posts: 68
  • Joined: 23-July 09


Dream Kudos: 0

Posted 24 July 2009 - 12:08 AM

how would you edit this so that it only changes value if the user press something like

Ctrl + ! or Ctrl + 1
Was This Post Helpful? 0
  • +
  • -

#8 sherwood  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: New Members
  • Posts: 2
  • Joined: 20-October 09


Dream Kudos: 0

Posted 20 October 2009 - 12:36 PM

Hello, thanks! Its nice, but how to make it to find non memory adress but value? Because many memory adresseses are dynamic.

It would be nice to find a value for example my nick in a game: PLAYER and to rewrite it to PLAYER 2. thanks
Was This Post Helpful? 0
  • +
  • -

#9 sherwood  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: New Members
  • Posts: 2
  • Joined: 20-October 09


Dream Kudos: 0

Posted 23 October 2009 - 02:28 AM

View PostCha0sBG, on 18 May, 2009 - 03:37 AM, said:

Dont know why but i get an error :S
Score is not changing and all the time it sayd

An error occured while attempting edit the score.


Any suggestions why ? :S


EDIT: ok after i went true the code a few times i figured out why...
On XP PROCESS_ALL_ACESS gives errors :) i just replaced it with

PROCESS_VM_READ | PROCESS_VM_WRITE

but after it "successfully changed the score i didn't saw the score changing :S ....


VM_READ and VM_WRITE is not enough.

This is the solution:
PROCESS_VM_READ | PROCESS_VM_WRITE | PROCESS_VM_OPERATION

This post has been edited by sherwood: 23 October 2009 - 02:29 AM

Was This Post Helpful? 0
  • +
  • -

#10 baseball435  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: Members
  • Posts: 12
  • Joined: 30-November 09


Dream Kudos: 0

Posted 04 January 2010 - 05:00 PM

View Postgibson_junk, on 24 Jul, 2009 - 12:08 AM, said:

how would you edit this so that it only changes value if the user press something like

Ctrl + ! or Ctrl + 1




to do this you will have to put in hotkeys. I dont know the exact code to do that though
Was This Post Helpful? 0
  • +
  • -

#11 shortymant  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: New Members
  • Posts: 8
  • Joined: 17-June 09


Dream Kudos: 0

Posted 10 January 2010 - 03:38 PM

View Postbaseball435, on 4 Jan, 2010 - 05:00 PM, said:

View Postgibson_junk, on 24 Jul, 2009 - 12:08 AM, said:

how would you edit this so that it only changes value if the user press something like

Ctrl + ! or Ctrl + 1




to do this you will have to put in hotkeys. I dont know the exact code to do that though


if( GetAsyncKeyState( Key1_Here )&0x8000 && GetAsyncKeyState( Key2_Here )&0x8000 ) )
{
  //Do you're crap.
}



P.S:
System( "Pause" );


..Never, ever, use system. Extremely bad programming practices.

Editing memory is nice, yeah. But, it's best if you actually get you're hands dirty with the functions inside of "pinball".
Example;

Quote

Update score address - 0x042BAE0
Parameters - ( int nScore )
type - void

typedef isn't the best, but I can't remember the other way off the top of my head.
dwUpdateScoreAddress = 0x0042BAE0;

typedef void( __cdecl* UpdateScoreType ) ( int nScore );
UpdateScoreType UpdateScore = ( UpdateScoreType )dwUpdateScoreAddress;

bool bActivation  = false;

void main( void )
{
  for(;;Sleep( 20 ) ) //Infinite loop
  {
	  if( bActivation = true )
	  { 
		  UpdateScore( 300 );
		  bActivation =! bActivation;
	   }
	   if( GetAsyncKeyState( VK_MENU )&0x8000 && GetAsyncKeyState ( 'L' )&0x8000 )
	   {
		   bActivation =! bActivation;
		}
   }
}

//DLL entry point here *forgot it, lol*


This post has been edited by shortymant: 10 January 2010 - 03:47 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month