C#

Posts 1–11 of 11 · Page 1 of 1
C#
I think a lot of people dont like C# because they dont know the benifits, i can well understand C++ knowers dont really like C# and i dont care but a lot of people who are trying to learn programming should understand, and let me get this message clear: C++ IS MUCH HARDER TO LEARN THAN C#!! If you are a person who is trying to learn programming but doesnt understand what the stuff with compilers means and all the C++ stuff in general then C# is perfect for you. You can compile any script from other people without needing to change anything, the .NET environment is so much more helpful (most people still use the C++ 6.0 because the new versions dont work, and im one of them), the code is so much simpler to understand and more self explanationary. Create great window and console applications in seconds, a neat drag-and-drop designer and double click on any window control to jump to the code associating the control, click on any event of a control to auto create a structure for it so you can instantly start programming. C# is much cleaner and easier in any way, it is perfect for beginners. Anyone who knows the difference between VB and C++ will know what i mean. And if you think C# is not a language for hacking then you are wrong. C# is simpler, true and therefor some functions arent included in .Net such as memory reading and writing but that wont stop you in any way from using them. You can simply import the .DLL file which you need and use the function, meaning C# has exactly the same possibilities as C++ without you requiring to make any changes (here is a good example of a memory reader-writer script http://www.codeproject.com/csharp/freecellreader.asp, insert this script into your project and read-write memory just like in C++). So for anyone who wants to give C# a try, its completly free with all its functionalities, and you dont need to buy Visual Studio. http://msdn.microsoft.com/vstudio/ex...p/default.aspx

Please post any arguments you have against C#.

A stamina tutorial - the C# version of l0ngcats C++ tutorial:

Code:
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using ProcessMemoryReaderLib;

namespace CSWarrockTrainer
{
    class Trainer
    {
        /* --------- TUTORIAL: Making your first Trainer -------- */
        /* --------- by Fluffy - posted on mpgh.net   -------- */
        
