Skip to content

Commit

Permalink
Slight refactoring of the above.
Browse files Browse the repository at this point in the history
  • Loading branch information
awgil committed Jan 18, 2025
1 parent 9ca267c commit f2147e7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
4 changes: 2 additions & 2 deletions BossMod/ActionTweaks/AutoAutosTweak.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public bool ShouldPreventAutoActivation(uint spellId)
return Enabled && ws.Client.CountdownRemaining > PrePullThreshold && !(ws.Party.Player()?.InCombat ?? false);
}

public bool GetDesiredState(bool currentState, ulong? targetIdOverride = null)
public bool GetDesiredState(bool currentState, ulong targetId)
{
if (!Enabled || _lastActionDisabledAutos)
return currentState;
Expand All @@ -26,7 +26,7 @@ public bool GetDesiredState(bool currentState, ulong? targetIdOverride = null)
if (player == null || player.IsDead || player.Statuses.Any(s => s.ID is 418 or 2648)) // transcendent
return currentState;

var target = ws.Actors.Find(targetIdOverride ?? player.TargetID);
var target = ws.Actors.Find(targetId);
if (target == null || target.IsAlly)
return currentState;

Expand Down
2 changes: 1 addition & 1 deletion BossMod/Debug/DebugAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public void DrawDutyActions()

public void DrawAutoAttack()
{
var aa = UIState.Instance()->WeaponState.IsAutoAttacking;
var aa = UIState.Instance()->WeaponState.AutoAttackState.IsAutoAttacking;
if (_autoAttack != aa)
Service.Log($"AA state changed: {_autoAttack} -> {aa}");
_autoAttack = aa;
Expand Down
27 changes: 14 additions & 13 deletions BossMod/Framework/ActionManagerEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,12 @@ public sealed unsafe class ActionManagerEx : IDisposable
private readonly HookAddress<ActionManager.Delegates.UseActionLocation> _useActionLocationHook;
private readonly HookAddress<PublicContentBozja.Delegates.UseFromHolster> _useBozjaFromHolsterDirectorHook;
private readonly HookAddress<ActionEffectHandler.Delegates.Receive> _processPacketActionEffectHook;
private readonly HookAddress<AutoAttackState.Delegates.SetImpl> _setAutoAttackStateHook;

private delegate void ExecuteCommandGTDelegate(uint commandId, Vector3* position, uint param1, uint param2, uint param3, uint param4);
private readonly ExecuteCommandGTDelegate _executeCommandGT;
private DateTime _nextAllowedExecuteCommand;

private delegate byte StartAutoattackDelegate(bool* playerAutoState, bool wantStart, char unk1, byte unk2);
private readonly HookAddress<StartAutoattackDelegate> _startAutosHook;

public ActionManagerEx(WorldState ws, AIHints hints, MovementOverride movement)
{
_ws = ws;
Expand All @@ -91,7 +89,7 @@ public ActionManagerEx(WorldState ws, AIHints hints, MovementOverride movement)
_useActionLocationHook = new(ActionManager.Addresses.UseActionLocation, UseActionLocationDetour);
_useBozjaFromHolsterDirectorHook = new(PublicContentBozja.Addresses.UseFromHolster, UseBozjaFromHolsterDirectorDetour);
_processPacketActionEffectHook = new(ActionEffectHandler.Addresses.Receive, ProcessPacketActionEffectDetour);
_startAutosHook = new("E8 ?? ?? ?? ?? EB 15 41 B0 01", StartAutosDetour);
_setAutoAttackStateHook = new(AutoAttackState.Addresses.SetImpl, SetAutoAttackStateDetour);

var executeCommandGTAddress = Service.SigScanner.ScanText("E8 ?? ?? ?? ?? EB 1E 48 8B 53 08");
Service.Log($"ExecuteCommandGT address: 0x{executeCommandGTAddress:X}");
Expand All @@ -100,12 +98,12 @@ public ActionManagerEx(WorldState ws, AIHints hints, MovementOverride movement)

public void Dispose()
{
_setAutoAttackStateHook.Dispose();
_processPacketActionEffectHook.Dispose();
_useBozjaFromHolsterDirectorHook.Dispose();
_useActionLocationHook.Dispose();
_useActionHook.Dispose();
_updateHook.Dispose();
_startAutosHook.Dispose();
_oocActionsTweak.Dispose();
}

Expand Down Expand Up @@ -400,8 +398,8 @@ private void UpdateDetour(ActionManager* self)
UIState.Instance()->Hotbar.CancelCast();
ForceCancelCastNextFrame = false;

var autosEnabled = UIState.Instance()->WeaponState.IsAutoAttacking;
if (_autoAutosTweak.GetDesiredState(autosEnabled) != autosEnabled)
var autosEnabled = UIState.Instance()->WeaponState.AutoAttackState.IsAutoAttacking;
if (_autoAutosTweak.GetDesiredState(autosEnabled, _ws.Party.Player()?.TargetID ?? 0) != autosEnabled)
_inst->UseAction(CSActionType.GeneralAction, 1);

if (_hints.WantDismount && _dismountTweak.AllowDismount())
Expand Down Expand Up @@ -551,12 +549,15 @@ private void HandleActionRequest(ActionID action, uint seq, ulong targetID, Vect
ActionRequestExecuted.Fire(new(action, targetID, targetPos, seq, _inst->AnimationLock, castElapsed, castTotal, recastElapsed, recastTotal));
}

private byte StartAutosDetour(bool* playerIsAutoattacking, bool wantStart, char unk1, byte unk2)
// note: we can't rely on worldstate target id, it might not be updated when this is called
// TODO: current implementation means that we'll check desired state twice (once before making a decision to start autos, then again in the hook)
private bool SetAutoAttackStateDetour(AutoAttackState* self, bool value, bool sendPacket, bool isInstant)
{
// in some cases, this function is called before player target ID is updated in worldstate; e.g. right clicking a passive mob
if (wantStart && !_autoAutosTweak.GetDesiredState(true, TargetSystem.Instance()->GetTargetObjectId()))
return 1;

return _startAutosHook.Original(playerIsAutoattacking, wantStart, unk1, unk2);
if (value && !_autoAutosTweak.GetDesiredState(true, TargetSystem.Instance()->GetTargetObjectId()))
{
Service.Log($"[AMEx] Prevented starting autoattacks");
return true;
}
return _setAutoAttackStateHook.Original(self, value, sendPacket, isInstant);
}
}

0 comments on commit f2147e7

Please sign in to comment.