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

Commit

Permalink
fix: fixed canceling countdown error.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Apr 1, 2023
1 parent 9d2f912 commit cf33a39
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private bool TargetAreaFriend(float range, bool mustUse, PlayerCharacter player)

//如果当前目标是Boss且有身位,放他身上。
if (Service.TargetManager.Target is BattleChara b && b.DistanceToPlayer() < range &&
b.IsBoss() && b.HasPositional() && b.HitboxRadius < _action.EffectRange + 2)
b.IsBoss() && b.HasPositional() && b.HitboxRadius <= 8)
{
_position = b.Position;
}
Expand Down
12 changes: 11 additions & 1 deletion RotationSolver.Basic/Service.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public class Service : IDisposable

private static IntPtr _countDown = IntPtr.Zero;

public static float CountDownTime => _countDown == IntPtr.Zero ? 0 : Math.Max(0, Marshal.PtrToStructure<float>(_countDown + 0x2c));
static float _lastTime = 0;
public static float CountDownTime { get; private set; }

public static GetChatBoxModuleDelegate GetChatBox { get; private set; }

Expand All @@ -58,9 +59,17 @@ public Service()
SigScanner.ScanText("48 89 5C 24 ?? 57 48 83 EC 20 48 8B FA 48 8B D9 45 84 C9"));

SignatureHelper.Initialise(this);
Framework.Update += Framework_Update;
_countdownTimerHook?.Enable();
}

private void Framework_Update(Framework framework)
{
var value = _countDown == IntPtr.Zero ? 0 : Math.Max(0, Marshal.PtrToStructure<float>(_countDown + 0x2c));
if (_lastTime == value) CountDownTime = 0;
else CountDownTime = _lastTime = value;
}

private IntPtr CountdownTimerFunc(IntPtr value)
{
_countDown = value;
Expand All @@ -70,6 +79,7 @@ private IntPtr CountdownTimerFunc(IntPtr value)
public void Dispose()
{
_countdownTimerHook?.Dispose();
Framework.Update -= Framework_Update;
}
public static PluginConfiguration Config { get; set; }

Expand Down
8 changes: 8 additions & 0 deletions RotationSolver/Commands/RSCommands_Actions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ private static void CancelState()
if (DataCenter.StateType != StateCommandType.Cancel) DoStateCommandType(StateCommandType.Cancel);
}

