Advertisement
Guest User

APB autoshoot

a guest
Jul 29th, 2011
1,127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.66 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Threading;
  10. using System.Runtime.InteropServices;
  11. using System.Diagnostics;
  12. using WindowsInput;
  13.  
  14. namespace APB
  15. {
  16.     public partial class Form1 : Form
  17.     {
  18.         [DllImport("user32.dll")]
  19.         public static extern IntPtr FindWindow(String sClassName, String sAppName);
  20.  
  21.         [return: MarshalAs(UnmanagedType.Bool)]
  22.         [DllImport("user32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
  23.         public static extern bool SetForegroundWindow(IntPtr hwnd);
  24.  
  25.         //this is just standard procedure copy and paste to get the mouse_event fucntion in user32.dll working here
  26.         [DllImport("user32.dll")]
  27.         static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo);
  28.  
  29.         [DllImport("user32.dll")]
  30.         static extern bool GetWindowRect(IntPtr hWnd, out RECT rect);
  31.  
  32.         [DllImport("user32.dll")]
  33.         static extern IntPtr GetDC(IntPtr hwnd);
  34.  
  35.         [DllImport("user32.dll")]
  36.         static extern Int32 ReleaseDC(IntPtr hwnd, IntPtr hdc);
  37.  
  38.         [DllImport("gdi32.dll")]
  39.         static extern uint GetPixel(IntPtr hdc, int nXPos, int nYPos);
  40.  
  41.         static public System.Drawing.Color GetPixelColor(int x, int y)
  42.         {
  43.             IntPtr hdc = GetDC(IntPtr.Zero);
  44.             uint pixel = GetPixel(hdc, x, y);
  45.             ReleaseDC(IntPtr.Zero, hdc);
  46.             Color color = Color.FromArgb((int)(pixel & 0x000000FF),
  47.                          (int)(pixel & 0x0000FF00) >> 8,
  48.                          (int)(pixel & 0x00FF0000) >> 16);
  49.             return color;
  50.         }
  51.  
  52.  
  53.         [StructLayout(LayoutKind.Sequential)]
  54.         struct RECT
  55.         {
  56.             public int left;
  57.             public int top;
  58.             public int right;
  59.             public int bottom;
  60.         }
  61.  
  62.         [Flags]
  63.         public enum MouseEventFlags
  64.         {
  65.             LEFTDOWN = 0x00000002,
  66.             LEFTUP = 0x00000004,
  67.             MIDDLEDOWN = 0x00000020,
  68.             MIDDLEUP = 0x00000040,
  69.             MOVE = 0x00000001,
  70.             ABSOLUTE = 0x00008000,
  71.             RIGHTDOWN = 0x00000008,
  72.             RIGHTUP = 0x00000010
  73.         }
  74.  
  75.        
  76.  
  77.         public Form1()
  78.         {
  79.             InitializeComponent();
  80.            
  81.  
  82.         }
  83.  
  84.      
  85.         void click(int posX, int posY)
  86.         {
  87.             mouse_event((int)(MouseEventFlags.LEFTDOWN), posX, posY, 0, 0);
  88.             mouse_event((int)(MouseEventFlags.LEFTUP), posX, posY, 0, 0);
  89.         }
  90.  
  91.  
  92.         void Shoot() {
  93.  
  94.             while (1 == 1)
  95.             {
  96.  
  97.                 RECT rect;
  98.                             IntPtr APBwindow = FindWindow(null, "APB Reloaded");
  99.                             GetWindowRect(APBwindow, out rect);
  100.                             int X,Y,winX, winY,sizeX,sizeY;
  101.                             winX = rect.left;
  102.                             winY = rect.top;
  103.                             sizeX = rect.right;
  104.                             sizeY = rect.bottom;
  105.  
  106.  
  107.                 if (InputSimulator.IsKeyDown(VirtualKeyCode.RBUTTON) == true)
  108.                 {
  109.                     for (int i = 1; i <= 10; i++)
  110.                     {
  111.  
  112.                         if (i == 1)
  113.                         {
  114.                             Thread.Sleep(250);
  115.                             if (GetPixelColor(winX + (sizeX * 803/1763), winY + (sizeY *488/984)).G < 140 & GetPixelColor(winX + (sizeX * 803/1763), winY + (sizeY *488/984)).B < 140 & GetPixelColor(winX + (sizeX * 803/1763), winY + (sizeY *488/984)).R > 170)
  116.                             {
  117.  
  118.                                 X = Cursor.Position.X;
  119.                                 Y = Cursor.Position.Y;
  120.                                 click(0, 0);
  121.                                 Thread.Sleep(150);
  122.                             }
  123.                         }
  124.  
  125.                         else if (i > 1)
  126.                         {
  127.  
  128.                             if (GetPixelColor(winX + (sizeX * 803/1763), winY + (sizeY *488/984)).G < 140 & GetPixelColor(winX + (sizeX * 803/1763), winY + (sizeY *488/984)).B < 140 & GetPixelColor(winX + (sizeX * 803/1763), winY + (sizeY *488/984)).R > 170)
  129.                             {
  130.                                 X = Cursor.Position.X;
  131.                                 Y = Cursor.Position.Y;
  132.                                 click(0, 0);
  133.                                 Thread.Sleep(150);
  134.                             }
  135.                         }
  136.                         if (InputSimulator.IsKeyDown(VirtualKeyCode.RBUTTON) == false)
  137.                         {
  138.                             break;
  139.                         }
  140.                         Thread.Sleep(1);
  141.                     }
  142.                     Thread.Sleep(1);              
  143.                 }
  144.             }
  145.         }
  146.  
  147.        
  148.         private void button1_Click(object sender, EventArgs e)
  149.         {
  150.  
  151.             ThreadStart APBshoot = new ThreadStart(Shoot);
  152.             Thread APBActive = new Thread(APBshoot);
  153.             APBActive.Start();
  154.  
  155.             IntPtr APBwindow = FindWindow(null, "APB Reloaded");
  156.             SetForegroundWindow(APBwindow);
  157.            
  158.            
  159.         }
  160.  
  161.         private void button2_Click(object sender, EventArgs e)
  162.         {
  163.            
  164.             foreach (Process clsProcess in Process.GetProcesses())
  165.             {
  166.                 if (clsProcess.ProcessName.StartsWith("APBbot"))
  167.                 {
  168.                     clsProcess.Kill();
  169.  
  170.                 }
  171.  
  172.             }
  173.         }
  174.     }
  175. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement