C# making a game trainer from scratch

Discussion in 'General Tutorials' started by Erfg1, Sep 8, 2017.

  1. Erfg1
    OP

    Erfg1 Advanced Member

    Newcomer
    51
    28
    Jan 3, 2016
    United States
    Here's a little video I made (about 50 minutes)

    Using Cheat Engine to find addresses. Then with Visual Studio Community Edition 2017 with Memory.dll do things like AoB scans, write/read addresses with pointers, addresses and offsets.

     
  2. DarkIrata

    DarkIrata GBAtemp Fan

    Member
    435
    226
    Jun 12, 2015
    Gambia, The
    Jumped through the video. Missing a little details on the used functions but overall actually good to understand.
     
  3. jimmyj

    jimmyj Official founder of altariaism. Copyright jimmyj

    Member
    850
    224
    May 26, 2017
    Italy
    Hyrule
    Where can I learn to code?
     
  4. RedBlueGreen

    RedBlueGreen GBAtemp Maniac

    Member
    1,150
    364
    Aug 10, 2015
    Canada
    School (college, and sometimes high school), you can get books on learning programming, maybe find some online resources.
     
  5. Ericthegreat

    Ericthegreat Not New Member

    Member
    1,816
    324
    Nov 8, 2008
    United States
    Vana'diel
    Try freeCodeCamp, but this is more web dev, there's a lot of unity tutorials for. game dev. Then once you know a language you can learn anything else, but for real hacking, is mostly C and assembly. Tho those are harder to learn, I think so anyway.
     
  6. ov3rkill

    ov3rkill GBAtemp Maniac

    Member
    1,107
    429
    May 10, 2009
    Australia
    in a cardboard box
  7. Erfg1
    OP

    Erfg1 Advanced Member

    Newcomer
    51
    28
    Jan 3, 2016
    United States
    Once you understand the basics you can use almost any programming language. You would also have to learn the structure too.

    Things like conditional statements, booleans, integers, floats, etc.
     
  8. Plomo

    Plomo GBAtemp Regular

    Member
    128
    29
    Feb 8, 2017
    United Kingdom
    Down the street
    From what I understand, Codecademy wants you to put exactly what it sais on the site,
    Example(Not from the actual site):
    Would tell me to put a font size in a .css file, when I could just use <style> in html5.
     
  9. ov3rkill

    ov3rkill GBAtemp Maniac

    Member
    1,107
    429
    May 10, 2009
    Australia
    in a cardboard box
    That's why it's good for beginners. It would confuse the hell out of them if you provide them with a lot of info at first.
     
    BooDaRippa likes this.
  10. bannana2

    bannana2 GBAtemp Regular

    Member
    243
    154
    Nov 11, 2008
    United States
    Spring Hill, KS
    College, Bookstore, Internet. Actually, the information is readily available; just look around.
     
  11. Psionic Roshambo

    Psionic Roshambo GBAtemp Advanced Maniac

    Member
    1,867
    711
    Aug 12, 2011
    United States
    I need an FPS shooter that trains me how to code, then my short attention span could be overcome lol

    Seriously why has no one made some sort of game game about C++ or C# or just C. Hell even if it is just a trivia game to help noobs learn (like myself)

    Or maybe it has been made and I just haven't come across it.

    Edit: Maybe this would be a fun place to start off for people. https://codecombat.com/

    Edit 2: Maybe this would be a bit better, it claims to support C and C++ and C# so you can pick your weapon of choice. https://www.codewars.com/
     
    Last edited by Psionic Roshambo, Sep 19, 2017
  12. Rottweiler

    Rottweiler Member

    Newcomer
    13
    1
    Sep 25, 2017
    United States
    Recently had to write my own trainer implementation for a game, it supports multiple offsets and getting module base address

    var trainer = new Trainer(Process.GetProcessesByName("hl2").FirstOrDefault());
    if(trainer.IsValid()) {
    var address = (uint) trainer.ReadInt(trainer.GetModuleAddress("server.dll") + 0xFFFFFF);
    var result = trainer.WriteInt(address, VALUE, .. offset);
    }

    PHP:
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Linq;
    using System.Runtime.InteropServices;
    using System.Text;
    using System.Text.RegularExpressions;
    using System.Threading.Tasks;

    namespace 
    Growl.Core.Memory
    {
        public class 
    Trainer
        
    {
            public 
    Process Process get; }
            public 
    bool IsValid get { return Process != null && Process.Handle != null && !Process.HasExited; } }

            public 
    Trainer(Process process)
            {
                
    Process process;
            }

            private 
    uint RecalculateAddress(uint addressparams uint[] offset)
            {
                for (
    int i 0offset.Lengthi++)
                {
                    if (
    == offset.Length)
                    {
                        return 
    address offset[i];
                    }
                    else
                    {
                        
    address = (uint)ReadInt(address offset[i]);
                    }
                }

                return 
    address;
            }

            public 
    int ReadInt(uint address)
            {
                var 
    read 0u;
                var 
    value = -1;
                
    ReadInt(Process.Handleaddressout valuesizeof(int), out read);
                return 
    value;
            }

            public 
    int ReadInt(uint addressparams uint[] offset)
            {
                return 
    ReadInt(RecalculateAddress(addressoffset));
            }

            public 
    bool WriteInt(uint addressint value)
            {
                var 
    write 0u;
                
    WriteInt(Process.Handleaddressref valuesizeof(int), out write);
                return 
    write 0;
            }

            public 
    bool WriteInt(uint addressint valueparams uint[] offset)
            {
                return 
    WriteInt(RecalculateAddress(addressoffset), value);
            }

            public 
    float ReadFloat(uint address)
            {
                var 
    read 0u;
                var 
    value = -1f;
                
    ReadFloat(Process.Handleaddressout valuesizeof(float), out read);
                return 
    value;
            }

            public 
    float ReadFloat(uint addressparams uint[] offset)
            {
                return 
    ReadFloat(RecalculateAddress(addressoffset));
            }

            public 
    bool WriteFloat(uint addressfloat value)
            {
                var 
    write 0u;
                
    WriteFloat(Process.Handleaddressref valuesizeof(float), out write);
                return 
    write 0;
            }

            public 
    bool WriteFloat(uint addressfloat valueparams uint[] offset)
            {
                return 
    WriteFloat(RecalculateAddress(addressoffset), value);
            }

            public 
    byte ReadByte(uint address)
            {
                var 
    read 0u;
                var 
    value = default(byte);
                
    ReadByte(Process.Handleaddressout valuesizeof(byte), out read);
                return 
    value;
            }

            public 
    byte ReadByte(uint addressparams uint[] offset)
            {
                return 
    ReadByte(RecalculateAddress(addressoffset));
            }

            public 
    bool WriteByte(uint addressbyte value)
            {
                var 
    write 0u;
                
    WriteByte(Process.Handleaddressref valuesizeof(byte), out write);
                return 
    write 0;
            }

            public 
    bool WriteByte(uint addressbyte valueparams uint[] offset)
            {
                return 
    WriteByte(RecalculateAddress(addressoffset), value);
            }

            public 
    uint GetModuleAddress(string name)
            {
                foreach (
    ProcessModule module in Process.Modules)
                {
                    if (
    module.ModuleName.ToLower() == name.ToLower() || Regex.Match(module.ModuleName.ToLower(), name.ToLower()).Success)
                    {
                        return (
    uint)module.BaseAddress.ToInt32();
                    }
                }

                return default(
    UInt32);
            }

            [
    DllImport("kernelbase"EntryPoint "ReadProcessMemory")]
            private static 
    extern IntPtr ReadInt(IntPtr handleuint addressout int valueuint lengthout uint read);

            [
    DllImport("kernelbase"EntryPoint "WriteProcessMemory")]
            private static 
    extern IntPtr WriteInt(IntPtr handleuint addressref int valueuint lengthout uint write);

            [
    DllImport("kernelbase"EntryPoint "ReadProcessMemory")]
            private static 
    extern IntPtr ReadFloat(IntPtr handleuint addressout float valueuint lengthout uint read);

            [
    DllImport("kernelbase"EntryPoint "WriteProcessMemory")]
            private static 
    extern IntPtr WriteFloat(IntPtr handleuint addressref float valueuint lengthout uint write);

            [
    DllImport("kernelbase"EntryPoint "ReadProcessMemory")]
            private static 
    extern IntPtr ReadByte(IntPtr handleuint addressout byte valueuint lengthout uint read);

            [
    DllImport("kernelbase"EntryPoint "WriteProcessMemory")]
            private static 
    extern IntPtr WriteByte(IntPtr handleuint addressref byte valueuint lengthout uint write);

        }
    }

     
    Last edited by Rottweiler, Sep 25, 2017
  13. Rottweiler

    Rottweiler Member

    Newcomer
    13
    1
    Sep 25, 2017
    United States
    Unity engine uses C# and there are tons of tutorials out there for that. Games in pure C# with GDI tend to perform so bad that nobody wants to use it