1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

[Tutorial] Make a trainer in C++ Part 1

Discussion in 'Programming' started by DarkSpace, Aug 9, 2010.

  1. DarkSpace

    DarkSpace Well-Known Member Coder

    Dont forget to give me some Credit in your Trainer/bot for writing all of these tutorials and helping some of you individually in my own free time.

    Hi everyone. here i'll show you the basics on how to make your own hacks for maplestory.
    starting off with the most basic form and making it into a DLL to attach to the maplestory.

    Visual Studio/C++ 2009 and up

    Step 1: Set up
    Open Your Visual Studio, Go To File -> New ->Win32->Win32 Project
    Name your Projet and create it

    In the pop up window do the following:
    Click Next on the 1st window
    Application Type ( DLL )
    Additonal Options ( Empty Project)
    You can click Finish now.

    You Should have something that looks like this now
    https://imagizer.ImageShack is toxicus/v2/183x147q90/539/58JtpX.png

    Step 2: File Creation
    Now we need to make our 1st .CPP file. this will be our main file thats gonna get called when we attach the DLL to the game.

    Right Click on Source Files and select Add -> New Item -> C++ file (.cpp) .
    Name it MainDLL for this tutorial.

    Now lets make our form.

    Right Click on Header Files. Add -> New Item -> Window Form.
    Name it Form1 for this tutorial. Click ok

    You should get this
    https://imagizer.ImageShack is toxicus/v2/466x195q90/537/KKXHzf.png
    Click YES there. it will take few seconds for the files to be created. so just sit and wait.

    When its done Loading. you'll see 2 new files created. Form1.h and Form1.cpp
    if you want to keep your program nice and neat. go ahead and move Form1.cpp to your Source Files.
    so you should have something like this now
    https://imagizer.ImageShack is toxicus/v2/180x200q90/746/O0lgJR.png

    We are done with step 2

    Step 3: Coding

    We'll Work our way from the top of the solution explorer just for the sake of simplicity. you can do this in any order
    or even change the code to match your trainer.

    Right click on Form1.h -> view Code
    on the very 1st line type
    Code (Text):
    2. #include <windows.h>
    So it looks like this
    https://imagizer.ImageShack is toxicus/v2/372x256q90/673/L501SC.png

    what #include does is it includes the needed files/functions to make the program work. there are 2 different includes.
    1st one is
    #include <file.h> this one includes files that are found on your system. external to the project
    2nd one is
    #include "file.h" this one includes files that are found within your project

    you can share functions and program's properties by including the files where those functions are found.

    Now we are done with Form1.h

    Double Click on Form1.cpp to open it up.
    there should be only 1 line of code there already and thats the include of form1.h
    Under that line of code we'll need to set the namespace we want to use
    *How do i know what namespace to use for my program?
    The namespace can be found in Form1.h and most of the time its your Project's name without the spaces

    type this under the includes
    Code (Text):
    2. using namespace Tutorial;
    what using namespace does is just makes your code a bit smaller and easier to use.
    now we can call out to our Form1 by just saying Form1 instead of typing Tutorial::Form1 every time we need to get to our Form.

    under the namespace we are going to create a function.

    That function is gonna be called "Main"

    Code (Text):
    2. void Main(void)
    3. {
    4.     Application::EnableVisualStyles();
    5.     Application::SetCompatibleTextRenderingDefault(false);
    6.     Application::Run(gcnew Form1); //change Form1 this to the name of your Form
    7.     Application::Exit();
    8. }
    A function is a block of code that gets executed by calling the functions name anywhere in our program.
    by just saying Main(); the program is going to run all those lines of code that are found in between { and }

    your Form1.cpp should look like this, now thats fully completed.
    https://imagizer.ImageShack is toxicus/v2/510x212q90/540/NqHQG0.png

    We are done with Form1.cpp

    Lets move on to the last file.

    Double Click MainDLL.cpp
    We'll need to Include a windows file to MainDLL
    so to include it type
    Code (Text):
    2. #include <windows.h>
    on the next line. we need to point to the Main function we created in Form1.cpp
    there are couple of ways to link to that function. but the most easy way is using the extern keyword
    type this under the includes
    Code (Text):
    2. extern void Main(void);
    extern tells the compiler that the function exist somewhere else in the program(in our case Main exists in Form1.cpp) and that its not in the current file.
    so when we build our program, the compiler is going to go out and find the function for us.

    Now we need to make a function that is going to be called after a successful injection
    under the extern keyword type this
    Code (Text):
    2. ::BOOL WINAPI DllWork ( __in ::HMODULE hModule )
    3. {
    4.     Main();
    5.     return true;
    6. }
    this function is a bit different than the 1st function we made in form1.cpp
    this one is of BOOL type. it means it will return 1 of 2 values when called.
    and it MUST ALWAYS return a value.
    WINAPI is just an _stdcall never mind that for now.
    DllWork is going to be the main function name that we'll call when we inject the program.

    last piece of code.
    this is auto called when injection is made.
    Code (Text):
    2. ::BOOL WINAPI DllMain ( __in ::HMODULE hModule, __in ::DWORD dwReason, __in __reserved ::LPVOID lpvReserved )
    3. {
    4.     ::HANDLE hThread = NULL;
    6.     if ( dwReason == DLL_PROCESS_ATTACH )
    7.     {
    8.         if (( hThread = ::CreateThread(NULL, 0, (::LPTHREAD_START_ROUTINE)&DllWork, (::HMODULE)hModule, 0, NULL) ) == NULL )
    9.         {
    10.             return FALSE;
    11.         }
    12.         if ( ::CloseHandle(hThread) == FALSE )
    13.         {
    14.                       //do nothing
    15.         }
    16.     }
    17.     return TRUE;
    18. }
    CreateThread function takes all the work from the main program and proccess it. makes the program respond much faster and doesnt cause any lag.
    when a Thread is created it will stay alive untill it reaches the end of the code. then it will die.
    to keep a thread alive there are couple of methods. like making a loop of some sort.

    MainDLL.cpp should look like this when done
    https://imagizer.ImageShack is toxicus/v2/994x465q90/904/iJpp0N.png

    Moment of truth. Click on where it says Debug on top of your visual studio.
    change it to Release.

    and then go to Build > Build Solution (F7)

    if everything went fine you should get
    ========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

    Start your Winject / other injecter
    Start MapleStory.
    Locate your DLL by going to your Docs -> Visual Studio -> Projects -> Tutorial -> Release
    or something like that

    Inject it and you'll see a window popup.

    Last edited: Aug 9, 2014
    • Like x 28
    • Made my day! x 6
    • Great work x 5
    • Informative x 2
    • Thank You! x 2
    • Helped me! x 1
  2. Ation

    Ation s. mod Moderator Donor

    Thaaanks a lot. :F2:
    After finishing my Aran's 3rd job and some other things I'll start making a trainer. :$
    • Heart-warming Heart-warming x 2
  3. DarkSpace

    DarkSpace Well-Known Member Coder

    Alright, would be nice seeing more releases on EMS section.

    what they say. give a man a fish, he's gonna eat for a day, teach him how to fish, he'll have enough food for a lifetime.

    same thing applies here. but everyone benefits.
    more trainers being released = more hacks to use = more options on what to use and what not.

    good luck and if you have any problems post in this section. i'll try to help out.
  4. Fury

    Fury <marquee><font color="#FFBF00"><b>Official CCPLZ G Banned

    D: i wast lot of time today watching videos on youtube and then i found this >.<
  5. Ation

    Ation s. mod Moderator Donor

    That's true indeed. Too bad some people keep just eating fishes forever and never bother to fish by theirselves -> they'll become fat = leechers.
    • Like Like x 1
  6. Twister

    Twister Well-Known Member

    I, Love, You, Man.
    I was looking for such a thread for quite some time, never found one. D:
    Thank you, so much for this. ♥
  7. DarkSpace

    DarkSpace Well-Known Member Coder

    you are very welcome. now show us what you can make =D

    part2 will show how to add some hacks. =D and then we will get into pointers and what not.
  8. Eztys

    Eztys New Member

    Awesome! Now I'm permbanned again, I think I start making hacks instead:) This should be a good start.
  9. Twister

    Twister Well-Known Member

    Cant wait!
  10. Subarashii

    Subarashii Well-Known Member

    Nice one dude, let's see what I can make out of this extra :D
  11. Scum 72638

    Scum 72638 Go with the flow. Banned

    Great job W8Dark, The idea to post it in such a way makes it so easy for people new to programming to understand! *points people in the direction of looking at kitterz bot to read all his descriptions* You know what, I would say this is the best trainer tutorial I have ever seen! ;-) grats!
  12. DarkSpace

    DarkSpace Well-Known Member Coder

    Thanks. Hope it helps the starters to get some new ideas out.
  13. Ation

    Ation s. mod Moderator Donor

    I tried to install Visual Studio 2010, but the installation kind of failed.

  14. Subarashii

    Subarashii Well-Known Member

    Kind of failed??? XD
  15. Ation

    Ation s. mod Moderator Donor

    Well... actually every step of installation failed totally. :D
    I'll try to install VS 2010 Pro now.
  16. Serenoxis

    Serenoxis Active Member

    Great tutorial for beginners though I dislike CLR you made it clear enough for people to understand :)
    It's not a problem with the installer as such but it's dependencies that are corrupt.This page had the solution I used when I had the problem. If you can be bothered to read it and find out why set a boot time disk check on your system partition, that should solve the problem.
  17. Ation

    Ation s. mod Moderator Donor

    I was reading that already, but thanks anyways. :)

    Now it works.
  18. Elite Crew

    Elite Crew Active Member

    Noice tut pal, i jawst mad mah 1st trainer :D, cawnt waty 4 next tut put ce scripts in mah trainer :)
  19. King Virus

    King Virus Banned Banned

    Thanks allot W8Dark, I was reading TheNullz' TuT aswell - Can't wait for ur 2nd part.
  20. Huskyhond

    Huskyhond New Member

    Nice REL (Soz if i bumped :P)

Share This Page