        static void Main(string[] args)
        {
            int store = 0; // an int to store stuff we dont need

            byte[] stamina = new byte[4];	// will store the stamina value

            bool dostamina = false;		// determines if user activated stamina freezing
            
            IntPtr stamina_addr = (IntPtr)0x007F1110;		// memory address of the stamina value in the WarRock process

            ProcessMemoryReader pReader = new ProcessMemoryReader(); // a new memory reader - writer

            Process[] hProcessSnap;	    // will store a snapshot of all processes
            Process hProcess = null;	// we will use this one for the WarRock process

            hProcessSnap = Process.GetProcesses();	// make process snapshot

            for (int i = 0; i < hProcessSnap.Length; i++)	// loop to find the WarRock process
            {
                if (hProcessSnap[i].ProcessName == "WarRock")	// if WarRock was found, the extension is only added if the process is not a .exe
                {
                    hProcess = hProcessSnap[i];	// open it, assigning to the hProcess handle
                }
            }

            hProcessSnap = null;	// close the handle (just fuckin do it)

            if (hProcess == null)	// self explanatory tbh
            {
                Console.Write("WarRock not found\n\n");
                Console.ReadKey();	// wait for a key press. otherwise the app will just close so fast when the process is not found, you wont know wtf happened.
            }
            else
            {
                screen(dostamina);	// print the display

                while (true)	// loop until user presses Escape
                {
                    if (Console.KeyAvailable)		// if a key was pressed
                    {
                        ConsoleKey key = Console.ReadKey().Key;	// it is saved into "key"

                        if (key == ConsoleKey.Escape)
                        {
                            break;
                        }

                        switch (key)		// here the commands are handled depending on the key that was pressed
                        {				// case '1': ... break;  case '2': ... break; and so on
                            case ConsoleKey.D1:
                                dostamina = !dostamina;		// flip the dostamina value true<->false to enable/disable it
                                pReader.ReadProcess = hProcess; // read from warrock process
                                pReader.OpenProcess();
                                stamina = pReader.ReadProcessMemory(stamina_addr, 4, out store); // read the stamina value from the memory into the "stamina" variable
                                break;

                        screen(dostamina);	// print the display after each key press

                    }

                    if (dostamina)	// if stamina freeze is activated
                    {
                        pReader.ReadProcess = hProcess; // read from warrock process
                        pReader.OpenProcess();
                        pReader.WriteProcessMemory(stamina_addr, stamina, out store);	// write the stamina value that was saved before with the key press into memory
                    }
                }

                hProcess.Close();	// close the handle
            }
            // The End, no return value - this is a void function
        }

        static void screen(bool dostamina)	// output
        {
            Console.Clear();	// clear the screen
            Console.Write("Hello World! This is my first WarRock trainer!  \n\n");

            if (dostamina) Console.Write("[1] - freeze stamina [ENABLED]\n");	// if user enabled stamina freeze, let him know!
            else Console.Write("[1] - freeze stamina [disabled]\n");			// same if it's disabled
        }
    }
}
This might seem strange at first but when you look closer at it, its much easier understandable code (try testing it against l0ngcats tutorial).
PS: I didnt test it with WarRock yet but it should work. Also be sure to include the proccesMemoryReaderLib for the memory reading writing or else this code wont compile (found here: http://www.codeproject.com/csharp/freecellreader.asp ).
Here is the process memory reader script.

Code:
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace ProcessMemoryReaderLib
{
	/// <summary>
	/// ProcessMemoryReader is a class that enables direct reading a process memory
	/// </summary>
	class ProcessMemoryReaderApi
	{
		// constants information can be found in <winnt.h>
		[Flags]
		public enum ProcessAccessType
		{
			PROCESS_TERMINATE			= (0x0001),
			PROCESS_CREATE_THREAD		= (0x0002), 
			PROCESS_SET_SESSIONID		= (0x0004), 
			PROCESS_VM_OPERATION		= (0x0008), 
			PROCESS_VM_READ				= (0x0010), 
			PROCESS_VM_WRITE			= (0x0020), 
			PROCESS_DUP_HANDLE			= (0x0040), 
			PROCESS_CREATE_PROCESS		= (0x0080), 
			PROCESS_SET_QUOTA			= (0x0100), 
			PROCESS_SET_INFORMATION		= (0x0200), 
			PROCESS_QUERY_INFORMATION	= (0x0400) 
		}
		
		// function declarations are found in the MSDN and in <winbase.h> 
		
		//		HANDLE OpenProcess(
		//			DWORD dwDesiredAccess,  // access flag
		//			BOOL bInheritHandle,    // handle inheritance option
		//			DWORD dwProcessId       // process identifier
		//			);
		[DllImport("kernel32.dll")]
		public static extern IntPtr OpenProcess(UInt32 dwDesiredAccess, Int32 bInheritHandle, UInt32 dwProcessId);

		//		BOOL CloseHandle(
		//			HANDLE hObject   // handle to object
		//			);
		[DllImport("kernel32.dll")]
		public static extern Int32 CloseHandle(IntPtr hObject);

		//		BOOL ReadProcessMemory(
		//			HANDLE hProcess,              // handle to the process
		//			LPCVOID lpBaseAddress,        // base of memory area
		//			LPVOID lpBuffer,              // data buffer
		//			SIZE_T nSize,                 // number of bytes to read
		//			SIZE_T * lpNumberOfBytesRead  // number of bytes read
		//			);
		[DllImport("kernel32.dll")]
		public static extern Int32 ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,[In, Out] byte[] buffer, UInt32 size, out IntPtr lpNumberOfBytesRead);
	
		//		BOOL WriteProcessMemory(
		//			HANDLE hProcess,                // handle to process
		//			LPVOID lpBaseAddress,           // base of memory area
		//			LPCVOID lpBuffer,               // data buffer
		//			SIZE_T nSize,                   // count of bytes to write
		//			SIZE_T * lpNumberOfBytesWritten // count of bytes written
		//			);
		[DllImport("kernel32.dll")]
		public static extern Int32 WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,[In, Out] byte[] buffer, UInt32 size, out IntPtr lpNumberOfBytesWritten);
	
		
	}

	public class ProcessMemoryReader
	{

		public ProcessMemoryReader()
		{
		}

        /// <summary>	
		/// Process from which to read		
		/// </summary>
		public Process ReadProcess
		{
			get
			{
				return m_ReadProcess;
			}
			set
			{
				m_ReadProcess = value;
			}
		}

