EzPlugins

CloseDialogPlugin

Jul 27th, 2025 (edited)
530
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.16 KB | None | 0 0
  1. using Turbo.Plugins.Default;
  2. using System;
  3. using System.Windows;
  4. using System.Windows.Forms;
  5. using System.Runtime.InteropServices;
  6.  
  7. namespace Turbo.Plugins.Ez
  8. {
  9.     public class CloseDialogPlugin : BasePlugin, IAfterCollectHandler
  10.     {
  11.         public bool DebugOn { get; set; } = false;
  12.  
  13.         public static IntPtr D3Hwnd = IntPtr.Zero;
  14.  
  15.         [DllImport("USER32.DLL")]
  16.         private static extern IntPtr FindWindow(string ClassName, string WindowText);
  17.  
  18.         [DllImport("USER32.DLL")]
  19.         private static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
  20.         [DllImport("user32.dll")]
  21.         private static extern IntPtr PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
  22.  
  23.         protected IUiElement GreaterRifts_VictoryScreen;
  24.         protected IUiElement GreaterRifts_VictoryScreen_Exit;
  25.         protected IUiElement rift_join_party_main;
  26.  
  27.         protected IUiElement ConversationMain;
  28.         protected IUiElement BountyRewardMain;
  29.         protected IUiElement QuestrewardMain;
  30.  
  31.         protected IUiElement ChatUI;
  32.         protected IUiElement uiSkilllist;
  33.         protected IUiElement uiProfile;
  34.         protected IUiElement uiLeaderboard;
  35.         protected IUiElement uiAchievements;
  36.         protected IUiElement uiGamemenu;
  37.         protected IUiElement uiGuild;
  38.         protected IUiElement uiStore;
  39.  
  40.         protected IUiElement lore_player_dlg;
  41.         protected IUiElement lore_player_close;
  42.         protected IUiElement lore_notify_dlg;
  43.  
  44.         protected IUiElement follower_swap;
  45.         protected IUiElement follower_swap_ButtonOk;
  46.  
  47.         protected IUiElement tutorial_dialog_background;
  48.         protected IUiElement tutorial_dialog_background_close;
  49.  
  50.         protected IUiElement SocialFlyoutButton;
  51.  
  52.         private const long intervalAction = 250;
  53.  
  54.         private long msLapseAction { get; set; } = 0;
  55.         private long msPauseAction { get; set; } = 0;
  56.         private long msPauseClose { get; set; } = 0;
  57.  
  58.         public Keys keyCloseDialog { get; set; }
  59.         public bool keepVictoryScreenInTown { get; set; }
  60.  
  61.         private static IntPtr MakeLParam(int x, int y)
  62.         {
  63.             return (IntPtr)(y << 16 | (x & 65535));
  64.         }
  65.  
  66.         public static void PostPressKey(Keys key)
  67.         {
  68.             PostMessage(D3Hwnd, 256U, (IntPtr)((int)key), IntPtr.Zero); PostMessage(D3Hwnd, 257U, (IntPtr)((int)key), IntPtr.Zero);
  69.         }
  70.  
  71.         public void mouseLClickUiE(IUiElement uie, float dx = 0.5f, float dy = 0.5f)
  72.         {
  73.             IntPtr lParam = MakeLParam((int) (uie.Rectangle.X + uie.Rectangle.Width * dx), (int) (uie.Rectangle.Y + uie.Rectangle.Height * dy));
  74.             PostMessage(D3Hwnd, 513U, (IntPtr)1, lParam);
  75.             PostMessage(D3Hwnd, 514U, (IntPtr)1, lParam);
  76.         }
  77.  
  78.         private bool UIEgoClick { get; set; } = false;
  79.         private IUiElement UIEforDelay { get; set; } = null;
  80.         private IUiElement UIEforClick { get; set; } = null;
  81.  
  82.         public CloseDialogPlugin()
  83.         {
  84.             Enabled = true;
  85.         }
  86.         public override void Load(IController hud)
  87.         {
  88.             base.Load(hud);
  89.  
  90.             keepVictoryScreenInTown = false;
  91.             keyCloseDialog = Keys.Space; // Close
  92.  
  93.             GreaterRifts_VictoryScreen = Hud.Render.RegisterUiElement("Root.NormalLayer.GreaterRifts_VictoryScreen.LayoutRoot", null, null);
  94.             GreaterRifts_VictoryScreen_Exit = Hud.Render.RegisterUiElement("Root.NormalLayer.GreaterRifts_VictoryScreen.LayoutRoot.Primary_Frame.button_exit", null, null);
  95.  
  96.             rift_join_party_main = Hud.Render.RegisterUiElement("Root.NormalLayer.rift_join_party_main.LayoutRoot", null, null);
  97.  
  98.             ConversationMain = Hud.Render.RegisterUiElement("Root.NormalLayer.conversation_dialog_main", null, null);
  99.             BountyRewardMain = Hud.Render.RegisterUiElement("Root.NormalLayer.BountyReward_main", null, null);
  100.             QuestrewardMain = Hud.Render.RegisterUiElement("Root.NormalLayer.questreward_dialog", null, null);
  101.  
  102.             ChatUI = Hud.Render.RegisterUiElement("Root.NormalLayer.chatentry_dialog_backgroundScreen.chatentry_content.chat_editline", null, null);
  103.             uiSkilllist = Hud.Render.RegisterUiElement("Root.NormalLayer.SkillPane_main.LayoutRoot.SkillsList", null, null);
  104.             uiProfile = Hud.Render.RegisterUiElement("Root.NormalLayer.BattleNetProfile_main.LayoutRoot.OverlayContainer", null, null);
  105.             uiLeaderboard = Hud.Render.RegisterUiElement("Root.NormalLayer.BattleNetLeaderboard_main.LayoutRoot.OverlayContainer", null, null);
  106.             uiAchievements = Hud.Render.RegisterUiElement("Root.NormalLayer.BattleNetAchievements_main.LayoutRoot.OverlayContainer", null, null);
  107.             uiGamemenu = Hud.Render.RegisterUiElement("Root.NormalLayer.gamemenu_dialog.gamemenu_bkgrnd.button_resumeGame", null, null);
  108.             uiGuild = Hud.Render.RegisterUiElement("Root.NormalLayer.Guild_main.LayoutRoot.OverlayContainer", null, null);
  109.             uiStore = Hud.Render.RegisterUiElement("Root.NormalLayer.BattleNetStore_main.LayoutRoot.OverlayContainer", null, null);
  110.  
  111.             lore_player_dlg = Hud.Render.RegisterUiElement("Root.NormalLayer.lore_player_dlg", null, null);
  112.             lore_player_close = Hud.Render.RegisterUiElement("Root.NormalLayer.lore_player_dlg.button_close", null, null);
  113.             lore_notify_dlg = Hud.Render.RegisterUiElement("Root.NormalLayer.lore_notify_dlg", null, null);
  114.  
  115.             follower_swap = Hud.Render.RegisterUiElement("Root.TopLayer.follower_swap", null, null);
  116.             follower_swap_ButtonOk = Hud.Render.RegisterUiElement("Root.TopLayer.follower_swap.subdlg.button_ok", null, null);
  117.  
  118.             tutorial_dialog_background = Hud.Render.RegisterUiElement("Root.NormalLayer.tutorial_dialog_background.tutorial.anchored", null, null);
  119.             tutorial_dialog_background_close = Hud.Render.RegisterUiElement("Root.NormalLayer.tutorial_dialog_background.tutorial.anchored.stack.wrapper.button_close", null, null);
  120.  
  121.             SocialFlyoutButton = Hud.Render.RegisterUiElement("Root.NormalLayer.BattleNetFooter_main.LayoutRoot.ButtonContainer.SocialFlyoutButton", null, null);
  122.  
  123.             D3Hwnd = FindWindow("D3 Main Window Class", null); // D3Hwnd = FindWindow(null, "Diablo III");
  124.         }
  125.  
  126.         public void AfterCollect()
  127.         {
  128.             if (!Hud.Game.IsInGame) return;
  129.  
  130.             if (Hud.Game.CurrentRealTimeMilliseconds > msLapseAction)
  131.             {
  132.                 msLapseAction = Hud.Game.CurrentRealTimeMilliseconds + intervalAction;
  133.                 if (Hud.Game.Me.AnimationState == AcdAnimationState.Transform) return;
  134.                 if (!Hud.Window.IsForeground || Hud.Game.IsPaused || ChatUI.Visible || Hud.Inventory.InventoryMainUiElement.Visible || Hud.Game.MapMode != MapMode.Minimap) return;
  135.                 if (uiSkilllist.Visible || uiProfile.Visible || uiLeaderboard.Visible || uiAchievements.Visible || uiGamemenu.Visible || uiGuild.Visible || uiStore.Visible) return;
  136.  
  137.                 UIEgoClick = false;
  138.  
  139.                 if (!SocialFlyoutButton.Visible) // Video
  140.                 {
  141.                     if (Hud.Game.CurrentRealTimeMilliseconds > msPauseAction)
  142.                     {
  143.                         msPauseAction =  Hud.Game.CurrentRealTimeMilliseconds + 1000;
  144.                         PostPressKey(keyCloseDialog);
  145.                         if (DebugOn) Hud.Sound.Speak("Video");
  146.                     }
  147.                 }
  148.                 else if (ConversationMain.Visible || BountyRewardMain.Visible || QuestrewardMain.Visible)
  149.                 {
  150.                     PostPressKey(keyCloseDialog);
  151.                 }
  152.                 else if (lore_notify_dlg.Visible)
  153.                 {
  154.                     UIEforClick = lore_notify_dlg;
  155.                     UIEgoClick = true;
  156.                 }
  157.                 else if (lore_player_dlg.Visible)
  158.                 {
  159.                     if (lore_player_close.Visible)
  160.                     {
  161.                         UIEforClick = lore_player_close;
  162.                         UIEgoClick = true;
  163.                     }
  164.                 }
  165.                 else if (follower_swap.Visible)
  166.                 {
  167.                     if (follower_swap_ButtonOk.Visible)
  168.                     {
  169.                         UIEforClick = follower_swap_ButtonOk;
  170.                         UIEgoClick = true;
  171.  
  172.                     }
  173.                 }
  174.                 else if (tutorial_dialog_background.Visible)
  175.                 {
  176.                     if (tutorial_dialog_background_close.Visible)
  177.                     {
  178.                         UIEforClick = tutorial_dialog_background_close;
  179.                         UIEgoClick = true;
  180.                     }
  181.                 }
  182.                 else if (GreaterRifts_VictoryScreen.Visible)
  183.                 {
  184.                     if (!Hud.Game.IsInTown || !keepVictoryScreenInTown)
  185.                     {
  186.                         if (!rift_join_party_main.Visible && GreaterRifts_VictoryScreen_Exit.Visible)
  187.                         {
  188.                             //UIEforClick = GreaterRifts_VictoryScreen_Exit;
  189.                             //UIEgoClick = true;
  190.                             PostPressKey(keyCloseDialog);
  191.                         }
  192.                     }
  193.                 }
  194.  
  195.                 if (UIEgoClick)
  196.                 {
  197.                     UIEforClick.Refresh();
  198.                     if (UIEforClick.Visible)
  199.                     {
  200.                         if (UIEforDelay != UIEforClick) // Delay
  201.                         {
  202.                             UIEforDelay = UIEforClick;
  203.                         }
  204.                         else
  205.                         {
  206.                             UIEforDelay = null;
  207.                             mouseLClickUiE(UIEforClick);
  208.                         }
  209.                     }
  210.                 }
  211.             }
  212.         }
  213.     }
  214. }
Advertisement
Add Comment
Please, Sign In to add comment