Skip to content

Commit

Permalink
Support both standard and legacy control modes.
Browse files Browse the repository at this point in the history
  • Loading branch information
awgil committed Mar 5, 2024
1 parent ce2f884 commit e4d6e1c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
22 changes: 18 additions & 4 deletions vnavmesh/Movement/OverrideMovement.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<RMIWalkDelegate> _rmiWalkHook = null!;
Expand All @@ -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();
}
Expand Down Expand Up @@ -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")}");
}
}
1 change: 1 addition & 0 deletions vnavmesh/Service.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(uint row) where T : Lumina.Excel.ExcelRow => LuminaGameData.GetExcelSheet<T>(Lumina.Data.Language.English)?.GetRow(row);
Expand Down

0 comments on commit e4d6e1c

Please sign in to comment.