• 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tutorial] Mw3 C# Base Trainer
#1
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:

CSHARP Code
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Runtime.InteropServices;
  9. using System.Diagnostics;
  10. using System.Windows.Forms;


Dll Imports:

CSHARP Code
  1. [DllImport("user32.dll")]
  2. public static extern short GetAsyncKeyState(Keys vKey);
  3.  
  4. [DllImport("kernel32.dll", EntryPoint = "WriteProcessMemory")]
  5. private static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, uint nSize, [Out] int lpNumberOfBytesWritten);
  6.  
  7.  
  8. [DllImport("kernel32.dll", EntryPoint = "ReadProcessMemory")]
  9. private static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [Out] byte[] lpBuffer, int dwSize, [Out] int lpNumberOfBytesRead);
  10.  
  11. [DllImport("kernel32.dll", EntryPoint = "OpenProcess")]
  12. private static extern IntPtr OpenProcess(uint dwDesiredAccess, bool bInheritHandle, int dwProcessId);


Variables:

CSHARP Code
  1. public int opt1 = 0;
  2. public int opt2 = 0;
  3. public int opt3 = 0;
  4.  
  5. private static int ProcessID = -1;
  6. private static IntPtr ProcessHandle = IntPtr.Zero;


First create a new project:

[Image: tutn.png]

We are going to need a form with some labels on it:

[Image: 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]

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]

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]

CSHARP Code
  1. System.Diagnostics.Process[] myprocesses = System.Diagnostics.Process.GetProcessesByName("iw5sp");
  2. if (myprocesses.Length != 0)
  3. {
  4. label5.Text = "Mw3 Found!";
  5. label5.ForeColor = Color.Lime;
  6.  
  7. }


Now we are going to make variables for our trainer options and import a function to detect our hotkeys:

CSHARP Code
  1. using System.Runtime.InteropServices;//Dont forget to add this to the includes...
  2.  
  3. ///////////////////////////// - Import / Variables - ///////////////////////////////
  4.  
  5. public int opt1 = 0;
  6. public int opt2 = 0;
  7. public int opt3 = 0;
  8.  
  9. [DllImport("user32.dll")]
  10. public static extern short GetAsyncKeyState(Keys vKey);


[Image: tut4v.png]

Now we are going to create another timer for writting memory and detecting our hotkeys:

[Image: tut5e.png]

[Image: scaled.php?server=807&filename=tut6.png&res=medium]

CSHARP Code
  1. private void timer2_Tick(object sender, EventArgs e)
  2. {
  3. bool OPT1 = Convert.ToBoolean(GetAsyncKeyState(Keys.F1));
  4. if (OPT1 == true)
  5. {
  6. if (opt1 == 0)
  7. {
  8. opt1 = 1;
  9. }
  10. else
  11. {
  12. opt1 = 0;
  13. }
  14. }
  15. bool OPT2 = Convert.ToBoolean(GetAsyncKeyState(Keys.F2));
  16. if (OPT2 == true)
  17. {
  18. if (opt2 == 0)
  19. {
  20. opt2 = 1;
  21. }
  22. else
  23. {
  24. opt2 = 0;
  25. }
  26. }
  27. bool OPT3 = Convert.ToBoolean(GetAsyncKeyState(Keys.F3));
  28. if (OPT3 == true)
  29. {
  30. if (opt3 == 0)
  31. {
  32. opt3 = 1;
  33. }
  34. else
  35. {
  36. opt3 = 0;
  37. }
  38. }
  39. bool OPT4 = Convert.ToBoolean(GetAsyncKeyState(Keys.F4));
  40. if (OPT4 == true)
  41. {
  42. int activated = 0;
  43. if (activated == 0)
  44. {
  45.  
  46. }
  47. else
  48. {
  49.  
  50. }
  51. }
  52. if (opt1 == 1)
  53. {
  54.  
  55. }
  56. if (opt2 == 1)
  57. {
  58.  
  59. }
  60. if (opt3 == 1)
  61. {
  62.  
  63. }
  64. }


