Skip to main content

Class Util

Class providing various helper methods for use in Dalamud and plugins.

Assembly: Dalamud.dll
View Source
Declaration
public static class Util

Properties

AssemblyVersion

Gets the assembly version of Dalamud.

View Source
Declaration
public static string AssemblyVersion { get; }

Methods

FastByteArrayCompare(byte[]?, byte[]?)

Check two byte arrays for equality.

View Source
Declaration
public static bool FastByteArrayCompare(byte[]? a1, byte[]? a2)
Returns

System.Boolean: Whether or not the byte arrays are equal.

Parameters
TypeNameDescription
System.Byte[]a1The first byte array.
System.Byte[]a2The second byte array.

GetScmVersion()

Gets the SCM Version from the assembly, or null if it cannot be found. This method will generally return the git describe output for this build, which will be a raw version if this is a stable build or an appropriately-annotated version if this is not stable. Local builds will return a Local Build text string.

View Source
Declaration
public static string GetScmVersion()
Returns

System.String: The SCM version of the assembly.### GetGitHash() Gets the git commit hash value from the assembly or null if it cannot be found. Will be null for Debug builds, and will be suffixed with -dirty if in release with pending changes.

View Source
Declaration
public static string? GetGitHash()
Returns

System.String: The git hash of the assembly.### GetGitCommitCount() Gets the amount of commits in the current branch, or null if undetermined.

View Source
Declaration
[Obsolete("Planned for removal in API 11. Use GetScmVersion for version tracking.")]
public static int? GetGitCommitCount()
Returns

System.Nullable<System.Int32>: The amount of commits in the current branch.### GetGitHashClientStructs() Gets the git hash value from the assembly or null if it cannot be found.

View Source
Declaration
public static string? GetGitHashClientStructs()
Returns

System.String: The git hash of the assembly.### DescribeAddress(void*) Describes a memory address relative to module, or allocation base.

View Source
Declaration
public static string DescribeAddress(void* p)
Returns

System.String: Address description.

Parameters
TypeNameDescription
System.Void*pAddress.

DescribeAddress(nint)

Describes a memory address relative to module, or allocation base.

View Source
Declaration
public static string DescribeAddress(nint p)
Returns

System.String: Address description.

Parameters
TypeNameDescription
System.IntPtrpAddress.

DumpMemory(nint, int)

Read memory from an offset and hexdump them via Serilog.

View Source
Declaration
public static void DumpMemory(nint offset, int len = 512)
Parameters
TypeNameDescription
System.IntPtroffsetThe offset to read from.
System.Int32lenThe length to read.

ByteArrayToHex(byte[], int, int)

Create a hexdump of the provided bytes.

View Source
Declaration
public static string ByteArrayToHex(byte[] bytes, int offset = 0, int bytesPerLine = 16)
Returns

System.String: The generated hexdump in string form.

Parameters
TypeNameDescription
System.Byte[]bytesThe bytes to hexdump.
System.Int32offsetThe offset in the byte array to start at.
System.Int32bytesPerLineThe amount of bytes to display per line.

ShowStruct(object, ulong, bool, IEnumerable<string>?)

Show a structure in an ImGui context.

View Source
Declaration
public static void ShowStruct(object obj, ulong addr, bool autoExpand = false, IEnumerable<string>? path = null)
Parameters
TypeNameDescription
System.ObjectobjThe structure to show.
System.UInt64addrThe address to the structure.
System.BooleanautoExpandWhether or not this structure should start out expanded.
System.Collections.Generic.IEnumerable<System.String>pathThe already followed path.

ShowStruct<T>(T*, bool)

Show a structure in an ImGui context.

View Source
Declaration
public static void ShowStruct<T>(T* obj, bool autoExpand = false) where T : unmanaged
Parameters
TypeNameDescription
<T>*objThe pointer to the structure.
System.BooleanautoExpandWhether or not this structure should start out expanded.
Type Parameters
NameDescription
TThe type of the structure.

ShowGameObjectStruct(IGameObject, bool)

Show a GameObject's internal data in an ImGui-context.

View Source
Declaration
public static void ShowGameObjectStruct(IGameObject go, bool autoExpand = true)
Parameters
TypeNameDescription
Dalamud.Game.ClientState.Objects.Types.IGameObjectgoThe GameObject to show.
System.BooleanautoExpandWhether or not the struct should start as expanded.

ShowObject(object)

Show all properties and fields of the provided object via ImGui.

View Source
Declaration
public static void ShowObject(object obj)
Parameters
TypeNameDescription
System.ObjectobjThe object to show.

Fatal(string, string, bool)

Display an error MessageBox and exit the current process.

