From e4d6e1c0b76c0f257ccf4e4d20d7257a1f3ec2c1 Mon Sep 17 00:00:00 2001 From: Andrew Gilewsky Date: Tue, 5 Mar 2024 01:41:41 +0000 Subject: [PATCH] Support both standard and legacy control modes. --- vnavmesh/Movement/OverrideMovement.cs | 22 ++++++++++++++++++---- vnavmesh/Service.cs | 1 + 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/vnavmesh/Movement/OverrideMovement.cs b/vnavmesh/Movement/OverrideMovement.cs index f537e68..6e91b15 100644 --- a/vnavmesh/Movement/OverrideMovement.cs +++ b/vnavmesh/Movement/OverrideMovement.cs @@ -1,4 +1,5 @@ -using Dalamud.Hooking; +using Dalamud.Game.Config; +using Dalamud.Hooking; using Dalamud.Utility.Signatures; using FFXIVClientStructs.FFXIV.Client.Game.Control; using System; @@ -43,6 +44,8 @@ public bool Enabled public Vector3 DesiredPosition; public float Precision = 0.01f; + private bool _legacyMode; + private delegate void RMIWalkDelegate(void* self, float* sumLeft, float* sumForward, float* sumTurnLeft, byte* haveBackwardOrStrafe, byte* a6, byte bAdditiveUnk); [Signature("E8 ?? ?? ?? ?? 80 7B 3E 00 48 8D 3D")] private Hook _rmiWalkHook = null!; @@ -56,10 +59,13 @@ public OverrideMovement() Service.Hook.InitializeFromAttributes(this); Service.Log.Information($"RMIWalk address: 0x{_rmiWalkHook.Address:X}"); Service.Log.Information($"RMIFly address: 0x{_rmiFlyHook.Address:X}"); + Service.GameConfig.UiControlChanged += OnConfigChanged; + UpdateLegacyMode(); } public void Dispose() { + Service.GameConfig.UiControlChanged -= OnConfigChanged; _rmiWalkHook.Dispose(); _rmiFlyHook.Dispose(); } @@ -103,8 +109,16 @@ private void RMIFlyDetour(void* self, PlayerMoveControllerFlyInput* result) var dirH = Angle.FromDirectionXZ(dist); var dirV = allowVertical ? Angle.FromDirection(new(dist.Y, new Vector2(dist.X, dist.Z).Length())) : default; - var camera = (CameraEx*)CameraManager.Instance()->GetActiveCamera(); - var cameraDir = camera->DirH.Radians() + 180.Degrees(); - return (dirH - cameraDir, dirV); + var refDir = _legacyMode + ? ((CameraEx*)CameraManager.Instance()->GetActiveCamera())->DirH.Radians() + 180.Degrees() + : player.Rotation.Radians(); + return (dirH - refDir, dirV); + } + + private void OnConfigChanged(object? sender, ConfigChangeEvent evt) => UpdateLegacyMode(); + private void UpdateLegacyMode() + { + _legacyMode = Service.GameConfig.UiControl.TryGetUInt("MoveMode", out var mode) && mode == 1; + Service.Log.Info($"Legacy mode is now {(_legacyMode ? "enabled" : "disabled")}"); } } diff --git a/vnavmesh/Service.cs b/vnavmesh/Service.cs index 83fc555..07fd9eb 100644 --- a/vnavmesh/Service.cs +++ b/vnavmesh/Service.cs @@ -23,6 +23,7 @@ public class Service [PluginService] public static IAddonLifecycle AddonLifecycle { get; private set; } = null!; [PluginService] public static IFramework Framework { get; private set; } = null!; [PluginService] public static DalamudPluginInterface PluginInterface { get; private set; } = null!; + [PluginService] public static IGameConfig GameConfig { get; private set; } = null!; public static Lumina.GameData LuminaGameData => DataManager.GameData; public static T? LuminaRow(uint row) where T : Lumina.Excel.ExcelRow => LuminaGameData.GetExcelSheet(Lumina.Data.Language.English)?.GetRow(row);