From 797bcade90383a6e0dd5c5d3bf0619c805af9ce2 Mon Sep 17 00:00:00 2001 From: Raymond Date: Sun, 22 Aug 2021 07:57:41 -0400 Subject: [PATCH 01/11] ClientState was set twice --- Dalamud/Dalamud.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dalamud/Dalamud.cs b/Dalamud/Dalamud.cs index 838d5c7c8..47a973c66 100644 --- a/Dalamud/Dalamud.cs +++ b/Dalamud/Dalamud.cs @@ -143,7 +143,7 @@ namespace Dalamud Service.Set(); Log.Information("[T2] NH OK!"); - Service.Set(); + var clientState = Service.Set(); Log.Information("[T2] CS OK!"); var localization = Service.Set(new Localization(Path.Combine(this.AssetDirectory.FullName, "UIRes", "loc", "dalamud"), "dalamud_")); @@ -210,7 +210,7 @@ namespace Dalamud Log.Information("[T2] CH OK!"); - Service.Set().Enable(); + clientState.Enable(); Log.Information("[T2] CS ENABLE!"); Service.Set().Enable(); From 9f863a4dbbaa371898779656eca8f8b0076b8931 Mon Sep 17 00:00:00 2001 From: Raymond Date: Sun, 22 Aug 2021 07:57:50 -0400 Subject: [PATCH 02/11] Prevent Services from being set twice --- Dalamud/Service{T}.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Dalamud/Service{T}.cs b/Dalamud/Service{T}.cs index daf291494..203b9f286 100644 --- a/Dalamud/Service{T}.cs +++ b/Dalamud/Service{T}.cs @@ -42,6 +42,9 @@ namespace Dalamud /// The set object. public static T Set() { + if (instance != null) + throw new Exception($"Service {typeof(T).FullName} was set twice"); + var obj = (T?)Activator.CreateInstance(typeof(T), true); SetInstanceObject(obj); From 92d943937a557fb7052b6c11095550cf8ff52524 Mon Sep 17 00:00:00 2001 From: Raymond Date: Sun, 22 Aug 2021 07:58:06 -0400 Subject: [PATCH 03/11] Throw meaningful exceptions, not Linq exceptions --- Dalamud/Plugin/Internal/LocalPlugin.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Dalamud/Plugin/Internal/LocalPlugin.cs b/Dalamud/Plugin/Internal/LocalPlugin.cs index 7c3c9ef25..82240b2dd 100644 --- a/Dalamud/Plugin/Internal/LocalPlugin.cs +++ b/Dalamud/Plugin/Internal/LocalPlugin.cs @@ -57,7 +57,9 @@ namespace Dalamud.Plugin.Internal this.pluginAssembly = this.loader.LoadDefaultAssembly(); // InvalidOperationException - this.pluginType = this.pluginAssembly.GetTypes().First(type => type.IsAssignableTo(typeof(IDalamudPlugin))); + this.pluginType = this.pluginAssembly.GetTypes().FirstOrDefault(type => type.IsAssignableTo(typeof(IDalamudPlugin))); + if (this.pluginType == default) + throw new Exception("Nothing inherits from IDalamudPlugin"); assemblyVersion = this.pluginAssembly.GetName().Version; } From a10dd416ac2b7023912cdd3836dd6da58a2d68ec Mon Sep 17 00:00:00 2001 From: Raymond Date: Sun, 22 Aug 2021 07:58:27 -0400 Subject: [PATCH 04/11] QoLBar reflects for these, may as well expose them. --- Dalamud/Plugin/DalamudPluginInterface.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Dalamud/Plugin/DalamudPluginInterface.cs b/Dalamud/Plugin/DalamudPluginInterface.cs index 73fec676d..f2988fa8e 100644 --- a/Dalamud/Plugin/DalamudPluginInterface.cs +++ b/Dalamud/Plugin/DalamudPluginInterface.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; @@ -123,6 +124,16 @@ namespace Dalamud.Plugin /// public XivChatType GeneralChatType { get; private set; } + /// + /// Gets a list of installed plugin names. + /// + public List PluginNames => Service.Get().InstalledPlugins.Select(p => p.Manifest.Name).ToList(); + + /// + /// Gets a list of installed plugin internal names. + /// + public List PluginInternalNames => Service.Get().InstalledPlugins.Select(p => p.Manifest.InternalName).ToList(); + #region Configuration /// @@ -210,7 +221,8 @@ namespace Dalamud.Plugin #endregion /// - /// Unregister your plugin and dispose all references. You have to call this when your IDalamudPlugin is disposed. + /// Unregister your plugin and dispose all references. + /// You have to call this when your IDalamudPlugin is disposed. /// public void Dispose() { From ca3973502256a724be7c0c0b37231c31d889f9df Mon Sep 17 00:00:00 2001 From: Raymond Date: Sun, 22 Aug 2021 07:59:03 -0400 Subject: [PATCH 05/11] Incorrect logic in ServiceContainer version check --- Dalamud/IoC/Internal/ServiceContainer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dalamud/IoC/Internal/ServiceContainer.cs b/Dalamud/IoC/Internal/ServiceContainer.cs index e806328c3..95c063b57 100644 --- a/Dalamud/IoC/Internal/ServiceContainer.cs +++ b/Dalamud/IoC/Internal/ServiceContainer.cs @@ -52,7 +52,7 @@ namespace Dalamud.IoC.Internal return (parameterType, requiredVersion); }); - var versionCheck = parameters.Any(p => + var versionCheck = parameters.All(p => { // if there's no required version, ignore it if (p.requiredVersion == null) From 5303a93a3d90fb141a6c102a64de9b4436e67ae8 Mon Sep 17 00:00:00 2001 From: Raymond Date: Sun, 22 Aug 2021 08:03:22 -0400 Subject: [PATCH 06/11] Fail gracefully for IDalamudPlugin check failures --- Dalamud/Plugin/Internal/LocalPlugin.cs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/Dalamud/Plugin/Internal/LocalPlugin.cs b/Dalamud/Plugin/Internal/LocalPlugin.cs index 82240b2dd..f7b7112ce 100644 --- a/Dalamud/Plugin/Internal/LocalPlugin.cs +++ b/Dalamud/Plugin/Internal/LocalPlugin.cs @@ -55,13 +55,6 @@ namespace Dalamud.Plugin.Internal { // BadImageFormatException this.pluginAssembly = this.loader.LoadDefaultAssembly(); - - // InvalidOperationException - this.pluginType = this.pluginAssembly.GetTypes().FirstOrDefault(type => type.IsAssignableTo(typeof(IDalamudPlugin))); - if (this.pluginType == default) - throw new Exception("Nothing inherits from IDalamudPlugin"); - - assemblyVersion = this.pluginAssembly.GetName().Version; } catch (Exception ex) { @@ -73,6 +66,19 @@ namespace Dalamud.Plugin.Internal throw new InvalidPluginException(this.DllFile); } + this.pluginType = this.pluginAssembly.GetTypes().FirstOrDefault(type => type.IsAssignableTo(typeof(IDalamudPlugin))); + if (this.pluginType == default) + { + this.pluginAssembly = null; + this.pluginType = null; + this.loader.Dispose(); + + Log.Error($"Nothing inherits from IDalamudPlugin: {this.DllFile.Name}"); + throw new InvalidPluginException(this.DllFile); + } + + assemblyVersion = this.pluginAssembly.GetName().Version; + // Files that may or may not exist this.manifestFile = LocalPluginManifest.GetManifestFile(this.DllFile); this.disabledFile = LocalPluginManifest.GetDisabledFile(this.DllFile); From a7bb97c91f255b950ff064001d4db8273bd2a6cf Mon Sep 17 00:00:00 2001 From: Raymond Date: Sun, 22 Aug 2021 08:21:47 -0400 Subject: [PATCH 07/11] Fail and display fullName --- Dalamud/Plugin/Internal/LocalPlugin.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dalamud/Plugin/Internal/LocalPlugin.cs b/Dalamud/Plugin/Internal/LocalPlugin.cs index f7b7112ce..1bbebb1d7 100644 --- a/Dalamud/Plugin/Internal/LocalPlugin.cs +++ b/Dalamud/Plugin/Internal/LocalPlugin.cs @@ -62,7 +62,7 @@ namespace Dalamud.Plugin.Internal this.pluginType = null; this.loader.Dispose(); - Log.Error(ex, $"Not a plugin: {this.DllFile.Name}"); + Log.Error(ex, $"Not a plugin: {this.DllFile.FullName}"); throw new InvalidPluginException(this.DllFile); } @@ -73,7 +73,7 @@ namespace Dalamud.Plugin.Internal this.pluginType = null; this.loader.Dispose(); - Log.Error($"Nothing inherits from IDalamudPlugin: {this.DllFile.Name}"); + Log.Error($"Nothing inherits from IDalamudPlugin: {this.DllFile.FullName}"); throw new InvalidPluginException(this.DllFile); } From f458b1d0c1347c6d93706a732bbcc411a4349fac Mon Sep 17 00:00:00 2001 From: Raymond Date: Sun, 22 Aug 2021 08:21:58 -0400 Subject: [PATCH 08/11] Fix disposed exception parameters --- Dalamud/Hooking/Hook.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dalamud/Hooking/Hook.cs b/Dalamud/Hooking/Hook.cs index ab6d1fd69..422fa8130 100644 --- a/Dalamud/Hooking/Hook.cs +++ b/Dalamud/Hooking/Hook.cs @@ -227,7 +227,7 @@ namespace Dalamud.Hooking { if (this.IsDisposed) { - throw new ObjectDisposedException("Hook is already disposed."); + throw new ObjectDisposedException(message: "Hook is already disposed", null); } } } From 2c0337762a7bb756a96e61892329c1522a4f928f Mon Sep 17 00:00:00 2001 From: Raymond Date: Sun, 22 Aug 2021 08:48:09 -0400 Subject: [PATCH 09/11] Remove extra disable in FlyTextGui.Dispose --- Dalamud/Game/Gui/FlyText/FlyTextGui.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Dalamud/Game/Gui/FlyText/FlyTextGui.cs b/Dalamud/Game/Gui/FlyText/FlyTextGui.cs index 2255e9171..043f02755 100644 --- a/Dalamud/Game/Gui/FlyText/FlyTextGui.cs +++ b/Dalamud/Game/Gui/FlyText/FlyTextGui.cs @@ -107,7 +107,6 @@ namespace Dalamud.Game.Gui.FlyText /// public void Dispose() { - this.createFlyTextHook.Disable(); this.createFlyTextHook.Dispose(); } From 69561fe4077b2e3d3126962af0c29e50210ed8d7 Mon Sep 17 00:00:00 2001 From: Raymond Date: Sun, 22 Aug 2021 10:57:26 -0400 Subject: [PATCH 10/11] Fix GameObject.Name length --- Dalamud/Game/ClientState/Objects/Types/GameObject.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dalamud/Game/ClientState/Objects/Types/GameObject.cs b/Dalamud/Game/ClientState/Objects/Types/GameObject.cs index 138dc43e2..8312b7374 100644 --- a/Dalamud/Game/ClientState/Objects/Types/GameObject.cs +++ b/Dalamud/Game/ClientState/Objects/Types/GameObject.cs @@ -92,7 +92,7 @@ namespace Dalamud.Game.ClientState.Objects.Types /// /// Gets the name of this . /// - public SeString Name => MemoryHelper.ReadSeString((IntPtr)this.Struct->Name, 32); + public SeString Name => MemoryHelper.ReadSeString((IntPtr)this.Struct->Name, 64); /// /// Gets the object ID of this . From 76b005d33b5095af3505dfd50845ca916f9d12b0 Mon Sep 17 00:00:00 2001 From: Raymond Date: Sun, 22 Aug 2021 10:57:37 -0400 Subject: [PATCH 11/11] Re-add Character.NameId --- Dalamud/Game/ClientState/Objects/Types/Character.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Dalamud/Game/ClientState/Objects/Types/Character.cs b/Dalamud/Game/ClientState/Objects/Types/Character.cs index 97a0a53d5..17a1ec6f3 100644 --- a/Dalamud/Game/ClientState/Objects/Types/Character.cs +++ b/Dalamud/Game/ClientState/Objects/Types/Character.cs @@ -88,6 +88,11 @@ namespace Dalamud.Game.ClientState.Objects.Types /// public override uint TargetObjectId => this.Struct->GameObject.TargetObjectID; + /// + /// Gets the name ID of the character. + /// + public uint NameId => this.Struct->NameID; + /// /// Gets the status flags. ///