Ok now we are ready for importing the functions for opening our game process and writting memory:

[Image: tut7k.png]

CSHARP Code
  1. private static int ProcessID = -1;
  2. private static IntPtr ProcessHandle = IntPtr.Zero;
  3.  
  4. [DllImport("kernel32.dll", EntryPoint = "WriteProcessMemory")]
  5. private static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, uint nSize, [Out] int lpNumberOfBytesWritten);
  6.  
  7.  
  8. [DllImport("kernel32.dll", EntryPoint = "ReadProcessMemory")]
  9. private static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [Out] byte[] lpBuffer, int dwSize, [Out] int lpNumberOfBytesRead);
  10.  
  11. [DllImport("kernel32.dll", EntryPoint = "OpenProcess")]
  12. 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
  1. private void timer1_Tick(object sender, EventArgs e)
  2. {
  3. System.Diagnostics.Process[] myprocesses = System.Diagnostics.Process.GetProcessesByName("iw5sp");
  4. if (myprocesses.Length != 0)
  5. {
  6. label5.Text = "Mw3 Found!";
  7. label5.ForeColor = Color.Lime;
  8. timer2.Start();
  9. Process[] processes = Process.GetProcessesByName("iw5sp"); // in the "iw5sp" is the name of the process
  10. ProcessID = processes[0].Id;
  11. ProcessHandle = OpenProcess(0x001F0FFF/*PROCESS_ALL_ACCESS*/, false, ProcessID);
  12. }
  13. }


NOP function:

http://www.itsmods.com/forum/Thread-Tuto...-in-C.html

CSHARP Code
  1. private void timer2_Tick(object sender, EventArgs e)
  2. {
  3. bool OPT1 = Convert.ToBoolean(GetAsyncKeyState(Keys.F1));
  4. if (OPT1 == true)
  5. {
  6. if (opt1 == 0)
  7. {
  8. opt1 = 1;
  9. label1.ForeColor = Color.Lime;
  10. }
  11. else
  12. {
  13. opt1 = 0;
  14. label1.ForeColor = Color.Red;
  15. }
  16. }
  17. bool OPT2 = Convert.ToBoolean(GetAsyncKeyState(Keys.F2));
  18. if (OPT2 == true)
  19. {
  20. if (opt2 == 0)
  21. {
  22. opt2 = 1;
  23. label2.ForeColor = Color.Lime;
  24. }
  25. else
  26. {
  27. opt2 = 0;
  28. label2.ForeColor = Color.Red;
  29. }
  30. }
  31. bool OPT3 = Convert.ToBoolean(GetAsyncKeyState(Keys.F3));
  32. if (OPT3 == true)
  33. {
  34. if (opt3 == 0)
  35. {
  36. opt3 = 1;
  37. label3.ForeColor = Color.Lime;
  38. }
  39. else
  40. {
  41. opt3 = 0;
  42. label3.ForeColor = Color.Red;
  43. }
  44. }
  45. bool OPT4 = Convert.ToBoolean(GetAsyncKeyState(Keys.F4));
  46. if (OPT4 == true)
  47. {
  48. int activated = 0;
  49. if (activated == 0)
  50. {
  51. byte[] nop = { 0x90, 0x90, 0x90, 0x90, 0x90 };// 5 bytes
  52. WriteProcessMemory(ProcessHandle, (IntPtr)0x004DBB96, nop, 5/*amount of bytes written(5)*/, 0);
  53. label4.ForeColor = Color.Lime;
  54. activated = 1;
  55. }
  56. else
  57. {
  58. byte[] nop = { 0xE8, 0xC5, 0x72, 0x03, 0x00 };// 5 bytes
  59. WriteProcessMemory(ProcessHandle, (IntPtr)0x004DBB96, nop, 5/*amount of bytes written(5)*/, 0);
  60. label4.ForeColor = Color.Red;
  61. activated = 0;
  62. }
  63. }
  64. if (opt1 == 1)
  65. {
  66. int val = 999;
  67. WriteProcessMemory(ProcessHandle, (IntPtr)0x012A7AA0, BitConverter.GetBytes(val), 4, 0);
  68. WriteProcessMemory(ProcessHandle, (IntPtr)0x012A7B18, BitConverter.GetBytes(val), 4, 0);
  69. WriteProcessMemory(ProcessHandle, (IntPtr)0x012A7AA8, BitConverter.GetBytes(val), 4, 0);
  70. WriteProcessMemory(ProcessHandle, (IntPtr)0x012A7B24, BitConverter.GetBytes(val), 4, 0);
  71. WriteProcessMemory(ProcessHandle, (IntPtr)0x012A7B30, BitConverter.GetBytes(val), 4, 0);
  72. WriteProcessMemory(ProcessHandle, (IntPtr)0x012A7B48, BitConverter.GetBytes(val), 4, 0);
  73. WriteProcessMemory(ProcessHandle, (IntPtr)0x012A7B54, BitConverter.GetBytes(val), 4, 0);
  74. WriteProcessMemory(ProcessHandle, (IntPtr)0x012A7B3C, BitConverter.GetBytes(val), 4, 0);
  75. }
  76. if (opt2 == 1)
  77. {
  78. int val = 999;
  79. WriteProcessMemory(ProcessHandle, (IntPtr)0x010BD628, BitConverter.GetBytes(val), 4, 0);
  80. }
  81. if (opt3 == 1)
  82. {
  83. int val = 0;
  84. WriteProcessMemory(ProcessHandle, (IntPtr)0x12A7948, BitConverter.GetBytes(val), 4, 0);
  85. WriteProcessMemory(ProcessHandle, (IntPtr)0x8ABA88, BitConverter.GetBytes(val), 4, 0);
  86. }
  87. }


