Class SafeMemory
Class facilitating safe memory access.
Assembly: Dalamud.dll
View Source
public static class SafeMemory
Methods
ReadBytes(nint, int, out byte[])
Read a byte array from the current process.
View Source
public static bool ReadBytes(nint address, int count, out byte[] buffer)
Returns
System.Boolean
: Whether or not the read succeeded.
Parameters
Type | Name | Description |
---|---|---|
System.IntPtr | address | The address to read from. |
System.Int32 | count | The amount of bytes to read. |
System.Byte[] | buffer | The result buffer. |
WriteBytes(nint, byte[])
Write a byte array to the current process.
View Source
public static bool WriteBytes(nint address, byte[] buffer)
Returns
System.Boolean
: Whether or not the write succeeded.
Parameters
Type | Name | Description |
---|---|---|
System.IntPtr | address | The address to write to. |
System.Byte[] | buffer | The buffer to write. |
Read<T>(nint, out T)
Read an object of the specified struct from the current process.
View Source
public static bool Read<T>(nint address, out T result) where T : struct
Returns
System.Boolean
: Whether or not the read succeeded.
Parameters
Type | Name | Description |
---|---|---|
System.IntPtr | address | The address to read from. |
<T> | result | The resulting object. |
Type Parameters
Name | Description |
---|---|
T | The type of the struct. |
Read<T>(nint, int)
Read an array of objects of the specified struct from the current process.
View Source
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
Type | Name | Description |
---|---|---|
System.IntPtr | address | The address to read from. |
System.Int32 | count | The length of the array. |
Type Parameters
Name | Description |
---|---|
T | The type of the struct. |
Write<T>(nint, T)
Write a struct to the current process.
View Source
public static bool Write<T>(nint address, T obj) where T : struct
Returns
System.Boolean
: Whether or not the write succeeded.
Parameters
Type | Name | Description |
---|---|---|
System.IntPtr | address | The address to write to. |
<T> | obj | The object to write. |
Type Parameters
Name | Description |
---|---|
T | The type of the struct. |
Write<T>(nint, T[])
Write an array of structs to the current process.
View Source
public static bool Write<T>(nint address, T[] objArray) where T : struct
Returns
System.Boolean
: Whether or not the write succeeded.
Parameters
Type | Name | Description |
---|---|---|
System.IntPtr | address | The address to write to. |
<T>[] | objArray | The array to write. |
Type Parameters
Name | Description |
---|---|
T | The type of the structs. |
ReadString(nint, int)
Read a string from the current process(UTF-8).
View Source
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
Type | Name | Description |
---|---|---|
System.IntPtr | address | The address to read from. |
System.Int32 | maxLength | The maximum length of the string. |
ReadString(nint, Encoding, int)
Read a string from the current process(UTF-8).
View Source
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
Type | Name | Description |
---|---|---|
System.IntPtr | address | The address to read from. |
System.Text.Encoding | encoding | The encoding to use to decode the string. |
System.Int32 | maxLength | The maximum length of the string. |
WriteString(nint, string)
Write a string to the current process.
View Source
public static bool WriteString(nint address, string str)
Returns
System.Boolean
: Whether or not the write succeeded.
Parameters
Type | Name | Description |
---|---|---|
System.IntPtr | address | The address to write to. |
System.String | str | The string to write. |
WriteString(nint, string, Encoding)
Write a string to the current process.
View Source
public static bool WriteString(nint address, string str, Encoding encoding)
Returns
System.Boolean
: Whether or not the write succeeded.
Parameters
Type | Name | Description |
---|---|---|
System.IntPtr | address | The address to write to. |
System.String | str | The string to write. |
System.Text.Encoding | encoding | The encoding to use. |
PtrToStructure<T>(nint)
Marshals data from an unmanaged block of memory to a managed object.
View Source
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
Type | Name | Description |
---|---|---|
System.IntPtr | addr | The address to read from. |
Type Parameters
Name | Description |
---|---|
T | The type to create. |
PtrToStructure(nint, Type)
Marshals data from an unmanaged block of memory to a managed object.
View Source
public static object? PtrToStructure(nint addr, Type type)
Returns
System.Object
: The read object, or null, if it could not be read.
Parameters
Type | Name | Description |
---|---|---|
System.IntPtr | addr | The address to read from. |
System.Type | type | The type to create. |
SizeOf<T>()
Get the size of the passed type.
View Source
public static int SizeOf<T>() where T : struct
Returns
System.Int32
: The size of the passed type.##### Type Parameters
Name | Description |
---|---|
T | The type to inspect. |