		private Process m_ReadProcess = null;

		private IntPtr m_hProcess = IntPtr.Zero;

		public void OpenProcess()
		{
//			m_hProcess = ProcessMemoryReaderApi.OpenProcess(ProcessMemoryReaderApi.PROCESS_VM_READ, 1, (uint)m_ReadProcess.Id);
			ProcessMemoryReaderApi.ProcessAccessType access;
			access = ProcessMemoryReaderApi.ProcessAccessType.PROCESS_VM_READ 
				| ProcessMemoryReaderApi.ProcessAccessType.PROCESS_VM_WRITE 
				| ProcessMemoryReaderApi.ProcessAccessType.PROCESS_VM_OPERATION;
				m_hProcess = ProcessMemoryReaderApi.OpenProcess((uint)access, 1, (uint)m_ReadProcess.Id);
		}

		public void CloseHandle()
		{
			int iRetValue;
			iRetValue = ProcessMemoryReaderApi.CloseHandle(m_hProcess);
			if (iRetValue == 0)
				throw new Exception("CloseHandle failed");
		}

		public byte[] ReadProcessMemory(IntPtr MemoryAddress, uint bytesToRead, out int bytesRead)
		{
			byte[] buffer = new byte[bytesToRead];
			
			IntPtr ptrBytesRead;
			ProcessMemoryReaderApi.ReadProcessMemory(m_hProcess,MemoryAddress,buffer ,bytesToRead,out ptrBytesRead);
			
			bytesRead = ptrBytesRead.ToInt32();

			return buffer;
		}

		public void WriteProcessMemory(IntPtr MemoryAddress, byte[] bytesToWrite ,out int bytesWritten)
		{
			IntPtr ptrBytesWritten;
			ProcessMemoryReaderApi.WriteProcessMemory(m_hProcess,MemoryAddress,bytesToWrite,(uint)bytesToWrite.Length,out ptrBytesWritten);
			
			bytesWritten = ptrBytesWritten.ToInt32();
		}

		


	}
}
Go drown yourself Nah, just kidding. But just to bring to your attention C# (the general .NET C#) came out in 2001 so it is one of the newest languages. Whereas C++ came out in 1985 and the 6.0 version is kinda outdated. (the new 2003 and 2005 version are the biggest pieces of crap imaginable, i know)
Argg..I have been trying to get C# on my computer for weeks. Well I finally did, It says I need SP1. So I google "Vista SP1 Download" and I get 300 links to the new update. Can someone show me some links to the SP1 site?
thanks. ive been searching for the code for hours already.
do you have code to make a loader ?
Depends what kind of loader.... progress bar for download? Or 3D render progress??
something like load an exe and then do some patching on the exe.
sorry to bump an old thread...

BUT...

here's what I have:

Code:
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using ProcessMemoryReaderLib;
using System.Runtime.InteropServices;

namespace CSWarrockTrainer
{
    class Trainer
    {
        /* --------- TUTORIAL: Making your first Trainer -------- */
        /* --------- by Fluffy - posted on mpgh.net  -------- */

