refactor: update for api 9

This commit is contained in:
Anna 2023-09-28 20:53:50 -04:00
parent ffb3c8c437
commit 8cc324ba84
Signed by: anna
GPG Key ID: D0943384CD9F87D1
10 changed files with 40 additions and 49 deletions

View File

@ -1,9 +1,7 @@
using System.Diagnostics; using System.Diagnostics;
using System.Numerics; using System.Numerics;
using Dalamud.Data;
using Dalamud.Game;
using Dalamud.Game.ClientState.Conditions; using Dalamud.Game.ClientState.Conditions;
using Dalamud.Logging; using Dalamud.Plugin.Services;
using Lumina.Excel.GeneratedSheets; using Lumina.Excel.GeneratedSheets;
using Newtonsoft.Json; using Newtonsoft.Json;
using OrangeGuidanceTomestone.Helpers; using OrangeGuidanceTomestone.Helpers;
@ -20,7 +18,7 @@ internal class Messages : IDisposable {
"bg/ex2/02_est_e3/common/vfx/eff/b0941trp1f_o.avfx", "bg/ex2/02_est_e3/common/vfx/eff/b0941trp1f_o.avfx",
}; };
private static string GetPath(DataManager data, Message message) { private static string GetPath(IDataManager data, Message message) {
var glyph = message.Glyph; var glyph = message.Glyph;
if (glyph < 0 || glyph >= VfxPaths.Length) { if (glyph < 0 || glyph >= VfxPaths.Length) {
// not checking if this exists, but the check is really only for the // not checking if this exists, but the check is really only for the
@ -105,7 +103,7 @@ internal class Messages : IDisposable {
private readonly Stopwatch _timer = new(); private readonly Stopwatch _timer = new();
private void TerritoryChanged(object? sender, ushort e) { private void TerritoryChanged(ushort territory) {
this._territoryChanged = true; this._territoryChanged = true;
this.RemoveVfx(); this.RemoveVfx();
} }
@ -113,7 +111,7 @@ internal class Messages : IDisposable {
private ushort _lastTerritory; private ushort _lastTerritory;
private bool _territoryChanged; private bool _territoryChanged;
private void DetermineIfSpawn(Framework framework) { private void DetermineIfSpawn(IFramework framework) {
var current = this.Plugin.ClientState.TerritoryType; var current = this.Plugin.ClientState.TerritoryType;
var diffTerritory = current != this._lastTerritory; var diffTerritory = current != this._lastTerritory;
@ -132,7 +130,7 @@ internal class Messages : IDisposable {
this._lastTerritory = current; this._lastTerritory = current;
} }
private void RemoveConditionally(Framework framework) { private void RemoveConditionally(IFramework framework) {
var nowCutscene = this.CutsceneActive; var nowCutscene = this.CutsceneActive;
var cutsceneChanged = this._inCutscene != nowCutscene; var cutsceneChanged = this._inCutscene != nowCutscene;
if (this.Plugin.Config.DisableInCutscene && cutsceneChanged) { if (this.Plugin.Config.DisableInCutscene && cutsceneChanged) {
@ -157,24 +155,20 @@ internal class Messages : IDisposable {
this._inGpose = nowGpose; this._inGpose = nowGpose;
} }
private unsafe void HandleSpawnQueue(Framework framework) { private unsafe void HandleSpawnQueue(IFramework framework) {
if (!this.SpawnQueue.TryDequeue(out var message)) { if (!this.SpawnQueue.TryDequeue(out var message)) {
return; return;
} }
PluginLog.Debug($"spawning vfx for {message.Id}"); Plugin.Log.Debug($"spawning vfx for {message.Id}");
var rotation = Quaternion.CreateFromYawPitchRoll(message.Yaw, 0, 0); var rotation = Quaternion.CreateFromYawPitchRoll(message.Yaw, 0, 0);
var path = GetPath(this.Plugin.DataManager, message); var path = GetPath(this.Plugin.DataManager, message);
if (this.Plugin.Vfx.SpawnStatic(message.Id, path, message.Position, rotation) == null) { if (this.Plugin.Vfx.SpawnStatic(message.Id, path, message.Position, rotation) == null) {
PluginLog.Debug("trying again"); Plugin.Log.Debug("trying again");
this.SpawnQueue.Enqueue(message); this.SpawnQueue.Enqueue(message);
} }
} }
private void SpawnVfx(object? sender, EventArgs e) {
this.SpawnVfx();
}
internal void SpawnVfx() { internal void SpawnVfx() {
var territory = this.Plugin.ClientState.TerritoryType; var territory = this.Plugin.ClientState.TerritoryType;
if (territory == 0 || this.Plugin.Config.BannedTerritories.Contains(territory)) { if (territory == 0 || this.Plugin.Config.BannedTerritories.Contains(territory)) {
@ -212,7 +206,7 @@ internal class Messages : IDisposable {
try { try {
await this.DownloadMessages(world, territory, ward, plot); await this.DownloadMessages(world, territory, ward, plot);
} catch (Exception ex) { } catch (Exception ex) {
PluginLog.LogError(ex, $"Failed to get messages for territory {territory}"); Plugin.Log.Error(ex, $"Failed to get messages for territory {territory}");
} }
}); });
} }

View File

@ -16,7 +16,7 @@ internal unsafe class VfxReplacer : IDisposable {
internal VfxReplacer(Plugin plugin) { internal VfxReplacer(Plugin plugin) {
this.Plugin = plugin; this.Plugin = plugin;
SignatureHelper.Initialise(this); this.Plugin.GameInteropProvider.InitializeFromAttributes(this);
this._readSqPackHook!.Enable(); this._readSqPackHook!.Enable();
} }

View File

@ -39,10 +39,6 @@
<HintPath>$(DalamudLibPath)\ImGui.NET.dll</HintPath> <HintPath>$(DalamudLibPath)\ImGui.NET.dll</HintPath>
<Private>false</Private> <Private>false</Private>
</Reference> </Reference>
<Reference Include="ImGuiScene">
<HintPath>$(DalamudLibPath)\ImGuiScene.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="Lumina"> <Reference Include="Lumina">
<HintPath>$(DalamudLibPath)\Lumina.dll</HintPath> <HintPath>$(DalamudLibPath)\Lumina.dll</HintPath>
<Private>false</Private> <Private>false</Private>

View File

@ -1,6 +1,5 @@
using System.Diagnostics; using System.Diagnostics;
using Dalamud.Game; using Dalamud.Plugin.Services;
using Dalamud.Logging;
using OrangeGuidanceTomestone.Helpers; using OrangeGuidanceTomestone.Helpers;
namespace OrangeGuidanceTomestone; namespace OrangeGuidanceTomestone;
@ -22,7 +21,7 @@ internal class Pinger : IDisposable {
this.Plugin.Framework.Update -= this.Ping; this.Plugin.Framework.Update -= this.Ping;
} }
private void Ping(Framework framework) { private void Ping(IFramework framework) {
if (this.Stopwatch.Elapsed < TimeSpan.FromSeconds(this._waitSecs)) { if (this.Stopwatch.Elapsed < TimeSpan.FromSeconds(this._waitSecs)) {
return; return;
} }
@ -45,7 +44,7 @@ internal class Pinger : IDisposable {
); );
if (!resp.IsSuccessStatusCode) { if (!resp.IsSuccessStatusCode) {
PluginLog.LogWarning($"Failed to ping, status {resp.StatusCode}"); Plugin.Log.Warning($"Failed to ping, status {resp.StatusCode}");
} }
}); });
} }

View File

@ -1,42 +1,43 @@
using Dalamud.Data; using Dalamud.IoC;
using Dalamud.Game;
using Dalamud.Game.ClientState;
using Dalamud.Game.ClientState.Conditions;
using Dalamud.Game.Command;
using Dalamud.Game.Gui;
using Dalamud.IoC;
using Dalamud.Plugin; using Dalamud.Plugin;
using Dalamud.Plugin.Services;
using OrangeGuidanceTomestone.MiniPenumbra; using OrangeGuidanceTomestone.MiniPenumbra;
using XivCommon; using XivCommon;
namespace OrangeGuidanceTomestone; namespace OrangeGuidanceTomestone;
public class Plugin : IDalamudPlugin { public class Plugin : IDalamudPlugin {
public string Name => "Orange Guidance Tomestone"; internal static string Name => "Orange Guidance Tomestone";
[PluginService]
internal static IPluginLog Log { get; private set; }
[PluginService] [PluginService]
internal DalamudPluginInterface Interface { get; init; } internal DalamudPluginInterface Interface { get; init; }
[PluginService] [PluginService]
internal ChatGui ChatGui { get; init; } internal IChatGui ChatGui { get; init; }
[PluginService] [PluginService]
internal ClientState ClientState { get; init; } internal IClientState ClientState { get; init; }
[PluginService] [PluginService]
internal CommandManager CommandManager { get; init; } internal ICommandManager CommandManager { get; init; }
[PluginService] [PluginService]
internal Condition Condition { get; init; } internal ICondition Condition { get; init; }
[PluginService] [PluginService]
internal DataManager DataManager { get; init; } internal IDataManager DataManager { get; init; }
[PluginService] [PluginService]
internal Framework Framework { get; init; } internal IFramework Framework { get; init; }
[PluginService] [PluginService]
internal GameGui GameGui { get; init; } internal IGameGui GameGui { get; init; }
[PluginService]
internal IGameInteropProvider GameInteropProvider { get; init; }
internal Configuration Config { get; } internal Configuration Config { get; }
internal XivCommonBase Common { get; } internal XivCommonBase Common { get; }
@ -54,7 +55,7 @@ public class Plugin : IDalamudPlugin {
this.Config = this.Interface!.GetPluginConfig() as Configuration ?? new Configuration(); this.Config = this.Interface!.GetPluginConfig() as Configuration ?? new Configuration();
this.Common = new XivCommonBase(); this.Common = new XivCommonBase();
this.Vfx = new Vfx(); this.Vfx = new Vfx(this);
this.Messages = new Messages(this); this.Messages = new Messages(this);
this.Ui = new PluginUi(this); this.Ui = new PluginUi(this);
this.VfxReplacer = new VfxReplacer(this); this.VfxReplacer = new VfxReplacer(this);

View File

@ -41,13 +41,13 @@ public class PluginUi : IDisposable {
private void DrawModals() { private void DrawModals() {
while (this.ToShow.TryDequeue(out var toShow)) { while (this.ToShow.TryDequeue(out var toShow)) {
ImGui.OpenPopup($"{this.Plugin.Name}##{toShow}"); ImGui.OpenPopup($"{Plugin.Name}##{toShow}");
} }
var toRemove = -1; var toRemove = -1;
for (var i = 0; i < this.Modals.Count; i++) { for (var i = 0; i < this.Modals.Count; i++) {
var (id, text) = this.Modals[i]; var (id, text) = this.Modals[i];
if (!ImGui.BeginPopupModal($"{this.Plugin.Name}##{id}")) { if (!ImGui.BeginPopupModal($"{Plugin.Name}##{id}")) {
continue; continue;
} }

View File

@ -26,7 +26,7 @@ internal class MainWindow {
} }
ImGui.SetNextWindowSize(new Vector2(475, 350), ImGuiCond.FirstUseEver); ImGui.SetNextWindowSize(new Vector2(475, 350), ImGuiCond.FirstUseEver);
if (!ImGui.Begin(this.Plugin.Name, ref this.Visible)) { if (!ImGui.Begin(Plugin.Name, ref this.Visible)) {
ImGui.End(); ImGui.End();
return; return;
} }
@ -65,7 +65,7 @@ internal class MainWindow {
private void DrawApiKey() { private void DrawApiKey() {
ImGui.PushTextWrapPos(); ImGui.PushTextWrapPos();
ImGui.TextUnformatted($"Somehow, {this.Plugin.Name} wasn't able to register you an account automatically."); ImGui.TextUnformatted($"Somehow, {Plugin.Name} wasn't able to register you an account automatically.");
ImGui.TextUnformatted("Click the button below to try again."); ImGui.TextUnformatted("Click the button below to try again.");
ImGui.PopTextWrapPos(); ImGui.PopTextWrapPos();

View File

@ -1,8 +1,8 @@
using System.Numerics; using System.Numerics;
using System.Text; using System.Text;
using Dalamud.Game.ClientState.Conditions; using Dalamud.Game.ClientState.Conditions;
using Dalamud.Interface.Internal;
using ImGuiNET; using ImGuiNET;
using ImGuiScene;
using Newtonsoft.Json; using Newtonsoft.Json;
using OrangeGuidanceTomestone.Helpers; using OrangeGuidanceTomestone.Helpers;
@ -21,7 +21,7 @@ internal class Write : ITab {
private (int, int) _word2 = (-1, -1); private (int, int) _word2 = (-1, -1);
private int _glyph; private int _glyph;
private List<TextureWrap> GlyphImages { get; } = new(); private List<IDalamudTextureWrap> GlyphImages { get; } = new();
private void LoadSignImages() { private void LoadSignImages() {
for (var i = 0; i < Messages.VfxPaths.Length; i++) { for (var i = 0; i < Messages.VfxPaths.Length; i++) {

View File

@ -1,5 +1,6 @@
using System.Numerics; using System.Numerics;
using Dalamud.Interface; using Dalamud.Interface;
using Dalamud.Interface.Utility;
using ImGuiNET; using ImGuiNET;
using OrangeGuidanceTomestone.Helpers; using OrangeGuidanceTomestone.Helpers;

View File

@ -6,7 +6,7 @@ using Dalamud.Utility.Signatures;
namespace OrangeGuidanceTomestone; namespace OrangeGuidanceTomestone;
internal unsafe class Vfx : IDisposable { internal unsafe class Vfx : IDisposable {
private static readonly byte[] Pool = Encoding.UTF8.GetBytes("Client.System.Scheduler.Instance.VfxObject"); private static readonly byte[] Pool = "Client.System.Scheduler.Instance.VfxObject"u8.ToArray();
[Signature("E8 ?? ?? ?? ?? F3 0F 10 35 ?? ?? ?? ?? 48 89 43 08")] [Signature("E8 ?? ?? ?? ?? F3 0F 10 35 ?? ?? ?? ?? 48 89 43 08")]
private delegate* unmanaged<byte*, byte*, VfxStruct*> _staticVfxCreate; private delegate* unmanaged<byte*, byte*, VfxStruct*> _staticVfxCreate;
@ -19,8 +19,8 @@ internal unsafe class Vfx : IDisposable {
private Dictionary<Guid, IntPtr> Spawned { get; } = new(); private Dictionary<Guid, IntPtr> Spawned { get; } = new();
internal Vfx() { internal Vfx(Plugin plugin) {
SignatureHelper.Initialise(this); plugin.GameInteropProvider.InitializeFromAttributes(this);
} }
public void Dispose() { public void Dispose() {