UnrealSkill-VIP
Gostaria de reagir a esta mensagem? Crie uma conta em poucos cliques ou inicie sessão para continuar.

[Source] TriggerBot C++ & C#

Ir para baixo

[Source] TriggerBot C++ & C# Empty [Source] TriggerBot C++ & C#

Mensagem por uNreal 10/7/2020, 00:21

C++
Código:
#include <wrl/client.h>
#include <windows.h>
#include <iostream>
#include <dxgi.h>
#include <dxgi1_2.h>
#include <d3d11.h>
#include <stdlib.h>
 
#pragma comment(lib,"d3d11.lib")
 
using namespace std;
 
int x;
int y;
 
const int lookSize = 5;
 
const int Shade_Variation = 35;
const int Formatted_Color_Red = 235;
const int Formatted_Color_Green = 80;
const int Formatted_Color_Blue = 235;
 
using Microsoft::WRL::ComPtr;
 
ComPtr<ID3D11Device> lDevice;
ComPtr<ID3D11DeviceContext> lImmediateContext;
ComPtr<IDXGIOutputDuplication> lDeskDupl;
ComPtr<ID3D11Texture2D> lAcquiredDesktopImage;
ComPtr<ID3D11Texture2D> lGDIImage;
DXGI_OUTPUT_DESC lOutputDesc;
DXGI_OUTDUPL_DESC lOutputDuplDesc;
D3D11_TEXTURE2D_DESC desc;
 
 
D3D_DRIVER_TYPE gDriverTypes[] = {
   D3D_DRIVER_TYPE_HARDWARE
};
UINT gNumDriverTypes = ARRAYSIZE(gDriverTypes);
 
// Feature levels supported
D3D_FEATURE_LEVEL gFeatureLevels[] = {
   D3D_FEATURE_LEVEL_11_0,
   D3D_FEATURE_LEVEL_10_1,
   D3D_FEATURE_LEVEL_10_0,
   D3D_FEATURE_LEVEL_9_1
};
UINT gNumFeatureLevels = ARRAYSIZE(gFeatureLevels);
 
 
void ToggleKey(BYTE key, bool set) {
   keybd_event(key,
      0x45,
      set ? (KEYEVENTF_EXTENDEDKEY | 0) : (KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP),
      0);
}
 
void MouseDown() {
   ToggleKey(VK_LBUTTON, true);
   Sleep(1);
   ToggleKey(VK_LBUTTON, false);
}
 
