muffin v7.4.5
This commit is contained in:
parent
8461a561d3
commit
bb09805213
11 changed files with 881 additions and 891 deletions
|
|
@ -6,7 +6,6 @@ using Dalamud.Game.ClientState.Conditions;
|
|||
using Dalamud.Plugin.Services;
|
||||
using FFXIVClientStructs.FFXIV.Client.Graphics.Kernel;
|
||||
using FFXIVClientStructs.FFXIV.Client.System.Input;
|
||||
using FFXIVClientStructs.FFXIV.Client.System.String;
|
||||
using FFXIVClientStructs.FFXIV.Client.UI;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Questionable.Controller.Steps.Common;
|
||||
|
|
@ -37,10 +36,12 @@ internal static class Dive
|
|||
}
|
||||
}
|
||||
|
||||
internal sealed class DoDive(ICondition condition, ILogger<DoDive> logger) : AbstractDelayedTaskExecutor<Task>(TimeSpan.FromSeconds(5L))
|
||||
internal sealed class DoDive(ICondition condition, ILogger<DoDive> logger) : AbstractDelayedTaskExecutor<Task>(TimeSpan.FromSeconds(5L)), IStoppableTaskExecutor, ITaskExecutor
|
||||
{
|
||||
private readonly Queue<(uint Type, nint Key)> _keysToPress = new Queue<(uint, nint)>();
|
||||
|
||||
private readonly HashSet<nint> _pressedKeys = new HashSet<nint>();
|
||||
|
||||
private int _attempts;
|
||||
|
||||
protected override bool StartInternal()
|
||||
|
|
@ -67,11 +68,30 @@ internal static class Dive
|
|||
}
|
||||
logger.LogDebug("{Action} key {KeyCode:X2}", (result.Item1 == 256) ? "Pressing" : "Releasing", result.Item2);
|
||||
NativeMethods.SendMessage((nint)Device.Instance()->hWnd, result.Item1, result.Item2, IntPtr.Zero);
|
||||
if (result.Item1 == 256)
|
||||
{
|
||||
_pressedKeys.Add(result.Item2);
|
||||
}
|
||||
else if (result.Item1 == 257)
|
||||
{
|
||||
_pressedKeys.Remove(result.Item2);
|
||||
}
|
||||
return ETaskResult.StillRunning;
|
||||
}
|
||||
return base.Update();
|
||||
}
|
||||
|
||||
public unsafe void StopNow()
|
||||
{
|
||||
foreach (nint pressedKey in _pressedKeys)
|
||||
{
|
||||
logger.LogDebug("Releasing stuck key {KeyCode:X2} on stop", pressedKey);
|
||||
NativeMethods.SendMessage((nint)Device.Instance()->hWnd, 257u, pressedKey, IntPtr.Zero);
|
||||
}
|
||||
_pressedKeys.Clear();
|
||||
_keysToPress.Clear();
|
||||
}
|
||||
|
||||
public override bool ShouldInterruptOnDamage()
|
||||
{
|
||||
return false;
|
||||
|
|
@ -83,7 +103,7 @@ internal static class Dive
|
|||
{
|
||||
return ETaskResult.TaskComplete;
|
||||
}
|
||||
if (_attempts >= 3)
|
||||
if (_attempts >= 5)
|
||||
{
|
||||
throw new TaskException("Please dive manually.");
|
||||
}
|
||||
|
|
@ -94,22 +114,25 @@ internal static class Dive
|
|||
|
||||
private unsafe void Descend()
|
||||
{
|
||||
byte* ptr = stackalloc byte[16];
|
||||
Utf8String* name = Utf8String.FromString("MOVE_DESCENT");
|
||||
UIInputData.Instance()->GetKeybindByName(name, (Keybind*)ptr);
|
||||
SeVirtualKey seVirtualKey = (SeVirtualKey)(*(uint*)ptr);
|
||||
byte b = ptr[4];
|
||||
SeVirtualKey seVirtualKey2 = (SeVirtualKey)((uint*)ptr)[2];
|
||||
byte b2 = ptr[12];
|
||||
logger.LogInformation("Dive keybind: {Key1} + {Modifier1}, {Key2} + {Modifier2}", seVirtualKey, b, seVirtualKey2, b2);
|
||||
Keybind* keybind = UIInputData.Instance()->GetKeybind(InputId.MOVE_DESCENT);
|
||||
if (keybind == null)
|
||||
{
|
||||
throw new TaskException("Could not find descent keybind");
|
||||
}
|
||||
Span<KeySetting> keySettings = keybind->KeySettings;
|
||||
SeVirtualKey key = keySettings[0].Key;
|
||||
KeyModifierFlag keyModifier = keySettings[0].KeyModifier;
|
||||
SeVirtualKey key2 = keySettings[1].Key;
|
||||
KeyModifierFlag keyModifier2 = keySettings[1].KeyModifier;
|
||||
logger.LogInformation("Dive keybind: {Key1} + {Modifier1}, {Key2} + {Modifier2}", key, keyModifier, key2, keyModifier2);
|
||||
int num = 2;
|
||||
List<List<nint>> list = new List<List<nint>>(num);
|
||||
CollectionsMarshal.SetCount(list, num);
|
||||
Span<List<nint>> span = CollectionsMarshal.AsSpan(list);
|
||||
int num2 = 0;
|
||||
span[num2] = GetKeysToPress(seVirtualKey, b);
|
||||
span[num2] = GetKeysToPress(key, keyModifier);
|
||||
num2++;
|
||||
span[num2] = GetKeysToPress(seVirtualKey2, b2);
|
||||
span[num2] = GetKeysToPress(key2, keyModifier2);
|
||||
List<nint> list2 = (from x in list
|
||||
where x != null
|
||||
select (x)).MinBy((List<nint> x) => x.Count);
|
||||
|
|
@ -120,10 +143,12 @@ internal static class Dive
|
|||
foreach (nint item in list2)
|
||||
{
|
||||
_keysToPress.Enqueue((256u, item));
|
||||
_keysToPress.Enqueue((0u, 0));
|
||||
_keysToPress.Enqueue((0u, 0));
|
||||
for (int num3 = 0; num3 < 15; num3++)
|
||||
{
|
||||
_keysToPress.Enqueue((0u, 0));
|
||||
}
|
||||
}
|
||||
for (int num3 = 0; num3 < 5; num3++)
|
||||
for (int num4 = 0; num4 < 5; num4++)
|
||||
{
|
||||
_keysToPress.Enqueue((0u, 0));
|
||||
}
|
||||
|
|
@ -146,18 +171,18 @@ internal static class Dive
|
|||
public static extern nint SendMessage(nint hWnd, uint Msg, nint wParam, nint lParam);
|
||||
}
|
||||
|
||||
private static List<nint>? GetKeysToPress(SeVirtualKey key, byte modifier)
|
||||
private static List<nint>? GetKeysToPress(SeVirtualKey key, KeyModifierFlag modifier)
|
||||
{
|
||||
List<nint> list = new List<nint>();
|
||||
if ((modifier & 1) != 0)
|
||||
if ((modifier & KeyModifierFlag.Ctrl) != KeyModifierFlag.None)
|
||||
{
|
||||
list.Add(17);
|
||||
}
|
||||
if ((modifier & 2) != 0)
|
||||
if ((modifier & KeyModifierFlag.Shift) != KeyModifierFlag.None)
|
||||
{
|
||||
list.Add(16);
|
||||
}
|
||||
if ((modifier & 4) != 0)
|
||||
if ((modifier & KeyModifierFlag.Alt) != KeyModifierFlag.None)
|
||||
{
|
||||
list.Add(18);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue