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

Commit

Permalink
fix: change interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed May 18, 2023
1 parent 20f9eb3 commit 719e0ff
Show file tree
Hide file tree
Showing 16 changed files with 49 additions and 47 deletions.
2 changes: 1 addition & 1 deletion RotationSolver.Basic/Actions/BaseAction_Target.cs
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ public unsafe bool CanUseTo(BattleChara tar)

if (!ActionManager.CanUseActionOnTarget(AdjustedID, tarAddress)) return false;

if((IntPtr)Service.RawPlayer == IntPtr.Zero || (IntPtr)tarAddress == IntPtr.Zero) return false;
if((IntPtr)Player.BattleChara == IntPtr.Zero || (IntPtr)tarAddress == IntPtr.Zero) return false;

return true;

Expand Down
8 changes: 5 additions & 3 deletions RotationSolver.Basic/Configuration/OtherConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Dalamud.Game.ClientState.GamePad;
using Dalamud.Logging;
using ECommons.DalamudServices;

namespace RotationSolver.Basic.Configuration;

Expand Down Expand Up @@ -51,9 +52,10 @@ public class OtherConfiguration

public static void Init()
{
if (!Directory.Exists(Service.Interface.ConfigDirectory.FullName))

if (!Directory.Exists(Svc.PluginInterface.ConfigDirectory.FullName))
{
Directory.CreateDirectory(Service.Interface.ConfigDirectory.FullName);
Directory.CreateDirectory(Svc.PluginInterface.ConfigDirectory.FullName);
}

Task.Run(() => InitOne(ref DangerousStatus, nameof(DangerousStatus)));
Expand Down Expand Up @@ -119,7 +121,7 @@ public static void SaveAnimationLockTime()

private static string GetFilePath(string name)
{
var directory = Service.Interface.ConfigDirectory.FullName;
var directory = Svc.PluginInterface.ConfigDirectory.FullName;
#if DEBUG
var dir = @"E:\OneDrive - stu.zafu.edu.cn\PartTime\FFXIV\RotationSolver\Resources";
if (Directory.Exists(dir)) directory = dir;
Expand Down
3 changes: 2 additions & 1 deletion RotationSolver.Basic/Configuration/PluginConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Dalamud.Configuration;
using Dalamud.Game.ClientState.GamePad;
using Dalamud.Logging;
using ECommons.DalamudServices;

namespace RotationSolver.Basic.Configuration;

Expand Down Expand Up @@ -208,6 +209,6 @@ public class PluginConfiguration : IPluginConfiguration

public void Save()
{
Service.Interface.SavePluginConfig(this);
Svc.PluginInterface.SavePluginConfig(this);
}
}
3 changes: 2 additions & 1 deletion RotationSolver.Basic/Data/IconSet.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Dalamud.Utility;
using ECommons.DalamudServices;
using ImGuiScene;
using System.Net;

Expand Down Expand Up @@ -102,7 +103,7 @@ private static TextureWrap TryLoadImage(byte[] bytes)

try
{
return Service.Interface.UiBuilder.LoadImage(bytes);
return Svc.PluginInterface.UiBuilder.LoadImage(bytes);
}
catch
{
Expand Down
4 changes: 2 additions & 2 deletions RotationSolver.Basic/DataCenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ public static void SetSpecialType(SpecialCommandType specialType)
public static bool HasPet { get; internal set; }


public static unsafe bool HasCompanion => (IntPtr)Service.RawPlayer != IntPtr.Zero
&& (IntPtr)CharacterManager.Instance()->LookupBuddyByOwnerObject(Service.RawPlayer) != IntPtr.Zero;
public static unsafe bool HasCompanion => (IntPtr)Player.BattleChara != IntPtr.Zero
&& (IntPtr)CharacterManager.Instance()->LookupBuddyByOwnerObject(Player.BattleChara) != IntPtr.Zero;

public static float RatioOfMembersIn2minsBurst
{
Expand Down
7 changes: 4 additions & 3 deletions RotationSolver.Basic/Helpers/TargetFilter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ECommons.GameHelpers;
using ECommons.DalamudServices;
using ECommons.GameHelpers;
using Lumina.Excel.GeneratedSheets;
using System.Data;

Expand Down Expand Up @@ -109,13 +110,13 @@ private static T FindMoveTargetFaceDirection<T>(IEnumerable<T> charas) where T :
private static T FindMoveTargetScreenCenter<T>(IEnumerable<T> charas) where T : GameObject
{
var pPosition = Player.Object.Position;
if (!Service.WorldToScreen(pPosition, out var playerScrPos)) return null;
if (!Svc.GameGui.WorldToScreen(pPosition, out var playerScrPos)) return null;

var tars = charas.Where(t =>
{
if (t.DistanceToPlayer() < DISTANCE_TO_MOVE) return false;

if (!Service.WorldToScreen(t.Position, out var scrPos)) return false;
if (!Svc.GameGui.WorldToScreen(t.Position, out var scrPos)) return false;

var dir = scrPos - playerScrPos;

Expand Down
16 changes: 2 additions & 14 deletions RotationSolver.Basic/Service.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using Dalamud.IoC;
using Dalamud.Plugin;
using Dalamud.Utility.Signatures;
using ECommons.DalamudServices;
using FFXIVClientStructs.Attributes;
using FFXIVClientStructs.FFXIV.Client.Game;
using FFXIVClientStructs.FFXIV.Client.Game.Control;
Expand Down Expand Up @@ -92,35 +93,22 @@ protected virtual void Dispose(bool disposing)
public static PluginConfiguration Config { get; set; }
public static PluginConfiguration Default { get; } = new PluginConfiguration();

internal static unsafe FFXIVClientStructs.FFXIV.Client.Game.Character.BattleChara* RawPlayer
=> Control.Instance()->LocalPlayer;


public static ActionID GetAdjustedActionId(ActionID id)
=> (ActionID)GetAdjustedActionId((uint)id);

public static unsafe uint GetAdjustedActionId(uint id)
=> ActionManager.Instance()->GetAdjustedActionId(id);

[PluginService]
public static DalamudPluginInterface Interface { get; private set; }
[PluginService]
public static SigScanner SigScanner { get; private set; }

[PluginService]
public static ChatGui ChatGui { get; private set; }

[PluginService]
public static GameGui GameGui { get; set; }

public static bool WorldToScreen(Vector3 worldPos, out Vector2 screenPos) => GameGui.WorldToScreen(worldPos, out screenPos);

public unsafe static IEnumerable<IntPtr> GetAddons<T>() where T : struct
{
if(typeof(T).GetCustomAttribute<Addon>() is not Addon on) return Array.Empty<nint>();

return on.AddonIdentifiers
.Select(str => GameGui.GetAddonByName(str, 1))
.Select(str => Svc.GameGui.GetAddonByName(str, 1))
.Where(ptr => ptr != IntPtr.Zero);
}

Expand Down
7 changes: 4 additions & 3 deletions RotationSolver/Localization/LocalizationManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Dalamud.Logging;
using ECommons.DalamudServices;

namespace RotationSolver.Localization;

Expand All @@ -16,8 +17,8 @@ public LocalizationManager()
ReadFile(lang, assembly);
}

SetLanguage(Service.Interface.UiLanguage);
Service.Interface.LanguageChanged += OnLanguageChange;
SetLanguage(Svc.PluginInterface.UiLanguage);
Svc.PluginInterface.LanguageChanged += OnLanguageChange;
}

private void ReadFile(string lang, Assembly assembly)
Expand Down Expand Up @@ -56,7 +57,7 @@ public static void ExportLocalization()

public void Dispose()
{
Service.Interface.LanguageChanged -= OnLanguageChange;
Svc.PluginInterface.LanguageChanged -= OnLanguageChange;
}

private void OnLanguageChange(string languageCode)
Expand Down
15 changes: 8 additions & 7 deletions RotationSolver/RotationSolverPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Dalamud.Logging;
using Dalamud.Plugin;
using ECommons;
using ECommons.DalamudServices;
using RotationSolver.Basic.Configuration;
using RotationSolver.Commands;
using RotationSolver.Data;
Expand Down Expand Up @@ -36,7 +37,7 @@ public RotationSolverPlugin(DalamudPluginInterface pluginInterface)
try
{
Service.Config = JsonConvert.DeserializeObject<PluginConfiguration>(
File.ReadAllText(Service.Interface.ConfigFile.FullName))
File.ReadAllText(Svc.PluginInterface.ConfigFile.FullName))
?? new PluginConfiguration();
}
catch
Expand All @@ -55,9 +56,9 @@ public RotationSolverPlugin(DalamudPluginInterface pluginInterface)
windowSystem.AddWindow(_nextActionWindow);
windowSystem.AddWindow(_cooldownWindow);

Service.Interface.UiBuilder.OpenConfigUi += OnOpenConfigUi;
Service.Interface.UiBuilder.Draw += windowSystem.Draw;
Service.Interface.UiBuilder.Draw += OverlayWindow.Draw;
Svc.PluginInterface.UiBuilder.OpenConfigUi += OnOpenConfigUi;
Svc.PluginInterface.UiBuilder.Draw += windowSystem.Draw;
Svc.PluginInterface.UiBuilder.Draw += OverlayWindow.Draw;

MajorUpdater.Enable();
OtherConfiguration.Init();
Expand Down Expand Up @@ -97,9 +98,9 @@ internal static void ChangeUITranslation()
public void Dispose()
{
RSCommands.Disable();
Service.Interface.UiBuilder.OpenConfigUi -= OnOpenConfigUi;
Service.Interface.UiBuilder.Draw -= windowSystem.Draw;
Service.Interface.UiBuilder.Draw -= OverlayWindow.Draw;
Svc.PluginInterface.UiBuilder.OpenConfigUi -= OnOpenConfigUi;
Svc.PluginInterface.UiBuilder.Draw -= windowSystem.Draw;
Svc.PluginInterface.UiBuilder.Draw -= OverlayWindow.Draw;

foreach (var item in _dis)
{
Expand Down
3 changes: 2 additions & 1 deletion RotationSolver/UI/ImGuiHelper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Dalamud.Interface.Colors;
using Dalamud.Interface.Components;
using Dalamud.Utility;
using ECommons.DalamudServices;
using FFXIVClientStructs.FFXIV.Client.Game;
using RotationSolver.Basic.Configuration;
using RotationSolver.Commands;
Expand Down Expand Up @@ -875,7 +876,7 @@ public static void Display(this RotationDescAttribute attr, ICustomRotation rota
public unsafe static ImFontPtr GetFont(float size)
{
var style = new Dalamud.Interface.GameFonts.GameFontStyle(Dalamud.Interface.GameFonts.GameFontStyle.GetRecommendedFamilyAndSize(Dalamud.Interface.GameFonts.GameFontFamily.Axis, size));
var font = Service.Interface.UiBuilder.GetGameFontHandle(style).ImFont;
var font = Svc.PluginInterface.UiBuilder.GetGameFontHandle(style).ImFont;

if((IntPtr)font.NativePtr == IntPtr.Zero)
{
Expand Down
11 changes: 6 additions & 5 deletions RotationSolver/UI/OverlayWindow.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Dalamud.Interface;
using ECommons.DalamudServices;
using ECommons.GameHelpers;
using RotationSolver.Updaters;

Expand Down Expand Up @@ -78,7 +79,7 @@ private static void DrawHealthRatio()
foreach (GameObject t in DataCenter.AllTargets)
{
if (t is not BattleChara b) continue;
if (Service.WorldToScreen(t.Position, out var p))
if (Svc.GameGui.WorldToScreen(t.Position, out var p))
{
ImGui.GetWindowDrawList().AddText(p, HealthRatioColor, $"Health Ratio: {b.CurrentHp / calHealth:F2} / {b.MaxHp / calHealth:F2}");
}
Expand All @@ -97,7 +98,7 @@ private unsafe static void DrawMoveTarget()

DrawTarget(tar, color, 8, out var scrPos);

if (Service.WorldToScreen(Player.Object.Position, out var plyPos))
if (Svc.GameGui.WorldToScreen(Player.Object.Position, out var plyPos))
{
var dir = scrPos - plyPos;

Expand All @@ -114,7 +115,7 @@ private unsafe static void DrawMoveTarget()

private static void DrawTarget(BattleChara tar, uint color, float radius, out Vector2 scrPos)
{
if (Service.WorldToScreen(tar.Position, out scrPos))
if (Svc.GameGui.WorldToScreen(tar.Position, out scrPos))
{
ImGui.GetWindowDrawList().AddCircle(scrPos, radius, color, COUNT, radius * 0.8f);
}
Expand All @@ -138,7 +139,7 @@ private static void DrawPositional()
&& !ActionUpdater.NextGCDAction.IsSingleTarget) return;

Vector3 pPosition = target.Position;
Service.WorldToScreen(pPosition, out var scrPos);
Svc.GameGui.WorldToScreen(pPosition, out var scrPos);

float radius = target.HitboxRadius + Player.Object.HitboxRadius + 3;
float rotation = target.Rotation;
Expand Down Expand Up @@ -238,7 +239,7 @@ private static void SectorPlots(ref List<Vector2> pts, Vector3 centre, float rad
var step = round / segments;
for (int i = 0; i <= segments; i++)
{
Service.WorldToScreen(ChangePoint(centre, radius, rotation + i * step), out var pt);
Svc.GameGui.WorldToScreen(ChangePoint(centre, radius, rotation + i * step), out var pt);
pts.Add(pt);
}
}
Expand Down
5 changes: 3 additions & 2 deletions RotationSolver/UI/RotationConfigWindow_Debug.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ECommons.GameHelpers;
using ECommons.DalamudServices;
using ECommons.GameHelpers;
using FFXIVClientStructs.FFXIV.Client.Game.Fate;
using RotationSolver.Updaters;

Expand Down Expand Up @@ -114,7 +115,7 @@ private unsafe void DrawTargetData()
ImGui.Text("EventType: " + b.GetEventType().ToString());
ImGui.Text("NamePlate: " + b.GetNamePlateIcon().ToString());
ImGui.Text("StatusFlags: " + b.StatusFlags.ToString());
ImGui.Text("InView: " + Service.WorldToScreen(b.Position, out _).ToString());
ImGui.Text("InView: " + Svc.GameGui.WorldToScreen(b.Position, out _).ToString());
ImGui.Text("Name Id: " + b.NameId.ToString());
ImGui.Text("Data Id: " + b.DataId.ToString());
ImGui.Text("Targetable: " + b.GetAddress()->TargetableStatus.ToString());
Expand Down
3 changes: 2 additions & 1 deletion RotationSolver/Updaters/MajorUpdater.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Dalamud.Game;
using Dalamud.Game.ClientState.Conditions;
using Dalamud.Logging;
using ECommons.DalamudServices;
using ECommons.GameHelpers;
using RotationSolver.Commands;

Expand Down Expand Up @@ -86,7 +87,7 @@ private static void FrameworkUpdate(Framework framework)
public static void Enable()
{
Service.Framework.Update += FrameworkUpdate;
ActionSequencerUpdater.Enable(Service.Interface.ConfigDirectory.FullName + "\\Conditions");
ActionSequencerUpdater.Enable(Svc.PluginInterface.ConfigDirectory.FullName + "\\Conditions");

SocialUpdater.Enable();
}
Expand Down
3 changes: 2 additions & 1 deletion RotationSolver/Updaters/RotationUpdater.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Dalamud.Logging;
using ECommons.DalamudServices;
using ECommons.GameHelpers;
using RotationSolver.Data;
using RotationSolver.Helpers;
Expand Down Expand Up @@ -31,7 +32,7 @@ public static async Task GetAllCustomRotationsAsync(DownloadOption option)

try
{
var relayFolder = Service.Interface.ConfigDirectory.FullName + "\\Rotations";
var relayFolder = Svc.PluginInterface.ConfigDirectory.FullName + "\\Rotations";
Directory.CreateDirectory(relayFolder);

if (option.HasFlag(DownloadOption.Local))
Expand Down
3 changes: 2 additions & 1 deletion RotationSolver/Updaters/TargetUpdater.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Dalamud.Game.ClientState.Objects.Enums;
using Dalamud.Game.ClientState.Objects.SubKinds;
using ECommons.DalamudServices;
using ECommons.GameHelpers;
using FFXIVClientStructs.FFXIV.Client.UI;
using FFXIVClientStructs.FFXIV.Client.UI.Agent;
Expand Down Expand Up @@ -76,7 +77,7 @@ private unsafe static void UpdateHostileTargets(IEnumerable<BattleChara> allTarg

if (Service.Config.OnlyAttackInView)
{
if (!Service.WorldToScreen(b.Position, out _)) return false;
if (!Svc.GameGui.WorldToScreen(b.Position, out _)) return false;
}

return true;
Expand Down
3 changes: 2 additions & 1 deletion RotationSolver/Watcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Dalamud.Logging;
using Dalamud.Plugin.Ipc;
using Dalamud.Utility.Signatures;
using ECommons.DalamudServices;
using ECommons.GameHelpers;
using FFXIVClientStructs.FFXIV.Client.Game;
using RotationSolver.Basic.Configuration;
Expand Down Expand Up @@ -31,7 +32,7 @@ public Watcher()
SignatureHelper.Initialise(this);
_receiveAbilityHook?.Enable();

IpcSubscriber = Service.Interface.GetIpcSubscriber<object, object>("PingPlugin.Ipc");
IpcSubscriber = Svc.PluginInterface.GetIpcSubscriber<object, object>("PingPlugin.Ipc");
IpcSubscriber.Subscribe(UpdateRTTDetour);
}

Expand Down

0 comments on commit 719e0ff

Please sign in to comment.