TR7Network.Com - GTA 4, Grand Theft Auto 4 (GTA:IV), SA-MP, MTA VC, San Andreas & Multiplayer Gaming Hacks & Cheats
March 11, 2010, 08:35:58 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: TroyRulz007.com has a new name
 
   Home   Help Search Login Register  

Pages: [1]
  Print  
Author Topic: Making a GTA Hack in C#  (Read 1652 times)
Magnus
Donator
Staff
Average
*

Rep: 12
Posts: 77


Howl and dream.


View Profile WWW
« on: December 13, 2009, 04:33:26 PM »

Just a simple money editor here. You can use the information here to extend your hack into something brilliant.

What you'll need

  • Microsoft Visual Studio. I'll be using 2008 edition in this tut, so don't expect the steps to be exactly the same in a different edition. I will not provide you with download links, so don't ask me for them.
  • GTA:SA Memory Addresses

Getting Started

Start your new project and give it a name. Make sure you choose Visual C# -> Windows Forms Application.



You'll then get your blank program. Open up your toolbox and drop a button onto it. Use the Properties box to call it whatever you want.







Double click on the button to open the code window.

To get the hack working, you must paste this code into the program:

Code:
// C# Signature for the FindWindow() API
        [DllImport("USER32.DLL")]
        public static extern IntPtr FindWindow(
            string lpClassName,
            string lpWindowName
        );

        // C# Signature for the WriteProcessMemory() API
        [DllImport("kernel32.dll")]
        static extern bool WriteProcessMemory(
            IntPtr hProcess,
            IntPtr lpBaseAddress,
            byte[] lpBuffer,
            UIntPtr nSize,
            out IntPtr lpNumberOfBytesWritten
        );

        // C# Signature for the OpenProcess() API
        [DllImport("kernel32.dll")]
        public static extern IntPtr OpenProcess(
            UInt32 dwDesiredAccess,
            Int32 bInheritHandle,
            UInt32 dwProcessId
        );

        // C# Signature for the GetWindowThreadProcessId() API
        [DllImport("user32.dll", SetLastError = true)]
        static extern uint GetWindowThreadProcessId(
            IntPtr hWnd,
            out uint lpdwProcessId
        );

        // C# Signature for the ReadProcessMemory() API
        [DllImport("kernel32.dll", SetLastError = true)]
        static unsafe extern bool ReadProcessMemory(
         IntPtr hProcess,
         IntPtr lpBaseAddress,
         void* lpBuffer,
         int dwSize,
         out IntPtr lpNumberOfBytesRead
        );

Place it all under the line that says "public partial class Form1 : Form {"

You can now make a function that edits the program memory using the above system functions. Here is one I made for your personal use:

Code:
public static bool EditMemory(int Address, uint Value)
        {
            UInt32 ProcID;
            IntPtr bytesout;
            IntPtr WindowHandle = FindWindow(null, "GTA: San Andreas");
            if (WindowHandle == null) { return false; }
            GetWindowThreadProcessId(WindowHandle, out ProcID);
            IntPtr ProcessHandle = OpenProcess(0x1F0FFF, 1, ProcID);
            WriteProcessMemory(ProcessHandle, (IntPtr)Address, BitConverter.GetBytes(Value), (UIntPtr)sizeof(uint), out bytesout);
            return true;
        }

You can use this function to edit your money. The address for money is 0xB7CE50, so you can edit your code to look like this:

Code:
private void btnMoney_Click(object sender, EventArgs e)
        {
            uint money = 99999999;
            EditMemory(0xB7CE50, money);
        }

If you're not very computer fluent, this sets your money to 99999999.

There's one more step you need to get your hack to work. In the menu bar, select "Project -> <YourHackName> Properties". On the Build tab, the "Allow Unsafe Code" check box must be checked.



I haven't tested this program, but it should work properly. Hope you've enjoyed this tutorial.
« Last Edit: January 09, 2010, 01:56:43 PM by Magnus » Logged



[Cr]TeDdY
Noob
*

Rep: 0
Posts: 6


View Profile
« Reply #1 on: December 17, 2009, 10:20:40 PM »

Nice tutorial.

How do i get it to make it a hotkey? so when i push like F1 it does it for me instead of tabbing out
Logged
wangdata
Skilled
*

Rep: -5
Posts: 110



View Profile WWW
« Reply #2 on: January 05, 2010, 07:44:04 PM »

