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:
We are going to need a form with some labels on it:
Then you are going to rename those labels to the functions of your trainer:
After this we are going to create a Groupbox and another label for detecting if the game process is running:
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:
Now we are going to make variables for our trainer options and import a function to detect our hotkeys:
Now we are going to create another timer for writting memory and detecting our hotkeys:
Ok now we are ready for importing the functions for opening our game process and writting memory:
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:
CSHARP 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:
CSHARP 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:
CSHARP 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:
We are going to need a form with some labels on it:
Then you are going to rename those labels to the functions of your trainer:
After this we are going to create a Groupbox and another label for detecting if the game process is running:
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:
CSHARP 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:
CSHARP 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);
Now we are going to create another timer for writting memory and detecting our hotkeys:
CSHARP 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:
CSHARP 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:
CSHARP 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
CSHARP 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:
CSHARP 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...