        static void Main(string[] args)
        {
            int store = 0; // an int to store stuff we dont need

            byte[] stamina = new byte[4];        // will store the stamina value

            bool dostamina = false;                // determines if user activated stamina freezing

            IntPtr stamina_addr = (IntPtr)0x007F2B34;                // memory address of the stamina value in the WarRock process

            ProcessMemoryReader pReader = new ProcessMemoryReader(); // a new memory reader - writer

            Process[] hProcessSnap;            // will store a snapshot of all processes
            Process hProcess = null;        // we will use this one for the WarRock process

            hProcessSnap = Process.GetProcesses();        // make process snapshot

            for (int i = 0; i < hProcessSnap.Length; i++)        // loop to find the WarRock process
            {
                if (hProcessSnap[i].ProcessName == "WarRock")        // if WarRock was found, the extension is only added if the process is not a .exe
                {
                    hProcess = hProcessSnap[i];        // open it, assigning to the hProcess handle
                }
            }

            hProcessSnap = null;        // close the handle (just fuckin do it)

            if (hProcess == null)        // self explanatory tbh
            {
                Console.Write("WarRock not found\n\n");
                Console.ReadKey();        // wait for a key press. otherwise the app will just close so fast when the process is not found, you wont know wtf happened.
            }
            else
            {
                screen(dostamina);        // print the display

                while (true)        // loop until user presses Escape
                {
                    if (Console.KeyAvailable)                // if a key was pressed
                    {
                        ConsoleKey key = Console.ReadKey().Key;        // it is saved into "key"

                        if (key == ConsoleKey.Escape)
                        {
                            break;
                        }

                        switch (key)                // here the commands are handled depending on the key that was pressed
                        {                                // case '1': ... break;  case '2': ... break; and so on
                            case ConsoleKey.D1:
                                dostamina = !dostamina;                // flip the dostamina value true<->false to enable/disable it
                                pReader.ReadProcess = hProcess; // read from warrock process
                                pReader.OpenProcess();
                                stamina = pReader.ReadProcessMemory(stamina_addr, 4, out store); // read the stamina value from the memory into the "stamina" variable
                                break;

                                screen(dostamina);        // print the display after each key press

                        }

                        if (dostamina)        // if stamina freeze is activated
                        {
                            pReader.ReadProcess = hProcess; // read from warrock process
                            pReader.OpenProcess();
                            pReader.WriteProcessMemory(stamina_addr, stamina, out store);        // write the stamina value that was saved before with the key press into memory
                        }
                    }

                    hProcess.Close();        // close the handle
                }
                // The End, no return value - this is a void function
            }
        }

        static void screen(bool dostamina)        // output
        {
            Console.Clear();        // clear the screen
            Console.Write("Hello World! This is my first WarRock trainer!  \n\n");

            if (dostamina) Console.Write("[1] - freeze stamina [ENABLED]\n");        // if user enabled stamina freeze, let him know!
            else Console.Write("[1] - freeze stamina [disabled]\n");                        // same if it's disabled
        }
    }
}



namespace ProcessMemoryReaderLib
{
        /// <summary>
        /// ProcessMemoryReader is a class that enables direct reading a process memory
        /// </summary>
        class ProcessMemoryReaderApi
        {
                // constants information can be found in <winnt.h>
                [Flags]
                public enum ProcessAccessType
                {
                        PROCESS_TERMINATE                        = (0x0001),
                        PROCESS_CREATE_THREAD                = (0x0002),
                        PROCESS_SET_SESSIONID                = (0x0004),
                        PROCESS_VM_OPERATION                = (0x0008),
                        PROCESS_VM_READ                                = (0x0010),
                        PROCESS_VM_WRITE                        = (0x0020),
                        PROCESS_DUP_HANDLE                        = (0x0040),
                        PROCESS_CREATE_PROCESS                = (0x0080),
                        PROCESS_SET_QUOTA                        = (0x0100),
                        PROCESS_SET_INFORMATION                = (0x0200),
                        PROCESS_QUERY_INFORMATION        = (0x0400)
                }
               
                // function declarations are found in the MSDN and in <winbase.h>
               
                //                HANDLE OpenProcess(
                //                        DWORD dwDesiredAccess,  // access flag
                //                        BOOL bInheritHandle,    // handle inheritance option
                //                        DWORD dwProcessId      // process identifier
                //                        );
                [DllImport("kernel32.dll")]
                public static extern IntPtr OpenProcess(UInt32 dwDesiredAccess, Int32 bInheritHandle, UInt32 dwProcessId);

                //                BOOL CloseHandle(
                //                        HANDLE hObject  // handle to object
                //                        );
                [DllImport("kernel32.dll")]
                public static extern Int32 CloseHandle(IntPtr hObject);

                //                BOOL ReadProcessMemory(
                //                        HANDLE hProcess,              // handle to the process
                //                        LPCVOID lpBaseAddress,        // base of memory area
                //                        LPVOID lpBuffer,              // data buffer
                //                        SIZE_T nSize,                // number of bytes to read
                //                        SIZE_T * lpNumberOfBytesRead  // number of bytes read
                //                        );
                [DllImport("kernel32.dll")]
                public static extern Int32 ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,[In, Out] byte[] buffer, UInt32 size, out IntPtr lpNumberOfBytesRead);
       