View Source
Declaration
public static void Fatal(string message, string caption, bool exit = true)
Parameters
TypeNameDescription
System.StringmessageMessageBox body.
System.StringcaptionMessageBox caption (title).
System.BooleanexitSpecify whether to exit immediately.

FormatBytes(long)

Transform byte count to human readable format.

View Source
Declaration
public static string FormatBytes(long bytes)
Returns

System.String: Human readable version.

Parameters
TypeNameDescription
System.Int64bytesNumber of bytes.

GetUTF8String(byte[])

Retrieve a UTF8 string from a null terminated byte array.

View Source
Declaration
public static string GetUTF8String(byte[] array)
Returns

System.String: A UTF8 encoded string.

Parameters
TypeNameDescription
System.Byte[]arrayA null terminated UTF8 byte array.

CompressString(string)

Compress a string using GZip.

View Source
Declaration
public static byte[] CompressString(string str)
Returns

System.Byte[]: The compressed output bytes.

Parameters
TypeNameDescription
System.StringstrThe input string.

DecompressString(byte[])

Decompress a string using GZip.

View Source
Declaration
public static string DecompressString(byte[] bytes)
Returns

System.String: The compressed output string.

Parameters
TypeNameDescription
System.Byte[]bytesThe input bytes.

IsWine()

Determine if Dalamud is currently running within a Wine context (e.g. either on macOS or Linux). This method will not return information about the host operating system.

View Source
Declaration
public static bool IsWine()
Returns

System.Boolean: Returns true if Wine is detected, false otherwise.### GetHostPlatform() Gets the best guess for the current host's platform based on the XL_PLATFORM environment variable or heuristics.

View Source
Declaration
public static OSPlatform GetHostPlatform()
Returns

System.Runtime.InteropServices.OSPlatform: Returns the System.Runtime.InteropServices.OSPlatform that Dalamud is currently running on.### IsWindows11() Heuristically determine if the Windows version is higher than Windows 11's first build.

View Source
Declaration
public static bool IsWindows11()
Returns

System.Boolean: If Windows 11 has been detected.### OpenLink(string) Open a link in the default browser.

View Source
Declaration
public static void OpenLink(string url)
Parameters
TypeNameDescription
System.StringurlThe link to open.

ZipperMerge<TSource>(params IEnumerable<TSource>[])

Perform a "zipper merge" (A, 1, B, 2, C, 3) of multiple enumerables, allowing for lists to end early.

View Source
Declaration
public static IEnumerable<TSource> ZipperMerge<TSource>(params IEnumerable<TSource>[] sources)
Returns

System.Collections.Generic.IEnumerable<<TSource>>: A new enumerable, consisting of the final merge of all lists.

Parameters
TypeNameDescription
System.Collections.Generic.IEnumerable<<TSource>>[]sourcesA set of enumerable sources to combine.
Type Parameters
NameDescription
TSourceThe resulting type of the merged list to return.

FlashWindow(bool)

Request that Windows flash the game window to grab the user's attention.

View Source
Declaration
public static void FlashWindow(bool flashIfOpen = false)
Parameters
TypeNameDescription
System.BooleanflashIfOpenAttempt to flash even if the game is currently focused.

WriteAllTextSafe(string, string)

Overwrite text in a file by first writing it to a temporary file, and then moving that file to the path specified.

View Source
Declaration
public static void WriteAllTextSafe(string path, string text)
Parameters
TypeNameDescription
System.StringpathThe path of the file to write to.
System.StringtextThe text to write.

WriteAllTextSafe(string, string, Encoding)

Overwrite text in a file by first writing it to a temporary file, and then moving that file to the path specified.

View Source
Declaration
public static void WriteAllTextSafe(string path, string text, Encoding encoding)
Parameters
TypeNameDescription
System.StringpathThe path of the file to write to.
System.StringtextThe text to write.
System.Text.EncodingencodingEncoding to use.

WriteAllBytesSafe(string, byte[])

Overwrite data in a file by first writing it to a temporary file, and then moving that file to the path specified.

View Source
Declaration
public static void WriteAllBytesSafe(string path, byte[] bytes)
Parameters
TypeNameDescription
System.StringpathThe path of the file to write to.
System.Byte[]bytesThe data to write.

GetTempFileNameForFileReplacement(string)

Gets a temporary file name, for use as the sourceFileName in System.IO.File.Replace(System.String%2cSystem.String%2cSystem.String).

View Source
Declaration
public static string GetTempFileNameForFileReplacement(string targetFile)
Returns

System.String: A temporary file name that should be usable with System.IO.File.Replace(System.String%2cSystem.String%2cSystem.String).

Parameters
TypeNameDescription
System.StringtargetFileThe target file.