SDL2

gfx draw variable

Jul 20th, 2020
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 13.93 KB | None | 0 0
  1. h@h init
  2. using System;
  3. using System.Text;
  4. using GameOverlay.Drawing;
  5. using GameOverlay.Windows;
  6. using SharpDX;
  7. using Point = GameOverlay.Drawing.Point;
  8. using Color = GameOverlay.Drawing.Color;
  9. using Rectangle = GameOverlay.Drawing.Rectangle;
  10. using RawVector2 = SharpDX.Mathematics.Interop.RawVector2;
  11. using ShpVector3 = SharpDX.Vector3;
  12. using ShpVector2 = SharpDX.Vector2;
  13. using System.Windows.Forms;
  14.  
  15. namespace PUBGMESP
  16. {
  17.     public interface IAimbotForm
  18.     {
  19.         void Initialize();
  20.         void Update();
  21.     }
  22.     public class AimTarget
  23.     {
  24.         public ShpVector2 Screen2D;
  25.         public float CrosshairDistance;
  26.         public int uniqueID;
  27.     }
  28.     public class AimbotForm : IAimbotForm
  29.     {
  30.         public readonly OverlayWindow _window;
  31.         private readonly Graphics _graphics;
  32.         private readonly GameMemSearch _ueSearch;
  33.  
  34.         private Font _font;
  35.         private Font _infoFont;
  36.         private Font _bigfont;
  37.         private SolidBrush _black;
  38.         private SolidBrush _red;
  39.         private SolidBrush _green;
  40.         private SolidBrush _blue;
  41.         private SolidBrush _orange;
  42.         private SolidBrush _purple;
  43.         private SolidBrush _yellow;
  44.         private SolidBrush _white;
  45.         private SolidBrush _transparent;
  46.         private SolidBrush _txtBrush;
  47.         private SolidBrush[] _randomBrush;
  48.         private SolidBrush _boxBrush;
  49.         private  int BestTargetUniqID = -1;
  50.  
  51.         private DisplayData _data;
  52.         private int playerCount;
  53.  
  54.         // offset
  55.         private int actorOffset, boneOffset, tmpOffset;
  56.  
  57.  
  58.         public AimbotForm(RECT rect, GameMemSearch ueSearch)
  59.         {
  60.             this._ueSearch = ueSearch;
  61.  
  62.             _window = new OverlayWindow(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top)
  63.             {
  64.                 IsTopmost = true,
  65.                 IsVisible = true
  66.             };
  67.  
  68.             _window.SizeChanged += _window_SizeChanged;
  69.  
  70.             _graphics = new Graphics
  71.             {
  72.                 MeasureFPS = true,
  73.                 Height = _window.Height,
  74.                 PerPrimitiveAntiAliasing = true,
  75.                 TextAntiAliasing = true,
  76.                 UseMultiThreadedFactories = false,
  77.                 VSync = true,
  78.                 Width = _window.Width,
  79.                 WindowHandle = IntPtr.Zero
  80.             };
  81.  
  82.             // offset
  83.             actorOffset = 320;
  84.             boneOffset = 1408;
  85.             tmpOffset = 776;
  86.         }
  87.  
  88.         ~AimbotForm()
  89.         {
  90.             _graphics.Dispose();
  91.             _window.Dispose();
  92.         }
  93.  
  94.         public void Initialize()
  95.         {
  96.             _window.CreateWindow();
  97.  
  98.             _graphics.WindowHandle = _window.Handle;
  99.             _graphics.Setup();
  100.  
  101.             _font = _graphics.CreateFont("Microsoft YaHei", 10);
  102.             _infoFont = _graphics.CreateFont("Microsoft YaHei", 12);
  103.             _bigfont = _graphics.CreateFont("Microsoft YaHei", 18, true);
  104.  
  105.             _black = _graphics.CreateSolidBrush(0, 0, 0);
  106.             _red = _graphics.CreateSolidBrush(255, 99, 71);
  107.             _green = _graphics.CreateSolidBrush(Color.Green);
  108.             _blue = _graphics.CreateSolidBrush(135, 206, 250);
  109.             _orange = _graphics.CreateSolidBrush(255, 97, 0);
  110.             _purple = _graphics.CreateSolidBrush(255, 105, 180);
  111.             _yellow = _graphics.CreateSolidBrush(255, 255, 0);
  112.             _white = _graphics.CreateSolidBrush(255, 255, 255);
  113.             _transparent = _graphics.CreateSolidBrush(0, 0, 0, 0);
  114.             _randomBrush = new SolidBrush[]
  115.             {
  116.                 _orange,_red,_green,_blue,_yellow,_white,_purple
  117.             };
  118.             _txtBrush = _graphics.CreateSolidBrush(0, 0, 0, 0.5f);
  119.         }
  120.  
  121.         public void UpdateData(DisplayData data)
  122.         {
  123.             _data = data;
  124.         }
  125.  
  126.         public void Update()
  127.         {
  128.             var gfx = _graphics;
  129.             gfx.BeginScene();
  130.             gfx.ClearScene(_transparent);
  131.  
  132.             if (Settings.ShowMenu)
  133.             {
  134.  
  135.                 DrawShadowText(gfx, _font, _green, new Point(20f, _window.Height / 2 + 115), "Aimbot Menu");
  136.                 if (Settings.aimEnabled)
  137.                 {
  138.                     DrawShadowText(gfx, _font, _red, new Point(20f, _window.Height / 2 + 130), "Aimbot ON    (F5) :  " + Settings.aimEnabled.ToString());
  139.                 }
  140.                 else
  141.                 {
  142.                     DrawShadowText(gfx, _font, _green, new Point(20f, _window.Height / 2 + 130), "Aimbot OF    (F5) :  " + Settings.aimEnabled.ToString());
  143.                 }
  144.                 if (Settings.bDrawFow)
  145.                 {
  146.                     DrawShadowText(gfx, _font, _red, new Point(20f, _window.Height / 2 + 145), "FOV SHOW    (F6) :  " + Settings.bDrawFow.ToString());
  147.                 }
  148.                 else
  149.                 {
  150.                     DrawShadowText(gfx, _font, _green, new Point(20f, _window.Height / 2 + 145), "FOV HIDE    (F6) :  " + Settings.bDrawFow.ToString());
  151.                 }
  152.  
  153.                 DrawShadowText(gfx, _font, _green, new Point(20f, _window.Height / 2 + 160), "┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈");
  154.             }
  155.  
  156.             // Read View Matrix
  157.             long viewMatrixAddr = Mem.ReadMemory<int>(Mem.ReadMemory<int>(_data.ViewMatrixBase) + 32) + 512;
  158.             D3DMatrix viewMatrix = Algorithms.ReadViewMatrix(viewMatrixAddr);
  159.  
  160.             var AimTargets = new AimTarget[_data.Players.Length];
  161.             float fClosestDist = -1;
  162.             // Draw Player ESP
  163.             if (Settings.PlayerESP)
  164.             {
  165.                 for (int i = 0; i < _data.Players.Length; i++)
  166.                 {
  167.  
  168.                     var player = _data.Players[i];
  169.                     //if (player.Health <= 0) continue;
  170.                     if (Algorithms.WorldToScreenPlayer(viewMatrix, player.Position, out ShpVector3 playerScreen, out int distance, _window.Width, _window.Height))
  171.                     {
  172.                         // Too Far not render
  173.                         if (distance > 500) continue;
  174.                         float x = playerScreen.X;
  175.                         float y = playerScreen.Y;
  176.                         float h = playerScreen.Z;
  177.                         float w = playerScreen.Z / 2;
  178.  
  179.                         try
  180.                         {
  181.                             _boxBrush = _randomBrush[player.TeamID % 7];
  182.                         }
  183.                         catch (IndexOutOfRangeException)
  184.                         {
  185.                             _boxBrush = _green;
  186.                         }
  187.                         //DrawShadowText(gfx,_font, _green, new Point((x - playerScreen.Z / 4) - 3, y - 15), player.Pose.ToString());
  188.  
  189.                         // Adjust Box
  190.                         if (player.Pose == 1114636288)
  191.                         {
  192.                             y = playerScreen.Y + playerScreen.Z / 5;
  193.                             h -= playerScreen.Z / 5;
  194.                         }
  195.                         if (player.Pose == 1112014848 || player.Status == 7)
  196.                         {
  197.                             y = playerScreen.Y + playerScreen.Z / 4;
  198.                             h -= playerScreen.Z / 4;
  199.                         }
  200.  
  201.                         int ScreenCenterX = _window.Width / 2, ScreenCenterY = _window.Height / 2;
  202.  
  203.                         if (Settings.aimEnabled)
  204.                         {
  205.                             long tmpAddv = Mem.ReadMemory<int>(player.Address + tmpOffset);
  206.                             long bodyAddv = tmpAddv + actorOffset;
  207.                             long boneAddv = Mem.ReadMemory<int>(tmpAddv + boneOffset) + 48;
  208.                             ShpVector3 headPos = Algorithms.GetBoneWorldPosition(bodyAddv, boneAddv + 5 * 48);
  209.  
  210.                             headPos.Z += 7;
  211.  
  212.                             var clampPos = headPos - player.Position;
  213.                             bool w2sHead = Algorithms.WorldToScreen3DBox(viewMatrix, new ShpVector3(headPos.X, headPos.Y - (Settings.bPredict * 2), headPos.Z - (Settings.bYAxis * 8)), out ShpVector2 HeadPosition, _window.Width, _window.Height);
  214.  
  215.                             AimTargets[i] = new AimTarget();
  216.                             AimTargets[i].Screen2D = HeadPosition;
  217.                             AimTargets[i].uniqueID = player.TeamID;
  218.                             AimTargets[i].CrosshairDistance = ShpVector2.Distance(HeadPosition, new ShpVector2(ScreenCenterX, ScreenCenterY));
  219.  
  220.                             if (BestTargetUniqID == -1)
  221.                             {
  222.                                 if (Algorithms.isInside(ScreenCenterX, ScreenCenterY, Settings.bFovArray[Settings.bFovInt], AimTargets[i].Screen2D.X, AimTargets[i].Screen2D.Y))
  223.                                 {
  224.                                     fClosestDist = AimTargets[i].CrosshairDistance;
  225.                                     BestTargetUniqID = AimTargets[i].uniqueID;
  226.                                 }
  227.                             }
  228.                             if (MainForm.GetAsyncKeyState(Settings.bAimKeys[Settings.bAimKeyINT]))
  229.                             {
  230.                                 if (BestTargetUniqID != -1)
  231.                                 {
  232.                                     var best = FindAimTargetByUniqueID(AimTargets, BestTargetUniqID);
  233.  
  234.                                     if (best != null)
  235.                                     {
  236.                                         {
  237.                                             var roundPos = new ShpVector2((float)Math.Round(best.Screen2D.X), (float)Math.Round(best.Screen2D.Y));
  238.                                             AimAtPosV2(roundPos.X, roundPos.Y, _window.Width, _window.Height, false);
  239.  
  240.                                         }
  241.                                     }
  242.                                 }
  243.                             }
  244.                             else
  245.                             {
  246.                                 BestTargetUniqID = -1;
  247.                             }
  248.                         }
  249.                         if (Settings.bDrawFow)
  250.                         {
  251.                             gfx.DrawCircle(_red, ScreenCenterX, ScreenCenterY, Settings.bFovArray[Settings.bFovInt], 2);
  252.                         }
  253.                     }
  254.                 }
  255.  
  256.                 gfx.EndScene();
  257.             }
  258.         }
  259.  
  260.         private static AimTarget FindAimTargetByUniqueID(AimTarget[] array, int uniqueID)
  261.         {
  262.             var entityList = array;
  263.             for (int i = 0; i < entityList.Length; i++)
  264.             {
  265.                 var current = entityList[i];
  266.                 if (current == null)
  267.                     continue;
  268.  
  269.                 if (current.uniqueID == uniqueID)
  270.                     return current;
  271.             }
  272.             return null;
  273.         }
  274.         //uc port
  275.         private  void AimAtPosV2(float x, float y, int Width, int Height , bool smooth)
  276.         {
  277.             int ScreenCenterX = Width / 2, ScreenCenterY = Height / 2;
  278.  
  279.             float AimSpeed = (float)Settings.bSmooth + 1f;;
  280.             float TargetX = 0;
  281.             float TargetY = 0;
  282.  
  283.             //X Axis
  284.             if (x != 0)
  285.             {
  286.                 if (x > ScreenCenterX)
  287.                 {
  288.                     TargetX = -(ScreenCenterX - x);
  289.                     TargetX /= AimSpeed;
  290.                     if (TargetX + ScreenCenterX > ScreenCenterX * 2) TargetX = 0;
  291.                 }
  292.  
  293.                 if (x < ScreenCenterX)
  294.                 {
  295.                     TargetX = x - ScreenCenterX;
  296.                     TargetX /= AimSpeed;
  297.                     if (TargetX + ScreenCenterX < 0) TargetX = 0;
  298.                 }
  299.             }
  300.  
  301.             //Y Axis
  302.  
  303.             if (y != 0)
  304.             {
  305.                 if (y > ScreenCenterY)
  306.                 {
  307.                     TargetY = -(ScreenCenterY - y);
  308.                     TargetY /= AimSpeed;
  309.                     if (TargetY + ScreenCenterY > ScreenCenterY * 2) TargetY = 0;
  310.                 }
  311.  
  312.                 if (y < ScreenCenterY)
  313.                 {
  314.                     TargetY = y - ScreenCenterY;
  315.                     TargetY /= AimSpeed;
  316.                     if (TargetY + ScreenCenterY < 0) TargetY = 0;
  317.                 }
  318.             }
  319.  
  320.             if (!smooth)
  321.             {
  322.                 MainForm.mouse_event(1, (int)TargetX, (int)(TargetY), 0, UIntPtr.Zero);
  323.                 return;
  324.             }
  325.  
  326.             TargetX /= 10;
  327.             TargetY /= 10;
  328.  
  329.             if (Math.Abs(TargetX) < 1)
  330.             {
  331.                 if (TargetX > 0)
  332.                 {
  333.                     TargetX = 1;
  334.                 }
  335.                 if (TargetX < 0)
  336.                 {
  337.                     TargetX = -1;
  338.                 }
  339.             }
  340.             if (Math.Abs(TargetY) < 1)
  341.             {
  342.                 if (TargetY > 0)
  343.                 {
  344.                     TargetY = 1;
  345.                 }
  346.                 if (TargetY < 0)
  347.                 {
  348.                     TargetY = -1;
  349.                 }
  350.             }
  351.             MainForm.mouse_event(1, (int)TargetX, (int)(TargetY), 0, UIntPtr.Zero);
  352.         }
  353.  
  354.         private void _window_SizeChanged(object sender, OverlaySizeEventArgs e)
  355.         {
  356.             if (_graphics == null) return;
  357.  
  358.             if (_graphics.IsInitialized)
  359.             {
  360.                 _graphics.Resize(e.Width, e.Height);
  361.             }
  362.             else
  363.             {
  364.                 _graphics.Width = e.Width;
  365.                 _graphics.Height = e.Height;
  366.             }
  367.         }
  368.  
  369.         private void DrawShadowText(Graphics gfx, Font font, IBrush brush, Point pt, string txt)
  370.         {
  371.             var bpPt = new Point(pt.X - 1, pt.Y + 1);
  372.             //var bpPt2 = new Point(pt.X + 1, pt.Y - 1);
  373.             gfx.DrawText(font, _txtBrush, bpPt, txt);
  374.             //gfx.DrawText(font, _txtBrush, bpPt2, txt);
  375.             gfx.DrawText(font, brush, pt, txt);
  376.  
  377.         }
  378.         private void DrawShadowText(Graphics gfx, Font font, float fontSize, IBrush brush, Point pt, string txt)
  379.         {
  380.             var bpPt = new Point();
  381.             bpPt.X = pt.X - 1;
  382.             bpPt.Y = pt.Y + 1;
  383.             gfx.DrawText(font, fontSize, _txtBrush, bpPt, txt);
  384.             gfx.DrawText(font, fontSize, brush, pt, txt);
  385.         }
  386.     }
  387.  
  388. }
Add Comment
Please, Sign In to add comment