Thanks for tut...
I had a go, i don't know that much about it.  Mine compiled fine it just doesn't seem to do anything in SAMP.  Even tried changing (null, "GTA: San Andreas") to (null, "GTA:SA:MP")

Things i changed...

The program told me it expected a ; after 'uint money = 99999999'

also had a problem with 'DllImport' (see below) so added 'using System.Runtime.InteropServices;' to the start of the code



Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace WACK2
{
    public partial class Form1 : Form
    {
        // C# Signature for the FindWindow() API
        [DllImport("USER32.DLL")]
        public static extern IntPtr FindWindow(
            string lpClassName,
            string lpWindowName
        );

        // C# Signature for the WriteProcessMemory() API
        [DllImport("kernel32.dll")]
        static extern bool WriteProcessMemory(
            IntPtr hProcess,
            IntPtr lpBaseAddress,
            byte[] lpBuffer,
            UIntPtr nSize,
            out IntPtr lpNumberOfBytesWritten
        );

        // C# Signature for the OpenProcess() API
        [DllImport("kernel32.dll")]
        public static extern IntPtr OpenProcess(
            UInt32 dwDesiredAccess,
            Int32 bInheritHandle,
            UInt32 dwProcessId
        );

        // C# Signature for the GetWindowThreadProcessId() API
        [DllImport("user32.dll", SetLastError = true)]
        static extern uint GetWindowThreadProcessId(
            IntPtr hWnd,
            out uint lpdwProcessId
        );

        // C# Signature for the ReadProcessMemory() API
        [DllImport("kernel32.dll", SetLastError = true)]
        static unsafe extern bool ReadProcessMemory(
         IntPtr hProcess,
         IntPtr lpBaseAddress,
         void* lpBuffer,
         int dwSize,
         out IntPtr lpNumberOfBytesRead
        );

        public static bool EditMemory(int Address, uint Value)
        {
            UInt32 ProcID;
            IntPtr bytesout;
            IntPtr WindowHandle = FindWindow(null, "GTA: San Andreas");
            if (WindowHandle == null) { return false; }
            GetWindowThreadProcessId(WindowHandle, out ProcID);
            IntPtr ProcessHandle = OpenProcess(0x1F0FFF, 1, ProcID);
            WriteProcessMemory(ProcessHandle, (IntPtr)Address, BitConverter.GetBytes(Value), (UIntPtr)sizeof(uint), out bytesout);
            return true;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            uint money = 99999999;
            EditMemory(0xB7CE50, money);
        }
        public Form1()
        {
            InitializeComponent();
        }
    }
}

Any help would be appreciated.

*edit* OK problem solved it works now, it wanted 'private void button1_Click_1(object sender, EventArgs e)' instead of 'private void button1_Click(object sender, EventArgs e)'  Thanks again for tutorial


« Last Edit: January 05, 2010, 08:52:23 PM by wangdata » Logged

Magnus
Donator
Staff
Average
*

Rep: 12
Posts: 77


Howl and dream.


View Profile WWW
« Reply #3 on: January 09, 2010, 01:59:06 PM »

The program told me it expected a ; after 'uint money = 99999999'

Thanks for pointing that out. God only knows how I got that to compile.
Logged



wangdata
Skilled
*

Rep: -5
Posts: 110



View Profile WWW
« Reply #4 on: January 09, 2010, 02:06:17 PM »

The program told me it expected a ; after 'uint money = 99999999'

Thanks for pointing that out. God only knows how I got that to compile.

No problem... Hey if its not to much trouble would you be able to post an example of code used for decimal numbers like gravity.  Its says i cant have a uint as a decimal.
Logged

Magnus
Donator
Staff
Average
*

Rep: 12
Posts: 77


Howl and dream.


View Profile WWW
« Reply #5 on: January 16, 2010, 05:51:17 PM »

No problem... Hey if its not to much trouble would you be able to post an example of code used for decimal numbers like gravity.  Its says i cant have a uint as a decimal.

Use a floating point value type for your variable. Double should work, I think.
Logged



wangdata
Skilled
*

Rep: -5
Posts: 110



View Profile WWW
« Reply #6 on: January 17, 2010, 02:00:59 PM »

No problem... Hey if its not to much trouble would you be able to post an example of code used for decimal numbers like gravity.  Its says i cant have a uint as a decimal.

Use a floating point value type for your variable. Double should work, I think.

Thank you
Logged

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC | Sitemap Valid XHTML 1.0! Valid CSS!


Google visited last this page Today at 10:06:41 AM