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

Commit

Permalink
fix: fixed timeline check.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Mar 2, 2024
1 parent a2fcba6 commit ffcd482
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 46 deletions.
4 changes: 2 additions & 2 deletions Resources/RotationSolverRecord.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"ClickingCount": 92543,
"SayingHelloCount": 133,
"ClickingCount": 93113,
"SayingHelloCount": 134,
"SaidUsers": []
}
17 changes: 9 additions & 8 deletions RotationSolver.Basic/Data/TimelineItem.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using ECommons.DalamudServices;
using Newtonsoft.Json.Linq;
using System.Text.RegularExpressions;
using static Dalamud.Interface.Utility.Raii.ImRaii;

namespace RotationSolver.Basic.Data;
internal enum TimelineType : byte
Expand All @@ -15,7 +14,7 @@ internal enum TimelineType : byte
ActorControl,
}

internal readonly struct TimelineItem(float time, string name, TimelineType type, JObject? obj, RaidLangs langs)
internal readonly struct TimelineItem(float time, string name, TimelineType type, JObject? obj, RaidLangs langs, float? jumpTime, float windowMin, float windowMax)
{
private RaidLangs.Lang Lang
{
Expand Down Expand Up @@ -50,6 +49,8 @@ public string Name
}
}

public bool IsInWindow => DataCenter.RaidTimeRaw >= Time - windowMin && DataCenter.RaidTimeRaw <= Time - windowMax;

public bool IsShown => Name is not "--Reset--" and not "--sync--";

public bool this[string propertyName, uint matchValue]
Expand Down Expand Up @@ -108,8 +109,8 @@ public string[] this[string propertyName]
}
}

public TimelineItem(float time, string name, string type, JObject? obj, RaidLangs langs)
: this(time, name, GetTypeFromName(type), obj, langs)
public TimelineItem(float time, string name, string type, JObject? obj, RaidLangs langs, float? jumpTime, float windowMin, float windowMax)
: this(time, name, GetTypeFromName(type), obj, langs, jumpTime, windowMin, windowMax)
{

}
Expand Down Expand Up @@ -163,17 +164,17 @@ public void UpdateRaidTimeOffset()
var timeOffset = Time - DataCenter.RaidTimeRaw;
Svc.Log.Debug($"Set the {nameof(DataCenter.RaidTimeRaw)} to {Time}, added {timeOffset}s");
#endif
DataCenter.RaidTimeRaw = Time;
DataCenter.RaidTimeRaw = jumpTime ?? Time;
}
}

public override string ToString()
{
return $"""
IsShown: {IsShown},
Time: {Time},
Name: {Name},
Type: {Type},
Time: {Time}, JumpTime: {jumpTime ?? -1},
Name: {Name}, Type: {Type},
Window: {windowMin}, {windowMax},
Ids: {string.Join(", ", this["id"])}
""";
}
Expand Down
2 changes: 1 addition & 1 deletion RotationSolver/RotationSolverPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public sealed class RotationSolverPlugin : IDalamudPlugin, IDisposable
public RotationSolverPlugin(DalamudPluginInterface pluginInterface)
{
ECommonsMain.Init(pluginInterface, this, ECommons.Module.DalamudReflector, ECommons.Module.ObjectFunctions);
ThreadLoadImageHandler.TryGetIconTextureWrap(0, false, out _);
ThreadLoadImageHandler.TryGetIconTextureWrap(0, true, out _);
IconSet.InIt();

//Init!
Expand Down
2 changes: 0 additions & 2 deletions RotationSolver/UI/PainterManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
using Dalamud.Game.ClientState.Objects.SubKinds;
using ECommons.DalamudServices;
using ECommons.GameHelpers;
using ECommons.ImGuiMethods;
using RotationSolver.Basic.Configuration;
using RotationSolver.Updaters;
using XIVPainter;
using XIVPainter.Element3D;
using XIVPainter.ElementSpecial;
using static Dalamud.Interface.Utility.Raii.ImRaii;

namespace RotationSolver.UI;

Expand Down
10 changes: 9 additions & 1 deletion RotationSolver/UI/RotationConfigWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,15 @@ static string GetName(TerritoryType? territory)

ImGui.TableNextColumn();

ImGui.Text(TimeSpan.FromSeconds(item.Time).ToString("mm\\:ss\\.f"));
var str = TimeSpan.FromSeconds(item.Time).ToString("hh\\:mm\\:ss\\.f");
if(DataCenter.RaidTimeRaw < item.Time && DataCenter.RaidTimeRaw > item.Time - 3)
{
ImGui.TextColored(ImGuiColors.HealerGreen, str);
}
else
{
ImGui.Text(str);
}

ImGui.TableNextColumn();
AddButton();
Expand Down
3 changes: 1 addition & 2 deletions RotationSolver/Updaters/ActionUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ private static void UpdateCombatTime()
{
foreach (var item in DataCenter.TimelineItems)
{
if (item.IsShown) continue;
if (item.Time < DataCenter.RaidTimeRaw) continue;
if (!item.IsInWindow) continue;
if (item.Type is not TimelineType.InCombat) continue;

item.UpdateRaidTimeOffset();
Expand Down
124 changes: 95 additions & 29 deletions RotationSolver/Updaters/RaidTimeUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
using RotationSolver.Basic.Configuration.Timeline;
using RotationSolver.UI;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Xml.Linq;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace RotationSolver.Updaters;
internal static partial class RaidTimeUpdater
Expand Down Expand Up @@ -72,25 +71,33 @@ internal static async void EnableAsync()
Svc.DutyState.DutyWiped += DutyState_DutyWiped;
Svc.DutyState.DutyCompleted += DutyState_DutyWiped;

using var client = new HttpClient();
var message = await client.GetAsync("https://raw.githubusercontent.com/xpdota/event-trigger/master/timelines/src/main/resources/timelines.csv");

if (!message.IsSuccessStatusCode)
try
{
return;
}
using var client = new HttpClient();
var message = await client.GetAsync("https://raw.githubusercontent.com/xpdota/event-trigger/master/timelines/src/main/resources/timelines.csv");

var str = await message.Content.ReadAsStringAsync();
if (!message.IsSuccessStatusCode)
{
return;
}

foreach (var pair in str.Split('\n'))
{
var items = pair.Split(',');
if (items.Length < 2) continue;
var str = await message.Content.ReadAsStringAsync();

foreach (var pair in str.Split('\n'))
{
var items = pair.Split(',');
if (items.Length < 2) continue;

if (!uint.TryParse(items[0], out var id)) continue;
var name = items[1][1..^1];
PathForRaids[id] = name;
if (!uint.TryParse(items[0], out var id)) continue;
var name = items[1][1..^1];
PathForRaids[id] = name;
}
}
catch(Exception ex)
{
Svc.Log.Warning(ex, "Failed to download the timelines!");
}


Svc.ClientState.TerritoryChanged += ClientState_TerritoryChanged;
ClientState_TerritoryChanged(Svc.ClientState.TerritoryType);
Expand All @@ -108,7 +115,7 @@ internal static void Disable()
Svc.Chat.ChatMessage -= Chat_ChatMessage;
}

private static void DutyState_DutyWiped(object? sender, ushort e)
private static void DutyState_DutyWiped(object? _, ushort e)
{
DataCenter.RaidTimeRaw = -1;
}
Expand All @@ -123,8 +130,7 @@ private static void Chat_ChatMessage(Dalamud.Game.Text.XivChatType type, uint se

foreach (var item in DataCenter.TimelineItems)
{
if (item.IsShown) continue;
if (item.Time < DataCenter.RaidTimeRaw) continue;
if (!item.IsInWindow) continue;
if (item.Type is not TimelineType.GameLog) continue;

var typeString = ((uint)type).ToString("X4");
Expand Down Expand Up @@ -169,8 +175,7 @@ private static void OnCast(IntPtr dataPtr, uint targetActorId)

foreach (var item in DataCenter.TimelineItems)
{
if (item.IsShown) continue;
if (item.Time < DataCenter.RaidTimeRaw) continue;
if (!item.IsInWindow) continue;
if (item.Type is not TimelineType.StartsUsing) continue;

if (!item["id", ReadUshort(dataPtr, 0)]) continue;
Expand All @@ -188,8 +193,7 @@ private static void OnEffect(IntPtr dataPtr, uint targetActorId)

foreach (var item in DataCenter.TimelineItems)
{
if (item.IsShown) continue;
if (item.Time < DataCenter.RaidTimeRaw) continue;
if (!item.IsInWindow) continue;
if (item.Type is not TimelineType.Ability) continue;

if (!item["id", ReadUint(dataPtr, 28)]) continue;
Expand All @@ -207,8 +211,7 @@ private static void OnActorControl(IntPtr dataPtr)
{
foreach (var item in DataCenter.TimelineItems)
{
if (item.IsShown) continue;
if (item.Time < DataCenter.RaidTimeRaw) continue;
if (!item.IsInWindow) continue;
if (item.Type is not TimelineType.ActorControl) continue;

if (!item["command", ReadUint(dataPtr, 8)]) continue;
Expand All @@ -226,8 +229,7 @@ private static void OnSystemLogMessage(IntPtr dataPtr)
{
foreach (var item in DataCenter.TimelineItems)
{
if (item.IsShown) continue;
if (item.Time < DataCenter.RaidTimeRaw) continue;
if (!item.IsInWindow) continue;
if (item.Type is not TimelineType.SystemLogMessage) continue;

if (!item["id", ReadUint(dataPtr, 4)]) continue;
Expand Down Expand Up @@ -342,7 +344,28 @@ static async Task<TimelineItem[]> DownloadRaidTimeAsync(string path, RaidLangs l
var str = await message.Content.ReadAsStringAsync();

var result = new List<TimelineItem>();
foreach (var timelineItem in TimeLineItem().Matches(str).Cast<Match>())
var matches = TimeLineItem().Matches(str).Cast<Match>();
var dict = new Dictionary<string, float>();

foreach (var timelineItem in matches)
{
try
{
var timeline = timelineItem.Value;
if (!LabelHeader().IsMatch(timeline)) continue;

var time = float.Parse(Time().Match(timeline).Value);
var name = Name().Match(timeline).Value[1..^1];

dict[name] = time;
}
catch (Exception e)
{
Svc.Log.Warning(e, "Failed to get the time label");
}
}

foreach (var timelineItem in matches)
{
try
{
Expand All @@ -366,7 +389,38 @@ static async Task<TimelineItem[]> DownloadRaidTimeAsync(string path, RaidLangs l
type = type[1..^2].Split(' ').LastOrDefault() ?? string.Empty;
}

result.Add(new (time, name, type, item, lang));
var jumpTimeStr = JumpTime().Match(timeline).Value;
float? jumpTime = null;
if (jumpTimeStr.Length > 5)
{
jumpTime = float.Parse(jumpTimeStr[5..]);
}
else
{
jumpTimeStr = JumpName().Match(timeline).Value;
if (jumpTimeStr.Length > 7)
{
if (dict.TryGetValue(jumpTimeStr[6..^1], out var t))
{
jumpTime = t;
}
else
{
Svc.Log.Warning($"Failed to parse the jump: {jumpTimeStr}");
}
}
}

var windowStr = WindowTime().Match(timeline).Value;
float windowMin = 2.5f, windowMax = 2.5f;
if (windowStr.Length > 7)
{
var windowStrs = windowStr[7..].Split(',');
windowMin = float.Parse(windowStrs.First());
windowMax = float.Parse(windowStrs.Last());
}

result.Add(new (time, name, type, item, lang, jumpTime, windowMin, windowMax));
}
catch (Exception ex)
{
Expand All @@ -383,6 +437,15 @@ static async Task<TimelineItem[]> DownloadRaidTimeAsync(string path, RaidLangs l
return [..result.OrderBy(i => i.Time)];
}

[GeneratedRegex("jump [\\d\\.]+")]
private static partial Regex JumpTime();

[GeneratedRegex("jump \".*?\"")]
private static partial Regex JumpName();

[GeneratedRegex("window [\\d\\.,]+")]
private static partial Regex WindowTime();

[GeneratedRegex(" .*? {")]
private static partial Regex Type();

Expand All @@ -398,6 +461,9 @@ static async Task<TimelineItem[]> DownloadRaidTimeAsync(string path, RaidLangs l
[GeneratedRegex("^[\\d\\.]+ \".*?\"")]
private static partial Regex TimeHeader();

[GeneratedRegex("^[\\d\\.]+ label \".*?\"")]
private static partial Regex LabelHeader();

[GeneratedRegex("{.*}")]
private static partial Regex ActionGetter();
}
2 changes: 1 addition & 1 deletion RotationSolver/Watcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static void Enable()

//From https://github.com/0ceal0t/Dalamud-VFXEditor/blob/main/VFXEditor/Interop/Constants.cs#L12C48-L12C206
_staticVfxCreateHook = Svc.Hook.HookFromSignature<StaticVfxCreateDelegate>("E8 ?? ?? ?? ?? F3 0F 10 35 ?? ?? ?? ?? 48 89 43 08", StaticVfxNewHandler);
_staticVfxCreateHook.Enable();
//_staticVfxCreateHook.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);
Expand Down

0 comments on commit ffcd482

Please sign in to comment.