And the final code should be:

CSHARP Code
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Runtime.InteropServices;
  9. using System.Diagnostics;
  10. using System.Windows.Forms;
  11.  
  12. namespace Mw3_Trainer_tuto
  13. {
  14. public partial class Form1 : Form
  15. {
  16. public int opt1 = 0;
  17. public int opt2 = 0;
  18. public int opt3 = 0;
  19.  
  20. private static int ProcessID = -1;
  21. private static IntPtr ProcessHandle = IntPtr.Zero;
  22.  
  23. public Form1()
  24. {
  25. InitializeComponent();
  26. }
  27.  
  28. [DllImport("user32.dll")]
  29. public static extern short GetAsyncKeyState(Keys vKey);
  30.  
  31. [DllImport("kernel32.dll", EntryPoint = "WriteProcessMemory")]
  32. private static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, uint nSize, [Out] int lpNumberOfBytesWritten);
  33.  
  34.  
  35. [DllImport("kernel32.dll", EntryPoint = "ReadProcessMemory")]
  36. private static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [Out] byte[] lpBuffer, int dwSize, [Out] int lpNumberOfBytesRead);
  37.  
  38. [DllImport("kernel32.dll", EntryPoint = "OpenProcess")]
  39. private static extern IntPtr OpenProcess(uint dwDesiredAccess, bool bInheritHandle, int dwProcessId);
  40.  
  41. private void Form1_Load(object sender, EventArgs e)
  42. {
  43. timer1.Start();
  44. }
  45.  
  46. private void timer1_Tick(object sender, EventArgs e)
  47. {
  48. System.Diagnostics.Process[] myprocesses = System.Diagnostics.Process.GetProcessesByName("iw5sp");
  49. if (myprocesses.Length != 0)
  50. {
  51. label5.Text = "Mw3 Found!";
  52. label5.ForeColor = Color.Lime;
  53. timer2.Start();
  54. Process[] processes = Process.GetProcessesByName("iw5sp"); // in the "iw5sp" is the name of the process
  55. ProcessID = processes[0].Id;
  56. ProcessHandle = OpenProcess(0x001F0FFF/*PROCESS_ALL_ACCESS*/, false, ProcessID);
  57. }
  58. }
  59.  
  60. private void timer2_Tick(object sender, EventArgs e)
  61. {
  62. bool OPT1 = Convert.ToBoolean(GetAsyncKeyState(Keys.F1));
  63. if (OPT1 == true)
  64. {
  65. if (opt1 == 0)
  66. {
  67. opt1 = 1;
  68. label1.ForeColor = Color.Lime;
  69. }
  70. else
  71. {
  72. opt1 = 0;
  73. label1.ForeColor = Color.Red;
  74. }
  75. }
  76. bool OPT2 = Convert.ToBoolean(GetAsyncKeyState(Keys.F2));
  77. if (OPT2 == true)
  78. {
  79. if (opt2 == 0)
  80. {
  81. opt2 = 1;
  82. label2.ForeColor = Color.Lime;
  83. }
  84. else
  85. {
  86. opt2 = 0;
  87. label2.ForeColor = Color.Red;
  88. }
  89. }
  90. bool OPT3 = Convert.ToBoolean(GetAsyncKeyState(Keys.F3));
  91. if (OPT3 == true)
  92. {
  93. if (opt3 == 0)
  94. {
  95. opt3 = 1;
  96. label3.ForeColor = Color.Lime;
  97. }
  98. else
  99. {
  100. opt3 = 0;
  101. label3.ForeColor = Color.Red;
  102. }
  103. }
  104. bool OPT4 = Convert.ToBoolean(GetAsyncKeyState(Keys.F4));
  105. if (OPT4 == true)
  106. {
  107. int activated = 0;
  108. if (activated == 0)
  109. {
  110. byte[] nop = { 0x90, 0x90, 0x90, 0x90, 0x90 };// 5 bytes
  111. WriteProcessMemory(ProcessHandle, (IntPtr)0x004DBB96, nop, 5/*amount of bytes written(5)*/, 0);
  112. label4.ForeColor = Color.Lime;
  113. activated = 1;
  114. }
  115. else
  116. {
  117. byte[] nop = { 0xE8, 0xC5, 0x72, 0x03, 0x00 };// 5 bytes
  118. WriteProcessMemory(ProcessHandle, (IntPtr)0x004DBB96, nop, 5/*amount of bytes written(5)*/, 0);
  119. label4.ForeColor = Color.Red;
  120. activated = 0;
  121. }
  122. }
  123. if (opt1 == 1)
  124. {
  125. int val = 999;
  126. WriteProcessMemory(ProcessHandle, (IntPtr)0x012A7AA0, BitConverter.GetBytes(val), 4, 0);
  127. WriteProcessMemory(ProcessHandle, (IntPtr)0x012A7B18, BitConverter.GetBytes(val), 4, 0);
  128. WriteProcessMemory(ProcessHandle, (IntPtr)0x012A7AA8, BitConverter.GetBytes(val), 4, 0);
  129. WriteProcessMemory(ProcessHandle, (IntPtr)0x012A7B24, BitConverter.GetBytes(val), 4, 0);
  130. WriteProcessMemory(ProcessHandle, (IntPtr)0x012A7B30, BitConverter.GetBytes(val), 4, 0);
  131. WriteProcessMemory(ProcessHandle, (IntPtr)0x012A7B48, BitConverter.GetBytes(val), 4, 0);
  132. WriteProcessMemory(ProcessHandle, (IntPtr)0x012A7B54, BitConverter.GetBytes(val), 4, 0);
  133. WriteProcessMemory(ProcessHandle, (IntPtr)0x012A7B3C, BitConverter.GetBytes(val), 4, 0);
  134. }
  135. if (opt2 == 1)
  136. {
  137. int val = 999;
  138. WriteProcessMemory(ProcessHandle, (IntPtr)0x010BD628, BitConverter.GetBytes(val), 4, 0);
  139. }
  140. if (opt3 == 1)
  141. {
  142. int val = 0;
  143. WriteProcessMemory(ProcessHandle, (IntPtr)0x12A7948, BitConverter.GetBytes(val), 4, 0);
  144. WriteProcessMemory(ProcessHandle, (IntPtr)0x8ABA88, BitConverter.GetBytes(val), 4, 0);
  145. }
  146. }
  147. }
  148. }


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.


