From 965f2142ff173829d98af00e3fd787b0f6007570 Mon Sep 17 00:00:00 2001 From: Raymond Date: Mon, 9 Aug 2021 11:04:26 -0400 Subject: [PATCH 01/23] Replace WebClient with HttpClient --- Dalamud/Plugin/Internal/PluginManager.cs | 9 +++++---- Dalamud/Plugin/Internal/PluginRepository.cs | 9 ++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Dalamud/Plugin/Internal/PluginManager.cs b/Dalamud/Plugin/Internal/PluginManager.cs index a3f4f250e..d3b7dbbd4 100644 --- a/Dalamud/Plugin/Internal/PluginManager.cs +++ b/Dalamud/Plugin/Internal/PluginManager.cs @@ -359,16 +359,17 @@ namespace Dalamud.Plugin.Internal // ignored, since the plugin may be loaded already } - using var client = new WebClient(); - var tempZip = new FileInfo(Path.GetTempFileName()); try { Log.Debug($"Downloading plugin to {tempZip} from {downloadUrl}"); - client.DownloadFile(downloadUrl, tempZip.FullName); + using var client = new HttpClient(); + var response = client.GetAsync(downloadUrl).Result; + using var fs = new FileStream(tempZip.FullName, FileMode.CreateNew); + response.Content.CopyToAsync(fs).GetAwaiter().GetResult(); } - catch (WebException ex) + catch (HttpRequestException ex) { Log.Error(ex, $"Download of plugin {repoManifest.Name} failed unexpectedly."); throw; diff --git a/Dalamud/Plugin/Internal/PluginRepository.cs b/Dalamud/Plugin/Internal/PluginRepository.cs index e76aa67d1..d90efaee8 100644 --- a/Dalamud/Plugin/Internal/PluginRepository.cs +++ b/Dalamud/Plugin/Internal/PluginRepository.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; using System.Collections.ObjectModel; -using System.Net; +using System.Net.Http; using System.Threading.Tasks; using Dalamud.Logging.Internal; @@ -74,11 +74,10 @@ namespace Dalamud.Plugin.Internal return Task.Run(() => { - using var client = new WebClient(); - Log.Information($"Fetching repo: {this.PluginMasterUrl}"); - - var data = client.DownloadString(this.PluginMasterUrl); + using var client = new HttpClient(); + using var response = client.GetAsync(this.PluginMasterUrl).Result; + var data = response.Content.ReadAsStringAsync().Result; var pluginMaster = JsonConvert.DeserializeObject>(data); pluginMaster.Sort((pm1, pm2) => pm1.Name.CompareTo(pm2.Name)); From 64bc2ddee410a9df8457730b2a6a0f22ab54e6ff Mon Sep 17 00:00:00 2001 From: Raymond Date: Mon, 9 Aug 2021 11:04:58 -0400 Subject: [PATCH 02/23] Fix Assembly hooks for sub-dependencies --- Dalamud/Plugin/Internal/PluginManager.cs | 36 +++++++++--------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/Dalamud/Plugin/Internal/PluginManager.cs b/Dalamud/Plugin/Internal/PluginManager.cs index d3b7dbbd4..ec2a9e584 100644 --- a/Dalamud/Plugin/Internal/PluginManager.cs +++ b/Dalamud/Plugin/Internal/PluginManager.cs @@ -978,26 +978,21 @@ namespace Dalamud.Plugin.Internal [SuppressMessage("StyleCop.CSharp.NamingRules", "SA1313:Parameter names should begin with lower-case letter", Justification = "Enforced naming for special injected parameters")] private static void AssemblyLocationPatch(Assembly __instance, ref string __result) { - // Assembly.GetExecutingAssembly can return this. - // Check for it as a special case and find the plugin. - if (__result.EndsWith("System.Private.CoreLib.dll", StringComparison.InvariantCultureIgnoreCase)) + if (string.IsNullOrEmpty(__result)) { foreach (var assemblyName in GetStackFrameAssemblyNames()) { if (PluginLocations.TryGetValue(assemblyName, out var data)) { __result = data.Location; - return; + break; } } } - else if (string.IsNullOrEmpty(__result)) - { - if (PluginLocations.TryGetValue(__instance.FullName, out var data)) - { - __result = data.Location; - } - } + + __result ??= string.Empty; + + Log.Verbose($"Assembly.Location // {__instance.FullName} // {__result}"); } /// @@ -1010,26 +1005,21 @@ namespace Dalamud.Plugin.Internal [SuppressMessage("StyleCop.CSharp.NamingRules", "SA1313:Parameter names should begin with lower-case letter", Justification = "Enforced naming for special injected parameters")] private static void AssemblyCodeBasePatch(Assembly __instance, ref string __result) { - // Assembly.GetExecutingAssembly can return this. - // Check for it as a special case and find the plugin. - if (__result.EndsWith("System.Private.CoreLib.dll")) + if (string.IsNullOrEmpty(__result)) { foreach (var assemblyName in GetStackFrameAssemblyNames()) { if (PluginLocations.TryGetValue(assemblyName, out var data)) { - __result = data.Location; - return; + __result = data.CodeBase; + break; } } } - else if (string.IsNullOrEmpty(__result)) - { - if (PluginLocations.TryGetValue(__instance.FullName, out var data)) - { - __result = data.Location; - } - } + + __result ??= string.Empty; + + Log.Verbose($"Assembly.CodeBase // {__instance.FullName} // {__result}"); } private static IEnumerable GetStackFrameAssemblyNames() From ff5502baa8b6aabe3cf4c28e90839309c50dc5b2 Mon Sep 17 00:00:00 2001 From: Raymond Date: Mon, 9 Aug 2021 11:06:18 -0400 Subject: [PATCH 03/23] Remove AssemblyLocation from PluginInterface ctor Hooks work better. --- .../Internal/Scratchpad/ScratchExecutionManager.cs | 2 +- Dalamud/Interface/Internal/Windows/DataWindow.cs | 4 ++-- Dalamud/Plugin/DalamudPluginInterface.cs | 9 +-------- Dalamud/Plugin/Internal/LocalPlugin.cs | 2 +- 4 files changed, 5 insertions(+), 12 deletions(-) diff --git a/Dalamud/Interface/Internal/Scratchpad/ScratchExecutionManager.cs b/Dalamud/Interface/Internal/Scratchpad/ScratchExecutionManager.cs index 729827b1e..ba3a501eb 100644 --- a/Dalamud/Interface/Internal/Scratchpad/ScratchExecutionManager.cs +++ b/Dalamud/Interface/Internal/Scratchpad/ScratchExecutionManager.cs @@ -83,7 +83,7 @@ namespace Dalamud.Interface.Internal.Scratchpad { var script = CSharpScript.Create(code, options); - var pi = new DalamudPluginInterface(this.dalamud, "Scratch-" + doc.Id, null, PluginLoadReason.Unknown); + var pi = new DalamudPluginInterface(this.dalamud, "Scratch-" + doc.Id, PluginLoadReason.Unknown); var plugin = script.ContinueWith("return new ScratchPlugin() as IDalamudPlugin;") .RunAsync().GetAwaiter().GetResult().ReturnValue; diff --git a/Dalamud/Interface/Internal/Windows/DataWindow.cs b/Dalamud/Interface/Internal/Windows/DataWindow.cs index 6b723098f..aaa20951a 100644 --- a/Dalamud/Interface/Internal/Windows/DataWindow.cs +++ b/Dalamud/Interface/Internal/Windows/DataWindow.cs @@ -468,8 +468,8 @@ namespace Dalamud.Interface.Internal.Windows private void DrawPluginIPC() { #pragma warning disable CS0618 // Type or member is obsolete - var i1 = new DalamudPluginInterface(this.dalamud, "DalamudTestSub", null, PluginLoadReason.Unknown); - var i2 = new DalamudPluginInterface(this.dalamud, "DalamudTestPub", null, PluginLoadReason.Unknown); + var i1 = new DalamudPluginInterface(this.dalamud, "DalamudTestSub", PluginLoadReason.Unknown); + var i2 = new DalamudPluginInterface(this.dalamud, "DalamudTestPub", PluginLoadReason.Unknown); if (ImGui.Button("Add test sub")) { diff --git a/Dalamud/Plugin/DalamudPluginInterface.cs b/Dalamud/Plugin/DalamudPluginInterface.cs index 8814e494a..cc3a9c247 100644 --- a/Dalamud/Plugin/DalamudPluginInterface.cs +++ b/Dalamud/Plugin/DalamudPluginInterface.cs @@ -35,9 +35,8 @@ namespace Dalamud.Plugin /// /// The dalamud instance to expose. /// The internal name of the plugin. - /// The equivalent of what Assembly.GetExecutingAssembly().Location should return. /// The reason the plugin was loaded. - internal DalamudPluginInterface(Dalamud dalamud, string pluginName, string assemblyLocation, PluginLoadReason reason) + internal DalamudPluginInterface(Dalamud dalamud, string pluginName, PluginLoadReason reason) { this.CommandManager = dalamud.CommandManager; this.Framework = dalamud.Framework; @@ -50,7 +49,6 @@ namespace Dalamud.Plugin this.dalamud = dalamud; this.pluginName = pluginName; this.configs = dalamud.PluginManager.PluginConfigs; - this.AssemblyLocation = assemblyLocation; this.Reason = reason; this.GeneralChatType = this.dalamud.Configuration.GeneralChatType; @@ -88,11 +86,6 @@ namespace Dalamud.Plugin /// public PluginLoadReason Reason { get; } - /// - /// Gets the plugin assembly location. - /// - public string AssemblyLocation { get; private set; } - /// /// Gets the directory Dalamud assets are stored in. /// diff --git a/Dalamud/Plugin/Internal/LocalPlugin.cs b/Dalamud/Plugin/Internal/LocalPlugin.cs index f5b3481f8..3299feced 100644 --- a/Dalamud/Plugin/Internal/LocalPlugin.cs +++ b/Dalamud/Plugin/Internal/LocalPlugin.cs @@ -272,7 +272,7 @@ namespace Dalamud.Plugin.Internal this.Manifest.Save(this.manifestFile); } - this.DalamudInterface = new DalamudPluginInterface(this.dalamud, this.pluginAssembly.GetName().Name, this.DllFile.FullName, reason); + this.DalamudInterface = new DalamudPluginInterface(this.dalamud, this.pluginAssembly.GetName().Name, reason); if (this.IsDev) { From 16266f9636fb377a2164257ed59a01133c6a9b23 Mon Sep 17 00:00:00 2001 From: Raymond Date: Mon, 9 Aug 2021 11:12:55 -0400 Subject: [PATCH 04/23] Utility class and namespace --- Dalamud/Data/DataManager.cs | 3 +- Dalamud/Hooking/Internal/HookInfo.cs | 2 +- .../Interface/Internal/DalamudInterface.cs | 1 + .../Interface/Internal/InterfaceManager.cs | 5 +- .../Scratchpad/ScratchMacroProcessor.cs | 4 +- .../Internal/Windows/ChangelogWindow.cs | 1 + .../Interface/Internal/Windows/DataWindow.cs | 1 + Dalamud/Plugin/DalamudPluginInterface.cs | 6 ++- Dalamud/Troubleshooting.cs | 1 + Dalamud/Utility/EnumExtensions.cs | 28 ++++++++++ Dalamud/Utility/StringExtensions.cs | 16 ++++++ .../TexFileExtensions.cs | 2 +- Dalamud/{ => Utility}/Util.cs | 11 +--- Dalamud/Utility/VectorExtensions.cs | 52 +++++++++++++++++++ 14 files changed, 114 insertions(+), 19 deletions(-) create mode 100644 Dalamud/Utility/EnumExtensions.cs create mode 100644 Dalamud/Utility/StringExtensions.cs rename Dalamud/{Data/LuminaExtensions => Utility}/TexFileExtensions.cs (95%) rename Dalamud/{ => Utility}/Util.cs (94%) create mode 100644 Dalamud/Utility/VectorExtensions.cs diff --git a/Dalamud/Data/DataManager.cs b/Dalamud/Data/DataManager.cs index ebdf24c57..006dfcd27 100644 --- a/Dalamud/Data/DataManager.cs +++ b/Dalamud/Data/DataManager.cs @@ -5,9 +5,8 @@ using System.Diagnostics; using System.IO; using System.Threading; -using Dalamud.Data.LuminaExtensions; -using Dalamud.Interface; using Dalamud.Interface.Internal; +using Dalamud.Utility; using ImGuiScene; using JetBrains.Annotations; using Lumina; diff --git a/Dalamud/Hooking/Internal/HookInfo.cs b/Dalamud/Hooking/Internal/HookInfo.cs index c2850b806..73db6864b 100644 --- a/Dalamud/Hooking/Internal/HookInfo.cs +++ b/Dalamud/Hooking/Internal/HookInfo.cs @@ -67,7 +67,7 @@ namespace Dalamud.Hooking.Internal internal Delegate Delegate { get; } /// - /// Gets the hooked assembly. + /// Gets the assembly implementing the hook. /// internal Assembly Assembly { get; } } diff --git a/Dalamud/Interface/Internal/DalamudInterface.cs b/Dalamud/Interface/Internal/DalamudInterface.cs index 630f01296..3afcbe331 100644 --- a/Dalamud/Interface/Internal/DalamudInterface.cs +++ b/Dalamud/Interface/Internal/DalamudInterface.cs @@ -9,6 +9,7 @@ using Dalamud.Interface.Windowing; using Dalamud.Logging; using Dalamud.Logging.Internal; using Dalamud.Plugin.Internal; +using Dalamud.Utility; using ImGuiNET; using Serilog.Events; diff --git a/Dalamud/Interface/Internal/InterfaceManager.cs b/Dalamud/Interface/Internal/InterfaceManager.cs index 92ed70a67..c4338cbfb 100644 --- a/Dalamud/Interface/Internal/InterfaceManager.cs +++ b/Dalamud/Interface/Internal/InterfaceManager.cs @@ -11,6 +11,7 @@ using Dalamud.Game.ClientState; using Dalamud.Game.Internal.DXGI; using Dalamud.Hooking; using Dalamud.Hooking.Internal; +using Dalamud.Utility; using ImGuiNET; using ImGuiScene; using Serilog; @@ -322,9 +323,7 @@ namespace Dalamud.Interface.Internal private static void ShowFontError(string path) { - Util.Fatal( - $"One or more files required by XIVLauncher were not found.\nPlease restart and report this error if it occurs again.\n\n{path}", - "Error"); + Util.Fatal($"One or more files required by XIVLauncher were not found.\nPlease restart and report this error if it occurs again.\n\n{path}", "Error"); } private IntPtr PresentDetour(IntPtr swapChain, uint syncInterval, uint presentFlags) diff --git a/Dalamud/Interface/Internal/Scratchpad/ScratchMacroProcessor.cs b/Dalamud/Interface/Internal/Scratchpad/ScratchMacroProcessor.cs index 4fdbd64f5..e39741072 100644 --- a/Dalamud/Interface/Internal/Scratchpad/ScratchMacroProcessor.cs +++ b/Dalamud/Interface/Internal/Scratchpad/ScratchMacroProcessor.cs @@ -131,7 +131,7 @@ public class ScratchPlugin : IDalamudPlugin { case ParseContext.Dispose: break; default: - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(paramName: nameof(input)); } ctx = ParseContext.None; @@ -156,7 +156,7 @@ public class ScratchPlugin : IDalamudPlugin { disposeBody += line + "\n"; break; default: - throw new ArgumentOutOfRangeException(); + throw new ArgumentOutOfRangeException(paramName: nameof(input)); } } diff --git a/Dalamud/Interface/Internal/Windows/ChangelogWindow.cs b/Dalamud/Interface/Internal/Windows/ChangelogWindow.cs index 69c2ade06..0420fe591 100644 --- a/Dalamud/Interface/Internal/Windows/ChangelogWindow.cs +++ b/Dalamud/Interface/Internal/Windows/ChangelogWindow.cs @@ -1,6 +1,7 @@ using System.Diagnostics; using Dalamud.Interface.Windowing; +using Dalamud.Utility; using ImGuiNET; namespace Dalamud.Interface.Internal.Windows diff --git a/Dalamud/Interface/Internal/Windows/DataWindow.cs b/Dalamud/Interface/Internal/Windows/DataWindow.cs index aaa20951a..f024af818 100644 --- a/Dalamud/Interface/Internal/Windows/DataWindow.cs +++ b/Dalamud/Interface/Internal/Windows/DataWindow.cs @@ -14,6 +14,7 @@ using Dalamud.Game.Internal.Gui.Toast; using Dalamud.Game.Text; using Dalamud.Interface.Windowing; using Dalamud.Plugin; +using Dalamud.Utility; using ImGuiNET; using ImGuiScene; using Newtonsoft.Json; diff --git a/Dalamud/Plugin/DalamudPluginInterface.cs b/Dalamud/Plugin/DalamudPluginInterface.cs index cc3a9c247..0cd7007a4 100644 --- a/Dalamud/Plugin/DalamudPluginInterface.cs +++ b/Dalamud/Plugin/DalamudPluginInterface.cs @@ -117,7 +117,7 @@ namespace Dalamud.Plugin public Framework Framework { get; private set; } /// - /// Gets the UiBuilder instance which allows you to draw UI into the game via ImGui draw calls. + /// Gets the instance which allows you to draw UI into the game via ImGui draw calls. /// public UiBuilder UiBuilder { get; private set; } @@ -165,6 +165,8 @@ namespace Dalamud.Plugin /// internal Action AnyPluginIpcAction { get; private set; } + #region Configuration + /// /// Save a plugin configuration(inheriting IPluginConfiguration). /// @@ -216,6 +218,8 @@ namespace Dalamud.Plugin /// directory with path of AppData/XIVLauncher/pluginConfig/PluginInternalName/loc. public string GetPluginLocDirectory() => this.configs.GetDirectory(Path.Combine(this.pluginName, "loc")); + #endregion + #region Chat Links /// diff --git a/Dalamud/Troubleshooting.cs b/Dalamud/Troubleshooting.cs index 69b0df23e..dbc507687 100644 --- a/Dalamud/Troubleshooting.cs +++ b/Dalamud/Troubleshooting.cs @@ -6,6 +6,7 @@ using System.Text; using Dalamud.Configuration; using Dalamud.Plugin; using Dalamud.Plugin.Internal.Types; +using Dalamud.Utility; using Newtonsoft.Json; using Serilog; diff --git a/Dalamud/Utility/EnumExtensions.cs b/Dalamud/Utility/EnumExtensions.cs new file mode 100644 index 000000000..5a2d9172b --- /dev/null +++ b/Dalamud/Utility/EnumExtensions.cs @@ -0,0 +1,28 @@ +using System; +using System.Linq; + +namespace Dalamud.Utility +{ + /// + /// Extension methods for enums. + /// + public static class EnumExtensions + { + /// + /// Gets an attribute on an enum. + /// + /// The type of attribute to get. + /// The enum value that has an attached attribute. + /// The attached attribute, if any. + public static TAttribute GetAttribute(this Enum value) + where TAttribute : Attribute + { + var type = value.GetType(); + var name = Enum.GetName(type, value); + return type.GetField(name) // I prefer to get attributes this way + .GetCustomAttributes(false) + .OfType() + .SingleOrDefault(); + } + } +} diff --git a/Dalamud/Utility/StringExtensions.cs b/Dalamud/Utility/StringExtensions.cs new file mode 100644 index 000000000..d5c1dfc14 --- /dev/null +++ b/Dalamud/Utility/StringExtensions.cs @@ -0,0 +1,16 @@ +namespace Dalamud.Utility +{ + /// + /// Extension methods for strings. + /// + public static class StringExtensions + { + /// + /// An extension method to chain usage of string.Format. + /// + /// Format string. + /// Format arguments. + /// Formatted string. + public static string Format(this string format, params object[] args) => string.Format(format, args); + } +} diff --git a/Dalamud/Data/LuminaExtensions/TexFileExtensions.cs b/Dalamud/Utility/TexFileExtensions.cs similarity index 95% rename from Dalamud/Data/LuminaExtensions/TexFileExtensions.cs rename to Dalamud/Utility/TexFileExtensions.cs index d2bb7b736..ddfccba9c 100644 --- a/Dalamud/Data/LuminaExtensions/TexFileExtensions.cs +++ b/Dalamud/Utility/TexFileExtensions.cs @@ -1,7 +1,7 @@ using ImGuiScene; using Lumina.Data.Files; -namespace Dalamud.Data.LuminaExtensions +namespace Dalamud.Utility { /// /// Extensions to . diff --git a/Dalamud/Util.cs b/Dalamud/Utility/Util.cs similarity index 94% rename from Dalamud/Util.cs rename to Dalamud/Utility/Util.cs index 3084e1bab..edd2d8c97 100644 --- a/Dalamud/Util.cs +++ b/Dalamud/Utility/Util.cs @@ -7,10 +7,11 @@ using System.Text; using Dalamud.Game; using Dalamud.Interface; using Dalamud.Interface.Colors; +using Dalamud.Logging.Internal; using ImGuiNET; using Serilog; -namespace Dalamud +namespace Dalamud.Utility { /// /// Class providing various helper methods for use in Dalamud and plugins. @@ -196,13 +197,5 @@ namespace Dalamud // TODO: Someone implement GetUTF8String with some IntPtr overloads. // while(Marshal.ReadByte(0, sz) != 0) { sz++; } - - /// - /// An extension method to chain usage of string.Format. - /// - /// Format string. - /// Format arguments. - /// Formatted string. - public static string Format(this string format, params object[] args) => string.Format(format, args); } } diff --git a/Dalamud/Utility/VectorExtensions.cs b/Dalamud/Utility/VectorExtensions.cs new file mode 100644 index 000000000..0a14299c2 --- /dev/null +++ b/Dalamud/Utility/VectorExtensions.cs @@ -0,0 +1,52 @@ +using System.Numerics; + +namespace Dalamud.Utility +{ + /// + /// Extension methods for System.Numerics.VectorN and SharpDX.VectorN. + /// + public static class VectorExtensions + { + /// + /// Converts a SharpDX vector to System.Numerics. + /// + /// Vector to convert. + /// A converted vector. + public static Vector2 ToSystem(this SharpDX.Vector2 vec) => new(x: vec.X, y: vec.Y); + + /// + /// Converts a SharpDX vector to System.Numerics. + /// + /// Vector to convert. + /// A converted vector. + public static Vector3 ToSystem(this SharpDX.Vector3 vec) => new(x: vec.X, y: vec.Y, z: vec.Z); + + /// + /// Converts a SharpDX vector to System.Numerics. + /// + /// Vector to convert. + /// A converted vector. + public static Vector4 ToSystem(this SharpDX.Vector4 vec) => new(x: vec.X, y: vec.Y, z: vec.Z, w: vec.W); + + /// + /// Converts a System.Numerics vector to SharpDX. + /// + /// Vector to convert. + /// A converted vector. + public static SharpDX.Vector2 ToSharpDX(this Vector2 vec) => new(x: vec.X, y: vec.Y); + + /// + /// Converts a System.Numerics vector to SharpDX. + /// + /// Vector to convert. + /// A converted vector. + public static SharpDX.Vector3 ToSharpDX(this Vector3 vec) => new(x: vec.X, y: vec.Y, z: vec.Z); + + /// + /// Converts a System.Numerics vector to SharpDX. + /// + /// Vector to convert. + /// A converted vector. + public static SharpDX.Vector4 ToSharpDX(this Vector4 vec) => new(x: vec.X, y: vec.Y, z: vec.Z, w: vec.W); + } +} From f26b1ead9ee6531e8f9fbc558ef9ead9d28ca222 Mon Sep 17 00:00:00 2001 From: Raymond Date: Mon, 9 Aug 2021 11:20:34 -0400 Subject: [PATCH 05/23] Break out XivChatType Extensions and InfoAttribute --- Dalamud/Game/Text/XivChatType.cs | 76 ------------------- Dalamud/Game/Text/XivChatTypeExtensions.cs | 20 +++++ Dalamud/Game/Text/XivChatTypeInfoAttribute.cs | 39 ++++++++++ 3 files changed, 59 insertions(+), 76 deletions(-) create mode 100644 Dalamud/Game/Text/XivChatTypeExtensions.cs create mode 100644 Dalamud/Game/Text/XivChatTypeInfoAttribute.cs diff --git a/Dalamud/Game/Text/XivChatType.cs b/Dalamud/Game/Text/XivChatType.cs index 9658078f0..d89fc5f0c 100644 --- a/Dalamud/Game/Text/XivChatType.cs +++ b/Dalamud/Game/Text/XivChatType.cs @@ -1,6 +1,3 @@ -using System; -using System.Linq; - namespace Dalamud.Game.Text { /// @@ -237,77 +234,4 @@ namespace Dalamud.Game.Text [XivChatTypeInfo("Crossworld Linkshell 8", "cw8", 0xFF1E90FF)] CrossLinkShell8 = 107, } - - /// - /// Extension methods for the type. - /// - public static class XivChatTypeExtensions - { - /// - /// Get the InfoAttribute associated with this chat type. - /// - /// The chat type. - /// The info attribute. - public static XivChatTypeInfoAttribute GetDetails(this XivChatType chatType) - { - return chatType.GetAttribute(); - } - } - - /// - /// Storage for relevant information associated with the chat type. - /// - public class XivChatTypeInfoAttribute : Attribute - { - /// - /// Initializes a new instance of the class. - /// - /// The fancy name. - /// The name slug. - /// The default color. - internal XivChatTypeInfoAttribute(string fancyName, string slug, uint defaultColor) - { - this.FancyName = fancyName; - this.Slug = slug; - this.DefaultColor = defaultColor; - } - - /// - /// Gets the "fancy" name of the type. - /// - public string FancyName { get; } - - /// - /// Gets the type name slug or short-form. - /// - public string Slug { get; } - - /// - /// Gets the type default color. - /// - public uint DefaultColor { get; } - } - - /// - /// Extension methods for enums. - /// - public static class EnumExtensions - { - /// - /// Gets an attribute on an enum. - /// - /// The type of attribute to get. - /// The enum value that has an attached attribute. - /// The attached attribute, if any. - public static TAttribute GetAttribute(this Enum value) - where TAttribute : Attribute - { - var type = value.GetType(); - var name = Enum.GetName(type, value); - return type.GetField(name) // I prefer to get attributes this way - .GetCustomAttributes(false) - .OfType() - .SingleOrDefault(); - } - } } diff --git a/Dalamud/Game/Text/XivChatTypeExtensions.cs b/Dalamud/Game/Text/XivChatTypeExtensions.cs new file mode 100644 index 000000000..a26687c47 --- /dev/null +++ b/Dalamud/Game/Text/XivChatTypeExtensions.cs @@ -0,0 +1,20 @@ +using Dalamud.Utility; + +namespace Dalamud.Game.Text +{ + /// + /// Extension methods for the type. + /// + public static class XivChatTypeExtensions + { + /// + /// Get the InfoAttribute associated with this chat type. + /// + /// The chat type. + /// The info attribute. + public static XivChatTypeInfoAttribute GetDetails(this XivChatType chatType) + { + return chatType.GetAttribute(); + } + } +} diff --git a/Dalamud/Game/Text/XivChatTypeInfoAttribute.cs b/Dalamud/Game/Text/XivChatTypeInfoAttribute.cs new file mode 100644 index 000000000..e549ac761 --- /dev/null +++ b/Dalamud/Game/Text/XivChatTypeInfoAttribute.cs @@ -0,0 +1,39 @@ +using System; + +namespace Dalamud.Game.Text +{ + /// + /// Storage for relevant information associated with the chat type. + /// + [AttributeUsage(AttributeTargets.Field)] + public class XivChatTypeInfoAttribute : Attribute + { + /// + /// Initializes a new instance of the class. + /// + /// The fancy name. + /// The name slug. + /// The default color. + internal XivChatTypeInfoAttribute(string fancyName, string slug, uint defaultColor) + { + this.FancyName = fancyName; + this.Slug = slug; + this.DefaultColor = defaultColor; + } + + /// + /// Gets the "fancy" name of the type. + /// + public string FancyName { get; } + + /// + /// Gets the type name slug or short-form. + /// + public string Slug { get; } + + /// + /// Gets the type default color. + /// + public uint DefaultColor { get; } + } +} From b46afa6357ce1862d057fcae2586265c0ebdf876 Mon Sep 17 00:00:00 2001 From: Raymond Date: Mon, 9 Aug 2021 11:20:46 -0400 Subject: [PATCH 06/23] Break out FontAwesome Extensions --- Dalamud/Interface/FontAwesomeExtensions.cs | 30 ++++++++++++++++++++++ Dalamud/Interface/FontAwesomeIcon.cs | 26 ------------------- 2 files changed, 30 insertions(+), 26 deletions(-) create mode 100644 Dalamud/Interface/FontAwesomeExtensions.cs diff --git a/Dalamud/Interface/FontAwesomeExtensions.cs b/Dalamud/Interface/FontAwesomeExtensions.cs new file mode 100644 index 000000000..734ec128d --- /dev/null +++ b/Dalamud/Interface/FontAwesomeExtensions.cs @@ -0,0 +1,30 @@ +// Font-Awesome - Version 5.0.9 + +namespace Dalamud.Interface +{ + /// + /// Extension methods for . + /// + public static class FontAwesomeExtensions + { + /// + /// Convert the FontAwesomeIcon to a type. + /// + /// The icon to convert. + /// The converted icon. + public static char ToIconChar(this FontAwesomeIcon icon) + { + return (char)icon; + } + + /// + /// Conver the FontAwesomeIcon to a type. + /// + /// The icon to convert. + /// The converted icon. + public static string ToIconString(this FontAwesomeIcon icon) + { + return string.Empty + (char)icon; + } + } +} diff --git a/Dalamud/Interface/FontAwesomeIcon.cs b/Dalamud/Interface/FontAwesomeIcon.cs index a8b93e9e7..c2267766c 100644 --- a/Dalamud/Interface/FontAwesomeIcon.cs +++ b/Dalamud/Interface/FontAwesomeIcon.cs @@ -7047,30 +7047,4 @@ namespace Dalamud.Interface /// Zhihu = 0xF63F, } - - /// - /// Extension methods for . - /// - public static class FontAwesomeExtensions - { - /// - /// Convert the FontAwesomeIcon to a type. - /// - /// The icon to convert. - /// The converted icon. - public static char ToIconChar(this FontAwesomeIcon icon) - { - return (char)icon; - } - - /// - /// Conver the FontAwesomeIcon to a type. - /// - /// The icon to convert. - /// The converted icon. - public static string ToIconString(this FontAwesomeIcon icon) - { - return string.Empty + (char)icon; - } - } } From 8f939807799decd84919a94e8d7b0af88a651997 Mon Sep 17 00:00:00 2001 From: Raymond Date: Mon, 9 Aug 2021 11:22:57 -0400 Subject: [PATCH 07/23] Payload.DataResolver is now a property --- Dalamud/Game/Text/SeStringHandling/Payload.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Dalamud/Game/Text/SeStringHandling/Payload.cs b/Dalamud/Game/Text/SeStringHandling/Payload.cs index ebf689646..ff550fb42 100644 --- a/Dalamud/Game/Text/SeStringHandling/Payload.cs +++ b/Dalamud/Game/Text/SeStringHandling/Payload.cs @@ -21,15 +21,15 @@ namespace Dalamud.Game.Text.SeStringHandling /// public abstract partial class Payload { - /// - /// The Lumina instance to use for any necessary data lookups. - /// - public DataManager DataResolver; - - // private for now, since subclasses shouldn't interact with this + // private for now, since subclasses shouldn't interact with this. // To force-invalidate it, Dirty can be set to true private byte[] encodedData; + /// + /// Gets or sets the Lumina instance to use for any necessary data lookups. + /// + public DataManager DataResolver { get; set; } + /// /// Gets the type of this payload. /// From a58cb7cb3a633c115f53896a68c77286eba4d7df Mon Sep 17 00:00:00 2001 From: Raymond Date: Mon, 9 Aug 2021 11:23:34 -0400 Subject: [PATCH 08/23] Suppress START_BYTE/END_BYTE in source. --- Dalamud/Game/Text/SeStringHandling/Payload.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Dalamud/Game/Text/SeStringHandling/Payload.cs b/Dalamud/Game/Text/SeStringHandling/Payload.cs index ff550fb42..3ace4ebf1 100644 --- a/Dalamud/Game/Text/SeStringHandling/Payload.cs +++ b/Dalamud/Game/Text/SeStringHandling/Payload.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.IO; using Dalamud.Data; @@ -233,11 +234,13 @@ namespace Dalamud.Game.Text.SeStringHandling /// /// The start byte of a payload. /// + [SuppressMessage("StyleCop.CSharp.NamingRules", "SA1310:Field names should not contain underscore", Justification = "This is prefered.")] protected const byte START_BYTE = 0x02; /// /// The end byte of a payload. /// + [SuppressMessage("StyleCop.CSharp.NamingRules", "SA1310:Field names should not contain underscore", Justification = "This is prefered.")] protected const byte END_BYTE = 0x03; /// From e6861b1cffa4a5a0ed33025ff2e4e484448bc56b Mon Sep 17 00:00:00 2001 From: Raymond Date: Mon, 9 Aug 2021 11:23:50 -0400 Subject: [PATCH 09/23] Use Array.Empty instead --- Dalamud/Game/Text/SeStringHandling/Payloads/TextPayload.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dalamud/Game/Text/SeStringHandling/Payloads/TextPayload.cs b/Dalamud/Game/Text/SeStringHandling/Payloads/TextPayload.cs index 9d05fb440..d12bdd3a7 100644 --- a/Dalamud/Game/Text/SeStringHandling/Payloads/TextPayload.cs +++ b/Dalamud/Game/Text/SeStringHandling/Payloads/TextPayload.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.IO; using System.Text; @@ -67,7 +68,7 @@ namespace Dalamud.Game.Text.SeStringHandling.Payloads // this may change or go away if (string.IsNullOrEmpty(this.text)) { - return new byte[] { }; + return Array.Empty(); } return Encoding.UTF8.GetBytes(this.text); From 8531603ff29e49f5d6e8f1b6b0696e6fb70d3133 Mon Sep 17 00:00:00 2001 From: Raymond Date: Mon, 9 Aug 2021 11:24:03 -0400 Subject: [PATCH 10/23] GetHashCode can be simplified --- Dalamud/Game/Text/SeStringHandling/Payloads/RawPayload.cs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Dalamud/Game/Text/SeStringHandling/Payloads/RawPayload.cs b/Dalamud/Game/Text/SeStringHandling/Payloads/RawPayload.cs index ae3754839..0d80f015d 100644 --- a/Dalamud/Game/Text/SeStringHandling/Payloads/RawPayload.cs +++ b/Dalamud/Game/Text/SeStringHandling/Payloads/RawPayload.cs @@ -84,12 +84,7 @@ namespace Dalamud.Game.Text.SeStringHandling.Payloads /// public override int GetHashCode() { - // Generated random values. - var hashCode = 1216194372; - hashCode = (hashCode * -1521134295) + this.Type.GetHashCode(); - hashCode = (hashCode * -1521134295) + this.chunkType.GetHashCode(); - hashCode = (hashCode * -1521134295) + EqualityComparer.Default.GetHashCode(this.data); - return hashCode; + return HashCode.Combine(this.Type, this.chunkType, this.data); } /// From d1c34de33369b02901ced01a2368bbee640683a9 Mon Sep 17 00:00:00 2001 From: Raymond Date: Mon, 9 Aug 2021 11:24:16 -0400 Subject: [PATCH 11/23] Remove unnecessary parenthesis --- Dalamud/Game/Text/SeStringHandling/Payloads/MapLinkPayload.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dalamud/Game/Text/SeStringHandling/Payloads/MapLinkPayload.cs b/Dalamud/Game/Text/SeStringHandling/Payloads/MapLinkPayload.cs index fbcb447c7..a6e6c2e49 100644 --- a/Dalamud/Game/Text/SeStringHandling/Payloads/MapLinkPayload.cs +++ b/Dalamud/Game/Text/SeStringHandling/Payloads/MapLinkPayload.cs @@ -222,7 +222,7 @@ namespace Dalamud.Game.Text.SeStringHandling.Payloads var c = scale / 100.0f; var scaledPos = pos * c / 1000.0f; - return ((41.0f / c) * ((scaledPos + 1024.0f) / 2048.0f)) + 1.0f; + return (41.0f / c * ((scaledPos + 1024.0f) / 2048.0f)) + 1.0f; } // Created as the inverse of ConvertRawPositionToMapCoordinate(), since no one seemed to have a version of that @@ -230,7 +230,7 @@ namespace Dalamud.Game.Text.SeStringHandling.Payloads { var c = scale / 100.0f; - var scaledPos = ((((pos - 1.0f) * c / 41.0f) * 2048.0f) - 1024.0f) / c; + var scaledPos = (((pos - 1.0f) * c / 41.0f * 2048.0f) - 1024.0f) / c; scaledPos *= 1000.0f; return (int)scaledPos; From 6e3d5382b02af67556678a297e9334ecb5bbbb4b Mon Sep 17 00:00:00 2001 From: Raymond Date: Mon, 9 Aug 2021 11:24:45 -0400 Subject: [PATCH 12/23] Add a ctor to Position3 --- Dalamud/Game/Position3.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Dalamud/Game/Position3.cs b/Dalamud/Game/Position3.cs index 3812376df..ed477d511 100644 --- a/Dalamud/Game/Position3.cs +++ b/Dalamud/Game/Position3.cs @@ -23,6 +23,19 @@ namespace Dalamud.Game /// public float Y; + /// + /// Initializes a new instance of the struct. + /// + /// The X position. + /// The Z position. + /// The Y position. + public Position3(float x, float z, float y) + { + this.X = x; + this.Z = z; + this.Y = y; + } + /// /// Convert this Position3 to a System.Numerics.Vector3. /// From a080c80014d583d811db7cee2820f33c1813b972 Mon Sep 17 00:00:00 2001 From: Raymond Date: Mon, 9 Aug 2021 11:25:44 -0400 Subject: [PATCH 13/23] /xldata should open, not toggle if given arguments --- Dalamud/Interface/Internal/DalamudCommands.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dalamud/Interface/Internal/DalamudCommands.cs b/Dalamud/Interface/Internal/DalamudCommands.cs index 6e0f5e7a6..1a4f64815 100644 --- a/Dalamud/Interface/Internal/DalamudCommands.cs +++ b/Dalamud/Interface/Internal/DalamudCommands.cs @@ -242,7 +242,7 @@ namespace Dalamud.Interface.Internal if (string.IsNullOrEmpty(arguments)) this.dalamud.DalamudUi.ToggleDataWindow(); else - this.dalamud.DalamudUi.ToggleDataWindow(arguments); + this.dalamud.DalamudUi.OpenDataWindow(arguments); } private void OnOpenLog(string command, string arguments) From 43b8ca1d789c862118fc3d5180f71d0d9acc041b Mon Sep 17 00:00:00 2001 From: Raymond Date: Mon, 9 Aug 2021 11:26:36 -0400 Subject: [PATCH 14/23] Remove unneeded imports --- Dalamud/Interface/Internal/Windows/PluginStatWindow.cs | 2 +- Dalamud/Troubleshooting.cs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Dalamud/Interface/Internal/Windows/PluginStatWindow.cs b/Dalamud/Interface/Internal/Windows/PluginStatWindow.cs index cdb60d9b0..dc18ce73c 100644 --- a/Dalamud/Interface/Internal/Windows/PluginStatWindow.cs +++ b/Dalamud/Interface/Internal/Windows/PluginStatWindow.cs @@ -2,7 +2,7 @@ using System; using System.Linq; using System.Reflection; -using Dalamud.Game.Internal; +using Dalamud.Game; using Dalamud.Hooking.Internal; using Dalamud.Interface.Windowing; using Dalamud.Plugin.Internal; diff --git a/Dalamud/Troubleshooting.cs b/Dalamud/Troubleshooting.cs index dbc507687..7aba6ec2c 100644 --- a/Dalamud/Troubleshooting.cs +++ b/Dalamud/Troubleshooting.cs @@ -4,7 +4,6 @@ using System.Linq; using System.Text; using Dalamud.Configuration; -using Dalamud.Plugin; using Dalamud.Plugin.Internal.Types; using Dalamud.Utility; using Newtonsoft.Json; From 87a11d58688cadc037431e68b79e83a9a36e054e Mon Sep 17 00:00:00 2001 From: Raymond Date: Mon, 9 Aug 2021 11:26:57 -0400 Subject: [PATCH 15/23] Move public LibC classes out of internal --- Dalamud/Game/{Internal => }/Libc/LibcFunction.cs | 2 +- .../Game/{Internal => }/Libc/LibcFunctionAddressResolver.cs | 4 +++- Dalamud/Game/{Internal => }/Libc/OwnedStdString.cs | 2 +- Dalamud/Game/{Internal => }/Libc/StdString.cs | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) rename Dalamud/Game/{Internal => }/Libc/LibcFunction.cs (98%) rename Dalamud/Game/{Internal => }/Libc/LibcFunctionAddressResolver.cs (94%) rename Dalamud/Game/{Internal => }/Libc/OwnedStdString.cs (98%) rename Dalamud/Game/{Internal => }/Libc/StdString.cs (98%) diff --git a/Dalamud/Game/Internal/Libc/LibcFunction.cs b/Dalamud/Game/Libc/LibcFunction.cs similarity index 98% rename from Dalamud/Game/Internal/Libc/LibcFunction.cs rename to Dalamud/Game/Libc/LibcFunction.cs index 33990caae..cfab061c3 100644 --- a/Dalamud/Game/Internal/Libc/LibcFunction.cs +++ b/Dalamud/Game/Libc/LibcFunction.cs @@ -2,7 +2,7 @@ using System; using System.Runtime.InteropServices; using System.Text; -namespace Dalamud.Game.Internal.Libc +namespace Dalamud.Game.Libc { /// /// This class handles creating cstrings utilizing native game methods. diff --git a/Dalamud/Game/Internal/Libc/LibcFunctionAddressResolver.cs b/Dalamud/Game/Libc/LibcFunctionAddressResolver.cs similarity index 94% rename from Dalamud/Game/Internal/Libc/LibcFunctionAddressResolver.cs rename to Dalamud/Game/Libc/LibcFunctionAddressResolver.cs index b96a37493..4d30a1e74 100644 --- a/Dalamud/Game/Internal/Libc/LibcFunctionAddressResolver.cs +++ b/Dalamud/Game/Libc/LibcFunctionAddressResolver.cs @@ -1,6 +1,8 @@ using System; -namespace Dalamud.Game.Internal.Libc +using Dalamud.Game.Internal; + +namespace Dalamud.Game.Libc { /// /// The address resolver for the class. diff --git a/Dalamud/Game/Internal/Libc/OwnedStdString.cs b/Dalamud/Game/Libc/OwnedStdString.cs similarity index 98% rename from Dalamud/Game/Internal/Libc/OwnedStdString.cs rename to Dalamud/Game/Libc/OwnedStdString.cs index 7969e4947..1939e068e 100644 --- a/Dalamud/Game/Internal/Libc/OwnedStdString.cs +++ b/Dalamud/Game/Libc/OwnedStdString.cs @@ -1,7 +1,7 @@ using System; using System.Runtime.InteropServices; -namespace Dalamud.Game.Internal.Libc +namespace Dalamud.Game.Libc { /// /// An address wrapper around the class. diff --git a/Dalamud/Game/Internal/Libc/StdString.cs b/Dalamud/Game/Libc/StdString.cs similarity index 98% rename from Dalamud/Game/Internal/Libc/StdString.cs rename to Dalamud/Game/Libc/StdString.cs index 9b627c88d..4d4478687 100644 --- a/Dalamud/Game/Internal/Libc/StdString.cs +++ b/Dalamud/Game/Libc/StdString.cs @@ -2,7 +2,7 @@ using System; using System.Runtime.InteropServices; using System.Text; -namespace Dalamud.Game.Internal.Libc +namespace Dalamud.Game.Libc { /// /// Interation with std::string. From 71e549d59d7991477fe290926211e300e7c78fcc Mon Sep 17 00:00:00 2001 From: Raymond Date: Mon, 9 Aug 2021 11:29:00 -0400 Subject: [PATCH 16/23] Delete ResourceManager --- .../Game/Internal/Resource/ResourceManager.cs | 159 ------------------ .../ResourceManagerAddressResolver.cs | 28 --- 2 files changed, 187 deletions(-) delete mode 100644 Dalamud/Game/Internal/Resource/ResourceManager.cs delete mode 100644 Dalamud/Game/Internal/Resource/ResourceManagerAddressResolver.cs diff --git a/Dalamud/Game/Internal/Resource/ResourceManager.cs b/Dalamud/Game/Internal/Resource/ResourceManager.cs deleted file mode 100644 index 7e3c2b045..000000000 --- a/Dalamud/Game/Internal/Resource/ResourceManager.cs +++ /dev/null @@ -1,159 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Runtime.InteropServices; - -using Dalamud.Hooking; -using Serilog; - -namespace Dalamud.Game.Internal.File -{ - /// - /// This class facilitates modifying how the game loads resources from disk. - /// - public class ResourceManager - { - private readonly Dalamud dalamud; - private readonly ResourceManagerAddressResolver address; - private readonly Hook getResourceAsyncHook; - private readonly Hook getResourceSyncHook; - - private Dictionary resourceHookMap = new(); - - /// - /// Initializes a new instance of the class. - /// - /// The Dalamud instance. - /// The SigScanner instance. - internal ResourceManager(Dalamud dalamud, SigScanner scanner) - { - this.dalamud = dalamud; - this.address = new ResourceManagerAddressResolver(); - this.address.Setup(scanner); - - Log.Verbose("===== R E S O U R C E M A N A G E R ====="); - Log.Verbose("GetResourceAsync address {GetResourceAsync}", this.address.GetResourceAsync); - Log.Verbose("GetResourceSync address {GetResourceSync}", this.address.GetResourceSync); - - this.getResourceAsyncHook = new Hook(this.address.GetResourceAsync, this.GetResourceAsyncDetour); - this.getResourceSyncHook = new Hook(this.address.GetResourceSync, this.GetResourceSyncDetour); - } - - [UnmanagedFunctionPointer(CallingConvention.ThisCall)] - private delegate IntPtr GetResourceAsyncDelegate(IntPtr manager, IntPtr a2, IntPtr a3, IntPtr a4, IntPtr pathPtr, IntPtr a6, byte a7); - - [UnmanagedFunctionPointer(CallingConvention.ThisCall)] - private delegate IntPtr GetResourceSyncDelegate(IntPtr manager, IntPtr a2, IntPtr a3, IntPtr a4, IntPtr pathPtr, IntPtr a6); - - /// - /// Check if a filepath has any invalid characters. - /// - /// The filepath to check. - /// A value indicating whether the filepath is safe to use. - public static bool FilePathHasInvalidChars(string path) - { - return !string.IsNullOrEmpty(path) && path.IndexOfAny(Path.GetInvalidPathChars()) >= 0; - } - - /// - /// Enable this module. - /// - public void Enable() - { - this.getResourceAsyncHook.Enable(); - this.getResourceSyncHook.Enable(); - } - - /// - /// Dispose of managed and unmanaged resources. - /// - public void Dispose() - { - this.getResourceAsyncHook.Dispose(); - this.getResourceSyncHook.Dispose(); - } - - private IntPtr GetResourceAsyncDetour(IntPtr manager, IntPtr a2, IntPtr a3, IntPtr a4, IntPtr pathPtr, IntPtr a6, byte a7) - { - try - { - var path = Marshal.PtrToStringAnsi(pathPtr); - - var resourceHandle = this.getResourceAsyncHook.Original(manager, a2, a3, a4, IntPtr.Zero, a6, a7); - // var resourceHandle = IntPtr.Zero; - - Log.Verbose("GetResourceAsync CALL - this:{0} a2:{1} a3:{2} a4:{3} a5:{4} a6:{5} a7:{6} => RET:{7}", manager, a2, a3, a4, pathPtr, a6, a7, resourceHandle); - - Log.Verbose($"->{path}"); - - this.HandleGetResourceHookAcquire(resourceHandle, path); - - return resourceHandle; - } - catch (Exception ex) - { - Log.Error(ex, "Exception on ReadResourceAsync hook."); - - return this.getResourceAsyncHook.Original(manager, a2, a3, a4, pathPtr, a6, a7); - } - } - - private IntPtr GetResourceSyncDetour(IntPtr manager, IntPtr a2, IntPtr a3, IntPtr a4, IntPtr pathPtr, IntPtr a6) - { - try - { - var resourceHandle = this.getResourceSyncHook.Original(manager, a2, a3, a4, pathPtr, a6); - - Log.Verbose("GetResourceSync CALL - this:{0} a2:{1} a3:{2} a4:{3} a5:{4} a6:{5} => RET:{6}", manager, a2, a3, a4, pathPtr, a6, resourceHandle); - - var path = Marshal.PtrToStringAnsi(pathPtr); - - Log.Verbose($"->{path}"); - - this.HandleGetResourceHookAcquire(resourceHandle, path); - - return resourceHandle; - } - catch (Exception ex) - { - Log.Error(ex, "Exception on ReadResourceSync hook."); - - return this.getResourceSyncHook.Original(manager, a2, a3, a4, pathPtr, a6); - } - } - - private void HandleGetResourceHookAcquire(IntPtr handlePtr, string path) - { - if (FilePathHasInvalidChars(path)) - return; - - if (this.resourceHookMap.ContainsKey(handlePtr)) - { - Log.Verbose($"-> Handle {handlePtr.ToInt64():X}({path}) was cached!"); - return; - } - - var hookInfo = new ResourceHandleHookInfo - { - Path = path, - }; - - var hookPath = Path.Combine(this.dalamud.StartInfo.WorkingDirectory, "ResourceHook", path); - - if (System.IO.File.Exists(hookPath)) - { - hookInfo.DetourFile = new FileStream(hookPath, FileMode.Open); - Log.Verbose("-> Added resource hook detour at {0}", hookPath); - } - - this.resourceHookMap.Add(handlePtr, hookInfo); - } - - private class ResourceHandleHookInfo - { - public string Path { get; set; } - - public Stream DetourFile { get; set; } - } - } -} diff --git a/Dalamud/Game/Internal/Resource/ResourceManagerAddressResolver.cs b/Dalamud/Game/Internal/Resource/ResourceManagerAddressResolver.cs deleted file mode 100644 index b92ea8209..000000000 --- a/Dalamud/Game/Internal/Resource/ResourceManagerAddressResolver.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; - -namespace Dalamud.Game.Internal.File -{ - /// - /// The address resolver for the class. - /// - internal class ResourceManagerAddressResolver : BaseAddressResolver - { - /// - /// Gets the address of the GetResourceAsync method. - /// - public IntPtr GetResourceAsync { get; private set; } - - /// - /// Gets the address of the GetResourceSync method. - /// - public IntPtr GetResourceSync { get; private set; } - - /// - protected override void Setup64Bit(SigScanner sig) - { - this.GetResourceAsync = sig.ScanText("48 89 5C 24 08 48 89 54 24 10 57 48 83 EC 20 B8 03 00 00 00 48 8B F9 86 82 A1 00 00 00 48 8B 5C 24 38 B8 01 00 00 00 87 83 90 00 00 00 85 C0 74"); - this.GetResourceSync = sig.ScanText("48 89 5C 24 08 48 89 6C 24 10 48 89 74 24 18 57 41 54 41 55 41 56 41 57 48 83 EC 30 48 8B F9 49 8B E9 48 83 C1 30 4D 8B F0 4C 8B EA FF 15 CE F6"); - // ReadResourceSync = sig.ScanText("48 89 74 24 18 57 48 83 EC 50 8B F2 49 8B F8 41 0F B7 50 02 8B CE E8 ?? ?? 7A FF 0F B7 57 02 8D 42 89 3D 5F 02 00 00 0F 87 60 01 00 00 4C 8D 05"); - } - } -} From a62680cf5b8a6d0ce4798196c169ee24d716d4e5 Mon Sep 17 00:00:00 2001 From: Raymond Date: Mon, 9 Aug 2021 11:36:27 -0400 Subject: [PATCH 17/23] Handle open handle error when first creating the old file --- Dalamud/EntryPoint.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dalamud/EntryPoint.cs b/Dalamud/EntryPoint.cs index 378f841fd..6ce1cdc4b 100644 --- a/Dalamud/EntryPoint.cs +++ b/Dalamud/EntryPoint.cs @@ -142,7 +142,7 @@ namespace Dalamud var oldFile = new FileInfo(oldPath); if (!oldFile.Exists) - oldFile.Create(); + oldFile.Create().Close(); using var reader = new BinaryReader(logFile.Open(FileMode.Open, FileAccess.Read)); using var writer = new BinaryWriter(oldFile.Open(FileMode.Append, FileAccess.Write)); From 47ac918e4657004951b2eeca237b7d107e8136c4 Mon Sep 17 00:00:00 2001 From: Raymond Date: Mon, 9 Aug 2021 12:01:03 -0400 Subject: [PATCH 18/23] ClientLanguageExtensions and usage --- Dalamud/ClientLanguageExtensions.cs | 27 +++++++++++++++++++++++++++ Dalamud/Data/DataManager.cs | 21 ++------------------- 2 files changed, 29 insertions(+), 19 deletions(-) create mode 100644 Dalamud/ClientLanguageExtensions.cs diff --git a/Dalamud/ClientLanguageExtensions.cs b/Dalamud/ClientLanguageExtensions.cs new file mode 100644 index 000000000..dccefb93f --- /dev/null +++ b/Dalamud/ClientLanguageExtensions.cs @@ -0,0 +1,27 @@ +using System; + +namespace Dalamud +{ + /// + /// Extension methods for the class. + /// + public static class ClientLanguageExtensions + { + /// + /// Converts a Dalamud ClientLanguage to the corresponding Lumina variant. + /// + /// Langauge to convert. + /// Converted langauge. + public static Lumina.Data.Language ToLumina(this ClientLanguage language) + { + return language switch + { + ClientLanguage.Japanese => Lumina.Data.Language.Japanese, + ClientLanguage.English => Lumina.Data.Language.English, + ClientLanguage.German => Lumina.Data.Language.German, + ClientLanguage.French => Lumina.Data.Language.French, + _ => throw new ArgumentOutOfRangeException(nameof(language)), + }; + } + } +} diff --git a/Dalamud/Data/DataManager.cs b/Dalamud/Data/DataManager.cs index 006dfcd27..f28a56e69 100644 --- a/Dalamud/Data/DataManager.cs +++ b/Dalamud/Data/DataManager.cs @@ -95,15 +95,7 @@ namespace Dalamud.Data /// The , giving access to game rows. public ExcelSheet GetExcelSheet(ClientLanguage language) where T : ExcelRow { - var lang = language switch - { - ClientLanguage.Japanese => Lumina.Data.Language.Japanese, - ClientLanguage.English => Lumina.Data.Language.English, - ClientLanguage.German => Lumina.Data.Language.German, - ClientLanguage.French => Lumina.Data.Language.French, - _ => throw new ArgumentOutOfRangeException(nameof(language), $"Unknown Language: {language}"), - }; - return this.Excel.GetSheet(lang); + return this.Excel.GetSheet(language.ToLumina()); } /// @@ -262,21 +254,12 @@ namespace Dalamud.Data var luminaOptions = new LuminaOptions { CacheFileResources = true, - #if DEBUG PanicOnSheetChecksumMismatch = true, #else PanicOnSheetChecksumMismatch = false, #endif - - DefaultExcelLanguage = this.Language switch - { - ClientLanguage.Japanese => Lumina.Data.Language.Japanese, - ClientLanguage.English => Lumina.Data.Language.English, - ClientLanguage.German => Lumina.Data.Language.German, - ClientLanguage.French => Lumina.Data.Language.French, - _ => throw new ArgumentOutOfRangeException(nameof(this.Language), $"Unknown Language: {this.Language}"), - }, + DefaultExcelLanguage = this.Language.ToLumina(), }; var processModule = Process.GetCurrentProcess().MainModule; From 3c5f6271ceff934fa18f53f3cd2b258a4bb08631 Mon Sep 17 00:00:00 2001 From: Raymond Date: Mon, 9 Aug 2021 12:02:59 -0400 Subject: [PATCH 19/23] GetIcon should be uint, add more overloads for HQ icons Apparently "hq" is a language internally. --- Dalamud/Data/DataManager.cs | 58 +++++++++++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 6 deletions(-) diff --git a/Dalamud/Data/DataManager.cs b/Dalamud/Data/DataManager.cs index f28a56e69..093c8bb1a 100644 --- a/Dalamud/Data/DataManager.cs +++ b/Dalamud/Data/DataManager.cs @@ -137,18 +137,30 @@ namespace Dalamud.Data /// /// The icon ID. /// The containing the icon. - public TexFile GetIcon(int iconId) + public TexFile GetIcon(uint iconId) { return this.GetIcon(this.Language, iconId); } + /// + /// Get a containing the icon with the given ID, of the given quality. + /// + /// A value indicating whether the icon should be HQ. + /// The icon ID. + /// The containing the icon. + public TexFile GetIcon(bool isHq, uint iconId) + { + var type = isHq ? "hq/" : string.Empty; + return this.GetIcon(type, iconId); + } + /// /// Get a containing the icon with the given ID, of the given language. /// /// The requested language. /// The icon ID. /// The containing the icon. - public TexFile GetIcon(ClientLanguage iconLanguage, int iconId) + public TexFile GetIcon(ClientLanguage iconLanguage, uint iconId) { var type = iconLanguage switch { @@ -168,7 +180,7 @@ namespace Dalamud.Data /// The type of the icon (e.g. 'hq' to get the HQ variant of an item icon). /// The icon ID. /// The containing the icon. - public TexFile GetIcon(string type, int iconId) + public TexFile GetIcon(string type, uint iconId) { type ??= string.Empty; if (type.Length > 0 && !type.EndsWith("/")) @@ -177,7 +189,8 @@ namespace Dalamud.Data var filePath = string.Format(IconFileFormat, iconId / 1000, type, iconId); var file = this.GetFile(filePath); - if (file != default(TexFile) || type.Length <= 0) return file; + if (type == string.Empty || file != default) + return file; // Couldn't get specific type, try for generic version. filePath = string.Format(IconFileFormat, iconId / 1000, string.Empty, iconId); @@ -185,6 +198,14 @@ namespace Dalamud.Data return file; } + /// + /// Get a containing the HQ icon with the given ID. + /// + /// The icon ID. + /// The containing the icon. + public TexFile GetHqIcon(uint iconId) + => this.GetIcon(true, iconId); + /// /// Get the passed as a drawable ImGui TextureWrap. /// @@ -201,13 +222,30 @@ namespace Dalamud.Data public TextureWrap GetImGuiTexture(string path) => this.GetImGuiTexture(this.GetFile(path)); + /// + /// Get a containing the icon with the given ID. + /// + /// The icon ID. + /// The containing the icon. + public TextureWrap GetImGuiTextureIcon(uint iconId) + => this.GetImGuiTexture(this.GetIcon(iconId)); + + /// + /// Get a containing the icon with the given ID, of the given quality. + /// + /// A value indicating whether the icon should be HQ. + /// The icon ID. + /// The containing the icon. + public TextureWrap GetImGuiTextureIcon(bool isHq, uint iconId) + => this.GetImGuiTexture(this.GetIcon(isHq, iconId)); + /// /// Get a containing the icon with the given ID, of the given language. /// /// The requested language. /// The icon ID. /// The containing the icon. - public TextureWrap GetImGuiTextureIcon(ClientLanguage iconLanguage, int iconId) + public TextureWrap GetImGuiTextureIcon(ClientLanguage iconLanguage, uint iconId) => this.GetImGuiTexture(this.GetIcon(iconLanguage, iconId)); /// @@ -216,9 +254,17 @@ namespace Dalamud.Data /// The type of the icon (e.g. 'hq' to get the HQ variant of an item icon). /// The icon ID. /// The containing the icon. - public TextureWrap GetImGuiTextureIcon(string type, int iconId) + public TextureWrap GetImGuiTextureIcon(string type, uint iconId) => this.GetImGuiTexture(this.GetIcon(type, iconId)); + /// + /// Get a containing the HQ icon with the given ID. + /// + /// The icon ID. + /// The containing the icon. + public TextureWrap GetImGuiTextureHqIcon(uint iconId) + => this.GetImGuiTexture(this.GetHqIcon(iconId)); + #endregion /// From 67624e14aefe152c48c2dfd1ecfcd6e22bdcbc60 Mon Sep 17 00:00:00 2001 From: Raymond Date: Mon, 9 Aug 2021 12:03:50 -0400 Subject: [PATCH 20/23] Name the tuple in BaseAddressResolver --- Dalamud/Game/{Internal => }/BaseAddressResolver.cs | 6 +++--- Dalamud/Interface/Internal/Windows/DataWindow.cs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) rename Dalamud/Game/{Internal => }/BaseAddressResolver.cs (94%) diff --git a/Dalamud/Game/Internal/BaseAddressResolver.cs b/Dalamud/Game/BaseAddressResolver.cs similarity index 94% rename from Dalamud/Game/Internal/BaseAddressResolver.cs rename to Dalamud/Game/BaseAddressResolver.cs index 287bacaaa..b1873b0d7 100644 --- a/Dalamud/Game/Internal/BaseAddressResolver.cs +++ b/Dalamud/Game/BaseAddressResolver.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; -namespace Dalamud.Game.Internal +namespace Dalamud.Game { /// /// Base memory address resolver. @@ -11,9 +11,9 @@ namespace Dalamud.Game.Internal public abstract class BaseAddressResolver { /// - /// A list of memory addresses that were found, to list in /xldata. + /// Gets a list of memory addresses that were found, to list in /xldata. /// - public static Dictionary> DebugScannedValues = new(); + public static Dictionary> DebugScannedValues { get; } = new(); /// /// Gets or sets a value indicating whether the resolver has successfully run or . diff --git a/Dalamud/Interface/Internal/Windows/DataWindow.cs b/Dalamud/Interface/Internal/Windows/DataWindow.cs index f024af818..23f869f9d 100644 --- a/Dalamud/Interface/Internal/Windows/DataWindow.cs +++ b/Dalamud/Interface/Internal/Windows/DataWindow.cs @@ -286,11 +286,11 @@ namespace Dalamud.Interface.Internal.Windows foreach (var valueTuple in debugScannedValue.Value) { ImGui.TextUnformatted( - $" {valueTuple.Item1} - 0x{valueTuple.Item2.ToInt64():x}"); + $" {valueTuple.ClassName} - 0x{valueTuple.Address.ToInt64():x}"); ImGui.SameLine(); if (ImGui.Button($"C##copyAddress{this.copyButtonIndex++}")) - ImGui.SetClipboardText(valueTuple.Item2.ToInt64().ToString("x")); + ImGui.SetClipboardText(valueTuple.Address.ToInt64().ToString("x")); } } } From 5e925907ab52a95a51273e44f4bfbf267b6e9200 Mon Sep 17 00:00:00 2001 From: Raymond Date: Mon, 9 Aug 2021 12:25:47 -0400 Subject: [PATCH 21/23] Remove obsolete methods, fix imports --- Dalamud/Game/Internal/Framework.cs | 2 +- Dalamud/Game/Internal/Gui/ChatGui.cs | 21 +------------------ .../SeStringHandling/Payloads/IconPayload.cs | 17 --------------- .../Interface/Internal/Windows/DataWindow.cs | 2 +- .../Internal/Windows/PluginStatWindow.cs | 1 + 5 files changed, 4 insertions(+), 39 deletions(-) diff --git a/Dalamud/Game/Internal/Framework.cs b/Dalamud/Game/Internal/Framework.cs index abe3272e0..adef8e3c8 100644 --- a/Dalamud/Game/Internal/Framework.cs +++ b/Dalamud/Game/Internal/Framework.cs @@ -6,8 +6,8 @@ using System.Runtime.InteropServices; using System.Threading; using Dalamud.Game.Internal.Gui; -using Dalamud.Game.Internal.Libc; using Dalamud.Game.Internal.Network; +using Dalamud.Game.Libc; using Dalamud.Hooking; using Serilog; diff --git a/Dalamud/Game/Internal/Gui/ChatGui.cs b/Dalamud/Game/Internal/Gui/ChatGui.cs index 09aa234eb..9b60b8b46 100644 --- a/Dalamud/Game/Internal/Gui/ChatGui.cs +++ b/Dalamud/Game/Internal/Gui/ChatGui.cs @@ -2,9 +2,8 @@ using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; -using System.Text; -using Dalamud.Game.Internal.Libc; +using Dalamud.Game.Libc; using Dalamud.Game.Text; using Dalamud.Game.Text.SeStringHandling; using Dalamud.Game.Text.SeStringHandling.Payloads; @@ -60,17 +59,6 @@ namespace Dalamud.Game.Internal.Gui /// A value indicating whether the message was handled or should be propagated. public delegate void OnMessageDelegate(XivChatType type, uint senderId, ref SeString sender, ref SeString message, ref bool isHandled); - /// - /// A delegate type used with the event. - /// - /// The type of chat. - /// The sender ID. - /// The sender name. - /// The message sent. - /// A value indicating whether the message was handled or should be propagated. - [Obsolete("Please use OnMessageDelegate instead. For modifications, it will take precedence.")] - public delegate void OnMessageRawDelegate(XivChatType type, uint senderId, ref StdString sender, ref StdString message, ref bool isHandled); - /// /// A delegate type used with the event. /// @@ -113,12 +101,6 @@ namespace Dalamud.Game.Internal.Gui /// public event OnMessageDelegate OnChatMessage; - /// - /// Event that will be fired when a chat message is sent by the game, containing raw, unparsed data. - /// - [Obsolete("Please use OnChatMessage instead. For modifications, it will take precedence.")] - public event OnMessageRawDelegate OnChatMessageRaw; - /// /// Event that allows you to stop messages from appearing in chat by setting the isHandled parameter to true. /// @@ -388,7 +370,6 @@ namespace Dalamud.Game.Internal.Gui if (!isHandled) { this.OnChatMessage?.Invoke(chattype, senderid, ref parsedSender, ref parsedMessage, ref isHandled); - this.OnChatMessageRaw?.Invoke(chattype, senderid, ref sender, ref message, ref isHandled); } var newEdited = parsedMessage.Encode(); diff --git a/Dalamud/Game/Text/SeStringHandling/Payloads/IconPayload.cs b/Dalamud/Game/Text/SeStringHandling/Payloads/IconPayload.cs index e526d9c70..04bcd1029 100644 --- a/Dalamud/Game/Text/SeStringHandling/Payloads/IconPayload.cs +++ b/Dalamud/Game/Text/SeStringHandling/Payloads/IconPayload.cs @@ -19,17 +19,6 @@ namespace Dalamud.Game.Text.SeStringHandling.Payloads this.Icon = icon; } - /// - /// Initializes a new instance of the class. - /// Create a Icon payload for the specified icon. - /// - /// Index of the icon. - [Obsolete("IconPayload(uint) is deprecated, please use IconPayload(BitmapFontIcon).")] - public IconPayload(uint iconIndex) - : this((BitmapFontIcon)iconIndex) - { - } - /// /// Initializes a new instance of the class. /// Create a Icon payload for the specified icon. @@ -41,12 +30,6 @@ namespace Dalamud.Game.Text.SeStringHandling.Payloads /// public override PayloadType Type => PayloadType.Icon; - /// - /// Gets the index of the icon. - /// - [Obsolete("Use IconPayload.Icon")] - public uint IconIndex => (uint)this.Icon; - /// /// Gets or sets the icon the payload represents. /// diff --git a/Dalamud/Interface/Internal/Windows/DataWindow.cs b/Dalamud/Interface/Internal/Windows/DataWindow.cs index 23f869f9d..391520a0b 100644 --- a/Dalamud/Interface/Internal/Windows/DataWindow.cs +++ b/Dalamud/Interface/Internal/Windows/DataWindow.cs @@ -4,11 +4,11 @@ using System.Dynamic; using System.Linq; using System.Numerics; +using Dalamud.Game; using Dalamud.Game.ClientState; using Dalamud.Game.ClientState.Actors.Types; using Dalamud.Game.ClientState.Actors.Types.NonPlayer; using Dalamud.Game.ClientState.Structs.JobGauge; -using Dalamud.Game.Internal; using Dalamud.Game.Internal.Gui.Addon; using Dalamud.Game.Internal.Gui.Toast; using Dalamud.Game.Text; diff --git a/Dalamud/Interface/Internal/Windows/PluginStatWindow.cs b/Dalamud/Interface/Internal/Windows/PluginStatWindow.cs index dc18ce73c..733baa454 100644 --- a/Dalamud/Interface/Internal/Windows/PluginStatWindow.cs +++ b/Dalamud/Interface/Internal/Windows/PluginStatWindow.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Reflection; using Dalamud.Game; +using Dalamud.Game.Internal; using Dalamud.Hooking.Internal; using Dalamud.Interface.Windowing; using Dalamud.Plugin.Internal; From 0e4f9c46ee7667e68bd158d2cfa749d0dc397f1b Mon Sep 17 00:00:00 2001 From: Raymond Date: Mon, 9 Aug 2021 17:38:20 -0400 Subject: [PATCH 22/23] Fix imports --- Dalamud/Interface/Internal/Windows/PluginInstallerWindow.cs | 1 + Dalamud/Plugin/Internal/PluginManager.cs | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Dalamud/Interface/Internal/Windows/PluginInstallerWindow.cs b/Dalamud/Interface/Internal/Windows/PluginInstallerWindow.cs index 445e434d5..a599dd2ef 100644 --- a/Dalamud/Interface/Internal/Windows/PluginInstallerWindow.cs +++ b/Dalamud/Interface/Internal/Windows/PluginInstallerWindow.cs @@ -19,6 +19,7 @@ using Dalamud.Plugin; using Dalamud.Plugin.Internal; using Dalamud.Plugin.Internal.Exceptions; using Dalamud.Plugin.Internal.Types; +using Dalamud.Utility; using ImGuiNET; using ImGuiScene; diff --git a/Dalamud/Plugin/Internal/PluginManager.cs b/Dalamud/Plugin/Internal/PluginManager.cs index ec2a9e584..29fc718e2 100644 --- a/Dalamud/Plugin/Internal/PluginManager.cs +++ b/Dalamud/Plugin/Internal/PluginManager.cs @@ -6,7 +6,7 @@ using System.Diagnostics.CodeAnalysis; using System.IO; using System.IO.Compression; using System.Linq; -using System.Net; +using System.Net.Http; using System.Reflection; using System.Threading; using System.Threading.Tasks; @@ -17,6 +17,7 @@ using Dalamud.Game.Text; using Dalamud.Logging.Internal; using Dalamud.Plugin.Internal.Exceptions; using Dalamud.Plugin.Internal.Types; +using Dalamud.Utility; using HarmonyLib; using JetBrains.Annotations; using Newtonsoft.Json; From c699d403cdf3c2753631dd35d315d05975fdfead Mon Sep 17 00:00:00 2001 From: Raymond Date: Mon, 9 Aug 2021 17:40:05 -0400 Subject: [PATCH 23/23] Restore PluginLog.LogN methods --- Dalamud/Logging/PluginLog.cs | 127 +++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) diff --git a/Dalamud/Logging/PluginLog.cs b/Dalamud/Logging/PluginLog.cs index fefb386c5..a21363854 100644 --- a/Dalamud/Logging/PluginLog.cs +++ b/Dalamud/Logging/PluginLog.cs @@ -8,6 +8,131 @@ namespace Dalamud.Logging /// public static class PluginLog { + #region "Log" prefixed Serilog style methods + + /// + /// Log a templated message to the in-game debug log. + /// + /// The message template. + /// Values to log. + public static void Log(string messageTemplate, params object[] values) + => Serilog.Log.Information($"[{Assembly.GetCallingAssembly().GetName().Name}] {messageTemplate}", values); + + /// + /// Log a templated message to the in-game debug log. + /// + /// The exception that caused the error. + /// The message template. + /// Values to log. + public static void Log(Exception exception, string messageTemplate, params object[] values) + => Serilog.Log.Information(exception, $"[{Assembly.GetCallingAssembly().GetName().Name}] {messageTemplate}", values); + + /// + /// Log a templated verbose message to the in-game debug log. + /// + /// The message template. + /// Values to log. + public static void LogVerbose(string messageTemplate, params object[] values) + => Serilog.Log.Verbose($"[{Assembly.GetCallingAssembly().GetName().Name}] {messageTemplate}", values); + + /// + /// Log a templated verbose message to the in-game debug log. + /// + /// The exception that caused the error. + /// The message template. + /// Values to log. + public static void LogVerbose(Exception exception, string messageTemplate, params object[] values) + => Serilog.Log.Verbose(exception, $"[{Assembly.GetCallingAssembly().GetName().Name}] {messageTemplate}", values); + + /// + /// Log a templated debug message to the in-game debug log. + /// + /// The message template. + /// Values to log. + public static void LogDebug(string messageTemplate, params object[] values) + => Serilog.Log.Debug($"[{Assembly.GetCallingAssembly().GetName().Name}] {messageTemplate}", values); + + /// + /// Log a templated debug message to the in-game debug log. + /// + /// The exception that caused the error. + /// The message template. + /// Values to log. + public static void LogDebug(Exception exception, string messageTemplate, params object[] values) + => Serilog.Log.Debug(exception, $"[{Assembly.GetCallingAssembly().GetName().Name}] {messageTemplate}", values); + + /// + /// Log a templated information message to the in-game debug log. + /// + /// The message template. + /// Values to log. + public static void LogInformation(string messageTemplate, params object[] values) + => Serilog.Log.Information($"[{Assembly.GetCallingAssembly().GetName().Name}] {messageTemplate}", values); + + /// + /// Log a templated information message to the in-game debug log. + /// + /// The exception that caused the error. + /// The message template. + /// Values to log. + public static void LogInformation(Exception exception, string messageTemplate, params object[] values) + => Serilog.Log.Information(exception, $"[{Assembly.GetCallingAssembly().GetName().Name}] {messageTemplate}", values); + + /// + /// Log a templated warning message to the in-game debug log. + /// + /// The message template. + /// Values to log. + public static void LogWarning(string messageTemplate, params object[] values) + => Serilog.Log.Warning($"[{Assembly.GetCallingAssembly().GetName().Name}] {messageTemplate}", values); + + /// + /// Log a templated warning message to the in-game debug log. + /// + /// The exception that caused the error. + /// The message template. + /// Values to log. + public static void LogWarning(Exception exception, string messageTemplate, params object[] values) + => Serilog.Log.Warning(exception, $"[{Assembly.GetCallingAssembly().GetName().Name}] {messageTemplate}", values); + + /// + /// Log a templated error message to the in-game debug log. + /// + /// The message template. + /// Values to log. + public static void LogError(string messageTemplate, params object[] values) + => Serilog.Log.Error($"[{Assembly.GetCallingAssembly().GetName().Name}] {messageTemplate}", values); + + /// + /// Log a templated error message to the in-game debug log. + /// + /// The exception that caused the error. + /// The message template. + /// Values to log. + public static void LogError(Exception exception, string messageTemplate, params object[] values) + => Serilog.Log.Error(exception, $"[{Assembly.GetCallingAssembly().GetName().Name}] {messageTemplate}", values); + + /// + /// Log a templated fatal message to the in-game debug log. + /// + /// The message template. + /// Values to log. + public static void LogFatal(string messageTemplate, params object[] values) + => Serilog.Log.Fatal($"[{Assembly.GetCallingAssembly().GetName().Name}] {messageTemplate}", values); + + /// + /// Log a templated fatal message to the in-game debug log. + /// + /// The exception that caused the error. + /// The message template. + /// Values to log. + public static void LogFatal(Exception exception, string messageTemplate, params object[] values) + => Serilog.Log.Fatal(exception, $"[{Assembly.GetCallingAssembly().GetName().Name}] {messageTemplate}", values); + + #endregion + + #region Serilog style methods + /// /// Log a templated verbose message to the in-game debug log. /// @@ -109,5 +234,7 @@ namespace Dalamud.Logging /// Values to log. public static void Fatal(Exception exception, string messageTemplate, params object[] values) => Serilog.Log.Fatal(exception, $"[{Assembly.GetCallingAssembly().GetName().Name}] {messageTemplate}", values); + + #endregion } }