Skip to content

Commit

Permalink
cleanup and a little performance
Browse files Browse the repository at this point in the history
  • Loading branch information
Jukkales committed Apr 22, 2024
1 parent 19af96f commit 6052dde
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 128 deletions.
6 changes: 4 additions & 2 deletions HoardFarm/HoardFarm.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Globalization;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using AutoRetainerAPI;
using Dalamud;
using Dalamud.Interface.Windowing;
Expand All @@ -14,6 +15,7 @@

namespace HoardFarm;

[SuppressMessage("ReSharper", "ClassNeverInstantiated.Global")]
public sealed class HoardFarm : IDalamudPlugin
{
private readonly HoardFarmService hoardFarmService;
Expand All @@ -23,7 +25,7 @@ public sealed class HoardFarm : IDalamudPlugin
private readonly DeepDungeonMenuOverlay deepDungeonMenuOverlay;
private readonly AutoRetainerApi autoRetainerApi;
private readonly RetainerService retainerService;
public WindowSystem WindowSystem = new("HoardFarm");
public readonly WindowSystem WindowSystem = new("HoardFarm");

public HoardFarm(DalamudPluginInterface? pluginInterface)
{
Expand Down
2 changes: 1 addition & 1 deletion HoardFarm/HoardFarm.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Authors>Jukkales</Authors>
<Version>1.5.2.1</Version>
<Version>1.5.2.2</Version>
<Description>HoardFarm Dalamud Plugin</Description>
<PackageProjectUrl>https://github.com/Jukkales/HoardFarm</PackageProjectUrl>
</PropertyGroup>
Expand Down
4 changes: 3 additions & 1 deletion HoardFarm/IPC/NavmeshIPC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
using ECommons;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Numerics;
using System.Threading.Tasks;

namespace HoardFarm.IPC;

public class NavmeshIPC
[SuppressMessage("ReSharper", "InconsistentNaming")]
public static class NavmeshIPC
{
internal static readonly string Name = "vnavmesh";
private static ICallGateSubscriber<bool>? _navIsReady;
Expand Down
22 changes: 11 additions & 11 deletions HoardFarm/Model/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ public class Configuration : IPluginConfiguration
{
public int Version { get; set; } = 1;

public int HoardModeSave { get; set; }
public int HoardFarmMode { get; set; }
public int StopAfter { get; set; } = 50;
public int StopAfterMode { get; set; } = 1;
public int OverallRuns { get; set; }
public int OverallFoundHoards { get; set; }
public int OverallTime { get; set; }
public bool ShowOverlay { get; set; } = true;
public bool ParanoidMode { get; set; }
public int HoardModeSave;
public int HoardFarmMode;
public int StopAfter = 50;
public int StopAfterMode = 1;
public int OverallRuns;
public int OverallFoundHoards;
public int OverallTime;
public bool ShowOverlay = true;
public bool ParanoidMode;

public bool DoRetainers { get; set; }
public int RetainerMode { get; set; } = 1;
public bool DoRetainers;
public int RetainerMode = 1;

public void Save()
{
Expand Down
5 changes: 3 additions & 2 deletions HoardFarm/Service/AchievementService.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
using System;
using System.Diagnostics.CodeAnalysis;
using ECommons.EzHookManager;
using FFXIVClientStructs.FFXIV.Client.Game.UI;

namespace HoardFarm.Service;

public unsafe class AchievementService
{

public delegate void ReceiveAchievementProgressDelegate(Achievement* achievement, uint id, uint current, uint max);
[EzHook("C7 81 ?? ?? ?? ?? ?? ?? ?? ?? 89 91 ?? ?? ?? ?? 44 89 81")]
public EzHook<ReceiveAchievementProgressDelegate> ReceiveAchievementProgressHook = null!;

public int Progress { get; set; }
public int Progress;

public AchievementService()
{
Expand All @@ -24,6 +24,7 @@ public void UpdateProgress()
Achievement.Instance()->RequestAchievementProgress(ForTheHoardAchievementId);
}

[SuppressMessage("ReSharper", "UnusedMember.Local")]
private void ReceiveAchievementProgressDetour(Achievement* achievement, uint id, uint current, uint max)
{
if (id == ForTheHoardAchievementId)
Expand Down
8 changes: 4 additions & 4 deletions HoardFarm/Service/RetainerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class RetainerService : IDisposable
private bool autoRetainerEnabled;
private readonly AutoRetainerIPC autoRetainerIcp = new();

private DateTime? autoRetainerRunningTreshold;
private DateTime? autoRetainerRunningThreshold;

public RetainerService()
{
Expand Down Expand Up @@ -182,11 +182,11 @@ private static bool CheckIsDone(long time)
private bool AutoRetainerRunning()
{
if (autoRetainerIcp.IsBusy())
autoRetainerRunningTreshold = null;
autoRetainerRunningThreshold = null;
else
autoRetainerRunningTreshold ??= DateTime.Now.AddSeconds(10);
autoRetainerRunningThreshold ??= DateTime.Now.AddSeconds(10);

return autoRetainerRunningTreshold == null || autoRetainerRunningTreshold > DateTime.Now;
return autoRetainerRunningThreshold == null || autoRetainerRunningThreshold > DateTime.Now;
}

public bool CanRunRetainer()
Expand Down
3 changes: 0 additions & 3 deletions HoardFarm/Utils/DataIDs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,11 @@ public static class DataIDs
public const uint LimsaAetherytId = 8;
public const uint RetainerBellDataId = 2000401;
public static readonly Vector3 RetainerBellLocation = new(-124.1676f, 18f, 19.9041f);


public const ushort HoHMapId1 = 770;
public const ushort HoHMapId11 = 771;
public const ushort HoHMapId21 = 772;



public const uint AbandonDutyMessageId = 2545;
public const uint ConfirmPartyKoMessageId = 10483;

Expand Down
103 changes: 48 additions & 55 deletions HoardFarm/Utils/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,57 +12,68 @@
using FFXIVClientStructs.FFXIV.Client.UI.Agent;
using FFXIVClientStructs.FFXIV.Component.GUI;
using HoardFarm.Model;
using Lumina.Excel.GeneratedSheets;

namespace HoardFarm.Utils;

public static class Utils
{
public static readonly Version MinAutoRetainerVersion = new(4, 2, 6, 3);
public static float SprintCD => Player.Status.FirstOrDefault(s => s.StatusId == 50)?.RemainingTime ?? 0;
public static bool Concealment => (Player.Status.FirstOrDefault(s => s.StatusId == VanishStatusId)?.RemainingTime ?? 0) > 0;

public static bool Concealment =>
(Player.Status.FirstOrDefault(s => s.StatusId == VanishStatusId)?.RemainingTime ?? 0) > 0;

public static bool InHoH => Player.Territory == HoHMapId11 || Player.Territory == HoHMapId21;
public static bool InRubySea => Player.Territory == RubySeaMapId;
public static unsafe bool IsMoving() => AgentMap.Instance()->IsPlayerMoving == 1;
public static float Distance(this Vector3 v, Vector3 v2) => new Vector2(v.X - v2.X, v.Z - v2.Z).Length();
public static bool PluginInstalled(string name) => DalamudReflector.TryGetDalamudPlugin(name, out _, false, true);

public static unsafe bool NotBusy()

public static unsafe bool IsMoving()
{
return AgentMap.Instance()->IsPlayerMoving == 1;
}

public static float Distance(this Vector3 v, Vector3 v2)
{
return new Vector2(v.X - v2.X, v.Z - v2.Z).Length();
}

public static bool PluginInstalled(string name)
{
return DalamudReflector.TryGetDalamudPlugin(name, out _, false, true);
}

public static unsafe bool NotBusy()
{
var occupied = IsOccupied();
var target = TargetSystem.Instance()->Target;

if (occupied && Svc.Condition[ConditionFlag.OccupiedInQuestEvent] && target != null && target->DataID == KyuseiDataId)
{
occupied = false;
}


if (occupied && Svc.Condition[ConditionFlag.OccupiedInQuestEvent] && target != null &&
target->DataID == KyuseiDataId) occupied = false;

return Player.Available
&& Player.Object.CastActionId == 0
&& Player.Object.CastActionId == 0
&& !occupied
&& !Svc.Condition[ConditionFlag.Jumping]
&& !Svc.Condition[ConditionFlag.Jumping]
&& Player.Object.IsTargetable;
}


public static unsafe AtkResNode* GetNodeByIDChain(AtkResNode* node, params uint[] ids) {
if(node == null || ids.Length <= 0) {
return null;
}

if(node->NodeID == ids[0]) {
if(ids.Length == 1) {
return node;
}
public static unsafe AtkResNode* GetNodeByIDChain(AtkResNode* node, params uint[] ids)
{
if (node == null || ids.Length <= 0) return null;

if (node->NodeID == ids[0])
{
if (ids.Length == 1) return node;

var newList = new List<uint>(ids);
newList.RemoveAt(0);

var childNode = node->ChildNode;
if(childNode != null) {
return GetNodeByIDChain(childNode, newList.ToArray());
}
if (childNode != null) return GetNodeByIDChain(childNode, newList.ToArray());

if((int)node->Type >= 1000) {
if ((int)node->Type >= 1000)
{
var componentNode = node->GetAsAtkComponentNode();
var component = componentNode->Component;
var uldManager = component->UldManager;
Expand All @@ -80,20 +91,16 @@ public static unsafe bool NotBusy()

public static unsafe AtkUnitBase* FindSelectYesNo(uint rowId)
{
var s = Svc.Data.GetExcelSheet<Lumina.Excel.GeneratedSheets.Addon>()!.GetRow(rowId)!.Text
.ToDalamudString().ExtractText();
var s = Svc.Data.GetExcelSheet<Addon>()!.GetRow(rowId)!.Text
.ToDalamudString().ExtractText();
for (var i = 1; i < 100; i++)
{
try
{
if (TryGetAddonByName<AtkUnitBase>("SelectYesno", out var addon) && IsAddonReady(addon))
{
var textNode = addon->UldManager.NodeList[15]->GetAsAtkTextNode();
var text = MemoryHelper.ReadSeString(&textNode->NodeText).ExtractText().Replace(" ", "");
if (text.EqualsAny(s) || text.ContainsAny(s))
{
return addon;
}
if (text.EqualsAny(s) || text.ContainsAny(s)) return addon;
{
return addon;
}
Expand All @@ -104,25 +111,18 @@ public static unsafe bool NotBusy()
PluginLog.Debug(e.ToString());
return null;
}
}

return null;
}


public static unsafe bool KyuseiInteractable()
{
if (ObjectTable.TryGetFirst(e => e.DataId == KyuseiDataId, out var npc))
{
return npc.Position.Distance(Player.GameObject->Position) < 7f;
}
return false;
}

public static bool WaitTillOnokoro()
{
return InRubySea && Player.Interactable && NotBusy();
}


public static unsafe bool CanUsePomander(Pomander pomander)
{
if (TryGetAddonByName<AtkUnitBase>("DeepDungeonStatus", out var addon) && IsAddonReady(addon))
Expand All @@ -139,25 +139,18 @@ public static unsafe bool CanUsePomander(Pomander pomander)

return false;
}

public static unsafe bool CanUseMagicite()
{
if (TryGetAddonByName<AtkUnitBase>("DeepDungeonStatus", out var addon) && IsAddonReady(addon))
{
return GetNodeByIDChain(addon->GetRootNode(), MagiciteChain)->IsVisible;
}

return false;
}

public static bool AutoRetainerVersionHighEnough()
{
if (DalamudReflector.TryGetDalamudPlugin("AutoRetainer", out var plugin, false, true))
{
var minimalVersion = new Version(4, 2, 6, 3);
return plugin.GetType().Assembly.GetName().Version >= minimalVersion;
}

return false;
return Svc.PluginInterface.InstalledPlugins.FirstOrDefault(x => x.IsLoaded && x.InternalName == "AutoRetainer")
?.Version >= MinAutoRetainerVersion;
}
}
12 changes: 3 additions & 9 deletions HoardFarm/Windows/ConfigWindow.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Diagnostics;
using System.Diagnostics;
using Dalamud.Interface;
using Dalamud.Interface.Windowing;
using ImGuiNET;
Expand All @@ -8,7 +7,6 @@ namespace HoardFarm.Windows;

public class ConfigWindow() : Window("Hoard Farm Config", ImGuiWindowFlags.AlwaysAutoResize)
{

public override void Draw()
{
ImGui.Text("Actually no really much to configure here.");
Expand All @@ -35,16 +33,12 @@ public override void Draw()
Config.Save();
}

var showOverlay = Config.ShowOverlay;
if (ImGui.Checkbox("Show \"Open Hoardfarm\"-Overlay", ref showOverlay))
if (ImGui.Checkbox("Show \"Open Hoardfarm\"-Overlay", ref Config.ShowOverlay))
{
Config.ShowOverlay = showOverlay;
Config.Save();
}
var paranoid = Config.ParanoidMode;
if (ImGui.Checkbox("Paranoid mode", ref paranoid))
if (ImGui.Checkbox("Paranoid mode", ref Config.ParanoidMode))
{
Config.ParanoidMode = paranoid;
Config.Save();
}
ImGui.SameLine();
Expand Down
Loading

0 comments on commit 6052dde

Please sign in to comment.