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

Commit

Permalink
fix: change countdown.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed May 24, 2023
1 parent 9e42f92 commit 537c7cc
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 82 deletions.
24 changes: 24 additions & 0 deletions RotationSolver.Basic/Data/Countdown.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
60 changes: 2 additions & 58 deletions RotationSolver.Basic/Service.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/// <summary>
///https://github.com/xorus/EngageTimer/blob/main/Game/CountdownHook.cs
/// </summary>
[Signature("48 89 5C 24 ?? 57 48 83 EC 40 8B 41", DetourName = nameof(CountdownTimerFunc))]
private readonly Hook<CountdownTimerDelegate> _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<float>(_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();

Expand All @@ -99,9 +46,6 @@ public unsafe static IEnumerable<IntPtr> GetAddons<T>() 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;

}
16 changes: 0 additions & 16 deletions RotationSolver/RotationSolverPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ public RotationSolverPlugin(DalamudPluginInterface pluginInterface)
{
ECommonsMain.Init(pluginInterface, this);

pluginInterface.Create<Service>();

try
{
Service.Config = JsonConvert.DeserializeObject<PluginConfiguration>(
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion RotationSolver/Updaters/MajorUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
12 changes: 6 additions & 6 deletions RotationSolver/Updaters/SocialUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TerritoryType>()
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 537c7cc

Please sign in to comment.