Skip to content

Commit

Permalink
Merge branch 'main' into l10n_main
Browse files Browse the repository at this point in the history
  • Loading branch information
xorus authored Oct 5, 2024
2 parents db4a63c + a6ddc19 commit 9bd4737
Show file tree
Hide file tree
Showing 26 changed files with 282 additions and 206 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 7.0.*
dotnet-version: 8.0.*
- name: Restore dependencies
run: dotnet restore
- name: Download Dalamud
Expand Down
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# v2.3.2.0

- Adds
- Add an option to draw the custom 0-5 numbers without hiding the original countdown
- Make animation match vanilla a bit better

# v2.3.1.0

Expand Down Expand Up @@ -59,4 +60,4 @@
- fix lag when starting a countdown for the first time after loading the plugin (will play a cursor noise when enabling
the plugin, I couldn't find a way around it yet)
- updated French and German translation thanks to contributors on [crowdin](https://crwd.in/engagetimer)
- internal reworking and optimizations
- internal reworking and optimizations
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
11 changes: 11 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 @@ -48,12 +50,18 @@ public class FloatingWindowConfiguration

[AutoField("Settings_FWTab_DisplayStopwatchOnlyInDuty")]
public bool StopwatchOnlyInDuty { get; set; } = false;

[AutoField("Settings_FWTab_HideInCutscenes")]
public bool HideInCutscenes { get; set; } = true;

[AutoField("Settings_FWTab_StopwatchAsSeconds")]
public bool StopwatchAsSeconds { get; set; } = false;

[AutoField("Settings_FWTab_CountdownNegativeSign")]
public bool CountdownNegativeSign { get; set; } = true;

[AutoField("Settings_FWTab_ForceHideWindowBorder")]
public bool ForceHideWindowBorder { get; set; } = true;

[AutoField("Settings_CountdownTab_FloatingWindowScale", Components.FieldType.DragFloat, .01f, .05f, 15f),
ItemWidth(100f)]
Expand All @@ -78,6 +86,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
19 changes: 15 additions & 4 deletions Plugin/EngageTimer.csproj
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0-windows</TargetFramework>
<TargetFramework>net8.0-windows</TargetFramework>
<PlatformTarget>x64</PlatformTarget>
<Platforms>AnyCPU</Platforms>
<LangVersion>10</LangVersion>
<LangVersion>12</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<ProduceReferenceAssembly>false</ProduceReferenceAssembly>
<AssemblyVersion>2.3.2.0</AssemblyVersion>
<AssemblyVersion>2.4.1.0</AssemblyVersion>
<Deterministic>false</Deterministic>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
Expand All @@ -17,6 +17,8 @@
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
<AssemblyName>EngageTimer</AssemblyName>
<Nullable>enable</Nullable>
<PackageLicenseExpression>AGPL-3.0-or-later</PackageLicenseExpression>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
Expand Down Expand Up @@ -65,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 All @@ -90,6 +92,15 @@

<PropertyGroup>
<DalamudLibPath>$(appdata)\XIVLauncher\addon\Hooks\dev\</DalamudLibPath>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>

<PropertyGroup Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))'">
<DalamudLibPath>$(DALAMUD_HOME)/</DalamudLibPath>
<DalamudLibPath Condition="$([MSBuild]::IsOSPlatform('Windows'))">$(appdata)\XIVLauncher\addon\Hooks\dev\</DalamudLibPath>
<DalamudLibPath Condition="$([MSBuild]::IsOSPlatform('Linux'))">$(HOME)/.xlcore/dalamud/Hooks/dev/</DalamudLibPath>
<DalamudLibPath Condition="$([MSBuild]::IsOSPlatform('OSX'))">$(HOME)/Library/Application Support/XIV on Mac/dalamud/Hooks/dev/</DalamudLibPath>
<DalamudLibPath Condition="$(DALAMUD_HOME) != ''">$(DALAMUD_HOME)/</DalamudLibPath>
</PropertyGroup>

<ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion Plugin/EngageTimer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ image_urls:
category_tags:
- jobs
changelog: |-
- Add an option to draw the custom 0-5 numbers without hiding the original countdown
- Option to hide the stopwatch/floating window in cutscenes
- Enabling light effect animation would show an error texture and required a plugin restart to be loaded properly
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
56 changes: 12 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 @@ -70,41 +63,16 @@ public void Update()
if (_state.Mocked) return;
UpdateCountDown();
_state.InInstance = Plugin.Condition[ConditionFlag.BoundByDuty];
_state.InCutscene = Plugin.Condition[ConditionFlag.OccupiedInCutSceneEvent];
}

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();
}
}
3 changes: 3 additions & 0 deletions Plugin/Properties/Strings.en.resx
Original file line number Diff line number Diff line change
Expand Up @@ -521,4 +521,7 @@ help text for the /eg settings command</comment>
<data name="Settings_AboutTab_Title" xml:space="preserve">
<value>About</value>
</data>
<data name="Settings_FWTab_ForceHideWindowBorder" xml:space="preserve">
<value>Hide window border</value>
</data>
</root>
22 changes: 13 additions & 9 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 @@ -118,6 +118,7 @@ private void ConfigurationChanged(object? sender, EventArgs e)
for (var index = 0; index < Plugin.Config.CombatAlarms.Alarms.Count; index++)
{
var alarm = Plugin.Config.CombatAlarms.Alarms[index];
if (!alarm.Enabled) continue;
_alarms[alarm.StartTime] = new AlarmAction()
{
Type = AlarmActionType.Start,
Expand Down Expand Up @@ -148,7 +149,7 @@ private void FrameworkUpdate(IFramework framework)
if (!Plugin.State.InCombat) return;

// only run once a second
var time = (int) Math.Floor(Plugin.State.CombatDuration.TotalSeconds);
var time = (int)Math.Floor(Plugin.State.CombatDuration.TotalSeconds);
if (_lastCheck == time) return;
_lastCheck = time;

Expand All @@ -167,22 +168,25 @@ public static void AlarmSfx(CombatAlarmsConfiguration.Alarm alarm)
{
if (alarm.Sfx != null)
{
Plugin.SfxPlay.SoundEffect((uint) (SfxPlay.FirstSeSfx + alarm.Sfx));
Plugin.SfxPlay.SoundEffect((uint)(SfxPlay.FirstSeSfx + alarm.Sfx));
}
}

public static void AlarmText(CombatAlarmsConfiguration.Alarm alarm)
{
var trimText = alarm.Text?.Trim();
if (trimText is not {Length: > 0}) return;
if (trimText is not { Length: > 0 }) return;
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
Loading

0 comments on commit 9bd4737

Please sign in to comment.