EzPlugins

AlwaysUseYourParagon

Mar 20th, 2025 (edited)
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 11.08 KB | None | 0 0
  1. using Turbo.Plugins.Default;
  2. using System;
  3. using System.Linq;
  4. using System.Windows.Forms;
  5. using SharpDX.DirectInput;
  6. using System.Runtime.InteropServices;
  7.  
  8. namespace Turbo.Plugins.Ez
  9. {
  10.     public class AlwaysUseYourParagon : BasePlugin, IAfterCollectHandler, INewAreaHandler, IInGameTopPainter
  11.     {
  12.         public static IntPtr D3Hwnd = IntPtr.Zero;
  13.  
  14.         [DllImport("USER32.DLL")]
  15.         private static extern IntPtr FindWindow(string ClassName, string WindowText);
  16.  
  17.         [DllImport("USER32.DLL")]
  18.         private static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
  19.  
  20.         public static void SendPressKey(Keys key)
  21.         {
  22.             SendMessage(D3Hwnd, 256U, (IntPtr)((int)key), IntPtr.Zero);
  23.             SendMessage(D3Hwnd, 257U, (IntPtr)((int)key), IntPtr.Zero);
  24.         }
  25.  
  26.         public static void SendHoldKey(Keys key)
  27.         {
  28.             SendMessage(D3Hwnd, 256U, (IntPtr)((int)key), IntPtr.Zero);
  29.         }
  30.  
  31.         public static void SendReleaseKey(Keys key)
  32.         {
  33.             SendMessage(D3Hwnd, 257U, (IntPtr)((int)key), IntPtr.Zero);
  34.         }
  35.  
  36.         public void mouseLClickUiE(IUiElement uie)  // D3Hwnd
  37.         {
  38.             var x = (int) (uie.Rectangle.X + uie.Rectangle.Width/2.0f);
  39.             var y = (int) (uie.Rectangle.Y + uie.Rectangle.Height/2.0f);
  40.             IntPtr lParam = (IntPtr)(y << 16 | (x & 65535));
  41.             SendMessage(D3Hwnd, 513U, (IntPtr)1, lParam);
  42.             SendMessage(D3Hwnd, 514U, (IntPtr)1, lParam);
  43.         }
  44.  
  45.         protected IUiElement PARAGONUI;
  46.         protected IUiElement PARAGON_TAB_ONE;
  47.         protected IUiElement PARAGON_BUTTON_MAIN;
  48.         protected IUiElement PARAGON_BUTTON_VIT;
  49.         protected IUiElement PARAGON_BUTTON_SPEED;
  50.         protected IUiElement PARAGON_BUTTON_ACCEPT;
  51.         protected IUiElement PARAGON_BUTTON_CANCEL;
  52.         protected IUiElement PARAGON_BUTTON_OPEN;
  53.         protected IUiElement GreaterRifts_VictoryScreen;
  54.         protected IUiElement Rift_Join_Party;
  55.  
  56.         private System.Drawing.RectangleF rectangleMain { get; set; }
  57.         private System.Drawing.RectangleF rectangleVit { get; set; }
  58.         public IFont FontGreen { get; set; }
  59.         public IBrush BrushAll { get; set; }
  60.  
  61.         private bool DetectParagonButton { get; set; } = false;
  62.         private bool doParagon { get; set; } = false;
  63.         private long msLapseAction { get; set; } = 0;
  64.         private uint LastAreaSno { get; set; } = 0;
  65.  
  66.         public long msLapseMin { get; set; } = 20;
  67.         public long msLapseUiEVisible { get; set; } = 200;
  68.         public bool MaxSpeed { get; set; }
  69.         public int ParagonMin { get; set; }
  70.         public bool AlsoInNewGame { get; set; }
  71.         public bool SupportVit { get; set; }
  72.  
  73.         public Keys KeyParagonWindow { get; set; } = Keys.P; // ParagonWindow
  74.  
  75.         public AlwaysUseYourParagon()
  76.         {
  77.             Enabled = true;
  78.         }
  79.  
  80.         public override void Load(IController hud)
  81.         {
  82.             base.Load(hud);
  83.             Order = int.MaxValue;
  84.  
  85.             ParagonMin = 800;       // Minimum Paragon required for this plugin to start working.
  86.             SupportVit = true;      // Increases Vit instead of the Main Stat if you have toxin or icebLink equipped.
  87.             MaxSpeed = true;        // Increase movement speed first
  88.             AlsoInNewGame = true;   // Work also when you enter a new game.
  89.  
  90.             PARAGONUI = Hud.Render.RegisterUiElement("Root.NormalLayer.Paragon_main.LayoutRoot.ParagonPointSelect", null, null, 0f, 0f);
  91.             PARAGON_TAB_ONE = Hud.Render.RegisterUiElement("Root.NormalLayer.Paragon_main.LayoutRoot.ParagonPointSelect.tab_1", null, null, 0f, 0f);
  92.             PARAGON_BUTTON_MAIN = Hud.Render.RegisterUiElement("Root.NormalLayer.Paragon_main.LayoutRoot.ParagonPointSelect.Bonuses.bonus0.IncreaseStat", null, null, 0f, 0f);
  93.             PARAGON_BUTTON_VIT = Hud.Render.RegisterUiElement("Root.NormalLayer.Paragon_main.LayoutRoot.ParagonPointSelect.Bonuses.bonus1.IncreaseStat", null, null, 0f, 0f);
  94.             PARAGON_BUTTON_SPEED = Hud.Render.RegisterUiElement("Root.NormalLayer.Paragon_main.LayoutRoot.ParagonPointSelect.Bonuses.bonus2.IncreaseStat", null, null, 0f, 0f);
  95.             PARAGON_BUTTON_ACCEPT = Hud.Render.RegisterUiElement("Root.NormalLayer.Paragon_main.LayoutRoot.ParagonPointSelect.AcceptParagonPointsButton", null, null, 0f, 0f);
  96.             PARAGON_BUTTON_CANCEL = Hud.Render.RegisterUiElement("Root.NormalLayer.Paragon_main.LayoutRoot.ParagonPointSelect.CancelParagonPointsButton", null, null, 0f, 0f);
  97.             PARAGON_BUTTON_OPEN = Hud.Render.RegisterUiElement("Root.NormalLayer.game_notify_dialog_backgroundScreen.dlg_new_paragon.button", null, null);
  98.             GreaterRifts_VictoryScreen = Hud.Render.RegisterUiElement("Root.NormalLayer.GreaterRifts_VictoryScreen.LayoutRoot", null, null);
  99.             Rift_Join_Party = Hud.Render.RegisterUiElement("Root.NormalLayer.rift_join_party_main.LayoutRoot", null, null);
  100.  
  101.             BrushAll = Hud.Render.CreateBrush(255, 100, 255, 100, 2);
  102.             FontGreen = Hud.Render.CreateFont("tahoma", 10f, 250, 0, 250, 0, false, false, 250, 0, 0, 0, true);
  103.  
  104.             D3Hwnd = FindWindow("D3 Main Window Class", null); // D3Hwnd = FindWindow(null, "Diablo III");
  105.         }
  106.  
  107.         public void OnNewArea(bool newGame, ISnoArea area) // bug ??
  108.         {
  109.             if (LastAreaSno != area.Sno) LastAreaSno = area.Sno; else if (!newGame) return; // Fix ??
  110.  
  111.             if (area.IsTown)
  112.             {
  113.                 if (Hud.Game.Me.ParagonPointsAvailable[0] > 0 && Hud.Game.Me.CurrentLevelParagon >= ParagonMin)
  114.                 {
  115.                     msLapseAction = Hud.Game.CurrentRealTimeMilliseconds + msLapseMin;
  116.                     if (newGame)
  117.                     {
  118.                         if (AlsoInNewGame)
  119.                         {
  120.                             doParagon = true;
  121.                             if (Hud.Game.CurrentAct != 1)
  122.                             {
  123.                                 var pl = Hud.AllPlugins.FirstOrDefault(p => p.GetType().Name == "AlwaysActOne");    // So that it doesn't interfere too much with AlwaysActOne
  124.                                 if (pl != null && pl.Enabled == true)
  125.                                 {
  126.                                     msLapseAction += 10000;
  127.                                 }
  128.                             }
  129.                         }
  130.                     }
  131.                     else
  132.                     {
  133.                         doParagon = true;
  134.                     }
  135.                 }
  136.                 DetectParagonButton = !PARAGON_BUTTON_OPEN.Visible;
  137.             }
  138.         }
  139.  
  140.         public void PaintTopInGame(ClipState clipState)
  141.         {
  142.             if (clipState != ClipState.AfterClip || !Hud.Game.IsInGame || doParagon) return;
  143.             if (PARAGON_TAB_ONE.Visible && PARAGON_TAB_ONE.AnimState == 13 && PARAGON_BUTTON_MAIN.Visible)
  144.             {
  145.                 var layout = FontGreen.GetTextLayout("All");
  146.  
  147.                 rectangleMain = new System.Drawing.RectangleF(PARAGON_BUTTON_MAIN.Rectangle.X + PARAGON_BUTTON_MAIN.Rectangle.Width * 2, PARAGON_BUTTON_MAIN.Rectangle.Y, PARAGON_BUTTON_MAIN.Rectangle.Width, PARAGON_BUTTON_MAIN.Rectangle.Height);
  148.                 BrushAll.DrawRectangle(rectangleMain.X, rectangleMain.Y, rectangleMain.Width, rectangleMain.Height);
  149.                 FontGreen.DrawText(layout, rectangleMain.X + (rectangleMain.Width - layout.Metrics.Width)/2.0f, rectangleMain.Y + (rectangleMain.Height - layout.Metrics.Height)/2.0f);
  150.  
  151.                 rectangleVit = new System.Drawing.RectangleF(PARAGON_BUTTON_VIT.Rectangle.X + PARAGON_BUTTON_VIT.Rectangle.Width * 2, PARAGON_BUTTON_VIT.Rectangle.Y, PARAGON_BUTTON_VIT.Rectangle.Width, PARAGON_BUTTON_VIT.Rectangle.Height);
  152.                 BrushAll.DrawRectangle(rectangleVit.X, rectangleVit.Y, rectangleVit.Width, rectangleVit.Height);
  153.                 FontGreen.DrawText(layout, rectangleVit.X + (rectangleVit.Width - layout.Metrics.Width)/2.0f, rectangleVit.Y + (rectangleVit.Height - layout.Metrics.Height)/2.0f);
  154.  
  155.                 if (Hud.Input.IsKeyDown(Keys.LButton))
  156.                 {
  157.                     var UiEStat = rectangleMain.Contains(Hud.Window.CursorX, Hud.Window.CursorY)? PARAGON_BUTTON_MAIN : rectangleVit.Contains(Hud.Window.CursorX, Hud.Window.CursorY)? PARAGON_BUTTON_VIT : null;
  158.                     if (UiEStat != null)
  159.                     {
  160.                         int i = Hud.Game.Me.ParagonPointsAvailable[0]/100 + 2;
  161.                         SendHoldKey(Keys.ControlKey);
  162.                         while (i-- > 0)
  163.                         {
  164.                             mouseLClickUiE(UiEStat);
  165.                         }
  166.                         SendReleaseKey(Keys.ControlKey);
  167.                     }
  168.                 }
  169.             }
  170.         }
  171.  
  172.         public void AfterCollect()
  173.         {
  174.             if (!Hud.Game.IsInGame || Hud.Game.IsPaused) return;
  175.             if (doParagon)
  176.             {
  177.                 if (Hud.Inventory.InventoryMainUiElement.Visible || GreaterRifts_VictoryScreen.Visible || Rift_Join_Party.Visible)
  178.                 {
  179.                     msLapseAction = Hud.Game.CurrentRealTimeMilliseconds + msLapseUiEVisible;
  180.                 }
  181.                 else if (Hud.Game.CurrentRealTimeMilliseconds > msLapseAction)
  182.                 {
  183.                     msLapseAction = Hud.Game.CurrentRealTimeMilliseconds + msLapseMin;
  184.                     if (PARAGON_TAB_ONE.Visible) // PARAGONUI.Visible && PARAGON_TAB_ONE.Visible
  185.                     {
  186.                         DetectParagonButton = true;
  187.                         if (PARAGON_TAB_ONE.AnimState != 13)
  188.                         {
  189.                             mouseLClickUiE(PARAGON_TAB_ONE);
  190.                         }
  191.                         else
  192.                         {
  193.                             if (MaxSpeed && PARAGON_BUTTON_SPEED.Visible)
  194.                             {
  195.                                 SendHoldKey(Keys.ControlKey);
  196.                                 mouseLClickUiE(PARAGON_BUTTON_SPEED);
  197.                                 SendReleaseKey(Keys.ControlKey);
  198.                             }
  199.                             else
  200.                             {
  201.                                 if (PARAGON_BUTTON_MAIN.Visible) //  doesn't matter if I check PARAGON_BUTTON_MAIN or PARAGON_BUTTON_VIT
  202.                                 {
  203.                                     IUiElement UiEStat = (SupportVit && (Hud.Game.Me.Powers.BuffIsActive(428354) || Hud.Game.Me.Powers.BuffIsActive(403556))) ? PARAGON_BUTTON_VIT : PARAGON_BUTTON_MAIN;
  204.                                     int i = Hud.Game.Me.ParagonPointsAvailable[0]/100 + 2;
  205.  
  206.                                     SendHoldKey(Keys.ControlKey);
  207.                                     while (i-- > 0)
  208.                                     {
  209.                                         mouseLClickUiE(UiEStat);
  210.                                     }
  211.                                     SendReleaseKey(Keys.ControlKey);
  212.                                 }
  213.                                 else
  214.                                 {
  215.                                     if (PARAGON_BUTTON_ACCEPT.Visible && PARAGON_BUTTON_ACCEPT.AnimState != 38)
  216.                                     {
  217.                                         mouseLClickUiE(PARAGON_BUTTON_ACCEPT);
  218.                                     }
  219.                                     else if (PARAGON_BUTTON_CANCEL.Visible)
  220.                                     {
  221.                                         mouseLClickUiE(PARAGON_BUTTON_CANCEL);
  222.                                     }
  223.                                 }
  224.                             }
  225.                         }
  226.                     }
  227.                     else if (Hud.Game.MapMode == MapMode.Minimap)
  228.                     {
  229.                         if (Hud.Game.Me.ParagonPointsAvailable[0] > 0)
  230.                         {
  231.                             SendPressKey(KeyParagonWindow);                 // Hud.Interaction.DoAction(ActionKey.ParagonWindow);
  232.                         }
  233.                         else
  234.                         {
  235.                             doParagon = false;
  236.                         }
  237.                     }
  238.                 }
  239.             }
  240.             else if (Hud.Game.IsInTown)
  241.             {
  242.                 if (DetectParagonButton && PARAGON_BUTTON_OPEN.Visible)
  243.                 {
  244.                     if (Hud.Game.Me.CurrentLevelParagon >= ParagonMin)
  245.                     {
  246.                         doParagon = true;
  247.                         msLapseAction = Hud.Game.CurrentRealTimeMilliseconds + msLapseMin;
  248.                     }
  249.                     DetectParagonButton = false;
  250.                 }
  251.             }
  252.         }
  253.     }
  254. }
Advertisement
Add Comment
Please, Sign In to add comment