static float _lastCountdownTime = 0;
internal static void UpdateRotationState()
{
if (Service.Conditions[ConditionFlag.LoggingOut])
Expand All @@ -92,9 +93,16 @@ internal static void UpdateRotationState()
{
CancelState();
}
//Cancel when pull
else if (Service.CountDownTime == 0 && _lastCountdownTime > 0.2f)
{
_lastCountdownTime = 0;
CancelState();
}
//Auto start at count Down.
else if (Service.Config.StartOnCountdown && Service.CountDownTime > 0)
{
_lastCountdownTime = Service.CountDownTime;
if (DataCenter.StateType == StateCommandType.Cancel)
{
DoStateCommandType(StateCommandType.Smart);
Expand Down
184 changes: 91 additions & 93 deletions RotationSolver/Updaters/TimeLineUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,134 +4,132 @@
using RotationSolver.UI;
using System.Diagnostics;

namespace RotationSolver.Updaters
namespace RotationSolver.Updaters;

internal class TimeLineUpdater
{
internal class TimeLineUpdater
{
static string _timelineFolder;
static string _timelineFolder;

static IEnumerable<MajorConditionSet> _conditionSet;
public static MajorConditionSet RightSet => _conditionSet?.ElementAtOrDefault(Service.Config.TimelineIndex);
static IEnumerable<MajorConditionSet> _conditionSet;
public static MajorConditionSet RightSet => _conditionSet?.ElementAtOrDefault(Service.Config.TimelineIndex);

public static string[] ConditionSetsName => _conditionSet?.Select(s => s.Name).ToArray() ?? new string[0];
public static string[] ConditionSetsName => _conditionSet?.Select(s => s.Name).ToArray() ?? new string[0];


public static void UpdateTimelineAction()
{
if (_conditionSet == null) return;
var customRotation = RotationUpdater.RightNowRotation;
if (customRotation == null) return;
public static void UpdateTimelineAction()
{
if (_conditionSet == null) return;
var customRotation = RotationUpdater.RightNowRotation;
if (customRotation == null) return;

var allActions = RotationUpdater.RightRotationBaseActions;
var allActions = RotationUpdater.RightRotationBaseActions;

var set = RightSet;
if (set == null) return;
var set = RightSet;
if (set == null) return;

bool find = false;
foreach (var conditionPair in set.Conditions)
{
var nextAct = allActions.FirstOrDefault(a => a.ID == conditionPair.Key);
if (nextAct == null) continue;
bool find = false;
foreach (var conditionPair in set.Conditions)
{
var nextAct = allActions.FirstOrDefault(a => a.ID == conditionPair.Key);
if (nextAct == null) continue;

if (!conditionPair.Value.IsTrue(customRotation)) continue;
if (!conditionPair.Value.IsTrue(customRotation)) continue;

DataCenter.TimeLineAction = nextAct;
find = true;
break;
}
if (!find)
{
DataCenter.TimeLineAction = null;
}
DataCenter.TimeLineAction = nextAct;
find = true;
break;
}

public static void Enable(string folder)
if (!find)
{
_timelineFolder = folder;
if (!Directory.Exists(_timelineFolder)) Directory.CreateDirectory(_timelineFolder);

_conditionSet = MajorConditionSet.Read(_timelineFolder);
DataCenter.TimeLineAction = null;
}
}

public static void SaveFiles()
{
try
{
Directory.Delete(_timelineFolder);
Directory.CreateDirectory(_timelineFolder);
}
catch
{
public static void Enable(string folder)
{
_timelineFolder = folder;
if (!Directory.Exists(_timelineFolder)) Directory.CreateDirectory(_timelineFolder);

}
foreach (var set in _conditionSet)
{
set.Save(_timelineFolder);
}
}
_conditionSet = MajorConditionSet.Read(_timelineFolder);
}

private static void AddNew()
public static void SaveFiles()
{
try
{
const string conditionName = "Unnamed";
if (!_conditionSet.Any(c => c.Name == conditionName))
{
_conditionSet = _conditionSet.Union(new[] { new MajorConditionSet(conditionName) });
}
Directory.Delete(_timelineFolder);
Directory.CreateDirectory(_timelineFolder);
}
catch
{

private static void Delete(string name)
}
foreach (var set in _conditionSet)
{
_conditionSet = _conditionSet.Where(c => c.Name != name);
set.Save(_timelineFolder);
}
}

public static void DrawHeader()
private static void AddNew()
{
const string conditionName = "Unnamed";
if (!_conditionSet.Any(c => c.Name == conditionName))
{
var set = RightSet;
bool hasSet = set != null;

if (hasSet)
{
ImGuiHelper.SetNextWidthWithName(set.Name);
ImGui.InputText("##MajorConditionSet", ref set.Name, 100);
_conditionSet = _conditionSet.Union(new[] { new MajorConditionSet(conditionName) });
}
}

ImGui.SameLine();
}
private static void Delete(string name)
{
_conditionSet = _conditionSet.Where(c => c.Name != name);
}

var combos = ConditionSetsName;
if (combos != null && combos.Length > Service.Config.TimelineIndex)
{
ImGui.SetNextItemWidth(ImGui.CalcTextSize(combos[Service.Config.TimelineIndex]).X + 30);
}
else
{
ImGui.SetNextItemWidth(30);
}
public static void DrawHeader()
{
var set = RightSet;
bool hasSet = set != null;

ImGui.Combo("##MajorConditionCombo", ref Service.Config.TimelineIndex, combos, combos.Length);
if (hasSet)
{
ImGuiHelper.SetNextWidthWithName(set.Name);
ImGui.InputText("##MajorConditionSet", ref set.Name, 100);

ImGui.SameLine();
}

var combos = ConditionSetsName;
if (combos != null && combos.Length > Service.Config.TimelineIndex)
{
ImGui.SetNextItemWidth(ImGui.CalcTextSize(combos[Service.Config.TimelineIndex]).X + 30);
}
else
{
ImGui.SetNextItemWidth(30);
}

if (hasSet)
{
if (ImGuiHelper.IconButton(Dalamud.Interface.FontAwesomeIcon.Ban, "##DeleteTimelineConditionSet"))
{
Delete(set.Name);
}
ImGui.Combo("##MajorConditionCombo", ref Service.Config.TimelineIndex, combos, combos.Length);

ImGui.SameLine();
}
ImGui.SameLine();

if (ImGuiHelper.IconButton(Dalamud.Interface.FontAwesomeIcon.Plus, "##AddNewTimelineConditionSet"))

if (hasSet)
{
if (ImGuiHelper.IconButton(Dalamud.Interface.FontAwesomeIcon.Ban, "##DeleteTimelineConditionSet"))
{
AddNew();
Delete(set.Name);
}

ImGui.SameLine();
if (ImGuiHelper.IconButton(Dalamud.Interface.FontAwesomeIcon.Folder, "##OpenDefinationFolder"))
{
Process.Start("explorer.exe", _timelineFolder);
}
}

if (ImGuiHelper.IconButton(Dalamud.Interface.FontAwesomeIcon.Plus, "##AddNewTimelineConditionSet"))
{
AddNew();
}

ImGui.SameLine();
if (ImGuiHelper.IconButton(Dalamud.Interface.FontAwesomeIcon.Folder, "##OpenDefinationFolder"))
{
Process.Start("explorer.exe", _timelineFolder);
}
}
}
3 changes: 0 additions & 3 deletions RotationSolver/Watcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ private static unsafe void ReceiveAbilityEffect(uint sourceId, IntPtr sourceChar
ShowStr = set.ToString();

//获得身为技能是否正确flag
//Marshal.ReadByte(effectArray + 3);
RecordAction(set.Target, set.Action, effectArray->Param2);
}

Expand Down Expand Up @@ -99,8 +98,6 @@ private static unsafe void RecordAction(GameObject tar, Action action, byte flag
}
}



public void Dispose()
{
_receiveAbilityHook?.Dispose();
Expand Down

0 comments on commit cf33a39

Please sign in to comment.