Skip to main content

Class SafeMemory

Class facilitating safe memory access.

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

Methods

ReadBytes(nint, int, out byte[])

Read a byte array from the current process.

View Source
Declaration
public static bool ReadBytes(nint address, int count, out byte[] buffer)
Returns

System.Boolean: Whether or not the read succeeded.

Parameters
TypeNameDescription
System.IntPtraddressThe address to read from.
System.Int32countThe amount of bytes to read.
System.Byte[]bufferThe result buffer.

WriteBytes(nint, byte[])

Write a byte array to the current process.

View Source
Declaration
public static bool WriteBytes(nint address, byte[] buffer)
Returns

System.Boolean: Whether or not the write succeeded.

Parameters
TypeNameDescription
System.IntPtraddressThe address to write to.
System.Byte[]bufferThe buffer to write.

Read<T>(nint, out T)

Read an object of the specified struct from the current process.

View Source
Declaration
public static bool Read<T>(nint address, out T result) where T : struct
Returns

System.Boolean: Whether or not the read succeeded.

Parameters
TypeNameDescription
System.IntPtraddressThe address to read from.
<T>resultThe resulting object.
Type Parameters
NameDescription
TThe type of the struct.

Read<T>(nint, int)

Read an array of objects of the specified struct from the current process.

View Source
Declaration
public static T[]? Read<T>(nint address, int count) where T : struct
Returns

<T>[]: An array of the read objects, or null if any entry of the array failed to read.

Parameters
TypeNameDescription
System.IntPtraddressThe address to read from.
System.Int32countThe length of the array.
Type Parameters
NameDescription
TThe type of the struct.

Write<T>(nint, T)

Write a struct to the current process.

View Source
Declaration
public static bool Write<T>(nint address, T obj) where T : struct
Returns

System.Boolean: Whether or not the write succeeded.

Parameters
TypeNameDescription
System.IntPtraddressThe address to write to.
<T>objThe object to write.
Type Parameters
NameDescription
TThe type of the struct.

Write<T>(nint, T[])

Write an array of structs to the current process.

View Source
Declaration
public static bool Write<T>(nint address, T[] objArray) where T : struct
Returns

System.Boolean: Whether or not the write succeeded.

Parameters
TypeNameDescription
System.IntPtraddressThe address to write to.
<T>[]objArrayThe array to write.
Type Parameters
NameDescription
TThe type of the structs.

ReadString(nint, int)

Read a string from the current process(UTF-8).

View Source
Declaration
public static string? ReadString(nint address, int maxLength = 256)
Returns

System.String: The read string, or null in case the read was not successful.

Parameters
TypeNameDescription
System.IntPtraddressThe address to read from.
System.Int32maxLengthThe maximum length of the string.

ReadString(nint, Encoding, int)

Read a string from the current process(UTF-8).

View Source
Declaration
public static string? ReadString(nint address, Encoding encoding, int maxLength = 256)
Returns

System.String: The read string, or null in case the read was not successful.

Parameters
TypeNameDescription
System.IntPtraddressThe address to read from.
System.Text.EncodingencodingThe encoding to use to decode the string.
System.Int32maxLengthThe maximum length of the string.

WriteString(nint, string)

Write a string to the current process.

View Source
Declaration
public static bool WriteString(nint address, string str)
Returns

System.Boolean: Whether or not the write succeeded.

Parameters
TypeNameDescription
System.IntPtraddressThe address to write to.
System.StringstrThe string to write.

WriteString(nint, string, Encoding)

Write a string to the current process.

View Source
Declaration
public static bool WriteString(nint address, string str, Encoding encoding)
Returns

System.Boolean: Whether or not the write succeeded.

Parameters
TypeNameDescription
System.IntPtraddressThe address to write to.
System.StringstrThe string to write.
System.Text.EncodingencodingThe encoding to use.

PtrToStructure<T>(nint)

Marshals data from an unmanaged block of memory to a managed object.

View Source
Declaration
public static T? PtrToStructure<T>(nint addr) where T : struct
Returns

System.Nullable<<T>>: The read object, or null, if it could not be read.

Parameters
TypeNameDescription
System.IntPtraddrThe address to read from.
Type Parameters
NameDescription
TThe type to create.

PtrToStructure(nint, Type)

Marshals data from an unmanaged block of memory to a managed object.

View Source
Declaration
public static object? PtrToStructure(nint addr, Type type)
Returns

System.Object: The read object, or null, if it could not be read.

Parameters
TypeNameDescription
System.IntPtraddrThe address to read from.
System.TypetypeThe type to create.

SizeOf<T>()

Get the size of the passed type.

View Source
Declaration
public static int SizeOf<T>() where T : struct
Returns

System.Int32: The size of the passed type.##### Type Parameters

NameDescription
TThe type to inspect.