Penumbra/Penumbra/Interop/Hooks/Meta/EqpHook.cs
Ottermandias 6b475ee229
Some checks failed
.NET Build / build (push) Has been cancelled
Move a lot of things over to Luna.
2025-10-24 22:47:14 +02:00

41 lines
1.5 KiB
C#

using FFXIVClientStructs.FFXIV.Client.Graphics.Scene;
using Luna;
using Penumbra.GameData;
using Penumbra.GameData.Structs;
using Penumbra.Interop.PathResolving;
namespace Penumbra.Interop.Hooks.Meta;
public unsafe class EqpHook : FastHook<EqpHook.Delegate>, IDisposable
{
public delegate void Delegate(CharacterUtility* utility, EqpEntry* flags, CharacterArmor* armor);
private readonly MetaState _metaState;
public EqpHook(HookManager hooks, MetaState metaState)
{
_metaState = metaState;
Task = hooks.CreateHook<Delegate>("GetEqpFlags", Sigs.GetEqpEntry, Detour,
metaState.Config.EnableMods && !HookOverrides.Instance.Meta.EqpHook);
if (!HookOverrides.Instance.Meta.EqpHook)
_metaState.Config.ModsEnabled += Set;
}
private void Detour(CharacterUtility* utility, EqpEntry* flags, CharacterArmor* armor)
{
if (_metaState.EqpCollection.TryPeek(out var collection) && collection is { Valid: true, ModCollection.MetaCache: { } cache })
{
*flags = cache.Eqp.GetValues(armor);
*flags = cache.GlobalEqp.Apply(*flags, armor);
}
else
{
Task.Result.Original(utility, flags, armor);
}
Penumbra.Log.Excessive($"[GetEqpFlags] Invoked on 0x{(nint)utility:X} with 0x{(ulong)armor:X}, returned 0x{(ulong)*flags:X16}.");
}
public void Dispose()
=> _metaState.Config.ModsEnabled -= Set;
}