carlAlex
10/6/2016 - 12:02 PM

Making a trainer in C#

Making a trainer in C#

1 Find an enemys coordinates
2 Find what writes to this address
3 Open memory viewer - "Find out what addresses this instruction accesses
4 Get list of nearby enemies :-)



Its almost a guarantee that all enemies base addresses are located next to each other somewhere in the code.

Just find the offset of map coords on one enemy and track that base address. I bet you find all enemies base addresses an offset apart. 

Then find the enemy count so you can reference how many offsets to use for your custom map.

***************

You can do an AoB injection if you want. If you're having a hard time finding a unique signature, then you can try scanning for an AoB above/below the instruction you're hooking and make sure you include that offset in the address where you write your jump to (and where you restore the original code to). Do whatever you want with the enemies' coordinates in your script. 

If you really need to find a pointer to it, though, then do several pointer scans for different enemies and cross reference them. Look for base addresses that are in all of them. If a base address is in one but not in another, throw it away. After that, just look at the offsets, and what to do from there should be self-explanatory. 

**************

Right click on your co ordinates find out what accesses this address and then check what addresses the instruction that pops up accesses. If its more than one then that instruction is shared. 

*******************

Cheat Engine Find coordinates XYZ tutorial HD
https://www.youtube.com/watch?v=AkKy3nta-94

1 - y axis easiest! Walk up and down something
2 - Often stored in a vector(float)
3 - Scan for unknown value
4 - Search for inc/dec
5 - Get the list down a bit.. < 200
6 - Change or freeze value to verify
7 - 
Start a new C# project, for the sake of example lets make it console, and add the library I gave you.

You should also add 'Threading' and 'Diagnostics' to your project.

Add constants.

Add a Process object, it will hold LF2.

Add a ProcessMemoryReader object, it will manage memory.

Add a loop waiting for LF2.

Once you find it, set Process to it.

Add the following code:
memoryeditor = new ProcessMemoryReader();
memoryeditor.ReadProcess = Game;
memoryeditor.OpenProcess();

Obviously, Game is the process that runs LF2.
 Because we want out trainer to be efficient, lets store the current, dynamic, addresses of HP & MP.
 So first, because we want to save code, let make a function called GetAddress with the parameter of Offset, because the Base address is static.
static IntPtr GetAddress(int Offset)
        {
            //This method returns the address which holds either HP\MP.
            //We get either 0x2FC, or 0x308, whcih is HP,MP respectively.
            byte[] memory;
            memory = memoryeditor.ReadProcessMemory(Base, 4);//Read where the fuck does 0x00458C94 points to.
            return (IntPtr)(BitConverter.ToInt32(memory, 0) + Offset);//Converts to int and adds offset.
        }
Then, we would put this code after we initialized memoryeditor
int GetHP(int ID)
        {
            //Uses CurrHPAddress to read from memory
            return BitConverter.ToInt32(memoryeditor.ReadProcessMemory(CurrHPAddress + ID * PlayerDiffrences, 4), 0);
        }
        void SetHP(int HP)
        {
            byte[] tmp = BitConverter.GetBytes(HP);
            foreach (int i in Players)
                memoryeditor.WriteProcessMemory(CurrHPAddress + i * PlayerDiffrences, tmp);
        }

        int GetMP(int ID)
        {
            return BitConverter.ToInt32(memoryeditor.ReadProcessMemory(CurrMPAddress + ID * PlayerDiffrences, 4), 0);
        }
        void SetMP(int MP)
        {
            foreach (int i in Players)
                memoryeditor.WriteProcessMemory(CurrMPAddress + i * PlayerDiffrences, BitConverter.GetBytes(MP));
        }
Now, we can add Get\Set HP\MP methods:
CurrHPAddress = GetAddress(HP_Offset);
CurrMPAddress = GetAddress(MP_Offset);
Now, we need to make a loop that applies HP & MP hacks for selected characters.
while (true)
            {
                foreach (int i in Players)
                    Console.WriteLine("Playerd #{0} HP: {1}; MP: {2}", i, GetHP(i), GetMP(1));
                SetHP(500);
                SetMP(500);
                Thread.Sleep(500);
            }

1.Base pointer is 0x027B4730
2.HP Offset is 0x2FC
3.MP Offset is 0x308
4.The difference between each character is 0x428