Class Util
Class providing various helper methods for use in Dalamud and plugins.
Assembly: Dalamud.dll
View Source
public static class Util
Properties
AssemblyVersion
Gets the assembly version of Dalamud.
View Source
public static string AssemblyVersion { get; }
Methods
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
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
public static string? GetGitHash()
Returns
System.String
: The git hash of the assembly.### GetGitHashClientStructs()
Gets the git hash value from the assembly or null if it cannot be found.
View Source
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
public static string DescribeAddress(void* p)
Returns
System.String
: Address description.
Parameters
Type | Name | Description |
---|---|---|
System.Void* | p | Address. |
DescribeAddress(nint)
Describes a memory address relative to module, or allocation base.
View Source
public static string DescribeAddress(nint p)
Returns
System.String
: Address description.
Parameters
Type | Name | Description |
---|---|---|
System.IntPtr | p | Address. |
DumpMemory(nint, int)
Read memory from an offset and hexdump them via Serilog.
View Source
public static void DumpMemory(nint offset, int len = 512)
Parameters
Type | Name | Description |
---|---|---|
System.IntPtr | offset | The offset to read from. |
System.Int32 | len | The length to read. |
ByteArrayToHex(byte[], int, int)
Create a hexdump of the provided bytes.
View Source
public static string ByteArrayToHex(byte[] bytes, int offset = 0, int bytesPerLine = 16)
Returns
System.String
: The generated hexdump in string form.
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | bytes | The bytes to hexdump. |
System.Int32 | offset | The offset in the byte array to start at. |
System.Int32 | bytesPerLine | The amount of bytes to display per line. |
ShowStruct(object, ulong, bool, IEnumerable<string>?)
Show a structure in an ImGui context.
View Source
public static void ShowStruct(object obj, ulong addr, bool autoExpand = false, IEnumerable<string>? path = null)
Parameters
Type | Name | Description |
---|---|---|
System.Object | obj | The structure to show. |
System.UInt64 | addr | The address to the structure. |
System.Boolean | autoExpand | Whether or not this structure should start out expanded. |
System.Collections.Generic.IEnumerable<System.String> | path | The already followed path. |
ShowStruct<T>(T*, bool)
Show a structure in an ImGui context.
View Source
public static void ShowStruct<T>(T* obj, bool autoExpand = false) where T : unmanaged
Parameters
Type | Name | Description |
---|---|---|
<T>* | obj | The pointer to the structure. |
System.Boolean | autoExpand | Whether or not this structure should start out expanded. |
Type Parameters
Name | Description |
---|---|
T | The type of the structure. |
ShowGameObjectStruct(IGameObject, bool)
Show a GameObject's internal data in an ImGui-context.
View Source
public static void ShowGameObjectStruct(IGameObject go, bool autoExpand = true)
Parameters
Type | Name | Description |
---|---|---|
Dalamud.Game.ClientState.Objects.Types.IGameObject | go | The GameObject to show. |
System.Boolean | autoExpand | Whether or not the struct should start as expanded. |
ShowObject(object)
Show all properties and fields of the provided object via ImGui.
View Source
public static void ShowObject(object obj)
Parameters
Type | Name | Description |
---|---|---|
System.Object | obj | The object to show. |
Fatal(string, string, bool)
Display an error MessageBox and exit the current process.
View Source
public static void Fatal(string message, string caption, bool exit = true)
Parameters
Type | Name | Description |
---|---|---|
System.String | message | MessageBox body. |
System.String | caption | MessageBox caption (title). |
System.Boolean | exit | Specify whether to exit immediately. |
FormatBytes(long)
Transform byte count to human readable format.
View Source
public static string FormatBytes(long bytes)
Returns
System.String
: Human readable version.
Parameters
Type | Name | Description |
---|---|---|
System.Int64 | bytes | Number of bytes. |
GetUTF8String(byte[])
Retrieve a UTF8 string from a null terminated byte array.
View Source
public static string GetUTF8String(byte[] array)
Returns
System.String
: A UTF8 encoded string.
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | array | A null terminated UTF8 byte array. |
CompressString(string)
Compress a string using GZip.
View Source
public static byte[] CompressString(string str)
Returns
System.Byte[]
: The compressed output bytes.
Parameters
Type | Name | Description |
---|---|---|
System.String | str | The input string. |
DecompressString(byte[])
Decompress a string using GZip.
View Source
public static string DecompressString(byte[] bytes)
Returns
System.String
: The compressed output string.
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | bytes | The 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
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
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
public static bool IsWindows11()
Returns
System.Boolean
: If Windows 11 has been detected.### OpenLink(string)
Open a link in the default browser.
View Source
public static void OpenLink(string url)
Parameters
Type | Name | Description |
---|---|---|
System.String | url | The 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
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
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<<TSource>>[] | sources | A set of enumerable sources to combine. |
Type Parameters
Name | Description |
---|---|
TSource | The 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
public static void FlashWindow(bool flashIfOpen = false)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | flashIfOpen | Attempt 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
public static void WriteAllTextSafe(string path, string text)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | The path of the file to write to. |
System.String | text | The 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
public static void WriteAllTextSafe(string path, string text, Encoding encoding)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | The path of the file to write to. |
System.String | text | The text to write. |
System.Text.Encoding | encoding | Encoding 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
public static void WriteAllBytesSafe(string path, byte[] bytes)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | The path of the file to write to. |
System.Byte[] | bytes | The 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
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
Type | Name | Description |
---|---|---|
System.String | targetFile | The target file. |