                //                BOOL WriteProcessMemory(
                //                        HANDLE hProcess,                // handle to process
                //                        LPVOID lpBaseAddress,          // base of memory area
                //                        LPCVOID lpBuffer,              // data buffer
                //                        SIZE_T nSize,                  // count of bytes to write
                //                        SIZE_T * lpNumberOfBytesWritten // count of bytes written
                //                        );
                [DllImport("kernel32.dll")]
                public static extern Int32 WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,[In, Out] byte[] buffer, UInt32 size, out IntPtr lpNumberOfBytesWritten);
       
               
        }

        public class ProcessMemoryReader
        {

                public ProcessMemoryReader()
                {
                }

        /// <summary>       
                /// Process from which to read               
                /// </summary>
                public Process ReadProcess
                {
                        get
                        {
                                return m_ReadProcess;
                        }
                        set
                        {
                                m_ReadProcess = value;
                        }
                }

                private Process m_ReadProcess = null;

                private IntPtr m_hProcess = IntPtr.Zero;

                public void OpenProcess()
                {
//                        m_hProcess = ProcessMemoryReaderApi.OpenProcess(ProcessMemoryReaderApi.PROCESS_VM_READ, 1, (uint)m_ReadProcess.Id);
                        ProcessMemoryReaderApi.ProcessAccessType access;
                        access = ProcessMemoryReaderApi.ProcessAccessType.PROCESS_VM_READ
                                | ProcessMemoryReaderApi.ProcessAccessType.PROCESS_VM_WRITE
                                | ProcessMemoryReaderApi.ProcessAccessType.PROCESS_VM_OPERATION;
                                m_hProcess = ProcessMemoryReaderApi.OpenProcess((uint)access, 1, (uint)m_ReadProcess.Id);
                }

                public void CloseHandle()
                {
                        int iRetValue;
                        iRetValue = ProcessMemoryReaderApi.CloseHandle(m_hProcess);
                        if (iRetValue == 0)
                                throw new Exception("CloseHandle failed");
                }

                public byte[] ReadProcessMemory(IntPtr MemoryAddress, uint bytesToRead, out int bytesRead)
                {
                        byte[] buffer = new byte[bytesToRead];
                       
                        IntPtr ptrBytesRead;
                        ProcessMemoryReaderApi.ReadProcessMemory(m_hProcess,MemoryAddress,buffer ,bytesToRead,out ptrBytesRead);
                       
                        bytesRead = ptrBytesRead.ToInt32();

                        return buffer;
                }

                public void WriteProcessMemory(IntPtr MemoryAddress, byte[] bytesToWrite ,out int bytesWritten)
                {
                        IntPtr ptrBytesWritten;
                        ProcessMemoryReaderApi.WriteProcessMemory(m_hProcess,MemoryAddress,bytesToWrite,(uint)bytesToWrite.Length,out ptrBytesWritten);
                       
                        bytesWritten = ptrBytesWritten.ToInt32();
                }

               


        }
}
Is that correct? Visual C# 205 Express Edition, when running in debug mode, throws me this error:

"No process is associated with this object."

for this line (line 198):

Code:
m_hProcess = ProcessMemoryReaderApi.OpenProcess((uint)access, 1, (uint)m_ReadProcess.Id);
its from the openProcess function:

Code:
                public void OpenProcess()
                {
//                        m_hProcess = ProcessMemoryReaderApi.OpenProcess(ProcessMemoryReaderApi.PROCESS_VM_READ, 1, (uint)m_ReadProcess.Id);
                        ProcessMemoryReaderApi.ProcessAccessType access;
                        access = ProcessMemoryReaderApi.ProcessAccessType.PROCESS_VM_READ
                                | ProcessMemoryReaderApi.ProcessAccessType.PROCESS_VM_WRITE
                                | ProcessMemoryReaderApi.ProcessAccessType.PROCESS_VM_OPERATION;
                                m_hProcess = ProcessMemoryReaderApi.OpenProcess((uint)access, 1, (uint)m_ReadProcess.Id);
                }

Whats going on?
bagpiperdude90, I'm having exactly the same problem!
Posts 1–11 of 11 · Page 1 of 1
This thread is closed for replies.

Tags for this Thread

None

Need help?