Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Turbo.Plugins.Default;
- using System;
- using System.Text;
- using System.Collections.Generic;
- using System.Linq;
- using System.Windows.Forms;
- using SharpDX.DirectInput;
- using System.Runtime.InteropServices;
- using System.Text.RegularExpressions;
- using System.Drawing;
- namespace Turbo.Plugins.Ez
- {
- public class TransmutePlugin : BasePlugin, IKeyEventHandler, IInGameTopPainter
- {
- public bool Debug { get; set; } = false;
- private 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);
- private static IntPtr MakeLParam(int x, int y)
- {
- return (IntPtr)(y << 16 | (x & 65535));
- }
- public void mouseClickUiE(Keys key, IUiElement uie) // D3Hwnd
- {
- if (uie.Visible)
- {
- IntPtr lParam = MakeLParam((int)(uie.Rectangle.X + uie.Rectangle.Width * 0.5f), (int)(uie.Rectangle.Y + uie.Rectangle.Height * 0.5f));
- if (key == Keys.LButton)
- {
- SendMessage(D3Hwnd, 513U, (IntPtr)1, lParam);
- SendMessage(D3Hwnd, 514U, (IntPtr)1, lParam);
- }
- else if (key == Keys.RButton)
- {
- SendMessage(D3Hwnd, 516U, (IntPtr)2, lParam);
- SendMessage(D3Hwnd, 517U, (IntPtr)2, lParam);
- }
- }
- }
- public void mouseRClickItem(IItem item) // D3Hwnd
- {
- var rect = Hud.Inventory.GetItemRect(item);
- if (rect != System.Drawing.RectangleF.Empty)
- {
- IntPtr lParam = MakeLParam((int)(rect.X + rect.Width/2.0f), (int)(rect.Y + rect.Height/2.0f));
- SendMessage(D3Hwnd, 516U, (IntPtr)2, lParam);
- SendMessage(D3Hwnd, 517U, (IntPtr)2, lParam);
- }
- }
- protected IUiElement TransmuteDialog;
- protected IUiElement PageNumber;
- protected IUiElement TransmuteButton;
- protected IUiElement RecipeButton;
- protected IUiElement FillButton;
- protected IUiElement PrevButton;
- protected IUiElement NextButton;
- protected IUiElement AcceptBlinker;
- private List<IItem> listItemsOrd { get; set; }
- private SharpDX.DirectWrite.TextLayout layout { get; set; } = null;
- private Point lastItemPoint { get; set; } = Point.Empty;
- private IItem lastItem { get; set; } = null;
- private int[] enabledRecipes { get; set; } = new int[] {2, 3, 7, 8, 9};
- private int[] enabledPages { get; set; } = new int[] {1, 2, 3, 6, 7, 8, 9};
- private bool doCube { get; set; } = false;
- private bool StopNow { get; set; } = false;
- private int numRecipe { get; set; } = 0;
- private int stepRecipe { get; set; } = 0;
- private long msLapseAction { get; set; } = 0;
- private long msLapseMin { get; set; } = 50;
- private string NamePlugin { get; } = "[TransmutePlugin] ";
- public bool IgnoreInventoryLockArea { get; set; }
- public IKeyEvent ToggleKeyEvent { get; set; }
- public IBrush ItemHighlightBrush { get; set; }
- public IFont InfoFont { get; set; }
- public string TextAvailable { get; set; }
- public string TextNotAvailable { get; set; }
- public string TextProcessing { get; set; }
- public string TextNoMats { get; set; }
- public string TextNoItems { get; set; }
- public TransmutePlugin()
- {
- Enabled = true;
- }
- public override void Load(IController hud)
- {
- base.Load(hud);
- TextAvailable = "Press {0} to Start."; // {0} => Hotkey
- TextNotAvailable = "Unavailable, lock area missing.";
- TextProcessing = "Recipe {0} of {1} is being processed."; // {0} => Number recipe , {1} => Total recipes
- TextNoMats = "You don't have the required mats.";
- TextNoItems = "No items in inventory to process.";
- ToggleKeyEvent = Hud.Input.CreateKeyEvent(true, Key.F3, controlPressed: false, altPressed: false, shiftPressed: false); // Hotkey
- IgnoreInventoryLockArea = false; // If false -> Lock area required in the inventory for recipe 2. If true -> Ignore if you have defined (or not) a lock area in the inventory.
- ItemHighlightBrush = Hud.Render.CreateBrush(255, 200, 200, 100, -1.6f);
- InfoFont = Hud.Render.CreateFont("tahoma", 8, 255, 200, 200, 0, true, false, 255, 0, 0, 0, true);
- PageNumber = Hud.Render.RegisterUiElement("Root.NormalLayer.Kanais_Recipes_main.LayoutRoot.PageControls.page_number", TransmuteDialog, null);
- TransmuteDialog = Hud.Render.RegisterUiElement("Root.NormalLayer.vendor_dialog_mainPage.transmute_dialog", null, null);
- TransmuteButton = Hud.Render.RegisterUiElement("Root.NormalLayer.vendor_dialog_mainPage.transmute_dialog.LayoutRoot.transmute_button", TransmuteDialog, null);
- RecipeButton = Hud.Render.RegisterUiElement("Root.NormalLayer.vendor_dialog_mainPage.transmute_dialog.LayoutRoot.recipe_button", TransmuteDialog, null);
- FillButton = Hud.Render.RegisterUiElement("Root.NormalLayer.Kanais_Recipes_main.LayoutRoot.button_fill_currencies", TransmuteDialog, null);
- NextButton = Hud.Render.RegisterUiElement("Root.NormalLayer.Kanais_Recipes_main.LayoutRoot.PageControls.page_next", TransmuteDialog, null);
- PrevButton = Hud.Render.RegisterUiElement("Root.NormalLayer.Kanais_Recipes_main.LayoutRoot.PageControls.page_previous", TransmuteDialog, null);
- AcceptBlinker = Hud.Render.RegisterUiElement("Root.NormalLayer.vendor_dialog_mainPage.transmute_dialog.LayoutRoot.AcceptBlinker", TransmuteDialog, null);
- D3Hwnd = FindWindow("D3 Main Window Class", null); // D3Hwnd = FindWindow(null, "Diablo III");
- }
- public void OnKeyEvent(IKeyEvent keyEvent)
- {
- if (keyEvent.IsPressed && ToggleKeyEvent.Matches(keyEvent))
- {
- if (Hud.Game.IsInTown && Hud.Inventory.InventoryMainUiElement.Visible && PageNumber.Visible)
- {
- if (doCube)
- {
- StopNow = true;
- }
- else
- {
- var match = Regex.Match(PageNumber.ReadText(Encoding.UTF8, true), @"([0-9]+)(/|(\sиз\s)|(쪽\s/\s))([0-9]+)");
- if (match.Success && int.TryParse(match.Groups[1].Value, out var num) && enabledRecipes.Contains(num))
- {
- if (num != 2 || IgnoreInventoryLockArea || (Hud.Inventory.InventoryLockArea.Width > 0 && Hud.Inventory.InventoryLockArea.Height > 0))
- {
- if (checkMatsRequired(num))
- {
- mouseClickUiE(Keys.RButton, PageNumber);
- var items = GetItemsForRecipe(num);
- if (items.Any())
- {
- numRecipe = num;
- stepRecipe = 0;
- lastItem = null;
- lastItemPoint = Point.Empty;
- listItemsOrd = items.ToList();
- listItemsOrd.Sort((a, b) =>
- {
- var r = a.InventoryX.CompareTo(b.InventoryX);
- if (r == 0) r = a.InventoryY.CompareTo(b.InventoryY);
- return r;
- });
- StopNow = false;
- doCube = true;
- }
- }
- }
- }
- }
- }
- }
- }
- private bool checkMatsRequired(int numRecipe)
- {
- switch (numRecipe)
- {
- case 2: return (Hud.Game.Me.Materials.ForgottenSoul > 49) && (Hud.Game.Me.Materials.KhanduranRune > 4) && (Hud.Game.Me.Materials.CaldeumNightShade > 4) && (Hud.Game.Me.Materials.ArreatWarTapestry > 4) && (Hud.Game.Me.Materials.CorruptedAngelFlesh > 4) && (Hud.Game.Me.Materials.WestmarchHolyWater > 4);
- case 3: return (Hud.Game.Me.Materials.ReusableParts > 49) && (Hud.Game.Me.Materials.ArcaneDust > 49) && (Hud.Game.Me.Materials.VeiledCrystal > 49) && (Hud.Game.Me.Materials.DeathsBreath > 24);
- case 7: return (Hud.Game.Me.Materials.ReusableParts > 99);
- case 8: return (Hud.Game.Me.Materials.ArcaneDust > 99);
- case 9: return (Hud.Game.Me.Materials.VeiledCrystal > 99);
- default: return false;
- }
- }
- private IEnumerable<IItem> GetItemsForRecipe(int numRecipe)
- {
- switch (numRecipe)
- {
- case 2: return Hud.Inventory.ItemsInInventory.Where(i => i.SnoItem.Kind == ItemKind.loot && i.IsLegendary && !i.Unidentified && i.AncientRank < 2 && !i.SnoItem.IsEthereal && (!i.IsInventoryLocked || IgnoreInventoryLockArea)
- && i.StatList.FirstOrDefault(s => s.Id == "IsCrafted#1048575")?.DoubleValue != 1 && Hud.Game.Me.ArmorySets.FirstOrDefault(armorySet => armorySet?.ContainsItem(i) == true) == null
- && i.SnoItem.MainGroupCode != "gems_unique" && i.SnoItem.MainGroupCode != "riftkeystone" && !i.SnoItem.Code.StartsWith("P72_Soulshard") && i.SnoItem.NameEnglish != "Hellforge Ember"
- );
- case 3: return Hud.Inventory.ItemsInInventory.Where(i => i.SnoItem.Kind == ItemKind.loot && i.IsRare && i.StatList.FirstOrDefault(s => s.Id == "Requirement#57")?.DoubleValue == 70);
- case 7: return Hud.Inventory.ItemsInInventory.Where(i => i.SnoItem.Kind == ItemKind.loot && (i.IsRare || i.IsMagic));
- case 8: return Hud.Inventory.ItemsInInventory.Where(i => i.SnoItem.Kind == ItemKind.loot && (i.IsRare || (i.IsNormal && !i.AccountBound)));
- case 9: return Hud.Inventory.ItemsInInventory.Where(i => i.SnoItem.Kind == ItemKind.loot && (i.IsMagic || (i.IsNormal && !i.AccountBound)));
- default: return Enumerable.Empty<IItem>();
- }
- }
- public void PaintTopInGame(ClipState clipState)
- {
- if (clipState != ClipState.Inventory || !Hud.Game.IsInGame || !Hud.Game.IsInTown || !Hud.Inventory.InventoryMainUiElement.Visible) return;
- if (PageNumber.Visible)
- {
- int numPageCurrent;
- var match = Regex.Match(PageNumber.ReadText(Encoding.UTF8, true), @"([0-9]+)(/|(\sиз\s)|(쪽\s/\s))([0-9]+)");
- if (!match.Success || !int.TryParse(match.Groups[1].Value, out numPageCurrent))
- {
- numPageCurrent = 0;
- }
- if (doCube)
- {
- if (Hud.Game.CurrentRealTimeMilliseconds > msLapseAction)
- {
- msLapseAction = Hud.Game.CurrentRealTimeMilliseconds + msLapseMin;
- if (enabledPages.Contains(numPageCurrent))
- {
- if (AcceptBlinker.Visible)
- {
- msLapseAction += 100;
- mouseClickUiE(Keys.LButton, AcceptBlinker);
- stepRecipe = 1;
- }
- else
- {
- if (numRecipe == numPageCurrent)
- {
- if (StopNow) doCube = false;
- else if (TransmuteButton.AnimState == 51)
- {
- if (stepRecipe == 0 || stepRecipe == 4)
- {
- mouseClickUiE(Keys.LButton, PrevButton);
- }
- else if (stepRecipe == 1 || stepRecipe == 2) // Fill // 2,3 => lastItem != null always // remove (list) does not cause exceptions if the value does not exist
- {
- if (checkMatsRequired(numRecipe))
- {
- if (numRecipe == 2 && stepRecipe == 1 && lastItem != null)
- {
- var itemAux = Hud.Inventory.ItemsInInventory.FirstOrDefault(a => a.InventoryX == lastItemPoint.X && a.InventoryY == lastItemPoint.Y);
- if (itemAux != null && itemAux.Seed != lastItem.Seed) // item has changed
- {
- if (itemAux.IsLegendary && itemAux.AncientRank == 0)
- {
- listItemsOrd.Insert(0,itemAux); // the new item is legendary, not ancient or primal => add to list
- }
- }
- }
- if (listItemsOrd.Any())
- {
- var newItem = listItemsOrd.First();
- if (newItem.SeenInInventory)
- {
- if (lastItem != newItem) // first
- {
- lastItem = newItem;
- lastItemPoint = new Point(lastItem.InventoryX, lastItem.InventoryY);
- stepRecipe = 2;
- }
- else // second
- {
- stepRecipe = 3;
- }
- mouseClickUiE(Keys.LButton, FillButton);
- mouseRClickItem(lastItem);
- }
- else
- {
- listItemsOrd.Remove(newItem);
- lastItem = null;
- }
- }
- else doCube = false;
- }
- else doCube = false;
- }
- else // stepRecipe == 3 // fill fail
- {
- stepRecipe = 0;
- listItemsOrd.Remove(lastItem);
- lastItem = null;
- }
- }
- else if (TransmuteButton.AnimState != 52)
- {
- if (stepRecipe == 2 || stepRecipe == 3)
- {
- listItemsOrd.Remove(lastItem);
- mouseClickUiE(Keys.LButton, TransmuteButton);
- stepRecipe = 4;
- }
- else
- {
- mouseClickUiE(Keys.LButton, PrevButton);
- }
- msLapseAction += 150;
- }
- }
- else
- {
- mouseClickUiE(Keys.LButton, (numPageCurrent < numRecipe)? NextButton : PrevButton);
- stepRecipe = 1;
- }
- }
- }
- else doCube = false;
- }
- foreach (var item in listItemsOrd)
- {
- var itemRect = Hud.Inventory.GetItemRect(item);
- if (itemRect != System.Drawing.RectangleF.Empty) ItemHighlightBrush.DrawRectangle(itemRect);
- }
- layout = InfoFont.GetTextLayout(NamePlugin + String.Format(TextProcessing, numRecipe, match.Success?match.Groups[5].Value:"?"));
- }
- else
- {
- if (enabledRecipes.Contains(numPageCurrent))
- {
- if (numPageCurrent == 2 && !IgnoreInventoryLockArea && (Hud.Inventory.InventoryLockArea.Width == 0 || Hud.Inventory.InventoryLockArea.Height == 0))
- {
- layout = InfoFont.GetTextLayout(NamePlugin + TextNotAvailable);
- }
- else
- {
- var items = GetItemsForRecipe(numPageCurrent);
- if (items.Any())
- {
- foreach (var item in items)
- {
- var itemRect = Hud.Inventory.GetItemRect(item);
- if (itemRect != System.Drawing.RectangleF.Empty) ItemHighlightBrush.DrawRectangle(itemRect);
- }
- if (checkMatsRequired(numPageCurrent))
- {
- layout = InfoFont.GetTextLayout(NamePlugin + String.Format(TextAvailable, ToggleKeyEvent.ToString()));
- }
- else layout = InfoFont.GetTextLayout(NamePlugin + TextNoMats);
- }
- else layout = InfoFont.GetTextLayout(NamePlugin + TextNoItems);
- }
- }
- else layout = null;
- }
- if (layout != null)
- {
- InfoFont.DrawText(layout, TransmuteDialog.Rectangle.X + (TransmuteDialog.Rectangle.Width * 0.056f), TransmuteDialog.Rectangle.Y + (TransmuteDialog.Rectangle.Height * 0.088f));
- }
- }
- else if (doCube)
- {
- doCube = false;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment