Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using Turbo.Plugins.Default;
- using System.Linq;
- using System.Collections.Generic;
- using System.Windows.Forms;
- using SharpDX.DirectInput;
- using System.Runtime.InteropServices;
- using System.Threading;
- namespace Turbo.Plugins.Ez
- {
- public class PickItemPlugin : BasePlugin, IItemPickedHandler, IAfterCollectHandler, INewAreaHandler, IKeyEventHandler
- {
- public static IntPtr D3Hwnd = IntPtr.Zero;
- [DllImport("USER32.DLL")]
- private static extern IntPtr FindWindow(string ClassName, string WindowText);
- [DllImport("user32.dll")]
- public static extern bool SetCursorPos(int x, int y);
- [DllImport("user32.dll")]
- private static extern void mouse_event(uint dwFlags, int dx, int dy, uint dwData, IntPtr dwExtraInfo);
- [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));
- }
- private static void MouseLeftClick()
- {
- mouse_event(6U, 0, 0, 0U, IntPtr.Zero);
- }
- private void DragAndDropItemInventory(IItem item, int x, int y)
- {
- 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, 513U, (IntPtr)1, lParam);
- lParam = MakeLParam(x, y);
- SendMessage(D3Hwnd, 514U, (IntPtr)1, lParam);
- }
- }
- protected IUiElement SeasonalLeaf;
- public IKeyEvent ToggleKeyEvent1 { get; set; } // ON/OFF
- public IKeyEvent ToggleKeyEvent2 { get; set; } // ON/OFF
- public int dist_Far { get; set; }
- public int dist_Near { get; set; }
- public Keys KeyNoPick { get; set; }
- private long MsPicked { get; set; } = 0;
- private long MsDragAndDrop { get; set; } = 0;
- private bool pick_Enabled { get; set; } = false;
- private bool inv_Enabled { get; set; } = false;
- private bool inv_Running { get; set; } = false;
- private bool PetDB { get; set; } = false;
- private bool PetNMR { get; set; } = false;
- private uint LastAreaSno { get; set; } = 0;
- private HashSet<uint> EnmityAreas { get; set; } = new HashSet<uint> { 488740, 488741, 488742, 488743, 488745, 488746, 488767, 488770, 488799, 488800, 488870, 488871, 488872, 488873, 488874 };
- private Dictionary<int, int> ItemsDicc { get; set; } = new Dictionary<int, int>();
- private HashSet<ActorSnoEnum> itemsToPick = new HashSet<ActorSnoEnum> // Items that do not need space in inventory
- {
- ActorSnoEnum._crafting_assortedparts_05, // 361984, Reusable Parts // craft normal
- ActorSnoEnum._crafting_magic_05, // 361985, Arcane Dust // craft magic
- ActorSnoEnum._crafting_rare_05, // 361986, Veiled Crystal // craft rare
- ActorSnoEnum._crafting_legendary_05, // 361988, Forgotten Soul // craft legendary
- ActorSnoEnum._crafting_looted_reagent_05, // 361989, breaths of death // craft rare
- ActorSnoEnum._tieredlootrunkey_0, // 408416, Keystone // loot normal
- ActorSnoEnum._craftingreagent_legendary_set_borns_x1, //365020, A1 Mats // craft Legenday
- ActorSnoEnum._craftingreagent_legendary_set_cains_x1, //364281, A2 Mats // craft Legenday
- ActorSnoEnum._craftingreagent_legendary_set_demon_x1, //364290, A3 Mats // craft Legenday
- ActorSnoEnum._craftingreagent_legendary_set_hallowed_x1, //364305, A4 Mats // craft Legenday
- ActorSnoEnum._craftingreagent_legendary_set_captaincrimsons_x1, //364975, A5 Mats // craft Legenday
- ActorSnoEnum._demonorgan_skeletonking_x1, // 364722, // normal uberstuff
- ActorSnoEnum._demonorgan_ghom_x1, // 364723, // normal uberstuff
- ActorSnoEnum._demonorgan_siegebreaker_x1, // 364724, // normal uberstuff
- ActorSnoEnum._demonorgan_diablo_x1, // 364725, // normal uberstuff
- };
- public HashSet<ISnoItem> BlackList { get; set; } = new HashSet<ISnoItem>();
- public PickItemPlugin()
- {
- Enabled = true;
- }
- public override void Load(IController hud)
- {
- base.Load(hud);
- dist_Near = 15; // pick auto
- dist_Far = 55; // F4
- KeyNoPick = Keys.C; // As long as you have this key pressed it will not pick up items // https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.keys
- ToggleKeyEvent1 = Hud.Input.CreateKeyEvent(true, Key.F4, controlPressed: true, altPressed: false, shiftPressed: false); // Trhow
- ToggleKeyEvent2 = Hud.Input.CreateKeyEvent(true, Key.F4, controlPressed: false, altPressed: false, shiftPressed: false); // Reset && Distance
- SeasonalLeaf = Hud.Render.RegisterUiElement("Root.NormalLayer.minimap_dialog_backgroundScreen.minimap_dialog_pve.BoostWrapper.BoostsDifficultyStackPanel.BoostsStackWrapper.BoostsStackPanel.Seasonal", null, null);
- D3Hwnd = FindWindow("D3 Main Window Class", null); // D3Hwnd = FindWindow(null, "Diablo III");
- if (Hud.Game.IsInGame) // TurboHud Free
- {
- LastAreaSno = Hud.Game.Me.SnoArea.Sno;
- DiscardMats2();
- }
- }
- public void OnKeyEvent(IKeyEvent keyEvent)
- {
- if (keyEvent.IsPressed)
- {
- if (ToggleKeyEvent1.Matches(keyEvent))
- {
- inv_Enabled = !inv_Enabled;
- }
- else if (ToggleKeyEvent2.Matches(keyEvent))
- {
- if (pick_Enabled)
- {
- pick_Enabled = false;
- }
- else
- {
- ItemsDicc.Clear();
- pick_Enabled = true;
- }
- }
- }
- }
- public void OnItemPicked(IItem item)
- {
- if (ItemsDicc.ContainsKey(item.Seed))
- ItemsDicc.Remove(item.Seed);
- }
- public void OnNewArea(bool newGame, ISnoArea area) // Compatibility Turbo Hud Free && Bug Lmod (dual area)
- {
- if (LastAreaSno != area.Sno)
- {
- LastAreaSno = area.Sno;
- if (area.IsTown) ItemsDicc.Clear();
- DiscardMats2();
- }
- }
- private void DiscardMats2()
- {
- if (Hud.Game.Me.Hero.Seasonal || SeasonalLeaf.Visible) // double checking (Hud.Game.Me.Hero.Seasonal not updated)
- {
- var petSeason = Hud.Game.Actors.Any(p => p.SummonerAcdDynamicId == Hud.Game.Me.SummonerId && p.GetAttributeValueAsUInt(Hud.Sno.Attributes.Pet_Type, 1048575) == 25);
- PetDB = petSeason && Hud.Game.Me.Powers.BuffIsActive(488027); // 488027 => Pets collect breaths of death
- PetNMR = (petSeason && Hud.Game.Me.Powers.BuffIsActive(488030)) || EnmityAreas.Contains(Hud.Game.Me.SnoArea.Sno); // 488030 => Pets salvage rare, magical, normal // in a Vision of Enmity always discard
- }
- else
- {
- PetDB = false;
- PetNMR = false;
- }
- }
- public void AfterCollect()
- {
- if (!Hud.Game.IsInGame || Hud.Game.IsPaused) return;
- if (Hud.Game.CurrentRealTimeMilliseconds - MsPicked > 100 && !Hud.Input.IsKeyDown(KeyNoPick) && Hud.Window.IsForeground && Hud.Game.Me.AnimationState == AcdAnimationState.Idle && !Hud.Render.WorldMapUiElement.Visible)
- {
- if (!Hud.Game.Me.Powers.CantMove && !Hud.Game.Me.Powers.BuffIsActive(439438) && (!Hud.Inventory.InventoryMainUiElement.Visible || pick_Enabled))
- {
- var distance = pick_Enabled?dist_Far:dist_Near; // Hud.Window.GroundRectangle.Contains((int)i.ScreenCoordinate.X, (int)i.ScreenCoordinate.Y)
- var items = Hud.Game.Items.Where(i => i.Location == ItemLocation.Floor && i.CentralXyDistanceToMe < distance && i.IsOnScreen && !BlackList.Contains(i.SnoItem)).OrderBy(o => o.CentralXyDistanceToMe);
- var picking = false;
- foreach(var item in items)
- {
- if (itemsToPick.Contains(item.SnoActor.Sno))
- {
- if (item.SnoActor.Sno == ActorSnoEnum._horadricrelic)
- {
- var maxShards = 500 + (Hud.Game.Me.HighestSoloRiftLevel * 10);
- if (Hud.Game.Me.Materials.BloodShard == maxShards) continue;
- }
- else if (item.SnoActor.Sno == ActorSnoEnum._crafting_looted_reagent_05)
- {
- if (PetDB) continue;
- }
- }
- else if (item.AccountBound && !item.BoundToMyAccount) continue;
- else
- {
- var s = Hud.Game.Me.InventorySpaceTotal - Hud.Game.InventorySpaceUsed;
- if (s == 0)
- {
- if (Hud.Inventory.ItemsInInventory.Any(i => i.SnoActor.Sno == item.SnoActor.Sno))
- {
- if (item.SnoActor.Sno == ActorSnoEnum._p74_consumable_sanctify_legendary_item)
- {
- if (item.StatList.FirstOrDefault(q => q.Id == "Unidentified#1048575")?.DoubleValue == 1) continue; // item.Unidentified bugged
- }
- else if (item.StatList.FirstOrDefault(q => q.Id == "ItemStackQuantityLo#1048575") == null) continue;
- }
- else continue;
- }
- else if (s == 1 && item.SnoItem.Kind != ItemKind.uberstuff && item.SnoItem.Kind != ItemKind.craft && item.SnoItem.Kind != ItemKind.gem
- && item.SnoItem.MainGroupCode != "gems_unique" && item.SnoItem.MainGroupCode != "ring" && item.SnoItem.MainGroupCode != "amulet" && item.SnoItem.MainGroupCode != "belt" && item.SnoItem.MainGroupCode != "consumable"
- ) continue;
- else if (item.IsMagic)
- {
- if (PetNMR) continue;
- }
- else if (item.IsNormal)
- {
- if (item.SnoItem.Kind == ItemKind.loot)
- {
- if (PetNMR && !item.AccountBound) continue;
- }
- else if (item.SnoItem.Kind != ItemKind.uberstuff && item.SnoItem.Kind != ItemKind.craft && item.SnoItem.Kind != ItemKind.gem ) continue;
- }
- else if (!item.IsLegendary) continue;
- }
- if (!ItemsDicc.TryGetValue(item.Seed,out var n))
- {
- n = 1;
- }
- else if (++n > 5) continue;
- ItemsDicc[item.Seed] = n;
- picking = true;
- MsPicked = Hud.Game.CurrentRealTimeMilliseconds;
- SetCursorPos((int)item.ScreenCoordinate.X + Hud.Window.Offset.X, (int)(item.ScreenCoordinate.Y - Hud.Window.Size.Height/55) + Hud.Window.Offset.Y);
- Thread.Sleep(1);
- if (Hud.Game.SelectedActor == null || Hud.Game.SelectedActor.GizmoType == GizmoType.Item)
- {
- MouseLeftClick();
- }
- break;
- }
- if (!picking && pick_Enabled)
- {
- pick_Enabled = false;
- }
- }
- }
- if (inv_Enabled)
- {
- if (Hud.Inventory.InventoryMainUiElement.Visible && Hud.Window.IsForeground)
- {
- if (Hud.Game.CurrentRealTimeMilliseconds - MsDragAndDrop > 10)
- {
- MsDragAndDrop = Hud.Game.CurrentRealTimeMilliseconds;
- var itemInv = PetNMR ? Hud.Inventory.ItemsInInventory.FirstOrDefault(i => (i.SnoItem.Kind == ItemKind.loot && !i.AccountBound && (i.IsRare || i.IsMagic || i.IsNormal)) || (!i.IsInventoryLocked && BlackList.Contains(i.SnoItem)))
- : Hud.Inventory.ItemsInInventory.FirstOrDefault(i => (i.SnoItem.Kind == ItemKind.loot && !i.AccountBound && i.IsRare) || (!i.IsInventoryLocked && BlackList.Contains(i.SnoItem)));
- if (itemInv != null)
- {
- DragAndDropItemInventory(itemInv, (int)(Hud.Window.Size.Width/2.0f), (int) (Hud.Window.Size.Height/2.0f));
- }
- else
- {
- inv_Enabled = false;
- }
- }
- }
- else
- {
- inv_Enabled = false;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment