From 537c7cc0baf1db2272f688b584bd93fc3e031460 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=8B=E6=B0=B4?= <1123993881@qq.com> Date: Wed, 24 May 2023 17:38:48 +0800 Subject: [PATCH] fix: change countdown. --- ECommons | 2 +- RotationSolver.Basic/Data/Countdown.cs | 24 ++++++++++ RotationSolver.Basic/Service.cs | 60 +----------------------- RotationSolver/RotationSolverPlugin.cs | 16 ------- RotationSolver/Updaters/MajorUpdater.cs | 2 +- RotationSolver/Updaters/SocialUpdater.cs | 12 ++--- 6 files changed, 34 insertions(+), 82 deletions(-) create mode 100644 RotationSolver.Basic/Data/Countdown.cs diff --git a/ECommons b/ECommons index 1d7842594..c5eeb88a4 160000 --- a/ECommons +++ b/ECommons @@ -1 +1 @@ -Subproject commit 1d7842594e1952ec79d4135bcce3500721a40500 +Subproject commit c5eeb88a4cb44f676e50591ea6ed256df655b73d diff --git a/RotationSolver.Basic/Data/Countdown.cs b/RotationSolver.Basic/Data/Countdown.cs new file mode 100644 index 000000000..0b7cecb4b --- /dev/null +++ b/RotationSolver.Basic/Data/Countdown.cs @@ -0,0 +1,24 @@ +using FFXIVClientStructs.FFXIV.Client.System.Framework; +using FFXIVClientStructs.FFXIV.Client.UI.Agent; +using System.Runtime.InteropServices; + +namespace RotationSolver.Basic.Data; + +[StructLayout(LayoutKind.Explicit)] +public unsafe struct Countdown +{ + [FieldOffset(0x28)] public float Timer; + [FieldOffset(0x38)] public byte Active; + [FieldOffset(0x3C)] public uint Initiator; + + public static unsafe Countdown* Instance => (Countdown*)Framework.Instance()->GetUiModule()->GetAgentModule()->GetAgentByInternalId(AgentId.CountDownSettingDialog); + + public static float TimeRemaining + { + get + { + var inst = Instance; + return inst->Active != 0 ? inst->Timer : 0; + } + } +} diff --git a/RotationSolver.Basic/Service.cs b/RotationSolver.Basic/Service.cs index 8cb1a0946..5e67fb98c 100644 --- a/RotationSolver.Basic/Service.cs +++ b/RotationSolver.Basic/Service.cs @@ -15,66 +15,13 @@ namespace RotationSolver.Basic; -public class Service : IDisposable +public static class Service { public const string Command = "/rotation"; - private delegate IntPtr CountdownTimerDelegate(IntPtr p1); + public static float CountDownTime => Countdown.TimeRemaining; - /// - ///https://github.com/xorus/EngageTimer/blob/main/Game/CountdownHook.cs - /// - [Signature("48 89 5C 24 ?? 57 48 83 EC 40 8B 41", DetourName = nameof(CountdownTimerFunc))] - private readonly Hook _countdownTimerHook = null; - private static IntPtr _countDown = IntPtr.Zero; - - static float _lastTime = 0; - private bool _disposed; - - public static float CountDownTime { get; private set; } - - - public Service() - { - SignatureHelper.Initialise(this); - Svc.Framework.Update += Framework_Update; - _countdownTimerHook?.Enable(); - } - - private void Framework_Update(Framework framework) - { - var value = _countDown == IntPtr.Zero ? 0 : Math.Max(0, Marshal.PtrToStructure(_countDown + 0x2c)); - if (_lastTime == value) CountDownTime = 0; - else CountDownTime = _lastTime = value; - } - - private IntPtr CountdownTimerFunc(IntPtr value) - { - _countDown = value; - return _countdownTimerHook!.Original(value); - } - - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - protected virtual void Dispose(bool disposing) - { - if (_disposed) - { - return; - } - - if (disposing) - { - _countdownTimerHook?.Dispose(); - Svc.Framework.Update -= Framework_Update; - } - _disposed = true; - } public static PluginConfiguration Config { get; set; } public static PluginConfiguration Default { get; } = new PluginConfiguration(); @@ -99,9 +46,6 @@ public unsafe static IEnumerable GetAddons() where T : struct internal static TextureWrap GetTextureIcon(uint id) => Svc.Data.GetImGuiTextureIcon(id); internal static TextureWrap GetTexture(string path) => Svc.Data.GetImGuiTexture(path); - [PluginService] - public static DutyState DutyState { get; private set; } - public static ClientLanguage Language => Svc.ClientState.ClientLanguage; } diff --git a/RotationSolver/RotationSolverPlugin.cs b/RotationSolver/RotationSolverPlugin.cs index 42ceb02a4..04c587fc2 100644 --- a/RotationSolver/RotationSolverPlugin.cs +++ b/RotationSolver/RotationSolverPlugin.cs @@ -31,8 +31,6 @@ public RotationSolverPlugin(DalamudPluginInterface pluginInterface) { ECommonsMain.Init(pluginInterface, this); - pluginInterface.Create(); - try { Service.Config = JsonConvert.DeserializeObject( @@ -79,20 +77,6 @@ public RotationSolverPlugin(DalamudPluginInterface pluginInterface) { if(id == 0) OpenConfigWindow(); }); - - //Task.Run(async () => - //{ - // await Task.Delay(1000); - // Splatoon.RemoveDynamicElements("Test"); - // var element = new Element(ElementType.CircleRelativeToActorPosition); - // element.refActorObjectID = Player.Object.ObjectId; - // element.refActorComparisonType = RefActorComparisonType.ObjectID; - // element.includeHitbox = true; - // element.radius = 0.5f; - // element.Donut = 0.8f; - // element.color = ImGui.GetColorU32(new Vector4(1, 1, 1, 0.4f)); - // Svc.Toasts.ShowQuest(Splatoon.AddDynamicElement("Test", element, -2).ToString()); - //}); } internal static void ChangeUITranslation() diff --git a/RotationSolver/Updaters/MajorUpdater.cs b/RotationSolver/Updaters/MajorUpdater.cs index d22d57f79..e0250f910 100644 --- a/RotationSolver/Updaters/MajorUpdater.cs +++ b/RotationSolver/Updaters/MajorUpdater.cs @@ -13,7 +13,7 @@ internal static class MajorUpdater public static bool ShouldPreventActions => Basic.Configuration.PluginConfiguration.GetValue(SettingsCommand.PreventActions) && Basic.Configuration.PluginConfiguration.GetValue(SettingsCommand.PreventActionsDuty) && Svc.Condition[ConditionFlag.BoundByDuty] - && !Service.DutyState.IsDutyStarted + && !Svc.DutyState.IsDutyStarted || Basic.Configuration.PluginConfiguration.GetValue(SettingsCommand.PreventActions) && !DataCenter.HasHostilesInMaxRange; diff --git a/RotationSolver/Updaters/SocialUpdater.cs b/RotationSolver/Updaters/SocialUpdater.cs index 2e0579f90..337ab3eb2 100644 --- a/RotationSolver/Updaters/SocialUpdater.cs +++ b/RotationSolver/Updaters/SocialUpdater.cs @@ -59,9 +59,9 @@ static bool CanSocial internal static void Enable() { - Service.DutyState.DutyStarted += DutyState_DutyStarted; - Service.DutyState.DutyWiped += DutyState_DutyWiped; - Service.DutyState.DutyCompleted += DutyState_DutyCompleted; + Svc.DutyState.DutyStarted += DutyState_DutyStarted; + Svc.DutyState.DutyWiped += DutyState_DutyWiped; + Svc.DutyState.DutyCompleted += DutyState_DutyCompleted; Svc.ClientState.TerritoryChanged += ClientState_TerritoryChanged; HighEndDuties = Service.GetSheet() @@ -143,9 +143,9 @@ static void DutyState_DutyWiped(object sender, ushort e) internal static void Disable() { - Service.DutyState.DutyStarted -= DutyState_DutyStarted; - Service.DutyState.DutyWiped -= DutyState_DutyWiped; - Service.DutyState.DutyCompleted -= DutyState_DutyCompleted; + Svc.DutyState.DutyStarted -= DutyState_DutyStarted; + Svc.DutyState.DutyWiped -= DutyState_DutyWiped; + Svc.DutyState.DutyCompleted -= DutyState_DutyCompleted; Svc.ClientState.TerritoryChanged -= ClientState_TerritoryChanged; }