EzPlugins

TalkToOrekPlugin

Aug 26th, 2025 (edited)
433
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.96 KB | None | 0 0
  1. //05-sept-2025
  2. using Turbo.Plugins.Default;
  3. using System;
  4. using System.Text.RegularExpressions;
  5. using System.Linq;
  6. using System.Windows.Forms;
  7. using System.Runtime.InteropServices;
  8. using System.Threading;
  9.  
  10. namespace Turbo.Plugins.Ez
  11. {
  12.     public class TalkToOrekPlugin : BasePlugin, IAfterCollectHandler
  13.     {
  14.         public static IntPtr D3Hwnd = IntPtr.Zero;
  15.  
  16.         [DllImport("USER32.DLL")]
  17.         private static extern IntPtr FindWindow(string ClassName, string WindowText);
  18.  
  19.         [DllImport("USER32.DLL")]
  20.         private static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
  21.  
  22.         [DllImport("user32.dll")]
  23.         public static extern bool SetCursorPos(int x, int y);
  24.  
  25.         [DllImport("user32.dll")]
  26.         private static extern void mouse_event(uint dwFlags, int dx, int dy, uint dwData, IntPtr dwExtraInfo);
  27.  
  28.         public static void MoveMouseEventLClick(int x, int y)
  29.         {
  30.             SetCursorPos(x, y);
  31.             Thread.Sleep(1); mouse_event(6U, 0, 0, 0U, IntPtr.Zero);
  32.             Thread.Sleep(1); SetCursorPos(x, y); mouse_event(6U, 0, 0, 0U, IntPtr.Zero); // quick rp and retry
  33.         }
  34.  
  35.         private static IntPtr MakeLParam(int x, int y)
  36.         {
  37.             return (IntPtr)(y << 16 | (x & 65535));
  38.         }
  39.  
  40.         public void mouseLClickUiE(IUiElement uie)
  41.         {
  42.             IntPtr lParam = MakeLParam((int) (uie.Rectangle.X + uie.Rectangle.Width/2.0f), (int) (uie.Rectangle.Y + uie.Rectangle.Height/2.0f));
  43.             SendMessage(D3Hwnd, 513U, (IntPtr)1, lParam);
  44.             SendMessage(D3Hwnd, 514U, (IntPtr)1, lParam);
  45.         }
  46.  
  47.         protected IUiElement ChatEntry;
  48.         protected IUiElement ChatEditLine;
  49.         protected IUiElement OrekCLoseGR;
  50.         private IUiElement[] UiEPortraitIcons { get; set; } = new IUiElement[4];
  51.  
  52.         private long msLapseAction { get; set; } = 0;
  53.  
  54.         public double distanceOrekMax { get; set; }
  55.         public bool OnlyWorkInParty { get; set; }
  56.  
  57.         private string _msgParty { get; set; } = string.Empty;
  58.         public string msgParty
  59.         {
  60.             get { return _msgParty; }
  61.             set
  62.             {
  63.                 if (_msgParty != value)
  64.                 {
  65.                     _msgParty = Regex.Replace(value, "[+^%~()]", "{$0}"); // _msgParty = Regex.Replace(value, "[+^%~()\\{\\}]", "{$0}");
  66.                 }
  67.             }
  68.         }
  69.  
  70.         public TalkToOrekPlugin()
  71.         {
  72.             Enabled = true;
  73.         }
  74.  
  75.         public override void Load(IController hud)
  76.         {
  77.             base.Load(hud);
  78.             Order = int.MaxValue;
  79.  
  80.             distanceOrekMax = 8.0f;
  81.             OnlyWorkInParty = true;
  82.             msgParty = "+";
  83.  
  84.             ChatEntry = Hud.Render.RegisterUiElement("Root.NormalLayer.chatentry_dialog_backgroundScreen.chatentry_content", null, null);
  85.             ChatEditLine = Hud.Render.RegisterUiElement("Root.NormalLayer.chatentry_dialog_backgroundScreen.chatentry_content.chat_editline", null, null);
  86.             OrekCLoseGR = Hud.Render.RegisterUiElement("Root.NormalLayer.interact_dialog_mainPage.interact_dialog_Background.stack.interact_button_2", null, null);
  87.  
  88.             for (var i = 0; i < 4; i++)
  89.             {
  90.                 UiEPortraitIcons[i] = Hud.Render.RegisterUiElement("Root.NormalLayer.portraits.stack.party_stack.portrait_" + i + ".icon", null, null);
  91.             }
  92.  
  93.             D3Hwnd = FindWindow("D3 Main Window Class", null); // D3Hwnd = FindWindow(null, "Diablo III");
  94.         }
  95.  
  96.         private int TotalPortraits()
  97.         {
  98.             var portraits = 0;
  99.             for(var i = 0; i < 4; i++)
  100.             {
  101.                 if (UiEPortraitIcons[i].Visible)
  102.                     portraits++ ;
  103.             }
  104.             return portraits;
  105.         }
  106.  
  107.         public void AfterCollect()
  108.         {
  109.             if (!Hud.Game.IsInGame || !Hud.Game.IsInTown || Hud.Game.IsPaused || !Hud.Window.IsForeground) return;
  110.             if (Hud.Game.Actors.Any(a => a.SnoActor.Sno == ActorSnoEnum._x1_openworld_tiered_rifts_portal))
  111.             {
  112.                 var orek = Hud.Game.Actors.FirstOrDefault(a => a.SnoActor.Sno == ActorSnoEnum._x1_lr_nephalem);
  113.                 if (orek != null && orek.CentralXyDistanceToMe < distanceOrekMax && orek.IsOnScreen)
  114.                 {
  115.                     if (Hud.Game.Me.InGreaterRift)
  116.                     {
  117.                         if (Hud.Game.RiftPercentage < 100)
  118.                         {
  119.                             if (Hud.Game.NumberOfPlayersInGame == 1 && (UiEPortraitIcons[1].Visible || !OnlyWorkInParty))
  120.                             {
  121.                                 if (Hud.Game.CurrentRealTimeMilliseconds > msLapseAction && Hud.Game.Me.AnimationState == AcdAnimationState.Idle)
  122.                                 {
  123.                                     if (OrekCLoseGR.Visible)
  124.                                     {
  125.                                         msLapseAction = Hud.Game.CurrentRealTimeMilliseconds + 1500;
  126.                                         mouseLClickUiE(OrekCLoseGR);
  127.                                     }
  128.                                     else
  129.                                     {
  130.                                         msLapseAction = Hud.Game.CurrentRealTimeMilliseconds + 250;
  131.                                         MoveMouseEventLClick((int) orek.ScreenCoordinate.X + Hud.Window.Offset.X, (int) orek.ScreenCoordinate.Y + Hud.Window.Offset.Y);
  132.                                     }
  133.                                 }
  134.                             }
  135.                         }
  136.                     }
  137.                     else if (Hud.Game.CurrentRealTimeMilliseconds < msLapseAction)
  138.                     {
  139.                         if (ChatEntry.Visible)
  140.                         {
  141.                             msLapseAction = Hud.Game.CurrentRealTimeMilliseconds;
  142.                             if (TotalPortraits() > Hud.Game.NumberOfPlayersInGame)
  143.                             {
  144.                                 SendKeys.SendWait((ChatEditLine.Visible?"{ESC}":"") + "{ENTER}/p " + msgParty + "{ENTER}");
  145.                             }
  146.                         }
  147.                     }
  148.                 }
  149.             }
  150.         }
  151.     }
  152. }
Advertisement
Add Comment
Please, Sign In to add comment