Well after releasing the D3D menu trainer in C++ i decided to make something more simple for the people who are starting in making trainers and stuff...
In this tutorial i will cover the following aspects:
- How to Import Functions
- How to detect a Process
- How to Write Process Memory (Editing Memory)
- How to Use GetAsyncKeyState ( Hotkeys )
First Steps:
Includes you are going to need:
Dll Imports:
Variables:
First create a new project:
![[Image: tutn.png]](http://img593.imageshack.us/img593/5543/tutn.png)
We are going to need a form with some labels on it:
![[Image: scaled.php?server=163&filename=tut1z.png&res=medium]](http://desmond.imageshack.us/Himg163/scaled.php?server=163&filename=tut1z.png&res=medium)
Then you are going to rename those labels to the functions of your trainer:
![[Image: scaled.php?server=828&filename=tut2e.png&res=medium]](http://desmond.imageshack.us/Himg828/scaled.php?server=828&filename=tut2e.png&res=medium)
After this we are going to create a Groupbox and another label for detecting if the game process is running:
![[Image: scaled.php?server=38&filename=tut3h.png&res=medium]](http://desmond.imageshack.us/Himg38/scaled.php?server=38&filename=tut3h.png&res=medium)
Now we are going to make the code for detecting the game process:
1 - Create a Timer;
2 - Double Click on the Timer and insert this code:
![[Image: tut4q.png]](http://img109.imageshack.us/img109/9784/tut4q.png)
Now we are going to make variables for our trainer options and import a function to detect our hotkeys:
![[Image: tut4v.png]](http://img839.imageshack.us/img839/4027/tut4v.png)
Now we are going to create another timer for writting memory and detecting our hotkeys:
![[Image: tut5e.png]](http://img849.imageshack.us/img849/4439/tut5e.png)
![[Image: scaled.php?server=807&filename=tut6.png&res=medium]](http://desmond.imageshack.us/Himg807/scaled.php?server=807&filename=tut6.png&res=medium)
Ok now we are ready for importing the functions for opening our game process and writting memory:
![[Image: tut7k.png]](http://img849.imageshack.us/img849/1866/tut7k.png)
And finally we are going to open the game process and writte it memory to get some results:
Open Game Process:
NOP function:
http://www.itsmods.com/forum/Thread-Tuto...-in-C.html
And the final code should be:
Well i know is not that detailed but i think its a good tutorial to start with.
You can do your modifications to design and make it a little less ugly.
Thats all,
Thanks Barata...
PS: the attachment is the compiled trainer.
In this tutorial i will cover the following aspects:
- How to Import Functions
- How to detect a Process
- How to Write Process Memory (Editing Memory)
- How to Use GetAsyncKeyState ( Hotkeys )
First Steps:
Includes you are going to need:
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Windows.Forms;Dll Imports:
Code:
[DllImport("user32.dll")]
public static extern short GetAsyncKeyState(Keys vKey);
[DllImport("kernel32.dll", EntryPoint = "WriteProcessMemory")]
private static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, uint nSize, [Out] int lpNumberOfBytesWritten);
[DllImport("kernel32.dll", EntryPoint = "ReadProcessMemory")]
private static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [Out] byte[] lpBuffer, int dwSize, [Out] int lpNumberOfBytesRead);
[DllImport("kernel32.dll", EntryPoint = "OpenProcess")]
private static extern IntPtr OpenProcess(uint dwDesiredAccess, bool bInheritHandle, int dwProcessId);Variables:
Code:
public int opt1 = 0;
public int opt2 = 0;
public int opt3 = 0;
private static int ProcessID = -1;
private static IntPtr ProcessHandle = IntPtr.Zero;First create a new project:
![[Image: tutn.png]](http://img593.imageshack.us/img593/5543/tutn.png)
We are going to need a form with some labels on it:
![[Image: scaled.php?server=163&filename=tut1z.png&res=medium]](http://desmond.imageshack.us/Himg163/scaled.php?server=163&filename=tut1z.png&res=medium)
Then you are going to rename those labels to the functions of your trainer:
![[Image: scaled.php?server=828&filename=tut2e.png&res=medium]](http://desmond.imageshack.us/Himg828/scaled.php?server=828&filename=tut2e.png&res=medium)
After this we are going to create a Groupbox and another label for detecting if the game process is running:
![[Image: scaled.php?server=38&filename=tut3h.png&res=medium]](http://desmond.imageshack.us/Himg38/scaled.php?server=38&filename=tut3h.png&res=medium)
Now we are going to make the code for detecting the game process:
1 - Create a Timer;
2 - Double Click on the Timer and insert this code:
![[Image: tut4q.png]](http://img109.imageshack.us/img109/9784/tut4q.png)
Code:
System.Diagnostics.Process[] myprocesses = System.Diagnostics.Process.GetProcessesByName("iw5sp");
if (myprocesses.Length != 0)
{
label5.Text = "Mw3 Found!";
label5.ForeColor = Color.Lime;
}Now we are going to make variables for our trainer options and import a function to detect our hotkeys:
Code:
using System.Runtime.InteropServices;//Dont forget to add this to the includes...
///////////////////////////// - Import / Variables - ///////////////////////////////
public int opt1 = 0;
public int opt2 = 0;
public int opt3 = 0;
[DllImport("user32.dll")]
public static extern short GetAsyncKeyState(Keys vKey);![[Image: tut4v.png]](http://img839.imageshack.us/img839/4027/tut4v.png)
Now we are going to create another timer for writting memory and detecting our hotkeys:
![[Image: tut5e.png]](http://img849.imageshack.us/img849/4439/tut5e.png)
![[Image: scaled.php?server=807&filename=tut6.png&res=medium]](http://desmond.imageshack.us/Himg807/scaled.php?server=807&filename=tut6.png&res=medium)
Code:
private void timer2_Tick(object sender, EventArgs e)
{
bool OPT1 = Convert.ToBoolean(GetAsyncKeyState(Keys.F1));
if (OPT1 == true)
{
if (opt1 == 0)
{
opt1 = 1;
}
else
{
opt1 = 0;
}
}
bool OPT2 = Convert.ToBoolean(GetAsyncKeyState(Keys.F2));
if (OPT2 == true)
{
if (opt2 == 0)
{
opt2 = 1;
}
else
{
opt2 = 0;
}
}
bool OPT3 = Convert.ToBoolean(GetAsyncKeyState(Keys.F3));
if (OPT3 == true)
{
if (opt3 == 0)
{
opt3 = 1;
}
else
{
opt3 = 0;
}
}
bool OPT4 = Convert.ToBoolean(GetAsyncKeyState(Keys.F4));
if (OPT4 == true)
{
int activated = 0;
if (activated == 0)
{
}
else
{
}
}
if (opt1 == 1)
{
}
if (opt2 == 1)
{
}
if (opt3 == 1)
{
}
}Ok now we are ready for importing the functions for opening our game process and writting memory:
![[Image: tut7k.png]](http://img849.imageshack.us/img849/1866/tut7k.png)
Code:
private static int ProcessID = -1;
private static IntPtr ProcessHandle = IntPtr.Zero;
[DllImport("kernel32.dll", EntryPoint = "WriteProcessMemory")]
private static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, uint nSize, [Out] int lpNumberOfBytesWritten);
[DllImport("kernel32.dll", EntryPoint = "ReadProcessMemory")]
private static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [Out] byte[] lpBuffer, int dwSize, [Out] int lpNumberOfBytesRead);
[DllImport("kernel32.dll", EntryPoint = "OpenProcess")]
private static extern IntPtr OpenProcess(uint dwDesiredAccess, bool bInheritHandle, int dwProcessId);And finally we are going to open the game process and writte it memory to get some results:
Open Game Process:
Code:
private void timer1_Tick(object sender, EventArgs e)
{
System.Diagnostics.Process[] myprocesses = System.Diagnostics.Process.GetProcessesByName("iw5sp");
if (myprocesses.Length != 0)
{
label5.Text = "Mw3 Found!";
label5.ForeColor = Color.Lime;
timer2.Start();
Process[] processes = Process.GetProcessesByName("iw5sp"); // in the "iw5sp" is the name of the process
ProcessID = processes[0].Id;
ProcessHandle = OpenProcess(0x001F0FFF/*PROCESS_ALL_ACCESS*/, false, ProcessID);
}
}NOP function:
http://www.itsmods.com/forum/Thread-Tuto...-in-C.html
Code:
private void timer2_Tick(object sender, EventArgs e)
{
bool OPT1 = Convert.ToBoolean(GetAsyncKeyState(Keys.F1));
if (OPT1 == true)
{
if (opt1 == 0)
{
opt1 = 1;
label1.ForeColor = Color.Lime;
}
else
{
opt1 = 0;
label1.ForeColor = Color.Red;
}
}
bool OPT2 = Convert.ToBoolean(GetAsyncKeyState(Keys.F2));
if (OPT2 == true)
{
if (opt2 == 0)
{
opt2 = 1;
label2.ForeColor = Color.Lime;
}
else
{
opt2 = 0;
label2.ForeColor = Color.Red;
}
}
bool OPT3 = Convert.ToBoolean(GetAsyncKeyState(Keys.F3));
if (OPT3 == true)
{
if (opt3 == 0)
{
opt3 = 1;
label3.ForeColor = Color.Lime;
}
else
{
opt3 = 0;
label3.ForeColor = Color.Red;
}
}
bool OPT4 = Convert.ToBoolean(GetAsyncKeyState(Keys.F4));
if (OPT4 == true)
{
int activated = 0;
if (activated == 0)
{
byte[] nop = { 0x90, 0x90, 0x90, 0x90, 0x90 };// 5 bytes
WriteProcessMemory(ProcessHandle, (IntPtr)0x004DBB96, nop, 5/*amount of bytes written(5)*/, 0);
label4.ForeColor = Color.Lime;
activated = 1;
}
else
{
byte[] nop = { 0xE8, 0xC5, 0x72, 0x03, 0x00 };// 5 bytes
WriteProcessMemory(ProcessHandle, (IntPtr)0x004DBB96, nop, 5/*amount of bytes written(5)*/, 0);
label4.ForeColor = Color.Red;
activated = 0;
}
}
if (opt1 == 1)
{
int val = 999;
WriteProcessMemory(ProcessHandle, (IntPtr)0x012A7AA0, BitConverter.GetBytes(val), 4, 0);
WriteProcessMemory(ProcessHandle, (IntPtr)0x012A7B18, BitConverter.GetBytes(val), 4, 0);
WriteProcessMemory(ProcessHandle, (IntPtr)0x012A7AA8, BitConverter.GetBytes(val), 4, 0);
WriteProcessMemory(ProcessHandle, (IntPtr)0x012A7B24, BitConverter.GetBytes(val), 4, 0);
WriteProcessMemory(ProcessHandle, (IntPtr)0x012A7B30, BitConverter.GetBytes(val), 4, 0);
WriteProcessMemory(ProcessHandle, (IntPtr)0x012A7B48, BitConverter.GetBytes(val), 4, 0);
WriteProcessMemory(ProcessHandle, (IntPtr)0x012A7B54, BitConverter.GetBytes(val), 4, 0);
WriteProcessMemory(ProcessHandle, (IntPtr)0x012A7B3C, BitConverter.GetBytes(val), 4, 0);
}
if (opt2 == 1)
{
int val = 999;
WriteProcessMemory(ProcessHandle, (IntPtr)0x010BD628, BitConverter.GetBytes(val), 4, 0);
}
if (opt3 == 1)
{
int val = 0;
WriteProcessMemory(ProcessHandle, (IntPtr)0x12A7948, BitConverter.GetBytes(val), 4, 0);
WriteProcessMemory(ProcessHandle, (IntPtr)0x8ABA88, BitConverter.GetBytes(val), 4, 0);
}
}And the final code should be:
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Windows.Forms;
namespace Mw3_Trainer_tuto
{
public partial class Form1 : Form
{
public int opt1 = 0;
public int opt2 = 0;
public int opt3 = 0;
private static int ProcessID = -1;
private static IntPtr ProcessHandle = IntPtr.Zero;
public Form1()
{
InitializeComponent();
}
[DllImport("user32.dll")]
public static extern short GetAsyncKeyState(Keys vKey);
[DllImport("kernel32.dll", EntryPoint = "WriteProcessMemory")]
private static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, uint nSize, [Out] int lpNumberOfBytesWritten);
[DllImport("kernel32.dll", EntryPoint = "ReadProcessMemory")]
private static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [Out] byte[] lpBuffer, int dwSize, [Out] int lpNumberOfBytesRead);
[DllImport("kernel32.dll", EntryPoint = "OpenProcess")]
private static extern IntPtr OpenProcess(uint dwDesiredAccess, bool bInheritHandle, int dwProcessId);
private void Form1_Load(object sender, EventArgs e)
{
timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
System.Diagnostics.Process[] myprocesses = System.Diagnostics.Process.GetProcessesByName("iw5sp");
if (myprocesses.Length != 0)
{
label5.Text = "Mw3 Found!";
label5.ForeColor = Color.Lime;
timer2.Start();
Process[] processes = Process.GetProcessesByName("iw5sp"); // in the "iw5sp" is the name of the process
ProcessID = processes[0].Id;
ProcessHandle = OpenProcess(0x001F0FFF/*PROCESS_ALL_ACCESS*/, false, ProcessID);
}
}
private void timer2_Tick(object sender, EventArgs e)
{
bool OPT1 = Convert.ToBoolean(GetAsyncKeyState(Keys.F1));
if (OPT1 == true)
{
if (opt1 == 0)
{
opt1 = 1;
label1.ForeColor = Color.Lime;
}
else
{
opt1 = 0;
label1.ForeColor = Color.Red;
}
}
bool OPT2 = Convert.ToBoolean(GetAsyncKeyState(Keys.F2));
if (OPT2 == true)
{
if (opt2 == 0)
{
opt2 = 1;
label2.ForeColor = Color.Lime;
}
else
{
opt2 = 0;
label2.ForeColor = Color.Red;
}
}
bool OPT3 = Convert.ToBoolean(GetAsyncKeyState(Keys.F3));
if (OPT3 == true)
{
if (opt3 == 0)
{
opt3 = 1;
label3.ForeColor = Color.Lime;
}
else
{
opt3 = 0;
label3.ForeColor = Color.Red;
}
}
bool OPT4 = Convert.ToBoolean(GetAsyncKeyState(Keys.F4));
if (OPT4 == true)
{
int activated = 0;
if (activated == 0)
{
byte[] nop = { 0x90, 0x90, 0x90, 0x90, 0x90 };// 5 bytes
WriteProcessMemory(ProcessHandle, (IntPtr)0x004DBB96, nop, 5/*amount of bytes written(5)*/, 0);
label4.ForeColor = Color.Lime;
activated = 1;
}
else
{
byte[] nop = { 0xE8, 0xC5, 0x72, 0x03, 0x00 };// 5 bytes
WriteProcessMemory(ProcessHandle, (IntPtr)0x004DBB96, nop, 5/*amount of bytes written(5)*/, 0);
label4.ForeColor = Color.Red;
activated = 0;
}
}
if (opt1 == 1)
{
int val = 999;
WriteProcessMemory(ProcessHandle, (IntPtr)0x012A7AA0, BitConverter.GetBytes(val), 4, 0);
WriteProcessMemory(ProcessHandle, (IntPtr)0x012A7B18, BitConverter.GetBytes(val), 4, 0);
WriteProcessMemory(ProcessHandle, (IntPtr)0x012A7AA8, BitConverter.GetBytes(val), 4, 0);
WriteProcessMemory(ProcessHandle, (IntPtr)0x012A7B24, BitConverter.GetBytes(val), 4, 0);
WriteProcessMemory(ProcessHandle, (IntPtr)0x012A7B30, BitConverter.GetBytes(val), 4, 0);
WriteProcessMemory(ProcessHandle, (IntPtr)0x012A7B48, BitConverter.GetBytes(val), 4, 0);
WriteProcessMemory(ProcessHandle, (IntPtr)0x012A7B54, BitConverter.GetBytes(val), 4, 0);
WriteProcessMemory(ProcessHandle, (IntPtr)0x012A7B3C, BitConverter.GetBytes(val), 4, 0);
}
if (opt2 == 1)
{
int val = 999;
WriteProcessMemory(ProcessHandle, (IntPtr)0x010BD628, BitConverter.GetBytes(val), 4, 0);
}
if (opt3 == 1)
{
int val = 0;
WriteProcessMemory(ProcessHandle, (IntPtr)0x12A7948, BitConverter.GetBytes(val), 4, 0);
WriteProcessMemory(ProcessHandle, (IntPtr)0x8ABA88, BitConverter.GetBytes(val), 4, 0);
}
}
}
}Well i know is not that detailed but i think its a good tutorial to start with.
You can do your modifications to design and make it a little less ugly.
Thats all,
Thanks Barata...
PS: the attachment is the compiled trainer.
Don't worry if things aren't the way you planned, in the end everything will solve itself...





+Rep!

![[Image: tagssmall.png]](http://i1212.photobucket.com/albums/cc459/rotceh_dnih/tagssmall.png)

