EzPlugins

AlwaysUseYourParagon

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