Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix api10 #67

Merged
merged 4 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Plugin/Configuration/ConfigurationFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public enum TextAlign
}

// Add any other properties or methods here.
[NonSerialized] private DalamudPluginInterface _pluginInterface = Plugin.PluginInterface;
[NonSerialized] private IDalamudPluginInterface _pluginInterface = Plugin.PluginInterface;
public CountdownConfiguration Countdown = new();

public DtrConfiguration Dtr = new();
Expand Down
5 changes: 5 additions & 0 deletions Plugin/Configuration/FloatingWindowConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
#nullable enable
using System;
using System.Numerics;
using System.Text.Json.Serialization;
using Dalamud.Interface.Colors;
using Dalamud.Interface.FontIdentifier;
using EngageTimer.Attributes;
using EngageTimer.Ui;

Expand Down Expand Up @@ -81,6 +83,9 @@ public class FloatingWindowConfiguration
public ConfigurationFile.TextAlign Align { get; set; } = ConfigurationFile.TextAlign.Left;

public int FontSize { get; set; } = 16;

// [JsonIgnore] public IFontSpec? FontSpec { get; set; } = null;
// public IFontSpec? Font { get; set; } = null;

[AutoField("Settings_FWTab_AutoHide_Left")]
public bool AutoHide { get; set; } = true;
Expand Down
4 changes: 2 additions & 2 deletions Plugin/EngageTimer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<ProduceReferenceAssembly>false</ProduceReferenceAssembly>
<AssemblyVersion>2.3.4.0</AssemblyVersion>
<AssemblyVersion>2.4.0.0</AssemblyVersion>
<Deterministic>false</Deterministic>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
Expand Down Expand Up @@ -67,7 +67,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="DalamudPackager" Version="2.1.12"/>
<PackageReference Include="DalamudPackager" Version="2.1.13" />
<PackageReference Include="EmbedIO" Version="3.5.2"/>
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0" />
<!-- required for Unosquare.Swan.Lite (implicit dependency of EmbedIO) -->
Expand Down
9 changes: 6 additions & 3 deletions Plugin/EngageTimer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ image_urls:
category_tags:
- jobs
changelog: |-
- Fix not being able to disable alarms
- Missing translation strings in web server config
- Hide floating window border by default (you can re-enable it in Floating Window -> styling)
- DT compatibility
- Update for API10:
- Use new texture loading for countdown
- Migrate to the new font system, the floating window contents might be blurry, this will be fixed soon when I
can implement font customization instead of always using the default dalamud one

6 changes: 4 additions & 2 deletions Plugin/Game/AddonHider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ private unsafe void ShowAddonNearEnd(object? sender, EventArgs eventArgs)
try
{
var atkUnitBase = (AtkUnitBase*)_lastCountdownAddon;
atkUnitBase->Flags |= VisibleFlag;
atkUnitBase->IsVisible = true;
// atkUnitBase->Flags |= VisibleFlag;
// Plugin.Logger.Debug("show addon");
}
catch (Exception)
Expand Down Expand Up @@ -74,7 +75,8 @@ private unsafe void HideAddon(AddonEvent type, AddonArgs args)
try
{
var atkUnitBase = (AtkUnitBase*)addon;
atkUnitBase->Flags = (byte)(atkUnitBase->Flags & ~VisibleFlag);
atkUnitBase->IsVisible = false;
// atkUnitBase->Flags = (byte)(atkUnitBase->Flags & ~VisibleFlag);
// Plugin.Logger.Debug("hide addon");
}
catch (Exception)
Expand Down
55 changes: 11 additions & 44 deletions Plugin/Game/CountdownHook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,24 @@

/*
* Based on the work (for finding the pointer) of https://github.com/Haplo064/Europe
* 7.0 function changes taken from https://github.com/DelvUI/DelvUI/commit/492211c8f43b813d10b2220e6fe768ac508dcede and
* https://discord.com/channels/581875019861328007/653504487352303619/1257920418388639774. Thanks Tischel for that work!
*/
namespace EngageTimer.Game;

