From 90fb40c3f69a96b3484eaa6482670d3d089143bd Mon Sep 17 00:00:00 2001 From: Det Date: Wed, 25 Jan 2023 02:53:09 -0300 Subject: [PATCH] AutoHook 2.4.2.0 [PUSH] AutoGig Improvements --- AutoHook/AutoHook.csproj | 2 +- AutoHook/AutoHook.json | 2 +- AutoHook/Configurations/Configuration.cs | 4 + AutoHook/PluginUI.cs | 16 -- AutoHook/Spearfishing/AutoGig.cs | 189 +++++++++++++----- .../Spearfishing/Struct/SpearfishWindow.cs | 5 + AutoHook/Ui/TabAutoGig.cs | 12 ++ AutoHook/Ui/TabGeneral.cs | 76 ++++++- 8 files changed, 239 insertions(+), 67 deletions(-) diff --git a/AutoHook/AutoHook.csproj b/AutoHook/AutoHook.csproj index 05d548d..f216e5b 100644 --- a/AutoHook/AutoHook.csproj +++ b/AutoHook/AutoHook.csproj @@ -2,7 +2,7 @@ Det - 2.4.1.0 + 2.4.2.0 Auto hooks for you https://github.com/InitialDet/AutoHook Release;Debug diff --git a/AutoHook/AutoHook.json b/AutoHook/AutoHook.json index fea0877..1638605 100644 --- a/AutoHook/AutoHook.json +++ b/AutoHook/AutoHook.json @@ -10,5 +10,5 @@ "DalamudApiLevel": 8, "AcceptsFeedback": false, "IconUrl": "https://raw.githubusercontent.com/InitialDet/AutoHook/main/AutoHook/images/icon.png", - "Changelog": "- Presets for custom baits added, you can now swap configs without needing to recreate it every time\n- Added options to cast Chum or Mooch only when under the effect of Fisher's Intuition\n- Added an option to only cast Prize Catch when Mooch II is not available, saving you 100gp if all you want is to mooch\n- Added Custom Timer when under the effect of Chum\n- Added an option to only use Prize Catch when under the effect of Identical Cast\n- Upgrade to .net7 and API8" + "Changelog": "Click the new Changelog button to see whats new" } \ No newline at end of file diff --git a/AutoHook/Configurations/Configuration.cs b/AutoHook/Configurations/Configuration.cs index 06f1fa5..cde48ac 100644 --- a/AutoHook/Configurations/Configuration.cs +++ b/AutoHook/Configurations/Configuration.cs @@ -30,10 +30,14 @@ public class Configuration : IPluginConfiguration public bool AutoGigEnabled = false; public bool AutoGigHideOverlay = false; public bool AutoGigNaturesBountyEnabled = false; + public bool AutoGigDrawFishHitbox = false; + public bool AutoGigDrawGigHitbox = false; public SpearfishSpeed currentSpeed = SpearfishSpeed.All; public SpearfishSize currentSize = SpearfishSize.All; + public Dictionary GigSpacing = new Dictionary(); + public void Save() { Service.PluginInterface!.SavePluginConfig(this); diff --git a/AutoHook/PluginUI.cs b/AutoHook/PluginUI.cs index 8c81b2a..a66f37e 100644 --- a/AutoHook/PluginUI.cs +++ b/AutoHook/PluginUI.cs @@ -115,22 +115,6 @@ public static void ShowKofi() ImGui.PopStyleColor(3); } - public static void ShowPaypal() - { - string buttonText = "Support on PayPal"; - ImGui.SameLine(); - ImGui.PushStyleColor(ImGuiCol.Button, 0xFFA06020); - ImGui.PushStyleColor(ImGuiCol.ButtonActive, 0xDD000000 | 0x005E5BFF); - ImGui.PushStyleColor(ImGuiCol.ButtonHovered, 0xAA000000 | 0x005E5BFF); - - if (ImGui.Button(buttonText)) - { - OpenBrowser("https://www.paypal.com/donate/?business=PDZJVTF5484UA&no_recurring=0¤cy_code=USD"); - } - - ImGui.PopStyleColor(3); - } - public static void OpenBrowser(string url) { Process.Start(new ProcessStartInfo { FileName = url, UseShellExecute = true }); diff --git a/AutoHook/Spearfishing/AutoGig.cs b/AutoHook/Spearfishing/AutoGig.cs index a63453f..0364963 100644 --- a/AutoHook/Spearfishing/AutoGig.cs +++ b/AutoHook/Spearfishing/AutoGig.cs @@ -1,6 +1,6 @@ using AutoHook.Data; using AutoHook.Utils; -using Dalamud.Hooking; +using Dalamud.Interface; using Dalamud.Interface.Windowing; using Dalamud.Logging; using FFXIVClientStructs.FFXIV.Client.Game; @@ -14,8 +14,6 @@ using System.Linq; using System.Numerics; using System.Runtime.InteropServices; -using System.Text; -using System.Threading.Tasks; namespace AutoHook.Spearfishing; internal class AutoGig : Window, IDisposable @@ -34,14 +32,32 @@ internal class AutoGig : Window, IDisposable private Vector2 _uiSize = Vector2.Zero; private unsafe SpearfishWindow* _addon = null; + private readonly List _sizeTypes = Enum.GetValues(typeof(SpearfishSize)).Cast().ToList(); + private readonly List _speedTypes = Enum.GetValues(typeof(SpearfishSpeed)).Cast().ToList(); - List speedTypes = Enum.GetValues(typeof(SpearfishSpeed)).Cast().ToList(); - List sizeTypes = Enum.GetValues(typeof(SpearfishSize)).Cast().ToList(); + private string currentKey = "zero"; public AutoGig() : base("SpearfishingHelper", WindowFlags, true) { Service.WindowSystem.AddWindow(this); IsOpen = true; + + currentKey = Service.Configuration.currentSize.ToName() + Service.Configuration.currentSpeed.ToName(); + } + + public static void ShowKofi() + { + string buttonText = "Support on Ko-fi"; + ImGui.PushStyleColor(ImGuiCol.Button, 0xFF000000 | 0x005E5BFF); + ImGui.PushStyleColor(ImGuiCol.ButtonActive, 0xDD000000 | 0x005E5BFF); + ImGui.PushStyleColor(ImGuiCol.ButtonHovered, 0xAA000000 | 0x005E5BFF); + + if (ImGui.Button(buttonText)) + { + Process.Start(new ProcessStartInfo { FileName = "https://ko-fi.com/initialdet", UseShellExecute = true }); + } + + ImGui.PopStyleColor(3); } public void Dispose() @@ -56,8 +72,9 @@ public override void Draw() DrawFishOverlay(); } - public void DrawSettings() + public unsafe void DrawSettings() { + currentKey = currentKey = Service.Configuration.currentSize.ToName() + Service.Configuration.currentSpeed.ToName(); if (ImGui.Checkbox("Enable AutoGig ", ref Service.Configuration.AutoGigEnabled)) { Service.Configuration.Save(); @@ -65,10 +82,40 @@ public void DrawSettings() ImGui.SameLine(); - if (ImGui.Checkbox("Use Nature's Bounty ", ref Service.Configuration.AutoGigNaturesBountyEnabled)) + try { - Service.Configuration.Save(); + if (Service.Configuration.GigSpacing != null) + { + int hitbox; + + if (!Service.Configuration.GigSpacing.ContainsKey(currentKey)) + Service.Configuration.GigSpacing.Add(currentKey, 30); + + hitbox = Service.Configuration.GigSpacing[currentKey]; + ImGui.SetNextItemWidth(90); + if (ImGui.InputInt("Hitbox ", ref hitbox)) + { + if (hitbox > 300) + hitbox = 300; + + if (hitbox < 0) + hitbox = 0; + + Service.Configuration.GigSpacing[currentKey] = hitbox; + } + ImGui.SameLine(); + if (ImGui.Checkbox("Use Nature's Bounty ", ref Service.Configuration.AutoGigNaturesBountyEnabled)) + { + Service.Configuration.Save(); + } + } + } + catch (Exception ex) + { + Service.Configuration.GigSpacing[currentKey] = 25; + PluginLog.Debug(ex.Message); } + ImGui.SameLine(); ShowKofi(); @@ -77,7 +124,7 @@ public void DrawSettings() if (ImGui.BeginCombo("Size", Service.Configuration.currentSize.ToName())) { - foreach (SpearfishSize size in sizeTypes.Where(size => + foreach (SpearfishSize size in _sizeTypes.Where(size => ImGui.Selectable(size.ToName(), size == Service.Configuration.currentSize))) { Service.Configuration.currentSize = size; @@ -90,7 +137,7 @@ public void DrawSettings() ImGui.SetNextItemWidth(130); if (ImGui.BeginCombo("Speed", Service.Configuration.currentSpeed.ToName())) { - foreach (SpearfishSpeed speed in speedTypes.Where(speed => + foreach (SpearfishSpeed speed in _speedTypes.Where(speed => ImGui.Selectable(speed.ToName(), speed == Service.Configuration.currentSpeed))) { Service.Configuration.currentSpeed = speed; @@ -99,24 +146,8 @@ public void DrawSettings() } } - public static void ShowKofi() - { - string buttonText = "Support on Ko-fi"; - ImGui.PushStyleColor(ImGuiCol.Button, 0xFF000000 | 0x005E5BFF); - ImGui.PushStyleColor(ImGuiCol.ButtonActive, 0xDD000000 | 0x005E5BFF); - ImGui.PushStyleColor(ImGuiCol.ButtonHovered, 0xAA000000 | 0x005E5BFF); - - if (ImGui.Button(buttonText)) - { - Process.Start(new ProcessStartInfo { FileName = "https://ko-fi.com/initialdet", UseShellExecute = true }); - } - - ImGui.PopStyleColor(3); - } - private unsafe void DrawFishOverlay() { - _addon = (SpearfishWindow*)Service.GameGui.GetAddonByName("SpearFishing", 1); bool _isOpen = _addon != null && _addon->Base.WindowNode != null; @@ -124,20 +155,18 @@ private unsafe void DrawFishOverlay() if (!_isOpen) return; - _uiScale = _addon->Base.Scale; - _uiPos = new Vector2(_addon->Base.X, _addon->Base.Y); - _uiSize = new Vector2(_addon->Base.WindowNode->AtkResNode.Width * _uiScale, _addon->Base.WindowNode->AtkResNode.Height * _uiScale); - ImGui.SetNextWindowPos(new Vector2(_addon->Base.X + 5, _addon->Base.Y - 65)); if (ImGui.Begin("gig", ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoTitleBar)) { DrawSettings(); + ImGui.End(); } + if (Service.Configuration.AutoGigEnabled) { - if (!PlayerResources.HasStatus(IDs.Status.NaturesBounty) && Service.Configuration.AutoGigNaturesBountyEnabled) - PlayerResources.CastActionDelayed(IDs.Actions.NaturesBounty); + /*if (!PlayerResources.HasStatus(IDs.Status.NaturesBounty) && Service.Configuration.AutoGigNaturesBountyEnabled) + PlayerResources.CastActionDelayed(IDs.Actions.NaturesBounty);*/ GigFish(_addon->Fish1, _addon->Fish1Node); GigFish(_addon->Fish2, _addon->Fish2Node); @@ -147,40 +176,108 @@ private unsafe void DrawFishOverlay() private unsafe void GigFish(SpearfishWindow.Info info, AtkResNode* node) { + var drawList = ImGui.GetWindowDrawList(); + + DrawGigHitbox(drawList); + if (!info.Available) return; var currentSize = Service.Configuration.currentSize; var currentSpeed = Service.Configuration.currentSpeed; - var gig = (info.Size == currentSize || currentSize == SpearfishSize.All) && + var gigFish = (info.Size == currentSize || currentSize == SpearfishSize.All) && (info.Speed == currentSpeed || currentSpeed == SpearfishSpeed.All); - if (!gig) + if (!gigFish) return; - var fixedx = (_uiSize.X / 2); - float newx = 0; + if (!PlayerResources.HasStatus(IDs.Status.NaturesBounty) && Service.Configuration.AutoGigNaturesBountyEnabled) + PlayerResources.CastActionDelayed(IDs.Actions.NaturesBounty); + + var centerX = (_uiSize.X / 2); + + float fishHitbox = 0; + // Im so tired of trying to figure this out someone help if (node->GetScaleX() == -1) - newx = (node->X * _uiScale) - (node->Width / 2); + fishHitbox = (node->X - (node->Width / 100 * 43)) * _uiScale; else - newx = (node->X * _uiScale) + (node->Width / 2); + fishHitbox = (node->X + (node->Width / 100 * 55)) * _uiScale; - if (newx <= fixedx + 25 && newx >= fixedx - 25) + int hitBox = Service.Configuration.GigSpacing[currentKey]; + + fishHitbox = (int)fishHitbox; + DrawFishHitbox(drawList, fishHitbox); + + if (fishHitbox >= (centerX - hitBox) - 3 && fishHitbox <= (centerX + hitBox) + 3) { + PlayerResources.CastActionNoDelay(IDs.Actions.Gig); + + if (node->GetScaleX() == -1) + PluginLog.Debug($"FishHitbox L = {fishHitbox}, GigHitbox = {centerX - hitBox}"); + else + PluginLog.Debug($"FishHitbox R= {fishHitbox}, GigHitbox = {centerX + hitBox}"); + } } - [StructLayout(LayoutKind.Explicit)] - public struct ActionEffectHeader + private unsafe void DrawGigHitbox(ImDrawListPtr drawList) { - [FieldOffset(0x0)] public long TargetObjectId; - [FieldOffset(0x8)] public uint ActionId; - [FieldOffset(0x14)] public uint UnkObjectId; - [FieldOffset(0x18)] public ushort Sequence; - [FieldOffset(0x1A)] public ushort Unk_1A; + if (!Service.Configuration.AutoGigDrawGigHitbox) + return; + + float startX = _uiSize.X / 2; + float centerY = _addon->FishLines->Y * _uiScale; + float endY = _addon->FishLines->Height * _uiScale; + + int space = Service.Configuration.GigSpacing[currentKey]; + + //Hitbox left + var lineStart = _uiPos + new Vector2(startX - space, centerY); + var lineEnd = lineStart + new Vector2(0, endY); + drawList.AddLine(lineStart, lineEnd, 0xFF0000C0, 1 * ImGuiHelpers.GlobalScale); + + //Hitbox right + lineStart = _uiPos + new Vector2(startX + space, centerY); + lineEnd = lineStart + new Vector2(0, endY); + drawList.AddLine(lineStart, lineEnd, 0xFF0000C0, 1 * ImGuiHelpers.GlobalScale); } + private unsafe void DrawFishHitbox(ImDrawListPtr drawList, float fishHitbox) + { + if (!Service.Configuration.AutoGigDrawFishHitbox) + return; + var lineStart = _uiPos + new Vector2(fishHitbox, _addon->FishLines->Y * _uiScale); + var lineEnd = lineStart + new Vector2(0, _addon->FishLines->Height * _uiScale); + drawList.AddLine(lineStart, lineEnd, 0xFF20B020, 1 * ImGuiHelpers.GlobalScale); + } + + public override unsafe bool DrawConditions() + { + _addon = (SpearfishWindow*)Service.GameGui.GetAddonByName("SpearFishing", 1); + + bool _isOpen = _addon != null && _addon->Base.WindowNode != null; + + if (!_isOpen) + return false; + + return true; + } + + public override unsafe void PreDraw() + { + _uiScale = _addon->Base.Scale; + _uiPos = new Vector2(_addon->Base.X, _addon->Base.Y); + _uiSize = new Vector2(_addon->Base.WindowNode->AtkResNode.Width * _uiScale, + _addon->Base.WindowNode->AtkResNode.Height * _uiScale); + + Position = _uiPos; + SizeConstraints = new WindowSizeConstraints + { + MinimumSize = _uiSize, + MaximumSize = Vector2.One * 10000, + }; + } } \ No newline at end of file diff --git a/AutoHook/Spearfishing/Struct/SpearfishWindow.cs b/AutoHook/Spearfishing/Struct/SpearfishWindow.cs index a120d36..8a39aaf 100644 --- a/AutoHook/Spearfishing/Struct/SpearfishWindow.cs +++ b/AutoHook/Spearfishing/Struct/SpearfishWindow.cs @@ -50,4 +50,9 @@ public unsafe AtkResNode* Fish2Node public unsafe AtkResNode* Fish3Node => Base.UldManager.NodeList[17]; + + public unsafe AtkComponentGaugeBar* GaugeBar + => (AtkComponentGaugeBar*)Base.UldManager.NodeList[35]; + + } \ No newline at end of file diff --git a/AutoHook/Ui/TabAutoGig.cs b/AutoHook/Ui/TabAutoGig.cs index 9da754a..ed68be9 100644 --- a/AutoHook/Ui/TabAutoGig.cs +++ b/AutoHook/Ui/TabAutoGig.cs @@ -45,6 +45,18 @@ public override void Draw() Service.Configuration.Save(); } + ImGui.Unindent(); + } else + { + ImGui.Indent(); + if (DrawUtil.Checkbox("Draw fish hitbox", ref Service.Configuration.AutoGigDrawFishHitbox, "The hitbox its only available for the fish of the Size and Speed selected")) + { + Service.Configuration.Save(); + } + if (DrawUtil.Checkbox("Draw gig hitbox", ref Service.Configuration.AutoGigDrawGigHitbox)) + { + Service.Configuration.Save(); + } ImGui.Unindent(); } diff --git a/AutoHook/Ui/TabGeneral.cs b/AutoHook/Ui/TabGeneral.cs index ac43110..eb6c77a 100644 --- a/AutoHook/Ui/TabGeneral.cs +++ b/AutoHook/Ui/TabGeneral.cs @@ -1,8 +1,12 @@ using System.Diagnostics; +using System.Linq; +using System.Numerics; +using System.Runtime.Intrinsics.X86; using Dalamud.Interface.Colors; using Dalamud.Interface.Components; using Dalamud.Logging; using ImGuiNET; +using Microsoft.VisualBasic; namespace AutoHook.Ui; @@ -18,25 +22,33 @@ public override void DrawHeader() ImGui.Separator(); ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.DalamudYellow); - ImGui.TextWrapped("Things might be broken in this new version. If you spot any weird behavior, please click the button below."); + ImGui.TextWrapped("Check the new changes in the Changelog below"); ImGui.PopStyleColor(); - + + ImGui.Spacing(); + + DrawChangelog(); + ImGui.Spacing(); if (ImGui.Button("Click here to report an issue or make a suggestion")) { Process.Start(new ProcessStartInfo { FileName = "https://github.com/InitialDet/AutoHook/issues", UseShellExecute = true }); } + ImGui.Spacing(); #if DEBUG + ImGui.SameLine(); if (ImGui.Button("Testing")) { - PluginLog.Debug($"Version = {Service.Configuration.Version}"); + ImGui.OpenPopup("changelog"); } + #endif } + public override void Draw() { @@ -99,4 +111,62 @@ public void DrawDefaultMooch() ImGui.Unindent(); } + + bool openChangelog = false; + private void DrawChangelog() + { + if (ImGui.Button("Changelog 2.4.2.0")) + { + //ImGui.OpenPopup("changelog"); + openChangelog = !openChangelog; + + if (openChangelog) + { + //ImGui.SetNextWindowSize(new Vector2(400, 250)); + } + + } + + if (openChangelog) + { + ImGui.SetNextWindowSize(new Vector2(400, 0)); + if (ImGui.Begin("Changelog", ref openChangelog, ImGuiWindowFlags.AlwaysAutoResize)) + { + ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.DalamudYellow); + ImGui.TextWrapped("2.4.2.0"); + ImGui.PopStyleColor(); + ImGui.Separator(); + ImGui.TextWrapped("- Added customizable hitbox for autogig"); + ImGui.Indent(); + ImGui.TextWrapped("Each Size and Speed combination has its own hitbox config"); + ImGui.Unindent(); + ImGui.TextWrapped("- Added an option to see the fish hitbox when spearfishing"); + ImGui.TextWrapped("- (experimental) Nature's Bounty will be used when the target fish appears on screen "); + ImGui.TextWrapped("- Added changelog button"); + + ImGui.Spacing(); + ImGui.Separator(); + ImGui.Spacing(); + + if (ImGui.TreeNode("2.4.1.0")) + { + ImGui.TextWrapped("- Added options to cast Mooch only when under the effect of Fisher's Intuition"); + ImGui.TreePop(); + } + + if (ImGui.TreeNode("2.4.0.0")) + { + ImGui.TextWrapped("- Presets for custom baits added, you can now swap configs without needing to recreate it every time"); + ImGui.TextWrapped("- Added options to cast Chum only when under the effect of Fisher's Intuition"); + ImGui.TextWrapped("- Added an option to only cast Prize Catch when Mooch II is not available, saving you 100gp if all you want is to mooch"); + ImGui.TextWrapped("- Added Custom Timer when under the effect of Chum"); + ImGui.TextWrapped("- Added an option to only use Prize Catch when under the effect of Identical Cast"); + ImGui.TextWrapped("- Upgrade to .net7 and API8"); + ImGui.TreePop(); + } + } + ImGui.End(); + } + } + } \ No newline at end of file