bool GoodTriggerbotInit() {
   int lresult(-1);
 
   D3D_FEATURE_LEVEL lFeatureLevel;
 
   HRESULT hr(E_FAIL);
 
   // Create device
   for (UINT DriverTypeIndex = 0; DriverTypeIndex < gNumDriverTypes; ++DriverTypeIndex)
   {
      hr = D3D11CreateDevice(
         nullptr,
         gDriverTypes[DriverTypeIndex],
         nullptr,
         0,
         gFeatureLevels,
         gNumFeatureLevels,
         D3D11_SDK_VERSION,
         &lDevice,
         &lFeatureLevel,
         &lImmediateContext);
 
      if (SUCCEEDED(hr))
      {
         // Device creation success, no need to loop anymore
         break;
      }
 
      lDevice.Reset();
 
      lImmediateContext.Reset();
   }
 
   if (FAILED(hr))
      return false;
 
   if (lDevice == nullptr)
      return false;
 
   // Get DXGI device
   ComPtr<IDXGIDevice> lDxgiDevice;
   hr = lDevice.As(&lDxgiDevice);
 
   if (FAILED(hr))
      return false;
 
   // Get DXGI adapter
   ComPtr<IDXGIAdapter> lDxgiAdapter;
   hr = lDxgiDevice->GetParent(
      __uuidof(IDXGIAdapter), &lDxgiAdapter);
 
   if (FAILED(hr))
      return false;
 
   lDxgiDevice.Reset();
 
   UINT Output = 0;
 
   // Get output
   ComPtr<IDXGIOutput> lDxgiOutput;
   hr = lDxgiAdapter->EnumOutputs(
      Output,
      &lDxgiOutput);
 
   if (FAILED(hr))
      return false;
 
   lDxgiAdapter.Reset();
 
   hr = lDxgiOutput->GetDesc(
      &lOutputDesc);
 
   if (FAILED(hr))
      return false;
 
   // QI for Output 1
   ComPtr<IDXGIOutput1> lDxgiOutput1;
   hr = lDxgiOutput.As(&lDxgiOutput1);
 
   if (FAILED(hr))
      return false;
 
   lDxgiOutput.Reset();
 
   // Create desktop duplication
   hr = lDxgiOutput1->DuplicateOutput(
      lDevice.Get(), //TODO what im i doing here
      &lDeskDupl);
 
   if (FAILED(hr))
      return false;
 
   lDxgiOutput1.Reset();
 
   // Create GUI drawing texture
   lDeskDupl->GetDesc(&lOutputDuplDesc);
   desc.Width = lOutputDuplDesc.ModeDesc.Width;
   desc.Height = lOutputDuplDesc.ModeDesc.Height;
   desc.Format = lOutputDuplDesc.ModeDesc.Format;
   desc.ArraySize = 1;
   desc.BindFlags = D3D11_BIND_FLAG::D3D11_BIND_RENDER_TARGET;
   desc.MiscFlags = D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
   desc.SampleDesc.Count = 1;
   desc.SampleDesc.Quality = 0;
   desc.MipLevels = 1;
   desc.CPUAccessFlags = 0;
   desc.Usage = D3D11_USAGE_DEFAULT;
 
 
   hr = lDevice->CreateTexture2D(&desc, NULL, &lGDIImage);
 
   if (FAILED(hr))
      return false;
 
   if (lGDIImage == nullptr)
      return false;
 
   // Create CPU access texture
   desc.Width = lOutputDuplDesc.ModeDesc.Width;
   desc.Height = lOutputDuplDesc.ModeDesc.Height;
   desc.Format = lOutputDuplDesc.ModeDesc.Format;
   std::cout << "Starting at " << desc.Width << "x" << desc.Height << endl;
   desc.ArraySize = 1;
   desc.BindFlags = 0;
   desc.MiscFlags = 0;
   desc.SampleDesc.Count = 1;
   desc.SampleDesc.Quality = 0;
   desc.MipLevels = 1;
   desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
   desc.Usage = D3D11_USAGE_STAGING;
 
   return true;
}
 
bool CaptureNextFrame() {
   HRESULT hr(E_FAIL);
   ComPtr<IDXGIResource> lDesktopResource = nullptr;
   DXGI_OUTDUPL_FRAME_INFO lFrameInfo;
   ID3D11Texture2D* currTexture;
 
   hr = lDeskDupl->AcquireNextFrame(
      999999,
      &lFrameInfo,
      &lDesktopResource);
 
   if (FAILED(hr)) {
      cout << "Failed to acquire new frame, Try restarting the program" << endl;
      return false;
   }
 
   hr = lDesktopResource.As(&lAcquiredDesktopImage);
 
   hr = lDevice->CreateTexture2D(&desc, NULL, &currTexture);
   if (FAILED(hr))
      return false;
   if (currTexture == nullptr)
      return false;
 
   lImmediateContext->CopyResource(currTexture, lAcquiredDesktopImage.Get());
   D3D11_MAPPED_SUBRESOURCE* pRes = new D3D11_MAPPED_SUBRESOURCE;
   UINT subresource = D3D11CalcSubresource(0, 0, 0);
 
   lImmediateContext->Map(currTexture, subresource, D3D11_MAP_READ_WRITE, 0, pRes);
 
   void* d = pRes->pData;
   char* data = reinterpret_cast<char*>(d);
 
   int hWidth = desc.Width / 2;
   int hHeight = desc.Height / 2;
 
   for (UINT x = hWidth - lookSize; x < hWidth + lookSize; x++) {
      for (UINT y = hHeight - lookSize; y < hHeight + lookSize; y++) {
         int base = (x + y * desc.Width) * 4;
         byte red = data[base + 2];
         if (red >= Formatted_Color_Red - Shade_Variation && red <= Formatted_Color_Red + Shade_Variation) {
            byte green = data[base + 1];
            if (green >= Formatted_Color_Green - Shade_Variation && green <= Formatted_Color_Green + Shade_Variation) {
               byte blue = data[base];
               if (blue >= Formatted_Color_Blue - Shade_Variation && blue <= Formatted_Color_Blue + Shade_Variation) {
                  MouseDown();
                  currTexture->Release();
                  hr = lDeskDupl->ReleaseFrame();
                  return true;
               }
            }
         }
      }
   }
 
   currTexture->Release();
   hr = lDeskDupl->ReleaseFrame();
   return true;
}
 
void BadTriggerbotInit() { // USED TO GET MONITOR REZ
   MONITORINFO target;
   target.cbSize = sizeof(MONITORINFO);
 
   HMONITOR hMon = MonitorFromWindow(GetDesktopWindow(), MONITOR_DEFAULTTOPRIMARY);
   GetMonitorInfo(hMon, &target);
   x = target.rcMonitor.right / 2;
   y = target.rcMonitor.bottom / 2;
 
   HDC hdcScreen = ::GetDC(NULL);
 
   // THIS MUST BE USED IF WINDOWS SCALING IS NOT 100%
   int LogicalScreenHeight = GetDeviceCaps(hdcScreen, VERTRES);
   int PhysicalScreenHeight = GetDeviceCaps(hdcScreen, DESKTOPVERTRES);
   float ScreenScalingFactor = (float)PhysicalScreenHeight / (float)LogicalScreenHeight;
 
   ::ReleaseDC(NULL, hdcScreen);
 
   x *= ScreenScalingFactor;
   y *= ScreenScalingFactor;
}
 
void BadTriggerbot() {
   HDC _hdc = GetDC(NULL);
   if (_hdc)
   {
      COLORREF _color = GetPixel(_hdc, x, y); // EACH CALL WILL COST YOU 16ms (1/hz of Monitor)
      int r = GetRValue(_color);
      int g = GetGValue(_color);
      int b = GetBValue(_color);
 
      if ((r < Formatted_Color_Red + Shade_Variation) && (r > Formatted_Color_Red - Shade_Variation)) {
         if ((b < Formatted_Color_Blue + Shade_Variation) && (b > Formatted_Color_Blue - Shade_Variation)) {
            if ((g < Formatted_Color_Green + Shade_Variation) && (g > Formatted_Color_Green - Shade_Variation)) {
               MouseDown();
            }
         }
      }
   }
}
 
void GoodTriggerBot() {
   while (!CaptureNextFrame()) {}
}
 
int main()
{
   GoodTriggerbotInit();
   while (true)
   {
      // https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes
      // GetAsyncKeyState(VK_MENU) // WHEN HELD DOWN
      // GetKeyState(VK_MENU) // TOGGLE
      if (GetAsyncKeyState(VK_MENU)) {
         GoodTriggerBot();
      }
      else { // TO KEEP CPU UNDER 1%
         Sleep(1);
      }
   }
}

C#
Código:
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;
 
namespace FastTriggerbotCSharp
{
    class Program
    {
        [DllImport("user32.dll", SetLastError = true)]
        static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);
 
        [DllImport("user32.dll")]
        static extern short GetKeyState(ushort nVirtKey);
 
        [DllImport("user32.dll")]
        static extern ushort GetAsyncKeyState(ushort nVirtKey);
 
        [DllImport("gdi32.dll")]
        static extern int GetDeviceCaps(IntPtr hdc, int nIndex);
 
        const int lookSize = 5;
 