Attached Files
.rar   Mw3 Trainer tuto.rar (Size: 4.91 KB / Downloads: 108)
Don't worry if things aren't the way you planned, in the end everything will solve itself...
  Reply
#2
thank you Awesome
  Reply
#3
Great Job, this is an excellent tutorial for beginners Big Grin +Rep!
  Reply
#4
This is completely epic, thanks for taking the time, i'm pretty sure i'll be using this
  Reply
#5
tldr; but great work man :0 will +rep 4sure

but c# Dodgy

next time c++ Like a sir
  Reply
#6
I'm happy that this is in C# because all injecting stuff is in C++
  Reply
#7
(02-22-2012, 09:42)rotceh_dnih Wrote: tldr; but great work man :0 will +rep 4sure

but c# Dodgy

next time c++ Like a sir

Next time i will make a C++ form trainer tuto, is almost the same as this but no problem!

Thanks Barata...
Don't worry if things aren't the way you planned, in the end everything will solve itself...
  Reply
#8
nice...but....
WHY THE HELL ALWAYS C#

i want C++!!!
[Image: ctoc.jpg]
  Reply
#9
(02-22-2012, 16:38)Tomsen1410 Wrote: nice...but....
WHY THE HELL ALWAYS C#

i want C++!!!

Coz this can be found in C++ all over the web Troll