public sealed class CountdownHook : IDisposable
{
[Signature("48 89 5C 24 ?? 57 48 83 EC 40 8B 41", DetourName = nameof(CountdownTimerFunc))]
[Signature("40 53 48 83 EC 40 80 79 38 00", DetourName = nameof(CountdownTimerFunc))]
private readonly Hook<CountdownTimerDelegate>? _countdownTimerHook = null;

private readonly State _state;

private ulong _countDown;
private bool _countDownRunning;

/// <summary>
/// Ticks since the timer stalled
/// </summary>
private int _countDownStallTicks;

private float _lastCountDownValue;

private ulong _paramValue;

public CountdownHook()
{
_state = Plugin.State;
_countDown = 0;
_paramValue = 0;
Plugin.GameInterop.InitializeFromAttributes(this);
_countdownTimerHook?.Enable();
}
Expand All @@ -61,7 +54,7 @@ public void Dispose()

private IntPtr CountdownTimerFunc(ulong value)
{
_countDown = value;
_paramValue = value;
return _countdownTimerHook!.Original(value);
}

Expand All @@ -74,37 +67,11 @@ public void Update()

private void UpdateCountDown()
{
var newCountingDown = false;
if (_countDown == 0)
{
_state.CountingDown = newCountingDown;
return;
}

var countDownPointerValue = Marshal.PtrToStructure<float>((IntPtr)_countDown + 0x2c);

// is last value close enough (workaround for floating point approx)
if (Math.Abs(countDownPointerValue - _lastCountDownValue) < 0.001f)
{
_countDownStallTicks++;
}
else
{
_countDownStallTicks = 0;
_countDownRunning = true;
}

if (_countDownStallTicks > 50) _countDownRunning = false;

if (countDownPointerValue > 0 && _countDownRunning)
{
var newValue = Marshal.PtrToStructure<float>((IntPtr)_countDown + 0x2c);
_state.CountDownValue = newValue;
newCountingDown = true;
}

_state.CountingDown = newCountingDown;
_lastCountDownValue = countDownPointerValue;
if (_paramValue == 0) return;
var countDownActive = Marshal.PtrToStructure<byte>((IntPtr)_paramValue + 0x38) == 1;
var countDownPointerValue = Marshal.PtrToStructure<float>((IntPtr)_paramValue + 0x2c);
_state.CountingDown = countDownActive && countDownPointerValue > 0f;
_state.CountDownValue = countDownPointerValue;
}

[UnmanagedFunctionPointer(CallingConvention.ThisCall, CharSet = CharSet.Ansi)]
Expand Down
7 changes: 4 additions & 3 deletions Plugin/Game/SFXPlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ namespace EngageTimer.Game;
/**
* thanks aers
* sig taken from https://github.com/philpax/plogonscript/blob/main/PlogonScript/Script/Bindings/Sound.cs
* https://github.com/0ceal0t/JobBars/blob/2c9bef8dd4f0bf9ebc91c07e03da6c841ac2bd35/JobBars/Helper/UiHelper.GameFunctions.cs#L61
* ---
* https://discord.com/channels/581875019861328007/653504487352303619/988123102116450335
*/
internal unsafe class GameSound
{
[Signature("E8 ?? ?? ?? ?? 4D 39 BE ?? ?? ?? ??")]
[Signature("E8 ?? ?? ?? ?? 48 63 45 80")]
public readonly delegate* unmanaged<uint, IntPtr, IntPtr, byte, void> PlaySoundEffect = null;

public GameSound()
Expand All @@ -45,10 +46,10 @@ public class SfxPlay
public SfxPlay()
{
/* Force a sound to play on load as a workaround for the CLR taking some time to init the pointy method call,
* we dont want a freeze midway through a countdown
* we don't want a freeze midway through a countdown (or midway in combat for alarms)
* https://discord.com/channels/581875019861328007/653504487352303619/988123102116450335
* https://i.imgur.com/BrLUr2p.png
* */
*/
SoundEffect(0); // should be cursor sound
}

Expand Down
9 changes: 7 additions & 2 deletions Plugin/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace EngageTimer;
[PublicAPI]
public sealed class Plugin : IDalamudPlugin
{
[PluginService] public static DalamudPluginInterface PluginInterface { get; private set; } = null!;
[PluginService] public static IDalamudPluginInterface PluginInterface { get; private set; } = null!;
[PluginService] public static IGameGui GameGui { get; private set; } = null!;
[PluginService] public static ICommandManager Commands { get; private set; } = null!;
[PluginService] public static ICondition Condition { get; private set; } = null!;
Expand All @@ -42,6 +42,8 @@ public sealed class Plugin : IDalamudPlugin
[PluginService] public static IPluginLog Logger { get; private set; } = null!;
[PluginService] public static IAddonLifecycle AddonLifecycle { get; private set; } = null!;
[PluginService] public static IToastGui ToastGui { get; private set; } = null!;
[PluginService] public static INotificationManager NotificationManager { get; private set; } = null!;
[PluginService] public static ITextureProvider TextureProvider { get; private set; } = null!;
public static ConfigurationFile Config { get; private set; } = null!;
public static State State { get; private set; } = null!;
public static PluginUi PluginUi { get; private set; } = null!;
Expand All @@ -52,8 +54,9 @@ public sealed class Plugin : IDalamudPlugin
private static SettingsCommand SettingsCommand { get; set; } = null!;
public static CombatAlarm CombatAlarm { get; set; } = null!;
public static SfxPlay SfxPlay { get; set; } = null!;
public static FloatingWindowFont FloatingWindowFont { get; set; } = null!;

public Plugin(DalamudPluginInterface pluginInterface)
public Plugin(IDalamudPluginInterface pluginInterface)
{
PluginPath = PluginInterface.AssemblyLocation.DirectoryName ??
throw new InvalidOperationException("Cannot find plugin directory");
Expand All @@ -63,6 +66,7 @@ public Plugin(DalamudPluginInterface pluginInterface)
FrameworkThings = new FrameworkThings();
MainCommand = new MainCommand();
SettingsCommand = new SettingsCommand();
FloatingWindowFont = new FloatingWindowFont();
PluginUi = new PluginUi();
CombatAlarm = new CombatAlarm();
SfxPlay = new SfxPlay();
Expand All @@ -77,5 +81,6 @@ void IDisposable.Dispose()
FrameworkThings.Dispose();
MainCommand.Dispose();
SettingsCommand.Dispose();
FloatingWindowFont.Dispose();
}
}
15 changes: 9 additions & 6 deletions Plugin/Status/CombatAlarm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
using System.IO;
using System.Linq;
using Dalamud.Game.Text;
using Dalamud.Interface.Internal.Notifications;
using Dalamud.Interface.ImGuiNotification;
using Dalamud.Plugin.Services;
using EngageTimer.Configuration;
using EngageTimer.Game;
Expand Down Expand Up @@ -179,11 +179,14 @@ public static void AlarmText(CombatAlarmsConfiguration.Alarm alarm)
switch (alarm.TextType)
{
case CombatAlarmsConfiguration.TextType.DalamudNotification:
Plugin.PluginInterface.UiBuilder.AddNotification(
trimText,
"EngageTimer",
NotificationType.Info,
8000
Plugin.NotificationManager.AddNotification(
new Notification()
{
Content = trimText,
Title ="EngageTimer",
Type = NotificationType.Info,
InitialDuration = TimeSpan.FromSeconds(8.0)
}
);
break;
case CombatAlarmsConfiguration.TextType.GameToast:
Expand Down
3 changes: 2 additions & 1 deletion Plugin/Status/CombatStopwatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using Dalamud.Game.ClientState.Objects.Types;
using Dalamud.Plugin.Services;
using EngageTimer.Configuration;
using FFXIVClientStructs.FFXIV.Client.Game.Character;

namespace EngageTimer.Status;

Expand All @@ -43,7 +44,7 @@ public void UpdateEncounterTimer()
// if anyone in the party is in combat
foreach (var actor in Plugin.PartyList)
{
if (actor.GameObject is not Character character ||
if (actor.GameObject is not ICharacter character ||
(character.StatusFlags & StatusFlags.InCombat) == 0) continue;
inCombat = true;
break;
Expand Down
24 changes: 17 additions & 7 deletions Plugin/Ui/CountDown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public sealed class CountDown : IDisposable
*
* In my testing, this is about 10 to 20ms.
*/
private bool _firstDraw = true;
private int _firstDrawTicks = 5;

private int _lastSecond;
private bool _wasInMainViewport = true;
Expand Down Expand Up @@ -88,9 +88,14 @@ private void FirstDraw()
if (ImGui.Begin(WindowTitle, ref visible, flags))
{
ImGui.Text("");
for (var i = 0; i <= 9; i++)
{
DrawNumber(false, i, 0.001f, 0f, 1f, false);
DrawNumber(true, i, 0.001f, 0f, 1f, false);
}
}

_firstDraw = false;
_firstDrawTicks--;
}

public void Draw()
Expand All @@ -112,7 +117,12 @@ public void Draw()
// ImGui.End();
// #endif

if (_firstDraw) FirstDraw();
if (_firstDrawTicks > 0)
{
FirstDraw();
return;
}

if (!Plugin.Config.Countdown.Display || !Plugin.State.CountingDown) return;

var showMainCountdown = Plugin.Config.Countdown.HideOriginalAddon ||
Expand All @@ -130,7 +140,7 @@ public void Draw()

if (Plugin.Config.Countdown.Animate)
{
var second = (int) Plugin.State.CountDownValue;
var second = (int)Plugin.State.CountDownValue;
if (_lastSecond != second)
{
_easing.Restart();
Expand All @@ -143,7 +153,7 @@ public void Draw()
if (Plugin.Config.Countdown.AnimateScale)
{
maxNumberScale = numberScale + NumberEasing.StartSize;
numberScale += NumberEasing.StartSize * (1 - (float) _easing.Value);
numberScale += NumberEasing.StartSize * (1 - (float)_easing.Value);
}
}
}
Expand Down Expand Up @@ -190,7 +200,7 @@ public void Draw()
ImGui.GetWindowPos(),
ImGui.GetWindowPos() + ImGui.GetWindowSize(),
ImGui.GetColorU32(ImGuiCol.Text), 0f, ImDrawFlags.None,
7f + (float) Math.Sin(ImGui.GetTime() * 2) * 5f);
7f + (float)Math.Sin(ImGui.GetTime() * 2) * 5f);
d.AddRect(
ImGui.GetWindowPos(),
ImGui.GetWindowPos() + ImGui.GetWindowSize(),
Expand All @@ -202,7 +212,7 @@ public void Draw()
DrawCountdown(showMainCountdown, numberScale, negativeMargin, false);
if (Plugin.Config.Countdown.Animate && Plugin.Config.Countdown.AnimateOpacity)
{
ImGui.PushStyleVar(ImGuiStyleVar.Alpha, (float) _easingOpacity.Value);
ImGui.PushStyleVar(ImGuiStyleVar.Alpha, (float)_easingOpacity.Value);
DrawCountdown(showMainCountdown, numberScale, negativeMargin, true);
ImGui.PopStyleVar();
}
Expand Down
7 changes: 4 additions & 3 deletions Plugin/Ui/DtrBarUi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace EngageTimer.Ui;

public sealed class DtrBarUi : IDisposable
{
private DtrBarEntry? _entry;
private IDtrBarEntry? _entry;

public DtrBarUi()
{
Expand All @@ -31,10 +31,10 @@ public DtrBarUi()

public void Dispose()
{
_entry?.Dispose();
_entry?.Remove();
}

private DtrBarEntry? GetEntry()
private IDtrBarEntry? GetEntry()
{
const string dtrBarTitle = "EngageTimer stopwatch";
var dtrBar = Plugin.DtrBar;
Expand Down Expand Up @@ -89,6 +89,7 @@ public void Update()
if (_entry is { Shown: true }) _entry.Shown = false;
return;
}

if (!_entry.Shown) _entry.Shown = true;

var seString = (SeString)(Plugin.Config.Dtr.CombatTimePrefix +
Expand Down
Loading
Loading