Skip to content

Commit

Permalink
AutoHook 2.4.2.0 [PUSH]
Browse files Browse the repository at this point in the history
AutoGig Improvements
  • Loading branch information
InitialDet committed Jan 25, 2023
1 parent 041c07d commit 90fb40c
Show file tree
Hide file tree
Showing 8 changed files with 239 additions and 67 deletions.
2 changes: 1 addition & 1 deletion AutoHook/AutoHook.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Authors>Det</Authors>
<Version>2.4.1.0</Version>
<Version>2.4.2.0</Version>
<Description>Auto hooks for you</Description>
<PackageProjectUrl>https://github.com/InitialDet/AutoHook</PackageProjectUrl>
<Configurations>Release;Debug</Configurations>
Expand Down
2 changes: 1 addition & 1 deletion AutoHook/AutoHook.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
4 changes: 4 additions & 0 deletions AutoHook/Configurations/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, int> GigSpacing = new Dictionary<string, int>();

public void Save()
{
Service.PluginInterface!.SavePluginConfig(this);
Expand Down
16 changes: 0 additions & 16 deletions AutoHook/PluginUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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&currency_code=USD");
}

ImGui.PopStyleColor(3);
}

public static void OpenBrowser(string url)
{
Process.Start(new ProcessStartInfo { FileName = url, UseShellExecute = true });
Expand Down
189 changes: 143 additions & 46 deletions AutoHook/Spearfishing/AutoGig.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand All @@ -34,14 +32,32 @@ internal class AutoGig : Window, IDisposable
private Vector2 _uiSize = Vector2.Zero;
private unsafe SpearfishWindow* _addon = null;

private readonly List<SpearfishSize> _sizeTypes = Enum.GetValues(typeof(SpearfishSize)).Cast<SpearfishSize>().ToList();
private readonly List<SpearfishSpeed> _speedTypes = Enum.GetValues(typeof(SpearfishSpeed)).Cast<SpearfishSpeed>().ToList();

List<SpearfishSpeed> speedTypes = Enum.GetValues(typeof(SpearfishSpeed)).Cast<SpearfishSpeed>().ToList();
List<SpearfishSize> sizeTypes = Enum.GetValues(typeof(SpearfishSize)).Cast<SpearfishSize>().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()
Expand All @@ -56,19 +72,50 @@ 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();
}

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();
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -99,45 +146,27 @@ 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;

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);
Expand All @@ -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,
};
}
}
5 changes: 5 additions & 0 deletions AutoHook/Spearfishing/Struct/SpearfishWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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];


}
12 changes: 12 additions & 0 deletions AutoHook/Ui/TabAutoGig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
Loading

0 comments on commit 90fb40c

Please sign in to comment.