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 ebdf24c57..093c8bb1a 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;
@@ -96,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());
}
///
@@ -146,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
{
@@ -177,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("/"))
@@ -186,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);
@@ -194,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.
///
@@ -210,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));
///
@@ -225,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
///
@@ -263,21 +300,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;
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));
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/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/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");
- }
- }
-}
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.
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.
///
diff --git a/Dalamud/Game/Text/SeStringHandling/Payload.cs b/Dalamud/Game/Text/SeStringHandling/Payload.cs
index ebf689646..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;
@@ -21,15 +22,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.
///
@@ -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;
///
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/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;
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);
}
///
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);
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; }
+ }
+}
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/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;
- }
- }
}
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)
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 825495dd1..9ebe4ec86 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/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/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 6b723098f..391520a0b 100644
--- a/Dalamud/Interface/Internal/Windows/DataWindow.cs
+++ b/Dalamud/Interface/Internal/Windows/DataWindow.cs
@@ -4,16 +4,17 @@ 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;
using Dalamud.Interface.Windowing;
using Dalamud.Plugin;
+using Dalamud.Utility;
using ImGuiNET;
using ImGuiScene;
using Newtonsoft.Json;
@@ -285,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"));
}
}
}
@@ -468,8 +469,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/Interface/Internal/Windows/PluginInstallerWindow.cs b/Dalamud/Interface/Internal/Windows/PluginInstallerWindow.cs
index 870251645..b99c1beb9 100644
--- a/Dalamud/Interface/Internal/Windows/PluginInstallerWindow.cs
+++ b/Dalamud/Interface/Internal/Windows/PluginInstallerWindow.cs
@@ -18,6 +18,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/Interface/Internal/Windows/PluginStatWindow.cs b/Dalamud/Interface/Internal/Windows/PluginStatWindow.cs
index cdb60d9b0..733baa454 100644
--- a/Dalamud/Interface/Internal/Windows/PluginStatWindow.cs
+++ b/Dalamud/Interface/Internal/Windows/PluginStatWindow.cs
@@ -2,6 +2,7 @@ using System;
using System.Linq;
using System.Reflection;
+using Dalamud.Game;
using Dalamud.Game.Internal;
using Dalamud.Hooking.Internal;
using Dalamud.Interface.Windowing;
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
}
}
diff --git a/Dalamud/Plugin/DalamudPluginInterface.cs b/Dalamud/Plugin/DalamudPluginInterface.cs
index 8814e494a..0cd7007a4 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.
///
@@ -124,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; }
@@ -172,6 +165,8 @@ namespace Dalamud.Plugin
///
internal Action AnyPluginIpcAction { get; private set; }
+ #region Configuration
+
///
/// Save a plugin configuration(inheriting IPluginConfiguration).
///
@@ -223,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/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)
{
diff --git a/Dalamud/Plugin/Internal/PluginManager.cs b/Dalamud/Plugin/Internal/PluginManager.cs
index a3f4f250e..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;
@@ -359,16 +360,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;
@@ -977,26 +979,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}");
}
///
@@ -1009,26 +1006,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()
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));
diff --git a/Dalamud/Troubleshooting.cs b/Dalamud/Troubleshooting.cs
index 69b0df23e..7aba6ec2c 100644
--- a/Dalamud/Troubleshooting.cs
+++ b/Dalamud/Troubleshooting.cs
@@ -4,8 +4,8 @@ using System.Linq;
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);
+ }
+}