Advertisement
Guest User

Simple Dota 2 trainer

a guest
May 1st, 2016
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.32 KB | None | 0 0
  1. /*
  2.  *  Simple trainer for dota. Can currently only change HP of abaddon.
  3.  * Code is based of the C++ trainer code from Fleep
  4.  * Download the original code from:  http://guidedhacking.com/attachment.php?attachmentid=3473&d=1445714125
  5.  *  Link to the tutorial:  http://guidedhacking.com/showthread.php?3-C-HOW-TO-HACK-any-game-TUTORIAL-Trainer-amp-DLL-Injection-DIFFICULTY-2-10
  6. */
  7.  
  8.  
  9.  
  10. #include <iostream>
  11. #include <Windows.h>
  12. #include <string>
  13. #include <ctime> // needed for our timer clock
  14.  
  15. #include <windows.h>
  16. #include <tchar.h>
  17. #include <stdio.h>
  18. #include <psapi.h>
  19.  
  20. #include <string.h>
  21.  
  22. void WriteToMemory(HANDLE hProcHandle);
  23. DWORD FindDmaAddy(int PointerLevel, HANDLE hProcHandle, DWORD Offsets[], DWORD BaseAddress);
  24.  
  25. //CREATES the string used to determine the name of our target window e.g. Calculator
  26. std::string GameName = "Dota 2";
  27. LPCWSTR LGameWindow = L"Dota 2"; //<- MAKE SURE it matches the window name
  28. std::string GameStatus;
  29. //FUNCTION PROTOTYPES
  30. bool IsGameAvail;
  31. bool UpdateOnNextRun; //used to update the display menu only when something changed
  32.  
  33. //-------HP VARS--------
  34. //number we are going to overwrite the current hp with in bytes
  35. bool HPStatus; // used to DEFine wether HP is on or not
  36. BYTE HPValue[] = {0x28,0xA,0x0,0x0}; // writing bytes into memory. This value here corresponds to 2600
  37. DWORD HPBaseAddress = {0x23CF62E0}; // should be server.dll+14E62E0    , this is just an example value
  38. DWORD HPOffsets[] = {0x0, 0xBC}; //3 LEVEL pointer
  39. bool addedOffset; //used to check if the 14E62E0  is already added to the adress of server.dll and stored in HPBaseAddress
  40.  
  41. //original function from   https://msdn.microsoft.com/en-us/library/ms682621%28v=vs.85%29.aspx
  42. int PrintModules( DWORD processID )
  43. {
  44.     HMODULE hMods[1024];
  45.     HANDLE hProcess;
  46.     DWORD cbNeeded;
  47.     unsigned int i;
  48.  
  49.     // Print the process identifier.
  50.  
  51.     printf( "\nProcess ID: %u\n", processID );
  52.  
  53.     // Get a handle to the process.
  54.  
  55.     hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
  56.                             PROCESS_VM_READ,
  57.                             FALSE, processID );
  58.     if (NULL == hProcess)
  59.         return 1;
  60.  
  61.    // Get a list of all the modules in this process.
  62.  
  63.     if( EnumProcessModules(hProcess, hMods, sizeof(hMods), &cbNeeded))
  64.     {
  65.         for ( i = 0; i < (cbNeeded / sizeof(HMODULE)); i++ )
  66.         {
  67.             TCHAR szModName[MAX_PATH];
  68.  
  69.             // Get the full path to the module's file.
  70.  
  71.             if ( GetModuleFileNameEx( hProcess, hMods[i], szModName,
  72.                                       sizeof(szModName) / sizeof(TCHAR)))
  73.             {
  74.                 // Print the module name and handle value.
  75.                 std::wstring getDLLstr(szModName);
  76.                 if(  getDLLstr.find(L"server.dll") != std::wstring::npos){ //we need the server.dll memory adresss
  77.                    _tprintf( TEXT("\t%s (0x%08X)\n"), szModName, hMods[i] );
  78.                     std::cout <<  hMods[i] << std::endl;
  79.                     HMODULE addtoThis = HMODULE(0x14E62E0);
  80.                     std::cout <<  (int)hMods[i] + 0x14E62E0 << std::endl;
  81.                     if( addedOffset == false){
  82.                         addedOffset = true;
  83.                         std::cout << "before extra offset:" <<  HPBaseAddress << std::endl;
  84.                         //add 0x14E62E0 to the server.dll memory adress to get the abaddon hp memory adress
  85.                         HPBaseAddress =  (DWORD)((int)hMods[i] + 0x14E62E0);
  86.                     }
  87.                     std::cout <<  "after extra offset:" <<  HPBaseAddress << std::endl;
  88.                    //char getHex = ( "(0x%08X)" , hMods[i] );
  89.                 }
  90.             }
  91.         }
  92.     }
  93.    
  94.     // Release the handle to the process.
  95.  
  96.     CloseHandle( hProcess );
  97.  
  98.     return 0;
  99. }
  100.  
  101. int main()
  102. {
  103.     addedOffset = false;
  104.     //Declare our handles as NULL to avoid crashes when closing if they were unused e.g. player starts trainer and closes it before doing any cheats
  105.     HWND hGameWindow = NULL;
  106.     int timeSinceLastUpdate = clock(); //forces status update every x seconds
  107.     int GameAvailTMR = clock();
  108.     int OnePressTMR;//used to limit keys input to only one per x ms
  109.     DWORD dwProcId = NULL;
  110.     HANDLE hProcHandle = NULL;
  111.     UpdateOnNextRun = true;
  112.     std::string sHPStatus;
  113.     sHPStatus = "OFF";
  114.     OnePressTMR = clock();
  115.     while(!GetAsyncKeyState(VK_INSERT)) //Key is not = 'INSERT'
  116.     {
  117.         //Does a series of checks every x ms and
  118.         //checks that the game is available and capable of being
  119.         //written to, if thats the case we write declare it available
  120.         //otherwise we report where it went wrong
  121.         //e.g. if game is closed we make things unavailable, or if its opened
  122.         //we make options available again
  123.        
  124.         if(clock() - GameAvailTMR > 100)
  125.         {
  126.             GameAvailTMR = clock();
  127.             //Declare game unavailable by default
  128.             //if it is available then it will change immediately
  129.             IsGameAvail = false;
  130.             //Check a valid window is available
  131.             // Get Window Handle
  132.             hGameWindow = FindWindow( NULL, LGameWindow);
  133.             if(hGameWindow)
  134.             {
  135.                GetWindowThreadProcessId( hGameWindow, &dwProcId );
  136.                //If it is a valid id we continue to try and open the process
  137.                if( dwProcId != 0 )
  138.                {
  139.                    // Get Process Handle
  140.                    hProcHandle = OpenProcess( PROCESS_ALL_ACCESS, FALSE, dwProcId );
  141.                    if( hProcHandle == INVALID_HANDLE_VALUE || hProcHandle == NULL )
  142.                    {
  143.                         GameStatus = "Failed to open process for valid handle";
  144.                    }
  145.                    else
  146.                    {
  147.                      GameStatus = "Dota 2 Ready to hack";
  148.                      IsGameAvail = true;
  149.                    }
  150.                }
  151.                else GameStatus = "Failed to obtain process id";
  152.             }
  153.             else GameStatus = "Dota 2 NOT FOUND";
  154.  
  155.             //if UpdateNextRun is called or a number of seconds without updates have gone by an auto update is done
  156.             //to make sure game is available etc.
  157.             if(UpdateOnNextRun || clock() - timeSinceLastUpdate > 5000)
  158.             {
  159.                 system("cls");
  160.                 std::cout << "----------------------------------------------------" << std::endl;
  161.                 std::cout << "        Example Dota 2 trainer" << std::endl;
  162.                 std::cout << "----------------------------------------------------" << std::endl << std::endl;
  163.                 std::cout << "GAME STATUS:"<< GameStatus  <<"   " << std::endl << std::endl;
  164.                 std::cout << "[F1] Abaddon always 2600 hp -> "<< sHPStatus <<" <-" << std::endl<< std::endl;
  165.                 //std::cout << "[F2] Unlimited Health and armor ->" << sHealthStatus << "<-" << std::endl<< std::endl;
  166.                 std::cout << "[INSERT] Exit" << std::endl;
  167.                 PrintModules( dwProcId );
  168.                 UpdateOnNextRun = false;
  169.                 timeSinceLastUpdate = clock();
  170.             }
  171.  
  172.             if(IsGameAvail)
  173.             {
  174.                 WriteToMemory(hProcHandle);
  175.             }
  176.         }
  177.  
  178.         //Stops Keys from being spammed e.g. only allow them to be pressed every x milliseconds
  179.         if(clock() - OnePressTMR > 400)
  180.         {
  181.             if(IsGameAvail)
  182.             {
  183.                 //DETECTS WHICH KEYS HAVE BEEN PRESSED IN order to turn cheats on and off
  184.                 if(GetAsyncKeyState(VK_F1))
  185.                 {
  186.                     OnePressTMR = clock();
  187.                     //Reverts the HP status e.g. from true to false and vice versa
  188.                     HPStatus = !HPStatus;
  189.                     UpdateOnNextRun = true;
  190.                     //changes the text to update on next display
  191.                     if(HPStatus)sHPStatus = "ON";
  192.                     else sHPStatus = "OFF";
  193.                 }
  194.             }
  195.         }
  196.     }
  197.     //Close any handles once the program is over
  198.     CloseHandle( hProcHandle );
  199.     CloseHandle(hGameWindow);
  200.  
  201.     //Returns that action was completed successfuly
  202.     return ERROR_SUCCESS;
  203. }
  204.  
  205.  
  206. //Handles Dynamic memory allocation
  207. //Receives how high the pointer level is e.g. 4 levels and from that calculates the initial address
  208. //the offset values and the memory addresses for those offsets
  209. DWORD FindDmaAddy(int PointerLevel, HANDLE hProcHandle, DWORD Offsets[], DWORD BaseAddress)
  210. {
  211.     //DECLARE BASE ADDRESS
  212.     DWORD pointer = BaseAddress;             // Declare a pointer of DWORD
  213.     //USED TO output the contents in the pointer
  214.     DWORD pTemp;
  215.  
  216.     DWORD pointerAddr;
  217.     for(int i = 0; i < PointerLevel; i ++)
  218.     {
  219.             if(i == 0)
  220.             {
  221.                 ReadProcessMemory(hProcHandle, (LPCVOID)pointer, &pTemp, 4, NULL);
  222.             }
  223.             //add first offset to that address
  224.             pointerAddr = pTemp + Offsets[i];   // Set p1 to content of p + offset
  225.  
  226.             //Read memory one more time and exit the loop
  227.             ReadProcessMemory(hProcHandle, (LPCVOID)pointerAddr, &pTemp, 4, NULL);
  228.     }
  229.     return pointerAddr;
  230. }
  231.  
  232. void WriteToMemory(HANDLE hProcHandle)
  233. {
  234.    if(HPStatus)
  235.    {
  236.        DWORD HPAddressToWrite = FindDmaAddy(2, hProcHandle, HPOffsets, HPBaseAddress);
  237.        WriteProcessMemory( hProcHandle, (BYTE*)HPAddressToWrite, &HPValue, sizeof(HPValue), NULL);
  238.    }
  239.  
  240. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement