Skip to content

Commit

Permalink
Merge pull request #423 from FFXIV-CombatReborn/vfx-fix
Browse files Browse the repository at this point in the history
Vfx Detection Fix
  • Loading branch information
NostraThomas99 authored Oct 4, 2024
2 parents badf6f3 + 49e093d commit 637e559
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 5 deletions.
2 changes: 1 addition & 1 deletion RotationSolver.Basic/Data/VfxNewData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace RotationSolver.Basic.Data;
/// <summary>
/// Represents new VFX data.
/// </summary>
public readonly struct VfxNewData
public readonly record struct VfxNewData
{
/// <summary>
/// Gets the object ID.
Expand Down
5 changes: 3 additions & 2 deletions RotationSolver.Basic/DataCenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ internal static IBattleChara? HostileTarget
internal static List<uint> PrioritizedNameIds { get; set; } = new();
internal static List<uint> BlacklistedNameIds { get; set; } = new();

internal static Queue<VfxNewData> VfxDataQueue { get; } = new(64);
internal static List<VfxNewData> VfxDataQueue { get; } = new();

/// <summary>
/// This one never be null.
Expand Down Expand Up @@ -738,6 +738,7 @@ internal static void ResetAllRecords()
_timeLastActionUsed = DateTime.Now;
_actions.Clear();

AttackedTargets.Clear();
VfxDataQueue.Clear();
}

Expand Down Expand Up @@ -782,7 +783,7 @@ public static bool IsCastingVfx(Func<VfxNewData, bool> isVfx)

try
{
foreach (var item in DataCenter.VfxDataQueue.Reverse())
foreach (var item in DataCenter.VfxDataQueue.OrderBy(v => v.TimeDuration))
{
if (item.TimeDuration.TotalSeconds is > 1 and < 5)
{
Expand Down
36 changes: 35 additions & 1 deletion RotationSolver.Basic/Service.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System.Collections.Concurrent;
using System.Text;
using Dalamud.Utility.Signatures;
using ECommons.DalamudServices;
using ECommons.EzHookManager;
using FFXIVClientStructs.Attributes;
using FFXIVClientStructs.FFXIV.Client.Game;
using Lumina.Excel;
Expand All @@ -19,9 +21,16 @@ internal class Service : IDisposable
public const string REPO = "RotationSolverReborn";
public const int ApiVersion = 4;

[EzHook("40 53 55 56 57 48 81 EC ?? ?? ?? ?? 0F 29 B4 24 ?? ?? ?? ?? 48 8B 05 ?? ?? ?? ?? 48 33 C4 48 89 84 24 ?? ?? ?? ?? 0F B6 AC 24 ?? ?? ?? ?? 0F 28 F3 49 8B F8", nameof(ActorVfxCreateDetour), true)]
private EzHook<ActorVfxCreateDelegate2> actorVfxCreateHook = null!;
private unsafe delegate IntPtr ActorVfxCreateDelegate2(char* a1, nint a2, nint a3, float a4, char a5, ushort a6, char a7);


// From https://GitHub.com/PunishXIV/Orbwalker/blame/master/Orbwalker/Memory.cs#L74-L76
[Signature("F3 0F 10 05 ?? ?? ?? ?? 0F 2E C7", ScanType = ScanType.StaticAddress, Fallibility = Fallibility.Infallible)]
[Signature("F3 0F 10 05 ?? ?? ?? ?? 0F 2E C7", ScanType = ScanType.StaticAddress,
Fallibility = Fallibility.Infallible)]
static IntPtr forceDisableMovementPtr = IntPtr.Zero;

private static unsafe ref int ForceDisableMovement => ref *(int*)(forceDisableMovementPtr + 4);

static bool _canMove = true;
Expand Down Expand Up @@ -49,6 +58,30 @@ internal static unsafe bool CanMove
}
}

private unsafe IntPtr ActorVfxCreateDetour(char* a1, nint a2, nint a3, float a4, char a5, ushort a6, char a7)
{
try
{
var path = Dalamud.Memory.MemoryHelper.ReadString(new nint(a1), Encoding.ASCII, 256);
var obj = Svc.Objects.CreateObjectReference(a2);
if (obj == null || string.IsNullOrEmpty(path))
{
throw new Exception("Failed to create object reference during VfxCreateDetour");
}

//Svc.Log.Verbose($"{obj.Name} is casting {path}");

var newVfx = new VfxNewData(obj.GameObjectId, path);
DataCenter.VfxDataQueue.Add(newVfx);
}
catch (Exception ex)
{
Svc.Log.Warning(ex, "Failed to process VfxCreateDetour");
}

return actorVfxCreateHook!.Original(a1, a2, a3, a4, a5, a6, a7);
}

/// <summary>
/// Gets the remaining countdown time.
/// </summary>
Expand All @@ -70,6 +103,7 @@ internal static unsafe bool CanMove
public Service()
{
Svc.Hook.InitializeFromAttributes(this);
EzSignatureHelper.Initialize(this);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion RotationSolver/RotationSolverPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public RotationSolverPlugin(IDalamudPluginInterface pluginInterface)
windowSystem.AddWindow(_cooldownWindow);
windowSystem.AddWindow(_changelogWindow);
windowSystem.AddWindow(_overlayWindow);
Notify.Success("Overlay Window was added!");
//Notify.Success("Overlay Window was added!");

Svc.PluginInterface.UiBuilder.OpenConfigUi += OnOpenConfigUi;
Svc.PluginInterface.UiBuilder.OpenMainUi += OnOpenConfigUi;
Expand Down
12 changes: 12 additions & 0 deletions RotationSolver/Updaters/MajorUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,18 @@ private static void UpdateWork()

RSCommands.UpdateRotationState();
HotbarHighlightManager.UpdateSettings();

List<VfxNewData> expiredVfx = new List<VfxNewData>();
foreach (var vfx in DataCenter.VfxDataQueue)
{
if (vfx.TimeDuration > TimeSpan.FromSeconds(30))
expiredVfx.Add(vfx);
}

foreach (var vfx in expiredVfx)
{
DataCenter.VfxDataQueue.Remove(vfx);
}
}
catch (Exception ex)
{
Expand Down

0 comments on commit 637e559

Please sign in to comment.