Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // My goal was to get the plugin to work properly by using RegisterUiElement as few times as possible. For this reason, do not use craftweapons_dialog/craftarmor_dialog/salvage_dialog/repair_dialog.
- using Turbo.Plugins.Default;
- using System;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Text.RegularExpressions;
- namespace Turbo.Plugins.Ez
- {
- public class AlwaysRepairYourItems : BasePlugin, IAfterCollectHandler, INewAreaHandler
- {
- public bool Debug { get; set; } = false;
- public static IntPtr D3Hwnd = IntPtr.Zero;
- [DllImport("USER32.DLL")]
- private static extern IntPtr FindWindow(string ClassName, string WindowText);
- [DllImport("USER32.DLL")]
- private static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
- public void mouseLClickUiE(IUiElement uie) // D3Hwnd
- {
- var x = (int) (uie.Rectangle.X + uie.Rectangle.Width/2.0f);
- var y = (int) (uie.Rectangle.Y + uie.Rectangle.Height/2.0f);
- IntPtr lParam = (IntPtr)(y << 16 | (x & 65535));
- SendMessage(D3Hwnd, 513U, (IntPtr)1, lParam);
- SendMessage(D3Hwnd, 514U, (IntPtr)1, lParam);
- }
- protected IUiElement VENDOR_MAIN;
- protected IUiElement VENDOR_REPAIRALL;
- protected IUiElement VENDOR_TAB_0;
- protected IUiElement VENDOR_TAB_1;
- protected IUiElement VENDOR_TAB_2;
- protected IUiElement VENDOR_TAB_3;
- private bool doRepair { get; set; } = false;
- private long msLapseAction { get; set; } = 0;
- private IUiElement TabActive { get; set; } = null;
- private ISnoArea LastSnoArea { get; set; } = null;
- public long msLapseMin { get; set; } = 10;
- public bool AfterRepairGoToSalvageTab { get; set; }
- public AlwaysRepairYourItems()
- {
- Enabled = true;
- }
- public override void Load(IController hud)
- {
- base.Load(hud);
- AfterRepairGoToSalvageTab = false;
- D3Hwnd = FindWindow("D3 Main Window Class", null); // D3Hwnd = FindWindow(null, "Diablo III");
- VENDOR_MAIN = Hud.Render.RegisterUiElement("Root.NormalLayer.vendor_dialog_mainPage", null, null);
- VENDOR_REPAIRALL = Hud.Render.RegisterUiElement("Root.NormalLayer.vendor_dialog_mainPage.repair_dialog.RepairAll", null, null);
- VENDOR_TAB_0 = Hud.Render.RegisterUiElement("Root.NormalLayer.vendor_dialog_mainPage.tab_0", null, null);
- VENDOR_TAB_1 = Hud.Render.RegisterUiElement("Root.NormalLayer.vendor_dialog_mainPage.tab_1", null, null);
- VENDOR_TAB_2 = Hud.Render.RegisterUiElement("Root.NormalLayer.vendor_dialog_mainPage.tab_2", null, null);
- VENDOR_TAB_3 = Hud.Render.RegisterUiElement("Root.NormalLayer.vendor_dialog_mainPage.tab_3", null, null);
- }
- public void OnNewArea(bool newGame, ISnoArea area)
- {
- if (LastSnoArea != area)
- {
- if (area.IsTown /*&& LastSnoArea?.IsTown != true*/) // once for each town or once for all towns
- {
- msLapseAction = Hud.Game.CurrentRealTimeMilliseconds;
- TabActive = null;
- doRepair = true;
- }
- LastSnoArea = area;
- }
- }
- public void AfterCollect()
- {
- if (!Hud.Game.IsInGame || !Hud.Game.IsInTown || Hud.Game.IsPaused ) return;
- if (doRepair)
- {
- if (VENDOR_MAIN.Visible && VENDOR_TAB_3.Visible) // BlackSmith, Jeweler, Mystic
- {
- if (Hud.Game.CurrentRealTimeMilliseconds - msLapseAction > msLapseMin)
- {
- msLapseAction = Hud.Game.CurrentRealTimeMilliseconds;
- if (Hud.Game.Me.AnimationState == AcdAnimationState.Idle)
- {
- if (VENDOR_TAB_3.AnimState == 34) // Tab active 16-13-37-34-73 , 19-46-22-73 , 85-88-96-73 // 73 training => conflicts // (+-1) => Values for non-active tab (mouse over or not)
- {
- if (VENDOR_REPAIRALL.Visible)
- {
- var match = Regex.Match(VENDOR_REPAIRALL.ReadText(Encoding.UTF8, true), @"([0-9]+)"); // @"([0-9]+([\.,][0-9]+)*)" for complete number ?
- if (match.Success && match.Groups[1].Value != "0")
- {
- mouseLClickUiE(VENDOR_REPAIRALL);
- }
- else
- {
- if (AfterRepairGoToSalvageTab)
- TabActive = VENDOR_TAB_2;
- if (TabActive != null)
- {
- mouseLClickUiE(TabActive);
- TabActive = null;
- }
- doRepair = false;
- }
- }
- }
- else // 73 is not necessary, and thus I avoid conflicts
- {
- if (VENDOR_TAB_0.AnimState == 16)
- TabActive = VENDOR_TAB_0;
- else if (VENDOR_TAB_1.AnimState == 13)
- TabActive = VENDOR_TAB_1;
- else if (VENDOR_TAB_2.AnimState == 37)
- TabActive = VENDOR_TAB_2;
- if (TabActive != null)
- mouseLClickUiE(VENDOR_TAB_3);
- }
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment