feat: expose GamepadState as plugin service

This commit is contained in:
goat 2022-02-16 14:19:44 +01:00
parent 623327d407
commit aa545ce209
No known key found for this signature in database
GPG key ID: 7773BB5B43BA52E5

View file

@ -1,6 +1,8 @@
using System;
using Dalamud.Hooking;
using Dalamud.IoC;
using Dalamud.IoC.Internal;
using ImGuiNET;
using Serilog;
@ -11,6 +13,8 @@ namespace Dalamud.Game.ClientState.GamePad
///
/// Will block game's gamepad input if <see cref="ImGuiConfigFlags.NavEnableGamepad"/> is set.
/// </summary>
[PluginInterface]
[InterfaceVersion("1.0.0")]
public unsafe class GamepadState : IDisposable
{
private readonly Hook<ControllerPoll> gamepadPoll;
@ -32,14 +36,6 @@ namespace Dalamud.Game.ClientState.GamePad
this.gamepadPoll = new Hook<ControllerPoll>(resolver.GamepadPoll, this.GamepadPollDetour);
}
/// <summary>
/// Finalizes an instance of the <see cref="GamepadState" /> class.
/// </summary>
~GamepadState()
{
this.Dispose(false);
}
private delegate int ControllerPoll(IntPtr controllerInput);
/// <summary>
@ -164,14 +160,6 @@ namespace Dalamud.Game.ClientState.GamePad
/// <returns>1 the whole time button is pressed, 0 otherwise.</returns>
public float Raw(GamepadButtons button) => (this.ButtonsRaw & (ushort)button) > 0 ? 1 : 0;
/// <summary>
/// Enables the hook of the GamepadPoll function.
/// </summary>
public void Enable()
{
this.gamepadPoll.Enable();
}
/// <summary>
/// Disposes this instance, alongside its hooks.
/// </summary>
@ -181,6 +169,14 @@ namespace Dalamud.Game.ClientState.GamePad
GC.SuppressFinalize(this);
}
/// <summary>
/// Enables the hook of the GamepadPoll function.
/// </summary>
internal void Enable()
{
this.gamepadPoll.Enable();
}
private int GamepadPollDetour(IntPtr gamepadInput)
{
var original = this.gamepadPoll.Original(gamepadInput);