Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions PandorasBox/Features/UI/FasterRepairAll.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using System;
using System.Linq;
using Dalamud.Game.Addon.Lifecycle;
using Dalamud.Game.Addon.Lifecycle.AddonArgTypes;
using ECommons.DalamudServices;
using FFXIVClientStructs.FFXIV.Client.Game;
using FFXIVClientStructs.FFXIV.Client.UI.Agent;
using FFXIVClientStructs.FFXIV.Component.GUI;
using PandorasBox.FeaturesSetup;
using PandorasBox.Helpers;

namespace PandorasBox.Features;

public unsafe class FasterRepairAll : Feature
{
public override string Name => "Faster Repair All";
public override string Description => "Substitutes the repair all button with a function to repair all instantly as opposed to queueing them one by one. Is this company stupid or what?";
public override FeatureType FeatureType => FeatureType.UI;

private const uint EventParamId = 0x50420000;
public override void Enable()
{
Svc.AddonLifecycle.RegisterListener(AddonEvent.PostSetup, "Repair", AddEvent);
Svc.AddonLifecycle.RegisterListener(AddonEvent.PreReceiveEvent, "Repair", HandleEvent);
}

public override void Disable()
{
Svc.AddonLifecycle.UnregisterListener(AddEvent);
Svc.AddonLifecycle.UnregisterListener(HandleEvent);
}

private unsafe void AddEvent(AddonEvent type, AddonArgs args)
{
var node = ((AtkUnitBase*)args.Addon.Address)->UldManager.SearchNodeById<AtkResNode>(12);
node->AddEvent(AtkEventType.ButtonClick, EventParamId, &((AtkUnitBase*)args.Addon.Address)->AtkEventListener, null, false);
// you have to match the event type that you're trying to replace or else the custom event doesn't go through
}

private void HandleEvent(AddonEvent type, AddonArgs args)
{
if (args is not AddonReceiveEventArgs rea) return;
// the normal event. Set both to 0 to block
if (rea is { AtkEventType: (byte)AtkEventType.ButtonClick, EventParam: 5 })
{
rea.AtkEventType = 0;
rea.EventParam = 0;
}
// custom event. Still has to be set to 0 or else the normal triggers (why?!)
if (rea is { AtkEventType: (byte)AtkEventType.ButtonClick, EventParam: (int)EventParamId })
{
rea.AtkEventType = 0;
rea.EventParam = 0;
RepairAll();
}
}

private unsafe void RepairAll()
{
if (AgentRepair.Instance()->IsSelfRepairOpen)
{
GameMain.ExecuteCommand(435, (int)InventoryType.EquippedItems);
Enum.GetValues<RepairCategory>().ToList().ForEach(inv => GameMain.ExecuteCommand(436, (int)inv));
}
else
{
GameMain.ExecuteCommand(1602, (int)InventoryType.EquippedItems);
Enum.GetValues<RepairCategory>().ToList().ForEach(inv => GameMain.ExecuteCommand(1601, (int)inv));
}
}

private enum RepairCategory : int
{
MainOffHand = 0,
HeadBodyArms = 1,
LegsFeet = 2,
EarsNeck = 3,
WristRing = 4,
Inventory = 5,
}
}
17 changes: 15 additions & 2 deletions PandorasBox/Helpers/AtkResNodeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

namespace PandorasBox.Helpers
{
internal static class AtkResNodeHelper
public static unsafe class AtkResNodeHelper
{

public static unsafe bool GetAtkUnitBase(this nint ptr, out AtkUnitBase* atkUnitBase)
{
if (ptr == IntPtr.Zero) { atkUnitBase = null; return false; }
Expand Down Expand Up @@ -41,5 +40,19 @@ public static unsafe Vector2 GetNodeScale(AtkResNode* node)

return scale;
}

public static T* SearchNodeById<T>(this AtkUldManager atkUldManager, uint nodeId) where T : unmanaged
{
foreach (var node in atkUldManager.Nodes)
{
if (node.Value is not null)
{
if (node.Value->NodeId == nodeId)
return (T*)node.Value;
}
}

return null;
}
}
}
2 changes: 1 addition & 1 deletion PandorasBox/PandorasBox.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ECommons" Version="3.1.0.6" />
<PackageReference Include="ECommons" Version="3.1.0.10" />
<PackageReference Include="NAudio" Version="2.1.0" />
<Reference Include="JetBrains.Annotations">
<Private>false</Private>
Expand Down
6 changes: 3 additions & 3 deletions PandorasBox/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
},
"ECommons": {
"type": "Direct",
"requested": "[3.1.0.6, )",
"resolved": "3.1.0.6",
"contentHash": "R17fNKyTD5ECL8EustEdjVZc5kbN5WQ4rK/SbSCVzQT6jQtzNC5xjrSBRz3W+YXVHCtyNJ1Aymqh80R4nfDuZA=="
"requested": "[3.1.0.10, )",
"resolved": "3.1.0.10",
"contentHash": "afgAdXz9ykESACvgssr9PXsPb8i7ZwSyqw58IGzgURUxkH8Hm1qIxwzybLDE5Eo8BXr4nESGqcRqEpbviH4/3g=="
},
"NAudio": {
"type": "Direct",
Expand Down