Advertisement
chrondog

Untitled

Dec 29th, 2012
702
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "stdafx.h"
  2. #include <Windows.h>
  3. #include <iostream>
  4. #include <TlHelp32.h>
  5. using namespace std;
  6.  
  7. bool GetGameAccess();
  8. void PressKey(unsigned short KeyCode);
  9. ULONG GetModuleAddress(const char *szModuleName, const ULONG dwProcessId);
  10. int IsAlive();
  11. int GetMyTeam();
  12. int GetTargetTeam(int AimTarget);
  13.  
  14. HANDLE phandle;
  15. ULONG ClientDLL;
  16. ULONG EngineDLL;
  17.  
  18. int main()
  19. {
  20.     bool Continue = GetGameAccess();
  21.     if(Continue)
  22.     {
  23.         cout << "Triggerbot loaded!" << endl;
  24.         int i = 0, AimTarget = 0; ULONG AimOffset=0;
  25.         while(1)
  26.         {
  27.             ReadProcessMemory(phandle, LPCVOID(ClientDLL+0x780CD0), &i, sizeof(i), 0); AimOffset = i + 0x14A8;
  28.             ReadProcessMemory(phandle, LPCVOID(AimOffset), &AimTarget, sizeof(AimTarget), NULL);
  29.             if(AimTarget != 0)
  30.             {
  31.                 int TargetTeam = GetTargetTeam(AimTarget);
  32.                 int MyTeam = GetMyTeam();
  33.                 int IsDead = IsAlive();
  34.                 if (TargetTeam != MyTeam &&
  35.                     (TargetTeam == 2 || TargetTeam == 3) &&
  36.                     (MyTeam == 2 || MyTeam == 3) &&
  37.                     IsDead == 0)
  38.                 PressKey(0x1A);
  39.             }
  40.             else
  41.                 Sleep(1);
  42.            
  43.         }
  44.     }
  45.     cin.get();
  46. }
  47.  
  48. int IsAlive()
  49. {
  50.     int Alive = 0;
  51.     ReadProcessMemory(phandle, LPCVOID(ClientDLL + 0x77C5F0), &Alive, sizeof(Alive), NULL);
  52.     return Alive;
  53. }
  54.  
  55. int GetMyTeam()
  56. {
  57.     int Value = 0, PlayerID = 0;
  58.     ReadProcessMemory(phandle, LPCVOID(EngineDLL + 0x42CAD8), &PlayerID, sizeof(PlayerID), NULL);
  59.     PlayerID = 0x6E4+(4*PlayerID);
  60.     ReadProcessMemory(phandle, LPCVOID(ClientDLL + 0x74B430), &Value, sizeof(Value), NULL);
  61.     ReadProcessMemory(phandle, LPCVOID(Value+0x26C), &Value, sizeof(Value), NULL);
  62.     ReadProcessMemory(phandle, LPCVOID(Value+PlayerID), &Value, sizeof(Value), NULL);
  63.     return Value;
  64. }
  65.  
  66. int GetTargetTeam(int AimTarget)
  67. {
  68.     int Value1 = 0, Value2 = 0;
  69.     ReadProcessMemory(phandle, LPCVOID(ClientDLL + 0x74B430), &Value1, sizeof(Value1), NULL);
  70.     ReadProcessMemory(phandle, LPCVOID(Value1 + 0x26C), &Value1, sizeof(Value1), NULL);
  71.     Value2 = 0x6E4+(4*AimTarget);
  72.     ReadProcessMemory(phandle, LPCVOID(Value1 + Value2), &Value1, sizeof(Value1), NULL);
  73.     return Value1;
  74. }
  75.  
  76. bool GetGameAccess()
  77. {
  78.     ULONG pid;
  79.     HWND hWnd;
  80.     hWnd = FindWindow(NULL, "Counter-Strike Source");
  81.     if(!hWnd)
  82.     {
  83.         cout <<"Game not found. Press enter to retry.\n";
  84.         cin.get();
  85.         main();
  86.         return false;
  87.     }
  88.     else
  89.     {
  90.         GetWindowThreadProcessId(hWnd, &pid);
  91.         phandle = OpenProcess(PROCESS_VM_READ, 0, pid);
  92.         if(!phandle)
  93.         {
  94.             cout << "Could not get handle to window. Press enter to retry.\n";
  95.             cin.get();
  96.             main();
  97.             return false;
  98.         }
  99.         else
  100.         {
  101.             ClientDLL = GetModuleAddress("client.dll", pid);
  102.             EngineDLL = GetModuleAddress("engine.dll", pid);
  103.             return true;
  104.         }
  105.     }
  106. }
  107.  
  108. ULONG GetModuleAddress(const char *szModuleName, const ULONG dwProcessId)
  109. {
  110.     if (!szModuleName || !dwProcessId)
  111.         return 0;
  112.     HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, dwProcessId);
  113.     if (hSnap == INVALID_HANDLE_VALUE)
  114.         return 0;
  115.     MODULEENTRY32 me;
  116.     me.dwSize = sizeof(MODULEENTRY32);
  117.     if (Module32First(hSnap, &me))
  118.     {
  119.         while (Module32Next(hSnap, &me))
  120.         {
  121.             if (strcmp(reinterpret_cast<const char*>(me.szModule), szModuleName) == 0)
  122.             {
  123.                 CloseHandle(hSnap);
  124.                 return (ULONG)me.modBaseAddr;
  125.             }
  126.         }
  127.     }
  128.     CloseHandle(hSnap);
  129.     return 0;
  130. }
  131.  
  132. void PressKey(unsigned short KeyCode)
  133. {
  134.     INPUT InputData;
  135.     InputData.type = INPUT_KEYBOARD;
  136.     InputData.ki.wScan = KeyCode;
  137.     InputData.ki.time = (0);
  138.     InputData.ki.dwExtraInfo = 0;
  139.     InputData.ki.dwFlags = 0;
  140.     SendInput(1, &InputData, sizeof(InputData));
  141.     Sleep(10);
  142.     InputData.ki.dwFlags = KEYEVENTF_KEYUP;
  143.     SendInput(1, &InputData, sizeof(InputData));
  144.     Sleep(10);
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement