Skip to content

Commit

Permalink
Add compatibility with Dalamud API 11
Browse files Browse the repository at this point in the history
  • Loading branch information
two-zee committed Nov 17, 2024
1 parent 1b01d3b commit f20c8d4
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 67 deletions.
21 changes: 10 additions & 11 deletions src/Data/ComboStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,36 @@ public static void Init(Configuration config) {
comboCache = [];
}

private static Dictionary<uint,List<uint>> GetCombos(uint jobclass, uint level, bool isPvp) {
private static Dictionary<uint, List<uint>> GetCombos(uint jobclass, uint level, bool isPvp) {
GCDTracker.Log.Verbose($"Get combos for class: {jobclass} at level {level}");
return DataStore.ActionSheet
.Where(row => row.ActionCombo.Value.RowId != 0
&& (row.ClassJobCategory.Value?.Name.RawString.Contains(DataStore.ClassSheet.GetRow(jobclass).Abbreviation) ?? false)
&& row.ClassJobCategory.Value.Name.ExtractText().Contains(DataStore.ClassSheet.GetRow(jobclass).Abbreviation.ExtractText())
&& row.ClassJobLevel <= level
&& row.Name.RawString.Length > 0
&& !row.Name.IsEmpty
&& row.IsPvP == isPvp)
.GroupBy(row => row.ActionCombo.Value.RowId)
.ToDictionary(row => row.Key, row => row.Select(act => act.RowId).ToList());
}

public static Dictionary<uint, List<uint>> GetCombos() {
var par = (DataStore.ClientState.LocalPlayer.ClassJob.Id, DataStore.ClientState.LocalPlayer.Level, false,conf.EnabledCTJobs);
par.EnabledCTJobs.TryGetValue(par.Id, out bool enabled);
var par = (DataStore.ClientState.LocalPlayer.ClassJob.RowId, DataStore.ClientState.LocalPlayer.Level, false, conf.EnabledCTJobs);
par.EnabledCTJobs.TryGetValue(par.RowId, out bool enabled);
if (!enabled) return [];
if(comboCache.TryGetValue(par, out var comboDict))
if (comboCache.TryGetValue(par, out var comboDict))
return comboDict;
comboDict = GetCombos(par.Id, par.Level, par.Item3);
ApplyManual(ref comboDict, par.Id, par.Level);
comboDict = GetCombos(par.RowId, par.Level, par.Item3);
ApplyManual(ref comboDict, par.RowId, par.Level);
comboCache.Add(par, comboDict);
return comboDict;
}

private static void ApplyManual(ref Dictionary<uint, List<uint>> comboDict, uint jobclass, uint level) {
if (DataStore.ManualCombo.TryGetValue(jobclass,out var modifications)) {
if (DataStore.ManualCombo.TryGetValue(jobclass, out var modifications)) {
foreach (var (condition, effect) in modifications) {
try {
if (condition(level)) effect(comboDict);
}
catch(Exception e) {
} catch (Exception e) {
GCDTracker.Log.Error("Couldn't apply modification: " + e);
}
}
Expand Down
19 changes: 8 additions & 11 deletions src/Data/DataStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,24 @@
using System.Linq;
using Dalamud.Plugin.Services;

namespace GCDTracker.Data
{
static unsafe class DataStore
{
namespace GCDTracker.Data {
static unsafe class DataStore {
public static IDataManager Lumina;
public static ComboDetail Combo;
public static Action* Action;
public static ActionManager* ActionManager;
public static AtkStage* AtkStage;
public static IClientState ClientState;
public static ICondition Condition;
public static ExcelSheet<Lumina.Excel.GeneratedSheets.Action> ActionSheet;
public static ExcelSheet<Lumina.Excel.GeneratedSheets.ClassJob> ClassSheet;
public static ExcelSheet<Lumina.Excel.Sheets.Action> ActionSheet;
public static ExcelSheet<Lumina.Excel.Sheets.ClassJob> ClassSheet;

public static Dictionary<int, bool> ComboPreserving;

public static void Init(IDataManager data, IClientState cs, ICondition cond) {
Lumina = data;
ActionSheet = data.Excel.GetSheet<Lumina.Excel.GeneratedSheets.Action>();
ClassSheet = data.Excel.GetSheet<Lumina.Excel.GeneratedSheets.ClassJob>();
ActionSheet = data.Excel.GetSheet<Lumina.Excel.Sheets.Action>();
ClassSheet = data.Excel.GetSheet<Lumina.Excel.Sheets.ClassJob>();

ActionManager = FFXIVClientStructs.FFXIV.Client.Game.ActionManager.Instance();
AtkStage = FFXIVClientStructs.FFXIV.Component.GUI.AtkStage.Instance();
Expand Down Expand Up @@ -77,12 +75,11 @@ public static void Init(IDataManager data, IClientState cs, ICondition cond) {
}
}
};
public static readonly List<uint> TeleportIds = [5,6];
public static readonly List<uint> TeleportIds = [5, 6];
}

[StructLayout(LayoutKind.Explicit)]
public readonly unsafe struct Action
{
public readonly unsafe struct Action {
[FieldOffset(0x0)] public readonly void* ActionManager;
[FieldOffset(0x8)] public readonly float AnimationLock;
[FieldOffset(0x24)] public readonly uint CastId;
Expand Down
32 changes: 14 additions & 18 deletions src/Data/HelperMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
using System.Runtime.InteropServices;

[assembly: InternalsVisibleTo("Tests")]
namespace GCDTracker.Data
{
public unsafe static class HelperMethods
{
namespace GCDTracker.Data {
public unsafe static class HelperMethods {
public delegate byte UseActionDelegate(ActionManager* actionManager, ActionType actionType, uint actionID, ulong targetID, uint param, uint useType, int pvp, nint a7);
public delegate void ReceiveActionEffectDetour(int sourceActorID, IntPtr sourceActor, IntPtr vectorPosition, IntPtr effectHeader, IntPtr effectArray, IntPtr effectTrail);

Expand Down Expand Up @@ -52,51 +50,49 @@ internal static bool _isAddingToQueue(bool isWeaponSkill, bool InQueue, float El
(!isWeaponSkill && AnimationLock != 0.5f && AnimationLock != 0.64000005f)); //OGCDS
}

public static uint? GetParentJob(uint jobId) => DataStore.ClassSheet.GetRow(jobId).ClassJobParent.Value?.RowId;
public static uint? GetParentJob(uint jobId) => DataStore.ClassSheet.GetRow(jobId).ClassJobParent.ValueNullable?.RowId;

public static string ReadStringFromPointer(byte** ptr) {
public static string ReadStringFromPointer(byte** ptr) {
if (ptr == null || *ptr == null) return "";
return MemoryHelper.ReadSeStringNullTerminated(new nint(*ptr)).TextValue;
}

public static string GetAbilityName(uint actionID, ActionType actionType) {
var lumina = DataStore.Lumina;
var objectKind = DataStore.ClientState?.LocalPlayer?.TargetObject?.ObjectKind ?? ObjectKind.None;

return objectKind switch
{
return objectKind switch {
ObjectKind.Aetheryte => "Attuning...",
ObjectKind.EventObj or ObjectKind.EventNpc => "Interacting...",
_ when actionID == 1 && actionType != ActionType.Mount => "Interacting...",
_ => actionType switch
{
_ => actionType switch {
ActionType.Ability
or ActionType.Action
or ActionType.BgcArmyAction
or ActionType.CraftAction
or ActionType.PetAction
or ActionType.PvPAction =>
lumina?.GetExcelSheet<Lumina.Excel.GeneratedSheets.Action>()?.GetRow(actionID)?.Name ?? "Unknown Ability",
lumina?.GetExcelSheet<Lumina.Excel.Sheets.Action>()?.GetRow(actionID).Name.ExtractText() ?? "Unknown Ability",

ActionType.Companion =>
lumina?.GetExcelSheet<Lumina.Excel.GeneratedSheets.Companion>()?.GetRow(actionID) is var companion && companion != null
? CapitalizeOutput(companion.Singular)
lumina?.GetExcelSheet<Lumina.Excel.Sheets.Companion>()?.GetRow(actionID) is var companion && companion != null
? CapitalizeOutput(companion.Value.Singular.ExtractText())
: "Unknown Companion",

ActionType.Item
or ActionType.KeyItem =>
lumina?.GetExcelSheet<Lumina.Excel.GeneratedSheets.Item>()?.GetRow(actionID)?.Name ?? "Unknown Item",
lumina?.GetExcelSheet<Lumina.Excel.Sheets.Item>()?.GetRow(actionID).Name.ExtractText() ?? "Unknown Item",

ActionType.Mount =>
lumina?.GetExcelSheet<Lumina.Excel.GeneratedSheets.Mount>()?.GetRow(actionID) is var mount && mount != null
? CapitalizeOutput(mount.Singular)
lumina?.GetExcelSheet<Lumina.Excel.Sheets.Mount>()?.GetRow(actionID) is var mount && mount != null
? CapitalizeOutput(mount.Value.Singular.ExtractText())
: "Unknown Mount",

_ => "Casting..."
}
};
}

private static string CapitalizeOutput(string input) {
if (string.IsNullOrEmpty(input))
return input;
Expand Down
38 changes: 19 additions & 19 deletions src/UI/GCDBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace GCDTracker.UI {
public unsafe class GCDBar : IWindow {
private readonly Configuration conf;
private readonly GCDHelper helper;
private readonly AbilityManager abilityManager;
private readonly AbilityManager abilityManager;
private readonly BarDecisionHelper go;
private readonly BarVertices bar_v;
private readonly GCDEventHandler notify;
Expand Down Expand Up @@ -41,12 +41,12 @@ public GCDBar(Configuration conf, GCDHelper helper, AbilityManager abilityManage

public void Update(IFramework _) {
go.Update(helper,
DataStore.ActionManager->CastActionType,
DataStore.ActionManager->CastActionType,
DataStore.ClientState?.LocalPlayer?.TargetObject?.ObjectKind ?? ObjectKind.None);
queueLock.Update(bar_v);
slideCast.Update(bar_v);
}

public void Draw(PluginUI ui) {
bar_v.Update(ui, notify);
if (go.IsCastBar) {
Expand All @@ -63,13 +63,13 @@ private void DrawGCDBar(PluginUI ui) {
float gcdTotal = helper.TotalGCD;
float gcdTime = helper.lastElapsedGCD;
if (gcdTotal < 0.1f) return;

DrawBackground(ui);
DrawProgress(ui);
if (!go.IsShortCast)
DrawOGCDs(ui);
queueLock.Draw(ui);
if (go.IsShortCast){
if (go.IsShortCast) {
slideCast.Draw(ui);
}
DrawBackgroundBorder(ui);
Expand All @@ -90,8 +90,8 @@ private void DrawGCDBar(PluginUI ui) {
DrawBarText(ui, " -> " + helper.queuedAbilityName);
}
}
public void DrawCastBar (PluginUI ui) {

public void DrawCastBar(PluginUI ui) {
float gcdTotal = DataStore.Action->TotalGCD;
float castTotal = DataStore.Action->TotalCastTime;
float castElapsed = DataStore.Action->ElapsedCastTime;
Expand All @@ -111,7 +111,7 @@ public void DrawCastBar (PluginUI ui) {
abilityNameOutput += " (" + helper.remainingCastTimeString + ")";
if (helper.queuedAbilityName != " " && conf.CastBarShowQueuedSpell)
abilityNameOutput += " -> " + helper.queuedAbilityName;

DrawBarText(ui, abilityNameOutput);
}
}
Expand All @@ -126,13 +126,13 @@ private void DrawBackground(PluginUI ui) {
private void DrawBackgroundBorder(PluginUI ui) => background.DrawBorder(ui, conf.backColBorder);

private void DrawProgress(PluginUI ui) {
if(go.CurrentPos > 0.001f){
if (go.CurrentPos > 0.001f) {
var progressBarColor = notify.ProgressPulseColor;
progressBar.Update(bar_v.Rect.Left, bar_v.ProgToScreen(go.CurrentPos) + bar_v.BorderSize);
progressBar.Draw(ui, progressBarColor, conf.BarGradMode, conf.BarGradientMul);
}
}

private void DrawOGCDs(PluginUI ui) {
float gcdTotal = helper.TotalGCD;
float gcdTime = helper.lastElapsedGCD;
Expand All @@ -156,7 +156,7 @@ private void DrawOGCDs(PluginUI ui) {
sclip.Draw(ui, conf.clipCol);
}
}
if(!go.IsShortCast || isClipping) {
if (!go.IsShortCast || isClipping) {
var clip = new Bar(bar_v);
clip.Update(bar_v.ProgToScreen(ogcdStart / gcdTotal), bar_v.ProgToScreen(ogcdEnd / gcdTotal));
clip.Draw(ui, isClipping ? conf.clipCol : conf.anLockCol);
Expand All @@ -171,7 +171,7 @@ private void DrawOGCDs(PluginUI ui) {
}
}

private void DrawBarText(PluginUI ui, string abilityName){
private void DrawBarText(PluginUI ui, string abilityName) {
int barWidth = (int)(ui.w_size.X * conf.BarWidthRatio);
string combinedText = abilityName + helper.remainingCastTimeString + "!)/|";
Vector2 spellNamePos = new(ui.w_cent.X - ((float)barWidth / 2.05f), ui.w_cent.Y);
Expand All @@ -197,20 +197,20 @@ private void TriggerQueueAlert() {
go.ActivateAlertIfNeeded(EventType.BarHeightPulse, conf.pulseBarHeightAtQueue, EventCause.Queuelock);
}

public Vector2 GetBarSize() => new (bar_v.Width, bar_v.Height);
public Vector2 GetBarSize() => new(bar_v.Width, bar_v.Height);

public bool ShouldDraw(bool inCombat, bool noUI) {
bool shouldShowBar = conf.BarEnabled && !noUI;
conf.EnabledGBJobs.TryGetValue(DataStore.ClientState.LocalPlayer.ClassJob.Id, out var enabledJobGB);
conf.EnabledGBJobs.TryGetValue(DataStore.ClientState.LocalPlayer.ClassJob.RowId, out var enabledJobGB);
bool showBarInCombat = enabledJobGB && (conf.ShowOutOfCombat || inCombat);
bool showBarWhenGCDNotRunning = !conf.ShowOnlyGCDRunning ||
bool showBarWhenGCDNotRunning = !conf.ShowOnlyGCDRunning ||
(helper.idleTimerAccum < helper.GCDTimeoutBuffer);
bool showCastBarOrNoLastActionTP = conf.CastBarEnabled || !helper.lastActionTP;

return shouldShowBar &&
(IsMoveable ||
(showBarInCombat &&
showBarWhenGCDNotRunning &&
return shouldShowBar &&
(IsMoveable ||
(showBarInCombat &&
showBarWhenGCDNotRunning &&
showCastBarOrNoLastActionTP));
}
public string WindowName => "GCDTracker_Bar";
Expand Down
16 changes: 8 additions & 8 deletions src/UI/GCDWheel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@ public void Draw(PluginUI ui) {
if (!iscast) ui.DrawCircSegment(ogcd / gcdTotal, (ogcd + 0.04f) / gcdTotal, 23f * notify.WheelScale, conf.ogcdCol);
}
}

public bool ShouldDraw(bool inCombat, bool noUI) {
conf.EnabledGWJobs.TryGetValue(DataStore.ClientState.LocalPlayer.ClassJob.Id, out var enabledJobGW);
conf.EnabledGWJobs.TryGetValue(DataStore.ClientState.LocalPlayer.ClassJob.RowId, out var enabledJobGW);

bool shouldShowGCDWheel = conf.WheelEnabled && !noUI;
bool showGCDWheelInCombat = enabledJobGW && (conf.ShowOutOfCombat || inCombat);
bool showGCDWheelWhenGCDNotRunning = !conf.ShowOnlyGCDRunning ||
(helper.idleTimerAccum < helper.GCDTimeoutBuffer &&
bool showGCDWheelWhenGCDNotRunning = !conf.ShowOnlyGCDRunning ||
(helper.idleTimerAccum < helper.GCDTimeoutBuffer &&
!helper.lastActionTP);

return shouldShowGCDWheel &&
(IsMoveable ||
(showGCDWheelInCombat &&
return shouldShowGCDWheel &&
(IsMoveable ||
(showGCDWheelInCombat &&
showGCDWheelWhenGCDNotRunning));
}
public string WindowName => "GCDTracker_GCDWheel";
Expand Down

0 comments on commit f20c8d4

Please sign in to comment.