        const int Shade_Variation = 35;
        const int Formatted_Color_Red = 235;
        const int Formatted_Color_Green = 80;
        const int Formatted_Color_Blue = 235;
        static int monitor = 0;
 
        static int xSize;
        static int ySize;
 
        static void Main(string[] args)
        {
            Init();
            Console.WriteLine($"Starting at {xSize}x{ySize}");
            while (true) {
                // https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes
                // GetAsyncKeyState((ushort)VirtualKeys.Menu) != 0 // WHEN HELD DOWN
                // GetKeyState((ushort)VirtualKeys.Menu) == 1 // TOGGLE
                if (GetAsyncKeyState((ushort)VirtualKeys.Menu) != 0) {
                    GoodTriggerBot(new Rectangle(xSize / 2, ySize / 2, lookSize * 2, lookSize * 2), Color.FromArgb(Formatted_Color_Red, Formatted_Color_Green, Formatted_Color_Red), Shade_Variation);
                }
                else {
                    Thread.Sleep(1);
                }
            }
        }
 
        static void Init()
        {
            float zoom = GetScalingFactor();
            Screen current = CurrentScreen();
            bool prim = current.Primary;
            xSize = (int)(current.Bounds.Width * (prim ? zoom : 1));
            ySize = (int)(current.Bounds.Height * (prim ? zoom : 1));
        }
 
        static void MouseDown()
        {
            ToggleKey((byte)VirtualKeys.LeftButton, true);
            Thread.Sleep(1);
            ToggleKey((byte)VirtualKeys.LeftButton, false);
        }
 
        static void ToggleKey(byte key, bool set)
        {
            keybd_event(key,
              0x45,
          set ? (int)(dwFlags.KEYEVENTF_EXTENDEDKEY | 0) : (int)(dwFlags.KEYEVENTF_EXTENDEDKEY | dwFlags.KEYEVENTF_KEYUP),
              0);
        }
 
