Penumbra/Penumbra/Interop/Hooks/Meta/SetupVisor.cs
2024-01-01 00:17:15 +01:00

35 lines
1.5 KiB
C#

using FFXIVClientStructs.FFXIV.Client.Graphics.Scene;
using OtterGui.Services;
using Penumbra.GameData;
using Penumbra.Interop.PathResolving;
namespace Penumbra.Interop.Hooks.Meta;
/// <summary>
/// GMP. This gets called every time when changing visor state, and it accesses the gmp file itself,
/// but it only applies a changed gmp file after a redraw for some reason.
/// </summary>
public sealed unsafe class SetupVisor : FastHook<SetupVisor.Delegate>
{
private readonly CollectionResolver _collectionResolver;
private readonly MetaState _metaState;
public SetupVisor(HookManager hooks, CollectionResolver collectionResolver, MetaState metaState)
{
_collectionResolver = collectionResolver;
_metaState = metaState;
Task = hooks.CreateHook<Delegate>("Setup Visor", Sigs.SetupVisor, Detour, true);
}
public delegate byte Delegate(DrawObject* drawObject, ushort modelId, byte visorState);
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
private byte Detour(DrawObject* drawObject, ushort modelId, byte visorState)
{
var collection = _collectionResolver.IdentifyCollection(drawObject, true);
using var gmp = _metaState.ResolveGmpData(collection.ModCollection);
var ret = Task.Result.Original.Invoke(drawObject, modelId, visorState);
Penumbra.Log.Excessive($"[Setup Visor] Invoked on {(nint)drawObject:X} with {modelId}, {visorState} -> {ret}.");
return ret;
}
}