Guest User

Untitled

a guest
Jun 26th, 2011
448
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.25 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <windows.h>
  3. #include <iostream>
  4. #include <Tlhelp32.h>
  5.  
  6. using namespace std;
  7. HMODULE Clientdll = NULL;
  8. /*HWND hwnd;
  9. HANDLE phandle;
  10. DWORD pid;*/
  11.  
  12. DWORD GetProcessIDFromName(LPSTR szProcName)                                        //this function gets the id of a process using a name (hl2.exe for instance)
  13. {
  14.     PROCESSENTRY32 procEntry;
  15.     HANDLE hSnapshot;
  16.     BOOL bFound;
  17.  
  18.     if(!(hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0))) return 0;   
  19.     procEntry.dwSize = sizeof(PROCESSENTRY32);
  20.  
  21.     bFound = Process32First(hSnapshot, &procEntry);
  22.     while(bFound)
  23.     {
  24.         if(!lstrcmp(procEntry.szExeFile, szProcName))
  25.         {
  26.             CloseHandle(hSnapshot);
  27.             return procEntry.th32ProcessID;
  28.         }
  29.         bFound = Process32Next(hSnapshot, &procEntry);
  30.     }
  31.     CloseHandle(hSnapshot);
  32.     return 0;
  33. }
  34.  
  35. HMODULE GetModuleHandleExtern( char *szModuleName, DWORD dwProcessId )                  //GetMoguleHandle recode for external processes
  36. {
  37.    if( !szModuleName || !dwProcessId ) { return NULL; }                                 //invalid input
  38.    HANDLE hSnap = CreateToolhelp32Snapshot( TH32CS_SNAPMODULE, dwProcessId );
  39.    if( hSnap == INVALID_HANDLE_VALUE ) { return NULL; }
  40.    MODULEENTRY32 me;
  41.    me.dwSize = sizeof( MODULEENTRY32 );
  42.    if( Module32First( hSnap, &me ) )                                                    //we go now
  43.    {
  44.       while( Module32Next( hSnap, &me ) )                                               //through all modules in the target process
  45.       {
  46.          if( !strcmp( me.szModule, szModuleName ) )                                     //is this the model we are looking for?
  47.          {
  48.             CloseHandle( hSnap );
  49.             return me.hModule;                                                          //this is our module, return it.
  50.          }
  51.       }
  52.    }
  53.    CloseHandle( hSnap );
  54.    return NULL;                                                                         //counldn't find module
  55. }
  56.  
  57. int main ()
  58. {
  59.     cout << "waiting for counter strike source...\n";
  60.     while( FindWindowA( "Valve001", NULL ) == NULL )                                    //before getting the module handle i wait for css
  61.     {
  62.         Sleep( 100 );
  63.     }
  64.  
  65.     /*
  66.     while (!hwnd)                                                                       //this is a test trying to fix the actual issue
  67.     {
  68.         hwnd = FindWindowA( "Valve001", NULL );
  69.     }
  70.     GetWindowThreadProcessId(hwnd, &pid);
  71.     phandle = OpenProcess(PROCESS_ALL_ACCESS, 0, pid);
  72.     */
  73.  
  74.     cout << "found the game!\n";
  75.     cout << "the id of process is: " << GetProcessIDFromName("hl2.exe") << "\n";        //showing the id to debug better
  76.     cout << "getting the module handle of client.dll\n";
  77.     do
  78.     {    
  79.         Clientdll = GetModuleHandleExtern("client.dll", GetProcessIDFromName("hl2.exe"));   //at this point we get the module handle from an ext process
  80.         Sleep(20);                                                                          //thanks a lot to mencore
  81.     }
  82.     while(Clientdll == NULL);                                                               //just looping it until we get it even if this shouldn't be needed
  83.    
  84.     cout << "got the module handle!!!";
  85.     cout << "the base is: " << Clientdll << "\n";                                           //showing it to debug it
  86.  
  87.     while (!GetAsyncKeyState(VK_F10))                                                       //loops the bhop code untill f10 is pressed
  88.     {
  89.         if( (*(int*)((DWORD)Clientdll + 0x590A0C) == 0) && (GetAsyncKeyState(VK_MENU)<0) )  //checks for OnGround->yes and ALT->pressed
  90.         {
  91.             keybd_event(VK_SPACE, 0x39, 0, 0);                                              //simulates jump...
  92.             Sleep(60);
  93.             keybd_event(VK_SPACE, 0x39, KEYEVENTF_KEYUP, 0);
  94.         }
  95.         Sleep(1);                                                                           //this value could be changed to a greater one to fit slower pc's
  96.     }
  97.     return 0;
  98. }
Add Comment
Please, Sign In to add comment