Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Turbo.Plugins.Default;
- using System;
- using System.Text;
- using System.Windows.Forms;
- using SharpDX.DirectInput;
- using System.Runtime.InteropServices;
- namespace Turbo.Plugins.Ez
- {
- public class KadalaShopPlugin : 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);
- }
- }
- }
- protected IUiElement ShopMainPage;
- protected IUiElement ShopGoldText;
- private bool doShop { get; set; }
- private int itemActive { get; set; } = 0;
- private long msLapseAction { get; set; } = 0;
- private long msLapseMin { get; set; } = 50;
- private IUiElement[] UiEItemsRegion { get; set; }
- private IUiElement[] UiETabs { get; set; }
- private int[,] itemsData { get; set; }
- public IFont InfoFont { get; set; }
- public IKeyEvent ToggleKeyEvent { get; set; }
- public string[] names { get; set; } = new string[] { "<None>", "1-H Weapon", "2-H Weapon", "Quiver", "Orb", "Mojo", "Phylactery", "Helm", "Gloves", "Boots", "Chest Armor", "Belt", "Shoulders", "Pants", "Bracers", "Shield", "Ring", "Amulet" };
- public KadalaShopPlugin()
- {
- Enabled = true;
- }
- public override void Load(IController hud)
- {
- base.Load(hud);
- ToggleKeyEvent = Hud.Input.CreateKeyEvent(true, Key.F3, controlPressed: false, altPressed: false, shiftPressed: false); // Hotkey
- InfoFont = Hud.Render.CreateFont("tahoma", 8, 255, 200, 200, 0, true, false, 255, 0, 0, 0, true);
- ShopMainPage = Hud.Render.RegisterUiElement("Root.NormalLayer.shop_dialog_mainPage", null, null);
- ShopGoldText = Hud.Render.RegisterUiElement("Root.NormalLayer.shop_dialog_mainPage.gold_text", ShopMainPage, null);
- itemsData = new int[18,5] //{numUieRegion, numUieTab, animTabActive, shards, space}
- {
- {0, 0, 0, 0, 0}, // 0) None
- {0, 0, 49, 75, 2}, // 1) 1-H Weapon
- {1, 0, 49, 75, 2}, // 2) 2-H Weapon
- {2, 0, 49, 25, 2}, // 3) Quiver
- {3, 0, 49, 25, 2}, // 4) Orb
- {4, 0, 49, 25, 2}, // 5) Mojo
- {5, 0, 49, 25, 2}, // 6) Phylactery
- {0, 1, 40, 25, 2}, // 7) Helm
- {1, 1, 40, 25, 2}, // 8) Gloves
- {2, 1, 40, 25, 2}, // 9) Boots
- {3, 1, 40, 25, 2}, // 10) Chest Armor
- {4, 1, 40, 25, 1}, // 11) Belt
- {5, 1, 40, 25, 2}, // 12) Shoulders
- {6, 1, 40, 25, 2}, // 13) Pants
- {7, 1, 40, 25, 2}, // 14) Bracers
- {8, 1, 40, 25, 2}, // 15) Shield
- {0, 2, 46, 50, 1}, // 16) Ring
- {1, 2, 46, 100, 1}, // 17) Amulet
- };
- UiEItemsRegion = new IUiElement[]
- {
- Hud.Render.RegisterUiElement("Root.NormalLayer.shop_dialog_mainPage.shop_item_region.item 0 0", ShopMainPage, null),
- Hud.Render.RegisterUiElement("Root.NormalLayer.shop_dialog_mainPage.shop_item_region.item 1 0", ShopMainPage, null),
- Hud.Render.RegisterUiElement("Root.NormalLayer.shop_dialog_mainPage.shop_item_region.item 0 1", ShopMainPage, null),
- Hud.Render.RegisterUiElement("Root.NormalLayer.shop_dialog_mainPage.shop_item_region.item 1 1", ShopMainPage, null),
- Hud.Render.RegisterUiElement("Root.NormalLayer.shop_dialog_mainPage.shop_item_region.item 0 2", ShopMainPage, null),
- Hud.Render.RegisterUiElement("Root.NormalLayer.shop_dialog_mainPage.shop_item_region.item 1 2", ShopMainPage, null),
- Hud.Render.RegisterUiElement("Root.NormalLayer.shop_dialog_mainPage.shop_item_region.item 0 3", ShopMainPage, null),
- Hud.Render.RegisterUiElement("Root.NormalLayer.shop_dialog_mainPage.shop_item_region.item 1 3", ShopMainPage, null),
- Hud.Render.RegisterUiElement("Root.NormalLayer.shop_dialog_mainPage.shop_item_region.item 0 4", ShopMainPage, null)
- };
- UiETabs = new IUiElement[]
- {
- Hud.Render.RegisterUiElement("Root.NormalLayer.shop_dialog_mainPage.tab_0", ShopMainPage, null), // AnimState 48-49-50 (over/active/out)
- Hud.Render.RegisterUiElement("Root.NormalLayer.shop_dialog_mainPage.tab_1", ShopMainPage, null), // AnimState 39-40-41 (over/active/out)
- Hud.Render.RegisterUiElement("Root.NormalLayer.shop_dialog_mainPage.tab_2", ShopMainPage, null) // AnimState 45-46-47 (over/active/out)
- };
- 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 == true && Hud.Inventory.InventoryMainUiElement.Visible && ShopMainPage.Visible && ShopGoldText.Visible && ShopGoldText.ReadText(Encoding.UTF8, true).EndsWith("{icon:x1_shard}"))
- {
- if (doShop)
- {
- doShop = false;
- }
- else
- {
- for (int i = 0; i < UiEItemsRegion.Length ; i++)
- {
- if (UiEItemsRegion[i].Visible && UiEItemsRegion[i].Rectangle.Contains(Hud.Window.CursorX, Hud.Window.CursorY))
- {
- for (int j = 1; j < itemsData.Length ; j++) // itemsData {numUieRegion, numUieTab, animTabActive, shards, space}
- {
- if (itemsData[j,0] == i && UiETabs[itemsData[j,1]].AnimState == itemsData[j,2])
- {
- itemActive = j;
- break;
- }
- }
- break;
- }
- }
- if (itemActive > 0 && itemActive < 18 && Hud.Game.Me.Materials.BloodShard >= itemsData[itemActive,3])
- {
- doShop = true;
- }
- }
- }
- }
- }
- public void PaintTopInGame(ClipState clipState)
- {
- if (!Hud.Game.IsInGame || !Hud.Game.IsInTown || !Hud.Inventory.InventoryMainUiElement.Visible) return;
- if (ShopMainPage.Visible && ShopGoldText.Visible && ShopGoldText.ReadText(Encoding.UTF8, true).EndsWith("{icon:x1_shard}"))
- {
- if (clipState == ClipState.AfterClip)
- {
- var layout = InfoFont.GetTextLayout(String.Format("[KadalaShopPlugin] Hotkey: {0} , Default Item: {1} ", ToggleKeyEvent.ToString(), names[itemActive]));
- InfoFont.DrawText(layout, ShopMainPage.Rectangle.X + (ShopMainPage.Rectangle.Width * 0.055f), ShopMainPage.Rectangle.Y + (ShopMainPage.Rectangle.Height * 0.089f));
- }
- else if (clipState == ClipState.Inventory)
- {
- if (doShop)
- {
- if (Hud.Game.CurrentRealTimeMilliseconds > msLapseAction)
- {
- if (UiETabs[itemsData[itemActive,1]].Visible)
- {
- if (UiETabs[itemsData[itemActive,1]].AnimState == itemsData[itemActive,2]) // itemsData {numUieRegion, numUieTab, animTabActive, shards, space}
- {
- doShop = false;
- if (UiEItemsRegion[itemsData[itemActive,0]].Visible)
- {
- int numShopShards = (int) Hud.Game.Me.Materials.BloodShard / itemsData[itemActive,3];
- int numShopInv = (Hud.Game.Me.InventorySpaceTotal - Hud.Game.InventorySpaceUsed) / itemsData[itemActive,4];
- var numShop = Math.Min(numShopShards,numShopInv);
- if (numShop++ > 0) // 1 more if (numShop != 0);
- {
- while (numShop-- > 0)
- {
- mouseClickUiE(Keys.RButton, UiEItemsRegion[itemsData[itemActive,0]]);
- }
- }
- }
- }
- else
- {
- mouseClickUiE(Keys.LButton, UiETabs[itemsData[itemActive,1]]);
- msLapseAction = Hud.Game.CurrentRealTimeMilliseconds + msLapseMin;
- }
- }
- else doShop = false;
- }
- }
- }
- }
- else if (doShop)
- {
- doShop = false;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment