Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
fix: add vfx condition.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Nov 1, 2023
1 parent e02234c commit 507fdc1
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 3 deletions.
17 changes: 17 additions & 0 deletions RotationSolver.Basic/Configuration/Conditions/TargetCondition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,22 @@ protected override bool IsTrueInside(ICustomRotation rotation)
}
}
break;

case TargetConditionType.Vfx:
foreach (var effect in DataCenter.VfxNewDatas.Reverse())
{
var time = effect.TimeDuration.TotalSeconds;
if (time > DistanceOrTime && time < TimeEnd
&& effect.Path == CastingActionName)
{
if (!FromSelf || effect.ObjectId == tar.ObjectId)
{
result = true;
break;
}
}
}
break;
}

return Condition ? !result : result;
Expand All @@ -157,4 +173,5 @@ internal enum TargetConditionType : byte
MP,
TargetName,
ObjectEffect,
Vfx,
}
22 changes: 22 additions & 0 deletions RotationSolver.Basic/Data/VfxNewData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using ECommons.DalamudServices;

namespace RotationSolver.Basic.Data;

internal readonly struct VfxNewData
{
public readonly uint ObjectId;
public readonly string Path;

public readonly DateTime Time;

public readonly TimeSpan TimeDuration => DateTime.Now - Time;

public VfxNewData(uint objectId, string path)
{
Time = DateTime.Now;
ObjectId = objectId;
Path = path;
}

public override string ToString() => $"Object Effect: {Svc.Objects.SearchById(ObjectId)?.Name ?? "Object"}: {Path}";
}
2 changes: 2 additions & 0 deletions RotationSolver.Basic/DataCenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ internal static class DataCenter
{
internal static Queue<MapEffectData> MapEffects { get; } = new(64);
internal static Queue<ObjectEffectData> ObjectEffects { get; } = new(64);
internal static Queue<VfxNewData> VfxNewDatas { get; } = new(64);

/// <summary>
/// This one never be null.
Expand Down Expand Up @@ -462,6 +463,7 @@ internal static void ResetAllRecords()

MapEffects.Clear();
ObjectEffects.Clear();
VfxNewDatas.Clear();
}

internal static void AddDamageRec(float damageRatio)
Expand Down
4 changes: 2 additions & 2 deletions RotationSolver.Basic/Rotations/CustomRotation_Actions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,13 @@ public override bool CanUse(out IAction act, CanUseOption option = CanUseOption.
/// </summary>
public static IBaseAction VariantCure { get; } = new RoleAction(ActionID.VariantCure,
new JobRole[] { JobRole.Melee, JobRole.Tank, JobRole.RangedMagical, JobRole.RangedPhysical },
ActionOption.Heal | ActionOption.DutyAction);
ActionOption.Heal | ActionOption.DutyAction | ActionOption.EndSpecial);

/// <summary>
///
/// </summary>
public static IBaseAction VariantCure2 { get; } = new RoleAction(ActionID.VariantCure2,
new JobRole[] { JobRole.Melee, JobRole.Tank, JobRole.RangedMagical, JobRole.RangedPhysical }, ActionOption.Heal | ActionOption.DutyAction);
new JobRole[] { JobRole.Melee, JobRole.Tank, JobRole.RangedMagical, JobRole.RangedPhysical }, ActionOption.Heal | ActionOption.DutyAction | ActionOption.EndSpecial);

/// <summary>
///
Expand Down
1 change: 1 addition & 0 deletions RotationSolver/Localization/EnumTranslations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ internal static class EnumTranslations
TargetConditionType.MP => LocalizationManager.RightLang.TargetConditionType_MP,
TargetConditionType.TargetName => LocalizationManager.RightLang.TargetConditionType_TargetName,
TargetConditionType.ObjectEffect => LocalizationManager.RightLang.TargetConditionType_ObjectEffect,
TargetConditionType.Vfx => LocalizationManager.RightLang.TargetConditionType_Vfx,
_ => string.Empty,
};

Expand Down
1 change: 1 addition & 0 deletions RotationSolver/Localization/Strings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ internal class Strings
public string TargetConditionType_MP { get; set; } = "MP";
public string TargetConditionType_TargetName { get; set; } = "Target Name";
public string TargetConditionType_ObjectEffect { get; set; } = "Object Effect";
public string TargetConditionType_Vfx { get; set; } = "Vfx";

#endregion