        public static void GoodTriggerBot(Rectangle rect, Color Pixel_Color, int Shade_Variation)
        {
            Bitmap RegionIn_Bitmap = new Bitmap(rect.Width, rect.Height, PixelFormat.Format24bppRgb);
 
            if (monitor >= Screen.AllScreens.Length) {
                monitor = 0;
            }
 
            int xOffset = Screen.AllScreens[monitor].Bounds.Left;
            int yOffset = Screen.AllScreens[monitor].Bounds.Top;
 
            using (Graphics GFX = Graphics.FromImage(RegionIn_Bitmap)) {
                GFX.CopyFromScreen(rect.X + xOffset, rect.Y + yOffset, 0, 0, rect.Size, CopyPixelOperation.SourceCopy);
            }
            BitmapData RegionIn_BitmapData = RegionIn_Bitmap.LockBits(new Rectangle(0, 0, RegionIn_Bitmap.Width, RegionIn_Bitmap.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
            int[] Formatted_Color = new int[3] { Pixel_Color.B, Pixel_Color.G, Pixel_Color.R }; //bgr
            unsafe {
                for (int y = 0; y < RegionIn_BitmapData.Height; y++) {
                    byte* row = (byte*)RegionIn_BitmapData.Scan0 + (y * RegionIn_BitmapData.Stride);
                    for (int x = 0; x < RegionIn_BitmapData.Width; x++) {
                        if (row[x * 3] >= (Formatted_Color[0] - Shade_Variation) & row[x * 3] <= (Formatted_Color[0] + Shade_Variation)) //blue
                            if (row[(x * 3) + 1] >= (Formatted_Color[1] - Shade_Variation) & row[(x * 3) + 1] <= (Formatted_Color[1] + Shade_Variation)) //green
                                if (row[(x * 3) + 2] >= (Formatted_Color[2] - Shade_Variation) & row[(x * 3) + 2] <= (Formatted_Color[2] + Shade_Variation)) { //red
                                    MouseDown();
                                    return;
                                }
                    }
                }
            }
        }
 
        static public Screen CurrentScreen()
        {
            return Screen.AllScreens[monitor];
        }
 
        static float GetScalingFactor()
        {
            Graphics g = Graphics.FromHwnd(IntPtr.Zero);
            IntPtr desktop = g.GetHdc();
            int LogicalScreenHeight = GetDeviceCaps(desktop, (int)DeviceCap.VERTRES);
            int PhysicalScreenHeight = GetDeviceCaps(desktop, (int)DeviceCap.DESKTOPVERTRES);
 
            float ScreenScalingFactor = (float)PhysicalScreenHeight / (float)LogicalScreenHeight;
 
            return ScreenScalingFactor; // 1.25 = 125%
        }
 
        // http://pinvoke.net/default.aspx/gdi32/GetDeviceCaps.html
        public enum DeviceCap
        {
            VERTRES = 10,
            DESKTOPVERTRES = 117,
        }
 
        [Flags]
        public enum dwFlags
        {
            KEYEVENTF_EXTENDEDKEY = 0x0001,
            KEYEVENTF_KEYUP = 0x0002,
            KEYEVENTF_UNICODE = 0x0004,
            KEYEVENTF_SCANCODE = 0x0008,
        }
 
        /// <summary>
        /// Enumeration for virtual keys.
        /// </summary>
        public enum VirtualKeys
            : ushort
        {
            LeftButton = 0x01,
            RightButton = 0x02,
            Cancel = 0x03,
            MiddleButton = 0x04,
            ExtraButton1 = 0x05,
            ExtraButton2 = 0x06,
            Back = 0x08,
            Tab = 0x09,
            Clear = 0x0C,
            Return = 0x0D,
            Shift = 0x10,
            Control = 0x11,
            Menu = 0x12,
            Pause = 0x13,
            CapsLock = 0x14,
            Kana = 0x15,
            Hangeul = 0x15,
            Hangul = 0x15,
            Junja = 0x17,
            Final = 0x18,
            Hanja = 0x19,
            Kanji = 0x19,
            Escape = 0x1B,
            Convert = 0x1C,
            NonConvert = 0x1D,
            Accept = 0x1E,
            ModeChange = 0x1F,
            Space = 0x20,
            Prior = 0x21,
            Next = 0x22,
            End = 0x23,
            Home = 0x24,
            Left = 0x25,
            Up = 0x26,
            Right = 0x27,
            Down = 0x28,
            Select = 0x29,
            Print = 0x2A,
            Execute = 0x2B,
            Snapshot = 0x2C,
            Insert = 0x2D,
            Delete = 0x2E,
            Help = 0x2F,
            N0 = 0x30,
            N1 = 0x31,
            N2 = 0x32,
            N3 = 0x33,
            N4 = 0x34,
            N5 = 0x35,
            N6 = 0x36,
            N7 = 0x37,
            N8 = 0x38,
            N9 = 0x39,
            A = 0x41,
            B = 0x42,
            C = 0x43,
            D = 0x44,
            E = 0x45,
            F = 0x46,
            G = 0x47,
            H = 0x48,
            I = 0x49,
            J = 0x4A,
            K = 0x4B,
            L = 0x4C,
            M = 0x4D,
            N = 0x4E,
            O = 0x4F,
            P = 0x50,
            Q = 0x51,
            R = 0x52,
            S = 0x53,
            T = 0x54,
            U = 0x55,
            V = 0x56,
            W = 0x57,
            X = 0x58,
            Y = 0x59,
            Z = 0x5A,
            LeftWindows = 0x5B,
            RightWindows = 0x5C,
            Application = 0x5D,
            Sleep = 0x5F,
            Numpad0 = 0x60,
            Numpad1 = 0x61,
            Numpad2 = 0x62,
            Numpad3 = 0x63,
            Numpad4 = 0x64,
            Numpad5 = 0x65,
            Numpad6 = 0x66,
            Numpad7 = 0x67,
            Numpad8 = 0x68,
            Numpad9 = 0x69,
            Multiply = 0x6A,
            Add = 0x6B,
            Separator = 0x6C,
            Subtract = 0x6D,
            Decimal = 0x6E,
            Divide = 0x6F,
            F1 = 0x70,
            F2 = 0x71,
            F3 = 0x72,
            F4 = 0x73,
            F5 = 0x74,
            F6 = 0x75,
            F7 = 0x76,
            F8 = 0x77,
            F9 = 0x78,
            F10 = 0x79,
            F11 = 0x7A,
            F12 = 0x7B,
            F13 = 0x7C,
            F14 = 0x7D,
            F15 = 0x7E,
            F16 = 0x7F,
            F17 = 0x80,
            F18 = 0x81,
            F19 = 0x82,
            F20 = 0x83,
            F21 = 0x84,
            F22 = 0x85,
            F23 = 0x86,
            F24 = 0x87,
            NumLock = 0x90,
            ScrollLock = 0x91,
            NEC_Equal = 0x92,
            Fujitsu_Jisho = 0x92,
            Fujitsu_Masshou = 0x93,
            Fujitsu_Touroku = 0x94,
            Fujitsu_Loya = 0x95,
            Fujitsu_Roya = 0x96,
            LeftShift = 0xA0,
            RightShift = 0xA1,
            LeftControl = 0xA2,
            RightControl = 0xA3,
            LeftMenu = 0xA4,
            RightMenu = 0xA5,
            BrowserBack = 0xA6,
            BrowserForward = 0xA7,
            BrowserRefresh = 0xA8,
            BrowserStop = 0xA9,
            BrowserSearch = 0xAA,
            BrowserFavorites = 0xAB,
            BrowserHome = 0xAC,
            VolumeMute = 0xAD,
            VolumeDown = 0xAE,
            VolumeUp = 0xAF,
            MediaNextTrack = 0xB0,
            MediaPrevTrack = 0xB1,
            MediaStop = 0xB2,
            MediaPlayPause = 0xB3,
            LaunchMail = 0xB4,
            LaunchMediaSelect = 0xB5,
            LaunchApplication1 = 0xB6,
            LaunchApplication2 = 0xB7,
            OEM1 = 0xBA,
            OEMPlus = 0xBB,
            OEMComma = 0xBC,
            OEMMinus = 0xBD,
            OEMPeriod = 0xBE,
            OEM2 = 0xBF,
            OEM3 = 0xC0,
            OEM4 = 0xDB,
            OEM5 = 0xDC,
            OEM6 = 0xDD,
            OEM7 = 0xDE,
            OEM8 = 0xDF,
            OEMAX = 0xE1,
            OEM102 = 0xE2,
            ICOHelp = 0xE3,
            ICO00 = 0xE4,
            ProcessKey = 0xE5,
            ICOClear = 0xE6,
            Packet = 0xE7,
            OEMReset = 0xE9,
            OEMJump = 0xEA,
            OEMPA1 = 0xEB,
            OEMPA2 = 0xEC,
            OEMPA3 = 0xED,
            OEMWSCtrl = 0xEE,
            OEMCUSel = 0xEF,
            OEMATTN = 0xF0,
            OEMFinish = 0xF1,
            OEMCopy = 0xF2,
            OEMAuto = 0xF3,
            OEMENLW = 0xF4,
            OEMBackTab = 0xF5,
            ATTN = 0xF6,
            CRSel = 0xF7,
            EXSel = 0xF8,
            EREOF = 0xF9,
            Play = 0xFA,
            Zoom = 0xFB,
            Noname = 0xFC,
            PA1 = 0xFD,
            OEMClear = 0xFE
        }
    }
}

Crédit: bluefire1337(UK)
uNreal
uNreal
ADM
ADM


Ir para o topo Ir para baixo

Ir para o topo

- Tópicos semelhantes

 
Permissões neste sub-fórum
Não podes responder a tópicos