http://lmgtfy.com/?q=c%2B%2B+injector+source
(08-10-2011, 12:58)Pozzuh Wrote:
Se7en Wrote:Stealed, from cod4 mod ...
look who's talking

[Release] Old School Mod v2.2
[Release] Scroll menu

  Reply
#10
but not on itsmods Troll

and i have my own injector already U JELLY?

(hahahaah)
[Image: ctoc.jpg]
  Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Release] Black Ops Single Player/Zombie Trainer V3.6 Craig87 52 79,399 07-01-2013, 15:12
Last Post: explosivebanana55
  [Release] LF's BO2 Trainer (Latest Version) LegitFlash 3 4,528 06-11-2013, 18:14
Last Post: surtek
  Black Ops 2 DLC camo trainer surtek 10 9,851 04-19-2013, 23:16
Last Post: Gladio
  Menu base EliTeEishiii 1 2,688 04-17-2013, 16:10
Last Post: Nekochan
  Black Ops 2 camo trainer surtek 33 26,521 04-16-2013, 11:07
Last Post: surtek
  Saint Row: The Third - +7 Trainer - Steam v1.0.0.1 - DX10/11 d0h! 5 29,661 03-02-2013, 15:31
Last Post: BunnySkills
  [Release] [DETECTED] Black ops 2 Zombie Trainer dylankrajewski 8 14,539 02-09-2013, 10:07
Last Post: Erik The Born
  Preview BarataConsole Trainer/Mod/Plugin API JariZ 1 2,834 02-05-2013, 23:59
Last Post: barata
  [Release] MW3 +12 Singleplayer Trainer 1.9.453 by Geomatrical Silencemod 15 10,421 01-18-2013, 21:54
Last Post: JariZ
  Black Ops 2 emblem trainer surtek 3 5,421 12-17-2012, 17:23
Last Post: surtek

Forum Jump:


Users browsing this thread: 1 Guest(s)