Expand Down
33 changes: 33 additions & 0 deletions RotationSolver/UI/ConditionDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,8 @@ private static void DrawAfter(this TargetCondition targetCondition, ICustomRotat
case TargetConditionType.InCombat:
case TargetConditionType.CastingAction:
case TargetConditionType.TargetName:
case TargetConditionType.ObjectEffect:
case TargetConditionType.Vfx:
combos = new string[]
{
LocalizationManager.RightLang.ActionSequencer_Is,
Expand Down Expand Up @@ -974,6 +976,37 @@ void DrawStatusIcon()
targetCondition.TimeEnd = Math.Min(Math.Max(targetCondition.DistanceOrTime, targetCondition.TimeEnd), MAX);
}

ImGui.SameLine();
check = targetCondition.FromSelf ? 1 : 0;
if (ImGuiHelper.SelectableCombo($"From Self {targetCondition.GetHashCode()}", new string[]
{
LocalizationManager.RightLang.ActionSequencer_StatusAll,
LocalizationManager.RightLang.ActionSequencer_StatusSelf,
}, ref check))
{
targetCondition.FromSelf = check != 0;
}
break;

case TargetConditionType.Vfx:
ImGui.SameLine();

ImGui.Text("Vfx Path:");
ImGuiHelper.SetNextWidthWithName(targetCondition.CastingActionName);
ImGui.InputText($"Name##TargetName{targetCondition.GetHashCode()}", ref targetCondition.CastingActionName, 128);

ImGui.SameLine();

ImGui.Text("Time Offset:");
ImGui.SameLine();

ImGui.SetNextItemWidth(150 * ImGuiHelpers.GlobalScale);
if (ImGui.DragFloatRange2($"##TimeOffset {targetCondition.GetHashCode()}", ref targetCondition.DistanceOrTime, ref targetCondition.TimeEnd, 0.1f, MIN, MAX))
{
targetCondition.DistanceOrTime = Math.Max(Math.Min(targetCondition.DistanceOrTime, targetCondition.TimeEnd), MIN);
targetCondition.TimeEnd = Math.Min(Math.Max(targetCondition.DistanceOrTime, targetCondition.TimeEnd), MAX);
}

ImGui.SameLine();
check = targetCondition.FromSelf ? 1 : 0;
if (ImGuiHelper.SelectableCombo($"From Self {targetCondition.GetHashCode()}", new string[]
Expand Down
32 changes: 31 additions & 1 deletion RotationSolver/Watcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public static class Watcher
private unsafe delegate long ProcessObjectEffect(GameObject* a1, ushort a2, ushort a3, long a4);
private static Hook<ProcessObjectEffect> _processObjectEffectHook;

private delegate IntPtr ActorVfxCreate(string path, IntPtr a2, IntPtr a3, float a4, char a5, ushort a6, char a7);
private static Hook<ActorVfxCreate> _actorVfxCreateHook;

private static ICallGateSubscriber<object, object> IpcSubscriber;

Expand All @@ -33,13 +35,16 @@ public static void Enable()
unsafe
{
#if DEBUG

_useActionHook = Svc.Hook.HookFromSignature<OnUseAction>("E8 ?? ?? ?? ?? EB 64 B1 01", UseActionDetour);
//_useActionHook.Enable();
#endif
//From https://github.com/PunishXIV/Splatoon/blob/main/Splatoon/Memory/ObjectEffectProcessor.cs#L14
_processObjectEffectHook = Svc.Hook.HookFromSignature<ProcessObjectEffect>("40 53 55 56 57 48 81 EC ?? ?? ?? ?? 48 8B 05 ?? ?? ?? ?? 48 33 C4 48 89 84 24 ?? ?? ?? ?? 0F B7 FA", ProcessObjectEffectDetour);
_processObjectEffectHook.Enable();

//From https://github.com/0ceal0t/Dalamud-VFXEditor/blob/main/VFXEditor/Interop/Constants.cs#L12
_actorVfxCreateHook = Svc.Hook.HookFromSignature<ActorVfxCreate>("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", ActorVfxNewHandler);
_actorVfxCreateHook.Enable();
}
IpcSubscriber = Svc.PluginInterface.GetIpcSubscriber<object, object>("PingPlugin.Ipc");
IpcSubscriber.Subscribe(UpdateRTTDetour);
Expand Down Expand Up @@ -73,6 +78,29 @@ public static void Disable()
ActionEffect.ActionEffectEvent -= ActionFromSelf;
}

private static IntPtr ActorVfxNewHandler(string path, IntPtr a2, IntPtr a3, float a4, char a5, ushort a6, char a7)
{
try
{
if (DataCenter.VfxNewDatas.Count >= 64)
{
DataCenter.VfxNewDatas.TryDequeue(out _);
}

var obj = Svc.Objects.CreateObjectReference(a2);
var effect = new VfxNewData(obj?.ObjectId ?? Dalamud.Game.ClientState.Objects.Types.GameObject.InvalidGameObjectId, path);
DataCenter.VfxNewDatas.Enqueue(effect);
#if DEBUG
Svc.Log.Debug(effect.ToString());
#endif
}
catch (Exception e)
{
Svc.Log.Warning(e, "Failed to load the vfx value!");
}
return _actorVfxCreateHook.Original(path, a2, a3, a4, a5, a6, a7);
}

private static unsafe long ProcessObjectEffectDetour(GameObject* a1, ushort a2, ushort a3, long a4)
{
try
Expand All @@ -84,6 +112,8 @@ private static unsafe long ProcessObjectEffectDetour(GameObject* a1, ushort a2,

var effect = new ObjectEffectData(a1->ObjectID, a2, a3);
DataCenter.ObjectEffects.Enqueue(effect);

Svc.Objects.CreateObjectReference((nint)a1);
#if DEBUG
Svc.Log.Debug(effect.ToString());
#endif
Expand Down

0 comments on commit 507fdc1

Please sign in to comment.