refactor: update for api 9

This commit is contained in:
Anna 2023-09-27 21:44:39 -04:00
parent 0f20595e0f
commit c76be2aaad
Signed by: anna
GPG Key ID: D0943384CD9F87D1
8 changed files with 43 additions and 43 deletions

View File

@ -7,7 +7,6 @@ using ASodium;
using Dalamud.Game.Text; using Dalamud.Game.Text;
using Dalamud.Game.Text.SeStringHandling; using Dalamud.Game.Text.SeStringHandling;
using Dalamud.Game.Text.SeStringHandling.Payloads; using Dalamud.Game.Text.SeStringHandling.Payloads;
using Dalamud.Logging;
using Dalamud.Utility; using Dalamud.Utility;
using ExtraChat.Protocol; using ExtraChat.Protocol;
using ExtraChat.Protocol.Channels; using ExtraChat.Protocol.Channels;
@ -72,11 +71,11 @@ internal class Client : IDisposable {
this._waitersSemaphore.Dispose(); this._waitersSemaphore.Dispose();
} }
private void Login(object? sender, EventArgs e) { private void Login() {
this.StartLoop(); this.StartLoop();
} }
private void Logout(object? sender, EventArgs e) { private void Logout() {
this.StopLoop(); this.StopLoop();
} }
@ -98,9 +97,9 @@ internal class Client : IDisposable {
try { try {
await this.Loop(); await this.Loop();
} catch (Exception ex) { } catch (Exception ex) {
PluginLog.LogError(ex, "Error in client loop"); Plugin.Log.Error(ex, "Error in client loop");
if (this._wasConnected) { if (this._wasConnected) {
this.Plugin.ChatGui.PrintChat(new XivChatEntry { this.Plugin.ChatGui.Print(new XivChatEntry {
Message = "Disconnected from ExtraChat. Trying to reconnect.", Message = "Disconnected from ExtraChat. Trying to reconnect.",
Type = XivChatType.Urgent, Type = XivChatType.Urgent,
}); });
@ -164,7 +163,7 @@ internal class Client : IDisposable {
if (await this.Authenticate()) { if (await this.Authenticate()) {
this._wasConnected = true; this._wasConnected = true;
this.Plugin.ChatGui.PrintChat(new XivChatEntry { this.Plugin.ChatGui.Print(new XivChatEntry {
Message = "Connected to ExtraChat.", Message = "Connected to ExtraChat.",
Type = XivChatType.Notice, Type = XivChatType.Notice,
}); });
@ -663,7 +662,7 @@ internal class Client : IDisposable {
#pragma warning restore CS4014 #pragma warning restore CS4014
private void HandleAnnounce(AnnounceResponse resp) { private void HandleAnnounce(AnnounceResponse resp) {
this.Plugin.ChatGui.PrintChat(new XivChatEntry { this.Plugin.ChatGui.Print(new XivChatEntry {
Type = XivChatType.Notice, Type = XivChatType.Notice,
Message = $"[ExtraChat] {resp.Announcement}", Message = $"[ExtraChat] {resp.Announcement}",
}); });
@ -706,7 +705,7 @@ internal class Client : IDisposable {
break; break;
} }
default: { default: {
PluginLog.LogWarning($"Unhandled update kind: {resp.Kind}"); Plugin.Log.Warning($"Unhandled update kind: {resp.Kind}");
break; break;
} }
} }
@ -993,7 +992,7 @@ internal class Client : IDisposable {
outputChannel = XivChatType.Debug; outputChannel = XivChatType.Debug;
} }
this.Plugin.ChatGui.PrintChat(new XivChatEntry { this.Plugin.ChatGui.Print(new XivChatEntry {
Message = output.Build(), Message = output.Build(),
Name = isSelf Name = isSelf
? resp.Sender ? resp.Sender

View File

@ -1,5 +1,4 @@
using Dalamud.Game.Command; using Dalamud.Game.Command;
using Dalamud.Logging;
using ExtraChat.Util; using ExtraChat.Util;
namespace ExtraChat; namespace ExtraChat;
@ -23,7 +22,7 @@ internal class Commands : IDisposable {
this.RegisterAll(); this.RegisterAll();
} }
private void OnLogout(object? sender, EventArgs e) { private void OnLogout() {
this.UnregisterAll(); this.UnregisterAll();
} }
@ -74,7 +73,7 @@ internal class Commands : IDisposable {
this.RegisteredInternal[command] = id; this.RegisteredInternal[command] = id;
void Handler(string _, string arguments) { void Handler(string _, string arguments) {
PluginLog.LogWarning("Command handler actually invoked"); Plugin.Log.Warning("Command handler actually invoked");
} }
this.Plugin.CommandManager.AddHandler(command, new CommandInfo(Handler) { this.Plugin.CommandManager.AddHandler(command, new CommandInfo(Handler) {

View File

@ -2,7 +2,6 @@
using Dalamud.Game.Text.SeStringHandling; using Dalamud.Game.Text.SeStringHandling;
using Dalamud.Game.Text.SeStringHandling.Payloads; using Dalamud.Game.Text.SeStringHandling.Payloads;
using Dalamud.Hooking; using Dalamud.Hooking;
using Dalamud.Logging;
using Dalamud.Memory; using Dalamud.Memory;
using Dalamud.Utility.Signatures; using Dalamud.Utility.Signatures;
using FFXIVClientStructs.FFXIV.Client.System.Framework; using FFXIVClientStructs.FFXIV.Client.System.Framework;
@ -89,8 +88,8 @@ internal unsafe class GameFunctions : IDisposable {
private bool _shouldForceNameLookup; private bool _shouldForceNameLookup;
internal GameFunctions(Plugin plugin) { internal GameFunctions(Plugin plugin) {
SignatureHelper.Initialise(this);
this.Plugin = plugin; this.Plugin = plugin;
this.Plugin.GameInteropProvider.InitializeFromAttributes(this);
this.SendMessageHook!.Enable(); this.SendMessageHook!.Enable();
this.SetChatChannelHook!.Enable(); this.SetChatChannelHook!.Enable();
@ -158,7 +157,7 @@ internal unsafe class GameFunctions : IDisposable {
this.SendMessageHook.Original(a1, message, a3); this.SendMessageHook.Original(a1, message, a3);
} }
} catch (Exception ex) { } catch (Exception ex) {
PluginLog.LogError(ex, "Error in message detour"); Plugin.Log.Error(ex, "Error in message detour");
} }
} }
@ -272,7 +271,7 @@ internal unsafe class GameFunctions : IDisposable {
} }
} }
} catch (Exception ex) { } catch (Exception ex) {
PluginLog.LogError(ex, "Error in get chat colour detour"); Plugin.Log.Error(ex, "Error in get chat colour detour");
} }
return this.GetChatColourHook.Original(a1, a2); return this.GetChatColourHook.Original(a1, a2);

View File

@ -1,17 +1,12 @@
using ASodium; using ASodium;
using Dalamud.ContextMenu; using Dalamud.ContextMenu;
using Dalamud.Data;
using Dalamud.Game;
using Dalamud.Game.ClientState;
using Dalamud.Game.ClientState.Objects; using Dalamud.Game.ClientState.Objects;
using Dalamud.Game.ClientState.Objects.SubKinds; using Dalamud.Game.ClientState.Objects.SubKinds;
using Dalamud.Game.Command;
using Dalamud.Game.Gui;
using Dalamud.Game.Gui.Toast;
using Dalamud.Game.Text; using Dalamud.Game.Text;
using Dalamud.Interface.Internal.Notifications; using Dalamud.Interface.Internal.Notifications;
using Dalamud.IoC; using Dalamud.IoC;
using Dalamud.Plugin; using Dalamud.Plugin;
using Dalamud.Plugin.Services;
using ExtraChat.Integrations; using ExtraChat.Integrations;
using ExtraChat.Ui; using ExtraChat.Ui;
using ExtraChat.Util; using ExtraChat.Util;
@ -20,40 +15,45 @@ namespace ExtraChat;
// ReSharper disable once ClassNeverInstantiated.Global // ReSharper disable once ClassNeverInstantiated.Global
public class Plugin : IDalamudPlugin { public class Plugin : IDalamudPlugin {
internal const string PluginName = "ExtraChat";
internal const ushort DefaultColour = 578; internal const ushort DefaultColour = 578;
public string Name => PluginName; internal static string Name => "ExtraChat";
[PluginService]
internal static IPluginLog Log { get; private set; }
[PluginService] [PluginService]
internal DalamudPluginInterface Interface { get; init; } internal DalamudPluginInterface Interface { 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 ChatGui ChatGui { get; init; } internal IChatGui ChatGui { 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] [PluginService]
internal ObjectTable ObjectTable { get; init; } internal IObjectTable ObjectTable { get; init; }
[PluginService] [PluginService]
internal TargetManager TargetManager { get; init; } internal ITargetManager TargetManager { get; init; }
[PluginService] [PluginService]
private ToastGui ToastGui { get; init; } internal IGameInteropProvider GameInteropProvider { get; init; }
[PluginService]
private IToastGui ToastGui { get; init; }
internal Configuration Config { get; } internal Configuration Config { get; }
internal ConfigInfo ConfigInfo => this.Config.GetConfig(this.ClientState.LocalContentId); internal ConfigInfo ConfigInfo => this.Config.GetConfig(this.ClientState.LocalContentId);
@ -120,7 +120,7 @@ public class Plugin : IDalamudPlugin {
this.ContextMenu.Dispose(); this.ContextMenu.Dispose();
} }
private void FrameworkUpdate(Framework framework) { private void FrameworkUpdate(IFramework framework) {
if (this.ClientState.LocalPlayer is { } player) { if (this.ClientState.LocalPlayer is { } player) {
this.LocalPlayer = player; this.LocalPlayer = player;
} else if (!this.ClientState.IsLoggedIn) { } else if (!this.ClientState.IsLoggedIn) {
@ -173,10 +173,10 @@ public class Plugin : IDalamudPlugin {
if (this.Config.UseNativeToasts) { if (this.Config.UseNativeToasts) {
this.ToastGui.ShowNormal(message); this.ToastGui.ShowNormal(message);
} else { } else {
this.Interface.UiBuilder.AddNotification(message, this.Name, NotificationType.Info); this.Interface.UiBuilder.AddNotification(message, Name, NotificationType.Info);
} }
this.ChatGui.PrintChat(new XivChatEntry { this.ChatGui.Print(new XivChatEntry {
Type = XivChatType.SystemMessage, Type = XivChatType.SystemMessage,
Message = message, Message = message,
}); });
@ -186,10 +186,10 @@ public class Plugin : IDalamudPlugin {
if (this.Config.UseNativeToasts) { if (this.Config.UseNativeToasts) {
this.ToastGui.ShowError(message); this.ToastGui.ShowError(message);
} else { } else {
this.Interface.UiBuilder.AddNotification(message, this.Name, NotificationType.Error); this.Interface.UiBuilder.AddNotification(message, Name, NotificationType.Error);
} }
this.ChatGui.PrintChat(new XivChatEntry { this.ChatGui.Print(new XivChatEntry {
Type = XivChatType.ErrorMessage, Type = XivChatType.ErrorMessage,
Message = message, Message = message,
}); });

View File

@ -1,6 +1,7 @@
using System.Numerics; using System.Numerics;
using System.Text; using System.Text;
using Dalamud.Interface; using Dalamud.Interface;
using Dalamud.Interface.Utility;
using ExtraChat.Protocol; using ExtraChat.Protocol;
using ExtraChat.Protocol.Channels; using ExtraChat.Protocol.Channels;
using ExtraChat.Util; using ExtraChat.Util;
@ -40,10 +41,10 @@ internal class ChannelList {
var syncButton = ImGui.CalcTextSize(FontAwesomeIcon.Sync.ToIconString()).X var syncButton = ImGui.CalcTextSize(FontAwesomeIcon.Sync.ToIconString()).X
+ ImGui.GetStyle().FramePadding.X * 2; + ImGui.GetStyle().FramePadding.X * 2;
// PluginLog.Log($"syncButton: {syncButton}"); // Plugin.Log.Info($"syncButton: {syncButton}");
var addButton = ImGui.CalcTextSize(FontAwesomeIcon.Plus.ToIconString()).X var addButton = ImGui.CalcTextSize(FontAwesomeIcon.Plus.ToIconString()).X
+ ImGui.GetStyle().FramePadding.X * 2; + ImGui.GetStyle().FramePadding.X * 2;
// PluginLog.Log($"addButton: {addButton}"); // Plugin.Log.Info($"addButton: {addButton}");
var syncOffset = ImGui.GetContentRegionAvail().X - syncButton; var syncOffset = ImGui.GetContentRegionAvail().X - syncButton;
var addOffset = ImGui.GetContentRegionAvail().X - syncButton - ImGui.GetStyle().ItemSpacing.X - addButton; var addOffset = ImGui.GetContentRegionAvail().X - syncButton - ImGui.GetStyle().ItemSpacing.X - addButton;
ImGui.SameLine(syncOffset); ImGui.SameLine(syncOffset);

View File

@ -3,6 +3,7 @@ using System.Numerics;
using System.Threading.Channels; using System.Threading.Channels;
using Dalamud; using Dalamud;
using Dalamud.Interface; using Dalamud.Interface;
using Dalamud.Interface.Utility;
using Dalamud.Plugin; using Dalamud.Plugin;
using ExtraChat.Protocol.Channels; using ExtraChat.Protocol.Channels;
using ExtraChat.Util; using ExtraChat.Util;
@ -77,7 +78,7 @@ internal class PluginUi : IDisposable {
ImGui.SetNextWindowSize(new Vector2(500, 325) * ImGuiHelpers.GlobalScale, ImGuiCond.FirstUseEver); ImGui.SetNextWindowSize(new Vector2(500, 325) * ImGuiHelpers.GlobalScale, 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;
} }

View File

@ -1,6 +1,7 @@
using System.Numerics; using System.Numerics;
using System.Text; using System.Text;
using Dalamud.Interface; using Dalamud.Interface;
using Dalamud.Interface.Utility;
using ImGuiNET; using ImGuiNET;
namespace ExtraChat.Util; namespace ExtraChat.Util;

View File

@ -1,4 +1,4 @@
using Dalamud.Data; using Dalamud.Plugin.Services;
using Lumina.Excel.GeneratedSheets; using Lumina.Excel.GeneratedSheets;
namespace ExtraChat.Util; namespace ExtraChat.Util;
@ -6,7 +6,7 @@ namespace ExtraChat.Util;
internal static class WorldUtil { internal static class WorldUtil {
private static readonly Dictionary<ushort, string> WorldNames = new(); private static readonly Dictionary<ushort, string> WorldNames = new();
internal static void Initialise(DataManager data) { internal static void Initialise(IDataManager data) {
WorldNames.Clear(); WorldNames.Clear();
var worlds = data.GetExcelSheet<World>(); var worlds = data.GetExcelSheet<World>();