EzPlugins

CloseDialogPlugin

Jul 27th, 2025 (edited)
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.37 KB | None | 0 0
  1. using Turbo.Plugins.Default;
  2. using System;
  3. using System.Windows.Forms;
  4. using System.Runtime.InteropServices;
  5.  
  6. namespace Turbo.Plugins.Ez
  7. {
  8.     public class CloseDialogPlugin : BasePlugin, IAfterCollectHandler
  9.     {
  10.         public bool DebugOn { get; set; } = false;
  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.         protected IUiElement GreaterRifts_VictoryScreen;
  21.         protected IUiElement GreaterRifts_VictoryScreen_Exit;
  22.  
  23.         protected IUiElement ConversationMain;
  24.         protected IUiElement BountyRewardMain;
  25.         protected IUiElement QuestrewardMain;
  26.  
  27.         protected IUiElement ChatUI;
  28.         protected IUiElement uiSkilllist;
  29.         protected IUiElement uiProfile;
  30.         protected IUiElement uiLeaderboard;
  31.         protected IUiElement uiAchievements;
  32.         protected IUiElement uiGamemenu;
  33.         protected IUiElement uiGuild;
  34.         protected IUiElement uiStore;
  35.  
  36.         protected IUiElement lore_player_dlg;
  37.         protected IUiElement lore_player_close;
  38.         protected IUiElement lore_notify_dlg;
  39.  
  40.         protected IUiElement follower_swap;
  41.         protected IUiElement follower_swap_ButtonOk;
  42.  
  43.         protected IUiElement PersonalizationButton;
  44.  
  45.         private const long intervalAction = 150;
  46.  
  47.         private long msLapseAction { get; set; } = 0;
  48.         private long msPauseAction { get; set; } = 0;
  49.  
  50.         public Keys keyCloseDialog { get; set; }
  51.  
  52.         private static IntPtr MakeLParam(int x, int y)
  53.         {
  54.             return (IntPtr)(y << 16 | (x & 65535));
  55.         }
  56.  
  57.         public static void SendPressKey(Keys key)
  58.         {
  59.             SendMessage(D3Hwnd, 256U, (IntPtr)((int)key), IntPtr.Zero);
  60.             SendMessage(D3Hwnd, 257U, (IntPtr)((int)key), IntPtr.Zero);
  61.         }
  62.  
  63.         public void mouseLClickUiE(IUiElement uie)
  64.         {
  65.             IntPtr lParam = MakeLParam((int) (uie.Rectangle.X + uie.Rectangle.Width/2.0f), (int) (uie.Rectangle.Y + uie.Rectangle.Height/2.0f));
  66.             SendMessage(D3Hwnd, 513U, (IntPtr)1, lParam);
  67.             SendMessage(D3Hwnd, 514U, (IntPtr)1, lParam);
  68.         }
  69.  
  70.         public CloseDialogPlugin()
  71.         {
  72.             Enabled = true;
  73.         }
  74.         public override void Load(IController hud)
  75.         {
  76.             base.Load(hud);
  77.  
  78.             keyCloseDialog = Keys.Space; // Close
  79.  
  80.             GreaterRifts_VictoryScreen = Hud.Render.RegisterUiElement("Root.NormalLayer.GreaterRifts_VictoryScreen.LayoutRoot", null, null);
  81.             GreaterRifts_VictoryScreen_Exit = Hud.Render.RegisterUiElement("Root.NormalLayer.GreaterRifts_VictoryScreen.LayoutRoot.Primary_Frame.button_exit", null, null);
  82.  
  83.             ConversationMain = Hud.Render.RegisterUiElement("Root.NormalLayer.conversation_dialog_main", null, null);
  84.             BountyRewardMain = Hud.Render.RegisterUiElement("Root.NormalLayer.BountyReward_main", null, null);
  85.             QuestrewardMain = Hud.Render.RegisterUiElement("Root.NormalLayer.questreward_dialog", null, null);
  86.  
  87.             ChatUI = Hud.Render.RegisterUiElement("Root.NormalLayer.chatentry_dialog_backgroundScreen.chatentry_content.chat_editline", null, null);
  88.             uiSkilllist = Hud.Render.RegisterUiElement("Root.NormalLayer.SkillPane_main.LayoutRoot.SkillsList", null, null);
  89.             uiProfile = Hud.Render.RegisterUiElement("Root.NormalLayer.BattleNetProfile_main.LayoutRoot.OverlayContainer", null, null);
  90.             uiLeaderboard = Hud.Render.RegisterUiElement("Root.NormalLayer.BattleNetLeaderboard_main.LayoutRoot.OverlayContainer", null, null);
  91.             uiAchievements = Hud.Render.RegisterUiElement("Root.NormalLayer.BattleNetAchievements_main.LayoutRoot.OverlayContainer", null, null);
  92.             uiGamemenu = Hud.Render.RegisterUiElement("Root.NormalLayer.gamemenu_dialog.gamemenu_bkgrnd.button_resumeGame", null, null);
  93.             uiGuild = Hud.Render.RegisterUiElement("Root.NormalLayer.Guild_main.LayoutRoot.OverlayContainer", null, null);
  94.             uiStore = Hud.Render.RegisterUiElement("Root.NormalLayer.BattleNetStore_main.LayoutRoot.OverlayContainer", null, null);
  95.  
  96.             lore_player_dlg = Hud.Render.RegisterUiElement("Root.NormalLayer.lore_player_dlg", null, null);
  97.             lore_player_close = Hud.Render.RegisterUiElement("Root.NormalLayer.lore_player_dlg.button_close", null, null);
  98.             lore_notify_dlg = Hud.Render.RegisterUiElement("Root.NormalLayer.lore_notify_dlg", null, null);
  99.  
  100.             follower_swap = Hud.Render.RegisterUiElement("Root.TopLayer.follower_swap", null, null);
  101.             follower_swap_ButtonOk = Hud.Render.RegisterUiElement("Root.TopLayer.follower_swap.subdlg.button_ok", null, null);
  102.  
  103.             PersonalizationButton = Hud.Render.RegisterUiElement("Root.NormalLayer.BattleNetFooter_main.LayoutRoot.ButtonContainer.PersonalizationButton", null, null);
  104.  
  105.             D3Hwnd = FindWindow("D3 Main Window Class", null); // D3Hwnd = FindWindow(null, "Diablo III");
  106.         }
  107.  
  108.         public void AfterCollect()
  109.         {
  110.             if (!Hud.Game.IsInGame) return;
  111.  
  112.             if (Hud.Game.CurrentRealTimeMilliseconds > msLapseAction)
  113.             {
  114.                 msLapseAction = Hud.Game.CurrentRealTimeMilliseconds + intervalAction;
  115.                 if (Hud.Game.Me.AnimationState == AcdAnimationState.Transform) return;
  116.                 if (!Hud.Window.IsForeground || Hud.Game.IsPaused || ChatUI.Visible || Hud.Inventory.InventoryMainUiElement.Visible || Hud.Game.MapMode != MapMode.Minimap) return;
  117.                 if (uiSkilllist.Visible || uiProfile.Visible || uiLeaderboard.Visible || uiAchievements.Visible || uiGamemenu.Visible || uiGuild.Visible || uiStore.Visible) return;
  118.  
  119.                 if (ConversationMain.Visible || BountyRewardMain.Visible || QuestrewardMain.Visible)
  120.                 {
  121.                     SendPressKey(keyCloseDialog);
  122.                 }
  123.                 else if (lore_player_dlg.Visible)
  124.                 {
  125.                     if (lore_player_close.Visible)
  126.                         mouseLClickUiE(lore_player_close);
  127.                 }
  128.                 else if (lore_notify_dlg.Visible)
  129.                 {
  130.                     mouseLClickUiE(lore_notify_dlg);
  131.                 }
  132.                 else if (Hud.Game.IsInTown)
  133.                 {
  134.                     if (follower_swap.Visible)
  135.                     {
  136.                         if (follower_swap_ButtonOk.Visible)
  137.                             mouseLClickUiE(follower_swap_ButtonOk);
  138.                     }
  139.                 }
  140.                 else
  141.                 {
  142.                     if (GreaterRifts_VictoryScreen.Visible)
  143.                     {
  144.                         if ( GreaterRifts_VictoryScreen_Exit.Visible)
  145.                             mouseLClickUiE(GreaterRifts_VictoryScreen_Exit);
  146.                     }
  147.                     else if (Hud.Game.CurrentRealTimeMilliseconds > msPauseAction)
  148.                     {
  149.                         if (!PersonalizationButton.Visible)
  150.                         {
  151.                             msPauseAction =  Hud.Game.CurrentRealTimeMilliseconds + 1000;
  152.                             SendPressKey(keyCloseDialog);
  153.                             if (DebugOn) Hud.Sound.Speak("Cinematic");
  154.                         }
  155.                     }
  156.                 }
  157.             }
  158.         }
  159.     }
  160. }
Advertisement
Add Comment
Please, Sign In to add comment