Skip to content

Commit

Permalink
add shared data consumer code for navmesh interop
Browse files Browse the repository at this point in the history
  • Loading branch information
xanunderscore committed Feb 20, 2025
1 parent 74d52b8 commit b577ebf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
16 changes: 14 additions & 2 deletions BossMod/Framework/MovementOverride.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Dalamud.Game.Config;
using Dalamud.Plugin;
using FFXIVClientStructs.FFXIV.Client.Game.Character;
using FFXIVClientStructs.FFXIV.Client.Game.Object;
using FFXIVClientStructs.FFXIV.Client.System.Input;
Expand Down Expand Up @@ -28,10 +29,12 @@ public sealed unsafe class MovementOverride : IDisposable
public WDir UserMove { get; private set; } // unfiltered movement direction, as read from input
public WDir ActualMove { get; private set; } // actual movement direction, as of last input read

private readonly IDalamudPluginInterface _dalamud;
private readonly ActionTweaksConfig _tweaksConfig = Service.Config.Get<ActionTweaksConfig>();
private bool _movementBlocked;
private bool? _forcedControlState;
private bool _legacyMode;
private bool[]? _navmeshPathIsRunning;

public bool IsMoving() => ActualMove != default;
public bool IsMoveRequested() => UserMove != default;
Expand Down Expand Up @@ -67,8 +70,10 @@ public bool MovementBlocked
private delegate byte MoveControlIsInputActiveDelegate(void* self, byte inputSourceFlags);
private readonly HookAddress<MoveControlIsInputActiveDelegate> _mcIsInputActiveHook;

public MovementOverride()
public MovementOverride(IDalamudPluginInterface dalamud)
{
_dalamud = dalamud;

var rmiWalkIsInputEnabled1Addr = Service.SigScanner.ScanText("E8 ?? ?? ?? ?? 84 C0 75 10 38 43 3C");
var rmiWalkIsInputEnabled2Addr = Service.SigScanner.ScanText("E8 ?? ?? ?? ?? 84 C0 75 03 88 47 3F");
Service.Log($"RMIWalkIsInputEnabled1 address: 0x{rmiWalkIsInputEnabled1Addr:X}");
Expand All @@ -86,20 +91,27 @@ public MovementOverride()

public void Dispose()
{
_dalamud.RelinquishData("vnav.PathIsRunning");
Service.GameConfig.UiControlChanged -= OnConfigChanged;
_movementBlocked = false;
_mcIsInputActiveHook.Dispose();
_rmiWalkHook.Dispose();
_rmiFlyHook.Dispose();
}

private bool NavmeshActive()
{
_navmeshPathIsRunning ??= _dalamud.GetData<bool[]>("vnav.PathIsRunning");
return _navmeshPathIsRunning != null && _navmeshPathIsRunning[0];
}

private void RMIWalkDetour(void* self, float* sumLeft, float* sumForward, float* sumTurnLeft, byte* haveBackwardOrStrafe, byte* a6, byte bAdditiveUnk)
{
_forcedControlState = null;
_rmiWalkHook.Original(self, sumLeft, sumForward, sumTurnLeft, haveBackwardOrStrafe, a6, bAdditiveUnk);

// TODO: we really need to introduce some extra checks that PlayerMoveController::readInput does - sometimes it skips reading input, and returning something non-zero breaks stuff...
var movementAllowed = bAdditiveUnk == 0 && _rmiWalkIsInputEnabled1(self) && _rmiWalkIsInputEnabled2(self);
var movementAllowed = bAdditiveUnk == 0 && _rmiWalkIsInputEnabled1(self) && _rmiWalkIsInputEnabled2(self) && !NavmeshActive();
var misdirectionMode = PlayerHasMisdirection();
if (!movementAllowed && misdirectionMode)
{
Expand Down
2 changes: 1 addition & 1 deletion BossMod/Framework/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public unsafe Plugin(IDalamudPluginInterface dalamud, ICommandManager commandMan
_bossmod = new(_ws);
_zonemod = new(_ws);
_hintsBuilder = new(_ws, _bossmod, _zonemod);
_movementOverride = new();
_movementOverride = new(dalamud);
_amex = new(_ws, _hints, _movementOverride);
_wsSync = new(_ws, _amex);
_rotation = new(_rotationDB, _bossmod, _hints);
Expand Down

0 comments on commit b577ebf

Please sign in to comment.